Subversion Repositories Kolibri OS

Rev

Rev 8866 | Rev 8928 | 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: 8869 $
  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.         jnz     @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.         jnz     @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.         mov     [edi + WDATA.box.width], esi
  1690.         jmp     .check_left
  1691. ;--------------------------------------
  1692. align 4
  1693. .fix_left_low:
  1694.         xor     eax, eax
  1695.         mov     [edi + WDATA.box.left], eax
  1696.         jmp     .check_height
  1697. ;--------------------------------------
  1698. align 4
  1699. .fix_left_high:
  1700.         mov     eax, esi
  1701.         sub     eax, ecx
  1702.         mov     [edi + WDATA.box.left], eax
  1703.         jmp     .check_height
  1704. ;--------------------------------------
  1705. align 4
  1706. .fix_height_high:
  1707.         mov     edx, esi
  1708.         mov     [edi + WDATA.box.height], esi
  1709.         jmp     .check_top
  1710. ;--------------------------------------
  1711. align 4
  1712. .fix_top_low:
  1713.         xor     ebx, ebx
  1714.         mov     [edi + WDATA.box.top], ebx
  1715.         jmp     .exit
  1716. ;--------------------------------------
  1717. align 4
  1718. .fix_top_high:
  1719.         mov     ebx, esi
  1720.         sub     ebx, edx
  1721.         mov     [edi + WDATA.box.top], ebx
  1722.         jmp     .exit
  1723. ;------------------------------------------------------------------------------
  1724. align 4
  1725. ;------------------------------------------------------------------------------
  1726. window._.get_titlebar_height: ;////////////////////////////////////////////////
  1727. ;------------------------------------------------------------------------------
  1728. ;? <description>
  1729. ;------------------------------------------------------------------------------
  1730. ;> edi = pointer to WDATA
  1731. ;------------------------------------------------------------------------------
  1732.         mov     al, [edi + WDATA.fl_wstyle]
  1733.         and     al, 0x0f
  1734.         cmp     al, 0x03
  1735.         jne     @f
  1736.         mov     eax, [_skinh]
  1737.         ret
  1738. ;--------------------------------------
  1739. align 4
  1740. @@:
  1741.         mov     eax, 21
  1742.         ret
  1743. ;------------------------------------------------------------------------------
  1744. align 4
  1745. ;------------------------------------------------------------------------------
  1746. window._.get_rolledup_height: ;////////////////////////////////////////////////
  1747. ;------------------------------------------------------------------------------
  1748. ;? <description>
  1749. ;------------------------------------------------------------------------------
  1750. ;> edi = pointer to WDATA
  1751. ;------------------------------------------------------------------------------
  1752.         mov     al, [edi + WDATA.fl_wstyle]
  1753.         and     al, 0x0f
  1754.         cmp     al, 0x03
  1755.         jb      @f
  1756.         mov     eax, [_skinh]
  1757.         add     eax, 3
  1758.         ret
  1759. ;--------------------------------------
  1760. align 4
  1761. @@:
  1762.         or      al, al
  1763.         jnz     @f
  1764.         mov     eax, 21
  1765.         ret
  1766. ;--------------------------------------
  1767. align 4
  1768. @@:
  1769.         mov     eax, 21 + 2
  1770.         ret
  1771. ;------------------------------------------------------------------------------
  1772. align 4
  1773. ;------------------------------------------------------------------------------
  1774. window._.set_screen: ;/////////////////////////////////////////////////////////
  1775. ;------------------------------------------------------------------------------
  1776. ;? Reserve window area in screen buffer
  1777. ;------------------------------------------------------------------------------
  1778. ;> eax = left
  1779. ;> ebx = top
  1780. ;> ecx = right
  1781. ;> edx = bottom
  1782. ;> esi = process number
  1783. ;------------------------------------------------------------------------------
  1784. virtual at esp
  1785.   ff_x     dd ?
  1786.   ff_y     dd ?
  1787.   ff_width dd ?
  1788.   ff_xsz   dd ?
  1789.   ff_ysz   dd ?
  1790.   ff_scale dd ?
  1791. end virtual
  1792.  
  1793.         pushad
  1794.  
  1795.         cmp     esi, 1
  1796.         jz      .check_for_shaped_window
  1797.         mov     edi, esi
  1798.         shl     edi, 5
  1799.         cmp     [window_data + edi + WDATA.box.width], 0
  1800.         jnz     .check_for_shaped_window
  1801.         cmp     [window_data + edi + WDATA.box.height], 0
  1802.         jz      .exit
  1803. ;--------------------------------------
  1804. align 4
  1805. .check_for_shaped_window:
  1806.         mov     edi, esi
  1807.         shl     edi, 8
  1808.         add     edi, SLOT_BASE
  1809.         cmp     [edi + APPDATA.wnd_shape], 0
  1810.         jne     .shaped_window
  1811.  
  1812.         ; get x&y size
  1813.         sub     ecx, eax
  1814.         sub     edx, ebx
  1815.         inc     ecx
  1816.         inc     edx
  1817.  
  1818.         ; get WinMap start
  1819.         push    esi
  1820.         mov     esi, [_display.width]
  1821.         mov     edi, [d_width_calc_area + ebx*4]
  1822.  
  1823.         add     edi, eax
  1824.         add     edi, [_display.win_map]
  1825.         pop     eax
  1826.         mov     ah, al
  1827.         push    ax
  1828.         shl     eax, 16
  1829.         pop     ax
  1830. ;--------------------------------------
  1831. align 4
  1832. .next_line:
  1833.         push    ecx
  1834.         shr     ecx, 2
  1835.         rep stosd
  1836.         mov     ecx, [esp]
  1837.         and     ecx, 3
  1838.         rep stosb
  1839.         pop     ecx
  1840.         add     edi, esi
  1841.         sub     edi, ecx
  1842.         dec     edx
  1843.         jnz     .next_line
  1844.  
  1845.         jmp     .exit
  1846. ;--------------------------------------
  1847. align 4
  1848. .shaped_window:
  1849.         ;  for (y=0; y <= x_size; y++)
  1850.         ;      for (x=0; x <= x_size; x++)
  1851.         ;          if (shape[coord(x,y,scale)]==1)
  1852.         ;             set_pixel(x, y, process_number);
  1853.  
  1854.         sub     ecx, eax
  1855.         sub     edx, ebx
  1856.         inc     ecx
  1857.         inc     edx
  1858.  
  1859.         push    [edi + APPDATA.wnd_shape_scale]  ; push scale first -> for loop
  1860.  
  1861.         ; get WinMap start  -> ebp
  1862.         push    eax
  1863.         mov     eax, [d_width_calc_area + ebx*4]
  1864.  
  1865.         add     eax, [esp]
  1866.         add     eax, [_display.win_map]
  1867.         mov     ebp, eax
  1868.  
  1869.         mov     edi, [edi + APPDATA.wnd_shape]
  1870.         pop     eax
  1871.  
  1872.         ; eax = x_start
  1873.         ; ebx = y_start
  1874.         ; ecx = x_size
  1875.         ; edx = y_size
  1876.         ; esi = process_number
  1877.         ; edi = &shape
  1878.         ;       [scale]
  1879.         push    edx ecx ; for loop - x,y size
  1880.  
  1881.         mov     ecx, esi
  1882.         shl     ecx, 5
  1883.         mov     edx, [window_data + ecx + WDATA.box.top]
  1884.         push    [window_data + ecx + WDATA.box.width]           ; for loop - width
  1885.         mov     ecx, [window_data + ecx + WDATA.box.left]
  1886.         sub     ebx, edx
  1887.         sub     eax, ecx
  1888.         push    ebx eax ; for loop - x,y
  1889.  
  1890.         add     [ff_xsz], eax
  1891.         add     [ff_ysz], ebx
  1892.  
  1893.         mov     ebx, [ff_y]
  1894. ;--------------------------------------
  1895. align 4
  1896. .ff_new_y:
  1897.         mov     edx, [ff_x]
  1898. ;--------------------------------------
  1899. align 4
  1900. .ff_new_x:
  1901.         ; -- body --
  1902.         mov     ecx, [ff_scale]
  1903.         mov     eax, [ff_width]
  1904.         inc     eax
  1905.         shr     eax, cl
  1906.         push    ebx edx
  1907.         shr     ebx, cl
  1908.         shr     edx, cl
  1909.         imul    eax, ebx
  1910.         add     eax, edx
  1911.         pop     edx ebx
  1912.         add     eax, edi
  1913.         call    .read_byte
  1914.         test    al, al
  1915.         jz      @f
  1916.         mov     eax, esi
  1917.         mov     [ebp], al
  1918.         ; -- end body --
  1919. ;--------------------------------------
  1920. align 4
  1921. @@:
  1922.         inc     ebp
  1923.         inc     edx
  1924.         cmp     edx, [ff_xsz]
  1925.         jb      .ff_new_x
  1926.  
  1927.         sub     ebp, [ff_xsz]
  1928.         add     ebp, [ff_x]
  1929.         add     ebp, [_display.width]  ; screen.x
  1930.         inc     ebx
  1931.         cmp     ebx, [ff_ysz]
  1932.         jb      .ff_new_y
  1933.  
  1934.         add     esp, 24
  1935. ;--------------------------------------
  1936. align 4
  1937. .exit:
  1938.         popad
  1939.         inc     [_display.mask_seqno]
  1940.         ret
  1941. ;--------------------------------------
  1942. align 4
  1943. .read_byte:
  1944.         ; eax - address
  1945.         ; esi - slot
  1946.         push    eax ecx edx esi
  1947.         xchg    eax, esi
  1948.         lea     ecx, [esp + 12]
  1949.         mov     edx, 1
  1950.         call    read_process_memory
  1951.         pop     esi edx ecx eax
  1952.         ret
  1953. ;------------------------------------------------------------------------------
  1954. align 4
  1955. ;------------------------------------------------------------------------------
  1956. window._.window_activate: ;////////////////////////////////////////////////////
  1957. ;------------------------------------------------------------------------------
  1958. ;? Activate window
  1959. ;------------------------------------------------------------------------------
  1960. ;> esi = pointer to WIN_POS+ window data
  1961. ;------------------------------------------------------------------------------
  1962.         push    eax ebx
  1963.  
  1964.         ; if type of current active window is 3 or 4, it must be redrawn
  1965.         mov     ebx, [thread_count]
  1966.  
  1967. ;       DEBUGF  1, "K : thread_count (0x%x)\n", ebx
  1968.  
  1969.         movzx   ebx, word[WIN_POS + ebx * 2]
  1970.         shl     ebx, 5
  1971.         add     eax, window_data
  1972.         mov     al, [window_data + ebx + WDATA.fl_wstyle]
  1973.         and     al, 0x0f
  1974.         cmp     al, 0x03
  1975.         je      .set_window_redraw_flag
  1976.         cmp     al, 0x04
  1977.         jne     .move_others_down
  1978. ;--------------------------------------
  1979. align 4
  1980. .set_window_redraw_flag:
  1981.         mov     [window_data + ebx + WDATA.fl_redraw], 1
  1982. ;--------------------------------------
  1983. align 4
  1984. .move_others_down:
  1985.         ; bx <- process no
  1986.         movzx   ebx, word[esi]
  1987.         ; bx <- position in window stack
  1988.         movzx   ebx, word[WIN_STACK + ebx * 2]
  1989.  
  1990.         ; drop others
  1991.         xor     eax, eax
  1992. ;--------------------------------------
  1993. align 4
  1994. .next_stack_window:
  1995.         cmp     eax, [thread_count]
  1996.         jae     .move_self_up
  1997.         inc     eax
  1998.  
  1999. ;       push    ebx
  2000. ;       xor     ebx,ebx
  2001. ;       mov     bx,[WIN_STACK + eax * 2]
  2002. ;       DEBUGF  1, "K : DEC WIN_STACK (0x%x)\n",ebx
  2003. ;       pop     ebx
  2004.  
  2005.         cmp     [WIN_STACK + eax * 2], bx
  2006.         jbe     .next_stack_window
  2007.         dec     word[WIN_STACK + eax * 2]
  2008.         jmp     .next_stack_window
  2009. ;--------------------------------------
  2010. align 4
  2011. .move_self_up:
  2012.         movzx   ebx, word[esi]
  2013.         ; number of thread
  2014.         mov     ax, word [thread_count]
  2015.         ; this is the last (and the upper)
  2016.         mov     [WIN_STACK + ebx * 2], ax
  2017.  
  2018.         ; update on screen - window stack
  2019.         xor     eax, eax
  2020. ;--------------------------------------
  2021. align 4
  2022. .next_window_pos:
  2023.         cmp     eax, [thread_count]
  2024.         jae     .reset_vars
  2025.         inc     eax
  2026.         movzx   ebx, word[WIN_STACK + eax * 2]
  2027.         mov     [WIN_POS + ebx * 2], ax
  2028.         jmp     .next_window_pos
  2029. ;--------------------------------------
  2030. align 4
  2031. .reset_vars:
  2032.         mov     byte[KEY_COUNT], 0
  2033.         mov     byte[BTN_COUNT], 0
  2034.         mov     word[MOUSE_SCROLL_H], 0
  2035.         mov     word[MOUSE_SCROLL_V], 0
  2036.  
  2037.         pop     ebx eax
  2038.         ret
  2039. ;------------------------------------------------------------------------------
  2040. window._.window_deactivate: ;////////////////////////////////////////////////////
  2041. ;------------------------------------------------------------------------------
  2042. ;? Deactivate window
  2043. ;------------------------------------------------------------------------------
  2044. ;> esi = pointer to WIN_POS+ window data
  2045. ;------------------------------------------------------------------------------
  2046.         push    eax ebx
  2047. ;--------------------------------------
  2048. align 4
  2049. .move_others_up:
  2050.         ; ax <- process no
  2051.         movzx   ebx, word[esi]
  2052.         ; ax <- position in window stack
  2053.         movzx   ebx, word[WIN_STACK + ebx * 2]
  2054.         ; up others
  2055.         xor     eax, eax
  2056. ;--------------------------------------
  2057. align 4
  2058. .next_stack_window:
  2059.         cmp     eax, [thread_count]
  2060.         jae     .move_self_down
  2061.         inc     eax
  2062.         cmp     [WIN_STACK + eax * 2], bx
  2063.         jae     .next_stack_window
  2064.         inc     word[WIN_STACK + eax * 2]
  2065.         jmp     .next_stack_window
  2066. ;--------------------------------------
  2067. align 4
  2068. .move_self_down:
  2069.         movzx   ebx, word[esi]
  2070.         ; this is the last (and the low)
  2071.         mov     [WIN_STACK + ebx * 2], word 1
  2072.         ; update on screen - window stack
  2073.         xor     eax, eax
  2074. ;--------------------------------------
  2075. align 4
  2076. .next_window_pos:
  2077.         cmp     eax, [thread_count]
  2078.         jae     .reset_vars
  2079.         inc     eax
  2080.         movzx   ebx, word[WIN_STACK + eax * 2]
  2081.         mov     [WIN_POS + ebx * 2], ax
  2082.         jmp     .next_window_pos
  2083. ;--------------------------------------
  2084. align 4
  2085. .reset_vars:
  2086.         mov     byte[KEY_COUNT], 0
  2087.         mov     byte[BTN_COUNT], 0
  2088.         mov     word[MOUSE_SCROLL_H], 0
  2089.         mov     word[MOUSE_SCROLL_V], 0
  2090.         pop     ebx eax
  2091.         ret
  2092. ;------------------------------------------------------------------------------
  2093. align 4
  2094. ;------------------------------------------------------------------------------
  2095. window._.check_window_draw: ;//////////////////////////////////////////////////
  2096. ;------------------------------------------------------------------------------
  2097. ;? Check if window is necessary to draw
  2098. ;------------------------------------------------------------------------------
  2099. ;> edi = pointer to WDATA
  2100. ;------------------------------------------------------------------------------
  2101.         mov     cl, [edi + WDATA.fl_wstyle]
  2102.         and     cl, 0x0f
  2103.         cmp     cl, 3
  2104.         je      .exit.redraw      ; window type 3
  2105.         cmp     cl, 4
  2106.         je      .exit.redraw      ; window type 4
  2107.  
  2108.         push    eax ebx edx esi
  2109.  
  2110.         mov     eax, edi
  2111.         sub     eax, window_data
  2112.         shr     eax, 5
  2113.  
  2114.         movzx   eax, word[WIN_STACK + eax * 2]  ; get value of the curr process
  2115.         lea     esi, [WIN_POS + eax * 2]        ; get address of this process at 0xC400
  2116. ;--------------------------------------
  2117. align 4
  2118. .next_window:
  2119.         add     esi, 2
  2120.  
  2121.         mov     eax, [thread_count]
  2122.         lea     eax, word[WIN_POS + eax * 2] ; number of the upper window
  2123.  
  2124.         cmp     esi, eax
  2125.         ja      .exit.no_redraw
  2126.  
  2127.         movzx   edx, word[esi]
  2128.         shl     edx, 5 ; size of TASKDATA and WDATA is 32 bytes
  2129.         cmp     byte [TASK_TABLE + edx + TASKDATA.state], TSTATE_FREE
  2130.         je      .next_window
  2131.  
  2132.         mov     eax, [edi + WDATA.box.top]
  2133.         mov     ebx, [edi + WDATA.box.height]
  2134.         add     ebx, eax
  2135.  
  2136.         mov     ecx, [window_data + edx + WDATA.box.top]
  2137.         cmp     ecx, ebx
  2138.         jge     .next_window
  2139.         add     ecx, [window_data + edx + WDATA.box.height]
  2140.         cmp     eax, ecx
  2141.         jge     .next_window
  2142.  
  2143.         mov     eax, [edi + WDATA.box.left]
  2144.         mov     ebx, [edi + WDATA.box.width]
  2145.         add     ebx, eax
  2146.  
  2147.         mov     ecx, [window_data + edx + WDATA.box.left]
  2148.         cmp     ecx, ebx
  2149.         jge     .next_window
  2150.         add     ecx, [window_data + edx + WDATA.box.width]
  2151.         cmp     eax, ecx
  2152.         jge     .next_window
  2153.  
  2154.         pop     esi edx ebx eax
  2155. ;--------------------------------------
  2156. align 4
  2157. .exit.redraw:
  2158.         xor     ecx, ecx
  2159.         inc     ecx
  2160.         ret
  2161. ;--------------------------------------
  2162. align 4
  2163. .exit.no_redraw:
  2164.         pop     esi edx ebx eax
  2165.         xor     ecx, ecx
  2166.         ret
  2167. ;------------------------------------------------------------------------------
  2168. align 4
  2169. ;------------------------------------------------------------------------------
  2170. window._.draw_window_caption: ;////////////////////////////////////////////////
  2171. ;------------------------------------------------------------------------------
  2172. ;? <description>
  2173. ;------------------------------------------------------------------------------
  2174.         xor     eax, eax
  2175.         mov     edx, [thread_count]
  2176.         movzx   edx, word[WIN_POS + edx * 2]
  2177.         cmp     edx, [current_slot_idx]
  2178.         jne     @f
  2179.         inc     eax
  2180. ;--------------------------------------
  2181. align 4
  2182. @@:
  2183.         mov     edx, [current_slot_idx]
  2184.         shl     edx, 5
  2185.         add     edx, window_data
  2186.         movzx   ebx, [edx + WDATA.fl_wstyle]
  2187.         and     bl, 0x0F
  2188.         cmp     bl, 3
  2189.         je      .draw_caption_style_3
  2190.         cmp     bl, 4
  2191.         je      .draw_caption_style_3
  2192.  
  2193.         jmp     .not_style_3
  2194. ;--------------------------------------
  2195. align 4
  2196. .draw_caption_style_3:
  2197.         push    edx
  2198.         call    drawwindow_IV_caption
  2199.         add     esp, 4
  2200.         jmp     .2
  2201. ;--------------------------------------
  2202. align 4
  2203. .not_style_3:
  2204.         cmp     bl, 2
  2205.         jne     .not_style_2
  2206.  
  2207.         call    drawwindow_III_caption
  2208.         jmp     .2
  2209. ;--------------------------------------
  2210. align 4
  2211. .not_style_2:
  2212.         cmp     bl, 0
  2213.         jne     .2
  2214.  
  2215.         call    drawwindow_I_caption
  2216. ;--------------------------------------
  2217. align 4
  2218. .2:
  2219.         mov     edi, [current_slot_idx]
  2220.         shl     edi, 5
  2221.         test    [edi + window_data + WDATA.fl_wstyle], WSTYLE_HASCAPTION
  2222.         jz      .exit
  2223.         mov     edx, [edi * 8 + SLOT_BASE + APPDATA.wnd_caption]
  2224.         or      edx, edx
  2225.         jz      .exit
  2226.  
  2227.         mov     ebp, [edi + window_data + WDATA.box.left - 2]
  2228.         mov     bp, word[edi + window_data + WDATA.box.top]
  2229.         movzx   eax, [edi + window_data + WDATA.fl_wstyle]
  2230.         and     al, 0x0F
  2231.         cmp     al, 3
  2232.         je      .skinned
  2233.         cmp     al, 4
  2234.         je      .skinned
  2235.  
  2236.         jmp     .not_skinned
  2237. ;--------------------------------------
  2238. align 4
  2239. .skinned:
  2240.         movzx   eax, word[edi + window_data + WDATA.box.width]
  2241.         sub     ax, [_skinmargins.left]
  2242.         sub     ax, [_skinmargins.right]
  2243.         js      .exit
  2244.         mov     ebx, dword[_skinmargins.left - 2]
  2245.         mov     bx, word[_skinh]
  2246.         sub     bx, [_skinmargins.bottom]
  2247.         sub     bx, [_skinmargins.top]
  2248.         sar     bx, 1
  2249.         add     bx, [_skinmargins.top]
  2250.         sub     bx, 8
  2251.         jmp     .dodraw
  2252. ;--------------------------------------
  2253. align 4
  2254. .not_skinned:
  2255.         cmp     al, 1
  2256.         je      .exit
  2257.         movzx   eax, word[edi + window_data + WDATA.box.width]
  2258.         sub     eax, 16
  2259.         js      .exit
  2260.         mov     ebx, 80002h
  2261. .dodraw:
  2262.         shr     eax, 3
  2263.         mov     esi, eax
  2264.         add     ebx, ebp
  2265.         mov     ecx, [common_colours + 16]
  2266.         mov     al, [edi*8 + SLOT_BASE + APPDATA.captionEncoding]
  2267.         test    al, al
  2268.         jnz     @f
  2269.         mov     al, 1
  2270.         cmp     byte [edx], 4
  2271.         jnc     @f
  2272.         mov     al, [edx]
  2273.         test    al, al
  2274.         jz      .exit
  2275.         inc     edx
  2276. @@:
  2277.         shl     eax, 28
  2278.         or      ecx, eax        
  2279.         xor     edi, edi
  2280.         stc
  2281.         call    dtext._
  2282. .exit:
  2283.         jmp     __sys_draw_pointer
  2284. ;------------------------------------------------------------------------------
  2285. align 4
  2286. ;------------------------------------------------------------------------------
  2287. window._.draw_negative_box: ;//////////////////////////////////////////////////
  2288. ;------------------------------------------------------------------------------
  2289. ;? Draw negative box
  2290. ;------------------------------------------------------------------------------
  2291. ;> edi = pointer to BOX struct
  2292. ;------------------------------------------------------------------------------
  2293.         push    eax ebx esi
  2294.         mov     esi, 0x01000000
  2295. ;--------------------------------------
  2296. align 4
  2297. .1:
  2298.         mov     eax, [edi + BOX.left - 2]
  2299.         mov     ax, word[edi + BOX.left]
  2300.         add     ax, word[edi + BOX.width]
  2301.         mov     ebx, [edi + BOX.top - 2]
  2302.         mov     bx, word[edi + BOX.top]
  2303.         add     bx, word[edi + BOX.height]
  2304.         call    draw_rectangle.forced
  2305.         pop     esi ebx eax
  2306.         ret
  2307. ;------------------------------------------------------------------------------
  2308. ;align 4
  2309. ;------------------------------------------------------------------------------
  2310. ;window._.end_moving__box: ;//////////////////////////////////////////////////
  2311. ;------------------------------------------------------------------------------
  2312. ;? Draw positive box
  2313. ;------------------------------------------------------------------------------
  2314. ;> edi = pointer to BOX struct
  2315. ;------------------------------------------------------------------------------
  2316. ;        push    eax ebx esi
  2317. ;        xor     esi, esi
  2318. ;        jmp     window._.draw_negative_box.1
  2319. ;------------------------------------------------------------------------------
  2320. align 4
  2321. ;------------------------------------------------------------------------------
  2322. window._.get_rect: ;/////////////////////////////////////////////////////
  2323. ;------------------------------------------------------------------------------
  2324. ;? <description>  void __fastcall get_window_rect(struct RECT* rc);
  2325. ;------------------------------------------------------------------------------
  2326. ;> ecx = pointer to RECT
  2327. ;------------------------------------------------------------------------------
  2328.         mov     eax, [TASK_BASE]
  2329.  
  2330.         mov     edx, [eax-twdw + WDATA.box.left]
  2331.         mov     [ecx+RECT.left], edx
  2332.  
  2333.         add     edx, [eax-twdw + WDATA.box.width]
  2334.         mov     [ecx+RECT.right], edx
  2335.  
  2336.         mov     edx, [eax-twdw + WDATA.box.top]
  2337.         mov     [ecx+RECT.top], edx
  2338.  
  2339.         add     edx, [eax-twdw + WDATA.box.height]
  2340.         mov     [ecx+RECT.bottom], edx
  2341.         ret
  2342. ;------------------------------------------------------------------------------
  2343. align 4
  2344. ;------------------------------------------------------------------------------
  2345. window._.redraw_top_wnd: ;////////////////////////////////////////////////////////
  2346. ;------------------------------------------------------------------------------
  2347. ;? redraw all windows one above the window
  2348. ;------------------------------------------------------------------------------
  2349. ;> eax = left
  2350. ;> ebx = top
  2351. ;> ecx = right
  2352. ;> edx = bottom
  2353. ;> esi = process number
  2354. ;! corrupted edi
  2355. ;------------------------------------------------------------------------------
  2356.         push    0
  2357.         jmp     window._.set_top_wnd.go
  2358.  
  2359. align 4
  2360. ;------------------------------------------------------------------------------
  2361. window._.set_top_wnd: ;////////////////////////////////////////////////////////
  2362. ;------------------------------------------------------------------------------
  2363. ;? call set_screen for all windows one above the window
  2364. ;------------------------------------------------------------------------------
  2365. ;> eax = left
  2366. ;> ebx = top
  2367. ;> ecx = right
  2368. ;> edx = bottom
  2369. ;> esi = process number
  2370. ;! corrupted edi
  2371. ;------------------------------------------------------------------------------
  2372.  
  2373.         push    1
  2374. .go:
  2375.         push    esi
  2376.         pushfd
  2377.         cli
  2378.  
  2379.         push    ebp
  2380.         mov     ebp, [thread_count]
  2381.         cmp     ebp, 1
  2382.         jbe     .exit
  2383.  
  2384.         shl     esi, 5
  2385.         cmp     [esi + window_data + WDATA.z_modif], ZPOS_ALWAYS_TOP
  2386.         je      .exit
  2387.  
  2388.         push    eax ;for num layout
  2389.         push    edx ecx ebx eax
  2390.  
  2391.         movsx   eax, byte [esi + window_data + WDATA.z_modif]
  2392.         inc     eax
  2393.         mov     dword[esp+10h], eax
  2394. ;--------------------------------------
  2395. align 4
  2396. .layout:
  2397.         mov     esi, 1        ; = num in window stack
  2398.         mov     ebp, [thread_count]
  2399. ;--------------------------------------
  2400. align 4
  2401. .next_window:
  2402.         movzx   edi, word[WIN_POS + esi * 2]
  2403.         shl     edi, 5                  ;size of TASKDATA and WDATA = 32 bytes
  2404.  
  2405.         cmp     byte [TASK_TABLE + edi + TASKDATA.state], TSTATE_FREE
  2406.         je      .skip_window
  2407.  
  2408.         add     edi, window_data
  2409.         test    [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  2410.         jnz     .skip_window
  2411.  
  2412.         mov     eax, [esp+10h]
  2413.         cmp     [edi + WDATA.z_modif], al
  2414.         jne     .skip_window
  2415.  
  2416.         mov     eax, [edi + WDATA.box.left]
  2417.         cmp     eax, [esp + RECT.right]
  2418.         jg      .skip_window
  2419.         mov     ebx, [edi + WDATA.box.top]
  2420.         cmp     ebx, [esp + RECT.bottom]
  2421.         jg      .skip_window
  2422.         mov     ecx, [edi + WDATA.box.width]
  2423.         add     ecx, eax
  2424.         cmp     ecx, [esp + RECT.left]
  2425.         jl      .skip_window
  2426.         mov     edx, [edi + WDATA.box.height]
  2427.         add     edx, ebx
  2428.         cmp     edx, [esp + RECT.top]
  2429.         jl      .skip_window
  2430.  
  2431.         cmp     eax, [esp + RECT.left]
  2432.         jae     @f
  2433.         mov     eax, [esp + RECT.left]
  2434. ;--------------------------------------
  2435. align 4
  2436. @@:
  2437.         cmp     ebx, [esp + RECT.top]
  2438.         jae     @f
  2439.         mov     ebx, [esp + RECT.top]
  2440. ;--------------------------------------
  2441. align 4
  2442. @@:
  2443.         cmp     ecx, [esp + RECT.right]
  2444.         jbe     @f
  2445.         mov     ecx, [esp + RECT.right]
  2446. ;--------------------------------------
  2447. align 4
  2448. @@:
  2449.         cmp     edx, [esp + RECT.bottom]
  2450.         jbe     @f
  2451.         mov     edx, [esp + RECT.bottom]
  2452. ;--------------------------------------
  2453. align 4
  2454. @@:
  2455.         cmp     dword[esp+32], 0
  2456.         je      .set_fl_redraw
  2457.  
  2458.         push    esi
  2459.         movzx   esi, word[WIN_POS + esi * 2]
  2460.         call    window._.set_screen
  2461.         pop     esi
  2462.         jmp     @f
  2463. .set_fl_redraw:
  2464.         mov     [edi + WDATA.fl_redraw], 1      ;set redraw flag
  2465.      @@:
  2466. ;--------------------------------------
  2467. align 4
  2468. .skip_window:
  2469.         inc     esi
  2470.         dec     ebp
  2471.         jnz     .next_window
  2472. ;--------------------------------------
  2473.         inc     dword[esp+10h]
  2474.         cmp     byte[esp+10h], ZPOS_ALWAYS_TOP
  2475.         jle     .layout
  2476. ;-------------------------------------
  2477.  
  2478.         pop     eax ebx ecx edx
  2479.         pop     ebp     ;del num layout
  2480. ;-------------------------------------
  2481. align 4
  2482. .exit:
  2483.  
  2484.         pop     ebp
  2485.         popfd
  2486.         pop     esi
  2487.  
  2488.         add     esp, 4   ;dword for 0/1 - set_screen/fl_redraw
  2489.         ret
  2490.  
  2491.  
  2492.  
  2493.