Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
  4. ;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
  5. ;; Distributed under terms of the GNU General Public License    ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. $Revision: 593 $
  9.  
  10.  
  11. max_buttons=4095
  12. dececx:
  13.     push edx
  14.     push ecx
  15.  
  16.     mov  edx,2
  17.   .loop:
  18.  
  19.     cmp   byte [esp+edx],0x20
  20.     jae   @f
  21.     mov   [esp+edx],byte 0x20
  22.    @@:
  23.     sub   [esp+edx],byte 0x20
  24.  
  25.     dec  edx
  26.     jns  .loop
  27.  
  28.     pop  ecx
  29.     pop  edx
  30.     ret
  31.  
  32. incecx:
  33.     push edx
  34.     push ecx
  35.  
  36.     mov  edx,2
  37.   .loop:
  38.  
  39.     cmp  byte [esp+edx],0xdf
  40.     jbe  @f
  41.     mov  [esp+edx],byte 0xdf
  42.    @@:
  43.     add  [esp+edx],byte 0x20
  44.  
  45.     dec  edx
  46.     jns  .loop
  47.     pop  ecx
  48.     pop  edx
  49.     ret
  50.  
  51. incecx2:
  52.     push edx
  53.     push ecx
  54.  
  55.     mov  edx,2
  56.   .loop:
  57.  
  58.     cmp  byte [esp+edx],0xeb
  59.     jbe  @f
  60.     mov  [esp+edx],byte 0xeb
  61.    @@:
  62.     add  [esp+edx],byte 0x14
  63.  
  64.     dec  edx
  65.     jns  .loop
  66.     pop  ecx
  67.     pop  edx
  68.     ret
  69.  
  70. drawbuttonframes:
  71.  
  72.         push  esi
  73.         push  edi
  74.         push  eax
  75.         push  ebx
  76.         push  ecx
  77.         push  edx
  78.  
  79.         shr   eax,16
  80.         shr   ebx,16
  81.         mov   edx,[TASK_BASE]
  82.  
  83.                 add   eax,[edx-twdw + WDATA.box.left]
  84.                 add   ebx,[edx-twdw + WDATA.box.top]
  85.         mov   cx,ax
  86.         mov   dx,bx
  87.         shl   eax,16
  88.         shl   ebx,16
  89.         mov   ax,cx
  90.         mov   bx,dx
  91.         add   ax,word [esp+12]
  92.         mov   esi,ebx
  93.         mov   edi,0
  94.         mov   ecx,[esp+0]
  95.         call  incecx
  96.         call  [draw_line]
  97.  
  98.         movzx edx,word [esp+8]
  99.         add   ebx,edx
  100.         shl   edx,16
  101.         add   ebx,edx
  102.         mov   ecx,[esp+0]
  103.         call  dececx
  104.         call  [draw_line]
  105.  
  106.         mov   ebx,esi
  107.         push  edx
  108.         mov   edx,eax
  109.         shr   edx,16
  110.         mov   ax,dx
  111.         mov   edx,ebx
  112.         shr   edx,16
  113.         mov   bx,dx
  114.         mov   dx,[esp+8+4]
  115.         add   bx,dx
  116.         pop   edx
  117.         mov   edi,0
  118.         mov   ecx,[esp+0]
  119.         call  incecx
  120.         call  [draw_line]
  121.  
  122.         mov   esi,edx
  123.         mov   dx,[esp+12]
  124.         add   ax,dx
  125.         shl   edx,16
  126.         add   eax,edx
  127.         add   ebx,1*65536
  128.         mov   edx,esi
  129.         mov   ecx,[esp+0]
  130.         call  dececx
  131.         call  [draw_line]
  132.  
  133.         pop   edx
  134.         pop   ecx
  135.         pop   ebx
  136.         pop   eax
  137.         pop   edi
  138.         pop   esi
  139.  
  140.         ret
  141.  
  142. button_dececx:
  143.  
  144.         cmp   [buttontype],dword 1
  145.         jne   .finish
  146. ;        je    bdece
  147. ;        ret
  148. ;      bdece:
  149.         push  eax
  150.         mov   eax,0x01
  151.         cmp   edi,20
  152.         jg    @f
  153.         mov   eax,0x02
  154.       @@:
  155.         test  ecx,0xff
  156.         jz    @f
  157.         sub   ecx,eax
  158.       @@:
  159.         shl   eax,8
  160.         test  ecx,0xff00
  161.         jz    @f
  162.         sub   ecx,eax
  163.       @@:
  164.         shl   eax,8
  165.         test  ecx,0xff0000
  166.         jz    @f
  167.         sub   ecx,eax
  168.       @@:
  169.         pop    eax
  170.       .finish:
  171.         ret
  172.  
  173.  
  174. sys_button:
  175.  
  176.         push    edi
  177.         mov     edi,[current_slot]
  178.         rol     eax,16
  179.         add     ax,word[edi+APPDATA.wnd_clientbox.left]
  180.         rol     eax,16
  181.         rol     ebx,16
  182.         add     bx,word[edi+APPDATA.wnd_clientbox.top]
  183.         rol     ebx,16
  184.         pop     edi
  185. .forced:
  186.  
  187.         test  ecx,0x80000000
  188.         jnz   remove_button
  189.  
  190.         push  esi
  191.         push  edi
  192.         push  eax ; <x,xs>
  193.         push  ebx ; <y,ys>
  194.         push  ecx ; <id>
  195.         push  edx
  196.  
  197.         or    ax,ax
  198.         jle   noaddbutt
  199.         or    bx,bx
  200.         jle   noaddbutt
  201.  
  202.         test  ecx,0x40000000
  203.         jnz   button_no_draw
  204.  
  205.         pushad                       ; button body
  206.         push  ebx
  207.         shr   eax,16
  208.         shr   ebx,16
  209.         mov   edx,[TASK_BASE]
  210.         mov   esi,[edx-twdw + WDATA.box.left]
  211.         mov   edi,[edx-twdw + WDATA.box.top]
  212.         add   eax,esi
  213.         add   ebx,edi
  214.         mov   cx,ax
  215.         mov   dx,bx
  216.         shl   eax,16
  217.         shl   ebx,16
  218.         mov   ax,cx
  219.         mov   bx,dx
  220.         movzx ecx,word [4+32+esp+12]
  221.         add   eax,ecx
  222.         mov   ecx,[4+32+esp+0]
  223.         cmp   [buttontype],dword 0
  224.         je    @f
  225.         call  incecx2
  226.        @@:
  227.         movzx edi,word [esp]
  228.  
  229.         pop   edx
  230.         and   edx, 0xFFFF
  231.  
  232. .newline:
  233.         call  button_dececx
  234.         push  edi
  235.         xor   edi, edi
  236.         call  [draw_line]
  237.         pop   edi
  238.         add   ebx,1*65536+1   ; [ y start | y end ]
  239.         dec   edx
  240.         jnz   .newline
  241.         popad
  242.  
  243.         call  drawbuttonframes
  244.  
  245. button_no_draw:
  246.  
  247.         and   ecx,0xffff
  248.  
  249.         mov   edi,[BTN_ADDR]
  250.         movzx eax,word [edi]
  251.         cmp   eax,max_buttons
  252.         jge   noaddbutt
  253.         inc   eax
  254.         mov   [edi],ax
  255.  
  256.         shl   eax,4
  257.         add   eax,edi
  258.  
  259.         mov   bx,[CURRENT_TASK]
  260.         mov   [eax],bx
  261.  
  262.         add   eax,2         ; save button id number
  263.         mov   ebx,[esp+4]
  264.         mov   [eax],bx      ; bits 0-15
  265.         shr   ebx,16
  266.         mov   [eax-2+0xc],bx; bits 16-31
  267.         add   eax,2         ; x start
  268.         mov   bx,[esp+12+2]
  269.         mov   [eax],bx
  270.         add   eax,2         ; x size
  271.         mov   bx,[esp+12+0]
  272.         mov   [eax],bx
  273.         add   eax,2         ; y start
  274.         mov   bx,[esp+8+2]
  275.         mov   [eax],bx
  276.         add   eax,2         ; y size
  277.         mov   bx,[esp+8+0]
  278.         mov   [eax],bx
  279.  
  280. noaddbutt:
  281.  
  282.         pop   edx
  283.         pop   ecx
  284.         pop   ebx
  285.         pop   eax
  286.         pop   edi
  287.         pop   esi
  288.  
  289.         ret
  290.  
  291.  
  292. remove_button:
  293.  
  294.     and  ecx,0x7fffffff
  295.  
  296. rnewba2:
  297.  
  298.     mov   edi,[BTN_ADDR]
  299.     mov   eax,edi
  300.     movzx ebx,word [edi]
  301.     inc   bx
  302.  
  303. rnewba:
  304.  
  305.     dec   bx
  306.     jz    rnmba
  307.  
  308.     add   eax,0x10
  309.  
  310.     mov   dx,[CURRENT_TASK]
  311.     cmp   dx,[eax]
  312.     jnz   rnewba
  313.  
  314.     cmp   cx,[eax+2]
  315.     jnz   rnewba
  316.  
  317.     pushad
  318.     mov   ecx,ebx
  319.     inc   ecx
  320.     shl   ecx,4
  321.     mov   ebx,eax
  322.     add   eax,0x10
  323.     call  memmove
  324.     dec   dword [edi]
  325.     popad
  326.  
  327.     jmp   rnewba2
  328.  
  329. rnmba:
  330.  
  331.     ret
  332.  
  333. find_pressed_button_frames:
  334.  
  335.         pushad
  336.  
  337.         movzx ebx,word [eax+0]
  338.         shl   ebx,5
  339.         add   ebx,window_data
  340.         mov   ecx, [ebx+ WDATA.box.left]     ; window x start
  341.         movzx edx,word [eax+4]     ; button x start
  342.         add   ecx,edx
  343.         push  ecx
  344.  
  345.         mov   dx,[eax+6]                 ; button x size
  346.         add   cx,dx
  347.         mov   esi,ecx
  348.         inc   esi
  349.         mov   ecx, [ebx+WDATA.box.top]   ; window y start
  350.         mov   dx,[eax+8]                 ; button y start
  351.         add   ecx,edx
  352.         mov   ebx,ecx
  353.                 mov   dx,[eax+10]                ; button y size
  354.         add   dx,cx
  355.         inc   dx
  356.  
  357.         pop   eax
  358.  
  359.         ; eax x beginning
  360.         ; ebx y beginning
  361.         ; esi x end
  362.         ; edx y end
  363.         ; ecx color
  364.  
  365.         mov   [pressed_button_eax],eax
  366.         mov   [pressed_button_ebx],ebx
  367.         mov   [pressed_button_ecx],ecx
  368.         mov   [pressed_button_edx],edx
  369.         mov   [pressed_button_esi],esi
  370.  
  371.         popad
  372.         ret
  373.  
  374. uglobal
  375.   pressed_button_eax  dd  0
  376.   pressed_button_ebx  dd  0
  377.   pressed_button_ecx  dd  0
  378.   pressed_button_edx  dd  0
  379.   pressed_button_esi  dd  0
  380. endg
  381.  
  382. ; negative button image
  383.  
  384. negativebutton:
  385.         ; If requested, do not display button
  386.         ; boarder on press.
  387.         test  ebx,0x20000000
  388.         jz    draw_negative_button
  389.         ret
  390.       draw_negative_button:
  391.  
  392.         pushad
  393.  
  394.         mov   eax,[pressed_button_eax]
  395.         mov   ebx,[pressed_button_ebx]
  396.         mov   ecx,[pressed_button_ecx]
  397.         mov   edx,[pressed_button_edx]
  398.         mov   esi,[pressed_button_esi]
  399.         mov   ecx,0x01000000
  400.  
  401.         dec   edx
  402.         push  edx
  403.         inc   edx
  404.         dec   esi
  405.         push  esi
  406.         inc   esi
  407.  
  408.         push  eax
  409.         push  ebx
  410.         push  ecx
  411.         push  edx
  412.         push  edi
  413.  
  414.         call  [disable_mouse]
  415.  
  416.       bdbnewline:
  417.         mov   edi,1    ; force
  418.         cmp   eax,[esp+16]
  419.         jz    bneg
  420.         cmp   eax,[esp+20]
  421.         jz    bneg
  422.         cmp   ebx,[esp+12]
  423.         jz    bneg
  424.         cmp   ebx,[esp+24]
  425.         jnz   nbneg
  426. ;        jz    bneg
  427. ;        jmp   nbneg
  428.  
  429.       bneg:
  430.  
  431.         ;;;call  [disable_mouse]
  432.         call  [putpixel]
  433.  
  434.       nbneg:
  435.  
  436.         inc   eax
  437.         cmp   eax,esi
  438.         jnz   bdbnewline
  439.         mov   eax,[esp+16]
  440.         inc   ebx
  441.         cmp   ebx,edx
  442.         jnz   bdbnewline
  443.  
  444.         add   esp,28
  445.  
  446.         popad
  447.  
  448.         ret
  449.  
  450. ; check buttons
  451.  
  452.  
  453. ; 0000 word process number
  454. ; 0002 word button id number : bits 0-15
  455. ; 0004 word x start
  456. ; 0006 word x size
  457. ; 0008 word y start
  458. ; 000A word y size
  459. ; 000C word button id number : bits 16-31
  460. ;
  461. ; button table in 0x10 increments
  462. ;
  463. ; first at 0x10
  464.  
  465.  
  466. checkbuttons:
  467.  
  468.     cmp   [BTN_DOWN],byte 0    ; mouse buttons pressed
  469.     jnz   @f
  470. ;..................................... start 1/5 : modified by vhanla .............................
  471.     mov [bPressedMouseXY_B],0
  472. ;..................................... end 1/5 : modified by vhanla .............................
  473.     ret
  474.   @@:
  475.     pushad
  476.  
  477.     xor    esi, esi
  478.     mov    edi, [BTN_ADDR]
  479.     movzx  edx, word [edi]
  480.     test   edx, edx
  481.     jne    @f
  482.     popad
  483.     ret
  484.  
  485.   @@:
  486. ;..................................... start 2/5 : modified by vhanla .............................
  487.   ;here i catch the coordinates when the mouse's button is clicked
  488.    push ax
  489.    cmp [bPressedMouseXY_B],0;FALSE
  490.    jnz @f
  491.    mov [bPressedMouseXY_B],1;TRUE - it was already clicked
  492.    mov ax,[MOUSE_X]
  493.    mov [mx],ax
  494.    mov ax,[MOUSE_Y]
  495.    mov [my],ax
  496.    @@:
  497.    pop  ax
  498.    ;and it is only refreshed after the mouse's button release
  499. ;..................................... end 2/5 : modified by vhanla .............................
  500.  
  501.     push  esi
  502.     inc   edx
  503.     push  edx
  504.  
  505.   buttonnewcheck:
  506.  
  507.     pop   edx
  508.     pop   esi
  509.     inc   esi
  510.     cmp   edx,esi
  511.     jge   bch
  512.  
  513.     popad                 ; no button pressed
  514.     ret
  515.  
  516.   bch:
  517.  
  518.     push  esi
  519.     push  edx
  520.     mov   eax,esi
  521.     shl   eax,4
  522.     add   eax,edi
  523.  
  524.     ; check that button is at top of windowing stack
  525.  
  526.     movzx ebx,word [eax]
  527.     movzx ecx,word [WIN_STACK + ebx * 2]
  528.     cmp   ecx,[TASK_COUNT]
  529.     jne   buttonnewcheck
  530.  
  531.     ; check that button start is inside window x/y end
  532.  
  533.     movzx ebx,word [eax+0]
  534.     shl   ebx,5
  535.  
  536.         test    [ebx+window_data+WDATA.fl_wstate],WSTATE_MINIMIZED
  537.         jnz     buttonnewcheck
  538.  
  539. ;    add   ebx,window_data
  540. ;    mov   ecx,[window_data+ebx+8]          ; window end X
  541.     movzx edx,word [eax+4]     ; button start X
  542.     cmp   edx, [window_data+ebx+WDATA.box.width] ;ecx
  543.     jge   buttonnewcheck
  544.  
  545. ;    mov   ecx,[window_data+ebx+12]         ; window end Y
  546.     movzx edx, word [eax+8]    ; button start Y
  547.     cmp   edx, [window_data+ebx+WDATA.box.height] ;ecx
  548.     jge   buttonnewcheck
  549.  
  550.     ; check coordinates
  551.                                ; mouse x >= button x ?
  552.     movzx ebx,word [eax+0]
  553.     shl   ebx,5
  554.     add   ebx,window_data
  555.         mov   ecx, [ebx+WDATA.box.left]     ; window x start
  556.     movzx edx,word [eax+4]     ; button x start
  557.     add   edx,ecx
  558. ;..................................... start 3/5 : modified by vhanla .............................
  559.     mov   cx,[mx]   ;mov cx,[MOUSE_X]
  560. ;..................................... end 3/5 : modified by vhanla .............................
  561.     cmp   edx,ecx
  562.     jg    buttonnewcheck
  563.  
  564.     movzx ebx,word [eax+6]     ; button x size
  565.     add   edx,ebx
  566.     cmp   ecx,edx
  567.     jg    buttonnewcheck
  568.  
  569.                                ; mouse y >= button y ?
  570.     movzx ebx,word [eax+0]
  571.     shl   ebx,5
  572.     add   ebx,window_data
  573.         mov   ecx, [ebx+WDATA.box.top]     ; window y start
  574.     movzx edx,word [eax+8]     ; button y start
  575.     add   edx,ecx
  576. ;..................................... start 4/5 : modified by vhanla .............................
  577.     mov   cx,[my]  ;mov cx,[MOUSE_Y]
  578. ;..................................... start 4/5 : modified by vhanla .............................
  579.     cmp   edx,ecx
  580.     jg    buttonnewcheck
  581.  
  582.     movzx ebx,word [eax+10]    ; button y size
  583.     add   edx,ebx
  584.     cmp   ecx,edx
  585.     jg    buttonnewcheck
  586.  
  587.     ; mouse on button
  588.  
  589.     pop   edx
  590.     pop   esi
  591.  
  592.     mov   bx,[eax+0xc]     ; button id : bits 16-31
  593.     shl   ebx,16
  594.     mov   bx,[eax+2]       ; button id : bits 00-16
  595.     push  ebx
  596.  
  597.     mov   [MOUSE_DOWN],byte 1  ; no mouse down checks
  598.     call find_pressed_button_frames
  599.     call negativebutton
  600.  
  601.     pushad
  602.   cbwaitmouseup:
  603.  
  604.     call  checkidle
  605.  
  606.     call  [draw_pointer]
  607.  
  608.     pushad
  609.     call  stack_handler
  610.     popad
  611.  
  612.     cmp   [BTN_DOWN],byte 0  ; mouse buttons pressed ?
  613.     jnz   cbwaitmouseup
  614.     popad
  615.  
  616.     call  negativebutton
  617.     mov   [MOUSE_BACKGROUND],byte 0  ; no mouse background
  618.     mov   [DONT_DRAW_MOUSE],byte 0  ; draw mouse
  619. ;..................................... start 5/5 : modified by vhanla .............................
  620.     ; check coordinates
  621.     jmp @f
  622.     mx dw 0x0 ; keeps the x mouse's position when it was clicked
  623.     my dw 0x0 ; keeps the y mouse's position when it was clicked
  624.     bPressedMouseXY_B db 0x0
  625.     @@:
  626.  
  627.    pusha
  628.   ; mouse x >= button x ?
  629.    movzx ebx,word [eax+0]
  630.    shl   ebx,5
  631.    add   ebx,window_data
  632.    mov   ecx, [ebx+WDATA.box.left]    ; window x start
  633.    movzx edx,word [eax+4]    ; button x start
  634.    add   edx,ecx
  635.    mov   cx,[MOUSE_X]
  636.    cmp   edx,ecx
  637.    jg   no_on_button ;if we release the pointer out of the button area
  638.  
  639.    movzx ebx,word [eax+6]    ; button x size
  640.    add   edx,ebx
  641.    cmp   ecx,edx
  642.    jg   no_on_button
  643.  
  644.         ; mouse y >= button y ?
  645.    movzx ebx,word [eax+0]
  646.    shl   ebx,5
  647.    add   ebx,window_data
  648.    mov   ecx, [ebx+WDATA.box.top]    ; window y start
  649.    movzx edx,word [eax+8]    ; button y start
  650.    add   edx,ecx
  651.    mov   cx,[MOUSE_Y]
  652.    cmp   edx,ecx
  653.    jg   no_on_button
  654.  
  655.    movzx ebx,word [eax+10]   ; button y size
  656.    add   edx,ebx
  657.    cmp   ecx,edx
  658.    jg   no_on_button
  659.    popa
  660.    mov   [BTN_COUNT],byte 1 ; no of buttons in buffer
  661.    pop   ebx
  662.    mov   [BTN_BUFF],ebx   ; lets put the button id in buffer
  663.    push  ebx
  664.    pusha
  665.    jmp yes_on_button
  666. no_on_button:
  667.    mov   [BTN_COUNT],byte 0 ; no of buttons in buffer
  668. yes_on_button:
  669.    mov   [MOUSE_DOWN],byte 0 ; mouse down -> do not draw
  670.    popa
  671.    pop ebx
  672.    popa
  673.    ret
  674.  
  675. ;..................................... end 5/5 : modified by vhanla ................................
  676.