Subversion Repositories Kolibri OS

Rev

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