Subversion Repositories Kolibri OS

Rev

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