Subversion Repositories Kolibri OS

Rev

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

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