Subversion Repositories Kolibri OS

Rev

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

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