Subversion Repositories Kolibri OS

Rev

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

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