Subversion Repositories Kolibri OS

Rev

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

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