Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | 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: 4424 $
  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.         call    window._.window_activate
  996.  
  997.         pushad
  998.         mov     edi, [TASK_COUNT]
  999.         movzx   esi, word[WIN_POS + edi * 2]
  1000.         shl     esi, 5
  1001.         add     esi, window_data
  1002.  
  1003.         mov     eax, [esi + WDATA.box.left]
  1004.         mov     ebx, [esi + WDATA.box.top]
  1005.         mov     ecx, [esi + WDATA.box.width]
  1006.         mov     edx, [esi + WDATA.box.height]
  1007.  
  1008.         add     ecx, eax
  1009.         add     edx, ebx
  1010.  
  1011.         mov     edi, [TASK_COUNT]
  1012.         movzx   esi, word[WIN_POS + edi * 2]
  1013.         call    window._.set_screen
  1014.         inc     [_display.mask_seqno]
  1015.         popad
  1016.  
  1017.         ; tell application to redraw itself
  1018.         mov     [edi + WDATA.fl_redraw], 1
  1019.         xor     eax, eax
  1020.         jmp     .exit
  1021. ;--------------------------------------
  1022. align 4
  1023. .do_not_draw:
  1024.         ; no it's not, just activate the window
  1025.         call    window._.window_activate
  1026.         xor     eax, eax
  1027.         ret
  1028.  
  1029. ;--------------------------------------
  1030. align 4
  1031. .exit:
  1032.         inc     eax
  1033.         ret
  1034. ;------------------------------------------------------------------------------
  1035. align 4
  1036. ;------------------------------------------------------------------------------
  1037. minimize_all_window:
  1038.         push    ebx ecx edx esi edi
  1039.         pushfd
  1040.         cli
  1041.         xor     edx, edx
  1042.         mov     eax, 2  ; we do not minimize the kernel thread N1
  1043.         mov     ebx, [TASK_COUNT]
  1044. ;--------------------------------------
  1045. align 4
  1046. .loop:
  1047.         movzx   edi, word[WIN_POS + eax * 2]
  1048.         shl     edi, 5
  1049. ; it is a unused slot?
  1050.         cmp     dword [edi+CURRENT_TASK+TASKDATA.state], 9
  1051.         je      @f
  1052. ; it is a hidden thread?
  1053.         lea     esi, [edi*8+SLOT_BASE+APPDATA.app_name]
  1054.         cmp     [esi], byte '@'
  1055.         je      @f
  1056. ; is it already minimized?
  1057.         test    [edi + window_data+WDATA.fl_wstate], WSTATE_MINIMIZED
  1058.         jnz     @f
  1059. ; no it's not, let's do that
  1060.         or      [edi + window_data+WDATA.fl_wstate], WSTATE_MINIMIZED
  1061.         inc     edx
  1062. ;--------------------------------------
  1063. align 4
  1064. @@:
  1065.         inc     eax
  1066.         cmp     eax, ebx
  1067.         jbe     .loop
  1068. ; If nothing has changed
  1069.         test    edx, edx
  1070.         jz      @f
  1071.  
  1072.         push    edx
  1073.         call    syscall_display_settings._.calculate_whole_screen
  1074.         call    syscall_display_settings._.redraw_whole_screen
  1075.         pop     edx
  1076. ;--------------------------------------
  1077. align 4
  1078. @@:
  1079.         mov     eax, edx
  1080.         popfd
  1081.         pop     edi esi edx ecx ebx
  1082.         ret
  1083. ;------------------------------------------------------------------------------
  1084. align 4
  1085. ;------------------------------------------------------------------------------
  1086. minimize_window: ;/////////////////////////////////////////////////////////////
  1087. ;------------------------------------------------------------------------------
  1088. ;> eax = window number on screen
  1089. ;------------------------------------------------------------------------------
  1090. ;# corrupts [dl*]
  1091. ;------------------------------------------------------------------------------
  1092.         push    edi
  1093.         pushfd
  1094.         cli
  1095.  
  1096.         ; is it already minimized?
  1097.         movzx   edi, word[WIN_POS + eax * 2]
  1098.         shl     edi, 5
  1099.         add     edi, window_data
  1100.         test    [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  1101.         jnz     .exit
  1102.  
  1103.         push    eax ebx ecx edx esi
  1104.  
  1105.         ; no it's not, let's do that
  1106.         or      [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  1107. ; If the window width is 0, then the action is not needed.
  1108.         cmp     [edi + WDATA.box.width], dword 0
  1109.         je      @f
  1110. ; If the window height is 0, then the action is not needed.
  1111.         cmp     [edi + WDATA.box.height], dword 0
  1112.         je      @f
  1113.  
  1114.         mov     eax, [edi + WDATA.box.left]
  1115.         mov     [draw_limits.left], eax
  1116.         mov     ecx, eax
  1117.         add     ecx, [edi + WDATA.box.width]
  1118.         mov     [draw_limits.right], ecx
  1119.         mov     ebx, [edi + WDATA.box.top]
  1120.         mov     [draw_limits.top], ebx
  1121.         mov     edx, ebx
  1122.         add     edx, [edi + WDATA.box.height]
  1123.         mov     [draw_limits.bottom], edx
  1124.  
  1125. ;        DEBUGF  1, "K : minimize_window\n"
  1126. ;        DEBUGF  1, "K : dl_left %x\n",[draw_limits.left]
  1127. ;        DEBUGF  1, "K : dl_right %x\n",[draw_limits.right]
  1128. ;        DEBUGF  1, "K : dl_top %x\n",[draw_limits.top]
  1129. ;        DEBUGF  1, "K : dl_bottom %x\n",[draw_limits.bottom]
  1130.         call    calculatescreen
  1131. ;        xor     esi, esi
  1132. ;        xor     eax, eax
  1133.         mov     eax, edi
  1134.         call    redrawscreen
  1135. ;--------------------------------------
  1136. align 4
  1137. @@:
  1138.         pop     esi edx ecx ebx eax
  1139. ;--------------------------------------
  1140. align 4
  1141. .exit:
  1142.         popfd
  1143.         pop     edi
  1144.         ret
  1145. ;------------------------------------------------------------------------------
  1146. align 4
  1147. ;------------------------------------------------------------------------------
  1148. restore_minimized_window: ;////////////////////////////////////////////////////
  1149. ;------------------------------------------------------------------------------
  1150. ;> eax = window number on screen
  1151. ;------------------------------------------------------------------------------
  1152. ;# corrupts [dl*]
  1153. ;------------------------------------------------------------------------------
  1154.         pushad
  1155.         pushfd
  1156.         cli
  1157.  
  1158.         ; is it already restored?
  1159.         movzx   esi, word[WIN_POS + eax * 2]
  1160.         mov     edi, esi
  1161.         shl     edi, 5
  1162.         add     edi, window_data
  1163.         test    [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  1164.         jz      .exit
  1165.  
  1166.         ; no it's not, let's do that
  1167.         mov     [edi + WDATA.fl_redraw], 1
  1168.         and     [edi + WDATA.fl_wstate], not WSTATE_MINIMIZED
  1169.         mov     ebp, window._.set_screen
  1170.         cmp     eax, [TASK_COUNT]
  1171.         jz      @f
  1172.         mov     ebp, calculatescreen
  1173. ;--------------------------------------
  1174. align 4
  1175. @@:
  1176.         mov     eax, [edi + WDATA.box.left]
  1177.         mov     ebx, [edi + WDATA.box.top]
  1178.         mov     ecx, [edi + WDATA.box.width]
  1179.         mov     edx, [edi + WDATA.box.height]
  1180.         add     ecx, eax
  1181.         add     edx, ebx
  1182.         call    ebp
  1183.         inc     [_display.mask_seqno]
  1184. ;--------------------------------------
  1185. align 4
  1186. .exit:
  1187.         popfd
  1188.         popad
  1189.         ret
  1190. ;------------------------------------------------------------------------------
  1191. align 4
  1192. ; TODO: remove this proc
  1193. ;------------------------------------------------------------------------------
  1194. window_check_events: ;/////////////////////////////////////////////////////////
  1195. ;------------------------------------------------------------------------------
  1196. ;? <description>
  1197. ;------------------------------------------------------------------------------
  1198.         ; do we have window minimize/restore request?
  1199.         cmp     [window_minimize], 0
  1200.         je      .exit
  1201.  
  1202.         ; okay, minimize or restore top-most window and exit
  1203.         mov     eax, [TASK_COUNT]
  1204.         mov     bl, 0
  1205.         xchg    [window_minimize], bl
  1206.         dec     bl
  1207.         jnz     @f
  1208.         call    minimize_window
  1209.         jmp     .exit
  1210. ;--------------------------------------
  1211. align 4
  1212. @@:
  1213.         call    restore_minimized_window
  1214. ;--------------------------------------
  1215. align 4
  1216. .exit:
  1217.         ret
  1218. ;------------------------------------------------------------------------------
  1219. align 4
  1220. ;------------------------------------------------------------------------------
  1221. sys_window_maximize_handler: ;/////////////////////////////////////////////////
  1222. ;------------------------------------------------------------------------------
  1223. ;? <description>
  1224. ;------------------------------------------------------------------------------
  1225. ;> esi = process slot
  1226. ;------------------------------------------------------------------------------
  1227.         mov     edi, esi
  1228.         shl     edi, 5
  1229.         add     edi, window_data
  1230.  
  1231.         ; can window change its height?
  1232.         ; only types 2 and 3 can be resized
  1233.         mov     dl, [edi + WDATA.fl_wstyle]
  1234.         test    dl, 2
  1235.         jz      .exit
  1236.  
  1237.         ; toggle normal/maximized window state
  1238.         mov     bl, [edi + WDATA.fl_wstate]
  1239.         xor     bl, WSTATE_MAXIMIZED
  1240.  
  1241.         ; calculate and set appropriate window bounds
  1242.         test    bl, WSTATE_MAXIMIZED
  1243.         jz      .restore_size
  1244.  
  1245.         mov     eax, [screen_workarea.left]
  1246.         mov     ecx, [screen_workarea.top]
  1247.         push    [screen_workarea.bottom] \
  1248.                 [screen_workarea.right] \
  1249.                 ecx \
  1250.                 eax
  1251.         sub     [esp + BOX.width], eax
  1252.         sub     [esp + BOX.height], ecx
  1253.         mov     eax, esp
  1254.         jmp     .set_box
  1255. ;--------------------------------------
  1256. align 4
  1257. .restore_size:
  1258.         mov     eax, esi
  1259.         shl     eax, 8
  1260.         add     eax, SLOT_BASE + APPDATA.saved_box
  1261.         push    [eax + BOX.height] \
  1262.                 [eax + BOX.width] \
  1263.                 [eax + BOX.top] \
  1264.                 [eax + BOX.left]
  1265.         mov     eax, esp
  1266. ;--------------------------------------
  1267. align 4
  1268. .set_box:
  1269.         test    bl, WSTATE_ROLLEDUP
  1270.         jz      @f
  1271.  
  1272.         xchg    eax, ecx
  1273.         call    window._.get_rolledup_height
  1274.         mov     [ecx + BOX.height], eax
  1275.         xchg    eax, ecx
  1276. ;--------------------------------------
  1277. align 4
  1278. @@:
  1279.         call    window._.set_window_box
  1280.         add     esp, sizeof.BOX
  1281. ;--------------------------------------
  1282. align 4
  1283. .exit:
  1284.         inc     [_display.mask_seqno]
  1285.         ret
  1286. ;------------------------------------------------------------------------------
  1287. align 4
  1288. ;------------------------------------------------------------------------------
  1289. sys_window_rollup_handler: ;///////////////////////////////////////////////////
  1290. ;------------------------------------------------------------------------------
  1291. ;? <description>
  1292. ;------------------------------------------------------------------------------
  1293. ;> esi = process slot
  1294. ;------------------------------------------------------------------------------
  1295.         mov     edx, esi
  1296.         shl     edx, 8
  1297.         add     edx, SLOT_BASE
  1298.  
  1299.         ; toggle normal/rolled up window state
  1300.         mov     bl, [edi + WDATA.fl_wstate]
  1301.         xor     bl, WSTATE_ROLLEDUP
  1302.  
  1303.         ; calculate and set appropriate window bounds
  1304.         test    bl, WSTATE_ROLLEDUP
  1305.         jz      .restore_size
  1306.  
  1307.         call    window._.get_rolledup_height
  1308.         push    eax \
  1309.                 [edi + WDATA.box.width] \
  1310.                 [edi + WDATA.box.top] \
  1311.                 [edi + WDATA.box.left]
  1312.         mov     eax, esp
  1313.         jmp     .set_box
  1314. ;--------------------------------------
  1315. align 4
  1316. .restore_size:
  1317.         test    bl, WSTATE_MAXIMIZED
  1318.         jnz     @f
  1319.         add     esp, -sizeof.BOX
  1320.         lea     eax, [edx + APPDATA.saved_box]
  1321.         jmp     .set_box
  1322. ;--------------------------------------
  1323. align 4
  1324. @@:
  1325.         mov     eax, [screen_workarea.top]
  1326.         push    [screen_workarea.bottom] \
  1327.                 [edi + WDATA.box.width] \
  1328.                 eax \
  1329.                 [edi + WDATA.box.left]
  1330.         sub     [esp + BOX.height], eax
  1331.         mov     eax, esp
  1332. ;--------------------------------------
  1333. align 4
  1334. .set_box:
  1335.         call    window._.set_window_box
  1336.         add     esp, sizeof.BOX
  1337.         ret
  1338. ;------------------------------------------------------------------------------
  1339. align 4
  1340. ;------------------------------------------------------------------------------
  1341. ;sys_window_start_moving_handler: ;/////////////////////////////////////////////
  1342. ;------------------------------------------------------------------------------
  1343. ;? <description>
  1344. ;------------------------------------------------------------------------------
  1345. ;> eax = old (original) window box
  1346. ;> esi = process slot
  1347. ;------------------------------------------------------------------------------
  1348. ;        mov     edi, eax
  1349. ;        call    window._.draw_negative_box
  1350. ;        ret
  1351. ;------------------------------------------------------------------------------
  1352. align 4
  1353. ;------------------------------------------------------------------------------
  1354. sys_window_end_moving_handler: ;///////////////////////////////////////////////
  1355. ;------------------------------------------------------------------------------
  1356. ;? <description>
  1357. ;------------------------------------------------------------------------------
  1358. ;> eax = old (original) window box
  1359. ;> ebx = new (final) window box
  1360. ;> esi = process slot
  1361. ;------------------------------------------------------------------------------
  1362. ;        mov     edi, ebx
  1363. ;        call    window._.end_moving__box
  1364.  
  1365.         mov     edi, esi
  1366.         shl     edi, 5
  1367.         add     edi, window_data
  1368.  
  1369.         mov     eax, ebx
  1370.         mov     bl, [edi + WDATA.fl_wstate]
  1371.         call    window._.set_window_box
  1372.         ret
  1373. ;------------------------------------------------------------------------------
  1374. align 4
  1375. ;------------------------------------------------------------------------------
  1376. sys_window_moving_handler: ;///////////////////////////////////////////////////
  1377. ;------------------------------------------------------------------------------
  1378. ;? <description>
  1379. ;------------------------------------------------------------------------------
  1380. ;> eax = old (from previous call) window box
  1381. ;> ebx = new (current) window box
  1382. ;> esi = process_slot
  1383. ;------------------------------------------------------------------------------
  1384.         mov     edi, eax
  1385.         call    window._.draw_negative_box
  1386.         mov     edi, ebx
  1387.         call    window._.draw_negative_box
  1388.         ret
  1389. ;==============================================================================
  1390. ;///// private functions //////////////////////////////////////////////////////
  1391. ;==============================================================================
  1392.  
  1393. iglobal
  1394.   FuncTable syscall_display_settings, ftable, \
  1395.     00, 01, 02, 03, 04, 05, 06, 07, 08
  1396.  
  1397.   align 4
  1398.   window_topleft dd \
  1399.     1, 21, \ ;type 0
  1400.     0,  0, \ ;type 1
  1401.     5, 20, \ ;type 2
  1402.     5,  ?, \ ;type 3 {set by skin}
  1403.     5,  ?    ;type 4 {set by skin}
  1404. endg
  1405.  
  1406. ;uglobal
  1407.   ; NOTE: commented out since doesn't provide necessary functionality anyway,
  1408.   ;       to be reworked
  1409. ; new_window_starting       dd ?
  1410. ;endg
  1411. ;------------------------------------------------------------------------------
  1412. align 4
  1413. ;------------------------------------------------------------------------------
  1414. window._.invalidate_screen: ;//////////////////////////////////////////////////
  1415. ;------------------------------------------------------------------------------
  1416. ;? <description>
  1417. ;------------------------------------------------------------------------------
  1418. ;> eax = old (original) window box
  1419. ;> ebx = new (final) window box
  1420. ;> edi = pointer to WDATA struct
  1421. ;------------------------------------------------------------------------------
  1422.         push    eax ebx
  1423.  
  1424.         ; TODO: do we really need `draw_limits`?
  1425.         ; Yes, they are used by background drawing code.
  1426.  
  1427. ; we need only to restore the background windows at the old place!
  1428.         mov     ecx, [ebx + BOX.left]
  1429.         mov     [draw_limits.left], ecx
  1430.         add     ecx, [ebx + BOX.width]
  1431.         mov     [draw_limits.right], ecx
  1432.         mov     ecx, [ebx + BOX.top]
  1433.         mov     [draw_limits.top], ecx
  1434.         add     ecx, [ebx + BOX.height]
  1435.         mov     [draw_limits.bottom], ecx
  1436. ; recalculate screen buffer at old position
  1437.         push    ebx
  1438.         mov     edx, [eax + BOX.height]
  1439.         mov     ecx, [eax + BOX.width]
  1440.         mov     ebx, [eax + BOX.top]
  1441.         mov     eax, [eax + BOX.left]
  1442.         add     ecx, eax
  1443.         add     edx, ebx
  1444.         call    calculatescreen
  1445.         pop     eax
  1446. ; recalculate screen buffer at new position
  1447.         mov     edx, [eax + BOX.height]
  1448.         mov     ecx, [eax + BOX.width]
  1449.         mov     ebx, [eax + BOX.top]
  1450.         mov     eax, [eax + BOX.left]
  1451.         add     ecx, eax
  1452.         add     edx, ebx
  1453.         call    calculatescreen
  1454.  
  1455.         mov     eax, edi
  1456.         call    redrawscreen
  1457.  
  1458.         ; tell window to redraw itself
  1459.         mov     [edi + WDATA.fl_redraw], 1
  1460.  
  1461.         pop     ebx eax
  1462.         ret
  1463. ;------------------------------------------------------------------------------
  1464. align 4
  1465. ;------------------------------------------------------------------------------
  1466. window._.set_window_box: ;/////////////////////////////////////////////////////
  1467. ;------------------------------------------------------------------------------
  1468. ;? <description>
  1469. ;------------------------------------------------------------------------------
  1470. ;> eax = pointer to BOX struct
  1471. ;> bl = new window state flags
  1472. ;> edi = pointer to WDATA struct
  1473. ;------------------------------------------------------------------------------
  1474.         push    eax ebx esi
  1475.  
  1476. ; don't do anything if the new box is identical to the old
  1477.         cmp     bl, [edi + WDATA.fl_wstate]
  1478.         jnz     @f
  1479.         mov     esi, eax
  1480.         push    edi
  1481. if WDATA.box
  1482.         add     edi, WDATA.box
  1483. end if
  1484.         mov     ecx, 4
  1485.         repz cmpsd
  1486.         pop     edi
  1487.         jz      .exit
  1488. ;--------------------------------------
  1489. align 4
  1490. @@:
  1491.         add     esp, -sizeof.BOX
  1492.         mov     ebx, esp
  1493. if WDATA.box
  1494.         lea     esi, [edi + WDATA.box]
  1495. else
  1496.         mov     esi, edi ; optimization for WDATA.box = 0
  1497. end if
  1498.         xchg    eax, esi
  1499.         mov     ecx, sizeof.BOX
  1500.         call    memmove
  1501.         xchg    eax, esi
  1502.         xchg    ebx, esi
  1503.         call    memmove
  1504.         mov     eax, ebx
  1505.         mov     ebx, esi
  1506.  
  1507.         call    window._.check_window_position
  1508.         call    window._.set_window_clientbox
  1509.         call    window._.invalidate_screen
  1510.  
  1511.         add     esp, sizeof.BOX
  1512.  
  1513.         mov     cl, [esp + 4]
  1514.         mov     ch, cl
  1515.         xchg    cl, [edi + WDATA.fl_wstate]
  1516.  
  1517.         or      cl, ch
  1518.         test    cl, WSTATE_MAXIMIZED
  1519.         jnz     .exit
  1520.  
  1521.         mov     eax, edi
  1522.         sub     eax, window_data
  1523.         shl     eax, 3
  1524.         add     eax, SLOT_BASE
  1525.  
  1526.         lea     ebx, [edi + WDATA.box]
  1527.         xchg    esp, ebx
  1528.  
  1529.         pop     [eax + APPDATA.saved_box.left] \
  1530.                 [eax + APPDATA.saved_box.top] \
  1531.                 [eax + APPDATA.saved_box.width] \
  1532.                 edx
  1533.  
  1534.         xchg    esp, ebx
  1535.  
  1536.         test    ch, WSTATE_ROLLEDUP
  1537.         jnz     .exit
  1538.  
  1539.         mov     [eax + APPDATA.saved_box.height], edx
  1540. ;--------------------------------------
  1541. align 4
  1542. .exit:
  1543.         pop     esi ebx eax
  1544.         ret
  1545. ;------------------------------------------------------------------------------
  1546. align 4
  1547. ;------------------------------------------------------------------------------
  1548. window._.set_window_clientbox: ;///////////////////////////////////////////////
  1549. ;------------------------------------------------------------------------------
  1550. ;? <description>
  1551. ;------------------------------------------------------------------------------
  1552. ;> edi = pointer to WDATA struct
  1553. ;------------------------------------------------------------------------------
  1554.         push    eax ecx edi
  1555.  
  1556.         mov     eax, [_skinh]
  1557.         mov     [window_topleft + 8 * 3 + 4], eax
  1558.         mov     [window_topleft + 8 * 4 + 4], eax
  1559.  
  1560.         mov     ecx, edi
  1561.         sub     edi, window_data
  1562.         shl     edi, 3
  1563.         test    [ecx + WDATA.fl_wstyle], WSTYLE_CLIENTRELATIVE
  1564.         jz      .whole_window
  1565.  
  1566.         movzx   eax, [ecx + WDATA.fl_wstyle]
  1567.         and     eax, 0x0F
  1568.         mov     eax, [eax * 8 + window_topleft + 0]
  1569.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.left], eax
  1570.         shl     eax, 1
  1571.         neg     eax
  1572.         add     eax, [ecx + WDATA.box.width]
  1573.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.width], eax
  1574.  
  1575.         movzx   eax, [ecx + WDATA.fl_wstyle]
  1576.         and     eax, 0x0F
  1577.         push    [eax * 8 + window_topleft + 0]
  1578.         mov     eax, [eax * 8 + window_topleft + 4]
  1579.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.top], eax
  1580.         neg     eax
  1581.         sub     eax, [esp]
  1582.         add     eax, [ecx + WDATA.box.height]
  1583.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.height], eax
  1584.         add     esp, 4
  1585.         jmp     .exit
  1586. ;--------------------------------------
  1587. align 4
  1588. .whole_window:
  1589.         xor     eax, eax
  1590.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.left], eax
  1591.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.top], eax
  1592.         mov     eax, [ecx + WDATA.box.width]
  1593.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.width], eax
  1594.         mov     eax, [ecx + WDATA.box.height]
  1595.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.height], eax
  1596. ;--------------------------------------
  1597. align 4
  1598. .exit:
  1599.         pop     edi ecx eax
  1600.         ret
  1601. ;------------------------------------------------------------------------------
  1602. align 4
  1603. ;------------------------------------------------------------------------------
  1604. window._.sys_set_window: ;/////////////////////////////////////////////////////
  1605. ;------------------------------------------------------------------------------
  1606. ;? <description>
  1607. ;------------------------------------------------------------------------------
  1608. ;< edx = pointer to WDATA struct
  1609. ;------------------------------------------------------------------------------
  1610.         mov     eax, [CURRENT_TASK]
  1611.         shl     eax, 5
  1612.         add     eax, window_data
  1613.  
  1614.         ; save window colors
  1615.         mov     [eax + WDATA.cl_workarea], edx
  1616.         mov     [eax + WDATA.cl_titlebar], esi
  1617.         mov     [eax + WDATA.cl_frames], edi
  1618.  
  1619.         mov     edi, eax
  1620.  
  1621.         ; was it already defined before?
  1622.         test    [edi + WDATA.fl_wdrawn], 1
  1623.         jnz     .set_client_box
  1624.         or      [edi + WDATA.fl_wdrawn], 1
  1625. ; After first draw_window we need redraw mouse necessarily!
  1626. ; Otherwise the user can see cursor specified by f.37.5 from another window.
  1627. ; He will be really unhappy! He is terrible in rage - usually he throws stones!
  1628.         mov     [redrawmouse_unconditional], 1
  1629.         call    wakeup_osloop
  1630.         ; NOTE: commented out since doesn't provide necessary functionality
  1631.         ;       anyway, to be reworked
  1632. ;       mov     eax, [timer_ticks] ; [0xfdf0]
  1633. ;       add     eax, 100
  1634. ;       mov     [new_window_starting], eax
  1635.  
  1636.         ; no it wasn't, performing initial window definition
  1637.         movzx   eax, bx
  1638.         mov     [edi + WDATA.box.width], eax
  1639.         movzx   eax, cx
  1640.         mov     [edi + WDATA.box.height], eax
  1641.         sar     ebx, 16
  1642.         sar     ecx, 16
  1643.         mov     [edi + WDATA.box.left], ebx
  1644.         mov     [edi + WDATA.box.top], ecx
  1645.  
  1646.         call    window._.check_window_position
  1647.  
  1648.         push    ecx edi
  1649.  
  1650.         mov     cl, [edi + WDATA.fl_wstyle]
  1651.         mov     eax, [edi + WDATA.cl_frames]
  1652.  
  1653.         sub     edi, window_data
  1654.         shl     edi, 3
  1655.         add     edi, SLOT_BASE
  1656.  
  1657.         and     cl, 0x0F
  1658.         cmp     cl, 3
  1659.         je      @f
  1660.         cmp     cl, 4
  1661.         je      @f
  1662.  
  1663.         xor     eax, eax
  1664. ;--------------------------------------
  1665. align 4
  1666. @@:
  1667.         mov     [edi + APPDATA.wnd_caption], eax
  1668.  
  1669.         mov     esi, [esp]
  1670.         add     edi, APPDATA.saved_box
  1671.         movsd
  1672.         movsd
  1673.         movsd
  1674.         movsd
  1675.  
  1676.         pop     edi ecx
  1677.  
  1678.         mov     esi, [CURRENT_TASK]
  1679.         movzx   esi, word[WIN_STACK + esi * 2]
  1680.         lea     esi, [WIN_POS + esi * 2]
  1681.         call    waredraw
  1682.  
  1683.         mov     eax, [edi + WDATA.box.left]
  1684.         mov     ebx, [edi + WDATA.box.top]
  1685.         mov     ecx, [edi + WDATA.box.width]
  1686.         mov     edx, [edi + WDATA.box.height]
  1687.         add     ecx, eax
  1688.         add     edx, ebx
  1689.         call    calculatescreen
  1690.  
  1691.         mov     byte[KEY_COUNT], 0           ; empty keyboard buffer
  1692.         mov     byte[BTN_COUNT], 0           ; empty button buffer
  1693. ;--------------------------------------
  1694. align 4
  1695. .set_client_box:
  1696.         ; update window client box coordinates
  1697.         call    window._.set_window_clientbox
  1698.  
  1699.         ; reset window redraw flag and exit
  1700.         mov     [edi + WDATA.fl_redraw], 0
  1701.         mov     edx, edi
  1702.         ret
  1703. ;------------------------------------------------------------------------------
  1704. align 4
  1705. ;------------------------------------------------------------------------------
  1706. window._.check_window_position: ;//////////////////////////////////////////////
  1707. ;------------------------------------------------------------------------------
  1708. ;? Check if window is inside screen area
  1709. ;------------------------------------------------------------------------------
  1710. ;> edi = pointer to WDATA
  1711. ;------------------------------------------------------------------------------
  1712.         push    eax ebx ecx edx esi
  1713.  
  1714.         mov     eax, [edi + WDATA.box.left]
  1715.         mov     ebx, [edi + WDATA.box.top]
  1716.         mov     ecx, [edi + WDATA.box.width]
  1717.         mov     edx, [edi + WDATA.box.height]
  1718.  
  1719.         mov     esi, [Screen_Max_X]
  1720.         cmp     ecx, esi
  1721.         ja      .fix_width_high
  1722. ;--------------------------------------
  1723. align 4
  1724. .check_left:
  1725.         or      eax, eax
  1726.         jl      .fix_left_low
  1727.         add     eax, ecx
  1728.         cmp     eax, esi
  1729.         jg      .fix_left_high
  1730. ;--------------------------------------
  1731. align 4
  1732. .check_height:
  1733.         mov     esi, [Screen_Max_Y]
  1734.         cmp     edx, esi
  1735.         ja      .fix_height_high
  1736. ;--------------------------------------
  1737. align 4
  1738. .check_top:
  1739.         or      ebx, ebx
  1740.         jl      .fix_top_low
  1741.         add     ebx, edx
  1742.         cmp     ebx, esi
  1743.         jg      .fix_top_high
  1744. ;--------------------------------------
  1745. align 4
  1746. .exit:
  1747.         pop     esi edx ecx ebx eax
  1748.         ret
  1749. ;--------------------------------------
  1750. align 4
  1751. .fix_width_high:
  1752.         mov     ecx, esi
  1753.         mov     [edi + WDATA.box.width], esi
  1754.         jmp     .check_left
  1755. ;--------------------------------------
  1756. align 4
  1757. .fix_left_low:
  1758.         xor     eax, eax
  1759.         mov     [edi + WDATA.box.left], eax
  1760.         jmp     .check_height
  1761. ;--------------------------------------
  1762. align 4
  1763. .fix_left_high:
  1764.         mov     eax, esi
  1765.         sub     eax, ecx
  1766.         mov     [edi + WDATA.box.left], eax
  1767.         jmp     .check_height
  1768. ;--------------------------------------
  1769. align 4
  1770. .fix_height_high:
  1771.         mov     edx, esi
  1772.         mov     [edi + WDATA.box.height], esi
  1773.         jmp     .check_top
  1774. ;--------------------------------------
  1775. align 4
  1776. .fix_top_low:
  1777.         xor     ebx, ebx
  1778.         mov     [edi + WDATA.box.top], ebx
  1779.         jmp     .exit
  1780. ;--------------------------------------
  1781. align 4
  1782. .fix_top_high:
  1783.         mov     ebx, esi
  1784.         sub     ebx, edx
  1785.         mov     [edi + WDATA.box.top], ebx
  1786.         jmp     .exit
  1787. ;------------------------------------------------------------------------------
  1788. align 4
  1789. ;------------------------------------------------------------------------------
  1790. window._.get_titlebar_height: ;////////////////////////////////////////////////
  1791. ;------------------------------------------------------------------------------
  1792. ;? <description>
  1793. ;------------------------------------------------------------------------------
  1794. ;> edi = pointer to WDATA
  1795. ;------------------------------------------------------------------------------
  1796.         mov     al, [edi + WDATA.fl_wstyle]
  1797.         and     al, 0x0f
  1798.         cmp     al, 0x03
  1799.         jne     @f
  1800.         mov     eax, [_skinh]
  1801.         ret
  1802. ;--------------------------------------
  1803. align 4
  1804. @@:
  1805.         mov     eax, 21
  1806.         ret
  1807. ;------------------------------------------------------------------------------
  1808. align 4
  1809. ;------------------------------------------------------------------------------
  1810. window._.get_rolledup_height: ;////////////////////////////////////////////////
  1811. ;------------------------------------------------------------------------------
  1812. ;? <description>
  1813. ;------------------------------------------------------------------------------
  1814. ;> edi = pointer to WDATA
  1815. ;------------------------------------------------------------------------------
  1816.         mov     al, [edi + WDATA.fl_wstyle]
  1817.         and     al, 0x0f
  1818.         cmp     al, 0x03
  1819.         jb      @f
  1820.         mov     eax, [_skinh]
  1821.         add     eax, 3
  1822.         ret
  1823. ;--------------------------------------
  1824. align 4
  1825. @@:
  1826.         or      al, al
  1827.         jnz     @f
  1828.         mov     eax, 21
  1829.         ret
  1830. ;--------------------------------------
  1831. align 4
  1832. @@:
  1833.         mov     eax, 21 + 2
  1834.         ret
  1835. ;------------------------------------------------------------------------------
  1836. align 4
  1837. ;------------------------------------------------------------------------------
  1838. window._.set_screen: ;/////////////////////////////////////////////////////////
  1839. ;------------------------------------------------------------------------------
  1840. ;? Reserve window area in screen buffer
  1841. ;------------------------------------------------------------------------------
  1842. ;> eax = left
  1843. ;> ebx = top
  1844. ;> ecx = right
  1845. ;> edx = bottom
  1846. ;> esi = process number
  1847. ;------------------------------------------------------------------------------
  1848. virtual at esp
  1849.   ff_x     dd ?
  1850.   ff_y     dd ?
  1851.   ff_width dd ?
  1852.   ff_xsz   dd ?
  1853.   ff_ysz   dd ?
  1854.   ff_scale dd ?
  1855. end virtual
  1856.  
  1857.         pushad
  1858.  
  1859.         cmp     esi, 1
  1860.         jz      .check_for_shaped_window
  1861.         mov     edi, esi
  1862.         shl     edi, 5
  1863.         cmp     [window_data + edi + WDATA.box.width], 0
  1864.         jnz     .check_for_shaped_window
  1865.         cmp     [window_data + edi + WDATA.box.height], 0
  1866.         jz      .exit
  1867. ;--------------------------------------
  1868. align 4
  1869. .check_for_shaped_window:
  1870.         mov     edi, esi
  1871.         shl     edi, 8
  1872.         add     edi, SLOT_BASE
  1873.         cmp     [edi + APPDATA.wnd_shape], 0
  1874.         jne     .shaped_window
  1875.  
  1876.         ; get x&y size
  1877.         sub     ecx, eax
  1878.         sub     edx, ebx
  1879.         inc     ecx
  1880.         inc     edx
  1881.  
  1882.         ; get WinMap start
  1883.         push    esi
  1884.         mov     esi, [_display.width]
  1885.         mov     edi, [d_width_calc_area + ebx*4]
  1886.  
  1887.         add     edi, eax
  1888.         add     edi, [_WinMapAddress]
  1889.         pop     eax
  1890.         mov     ah, al
  1891.         push    ax
  1892.         shl     eax, 16
  1893.         pop     ax
  1894. ;--------------------------------------
  1895. align 4
  1896. .next_line:
  1897.         push    ecx
  1898.         shr     ecx, 2
  1899.         rep stosd
  1900.         mov     ecx, [esp]
  1901.         and     ecx, 3
  1902.         rep stosb
  1903.         pop     ecx
  1904.         add     edi, esi
  1905.         sub     edi, ecx
  1906.         dec     edx
  1907.         jnz     .next_line
  1908.  
  1909.         jmp     .exit
  1910. ;--------------------------------------
  1911. align 4
  1912. .shaped_window:
  1913.         ;  for (y=0; y <= x_size; y++)
  1914.         ;      for (x=0; x <= x_size; x++)
  1915.         ;          if (shape[coord(x,y,scale)]==1)
  1916.         ;             set_pixel(x, y, process_number);
  1917.  
  1918.         sub     ecx, eax
  1919.         sub     edx, ebx
  1920.         inc     ecx
  1921.         inc     edx
  1922.  
  1923.         push    [edi + APPDATA.wnd_shape_scale]  ; push scale first -> for loop
  1924.  
  1925.         ; get WinMap start  -> ebp
  1926.         push    eax
  1927.         mov     eax, [d_width_calc_area + ebx*4]
  1928.  
  1929.         add     eax, [esp]
  1930.         add     eax, [_WinMapAddress]
  1931.         mov     ebp, eax
  1932.  
  1933.         mov     edi, [edi + APPDATA.wnd_shape]
  1934.         pop     eax
  1935.  
  1936.         ; eax = x_start
  1937.         ; ebx = y_start
  1938.         ; ecx = x_size
  1939.         ; edx = y_size
  1940.         ; esi = process_number
  1941.         ; edi = &shape
  1942.         ;       [scale]
  1943.         push    edx ecx ; for loop - x,y size
  1944.  
  1945.         mov     ecx, esi
  1946.         shl     ecx, 5
  1947.         mov     edx, [window_data + ecx + WDATA.box.top]
  1948.         push    [window_data + ecx + WDATA.box.width]           ; for loop - width
  1949.         mov     ecx, [window_data + ecx + WDATA.box.left]
  1950.         sub     ebx, edx
  1951.         sub     eax, ecx
  1952.         push    ebx eax ; for loop - x,y
  1953.  
  1954.         add     [ff_xsz], eax
  1955.         add     [ff_ysz], ebx
  1956.  
  1957.         mov     ebx, [ff_y]
  1958. ;--------------------------------------
  1959. align 4
  1960. .ff_new_y:
  1961.         mov     edx, [ff_x]
  1962. ;--------------------------------------
  1963. align 4
  1964. .ff_new_x:
  1965.         ; -- body --
  1966.         mov     ecx, [ff_scale]
  1967.         mov     eax, [ff_width]
  1968.         inc     eax
  1969.         shr     eax, cl
  1970.         push    ebx edx
  1971.         shr     ebx, cl
  1972.         shr     edx, cl
  1973.         imul    eax, ebx
  1974.         add     eax, edx
  1975.         pop     edx ebx
  1976.         add     eax, edi
  1977.         call    .read_byte
  1978.         test    al, al
  1979.         jz      @f
  1980.         mov     eax, esi
  1981.         mov     [ebp], al
  1982.         ; -- end body --
  1983. ;--------------------------------------
  1984. align 4
  1985. @@:
  1986.         inc     ebp
  1987.         inc     edx
  1988.         cmp     edx, [ff_xsz]
  1989.         jb      .ff_new_x
  1990.  
  1991.         sub     ebp, [ff_xsz]
  1992.         add     ebp, [ff_x]
  1993.         add     ebp, [Screen_Max_X]  ; screen.x
  1994.         inc     ebp
  1995.         inc     ebx
  1996.         cmp     ebx, [ff_ysz]
  1997.         jb      .ff_new_y
  1998.  
  1999.         add     esp, 24
  2000. ;--------------------------------------
  2001. align 4
  2002. .exit:
  2003.         popad
  2004.         inc     [_display.mask_seqno]
  2005.         ret
  2006. ;--------------------------------------
  2007. align 4
  2008. .read_byte:
  2009.         ; eax - address
  2010.         ; esi - slot
  2011.         push    eax ecx edx esi
  2012.         xchg    eax, esi
  2013.         lea     ecx, [esp + 12]
  2014.         mov     edx, 1
  2015.         call    read_process_memory
  2016.         pop     esi edx ecx eax
  2017.         ret
  2018. ;------------------------------------------------------------------------------
  2019. align 4
  2020. ;------------------------------------------------------------------------------
  2021. window._.window_activate: ;////////////////////////////////////////////////////
  2022. ;------------------------------------------------------------------------------
  2023. ;? Activate window
  2024. ;------------------------------------------------------------------------------
  2025. ;> esi = pointer to WIN_POS+ window data
  2026. ;------------------------------------------------------------------------------
  2027.         push    eax ebx
  2028.  
  2029.         ; if type of current active window is 3 or 4, it must be redrawn
  2030.         mov     ebx, [TASK_COUNT]
  2031.        
  2032. ;       DEBUGF  1, "K : TASK_COUNT (0x%x)\n", ebx
  2033.        
  2034.         movzx   ebx, word[WIN_POS + ebx * 2]
  2035.         shl     ebx, 5
  2036.         add     eax, window_data
  2037.         mov     al, [window_data + ebx + WDATA.fl_wstyle]
  2038.         and     al, 0x0f
  2039.         cmp     al, 0x03
  2040.         je      .set_window_redraw_flag
  2041.         cmp     al, 0x04
  2042.         jne     .move_others_down
  2043. ;--------------------------------------
  2044. align 4
  2045. .set_window_redraw_flag:
  2046.         mov     [window_data + ebx + WDATA.fl_redraw], 1
  2047. ;--------------------------------------
  2048. align 4
  2049. .move_others_down:
  2050.         ; ax <- process no
  2051.         movzx   ebx, word[esi]
  2052.         ; ax <- position in window stack
  2053.         movzx   ebx, word[WIN_STACK + ebx * 2]
  2054.  
  2055.         ; drop others
  2056.         xor     eax, eax
  2057. ;--------------------------------------
  2058. align 4
  2059. .next_stack_window:
  2060.         cmp     eax, [TASK_COUNT]
  2061.         jae     .move_self_up
  2062.         inc     eax
  2063.        
  2064. ;       push    ebx
  2065. ;       xor     ebx,ebx
  2066. ;       mov     bx,[WIN_STACK + eax * 2]
  2067. ;       DEBUGF  1, "K : DEC WIN_STACK (0x%x)\n",ebx
  2068. ;       pop     ebx
  2069.        
  2070.         cmp     [WIN_STACK + eax * 2], bx
  2071.         jbe     .next_stack_window
  2072.         dec     word[WIN_STACK + eax * 2]
  2073.         jmp     .next_stack_window
  2074. ;--------------------------------------
  2075. align 4
  2076. .move_self_up:
  2077.         movzx   ebx, word[esi]
  2078.         ; number of processes
  2079.         mov     ax, [TASK_COUNT]
  2080.         ; this is the last (and the upper)
  2081.         mov     [WIN_STACK + ebx * 2], ax
  2082.  
  2083.         ; update on screen - window stack
  2084.         xor     eax, eax
  2085. ;--------------------------------------
  2086. align 4
  2087. .next_window_pos:
  2088.         cmp     eax, [TASK_COUNT]
  2089.         jae     .reset_vars
  2090.         inc     eax
  2091.         movzx   ebx, word[WIN_STACK + eax * 2]
  2092.         mov     [WIN_POS + ebx * 2], ax
  2093.         jmp     .next_window_pos
  2094. ;--------------------------------------
  2095. align 4
  2096. .reset_vars:
  2097.         mov     byte[KEY_COUNT], 0
  2098.         mov     byte[BTN_COUNT], 0
  2099.         mov     word[MOUSE_SCROLL_H], 0
  2100.         mov     word[MOUSE_SCROLL_V], 0
  2101.  
  2102.         pop     ebx eax
  2103.         ret
  2104. ;------------------------------------------------------------------------------
  2105. window._.window_deactivate: ;////////////////////////////////////////////////////
  2106. ;------------------------------------------------------------------------------
  2107. ;? Deactivate window
  2108. ;------------------------------------------------------------------------------
  2109. ;> esi = pointer to WIN_POS+ window data
  2110. ;------------------------------------------------------------------------------
  2111.         push    eax ebx
  2112. ;--------------------------------------
  2113. align 4
  2114. .move_others_up:
  2115.         ; ax <- process no
  2116.         movzx   ebx, word[esi]
  2117.         ; ax <- position in window stack
  2118.         movzx   ebx, word[WIN_STACK + ebx * 2]
  2119.         ; up others
  2120.         xor     eax, eax
  2121. ;--------------------------------------
  2122. align 4
  2123. .next_stack_window:
  2124.         cmp     eax, [TASK_COUNT]
  2125.         jae     .move_self_down
  2126.         inc     eax
  2127.         cmp     [WIN_STACK + eax * 2], bx
  2128.         jae     .next_stack_window
  2129.         inc     word[WIN_STACK + eax * 2]
  2130.         jmp     .next_stack_window
  2131. ;--------------------------------------
  2132. align 4
  2133. .move_self_down:
  2134.         movzx   ebx, word[esi]
  2135.         ; this is the last (and the low)
  2136.         mov     [WIN_STACK + ebx * 2], word 1
  2137.         ; update on screen - window stack
  2138.         xor     eax, eax
  2139. ;--------------------------------------
  2140. align 4
  2141. .next_window_pos:
  2142.         cmp     eax, [TASK_COUNT]
  2143.         jae     .reset_vars
  2144.         inc     eax
  2145.         movzx   ebx, word[WIN_STACK + eax * 2]
  2146.         mov     [WIN_POS + ebx * 2], ax
  2147.         jmp     .next_window_pos
  2148. ;--------------------------------------
  2149. align 4
  2150. .reset_vars:
  2151.         mov     byte[KEY_COUNT], 0
  2152.         mov     byte[BTN_COUNT], 0
  2153.         mov     word[MOUSE_SCROLL_H], 0
  2154.         mov     word[MOUSE_SCROLL_V], 0
  2155.         pop     ebx eax
  2156.         ret
  2157. ;------------------------------------------------------------------------------
  2158. align 4
  2159. ;------------------------------------------------------------------------------
  2160. window._.check_window_draw: ;//////////////////////////////////////////////////
  2161. ;------------------------------------------------------------------------------
  2162. ;? Check if window is necessary to draw
  2163. ;------------------------------------------------------------------------------
  2164. ;> edi = pointer to WDATA
  2165. ;------------------------------------------------------------------------------
  2166.         mov     cl, [edi + WDATA.fl_wstyle]
  2167.         and     cl, 0x0f
  2168.         cmp     cl, 3
  2169.         je      .exit.redraw      ; window type 3
  2170.         cmp     cl, 4
  2171.         je      .exit.redraw      ; window type 4
  2172.  
  2173.         push    eax ebx edx esi
  2174.  
  2175.         mov     eax, edi
  2176.         sub     eax, window_data
  2177.         shr     eax, 5
  2178.  
  2179.         movzx   eax, word[WIN_STACK + eax * 2]  ; get value of the curr process
  2180.         lea     esi, [WIN_POS + eax * 2]        ; get address of this process at 0xC400
  2181. ;--------------------------------------
  2182. align 4
  2183. .next_window:
  2184.         add     esi, 2
  2185.  
  2186.         mov     eax, [TASK_COUNT]
  2187.         lea     eax, word[WIN_POS + eax * 2] ; number of the upper window
  2188.  
  2189.         cmp     esi, eax
  2190.         ja      .exit.no_redraw
  2191.  
  2192.         movzx   edx, word[esi]
  2193.         shl     edx, 5
  2194.         cmp     [CURRENT_TASK + edx + TASKDATA.state], TSTATE_FREE
  2195.         je      .next_window
  2196.  
  2197.         mov     eax, [edi + WDATA.box.top]
  2198.         mov     ebx, [edi + WDATA.box.height]
  2199.         add     ebx, eax
  2200.  
  2201.         mov     ecx, [window_data + edx + WDATA.box.top]
  2202.         cmp     ecx, ebx
  2203.         jge     .next_window
  2204.         add     ecx, [window_data + edx + WDATA.box.height]
  2205.         cmp     eax, ecx
  2206.         jge     .next_window
  2207.  
  2208.         mov     eax, [edi + WDATA.box.left]
  2209.         mov     ebx, [edi + WDATA.box.width]
  2210.         add     ebx, eax
  2211.  
  2212.         mov     ecx, [window_data + edx + WDATA.box.left]
  2213.         cmp     ecx, ebx
  2214.         jge     .next_window
  2215.         add     ecx, [window_data + edx + WDATA.box.width]
  2216.         cmp     eax, ecx
  2217.         jge     .next_window
  2218.  
  2219.         pop     esi edx ebx eax
  2220. ;--------------------------------------
  2221. align 4
  2222. .exit.redraw:
  2223.         xor     ecx, ecx
  2224.         inc     ecx
  2225.         ret
  2226. ;--------------------------------------
  2227. align 4
  2228. .exit.no_redraw:
  2229.         pop     esi edx ebx eax
  2230.         xor     ecx, ecx
  2231.         ret
  2232. ;------------------------------------------------------------------------------
  2233. align 4
  2234. ;------------------------------------------------------------------------------
  2235. window._.draw_window_caption: ;////////////////////////////////////////////////
  2236. ;------------------------------------------------------------------------------
  2237. ;? <description>
  2238. ;------------------------------------------------------------------------------
  2239.         xor     eax, eax
  2240.         mov     edx, [TASK_COUNT]
  2241.         movzx   edx, word[WIN_POS + edx * 2]
  2242.         cmp     edx, [CURRENT_TASK]
  2243.         jne     @f
  2244.         inc     eax
  2245. ;--------------------------------------
  2246. align 4
  2247. @@:
  2248.         mov     edx, [CURRENT_TASK]
  2249.         shl     edx, 5
  2250.         add     edx, window_data
  2251.         movzx   ebx, [edx + WDATA.fl_wstyle]
  2252.         and     bl, 0x0F
  2253.         cmp     bl, 3
  2254.         je      .draw_caption_style_3
  2255.         cmp     bl, 4
  2256.         je      .draw_caption_style_3
  2257.  
  2258.         jmp     .not_style_3
  2259. ;--------------------------------------
  2260. align 4
  2261. .draw_caption_style_3:
  2262.         push    edx
  2263.         call    drawwindow_IV_caption
  2264.         add     esp, 4
  2265.         jmp     .2
  2266. ;--------------------------------------
  2267. align 4
  2268. .not_style_3:
  2269.         cmp     bl, 2
  2270.         jne     .not_style_2
  2271.  
  2272.         call    drawwindow_III_caption
  2273.         jmp     .2
  2274. ;--------------------------------------
  2275. align 4
  2276. .not_style_2:
  2277.         cmp     bl, 0
  2278.         jne     .2
  2279.  
  2280.         call    drawwindow_I_caption
  2281. ;--------------------------------------
  2282. align 4
  2283. .2:
  2284.         mov     edi, [CURRENT_TASK]
  2285.         shl     edi, 5
  2286.         test    [edi + window_data + WDATA.fl_wstyle], WSTYLE_HASCAPTION
  2287.         jz      .exit
  2288.         mov     edx, [edi * 8 + SLOT_BASE + APPDATA.wnd_caption]
  2289.         or      edx, edx
  2290.         jz      .exit
  2291.  
  2292.         movzx   eax, [edi + window_data + WDATA.fl_wstyle]
  2293.         and     al, 0x0F
  2294.         cmp     al, 3
  2295.         je      .skinned
  2296.         cmp     al, 4
  2297.         je      .skinned
  2298.  
  2299.         jmp     .not_skinned
  2300. ;--------------------------------------
  2301. align 4
  2302. .skinned:
  2303.         mov     ebp, [edi + window_data + WDATA.box.left - 2]
  2304.         mov     bp, word[edi + window_data + WDATA.box.top]
  2305.         movzx   eax, word[edi + window_data + WDATA.box.width]
  2306.         sub     ax, [_skinmargins.left]
  2307.         sub     ax, [_skinmargins.right]
  2308.         push    edx
  2309.         cwde
  2310.         cdq
  2311.         mov     ebx, 6
  2312.         idiv    ebx
  2313.         pop     edx
  2314.         or      eax, eax
  2315.         js      .exit
  2316.  
  2317.         mov     esi, eax
  2318.         mov     ebx, dword[_skinmargins.left - 2]
  2319.         mov     bx, word[_skinh]
  2320.         sub     bx, [_skinmargins.bottom]
  2321.         sub     bx, [_skinmargins.top]
  2322.         sar     bx, 1
  2323.         adc     bx, 0
  2324.         add     bx, [_skinmargins.top]
  2325.         add     bx, -3
  2326.         add     ebx, ebp
  2327.         jmp     .dodraw
  2328. ;--------------------------------------
  2329. align 4
  2330. .not_skinned:
  2331.         cmp     al, 1
  2332.         je      .exit
  2333.  
  2334.         mov     ebp, [edi + window_data + WDATA.box.left - 2]
  2335.         mov     bp, word[edi + window_data + WDATA.box.top]
  2336.         movzx   eax, word[edi + window_data + WDATA.box.width]
  2337.         sub     eax, 16
  2338.         push    edx
  2339.         cwde
  2340.         cdq
  2341.         mov     ebx, 6
  2342.         idiv    ebx
  2343.         pop     edx
  2344.         or      eax, eax
  2345.         js      .exit
  2346.  
  2347.         mov     esi, eax
  2348.         mov     ebx, 0x00080007
  2349.         add     ebx, ebp
  2350. ;--------------------------------------
  2351. align 4
  2352. .dodraw:
  2353.         mov     ecx, [common_colours + 16]
  2354.         or      ecx, 0x80000000
  2355.         xor     edi, edi
  2356.         call    dtext_asciiz_esi
  2357. ;--------------------------------------
  2358. align 4
  2359. .exit:
  2360. ;        call    [draw_pointer]
  2361.         call    __sys_draw_pointer
  2362.         ret
  2363. ;------------------------------------------------------------------------------
  2364. align 4
  2365. ;------------------------------------------------------------------------------
  2366. window._.draw_negative_box: ;//////////////////////////////////////////////////
  2367. ;------------------------------------------------------------------------------
  2368. ;? Draw negative box
  2369. ;------------------------------------------------------------------------------
  2370. ;> edi = pointer to BOX struct
  2371. ;------------------------------------------------------------------------------
  2372.         push    eax ebx esi
  2373.         mov     esi, 0x01000000
  2374. ;--------------------------------------
  2375. align 4
  2376. .1:
  2377.         mov     eax, [edi + BOX.left - 2]
  2378.         mov     ax, word[edi + BOX.left]
  2379.         add     ax, word[edi + BOX.width]
  2380.         mov     ebx, [edi + BOX.top - 2]
  2381.         mov     bx, word[edi + BOX.top]
  2382.         add     bx, word[edi + BOX.height]
  2383.         call    draw_rectangle.forced
  2384.         pop     esi ebx eax
  2385.         ret
  2386. ;------------------------------------------------------------------------------
  2387. ;align 4
  2388. ;------------------------------------------------------------------------------
  2389. ;window._.end_moving__box: ;//////////////////////////////////////////////////
  2390. ;------------------------------------------------------------------------------
  2391. ;? Draw positive box
  2392. ;------------------------------------------------------------------------------
  2393. ;> edi = pointer to BOX struct
  2394. ;------------------------------------------------------------------------------
  2395. ;        push    eax ebx esi
  2396. ;        xor     esi, esi
  2397. ;        jmp     window._.draw_negative_box.1
  2398. ;------------------------------------------------------------------------------
  2399. align 4
  2400. ;------------------------------------------------------------------------------
  2401. window._.get_rect: ;/////////////////////////////////////////////////////
  2402. ;------------------------------------------------------------------------------
  2403. ;? <description>  void __fastcall get_window_rect(struct RECT* rc);
  2404. ;------------------------------------------------------------------------------
  2405. ;> ecx = pointer to RECT
  2406. ;------------------------------------------------------------------------------
  2407.         mov     eax, [TASK_BASE]
  2408.  
  2409.         mov     edx, [eax-twdw + WDATA.box.left]
  2410.         mov     [ecx+RECT.left], edx
  2411.  
  2412.         add     edx, [eax-twdw + WDATA.box.width]
  2413.         mov     [ecx+RECT.right], edx
  2414.  
  2415.         mov     edx, [eax-twdw + WDATA.box.top]
  2416.         mov     [ecx+RECT.top], edx
  2417.  
  2418.         add     edx, [eax-twdw + WDATA.box.height]
  2419.         mov     [ecx+RECT.bottom], edx
  2420.         ret
  2421. ;------------------------------------------------------------------------------
  2422.