Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2009. 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.  
  9. $Revision: 1300 $
  10.  
  11.  
  12. get_titlebar_height: ; edi = window draw_data pointer
  13.         mov     al,[edi+WDATA.fl_wstyle]
  14.         and     al,0x0F
  15.         cmp     al,0x03
  16.         jne     @f
  17.         mov     eax,[_skinh]
  18.         ret
  19.     @@: mov     eax,21
  20.         ret
  21.  
  22. get_rolledup_height: ; edi = window draw_data pointer
  23.         mov     al,[edi+WDATA.fl_wstyle]
  24.         and     al,0x0F
  25.         cmp     al,0x03
  26.         jb      @f
  27.         mov     eax,[_skinh]
  28.         add     eax,3
  29.         ret
  30.     @@: or      al,al
  31.         jnz     @f
  32.         mov     eax,21
  33.         ret
  34.     @@: mov     eax,21+2
  35.         ret
  36.  
  37.  
  38. setwindowdefaults:
  39.         pushad
  40.  
  41.         xor   eax,eax
  42.         mov   ecx,WIN_STACK
  43.        @@:
  44.         inc   eax
  45.         add   ecx,2
  46.         mov   [ecx+0x000],ax          ; process no
  47.         mov   [ecx+0x400],ax          ; positions in stack
  48.         cmp   ecx,WIN_POS-2            ; the more high, the more surface
  49.         jnz   @b
  50.  
  51.         popad
  52.         ret
  53.  
  54.  
  55.  
  56. ; eax = cx
  57. ; ebx = cy
  58. ; ecx = ex
  59. ; edx = ey
  60. ; èäåÿ: ïåðåáðàòü âñå îêíà, íà÷èíàÿ ñ ñàìîãî íèæíåãî,
  61. ;       è äëÿ ïîïàâøèõ â çàäàííóþ îáëàñòü
  62. ;       ÷àñòåé îêîí âûçâàòü setscreen
  63. align 4
  64. calculatescreen:
  65.         pushad
  66.         pushfd
  67.         cli
  68.  
  69.         push    edx ecx ebx eax
  70.  
  71.         mov     esi, 1
  72.         call    setscreen
  73.  
  74.         mov     ebp, [TASK_COUNT]        ; number of processes
  75.         cmp     ebp, 1
  76.         jbe     .finish
  77.         align 4
  78.       .new_wnd:
  79.         movzx   edi, word [WIN_POS + esi * 2]
  80.         shl     edi, 5
  81.  
  82.         cmp     [CURRENT_TASK+edi+TASKDATA.state], byte 9
  83.         je      .not_wnd
  84.  
  85.         add     edi, window_data
  86.         test    [edi+WDATA.fl_wstate], WSTATE_MINIMIZED
  87.         jnz     .not_wnd
  88.  
  89.         mov     eax,[edi+WDATA.box.left]
  90.         cmp     eax, [esp+RECT.right]
  91.         ja      .out_of_bounds
  92.         mov     ebx,[edi+WDATA.box.top]
  93.         cmp     ebx, [esp+RECT.bottom]
  94.         ja      .out_of_bounds
  95.         mov     ecx,[edi+WDATA.box.width]
  96.         add     ecx, eax
  97.         cmp     ecx, [esp+RECT.left]
  98.         jb      .out_of_bounds
  99.         mov     edx,[edi+WDATA.box.height]
  100.         add     edx, ebx
  101.         cmp     edx, [esp+RECT.top]
  102.         jb      .out_of_bounds
  103.  
  104.     cmp     eax, [esp+RECT.left]
  105.         jae     @f
  106.         mov     eax, [esp+RECT.left]
  107.      @@:
  108.     cmp     ebx, [esp+RECT.top]
  109.         jae     @f
  110.         mov     ebx, [esp+RECT.top]
  111.      @@:
  112.     cmp     ecx, [esp+RECT.right]
  113.         jbe     @f
  114.         mov     ecx, [esp+RECT.right]
  115.      @@:
  116.     cmp     edx, [esp+RECT.bottom]
  117.         jbe     @f
  118.         mov     edx, [esp+RECT.bottom]
  119.      @@:
  120.  
  121.         push    esi
  122.         movzx   esi, word [WIN_POS + esi * 2]
  123.         call    setscreen
  124.         pop     esi
  125.  
  126.       .not_wnd:
  127.       .out_of_bounds:
  128.         inc     esi
  129.         dec     ebp
  130.         jnz     .new_wnd
  131.       .finish:
  132.  
  133.     pop     eax ebx ecx edx
  134.  
  135.         popfd
  136.         popad
  137. ret
  138.  
  139.  
  140.  
  141. virtual at esp
  142.   ff_x     dd ?
  143.   ff_y     dd ?
  144.   ff_width dd ?
  145.   ff_xsz   dd ?
  146.   ff_ysz   dd ?
  147.   ff_scale dd ?
  148. end virtual
  149.  
  150. align 4
  151. ; ðåçåðâèðóåò ìåñòî ïîä îêíî çàäàííîãî ïðîöåññà
  152. setscreen:
  153. ;  eax  x start
  154. ;  ebx  y start
  155. ;  ecx  x end
  156. ;  edx  y end
  157. ;  esi  process number
  158. pushad
  159. ; \begin{diamond}[29.08.2006]
  160.         cmp     esi, 1
  161.         jz      @f
  162.         mov     edi, esi
  163.         shl     edi, 5
  164.         cmp     [edi+window_data+WDATA.box.width], 0
  165.         jnz     @f
  166.         cmp     [edi+window_data+WDATA.box.height], 0
  167.         jz      .ret
  168. @@:
  169. ; \end{diamond}[29.08.2006]
  170.         mov edi, esi ;;;word [esi*2+WIN_POS]
  171.         shl   edi, 8
  172.         add   edi, SLOT_BASE  ; address of random shaped window area
  173.         cmp   [edi+APPDATA.wnd_shape], dword 0
  174.         jne   .free_form
  175.  
  176.         ; get x&y size
  177.         sub   ecx, eax
  178.         sub   edx, ebx
  179.         inc   ecx
  180.         inc   edx
  181.  
  182.         ; get WinMap start
  183.         mov   edi, [Screen_Max_X] ; screen_sx
  184.         inc   edi
  185.         imul  edi, ebx
  186.         add   edi, eax
  187.     add   edi, [_WinMapAddress]
  188.  
  189.   .new_y:
  190.         push  ecx ; sx
  191.         push  edx
  192.  
  193.         mov   edx, esi
  194.         align 4
  195.   .new_x:
  196.         mov   byte [edi], dl
  197.         inc   edi
  198.         dec   ecx
  199.         jnz   .new_x
  200.  
  201.         pop   edx
  202.         pop   ecx
  203.         add   edi, [Screen_Max_X]
  204.         inc   edi
  205.         sub   edi, ecx
  206.         dec   edx
  207.         jnz   .new_y
  208. .ret:
  209.  popad
  210.  ret
  211.   .read_byte:
  212.    ;eax - address
  213.    ;esi - slot
  214.         push  eax
  215.         push  ebx
  216.         push  ecx
  217.         push  edx
  218.         mov   edx,eax
  219.         mov   eax,esi
  220.         lea   ebx,[esp+12]
  221.         mov   ecx,1
  222.         call  read_process_memory
  223.         pop   edx
  224.         pop   ecx
  225.         pop   ebx
  226.         pop   eax
  227.         ret
  228.   .free_form:
  229.  
  230.         ;  for (y=0; y <= x_size; y++)
  231.         ;      for (x=0; x <= x_size; x++)
  232.         ;          if (shape[coord(x,y,scale)]==1)
  233.         ;             set_pixel(x, y, process_number);
  234.  
  235.         sub  ecx, eax
  236.         sub  edx, ebx
  237.         inc  ecx
  238.         inc  edx
  239.  
  240.         push  dword [edi+APPDATA.wnd_shape_scale]  ; push scale first -> for loop
  241.  
  242.         ; get WinMap start  -> ebp
  243.         push  eax
  244.         mov   eax, [Screen_Max_X] ; screen_sx
  245.         inc   eax
  246.         imul  eax, ebx
  247.         add   eax, [esp]
  248.     add   eax, [_WinMapAddress]
  249.         mov   ebp, eax
  250.  
  251.         mov   edi, [edi+APPDATA.wnd_shape]
  252.         pop   eax
  253.  
  254.         ; eax = x_start
  255.         ; ebx = y_start
  256.         ; ecx = x_size
  257.         ; edx = y_size
  258.         ; esi = process_number
  259.         ; edi = &shape
  260.         ;       [scale]
  261.         push edx ecx ; for loop - x,y size
  262.  
  263.         mov  ecx, esi
  264.         shl  ecx, 5
  265.         mov  edx, [window_data+ecx+WDATA.box.top]
  266.         push [window_data+ecx+WDATA.box.width]      ; for loop - width
  267.         mov  ecx, [window_data+ecx+WDATA.box.left]
  268.         sub  ebx, edx
  269.         sub  eax, ecx
  270.         push ebx eax ; for loop - x,y
  271.  
  272.         add  [ff_xsz], eax
  273.         add  [ff_ysz], ebx
  274.  
  275.         mov  ebx, [ff_y]
  276.  
  277.       .ff_new_y:
  278.         mov  edx, [ff_x]
  279.  
  280.       .ff_new_x:
  281.         ; -- body --
  282.         mov  ecx, [ff_scale]
  283.         mov  eax, [ff_width]
  284.         inc  eax
  285.         shr  eax, cl
  286.         push ebx edx
  287.         shr  ebx, cl
  288.         shr  edx, cl
  289.         imul eax, ebx
  290.         add  eax, edx
  291.         pop  edx ebx
  292.         add  eax, edi
  293.         call .read_byte
  294.         test al,al
  295.         jz   @f
  296.         mov  eax, esi
  297.         mov  [ebp], al
  298.        @@:
  299.         ; -- end body --
  300.         inc  ebp
  301.         inc  edx
  302.         cmp  edx, [ff_xsz]
  303.         jb   .ff_new_x
  304.         sub  ebp, [ff_xsz]
  305.         add  ebp, [ff_x]
  306.         add  ebp, [Screen_Max_X]  ; screen.x
  307.         inc  ebp
  308.         inc  ebx
  309.         cmp  ebx, [ff_ysz]
  310.         jb   .ff_new_y
  311.  
  312.         add  esp, 24
  313. popad
  314. ret
  315.  
  316.  
  317. display_settings:
  318.  
  319. ;    eax = 0         ; DISPLAY redraw
  320. ;          ebx = 0   ; all
  321. ;
  322. ;    eax = 1         ; BUTTON type
  323. ;          ebx = 0   ; flat
  324. ;          ebx = 1   ; 3D
  325. ;    eax = 2         ; set WINDOW colours
  326. ;          ebx = pointer to table
  327. ;          ecx = number of bytes define
  328. ;    eax = 3         ; get WINDOW colours
  329. ;          ebx = pointer to table
  330. ;          ecx = number of bytes wanted
  331. ;    eax = 4         ; get skin height
  332. ;          input  : nothing
  333. ;          output : eax = skin height in pixel
  334. ;    eax = 5         ; get screen workarea
  335. ;          input  : nothing
  336. ;          output : eax = [left]*65536+[right]
  337. ;                   ebx = [top]*65536+[bottom]
  338. ;    eax = 6         ; set screen workarea
  339. ;          input  : ecx = [left]*65536+[right]
  340. ;                   edx = [top]*65536+[bottom]
  341. ;          output : nothing
  342. ;    eax = 7         ; get skin margins
  343. ;          input  : nothing
  344. ;          output : eax = [left]*65536+[right]
  345. ;                   ebx = [top]*65536+[bottom]
  346. ;    eax = 8         ; set window skin
  347. ;          input  : ecx = pointer to file info block
  348. ;          output : eax = FS error code
  349.  
  350.  
  351.      pushad
  352.  
  353.      test eax, eax      ; redraw display
  354.      jnz  dspl0
  355.      test ebx, ebx
  356.      jnz  dspl0
  357.      cmp  [windowtypechanged],dword 1
  358.      jne  dspl00
  359.      mov  [windowtypechanged],dword 0
  360.   redraw_screen_direct:
  361.      mov  [dlx],dword 0
  362.      mov  [dly],dword 0
  363.      mov  eax,[Screen_Max_X]
  364.      mov  [dlxe],eax
  365.      mov  eax,[Screen_Max_Y]
  366.      mov  [dlye],eax
  367.      mov  eax,window_data
  368.      call redrawscreen
  369.    dspl00:
  370.      popad
  371.      ret
  372.    dspl0:
  373.  
  374.      cmp  eax,1       ; button type
  375.      jne  dspl1
  376.      and  ebx,1
  377.      cmp  ebx,[buttontype]
  378.      je   dspl9
  379.      mov  [buttontype],ebx
  380.      mov  [windowtypechanged],dword 1
  381.     dspl9:
  382.      popad
  383.      ret
  384.    dspl1:
  385.  
  386.      cmp  eax,2       ; set common window colours
  387.      jne  no_com_colours
  388.      mov  [windowtypechanged],dword 1
  389.      mov  esi,[TASK_BASE]
  390.      add  esi,TASKDATA.mem_start
  391.      add  ebx,[esi]
  392.      mov  esi,ebx
  393.      mov  edi,common_colours
  394.      and  ecx,127
  395.      cld
  396.      rep  movsb
  397.      popad
  398.      ret
  399.    no_com_colours:
  400.  
  401.      cmp  eax,3       ; get common window colours
  402.      jne  no_get_com
  403.      mov  esi,[TASK_BASE]
  404.      add  esi,TASKDATA.mem_start
  405.      add  ebx,[esi]
  406.      mov  edi,ebx
  407.      mov  esi,common_colours
  408.      and  ecx,127
  409.      cld
  410.      rep  movsb
  411.      popad
  412.      ret
  413.    no_get_com:
  414.  
  415.      cmp  eax,4       ; get skin height
  416.      jne  no_skin_height
  417.      popad
  418.      mov  eax,[_skinh]
  419.      mov  [esp+36],eax
  420.      ret
  421.    no_skin_height:
  422.  
  423.         cmp     eax,5       ; get screen workarea
  424.         jne     no_get_workarea
  425.         popad
  426.         mov     eax,[screen_workarea.left-2]
  427.         mov     ax,word[screen_workarea.right]
  428.         mov     [esp+36],eax
  429.         mov     eax,[screen_workarea.top-2]
  430.         mov     ax,word[screen_workarea.bottom]
  431.         mov     [esp+24],eax
  432.         ret
  433.    no_get_workarea:
  434.  
  435.         cmp     eax,6       ; set screen workarea
  436.         jne     no_set_workarea
  437.         movsx   eax,word[esp+16+2]
  438.         movsx   ebx,word[esp+16]
  439.         cmp     eax,ebx
  440.         jge     .lp1
  441.         or      eax,eax;[Screen_Max_X]
  442.         jl      @f
  443.         mov     [screen_workarea.left],eax
  444.     @@: cmp     ebx,[Screen_Max_X]
  445.         jg      .lp1
  446.         mov     [screen_workarea.right],ebx
  447.   .lp1: movsx   eax,word[esp+24+2]
  448.         movsx   ebx,word[esp+24]
  449.         cmp     eax,ebx
  450.         jge     .lp2
  451.         or      eax,eax;[0xFE04]
  452.         jl      @f
  453.         mov     [screen_workarea.top],eax
  454.     @@: cmp     ebx,[Screen_Max_Y]
  455.         jg      .lp2
  456.         mov     [screen_workarea.bottom],ebx
  457.   .lp2: call    repos_windows
  458.         mov     eax, 0
  459.         mov     ebx, 0
  460.         mov     ecx, [Screen_Max_X]
  461.         mov     edx, [Screen_Max_Y]
  462.     call    calculatescreen
  463. ;    jmp    redraw_screen_direct
  464.     .exit:
  465.         popad
  466.         ret
  467.    no_set_workarea:
  468.  
  469.         cmp     eax,7       ; get skin margins
  470.         jne     no_get_skinmargins
  471.         popad
  472.         mov     eax,dword[_skinmargins+0]
  473.         mov     [esp+36],eax
  474.         mov     eax,dword[_skinmargins+4]
  475.         mov     [esp+24],eax
  476.         ret
  477.    no_get_skinmargins:
  478.  
  479.         cmp     eax,8       ; set window skin
  480.         jne     no_set_skin
  481.         call    read_skin_file
  482.         mov     [esp+32+36], eax
  483.         test    eax, eax
  484.         jnz     .ret
  485.         xor     eax, eax
  486.         xor     ebx, ebx
  487.         mov     ecx, [Screen_Max_X]
  488.         mov     edx, [Screen_Max_Y]
  489.         call    calculatescreen
  490.         jmp     redraw_screen_direct
  491. .ret:
  492.         popad
  493.         ret
  494.    no_set_skin:
  495.  
  496.      popad
  497.      ret
  498.  
  499.  
  500. repos_windows:
  501.         mov     ecx,[TASK_COUNT]
  502.         mov     edi, window_data+0x20*2
  503.         call    force_redraw_background
  504.         dec     ecx
  505.         jge    @f
  506.         ret
  507.     @@: mov     [edi+WDATA.fl_redraw],1
  508.         test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
  509.         jz      .lp2
  510.         mov     eax,[screen_workarea.left]
  511.         mov     [edi+WDATA.box.left],eax
  512.         sub     eax,[screen_workarea.right]
  513.         neg     eax
  514.         mov     [edi+WDATA.box.width],eax
  515.         mov     eax,[screen_workarea.top]
  516.         mov     [edi+WDATA.box.top],eax
  517.         test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
  518.         jnz     .lp1
  519.         sub     eax,[screen_workarea.bottom]
  520.         neg     eax
  521.         mov     [edi+WDATA.box.height],eax
  522.   .lp1:
  523.  
  524.         call    set_window_clientbox
  525.         add     edi,0x20
  526.         loop    @b
  527.         ret
  528.   .lp2: mov     eax,[edi+WDATA.box.left]
  529.         add     eax,[edi+WDATA.box.width]
  530.     mov    ebx,[Screen_Max_X]
  531. ;    inc    ebx
  532.     cmp    eax,ebx
  533.     jle    .lp4
  534.         mov     eax,[edi+WDATA.box.width]
  535.     sub    eax,ebx
  536.     jle    .lp3
  537.         mov     [edi+WDATA.box.width],ebx
  538.   .lp3: sub     ebx,[edi+WDATA.box.width]
  539.         mov     [edi+WDATA.box.left],ebx
  540.   .lp4: mov     eax,[edi+WDATA.box.top]
  541.         add     eax,[edi+WDATA.box.height]
  542.     mov    ebx,[Screen_Max_Y]
  543. ;    inc    ebx
  544.     cmp    eax,ebx
  545.     jle    .lp6
  546.         mov     eax,[edi+WDATA.box.height]
  547.     sub    eax,ebx
  548.     jle    .lp5
  549.         mov     [edi+WDATA.box.height],ebx
  550.   .lp5: sub     ebx,[edi+WDATA.box.height]
  551.         mov     [edi+WDATA.box.top],ebx
  552.   .lp6: jmp     .lp1
  553.  
  554. uglobal
  555.   common_colours:
  556.      times 128 db 0x0
  557. endg
  558.  
  559.  
  560.  
  561.  
  562. check_window_position:
  563.  
  564.     pushad                           ; window inside screen ?
  565.  
  566.     mov   eax, [edi+WDATA.box.left]
  567.     mov   ebx, [edi+WDATA.box.top]
  568.     mov   ecx, [edi+WDATA.box.width]
  569.     mov   edx, [edi+WDATA.box.height]
  570.  
  571.     cmp   ecx,[Screen_Max_X]          ; check x size
  572.     jbe   x_size_ok
  573.     mov   ecx,[Screen_Max_X]
  574.     mov   [edi+WDATA.box.width],ecx
  575.  
  576.   x_size_ok:
  577.  
  578.     cmp   edx,[Screen_Max_Y]          ; check y size
  579.     jbe   y_size_ok
  580.     mov   edx,[Screen_Max_Y]
  581.     mov   [edi+WDATA.box.height],edx
  582.  
  583.   y_size_ok:
  584.  
  585.     cmp   eax,0       ; check x pos
  586.     jnle  @f
  587.     xor   eax,eax
  588.     mov   [edi+WDATA.box.left],eax
  589.     jmp   x_pos_ok
  590.   @@:
  591.     add   eax,ecx
  592.     cmp   eax,[Screen_Max_X]
  593.     jbe   x_pos_ok
  594.     mov   eax,[Screen_Max_X]
  595.     sub   eax,ecx
  596.     mov   [edi+WDATA.box.left],eax
  597.  
  598.   x_pos_ok:
  599.  
  600.     cmp   ebx,0       ; check x pos
  601.     jnle  @f
  602.     xor   ebx,ebx
  603.     mov   [edi+WDATA.box.top],ebx
  604.     jmp   y_pos_ok
  605.   @@:
  606.     add   ebx,edx
  607.     cmp   ebx,[Screen_Max_Y]
  608.     jbe   y_pos_ok
  609.     mov   ebx,[Screen_Max_Y]
  610.     sub   ebx,edx
  611.     mov   [edi+WDATA.box.top],ebx
  612.  
  613.   y_pos_ok:
  614.  
  615.     popad
  616.  
  617.     ret
  618.  
  619.  
  620. uglobal
  621.   new_window_starting dd 0
  622. endg
  623.  
  624.  
  625. sys_window_mouse:
  626.  
  627.     push  eax
  628.  
  629.     mov   eax,[timer_ticks]
  630.     cmp   [new_window_starting],eax
  631.     jb    swml1
  632.  
  633.     mov   [MOUSE_BACKGROUND],byte 0  ; no mouse background
  634.     mov   [DONT_DRAW_MOUSE],byte 0  ; draw mouse
  635.  
  636.     mov   [new_window_starting],eax
  637.  
  638.   swml1:
  639.  
  640.     pop   eax
  641.  
  642.     ret
  643.  
  644.  
  645.  
  646.  
  647. drawwindow_I_caption:
  648.  
  649.         mov   ecx,[edx+WDATA.cl_titlebar]   ; grab bar
  650.         push  ecx
  651.         mov   esi,edx
  652.         mov   edx,[esi+WDATA.box.top]
  653.         add   edx,1
  654.         mov   ebx,[esi+WDATA.box.top]
  655.         add   ebx,21
  656.         mov   eax,[esi+WDATA.box.top]
  657.         add   eax,[esi+WDATA.box.height]
  658.         cmp   ebx,eax
  659.         jb    .wdsizeok
  660.         mov   ebx,eax
  661.   .wdsizeok:
  662.         push  ebx
  663.   .drwi:
  664.         mov   ebx,edx
  665.         shl   ebx,16
  666.         add   ebx,edx
  667.         mov   eax,[esi+WDATA.box.left]
  668.         inc   eax
  669.         shl   eax,16
  670.         add   eax,[esi+WDATA.box.left]
  671.         add   eax,[esi+WDATA.box.width]
  672.         sub   eax,1
  673.         push  edx
  674.         mov   edx,0x80000000
  675.         mov   ecx,[esi+WDATA.cl_titlebar]
  676.         and   ecx,edx
  677.         cmp   ecx,edx
  678.         jnz   .nofa
  679.         mov   ecx,[esi+WDATA.cl_titlebar]
  680.         sub   ecx,0x00040404
  681.         mov   [esi+WDATA.cl_titlebar],ecx
  682.         and   ecx,0x00ffffff
  683.         jmp   .faj
  684.   .nofa:
  685.         mov   ecx,[esi+WDATA.cl_titlebar]
  686.         and   ecx,0x00ffffff
  687.   .faj:
  688.         pop   edx
  689.         mov   edi,0
  690.         call  [draw_line]
  691.         inc   edx
  692.         cmp   edx,[esp]
  693.         jb    .drwi
  694.         add   esp,4
  695.         pop   ecx
  696.         mov   [esi+WDATA.cl_titlebar],ecx
  697.  
  698.         ret
  699.  
  700.  
  701. drawwindow_I:
  702.  
  703.         pushad
  704.         or      [edx+WDATA.fl_wdrawn], 4
  705.  
  706.         mov   esi,[edx+WDATA.cl_frames]   ; rectangle
  707.         mov   eax,[edx+WDATA.box.left]
  708.         shl   eax,16
  709.         add   eax,[edx+WDATA.box.left]
  710.         add   eax,[edx+WDATA.box.width]
  711.         mov   ebx,[edx+WDATA.box.top]
  712.         shl   ebx,16
  713.         add   ebx,[edx+WDATA.box.top]
  714.         add   ebx,[edx+WDATA.box.height]
  715.         call  draw_rectangle
  716.  
  717.         and     [edx+WDATA.fl_wdrawn], not 4
  718.         test    [edx+WDATA.fl_wdrawn], 2
  719.         jz      @f
  720.         call    drawwindowframes2
  721. @@:
  722.  
  723.         call    drawwindow_I_caption
  724.  
  725.         mov   edx,[esi+WDATA.box.top]      ; inside work area
  726.         add   edx,21+5
  727.         mov   ebx,[esi+WDATA.box.top]
  728.         add   ebx,[esi+WDATA.box.height]
  729.         cmp   edx,ebx
  730.         jg    noinside
  731.         mov   eax,1
  732.         mov   ebx,21
  733.         mov   ecx,[esi+WDATA.box.width]
  734.         mov   edx,[esi+WDATA.box.height]
  735.         mov   edi,[esi+WDATA.cl_workarea]
  736.         test  edi,0x40000000
  737.         jnz   noinside
  738.         call  [drawbar]
  739.       noinside:
  740.  
  741.         popad
  742.  
  743.         ret
  744.  
  745.  
  746. draw_rectangle:
  747.  
  748. r_eax equ [esp+28]   ; x start
  749. r_ax  equ [esp+30]   ; x end
  750. r_ebx equ [esp+16]   ; y start
  751. r_bx  equ [esp+18]   ; y end
  752. ;esi                 ; color
  753.  
  754.         pushad
  755.  
  756.         mov   ecx,esi          ; yb,xb -> yb,xe
  757.         mov   eax, r_eax
  758.         rol   eax, 16
  759.         mov   ebx,r_ebx
  760.         shl   ebx,16
  761.         mov   bx,r_ebx
  762.         xor   edi, edi
  763.         call  [draw_line]
  764.  
  765.         mov   ebx,r_bx         ; ye,xb -> ye,xe
  766.         shl   ebx,16
  767.         mov   bx,r_bx
  768.         call  [draw_line]
  769.  
  770.         mov   ecx,esi          ; ya,xa -> ye,xa
  771.         mov   eax,r_eax
  772.         shl   eax,16
  773.         mov   ax,r_eax
  774.         mov   ebx,r_ebx
  775.         shl   ebx,16
  776.         mov   bx,r_bx
  777.         mov   edi,0
  778.         call  [draw_line]
  779.  
  780.         mov   eax,r_ax       ; ya,xe -> ye,xe
  781.         shl   eax,16
  782.         mov   ax,r_ax
  783.         call  [draw_line]
  784.  
  785.         popad
  786.         ret
  787.  
  788.  
  789. drawwindow_III_caption:
  790.  
  791.         mov   ecx,[edx+WDATA.cl_titlebar]                       ; GRAB BAR
  792.         push  ecx
  793.         mov   esi,edx
  794.         mov   edx,[esi+WDATA.box.top]
  795.         add   edx,4
  796.         mov   ebx,[esi+WDATA.box.top]
  797.         add   ebx,20
  798.         mov   eax,[esi+WDATA.box.top]
  799.         add   eax,[esi+WDATA.box.height]
  800.         cmp   ebx,eax
  801.         jb    .wdsizeok
  802.         mov   ebx,eax
  803.   .wdsizeok:
  804.         push  ebx
  805.   .drwi:
  806.         mov   ebx,edx
  807.         shl   ebx,16
  808.         add   ebx,edx
  809.         mov   eax,[esi+WDATA.box.left]
  810.         shl   eax,16
  811.         add   eax,[esi+WDATA.box.left]
  812.         add   eax,[esi+WDATA.box.width]
  813.         add   eax,4*65536-4
  814.         mov   ecx,[esi+WDATA.cl_titlebar]
  815.         test  ecx,0x40000000
  816.         jz    .nofa
  817.         add   ecx,0x040404
  818.   .nofa:
  819.         test  ecx,0x80000000
  820.         jz    .nofa2
  821.         sub   ecx,0x040404
  822.   .nofa2:
  823.         mov   [esi+WDATA.cl_titlebar],ecx
  824.         and   ecx,0xffffff
  825.         xor   edi, edi
  826.         call  [draw_line]
  827.         inc   edx
  828.         cmp   edx,[esp]
  829.         jb    .drwi
  830.         add   esp,4
  831.         pop   ecx
  832.         mov   [esi+WDATA.cl_titlebar],ecx
  833.  
  834.         ret
  835.  
  836.  
  837. drawwindow_III:
  838.  
  839.         pushad
  840.  
  841.         mov   edi,edx                              ; RECTANGLE
  842.         mov   eax,[edi+WDATA.box.left]
  843.         shl   eax,16
  844.     mov   ax, word [edi+WDATA.box.left]
  845.     add   ax, word [edi+WDATA.box.width]
  846.         mov   ebx,[edi+WDATA.box.top]
  847.         shl   ebx,16
  848.     mov   bx, word [edi+WDATA.box.top]
  849.     add   bx, word [edi+WDATA.box.height]
  850.         mov   esi,[edi+WDATA.cl_frames]
  851.         shr   esi,1
  852.         and   esi,0x007f7f7f
  853.         push  esi
  854.         or      [edi+WDATA.fl_wdrawn], 4
  855.         call  draw_rectangle
  856.         and     [edi+WDATA.fl_wdrawn], not 4
  857.         test    [edi+WDATA.fl_wdrawn], 2
  858.         jz      @f
  859.         call    drawwindowframes2
  860. @@:
  861.         mov   ecx,3
  862.       dw3l:
  863.         add   eax,1*65536-1
  864.         add   ebx,1*65536-1
  865.         mov   esi,[edi+WDATA.cl_frames]
  866.         call  draw_rectangle
  867.         dec   ecx
  868.         jnz   dw3l
  869.         pop   esi
  870.         add   eax,1*65536-1
  871.         add   ebx,1*65536-1
  872.         call  draw_rectangle
  873.  
  874.         call    drawwindow_III_caption
  875.  
  876.         mov   edx,[esi+WDATA.box.top]                       ; WORK AREA
  877.         add   edx,21+5
  878.         mov   ebx,[esi+WDATA.box.top]
  879.         add   ebx,[esi+WDATA.box.height]
  880.         cmp   edx,ebx
  881.         jg    noinside2
  882.         mov   eax,5
  883.         mov   ebx,20
  884.         mov   ecx,[esi+WDATA.box.width]
  885.         mov   edx,[esi+WDATA.box.height]
  886.         sub   ecx,4
  887.         sub   edx,4
  888.         mov   edi,[esi+WDATA.cl_workarea]
  889.         test  edi,0x40000000
  890.         jnz   noinside2
  891.         call  [drawbar]
  892.       noinside2:
  893.  
  894.         popad
  895.  
  896.         ret
  897.  
  898.  
  899.  
  900. ; activate window
  901. align 4
  902. windowactivate:
  903.  
  904.         ; esi = abs mem position in stack 0xC400+
  905.  
  906.         pushad
  907.  
  908.      ; if type of current active window is 3,
  909.      ; it must be redrawn
  910.         mov   eax, [TASK_COUNT]
  911.         movzx eax, word [WIN_POS + eax*2]
  912.         shl   eax, 5
  913.         add   eax, window_data
  914.         mov   ebx, [eax + WDATA.cl_workarea]
  915.         and   ebx, 0x0f000000
  916.         cmp   ebx, 0x03000000
  917.         je   .set_WDATA_fl_redraw   ; for 3 and 4 style
  918.         cmp   ebx, 0x04000000
  919.         je   .set_WDATA_fl_redraw
  920.         jmp @f
  921.         .set_WDATA_fl_redraw:
  922.         mov   [eax + WDATA.fl_redraw], byte 1
  923.      @@:
  924.  
  925.         push   esi
  926.       movzx   eax, word [esi] ; ax <- process no
  927.       movzx   eax, word [WIN_STACK+eax*2] ; ax <- position in window stack
  928.  
  929.         xor   esi, esi        ; drop others
  930.       waloop:
  931.         cmp   esi, dword [TASK_COUNT]
  932.         jae   wacont
  933.         inc   esi
  934.         lea   edi, [WIN_STACK + esi*2]
  935.         mov   bx, [edi] ; position of the current process
  936.         cmp   bx, ax
  937.         jbe   @f
  938.         dec   bx       ; upper? => drop!
  939.         mov   [edi], bx
  940.       @@:
  941.         jmp   waloop
  942.       wacont:
  943.                             ; set to no 1
  944.         pop   esi           ;   esi = pointer at 0xC400
  945.  
  946.       movzx   eax, word [esi]
  947.         mov   bx, [TASK_COUNT]  ; number of processes
  948.         mov   [WIN_STACK+eax*2], bx     ; this is the last (and the upper)
  949.  
  950.         ; update on screen -window stack
  951.         xor   esi, esi
  952.       waloop2:
  953.         mov   edi, [TASK_COUNT]
  954.         cmp   esi, edi
  955.         jae   wacont2
  956.         inc   esi
  957.         movzx ebx, word [esi*2 + WIN_STACK]
  958.         mov   [ebx*2 + WIN_POS], si
  959.         jmp   waloop2
  960.       wacont2:
  961.         mov   [KEY_COUNT], byte 0             ; empty keyboard buffer
  962.         mov   [BTN_COUNT], byte 0             ; empty button buffer
  963.         mov   [MOUSE_SCROLL_H], word 0  ; zero mouse z-index
  964.         mov   [MOUSE_SCROLL_V], word 0  ; zero mouse z-index
  965.         popad
  966.         ret
  967.  
  968.  
  969. ; check if window is necessary to draw
  970.  
  971. checkwindowdraw:
  972.  
  973.         ; edi = position in window_data+
  974.  
  975.         mov   eax, [edi + WDATA.cl_workarea]
  976.         and   eax, 0x0f000000
  977.         cmp   eax, 0x03000000
  978.         je    .return_yes      ; window type 3
  979.         cmp   eax, 0x04000000
  980.         je    .return_yes      ; window type 4
  981.  
  982.         mov   esi, edi
  983.         sub   esi, window_data
  984.         shr   esi, 5
  985.  
  986.         ; esi = process number
  987.  
  988.         movzx eax, word [WIN_STACK + esi * 2] ; get value of the curr process
  989.         lea   esi, [WIN_POS + eax * 2]      ; get address of this process at 0xC400
  990.  
  991.         push  esi
  992.  
  993.       .new_check:
  994.  
  995.         pop   esi
  996.         add   esi, 2
  997.         push  esi
  998.  
  999.         mov   eax, [TASK_COUNT]
  1000.         lea   eax, word [WIN_POS + eax * 2] ; number of the upper window
  1001.  
  1002.         cmp   esi, eax
  1003.         ja    .all_wnds_to_top
  1004.  
  1005.         movzx eax, word [esi]
  1006.         shl   eax, 5
  1007.         cmp   [CURRENT_TASK + eax + TASKDATA.state], byte 9
  1008.         je    .new_check                    ; skip dead windows
  1009.  
  1010.         lea   esi, [eax+window_data]
  1011.  
  1012.         mov   ebx, [edi+WDATA.box.top]  ; y0
  1013.         mov   edx, [edi+WDATA.box.height]
  1014.         add   edx, ebx      ; y0e
  1015.  
  1016.         mov   ecx, [esi+WDATA.box.top]  ; y  ; y check
  1017.         cmp   ecx, edx
  1018.         jae   .new_check     ; y < y0e
  1019.         mov   eax, [esi+WDATA.box.height]
  1020.         add   ecx, eax       ; ye
  1021.         cmp   ebx, ecx       ; y0 >= ye
  1022.         ja    .new_check
  1023.  
  1024.         mov   eax, [edi+WDATA.box.left]   ; x0
  1025.         mov   ecx, [edi+WDATA.box.width]
  1026.         add   ecx, eax       ; x0e
  1027.  
  1028.         mov   edx, [esi+WDATA.box.left]   ; x ; x check
  1029.         cmp   edx, ecx
  1030.         jae   .new_check     ; x < x0e
  1031.         mov   ecx, [esi+WDATA.box.width]
  1032.         add   edx, ecx
  1033.         cmp   eax, edx
  1034.         ja    .new_check
  1035.  
  1036.         pop   esi
  1037.   .return_yes:
  1038.         mov   ecx,1   ; overlap some window
  1039.         ret
  1040.  
  1041.   .all_wnds_to_top:
  1042.  
  1043.         pop   esi
  1044.  
  1045.         xor   ecx, ecx       ; passed all windows to top
  1046.         ret
  1047.  
  1048.  
  1049.  
  1050.  
  1051. waredraw:     ; if redraw necessary at activate
  1052.  
  1053.         pushad
  1054.  
  1055.         call  checkwindowdraw      ; draw window on activation ?
  1056.         test  ecx, ecx
  1057.         jz    .do_not_draw
  1058.  
  1059.         popad
  1060.         mov   [MOUSE_DOWN], byte 1     ; do draw mouse
  1061.         call  windowactivate
  1062.  
  1063.         ; update screen info
  1064.         pushad
  1065.         mov   edi, [TASK_COUNT] ; the last process (number)
  1066.         movzx esi, word [WIN_POS + edi * 2]
  1067.         shl   esi, 5
  1068.         add   esi, window_data
  1069.  
  1070.         ; coordinates of the upper window
  1071.     mov   eax, [esi + WDATA.box.left]   ; cx
  1072.     mov   ebx, [esi + WDATA.box.top]    ; cy
  1073.     mov   ecx, [esi + WDATA.box.width]  ; sx
  1074.     mov   edx, [esi + WDATA.box.height] ; sy
  1075.  
  1076.         add   ecx, eax       ; ecx = x_end
  1077.         add   edx, ebx       ; edx = y_end
  1078.  
  1079.         mov   edi, [TASK_COUNT]
  1080.         movzx esi, word [WIN_POS + edi * 2]
  1081.         call  setscreen
  1082.         popad
  1083.  
  1084.     mov   [edi + WDATA.fl_redraw], 1  ; redraw flag for app
  1085.     mov   [MOUSE_DOWN],byte 0             ; mouse down checks
  1086.  
  1087.         ret
  1088.  
  1089.      .do_not_draw:
  1090.  
  1091.         popad
  1092.  
  1093.         call  windowactivate
  1094.         mov   [MOUSE_DOWN],byte 0  ; mouse down checks
  1095.         mov   [MOUSE_BACKGROUND],byte 0  ; no mouse background
  1096.         mov   [DONT_DRAW_MOUSE],byte 0  ; draw mouse
  1097.         ret
  1098.  
  1099.  
  1100. ; eax = window number on screen
  1101. ; corrupts registers and [dl*]
  1102. minimize_window:
  1103.         movzx eax, word [WIN_POS+eax*2]
  1104.         shl   eax, 5
  1105.         add   eax, window_data
  1106.         test  [eax+WDATA.fl_wstate], WSTATE_MINIMIZED
  1107.         jnz   .skip_redrawings
  1108.         pushfd
  1109.         cli
  1110.         or    [eax+WDATA.fl_wstate], WSTATE_MINIMIZED
  1111.         mov   edi, eax
  1112.         ;call  calculatescreen
  1113.         mov   eax, [edi+WDATA.box.left]
  1114.         mov   [dlx], eax
  1115.         mov   ecx, eax
  1116.         add   ecx, [edi+WDATA.box.width]
  1117.         mov   [dlxe], ecx
  1118.         mov   ebx, [edi+WDATA.box.top]
  1119.         mov   [dly], ebx
  1120.         mov   edx, ebx
  1121.         add   edx, [edi+WDATA.box.height]
  1122.         mov   [dlye], edx
  1123.         call  calculatescreen
  1124.         xor   esi, esi
  1125.         xor   eax, eax
  1126.         call  redrawscreen
  1127.         popfd
  1128. .skip_redrawings:
  1129.         ret
  1130.  
  1131. ; eax = window number on screen
  1132. ; corrupts registers and [dl*]
  1133. restore_minimized_window:
  1134.         pushfd
  1135.         cli
  1136.         movzx esi, word [WIN_POS+eax*2]
  1137.         mov   edi, esi
  1138.         shl   edi, 5
  1139.         add   edi, window_data
  1140.         test  [edi+WDATA.fl_wstate], WSTATE_MINIMIZED
  1141.         jz    .skip_redrawings
  1142.         mov   [edi+WDATA.fl_redraw], 1
  1143.         and   [edi+WDATA.fl_wstate], not WSTATE_MINIMIZED
  1144.         cmp   eax, [TASK_COUNT] ; the uppermost window
  1145.         jnz   .no_uppermost
  1146.         mov   eax, [edi+WDATA.box.left]
  1147.         mov   ebx, [edi+WDATA.box.top]
  1148.         mov   ecx, eax
  1149.         mov   edx, ebx
  1150.         add   ecx, [edi+WDATA.box.width]
  1151.         add   edx, [edi+WDATA.box.height]
  1152.         call  setscreen
  1153.         jmp   .done
  1154. .no_uppermost:
  1155.         mov   eax, [edi+WDATA.box.left]
  1156.         mov   ebx, [edi+WDATA.box.top]
  1157.         mov   ecx, eax
  1158.         mov   edx, ebx
  1159.         add   ecx, [edi+WDATA.box.width]
  1160.         add   edx, [edi+WDATA.box.height]
  1161.         call  calculatescreen
  1162. .done:
  1163.         mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
  1164. .skip_redrawings:
  1165.         popfd
  1166.         ret
  1167.  
  1168.  
  1169. ;iglobal
  1170. ;  window_moving   db 'K : Window - move/resize',13,10,0
  1171. ;  window_moved   db 'K : Window - done',13,10,0
  1172. ;endg
  1173.  
  1174. ; check window touch
  1175. align 4
  1176. checkwindows:
  1177.         pushad
  1178.  
  1179.         cmp   [window_minimize], 0
  1180.         je    .no_minimizing
  1181.         mov   eax, [TASK_COUNT]       ; the uppermost window
  1182.         mov   bl, 0
  1183.         xchg  [window_minimize], bl
  1184.         cmp   bl, 1
  1185.         jne   .restore
  1186.         call  minimize_window
  1187.         jmp   .continue
  1188.   .restore:
  1189.         call  restore_minimized_window
  1190.   .continue:
  1191.   .no_minimizing:
  1192.  
  1193.         cmp   [BTN_DOWN],byte 0    ; mouse buttons pressed ?
  1194.         jne  .mouse_buttons_pressed
  1195. ;..................................... start 1/4 : modified by vhanla .................
  1196.         mov [bPressedMouseXY_W],0
  1197. ;..................................... end 1/4 : modified by vhanla ...................
  1198.         popad
  1199.         ret
  1200.     .mouse_buttons_pressed:
  1201. ;..................................... start 2/4 : modified by vhanla .................
  1202. uglobal
  1203.         bPressedMouseXY_W db 0x0
  1204. endg
  1205. ;..................................... end 2/4 : modified by vhanla ...................
  1206.         mov   esi,[TASK_COUNT]
  1207.         inc   esi
  1208.  
  1209. ;..................................... start 3/4 : modified by vhanla .................
  1210.         cmp [bPressedMouseXY_W],1
  1211.         ja  @f
  1212.         inc [bPressedMouseXY_W]
  1213.         jnc @f
  1214.         ;mov ax,[MOUSE_X]
  1215.         ;mov [mx],ax
  1216.         ;mov ax,[MOUSE_Y]
  1217.         ;mov [my],ax
  1218.         mov eax,dword[MOUSE_X]
  1219.         mov dword[mx],eax
  1220.       @@:
  1221. ;..................................... end 3/4 : modified by vhanla ...................
  1222.  
  1223.       cwloop:
  1224.         cmp   esi,2
  1225.         jb   .exit
  1226.  
  1227.         dec   esi
  1228.         movzx edi, word [WIN_POS + esi * 2] ; ebx
  1229.         shl   edi, 5
  1230.         add   edi, window_data
  1231. ;        mov   edi, ebx
  1232.     mov   ecx, [edi + WDATA.box.left]
  1233.     mov   edx, [edi + WDATA.box.top]
  1234.  
  1235.         mov   eax,ecx
  1236.         mov   ebx,edx
  1237.         test    [edi+WDATA.fl_wstate],WSTATE_MINIMIZED
  1238.         jnz     cwloop
  1239.  
  1240. ;..................................... start 4/4 : modified by vhanla .................
  1241.        movzx  eax, word [mx]; movzx eax,word[MOUSE_X]
  1242.        movzx  ebx, word [my]; movzx ebx,word[MOUSE_Y]
  1243. ;..................................... endt 4/4 : modified by vhanla ..................
  1244.         cmp   ecx, eax
  1245.         jae   cwloop
  1246.         cmp   edx, ebx
  1247.         jae   cwloop
  1248.     add   ecx, [edi + WDATA.box.width]
  1249.     add   edx, [edi + WDATA.box.height]
  1250.         cmp   eax, ecx
  1251.         jae   cwloop
  1252.         cmp   ebx, edx
  1253.         jae   cwloop
  1254.  
  1255.         pushad
  1256.         mov   eax, esi
  1257.         mov   ebx, [TASK_COUNT]
  1258.         cmp   eax, ebx      ; is this window active?
  1259.         jz    .move_resize_window
  1260.  
  1261.         cmp   [bPressedMouseXY_W], 1
  1262.         ja    .exit_popa
  1263.  
  1264.         ; eax = position in windowing stack
  1265.         ; redraw must ?
  1266.         lea   esi, [WIN_POS + esi * 2]
  1267.         call  waredraw
  1268.       .exit_popa:
  1269.         add   esp, 32
  1270.  
  1271.       .exit:
  1272.         popad
  1273.         ret
  1274.  
  1275.    .move_resize_window:    ; MOVE OR RESIZE WINDOW
  1276.         popad
  1277.  
  1278.         ; Check for user enabled fixed window
  1279.     mov   edx, [edi + WDATA.cl_titlebar]
  1280.         and   edx, 0x0f000000
  1281.         cmp   edx, 0x01000000
  1282.         jne   .window_move_enabled_for_user
  1283.         popad
  1284.         ret
  1285.       .window_move_enabled_for_user:
  1286.  
  1287.     test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
  1288.         jnz     .no_resize_2
  1289.  
  1290.         mov   [do_resize_from_corner],byte 0   ; resize for skinned window
  1291.     mov   edx, [edi + WDATA.cl_workarea]
  1292.         and   edx, 0x0f000000
  1293.         cmp   edx, 0x00000000                                           ;{test for resized}
  1294.         je    .no_resize_2
  1295.         cmp   edx, 0x01000000                                           ;{test for resized}
  1296.         je    .no_resize_2
  1297.         cmp   edx, 0x04000000                                           ;{test for resized}
  1298.         je    .no_resize_2
  1299. ;       jb    .no_resize_2 ; not type 2 wnd
  1300.  
  1301.     mov   edx, [edi + WDATA.box.top]
  1302.     add   edx, [edi + WDATA.box.height]
  1303.         sub   edx, 6       ; edx = y_end - 6
  1304.         cmp   ebx, edx     ; ebx = mouse_y
  1305.         jb    .no_resize_2
  1306.         mov   [do_resize_from_corner],byte 1
  1307.         jmp   .continue
  1308.       .no_resize_2:
  1309.  
  1310.         push    eax
  1311.         call    get_titlebar_height
  1312.     add     eax,[edi + WDATA.box.top]
  1313.         cmp     ebx,eax
  1314.         pop     eax
  1315.         jae     .exit
  1316.  
  1317.      .continue:
  1318.  
  1319. ;       push  esi
  1320. ;       mov   esi, window_moving
  1321. ;       call  sys_msg_board_str
  1322. ;       pop   esi
  1323.  
  1324.         mov   ecx, [timer_ticks]     ; double-click ?
  1325.         mov   edx, ecx
  1326.         sub   edx, [latest_window_touch]
  1327.         mov   [latest_window_touch], ecx
  1328.         mov   [latest_window_touch_delta], edx
  1329.  
  1330.         mov   cl, [BTN_DOWN]     ; save for shade check
  1331.         mov   [do_resize], cl
  1332.      no_emulation_righ_button:
  1333.     mov   ecx, [edi + WDATA.box.left]
  1334.     mov   edx, [edi + WDATA.box.top]
  1335.  
  1336.         push  eax ecx edx
  1337.         mov   [dlx], ecx      ; save for drawlimits
  1338.         mov   [dly], edx
  1339.     mov   eax, [edi + WDATA.box.width]
  1340.         add   ecx, eax
  1341.     mov   eax, [edi + WDATA.box.height]
  1342.         add   edx, eax
  1343.         mov   [dlxe], ecx
  1344.         mov   [dlye], edx
  1345.         pop   edx ecx eax
  1346.  
  1347.         sub   eax, ecx
  1348.         sub   ebx, edx
  1349.  
  1350.         mov   esi, [MOUSE_X]
  1351.         mov   [WIN_TEMP_XY], esi
  1352.  
  1353.         pushad           ; wait for putimages to finish
  1354. ;        mov   ebx,5
  1355. ;        call  delay_hs
  1356.     mov   eax,[edi + WDATA.box.left]
  1357.         mov   [npx],eax
  1358.     mov   eax,[edi + WDATA.box.top]
  1359.         mov   [npy],eax
  1360.         popad
  1361.  
  1362.         push eax                  ; save old coordinates
  1363.     mov   ax, word [edi + WDATA.box.left]
  1364.         mov   word [oldc+BOX.left],ax
  1365.     mov   ax, word [edi + WDATA.box.top]
  1366.         mov   word [oldc+BOX.top],ax
  1367.     mov   ax, word [edi + WDATA.box.width]
  1368.         mov   word [oldc+BOX.width],ax
  1369.         mov   word [npxe],ax
  1370.     mov   ax, word [edi + WDATA.box.height]
  1371.         mov   word [oldc+BOX.height],ax
  1372.         mov   word [npye],ax
  1373.         pop eax
  1374.  
  1375.         call  drawwindowframes
  1376.  
  1377.         mov   [reposition],0
  1378.         mov   [MOUSE_DOWN],byte 1   ; no reaction to mouse up/down
  1379.  
  1380.         ; move window
  1381.  
  1382.       newchm:
  1383.  
  1384.         mov   [DONT_DRAW_MOUSE],byte 1
  1385.  
  1386.         call  checkidle
  1387.  
  1388.         call  checkVga_N13
  1389.  
  1390.         mov   [MOUSE_BACKGROUND],byte 0
  1391.  
  1392.         call  [draw_pointer]
  1393.  
  1394.         pushad
  1395.         call   stack_handler
  1396.         popad
  1397.  
  1398.         mov   esi,[WIN_TEMP_XY]
  1399.         cmp   esi,[MOUSE_X]
  1400.         je    cwb
  1401.  
  1402.         mov   cx,[MOUSE_X]
  1403.         mov   dx,[MOUSE_Y]
  1404.         sub   cx,ax
  1405.         sub   dx,bx
  1406.  
  1407.         push  ax
  1408.         push  bx
  1409.  
  1410.         call  drawwindowframes
  1411.  
  1412.         mov   ax,[Screen_Max_X]
  1413.         mov   bx,[Screen_Max_Y]
  1414.  
  1415.         cmp   [do_resize_from_corner],1
  1416.         je    no_new_position
  1417.  
  1418.         mov   word [npx],word 0     ; x repos ?
  1419.         cmp   ax,cx
  1420.         jb    noreposx
  1421.         mov   [reposition],1
  1422.         sub   ax,word [npxe]
  1423.         mov   word [npx],ax
  1424.         cmp   ax,cx
  1425.         jb    noreposx
  1426.         mov   word [npx],cx
  1427.       noreposx:
  1428.  
  1429.         mov   word [npy],word 0     ; y repos ?
  1430.         cmp   bx,dx
  1431.         jb    noreposy
  1432.         mov   [reposition],1
  1433.         sub   bx,word [npye]
  1434.         mov   word [npy],bx
  1435.         cmp   bx,dx
  1436.         jb    noreposy
  1437.         mov   word [npy],dx
  1438.       noreposy:
  1439.  
  1440.       no_new_position:
  1441.  
  1442.         cmp   [do_resize_from_corner],0    ; resize from right corner
  1443.         je    norepos_size
  1444.         pushad
  1445.  
  1446.         mov   edx,edi
  1447.         sub   edx,window_data
  1448.         ;shr   edx,5
  1449.         ;shl   edx,8
  1450.         ;add   edx,0x80000                 ; process base at 0x80000+
  1451.     lea   edx, [SLOT_BASE + edx*8]
  1452.  
  1453.         movzx eax,word [MOUSE_X]
  1454.     cmp   eax,[edi + WDATA.box.left]
  1455.         jb    nnepx
  1456.     sub   eax,[edi + WDATA.box.left]
  1457.         cmp   eax,32 ; [edx+0x90+8]
  1458.         jge   nnepx2
  1459.         mov   eax,32 ; [edx+0x90+8]
  1460.       nnepx2:
  1461.         mov   [npxe],eax
  1462.       nnepx:
  1463.  
  1464.         call    get_rolledup_height
  1465.         mov     ebx,eax
  1466.         movzx eax,word [MOUSE_Y]
  1467.     cmp   eax,[edi + WDATA.box.top]
  1468.         jb    nnepy
  1469.     sub   eax,[edi + WDATA.box.top]
  1470.         cmp     eax,ebx ; [edx+0x90+12]
  1471.         jge     nnepy2
  1472.         mov     eax,ebx ; [edx+0x90+12]
  1473.       nnepy2:
  1474.         mov   [npye],eax
  1475.       nnepy:
  1476.  
  1477.         mov   [reposition],1
  1478.  
  1479.         popad
  1480.       norepos_size:
  1481.  
  1482.         pop   bx
  1483.         pop   ax
  1484.         call  drawwindowframes
  1485.  
  1486.         mov   esi,[MOUSE_X]
  1487.         mov   [WIN_TEMP_XY],esi
  1488.  
  1489.       cwb:
  1490.         cmp   [BTN_DOWN],byte 0
  1491.         jne   newchm
  1492.                                      ; new position done
  1493.         mov     [DONT_DRAW_MOUSE],byte 1
  1494.         mov     cl,0
  1495.         test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
  1496.         jnz     @f
  1497.         mov     cl,[reposition]
  1498.         call    drawwindowframes
  1499.  
  1500.         mov   eax,[npx]
  1501.     mov   [edi + WDATA.box.left],eax
  1502.         mov   eax,[npy]
  1503.     mov   [edi + WDATA.box.top],eax
  1504.         mov   eax,[npxe]
  1505.     mov   [edi + WDATA.box.width],eax
  1506.         mov   eax,[npye]
  1507.     mov   [edi + WDATA.box.height],eax
  1508.         call    set_window_clientbox
  1509.  
  1510.     @@: mov     [reposition],cl
  1511.  
  1512.         cmp   [reposition],1         ; save new position and size
  1513.         jne   no_bounds_save
  1514.         push  esi edi ecx
  1515.         mov   esi,edi
  1516.         mov   ecx,2
  1517.         test  [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP or WSTATE_MAXIMIZED
  1518.         jnz   @f
  1519.         add   ecx,2
  1520.     @@: sub   edi,window_data
  1521.         shr   edi,5
  1522.         shl   edi,8
  1523.         add   edi,SLOT_BASE+APPDATA.saved_box
  1524.         cld
  1525.         rep   movsd
  1526.         pop   ecx edi esi
  1527.       no_bounds_save:
  1528.  
  1529.         pushad                             ; WINDOW SHADE/FULLSCREEN
  1530.  
  1531.         ;{doule click not worked for 4 type window}
  1532.     mov   edx, [edi + WDATA.cl_workarea]
  1533.         and   edx, 0x0f000000
  1534.         cmp   edx, 0x00000000
  1535.         je    no_fullscreen_restore
  1536.         cmp   edx, 0x01000000
  1537.         je    no_fullscreen_restore
  1538.  
  1539.         cmp   [reposition],1
  1540.         je    no_window_sizing
  1541.         mov   edx,edi
  1542.         sub   edx,window_data
  1543.         shr   edx,5
  1544.         shl   edx,8
  1545.         add   edx,SLOT_BASE                 ; process base at 0x80000+
  1546.  
  1547.         cmp   [do_resize],2               ; window shade ?
  1548.         jne   no_window_shade
  1549.         mov   [reposition],1
  1550.  
  1551.         test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
  1552.         jnz     wnd_rolldown
  1553.   wnd_rollup:
  1554.         or      [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
  1555.         call    get_rolledup_height
  1556.         jmp     @f
  1557.   wnd_rolldown:
  1558.         and     [edi+WDATA.fl_wstate],not WSTATE_ROLLEDUP
  1559.     mov     eax,[edx + APPDATA.saved_box.height] ; 0x90+BOX.height
  1560.         test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
  1561.         jz      @f
  1562.         mov     eax,[screen_workarea.bottom]
  1563.         sub     eax,[screen_workarea.top]
  1564.     @@: mov     [edi+WDATA.box.height],eax
  1565.         add     eax, [edi+WDATA.box.top]
  1566.         cmp     eax, [Screen_Max_Y]
  1567.         jbe     @f
  1568.         mov     eax, [Screen_Max_Y]
  1569.         sub     eax, [edi+WDATA.box.height]
  1570.         mov     [edi+WDATA.box.top], eax
  1571.     @@: call    check_window_position
  1572.         call    set_window_clientbox
  1573.  
  1574.       no_window_shade:
  1575.  
  1576.         push edx
  1577.         mov   edx, [edi + WDATA.cl_workarea]
  1578.         and   edx, 0x0f000000
  1579.         cmp   edx, 0x04000000
  1580.         pop edx
  1581.         je    no_fullscreen_restore
  1582.  
  1583.         cmp   [do_resize],1               ; fullscreen/restore ?
  1584.         jne   no_fullscreen_restore
  1585.         cmp   [latest_window_touch_delta],dword 50
  1586.         jg    no_fullscreen_restore
  1587.         mov   [reposition],1
  1588.         test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
  1589.         jnz     restore_from_fullscreen
  1590.         or      [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
  1591.         mov     eax,[screen_workarea.left]
  1592.         mov     [edi+WDATA.box.left],eax
  1593.         sub     eax,[screen_workarea.right]
  1594.         neg     eax
  1595.         mov     [edi+WDATA.box.width],eax
  1596.         mov     eax,[screen_workarea.top]
  1597.         mov     [edi+WDATA.box.top],eax
  1598.         test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
  1599.         jnz     @f
  1600.         sub     eax,[screen_workarea.bottom]
  1601.         neg     eax
  1602.         mov     [edi+WDATA.box.height],eax
  1603.     @@:
  1604.         jmp     restore_from_fullscreen.clientbox
  1605.       restore_from_fullscreen:
  1606.         and     [edi+WDATA.fl_wstate],not WSTATE_MAXIMIZED
  1607.         push    [edi+WDATA.box.height]
  1608.         push  edi                         ; restore
  1609.         lea   esi, [edx + APPDATA.saved_box]
  1610.         mov   ecx,4
  1611.         cld
  1612.         rep   movsd
  1613.         pop   edi
  1614.         pop     eax
  1615.         test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
  1616.         jz      @f
  1617.         mov     [edi+WDATA.box.height],eax
  1618.     @@:
  1619.     .clientbox:
  1620.         call    set_window_clientbox
  1621.  
  1622.       no_fullscreen_restore:
  1623.  
  1624.         mov   eax,[edi+WDATA.box.top]                 ; check Y inside screen
  1625.         add   eax,[edi+WDATA.box.height]
  1626.         cmp   eax,[Screen_Max_Y]
  1627.         jbe   no_window_sizing
  1628.         mov   eax,[edi+WDATA.box.left]                 ; check X inside screen
  1629.         add   eax,[edi+WDATA.box.width]
  1630.         cmp   eax,[Screen_Max_X]
  1631.         jbe   no_window_sizing
  1632.         mov   eax,[Screen_Max_X]
  1633.         sub   eax,[edi+WDATA.box.width]
  1634.         mov   [edi+WDATA.box.left],eax
  1635.         mov   eax,[Screen_Max_Y]
  1636.         sub   eax,[edi+WDATA.box.height]
  1637.         mov   [edi+WDATA.box.top],eax
  1638.         call  set_window_clientbox
  1639.       no_window_sizing:
  1640.  
  1641.         popad
  1642.  
  1643.         cmp   [reposition],0
  1644.         je    retwm
  1645.  
  1646.         mov   [DONT_DRAW_MOUSE],byte 1 ; no mouse
  1647.  
  1648.  
  1649.         push  eax ebx ecx edx
  1650.         mov   eax,[edi+WDATA.box.left]
  1651.         mov   ebx,[edi+WDATA.box.top]
  1652.         mov   ecx,[edi+WDATA.box.width]
  1653.         mov   edx,[edi+WDATA.box.height]
  1654.         add   ecx,eax
  1655.         add   edx,ebx
  1656.         call  calculatescreen
  1657.  
  1658.         mov   eax,[oldc+BOX.left]
  1659.         mov   ebx,[oldc+BOX.top]
  1660.         mov   ecx,[oldc+BOX.width]
  1661.         mov   edx,[oldc+BOX.height]
  1662.         add   ecx,eax
  1663.         add   edx,ebx
  1664.         call  calculatescreen
  1665.         pop   edx ecx ebx eax
  1666.  
  1667.         mov   eax,edi
  1668.         call  redrawscreen
  1669.  
  1670.  
  1671.         mov     [edi+WDATA.fl_redraw],1
  1672.  
  1673.         mov   ecx,100         ; wait to avoid mouse residuals
  1674.       waitre2:
  1675.         mov   [DONT_DRAW_MOUSE],byte 1
  1676.         call  checkidle
  1677.         cmp     [edi+WDATA.fl_redraw],0
  1678.         jz    retwm
  1679.         loop  waitre2
  1680.  
  1681.       retwm:
  1682.  
  1683.         mov   [DONT_DRAW_MOUSE],byte 0 ; mouse pointer
  1684.         mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
  1685.         mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down
  1686.  
  1687. ;       mov    esi,window_moved
  1688. ;       call   sys_msg_board_str
  1689.  
  1690.         popad
  1691.  
  1692.         ret
  1693.  
  1694.  
  1695. uglobal
  1696.   add_window_data            dd  0
  1697.   do_resize_from_corner      db  0x0
  1698.   reposition                 db  0x0
  1699.   latest_window_touch        dd  0x0
  1700.   latest_window_touch_delta  dd  0x0
  1701.  
  1702.   do_resize db 0x0
  1703.  
  1704.   oldc    dd 0x0,0x0,0x0,0x0
  1705.  
  1706.   dlx     dd 0x0
  1707.   dly     dd 0x0
  1708.   dlxe    dd 0x0
  1709.   dlye    dd 0x0
  1710.  
  1711.   npx     dd 0x0
  1712.   npy     dd 0x0
  1713.   npxe    dd 0x0
  1714.   npye    dd 0x0
  1715.  
  1716.   mpx     dd 0x0
  1717.   mpy     dd 0x0
  1718. endg
  1719.  
  1720.  
  1721. ; draw negative window frames
  1722. drawwindowframes2:
  1723.         pushad
  1724.         cli
  1725.         jmp     drawwindowframes.do
  1726. drawwindowframes:
  1727.         pushad
  1728.         cli
  1729.  
  1730.         test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
  1731.         jnz     .ret
  1732.         mov     eax, [npx]
  1733.         cmp     eax, [edi+WDATA.box.left]
  1734.         jnz     .nowndframe
  1735.         mov     eax, [npxe]
  1736.         cmp     eax, [edi+WDATA.box.width]
  1737.         jnz     .nowndframe
  1738.         mov     eax, [npy]
  1739.         cmp     eax, [edi+WDATA.box.top]
  1740.         jnz     .nowndframe
  1741.         mov     eax, [npye]
  1742.         cmp     eax, [edi+WDATA.box.height]
  1743.         jnz     .nowndframe
  1744.         xor     [edi+WDATA.fl_wdrawn], 2
  1745.         test    [edi+WDATA.fl_wdrawn], 4
  1746.         jnz     .ret
  1747.  
  1748. .nowndframe:
  1749. .do:
  1750.         mov     edi, 1
  1751.         mov     ecx, 0x01000000
  1752.         mov   eax,[npx]
  1753.         shl   eax,16
  1754.         add   eax,[npx]
  1755.         add   eax,[npxe]
  1756.         add   eax,65536*1-1
  1757.         mov   ebx,[npy]
  1758.         shl   ebx,16
  1759.         add   ebx,[npy]
  1760.         call  [draw_line]
  1761.  
  1762.         mov   eax,[npx]
  1763.         shl   eax,16
  1764.         add   eax,[npx]
  1765.         add   eax,[npxe]
  1766.         add   eax,65536*1-1
  1767.         mov   ebx,[npy]
  1768.         add   ebx,[npye]
  1769.         shl   ebx,16
  1770.         add   ebx,[npy]
  1771.         add   ebx,[npye]
  1772.         call  [draw_line]
  1773.  
  1774.         mov   eax,[npx]
  1775.         shl   eax,16
  1776.         add   eax,[npx]
  1777.         mov   ebx,[npy]
  1778.         shl   ebx,16
  1779.         add   ebx,[npy]
  1780.         add   ebx,[npye]
  1781.         call  [draw_line]
  1782.  
  1783.         mov   eax,[npx]
  1784.         add   eax,[npxe]
  1785.         shl   eax,16
  1786.         add   eax,[npx]
  1787.         add   eax,[npxe]
  1788.         mov   ebx,[npy]
  1789.         shl   ebx,16
  1790.         add   ebx,[npy]
  1791.         add   ebx,[npye]
  1792.         call  [draw_line]
  1793.  
  1794. .ret:
  1795.         sti
  1796.         popad
  1797.         ret
  1798.  
  1799.  
  1800.  
  1801. random_shaped_window:
  1802.  
  1803. ;
  1804. ;  eax = 0    giving address of data area
  1805. ;      ebx    address
  1806. ;  eax = 1    shape area scale
  1807. ;      ebx    2^ebx scale
  1808.  
  1809.      test eax, eax
  1810.      jne  rsw_no_address
  1811.      mov  eax,[current_slot]
  1812.      mov  [eax+APPDATA.wnd_shape],ebx
  1813. rsw_no_address:
  1814.  
  1815.      cmp  eax,1
  1816.      jne  rsw_no_scale
  1817.      mov  eax,[current_slot]
  1818.      mov  byte [eax+APPDATA.wnd_shape_scale], bl
  1819. rsw_no_scale:
  1820.  
  1821.      ret
  1822.  
  1823.  
  1824.