Subversion Repositories Kolibri OS

Rev

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

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