Subversion Repositories Kolibri OS

Rev

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