Subversion Repositories Kolibri OS

Rev

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