Subversion Repositories Kolibri OS

Rev

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