Subversion Repositories Kolibri OS

Rev

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

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