Subversion Repositories Kolibri OS

Rev

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