Subversion Repositories Kolibri OS

Rev

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