Subversion Repositories Kolibri OS

Rev

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