Subversion Repositories Kolibri OS

Rev

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