Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2010. 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: 2436 $
  10.  
  11. ;==============================================================================
  12. ;///// public functions ///////////////////////////////////////////////////////
  13. ;==============================================================================
  14.  
  15. window.BORDER_SIZE = 5
  16.  
  17. macro FuncTable name, table_name, [label]
  18. {
  19.   common
  20.     align 4
  21.     \label name#.#table_name dword
  22.   forward
  23.     dd name#.#label
  24.   common
  25.     name#.sizeof.#table_name = $ - name#.#table_name
  26. }
  27.  
  28. uglobal
  29.   common_colours rd 32
  30.   draw_limits    RECT
  31. endg
  32.  
  33. align 4
  34. ;------------------------------------------------------------------------------
  35. syscall_draw_window: ;///// system function 0 /////////////////////////////////
  36. ;------------------------------------------------------------------------------
  37. ;? <description>
  38. ;------------------------------------------------------------------------------
  39.         mov     eax, edx
  40.         shr     eax, 24
  41.         and     al, 0x0f
  42.         cmp     al, 5
  43.         jae     .exit
  44.  
  45.         push    eax
  46.         call    window._.sys_set_window
  47.         pop     eax
  48.  
  49.         or      al, al
  50.         jnz     @f
  51.  
  52.         ; type I - original style
  53.         call    drawwindow_I
  54.         jmp     window._.draw_window_caption.2
  55. ;--------------------------------------
  56. align 4
  57. @@:
  58.         dec     al
  59.         jnz     @f
  60.  
  61.         ; type II - only reserve area, no draw
  62. ;        call    sys_window_mouse
  63.         call    [draw_pointer]
  64.         jmp     .exit
  65. ;--------------------------------------
  66. align 4
  67. @@:
  68.         dec     al
  69.         jnz     @f
  70.  
  71.         ; type III  - new style
  72.         call    drawwindow_III
  73.         jmp     window._.draw_window_caption.2
  74.  
  75.         ; type IV & V - skinned window (resizable & not)
  76. ;--------------------------------------
  77. align 4
  78. @@:
  79.         mov     eax, [TASK_COUNT]
  80.         movzx   eax, word[WIN_POS + eax * 2]
  81.         cmp     eax, [CURRENT_TASK]
  82.         setz    al
  83.         movzx   eax, al
  84.         push    eax
  85.         call    drawwindow_IV
  86.         jmp     window._.draw_window_caption.2
  87. ;--------------------------------------
  88. align 4
  89. .exit:
  90.         ret
  91. ;------------------------------------------------------------------------------
  92. align 4
  93. ;------------------------------------------------------------------------------
  94. syscall_display_settings: ;///// system function 48 ///////////////////////////
  95. ;------------------------------------------------------------------------------
  96. ;; Redraw screen:
  97. ;< ebx = 0
  98. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  99. ;; Set button style:
  100. ;< ebx = 1
  101. ;< ecx = 0 (flat) or 1 (with gradient)
  102. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  103. ;; Set system color palette:
  104. ;< ebx = 2
  105. ;< ecx = pointer to color table
  106. ;< edx = size of color table
  107. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  108. ;; Get system color palette:
  109. ;< ebx = 3
  110. ;< ecx = pointer to color table buffer
  111. ;< edx = size of color table buffer
  112. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  113. ;; Get skinned caption height:
  114. ;< ebx = 4
  115. ;> eax = height in pixels
  116. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  117. ;; Get screen working area:
  118. ;< ebx = 5
  119. ;> eax = pack[16(left), 16(right)]
  120. ;> ebx = pack[16(top), 16(bottom)]
  121. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  122. ;; Set screen working area:
  123. ;< ebx = 6
  124. ;< ecx = pack[16(left), 16(right)]
  125. ;< edx = pack[16(top), 16(bottom)]
  126. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  127. ;; Get skin margins:
  128. ;< ebx = 7
  129. ;> eax = pack[16(left), 16(right)]
  130. ;> ebx = pack[16(top), 16(bottom)]
  131. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  132. ;; Set skin:
  133. ;< ebx = 8
  134. ;< ecx = pointer to FileInfoBlock struct
  135. ;> eax = FS error code
  136. ;------------------------------------------------------------------------------
  137.         cmp     ebx, .sizeof.ftable / 4
  138.         ja      @f
  139.         jmp     [.ftable + ebx * 4]
  140. ;--------------------------------------
  141. align 4
  142. @@:
  143.         ret
  144. ;------------------------------------------------------------------------------
  145. align 4
  146. syscall_display_settings.00:
  147.         xor     eax, eax
  148.         inc     ebx
  149.         cmp     [windowtypechanged], ebx
  150.         jne     .exit
  151.         mov     [windowtypechanged], eax
  152.  
  153.         jmp     syscall_display_settings._.redraw_whole_screen
  154. ;--------------------------------------
  155. align 4
  156. .exit:
  157.         ret
  158. ;------------------------------------------------------------------------------
  159. align 4
  160. syscall_display_settings.01:
  161.         and     ecx, 1
  162.         cmp     ecx, [buttontype]
  163.         je      .exit
  164.         mov     [buttontype], ecx
  165.         mov     [windowtypechanged], ebx
  166. ;--------------------------------------
  167. align 4
  168.   .exit:
  169.         ret
  170. ;------------------------------------------------------------------------------
  171. align 4
  172. syscall_display_settings.02:
  173.         dec     ebx
  174.         mov     esi, ecx
  175.         and     edx, 127
  176.         mov     edi, common_colours
  177.         mov     ecx, edx
  178.         rep movsb
  179.         mov     [windowtypechanged], ebx
  180.         ret
  181. ;------------------------------------------------------------------------------
  182. align 4
  183. syscall_display_settings.03:
  184.         mov     edi, ecx
  185.         and     edx, 127
  186.         mov     esi, common_colours
  187.         mov     ecx, edx
  188.         rep movsb
  189.         ret
  190. ;------------------------------------------------------------------------------
  191. align 4
  192. syscall_display_settings.04:
  193.         mov     eax, [_skinh]
  194.         mov     [esp + 32], eax
  195.         ret
  196. ;------------------------------------------------------------------------------
  197. align 4
  198. syscall_display_settings.05:
  199.         mov     eax, [screen_workarea.left - 2]
  200.         mov     ax, word[screen_workarea.right]
  201.         mov     [esp + 32], eax
  202.         mov     eax, [screen_workarea.top - 2]
  203.         mov     ax, word[screen_workarea.bottom]
  204.         mov     [esp + 20], eax
  205.         ret
  206. ;------------------------------------------------------------------------------
  207. align 4
  208. syscall_display_settings.06:
  209.         xor     esi, esi
  210.  
  211.         mov     edi, [Screen_Max_X]
  212.         mov     eax, ecx
  213.         movsx   ebx, ax
  214.         sar     eax, 16
  215.         cmp     eax, ebx
  216.         jge     .check_horizontal
  217.         inc     esi
  218.         or      eax, eax
  219.         jge     @f
  220.         xor     eax, eax
  221. ;--------------------------------------
  222. align 4
  223. @@:
  224.         mov     [screen_workarea.left], eax
  225.         cmp     ebx, edi
  226.         jle     @f
  227.         mov     ebx, edi
  228. ;--------------------------------------
  229. align 4
  230. @@:
  231.         mov     [screen_workarea.right], ebx
  232. ;--------------------------------------
  233. align 4
  234. .check_horizontal:
  235.         mov     edi, [Screen_Max_Y]
  236.         mov     eax, edx
  237.         movsx   ebx, ax
  238.         sar     eax, 16
  239.         cmp     eax, ebx
  240.         jge     .check_if_redraw_needed
  241.         inc     esi
  242.         or      eax, eax
  243.         jge     @f
  244.         xor     eax, eax
  245. ;--------------------------------------
  246. align 4
  247. @@:
  248.         mov     [screen_workarea.top], eax
  249.         cmp     ebx, edi
  250.         jle     @f
  251.         mov     ebx, edi
  252. ;--------------------------------------
  253. align 4
  254. @@:
  255.         mov     [screen_workarea.bottom], ebx
  256. ;--------------------------------------
  257. align 4
  258. .check_if_redraw_needed:
  259.         or      esi, esi
  260.         jz      .exit
  261.  
  262.         call    repos_windows
  263.         jmp     syscall_display_settings._.calculate_whole_screen
  264. ;--------------------------------------
  265. align 4
  266. .exit:
  267.         ret
  268. ;------------------------------------------------------------------------------
  269. align 4
  270. syscall_display_settings.07:
  271.         mov     eax, [_skinmargins + 0]
  272.         mov     [esp + 32], eax
  273.         mov     eax, [_skinmargins + 4]
  274.         mov     [esp + 20], eax
  275.         ret
  276. ;------------------------------------------------------------------------------
  277. align 4
  278. syscall_display_settings.08:
  279.         mov     ebx, ecx
  280.         call    read_skin_file
  281.         mov     [esp + 32], eax
  282.         test    eax, eax
  283.         jnz     .exit
  284.  
  285.         call    syscall_display_settings._.calculate_whole_screen
  286.         jmp     syscall_display_settings._.redraw_whole_screen
  287. ;--------------------------------------
  288. align 4
  289. .exit:
  290.         ret
  291. ;------------------------------------------------------------------------------
  292. align 4
  293. syscall_display_settings._.calculate_whole_screen:
  294.         xor     eax, eax
  295.         xor     ebx, ebx
  296.         mov     ecx, [Screen_Max_X]
  297.         mov     edx, [Screen_Max_Y]
  298.         jmp     calculatescreen
  299. ;------------------------------------------------------------------------------
  300. align 4
  301. syscall_display_settings._.redraw_whole_screen:
  302.         xor     eax, eax
  303.         mov     [draw_limits.left], eax
  304.         mov     [draw_limits.top], eax
  305.         mov     eax, [Screen_Max_X]
  306.         mov     [draw_limits.right], eax
  307.         mov     eax, [Screen_Max_Y]
  308.         mov     [draw_limits.bottom], eax
  309.         mov     eax, window_data
  310.         jmp     redrawscreen
  311. ;------------------------------------------------------------------------------
  312. align 4
  313. ;------------------------------------------------------------------------------
  314. syscall_set_window_shape: ;///// system function 50 ///////////////////////////
  315. ;------------------------------------------------------------------------------
  316. ;; Set window shape address:
  317. ;> ebx = 0
  318. ;> ecx = shape data address
  319. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  320. ;; Set window shape scale:
  321. ;> ebx = 1
  322. ;> ecx = scale power (resulting scale is 2^ebx)
  323. ;------------------------------------------------------------------------------
  324.         mov     edi, [current_slot]
  325.  
  326.         test    ebx, ebx
  327.         jne     .shape_scale
  328.         mov     [edi + APPDATA.wnd_shape], ecx
  329. ;--------------------------------------
  330. align 4
  331. .shape_scale:
  332.         dec     ebx
  333.         jnz     .exit
  334.         mov     [edi + APPDATA.wnd_shape_scale], ecx
  335. ;--------------------------------------
  336. align 4
  337. .exit:
  338.         ret
  339. ;------------------------------------------------------------------------------
  340. align 4
  341. ;------------------------------------------------------------------------------
  342. syscall_move_window: ;///// system function 67 ////////////////////////////////
  343. ;------------------------------------------------------------------------------
  344. ;? <description>
  345. ;------------------------------------------------------------------------------
  346.         mov     edi, [CURRENT_TASK]
  347.         shl     edi, 5
  348.         add     edi, window_data
  349.  
  350.         test    [edi + WDATA.fl_wdrawn], 1
  351.         jz      .exit
  352.  
  353.         test    [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED
  354.         jnz     .exit
  355.  
  356.         cmp     ebx, -1
  357.         jne     @f
  358.         mov     ebx, [edi + WDATA.box.left]
  359. ;--------------------------------------
  360. align 4
  361. @@:
  362.         cmp     ecx, -1
  363.         jne     @f
  364.         mov     ecx, [edi + WDATA.box.top]
  365. ;--------------------------------------
  366. align 4
  367. @@:
  368.         cmp     edx, -1
  369.         jne     @f
  370.         mov     edx, [edi + WDATA.box.width]
  371. ;--------------------------------------
  372. align 4
  373. @@:
  374.         cmp     esi, -1
  375.         jne     @f
  376.         mov     esi, [edi + WDATA.box.height]
  377. ;--------------------------------------
  378. align 4
  379. @@:
  380.         push    esi edx ecx ebx
  381.         mov     eax, esp
  382.         mov     bl, [edi + WDATA.fl_wstate]
  383.         call    window._.set_window_box
  384.         add     esp, sizeof.BOX
  385.  
  386.         ; NOTE: do we really need this? to be reworked
  387. ;       mov     byte[DONT_DRAW_MOUSE], 0 ; mouse pointer
  388. ;       mov     byte[MOUSE_BACKGROUND], 0 ; no mouse under
  389. ;       mov     byte[MOUSE_DOWN], 0 ; react to mouse up/down
  390.  
  391.         ; NOTE: do we really need this? to be reworked
  392. ;       call    [draw_pointer]
  393. ;--------------------------------------
  394. align 4
  395. .exit:
  396.         ret
  397. ;------------------------------------------------------------------------------
  398. align 4
  399. ;------------------------------------------------------------------------------
  400. syscall_window_settings: ;///// system function 71 /////////////////////////////
  401. ;------------------------------------------------------------------------------
  402. ;? <description>
  403. ;------------------------------------------------------------------------------
  404.         dec     ebx     ; subfunction #1 - set window caption
  405.         jnz     .exit_fail
  406.  
  407.         ; NOTE: only window owner thread can set its caption,
  408.         ;       so there's no parameter for PID/TID
  409.  
  410.         mov     edi, [CURRENT_TASK]
  411.         shl     edi, 5
  412.  
  413.         mov     [edi * 8 + SLOT_BASE + APPDATA.wnd_caption], ecx
  414.         or      [edi + window_data + WDATA.fl_wstyle], WSTYLE_HASCAPTION
  415.  
  416.         call    window._.draw_window_caption
  417.  
  418.         xor     eax, eax ; eax = 0 (success)
  419.         ret
  420.  
  421. ;  .get_window_caption:
  422. ;        dec     eax     ; subfunction #2 - get window caption
  423. ;        jnz     .exit_fail
  424.  
  425.         ; not implemented yet
  426. ;--------------------------------------
  427. align 4
  428. .exit_fail:
  429.         xor     eax, eax
  430.         inc     eax     ; eax = 1 (fail)
  431.         ret
  432. ;------------------------------------------------------------------------------
  433. align 4
  434. ;------------------------------------------------------------------------------
  435. set_window_defaults: ;/////////////////////////////////////////////////////////
  436. ;------------------------------------------------------------------------------
  437. ;? <description>
  438. ;------------------------------------------------------------------------------
  439.         mov     byte [window_data + 0x20 + WDATA.cl_titlebar + 3], 1 ; desktop is not movable
  440.         push    eax ecx
  441.         xor     eax, eax
  442.         mov     ecx, WIN_STACK
  443. ;--------------------------------------
  444. align 4
  445. @@:
  446.         inc     eax
  447.         add     ecx, 2
  448.         ; process no
  449.         mov     [ecx + 0x000], ax
  450.         ; positions in stack
  451.         mov     [ecx + 0x400], ax
  452.         cmp     ecx, WIN_POS - 2
  453.         jne     @b
  454.         pop     ecx eax
  455.         ret
  456. ;------------------------------------------------------------------------------
  457. align 4
  458. ;------------------------------------------------------------------------------
  459. calculatescreen: ;/////////////////////////////////////////////////////////////
  460. ;------------------------------------------------------------------------------
  461. ;? Scan all windows from bottom to top, calling `setscreen` for each one
  462. ;? intersecting given screen area
  463. ;------------------------------------------------------------------------------
  464. ;> eax = left
  465. ;> ebx = top
  466. ;> ecx = right
  467. ;> edx = bottom
  468. ;------------------------------------------------------------------------------
  469.         push    esi
  470.         pushfd
  471.         cli
  472.  
  473.         mov     esi, 1
  474.         call    window._.set_screen
  475.  
  476.         push    ebp
  477.  
  478.         mov     ebp, [TASK_COUNT]
  479.         cmp     ebp, 1
  480.         jbe     .exit
  481.  
  482.         push    edx ecx ebx eax
  483. ;--------------------------------------
  484. align 4
  485. .next_window:
  486.         movzx   edi, word[WIN_POS + esi * 2]
  487.         shl     edi, 5
  488.  
  489.         cmp     [CURRENT_TASK + edi + TASKDATA.state], TSTATE_FREE
  490.         je      .skip_window
  491.  
  492.         add     edi, window_data
  493.         test    [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  494.         jnz     .skip_window
  495.  
  496.         mov     eax, [edi + WDATA.box.left]
  497.         cmp     eax, [esp + RECT.right]
  498.         jg      .skip_window
  499.         mov     ebx, [edi + WDATA.box.top]
  500.         cmp     ebx, [esp + RECT.bottom]
  501.         jg      .skip_window
  502.         mov     ecx, [edi + WDATA.box.width]
  503.         add     ecx, eax
  504.         cmp     ecx, [esp + RECT.left]
  505.         jl      .skip_window
  506.         mov     edx, [edi + WDATA.box.height]
  507.         add     edx, ebx
  508.         cmp     edx, [esp + RECT.top]
  509.         jl      .skip_window
  510.  
  511.         cmp     eax, [esp + RECT.left]
  512.         jae     @f
  513.         mov     eax, [esp + RECT.left]
  514. ;--------------------------------------
  515. align 4
  516. @@:
  517.         cmp     ebx, [esp + RECT.top]
  518.         jae     @f
  519.         mov     ebx, [esp + RECT.top]
  520. ;--------------------------------------
  521. align 4
  522. @@:
  523.         cmp     ecx, [esp + RECT.right]
  524.         jbe     @f
  525.         mov     ecx, [esp + RECT.right]
  526. ;--------------------------------------
  527. align 4
  528. @@:
  529.         cmp     edx, [esp + RECT.bottom]
  530.         jbe     @f
  531.         mov     edx, [esp + RECT.bottom]
  532. ;--------------------------------------
  533. align 4
  534. @@:
  535.         push    esi
  536.         movzx   esi, word[WIN_POS + esi * 2]
  537.         call    window._.set_screen
  538.         pop     esi
  539. ;--------------------------------------
  540. align 4
  541. .skip_window:
  542.         inc     esi
  543.         dec     ebp
  544.         jnz     .next_window
  545.  
  546.         pop     eax ebx ecx edx
  547. ;--------------------------------------
  548. align 4
  549. .exit:
  550.         pop     ebp
  551.         popfd
  552.         pop     esi
  553.         ret
  554. ;------------------------------------------------------------------------------
  555. align 4
  556. ;------------------------------------------------------------------------------
  557. repos_windows: ;///////////////////////////////////////////////////////////////
  558. ;------------------------------------------------------------------------------
  559. ;? <description>
  560. ;------------------------------------------------------------------------------
  561.         mov     ecx, [TASK_COUNT]
  562.         mov     edi, window_data + sizeof.WDATA * 2
  563.         call    force_redraw_background
  564.         dec     ecx
  565.         jle     .exit
  566. ;--------------------------------------
  567. align 4
  568. .next_window:
  569.         mov     [edi + WDATA.fl_redraw], 1
  570.         test    [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED
  571.         jnz     .fix_maximized
  572.  
  573.         mov     eax, [edi + WDATA.box.left]
  574.         add     eax, [edi + WDATA.box.width]
  575.         mov     ebx, [Screen_Max_X]
  576.         cmp     eax, ebx
  577.         jle     .fix_vertical
  578.         mov     eax, [edi + WDATA.box.width]
  579.         sub     eax, ebx
  580.         jle     @f
  581.         mov     [edi + WDATA.box.width], ebx
  582. ;--------------------------------------
  583. align 4
  584. @@:
  585.         sub     ebx, [edi + WDATA.box.width]
  586.         mov     [edi + WDATA.box.left], ebx
  587. ;--------------------------------------
  588. align 4
  589. .fix_vertical:
  590.         mov     eax, [edi + WDATA.box.top]
  591.         add     eax, [edi + WDATA.box.height]
  592.         mov     ebx, [Screen_Max_Y]
  593.         cmp     eax, ebx
  594.         jle     .fix_client_box
  595.         mov     eax, [edi + WDATA.box.height]
  596.         sub     eax, ebx
  597.         jle     @f
  598.         mov     [edi + WDATA.box.height], ebx
  599. ;--------------------------------------
  600. align 4
  601. @@:
  602.         sub     ebx, [edi + WDATA.box.height]
  603.         mov     [edi + WDATA.box.top], ebx
  604. ;--------------------------------------
  605. align 4
  606. .fix_client_box:
  607.         call    window._.set_window_clientbox
  608.         add     edi, sizeof.WDATA
  609.         loop    .next_window
  610. ;--------------------------------------
  611. align 4
  612. .exit:
  613.         ret
  614. ;--------------------------------------
  615. align 4
  616. .fix_maximized:
  617.         mov     eax, [screen_workarea.left]
  618.         mov     [edi + WDATA.box.left], eax
  619.         sub     eax, [screen_workarea.right]
  620.         neg     eax
  621.         mov     [edi + WDATA.box.width], eax
  622.         mov     eax, [screen_workarea.top]
  623.         mov     [edi + WDATA.box.top], eax
  624.         test    [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP
  625.         jnz     .fix_client_box
  626.         sub     eax, [screen_workarea.bottom]
  627.         neg     eax
  628.         mov     [edi + WDATA.box.height], eax
  629.         jmp     .fix_client_box
  630. ;------------------------------------------------------------------------------
  631. ;align 4
  632. ;------------------------------------------------------------------------------
  633. ;sys_window_mouse: ;////////////////////////////////////////////////////////////
  634. ;------------------------------------------------------------------------------
  635. ;? <description>
  636. ;------------------------------------------------------------------------------
  637.         ; NOTE: commented out since doesn't provide necessary functionality
  638.         ;       anyway, to be reworked
  639. ;       push    eax
  640. ;
  641. ;       mov     eax, [timer_ticks]
  642. ;       cmp     [new_window_starting], eax
  643. ;       jb      .exit
  644. ;
  645. ;       mov     byte[MOUSE_BACKGROUND], 0
  646. ;       mov     byte[DONT_DRAW_MOUSE], 0
  647. ;
  648. ;       mov     [new_window_starting], eax
  649. ;
  650. ; .exit:
  651. ;       pop     eax
  652. ;        ret
  653. ;------------------------------------------------------------------------------
  654. align 4
  655. ;------------------------------------------------------------------------------
  656. draw_rectangle: ;//////////////////////////////////////////////////////////////
  657. ;------------------------------------------------------------------------------
  658. ;> eax = pack[16(left), 16(right)]
  659. ;> ebx = pack[16(top), 16(bottom)]
  660. ;> esi = color
  661. ;       ?? RR GG BB    ; 0x01000000 negation
  662. ;                      ; 0x02000000 used for draw_rectangle without top line
  663. ;                      ;           for example drawwindow_III and drawwindow_IV
  664. ;------------------------------------------------------------------------------
  665.         push    eax ebx ecx edi
  666.  
  667.         xor     edi, edi
  668. ;--------------------------------------
  669. align 4
  670. .flags_set:
  671.         push    ebx
  672.  
  673.         ; set line color
  674.         mov     ecx, esi
  675.         ; draw top border
  676.         rol     ebx, 16
  677.         push    ebx
  678.         rol     ebx, 16
  679.         pop     bx
  680.         test    ecx, 1 shl 25
  681.         jnz     @f
  682.         sub     ecx, 1 shl 25
  683.         call    [draw_line]
  684. ;--------------------------------------
  685. align 4
  686. @@:
  687.         ; draw bottom border
  688.         mov     ebx, [esp - 2]
  689.         pop     bx
  690.         call    [draw_line]
  691.  
  692.         pop     ebx
  693.         add     ebx, 1 * 65536 - 1
  694.  
  695.         ; draw left border
  696.         rol     eax, 16
  697.         push    eax
  698.         rol     eax, 16
  699.         pop     ax
  700.         call    [draw_line]
  701.  
  702.         ; draw right border
  703.         mov     eax, [esp - 2]
  704.         pop     ax
  705.         call    [draw_line]
  706.  
  707.         pop     edi ecx ebx eax
  708.         ret
  709. ;--------------------------------------
  710. align 4
  711. .forced:
  712.         push    eax ebx ecx edi
  713.         xor     edi, edi
  714.         inc     edi
  715.         jmp     .flags_set
  716. ;------------------------------------------------------------------------------
  717. align 4
  718. ;------------------------------------------------------------------------------
  719. drawwindow_I_caption: ;////////////////////////////////////////////////////////
  720. ;------------------------------------------------------------------------------
  721. ;? <description>
  722. ;------------------------------------------------------------------------------
  723.         push    [edx + WDATA.cl_titlebar]
  724.         mov     esi, edx
  725.  
  726.         mov     edx, [esi + WDATA.box.top]
  727.         mov     eax, edx
  728.         lea     ebx, [edx + 21]
  729.         inc     edx
  730.         add     eax, [esi + WDATA.box.height]
  731.  
  732.         cmp     ebx, eax
  733.         jbe     @f
  734.         mov     ebx, eax
  735. ;--------------------------------------
  736. align 4
  737. @@:
  738.         push    ebx
  739.  
  740.         xor     edi, edi
  741. ;--------------------------------------
  742. align 4
  743. .next_line:
  744.         mov     ebx, edx
  745.         shl     ebx, 16
  746.         add     ebx, edx
  747.         mov     eax, [esi + WDATA.box.left]
  748.         inc     eax
  749.         shl     eax, 16
  750.         add     eax, [esi + WDATA.box.left]
  751.         add     eax, [esi + WDATA.box.width]
  752.         dec     eax
  753.         mov     ecx, [esi + WDATA.cl_titlebar]
  754.         test    ecx, 0x80000000
  755.         jz      @f
  756.         sub     ecx, 0x00040404
  757.         mov     [esi + WDATA.cl_titlebar], ecx
  758. ;--------------------------------------
  759. align 4
  760. @@:
  761.         and     ecx, 0x00ffffff
  762.         call    [draw_line]
  763.         inc     edx
  764.         cmp     edx, [esp]
  765.         jb      .next_line
  766.  
  767.         add     esp, 4
  768.         pop     [esi + WDATA.cl_titlebar]
  769.         ret
  770. ;------------------------------------------------------------------------------
  771. align 4
  772. ;------------------------------------------------------------------------------
  773. drawwindow_I: ;////////////////////////////////////////////////////////////////
  774. ;------------------------------------------------------------------------------
  775. ;? <description>
  776. ;------------------------------------------------------------------------------
  777.         pushad
  778.  
  779.         ; window border
  780.  
  781.         mov     eax, [edx + WDATA.box.left - 2]
  782.         mov     ax, word[edx + WDATA.box.left]
  783.         add     ax, word[edx + WDATA.box.width]
  784.         mov     ebx, [edx + WDATA.box.top - 2]
  785.         mov     bx, word[edx + WDATA.box.top]
  786.         add     bx, word[edx + WDATA.box.height]
  787.  
  788.         mov     esi, [edx + WDATA.cl_frames]
  789.         call    draw_rectangle
  790.  
  791.         ; window caption
  792.  
  793.         call    drawwindow_I_caption
  794.  
  795.         ; window client area
  796.  
  797.         ; do we need to draw it?
  798.         mov     edi, [esi + WDATA.cl_workarea]
  799.         test    edi, 0x40000000
  800.         jnz     .exit
  801.  
  802.         ; does client area have a positive size on screen?
  803.         mov     edx, [esi + WDATA.box.top]
  804.         add     edx, 21 + 5
  805.         mov     ebx, [esi + WDATA.box.top]
  806.         add     ebx, [esi + WDATA.box.height]
  807.         cmp     edx, ebx
  808.         jg      .exit
  809.  
  810.         ; okay, let's draw it
  811.         mov     eax, 1
  812.         mov     ebx, 21
  813.         mov     ecx, [esi + WDATA.box.width]
  814.         mov     edx, [esi + WDATA.box.height]
  815.         call    [drawbar]
  816. ;--------------------------------------
  817. align 4
  818. .exit:
  819.         popad
  820.         ret
  821. ;------------------------------------------------------------------------------
  822. align 4
  823. ;------------------------------------------------------------------------------
  824. drawwindow_III_caption: ;/////////////////////////////////////////////////////
  825. ;------------------------------------------------------------------------------
  826. ;? <description>
  827. ;------------------------------------------------------------------------------
  828.         mov     ecx, [edx + WDATA.cl_titlebar]
  829.         push    ecx
  830.         mov     esi, edx
  831.         mov     edx, [esi + WDATA.box.top]
  832.         add     edx, 4
  833.         mov     ebx, [esi + WDATA.box.top]
  834.         add     ebx, 20
  835.         mov     eax, [esi + WDATA.box.top]
  836.         add     eax, [esi + WDATA.box.height]
  837.  
  838.         cmp     ebx, eax
  839.         jb      @f
  840.         mov     ebx, eax
  841. ;--------------------------------------
  842. align 4
  843. @@:
  844.         push    ebx
  845.  
  846.         xor     edi, edi
  847. ;--------------------------------------
  848. align 4
  849. .next_line:
  850.         mov     ebx, edx
  851.         shl     ebx, 16
  852.         add     ebx, edx
  853.         mov     eax, [esi + WDATA.box.left]
  854.         shl     eax, 16
  855.         add     eax, [esi + WDATA.box.left]
  856.         add     eax, [esi + WDATA.box.width]
  857.         add     eax, 4 * 65536 - 4
  858.         mov     ecx, [esi + WDATA.cl_titlebar]
  859.         test    ecx, 0x40000000
  860.         jz      @f
  861.         add     ecx, 0x00040404
  862. ;--------------------------------------
  863. align 4
  864. @@:
  865.         test    ecx, 0x80000000
  866.         jz      @f
  867.         sub     ecx, 0x00040404
  868. ;--------------------------------------
  869. align 4
  870. @@:
  871.         mov     [esi + WDATA.cl_titlebar], ecx
  872.         and     ecx, 0x00ffffff
  873.         call    [draw_line]
  874.         inc     edx
  875.         cmp     edx, [esp]
  876.         jb      .next_line
  877.  
  878.         add     esp, 4
  879.         pop     [esi + WDATA.cl_titlebar]
  880.         ret
  881. ;------------------------------------------------------------------------------
  882. align 4
  883. ;------------------------------------------------------------------------------
  884. drawwindow_III: ;//////////////////////////////////////////////////////////////
  885. ;------------------------------------------------------------------------------
  886. ;? <description>
  887. ;------------------------------------------------------------------------------
  888.         pushad
  889.  
  890.         ; window border
  891.  
  892.         mov     eax, [edx + WDATA.box.left - 2]
  893.         mov     ax, word[edx + WDATA.box.left]
  894.         add     ax, word[edx + WDATA.box.width]
  895.         mov     ebx, [edx + WDATA.box.top - 2]
  896.         mov     bx, word[edx + WDATA.box.top]
  897.         add     bx, word[edx + WDATA.box.height]
  898.  
  899.         mov     esi, [edx + WDATA.cl_frames]
  900.         shr     esi, 1
  901.         and     esi, 0x007f7f7f
  902.         or      esi, 1 shl 25; 0x02000000 used for draw_rectangle without top line
  903.         ror     ebx, 16
  904.         add     ebx, [_skinh]
  905.         sub     bx, 1
  906.         rol     ebx, 16
  907.         call    draw_rectangle
  908.  
  909.         push    esi
  910.         mov     ecx, 3
  911.         mov     esi, [edx + WDATA.cl_frames]
  912.         or      esi, 1 shl 25; 0x02000000 used for draw_rectangle without top line
  913. ;--------------------------------------
  914. align 4
  915. .next_frame:
  916.         add     eax, 1 * 65536 - 1
  917.         add     ebx, 0 * 65536 - 1
  918.         call    draw_rectangle
  919.         dec     ecx
  920.         jnz     .next_frame
  921.  
  922.         pop     esi
  923.         add     eax, 1 * 65536 - 1
  924.         add     ebx, 0 * 65536 - 1
  925.         call    draw_rectangle
  926.  
  927.         ; window caption
  928.  
  929.         call    drawwindow_III_caption
  930.  
  931.         ; window client area
  932.  
  933.         ; do we need to draw it?
  934.         mov     edi, [esi + WDATA.cl_workarea]
  935.         test    edi, 0x40000000
  936.         jnz     .exit
  937.  
  938.         ; does client area have a positive size on screen?
  939.         mov     edx, [esi + WDATA.box.top]
  940.         add     edx, 21 + 5
  941.         mov     ebx, [esi + WDATA.box.top]
  942.         add     ebx, [esi + WDATA.box.height]
  943.         cmp     edx, ebx
  944.         jg      .exit
  945.  
  946.         ; okay, let's draw it
  947.         mov     eax, 5
  948.         mov     ebx, 20
  949.         mov     ecx, [esi + WDATA.box.width]
  950.         mov     edx, [esi + WDATA.box.height]
  951.         sub     ecx, 4
  952.         sub     edx, 4
  953.         call    [drawbar]
  954. ;--------------------------------------
  955. align 4
  956. .exit:
  957.         popad
  958.         ret
  959. ;------------------------------------------------------------------------------
  960. align 4
  961. ;------------------------------------------------------------------------------
  962. waredraw: ;////////////////////////////////////////////////////////////////////
  963. ;------------------------------------------------------------------------------
  964. ;? Activate window, redrawing if necessary
  965. ;------------------------------------------------------------------------------
  966.         push    -1
  967.         mov     eax, [TASK_COUNT]
  968.         lea     eax, [WIN_POS + eax * 2]
  969.         cmp     eax, esi
  970.         pop     eax
  971.         je      .exit
  972.  
  973.         ; is it overlapped by another window now?
  974.         push    ecx
  975.         call    window._.check_window_draw
  976.         test    ecx, ecx
  977.         pop     ecx
  978.         jz      .do_not_draw
  979.  
  980.         ; yes it is, activate and update screen buffer
  981.         mov     byte[MOUSE_DOWN], 1
  982.         call    window._.window_activate
  983.  
  984.         pushad
  985.         mov     edi, [TASK_COUNT]
  986.         movzx   esi, word[WIN_POS + edi * 2]
  987.         shl     esi, 5
  988.         add     esi, window_data
  989.  
  990.         mov     eax, [esi + WDATA.box.left]
  991.         mov     ebx, [esi + WDATA.box.top]
  992.         mov     ecx, [esi + WDATA.box.width]
  993.         mov     edx, [esi + WDATA.box.height]
  994.  
  995.         add     ecx, eax
  996.         add     edx, ebx
  997.  
  998.         mov     edi, [TASK_COUNT]
  999.         movzx   esi, word[WIN_POS + edi * 2]
  1000.         call    window._.set_screen
  1001.         popad
  1002.  
  1003.         ; tell application to redraw itself
  1004.         mov     [edi + WDATA.fl_redraw], 1
  1005.         xor     eax, eax
  1006.         jmp     .exit
  1007. ;--------------------------------------
  1008. align 4
  1009. .do_not_draw:
  1010.         ; no it's not, just activate the window
  1011.         call    window._.window_activate
  1012.         xor     eax, eax
  1013.         mov     byte[MOUSE_BACKGROUND], al
  1014.         mov     byte[DONT_DRAW_MOUSE], al
  1015. ;--------------------------------------
  1016. align 4
  1017. .exit:
  1018.         mov     byte[MOUSE_DOWN], 0
  1019.         inc     eax
  1020.         ret
  1021. ;------------------------------------------------------------------------------
  1022. align 4
  1023. ;------------------------------------------------------------------------------
  1024. minimize_window: ;/////////////////////////////////////////////////////////////
  1025. ;------------------------------------------------------------------------------
  1026. ;> eax = window number on screen
  1027. ;------------------------------------------------------------------------------
  1028. ;# corrupts [dl*]
  1029. ;------------------------------------------------------------------------------
  1030.         push    edi
  1031.         pushfd
  1032.         cli
  1033.  
  1034.         ; is it already minimized?
  1035.         movzx   edi, word[WIN_POS + eax * 2]
  1036.         shl     edi, 5
  1037.         add     edi, window_data
  1038.         test    [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  1039.         jnz     .exit
  1040.  
  1041.         push    eax ebx ecx edx esi
  1042.  
  1043.         ; no it's not, let's do that
  1044.         or      [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  1045.         mov     eax, [edi + WDATA.box.left]
  1046.         mov     [draw_limits.left], eax
  1047.         mov     ecx, eax
  1048.         add     ecx, [edi + WDATA.box.width]
  1049.         mov     [draw_limits.right], ecx
  1050.         mov     ebx, [edi + WDATA.box.top]
  1051.         mov     [draw_limits.top], ebx
  1052.         mov     edx, ebx
  1053.         add     edx, [edi + WDATA.box.height]
  1054.         mov     [draw_limits.bottom], edx
  1055.         call    calculatescreen
  1056.         xor     esi, esi
  1057.         xor     eax, eax
  1058.         call    redrawscreen
  1059.  
  1060.         pop     esi edx ecx ebx eax
  1061. ;--------------------------------------
  1062. align 4
  1063. .exit:
  1064.         popfd
  1065.         pop     edi
  1066.         ret
  1067. ;------------------------------------------------------------------------------
  1068. align 4
  1069. ;------------------------------------------------------------------------------
  1070. restore_minimized_window: ;////////////////////////////////////////////////////
  1071. ;------------------------------------------------------------------------------
  1072. ;> eax = window number on screen
  1073. ;------------------------------------------------------------------------------
  1074. ;# corrupts [dl*]
  1075. ;------------------------------------------------------------------------------
  1076.         pushad
  1077.         pushfd
  1078.         cli
  1079.  
  1080.         ; is it already restored?
  1081.         movzx   esi, word[WIN_POS + eax * 2]
  1082.         mov     edi, esi
  1083.         shl     edi, 5
  1084.         add     edi, window_data
  1085.         test    [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  1086.         jz      .exit
  1087.  
  1088.         ; no it's not, let's do that
  1089.         mov     [edi + WDATA.fl_redraw], 1
  1090.         and     [edi + WDATA.fl_wstate], not WSTATE_MINIMIZED
  1091.         mov     ebp, window._.set_screen
  1092.         cmp     eax, [TASK_COUNT]
  1093.         jz      @f
  1094.         mov     ebp, calculatescreen
  1095. ;--------------------------------------
  1096. align 4
  1097. @@:
  1098.         mov     eax, [edi + WDATA.box.left]
  1099.         mov     ebx, [edi + WDATA.box.top]
  1100.         mov     ecx, [edi + WDATA.box.width]
  1101.         mov     edx, [edi + WDATA.box.height]
  1102.         add     ecx, eax
  1103.         add     edx, ebx
  1104.         call    ebp
  1105.  
  1106.         mov     byte[MOUSE_BACKGROUND], 0
  1107. ;--------------------------------------
  1108. align 4
  1109. .exit:
  1110.         popfd
  1111.         popad
  1112.         ret
  1113. ;------------------------------------------------------------------------------
  1114. align 4
  1115. ; TODO: remove this proc
  1116. ;------------------------------------------------------------------------------
  1117. window_check_events: ;/////////////////////////////////////////////////////////
  1118. ;------------------------------------------------------------------------------
  1119. ;? <description>
  1120. ;------------------------------------------------------------------------------
  1121.         ; do we have window minimize/restore request?
  1122.         cmp     [window_minimize], 0
  1123.         je      .exit
  1124.  
  1125.         ; okay, minimize or restore top-most window and exit
  1126.         mov     eax, [TASK_COUNT]
  1127.         mov     bl, 0
  1128.         xchg    [window_minimize], bl
  1129.         dec     bl
  1130.         jnz     @f
  1131.         call    minimize_window
  1132.         jmp     .exit
  1133. ;--------------------------------------
  1134. align 4
  1135. @@:
  1136.         call    restore_minimized_window
  1137. ;--------------------------------------
  1138. align 4
  1139. .exit:
  1140.         ret
  1141. ;------------------------------------------------------------------------------
  1142. align 4
  1143. ;------------------------------------------------------------------------------
  1144. sys_window_maximize_handler: ;/////////////////////////////////////////////////
  1145. ;------------------------------------------------------------------------------
  1146. ;? <description>
  1147. ;------------------------------------------------------------------------------
  1148. ;> esi = process slot
  1149. ;------------------------------------------------------------------------------
  1150.         mov     edi, esi
  1151.         shl     edi, 5
  1152.         add     edi, window_data
  1153.  
  1154.         ; can window change its height?
  1155.         ; only types 2 and 3 can be resized
  1156.         mov     dl, [edi + WDATA.fl_wstyle]
  1157.         test    dl, 2
  1158.         jz      .exit
  1159.  
  1160.         ; toggle normal/maximized window state
  1161.         mov     bl, [edi + WDATA.fl_wstate]
  1162.         xor     bl, WSTATE_MAXIMIZED
  1163.  
  1164.         ; calculate and set appropriate window bounds
  1165.         test    bl, WSTATE_MAXIMIZED
  1166.         jz      .restore_size
  1167.  
  1168.         mov     eax, [screen_workarea.left]
  1169.         mov     ecx, [screen_workarea.top]
  1170.         push    [screen_workarea.bottom] \
  1171.                 [screen_workarea.right] \
  1172.                 ecx \
  1173.                 eax
  1174.         sub     [esp + BOX.width], eax
  1175.         sub     [esp + BOX.height], ecx
  1176.         mov     eax, esp
  1177.         jmp     .set_box
  1178. ;--------------------------------------
  1179. align 4
  1180. .restore_size:
  1181.         mov     eax, esi
  1182.         shl     eax, 8
  1183.         add     eax, SLOT_BASE + APPDATA.saved_box
  1184.         push    [eax + BOX.height] \
  1185.                 [eax + BOX.width] \
  1186.                 [eax + BOX.top] \
  1187.                 [eax + BOX.left]
  1188.         mov     eax, esp
  1189. ;--------------------------------------
  1190. align 4
  1191. .set_box:
  1192.         test    bl, WSTATE_ROLLEDUP
  1193.         jz      @f
  1194.  
  1195.         xchg    eax, ecx
  1196.         call    window._.get_rolledup_height
  1197.         mov     [ecx + BOX.height], eax
  1198.         xchg    eax, ecx
  1199. ;--------------------------------------
  1200. align 4
  1201. @@:
  1202.         call    window._.set_window_box
  1203.         add     esp, sizeof.BOX
  1204. ;--------------------------------------
  1205. align 4
  1206. .exit:
  1207.         ret
  1208. ;------------------------------------------------------------------------------
  1209. align 4
  1210. ;------------------------------------------------------------------------------
  1211. sys_window_rollup_handler: ;///////////////////////////////////////////////////
  1212. ;------------------------------------------------------------------------------
  1213. ;? <description>
  1214. ;------------------------------------------------------------------------------
  1215. ;> esi = process slot
  1216. ;------------------------------------------------------------------------------
  1217.         mov     edx, esi
  1218.         shl     edx, 8
  1219.         add     edx, SLOT_BASE
  1220.  
  1221.         ; toggle normal/rolled up window state
  1222.         mov     bl, [edi + WDATA.fl_wstate]
  1223.         xor     bl, WSTATE_ROLLEDUP
  1224.  
  1225.         ; calculate and set appropriate window bounds
  1226.         test    bl, WSTATE_ROLLEDUP
  1227.         jz      .restore_size
  1228.  
  1229.         call    window._.get_rolledup_height
  1230.         push    eax \
  1231.                 [edi + WDATA.box.width] \
  1232.                 [edi + WDATA.box.top] \
  1233.                 [edi + WDATA.box.left]
  1234.         mov     eax, esp
  1235.         jmp     .set_box
  1236. ;--------------------------------------
  1237. align 4
  1238. .restore_size:
  1239.         test    bl, WSTATE_MAXIMIZED
  1240.         jnz     @f
  1241.         add     esp, -sizeof.BOX
  1242.         lea     eax, [edx + APPDATA.saved_box]
  1243.         jmp     .set_box
  1244. ;--------------------------------------
  1245. align 4
  1246. @@:
  1247.         mov     eax, [screen_workarea.top]
  1248.         push    [screen_workarea.bottom] \
  1249.                 [edi + WDATA.box.width] \
  1250.                 eax \
  1251.                 [edi + WDATA.box.left]
  1252.         sub     [esp + BOX.height], eax
  1253.         mov     eax, esp
  1254. ;--------------------------------------
  1255. align 4
  1256. .set_box:
  1257.         call    window._.set_window_box
  1258.         add     esp, sizeof.BOX
  1259.         ret
  1260. ;------------------------------------------------------------------------------
  1261. align 4
  1262. ;------------------------------------------------------------------------------
  1263. sys_window_start_moving_handler: ;/////////////////////////////////////////////
  1264. ;------------------------------------------------------------------------------
  1265. ;? <description>
  1266. ;------------------------------------------------------------------------------
  1267. ;> eax = old (original) window box
  1268. ;> esi = process slot
  1269. ;------------------------------------------------------------------------------
  1270.         mov     edi, eax
  1271.         call    window._.draw_negative_box
  1272.         ret
  1273. ;------------------------------------------------------------------------------
  1274. align 4
  1275. ;------------------------------------------------------------------------------
  1276. sys_window_end_moving_handler: ;///////////////////////////////////////////////
  1277. ;------------------------------------------------------------------------------
  1278. ;? <description>
  1279. ;------------------------------------------------------------------------------
  1280. ;> eax = old (original) window box
  1281. ;> ebx = new (final) window box
  1282. ;> esi = process slot
  1283. ;------------------------------------------------------------------------------
  1284.         mov     edi, ebx
  1285.         call    window._.end_moving__box
  1286.  
  1287.         mov     edi, esi
  1288.         shl     edi, 5
  1289.         add     edi, window_data
  1290.  
  1291.         mov     eax, ebx
  1292.         mov     bl, [edi + WDATA.fl_wstate]
  1293.         call    window._.set_window_box
  1294.         ret
  1295. ;------------------------------------------------------------------------------
  1296. align 4
  1297. ;------------------------------------------------------------------------------
  1298. sys_window_moving_handler: ;///////////////////////////////////////////////////
  1299. ;------------------------------------------------------------------------------
  1300. ;? <description>
  1301. ;------------------------------------------------------------------------------
  1302. ;> eax = old (from previous call) window box
  1303. ;> ebx = new (current) window box
  1304. ;> esi = process_slot
  1305. ;------------------------------------------------------------------------------
  1306.         mov     edi, eax
  1307.         call    window._.draw_negative_box
  1308.         mov     edi, ebx
  1309.         call    window._.draw_negative_box
  1310.         ret
  1311. ;==============================================================================
  1312. ;///// private functions //////////////////////////////////////////////////////
  1313. ;==============================================================================
  1314.  
  1315. iglobal
  1316.   FuncTable syscall_display_settings, ftable, \
  1317.     00, 01, 02, 03, 04, 05, 06, 07, 08
  1318.  
  1319.   align 4
  1320.   window_topleft dd \
  1321.     1, 21, \ ;type 0
  1322.     0,  0, \ ;type 1
  1323.     5, 20, \ ;type 2
  1324.     5,  ?, \ ;type 3 {set by skin}
  1325.     5,  ?    ;type 4 {set by skin}
  1326. endg
  1327.  
  1328. ;uglobal
  1329.   ; NOTE: commented out since doesn't provide necessary functionality anyway,
  1330.   ;       to be reworked
  1331. ; new_window_starting       dd ?
  1332. ;endg
  1333. ;------------------------------------------------------------------------------
  1334. align 4
  1335. ;------------------------------------------------------------------------------
  1336. window._.invalidate_screen: ;//////////////////////////////////////////////////
  1337. ;------------------------------------------------------------------------------
  1338. ;? <description>
  1339. ;------------------------------------------------------------------------------
  1340. ;> eax = old (original) window box
  1341. ;> ebx = new (final) window box
  1342. ;> edi = pointer to WDATA struct
  1343. ;------------------------------------------------------------------------------
  1344.         push    eax ebx
  1345.  
  1346.         ; TODO: do we really need `draw_limits`?
  1347.         ; Yes, they are used by background drawing code.
  1348.         mov     ecx, [eax + BOX.left]
  1349.         mov     edx, [ebx + BOX.left]
  1350.         cmp     ecx, edx
  1351.         jle     @f
  1352.         mov     ecx, edx
  1353. ;--------------------------------------
  1354. align 4
  1355. @@:
  1356.         mov     [draw_limits.left], ecx
  1357.         mov     ecx, [eax + BOX.left]
  1358.         add     ecx, [eax + BOX.width]
  1359.         add     edx, [ebx + BOX.width]
  1360.         cmp     ecx, edx
  1361.         jae     @f
  1362.         mov     ecx, edx
  1363. ;--------------------------------------
  1364. align 4
  1365. @@:
  1366.         mov     [draw_limits.right], ecx
  1367.         mov     ecx, [eax + BOX.top]
  1368.         mov     edx, [ebx + BOX.top]
  1369.         cmp     ecx, edx
  1370.         jle     @f
  1371.         mov     ecx, edx
  1372. ;--------------------------------------
  1373. align 4
  1374. @@:
  1375.         mov     [draw_limits.top], ecx
  1376.         mov     ecx, [eax + BOX.top]
  1377.         add     ecx, [eax + BOX.height]
  1378.         add     edx, [ebx + BOX.height]
  1379.         cmp     ecx, edx
  1380.         jae     @f
  1381.         mov     ecx, edx
  1382. ;--------------------------------------
  1383. align 4
  1384. @@:
  1385.         mov     [draw_limits.bottom], ecx
  1386.         ; recalculate screen buffer at old position
  1387.         push    ebx
  1388.         mov     edx, [eax + BOX.height]
  1389.         mov     ecx, [eax + BOX.width]
  1390.         mov     ebx, [eax + BOX.top]
  1391.         mov     eax, [eax + BOX.left]
  1392.         add     ecx, eax
  1393.         add     edx, ebx
  1394.         call    calculatescreen
  1395.         pop     eax
  1396.         ; recalculate screen buffer at new position
  1397.         mov     edx, [eax + BOX.height]
  1398.         mov     ecx, [eax + BOX.width]
  1399.         mov     ebx, [eax + BOX.top]
  1400.         mov     eax, [eax + BOX.left]
  1401.         add     ecx, eax
  1402.         add     edx, ebx
  1403.         call    calculatescreen
  1404.  
  1405.         mov     eax, edi
  1406.         call    redrawscreen
  1407.  
  1408.         ; tell window to redraw itself
  1409.         mov     [edi + WDATA.fl_redraw], 1
  1410.  
  1411.         pop     ebx eax
  1412.         ret
  1413. ;------------------------------------------------------------------------------
  1414. align 4
  1415. ;------------------------------------------------------------------------------
  1416. window._.set_window_box: ;/////////////////////////////////////////////////////
  1417. ;------------------------------------------------------------------------------
  1418. ;? <description>
  1419. ;------------------------------------------------------------------------------
  1420. ;> eax = pointer to BOX struct
  1421. ;> bl = new window state flags
  1422. ;> edi = pointer to WDATA struct
  1423. ;------------------------------------------------------------------------------
  1424.         push    eax ebx esi
  1425.  
  1426. ; don't do anything if the new box is identical to the old
  1427.         cmp     bl, [edi + WDATA.fl_wstate]
  1428.         jnz     @f
  1429.         mov     esi, eax
  1430.         push    edi
  1431. if WDATA.box
  1432.         add     edi, WDATA.box
  1433. end if
  1434.         mov     ecx, 4
  1435.         repz cmpsd
  1436.         pop     edi
  1437.         jz      .exit
  1438. ;--------------------------------------
  1439. align 4
  1440. @@:
  1441.         add     esp, -sizeof.BOX
  1442.         mov     ebx, esp
  1443. if WDATA.box
  1444.         lea     esi, [edi + WDATA.box]
  1445. else
  1446.         mov     esi, edi ; optimization for WDATA.box = 0
  1447. end if
  1448.         xchg    eax, esi
  1449.         mov     ecx, sizeof.BOX
  1450.         call    memmove
  1451.         xchg    eax, esi
  1452.         xchg    ebx, esi
  1453.         call    memmove
  1454.         mov     eax, ebx
  1455.         mov     ebx, esi
  1456.  
  1457.         call    window._.check_window_position
  1458.         call    window._.set_window_clientbox
  1459.         call    window._.invalidate_screen
  1460.  
  1461.         add     esp, sizeof.BOX
  1462.  
  1463.         mov     cl, [esp + 4]
  1464.         mov     ch, cl
  1465.         xchg    cl, [edi + WDATA.fl_wstate]
  1466.  
  1467.         or      cl, ch
  1468.         test    cl, WSTATE_MAXIMIZED
  1469.         jnz     .exit
  1470.  
  1471.         mov     eax, edi
  1472.         sub     eax, window_data
  1473.         shl     eax, 3
  1474.         add     eax, SLOT_BASE
  1475.  
  1476.         lea     ebx, [edi + WDATA.box]
  1477.         xchg    esp, ebx
  1478.  
  1479.         pop     [eax + APPDATA.saved_box.left] \
  1480.                 [eax + APPDATA.saved_box.top] \
  1481.                 [eax + APPDATA.saved_box.width] \
  1482.                 edx
  1483.  
  1484.         xchg    esp, ebx
  1485.  
  1486.         test    ch, WSTATE_ROLLEDUP
  1487.         jnz     .exit
  1488.  
  1489.         mov     [eax + APPDATA.saved_box.height], edx
  1490. ;--------------------------------------
  1491. align 4
  1492. .exit:
  1493.         pop     esi ebx eax
  1494.         ret
  1495. ;------------------------------------------------------------------------------
  1496. align 4
  1497. ;------------------------------------------------------------------------------
  1498. window._.set_window_clientbox: ;///////////////////////////////////////////////
  1499. ;------------------------------------------------------------------------------
  1500. ;? <description>
  1501. ;------------------------------------------------------------------------------
  1502. ;> edi = pointer to WDATA struct
  1503. ;------------------------------------------------------------------------------
  1504.         push    eax ecx edi
  1505.  
  1506.         mov     eax, [_skinh]
  1507.         mov     [window_topleft + 8 * 3 + 4], eax
  1508.         mov     [window_topleft + 8 * 4 + 4], eax
  1509.  
  1510.         mov     ecx, edi
  1511.         sub     edi, window_data
  1512.         shl     edi, 3
  1513.         test    [ecx + WDATA.fl_wstyle], WSTYLE_CLIENTRELATIVE
  1514.         jz      .whole_window
  1515.  
  1516.         movzx   eax, [ecx + WDATA.fl_wstyle]
  1517.         and     eax, 0x0F
  1518.         mov     eax, [eax * 8 + window_topleft + 0]
  1519.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.left], eax
  1520.         shl     eax, 1
  1521.         neg     eax
  1522.         add     eax, [ecx + WDATA.box.width]
  1523.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.width], eax
  1524.  
  1525.         movzx   eax, [ecx + WDATA.fl_wstyle]
  1526.         and     eax, 0x0F
  1527.         push    [eax * 8 + window_topleft + 0]
  1528.         mov     eax, [eax * 8 + window_topleft + 4]
  1529.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.top], eax
  1530.         neg     eax
  1531.         sub     eax, [esp]
  1532.         add     eax, [ecx + WDATA.box.height]
  1533.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.height], eax
  1534.         add     esp, 4
  1535.         jmp     .exit
  1536. ;--------------------------------------
  1537. align 4
  1538. .whole_window:
  1539.         xor     eax, eax
  1540.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.left], eax
  1541.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.top], eax
  1542.         mov     eax, [ecx + WDATA.box.width]
  1543.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.width], eax
  1544.         mov     eax, [ecx + WDATA.box.height]
  1545.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.height], eax
  1546. ;--------------------------------------
  1547. align 4
  1548. .exit:
  1549.         pop     edi ecx eax
  1550.         ret
  1551. ;------------------------------------------------------------------------------
  1552. align 4
  1553. ;------------------------------------------------------------------------------
  1554. window._.sys_set_window: ;/////////////////////////////////////////////////////
  1555. ;------------------------------------------------------------------------------
  1556. ;? <description>
  1557. ;------------------------------------------------------------------------------
  1558. ;< edx = pointer to WDATA struct
  1559. ;------------------------------------------------------------------------------
  1560.         mov     eax, [CURRENT_TASK]
  1561.         shl     eax, 5
  1562.         add     eax, window_data
  1563.  
  1564.         ; save window colors
  1565.         mov     [eax + WDATA.cl_workarea], edx
  1566.         mov     [eax + WDATA.cl_titlebar], esi
  1567.         mov     [eax + WDATA.cl_frames], edi
  1568.  
  1569.         mov     edi, eax
  1570.  
  1571.         ; was it already defined before?
  1572.         test    [edi + WDATA.fl_wdrawn], 1
  1573.         jnz     .set_client_box
  1574.         or      [edi + WDATA.fl_wdrawn], 1
  1575.  
  1576.         ; NOTE: commented out since doesn't provide necessary functionality
  1577.         ;       anyway, to be reworked
  1578. ;       mov     eax, [timer_ticks] ; [0xfdf0]
  1579. ;       add     eax, 100
  1580. ;       mov     [new_window_starting], eax
  1581.  
  1582.         ; no it wasn't, performing initial window definition
  1583.         movzx   eax, bx
  1584.         mov     [edi + WDATA.box.width], eax
  1585.         movzx   eax, cx
  1586.         mov     [edi + WDATA.box.height], eax
  1587.         sar     ebx, 16
  1588.         sar     ecx, 16
  1589.         mov     [edi + WDATA.box.left], ebx
  1590.         mov     [edi + WDATA.box.top], ecx
  1591.  
  1592.         call    window._.check_window_position
  1593.  
  1594.         push    ecx edi
  1595.  
  1596.         mov     cl, [edi + WDATA.fl_wstyle]
  1597.         mov     eax, [edi + WDATA.cl_frames]
  1598.  
  1599.         sub     edi, window_data
  1600.         shl     edi, 3
  1601.         add     edi, SLOT_BASE
  1602.  
  1603.         and     cl, 0x0F
  1604.         cmp     cl, 3
  1605.         je      @f
  1606.         cmp     cl, 4
  1607.         je      @f
  1608.  
  1609.         xor     eax, eax
  1610. ;--------------------------------------
  1611. align 4
  1612. @@:
  1613.         mov     [edi + APPDATA.wnd_caption], eax
  1614.  
  1615.         mov     esi, [esp]
  1616.         add     edi, APPDATA.saved_box
  1617.         movsd
  1618.         movsd
  1619.         movsd
  1620.         movsd
  1621.  
  1622.         pop     edi ecx
  1623.  
  1624.         mov     esi, [CURRENT_TASK]
  1625.         movzx   esi, word[WIN_STACK + esi * 2]
  1626.         lea     esi, [WIN_POS + esi * 2]
  1627.         call    waredraw
  1628.  
  1629.         mov     eax, [edi + WDATA.box.left]
  1630.         mov     ebx, [edi + WDATA.box.top]
  1631.         mov     ecx, [edi + WDATA.box.width]
  1632.         mov     edx, [edi + WDATA.box.height]
  1633.         add     ecx, eax
  1634.         add     edx, ebx
  1635.         call    calculatescreen
  1636.  
  1637.         mov     byte[KEY_COUNT], 0           ; empty keyboard buffer
  1638.         mov     byte[BTN_COUNT], 0           ; empty button buffer
  1639. ;--------------------------------------
  1640. align 4
  1641. .set_client_box:
  1642.         ; update window client box coordinates
  1643.         call    window._.set_window_clientbox
  1644.  
  1645.         ; reset window redraw flag and exit
  1646.         mov     [edi + WDATA.fl_redraw], 0
  1647.         mov     edx, edi
  1648.         ret
  1649. ;------------------------------------------------------------------------------
  1650. align 4
  1651. ;------------------------------------------------------------------------------
  1652. window._.check_window_position: ;//////////////////////////////////////////////
  1653. ;------------------------------------------------------------------------------
  1654. ;? Check if window is inside screen area
  1655. ;------------------------------------------------------------------------------
  1656. ;> edi = pointer to WDATA
  1657. ;------------------------------------------------------------------------------
  1658.         push    eax ebx ecx edx esi
  1659.  
  1660.         mov     eax, [edi + WDATA.box.left]
  1661.         mov     ebx, [edi + WDATA.box.top]
  1662.         mov     ecx, [edi + WDATA.box.width]
  1663.         mov     edx, [edi + WDATA.box.height]
  1664.  
  1665.         mov     esi, [Screen_Max_X]
  1666.         cmp     ecx, esi
  1667.         ja      .fix_width_high
  1668. ;--------------------------------------
  1669. align 4
  1670. .check_left:
  1671.         or      eax, eax
  1672.         jl      .fix_left_low
  1673.         add     eax, ecx
  1674.         cmp     eax, esi
  1675.         jg      .fix_left_high
  1676. ;--------------------------------------
  1677. align 4
  1678. .check_height:
  1679.         mov     esi, [Screen_Max_Y]
  1680.         cmp     edx, esi
  1681.         ja      .fix_height_high
  1682. ;--------------------------------------
  1683. align 4
  1684. .check_top:
  1685.         or      ebx, ebx
  1686.         jl      .fix_top_low
  1687.         add     ebx, edx
  1688.         cmp     ebx, esi
  1689.         jg      .fix_top_high
  1690. ;--------------------------------------
  1691. align 4
  1692. .exit:
  1693.         pop     esi edx ecx ebx eax
  1694.         ret
  1695. ;--------------------------------------
  1696. align 4
  1697. .fix_width_high:
  1698.         mov     ecx, esi
  1699.         mov     [edi + WDATA.box.width], esi
  1700.         jmp     .check_left
  1701. ;--------------------------------------
  1702. align 4
  1703. .fix_left_low:
  1704.         xor     eax, eax
  1705.         mov     [edi + WDATA.box.left], eax
  1706.         jmp     .check_height
  1707. ;--------------------------------------
  1708. align 4
  1709. .fix_left_high:
  1710.         mov     eax, esi
  1711.         sub     eax, ecx
  1712.         mov     [edi + WDATA.box.left], eax
  1713.         jmp     .check_height
  1714. ;--------------------------------------
  1715. align 4
  1716. .fix_height_high:
  1717.         mov     edx, esi
  1718.         mov     [edi + WDATA.box.height], esi
  1719.         jmp     .check_top
  1720. ;--------------------------------------
  1721. align 4
  1722. .fix_top_low:
  1723.         xor     ebx, ebx
  1724.         mov     [edi + WDATA.box.top], ebx
  1725.         jmp     .exit
  1726. ;--------------------------------------
  1727. align 4
  1728. .fix_top_high:
  1729.         mov     ebx, esi
  1730.         sub     ebx, edx
  1731.         mov     [edi + WDATA.box.top], ebx
  1732.         jmp     .exit
  1733. ;------------------------------------------------------------------------------
  1734. align 4
  1735. ;------------------------------------------------------------------------------
  1736. window._.get_titlebar_height: ;////////////////////////////////////////////////
  1737. ;------------------------------------------------------------------------------
  1738. ;? <description>
  1739. ;------------------------------------------------------------------------------
  1740. ;> edi = pointer to WDATA
  1741. ;------------------------------------------------------------------------------
  1742.         mov     al, [edi + WDATA.fl_wstyle]
  1743.         and     al, 0x0f
  1744.         cmp     al, 0x03
  1745.         jne     @f
  1746.         mov     eax, [_skinh]
  1747.         ret
  1748. ;--------------------------------------
  1749. align 4
  1750. @@:
  1751.         mov     eax, 21
  1752.         ret
  1753. ;------------------------------------------------------------------------------
  1754. align 4
  1755. ;------------------------------------------------------------------------------
  1756. window._.get_rolledup_height: ;////////////////////////////////////////////////
  1757. ;------------------------------------------------------------------------------
  1758. ;? <description>
  1759. ;------------------------------------------------------------------------------
  1760. ;> edi = pointer to WDATA
  1761. ;------------------------------------------------------------------------------
  1762.         mov     al, [edi + WDATA.fl_wstyle]
  1763.         and     al, 0x0f
  1764.         cmp     al, 0x03
  1765.         jb      @f
  1766.         mov     eax, [_skinh]
  1767.         add     eax, 3
  1768.         ret
  1769. ;--------------------------------------
  1770. align 4
  1771. @@:
  1772.         or      al, al
  1773.         jnz     @f
  1774.         mov     eax, 21
  1775.         ret
  1776. ;--------------------------------------
  1777. align 4
  1778. @@:
  1779.         mov     eax, 21 + 2
  1780.         ret
  1781. ;------------------------------------------------------------------------------
  1782. align 4
  1783. ;------------------------------------------------------------------------------
  1784. window._.set_screen: ;/////////////////////////////////////////////////////////
  1785. ;------------------------------------------------------------------------------
  1786. ;? Reserve window area in screen buffer
  1787. ;------------------------------------------------------------------------------
  1788. ;> eax = left
  1789. ;> ebx = top
  1790. ;> ecx = right
  1791. ;> edx = bottom
  1792. ;> esi = process number
  1793. ;------------------------------------------------------------------------------
  1794. virtual at esp
  1795.   ff_x     dd ?
  1796.   ff_y     dd ?
  1797.   ff_width dd ?
  1798.   ff_xsz   dd ?
  1799.   ff_ysz   dd ?
  1800.   ff_scale dd ?
  1801. end virtual
  1802.  
  1803.         pushad
  1804.  
  1805.         cmp     esi, 1
  1806.         jz      .check_for_shaped_window
  1807.         mov     edi, esi
  1808.         shl     edi, 5
  1809.         cmp     [window_data + edi + WDATA.box.width], 0
  1810.         jnz     .check_for_shaped_window
  1811.         cmp     [window_data + edi + WDATA.box.height], 0
  1812.         jz      .exit
  1813. ;--------------------------------------
  1814. align 4
  1815. .check_for_shaped_window:
  1816.         mov     edi, esi
  1817.         shl     edi, 8
  1818.         add     edi, SLOT_BASE
  1819.         cmp     [edi + APPDATA.wnd_shape], 0
  1820.         jne     .shaped_window
  1821.  
  1822.         ; get x&y size
  1823.         sub     ecx, eax
  1824.         sub     edx, ebx
  1825.         inc     ecx
  1826.         inc     edx
  1827.  
  1828.         ; get WinMap start
  1829.         push    esi
  1830.         mov     edi, [Screen_Max_X]
  1831.         inc     edi
  1832.         mov     esi, edi
  1833.         imul    edi, ebx
  1834.         add     edi, eax
  1835.         add     edi, [_WinMapAddress]
  1836.         pop     eax
  1837.         mov     ah, al
  1838.         push    ax
  1839.         shl     eax, 16
  1840.         pop     ax
  1841. ;--------------------------------------
  1842. align 4
  1843. .next_line:
  1844.         push    ecx
  1845.         shr     ecx, 2
  1846.         rep stosd
  1847.         mov     ecx, [esp]
  1848.         and     ecx, 3
  1849.         rep stosb
  1850.         pop     ecx
  1851.         add     edi, esi
  1852.         sub     edi, ecx
  1853.         dec     edx
  1854.         jnz     .next_line
  1855.  
  1856.         jmp     .exit
  1857. ;--------------------------------------
  1858. align 4
  1859. .shaped_window:
  1860.         ;  for (y=0; y <= x_size; y++)
  1861.         ;      for (x=0; x <= x_size; x++)
  1862.         ;          if (shape[coord(x,y,scale)]==1)
  1863.         ;             set_pixel(x, y, process_number);
  1864.  
  1865.         sub     ecx, eax
  1866.         sub     edx, ebx
  1867.         inc     ecx
  1868.         inc     edx
  1869.  
  1870.         push    [edi + APPDATA.wnd_shape_scale]  ; push scale first -> for loop
  1871.  
  1872.         ; get WinMap start  -> ebp
  1873.         push    eax
  1874.         mov     eax, [Screen_Max_X] ; screen_sx
  1875.         inc     eax
  1876.         imul    eax, ebx
  1877.         add     eax, [esp]
  1878.         add     eax, [_WinMapAddress]
  1879.         mov     ebp, eax
  1880.  
  1881.         mov     edi, [edi + APPDATA.wnd_shape]
  1882.         pop     eax
  1883.  
  1884.         ; eax = x_start
  1885.         ; ebx = y_start
  1886.         ; ecx = x_size
  1887.         ; edx = y_size
  1888.         ; esi = process_number
  1889.         ; edi = &shape
  1890.         ;       [scale]
  1891.         push    edx ecx ; for loop - x,y size
  1892.  
  1893.         mov     ecx, esi
  1894.         shl     ecx, 5
  1895.         mov     edx, [window_data + ecx + WDATA.box.top]
  1896.         push    [window_data + ecx + WDATA.box.width]           ; for loop - width
  1897.         mov     ecx, [window_data + ecx + WDATA.box.left]
  1898.         sub     ebx, edx
  1899.         sub     eax, ecx
  1900.         push    ebx eax ; for loop - x,y
  1901.  
  1902.         add     [ff_xsz], eax
  1903.         add     [ff_ysz], ebx
  1904.  
  1905.         mov     ebx, [ff_y]
  1906. ;--------------------------------------
  1907. align 4
  1908. .ff_new_y:
  1909.         mov     edx, [ff_x]
  1910. ;--------------------------------------
  1911. align 4
  1912. .ff_new_x:
  1913.         ; -- body --
  1914.         mov     ecx, [ff_scale]
  1915.         mov     eax, [ff_width]
  1916.         inc     eax
  1917.         shr     eax, cl
  1918.         push    ebx edx
  1919.         shr     ebx, cl
  1920.         shr     edx, cl
  1921.         imul    eax, ebx
  1922.         add     eax, edx
  1923.         pop     edx ebx
  1924.         add     eax, edi
  1925.         call    .read_byte
  1926.         test    al, al
  1927.         jz      @f
  1928.         mov     eax, esi
  1929.         mov     [ebp], al
  1930.         ; -- end body --
  1931. ;--------------------------------------
  1932. align 4
  1933. @@:
  1934.         inc     ebp
  1935.         inc     edx
  1936.         cmp     edx, [ff_xsz]
  1937.         jb      .ff_new_x
  1938.  
  1939.         sub     ebp, [ff_xsz]
  1940.         add     ebp, [ff_x]
  1941.         add     ebp, [Screen_Max_X]  ; screen.x
  1942.         inc     ebp
  1943.         inc     ebx
  1944.         cmp     ebx, [ff_ysz]
  1945.         jb      .ff_new_y
  1946.  
  1947.         add     esp, 24
  1948. ;--------------------------------------
  1949. align 4
  1950. .exit:
  1951.         popad
  1952.         ret
  1953. ;--------------------------------------
  1954. align 4
  1955. .read_byte:
  1956.         ; eax - address
  1957.         ; esi - slot
  1958.         push    eax ecx edx esi
  1959.         xchg    eax, esi
  1960.         lea     ecx, [esp + 12]
  1961.         mov     edx, 1
  1962.         call    read_process_memory
  1963.         pop     esi edx ecx eax
  1964.         ret
  1965. ;------------------------------------------------------------------------------
  1966. align 4
  1967. ;------------------------------------------------------------------------------
  1968. window._.window_activate: ;////////////////////////////////////////////////////
  1969. ;------------------------------------------------------------------------------
  1970. ;? Activate window
  1971. ;------------------------------------------------------------------------------
  1972. ;> esi = pointer to WIN_POS+ window data
  1973. ;------------------------------------------------------------------------------
  1974.         push    eax ebx
  1975.  
  1976.         ; if type of current active window is 3 or 4, it must be redrawn
  1977.         mov     ebx, [TASK_COUNT]
  1978.        
  1979. ;       DEBUGF  1, "K : TASK_COUNT (0x%x)\n", ebx
  1980.        
  1981.         movzx   ebx, word[WIN_POS + ebx * 2]
  1982.         shl     ebx, 5
  1983.         add     eax, window_data
  1984.         mov     al, [window_data + ebx + WDATA.fl_wstyle]
  1985.         and     al, 0x0f
  1986.         cmp     al, 0x03
  1987.         je      .set_window_redraw_flag
  1988.         cmp     al, 0x04
  1989.         jne     .move_others_down
  1990. ;--------------------------------------
  1991. align 4
  1992. .set_window_redraw_flag:
  1993.         mov     [window_data + ebx + WDATA.fl_redraw], 1
  1994. ;--------------------------------------
  1995. align 4
  1996. .move_others_down:
  1997.         ; ax <- process no
  1998.         movzx   ebx, word[esi]
  1999.         ; ax <- position in window stack
  2000.         movzx   ebx, word[WIN_STACK + ebx * 2]
  2001.  
  2002.         ; drop others
  2003.         xor     eax, eax
  2004. ;--------------------------------------
  2005. align 4
  2006. .next_stack_window:
  2007.         cmp     eax, [TASK_COUNT]
  2008.         jae     .move_self_up
  2009.         inc     eax
  2010.        
  2011. ;       push    ebx
  2012. ;       xor     ebx,ebx
  2013. ;       mov     bx,[WIN_STACK + eax * 2]
  2014. ;       DEBUGF  1, "K : DEC WIN_STACK (0x%x)\n",ebx
  2015. ;       pop     ebx
  2016.        
  2017.         cmp     [WIN_STACK + eax * 2], bx
  2018.         jbe     .next_stack_window
  2019.         dec     word[WIN_STACK + eax * 2]
  2020.         jmp     .next_stack_window
  2021. ;--------------------------------------
  2022. align 4
  2023. .move_self_up:
  2024.         movzx   ebx, word[esi]
  2025.         ; number of processes
  2026.         mov     ax, [TASK_COUNT]
  2027.         ; this is the last (and the upper)
  2028.         mov     [WIN_STACK + ebx * 2], ax
  2029.  
  2030.         ; update on screen - window stack
  2031.         xor     eax, eax
  2032. ;--------------------------------------
  2033. align 4
  2034. .next_window_pos:
  2035.         cmp     eax, [TASK_COUNT]
  2036.         jae     .reset_vars
  2037.         inc     eax
  2038.         movzx   ebx, word[WIN_STACK + eax * 2]
  2039.         mov     [WIN_POS + ebx * 2], ax
  2040.         jmp     .next_window_pos
  2041. ;--------------------------------------
  2042. align 4
  2043. .reset_vars:
  2044.         mov     byte[KEY_COUNT], 0
  2045.         mov     byte[BTN_COUNT], 0
  2046.         mov     word[MOUSE_SCROLL_H], 0
  2047.         mov     word[MOUSE_SCROLL_V], 0
  2048.  
  2049.         pop     ebx eax
  2050.         ret
  2051. ;------------------------------------------------------------------------------
  2052. window._.window_deactivate: ;////////////////////////////////////////////////////
  2053. ;------------------------------------------------------------------------------
  2054. ;? Deactivate window
  2055. ;------------------------------------------------------------------------------
  2056. ;> esi = pointer to WIN_POS+ window data
  2057. ;------------------------------------------------------------------------------
  2058.         push    eax ebx
  2059. ;--------------------------------------
  2060. align 4
  2061. .move_others_up:
  2062.         ; ax <- process no
  2063.         movzx   ebx, word[esi]
  2064.         ; ax <- position in window stack
  2065.         movzx   ebx, word[WIN_STACK + ebx * 2]
  2066.         ; up others
  2067.         xor     eax, eax
  2068. ;--------------------------------------
  2069. align 4
  2070. .next_stack_window:
  2071.         cmp     eax, [TASK_COUNT]
  2072.         jae     .move_self_down
  2073.         inc     eax
  2074.         cmp     [WIN_STACK + eax * 2], bx
  2075.         jae     .next_stack_window
  2076.         inc     word[WIN_STACK + eax * 2]
  2077.         jmp     .next_stack_window
  2078. ;--------------------------------------
  2079. align 4
  2080. .move_self_down:
  2081.         movzx   ebx, word[esi]
  2082.         ; this is the last (and the low)
  2083.         mov     [WIN_STACK + ebx * 2], word 1
  2084.         ; update on screen - window stack
  2085.         xor     eax, eax
  2086. ;--------------------------------------
  2087. align 4
  2088. .next_window_pos:
  2089.         cmp     eax, [TASK_COUNT]
  2090.         jae     .reset_vars
  2091.         inc     eax
  2092.         movzx   ebx, word[WIN_STACK + eax * 2]
  2093.         mov     [WIN_POS + ebx * 2], ax
  2094.         jmp     .next_window_pos
  2095. ;--------------------------------------
  2096. align 4
  2097. .reset_vars:
  2098.         mov     byte[KEY_COUNT], 0
  2099.         mov     byte[BTN_COUNT], 0
  2100.         mov     word[MOUSE_SCROLL_H], 0
  2101.         mov     word[MOUSE_SCROLL_V], 0
  2102.         pop     ebx eax
  2103.         ret
  2104. ;------------------------------------------------------------------------------
  2105. align 4
  2106. ;------------------------------------------------------------------------------
  2107. window._.check_window_draw: ;//////////////////////////////////////////////////
  2108. ;------------------------------------------------------------------------------
  2109. ;? Check if window is necessary to draw
  2110. ;------------------------------------------------------------------------------
  2111. ;> edi = pointer to WDATA
  2112. ;------------------------------------------------------------------------------
  2113.         mov     cl, [edi + WDATA.fl_wstyle]
  2114.         and     cl, 0x0f
  2115.         cmp     cl, 3
  2116.         je      .exit.redraw      ; window type 3
  2117.         cmp     cl, 4
  2118.         je      .exit.redraw      ; window type 4
  2119.  
  2120.         push    eax ebx edx esi
  2121.  
  2122.         mov     eax, edi
  2123.         sub     eax, window_data
  2124.         shr     eax, 5
  2125.  
  2126.         movzx   eax, word[WIN_STACK + eax * 2]  ; get value of the curr process
  2127.         lea     esi, [WIN_POS + eax * 2]        ; get address of this process at 0xC400
  2128. ;--------------------------------------
  2129. align 4
  2130. .next_window:
  2131.         add     esi, 2
  2132.  
  2133.         mov     eax, [TASK_COUNT]
  2134.         lea     eax, word[WIN_POS + eax * 2] ; number of the upper window
  2135.  
  2136.         cmp     esi, eax
  2137.         ja      .exit.no_redraw
  2138.  
  2139.         movzx   edx, word[esi]
  2140.         shl     edx, 5
  2141.         cmp     [CURRENT_TASK + edx + TASKDATA.state], TSTATE_FREE
  2142.         je      .next_window
  2143.  
  2144.         mov     eax, [edi + WDATA.box.top]
  2145.         mov     ebx, [edi + WDATA.box.height]
  2146.         add     ebx, eax
  2147.  
  2148.         mov     ecx, [window_data + edx + WDATA.box.top]
  2149.         cmp     ecx, ebx
  2150.         jge     .next_window
  2151.         add     ecx, [window_data + edx + WDATA.box.height]
  2152.         cmp     eax, ecx
  2153.         jge     .next_window
  2154.  
  2155.         mov     eax, [edi + WDATA.box.left]
  2156.         mov     ebx, [edi + WDATA.box.width]
  2157.         add     ebx, eax
  2158.  
  2159.         mov     ecx, [window_data + edx + WDATA.box.left]
  2160.         cmp     ecx, ebx
  2161.         jge     .next_window
  2162.         add     ecx, [window_data + edx + WDATA.box.width]
  2163.         cmp     eax, ecx
  2164.         jge     .next_window
  2165.  
  2166.         pop     esi edx ebx eax
  2167. ;--------------------------------------
  2168. align 4
  2169. .exit.redraw:
  2170.         xor     ecx, ecx
  2171.         inc     ecx
  2172.         ret
  2173. ;--------------------------------------
  2174. align 4
  2175. .exit.no_redraw:
  2176.         pop     esi edx ebx eax
  2177.         xor     ecx, ecx
  2178.         ret
  2179. ;------------------------------------------------------------------------------
  2180. align 4
  2181. ;------------------------------------------------------------------------------
  2182. window._.draw_window_caption: ;////////////////////////////////////////////////
  2183. ;------------------------------------------------------------------------------
  2184. ;? <description>
  2185. ;------------------------------------------------------------------------------
  2186.         xor     eax, eax
  2187.         mov     edx, [TASK_COUNT]
  2188.         movzx   edx, word[WIN_POS + edx * 2]
  2189.         cmp     edx, [CURRENT_TASK]
  2190.         jne     @f
  2191.         inc     eax
  2192. ;--------------------------------------
  2193. align 4
  2194. @@:
  2195.         mov     edx, [CURRENT_TASK]
  2196.         shl     edx, 5
  2197.         add     edx, window_data
  2198.         movzx   ebx, [edx + WDATA.fl_wstyle]
  2199.         and     bl, 0x0F
  2200.         cmp     bl, 3
  2201.         je      .draw_caption_style_3
  2202.         cmp     bl, 4
  2203.         je      .draw_caption_style_3
  2204.  
  2205.         jmp     .not_style_3
  2206. ;--------------------------------------
  2207. align 4
  2208. .draw_caption_style_3:
  2209.         push    edx
  2210.         call    drawwindow_IV_caption
  2211.         add     esp, 4
  2212.         jmp     .2
  2213. ;--------------------------------------
  2214. align 4
  2215. .not_style_3:
  2216.         cmp     bl, 2
  2217.         jne     .not_style_2
  2218.  
  2219.         call    drawwindow_III_caption
  2220.         jmp     .2
  2221. ;--------------------------------------
  2222. align 4
  2223. .not_style_2:
  2224.         cmp     bl, 0
  2225.         jne     .2
  2226.  
  2227.         call    drawwindow_I_caption
  2228. ;--------------------------------------
  2229. align 4
  2230. .2:
  2231.         mov     edi, [CURRENT_TASK]
  2232.         shl     edi, 5
  2233.         test    [edi + window_data + WDATA.fl_wstyle], WSTYLE_HASCAPTION
  2234.         jz      .exit
  2235.         mov     edx, [edi * 8 + SLOT_BASE + APPDATA.wnd_caption]
  2236.         or      edx, edx
  2237.         jz      .exit
  2238.  
  2239.         movzx   eax, [edi + window_data + WDATA.fl_wstyle]
  2240.         and     al, 0x0F
  2241.         cmp     al, 3
  2242.         je      .skinned
  2243.         cmp     al, 4
  2244.         je      .skinned
  2245.  
  2246.         jmp     .not_skinned
  2247. ;--------------------------------------
  2248. align 4
  2249. .skinned:
  2250.         mov     ebp, [edi + window_data + WDATA.box.left - 2]
  2251.         mov     bp, word[edi + window_data + WDATA.box.top]
  2252.         movzx   eax, word[edi + window_data + WDATA.box.width]
  2253.         sub     ax, [_skinmargins.left]
  2254.         sub     ax, [_skinmargins.right]
  2255.         push    edx
  2256.         cwde
  2257.         cdq
  2258.         mov     ebx, 6
  2259.         idiv    ebx
  2260.         pop     edx
  2261.         or      eax, eax
  2262.         js      .exit
  2263.  
  2264.         mov     esi, eax
  2265.         mov     ebx, dword[_skinmargins.left - 2]
  2266.         mov     bx, word[_skinh]
  2267.         sub     bx, [_skinmargins.bottom]
  2268.         sub     bx, [_skinmargins.top]
  2269.         sar     bx, 1
  2270.         adc     bx, 0
  2271.         add     bx, [_skinmargins.top]
  2272.         add     bx, -3
  2273.         add     ebx, ebp
  2274.         jmp     .dodraw
  2275. ;--------------------------------------
  2276. align 4
  2277. .not_skinned:
  2278.         cmp     al, 1
  2279.         je      .exit
  2280.  
  2281.         mov     ebp, [edi + window_data + WDATA.box.left - 2]
  2282.         mov     bp, word[edi + window_data + WDATA.box.top]
  2283.         movzx   eax, word[edi + window_data + WDATA.box.width]
  2284.         sub     eax, 16
  2285.         push    edx
  2286.         cwde
  2287.         cdq
  2288.         mov     ebx, 6
  2289.         idiv    ebx
  2290.         pop     edx
  2291.         or      eax, eax
  2292.         js      .exit
  2293.  
  2294.         mov     esi, eax
  2295.         mov     ebx, 0x00080007
  2296.         add     ebx, ebp
  2297. ;--------------------------------------
  2298. align 4
  2299. .dodraw:
  2300.         mov     ecx, [common_colours + 16]
  2301.         or      ecx, 0x80000000
  2302.         xor     edi, edi
  2303.         call    dtext_asciiz_esi
  2304. ;--------------------------------------
  2305. align 4
  2306. .exit:
  2307.         call    [draw_pointer]
  2308.         ret
  2309. ;------------------------------------------------------------------------------
  2310. align 4
  2311. ;------------------------------------------------------------------------------
  2312. window._.draw_negative_box: ;//////////////////////////////////////////////////
  2313. ;------------------------------------------------------------------------------
  2314. ;? Draw negative box
  2315. ;------------------------------------------------------------------------------
  2316. ;> edi = pointer to BOX struct
  2317. ;------------------------------------------------------------------------------
  2318.         push    eax ebx esi
  2319.         mov     esi, 0x01000000
  2320. ;--------------------------------------
  2321. align 4
  2322. .1:
  2323.         mov     eax, [edi + BOX.left - 2]
  2324.         mov     ax, word[edi + BOX.left]
  2325.         add     ax, word[edi + BOX.width]
  2326.         mov     ebx, [edi + BOX.top - 2]
  2327.         mov     bx, word[edi + BOX.top]
  2328.         add     bx, word[edi + BOX.height]
  2329.         call    draw_rectangle.forced
  2330.         pop     esi ebx eax
  2331.         ret
  2332. ;------------------------------------------------------------------------------
  2333. align 4
  2334. ;------------------------------------------------------------------------------
  2335. window._.end_moving__box: ;//////////////////////////////////////////////////
  2336. ;------------------------------------------------------------------------------
  2337. ;? Draw positive box
  2338. ;------------------------------------------------------------------------------
  2339. ;> edi = pointer to BOX struct
  2340. ;------------------------------------------------------------------------------
  2341.         push    eax ebx esi
  2342.         xor     esi, esi
  2343.         jmp     window._.draw_negative_box.1
  2344. ;------------------------------------------------------------------------------
  2345. align 4
  2346. ;------------------------------------------------------------------------------
  2347. window._.get_rect: ;/////////////////////////////////////////////////////
  2348. ;------------------------------------------------------------------------------
  2349. ;? <description>  void __fastcall get_window_rect(struct RECT* rc);
  2350. ;------------------------------------------------------------------------------
  2351. ;> ecx = pointer to RECT
  2352. ;------------------------------------------------------------------------------
  2353.         mov     eax, [TASK_BASE]
  2354.  
  2355.         mov     edx, [eax-twdw + WDATA.box.left]
  2356.         mov     [ecx+RECT.left], edx
  2357.  
  2358.         add     edx, [eax-twdw + WDATA.box.width]
  2359.         mov     [ecx+RECT.right], edx
  2360.  
  2361.         mov     edx, [eax-twdw + WDATA.box.top]
  2362.         mov     [ecx+RECT.top], edx
  2363.  
  2364.         add     edx, [eax-twdw + WDATA.box.height]
  2365.         mov     [ecx+RECT.bottom], edx
  2366.         ret
  2367. ;------------------------------------------------------------------------------
  2368.