Subversion Repositories Kolibri OS

Rev

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

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