Subversion Repositories Kolibri OS

Rev

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

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