Subversion Repositories Kolibri OS

Rev

Rev 2434 | Rev 2465 | 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: 2439 $
  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.         inc     [_display.mask_seqno]
  552.         popfd
  553.         pop     esi
  554.         ret
  555. ;------------------------------------------------------------------------------
  556. align 4
  557. ;------------------------------------------------------------------------------
  558. repos_windows: ;///////////////////////////////////////////////////////////////
  559. ;------------------------------------------------------------------------------
  560. ;? <description>
  561. ;------------------------------------------------------------------------------
  562.         mov     ecx, [TASK_COUNT]
  563.         mov     edi, window_data + sizeof.WDATA * 2
  564.         call    force_redraw_background
  565.         dec     ecx
  566.         jle     .exit
  567. ;--------------------------------------
  568. align 4
  569. .next_window:
  570.         mov     [edi + WDATA.fl_redraw], 1
  571.         test    [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED
  572.         jnz     .fix_maximized
  573.  
  574.         mov     eax, [edi + WDATA.box.left]
  575.         add     eax, [edi + WDATA.box.width]
  576.         mov     ebx, [Screen_Max_X]
  577.         cmp     eax, ebx
  578.         jle     .fix_vertical
  579.         mov     eax, [edi + WDATA.box.width]
  580.         sub     eax, ebx
  581.         jle     @f
  582.         mov     [edi + WDATA.box.width], ebx
  583. ;--------------------------------------
  584. align 4
  585. @@:
  586.         sub     ebx, [edi + WDATA.box.width]
  587.         mov     [edi + WDATA.box.left], ebx
  588. ;--------------------------------------
  589. align 4
  590. .fix_vertical:
  591.         mov     eax, [edi + WDATA.box.top]
  592.         add     eax, [edi + WDATA.box.height]
  593.         mov     ebx, [Screen_Max_Y]
  594.         cmp     eax, ebx
  595.         jle     .fix_client_box
  596.         mov     eax, [edi + WDATA.box.height]
  597.         sub     eax, ebx
  598.         jle     @f
  599.         mov     [edi + WDATA.box.height], ebx
  600. ;--------------------------------------
  601. align 4
  602. @@:
  603.         sub     ebx, [edi + WDATA.box.height]
  604.         mov     [edi + WDATA.box.top], ebx
  605. ;--------------------------------------
  606. align 4
  607. .fix_client_box:
  608.         call    window._.set_window_clientbox
  609.         add     edi, sizeof.WDATA
  610.         loop    .next_window
  611. ;--------------------------------------
  612. align 4
  613. .exit:
  614.         ret
  615. ;--------------------------------------
  616. align 4
  617. .fix_maximized:
  618.         mov     eax, [screen_workarea.left]
  619.         mov     [edi + WDATA.box.left], eax
  620.         sub     eax, [screen_workarea.right]
  621.         neg     eax
  622.         mov     [edi + WDATA.box.width], eax
  623.         mov     eax, [screen_workarea.top]
  624.         mov     [edi + WDATA.box.top], eax
  625.         test    [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP
  626.         jnz     .fix_client_box
  627.         sub     eax, [screen_workarea.bottom]
  628.         neg     eax
  629.         mov     [edi + WDATA.box.height], eax
  630.         jmp     .fix_client_box
  631. ;------------------------------------------------------------------------------
  632. ;align 4
  633. ;------------------------------------------------------------------------------
  634. ;sys_window_mouse: ;////////////////////////////////////////////////////////////
  635. ;------------------------------------------------------------------------------
  636. ;? <description>
  637. ;------------------------------------------------------------------------------
  638.         ; NOTE: commented out since doesn't provide necessary functionality
  639.         ;       anyway, to be reworked
  640. ;       push    eax
  641. ;
  642. ;       mov     eax, [timer_ticks]
  643. ;       cmp     [new_window_starting], eax
  644. ;       jb      .exit
  645. ;
  646. ;       mov     byte[MOUSE_BACKGROUND], 0
  647. ;       mov     byte[DONT_DRAW_MOUSE], 0
  648. ;
  649. ;       mov     [new_window_starting], eax
  650. ;
  651. ; .exit:
  652. ;       pop     eax
  653. ;        ret
  654. ;------------------------------------------------------------------------------
  655. align 4
  656. ;------------------------------------------------------------------------------
  657. draw_rectangle: ;//////////////////////////////////////////////////////////////
  658. ;------------------------------------------------------------------------------
  659. ;> eax = pack[16(left), 16(right)]
  660. ;> ebx = pack[16(top), 16(bottom)]
  661. ;> esi = color
  662. ;       ?? RR GG BB    ; 0x01000000 negation
  663. ;                      ; 0x02000000 used for draw_rectangle without top line
  664. ;                      ;           for example drawwindow_III and drawwindow_IV
  665. ;------------------------------------------------------------------------------
  666.         push    eax ebx ecx edi
  667.  
  668.         xor     edi, edi
  669. ;--------------------------------------
  670. align 4
  671. .flags_set:
  672.         push    ebx
  673.  
  674.         ; set line color
  675.         mov     ecx, esi
  676.         ; draw top border
  677.         rol     ebx, 16
  678.         push    ebx
  679.         rol     ebx, 16
  680.         pop     bx
  681.         test    ecx, 1 shl 25
  682.         jnz     @f
  683.         sub     ecx, 1 shl 25
  684.         call    [draw_line]
  685. ;--------------------------------------
  686. align 4
  687. @@:
  688.         ; draw bottom border
  689.         mov     ebx, [esp - 2]
  690.         pop     bx
  691.         call    [draw_line]
  692.  
  693.         pop     ebx
  694.         add     ebx, 1 * 65536 - 1
  695.  
  696.         ; draw left border
  697.         rol     eax, 16
  698.         push    eax
  699.         rol     eax, 16
  700.         pop     ax
  701.         call    [draw_line]
  702.  
  703.         ; draw right border
  704.         mov     eax, [esp - 2]
  705.         pop     ax
  706.         call    [draw_line]
  707.  
  708.         pop     edi ecx ebx eax
  709.         ret
  710. ;--------------------------------------
  711. align 4
  712. .forced:
  713.         push    eax ebx ecx edi
  714.         xor     edi, edi
  715.         inc     edi
  716.         jmp     .flags_set
  717. ;------------------------------------------------------------------------------
  718. align 4
  719. ;------------------------------------------------------------------------------
  720. drawwindow_I_caption: ;////////////////////////////////////////////////////////
  721. ;------------------------------------------------------------------------------
  722. ;? <description>
  723. ;------------------------------------------------------------------------------
  724.         push    [edx + WDATA.cl_titlebar]
  725.         mov     esi, edx
  726.  
  727.         mov     edx, [esi + WDATA.box.top]
  728.         mov     eax, edx
  729.         lea     ebx, [edx + 21]
  730.         inc     edx
  731.         add     eax, [esi + WDATA.box.height]
  732.  
  733.         cmp     ebx, eax
  734.         jbe     @f
  735.         mov     ebx, eax
  736. ;--------------------------------------
  737. align 4
  738. @@:
  739.         push    ebx
  740.  
  741.         xor     edi, edi
  742. ;--------------------------------------
  743. align 4
  744. .next_line:
  745.         mov     ebx, edx
  746.         shl     ebx, 16
  747.         add     ebx, edx
  748.         mov     eax, [esi + WDATA.box.left]
  749.         inc     eax
  750.         shl     eax, 16
  751.         add     eax, [esi + WDATA.box.left]
  752.         add     eax, [esi + WDATA.box.width]
  753.         dec     eax
  754.         mov     ecx, [esi + WDATA.cl_titlebar]
  755.         test    ecx, 0x80000000
  756.         jz      @f
  757.         sub     ecx, 0x00040404
  758.         mov     [esi + WDATA.cl_titlebar], ecx
  759. ;--------------------------------------
  760. align 4
  761. @@:
  762.         and     ecx, 0x00ffffff
  763.         call    [draw_line]
  764.         inc     edx
  765.         cmp     edx, [esp]
  766.         jb      .next_line
  767.  
  768.         add     esp, 4
  769.         pop     [esi + WDATA.cl_titlebar]
  770.         ret
  771. ;------------------------------------------------------------------------------
  772. align 4
  773. ;------------------------------------------------------------------------------
  774. drawwindow_I: ;////////////////////////////////////////////////////////////////
  775. ;------------------------------------------------------------------------------
  776. ;? <description>
  777. ;------------------------------------------------------------------------------
  778.         pushad
  779.  
  780.         ; window border
  781.  
  782.         mov     eax, [edx + WDATA.box.left - 2]
  783.         mov     ax, word[edx + WDATA.box.left]
  784.         add     ax, word[edx + WDATA.box.width]
  785.         mov     ebx, [edx + WDATA.box.top - 2]
  786.         mov     bx, word[edx + WDATA.box.top]
  787.         add     bx, word[edx + WDATA.box.height]
  788.  
  789.         mov     esi, [edx + WDATA.cl_frames]
  790.         call    draw_rectangle
  791.  
  792.         ; window caption
  793.  
  794.         call    drawwindow_I_caption
  795.  
  796.         ; window client area
  797.  
  798.         ; do we need to draw it?
  799.         mov     edi, [esi + WDATA.cl_workarea]
  800.         test    edi, 0x40000000
  801.         jnz     .exit
  802.  
  803.         ; does client area have a positive size on screen?
  804.         mov     edx, [esi + WDATA.box.top]
  805.         add     edx, 21 + 5
  806.         mov     ebx, [esi + WDATA.box.top]
  807.         add     ebx, [esi + WDATA.box.height]
  808.         cmp     edx, ebx
  809.         jg      .exit
  810.  
  811.         ; okay, let's draw it
  812.         mov     eax, 1
  813.         mov     ebx, 21
  814.         mov     ecx, [esi + WDATA.box.width]
  815.         mov     edx, [esi + WDATA.box.height]
  816.         call    [drawbar]
  817. ;--------------------------------------
  818. align 4
  819. .exit:
  820.         popad
  821.         ret
  822. ;------------------------------------------------------------------------------
  823. align 4
  824. ;------------------------------------------------------------------------------
  825. drawwindow_III_caption: ;/////////////////////////////////////////////////////
  826. ;------------------------------------------------------------------------------
  827. ;? <description>
  828. ;------------------------------------------------------------------------------
  829.         mov     ecx, [edx + WDATA.cl_titlebar]
  830.         push    ecx
  831.         mov     esi, edx
  832.         mov     edx, [esi + WDATA.box.top]
  833.         add     edx, 4
  834.         mov     ebx, [esi + WDATA.box.top]
  835.         add     ebx, 20
  836.         mov     eax, [esi + WDATA.box.top]
  837.         add     eax, [esi + WDATA.box.height]
  838.  
  839.         cmp     ebx, eax
  840.         jb      @f
  841.         mov     ebx, eax
  842. ;--------------------------------------
  843. align 4
  844. @@:
  845.         push    ebx
  846.  
  847.         xor     edi, edi
  848. ;--------------------------------------
  849. align 4
  850. .next_line:
  851.         mov     ebx, edx
  852.         shl     ebx, 16
  853.         add     ebx, edx
  854.         mov     eax, [esi + WDATA.box.left]
  855.         shl     eax, 16
  856.         add     eax, [esi + WDATA.box.left]
  857.         add     eax, [esi + WDATA.box.width]
  858.         add     eax, 4 * 65536 - 4
  859.         mov     ecx, [esi + WDATA.cl_titlebar]
  860.         test    ecx, 0x40000000
  861.         jz      @f
  862.         add     ecx, 0x00040404
  863. ;--------------------------------------
  864. align 4
  865. @@:
  866.         test    ecx, 0x80000000
  867.         jz      @f
  868.         sub     ecx, 0x00040404
  869. ;--------------------------------------
  870. align 4
  871. @@:
  872.         mov     [esi + WDATA.cl_titlebar], ecx
  873.         and     ecx, 0x00ffffff
  874.         call    [draw_line]
  875.         inc     edx
  876.         cmp     edx, [esp]
  877.         jb      .next_line
  878.  
  879.         add     esp, 4
  880.         pop     [esi + WDATA.cl_titlebar]
  881.         ret
  882. ;------------------------------------------------------------------------------
  883. align 4
  884. ;------------------------------------------------------------------------------
  885. drawwindow_III: ;//////////////////////////////////////////////////////////////
  886. ;------------------------------------------------------------------------------
  887. ;? <description>
  888. ;------------------------------------------------------------------------------
  889.         pushad
  890.  
  891.         ; window border
  892.  
  893.         mov     eax, [edx + WDATA.box.left - 2]
  894.         mov     ax, word[edx + WDATA.box.left]
  895.         add     ax, word[edx + WDATA.box.width]
  896.         mov     ebx, [edx + WDATA.box.top - 2]
  897.         mov     bx, word[edx + WDATA.box.top]
  898.         add     bx, word[edx + WDATA.box.height]
  899.  
  900.         mov     esi, [edx + WDATA.cl_frames]
  901.         shr     esi, 1
  902.         and     esi, 0x007f7f7f
  903.         or      esi, 1 shl 25; 0x02000000 used for draw_rectangle without top line
  904.         ror     ebx, 16
  905.         add     ebx, [_skinh]
  906.         sub     bx, 1
  907.         rol     ebx, 16
  908.         call    draw_rectangle
  909.  
  910.         push    esi
  911.         mov     ecx, 3
  912.         mov     esi, [edx + WDATA.cl_frames]
  913.         or      esi, 1 shl 25; 0x02000000 used for draw_rectangle without top line
  914. ;--------------------------------------
  915. align 4
  916. .next_frame:
  917.         add     eax, 1 * 65536 - 1
  918.         add     ebx, 0 * 65536 - 1
  919.         call    draw_rectangle
  920.         dec     ecx
  921.         jnz     .next_frame
  922.  
  923.         pop     esi
  924.         add     eax, 1 * 65536 - 1
  925.         add     ebx, 0 * 65536 - 1
  926.         call    draw_rectangle
  927.  
  928.         ; window caption
  929.  
  930.         call    drawwindow_III_caption
  931.  
  932.         ; window client area
  933.  
  934.         ; do we need to draw it?
  935.         mov     edi, [esi + WDATA.cl_workarea]
  936.         test    edi, 0x40000000
  937.         jnz     .exit
  938.  
  939.         ; does client area have a positive size on screen?
  940.         mov     edx, [esi + WDATA.box.top]
  941.         add     edx, 21 + 5
  942.         mov     ebx, [esi + WDATA.box.top]
  943.         add     ebx, [esi + WDATA.box.height]
  944.         cmp     edx, ebx
  945.         jg      .exit
  946.  
  947.         ; okay, let's draw it
  948.         mov     eax, 5
  949.         mov     ebx, 20
  950.         mov     ecx, [esi + WDATA.box.width]
  951.         mov     edx, [esi + WDATA.box.height]
  952.         sub     ecx, 4
  953.         sub     edx, 4
  954.         call    [drawbar]
  955. ;--------------------------------------
  956. align 4
  957. .exit:
  958.         popad
  959.         ret
  960. ;------------------------------------------------------------------------------
  961. align 4
  962. ;------------------------------------------------------------------------------
  963. waredraw: ;////////////////////////////////////////////////////////////////////
  964. ;------------------------------------------------------------------------------
  965. ;? Activate window, redrawing if necessary
  966. ;------------------------------------------------------------------------------
  967.         push    -1
  968.         mov     eax, [TASK_COUNT]
  969.         lea     eax, [WIN_POS + eax * 2]
  970.         cmp     eax, esi
  971.         pop     eax
  972.         je      .exit
  973.  
  974.         ; is it overlapped by another window now?
  975.         push    ecx
  976.         call    window._.check_window_draw
  977.         test    ecx, ecx
  978.         pop     ecx
  979.         jz      .do_not_draw
  980.  
  981.         ; yes it is, activate and update screen buffer
  982.         mov     byte[MOUSE_DOWN], 1
  983.         call    window._.window_activate
  984.  
  985.         pushad
  986.         mov     edi, [TASK_COUNT]
  987.         movzx   esi, word[WIN_POS + edi * 2]
  988.         shl     esi, 5
  989.         add     esi, window_data
  990.  
  991.         mov     eax, [esi + WDATA.box.left]
  992.         mov     ebx, [esi + WDATA.box.top]
  993.         mov     ecx, [esi + WDATA.box.width]
  994.         mov     edx, [esi + WDATA.box.height]
  995.  
  996.         add     ecx, eax
  997.         add     edx, ebx
  998.  
  999.         mov     edi, [TASK_COUNT]
  1000.         movzx   esi, word[WIN_POS + edi * 2]
  1001.         call    window._.set_screen
  1002.         inc     [_display.mask_seqno]
  1003.         popad
  1004.  
  1005.         ; tell application to redraw itself
  1006.         mov     [edi + WDATA.fl_redraw], 1
  1007.         xor     eax, eax
  1008.         jmp     .exit
  1009. ;--------------------------------------
  1010. align 4
  1011. .do_not_draw:
  1012.         ; no it's not, just activate the window
  1013.         call    window._.window_activate
  1014.         xor     eax, eax
  1015.         mov     byte[MOUSE_BACKGROUND], al
  1016.         mov     byte[DONT_DRAW_MOUSE], al
  1017. ;--------------------------------------
  1018. align 4
  1019. .exit:
  1020.         mov     byte[MOUSE_DOWN], 0
  1021.         inc     eax
  1022.         ret
  1023. ;------------------------------------------------------------------------------
  1024. align 4
  1025. ;------------------------------------------------------------------------------
  1026. minimize_window: ;/////////////////////////////////////////////////////////////
  1027. ;------------------------------------------------------------------------------
  1028. ;> eax = window number on screen
  1029. ;------------------------------------------------------------------------------
  1030. ;# corrupts [dl*]
  1031. ;------------------------------------------------------------------------------
  1032.         push    edi
  1033.         pushfd
  1034.         cli
  1035.  
  1036.         ; is it already minimized?
  1037.         movzx   edi, word[WIN_POS + eax * 2]
  1038.         shl     edi, 5
  1039.         add     edi, window_data
  1040.         test    [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  1041.         jnz     .exit
  1042.  
  1043.         push    eax ebx ecx edx esi
  1044.  
  1045.         ; no it's not, let's do that
  1046.         or      [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  1047.         mov     eax, [edi + WDATA.box.left]
  1048.         mov     [draw_limits.left], eax
  1049.         mov     ecx, eax
  1050.         add     ecx, [edi + WDATA.box.width]
  1051.         mov     [draw_limits.right], ecx
  1052.         mov     ebx, [edi + WDATA.box.top]
  1053.         mov     [draw_limits.top], ebx
  1054.         mov     edx, ebx
  1055.         add     edx, [edi + WDATA.box.height]
  1056.         mov     [draw_limits.bottom], edx
  1057.         call    calculatescreen
  1058.         xor     esi, esi
  1059.         xor     eax, eax
  1060.         call    redrawscreen
  1061.  
  1062.         pop     esi edx ecx ebx eax
  1063. ;--------------------------------------
  1064. align 4
  1065. .exit:
  1066.         popfd
  1067.         pop     edi
  1068.         ret
  1069. ;------------------------------------------------------------------------------
  1070. align 4
  1071. ;------------------------------------------------------------------------------
  1072. restore_minimized_window: ;////////////////////////////////////////////////////
  1073. ;------------------------------------------------------------------------------
  1074. ;> eax = window number on screen
  1075. ;------------------------------------------------------------------------------
  1076. ;# corrupts [dl*]
  1077. ;------------------------------------------------------------------------------
  1078.         pushad
  1079.         pushfd
  1080.         cli
  1081.  
  1082.         ; is it already restored?
  1083.         movzx   esi, word[WIN_POS + eax * 2]
  1084.         mov     edi, esi
  1085.         shl     edi, 5
  1086.         add     edi, window_data
  1087.         test    [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  1088.         jz      .exit
  1089.  
  1090.         ; no it's not, let's do that
  1091.         mov     [edi + WDATA.fl_redraw], 1
  1092.         and     [edi + WDATA.fl_wstate], not WSTATE_MINIMIZED
  1093.         mov     ebp, window._.set_screen
  1094.         cmp     eax, [TASK_COUNT]
  1095.         jz      @f
  1096.         mov     ebp, calculatescreen
  1097. ;--------------------------------------
  1098. align 4
  1099. @@:
  1100.         mov     eax, [edi + WDATA.box.left]
  1101.         mov     ebx, [edi + WDATA.box.top]
  1102.         mov     ecx, [edi + WDATA.box.width]
  1103.         mov     edx, [edi + WDATA.box.height]
  1104.         add     ecx, eax
  1105.         add     edx, ebx
  1106.         call    ebp
  1107.         inc     [_display.mask_seqno]
  1108.         mov     byte[MOUSE_BACKGROUND], 0
  1109. ;--------------------------------------
  1110. align 4
  1111. .exit:
  1112.         popfd
  1113.         popad
  1114.         ret
  1115. ;------------------------------------------------------------------------------
  1116. align 4
  1117. ; TODO: remove this proc
  1118. ;------------------------------------------------------------------------------
  1119. window_check_events: ;/////////////////////////////////////////////////////////
  1120. ;------------------------------------------------------------------------------
  1121. ;? <description>
  1122. ;------------------------------------------------------------------------------
  1123.         ; do we have window minimize/restore request?
  1124.         cmp     [window_minimize], 0
  1125.         je      .exit
  1126.  
  1127.         ; okay, minimize or restore top-most window and exit
  1128.         mov     eax, [TASK_COUNT]
  1129.         mov     bl, 0
  1130.         xchg    [window_minimize], bl
  1131.         dec     bl
  1132.         jnz     @f
  1133.         call    minimize_window
  1134.         jmp     .exit
  1135. ;--------------------------------------
  1136. align 4
  1137. @@:
  1138.         call    restore_minimized_window
  1139. ;--------------------------------------
  1140. align 4
  1141. .exit:
  1142.         ret
  1143. ;------------------------------------------------------------------------------
  1144. align 4
  1145. ;------------------------------------------------------------------------------
  1146. sys_window_maximize_handler: ;/////////////////////////////////////////////////
  1147. ;------------------------------------------------------------------------------
  1148. ;? <description>
  1149. ;------------------------------------------------------------------------------
  1150. ;> esi = process slot
  1151. ;------------------------------------------------------------------------------
  1152.         mov     edi, esi
  1153.         shl     edi, 5
  1154.         add     edi, window_data
  1155.  
  1156.         ; can window change its height?
  1157.         ; only types 2 and 3 can be resized
  1158.         mov     dl, [edi + WDATA.fl_wstyle]
  1159.         test    dl, 2
  1160.         jz      .exit
  1161.  
  1162.         ; toggle normal/maximized window state
  1163.         mov     bl, [edi + WDATA.fl_wstate]
  1164.         xor     bl, WSTATE_MAXIMIZED
  1165.  
  1166.         ; calculate and set appropriate window bounds
  1167.         test    bl, WSTATE_MAXIMIZED
  1168.         jz      .restore_size
  1169.  
  1170.         mov     eax, [screen_workarea.left]
  1171.         mov     ecx, [screen_workarea.top]
  1172.         push    [screen_workarea.bottom] \
  1173.                 [screen_workarea.right] \
  1174.                 ecx \
  1175.                 eax
  1176.         sub     [esp + BOX.width], eax
  1177.         sub     [esp + BOX.height], ecx
  1178.         mov     eax, esp
  1179.         jmp     .set_box
  1180. ;--------------------------------------
  1181. align 4
  1182. .restore_size:
  1183.         mov     eax, esi
  1184.         shl     eax, 8
  1185.         add     eax, SLOT_BASE + APPDATA.saved_box
  1186.         push    [eax + BOX.height] \
  1187.                 [eax + BOX.width] \
  1188.                 [eax + BOX.top] \
  1189.                 [eax + BOX.left]
  1190.         mov     eax, esp
  1191. ;--------------------------------------
  1192. align 4
  1193. .set_box:
  1194.         test    bl, WSTATE_ROLLEDUP
  1195.         jz      @f
  1196.  
  1197.         xchg    eax, ecx
  1198.         call    window._.get_rolledup_height
  1199.         mov     [ecx + BOX.height], eax
  1200.         xchg    eax, ecx
  1201. ;--------------------------------------
  1202. align 4
  1203. @@:
  1204.         call    window._.set_window_box
  1205.         add     esp, sizeof.BOX
  1206. ;--------------------------------------
  1207. align 4
  1208. .exit:
  1209.         inc     [_display.mask_seqno]
  1210.         ret
  1211. ;------------------------------------------------------------------------------
  1212. align 4
  1213. ;------------------------------------------------------------------------------
  1214. sys_window_rollup_handler: ;///////////////////////////////////////////////////
  1215. ;------------------------------------------------------------------------------
  1216. ;? <description>
  1217. ;------------------------------------------------------------------------------
  1218. ;> esi = process slot
  1219. ;------------------------------------------------------------------------------
  1220.         mov     edx, esi
  1221.         shl     edx, 8
  1222.         add     edx, SLOT_BASE
  1223.  
  1224.         ; toggle normal/rolled up window state
  1225.         mov     bl, [edi + WDATA.fl_wstate]
  1226.         xor     bl, WSTATE_ROLLEDUP
  1227.  
  1228.         ; calculate and set appropriate window bounds
  1229.         test    bl, WSTATE_ROLLEDUP
  1230.         jz      .restore_size
  1231.  
  1232.         call    window._.get_rolledup_height
  1233.         push    eax \
  1234.                 [edi + WDATA.box.width] \
  1235.                 [edi + WDATA.box.top] \
  1236.                 [edi + WDATA.box.left]
  1237.         mov     eax, esp
  1238.         jmp     .set_box
  1239. ;--------------------------------------
  1240. align 4
  1241. .restore_size:
  1242.         test    bl, WSTATE_MAXIMIZED
  1243.         jnz     @f
  1244.         add     esp, -sizeof.BOX
  1245.         lea     eax, [edx + APPDATA.saved_box]
  1246.         jmp     .set_box
  1247. ;--------------------------------------
  1248. align 4
  1249. @@:
  1250.         mov     eax, [screen_workarea.top]
  1251.         push    [screen_workarea.bottom] \
  1252.                 [edi + WDATA.box.width] \
  1253.                 eax \
  1254.                 [edi + WDATA.box.left]
  1255.         sub     [esp + BOX.height], eax
  1256.         mov     eax, esp
  1257. ;--------------------------------------
  1258. align 4
  1259. .set_box:
  1260.         call    window._.set_window_box
  1261.         add     esp, sizeof.BOX
  1262.         ret
  1263. ;------------------------------------------------------------------------------
  1264. align 4
  1265. ;------------------------------------------------------------------------------
  1266. sys_window_start_moving_handler: ;/////////////////////////////////////////////
  1267. ;------------------------------------------------------------------------------
  1268. ;? <description>
  1269. ;------------------------------------------------------------------------------
  1270. ;> eax = old (original) window box
  1271. ;> esi = process slot
  1272. ;------------------------------------------------------------------------------
  1273.         mov     edi, eax
  1274.         call    window._.draw_negative_box
  1275.         ret
  1276. ;------------------------------------------------------------------------------
  1277. align 4
  1278. ;------------------------------------------------------------------------------
  1279. sys_window_end_moving_handler: ;///////////////////////////////////////////////
  1280. ;------------------------------------------------------------------------------
  1281. ;? <description>
  1282. ;------------------------------------------------------------------------------
  1283. ;> eax = old (original) window box
  1284. ;> ebx = new (final) window box
  1285. ;> esi = process slot
  1286. ;------------------------------------------------------------------------------
  1287.         mov     edi, ebx
  1288.         call    window._.end_moving__box
  1289.  
  1290.         mov     edi, esi
  1291.         shl     edi, 5
  1292.         add     edi, window_data
  1293.  
  1294.         mov     eax, ebx
  1295.         mov     bl, [edi + WDATA.fl_wstate]
  1296.         call    window._.set_window_box
  1297.         ret
  1298. ;------------------------------------------------------------------------------
  1299. align 4
  1300. ;------------------------------------------------------------------------------
  1301. sys_window_moving_handler: ;///////////////////////////////////////////////////
  1302. ;------------------------------------------------------------------------------
  1303. ;? <description>
  1304. ;------------------------------------------------------------------------------
  1305. ;> eax = old (from previous call) window box
  1306. ;> ebx = new (current) window box
  1307. ;> esi = process_slot
  1308. ;------------------------------------------------------------------------------
  1309.         mov     edi, eax
  1310.         call    window._.draw_negative_box
  1311.         mov     edi, ebx
  1312.         call    window._.draw_negative_box
  1313.         ret
  1314. ;==============================================================================
  1315. ;///// private functions //////////////////////////////////////////////////////
  1316. ;==============================================================================
  1317.  
  1318. iglobal
  1319.   FuncTable syscall_display_settings, ftable, \
  1320.     00, 01, 02, 03, 04, 05, 06, 07, 08
  1321.  
  1322.   align 4
  1323.   window_topleft dd \
  1324.     1, 21, \ ;type 0
  1325.     0,  0, \ ;type 1
  1326.     5, 20, \ ;type 2
  1327.     5,  ?, \ ;type 3 {set by skin}
  1328.     5,  ?    ;type 4 {set by skin}
  1329. endg
  1330.  
  1331. ;uglobal
  1332.   ; NOTE: commented out since doesn't provide necessary functionality anyway,
  1333.   ;       to be reworked
  1334. ; new_window_starting       dd ?
  1335. ;endg
  1336. ;------------------------------------------------------------------------------
  1337. align 4
  1338. ;------------------------------------------------------------------------------
  1339. window._.invalidate_screen: ;//////////////////////////////////////////////////
  1340. ;------------------------------------------------------------------------------
  1341. ;? <description>
  1342. ;------------------------------------------------------------------------------
  1343. ;> eax = old (original) window box
  1344. ;> ebx = new (final) window box
  1345. ;> edi = pointer to WDATA struct
  1346. ;------------------------------------------------------------------------------
  1347.         push    eax ebx
  1348.  
  1349.         ; TODO: do we really need `draw_limits`?
  1350.         ; Yes, they are used by background drawing code.
  1351.         mov     ecx, [eax + BOX.left]
  1352.         mov     edx, [ebx + BOX.left]
  1353.         cmp     ecx, edx
  1354.         jle     @f
  1355.         mov     ecx, edx
  1356. ;--------------------------------------
  1357. align 4
  1358. @@:
  1359.         mov     [draw_limits.left], ecx
  1360.         mov     ecx, [eax + BOX.left]
  1361.         add     ecx, [eax + BOX.width]
  1362.         add     edx, [ebx + BOX.width]
  1363.         cmp     ecx, edx
  1364.         jae     @f
  1365.         mov     ecx, edx
  1366. ;--------------------------------------
  1367. align 4
  1368. @@:
  1369.         mov     [draw_limits.right], ecx
  1370.         mov     ecx, [eax + BOX.top]
  1371.         mov     edx, [ebx + BOX.top]
  1372.         cmp     ecx, edx
  1373.         jle     @f
  1374.         mov     ecx, edx
  1375. ;--------------------------------------
  1376. align 4
  1377. @@:
  1378.         mov     [draw_limits.top], ecx
  1379.         mov     ecx, [eax + BOX.top]
  1380.         add     ecx, [eax + BOX.height]
  1381.         add     edx, [ebx + BOX.height]
  1382.         cmp     ecx, edx
  1383.         jae     @f
  1384.         mov     ecx, edx
  1385. ;--------------------------------------
  1386. align 4
  1387. @@:
  1388.         mov     [draw_limits.bottom], ecx
  1389.         ; recalculate screen buffer at old position
  1390.         push    ebx
  1391.         mov     edx, [eax + BOX.height]
  1392.         mov     ecx, [eax + BOX.width]
  1393.         mov     ebx, [eax + BOX.top]
  1394.         mov     eax, [eax + BOX.left]
  1395.         add     ecx, eax
  1396.         add     edx, ebx
  1397.         call    calculatescreen
  1398.         pop     eax
  1399.         ; recalculate screen buffer at new position
  1400.         mov     edx, [eax + BOX.height]
  1401.         mov     ecx, [eax + BOX.width]
  1402.         mov     ebx, [eax + BOX.top]
  1403.         mov     eax, [eax + BOX.left]
  1404.         add     ecx, eax
  1405.         add     edx, ebx
  1406.         call    calculatescreen
  1407.  
  1408.         mov     eax, edi
  1409.         call    redrawscreen
  1410.  
  1411.         ; tell window to redraw itself
  1412.         mov     [edi + WDATA.fl_redraw], 1
  1413.  
  1414.         pop     ebx eax
  1415.         ret
  1416. ;------------------------------------------------------------------------------
  1417. align 4
  1418. ;------------------------------------------------------------------------------
  1419. window._.set_window_box: ;/////////////////////////////////////////////////////
  1420. ;------------------------------------------------------------------------------
  1421. ;? <description>
  1422. ;------------------------------------------------------------------------------
  1423. ;> eax = pointer to BOX struct
  1424. ;> bl = new window state flags
  1425. ;> edi = pointer to WDATA struct
  1426. ;------------------------------------------------------------------------------
  1427.         push    eax ebx esi
  1428.  
  1429. ; don't do anything if the new box is identical to the old
  1430.         cmp     bl, [edi + WDATA.fl_wstate]
  1431.         jnz     @f
  1432.         mov     esi, eax
  1433.         push    edi
  1434. if WDATA.box
  1435.         add     edi, WDATA.box
  1436. end if
  1437.         mov     ecx, 4
  1438.         repz cmpsd
  1439.         pop     edi
  1440.         jz      .exit
  1441. ;--------------------------------------
  1442. align 4
  1443. @@:
  1444.         add     esp, -sizeof.BOX
  1445.         mov     ebx, esp
  1446. if WDATA.box
  1447.         lea     esi, [edi + WDATA.box]
  1448. else
  1449.         mov     esi, edi ; optimization for WDATA.box = 0
  1450. end if
  1451.         xchg    eax, esi
  1452.         mov     ecx, sizeof.BOX
  1453.         call    memmove
  1454.         xchg    eax, esi
  1455.         xchg    ebx, esi
  1456.         call    memmove
  1457.         mov     eax, ebx
  1458.         mov     ebx, esi
  1459.  
  1460.         call    window._.check_window_position
  1461.         call    window._.set_window_clientbox
  1462.         call    window._.invalidate_screen
  1463.  
  1464.         add     esp, sizeof.BOX
  1465.  
  1466.         mov     cl, [esp + 4]
  1467.         mov     ch, cl
  1468.         xchg    cl, [edi + WDATA.fl_wstate]
  1469.  
  1470.         or      cl, ch
  1471.         test    cl, WSTATE_MAXIMIZED
  1472.         jnz     .exit
  1473.  
  1474.         mov     eax, edi
  1475.         sub     eax, window_data
  1476.         shl     eax, 3
  1477.         add     eax, SLOT_BASE
  1478.  
  1479.         lea     ebx, [edi + WDATA.box]
  1480.         xchg    esp, ebx
  1481.  
  1482.         pop     [eax + APPDATA.saved_box.left] \
  1483.                 [eax + APPDATA.saved_box.top] \
  1484.                 [eax + APPDATA.saved_box.width] \
  1485.                 edx
  1486.  
  1487.         xchg    esp, ebx
  1488.  
  1489.         test    ch, WSTATE_ROLLEDUP
  1490.         jnz     .exit
  1491.  
  1492.         mov     [eax + APPDATA.saved_box.height], edx
  1493. ;--------------------------------------
  1494. align 4
  1495. .exit:
  1496.         pop     esi ebx eax
  1497.         ret
  1498. ;------------------------------------------------------------------------------
  1499. align 4
  1500. ;------------------------------------------------------------------------------
  1501. window._.set_window_clientbox: ;///////////////////////////////////////////////
  1502. ;------------------------------------------------------------------------------
  1503. ;? <description>
  1504. ;------------------------------------------------------------------------------
  1505. ;> edi = pointer to WDATA struct
  1506. ;------------------------------------------------------------------------------
  1507.         push    eax ecx edi
  1508.  
  1509.         mov     eax, [_skinh]
  1510.         mov     [window_topleft + 8 * 3 + 4], eax
  1511.         mov     [window_topleft + 8 * 4 + 4], eax
  1512.  
  1513.         mov     ecx, edi
  1514.         sub     edi, window_data
  1515.         shl     edi, 3
  1516.         test    [ecx + WDATA.fl_wstyle], WSTYLE_CLIENTRELATIVE
  1517.         jz      .whole_window
  1518.  
  1519.         movzx   eax, [ecx + WDATA.fl_wstyle]
  1520.         and     eax, 0x0F
  1521.         mov     eax, [eax * 8 + window_topleft + 0]
  1522.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.left], eax
  1523.         shl     eax, 1
  1524.         neg     eax
  1525.         add     eax, [ecx + WDATA.box.width]
  1526.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.width], eax
  1527.  
  1528.         movzx   eax, [ecx + WDATA.fl_wstyle]
  1529.         and     eax, 0x0F
  1530.         push    [eax * 8 + window_topleft + 0]
  1531.         mov     eax, [eax * 8 + window_topleft + 4]
  1532.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.top], eax
  1533.         neg     eax
  1534.         sub     eax, [esp]
  1535.         add     eax, [ecx + WDATA.box.height]
  1536.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.height], eax
  1537.         add     esp, 4
  1538.         jmp     .exit
  1539. ;--------------------------------------
  1540. align 4
  1541. .whole_window:
  1542.         xor     eax, eax
  1543.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.left], eax
  1544.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.top], eax
  1545.         mov     eax, [ecx + WDATA.box.width]
  1546.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.width], eax
  1547.         mov     eax, [ecx + WDATA.box.height]
  1548.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.height], eax
  1549. ;--------------------------------------
  1550. align 4
  1551. .exit:
  1552.         pop     edi ecx eax
  1553.         ret
  1554. ;------------------------------------------------------------------------------
  1555. align 4
  1556. ;------------------------------------------------------------------------------
  1557. window._.sys_set_window: ;/////////////////////////////////////////////////////
  1558. ;------------------------------------------------------------------------------
  1559. ;? <description>
  1560. ;------------------------------------------------------------------------------
  1561. ;< edx = pointer to WDATA struct
  1562. ;------------------------------------------------------------------------------
  1563.         mov     eax, [CURRENT_TASK]
  1564.         shl     eax, 5
  1565.         add     eax, window_data
  1566.  
  1567.         ; save window colors
  1568.         mov     [eax + WDATA.cl_workarea], edx
  1569.         mov     [eax + WDATA.cl_titlebar], esi
  1570.         mov     [eax + WDATA.cl_frames], edi
  1571.  
  1572.         mov     edi, eax
  1573.  
  1574.         ; was it already defined before?
  1575.         test    [edi + WDATA.fl_wdrawn], 1
  1576.         jnz     .set_client_box
  1577.         or      [edi + WDATA.fl_wdrawn], 1
  1578.  
  1579.         ; NOTE: commented out since doesn't provide necessary functionality
  1580.         ;       anyway, to be reworked
  1581. ;       mov     eax, [timer_ticks] ; [0xfdf0]
  1582. ;       add     eax, 100
  1583. ;       mov     [new_window_starting], eax
  1584.  
  1585.         ; no it wasn't, performing initial window definition
  1586.         movzx   eax, bx
  1587.         mov     [edi + WDATA.box.width], eax
  1588.         movzx   eax, cx
  1589.         mov     [edi + WDATA.box.height], eax
  1590.         sar     ebx, 16
  1591.         sar     ecx, 16
  1592.         mov     [edi + WDATA.box.left], ebx
  1593.         mov     [edi + WDATA.box.top], ecx
  1594.  
  1595.         call    window._.check_window_position
  1596.  
  1597.         push    ecx edi
  1598.  
  1599.         mov     cl, [edi + WDATA.fl_wstyle]
  1600.         mov     eax, [edi + WDATA.cl_frames]
  1601.  
  1602.         sub     edi, window_data
  1603.         shl     edi, 3
  1604.         add     edi, SLOT_BASE
  1605.  
  1606.         and     cl, 0x0F
  1607.         cmp     cl, 3
  1608.         je      @f
  1609.         cmp     cl, 4
  1610.         je      @f
  1611.  
  1612.         xor     eax, eax
  1613. ;--------------------------------------
  1614. align 4
  1615. @@:
  1616.         mov     [edi + APPDATA.wnd_caption], eax
  1617.  
  1618.         mov     esi, [esp]
  1619.         add     edi, APPDATA.saved_box
  1620.         movsd
  1621.         movsd
  1622.         movsd
  1623.         movsd
  1624.  
  1625.         pop     edi ecx
  1626.  
  1627.         mov     esi, [CURRENT_TASK]
  1628.         movzx   esi, word[WIN_STACK + esi * 2]
  1629.         lea     esi, [WIN_POS + esi * 2]
  1630.         call    waredraw
  1631.  
  1632.         mov     eax, [edi + WDATA.box.left]
  1633.         mov     ebx, [edi + WDATA.box.top]
  1634.         mov     ecx, [edi + WDATA.box.width]
  1635.         mov     edx, [edi + WDATA.box.height]
  1636.         add     ecx, eax
  1637.         add     edx, ebx
  1638.         call    calculatescreen
  1639.  
  1640.         mov     byte[KEY_COUNT], 0           ; empty keyboard buffer
  1641.         mov     byte[BTN_COUNT], 0           ; empty button buffer
  1642. ;--------------------------------------
  1643. align 4
  1644. .set_client_box:
  1645.         ; update window client box coordinates
  1646.         call    window._.set_window_clientbox
  1647.  
  1648.         ; reset window redraw flag and exit
  1649.         mov     [edi + WDATA.fl_redraw], 0
  1650.         mov     edx, edi
  1651.         ret
  1652. ;------------------------------------------------------------------------------
  1653. align 4
  1654. ;------------------------------------------------------------------------------
  1655. window._.check_window_position: ;//////////////////////////////////////////////
  1656. ;------------------------------------------------------------------------------
  1657. ;? Check if window is inside screen area
  1658. ;------------------------------------------------------------------------------
  1659. ;> edi = pointer to WDATA
  1660. ;------------------------------------------------------------------------------
  1661.         push    eax ebx ecx edx esi
  1662.  
  1663.         mov     eax, [edi + WDATA.box.left]
  1664.         mov     ebx, [edi + WDATA.box.top]
  1665.         mov     ecx, [edi + WDATA.box.width]
  1666.         mov     edx, [edi + WDATA.box.height]
  1667.  
  1668.         mov     esi, [Screen_Max_X]
  1669.         cmp     ecx, esi
  1670.         ja      .fix_width_high
  1671. ;--------------------------------------
  1672. align 4
  1673. .check_left:
  1674.         or      eax, eax
  1675.         jl      .fix_left_low
  1676.         add     eax, ecx
  1677.         cmp     eax, esi
  1678.         jg      .fix_left_high
  1679. ;--------------------------------------
  1680. align 4
  1681. .check_height:
  1682.         mov     esi, [Screen_Max_Y]
  1683.         cmp     edx, esi
  1684.         ja      .fix_height_high
  1685. ;--------------------------------------
  1686. align 4
  1687. .check_top:
  1688.         or      ebx, ebx
  1689.         jl      .fix_top_low
  1690.         add     ebx, edx
  1691.         cmp     ebx, esi
  1692.         jg      .fix_top_high
  1693. ;--------------------------------------
  1694. align 4
  1695. .exit:
  1696.         pop     esi edx ecx ebx eax
  1697.         ret
  1698. ;--------------------------------------
  1699. align 4
  1700. .fix_width_high:
  1701.         mov     ecx, esi
  1702.         mov     [edi + WDATA.box.width], esi
  1703.         jmp     .check_left
  1704. ;--------------------------------------
  1705. align 4
  1706. .fix_left_low:
  1707.         xor     eax, eax
  1708.         mov     [edi + WDATA.box.left], eax
  1709.         jmp     .check_height
  1710. ;--------------------------------------
  1711. align 4
  1712. .fix_left_high:
  1713.         mov     eax, esi
  1714.         sub     eax, ecx
  1715.         mov     [edi + WDATA.box.left], eax
  1716.         jmp     .check_height
  1717. ;--------------------------------------
  1718. align 4
  1719. .fix_height_high:
  1720.         mov     edx, esi
  1721.         mov     [edi + WDATA.box.height], esi
  1722.         jmp     .check_top
  1723. ;--------------------------------------
  1724. align 4
  1725. .fix_top_low:
  1726.         xor     ebx, ebx
  1727.         mov     [edi + WDATA.box.top], ebx
  1728.         jmp     .exit
  1729. ;--------------------------------------
  1730. align 4
  1731. .fix_top_high:
  1732.         mov     ebx, esi
  1733.         sub     ebx, edx
  1734.         mov     [edi + WDATA.box.top], ebx
  1735.         jmp     .exit
  1736. ;------------------------------------------------------------------------------
  1737. align 4
  1738. ;------------------------------------------------------------------------------
  1739. window._.get_titlebar_height: ;////////////////////////////////////////////////
  1740. ;------------------------------------------------------------------------------
  1741. ;? <description>
  1742. ;------------------------------------------------------------------------------
  1743. ;> edi = pointer to WDATA
  1744. ;------------------------------------------------------------------------------
  1745.         mov     al, [edi + WDATA.fl_wstyle]
  1746.         and     al, 0x0f
  1747.         cmp     al, 0x03
  1748.         jne     @f
  1749.         mov     eax, [_skinh]
  1750.         ret
  1751. ;--------------------------------------
  1752. align 4
  1753. @@:
  1754.         mov     eax, 21
  1755.         ret
  1756. ;------------------------------------------------------------------------------
  1757. align 4
  1758. ;------------------------------------------------------------------------------
  1759. window._.get_rolledup_height: ;////////////////////////////////////////////////
  1760. ;------------------------------------------------------------------------------
  1761. ;? <description>
  1762. ;------------------------------------------------------------------------------
  1763. ;> edi = pointer to WDATA
  1764. ;------------------------------------------------------------------------------
  1765.         mov     al, [edi + WDATA.fl_wstyle]
  1766.         and     al, 0x0f
  1767.         cmp     al, 0x03
  1768.         jb      @f
  1769.         mov     eax, [_skinh]
  1770.         add     eax, 3
  1771.         ret
  1772. ;--------------------------------------
  1773. align 4
  1774. @@:
  1775.         or      al, al
  1776.         jnz     @f
  1777.         mov     eax, 21
  1778.         ret
  1779. ;--------------------------------------
  1780. align 4
  1781. @@:
  1782.         mov     eax, 21 + 2
  1783.         ret
  1784. ;------------------------------------------------------------------------------
  1785. align 4
  1786. ;------------------------------------------------------------------------------
  1787. window._.set_screen: ;/////////////////////////////////////////////////////////
  1788. ;------------------------------------------------------------------------------
  1789. ;? Reserve window area in screen buffer
  1790. ;------------------------------------------------------------------------------
  1791. ;> eax = left
  1792. ;> ebx = top
  1793. ;> ecx = right
  1794. ;> edx = bottom
  1795. ;> esi = process number
  1796. ;------------------------------------------------------------------------------
  1797. virtual at esp
  1798.   ff_x     dd ?
  1799.   ff_y     dd ?
  1800.   ff_width dd ?
  1801.   ff_xsz   dd ?
  1802.   ff_ysz   dd ?
  1803.   ff_scale dd ?
  1804. end virtual
  1805.  
  1806.         pushad
  1807.  
  1808.         cmp     esi, 1
  1809.         jz      .check_for_shaped_window
  1810.         mov     edi, esi
  1811.         shl     edi, 5
  1812.         cmp     [window_data + edi + WDATA.box.width], 0
  1813.         jnz     .check_for_shaped_window
  1814.         cmp     [window_data + edi + WDATA.box.height], 0
  1815.         jz      .exit
  1816. ;--------------------------------------
  1817. align 4
  1818. .check_for_shaped_window:
  1819.         mov     edi, esi
  1820.         shl     edi, 8
  1821.         add     edi, SLOT_BASE
  1822.         cmp     [edi + APPDATA.wnd_shape], 0
  1823.         jne     .shaped_window
  1824.  
  1825.         ; get x&y size
  1826.         sub     ecx, eax
  1827.         sub     edx, ebx
  1828.         inc     ecx
  1829.         inc     edx
  1830.  
  1831.         ; get WinMap start
  1832.         push    esi
  1833.         mov     edi, [Screen_Max_X]
  1834.         inc     edi
  1835.         mov     esi, edi
  1836.         imul    edi, ebx
  1837.         add     edi, eax
  1838.         add     edi, [_WinMapAddress]
  1839.         pop     eax
  1840.         mov     ah, al
  1841.         push    ax
  1842.         shl     eax, 16
  1843.         pop     ax
  1844. ;--------------------------------------
  1845. align 4
  1846. .next_line:
  1847.         push    ecx
  1848.         shr     ecx, 2
  1849.         rep stosd
  1850.         mov     ecx, [esp]
  1851.         and     ecx, 3
  1852.         rep stosb
  1853.         pop     ecx
  1854.         add     edi, esi
  1855.         sub     edi, ecx
  1856.         dec     edx
  1857.         jnz     .next_line
  1858.  
  1859.         jmp     .exit
  1860. ;--------------------------------------
  1861. align 4
  1862. .shaped_window:
  1863.         ;  for (y=0; y <= x_size; y++)
  1864.         ;      for (x=0; x <= x_size; x++)
  1865.         ;          if (shape[coord(x,y,scale)]==1)
  1866.         ;             set_pixel(x, y, process_number);
  1867.  
  1868.         sub     ecx, eax
  1869.         sub     edx, ebx
  1870.         inc     ecx
  1871.         inc     edx
  1872.  
  1873.         push    [edi + APPDATA.wnd_shape_scale]  ; push scale first -> for loop
  1874.  
  1875.         ; get WinMap start  -> ebp
  1876.         push    eax
  1877.         mov     eax, [Screen_Max_X] ; screen_sx
  1878.         inc     eax
  1879.         imul    eax, ebx
  1880.         add     eax, [esp]
  1881.         add     eax, [_WinMapAddress]
  1882.         mov     ebp, eax
  1883.  
  1884.         mov     edi, [edi + APPDATA.wnd_shape]
  1885.         pop     eax
  1886.  
  1887.         ; eax = x_start
  1888.         ; ebx = y_start
  1889.         ; ecx = x_size
  1890.         ; edx = y_size
  1891.         ; esi = process_number
  1892.         ; edi = &shape
  1893.         ;       [scale]
  1894.         push    edx ecx ; for loop - x,y size
  1895.  
  1896.         mov     ecx, esi
  1897.         shl     ecx, 5
  1898.         mov     edx, [window_data + ecx + WDATA.box.top]
  1899.         push    [window_data + ecx + WDATA.box.width]           ; for loop - width
  1900.         mov     ecx, [window_data + ecx + WDATA.box.left]
  1901.         sub     ebx, edx
  1902.         sub     eax, ecx
  1903.         push    ebx eax ; for loop - x,y
  1904.  
  1905.         add     [ff_xsz], eax
  1906.         add     [ff_ysz], ebx
  1907.  
  1908.         mov     ebx, [ff_y]
  1909. ;--------------------------------------
  1910. align 4
  1911. .ff_new_y:
  1912.         mov     edx, [ff_x]
  1913. ;--------------------------------------
  1914. align 4
  1915. .ff_new_x:
  1916.         ; -- body --
  1917.         mov     ecx, [ff_scale]
  1918.         mov     eax, [ff_width]
  1919.         inc     eax
  1920.         shr     eax, cl
  1921.         push    ebx edx
  1922.         shr     ebx, cl
  1923.         shr     edx, cl
  1924.         imul    eax, ebx
  1925.         add     eax, edx
  1926.         pop     edx ebx
  1927.         add     eax, edi
  1928.         call    .read_byte
  1929.         test    al, al
  1930.         jz      @f
  1931.         mov     eax, esi
  1932.         mov     [ebp], al
  1933.         ; -- end body --
  1934. ;--------------------------------------
  1935. align 4
  1936. @@:
  1937.         inc     ebp
  1938.         inc     edx
  1939.         cmp     edx, [ff_xsz]
  1940.         jb      .ff_new_x
  1941.  
  1942.         sub     ebp, [ff_xsz]
  1943.         add     ebp, [ff_x]
  1944.         add     ebp, [Screen_Max_X]  ; screen.x
  1945.         inc     ebp
  1946.         inc     ebx
  1947.         cmp     ebx, [ff_ysz]
  1948.         jb      .ff_new_y
  1949.  
  1950.         add     esp, 24
  1951. ;--------------------------------------
  1952. align 4
  1953. .exit:
  1954.         popad
  1955.         inc     [_display.mask_seqno]
  1956.         ret
  1957. ;--------------------------------------
  1958. align 4
  1959. .read_byte:
  1960.         ; eax - address
  1961.         ; esi - slot
  1962.         push    eax ecx edx esi
  1963.         xchg    eax, esi
  1964.         lea     ecx, [esp + 12]
  1965.         mov     edx, 1
  1966.         call    read_process_memory
  1967.         pop     esi edx ecx eax
  1968.         ret
  1969. ;------------------------------------------------------------------------------
  1970. align 4
  1971. ;------------------------------------------------------------------------------
  1972. window._.window_activate: ;////////////////////////////////////////////////////
  1973. ;------------------------------------------------------------------------------
  1974. ;? Activate window
  1975. ;------------------------------------------------------------------------------
  1976. ;> esi = pointer to WIN_POS+ window data
  1977. ;------------------------------------------------------------------------------
  1978.         push    eax ebx
  1979.  
  1980.         ; if type of current active window is 3 or 4, it must be redrawn
  1981.         mov     ebx, [TASK_COUNT]
  1982.        
  1983. ;       DEBUGF  1, "K : TASK_COUNT (0x%x)\n", ebx
  1984.        
  1985.         movzx   ebx, word[WIN_POS + ebx * 2]
  1986.         shl     ebx, 5
  1987.         add     eax, window_data
  1988.         mov     al, [window_data + ebx + WDATA.fl_wstyle]
  1989.         and     al, 0x0f
  1990.         cmp     al, 0x03
  1991.         je      .set_window_redraw_flag
  1992.         cmp     al, 0x04
  1993.         jne     .move_others_down
  1994. ;--------------------------------------
  1995. align 4
  1996. .set_window_redraw_flag:
  1997.         mov     [window_data + ebx + WDATA.fl_redraw], 1
  1998. ;--------------------------------------
  1999. align 4
  2000. .move_others_down:
  2001.         ; ax <- process no
  2002.         movzx   ebx, word[esi]
  2003.         ; ax <- position in window stack
  2004.         movzx   ebx, word[WIN_STACK + ebx * 2]
  2005.  
  2006.         ; drop others
  2007.         xor     eax, eax
  2008. ;--------------------------------------
  2009. align 4
  2010. .next_stack_window:
  2011.         cmp     eax, [TASK_COUNT]
  2012.         jae     .move_self_up
  2013.         inc     eax
  2014.        
  2015. ;       push    ebx
  2016. ;       xor     ebx,ebx
  2017. ;       mov     bx,[WIN_STACK + eax * 2]
  2018. ;       DEBUGF  1, "K : DEC WIN_STACK (0x%x)\n",ebx
  2019. ;       pop     ebx
  2020.        
  2021.         cmp     [WIN_STACK + eax * 2], bx
  2022.         jbe     .next_stack_window
  2023.         dec     word[WIN_STACK + eax * 2]
  2024.         jmp     .next_stack_window
  2025. ;--------------------------------------
  2026. align 4
  2027. .move_self_up:
  2028.         movzx   ebx, word[esi]
  2029.         ; number of processes
  2030.         mov     ax, [TASK_COUNT]
  2031.         ; this is the last (and the upper)
  2032.         mov     [WIN_STACK + ebx * 2], ax
  2033.  
  2034.         ; update on screen - window stack
  2035.         xor     eax, eax
  2036. ;--------------------------------------
  2037. align 4
  2038. .next_window_pos:
  2039.         cmp     eax, [TASK_COUNT]
  2040.         jae     .reset_vars
  2041.         inc     eax
  2042.         movzx   ebx, word[WIN_STACK + eax * 2]
  2043.         mov     [WIN_POS + ebx * 2], ax
  2044.         jmp     .next_window_pos
  2045. ;--------------------------------------
  2046. align 4
  2047. .reset_vars:
  2048.         mov     byte[KEY_COUNT], 0
  2049.         mov     byte[BTN_COUNT], 0
  2050.         mov     word[MOUSE_SCROLL_H], 0
  2051.         mov     word[MOUSE_SCROLL_V], 0
  2052.  
  2053.         pop     ebx eax
  2054.         ret
  2055. ;------------------------------------------------------------------------------
  2056. window._.window_deactivate: ;////////////////////////////////////////////////////
  2057. ;------------------------------------------------------------------------------
  2058. ;? Deactivate window
  2059. ;------------------------------------------------------------------------------
  2060. ;> esi = pointer to WIN_POS+ window data
  2061. ;------------------------------------------------------------------------------
  2062.         push    eax ebx
  2063. ;--------------------------------------
  2064. align 4
  2065. .move_others_up:
  2066.         ; ax <- process no
  2067.         movzx   ebx, word[esi]
  2068.         ; ax <- position in window stack
  2069.         movzx   ebx, word[WIN_STACK + ebx * 2]
  2070.         ; up others
  2071.         xor     eax, eax
  2072. ;--------------------------------------
  2073. align 4
  2074. .next_stack_window:
  2075.         cmp     eax, [TASK_COUNT]
  2076.         jae     .move_self_down
  2077.         inc     eax
  2078.         cmp     [WIN_STACK + eax * 2], bx
  2079.         jae     .next_stack_window
  2080.         inc     word[WIN_STACK + eax * 2]
  2081.         jmp     .next_stack_window
  2082. ;--------------------------------------
  2083. align 4
  2084. .move_self_down:
  2085.         movzx   ebx, word[esi]
  2086.         ; this is the last (and the low)
  2087.         mov     [WIN_STACK + ebx * 2], word 1
  2088.         ; update on screen - window stack
  2089.         xor     eax, eax
  2090. ;--------------------------------------
  2091. align 4
  2092. .next_window_pos:
  2093.         cmp     eax, [TASK_COUNT]
  2094.         jae     .reset_vars
  2095.         inc     eax
  2096.         movzx   ebx, word[WIN_STACK + eax * 2]
  2097.         mov     [WIN_POS + ebx * 2], ax
  2098.         jmp     .next_window_pos
  2099. ;--------------------------------------
  2100. align 4
  2101. .reset_vars:
  2102.         mov     byte[KEY_COUNT], 0
  2103.         mov     byte[BTN_COUNT], 0
  2104.         mov     word[MOUSE_SCROLL_H], 0
  2105.         mov     word[MOUSE_SCROLL_V], 0
  2106.         pop     ebx eax
  2107.         ret
  2108. ;------------------------------------------------------------------------------
  2109. align 4
  2110. ;------------------------------------------------------------------------------
  2111. window._.check_window_draw: ;//////////////////////////////////////////////////
  2112. ;------------------------------------------------------------------------------
  2113. ;? Check if window is necessary to draw
  2114. ;------------------------------------------------------------------------------
  2115. ;> edi = pointer to WDATA
  2116. ;------------------------------------------------------------------------------
  2117.         mov     cl, [edi + WDATA.fl_wstyle]
  2118.         and     cl, 0x0f
  2119.         cmp     cl, 3
  2120.         je      .exit.redraw      ; window type 3
  2121.         cmp     cl, 4
  2122.         je      .exit.redraw      ; window type 4
  2123.  
  2124.         push    eax ebx edx esi
  2125.  
  2126.         mov     eax, edi
  2127.         sub     eax, window_data
  2128.         shr     eax, 5
  2129.  
  2130.         movzx   eax, word[WIN_STACK + eax * 2]  ; get value of the curr process
  2131.         lea     esi, [WIN_POS + eax * 2]        ; get address of this process at 0xC400
  2132. ;--------------------------------------
  2133. align 4
  2134. .next_window:
  2135.         add     esi, 2
  2136.  
  2137.         mov     eax, [TASK_COUNT]
  2138.         lea     eax, word[WIN_POS + eax * 2] ; number of the upper window
  2139.  
  2140.         cmp     esi, eax
  2141.         ja      .exit.no_redraw
  2142.  
  2143.         movzx   edx, word[esi]
  2144.         shl     edx, 5
  2145.         cmp     [CURRENT_TASK + edx + TASKDATA.state], TSTATE_FREE
  2146.         je      .next_window
  2147.  
  2148.         mov     eax, [edi + WDATA.box.top]
  2149.         mov     ebx, [edi + WDATA.box.height]
  2150.         add     ebx, eax
  2151.  
  2152.         mov     ecx, [window_data + edx + WDATA.box.top]
  2153.         cmp     ecx, ebx
  2154.         jge     .next_window
  2155.         add     ecx, [window_data + edx + WDATA.box.height]
  2156.         cmp     eax, ecx
  2157.         jge     .next_window
  2158.  
  2159.         mov     eax, [edi + WDATA.box.left]
  2160.         mov     ebx, [edi + WDATA.box.width]
  2161.         add     ebx, eax
  2162.  
  2163.         mov     ecx, [window_data + edx + WDATA.box.left]
  2164.         cmp     ecx, ebx
  2165.         jge     .next_window
  2166.         add     ecx, [window_data + edx + WDATA.box.width]
  2167.         cmp     eax, ecx
  2168.         jge     .next_window
  2169.  
  2170.         pop     esi edx ebx eax
  2171. ;--------------------------------------
  2172. align 4
  2173. .exit.redraw:
  2174.         xor     ecx, ecx
  2175.         inc     ecx
  2176.         ret
  2177. ;--------------------------------------
  2178. align 4
  2179. .exit.no_redraw:
  2180.         pop     esi edx ebx eax
  2181.         xor     ecx, ecx
  2182.         ret
  2183. ;------------------------------------------------------------------------------
  2184. align 4
  2185. ;------------------------------------------------------------------------------
  2186. window._.draw_window_caption: ;////////////////////////////////////////////////
  2187. ;------------------------------------------------------------------------------
  2188. ;? <description>
  2189. ;------------------------------------------------------------------------------
  2190.         xor     eax, eax
  2191.         mov     edx, [TASK_COUNT]
  2192.         movzx   edx, word[WIN_POS + edx * 2]
  2193.         cmp     edx, [CURRENT_TASK]
  2194.         jne     @f
  2195.         inc     eax
  2196. ;--------------------------------------
  2197. align 4
  2198. @@:
  2199.         mov     edx, [CURRENT_TASK]
  2200.         shl     edx, 5
  2201.         add     edx, window_data
  2202.         movzx   ebx, [edx + WDATA.fl_wstyle]
  2203.         and     bl, 0x0F
  2204.         cmp     bl, 3
  2205.         je      .draw_caption_style_3
  2206.         cmp     bl, 4
  2207.         je      .draw_caption_style_3
  2208.  
  2209.         jmp     .not_style_3
  2210. ;--------------------------------------
  2211. align 4
  2212. .draw_caption_style_3:
  2213.         push    edx
  2214.         call    drawwindow_IV_caption
  2215.         add     esp, 4
  2216.         jmp     .2
  2217. ;--------------------------------------
  2218. align 4
  2219. .not_style_3:
  2220.         cmp     bl, 2
  2221.         jne     .not_style_2
  2222.  
  2223.         call    drawwindow_III_caption
  2224.         jmp     .2
  2225. ;--------------------------------------
  2226. align 4
  2227. .not_style_2:
  2228.         cmp     bl, 0
  2229.         jne     .2
  2230.  
  2231.         call    drawwindow_I_caption
  2232. ;--------------------------------------
  2233. align 4
  2234. .2:
  2235.         mov     edi, [CURRENT_TASK]
  2236.         shl     edi, 5
  2237.         test    [edi + window_data + WDATA.fl_wstyle], WSTYLE_HASCAPTION
  2238.         jz      .exit
  2239.         mov     edx, [edi * 8 + SLOT_BASE + APPDATA.wnd_caption]
  2240.         or      edx, edx
  2241.         jz      .exit
  2242.  
  2243.         movzx   eax, [edi + window_data + WDATA.fl_wstyle]
  2244.         and     al, 0x0F
  2245.         cmp     al, 3
  2246.         je      .skinned
  2247.         cmp     al, 4
  2248.         je      .skinned
  2249.  
  2250.         jmp     .not_skinned
  2251. ;--------------------------------------
  2252. align 4
  2253. .skinned:
  2254.         mov     ebp, [edi + window_data + WDATA.box.left - 2]
  2255.         mov     bp, word[edi + window_data + WDATA.box.top]
  2256.         movzx   eax, word[edi + window_data + WDATA.box.width]
  2257.         sub     ax, [_skinmargins.left]
  2258.         sub     ax, [_skinmargins.right]
  2259.         push    edx
  2260.         cwde
  2261.         cdq
  2262.         mov     ebx, 6
  2263.         idiv    ebx
  2264.         pop     edx
  2265.         or      eax, eax
  2266.         js      .exit
  2267.  
  2268.         mov     esi, eax
  2269.         mov     ebx, dword[_skinmargins.left - 2]
  2270.         mov     bx, word[_skinh]
  2271.         sub     bx, [_skinmargins.bottom]
  2272.         sub     bx, [_skinmargins.top]
  2273.         sar     bx, 1
  2274.         adc     bx, 0
  2275.         add     bx, [_skinmargins.top]
  2276.         add     bx, -3
  2277.         add     ebx, ebp
  2278.         jmp     .dodraw
  2279. ;--------------------------------------
  2280. align 4
  2281. .not_skinned:
  2282.         cmp     al, 1
  2283.         je      .exit
  2284.  
  2285.         mov     ebp, [edi + window_data + WDATA.box.left - 2]
  2286.         mov     bp, word[edi + window_data + WDATA.box.top]
  2287.         movzx   eax, word[edi + window_data + WDATA.box.width]
  2288.         sub     eax, 16
  2289.         push    edx
  2290.         cwde
  2291.         cdq
  2292.         mov     ebx, 6
  2293.         idiv    ebx
  2294.         pop     edx
  2295.         or      eax, eax
  2296.         js      .exit
  2297.  
  2298.         mov     esi, eax
  2299.         mov     ebx, 0x00080007
  2300.         add     ebx, ebp
  2301. ;--------------------------------------
  2302. align 4
  2303. .dodraw:
  2304.         mov     ecx, [common_colours + 16]
  2305.         or      ecx, 0x80000000
  2306.         xor     edi, edi
  2307.         call    dtext_asciiz_esi
  2308. ;--------------------------------------
  2309. align 4
  2310. .exit:
  2311.         call    [draw_pointer]
  2312.         ret
  2313. ;------------------------------------------------------------------------------
  2314. align 4
  2315. ;------------------------------------------------------------------------------
  2316. window._.draw_negative_box: ;//////////////////////////////////////////////////
  2317. ;------------------------------------------------------------------------------
  2318. ;? Draw negative box
  2319. ;------------------------------------------------------------------------------
  2320. ;> edi = pointer to BOX struct
  2321. ;------------------------------------------------------------------------------
  2322.         push    eax ebx esi
  2323.         mov     esi, 0x01000000
  2324. ;--------------------------------------
  2325. align 4
  2326. .1:
  2327.         mov     eax, [edi + BOX.left - 2]
  2328.         mov     ax, word[edi + BOX.left]
  2329.         add     ax, word[edi + BOX.width]
  2330.         mov     ebx, [edi + BOX.top - 2]
  2331.         mov     bx, word[edi + BOX.top]
  2332.         add     bx, word[edi + BOX.height]
  2333.         call    draw_rectangle.forced
  2334.         pop     esi ebx eax
  2335.         ret
  2336. ;------------------------------------------------------------------------------
  2337. align 4
  2338. ;------------------------------------------------------------------------------
  2339. window._.end_moving__box: ;//////////////////////////////////////////////////
  2340. ;------------------------------------------------------------------------------
  2341. ;? Draw positive box
  2342. ;------------------------------------------------------------------------------
  2343. ;> edi = pointer to BOX struct
  2344. ;------------------------------------------------------------------------------
  2345.         push    eax ebx esi
  2346.         xor     esi, esi
  2347.         jmp     window._.draw_negative_box.1
  2348. ;------------------------------------------------------------------------------
  2349. align 4
  2350. ;------------------------------------------------------------------------------
  2351. window._.get_rect: ;/////////////////////////////////////////////////////
  2352. ;------------------------------------------------------------------------------
  2353. ;? <description>  void __fastcall get_window_rect(struct RECT* rc);
  2354. ;------------------------------------------------------------------------------
  2355. ;> ecx = pointer to RECT
  2356. ;------------------------------------------------------------------------------
  2357.         mov     eax, [TASK_BASE]
  2358.  
  2359.         mov     edx, [eax-twdw + WDATA.box.left]
  2360.         mov     [ecx+RECT.left], edx
  2361.  
  2362.         add     edx, [eax-twdw + WDATA.box.width]
  2363.         mov     [ecx+RECT.right], edx
  2364.  
  2365.         mov     edx, [eax-twdw + WDATA.box.top]
  2366.         mov     [ecx+RECT.top], edx
  2367.  
  2368.         add     edx, [eax-twdw + WDATA.box.height]
  2369.         mov     [ecx+RECT.bottom], edx
  2370.         ret
  2371. ;------------------------------------------------------------------------------
  2372.