Subversion Repositories Kolibri OS

Rev

Rev 987 | Rev 8589 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. diff16 'tp-common.asm',0,$
  2.  
  3. ;-----------------------------------------------------------------------------
  4. proc clear_selection ;////////////////////////////////////////////////////////
  5. ;-----------------------------------------------------------------------------
  6.         push    eax ebx
  7.         mov     eax,[cur_editor.SelStart.Y]
  8.         mov     ebx,[cur_editor.Caret.Y]
  9.         cmp     eax,ebx
  10.         jle     @f
  11.         xchg    eax,ebx
  12.     @@: push    [cur_editor.Caret.X] [cur_editor.Caret.Y]
  13.         pop     [cur_editor.SelStart.Y] [cur_editor.SelStart.X]
  14.         pop     ebx eax
  15.         ret
  16. endp
  17.  
  18. ;-----------------------------------------------------------------------------
  19. proc pt_in_rect ;/////////////////////////////////////////////////////////////
  20. ;-----------------------------------------------------------------------------
  21.         cmp     eax,[ecx+0x0]
  22.         jl      @f
  23.         cmp     ebx,[ecx+0x4]
  24.         jl      @f
  25.         cmp     eax,[ecx+0x8]
  26.         jg      @f
  27.         cmp     ebx,[ecx+0xC]
  28.         jg      @f
  29.         stc
  30.         ret
  31.     @@: clc
  32.         ret
  33. endp
  34.  
  35. ;-----------------------------------------------------------------------------
  36. proc check_bottom_right ;/////////////////////////////////////////////////////
  37. ;-----------------------------------------------------------------------------
  38.         push    eax
  39.         mov     eax,[cur_editor.TopLeft.Y]
  40.         or      eax,eax
  41.         jns     @f
  42.         xor     eax,eax
  43.         mov     [cur_editor.TopLeft.Y],eax
  44.     @@: add     eax,[lines.scr]
  45.         cmp     eax,[cur_editor.Lines.Count]
  46.         jbe     .lp1
  47.         mov     eax,[cur_editor.Lines.Count]
  48.         sub     eax,[lines.scr]
  49.         jns     @f
  50.         xor     eax,eax
  51.     @@: mov     [cur_editor.TopLeft.Y],eax
  52.   .lp1: mov     eax,[cur_editor.TopLeft.X]
  53.         or      eax,eax
  54.         jns     @f
  55.         xor     eax,eax
  56.         mov     [cur_editor.TopLeft.X],eax
  57.     @@: add     eax,[columns.scr]
  58.         cmp     eax,[cur_editor.Columns.Count]
  59.         jbe     .exit
  60.         mov     eax,[cur_editor.Columns.Count]
  61.         sub     eax,[columns.scr]
  62.         jns     @f
  63.         xor     eax,eax
  64.     @@: mov     [cur_editor.TopLeft.X],eax
  65.   .exit:
  66.         pop     eax
  67.         ret
  68. endp
  69.  
  70. ;-----------------------------------------------------------------------------
  71. proc get_real_length ;////////////////////////////////////////////////////////
  72. ;-----------------------------------------------------------------------------
  73.         mov     eax,[esi+EDITOR_LINE_DATA.Size]
  74.     @@: cmp     byte[esi+eax+sizeof.EDITOR_LINE_DATA-1],' '
  75.         jne     @f
  76.         dec     eax
  77.         jnz     @b
  78.     @@: ret
  79. endp
  80.  
  81. ;-----------------------------------------------------------------------------
  82. proc get_line_offset ;////////////////////////////////////////////////////////
  83. ;-----------------------------------------------------------------------------
  84. ; Input:
  85. ;  ECX = line number
  86. ; Output:
  87. ;  ESI = line data offset
  88. ;-----------------------------------------------------------------------------
  89.         push    eax ecx
  90.         mov     esi,[cur_editor.Lines]
  91.     @@: dec     ecx
  92.         js      .exit
  93.         mov     eax,[esi+EDITOR_LINE_DATA.Size]
  94.         lea     esi,[esi+eax+sizeof.EDITOR_LINE_DATA]
  95.         jmp     @b
  96.   .exit:
  97.         pop     ecx eax
  98.         ret
  99. endp
  100.  
  101. ;-----------------------------------------------------------------------------
  102. proc init_sel_vars ;//////////////////////////////////////////////////////////
  103. ;-----------------------------------------------------------------------------
  104.         pushad
  105.         mov     [sel.selected],1
  106.         mov     eax,[ebp+EDITOR.SelStart.X]
  107.         mov     ebx,[ebp+EDITOR.SelStart.Y]
  108.         mov     ecx,[ebp+EDITOR.Caret.X]
  109.         mov     edx,[ebp+EDITOR.Caret.Y]
  110.         cmp     ebx,edx
  111.         jl      .lp2
  112.         jne     @f
  113.         cmp     eax,ecx
  114.         jl      .lp2
  115.         jne     .lp1
  116.         dec     [sel.selected]
  117.         jmp     .lp2
  118.     @@: xchg    ebx,edx
  119.   .lp1: xchg    eax,ecx
  120.   .lp2: mov     [sel.begin.x],eax
  121.         mov     [sel.begin.y],ebx
  122.         mov     [sel.end.x],ecx
  123.         mov     [sel.end.y],edx
  124.         popad
  125.         ret
  126. endp
  127.  
  128. ;-----------------------------------------------------------------------------
  129. proc get_scroll_vars ;////////////////////////////////////////////////////////
  130. ;-----------------------------------------------------------------------------
  131. ; Input:
  132. ;  EAX = maximum data size      (units)
  133. ;  EBX = visible data size      (units)
  134. ;  ECX = current data position  (units)
  135. ;  EDX = scrolling area size    (pixels)
  136. ; Output:
  137. ;  EAX = srcoller offset        (pixels)
  138. ;  EBX = scroller size          (pixels)
  139. ;-----------------------------------------------------------------------------
  140.         push    eax ebx edx
  141. ;       sub     eax,ebx
  142.         mov     esi,eax
  143.         mov     eax,edx
  144.         imul    ebx
  145.         idiv    esi
  146.         cmp     eax,[esp]
  147.         jge     .null
  148.         cmp     eax,AMINS
  149.         jge     @f
  150.         neg     eax
  151.         add     eax,AMINS
  152.         sub     [esp],eax
  153.         mov     eax,AMINS
  154.     @@: mov     [esp+4],eax     ; scroller size
  155.         mov     eax,[esp]
  156.         imul    ecx
  157.         idiv    esi
  158.         or      eax,eax
  159.         jns     @f
  160.         xor     eax,eax
  161.    @@:  mov     [esp+8],eax     ; scroller offset
  162.         add     eax,[esp+4]
  163.         cmp     eax,[esp]
  164.         jle     @f
  165.     @@:
  166.         pop     edx ebx eax
  167.         ret
  168.   .null:
  169.         mov     dword[esp+4],0
  170.         mov     dword[esp+8],0
  171.         jmp     @b
  172. endp
  173.  
  174. ;-----------------------------------------------------------------------------
  175. proc uint2strz ;//////////////////////////////////////////////////////////////
  176. ;-----------------------------------------------------------------------------
  177.         dec     ebx
  178.         jz      @f
  179.         xor     edx,edx
  180.         div     ecx
  181.         push    edx
  182.         call    uint2strz
  183.         pop     eax
  184.     @@: cmp     al,10
  185.         sbb     al,$69
  186.         das
  187.         stosb
  188.         ret
  189. endp
  190.  
  191. ;-----------------------------------------------------------------------------
  192. proc uint2str ;///////////////////////////////////////////////////////////////
  193. ;-----------------------------------------------------------------------------
  194.         cmp     eax,ecx
  195.         jb      @f
  196.         xor     edx,edx
  197.         div     ecx
  198.         push    edx
  199.         call    uint2str
  200.         pop     eax
  201.     @@: cmp     al,10
  202.         sbb     al,$69
  203.         das
  204.         stosb
  205.         ret
  206. endp
  207.  
  208. ;-----------------------------------------------------------------------------
  209. proc strlen ;/////////////////////////////////////////////////////////////////
  210. ;-----------------------------------------------------------------------------
  211.         push    ebx
  212.         mov     ebx,eax
  213.         xor     eax,eax
  214.     @@: cmp     byte[ebx+eax],0
  215.         je      @f
  216.         inc     eax
  217.         jmp     @b
  218.     @@: pop     ebx
  219.         ret
  220. endp
  221.  
  222. ;-----------------------------------------------------------------------------
  223. proc rgb_to_gray ;////////////////////////////////////////////////////////////
  224. ;-----------------------------------------------------------------------------
  225.         push    0 eax
  226.         and     dword[esp],0x000000FF
  227.         fild    dword[esp]
  228.         fmul    [float_gray_b]
  229.         shr     eax,8
  230.         mov     [esp],eax
  231.         and     dword[esp],0x000000FF
  232.         fild    dword[esp]
  233.         fmul    [float_gray_g]
  234.         faddp
  235.         shr     eax,8
  236.         and     eax,0x000000FF
  237.         mov     [esp],eax
  238.         fild    dword[esp]
  239.         fmul    [float_gray_r]
  240.         faddp
  241.         frndint
  242.         fist    dword[esp]
  243.         fist    dword[esp+1]
  244.         fistp   dword[esp+2]
  245.         pop     eax
  246.         add     esp,4
  247.         ret
  248. endp
  249.  
  250. ;float_gray_r dd 0.30f
  251. ;float_gray_g dd 0.59f
  252. ;float_gray_b dd 0.11f
  253.  
  254. ;-----------------------------------------------------------------------------
  255. proc get_active_menu_item ;///////////////////////////////////////////////////
  256. ;-----------------------------------------------------------------------------
  257.         pushad
  258.         mov     [mi_cur],0
  259.         mcall   37,1
  260.         movsx   ebx,ax
  261.         sar     eax,16
  262.         mov     ecx,__rc
  263.         pushd   2 0 (main_menu.width+7) (ATOPH-2)
  264.         popd    [__rc+0xC] [__rc+0x8] [__rc+0x4] [__rc+0x0]
  265. ;       add     [__rc+0xC],ATOPH-2
  266.         call    pt_in_rect
  267.         jnc     .outside_menu
  268.         m2m     dword[ecx+0x8],dword[ecx+0x0]
  269.         mov     edx,main_menu
  270.     @@: inc     [mi_cur]
  271.         movzx   esi,word[edx+0]
  272.         add     [ecx+0x8],esi
  273.         call    pt_in_rect
  274.         jc      .exit
  275.         m2m     dword[ecx+0x0],dword[ecx+0x8]
  276.         add     edx,8+1
  277.         movzx   esi,byte[edx-1]
  278.         add     edx,esi
  279.         cmp     byte[edx+8],0
  280.         jne     @b
  281.         mov     [mi_cur],0
  282.   .exit:
  283.         popad
  284.         ret
  285.   .outside_menu:
  286.         or      [mi_cur],-1
  287.     @@: popad
  288.         ret
  289. endp
  290.  
  291. ;-----------------------------------------------------------------------------
  292. proc get_active_popup_item ;//////////////////////////////////////////////////
  293. ;-----------------------------------------------------------------------------
  294.         pushad
  295.         mov     [pi_cur],0
  296.         mcall   37,1
  297.         movsx   ebx,ax
  298.         sar     eax,16
  299.         mov     ecx,__rc
  300.         mov     dword[ecx+0x0],0
  301.         mov     dword[ecx+0x4],0
  302.         movzx   edx,[ebp+POPUP.width]
  303.         mov     dword[ecx+0x8],edx
  304.         movzx   edx,[ebp+POPUP.height]
  305.         mov     dword[ecx+0xC],edx
  306.         call    pt_in_rect
  307.         jnc     .outside_window
  308.         inc     dword[ecx+0x0]
  309.         mov     dword[ecx+0x4],2
  310.         dec     dword[ecx+0x8]
  311.         mov     dword[ecx+0xC],2+POP_IHEIGHT-1
  312.         mov     edx,[ebp+POPUP.data]
  313.     @@: inc     [pi_cur]
  314.         inc     edx
  315.         movzx   esi,byte[edx-1]
  316.         cmp     byte[edx],'-'
  317.         jne     .lp1
  318.         pushd   [ecx+0xC]
  319.         sub     dword[ecx+0xC],POP_IHEIGHT-POP_SHEIGHT
  320.         call    pt_in_rect
  321.         popd    [ecx+0xC]
  322.         jc      .separator
  323.         add     dword[ecx+0x4],POP_SHEIGHT
  324.         add     dword[ecx+0xC],POP_SHEIGHT
  325.         jmp     .lp3
  326.   .lp1: call    pt_in_rect
  327.         jnc     .lp2
  328.         mov     eax,[pi_cur]
  329.         test    byte[ebp+eax-1],1
  330.         jnz     .exit
  331.         jmp     .separator
  332.   .lp2: add     dword[ecx+0x4],POP_IHEIGHT
  333.         add     dword[ecx+0xC],POP_IHEIGHT
  334.         add     edx,esi
  335.         inc     edx
  336.         movzx   esi,byte[edx-1]
  337.   .lp3: add     edx,esi
  338.         cmp     byte[edx],0
  339.         jne     @b
  340.   .separator:
  341.         mov     [pi_cur],0
  342.   .exit:
  343.         popad
  344.         ret
  345.   .outside_window:
  346.         or      [pi_cur],-1
  347.         jmp     .exit
  348. endp
  349.  
  350. ;-----------------------------------------------------------------------------
  351. proc line_add_spaces ;////////////////////////////////////////////////////////
  352. ;-----------------------------------------------------------------------------
  353. ; Input:
  354. ;  ESI = line offset
  355. ;  ECX = needed line length
  356. ; Output:
  357. ;  EAX = delta
  358. ;-----------------------------------------------------------------------------
  359.         xor     eax,eax
  360.         pushad
  361.         mov     edx,[esi+EDITOR_LINE_DATA.Size]
  362.         cmp     ecx,edx
  363.         jbe     .exit
  364.         sub     ecx,edx
  365.         lea     eax,[ecx+sizeof.EDITOR_LINE_DATA]
  366.         call    editor_realloc_lines
  367.         mov     [esp+4*7],eax
  368.         add     esi,eax
  369.         push    ecx
  370.         mov     edi,[cur_editor.Lines]
  371.         add     edi,[cur_editor.Lines.Size] ; !!! CHECK THIS!!! add edi,[edi-4]
  372.         dec     edi
  373.         mov     eax,esi
  374.         mov     esi,edi
  375.         sub     esi,ecx
  376.         lea     ecx,[eax+sizeof.EDITOR_LINE_DATA]
  377.         add     ecx,edx
  378.         push    ecx
  379.         neg     ecx
  380.         lea     ecx,[esi+ecx+1]
  381.         std
  382.         rep     movsb
  383.         pop     edi ecx
  384.         add     [eax+EDITOR_LINE_DATA.Size],ecx
  385.         mov     al,' '
  386.         cld
  387.         rep     stosb
  388.   .exit:
  389.         popad
  390.         ret
  391. endp
  392.  
  393. ;-----------------------------------------------------------------------------
  394. proc delete_selection ;///////////////////////////////////////////////////////
  395. ;-----------------------------------------------------------------------------
  396. ;       call    init_sel_vars
  397.  
  398.         cmp     [sel.selected],0
  399.         je      .exit.2
  400.  
  401.         pushad
  402.         mov     ecx,[sel.begin.y]
  403.         cmp     ecx,[sel.end.y]
  404.         je      .single_line
  405.         call    get_line_offset
  406.         and     [esi+EDITOR_LINE_DATA.Flags],not EDITOR_LINE_FLAG_SAVED
  407.         or      [esi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
  408.         mov     ecx,[sel.begin.x]
  409.         call    line_add_spaces
  410.         add     esi,eax
  411.         lea     edi,[esi+sizeof.EDITOR_LINE_DATA]
  412.         mov     ecx,[sel.end.y]
  413.         call    get_line_offset
  414.         call    get_real_length
  415.         cmp     eax,[sel.end.x]
  416.         jbe     @f
  417.         mov     eax,[sel.end.x]
  418.     @@: mov     ecx,[esi+EDITOR_LINE_DATA.Size]
  419.         sub     ecx,eax
  420.         mov     ebx,[sel.begin.x]
  421.         add     ebx,ecx
  422.         mov     [edi-sizeof.EDITOR_LINE_DATA+EDITOR_LINE_DATA.Size],ebx
  423.         add     edi,[sel.begin.x]
  424.         lea     esi,[esi+eax+sizeof.EDITOR_LINE_DATA]
  425.         mov     ecx,[cur_editor.Lines]
  426.         add     ecx,[cur_editor.Lines.Size] ;*** add ecx,[ecx-4]
  427.         sub     ecx,esi
  428.         cld
  429.         rep     movsb
  430.         mov     eax,[sel.end.y]
  431.         sub     eax,[sel.begin.y]
  432.         sub     [cur_editor.Lines.Count],eax
  433.         jmp     .exit
  434.  
  435.   .single_line:
  436.         call    get_line_offset
  437.         and     [esi+EDITOR_LINE_DATA.Flags],not EDITOR_LINE_FLAG_SAVED
  438.         or      [esi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
  439.         call    get_real_length
  440.         cmp     eax,[sel.begin.x]
  441.         jbe     .exit
  442.         mov     ecx,[sel.end.x]
  443.         cmp     ecx,eax
  444.         jbe     @f
  445.         mov     ecx,eax
  446.     @@: sub     ecx,[sel.begin.x]
  447.         sub     [esi+EDITOR_LINE_DATA.Size],ecx
  448.         lea     edi,[esi+sizeof.EDITOR_LINE_DATA]
  449.         add     edi,[sel.begin.x]
  450.         lea     esi,[edi+ecx]
  451.         mov     ecx,[cur_editor.Lines]
  452.         add     ecx,[cur_editor.Lines.Size] ;*** add ecx,[ecx-4]
  453.         sub     ecx,esi
  454.         cld
  455.         rep     movsb
  456.  
  457.   .exit:
  458.         mov     eax,[sel.begin.x]
  459.         mov     [cur_editor.Caret.X],eax
  460.         mov     [cur_editor.SelStart.X],eax
  461.         mov     eax,[sel.begin.y]
  462.         mov     [cur_editor.Caret.Y],eax
  463.         mov     [cur_editor.SelStart.Y],eax
  464.  
  465.         mov     ecx,[cur_editor.Lines.Count]
  466.         call    get_line_offset
  467.         mov     eax,[esi+EDITOR_LINE_DATA.Size]
  468.         lea     esi,[esi+eax+sizeof.EDITOR_LINE_DATA]
  469.         mov     eax,[cur_editor.Lines]
  470.         add     eax,[cur_editor.Lines.Size] ;*** add eax,[eax-4]
  471.         sub     esi,eax
  472.         lea     eax,[esi+4096]
  473.         call    editor_realloc_lines
  474.  
  475.         popad
  476.         mov     [cur_editor.Modified],1
  477.         clc
  478.         ret
  479.  
  480.   .exit.2:
  481.         stc
  482.         ret
  483. endp
  484.  
  485. ;-----------------------------------------------------------------------------
  486. proc get_selection_size ;/////////////////////////////////////////////////////
  487. ;-----------------------------------------------------------------------------
  488.         push    ecx esi
  489.         mov     ecx,[sel.end.y]
  490.         inc     ecx
  491.         call    get_line_offset
  492.         mov     eax,esi
  493.         mov     ecx,[sel.begin.y]
  494.         call    get_line_offset
  495.         sub     eax,esi
  496.         pop     esi ecx
  497.         ret
  498. endp
  499.  
  500. ;-----------------------------------------------------------------------------
  501. proc get_lines_in_file ;//////////////////////////////////////////////////////
  502. ;-----------------------------------------------------------------------------
  503. ; Input:
  504. ;  ESI = data pointer
  505. ;  ECX = data length
  506. ; Output:
  507. ;  EAX = lines number
  508. ;  EBX = extra length after tabs expansion
  509. ;-----------------------------------------------------------------------------
  510.         push    ecx edx esi 0
  511.         or      ebx,-1
  512.         xor     edx,edx
  513.   .lp0: inc     ebx
  514.   .lp1: dec     ecx
  515.         jle     .lp2
  516.         lodsb
  517.         cmp     al,0
  518.         je      .lp2
  519.         cmp     al,9
  520.         je      .TB
  521.         cmp     al,10
  522.         je      .LF
  523.         cmp     al,13
  524.         je      .CR
  525.         inc     edx
  526.         jmp     .lp1
  527.   .lp2: lea     eax,[ebx+1]
  528.         pop     ebx esi edx ecx
  529.         ret
  530.  
  531.    .CR: cmp     byte[esi],10
  532.         jne     .LF
  533.         lodsb
  534.    .LF: xor     edx,edx
  535.         jmp     .lp0
  536.    .TB: and     edx,00000111b
  537.         add     dword[esp],ATABW
  538.         sub     [esp],edx
  539.         xor     edx,edx
  540.         jmp     .lp1
  541. endp
  542.  
  543. ;-----------------------------------------------------------------------------
  544. proc update_caption ;/////////////////////////////////////////////////////////
  545. ;-----------------------------------------------------------------------------
  546.         lea     esi,[cur_editor.FilePath]
  547.         mov     edi,s_title
  548.  
  549.         xor     ecx,ecx
  550.     @@: lodsb
  551.         cmp     al,0
  552.         je      @f
  553.         stosb
  554.         inc     ecx
  555.         jmp     @b
  556.     @@:
  557.         push    ecx
  558.         mov     dword[edi],' - '
  559.         add     edi,3
  560.         mov     esi,htext
  561.         mov     ecx,htext.size
  562.         cld
  563.         rep     movsb
  564.  
  565.         mov     al,0
  566.         stosb
  567.  
  568.         mcall   71,1,s_title
  569.  
  570.         cmp     [do_not_draw],0
  571.         jne     @f
  572.         lea     esi,[cur_editor.FilePath]
  573.         mov     edi,tb_opensave.text
  574.         mov     ecx,[esp]
  575.         cld
  576.         rep     movsb
  577.         pop     ecx
  578.         mov     [tb_opensave.length],cl
  579.         clc
  580.         ret
  581.     @@:
  582.         add     esp,4
  583.         clc
  584.         ret
  585. endp
  586.  
  587.