Subversion Repositories Kolibri OS

Rev

Rev 1401 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ; ìàêðîñ äëÿ ñèñòåìíîé áèáëèîòåêè box_lib.obj
  2. ; ýëåìåíò TreeList äëÿ Kolibri OS
  3. ; ôàéë ïîñëåäíèé ðàç èçìåíÿëñÿ 10.02.2010 IgorA
  4. ; íà êîä ïðèìåíåíà GPL2 ëèöåíçèÿ
  5.  
  6.  
  7. sizeof.TreeList equ 20
  8. ;struct TreeList
  9. ;  type dw ? ;+ 0 òèï ýëåìåíòà, èëè èíäåêñ èêîíêè äëÿ óçëà
  10. ;  lev db ?  ;+ 2 óðîâåíü ýëåìåíòà
  11. ;  clo db ?  ;+ 3 ôëàã çàêðûòèÿ, èëè îòêðûòèÿ (èìååò ñìûñë äëÿ ðîäèòåëüñêîãî óçëà)
  12. ;  perv dd ? ;+ 4 èíäåêñ ïðåäûäóùåãî ýëåìåíòà
  13. ;  next dd ? ;+ 8 èíäåêñ ïîñëåäóþùåãî ýëåìåíòà
  14. ;  tc dd ?   ;+12 âðåì. ñîçäàíèÿ
  15. ;  td dd ?   ;+16 âðåì. óäàëåíèÿ
  16. ;ends
  17.  
  18. tl_info_size  equ  word[edi +4] ;ðàçìåð äàííûõ âûäåëÿåìûõ äëÿ êàæäîãî óçëà (ïîëüçîâàòåëüñüêèå äàííûå + òåêñò äëÿ ïîäïèñè)
  19. tl_info_max_count equ dword[edi+6] ;ìàêñèìàëüíîå êîëè÷åñòâî óçëîâ, êîòîðûå ìîæíî äîáàâèòü â ýëåìåíò
  20. tl_style      equ dword[edi+10] ;ñòèëè ýëåìåíòà
  21. tl_data_nodes equ dword[edi+14] ;óêàçàòåëü íà ñòðóêòóðû óçëîâ
  22. tl_data_img   equ dword[edi+18] ;óêàçàòåëü íà èçîáðàæåíèÿ ñ èêîíêàìè óçëîâ
  23. tl_img_cx     equ  word[edi+22] ;øèðèíà èêîíîê
  24. tl_img_cy     equ  word[edi+24] ;âûñîòà èêîíîê
  25. tl_data_img_sys equ dword[edi+26] ;óêàçàòåëü íà ñèñòåìíûå èçîáðàæåíèÿ (ñòðåëêè, ïëþñèêè)
  26. tl_ch_tim     equ dword[edi+30] ;êîëè÷åñòâî èçìåíåíèé â ôàéëå
  27. tl_tim_undo   equ dword[edi+38] ;êîëè÷åñòâî îòìåíåííûõ äåéñòâèé
  28. tl_cur_pos    equ dword[edi+42] ;ïîçèöèÿ êóðñîðà
  29. tl_col_bkg    equ dword[edi+46] ;öâåò ôîíà
  30. tl_col_zag    equ dword[edi+50] ;öâåò çàãîëîâêà
  31. tl_col_txt    equ dword[edi+54] ;öâåò òåêñòà
  32. tl_box_left   equ dword[edi+58]
  33. tl_box_top    equ dword[edi+62]
  34. tl_box_width  equ dword[edi+66]
  35. tl_box_height equ dword[edi+70]
  36. tl_capt_cy    equ  word[edi+74] ;âûñîòà ïîäïèñè
  37. tl_info_capt_offs equ word[edi+76] ;ñäâèã äëÿ íà÷àëà òåêñòà (ïîäïèñè óçëà)
  38. tl_info_capt_len equ word[edi+78] ;äëèííà òåêñòà ïîäïèñè óçëà (åñëè = 0 òî äî êîíöà ñòðóêòóðû)
  39. tl_el_focus   equ dword[edi+80] ;óêàçàòåëü íà ñòðóêòóðó ýëåìåíòà â ôîêóñå
  40. tl_p_scrol    equ dword[edi+84] ;óêàçàòåëü íà ñòðóêòóðó ñêðîëëèíãà
  41. tl_on_press   equ dword[edi+96] ;óêàçàòåëü íà ôóíêöèþ, êîòîðàÿ âûçûâàåòñÿ ïðè íàæàòèè Enter
  42.  
  43. ;êîíñòàíòû ñòèëÿ
  44. tl_key_no_edit   equ   1b ;ýëåìåíò íåëüçÿ ðåäàêòèðîâàòü íà êëàâèàòóðå (èçìåíÿòü óðîâíè, óäàëÿòü)
  45. tl_draw_par_line equ  10b ;ðèñîâàòü ëèíèè ê ðîäèòåëüñêîìó óçëó
  46. tl_list_box_mode equ 100b ;ñòèëü íå îòîáðàæàåò óðîâíè (êàê â ListBox âñå îäíîãî óðîâíÿ)
  47.  
  48. ;êîíñòàíòû äëÿ ôóíêöèé
  49. tl_err_save_memory_size equ  10b ;íå õâàòàåò ïàìÿòè äëÿ ñîõðàíåíèÿ ýëåìåíòà
  50. tl_err_load_caption     equ   1b ;â ïàìÿòè íåò çàãîëîâêà 'tree'
  51. tl_err_load_info_size   equ 100b ;íå ñîâïàäàåò ðàçìåð èíôîðìàöèîííîé ñòðóêòóðû ïðè îòêðûòèè
  52. tl_load_mode_add        equ 0x20000 ;îïöèÿ ñ÷èòûâàíèÿ â ðåæèìå äîáàâëåíèÿ èíôîðìàöèè
  53. tl_save_load_heder_size equ 26 ;ðàçìåð çàãîëîâêà äëÿ çàïèñè/÷òåíèÿ ýëåìåíòîâ
  54.  
  55. ;data_info       dd ? ;+ 0 óêàçàòåëü íà îñíîâíûå äàíûå
  56. ;ls_tim         dd ? ;+34 âðåìÿ ïîñëåäíåãî ñîõðàíåíèÿ
  57. ;on_activate dd ? ;+92 óêàçàòåëü íà ôóíêöèþ ïðè àêòèâèðîâàíèè óçëà
  58.  
  59. struc tree_list info_size,info_max_count,style, img_cx,img_cy,\
  60.     col_bkg,col_zag,col_txt, box_l,box_t,box_w,box_h, capt_cy,info_capt_offs,\
  61.     info_capt_len,el_focus, p_scrol,on_press {
  62.   .data_info    dd 0
  63.   .info_size    dw info_size
  64.   .info_max_count dd info_max_count
  65.   .style            dd style
  66.   .data_nodes   dd 0
  67.   .data_img      dd 0
  68.   .img_cx          dw img_cx
  69.   .img_cy          dw img_cy
  70.   .data_img_sys  dd 0
  71.   .ch_tim                 dd 0
  72.   .ls_tim                 dd 0
  73.   .tim_undo      dd 0
  74.   .cur_pos        dd 0
  75.   .col_bkg        dd col_bkg
  76.   .col_zag        dd col_zag
  77.   .col_txt        dd col_txt
  78.   .box_left   dd box_l
  79.   .box_top    dd box_t
  80.   .box_width  dd box_w
  81.   .box_height dd box_h
  82.   .capt_cy         dw capt_cy
  83.   .info_capt_offs dw info_capt_offs
  84.   .info_capt_len dw info_capt_len
  85.   .el_focus dd el_focus
  86.   .p_scrol  dd p_scrol
  87.   rb 4
  88.   .on_activate dd 0
  89.   .on_press dd on_press
  90. }
  91.  
  92. macro use_tree_list
  93. {
  94. ;-----------------------------------------------------------------------------
  95. ;ôóíêöèÿ äëÿ âûäåëåíèÿ ïàìÿòè
  96. ;input:
  97. ; ecx = size data
  98. ;otput:
  99. ; eax = pointer to memory
  100. align 4
  101. mem_Alloc:
  102.   push ebx
  103.   mov eax,68
  104.   mov ebx,12
  105.   int 0x40
  106.   pop ebx
  107.   ret
  108. ;-----------------------------------------------------------------------------
  109. ;ôóíêöèÿ äëÿ îñâîáîæäåíèÿ ïàìÿòè
  110. ;input:
  111. ; ecx = pointer to memory
  112. align 4
  113. mem_Free:
  114.   push eax ebx
  115.   cmp ecx,0
  116.   jz @f
  117.     mov eax,68
  118.     mov ebx,13
  119.     int 0x40
  120.   @@:
  121.   pop ebx eax
  122.   ret
  123.  
  124. align 4
  125. tl_data_init: ;âûäåëíèå ïàìÿòè äëÿ ñòðóêòóð ñïèñêà è îñíîâíîé èíôîðìàöèè (êîíñòðóêòîð)
  126.   push ebp
  127.   mov ebp,esp
  128.   push eax ecx edi
  129.     mov edi,dword[ebp+8]
  130.  
  131.     xor ecx,ecx
  132.     mov cx,tl_info_size
  133.     imul ecx,dword[edi+6]
  134.     call mem_Alloc
  135.     mov dword[edi],eax ;êîïèðóåì óêàçàòåëü íà ïîëó÷åíóþ ïàìÿòü â ñòðóêòóðó
  136.     mov tl_data_img,0  ;îáíóëÿåì óêàçàòåëü 'data_img'
  137.     mov tl_data_img_sys,0 ;îáíóëÿåì óêàçàòåëü 'data_img_sys'
  138.  
  139.     mov ecx,sizeof.TreeList
  140.     imul ecx,dword[edi+6]
  141.     call mem_Alloc
  142.     mov tl_data_nodes,eax ;êîïèðóåì óêàçàòåëü íà ïîëó÷åíóþ ïàìÿòü â ñòðóêòóðó
  143.  
  144.     push dword edi
  145.     call tl_info_clear
  146.  
  147.     ;íàñòðîéêè äî÷åðíåãî ñêðîëëèíãà
  148.     cmp tl_p_scrol,0
  149.     je @f
  150.       mov eax,tl_p_scrol
  151.       ;*** öâåòîâûå íàñòðîéêè ***
  152.       mov ecx,tl_col_bkg
  153.       mov dword[eax+28],ecx ;+28 .bckg_col
  154.       mov ecx,tl_col_zag
  155.       mov dword[eax+32],ecx ;+32 .frnt_col
  156.       mov ecx,tl_col_txt
  157.       mov dword[eax+36],ecx ;+32 .line_col
  158.       ;*** íàñòðîéêè ðàçìåðîâ ***
  159.       mov ecx,tl_box_left
  160.       add ecx,tl_box_width
  161.       mov word[eax+2],cx
  162.       mov ecx,tl_box_height
  163.       mov word[eax+4],cx
  164.       mov ecx,tl_box_top
  165.       mov word[eax+6],cx
  166.     @@:
  167.   pop edi ecx eax
  168.   pop ebp
  169.   ret 4
  170.  
  171. align 4
  172. tl_data_clear: ;î÷èñòêà ïàìÿòè ýëåìåíòà (äåñòðóêòîð)
  173.   push ebp
  174.   mov ebp,esp
  175.     push ecx edi
  176.     mov edi,dword[ebp+8]
  177.     cmp tl_data_img,0
  178.     je @f
  179.       mov ecx,dword[edi+18]
  180.       call mem_Free ;÷èñòêà ñèñòåìíûõ èêîíîê
  181.     @@:
  182.     cmp tl_data_img_sys,0
  183.     je @f
  184.       mov ecx,tl_data_img_sys
  185.       call mem_Free ;÷èñòêà ñèñòåìíûõ èêîíîê
  186.     @@:
  187.     mov ecx,dword[edi]
  188.     call mem_Free
  189.  
  190.     mov ecx,tl_data_nodes
  191.     call mem_Free
  192.     pop edi ecx
  193.   pop ebp
  194.   ret 4
  195.  
  196. align 4
  197. tl_info_clear: ;î÷èñòêà ñïèñêà (èíôîðìàöèè)
  198.   push ebp
  199.   mov ebp,esp
  200.     push eax ecx edi
  201.     mov edi,dword[ebp+8]
  202.     mov tl_ch_tim,0
  203.     mov dword[edi+34],0 ;ls_tim
  204.     mov tl_tim_undo,0
  205.     mov tl_cur_pos,0
  206.     ;xor ecx,ecx
  207.     mov ecx,sizeof.TreeList
  208.     imul ecx,dword[edi+6]
  209.     mov eax,tl_data_nodes
  210.     @@:
  211.       mov byte[eax],0 ;÷èñòèì óçëû 0-ìè
  212.       inc eax
  213.       loop @b
  214.     mov eax,tl_data_nodes ;óêàçàòåëü íà 0-é óçåë
  215.     mov dword[eax+8],1 ;óêàçàòåëü next â 0-ì óçëå ïðèðàâíèâàåì ê 1
  216.  
  217.     cmp tl_p_scrol,0 ;îáðàáîòêà ñêðîëëèíãà
  218.     je @f
  219.       mov eax,tl_p_scrol
  220.       mov dword[eax+24],0 ;+24 .position
  221.       call tb_scrol_resize
  222.     @@:
  223.     pop edi ecx eax
  224.   pop ebp
  225.   ret 4
  226.  
  227.  
  228. align 4
  229. tl_key: ;ðåàêöèÿ íà êëàâèàòóðó
  230.   push ebp
  231.   mov ebp,esp
  232.     push ebx ecx edi
  233.     mov edi,dword[ebp+8]
  234.  
  235.     mov ebx,tl_el_focus
  236.     cmp dword[ebx],edi
  237.     jne .no_focus ;ýëåìåíò íå â ôîêóñå
  238.  
  239.     push eax
  240.     mov eax,66
  241.     mov ebx,2
  242.     int 0x40  ;ïîëó÷èòü ðåæèì ââîäà ñ êëàâèàòóðû
  243.  
  244.     lea ecx,[tl_key_scan]
  245.     cmp eax,1 ;1 = ñêàíêîäû
  246.     je @f
  247.       lea ecx,[tl_key_ascii]
  248.     @@:
  249.     pop eax
  250.  
  251.     xor bx,bx
  252.     cmp ah,byte[ecx] ;Enter
  253.     jne @f
  254.       cmp tl_on_press,0
  255.       je @f
  256.         call tl_on_press
  257.     @@:
  258.     cmp ah,byte[ecx+1] ;Space
  259.     jne @f
  260.       push dword edi
  261.       call tl_node_close_open
  262.     @@:
  263.     cmp ah,byte[ecx+2] ;Up
  264.     jne @f
  265.       push dword edi
  266.       call tl_cur_perv
  267.     @@:
  268.     cmp ah,byte[ecx+3] ;Down
  269.     jne @f
  270.       push dword edi
  271.       call tl_cur_next
  272.     @@:
  273.     cmp ah,byte[ecx+7] ;Page Up
  274.     jne @f
  275.       push dword edi
  276.       call tl_cur_page_up
  277.     @@:
  278.     cmp ah,byte[ecx+8] ;Page Down
  279.     jne @f
  280.       push dword edi
  281.       call tl_cur_page_down
  282.     @@:
  283.  
  284.     bt tl_style,0 ;tl_key_no_edit
  285.     jc .no_edit
  286.       cmp ah,byte[ecx+4] ;Left
  287.       jne @f
  288.         push dword edi
  289.         call tl_node_lev_dec
  290.         mov bx,1
  291.       @@:
  292.       cmp ah,byte[ecx+5] ;Right
  293.       jne @f
  294.         push dword edi
  295.         call tl_node_lev_inc
  296.         mov bx,1
  297.       @@:
  298.       cmp ah,byte[ecx+6] ;Delete
  299.       jne @f
  300.         push dword edi
  301.         call tl_node_delete
  302.         mov bx,1
  303.       @@:
  304.     .no_edit:
  305.  
  306.     cmp bx,1
  307.     jne .no_focus
  308.       push dword edi
  309.       call tl_draw
  310.     .no_focus:
  311.  
  312.     pop edi ecx ebx
  313.   pop ebp
  314.   ret 4
  315.  
  316. align 4
  317. tl_mouse: ;ðåàêöèÿ íà ìûøü
  318.   push ebp
  319.   mov ebp,esp
  320.     pushad
  321.     mov edi,dword[ebp+8]
  322.  
  323.     mov eax,37
  324.     mov ebx,1
  325.     int 0x40
  326.  
  327.     mov ebx,tl_box_left
  328.     shl ebx,16
  329.     cmp eax,ebx ;ëåâàÿ ãðàíèöà îêíà
  330.     jl .no_in_wnd ;.test_scroll
  331.  
  332.     mov ebx,tl_box_left
  333.     add ebx,tl_box_width
  334.     shl ebx,16
  335.     cmp eax,ebx ;ïðàâàÿ ãðàíèöà îêíà
  336.     jg .test_scroll
  337.  
  338.     mov ebx,tl_box_top
  339.     add ebx,tl_box_height
  340.     cmp ax,bx ;íèæíÿÿ ãðàíèöà îêíà
  341.     jg .test_scroll
  342.  
  343.     sub ebx,tl_box_height
  344.     add bx,tl_capt_cy
  345.     cmp ax,bx ;âåðõíÿÿ ãðàíèöà îêíà + âûñîòà ïîäïèñè
  346.     jl .test_scroll
  347.  
  348.     push eax ebx
  349.       mov eax,37
  350.       mov ebx,2
  351.       int 0x40
  352.  
  353.       bt eax,0 ;left mouse button press
  354.     pop ebx eax
  355.       jae .no_draw
  356.  
  357.  
  358.     mov esi,tl_el_focus
  359.     mov dword[esi],edi ;set focus
  360.  
  361.     ; if '+' or '-' press
  362.     mov esi,eax
  363.     shr esi,16
  364.     sub esi,tl_box_left ;esi = mouse x coord in element window
  365.  
  366.     and eax,0xffff
  367.     sub ax,bx
  368.     xor edx,edx
  369.     xor ecx,ecx
  370.     mov cx,tl_img_cy
  371.     div ecx
  372.     cmp tl_p_scrol,0 ;ó÷èòûâàåì ñêðîëëèíã
  373.     je @f
  374.       mov edx,tl_p_scrol
  375.       add eax,dword[edx+24] ;äîáàâëÿåì ñêðîëëèíã íà âåðõó
  376.     @@:
  377.  
  378.     mov ecx,eax
  379.     call tl_get_node_count ;eax = node count
  380.     cmp eax,ecx
  381.     jl @f
  382.       mov eax,ecx ;åñëè êóðñîð íå âûøåë çà ïðåäåëû óçëîâ, âîññòàíàâëèâàåì ñòàðîå çíà÷åíèå eax
  383.     @@:
  384.  
  385.     cmp eax,tl_cur_pos ;åñëè íîâîå çíà÷åíèå êóðñîðà ñîâïàëî ñ ïðåäûäóùèì
  386.     je @f ;òî íå ñòèðàåì êóðñîð
  387.     push esi
  388.       mov esi,tl_box_top
  389.       add esi,tl_box_height ;esi = coord bottom border
  390.       call tl_draw_null_cursor ;ñòèðàåì êóðñîð
  391.     pop esi
  392.     @@:
  393.  
  394.     mov tl_cur_pos,eax
  395.  
  396.     ; if '+' or '-' press
  397.     call tl_get_cur_node_index ;eax = node index
  398.     cmp eax,2
  399.     jl .no_open_close ;êóðñîð ñòîèò íà ïóñòîì ìåñòå, áåç óçëîâ
  400.     imul eax,sizeof.TreeList
  401.     add eax,tl_data_nodes
  402.     xor bx,bx
  403.     mov bl,byte[eax+2] ;+2 lev ñîõðàíÿåì óðîâåíü òåêóùåãî óçëà
  404.     inc bx ;+ ïîëå äëÿ êóðñîðà
  405.  
  406.     cmp si,tl_img_cx
  407.     jl .no_open_close ;ìûøåé ïîïàëè íà ëåâîå ïîëå äëÿ êóðñîðà, ãäå òî÷íî íåò '+' è '-'
  408.       mov eax,esi
  409.       xor edx,edx
  410.       xor ecx,ecx
  411.       mov cx,tl_img_cx
  412.       div ecx
  413.  
  414.       cmp ax,bx
  415.       jne .no_open_close
  416.  
  417.       push dword edi
  418.       call tl_node_close_open
  419.     .no_open_close:
  420.  
  421.       mov esi,tl_box_top
  422.       add esi,tl_box_height ;esi = coord bottom border
  423.       call tl_draw_cursor ;ïåðåðèñîâêà êóðñîðà
  424.       call tl_draw_caption_cur_pos
  425.       jmp .no_draw
  426. ;--- mouse event for children scrollbar ----------------------------------------
  427. .test_scroll:
  428.   mov edx,tl_p_scrol
  429.   cmp edx,0
  430.   je .no_in_wnd ;ïîëüçîâàòåëü íå ñîçäàë äî÷åðíåãî ñêðîëëèíãà
  431.     shr ebx,16
  432.     add bx,word[edx] ;+0 .size_x
  433.     shl ebx,16
  434.     cmp eax,ebx ;ïðàâàÿ ãðàíèöà îêíà
  435.     jg .no_in_wnd
  436.  
  437.     mov eax,dword[edx+16] ;+16 .max_area
  438.     cmp eax,dword[edx+20] ;+20 .cur_area
  439.     jbe .no_in_wnd ;âñå óçëû ïîïàäàþò â îêíî ñêðîëëèíãà
  440.       push dword edx
  441.       call scroll_bar_vertical.mouse ;scrollbar_ver_mouse
  442.  
  443.       cmp dword[edx+40],0 ;+40 .redraw
  444.       je  @f
  445.         mov dword[edx+40],0 ;+40 .redraw
  446.         push dword edi
  447.         call tl_draw ;ïðîèçîøëè èçìåíåíèÿ ñêðîëëèíãà
  448.       @@:
  449.       cmp dword[edx+46],0 ;+46 .delta2
  450.       jne .no_draw ;ïîïàëè íà ñêðîëëèíã - íå ñíèìàåì ôîêóñ ñ TreeList
  451. ;-------------------------------------------------------------------------------
  452.     .no_in_wnd:  ;íå ïîïàëè â îêíî - ïîòåðÿ ôîêóñà (ïðè óñëîâèè ÷òî ôîêóñ áûë íà äàííîì ýåëåìåíòå)
  453.       mov eax,37 ;ïðîâåðÿåì íàæàòîñòü ëþáûõ êíîïîê
  454.       mov ebx,2
  455.       int 0x40
  456.       cmp eax,0  ;íè÷å íå íàæàëè eax=0
  457.       je .no_draw
  458.  
  459.       mov ebx,tl_el_focus
  460.       cmp dword[ebx],edi
  461.       jne .no_draw ;ýëåìåíò íå â ôîêóñå
  462.         mov dword[ebx],0 ;reset focus
  463.         mov esi,tl_box_top
  464.         add esi,tl_box_height ;esi = coord bottom border
  465.         call tl_draw_cursor ;ðèñóåì êóðñîð ñ ïîòåðÿíûì ôîêóñîì
  466.     .no_draw:
  467.  
  468.     popad
  469.   pop ebp
  470.   ret 4
  471.  
  472. align 4
  473. tl_info_undo: ;îòìåíà äåéñòâèÿ
  474.   push ebp
  475.   mov ebp,esp
  476.   push eax edi
  477.     mov edi,dword[ebp+8]
  478.     mov eax,tl_tim_undo
  479.     cmp tl_ch_tim,eax
  480.     jbe @f
  481.       inc tl_tim_undo
  482.       call tb_scrol_resize ;îáðàáîòêà ñêðîëëèíãà
  483.     @@:
  484.   pop edi eax
  485.   pop ebp
  486.   ret 4
  487.  
  488. align 4
  489. tl_info_redo: ;ïîâòîð äåéñòâèÿ
  490.   push ebp
  491.   mov ebp,esp
  492.   push edi
  493.     mov edi,dword[ebp+8]
  494.     cmp tl_tim_undo,1
  495.     jl @f
  496.       dec tl_tim_undo
  497.       call tb_scrol_resize ;îáðàáîòêà ñêðîëëèíãà
  498.     @@:
  499.   pop edi
  500.   pop ebp
  501.   ret 4
  502.  
  503. align 4
  504. tl_info_set_undo: ;óäàëåíèå îòìåíåííûõ äåéñòâèé
  505. ;  push ebp
  506. ;  mov ebp,esp
  507. ;  push edi
  508. ;    mov edi,dword[ebp+8]
  509.  
  510. ;  mov [dragk],0 ;çàêàí÷èâàåì âûäåëåíèå îò êëàâèàòóðû
  511.   cmp tl_tim_undo,1
  512.   jl .no_work
  513.  
  514.   push eax ebx ecx edx
  515.   mov edx,tl_data_nodes
  516.   mov ecx,edx
  517.   add ecx,sizeof.TreeList
  518.   call tl_move_next ;long i=node[0].next;
  519.   mov eax,tl_tim_undo
  520.   sub tl_ch_tim,eax ;ch_tim-=tim_undo;
  521.   mov eax,tl_ch_tim
  522.   cmp [edi+34],eax ;if(ls_tim>ch_tim)
  523.   jle @f
  524.     mov dword[edi+34],0 ;ls_tim=0
  525.   @@:
  526.     cmp edx,ecx
  527.     jle @f
  528.  
  529.     ;if(node[i].tc>ch_tim){ // åñëè ñîçäàíèå ñèìâîëà áûëî îòìåíåíî
  530.     cmp dword[edx+12],eax
  531.     jle .no_u1
  532.       mov dword[edx+12],0
  533.       mov dword[edx+16],0
  534.  
  535.       mov ebx, dword[edx+4]
  536.       imul ebx,sizeof.TreeList
  537.       add ebx, tl_data_nodes ;.next
  538.       push dword[edx+8] ;node[node[i].perv].next=node[i].next;
  539.       pop dword[ebx+8]
  540.  
  541.       mov ebx, dword[edx+8]
  542.       imul ebx,sizeof.TreeList
  543.       add ebx, tl_data_nodes ;.perv
  544.       push dword[edx+4] ;node[node[i].next].perv=node[i].perv;
  545.       pop dword[ebx+4]
  546.  
  547.     .no_u1:
  548.  
  549.     ;else if(node[i].td>ch_tim) node[i].td=0; // åñëè óäàëåíèå ñèìâîëà áûëî îòìåíåíî
  550.     cmp dword[edx+16],eax
  551.     jle .no_u2
  552.       mov dword[edx+16],0
  553.     .no_u2:
  554.  
  555.     call tl_move_next
  556.     jmp @b
  557.   @@:
  558.   mov tl_tim_undo,0
  559. ;  mov eax,[edi+?] ;co_tim
  560. ;  cmp tl_ch_tim,eax ;ch_tim
  561. ;  jge @f
  562. ;    mov [edi+?],0 ;co_tim
  563. ;  @@:
  564.   pop edx ecx ebx eax
  565.   .no_work:
  566.  
  567. ;  pop edi
  568. ;  pop ebp
  569. ;  ret 4
  570.   ret
  571.  
  572. align 4
  573. tl_draw: ;âûâîä ñïèñêà íà ýêðàí
  574.   push ebp
  575.   mov ebp,esp
  576.     pushad
  577.     ;draw dir_list main rect
  578.     mov edi,dword[ebp+8]
  579.     mov ebx,tl_box_left
  580.     shl ebx,16
  581.     add ebx,tl_box_width
  582.     mov ecx,tl_box_top
  583.     shl ecx,16
  584.     mov cx,tl_capt_cy
  585.     mov edx,tl_col_zag
  586.     mov eax,13
  587.     int 0x40 ;draw window caption
  588.  
  589.     add ecx,tl_box_top
  590.     shl ecx,16
  591.     add ecx,tl_box_height
  592.     sub cx,tl_capt_cy
  593.     mov edx,tl_col_bkg
  594.     int 0x40 ;draw window client rect
  595.  
  596.     cmp tl_capt_cy,9 ;9 - minimum caption height
  597.     jl @f
  598.     mov ebx,edi ;calculate cursor position
  599.     mov eax,tl_cur_pos
  600.     inc eax
  601.     lea edi,[txt_capt_cur]
  602.     add edi,7
  603.     call tl_convert_to_str
  604.  
  605.     mov edi,ebx
  606.     mov eax,tl_tim_undo
  607.     lea edi,[txt_capt_otm]
  608.     add edi,7
  609.     call tl_convert_to_str
  610.     mov edi,ebx ;restore edi
  611.  
  612.     mov eax,4 ;draw text captions
  613.     mov ebx,tl_box_left
  614.     shl ebx,16
  615.     add ebx,5*65536+3
  616.     add ebx,tl_box_top
  617.     mov ecx,tl_col_txt
  618.     or  ecx,0x80000000
  619.     lea edx,[txt_capt_cur]
  620.     int 0x40
  621.  
  622.     mov ebx,tl_box_left
  623.     shl ebx,16
  624.     add ebx,100*65536+3
  625.     add ebx,tl_box_top
  626.     lea edx,[txt_capt_otm]
  627.     int 0x40
  628.     @@:
  629.  
  630.     ;cycle to nodes
  631.     xor eax,eax
  632.     mov edx,tl_data_nodes
  633.     mov ecx,edx
  634.     add ecx,sizeof.TreeList
  635.  
  636.     ;*** ïðîïóñê óçëîâ, êîòîðûå ïðîìîòàíû ñêðîëëèíãîì ***
  637.     cmp tl_p_scrol,0 ;åñëè åñòü óêàçàòåëü íà ñêðîëëèíã
  638.     je .end_c1
  639.     mov esi,tl_p_scrol
  640.     cmp dword[esi+24],0 ;åñëè ñêðîëëèíã íà âåðõó, âûõîäèì
  641.     je .end_c1
  642.       @@:
  643.         call tl_iterat_next
  644.         cmp edx,ecx
  645.         jle .end_draw
  646.         inc eax
  647.         cmp eax,dword[esi+24]
  648.         jge .end_c1
  649.         jmp @b
  650.     .end_c1:
  651.  
  652.     xor eax,eax
  653.     mov esi,tl_box_top
  654.     add esi,tl_box_height ;esi = coord bottom border
  655.     @@:
  656.       call tl_iterat_next
  657.       cmp edx,ecx
  658.       jle @f
  659.       call tl_draw_node
  660.       inc eax
  661.       jmp @b
  662.     @@:
  663.  
  664.     call tl_draw_cursor
  665.  
  666.     mov edi,tl_p_scrol ;ðèñóåì äî÷åðíèé ñêðîëëèíã
  667.     cmp edi,0          ;äëÿ òîãî ÷òî-áû åãî íå ïðèøëîñü ðèñîâàòü â ïîëüçîâàòåëüñêîé ïðîãðàììå
  668.     je .end_draw       ;åñëè íåò ñêðîëëèíãà âûõîäèì
  669.     push dword edi
  670.     call scroll_bar_vertical.draw
  671.  
  672.     .end_draw:
  673.     popad
  674.   pop ebp
  675.   ret 4
  676.  
  677. ;input:
  678. ; ecx = pointer to 1 node struct
  679. ; edx = pointer to some node struct
  680. ; edi = pointer to 'TreeList' struct
  681. ;output:
  682. ; edx = pointer to next node struct
  683. align 4
  684. tl_iterat_next: ;ïåðåõîä íà ñëåäóùèé âèäèìûé óçåë (ïðîïóñêàÿ çàêðûòûå)
  685.   push bx
  686.   mov bl,0x7f
  687.   cmp byte[edx+3],1
  688.   jne @f
  689.     mov bl,byte[edx+2]
  690.   @@:
  691.  
  692.   cmp tl_tim_undo,0
  693.   je .else
  694.  
  695.   push eax
  696.   .beg0:
  697.     call tl_move_next
  698.     cmp edx,ecx
  699.     jle @f
  700.     call tl_node_not_vis ;ïðîïóñê óäàëåííûõ è îòìåíåííûõ
  701.     cmp al,1
  702.     je .beg0
  703.     cmp bl,byte[edx+2] ;ïðîïóñê çàêðûòûõ
  704.     jl .beg0
  705.   @@:
  706.   pop eax
  707.   pop bx
  708.   ret
  709.  
  710.   .else:
  711.     call tl_move_next
  712.     cmp edx,ecx
  713.     jle .endif
  714.     cmp dword[edx+16],0 ;td = 'time delete' -> ïðîïóñê óäàëåííûõ
  715.     jne .else
  716.     cmp bl,byte[edx+2] ;ïðîïóñê çàêðûòûõ
  717.     jl .else
  718.   .endif:
  719.   pop bx
  720.   ret
  721.  
  722. ;input:
  723. ; ecx = pointer to 1 node struct
  724. ; edx = pointer to some node struct
  725. ; edi = pointer to 'TreeList' struct
  726. align 4
  727. tl_iterat_next_all: ;ïåðåõîä íà ñëåäóùèé âèäèìûé óçåë (è íà çàêðûòûå òîæå)
  728.   cmp tl_tim_undo,0
  729.   je .else
  730.  
  731.   push eax
  732.   @@:
  733.     call tl_move_next
  734.     cmp edx,ecx
  735.     jle @f
  736.     call tl_node_not_vis
  737.     cmp al,1
  738.     je @b
  739.   @@:
  740.   pop eax
  741.   ret
  742.   .else:
  743.     call tl_move_next
  744.     cmp edx,ecx
  745.     jle .endif
  746.     cmp dword[edx+16],0 ;td -> time delete
  747.     jne .else
  748.   .endif:
  749.   ret
  750.  
  751. ;input:
  752. ; ecx = pointer to 1 node struct
  753. ; edx = pointer to some node struct
  754. ; edi = pointer to 'TreeList' struct
  755. align 4
  756. tl_iterat_perv: ;ïåðåõîä íà ïðåäûäóùèé âèäèìûé óçåë (ïðîïóñêàÿ çàêðûòûå)
  757.   push eax
  758.   cmp tl_tim_undo,0
  759.   je .beg1
  760.  
  761.   .beg0:
  762.     call tl_move_perv
  763.     cmp edx,ecx
  764.     jle @f
  765.     call tl_node_not_vis ;ïðîïóñê óäàëåííûõ è îòìåíåííûõ
  766.     cmp al,1
  767.     je .beg0
  768.  
  769.   .beg1:
  770.     call tl_move_perv
  771.     cmp edx,ecx
  772.     jle @f
  773.     cmp dword[edx+16],0 ;td = 'time delete' -> ïðîïóñê óäàëåííûõ
  774.     jne .beg1
  775.  
  776.   @@:
  777.     call tl_move_max_clo_par
  778.   pop eax
  779.   ret
  780.  
  781.  
  782. ;input:
  783. ; edx = pointer to some node struct
  784. ; edi = pointer to 'TreeList' struct
  785. ;output:
  786. ; edx = pointer closed parent node with maximum level
  787. align 4
  788. tl_move_max_clo_par: ;íàõîäèò ðîäèòåëüñêèé çàêðûòûé óçåë ìàêñèìàëüíîãî óðîâíÿ
  789.   push eax ebx
  790.   mov eax,edx
  791.   xor ebx,ebx
  792.   .beg:
  793.     call tl_move_par
  794.     cmp byte[edx+3],1 ;ðîäèòåëüñêèé óçåë çàêðûò ?
  795.     jne @f
  796.       mov eax,edx
  797.     @@:
  798.     cmp ebx,edx
  799.     je .end_f
  800.       mov ebx,edx
  801.     jmp .beg
  802.   .end_f:
  803.   mov edx,eax
  804.   pop ebx eax
  805.   ret
  806.  
  807. ;input:
  808. ; edx = pointer to some node struct
  809. ; edi = pointer to 'TreeList' struct
  810. ;output:
  811. ; edx = pointer to next node struct
  812. align 4
  813. tl_move_next:
  814.   mov edx,dword[edx+8]
  815.   imul edx,sizeof.TreeList
  816.   add edx,tl_data_nodes
  817.   ret
  818.  
  819. ;input:
  820. ; edx = pointer to some node struct
  821. ; edi = pointer to 'TreeList' struct
  822. ;output:
  823. ; edx = pointer to perv node struct
  824. align 4
  825. tl_move_perv:
  826.   mov edx,dword[edx+4]
  827.   imul edx,sizeof.TreeList
  828.   add edx,tl_data_nodes
  829.   ret
  830.  
  831. ;input:
  832. ; ecx =
  833. ; edx = pointer to some node struct
  834. ; edi = pointer to 'TreeList' struct
  835. ;output:
  836. ; edx = pointer to parent node struct
  837. align 4
  838. tl_move_par: ;ïåðåäâèãàåìñÿ íà ðîäèòåëüñêèé óçåë, åñëè òàêîãî íåò, òî îñòàâëÿåì ñòàðîå çíà÷åíèå óêàçàòåëÿ
  839.  cmp byte[edx+2],0
  840.  je .end_f ;óçåë 0-ãî óðîâíÿ íå ìîæåò áûòü äî÷åðíèì
  841.  push eax ebx esi
  842.  mov esi,edx ;copy node pointer (edx)
  843.  mov bl,byte[edx+2]
  844.  @@:
  845.    call tl_move_perv
  846.    cmp edx,ecx
  847.    jle @f ;âñå âûøå ñòîÿùèå óçëû íå ðîäèòåëüñêèå
  848.    call tl_node_not_vis ;ïðîïóñê óäàëåííûõ è îòìåíåííûõ
  849.    cmp al,1
  850.    je @b
  851.    cmp byte[edx+2],bl
  852.    jl .end_0 ;óäà÷íî íàøëè ðîäèòåëüñêèé óçåë
  853.    jmp @b
  854.  @@:
  855.    mov esi,ebx ;restore node pointer
  856.  .end_0:
  857.  pop esi ebx eax
  858.  .end_f:
  859.  ret
  860.  
  861. ;input:
  862. ; edx = pointer to symbol struct
  863. ; edi = pointer to 'TreeList' struct
  864. ;output:
  865. ; al = 1 if sumbol not visible
  866. ; (node[i].td+tim_Undo<=ch_tim && node[i].td) || (node[i].tc>ch_tim-tim_Undo)
  867. align 4
  868. tl_node_not_vis: ;ïðîâåðÿåò âèäèìûé ëè óêàçàííûé óçåë ñ ó÷åòîì: äîáàâëåíèé, óäàëåíèé, îòìåí äåéñòâèé
  869.   cmp dword[edx+16],0
  870.   je @f
  871.   mov eax,dword[edx+16] ;eax=node[i].td
  872.   add eax,tl_tim_undo
  873.   cmp eax,tl_ch_tim
  874.   jg @f
  875.     mov al,1
  876.     ret
  877.   @@:
  878.  
  879.   mov eax,tl_ch_tim
  880.   sub eax,tl_tim_undo
  881.   cmp dword[edx+12],eax ;tc -> time create
  882.   jle @f
  883.     mov al,1
  884.     ret
  885.   @@:
  886.   xor al,al
  887.   ret
  888.  
  889.  
  890. ;input:
  891. ; edi = pointer to TreeInfo struct
  892. ; esi = coord bottom border
  893. align 4
  894. tl_draw_cursor: ;ðèñóåì êóðñîð íà ýêðàíå
  895.   push eax ebx ecx edx esi
  896.     call tl_get_display_cur_pos ;eax = cursor pos in screen
  897.     cmp eax,0
  898.     jl .end_f ;êóðñîð íàõîäèòñÿ âûøå îêíà, â îáëàñòè ïðîêðó÷åííîé ñêðîëëèíãîì
  899.  
  900.     cmp tl_data_img_sys,0 ;ñìîòðèì åñòü ëè óêàçàòåëü íà êàðòèíêó ñèñòåìíûõ èêîíîê
  901.     jne @f
  902.       mov ebx,tl_box_left
  903.       shl ebx,16
  904.       mov bx,tl_img_cx
  905.       xor ecx,ecx
  906.       mov cx,tl_img_cy
  907.       imul ecx,eax
  908.       add ecx,tl_box_top
  909.       add cx,tl_capt_cy
  910.  
  911.       ;crop image if on the border
  912.       cmp esi,ecx ;åñëè êóðñîð âíèçó è åãî âîîáùå íå âèäíî
  913.       jl .end_f
  914.  
  915.       sub esi,ecx
  916.       shl ecx,16
  917.       mov cx,tl_img_cy
  918.       cmp si,tl_img_cy
  919.       jge .crop0
  920.         mov cx,si ;åñëè êóðñîð âèäåí ÷àñòè÷íî (ïîïàë íà íèæíþþ ãðàíèöó)
  921.       .crop0:
  922.  
  923.       mov edx,tl_col_txt
  924.       mov eax,13
  925.       int 0x40 ;ðèñóåì ïðîñòîé ïðÿìîóãîëüíèê, ò.ê. íåò ñèñòåìíûõ èêîíîê
  926.       jmp .end_f
  927.     @@:
  928.       mov ebx,tl_data_img_sys
  929.       imul ax,tl_img_cy
  930.       mov edx,tl_box_left
  931.       shl edx,16
  932.       mov dx,ax
  933.       add edx,tl_box_top
  934.       add dx,tl_capt_cy
  935.  
  936.       mov ecx,tl_el_focus ;ïðîâåðÿåì â ôîêóñå ýëåìåíò èëè íåò
  937.       cmp dword[ecx],edi
  938.       je .focus
  939.         xor eax,eax
  940.         xor ecx,ecx
  941.         mov cx,tl_img_cx
  942.         mov ax,tl_img_cy
  943.         imul eax,ecx
  944.         imul eax,4*3 ;4=icon index 3=rgb
  945.         add ebx,eax
  946.       .focus:
  947.  
  948.       mov cx,tl_img_cx
  949.       shl ecx,16
  950.       mov cx,tl_img_cy
  951.  
  952.       ;crop image if on the border
  953.       cmp si,dx ;åñëè êóðñîð âíèçó è åãî âîîáùå íå âèäíî
  954.       jl .end_f
  955.  
  956.       sub si,dx
  957.       cmp si,tl_img_cy
  958.       jge .crop1
  959.         mov cx,si ;åñëè êóðñîð âèäåí ÷àñòè÷íî (ïîïàë íà íèæíþþ ãðàíèöó)
  960.       .crop1:
  961.  
  962.       mov eax,7
  963.       int 0x40 ;ðèñóåì èêîíêó êóðñîðà
  964.     .end_f:
  965.   pop esi edx ecx ebx eax
  966.   ret
  967.  
  968. ;input:
  969. ; edi = pointer to TreeInfo struct
  970. ; esi = coord bottom border
  971. align 4
  972. tl_draw_null_cursor: ;ñòèðàåì êóðñîð íà ýêðàíå
  973.   push eax ebx ecx edx esi
  974.     call tl_get_display_cur_pos ;eax = cursor pos in screen
  975.     cmp eax,0
  976.     jl .end_f ;êóðñîð íàõîäèòñÿ âûøå îêíà, â îáëàñòè ïðîêðó÷åííîé ñêðîëëèíãîì
  977.  
  978.     mov ebx,tl_box_left
  979.     shl ebx,16
  980.     mov bx,tl_img_cx
  981.     xor ecx,ecx
  982.     mov cx,tl_img_cy
  983.     imul ecx,eax
  984.     add ecx,tl_box_top
  985.     add cx,tl_capt_cy
  986.  
  987.     ;crop image if on the border
  988.     cmp esi,ecx ;åñëè êóðñîð âíèçó è åãî âîîáùå íå âèäíî
  989.     jl .end_f
  990.  
  991.     sub esi,ecx
  992.     shl ecx,16
  993.     mov cx,tl_img_cy
  994.     cmp si,tl_img_cy
  995.     jge @f
  996.       mov cx,si ;åñëè êóðñîð âèäåí ÷àñòè÷íî (ïîïàë íà íèæíþþ ãðàíèöó)
  997.     @@:
  998.  
  999.     mov edx,tl_col_bkg
  1000.     mov eax,13
  1001.     int 0x40 ;ðèñóåì ïðîñòîé ïðÿìîóãîëüíèê ñ ôîíîâûì öâåòîì
  1002.  
  1003.     .end_f:
  1004.   pop esi edx ecx ebx eax
  1005.   ret
  1006.  
  1007. ;input:
  1008. ; edi = pointer to TreeInfo struct
  1009. ;output:
  1010. ; eax = index
  1011. align 4
  1012. tl_get_display_cur_pos: ;áåðåò ïîçèöèþ êóðñîðà, îòíîñèòåëüíî ýêðàíà
  1013.    mov eax,tl_cur_pos
  1014.    cmp tl_p_scrol,0
  1015.    je @f
  1016.      push ebx
  1017.        mov ebx,tl_p_scrol
  1018.        mov ebx,dword[ebx+24]
  1019.        sub eax,ebx ;îòíèìàåì ïîçèöèþ ñêðîëëèíãà
  1020.      pop ebx
  1021.   @@:
  1022.   ret
  1023.  
  1024. ;input:
  1025. ; eax = node position
  1026. ; edx = pointer to some node struct
  1027. ; edi = pointer to 'TreeList' struct
  1028. ; esi = coord of bottom border
  1029. align 4
  1030. tl_draw_node: ;ðèñóåò óçåë ñ: êàðòèíêîé, ïîäïèñüþ, èêîíêîé îòêðûòèÿ/çàêðûòèÿ è ëèíèÿìè ê ðîäèò. óçëó
  1031.   push eax ebx ecx edx esi
  1032.  
  1033.     mov ebx,1 ;1 - ìåñòî ïîä êóðñîð è ïîä çíàê +,-
  1034.     bt tl_style,2 ;tl_list_box_mode
  1035.     jc @f
  1036.       inc ebx ;+1 - ìåñòî ïîä çíàê +,-
  1037.     @@:
  1038.     add bl,byte[edx+2];get level
  1039.     imul bx,tl_img_cx
  1040.     add ebx,tl_box_left
  1041.  
  1042.     shl ebx,16
  1043.     mov bx,tl_img_cx
  1044.     xor ecx,ecx
  1045.     mov cx,tl_img_cy
  1046.     imul ecx,eax
  1047.     add ecx,tl_box_top
  1048.     add cx,tl_capt_cy
  1049.  
  1050.     ;crop image if on the border
  1051.     cmp esi,ecx ;åñëè óçåë âíèçó è åãî âîîáùå íå âèäíî
  1052.     jl .end_draw
  1053.  
  1054.     sub esi,ecx
  1055.     shl ecx,16
  1056.     mov cx,tl_img_cy
  1057.     cmp si,tl_img_cy
  1058.     jge @f
  1059.       mov cx,si ;åñëè óçåë âèäåí ÷àñòè÷íî (ïîïàë íà íèæíþþ ãðàíèöó)
  1060.       jmp .crop ;ïðîïóñêàåì ðèñîâàíèå íàäïèñè, êîòîðàÿ ñêîðåå âñåãî òîæå âûëåçåò çà íèæíþþ ãðàíèöó
  1061.     @@:
  1062.       call tl_draw_node_caption
  1063.     .crop:
  1064.     mov esi,ecx ;save ecx
  1065.  
  1066.     cmp tl_data_img,0
  1067.     jne .draw_img_n
  1068.     push edx
  1069.       mov edx,tl_col_txt
  1070.       mov eax,13
  1071.       int 0x40 ;draw node rect
  1072.     pop edx
  1073.     jmp @f
  1074.     .draw_img_n:
  1075.     push ebx edx esi
  1076.       xor esi,esi
  1077.       mov si,word[edx] ;get icon type
  1078.       mov edx,ebx
  1079.       ror ecx,16
  1080.       mov dx,cx
  1081.       mov cx,bx
  1082.       ror ecx,16
  1083.       mov ebx,3 ;rgb = 3 bytes
  1084.       imul bx,tl_img_cx
  1085.       imul bx,tl_img_cy
  1086.       imul ebx,esi ;esi = icon index
  1087.       add ebx,tl_data_img
  1088.  
  1089.       mov eax,7
  1090.       int 0x40 ;draw node icon '-'
  1091.     pop esi edx ebx
  1092.     @@:
  1093.  
  1094.     mov al,byte[edx+2] ;draw minus '-'
  1095.     mov ecx,tl_data_nodes
  1096.     add ecx,sizeof.TreeList
  1097.  
  1098.     mov ah,10 ;get icon index '+' or '-' ?
  1099.     cmp byte[edx+3],1
  1100.     jne .close
  1101.       dec ah
  1102.     .close:
  1103.  
  1104.     call tl_draw_node_icon_opn_clo ;ðèñîâàíèå èêîíêè îòêðûòîãî èëè çàêðûòîãî óçëà
  1105.     bt tl_style,1
  1106.     jae .end_draw
  1107.       call tl_draw_node_icon_par_lin ;ðèñîâàíèå ëèíèè ê ðîäèòåëüñêîìó ýëåìåíòó
  1108.       call tl_draw_node_icon_par_lin_up ;ðèñîâàíèå âåðòèêàëüíîé ëèíèè ê ðîäèòåëüñêîìó ýëåìåíòó
  1109.     .end_draw:
  1110.   pop esi edx ecx ebx eax
  1111.   ret
  1112.  
  1113. ;input:
  1114. ; ecx = pointer to 1 node struct
  1115. ; edx = pointer to some node struct
  1116. ;...
  1117. align 4
  1118. tl_draw_node_icon_opn_clo: ;ðèñóåò èêîíêè îòêðûòîãî èëè çàêðûòîãî óçëà (îáû÷íî + èëè -)
  1119.   push eax ebx ecx edx esi
  1120.     inc al
  1121.     call tl_iterat_next_all ;get next visible item
  1122.     cmp edx,ecx
  1123.     jle @f
  1124.       mov ecx,esi ;load ecx
  1125.       cmp al,byte[edx+2]
  1126.       jne @f
  1127.       ror ebx,16
  1128.       sub bx,tl_img_cx
  1129.       ror ebx,16
  1130.       cmp tl_data_img_sys,0
  1131.       jne .draw_img_s
  1132.         mov edx,tl_col_txt
  1133.         mov eax,13
  1134.         int 0x40 ;draw minus rect, if not system icons
  1135.         jmp @f
  1136.       .draw_img_s:
  1137.       mov ecx,esi ;load ecx
  1138.       mov edx,ebx
  1139.       ror ecx,16
  1140.       mov dx,cx
  1141.       mov cx,bx
  1142.       ror ecx,16
  1143.       mov ebx,3 ;rgb = 3 bytes
  1144.       imul bx,tl_img_cx
  1145.       imul bx,tl_img_cy
  1146.       shr eax,8
  1147.       and eax,0xff
  1148.       imul ebx,eax ;eax = icon index
  1149.       add ebx,tl_data_img_sys
  1150.       mov eax,7
  1151.       int 0x40 ;draw minus icon '-'
  1152.     @@:
  1153.   pop esi edx ecx ebx eax
  1154.   ret
  1155.  
  1156. ;input:
  1157. ; al = óðîâåíü ýëåìåíòà
  1158. ; ecx = pointer to 1 node struct
  1159. ; edx = pointer to some node struct
  1160. ;...
  1161. align 4
  1162. tl_draw_node_icon_par_lin: ;ðèñîâàíèå ëèíèè ê ðîäèòåëüñêîìó ýëåìåíòó
  1163.   cmp byte[edx+3],1
  1164.   je .close
  1165.   push eax ebx ecx edx esi
  1166.     cmp al,0
  1167.     je @f
  1168. ;    dec al
  1169. ;    call tl_iterat_perv ;get perv visible item
  1170.  
  1171.     call tl_iterat_next_all ;get next visible item
  1172.     cmp edx,ecx
  1173.     jle .line3 ;if end of list
  1174.       cmp al,byte[edx+2]
  1175.       jne .line3 ;jg ???
  1176.       mov eax,3 ;line in middle element
  1177.       jmp .line2
  1178.     .line3:
  1179.       mov eax,6 ;line in end element
  1180.     .line2:
  1181.  
  1182.       mov ecx,esi ;load ecx
  1183.       ror ebx,16
  1184.       sub bx,tl_img_cx
  1185.       ror ebx,16
  1186.       cmp tl_data_img_sys,0
  1187.       jne .draw_img_s
  1188.         mov edx,tl_col_txt
  1189.         mov eax,13
  1190.         int 0x40 ;draw minus rect, if not system icons
  1191.         jmp @f
  1192.       .draw_img_s:
  1193. ;      mov ecx,esi ;load ecx
  1194.       mov edx,ebx
  1195.       ror ecx,16
  1196.       mov dx,cx
  1197.       mov cx,bx
  1198.       ror ecx,16
  1199.       mov ebx,3 ;rgb = 3 bytes
  1200.       imul bx,tl_img_cx
  1201.       imul bx,tl_img_cy
  1202.  
  1203. ;      shr eax,8
  1204. ;      and eax,0xff
  1205.       imul ebx,eax ;eax = icon index
  1206.       add ebx,tl_data_img_sys
  1207.       mov eax,7
  1208.       int 0x40 ;draw line icon
  1209.     @@:
  1210.   pop esi edx ecx ebx eax
  1211.   .close:
  1212.   ret
  1213.  
  1214.  
  1215. ;input:
  1216. ; al = óðîâåíü ýëåìåíòà
  1217. ; ecx = pointer to 1 node struct
  1218. ; edx = pointer to some node struct
  1219. ; edi = pointer to 'TreeList' struct
  1220. align 4
  1221. tl_draw_node_icon_par_lin_up:
  1222.   push eax ebx ecx edx
  1223.   push esi
  1224.     cmp tl_data_img_sys,0 ;if not image
  1225.     je @f
  1226.     cmp al,0
  1227.     je @f
  1228.  
  1229.     xor esi,esi ;â si áóäåì íàñ÷èòûâàòü êîë-âî èêîíîê, íóæíûõ äëÿ ïðîðèñîâêè ëèíèè
  1230. ;--- öèêë äëÿ âû÷èñëåíèÿ êîëëè÷åñòâà âåðòèêàëüíûõ ëèíèé ---
  1231.     .cycle0:
  1232.       call tl_iterat_perv ;get perv visible item
  1233.       cmp edx,ecx
  1234.       jle .cycle1 ;if begin of list
  1235.  
  1236.       cmp byte[edx+2],al
  1237.       jle .cycle0end ;óðîâåíü âåðõíåãî ýëåìåíòà íå òðåáóåò ïðîðèñîâêè
  1238.       inc si
  1239.       jmp .cycle0
  1240.     .cycle0end:
  1241.       cmp si,0 ;si = êîë-âî èêîíîê ëèíèè êîòîðûå íóæíî íàðèñîâàòü ñâåðõó
  1242.       je @f
  1243.       shl esi,16
  1244.  
  1245.       pop ecx ;esi->ecx
  1246.       push ecx ;save esi
  1247.  
  1248.       ror ebx,16
  1249.       sub bx,tl_img_cx
  1250.       ror ebx,16
  1251.  
  1252.       mov edx,ebx
  1253.       ror ecx,16
  1254.       mov dx,cx
  1255.       mov cx,bx
  1256.       ror ecx,16
  1257.       mov cx,tl_img_cy ;restore size y (if crop)
  1258.       mov ebx,3 ;rgb = 3 bytes
  1259.       imul bx,tl_img_cx
  1260.       imul bx,tl_img_cy
  1261.       add ebx,tl_data_img_sys
  1262.  
  1263.       add esi,tl_box_top
  1264.       add si,tl_capt_cy ;si = âåðõíÿÿ ãðàíèöà îêíà
  1265.       mov eax,7
  1266. ;--- öèêë äëÿ ðèñîâàíèÿ âåðòèêàëüíîé ëèíèè ---
  1267.       .cycle1:
  1268.       sub dx,tl_img_cy ;ïîäíèìàåì êîîðäèíàòó y ââåðõ
  1269.       cmp dx,si
  1270.       jl @f
  1271.         cmp esi,0x10000
  1272.         jl @f
  1273.         int 0x40 ;draw line icon
  1274.         sub esi,0x10000 ;óìåíüøàåì ñ÷åò÷èê èêîíîê
  1275.       jmp .cycle1
  1276.     @@:
  1277.   pop esi
  1278.   pop edx ecx ebx eax
  1279.   ret
  1280.  
  1281. ;input:
  1282. ; edi = pointer to TreeInfo struct
  1283. ;output:
  1284. ; eax = rows
  1285. align 4
  1286. tl_get_rows_count:
  1287.   push ecx edx
  1288.     mov eax,tl_box_height
  1289.     sub ax,tl_capt_cy
  1290.     xor ecx,ecx
  1291.     mov cx,tl_img_cy
  1292.     xor edx,edx
  1293.     div ecx
  1294.   pop edx ecx
  1295.   ret
  1296.  
  1297. ;input:
  1298. ; eax = node position
  1299. ; ebx = [êîîðäèíàòà ïî îñè x]*65536 + [img_cx]
  1300. ; ecx = [êîîðäèíàòà ïî îñè y]*65536 + [img_cy]
  1301. ; edx = pointer to some node struct
  1302. ; edi = pointer to TreeInfo struct
  1303. align 4
  1304. tl_draw_node_caption:
  1305.     push ebx ecx edx esi
  1306.  
  1307.     xor esi,esi
  1308.     mov si,tl_info_size
  1309.     cmp si,tl_info_capt_offs
  1310.     jle @f ;if caption size <= 0
  1311.  
  1312.     push eax
  1313.       call tl_get_node_index ;eax = node index
  1314.       imul esi,eax
  1315.     pop eax
  1316.       add si,tl_info_capt_offs
  1317.       add esi,dword[edi]
  1318.       mov edx,esi
  1319.  
  1320.       shr ebx,16
  1321.       add bx,tl_img_cx ;ñäâèãàåì íàäïèñü ïî ãîðèçîíòàëè --->
  1322.       add bx,3 ;îòñòóï
  1323.       ;bx = coord. x
  1324.       call tl_strlen ;eax = strlen
  1325.       call tl_get_draw_text_len
  1326.       mov cx,bx
  1327.       ror ecx,16
  1328.       mov ebx,ecx
  1329.       add bx,tl_img_cy ;âûðàâíèâèíèå ïî íèæíåé ãðàíèöå èêîíêè
  1330.       sub bx,9 ;îòíèìàåì âûñîòó òåêñòà
  1331.       mov ecx,tl_col_txt
  1332.       and ecx,0xffffff
  1333. ;      or ecx,0x80000000 ;text is ASCIIZ
  1334.       mov eax,4
  1335.       int 0x40
  1336.     @@:
  1337.     pop esi edx ecx ebx
  1338.   ret
  1339.  
  1340. ;input:
  1341. ; eax = strlen
  1342. ; ebx = text coord x
  1343. ;output:
  1344. ; esi = text len
  1345. align 4
  1346. tl_get_draw_text_len:
  1347.   push eax ecx edx
  1348.     mov esi,eax ;áåðåì äëèííó ñòðîêè
  1349.  
  1350.     mov eax,tl_box_left
  1351.     add eax,tl_box_width
  1352.     cmp eax,ebx
  1353.     jle .text_null ;åñëè ïîäïèñü ïîëíîñòüþ âñÿ çà ýêðàíîì
  1354.     sub eax,ebx
  1355.     xor edx,edx
  1356.     mov ecx,6 ;øèðèíà ñèñòåìíîãî øðèôòà
  1357.     div ecx ;ñìîòðèì ñêîëüêî ñèìâîëîâ ìîæåò ïîìåñòèòüñÿ íà ýêðàíå
  1358.  
  1359.     cmp esi,eax
  1360.     jl @f
  1361.       mov esi,eax ;åñëè äëèííà òåêñòà ìåíüøå, ÷åì âñå ìåñòî ïîä ñòðîêó
  1362.     jmp @f
  1363.     .text_null:
  1364.       xor esi,esi
  1365.     @@:
  1366.   pop edx ecx eax
  1367.   ret
  1368.  
  1369. ;input:
  1370. ; esi = pointer to string
  1371. ;output:
  1372. ; eax = strlen
  1373. align 4
  1374. tl_strlen:
  1375.   mov eax,esi
  1376.   @@:
  1377.     cmp byte[eax],0
  1378.     je @f
  1379.     inc eax
  1380.     loop @b
  1381.   @@:
  1382.   sub eax,esi
  1383.   ret
  1384.  
  1385. ;input:
  1386. ;dword[ebp+ 8] - pointer to node info
  1387. ;dword[ebp+12] - options
  1388. ;dword[ebp+16] - pointer to 'TreeList' struct
  1389. align 4
  1390. tl_node_add: ;äîáàâèòü óçåë
  1391.   push ebp
  1392.   mov ebp,esp
  1393.   push eax ebx ecx edx edi
  1394.     mov edi,dword[ebp+16]
  1395.  
  1396.     call tl_info_set_undo
  1397.  
  1398.     mov ebx,sizeof.TreeList
  1399.     imul ebx,dword[edi+6] ;+6 ìàêñ. êîëè÷åñòâî óçëîâ
  1400.     add ebx,tl_data_nodes
  1401. ;--
  1402.     call tl_get_cur_node_index ;eax=po_t
  1403.     imul eax,sizeof.TreeList
  1404.     add eax,tl_data_nodes
  1405.     mov edx,eax
  1406.     call tl_move_perv
  1407.     call tl_get_node_index ;eax = index of pointer [edx]
  1408. ;--
  1409.     mov edx,sizeof.TreeList
  1410.     shl edx,1
  1411.     add edx,tl_data_nodes
  1412.     @@: ;for(i=2;i<nodeMax;i++)
  1413.       cmp dword [edx+12],0
  1414.       jne .u0
  1415.       cmp dword [edx+16],0
  1416.       jne .u0
  1417.  
  1418.         inc  tl_ch_tim
  1419.         mov cx,word[ebp+14] ;get type
  1420.         mov word[edx],cx
  1421.  mov cl,byte[ebp+13]
  1422.  mov byte[edx+3],cl  ;node[i].clo
  1423.         mov   byte[edx+2], 0 ;node[i].lev=0
  1424.   bt tl_style,2 ;tl_list_box_mode
  1425.   jc .l_box_m
  1426.     mov cl,byte[ebp+12]
  1427.     mov byte[edx+2],cl  ;node[i].lev
  1428.   .l_box_m:
  1429.         push tl_ch_tim       ;node[i].tc=ch_tim;
  1430.         pop  dword[edx+12]
  1431.         mov  dword[edx+4], eax ;node[i].perv=po_t;
  1432.         ;*** copy node data ***
  1433.         push esi
  1434.         xor ecx,ecx
  1435.         mov cx,tl_info_size
  1436.         mov esi,ecx
  1437.  
  1438.         push eax
  1439.           call tl_get_node_index ;eax = node index
  1440.           imul esi,eax
  1441.         pop eax
  1442.         add esi,dword[edi]
  1443.         mov edi,dword[ebp+8] ;pointer to node data
  1444.         xchg edi,esi
  1445.         rep movsb
  1446.  
  1447.         mov esi,edi
  1448.         mov edi,dword[ebp+16] ;restore edi
  1449.         mov cx,tl_info_capt_offs
  1450.         cmp cx,tl_info_size
  1451.         jge .no_text_data
  1452.  cmp tl_info_capt_len,0 ;ïðîâåðÿåì åñòü ëè îãðàíè÷åíèå íà äëèííó ñòðîêè
  1453.  je .no_len_ogran
  1454.    add cx,tl_info_capt_len
  1455.    and ecx,0xffff
  1456.    add esi,ecx
  1457.    mov cx,tl_info_size
  1458.    sub esi,ecx
  1459.  .no_len_ogran:
  1460.           dec esi
  1461.           mov byte[esi],0
  1462.         .no_text_data:
  1463.         pop esi ;restore esi
  1464.  
  1465.         mov ecx,eax
  1466.         imul ecx,sizeof.TreeList
  1467.         add ecx,tl_data_nodes ; *** ecx = node[po_t] ***
  1468.         add ecx,8   ; *** ecx = node[po_t].next ***
  1469.         push dword [ecx] ;node[i].next=node[po_t].next;
  1470.         pop dword [edx+8]
  1471.  
  1472.         call tl_get_node_index ;*** eax = i ***
  1473.         cmp eax,tl_info_max_count
  1474.         jge .u0
  1475.  
  1476.         mov [ecx],eax ;node[po_t].next=i; // ññûëêè ïåðåíàïðàâëÿåì
  1477.         mov ecx,[edx+8] ; *** ecx = node[i].next ***
  1478.         imul ecx,sizeof.TreeList
  1479.         add ecx,tl_data_nodes ; *** ecx = node[node[i].next] ***
  1480.         mov [ecx+4],eax ;node[node[i].next].perv=i;
  1481.  
  1482.         call tb_scrol_resize ;îáðàáîòêà ñêðîëëèíãà
  1483.     jmp @f
  1484.       .u0:
  1485.       add edx,sizeof.TreeList
  1486.       cmp edx,ebx ;enf of node memory ?
  1487.       jle @b
  1488.     @@:
  1489.   pop edi edx ecx ebx eax
  1490.   pop ebp
  1491.   ret 12
  1492.  
  1493. ;input:
  1494. ; edi = pointer to TreeInfo struct
  1495. align 4
  1496. tb_scrol_resize:
  1497.   push eax ecx edx
  1498.   cmp tl_p_scrol,0 ;îáðàáîòêà ñêðîëëèíãà
  1499.   je @f
  1500.     call tl_get_node_count ;eax = node count
  1501.     mov ecx,eax
  1502.     call tl_get_rows_count
  1503.     cmp ecx,eax
  1504.     jg .ye_sb
  1505.       xor ecx,ecx
  1506.     .ye_sb:
  1507.  
  1508.     mov edx,tl_p_scrol
  1509.     mov dword[edx+20],eax ;+20 .cur_area
  1510.     mov dword[edx+16],ecx ;+16 .max_area
  1511.     push dword edx ;pointer to scroll struct
  1512.     call scroll_bar_vertical.draw
  1513.   @@:
  1514.   pop edx ecx eax
  1515. ret
  1516.  
  1517. ;input:
  1518. ;dword[ebp+ 8] - pointer to node info
  1519. ;dword[ebp+12] - pointer to 'TreeList' struct
  1520. align 4
  1521. tl_node_set_data:
  1522.   push ebp
  1523.   mov ebp,esp
  1524.   push eax ecx edx edi esi
  1525.     mov edi,dword[ebp+12]
  1526.     call tl_get_cur_node_index ;eax=po_t
  1527.     cmp eax,2
  1528.     jl @f
  1529.       xor ecx,ecx
  1530.       mov cx,tl_info_size
  1531.       imul eax,ecx
  1532.       add eax,dword[edi]
  1533.       mov edi,eax
  1534.       mov esi,dword[ebp+8] ;pointer to node data
  1535.       rep movsb
  1536.  
  1537.       mov esi,edi
  1538.       mov edi,dword[ebp+12] ;restore edi
  1539.       mov cx,tl_info_capt_offs
  1540.       cmp cx,tl_info_size
  1541.       jge .no_text_data
  1542.         mov ax,tl_info_capt_len ;ïðîâåðÿåì åñòü ëè îãðàíè÷åíèå íà äëèííó òåêñòà
  1543.         cmp ax,0
  1544.         je .no_limit
  1545.         add cx,ax ;cx = tl_info_capt_offs + tl_info_capt_len
  1546.         and ecx,0xffff
  1547.         xor eax,eax
  1548.         mov ax,tl_info_size
  1549.         cmp eax,ecx
  1550.         jl .no_limit ;ïîëüçîâàòåëü çàäàë ñëèøêîì áîëüøóþ äëèííó òåêñòà
  1551.         add esi,ecx
  1552.         sub esi,eax
  1553.         .no_limit:
  1554.           dec esi
  1555.           mov byte[esi],0 ;îáíóëÿåì ïîñëåäíèé ñèìâîë ïîäïèñè, ÷òî-áû íå ãëþ÷èëî åñëè ïîëüçîâàòåëü çàäàë íåïðàâèëüíóþ ñòðóêòóðó
  1556.       .no_text_data:
  1557.  
  1558.     @@:
  1559.   pop esi edi edx ecx eax
  1560.   pop ebp
  1561.   ret 8
  1562.  
  1563. ;input:
  1564. ;dword[ebp+ 8] - pointer to 'TreeList' struct
  1565. align 4
  1566. tl_node_get_data: ;âçÿòü óêàçàòåëü íà äàííûå óçëà ïîä êóðñîðîì
  1567.   push ebp
  1568.   mov ebp,esp
  1569.   push eax ecx edi
  1570.     mov edi,dword[ebp+8]
  1571.     call tl_get_cur_node_index ;eax=po_t
  1572.     mov dword[ebp+8],0 ;if return 0 pointer
  1573.     cmp eax,2
  1574.     jl @f
  1575.       xor ecx,ecx
  1576.       mov cx,tl_info_size
  1577.       imul eax,ecx
  1578.       add eax,dword[edi]
  1579.       mov dword[ebp+8],eax ;return node data pointer
  1580.     @@:
  1581.   pop edi ecx eax
  1582.   pop ebp
  1583.   ret
  1584.  
  1585. ;input:
  1586. ;dword[ebp+ 8] - node index
  1587. ;dword[ebp+12] - pointer to 'TreeList' struct
  1588. align 4
  1589. tl_node_poi_get_info: ;âçÿòü óêàçàòåëü íà ñòðóêòóðó óçëà â óêàçàííîé ïîçèöèè
  1590.   push ebp
  1591.   mov ebp,esp
  1592.   push eax ecx edx edi
  1593.     mov edi,dword[ebp+12]
  1594.     mov eax,dword[ebp+8]
  1595.  
  1596.     ;cycle to nodes
  1597.     mov edx,tl_data_nodes
  1598.     mov ecx,edx
  1599.     add ecx,sizeof.TreeList
  1600.     @@:
  1601.       call tl_iterat_next_all
  1602.       cmp edx,ecx
  1603.       jle @f
  1604.       dec eax
  1605.       cmp eax,0
  1606.       jg @b
  1607.       jmp .find
  1608.     @@:
  1609.       xor edx,edx
  1610.     .find:
  1611.     mov dword[ebp+12],edx
  1612.   pop edi edx ecx eax
  1613.   pop ebp
  1614.   ret 4
  1615.  
  1616. ;input:
  1617. ;dword[ebp+ 8] - node param struct
  1618. ;dword[ebp+12] - pointer to 'TreeList' struct
  1619. align 4
  1620. tl_node_poi_get_next_info: ;âçÿòü óêàçàòåëü íà ñëåäóùóþ ñòðóêòóðó óçëà
  1621.   push ebp
  1622.   mov ebp,esp
  1623.   push ecx edx edi
  1624.     mov edi,dword[ebp+12]
  1625.     mov edx,dword[ebp+8]
  1626.  
  1627.     mov ecx,tl_data_nodes
  1628.     add ecx,sizeof.TreeList
  1629.  
  1630.     call tl_iterat_next_all
  1631.     cmp edx,ecx
  1632.     jg @f
  1633.       xor edx,edx
  1634.     @@:
  1635.  
  1636.     mov dword[ebp+12],edx
  1637.   pop edi edx ecx
  1638.   pop ebp
  1639.   ret 4
  1640.  
  1641. ;input:
  1642. ;dword[ebp+ 8] - node param struct
  1643. ;dword[ebp+12] - pointer to 'TreeList' struct
  1644. align 4
  1645. tl_node_poi_get_data: ;âçÿòü óêàçàòåëü íà äàííûå óçëà
  1646.   push ebp
  1647.   mov ebp,esp
  1648.   push eax ecx edi
  1649.     mov edi,dword[ebp+12]
  1650.     mov edx,dword[ebp+8]
  1651.  
  1652.     mov dword[ebp+12],0
  1653.     call tl_get_node_index ;eax = node index
  1654.     cmp eax,2
  1655.     jl @f
  1656.       xor ecx,ecx
  1657.       mov cx,tl_info_size
  1658.       imul eax,ecx
  1659.       add eax,dword[edi]
  1660.       mov dword[ebp+12],eax ;return node data pointer
  1661.     @@:
  1662.   pop edi ecx eax
  1663.   pop ebp
  1664.   ret 4
  1665.  
  1666. ;input:
  1667. ; edi = pointer 'tl' struct
  1668. ;output:
  1669. ; eax = index of current node
  1670. align 4
  1671. tl_get_cur_node_index: ;áåðåò ïîçèöèþ ïîä êóðñîðîì
  1672.   push ecx edx
  1673.     ;cycle to nodes
  1674.     xor eax,eax
  1675.     mov edx,tl_data_nodes
  1676.     mov ecx,edx
  1677.     add ecx,sizeof.TreeList
  1678.     @@:
  1679.       call tl_iterat_next
  1680.       cmp edx,ecx
  1681.       jle @f
  1682.       cmp eax,tl_cur_pos
  1683.       je @f
  1684.       inc eax
  1685.       jmp @b
  1686.     @@:
  1687.   mov eax,edx
  1688.   sub eax,tl_data_nodes
  1689.   xor edx,edx
  1690.   mov ecx,sizeof.TreeList
  1691.   div ecx
  1692.   pop edx ecx
  1693.   ret
  1694.  
  1695. ;input:
  1696. ; edx = pointer node memory
  1697. ; edi = pointer 'tl' struct
  1698. ;output:
  1699. ; eax = struct index of current node
  1700. align 4
  1701. tl_get_node_index: ;áåðåò ïîçèöèþ óêàçàííîãî ñèìâîëà
  1702.   push ecx edx
  1703.   mov eax,edx
  1704.   sub eax,tl_data_nodes
  1705.   xor edx,edx
  1706.   mov ecx,sizeof.TreeList
  1707.   div ecx
  1708.   pop edx ecx
  1709.   ret
  1710.  
  1711. align 4
  1712. tl_node_delete: ;óäàëèòü óçåë
  1713.   push ebp
  1714.   mov ebp,esp
  1715.   push eax edx edi
  1716.     mov edi,dword[ebp+8]
  1717.     call tl_get_cur_node_index ;eax=po_t
  1718.     cmp eax,2
  1719.     jl @f
  1720.       imul eax,sizeof.TreeList
  1721.       add eax,tl_data_nodes
  1722.       mov edx,eax
  1723.       inc tl_ch_tim
  1724.       mov eax,tl_ch_tim
  1725.       mov dword[edx+16],eax
  1726.       call tb_scrol_resize ;îáðàáîòêà ñêðîëëèíãà
  1727.     @@:
  1728.   pop edi edx eax
  1729.   pop ebp
  1730.   ret 4
  1731.  
  1732. align 4
  1733. tl_cur_beg: ;ïîñòàâèòü êóðñîð íà ïåðâûé óçåë
  1734.   push ebp
  1735.   mov ebp,esp
  1736.   push edi
  1737.     mov edi,dword[ebp+8]
  1738.     mov tl_cur_pos,0
  1739.     cmp tl_p_scrol,0
  1740.     je @f
  1741.       mov edi,tl_p_scrol
  1742.       mov dword[edi+24],0
  1743.       push dword edi
  1744.       mov edi,dword[ebp+8]
  1745.       call scroll_bar_vertical.draw
  1746.     @@:
  1747.   pop edi
  1748.  
  1749.   pop ebp
  1750.   ret 4
  1751.  
  1752. align 4
  1753. tl_cur_next: ;ïåðåíåñòè êóðñîð íà 1 ïîçèöèþ íèæå
  1754.   push ebp
  1755.   mov ebp,esp
  1756.   push eax ebx edi esi
  1757.     mov edi,dword[ebp+8]
  1758.     call tl_get_node_count ;eax = node count
  1759.     ;inc eax
  1760.     cmp tl_cur_pos,eax
  1761.     jge .no_redraw
  1762.       mov esi,tl_box_top
  1763.       add esi,tl_box_height ;esi = coord bottom border
  1764.       call tl_draw_null_cursor ;ñòèðàåì êóðñîð
  1765.       inc tl_cur_pos
  1766.  
  1767.     cmp tl_p_scrol,0 ;if not scrol struct
  1768.     je @f
  1769.     call tl_get_rows_count ;eax = rows count
  1770.     mov ebx,tl_p_scrol
  1771.     add eax,dword[ebx+24] ;.position +24
  1772.     cmp tl_cur_pos,eax
  1773.     jl @f
  1774.       inc dword[ebx+24] ;.position +24
  1775.       push dword ebx
  1776.       call scroll_bar_vertical.draw
  1777.  
  1778.       mov edi,dword[ebp+8] ;restore edi
  1779.       push dword edi
  1780.       call tl_draw ;ïîëíàÿ ïåðåðèñîâêà îêíà
  1781.       jmp .no_redraw
  1782.     @@:
  1783.       mov edi,dword[ebp+8] ;restore edi
  1784.       call tl_draw_cursor ;ïåðåðèñîâêà êóðñîðà
  1785.       call tl_draw_caption_cur_pos
  1786.     .no_redraw:
  1787.   pop esi edi ebx eax
  1788.   pop ebp
  1789.   ret 4
  1790.  
  1791.  
  1792. ;input:
  1793. ; edi = pointer 'tl' struct
  1794. ;output:
  1795. ; eax = struct index of current node
  1796. align 4
  1797. tl_get_node_count: ;áåðåò ÷èñëî âñåõ âèäèìûõ óçëîâ (íå ñ÷èòàÿ çàêðûòûõ äî÷åðíèõ)
  1798.   push ecx edx
  1799.     ;cycle to nodes
  1800.     xor eax,eax
  1801.     mov edx,tl_data_nodes
  1802.     mov ecx,edx
  1803.     add ecx,sizeof.TreeList
  1804.     @@:
  1805.       call tl_iterat_next
  1806.       cmp edx,ecx
  1807.       jle @f
  1808.       inc eax
  1809.       jmp @b
  1810.     @@:
  1811.   pop edx ecx
  1812.   ret
  1813.  
  1814. ;input:
  1815. ; edi = pointer 'tl' struct
  1816. ;output:
  1817. ; eax = struct index of current node
  1818. align 4
  1819. tl_get_node_count_all: ;áåðåò ÷èñëî âñåõ âèäèìûõ óçëîâ (ñ÷èòàÿ çàêðûòûå äî÷åðíèå)
  1820.   push ecx edx
  1821.     ;cycle to nodes
  1822.     xor eax,eax
  1823.     mov edx,tl_data_nodes
  1824.     mov ecx,edx
  1825.     add ecx,sizeof.TreeList
  1826.     @@:
  1827.       call tl_iterat_next_all
  1828.       cmp edx,ecx
  1829.       jle @f
  1830.       inc eax
  1831.       jmp @b
  1832.     @@:
  1833.   pop edx ecx
  1834.   ret
  1835.  
  1836. align 4
  1837. tl_cur_perv: ;ïåðåíåñòè êóðñîð íà 1 ïîçèöèþ âûøå
  1838.   push ebp
  1839.   mov ebp,esp
  1840.   push eax edi esi
  1841.     mov edi,dword[ebp+8]
  1842.     cmp tl_cur_pos,0
  1843.     je .no_redraw
  1844.       mov esi,tl_box_top
  1845.       add esi,tl_box_height ;esi = coord bottom border
  1846.       call tl_draw_null_cursor ;ñòèðàåì êóðñîð
  1847.       dec tl_cur_pos ;äâèãàåì êóðñîð ââåðõ
  1848.  
  1849.     cmp tl_p_scrol,0 ;åñëè åñòü óêàçàòåëü íà ñêðîëëèíã
  1850.     je @f
  1851.     mov eax,tl_p_scrol
  1852.     cmp dword[eax+24],0 ;åñëè ñêðîëëèíã íà âåðõó, âûõîäèì
  1853.     je @f
  1854.     mov edi,tl_cur_pos
  1855.     cmp edi,dword[eax+24] ;åñëè êóðñîð óøåë âûøå ñêðîëëèíãà, òîãäà îïóñêàåì ñêðîëëèíã
  1856.     jge @f
  1857.       dec dword[eax+24]
  1858.       push dword eax
  1859.       mov edi,dword[ebp+8]
  1860.       call scroll_bar_vertical.draw
  1861.       mov edi,dword[ebp+8] ;restore edi
  1862.       push dword edi
  1863.       call tl_draw ;ïîëíàÿ ïåðåðèñîâêà îêíà
  1864.       jmp .no_redraw
  1865.     @@:
  1866.       mov edi,dword[ebp+8] ;restore edi
  1867.       ;mov esi,tl_box_top
  1868.       ;add esi,tl_box_height ;esi = coord bottom border
  1869.       call tl_draw_cursor ;ïåðåðèñîâêà êóðñîðà
  1870.       call tl_draw_caption_cur_pos
  1871.     .no_redraw:
  1872.   pop esi edi eax
  1873.   pop ebp
  1874.   ret 4
  1875.  
  1876. align 4
  1877. tl_cur_page_up: ;ïåðåíåñòè êóðñîð íà 1 ñòðàíèöó âûøå
  1878.   push ebp
  1879.   mov ebp,esp
  1880.   push eax edi esi
  1881.     mov edi,dword[ebp+8]
  1882.  
  1883.     cmp tl_p_scrol,0 ;åñëè åñòü óêàçàòåëü íà ñêðîëëèíã
  1884.     je .no_redraw
  1885.  
  1886.     mov esi,tl_p_scrol
  1887.     call tl_get_rows_count ;eax = rows count
  1888.  
  1889.     cmp tl_cur_pos,0
  1890.     jne @f
  1891.     cmp dword[esi+24],0 ;åñëè ñêðîëëèíã íà âåðõó, âûõîäèì
  1892.     jne @f
  1893.       jmp .no_redraw
  1894.     @@:
  1895.       cmp tl_cur_pos,eax ;ïðîâåðÿåì ïîçèöèþ êóðñîðà è êîë-âî ñòîê íà ñòðàíèöå
  1896.       jl @f ;åñëè ìåíüøå, òî ïðèðàâíèâàåì ê 0, ÷òî-áû íå îòíÿòü áîëüøå ÷åì íàäî
  1897.         sub tl_cur_pos,eax
  1898.         jmp .cursor
  1899.       @@:
  1900.         mov tl_cur_pos,0
  1901.       .cursor:
  1902.       cmp dword[esi+24],eax
  1903.       jl @f
  1904.         sub dword[esi+24],eax
  1905.         jmp .scroll
  1906.       @@:
  1907.         mov dword[esi+24],0
  1908.       .scroll:
  1909.       ;ïåðåðèñîâêè îêíà è ñêðîëëèíãà
  1910.       push dword edi
  1911.       call tl_draw ;draw window
  1912.       push dword esi
  1913.       call scroll_bar_vertical.draw
  1914.     .no_redraw:
  1915.   pop esi edi eax
  1916.   pop ebp
  1917.   ret 4
  1918.  
  1919. align 4
  1920. tl_cur_page_down: ;ïåðåíåñòè êóðñîð íà 1 ñòðàíèöó íèæå
  1921.   push ebp
  1922.   mov ebp,esp
  1923.   push eax ebx ecx edi esi
  1924. ;eax - êîë-âî ñòðîê íà ñòðàíèöå
  1925. ;ebx - ìàêñ. ïîçèöèÿ êóðñîðà
  1926. ;ecx - ìàêñ. ïîçèöèÿ ñêðîëëèíãà
  1927.     mov edi,dword[ebp+8]
  1928.  
  1929.     cmp tl_p_scrol,0 ;åñëè åñòü óêàçàòåëü íà ñêðîëëèíã
  1930.     je .no_redraw
  1931.  
  1932.     mov esi,tl_p_scrol
  1933.     call tl_get_node_count ;eax = node count
  1934.     mov ebx,eax
  1935.     call tl_get_rows_count ;eax = rows count
  1936.  
  1937.     mov ecx,ebx
  1938.     inc ecx ;åñëè íèæíèé óçåë âèäåí íà ïîëîâèíó
  1939.     cmp ecx,eax ;if (ecx>eax) { ecx=ecx-eax } else { ecx=0 }
  1940.     jl @f
  1941.       sub ecx,eax ;óìåíüøàåì ìàêñèìàëüíóþ ïîçèöèþ ñêðîëëèíãà, òàê ÷òî-áû áûëè âèäíû ïîñëåäíèå óçëû
  1942.       jmp .control
  1943.     @@:
  1944.       xor ecx,ecx ;ecx=0 - âñå óçëû âëàçÿò â ýêðàí, ñêðîëëèíã íå íóæåí
  1945.     .control:
  1946.  
  1947.     cmp tl_cur_pos,ebx ;êóðñîð âíèçó ?
  1948.     jl @f
  1949.     cmp dword[esi+24],ecx ;ñêðîëëèíã âíèçó ?
  1950.     jl @f
  1951.       jmp .no_redraw
  1952.     @@:
  1953.  
  1954.       add tl_cur_pos,eax ;ïåðåìåùàåì êóðñîð
  1955.       cmp tl_cur_pos,ebx
  1956.       jl @f
  1957.         mov tl_cur_pos,ebx
  1958.       @@:
  1959.  
  1960.       add dword[esi+24],eax ;ïåðåìåùàåì ñêðîëëèíã
  1961.       cmp dword[esi+24],ecx
  1962.       jl @f
  1963.         mov dword[esi+24],ecx
  1964.       @@:
  1965.  
  1966.       ;ïåðåðèñîâêè îêíà è ñêðîëëèíãà
  1967.       push dword edi
  1968.       call tl_draw ;draw window
  1969.       push dword esi
  1970.       call scroll_bar_vertical.draw
  1971.     .no_redraw:
  1972.   pop esi edi ecx ebx eax
  1973.   pop ebp
  1974.   ret 4
  1975.  
  1976. align 4
  1977. tl_node_close_open: ;îòêðûòü/çàêðûòü óçåë (ðàáîòàåò ñ óçëàìè êîòîðûå èìåþò äî÷åðíèå óçëû)
  1978.   push ebp
  1979.   mov ebp,esp
  1980.   push eax edx edi
  1981.     mov edi,dword[ebp+8]
  1982.     call tl_get_cur_node_index ;eax = ïîçèöèÿ óçëà íà êîòîðîì ñòîèò êóðñîð
  1983.     cmp eax,2 ;êóðñîð ñòîèò íà óçëå ?
  1984.     jl @f
  1985.       imul eax,sizeof.TreeList
  1986.       add eax,tl_data_nodes
  1987.       ;eax = óêàçàòåëü íà ñòðóêòóðó óçëà âûáðàííîãî êóðñîðîì
  1988.       push dword edi
  1989.       push dword eax
  1990.       call tl_node_poi_get_next_info
  1991.       pop dword edx ;edx = óêàçàòåëü íà ñòðóêòóðó óçëà êîòîðûé èäåò ïîñëå óçëà eax
  1992.       cmp edx,0 ;åñòü ëè óçëû íèæå âûáðàííîãî íàìè ?
  1993.       je @f
  1994.         mov dl,byte[edx+2] ;áåðåì óðîâåíü íèæíåãî óçëà
  1995.         cmp byte[eax+2],dl ;+2 = .lev
  1996.         jge @f ;åñëè íèæíèå óçëû ìåíüøåãî óðîâíÿ, çíà÷èò îíè íå äî÷åðíèå, êîíåö ôóíêöèè
  1997.           xor byte[eax+3],1 ;+3 = .clo *** îòêðûòèå/çàêðûòèå óçëà ***
  1998.           call tb_scrol_resize ;îáðàáîòêà ñêðîëëèíãà
  1999.  
  2000.           push dword edi
  2001.           call tl_draw ;îáíîâëåíèå îêíà
  2002.     @@:
  2003.   pop edi edx eax
  2004.   pop ebp
  2005.   ret 4
  2006.  
  2007. align 4
  2008. tl_node_lev_inc: ;óâåëè÷èòü óðîâåíü
  2009.   push ebp
  2010.   mov ebp,esp
  2011.   push eax ecx edx edi
  2012.     mov edi,dword[ebp+8]
  2013.     bt tl_style,2 ;tl_list_box_mode
  2014.     jc @f
  2015.     call tl_get_cur_node_index ;eax=po_t
  2016.     cmp eax,2
  2017.     jl @f
  2018.       mov ecx,tl_data_nodes
  2019.       imul eax,sizeof.TreeList
  2020.       add eax,ecx ;eax = pointer to some node struct
  2021.       add ecx,sizeof.TreeList ;ecx = pointer to 1 node struct
  2022.  
  2023.       mov edx,eax
  2024.       call tl_iterat_perv ;ïðîâåðÿåì åñòü ëè âåðõíèé óçåë
  2025.       cmp edx,ecx
  2026.       jle @f ;åñëè âåðõíåãî óçëà íåò òî òåêóùèé óçåë íå äâèãàåì
  2027.       mov cl,byte[edx+2] ;áåðåì óðîâåíü ðîäèòåëüñêîãî óçëà
  2028.       inc cl ;äîáàâëÿåì 1 è ïîëó÷àåì ìàêñèìàëüíîå çíà÷åíèå
  2029.       cmp byte[eax+2],cl
  2030.       jge @f
  2031.         inc byte[eax+2] ;óâåëè÷èâàåì çíà÷åíèå óçëà
  2032.     @@:
  2033.   pop edi edx ecx eax
  2034.   pop ebp
  2035.   ret 4
  2036.  
  2037. align 4
  2038. tl_node_lev_dec: ;óìåíüøèòü óðîâåíü
  2039.   push ebp
  2040.   mov ebp,esp
  2041.   push eax edi
  2042.     mov edi,dword[ebp+8]
  2043.     call tl_get_cur_node_index ;eax=po_t
  2044.     cmp eax,2
  2045.     jl @f
  2046.       imul eax,sizeof.TreeList
  2047.       add eax,tl_data_nodes
  2048.       cmp byte[eax+2],0
  2049.       je @f
  2050.       dec byte[eax+2]
  2051.     @@:
  2052.   pop edi eax
  2053.   pop ebp
  2054.   ret 4
  2055.  
  2056. align 4
  2057. tl_node_move_up: ;ïåðåìåùàåì óçåë ââåðõ
  2058.   push ebp
  2059.   mov ebp,esp
  2060.   push eax ebx ecx edx edi esi
  2061.     mov edi,dword[ebp+8]
  2062.     call tl_get_cur_node_index ;eax=po_t
  2063.     cmp eax,2
  2064.     jl @f
  2065.       mov ebx,eax ;copy index of node struct
  2066.       mov edx,tl_data_nodes
  2067.       mov ecx,edx
  2068.       add ecx,sizeof.TreeList
  2069.       imul eax,sizeof.TreeList
  2070.       add eax,edx ;eax = pointer to 2 node struct
  2071.       mov edx,eax ;edx = pointer to 2 node struct
  2072.       mov esi,eax ;esi = pointer to 2 node struct
  2073.       call tl_iterat_perv ;edx = pointer to 1 node struct
  2074.       call tl_get_node_index ;eax = index of 1 node struct
  2075.       cmp edx,ecx
  2076.       jle @f
  2077.         cmp dword[edx+8],ebx ;+8 next
  2078.         jne .po8
  2079.           call tl_node_move_po6 ;óçëû èäóò ïîäðÿä ìåíÿåì 6 ññûëîê
  2080.           jmp .cur_mov
  2081.         .po8:
  2082.           call tl_node_move_po8 ;óçëû èäóò íå ïîäðÿä ìåíÿåì 8 ññûëîê
  2083.         .cur_mov:
  2084.           push dword edi
  2085.           call tl_cur_perv
  2086.           push dword edi
  2087.           call tl_draw
  2088.     @@:
  2089.   pop esi edi edx ecx ebx eax
  2090.   pop ebp
  2091.   ret 4
  2092.  
  2093. align 4
  2094. tl_node_move_down: ;ïåðåìåùàåì óçåë âíèç
  2095.   push ebp
  2096.   mov ebp,esp
  2097.   push eax ebx ecx edx edi esi
  2098.     mov edi,dword[ebp+8]
  2099.     call tl_get_cur_node_index ;eax=po_t
  2100.     cmp eax,2
  2101.     jl @f
  2102.       mov ebx,eax ;copy index of node struct
  2103.       mov edx,tl_data_nodes
  2104.       mov ecx,edx
  2105.       add ecx,sizeof.TreeList
  2106.       imul eax,sizeof.TreeList
  2107.       add eax,edx ;eax = pointer to 1 node struct
  2108.       mov edx,eax ;edx = pointer to 1 node struct
  2109.       mov esi,eax ;esi = pointer to 1 node struct
  2110.       call tl_iterat_next ;edx = pointer to 2 node struct
  2111.       call tl_get_node_index ;eax = index of 2 node struct
  2112.       cmp edx,ecx
  2113.       jle @f
  2114.         cmp dword[esi+8],eax ;+8 next
  2115.         jne .po8
  2116.           xchg eax,ebx ;ìåíÿå ïîðÿäîê ñëåäîâàíèÿ çàìåíÿåìûõ óçëîâ
  2117.           xchg edx,esi
  2118.           call tl_node_move_po6 ;óçëû èäóò ïîäðÿä ìåíÿåì 6 ññûëîê
  2119.           jmp .cur_mov
  2120.         .po8: ;à òóò ïîðÿäîê ñëåäîâàíèÿ óçëîâ íå ìåíÿåì
  2121.           call tl_node_move_po8 ;óçëû èäóò íå ïîäðÿä ìåíÿåì 8 ññûëîê
  2122.         .cur_mov:
  2123.           push dword edi
  2124.           call tl_cur_next
  2125.           push dword edi
  2126.           call tl_draw
  2127.     @@:
  2128.   pop esi edi edx ecx ebx eax
  2129.   pop ebp
  2130.   ret 4
  2131.  
  2132. align 4
  2133. tl_node_move_po6:
  2134.   mov ecx,edx ;save node pointer
  2135.   call tl_move_perv
  2136.   mov dword[edx+8],ebx
  2137.  
  2138.   mov edx,esi
  2139.   call tl_move_next
  2140.   mov dword[edx+4],eax
  2141.   mov edx,ecx ;restore node pointer
  2142.  
  2143.   ;+4 perv
  2144.   mov ecx,dword[edx+4]
  2145.   mov dword[esi+4],ecx
  2146.   ;+8 next
  2147.   mov ecx,dword[esi+8]
  2148.   mov dword[edx+8],ecx
  2149.  
  2150.   mov dword[edx+4],ebx
  2151.   mov dword[esi+8],eax
  2152.   ret
  2153.  
  2154. ;input
  2155. ;eax = index 1 node struct
  2156. ;ebx = index 2 node struct
  2157. ;edx = pointer 1 node struct
  2158. ;esi = pointer 2 node struct
  2159. ;edi = pointer to 'TreeList' struct
  2160. ;output:
  2161. ;eax = ?
  2162. ;ebx = ?
  2163. ;ecx = ?
  2164. align 4
  2165. tl_node_move_po8:
  2166. ;  push ecx
  2167.   mov ecx,edx ;save node pointer
  2168.   call tl_move_perv
  2169.   mov dword[edx+8],ebx
  2170.   mov edx,ecx
  2171.   call tl_move_next
  2172.   mov dword[edx+4],ebx
  2173.   mov edx,esi
  2174.   call tl_move_perv
  2175.   mov dword[edx+8],eax
  2176.   mov edx,esi
  2177.   call tl_move_next
  2178.   mov dword[edx+4],eax
  2179.   mov edx,ecx ;restore node pointer
  2180. ;  pop ecx
  2181.  
  2182.   ;+4 perv
  2183.   mov eax,dword[edx+4]
  2184.   mov ebx,dword[esi+4]
  2185.   xchg eax,ebx
  2186.   mov dword[edx+4],eax
  2187.   mov dword[esi+4],ebx
  2188.   ;+8 next
  2189.   mov eax,dword[edx+8]
  2190.   mov ebx,dword[esi+8]
  2191.   xchg eax,ebx
  2192.   mov dword[edx+8],eax
  2193.   mov dword[esi+8],ebx
  2194.   ret
  2195.  
  2196. ;input:
  2197. ; edi = pointer to 'TreeList' struct
  2198. align 4
  2199. tl_draw_caption_cur_pos:
  2200.   cmp tl_capt_cy,9 ;9 - minimum caption height
  2201.   jl @f
  2202.   push eax ebx ecx edx edi esi
  2203.     mov ebx,edi ;calculate cursor position
  2204.     mov eax,tl_cur_pos
  2205.     inc eax
  2206.     lea edi,[txt_capt_cur]
  2207.     add edi,7
  2208.     call tl_convert_to_str
  2209.     mov edi,ebx
  2210.  
  2211.     mov eax,4 ;draw text captions
  2212.     mov ebx,tl_box_left
  2213.     shl ebx,16
  2214.     add ebx,5*65536+3
  2215.     add ebx,tl_box_top
  2216.     mov ecx,tl_col_txt
  2217.     or  ecx,0xc0000000 ;0x40000000 çàêðàøèâàòü ôîí öâåòîì edi
  2218.     lea edx,[txt_capt_cur]
  2219.     mov edi,tl_col_zag
  2220.     int 0x40
  2221.  
  2222.   pop esi edi edx ecx ebx eax
  2223.   @@:
  2224.   ret
  2225.  
  2226. ;input:
  2227. ;dword[ebp+ 8] - memory size
  2228. ;dword[ebp+12] - pointer to memory
  2229. ;dword[ebp+16] - options: 0 - first element, 1 - add next element
  2230. ;dword[ebp+20] - pointer to 'TreeList' struct
  2231. ;output:
  2232. ;dword[ebp+ 8] - error code
  2233. align 4
  2234. tl_save_mem:
  2235.   push ebp
  2236.   mov ebp,esp
  2237.     push eax ebx ecx edx edi esi
  2238.     mov esi,dword[ebp+12]
  2239.     mov edi,dword[ebp+20]
  2240.  
  2241.     cmp dword[ebp+16],0 ;add mode
  2242.     je @f
  2243.       push dword edi
  2244.       push dword esi
  2245.       call tl_get_mem_size ;áåðåì ðàçìåð ðàíåå ñîõðàí¸ííûõ äàííûõ
  2246.       pop ebx
  2247.       add esi,ebx
  2248.     @@:
  2249.  
  2250.     xor ebx,ebx
  2251.     mov bx,tl_info_size
  2252.  
  2253.     call tl_get_node_count_all ;eax = all node count
  2254.  
  2255.     mov ecx,eax  ;âû÷èñëÿåì ñêîëüêî ïàìÿòè äîëæíî áûòü çàïîëíåíî
  2256.     imul ecx,ebx ;óìíîæàåì íà ðàçìåð ñòðóêòóðû óçëà
  2257.     add ecx,tl_save_load_heder_size+1 ;element header +1 end element sumbol
  2258.     add ecx,esi  ;äîáàâëÿåì óêàçàòåëü íà íà÷àëî ïàìÿòè (ñ ó÷åòîì ðàíåå çàïèñàííûõ ñòðóêòóð)
  2259.     sub ecx,dword[ebp+12] ;îòíèìàåì óêàçàòåëü íà íà÷àëî ïàìÿòè (áåç ðàíåå çàïèñàííûõ ñòðóêòóð)
  2260.     cmp ecx,dword[ebp+8]  ;ecx = element memory size
  2261.     jg .err_mem_size
  2262.  
  2263.     ;save tree params (in header)
  2264.     mov dword[esi],'tree'
  2265.     mov word[esi+4],bx
  2266.     mov dword[esi+6],eax ;element count
  2267.  
  2268.     mov eax,tl_style
  2269.     mov dword[esi+10],eax
  2270.  
  2271.     mov eax,tl_cur_pos
  2272.     mov dword[esi+14],eax
  2273.  
  2274.     mov ax,tl_info_capt_offs
  2275.     mov word[esi+18],ax
  2276.  
  2277.     mov ax,tl_info_capt_len
  2278.     mov word[esi+20],ax
  2279.  
  2280.     ;copy scroll position
  2281.     mov edx,tl_p_scrol
  2282.     mov eax,dword[edx+24] ;+24 .position
  2283.     mov dword[esi+22],eax
  2284.  
  2285.     add esi,tl_save_load_heder_size ;add header size
  2286.  
  2287.     ;cycle to nodes
  2288.     mov edx,tl_data_nodes
  2289.     mov ecx,edx
  2290.     add ecx,sizeof.TreeList
  2291.     @@:
  2292.       call tl_iterat_next_all
  2293.       cmp edx,ecx
  2294.       jle @f
  2295. ;save node params
  2296. call tl_get_node_index ;eax = index of pointer [edx]
  2297. mov dword[esi],eax
  2298.  
  2299. add esi,4
  2300. mov eax,dword[edx] ;eax = (type; lev; clo)
  2301. mov dword[esi],eax
  2302. add esi,4
  2303.  
  2304. push dword edi
  2305. push dword edx
  2306. call tl_node_poi_get_data
  2307. pop dword eax
  2308.  
  2309. ;call tl_node_copy_data
  2310. push ecx edi
  2311.   mov edi,eax
  2312.   mov ecx,ebx
  2313.   xchg esi,edi
  2314.   rep movsb
  2315.   mov esi,edi
  2316. pop edi ecx
  2317. ;add esi,ebx
  2318.       jmp @b
  2319.     @@:
  2320.     mov byte[esi],0 ;end of 'treelist'
  2321.     mov dword[ebp+20],0 ;return error code
  2322.     jmp @f
  2323.       .err_mem_size:
  2324.       or dword[ebp+20],tl_err_save_memory_size
  2325.     @@:
  2326.     pop esi edi edx ecx ebx eax
  2327.   pop ebp
  2328.   ret 12
  2329.  
  2330. ;input:
  2331. ;dword[ebp+ 8] - memory size
  2332. ;dword[ebp+12] - pointer to memory
  2333. ;word[ebp+16] - options: element index
  2334. ;word[ebp+18] - options: 2*(add mode)+(init mode)
  2335. ;dword[ebp+20] - pointer to 'TreeList' struct
  2336. ;output:
  2337. ;dword[ebp+ 8] - error code
  2338. align 4
  2339. tl_load_mem:
  2340.   push ebp
  2341.   mov ebp,esp
  2342.     push eax ebx ecx edx edi esi
  2343.     mov esi,dword[ebp+12]
  2344.     mov edi,dword[ebp+20]
  2345.  
  2346.     mov dword[ebp+20],0 ;return error code
  2347.  
  2348.     xor ecx,ecx
  2349.     mov cx,word[ebp+16]
  2350.     cmp cx,0 ;load in array mode
  2351.     je @f
  2352. ;      push dword edi
  2353. ;      push dword esi
  2354. ;      call tl_get_mem_size ;áåðåì ðàçìåð ðàíåå ñîõðàí¸ííûõ äàííûõ
  2355. ;      pop ebx
  2356. ;      add esi,ebx
  2357.       .beg_cycle:
  2358.       cmp dword[esi],'tree'
  2359.       jne .no_tree
  2360.       xor ebx,ebx
  2361.       mov bx,word[esi+4]
  2362.       add bx,8
  2363.       imul ebx,dword[esi+6]
  2364.       add ebx,tl_save_load_heder_size
  2365.       add esi,ebx
  2366.       loop .beg_cycle
  2367.     @@:
  2368.  
  2369.     cmp dword[esi],'tree'
  2370.     jne .no_tree
  2371.       bt word[ebp+18],1 ;load in add mode
  2372.       jc @f
  2373.         push dword edi
  2374.         call tl_info_clear
  2375.       @@:
  2376.  
  2377.       xor ebx,ebx
  2378.       mov bx,word[esi+4] ;info_size
  2379.       cmp bx,tl_info_size
  2380.       je @f
  2381.         or dword[ebp+20],tl_err_load_info_size
  2382.       @@:
  2383.       mov ecx,dword[esi+6] ;count nodes
  2384.       cmp ecx,1
  2385.       jl .end_f
  2386.       mov edx,esi ;save header pointer
  2387.       add esi,tl_save_load_heder_size
  2388.  
  2389.       @@:
  2390. ;load node params
  2391. push dword edi
  2392. mov eax,dword[esi+4]
  2393. ror eax,16
  2394. push dword eax ;options (type; lev; clo)
  2395. add esi,8
  2396. push dword esi
  2397. call tl_node_add
  2398.  
  2399. push dword edi
  2400. call tl_cur_next
  2401. ;...
  2402. add esi,ebx
  2403.         loop @b
  2404.  
  2405.       bt word[ebp+18],1 ;load in add mode
  2406.       jc .no_tree
  2407.         mov eax,dword[edx+14] ;set cursor pos
  2408.         mov tl_cur_pos,eax
  2409.         mov eax,dword[edx+22] ;set scroll pos
  2410.         mov ebx,tl_p_scrol
  2411.         cmp ebx,0
  2412.         je .end_f
  2413.           mov dword[ebx+24],eax ;+24 .position
  2414.           push dword ebx ;pointer to scroll struct
  2415.           call scroll_bar_vertical.draw
  2416.  
  2417.       jmp .end_f
  2418.     .no_tree:
  2419.       mov dword[ebp+20],tl_err_load_caption
  2420.     .end_f:
  2421.     pop esi edi edx ecx ebx eax
  2422.   pop ebp
  2423.   ret 12
  2424.  
  2425. ;input:
  2426. ;dword[ebp+ 8] - pointer to memory
  2427. ;dword[ebp+12] - pointer to 'TreeList' struct
  2428. ;output:
  2429. ;dword[ebp+ 8] - error code
  2430. align 4
  2431. tl_get_mem_size: ;áåðåò ðàçìåð ïàìÿòè çàíÿòîé ôóíêöèåé tl_save_mem ïðè ñîõðàíåíèè ýëåìåíòîâ
  2432.   push ebp
  2433.   mov ebp,esp
  2434.     push ebx edi esi
  2435.     mov esi,dword[ebp+ 8]
  2436.     mov edi,dword[ebp+12]
  2437.     @@:
  2438.       cmp dword[esi],'tree'
  2439.       jne @f
  2440.       xor ebx,ebx
  2441.       mov bx,word[esi+4]
  2442.       add bx,8 ;ðàçìåð äîïîëíèòåëüíîé èíôîðìàöèè îá óçëå (èíäåêñ çàïèñè; èíäåêñ èêîíêè, óðîâåíü, ...)
  2443.       imul ebx,dword[esi+6]
  2444.       add ebx,tl_save_load_heder_size
  2445.       add esi,ebx
  2446.       jmp @b
  2447.     @@:
  2448.     sub esi,dword[ebp+ 8]
  2449.     mov dword[ebp+12],esi ;âîçâðàùàåì ðàçìåð áëîêà ïàìÿòè
  2450.     pop esi edi edx
  2451.   pop ebp
  2452.   ret 4
  2453.  
  2454.  
  2455. ;ascii scan key
  2456. ;  13    28 Enter
  2457. ;  32    57 Space
  2458. ; 178    72 Up
  2459. ; 177    80 Down
  2460. ; 176    75 Left
  2461. ; 179    77 Right
  2462. ; 182    83 Delete
  2463. ; 184    73 Pg Up
  2464. ; 183    81 Pg Dn
  2465.  
  2466. tl_key_ascii db 13,32,178,177,176,179,182,184,183
  2467. tl_key_scan  db 28,57, 72, 80, 75, 77, 83, 73, 81
  2468.  
  2469. txt_capt_cur db '‘âப       ',0
  2470. txt_capt_otm db 'Žâ¬¥­ë      ',0
  2471.  
  2472. ;ýòîò êîä íå ìîé, îí ïðåîáðàçóåò ÷èñëî â ñòðîêó
  2473. ;input:
  2474. ; eax = value
  2475. ; edi = string buffer
  2476. align 4
  2477. tl_convert_to_str:
  2478.   pushad
  2479.     mov dword[edi+1],0x20202020
  2480.     call .str
  2481.   popad
  2482.   ret
  2483.  
  2484. align 4
  2485. .str:
  2486.   mov ecx,0x0a ;çàäàåòñÿ ñèñòåìà ñ÷èñëåíèÿ èçìåíÿþòñÿ ðåãèñòðû ebx,eax,ecx,edx âõîäíûå ïàðàìåòðû eax - ÷èñëî
  2487.     ;ïðåðåâîä ÷èñëà â ASCII ñòðîêó âçîäíûå äàííûå ecx=ñèñòåìà ñ÷èñëåíÿ edi àäðåñ êóäà çàïèñûâàòü, áóäåì ñòðîêó, ïðè÷åì êîíåö ïåðåìåííîé
  2488.   cmp eax,ecx  ;ñðàâíèòü åñëè â eax ìåíüøå ÷åì â ecx òî ïåðåéòè íà @@-1 ò.å. íà pop eax
  2489.   jb @f
  2490.   xor edx,edx  ;î÷èñòèòü edx
  2491.   div ecx      ;ðàçäåëèòü - îñòàòîê â edx
  2492.   push edx     ;ïîëîæèòü â ñòåê
  2493.   ;dec edi             ;ñìåùåíèå íåîáõîäèìîå äëÿ çàïèñè ñ êîíöà ñòðîêè
  2494.   call .str;ïåðåéòè íà ñàìó ñåáÿ ò.å. âûçâàòü ñàìó ñåáÿ è òàê äî òîãî ìîìåíòà ïîêà â eax íå ñòàíåò ìåíüøå ÷åì â ecx
  2495.   pop eax
  2496.   @@: ;cmp al,10 ;ïðîâåðèòü íå ìåíüøå ëè çíà÷åíèå â al ÷åì 10 (äëÿ ñèñòåìû ñ÷èñëåíÿ 10 äàííàÿ êîìàíäà - ëèøíàÿ))
  2497.   ;sbb al,$69  ;- ÷åñòíî äàííàÿ èíñòðóêöèÿ ìåíÿ çàñòàâëÿåò çàäóìàòüñÿ ò.å. ÿ íå çíàþ êàê ýòî ðàáîòàåò
  2498.   ;das        ;ïîñëå äàííîé êîìàíäû êàê áû ïðîèñõîäèò óìåíüøåíèå al íà 66h  (â êíèãå íàïèñàíî äðóãîå)
  2499.   or al,0x30  ;äàííàÿ êîìàíäà êîðî÷å  ÷åì äâå âûøå
  2500.   stosb       ;çàïèñàòü ýëåìåíò èç ðåãèñòðà al â ÿ÷åêó ïàìÿòè es:edi
  2501.   ret         ;âåðíóòüñÿ ÷åíü èíòåðåñíûé õîä ò.ê. ïîêà â ñòåêå õðàíèòüñÿ êîë-âî âûçîâîâ òî ñòîëüêî ðàç ìû è áóäåì âûçûâàòüñÿ
  2502. }
  2503.