Subversion Repositories Kolibri OS

Rev

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