Subversion Repositories Kolibri OS

Rev

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

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