Subversion Repositories Kolibri OS

Rev

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