Subversion Repositories Kolibri OS

Rev

Rev 2443 | Rev 2453 | 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: 2446 $
  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.         mov     esi, [Screen_Max_X]
  1837.         inc     esi
  1838. ;        imul    edi, ebx
  1839.         mov     edi, [d_width_calc_area + ebx*4]
  1840.  
  1841.         add     edi, eax
  1842.         add     edi, [_WinMapAddress]
  1843.         pop     eax
  1844.         mov     ah, al
  1845.         push    ax
  1846.         shl     eax, 16
  1847.         pop     ax
  1848. ;--------------------------------------
  1849. align 4
  1850. .next_line:
  1851.         push    ecx
  1852.         shr     ecx, 2
  1853.         rep stosd
  1854.         mov     ecx, [esp]
  1855.         and     ecx, 3
  1856.         rep stosb
  1857.         pop     ecx
  1858.         add     edi, esi
  1859.         sub     edi, ecx
  1860.         dec     edx
  1861.         jnz     .next_line
  1862.  
  1863.         jmp     .exit
  1864. ;--------------------------------------
  1865. align 4
  1866. .shaped_window:
  1867.         ;  for (y=0; y <= x_size; y++)
  1868.         ;      for (x=0; x <= x_size; x++)
  1869.         ;          if (shape[coord(x,y,scale)]==1)
  1870.         ;             set_pixel(x, y, process_number);
  1871.  
  1872.         sub     ecx, eax
  1873.         sub     edx, ebx
  1874.         inc     ecx
  1875.         inc     edx
  1876.  
  1877.         push    [edi + APPDATA.wnd_shape_scale]  ; push scale first -> for loop
  1878.  
  1879.         ; get WinMap start  -> ebp
  1880.         push    eax
  1881. ;        mov     eax, [Screen_Max_X] ; screen_sx
  1882. ;        inc     eax
  1883. ;        imul    eax, ebx
  1884.         mov     eax, [d_width_calc_area + ebx*4]
  1885.  
  1886.         add     eax, [esp]
  1887.         add     eax, [_WinMapAddress]
  1888.         mov     ebp, eax
  1889.  
  1890.         mov     edi, [edi + APPDATA.wnd_shape]
  1891.         pop     eax
  1892.  
  1893.         ; eax = x_start
  1894.         ; ebx = y_start
  1895.         ; ecx = x_size
  1896.         ; edx = y_size
  1897.         ; esi = process_number
  1898.         ; edi = &shape
  1899.         ;       [scale]
  1900.         push    edx ecx ; for loop - x,y size
  1901.  
  1902.         mov     ecx, esi
  1903.         shl     ecx, 5
  1904.         mov     edx, [window_data + ecx + WDATA.box.top]
  1905.         push    [window_data + ecx + WDATA.box.width]           ; for loop - width
  1906.         mov     ecx, [window_data + ecx + WDATA.box.left]
  1907.         sub     ebx, edx
  1908.         sub     eax, ecx
  1909.         push    ebx eax ; for loop - x,y
  1910.  
  1911.         add     [ff_xsz], eax
  1912.         add     [ff_ysz], ebx
  1913.  
  1914.         mov     ebx, [ff_y]
  1915. ;--------------------------------------
  1916. align 4
  1917. .ff_new_y:
  1918.         mov     edx, [ff_x]
  1919. ;--------------------------------------
  1920. align 4
  1921. .ff_new_x:
  1922.         ; -- body --
  1923.         mov     ecx, [ff_scale]
  1924.         mov     eax, [ff_width]
  1925.         inc     eax
  1926.         shr     eax, cl
  1927.         push    ebx edx
  1928.         shr     ebx, cl
  1929.         shr     edx, cl
  1930.         imul    eax, ebx
  1931.         add     eax, edx
  1932.         pop     edx ebx
  1933.         add     eax, edi
  1934.         call    .read_byte
  1935.         test    al, al
  1936.         jz      @f
  1937.         mov     eax, esi
  1938.         mov     [ebp], al
  1939.         ; -- end body --
  1940. ;--------------------------------------
  1941. align 4
  1942. @@:
  1943.         inc     ebp
  1944.         inc     edx
  1945.         cmp     edx, [ff_xsz]
  1946.         jb      .ff_new_x
  1947.  
  1948.         sub     ebp, [ff_xsz]
  1949.         add     ebp, [ff_x]
  1950.         add     ebp, [Screen_Max_X]  ; screen.x
  1951.         inc     ebp
  1952.         inc     ebx
  1953.         cmp     ebx, [ff_ysz]
  1954.         jb      .ff_new_y
  1955.  
  1956.         add     esp, 24
  1957. ;--------------------------------------
  1958. align 4
  1959. .exit:
  1960.         popad
  1961.         inc     [_display.mask_seqno]
  1962.         ret
  1963. ;--------------------------------------
  1964. align 4
  1965. .read_byte:
  1966.         ; eax - address
  1967.         ; esi - slot
  1968.         push    eax ecx edx esi
  1969.         xchg    eax, esi
  1970.         lea     ecx, [esp + 12]
  1971.         mov     edx, 1
  1972.         call    read_process_memory
  1973.         pop     esi edx ecx eax
  1974.         ret
  1975. ;------------------------------------------------------------------------------
  1976. align 4
  1977. ;------------------------------------------------------------------------------
  1978. window._.window_activate: ;////////////////////////////////////////////////////
  1979. ;------------------------------------------------------------------------------
  1980. ;? Activate window
  1981. ;------------------------------------------------------------------------------
  1982. ;> esi = pointer to WIN_POS+ window data
  1983. ;------------------------------------------------------------------------------
  1984.         push    eax ebx
  1985.  
  1986.         ; if type of current active window is 3 or 4, it must be redrawn
  1987.         mov     ebx, [TASK_COUNT]
  1988.        
  1989. ;       DEBUGF  1, "K : TASK_COUNT (0x%x)\n", ebx
  1990.        
  1991.         movzx   ebx, word[WIN_POS + ebx * 2]
  1992.         shl     ebx, 5
  1993.         add     eax, window_data
  1994.         mov     al, [window_data + ebx + WDATA.fl_wstyle]
  1995.         and     al, 0x0f
  1996.         cmp     al, 0x03
  1997.         je      .set_window_redraw_flag
  1998.         cmp     al, 0x04
  1999.         jne     .move_others_down
  2000. ;--------------------------------------
  2001. align 4
  2002. .set_window_redraw_flag:
  2003.         mov     [window_data + ebx + WDATA.fl_redraw], 1
  2004. ;--------------------------------------
  2005. align 4
  2006. .move_others_down:
  2007.         ; ax <- process no
  2008.         movzx   ebx, word[esi]
  2009.         ; ax <- position in window stack
  2010.         movzx   ebx, word[WIN_STACK + ebx * 2]
  2011.  
  2012.         ; drop others
  2013.         xor     eax, eax
  2014. ;--------------------------------------
  2015. align 4
  2016. .next_stack_window:
  2017.         cmp     eax, [TASK_COUNT]
  2018.         jae     .move_self_up
  2019.         inc     eax
  2020.        
  2021. ;       push    ebx
  2022. ;       xor     ebx,ebx
  2023. ;       mov     bx,[WIN_STACK + eax * 2]
  2024. ;       DEBUGF  1, "K : DEC WIN_STACK (0x%x)\n",ebx
  2025. ;       pop     ebx
  2026.        
  2027.         cmp     [WIN_STACK + eax * 2], bx
  2028.         jbe     .next_stack_window
  2029.         dec     word[WIN_STACK + eax * 2]
  2030.         jmp     .next_stack_window
  2031. ;--------------------------------------
  2032. align 4
  2033. .move_self_up:
  2034.         movzx   ebx, word[esi]
  2035.         ; number of processes
  2036.         mov     ax, [TASK_COUNT]
  2037.         ; this is the last (and the upper)
  2038.         mov     [WIN_STACK + ebx * 2], ax
  2039.  
  2040.         ; update on screen - window stack
  2041.         xor     eax, eax
  2042. ;--------------------------------------
  2043. align 4
  2044. .next_window_pos:
  2045.         cmp     eax, [TASK_COUNT]
  2046.         jae     .reset_vars
  2047.         inc     eax
  2048.         movzx   ebx, word[WIN_STACK + eax * 2]
  2049.         mov     [WIN_POS + ebx * 2], ax
  2050.         jmp     .next_window_pos
  2051. ;--------------------------------------
  2052. align 4
  2053. .reset_vars:
  2054.         mov     byte[KEY_COUNT], 0
  2055.         mov     byte[BTN_COUNT], 0
  2056.         mov     word[MOUSE_SCROLL_H], 0
  2057.         mov     word[MOUSE_SCROLL_V], 0
  2058.  
  2059.         pop     ebx eax
  2060.         ret
  2061. ;------------------------------------------------------------------------------
  2062. window._.window_deactivate: ;////////////////////////////////////////////////////
  2063. ;------------------------------------------------------------------------------
  2064. ;? Deactivate window
  2065. ;------------------------------------------------------------------------------
  2066. ;> esi = pointer to WIN_POS+ window data
  2067. ;------------------------------------------------------------------------------
  2068.         push    eax ebx
  2069. ;--------------------------------------
  2070. align 4
  2071. .move_others_up:
  2072.         ; ax <- process no
  2073.         movzx   ebx, word[esi]
  2074.         ; ax <- position in window stack
  2075.         movzx   ebx, word[WIN_STACK + ebx * 2]
  2076.         ; up others
  2077.         xor     eax, eax
  2078. ;--------------------------------------
  2079. align 4
  2080. .next_stack_window:
  2081.         cmp     eax, [TASK_COUNT]
  2082.         jae     .move_self_down
  2083.         inc     eax
  2084.         cmp     [WIN_STACK + eax * 2], bx
  2085.         jae     .next_stack_window
  2086.         inc     word[WIN_STACK + eax * 2]
  2087.         jmp     .next_stack_window
  2088. ;--------------------------------------
  2089. align 4
  2090. .move_self_down:
  2091.         movzx   ebx, word[esi]
  2092.         ; this is the last (and the low)
  2093.         mov     [WIN_STACK + ebx * 2], word 1
  2094.         ; update on screen - window stack
  2095.         xor     eax, eax
  2096. ;--------------------------------------
  2097. align 4
  2098. .next_window_pos:
  2099.         cmp     eax, [TASK_COUNT]
  2100.         jae     .reset_vars
  2101.         inc     eax
  2102.         movzx   ebx, word[WIN_STACK + eax * 2]
  2103.         mov     [WIN_POS + ebx * 2], ax
  2104.         jmp     .next_window_pos
  2105. ;--------------------------------------
  2106. align 4
  2107. .reset_vars:
  2108.         mov     byte[KEY_COUNT], 0
  2109.         mov     byte[BTN_COUNT], 0
  2110.         mov     word[MOUSE_SCROLL_H], 0
  2111.         mov     word[MOUSE_SCROLL_V], 0
  2112.         pop     ebx eax
  2113.         ret
  2114. ;------------------------------------------------------------------------------
  2115. align 4
  2116. ;------------------------------------------------------------------------------
  2117. window._.check_window_draw: ;//////////////////////////////////////////////////
  2118. ;------------------------------------------------------------------------------
  2119. ;? Check if window is necessary to draw
  2120. ;------------------------------------------------------------------------------
  2121. ;> edi = pointer to WDATA
  2122. ;------------------------------------------------------------------------------
  2123.         mov     cl, [edi + WDATA.fl_wstyle]
  2124.         and     cl, 0x0f
  2125.         cmp     cl, 3
  2126.         je      .exit.redraw      ; window type 3
  2127.         cmp     cl, 4
  2128.         je      .exit.redraw      ; window type 4
  2129.  
  2130.         push    eax ebx edx esi
  2131.  
  2132.         mov     eax, edi
  2133.         sub     eax, window_data
  2134.         shr     eax, 5
  2135.  
  2136.         movzx   eax, word[WIN_STACK + eax * 2]  ; get value of the curr process
  2137.         lea     esi, [WIN_POS + eax * 2]        ; get address of this process at 0xC400
  2138. ;--------------------------------------
  2139. align 4
  2140. .next_window:
  2141.         add     esi, 2
  2142.  
  2143.         mov     eax, [TASK_COUNT]
  2144.         lea     eax, word[WIN_POS + eax * 2] ; number of the upper window
  2145.  
  2146.         cmp     esi, eax
  2147.         ja      .exit.no_redraw
  2148.  
  2149.         movzx   edx, word[esi]
  2150.         shl     edx, 5
  2151.         cmp     [CURRENT_TASK + edx + TASKDATA.state], TSTATE_FREE
  2152.         je      .next_window
  2153.  
  2154.         mov     eax, [edi + WDATA.box.top]
  2155.         mov     ebx, [edi + WDATA.box.height]
  2156.         add     ebx, eax
  2157.  
  2158.         mov     ecx, [window_data + edx + WDATA.box.top]
  2159.         cmp     ecx, ebx
  2160.         jge     .next_window
  2161.         add     ecx, [window_data + edx + WDATA.box.height]
  2162.         cmp     eax, ecx
  2163.         jge     .next_window
  2164.  
  2165.         mov     eax, [edi + WDATA.box.left]
  2166.         mov     ebx, [edi + WDATA.box.width]
  2167.         add     ebx, eax
  2168.  
  2169.         mov     ecx, [window_data + edx + WDATA.box.left]
  2170.         cmp     ecx, ebx
  2171.         jge     .next_window
  2172.         add     ecx, [window_data + edx + WDATA.box.width]
  2173.         cmp     eax, ecx
  2174.         jge     .next_window
  2175.  
  2176.         pop     esi edx ebx eax
  2177. ;--------------------------------------
  2178. align 4
  2179. .exit.redraw:
  2180.         xor     ecx, ecx
  2181.         inc     ecx
  2182.         ret
  2183. ;--------------------------------------
  2184. align 4
  2185. .exit.no_redraw:
  2186.         pop     esi edx ebx eax
  2187.         xor     ecx, ecx
  2188.         ret
  2189. ;------------------------------------------------------------------------------
  2190. align 4
  2191. ;------------------------------------------------------------------------------
  2192. window._.draw_window_caption: ;////////////////////////////////////////////////
  2193. ;------------------------------------------------------------------------------
  2194. ;? <description>
  2195. ;------------------------------------------------------------------------------
  2196.         xor     eax, eax
  2197.         mov     edx, [TASK_COUNT]
  2198.         movzx   edx, word[WIN_POS + edx * 2]
  2199.         cmp     edx, [CURRENT_TASK]
  2200.         jne     @f
  2201.         inc     eax
  2202. ;--------------------------------------
  2203. align 4
  2204. @@:
  2205.         mov     edx, [CURRENT_TASK]
  2206.         shl     edx, 5
  2207.         add     edx, window_data
  2208.         movzx   ebx, [edx + WDATA.fl_wstyle]
  2209.         and     bl, 0x0F
  2210.         cmp     bl, 3
  2211.         je      .draw_caption_style_3
  2212.         cmp     bl, 4
  2213.         je      .draw_caption_style_3
  2214.  
  2215.         jmp     .not_style_3
  2216. ;--------------------------------------
  2217. align 4
  2218. .draw_caption_style_3:
  2219.         push    edx
  2220.         call    drawwindow_IV_caption
  2221.         add     esp, 4
  2222.         jmp     .2
  2223. ;--------------------------------------
  2224. align 4
  2225. .not_style_3:
  2226.         cmp     bl, 2
  2227.         jne     .not_style_2
  2228.  
  2229.         call    drawwindow_III_caption
  2230.         jmp     .2
  2231. ;--------------------------------------
  2232. align 4
  2233. .not_style_2:
  2234.         cmp     bl, 0
  2235.         jne     .2
  2236.  
  2237.         call    drawwindow_I_caption
  2238. ;--------------------------------------
  2239. align 4
  2240. .2:
  2241.         mov     edi, [CURRENT_TASK]
  2242.         shl     edi, 5
  2243.         test    [edi + window_data + WDATA.fl_wstyle], WSTYLE_HASCAPTION
  2244.         jz      .exit
  2245.         mov     edx, [edi * 8 + SLOT_BASE + APPDATA.wnd_caption]
  2246.         or      edx, edx
  2247.         jz      .exit
  2248.  
  2249.         movzx   eax, [edi + window_data + WDATA.fl_wstyle]
  2250.         and     al, 0x0F
  2251.         cmp     al, 3
  2252.         je      .skinned
  2253.         cmp     al, 4
  2254.         je      .skinned
  2255.  
  2256.         jmp     .not_skinned
  2257. ;--------------------------------------
  2258. align 4
  2259. .skinned:
  2260.         mov     ebp, [edi + window_data + WDATA.box.left - 2]
  2261.         mov     bp, word[edi + window_data + WDATA.box.top]
  2262.         movzx   eax, word[edi + window_data + WDATA.box.width]
  2263.         sub     ax, [_skinmargins.left]
  2264.         sub     ax, [_skinmargins.right]
  2265.         push    edx
  2266.         cwde
  2267.         cdq
  2268.         mov     ebx, 6
  2269.         idiv    ebx
  2270.         pop     edx
  2271.         or      eax, eax
  2272.         js      .exit
  2273.  
  2274.         mov     esi, eax
  2275.         mov     ebx, dword[_skinmargins.left - 2]
  2276.         mov     bx, word[_skinh]
  2277.         sub     bx, [_skinmargins.bottom]
  2278.         sub     bx, [_skinmargins.top]
  2279.         sar     bx, 1
  2280.         adc     bx, 0
  2281.         add     bx, [_skinmargins.top]
  2282.         add     bx, -3
  2283.         add     ebx, ebp
  2284.         jmp     .dodraw
  2285. ;--------------------------------------
  2286. align 4
  2287. .not_skinned:
  2288.         cmp     al, 1
  2289.         je      .exit
  2290.  
  2291.         mov     ebp, [edi + window_data + WDATA.box.left - 2]
  2292.         mov     bp, word[edi + window_data + WDATA.box.top]
  2293.         movzx   eax, word[edi + window_data + WDATA.box.width]
  2294.         sub     eax, 16
  2295.         push    edx
  2296.         cwde
  2297.         cdq
  2298.         mov     ebx, 6
  2299.         idiv    ebx
  2300.         pop     edx
  2301.         or      eax, eax
  2302.         js      .exit
  2303.  
  2304.         mov     esi, eax
  2305.         mov     ebx, 0x00080007
  2306.         add     ebx, ebp
  2307. ;--------------------------------------
  2308. align 4
  2309. .dodraw:
  2310.         mov     ecx, [common_colours + 16]
  2311.         or      ecx, 0x80000000
  2312.         xor     edi, edi
  2313.         call    dtext_asciiz_esi
  2314. ;--------------------------------------
  2315. align 4
  2316. .exit:
  2317.         call    [draw_pointer]
  2318.         ret
  2319. ;------------------------------------------------------------------------------
  2320. align 4
  2321. ;------------------------------------------------------------------------------
  2322. window._.draw_negative_box: ;//////////////////////////////////////////////////
  2323. ;------------------------------------------------------------------------------
  2324. ;? Draw negative box
  2325. ;------------------------------------------------------------------------------
  2326. ;> edi = pointer to BOX struct
  2327. ;------------------------------------------------------------------------------
  2328.         push    eax ebx esi
  2329.         mov     esi, 0x01000000
  2330. ;--------------------------------------
  2331. align 4
  2332. .1:
  2333.         mov     eax, [edi + BOX.left - 2]
  2334.         mov     ax, word[edi + BOX.left]
  2335.         add     ax, word[edi + BOX.width]
  2336.         mov     ebx, [edi + BOX.top - 2]
  2337.         mov     bx, word[edi + BOX.top]
  2338.         add     bx, word[edi + BOX.height]
  2339.         call    draw_rectangle.forced
  2340.         pop     esi ebx eax
  2341.         ret
  2342. ;------------------------------------------------------------------------------
  2343. align 4
  2344. ;------------------------------------------------------------------------------
  2345. window._.end_moving__box: ;//////////////////////////////////////////////////
  2346. ;------------------------------------------------------------------------------
  2347. ;? Draw positive box
  2348. ;------------------------------------------------------------------------------
  2349. ;> edi = pointer to BOX struct
  2350. ;------------------------------------------------------------------------------
  2351.         push    eax ebx esi
  2352.         xor     esi, esi
  2353.         jmp     window._.draw_negative_box.1
  2354. ;------------------------------------------------------------------------------
  2355. align 4
  2356. ;------------------------------------------------------------------------------
  2357. window._.get_rect: ;/////////////////////////////////////////////////////
  2358. ;------------------------------------------------------------------------------
  2359. ;? <description>  void __fastcall get_window_rect(struct RECT* rc);
  2360. ;------------------------------------------------------------------------------
  2361. ;> ecx = pointer to RECT
  2362. ;------------------------------------------------------------------------------
  2363.         mov     eax, [TASK_BASE]
  2364.  
  2365.         mov     edx, [eax-twdw + WDATA.box.left]
  2366.         mov     [ecx+RECT.left], edx
  2367.  
  2368.         add     edx, [eax-twdw + WDATA.box.width]
  2369.         mov     [ecx+RECT.right], edx
  2370.  
  2371.         mov     edx, [eax-twdw + WDATA.box.top]
  2372.         mov     [ecx+RECT.top], edx
  2373.  
  2374.         add     edx, [eax-twdw + WDATA.box.height]
  2375.         mov     [ecx+RECT.bottom], edx
  2376.         ret
  2377. ;------------------------------------------------------------------------------
  2378.