Subversion Repositories Kolibri OS

Rev

Rev 3534 | Rev 3558 | 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: 3536 $
  10.  
  11. ;==============================================================================
  12. ;///// public functions ///////////////////////////////////////////////////////
  13. ;==============================================================================
  14.  
  15. window.BORDER_SIZE = 5
  16.  
  17. macro FuncTable name, table_name, [label]
  18. {
  19.   common
  20.     align 4
  21.     \label name#.#table_name dword
  22.   forward
  23.     dd name#.#label
  24.   common
  25.     name#.sizeof.#table_name = $ - name#.#table_name
  26. }
  27.  
  28. uglobal
  29.   common_colours rd 32
  30.   draw_limits    RECT
  31. endg
  32.  
  33. align 4
  34. ;------------------------------------------------------------------------------
  35. syscall_draw_window: ;///// system function 0 /////////////////////////////////
  36. ;------------------------------------------------------------------------------
  37. ;? <description>
  38. ;------------------------------------------------------------------------------
  39.         mov     eax, edx
  40.         shr     eax, 24
  41.         and     al, 0x0f
  42.         cmp     al, 5
  43.         jae     .exit
  44.  
  45.         push    eax
  46.         call    window._.sys_set_window
  47.         pop     eax
  48.  
  49.         or      al, al
  50.         jnz     @f
  51.  
  52.         ; type I - original style
  53.         call    drawwindow_I
  54.         jmp     window._.draw_window_caption.2
  55. ;--------------------------------------
  56. align 4
  57. @@:
  58.         dec     al
  59.         jnz     @f
  60.  
  61.         ; type II - only reserve area, no draw
  62. ;        call    sys_window_mouse
  63. ;        call    [draw_pointer]
  64.         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.         and     edx, 127
  177.         mov     edi, common_colours
  178.         mov     ecx, edx
  179.         rep movsb
  180.         mov     [windowtypechanged], ebx
  181.         ret
  182. ;------------------------------------------------------------------------------
  183. align 4
  184. syscall_display_settings.03:
  185.         mov     edi, ecx
  186.         and     edx, 127
  187.         mov     esi, common_colours
  188.         mov     ecx, edx
  189.         rep movsb
  190.         ret
  191. ;------------------------------------------------------------------------------
  192. align 4
  193. syscall_display_settings.04:
  194.         mov     eax, [_skinh]
  195.         mov     [esp + 32], eax
  196.         ret
  197. ;------------------------------------------------------------------------------
  198. align 4
  199. syscall_display_settings.05:
  200.         mov     eax, [screen_workarea.left - 2]
  201.         mov     ax, word[screen_workarea.right]
  202.         mov     [esp + 32], eax
  203.         mov     eax, [screen_workarea.top - 2]
  204.         mov     ax, word[screen_workarea.bottom]
  205.         mov     [esp + 20], eax
  206.         ret
  207. ;------------------------------------------------------------------------------
  208. align 4
  209. syscall_display_settings.06:
  210.         xor     esi, esi
  211.  
  212.         mov     edi, [Screen_Max_X]
  213.         mov     eax, ecx
  214.         movsx   ebx, ax
  215.         sar     eax, 16
  216.         cmp     eax, ebx
  217.         jge     .check_horizontal
  218.         inc     esi
  219.         or      eax, eax
  220.         jge     @f
  221.         xor     eax, eax
  222. ;--------------------------------------
  223. align 4
  224. @@:
  225.         mov     [screen_workarea.left], eax
  226.         cmp     ebx, edi
  227.         jle     @f
  228.         mov     ebx, edi
  229. ;--------------------------------------
  230. align 4
  231. @@:
  232.         mov     [screen_workarea.right], ebx
  233. ;--------------------------------------
  234. align 4
  235. .check_horizontal:
  236.         mov     edi, [Screen_Max_Y]
  237.         mov     eax, edx
  238.         movsx   ebx, ax
  239.         sar     eax, 16
  240.         cmp     eax, ebx
  241.         jge     .check_if_redraw_needed
  242.         inc     esi
  243.         or      eax, eax
  244.         jge     @f
  245.         xor     eax, eax
  246. ;--------------------------------------
  247. align 4
  248. @@:
  249.         mov     [screen_workarea.top], eax
  250.         cmp     ebx, edi
  251.         jle     @f
  252.         mov     ebx, edi
  253. ;--------------------------------------
  254. align 4
  255. @@:
  256.         mov     [screen_workarea.bottom], ebx
  257. ;--------------------------------------
  258. align 4
  259. .check_if_redraw_needed:
  260.         or      esi, esi
  261.         jz      .exit
  262.  
  263.         call    repos_windows
  264.         jmp     syscall_display_settings._.calculate_whole_screen
  265. ;--------------------------------------
  266. align 4
  267. .exit:
  268.         ret
  269. ;------------------------------------------------------------------------------
  270. align 4
  271. syscall_display_settings.07:
  272.         mov     eax, [_skinmargins + 0]
  273.         mov     [esp + 32], eax
  274.         mov     eax, [_skinmargins + 4]
  275.         mov     [esp + 20], eax
  276.         ret
  277. ;------------------------------------------------------------------------------
  278. align 4
  279. syscall_display_settings.08:
  280.         mov     ebx, ecx
  281.         call    read_skin_file
  282.         mov     [esp + 32], eax
  283.         test    eax, eax
  284.         jnz     .exit
  285.  
  286.         call    syscall_display_settings._.calculate_whole_screen
  287.         jmp     syscall_display_settings._.redraw_whole_screen
  288. ;--------------------------------------
  289. align 4
  290. .exit:
  291.         ret
  292. ;------------------------------------------------------------------------------
  293. align 4
  294. syscall_display_settings._.calculate_whole_screen:
  295.         xor     eax, eax
  296.         xor     ebx, ebx
  297.         mov     ecx, [Screen_Max_X]
  298.         mov     edx, [Screen_Max_Y]
  299.         jmp     calculatescreen
  300. ;------------------------------------------------------------------------------
  301. align 4
  302. syscall_display_settings._.redraw_whole_screen:
  303.         xor     eax, eax
  304.         mov     [draw_limits.left], eax
  305.         mov     [draw_limits.top], eax
  306.         mov     eax, [Screen_Max_X]
  307.         mov     [draw_limits.right], eax
  308.         mov     eax, [Screen_Max_Y]
  309.         mov     [draw_limits.bottom], eax
  310.         mov     eax, window_data
  311.         jmp     redrawscreen
  312. ;------------------------------------------------------------------------------
  313. align 4
  314. ;------------------------------------------------------------------------------
  315. syscall_set_window_shape: ;///// system function 50 ///////////////////////////
  316. ;------------------------------------------------------------------------------
  317. ;; Set window shape address:
  318. ;> ebx = 0
  319. ;> ecx = shape data address
  320. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  321. ;; Set window shape scale:
  322. ;> ebx = 1
  323. ;> ecx = scale power (resulting scale is 2^ebx)
  324. ;------------------------------------------------------------------------------
  325.         mov     edi, [current_slot]
  326.  
  327.         test    ebx, ebx
  328.         jne     .shape_scale
  329.         mov     [edi + APPDATA.wnd_shape], ecx
  330. ;--------------------------------------
  331. align 4
  332. .shape_scale:
  333.         dec     ebx
  334.         jnz     .exit
  335.         mov     [edi + APPDATA.wnd_shape_scale], ecx
  336. ;--------------------------------------
  337. align 4
  338. .exit:
  339.         ret
  340. ;------------------------------------------------------------------------------
  341. align 4
  342. ;------------------------------------------------------------------------------
  343. syscall_move_window: ;///// system function 67 ////////////////////////////////
  344. ;------------------------------------------------------------------------------
  345. ;? <description>
  346. ;------------------------------------------------------------------------------
  347.         mov     edi, [CURRENT_TASK]
  348.         shl     edi, 5
  349.         add     edi, window_data
  350.  
  351.         test    [edi + WDATA.fl_wdrawn], 1
  352.         jz      .exit
  353.  
  354.         test    [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED
  355.         jnz     .exit
  356.  
  357.         cmp     ebx, -1
  358.         jne     @f
  359.         mov     ebx, [edi + WDATA.box.left]
  360. ;--------------------------------------
  361. align 4
  362. @@:
  363.         cmp     ecx, -1
  364.         jne     @f
  365.         mov     ecx, [edi + WDATA.box.top]
  366. ;--------------------------------------
  367. align 4
  368. @@:
  369.         cmp     edx, -1
  370.         jne     @f
  371.         mov     edx, [edi + WDATA.box.width]
  372. ;--------------------------------------
  373. align 4
  374. @@:
  375.         cmp     esi, -1
  376.         jne     @f
  377.         mov     esi, [edi + WDATA.box.height]
  378. ;--------------------------------------
  379. align 4
  380. @@:
  381.         push    esi edx ecx ebx
  382.         mov     eax, esp
  383.         mov     bl, [edi + WDATA.fl_wstate]
  384. ;--------------------------------------
  385. align 4
  386. @@:
  387.         cmp     [REDRAW_BACKGROUND], byte 0
  388.         jz      @f
  389.         call    change_task
  390.         jmp     @b
  391. ;--------------------------------------
  392. align 4
  393. @@:
  394.         call    window._.set_window_box
  395.         add     esp, sizeof.BOX
  396.  
  397.         ; NOTE: do we really need this? to be reworked
  398. ;       mov     byte[DONT_DRAW_MOUSE], 0 ; mouse pointer
  399. ;       mov     byte[MOUSE_BACKGROUND], 0 ; no mouse under
  400. ;       mov     byte[MOUSE_DOWN], 0 ; react to mouse up/down
  401.  
  402.         ; NOTE: do we really need this? to be reworked
  403. ;       call    [draw_pointer]
  404. ;--------------------------------------
  405. align 4
  406. .exit:
  407.         ret
  408. ;------------------------------------------------------------------------------
  409. align 4
  410. ;------------------------------------------------------------------------------
  411. syscall_window_settings: ;///// system function 71 /////////////////////////////
  412. ;------------------------------------------------------------------------------
  413. ;? <description>
  414. ;------------------------------------------------------------------------------
  415.         dec     ebx     ; subfunction #1 - set window caption
  416.         jnz     .exit_fail
  417.  
  418.         ; NOTE: only window owner thread can set its caption,
  419.         ;       so there's no parameter for PID/TID
  420.  
  421.         mov     edi, [CURRENT_TASK]
  422.         shl     edi, 5
  423.  
  424.         mov     [edi * 8 + SLOT_BASE + APPDATA.wnd_caption], ecx
  425.         or      [edi + window_data + WDATA.fl_wstyle], WSTYLE_HASCAPTION
  426.  
  427.         call    window._.draw_window_caption
  428.  
  429.         xor     eax, eax ; eax = 0 (success)
  430.         ret
  431.  
  432. ;  .get_window_caption:
  433. ;        dec     eax     ; subfunction #2 - get window caption
  434. ;        jnz     .exit_fail
  435.  
  436.         ; not implemented yet
  437. ;--------------------------------------
  438. align 4
  439. .exit_fail:
  440.         xor     eax, eax
  441.         inc     eax     ; eax = 1 (fail)
  442.         ret
  443. ;------------------------------------------------------------------------------
  444. align 4
  445. ;------------------------------------------------------------------------------
  446. set_window_defaults: ;/////////////////////////////////////////////////////////
  447. ;------------------------------------------------------------------------------
  448. ;? <description>
  449. ;------------------------------------------------------------------------------
  450.         mov     byte [window_data + 0x20 + WDATA.cl_titlebar + 3], 1 ; desktop is not movable
  451.         push    eax ecx
  452.         xor     eax, eax
  453.         mov     ecx, WIN_STACK
  454. ;--------------------------------------
  455. align 4
  456. @@:
  457.         inc     eax
  458.         add     ecx, 2
  459.         ; process no
  460.         mov     [ecx + 0x000], ax
  461.         ; positions in stack
  462.         mov     [ecx + 0x400], ax
  463.         cmp     ecx, WIN_POS - 2
  464.         jne     @b
  465.         pop     ecx eax
  466.         ret
  467. ;------------------------------------------------------------------------------
  468. align 4
  469. ;------------------------------------------------------------------------------
  470. calculatescreen: ;/////////////////////////////////////////////////////////////
  471. ;------------------------------------------------------------------------------
  472. ;? Scan all windows from bottom to top, calling `setscreen` for each one
  473. ;? intersecting given screen area
  474. ;------------------------------------------------------------------------------
  475. ;> eax = left
  476. ;> ebx = top
  477. ;> ecx = right
  478. ;> edx = bottom
  479. ;------------------------------------------------------------------------------
  480.         push    esi
  481.         pushfd
  482.         cli
  483.  
  484.         mov     esi, 1
  485.         call    window._.set_screen
  486.  
  487.         push    ebp
  488.  
  489.         mov     ebp, [TASK_COUNT]
  490.         cmp     ebp, 1
  491.         jbe     .exit
  492.  
  493.         push    edx ecx ebx eax
  494. ;--------------------------------------
  495. align 4
  496. .next_window:
  497.         movzx   edi, word[WIN_POS + esi * 2]
  498.         shl     edi, 5
  499.  
  500.         cmp     [CURRENT_TASK + edi + TASKDATA.state], TSTATE_FREE
  501.         je      .skip_window
  502.  
  503.         add     edi, window_data
  504.         test    [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  505.         jnz     .skip_window
  506.  
  507.         mov     eax, [edi + WDATA.box.left]
  508.         cmp     eax, [esp + RECT.right]
  509.         jg      .skip_window
  510.         mov     ebx, [edi + WDATA.box.top]
  511.         cmp     ebx, [esp + RECT.bottom]
  512.         jg      .skip_window
  513.         mov     ecx, [edi + WDATA.box.width]
  514.         add     ecx, eax
  515.         cmp     ecx, [esp + RECT.left]
  516.         jl      .skip_window
  517.         mov     edx, [edi + WDATA.box.height]
  518.         add     edx, ebx
  519.         cmp     edx, [esp + RECT.top]
  520.         jl      .skip_window
  521.  
  522.         cmp     eax, [esp + RECT.left]
  523.         jae     @f
  524.         mov     eax, [esp + RECT.left]
  525. ;--------------------------------------
  526. align 4
  527. @@:
  528.         cmp     ebx, [esp + RECT.top]
  529.         jae     @f
  530.         mov     ebx, [esp + RECT.top]
  531. ;--------------------------------------
  532. align 4
  533. @@:
  534.         cmp     ecx, [esp + RECT.right]
  535.         jbe     @f
  536.         mov     ecx, [esp + RECT.right]
  537. ;--------------------------------------
  538. align 4
  539. @@:
  540.         cmp     edx, [esp + RECT.bottom]
  541.         jbe     @f
  542.         mov     edx, [esp + RECT.bottom]
  543. ;--------------------------------------
  544. align 4
  545. @@:
  546.         push    esi
  547.         movzx   esi, word[WIN_POS + esi * 2]
  548.         call    window._.set_screen
  549.         pop     esi
  550. ;--------------------------------------
  551. align 4
  552. .skip_window:
  553.         inc     esi
  554.         dec     ebp
  555.         jnz     .next_window
  556.  
  557.         pop     eax ebx ecx edx
  558. ;--------------------------------------
  559. align 4
  560. .exit:
  561.         pop     ebp
  562.         inc     [_display.mask_seqno]
  563.         popfd
  564.         pop     esi
  565.         ret
  566. ;------------------------------------------------------------------------------
  567. align 4
  568. ;------------------------------------------------------------------------------
  569. repos_windows: ;///////////////////////////////////////////////////////////////
  570. ;------------------------------------------------------------------------------
  571. ;? <description>
  572. ;------------------------------------------------------------------------------
  573.         mov     ecx, [TASK_COUNT]
  574.         mov     edi, window_data + sizeof.WDATA * 2
  575.         call    force_redraw_background
  576.         dec     ecx
  577.         jle     .exit
  578. ;--------------------------------------
  579. align 4
  580. .next_window:
  581.         mov     [edi + WDATA.fl_redraw], 1
  582.         test    [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED
  583.         jnz     .fix_maximized
  584.  
  585.         mov     eax, [edi + WDATA.box.left]
  586.         add     eax, [edi + WDATA.box.width]
  587.         mov     ebx, [Screen_Max_X]
  588.         cmp     eax, ebx
  589.         jle     .fix_vertical
  590.         mov     eax, [edi + WDATA.box.width]
  591.         sub     eax, ebx
  592.         jle     @f
  593.         mov     [edi + WDATA.box.width], ebx
  594. ;--------------------------------------
  595. align 4
  596. @@:
  597.         sub     ebx, [edi + WDATA.box.width]
  598.         mov     [edi + WDATA.box.left], ebx
  599. ;--------------------------------------
  600. align 4
  601. .fix_vertical:
  602.         mov     eax, [edi + WDATA.box.top]
  603.         add     eax, [edi + WDATA.box.height]
  604.         mov     ebx, [Screen_Max_Y]
  605.         cmp     eax, ebx
  606.         jle     .fix_client_box
  607.         mov     eax, [edi + WDATA.box.height]
  608.         sub     eax, ebx
  609.         jle     @f
  610.         mov     [edi + WDATA.box.height], ebx
  611. ;--------------------------------------
  612. align 4
  613. @@:
  614.         sub     ebx, [edi + WDATA.box.height]
  615.         mov     [edi + WDATA.box.top], ebx
  616. ;--------------------------------------
  617. align 4
  618. .fix_client_box:
  619.         call    window._.set_window_clientbox
  620.         add     edi, sizeof.WDATA
  621.         loop    .next_window
  622. ;--------------------------------------
  623. align 4
  624. .exit:
  625.         ret
  626. ;--------------------------------------
  627. align 4
  628. .fix_maximized:
  629.         mov     eax, [screen_workarea.left]
  630.         mov     [edi + WDATA.box.left], eax
  631.         sub     eax, [screen_workarea.right]
  632.         neg     eax
  633.         mov     [edi + WDATA.box.width], eax
  634.         mov     eax, [screen_workarea.top]
  635.         mov     [edi + WDATA.box.top], eax
  636.         test    [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP
  637.         jnz     .fix_client_box
  638.         sub     eax, [screen_workarea.bottom]
  639.         neg     eax
  640.         mov     [edi + WDATA.box.height], eax
  641.         jmp     .fix_client_box
  642. ;------------------------------------------------------------------------------
  643. ;align 4
  644. ;------------------------------------------------------------------------------
  645. ;sys_window_mouse: ;////////////////////////////////////////////////////////////
  646. ;------------------------------------------------------------------------------
  647. ;? <description>
  648. ;------------------------------------------------------------------------------
  649.         ; NOTE: commented out since doesn't provide necessary functionality
  650.         ;       anyway, to be reworked
  651. ;       push    eax
  652. ;
  653. ;       mov     eax, [timer_ticks]
  654. ;       cmp     [new_window_starting], eax
  655. ;       jb      .exit
  656. ;
  657. ;       mov     byte[MOUSE_BACKGROUND], 0
  658. ;       mov     byte[DONT_DRAW_MOUSE], 0
  659. ;
  660. ;       mov     [new_window_starting], eax
  661. ;
  662. ; .exit:
  663. ;       pop     eax
  664. ;        ret
  665. ;------------------------------------------------------------------------------
  666. align 4
  667. ;------------------------------------------------------------------------------
  668. draw_rectangle: ;//////////////////////////////////////////////////////////////
  669. ;------------------------------------------------------------------------------
  670. ;> eax = pack[16(left), 16(right)]
  671. ;> ebx = pack[16(top), 16(bottom)]
  672. ;> esi = color
  673. ;       ?? RR GG BB    ; 0x01000000 negation
  674. ;                      ; 0x02000000 used for draw_rectangle without top line
  675. ;                      ;           for example drawwindow_III and drawwindow_IV
  676. ;------------------------------------------------------------------------------
  677.         push    eax ebx ecx edi
  678.  
  679.         xor     edi, edi
  680. ;--------------------------------------
  681. align 4
  682. .flags_set:
  683.         push    ebx
  684.  
  685.         ; set line color
  686.         mov     ecx, esi
  687.         ; draw top border
  688.         rol     ebx, 16
  689.         push    ebx
  690.         rol     ebx, 16
  691.         pop     bx
  692.         test    ecx, 1 shl 25
  693.         jnz     @f
  694.         sub     ecx, 1 shl 25
  695. ;        call    [draw_line]
  696.         call    __sys_draw_line
  697. ;--------------------------------------
  698. align 4
  699. @@:
  700.         ; draw bottom border
  701.         mov     ebx, [esp - 2]
  702.         pop     bx
  703. ;        call    [draw_line]
  704.         call    __sys_draw_line
  705.  
  706.         pop     ebx
  707.         add     ebx, 1 * 65536 - 1
  708.  
  709.         ; draw left border
  710.         rol     eax, 16
  711.         push    eax
  712.         rol     eax, 16
  713.         pop     ax
  714. ;        call    [draw_line]
  715.         call    __sys_draw_line
  716.  
  717.         ; draw right border
  718.         mov     eax, [esp - 2]
  719.         pop     ax
  720. ;        call    [draw_line]
  721.         call    __sys_draw_line
  722.  
  723.         pop     edi ecx ebx eax
  724.         ret
  725. ;--------------------------------------
  726. align 4
  727. .forced:
  728.         push    eax ebx ecx edi
  729.         xor     edi, edi
  730.         inc     edi
  731.         jmp     .flags_set
  732. ;------------------------------------------------------------------------------
  733. align 4
  734. ;------------------------------------------------------------------------------
  735. drawwindow_I_caption: ;////////////////////////////////////////////////////////
  736. ;------------------------------------------------------------------------------
  737. ;? <description>
  738. ;------------------------------------------------------------------------------
  739.         push    [edx + WDATA.cl_titlebar]
  740.         mov     esi, edx
  741.  
  742.         mov     edx, [esi + WDATA.box.top]
  743.         mov     eax, edx
  744.         lea     ebx, [edx + 21]
  745.         inc     edx
  746.         add     eax, [esi + WDATA.box.height]
  747.  
  748.         cmp     ebx, eax
  749.         jbe     @f
  750.         mov     ebx, eax
  751. ;--------------------------------------
  752. align 4
  753. @@:
  754.         push    ebx
  755.  
  756.         xor     edi, edi
  757. ;--------------------------------------
  758. align 4
  759. .next_line:
  760.         mov     ebx, edx
  761.         shl     ebx, 16
  762.         add     ebx, edx
  763.         mov     eax, [esi + WDATA.box.left]
  764.         inc     eax
  765.         shl     eax, 16
  766.         add     eax, [esi + WDATA.box.left]
  767.         add     eax, [esi + WDATA.box.width]
  768.         dec     eax
  769.         mov     ecx, [esi + WDATA.cl_titlebar]
  770.         test    ecx, 0x80000000
  771.         jz      @f
  772.         sub     ecx, 0x00040404
  773.         mov     [esi + WDATA.cl_titlebar], ecx
  774. ;--------------------------------------
  775. align 4
  776. @@:
  777.         and     ecx, 0x00ffffff
  778. ;        call    [draw_line]
  779.         call    __sys_draw_line
  780.         inc     edx
  781.         cmp     edx, [esp]
  782.         jb      .next_line
  783.  
  784.         add     esp, 4
  785.         pop     [esi + WDATA.cl_titlebar]
  786.         ret
  787. ;------------------------------------------------------------------------------
  788. align 4
  789. ;------------------------------------------------------------------------------
  790. drawwindow_I: ;////////////////////////////////////////////////////////////////
  791. ;------------------------------------------------------------------------------
  792. ;? <description>
  793. ;------------------------------------------------------------------------------
  794.         pushad
  795.  
  796.         ; window border
  797.  
  798.         mov     eax, [edx + WDATA.box.left - 2]
  799.         mov     ax, word[edx + WDATA.box.left]
  800.         add     ax, word[edx + WDATA.box.width]
  801.         mov     ebx, [edx + WDATA.box.top - 2]
  802.         mov     bx, word[edx + WDATA.box.top]
  803.         add     bx, word[edx + WDATA.box.height]
  804.  
  805.         mov     esi, [edx + WDATA.cl_frames]
  806.         call    draw_rectangle
  807.  
  808.         ; window caption
  809.  
  810.         call    drawwindow_I_caption
  811.  
  812.         ; window client area
  813.  
  814.         ; do we need to draw it?
  815.         mov     edi, [esi + WDATA.cl_workarea]
  816.         test    edi, 0x40000000
  817.         jnz     .exit
  818.  
  819.         ; does client area have a positive size on screen?
  820.         mov     edx, [esi + WDATA.box.top]
  821.         add     edx, 21 + 5
  822.         mov     ebx, [esi + WDATA.box.top]
  823.         add     ebx, [esi + WDATA.box.height]
  824.         cmp     edx, ebx
  825.         jg      .exit
  826.  
  827.         ; okay, let's draw it
  828.         mov     eax, 1
  829.         mov     ebx, 21
  830.         mov     ecx, [esi + WDATA.box.width]
  831.         mov     edx, [esi + WDATA.box.height]
  832. ;        call    [drawbar]
  833.         call    vesa20_drawbar
  834. ;--------------------------------------
  835. align 4
  836. .exit:
  837.         popad
  838.         ret
  839. ;------------------------------------------------------------------------------
  840. align 4
  841. ;------------------------------------------------------------------------------
  842. drawwindow_III_caption: ;/////////////////////////////////////////////////////
  843. ;------------------------------------------------------------------------------
  844. ;? <description>
  845. ;------------------------------------------------------------------------------
  846.         mov     ecx, [edx + WDATA.cl_titlebar]
  847.         push    ecx
  848.         mov     esi, edx
  849.         mov     edx, [esi + WDATA.box.top]
  850.         add     edx, 4
  851.         mov     ebx, [esi + WDATA.box.top]
  852.         add     ebx, 20
  853.         mov     eax, [esi + WDATA.box.top]
  854.         add     eax, [esi + WDATA.box.height]
  855.  
  856.         cmp     ebx, eax
  857.         jb      @f
  858.         mov     ebx, eax
  859. ;--------------------------------------
  860. align 4
  861. @@:
  862.         push    ebx
  863.  
  864.         xor     edi, edi
  865. ;--------------------------------------
  866. align 4
  867. .next_line:
  868.         mov     ebx, edx
  869.         shl     ebx, 16
  870.         add     ebx, edx
  871.         mov     eax, [esi + WDATA.box.left]
  872.         shl     eax, 16
  873.         add     eax, [esi + WDATA.box.left]
  874.         add     eax, [esi + WDATA.box.width]
  875.         add     eax, 4 * 65536 - 4
  876.         mov     ecx, [esi + WDATA.cl_titlebar]
  877.         test    ecx, 0x40000000
  878.         jz      @f
  879.         add     ecx, 0x00040404
  880. ;--------------------------------------
  881. align 4
  882. @@:
  883.         test    ecx, 0x80000000
  884.         jz      @f
  885.         sub     ecx, 0x00040404
  886. ;--------------------------------------
  887. align 4
  888. @@:
  889.         mov     [esi + WDATA.cl_titlebar], ecx
  890.         and     ecx, 0x00ffffff
  891. ;        call    [draw_line]
  892.         call    __sys_draw_line
  893.         inc     edx
  894.         cmp     edx, [esp]
  895.         jb      .next_line
  896.  
  897.         add     esp, 4
  898.         pop     [esi + WDATA.cl_titlebar]
  899.         ret
  900. ;------------------------------------------------------------------------------
  901. align 4
  902. ;------------------------------------------------------------------------------
  903. drawwindow_III: ;//////////////////////////////////////////////////////////////
  904. ;------------------------------------------------------------------------------
  905. ;? <description>
  906. ;------------------------------------------------------------------------------
  907.         pushad
  908.  
  909.         ; window border
  910.  
  911.         mov     eax, [edx + WDATA.box.left - 2]
  912.         mov     ax, word[edx + WDATA.box.left]
  913.         add     ax, word[edx + WDATA.box.width]
  914.         mov     ebx, [edx + WDATA.box.top - 2]
  915.         mov     bx, word[edx + WDATA.box.top]
  916.         add     bx, word[edx + WDATA.box.height]
  917.  
  918.         mov     esi, [edx + WDATA.cl_frames]
  919.         shr     esi, 1
  920.         and     esi, 0x007f7f7f
  921.         call    draw_rectangle
  922.  
  923.         push    esi
  924.         mov     ecx, 3
  925.         mov     esi, [edx + WDATA.cl_frames]
  926. ;--------------------------------------
  927. align 4
  928. .next_frame:
  929.         add     eax, 1 * 65536 - 1
  930.         add     ebx, 1 * 65536 - 1
  931.         call    draw_rectangle
  932.         dec     ecx
  933.         jnz     .next_frame
  934.  
  935.         pop     esi
  936.         add     eax, 1 * 65536 - 1
  937.         add     ebx, 1 * 65536 - 1
  938.         call    draw_rectangle
  939.  
  940.         ; window caption
  941.  
  942.         call    drawwindow_III_caption
  943.  
  944.         ; window client area
  945.  
  946.         ; do we need to draw it?
  947.         mov     edi, [esi + WDATA.cl_workarea]
  948.         test    edi, 0x40000000
  949.         jnz     .exit
  950.  
  951.         ; does client area have a positive size on screen?
  952.         mov     edx, [esi + WDATA.box.top]
  953.         add     edx, 21 + 5
  954.         mov     ebx, [esi + WDATA.box.top]
  955.         add     ebx, [esi + WDATA.box.height]
  956.         cmp     edx, ebx
  957.         jg      .exit
  958.  
  959.         ; okay, let's draw it
  960.         mov     eax, 5
  961.         mov     ebx, 20
  962.         mov     ecx, [esi + WDATA.box.width]
  963.         mov     edx, [esi + WDATA.box.height]
  964.         sub     ecx, 4
  965.         sub     edx, 4
  966. ;        call    [drawbar]
  967.         call    vesa20_drawbar
  968. ;--------------------------------------
  969. align 4
  970. .exit:
  971.         popad
  972.         ret
  973. ;------------------------------------------------------------------------------
  974. align 4
  975. ;------------------------------------------------------------------------------
  976. waredraw: ;////////////////////////////////////////////////////////////////////
  977. ;------------------------------------------------------------------------------
  978. ;? Activate window, redrawing if necessary
  979. ;------------------------------------------------------------------------------
  980.         push    -1
  981.         mov     eax, [TASK_COUNT]
  982.         lea     eax, [WIN_POS + eax * 2]
  983.         cmp     eax, esi
  984.         pop     eax
  985.         je      .exit
  986.  
  987.         ; is it overlapped by another window now?
  988.         push    ecx
  989.         call    window._.check_window_draw
  990.         test    ecx, ecx
  991.         pop     ecx
  992.         jz      .do_not_draw
  993.  
  994.         ; yes it is, activate and update screen buffer
  995.         mov     byte[MOUSE_DOWN], 1
  996.         call    window._.window_activate
  997.  
  998.         pushad
  999.         mov     edi, [TASK_COUNT]
  1000.         movzx   esi, word[WIN_POS + edi * 2]
  1001.         shl     esi, 5
  1002.         add     esi, window_data
  1003.  
  1004.         mov     eax, [esi + WDATA.box.left]
  1005.         mov     ebx, [esi + WDATA.box.top]
  1006.         mov     ecx, [esi + WDATA.box.width]
  1007.         mov     edx, [esi + WDATA.box.height]
  1008.  
  1009.         add     ecx, eax
  1010.         add     edx, ebx
  1011.  
  1012.         mov     edi, [TASK_COUNT]
  1013.         movzx   esi, word[WIN_POS + edi * 2]
  1014.         call    window._.set_screen
  1015.         inc     [_display.mask_seqno]
  1016.         popad
  1017.  
  1018.         ; tell application to redraw itself
  1019.         mov     [edi + WDATA.fl_redraw], 1
  1020.         xor     eax, eax
  1021.         jmp     .exit
  1022. ;--------------------------------------
  1023. align 4
  1024. .do_not_draw:
  1025.         ; no it's not, just activate the window
  1026.         call    window._.window_activate
  1027.         xor     eax, eax
  1028.         mov     byte[MOUSE_BACKGROUND], al
  1029.         mov     byte[DONT_DRAW_MOUSE], al
  1030.         dec     eax
  1031. ;--------------------------------------
  1032. align 4
  1033. .exit:
  1034.         mov     byte[MOUSE_DOWN], 0
  1035.         inc     eax
  1036.         ret
  1037. ;------------------------------------------------------------------------------
  1038. align 4
  1039. ;------------------------------------------------------------------------------
  1040. minimize_all_window:
  1041.         push    ebx ecx edx esi edi
  1042.         pushfd
  1043.         cli
  1044.         xor     edx, edx
  1045.         mov     eax, 2  ; we do not minimize the kernel thread N1
  1046.         mov     ebx, [TASK_COUNT]
  1047. ;--------------------------------------
  1048. align 4
  1049. .loop:
  1050.         movzx   edi, word[WIN_POS + eax * 2]
  1051.         shl     edi, 5
  1052. ; it is a unused slot?
  1053.         cmp     dword [edi+CURRENT_TASK+TASKDATA.state], 9
  1054.         je      @f
  1055. ; it is a hidden thread?
  1056.         lea     esi, [edi*8+SLOT_BASE+APPDATA.app_name]
  1057.         cmp     [esi], byte '@'
  1058.         je      @f
  1059. ; is it already minimized?
  1060.         test    [edi + window_data+WDATA.fl_wstate], WSTATE_MINIMIZED
  1061.         jnz     @f
  1062. ; no it's not, let's do that
  1063.         or      [edi + window_data+WDATA.fl_wstate], WSTATE_MINIMIZED
  1064.         inc     edx
  1065. ;--------------------------------------
  1066. align 4
  1067. @@:
  1068.         inc     eax
  1069.         cmp     eax, ebx
  1070.         jbe     .loop
  1071. ; If nothing has changed
  1072.         test    edx, edx
  1073.         jz      @f
  1074.  
  1075.         push    edx
  1076.         call    syscall_display_settings._.calculate_whole_screen
  1077.         call    syscall_display_settings._.redraw_whole_screen
  1078.         pop     edx
  1079. ;--------------------------------------
  1080. align 4
  1081. @@:
  1082.         mov     eax, edx
  1083.         popfd
  1084.         pop     edi esi edx ecx ebx
  1085.         ret
  1086. ;------------------------------------------------------------------------------
  1087. align 4
  1088. ;------------------------------------------------------------------------------
  1089. minimize_window: ;/////////////////////////////////////////////////////////////
  1090. ;------------------------------------------------------------------------------
  1091. ;> eax = window number on screen
  1092. ;------------------------------------------------------------------------------
  1093. ;# corrupts [dl*]
  1094. ;------------------------------------------------------------------------------
  1095.         push    edi
  1096.         pushfd
  1097.         cli
  1098.  
  1099.         ; is it already minimized?
  1100.         movzx   edi, word[WIN_POS + eax * 2]
  1101.         shl     edi, 5
  1102.         add     edi, window_data
  1103.         test    [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  1104.         jnz     .exit
  1105.  
  1106.         push    eax ebx ecx edx esi
  1107.  
  1108.         ; no it's not, let's do that
  1109.         or      [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  1110. ; If the window width is 0, then the action is not needed.
  1111.         cmp     [edi + WDATA.box.width], dword 0
  1112.         je      @f
  1113. ; If the window height is 0, then the action is not needed.
  1114.         cmp     [edi + WDATA.box.height], dword 0
  1115.         je      @f
  1116.  
  1117.         mov     eax, [edi + WDATA.box.left]
  1118.         mov     [draw_limits.left], eax
  1119.         mov     ecx, eax
  1120.         add     ecx, [edi + WDATA.box.width]
  1121.         mov     [draw_limits.right], ecx
  1122.         mov     ebx, [edi + WDATA.box.top]
  1123.         mov     [draw_limits.top], ebx
  1124.         mov     edx, ebx
  1125.         add     edx, [edi + WDATA.box.height]
  1126.         mov     [draw_limits.bottom], edx
  1127.  
  1128. ;        DEBUGF  1, "K : minimize_window\n"
  1129. ;        DEBUGF  1, "K : dl_left %x\n",[draw_limits.left]
  1130. ;        DEBUGF  1, "K : dl_right %x\n",[draw_limits.right]
  1131. ;        DEBUGF  1, "K : dl_top %x\n",[draw_limits.top]
  1132. ;        DEBUGF  1, "K : dl_bottom %x\n",[draw_limits.bottom]
  1133.         call    calculatescreen
  1134. ;        xor     esi, esi
  1135. ;        xor     eax, eax
  1136.         mov     eax, edi
  1137.         call    redrawscreen
  1138. ;--------------------------------------
  1139. align 4
  1140. @@:
  1141.         pop     esi edx ecx ebx eax
  1142. ;--------------------------------------
  1143. align 4
  1144. .exit:
  1145.         popfd
  1146.         pop     edi
  1147.         ret
  1148. ;------------------------------------------------------------------------------
  1149. align 4
  1150. ;------------------------------------------------------------------------------
  1151. restore_minimized_window: ;////////////////////////////////////////////////////
  1152. ;------------------------------------------------------------------------------
  1153. ;> eax = window number on screen
  1154. ;------------------------------------------------------------------------------
  1155. ;# corrupts [dl*]
  1156. ;------------------------------------------------------------------------------
  1157.         pushad
  1158.         pushfd
  1159.         cli
  1160.  
  1161.         ; is it already restored?
  1162.         movzx   esi, word[WIN_POS + eax * 2]
  1163.         mov     edi, esi
  1164.         shl     edi, 5
  1165.         add     edi, window_data
  1166.         test    [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  1167.         jz      .exit
  1168.  
  1169.         ; no it's not, let's do that
  1170.         mov     [edi + WDATA.fl_redraw], 1
  1171.         and     [edi + WDATA.fl_wstate], not WSTATE_MINIMIZED
  1172.         mov     ebp, window._.set_screen
  1173.         cmp     eax, [TASK_COUNT]
  1174.         jz      @f
  1175.         mov     ebp, calculatescreen
  1176. ;--------------------------------------
  1177. align 4
  1178. @@:
  1179.         mov     eax, [edi + WDATA.box.left]
  1180.         mov     ebx, [edi + WDATA.box.top]
  1181.         mov     ecx, [edi + WDATA.box.width]
  1182.         mov     edx, [edi + WDATA.box.height]
  1183.         add     ecx, eax
  1184.         add     edx, ebx
  1185.         call    ebp
  1186.         inc     [_display.mask_seqno]
  1187.         mov     byte[MOUSE_BACKGROUND], 0
  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     edi, [Screen_Max_X]
  1889. ;        inc     edi
  1890. ;        mov     esi, edi
  1891.         mov     esi, [Screen_Max_X]
  1892.         inc     esi
  1893. ;        imul    edi, ebx
  1894.         mov     edi, [d_width_calc_area + ebx*4]
  1895.  
  1896.         add     edi, eax
  1897.         add     edi, [_WinMapAddress]
  1898.         pop     eax
  1899.         mov     ah, al
  1900.         push    ax
  1901.         shl     eax, 16
  1902.         pop     ax
  1903. ;--------------------------------------
  1904. align 4
  1905. .next_line:
  1906.         push    ecx
  1907.         shr     ecx, 2
  1908.         rep stosd
  1909.         mov     ecx, [esp]
  1910.         and     ecx, 3
  1911.         rep stosb
  1912.         pop     ecx
  1913.         add     edi, esi
  1914.         sub     edi, ecx
  1915.         dec     edx
  1916.         jnz     .next_line
  1917.  
  1918.         jmp     .exit
  1919. ;--------------------------------------
  1920. align 4
  1921. .shaped_window:
  1922.         ;  for (y=0; y <= x_size; y++)
  1923.         ;      for (x=0; x <= x_size; x++)
  1924.         ;          if (shape[coord(x,y,scale)]==1)
  1925.         ;             set_pixel(x, y, process_number);
  1926.  
  1927.         sub     ecx, eax
  1928.         sub     edx, ebx
  1929.         inc     ecx
  1930.         inc     edx
  1931.  
  1932.         push    [edi + APPDATA.wnd_shape_scale]  ; push scale first -> for loop
  1933.  
  1934.         ; get WinMap start  -> ebp
  1935.         push    eax
  1936. ;        mov     eax, [Screen_Max_X] ; screen_sx
  1937. ;        inc     eax
  1938. ;        imul    eax, ebx
  1939.         mov     eax, [d_width_calc_area + ebx*4]
  1940.  
  1941.         add     eax, [esp]
  1942.         add     eax, [_WinMapAddress]
  1943.         mov     ebp, eax
  1944.  
  1945.         mov     edi, [edi + APPDATA.wnd_shape]
  1946.         pop     eax
  1947.  
  1948.         ; eax = x_start
  1949.         ; ebx = y_start
  1950.         ; ecx = x_size
  1951.         ; edx = y_size
  1952.         ; esi = process_number
  1953.         ; edi = &shape
  1954.         ;       [scale]
  1955.         push    edx ecx ; for loop - x,y size
  1956.  
  1957.         mov     ecx, esi
  1958.         shl     ecx, 5
  1959.         mov     edx, [window_data + ecx + WDATA.box.top]
  1960.         push    [window_data + ecx + WDATA.box.width]           ; for loop - width
  1961.         mov     ecx, [window_data + ecx + WDATA.box.left]
  1962.         sub     ebx, edx
  1963.         sub     eax, ecx
  1964.         push    ebx eax ; for loop - x,y
  1965.  
  1966.         add     [ff_xsz], eax
  1967.         add     [ff_ysz], ebx
  1968.  
  1969.         mov     ebx, [ff_y]
  1970. ;--------------------------------------
  1971. align 4
  1972. .ff_new_y:
  1973.         mov     edx, [ff_x]
  1974. ;--------------------------------------
  1975. align 4
  1976. .ff_new_x:
  1977.         ; -- body --
  1978.         mov     ecx, [ff_scale]
  1979.         mov     eax, [ff_width]
  1980.         inc     eax
  1981.         shr     eax, cl
  1982.         push    ebx edx
  1983.         shr     ebx, cl
  1984.         shr     edx, cl
  1985.         imul    eax, ebx
  1986.         add     eax, edx
  1987.         pop     edx ebx
  1988.         add     eax, edi
  1989.         call    .read_byte
  1990.         test    al, al
  1991.         jz      @f
  1992.         mov     eax, esi
  1993.         mov     [ebp], al
  1994.         ; -- end body --
  1995. ;--------------------------------------
  1996. align 4
  1997. @@:
  1998.         inc     ebp
  1999.         inc     edx
  2000.         cmp     edx, [ff_xsz]
  2001.         jb      .ff_new_x
  2002.  
  2003.         sub     ebp, [ff_xsz]
  2004.         add     ebp, [ff_x]
  2005.         add     ebp, [Screen_Max_X]  ; screen.x
  2006.         inc     ebp
  2007.         inc     ebx
  2008.         cmp     ebx, [ff_ysz]
  2009.         jb      .ff_new_y
  2010.  
  2011.         add     esp, 24
  2012. ;--------------------------------------
  2013. align 4
  2014. .exit:
  2015.         popad
  2016.         inc     [_display.mask_seqno]
  2017.         ret
  2018. ;--------------------------------------
  2019. align 4
  2020. .read_byte:
  2021.         ; eax - address
  2022.         ; esi - slot
  2023.         push    eax ecx edx esi
  2024.         xchg    eax, esi
  2025.         lea     ecx, [esp + 12]
  2026.         mov     edx, 1
  2027.         call    read_process_memory
  2028.         pop     esi edx ecx eax
  2029.         ret
  2030. ;------------------------------------------------------------------------------
  2031. align 4
  2032. ;------------------------------------------------------------------------------
  2033. window._.window_activate: ;////////////////////////////////////////////////////
  2034. ;------------------------------------------------------------------------------
  2035. ;? Activate window
  2036. ;------------------------------------------------------------------------------
  2037. ;> esi = pointer to WIN_POS+ window data
  2038. ;------------------------------------------------------------------------------
  2039.         push    eax ebx
  2040.  
  2041.         ; if type of current active window is 3 or 4, it must be redrawn
  2042.         mov     ebx, [TASK_COUNT]
  2043.        
  2044. ;       DEBUGF  1, "K : TASK_COUNT (0x%x)\n", ebx
  2045.        
  2046.         movzx   ebx, word[WIN_POS + ebx * 2]
  2047.         shl     ebx, 5
  2048.         add     eax, window_data
  2049.         mov     al, [window_data + ebx + WDATA.fl_wstyle]
  2050.         and     al, 0x0f
  2051.         cmp     al, 0x03
  2052.         je      .set_window_redraw_flag
  2053.         cmp     al, 0x04
  2054.         jne     .move_others_down
  2055. ;--------------------------------------
  2056. align 4
  2057. .set_window_redraw_flag:
  2058.         mov     [window_data + ebx + WDATA.fl_redraw], 1
  2059. ;--------------------------------------
  2060. align 4
  2061. .move_others_down:
  2062.         ; ax <- process no
  2063.         movzx   ebx, word[esi]
  2064.         ; ax <- position in window stack
  2065.         movzx   ebx, word[WIN_STACK + ebx * 2]
  2066.  
  2067.         ; drop others
  2068.         xor     eax, eax
  2069. ;--------------------------------------
  2070. align 4
  2071. .next_stack_window:
  2072.         cmp     eax, [TASK_COUNT]
  2073.         jae     .move_self_up
  2074.         inc     eax
  2075.        
  2076. ;       push    ebx
  2077. ;       xor     ebx,ebx
  2078. ;       mov     bx,[WIN_STACK + eax * 2]
  2079. ;       DEBUGF  1, "K : DEC WIN_STACK (0x%x)\n",ebx
  2080. ;       pop     ebx
  2081.        
  2082.         cmp     [WIN_STACK + eax * 2], bx
  2083.         jbe     .next_stack_window
  2084.         dec     word[WIN_STACK + eax * 2]
  2085.         jmp     .next_stack_window
  2086. ;--------------------------------------
  2087. align 4
  2088. .move_self_up:
  2089.         movzx   ebx, word[esi]
  2090.         ; number of processes
  2091.         mov     ax, [TASK_COUNT]
  2092.         ; this is the last (and the upper)
  2093.         mov     [WIN_STACK + ebx * 2], ax
  2094.  
  2095.         ; update on screen - window stack
  2096.         xor     eax, eax
  2097. ;--------------------------------------
  2098. align 4
  2099. .next_window_pos:
  2100.         cmp     eax, [TASK_COUNT]
  2101.         jae     .reset_vars
  2102.         inc     eax
  2103.         movzx   ebx, word[WIN_STACK + eax * 2]
  2104.         mov     [WIN_POS + ebx * 2], ax
  2105.         jmp     .next_window_pos
  2106. ;--------------------------------------
  2107. align 4
  2108. .reset_vars:
  2109.         mov     byte[KEY_COUNT], 0
  2110.         mov     byte[BTN_COUNT], 0
  2111.         mov     word[MOUSE_SCROLL_H], 0
  2112.         mov     word[MOUSE_SCROLL_V], 0
  2113.  
  2114.         pop     ebx eax
  2115.         ret
  2116. ;------------------------------------------------------------------------------
  2117. window._.window_deactivate: ;////////////////////////////////////////////////////
  2118. ;------------------------------------------------------------------------------
  2119. ;? Deactivate window
  2120. ;------------------------------------------------------------------------------
  2121. ;> esi = pointer to WIN_POS+ window data
  2122. ;------------------------------------------------------------------------------
  2123.         push    eax ebx
  2124. ;--------------------------------------
  2125. align 4
  2126. .move_others_up:
  2127.         ; ax <- process no
  2128.         movzx   ebx, word[esi]
  2129.         ; ax <- position in window stack
  2130.         movzx   ebx, word[WIN_STACK + ebx * 2]
  2131.         ; up others
  2132.         xor     eax, eax
  2133. ;--------------------------------------
  2134. align 4
  2135. .next_stack_window:
  2136.         cmp     eax, [TASK_COUNT]
  2137.         jae     .move_self_down
  2138.         inc     eax
  2139.         cmp     [WIN_STACK + eax * 2], bx
  2140.         jae     .next_stack_window
  2141.         inc     word[WIN_STACK + eax * 2]
  2142.         jmp     .next_stack_window
  2143. ;--------------------------------------
  2144. align 4
  2145. .move_self_down:
  2146.         movzx   ebx, word[esi]
  2147.         ; this is the last (and the low)
  2148.         mov     [WIN_STACK + ebx * 2], word 1
  2149.         ; update on screen - window stack
  2150.         xor     eax, eax
  2151. ;--------------------------------------
  2152. align 4
  2153. .next_window_pos:
  2154.         cmp     eax, [TASK_COUNT]
  2155.         jae     .reset_vars
  2156.         inc     eax
  2157.         movzx   ebx, word[WIN_STACK + eax * 2]
  2158.         mov     [WIN_POS + ebx * 2], ax
  2159.         jmp     .next_window_pos
  2160. ;--------------------------------------
  2161. align 4
  2162. .reset_vars:
  2163.         mov     byte[KEY_COUNT], 0
  2164.         mov     byte[BTN_COUNT], 0
  2165.         mov     word[MOUSE_SCROLL_H], 0
  2166.         mov     word[MOUSE_SCROLL_V], 0
  2167.         pop     ebx eax
  2168.         ret
  2169. ;------------------------------------------------------------------------------
  2170. align 4
  2171. ;------------------------------------------------------------------------------
  2172. window._.check_window_draw: ;//////////////////////////////////////////////////
  2173. ;------------------------------------------------------------------------------
  2174. ;? Check if window is necessary to draw
  2175. ;------------------------------------------------------------------------------
  2176. ;> edi = pointer to WDATA
  2177. ;------------------------------------------------------------------------------
  2178.         mov     cl, [edi + WDATA.fl_wstyle]
  2179.         and     cl, 0x0f
  2180.         cmp     cl, 3
  2181.         je      .exit.redraw      ; window type 3
  2182.         cmp     cl, 4
  2183.         je      .exit.redraw      ; window type 4
  2184.  
  2185.         push    eax ebx edx esi
  2186.  
  2187.         mov     eax, edi
  2188.         sub     eax, window_data
  2189.         shr     eax, 5
  2190.  
  2191.         movzx   eax, word[WIN_STACK + eax * 2]  ; get value of the curr process
  2192.         lea     esi, [WIN_POS + eax * 2]        ; get address of this process at 0xC400
  2193. ;--------------------------------------
  2194. align 4
  2195. .next_window:
  2196.         add     esi, 2
  2197.  
  2198.         mov     eax, [TASK_COUNT]
  2199.         lea     eax, word[WIN_POS + eax * 2] ; number of the upper window
  2200.  
  2201.         cmp     esi, eax
  2202.         ja      .exit.no_redraw
  2203.  
  2204.         movzx   edx, word[esi]
  2205.         shl     edx, 5
  2206.         cmp     [CURRENT_TASK + edx + TASKDATA.state], TSTATE_FREE
  2207.         je      .next_window
  2208.  
  2209.         mov     eax, [edi + WDATA.box.top]
  2210.         mov     ebx, [edi + WDATA.box.height]
  2211.         add     ebx, eax
  2212.  
  2213.         mov     ecx, [window_data + edx + WDATA.box.top]
  2214.         cmp     ecx, ebx
  2215.         jge     .next_window
  2216.         add     ecx, [window_data + edx + WDATA.box.height]
  2217.         cmp     eax, ecx
  2218.         jge     .next_window
  2219.  
  2220.         mov     eax, [edi + WDATA.box.left]
  2221.         mov     ebx, [edi + WDATA.box.width]
  2222.         add     ebx, eax
  2223.  
  2224.         mov     ecx, [window_data + edx + WDATA.box.left]
  2225.         cmp     ecx, ebx
  2226.         jge     .next_window
  2227.         add     ecx, [window_data + edx + WDATA.box.width]
  2228.         cmp     eax, ecx
  2229.         jge     .next_window
  2230.  
  2231.         pop     esi edx ebx eax
  2232. ;--------------------------------------
  2233. align 4
  2234. .exit.redraw:
  2235.         xor     ecx, ecx
  2236.         inc     ecx
  2237.         ret
  2238. ;--------------------------------------
  2239. align 4
  2240. .exit.no_redraw:
  2241.         pop     esi edx ebx eax
  2242.         xor     ecx, ecx
  2243.         ret
  2244. ;------------------------------------------------------------------------------
  2245. align 4
  2246. ;------------------------------------------------------------------------------
  2247. window._.draw_window_caption: ;////////////////////////////////////////////////
  2248. ;------------------------------------------------------------------------------
  2249. ;? <description>
  2250. ;------------------------------------------------------------------------------
  2251.         xor     eax, eax
  2252.         mov     edx, [TASK_COUNT]
  2253.         movzx   edx, word[WIN_POS + edx * 2]
  2254.         cmp     edx, [CURRENT_TASK]
  2255.         jne     @f
  2256.         inc     eax
  2257. ;--------------------------------------
  2258. align 4
  2259. @@:
  2260.         mov     edx, [CURRENT_TASK]
  2261.         shl     edx, 5
  2262.         add     edx, window_data
  2263.         movzx   ebx, [edx + WDATA.fl_wstyle]
  2264.         and     bl, 0x0F
  2265.         cmp     bl, 3
  2266.         je      .draw_caption_style_3
  2267.         cmp     bl, 4
  2268.         je      .draw_caption_style_3
  2269.  
  2270.         jmp     .not_style_3
  2271. ;--------------------------------------
  2272. align 4
  2273. .draw_caption_style_3:
  2274.         push    edx
  2275.         call    drawwindow_IV_caption
  2276.         add     esp, 4
  2277.         jmp     .2
  2278. ;--------------------------------------
  2279. align 4
  2280. .not_style_3:
  2281.         cmp     bl, 2
  2282.         jne     .not_style_2
  2283.  
  2284.         call    drawwindow_III_caption
  2285.         jmp     .2
  2286. ;--------------------------------------
  2287. align 4
  2288. .not_style_2:
  2289.         cmp     bl, 0
  2290.         jne     .2
  2291.  
  2292.         call    drawwindow_I_caption
  2293. ;--------------------------------------
  2294. align 4
  2295. .2:
  2296.         mov     edi, [CURRENT_TASK]
  2297.         shl     edi, 5
  2298.         test    [edi + window_data + WDATA.fl_wstyle], WSTYLE_HASCAPTION
  2299.         jz      .exit
  2300.         mov     edx, [edi * 8 + SLOT_BASE + APPDATA.wnd_caption]
  2301.         or      edx, edx
  2302.         jz      .exit
  2303.  
  2304.         movzx   eax, [edi + window_data + WDATA.fl_wstyle]
  2305.         and     al, 0x0F
  2306.         cmp     al, 3
  2307.         je      .skinned
  2308.         cmp     al, 4
  2309.         je      .skinned
  2310.  
  2311.         jmp     .not_skinned
  2312. ;--------------------------------------
  2313. align 4
  2314. .skinned:
  2315.         mov     ebp, [edi + window_data + WDATA.box.left - 2]
  2316.         mov     bp, word[edi + window_data + WDATA.box.top]
  2317.         movzx   eax, word[edi + window_data + WDATA.box.width]
  2318.         sub     ax, [_skinmargins.left]
  2319.         sub     ax, [_skinmargins.right]
  2320.         push    edx
  2321.         cwde
  2322.         cdq
  2323.         mov     ebx, 6
  2324.         idiv    ebx
  2325.         pop     edx
  2326.         or      eax, eax
  2327.         js      .exit
  2328.  
  2329.         mov     esi, eax
  2330.         mov     ebx, dword[_skinmargins.left - 2]
  2331.         mov     bx, word[_skinh]
  2332.         sub     bx, [_skinmargins.bottom]
  2333.         sub     bx, [_skinmargins.top]
  2334.         sar     bx, 1
  2335.         adc     bx, 0
  2336.         add     bx, [_skinmargins.top]
  2337.         add     bx, -3
  2338.         add     ebx, ebp
  2339.         jmp     .dodraw
  2340. ;--------------------------------------
  2341. align 4
  2342. .not_skinned:
  2343.         cmp     al, 1
  2344.         je      .exit
  2345.  
  2346.         mov     ebp, [edi + window_data + WDATA.box.left - 2]
  2347.         mov     bp, word[edi + window_data + WDATA.box.top]
  2348.         movzx   eax, word[edi + window_data + WDATA.box.width]
  2349.         sub     eax, 16
  2350.         push    edx
  2351.         cwde
  2352.         cdq
  2353.         mov     ebx, 6
  2354.         idiv    ebx
  2355.         pop     edx
  2356.         or      eax, eax
  2357.         js      .exit
  2358.  
  2359.         mov     esi, eax
  2360.         mov     ebx, 0x00080007
  2361.         add     ebx, ebp
  2362. ;--------------------------------------
  2363. align 4
  2364. .dodraw:
  2365.         mov     ecx, [common_colours + 16]
  2366.         or      ecx, 0x80000000
  2367.         xor     edi, edi
  2368.         call    dtext_asciiz_esi
  2369. ;--------------------------------------
  2370. align 4
  2371. .exit:
  2372. ;        call    [draw_pointer]
  2373.         call    __sys_draw_pointer
  2374.         ret
  2375. ;------------------------------------------------------------------------------
  2376. align 4
  2377. ;------------------------------------------------------------------------------
  2378. window._.draw_negative_box: ;//////////////////////////////////////////////////
  2379. ;------------------------------------------------------------------------------
  2380. ;? Draw negative box
  2381. ;------------------------------------------------------------------------------
  2382. ;> edi = pointer to BOX struct
  2383. ;------------------------------------------------------------------------------
  2384.         push    eax ebx esi
  2385.         mov     esi, 0x01000000
  2386. ;--------------------------------------
  2387. align 4
  2388. .1:
  2389.         mov     eax, [edi + BOX.left - 2]
  2390.         mov     ax, word[edi + BOX.left]
  2391.         add     ax, word[edi + BOX.width]
  2392.         mov     ebx, [edi + BOX.top - 2]
  2393.         mov     bx, word[edi + BOX.top]
  2394.         add     bx, word[edi + BOX.height]
  2395.         call    draw_rectangle.forced
  2396.         pop     esi ebx eax
  2397.         ret
  2398. ;------------------------------------------------------------------------------
  2399. ;align 4
  2400. ;------------------------------------------------------------------------------
  2401. ;window._.end_moving__box: ;//////////////////////////////////////////////////
  2402. ;------------------------------------------------------------------------------
  2403. ;? Draw positive box
  2404. ;------------------------------------------------------------------------------
  2405. ;> edi = pointer to BOX struct
  2406. ;------------------------------------------------------------------------------
  2407. ;        push    eax ebx esi
  2408. ;        xor     esi, esi
  2409. ;        jmp     window._.draw_negative_box.1
  2410. ;------------------------------------------------------------------------------
  2411. align 4
  2412. ;------------------------------------------------------------------------------
  2413. window._.get_rect: ;/////////////////////////////////////////////////////
  2414. ;------------------------------------------------------------------------------
  2415. ;? <description>  void __fastcall get_window_rect(struct RECT* rc);
  2416. ;------------------------------------------------------------------------------
  2417. ;> ecx = pointer to RECT
  2418. ;------------------------------------------------------------------------------
  2419.         mov     eax, [TASK_BASE]
  2420.  
  2421.         mov     edx, [eax-twdw + WDATA.box.left]
  2422.         mov     [ecx+RECT.left], edx
  2423.  
  2424.         add     edx, [eax-twdw + WDATA.box.width]
  2425.         mov     [ecx+RECT.right], edx
  2426.  
  2427.         mov     edx, [eax-twdw + WDATA.box.top]
  2428.         mov     [ecx+RECT.top], edx
  2429.  
  2430.         add     edx, [eax-twdw + WDATA.box.height]
  2431.         mov     [ecx+RECT.bottom], edx
  2432.         ret
  2433. ;------------------------------------------------------------------------------
  2434.