Subversion Repositories Kolibri OS

Rev

Rev 1285 | Blame | Last modification | View Log | Download | RSS feed

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