Subversion Repositories Kolibri OS

Rev

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

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