Subversion Repositories Kolibri OS

Rev

Rev 9911 | Rev 9930 | 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: 9926 $
  10.  
  11. ;==============================================================================
  12. ;     public functions
  13. ;==============================================================================
  14.  
  15. window.BORDER_SIZE = 5
  16.  
  17. uglobal
  18.   common_colours rd 48
  19.   draw_limits    RECT
  20. endg
  21. ;------------------------------------------------------------------------------
  22.  
  23.  
  24. align 4
  25. syscall_draw_window: ;     system function 0
  26.         mov     eax, edx
  27.         shr     eax, 24
  28.         and     al, 0x0f
  29.         cmp     al, 5
  30.         jae     .exit
  31.  
  32.         push    eax
  33.         call    window._.sys_set_window
  34.         pop     eax
  35.  
  36.         or      al, al
  37.         jnz     @f
  38.  
  39. ; type I - original style
  40.         call    drawwindow_I
  41.         jmp     window._.draw_window_caption.2
  42. ;--------------------------------------
  43. @@:
  44.         dec     al
  45.         jnz     @f
  46.  
  47. ; type II - only reserve area, no draw
  48.         call    __sys_draw_pointer
  49.         jmp     .exit
  50. ;--------------------------------------
  51. @@:
  52.         dec     al
  53.         jnz     @f
  54.  
  55. ; type III  - new style
  56.         call    drawwindow_III
  57.         jmp     window._.draw_window_caption.2
  58. ;--------------------------------------
  59. @@:
  60. ; type IV & V - skinned window (resizable & not)
  61.         mov     eax, [thread_count]
  62.         movzx   eax, word[WIN_POS + eax * 2]
  63.         cmp     eax, [current_slot_idx]
  64.         setz    al
  65.         movzx   eax, al
  66.         push    eax
  67.         call    drawwindow_IV
  68.         jmp     window._.draw_window_caption.2
  69. ;--------------------------------------
  70. .exit:
  71.         ret
  72. ;------------------------------------------------------------------------------
  73.  
  74.  
  75. align 4
  76. ; system function 1
  77. syscall_setpixel:  
  78.         mov     eax, ebx
  79.         mov     ebx, ecx
  80.         mov     ecx, edx
  81.         mov     edx, [current_slot_idx]
  82.         shl     edx, BSF sizeof.WDATA
  83.         add     eax, [window_data + edx + WDATA.box.left]
  84.         add     ebx, [window_data + edx + WDATA.box.top]
  85.         add     eax, [window_data + edx + WDATA.clientbox.left]
  86.         add     ebx, [window_data + 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_idx]
  107.         shl     eax, BSF sizeof.WDATA
  108.         mov     ebp, [window_data + eax + WDATA.box.left]
  109.         add     ebp, [window_data + eax + WDATA.clientbox.left]
  110.         shl     ebp, 16
  111.         add     ebp, [window_data + eax + WDATA.box.top]
  112.         add     bp, word[window_data + 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_idx]
  151.         shl     esi, BSF sizeof.WDATA
  152.         add     eax, [window_data + esi + WDATA.clientbox.left]
  153.         add     ebx, [window_data + 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_idx]
  165.         shl     edi, BSF sizeof.WDATA
  166.         movzx   eax, word[window_data + edi + WDATA.box.left]
  167.         mov     ebp, eax
  168.         add     ebp, [window_data + edi + WDATA.clientbox.left]
  169.         add     ax, word[window_data + edi + WDATA.clientbox.left]
  170.         add     ebp, ebx
  171.         shl     eax, 16
  172.         movzx   ebx, word[window_data + edi + WDATA.box.top]
  173.         add     eax, ebp
  174.         mov     ebp, ebx
  175.         add     ebp, [window_data + edi + WDATA.clientbox.top]
  176.         add     bx, word[window_data + 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, 13
  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.  
  210. .redrawWholeScreen:
  211.         xor     eax, eax
  212.         inc     ebx
  213.         cmp     [windowtypechanged], ebx
  214.         jne     .ret
  215.         mov     [windowtypechanged], eax
  216. .redrawScreen:
  217.         xor     eax, eax
  218.         mov     [draw_limits.left], eax
  219.         mov     [draw_limits.top], eax
  220.         mov     eax, [_display.width]
  221.         dec     eax
  222.         mov     [draw_limits.right], eax
  223.         mov     eax, [_display.height]
  224.         dec     eax
  225.         mov     [draw_limits.bottom], eax
  226.         mov     eax, window_data
  227.         jmp     redrawscreen
  228.  
  229. .setButtonStyle:
  230. ; in: ecx: 0 = flat, 1 = with gradient
  231.         and     ecx, 1
  232.         cmp     ecx, [buttontype]
  233.         je      .ret
  234.         mov     [buttontype], ecx
  235.         mov     [windowtypechanged], ebx
  236. .ret:
  237.         ret
  238.  
  239. .setSystemColors:
  240. ; in: ecx = pointer to color table, edx = size of color table
  241.         dec     ebx
  242.         mov     esi, ecx
  243.         cmp     edx, 192
  244.         jnae    @f
  245.         mov     edx, 192 ; max size
  246. @@:
  247.         stdcall is_region_userspace, esi, edx    ;
  248.         jz      @f                               ;
  249.         ret                                      ;
  250. @@:
  251.         mov     edi, common_colours
  252.         mov     ecx, edx
  253.         rep movsb
  254.         mov     [windowtypechanged], ebx
  255.         ret
  256.  
  257. .getSystemColors:
  258. ; in: ecx = pointer to color table, edx = size of color table
  259.         mov     edi, ecx
  260.         cmp     edx, 192
  261.         jnae    @f
  262.         mov     edx, 192 ; max size
  263. @@:
  264.         stdcall is_region_userspace, edi, edx
  265.         jz      @f
  266.         ret
  267. @@:
  268.         mov     esi, common_colours
  269.         mov     ecx, edx
  270.         rep movsb
  271.         ret
  272.  
  273. .getCaptionHeight:
  274.         mov     eax, [_skinh]
  275.         mov     [esp + SYSCALL_STACK.eax], eax
  276.         ret
  277.  
  278. .getScreenWorkingArea:
  279. ; out: eax = pack[left, right], ebx = pack[top, bottom]
  280.         mov     eax, [screen_workarea.left - 2]
  281.         mov     ax, word[screen_workarea.right]
  282.         mov     [esp + SYSCALL_STACK.eax], eax
  283.         mov     eax, [screen_workarea.top - 2]
  284.         mov     ax, word[screen_workarea.bottom]
  285.         mov     [esp + SYSCALL_STACK.ebx], eax
  286.         ret
  287.  
  288. .setScreenWorkingArea:
  289. ; in: ecx = pack[left, right], edx = pack[top, bottom]
  290.         xor     esi, esi
  291.         mov     edi, [_display.width]
  292.         dec     edi
  293.         mov     eax, ecx
  294.         movsx   ebx, ax
  295.         sar     eax, 16
  296.         cmp     eax, ebx
  297.         jge     .check_horizontal
  298.         inc     esi
  299.         or      eax, eax
  300.         jge     @f
  301.         xor     eax, eax
  302. @@:
  303.         mov     [screen_workarea.left], eax
  304.         cmp     ebx, edi
  305.         jle     @f
  306.         mov     ebx, edi
  307. @@:
  308.         mov     [screen_workarea.right], ebx
  309. .check_horizontal:
  310.         mov     edi, [_display.height]
  311.         dec     edi
  312.         mov     eax, edx
  313.         movsx   ebx, ax
  314.         sar     eax, 16
  315.         cmp     eax, ebx
  316.         jge     .check_if_redraw_needed
  317.         inc     esi
  318.         or      eax, eax
  319.         jge     @f
  320.         xor     eax, eax
  321. @@:
  322.         mov     [screen_workarea.top], eax
  323.         cmp     ebx, edi
  324.         jle     @f
  325.         mov     ebx, edi
  326. @@:
  327.         mov     [screen_workarea.bottom], ebx
  328. .check_if_redraw_needed:
  329.         or      esi, esi
  330.         jz      @f
  331.         call    repos_windows
  332. .calculateScreen:
  333.         xor     eax, eax
  334.         xor     ebx, ebx
  335.         mov     ecx, [_display.width]
  336.         mov     edx, [_display.height]
  337.         dec     ecx
  338.         dec     edx
  339.         jmp     calculatescreen
  340.  
  341. .getSkinMargins:
  342. ; out: eax = pack[left, right], ebx = pack[top, bottom]
  343.         mov     eax, [_skinmargins + 0]
  344.         mov     [esp + SYSCALL_STACK.eax], eax
  345.         mov     eax, [_skinmargins + 4]
  346.         mov     [esp + SYSCALL_STACK.ebx], eax
  347.         ret
  348.  
  349. .setSkin:
  350. ; in: ecx -> file path string
  351.         mov     ebx, ecx
  352.         call    read_skin_file
  353.         mov     [esp + SYSCALL_STACK.eax], eax
  354.         test    eax, eax
  355.         jnz     .ret
  356.         call    .calculateScreen
  357.         jmp     .redrawScreen
  358.  
  359. .getFontSmoothing:
  360.         xor     eax, eax
  361.         mov     al, [fontSmoothing]
  362.         mov     [esp + SYSCALL_STACK.eax], eax
  363.         ret
  364.  
  365. .setFontSmoothing:
  366.         mov     [fontSmoothing], cl
  367.         ret
  368.  
  369. .getFontSize:
  370.         xor     eax, eax
  371.         mov     al, [fontSize]
  372.         mov     [esp + SYSCALL_STACK.eax], eax
  373.         ret
  374.  
  375. .setFontSize:
  376.         mov     [fontSize], cl
  377.         ret
  378.  
  379. .setSkinUnicode:
  380. ; in: ecx -> file path string, edx = string encoding
  381.         push    ecx edx
  382.         stdcall kernel_alloc, maxPathLength
  383.         mov     edi, eax
  384.         pop     eax esi
  385.         push    edi
  386.         call    getFullPath
  387.         test    eax, eax
  388.         jz      @f
  389.         mov     ebx, [esp]
  390.         call    read_skin_file
  391.         mov     [esp + SYSCALL_STACK.eax + 4], eax
  392. @@:
  393.         call    kernel_free
  394.         call    .calculateScreen
  395.         jmp     .redrawScreen
  396.  
  397. ;------------------------------------------------------------------------------
  398.  
  399. align 4
  400. ; system function 50
  401. ;; Set window shape address:
  402. ;> ebx = 0
  403. ;> ecx = shape data address
  404. ; --------------------------
  405. ;; Set window shape scale:
  406. ;> ebx = 1
  407. ;> ecx = scale power (resulting scale is 2^ebx)
  408. syscall_set_window_shape:
  409.         mov     edi, [current_slot_idx]
  410.         shl     edi, BSF sizeof.WDATA
  411.  
  412.         test    ebx, ebx
  413.         jne     .shape_scale
  414.         mov     [window_data + edi + WDATA.shape], ecx
  415. ;--------------------------------------
  416. align 4
  417. .shape_scale:
  418.         dec     ebx
  419.         jnz     .exit
  420.         mov     [window_data + edi + WDATA.shape_scale], ecx
  421. ;--------------------------------------
  422. align 4
  423. .exit:
  424.         ret
  425. ;------------------------------------------------------------------------------
  426.  
  427. align 4
  428. ;     system function 67
  429. syscall_move_window:
  430.         mov     edi, [current_slot_idx]
  431.         shl     edi, BSF sizeof.WDATA
  432.         add     edi, window_data
  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_idx]
  487.         shl     edi, BSF sizeof.WDATA
  488.         or      [edi + window_data + 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     [window_data + edi + WDATA.caption], ecx
  498.         mov     [window_data + edi + WDATA.captionEncoding], dl
  499.         jmp     window._.draw_window_caption
  500. ;------------------------------------------------------------------------------
  501.  
  502. align 4
  503. set_window_defaults:
  504.         mov     byte [window_data + sizeof.WDATA + 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        ;size of TASKDATA and WDATA = 32 bytes
  559.  
  560.         cmp     byte [SLOT_BASE + edi*(sizeof.APPDATA/sizeof.WDATA) + APPDATA.state], TSTATE_FREE
  561.         je      .skip_window
  562.  
  563.         add     edi, window_data
  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.         cmp     byte [SLOT_BASE + edi*(sizeof.APPDATA/sizeof.WDATA) + APPDATA.state], TSTATE_FREE
  1090.         je      @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    [edi + window_data+WDATA.fl_wstate], WSTATE_MINIMIZED
  1097.         jnz     @f
  1098. ; no it's not, let's do that
  1099.         or      [edi + window_data+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.         jmp     .exit
  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.         mov     eax, esi
  1295.         shl     eax, BSF sizeof.APPDATA
  1296.         add     eax, SLOT_BASE + APPDATA.saved_box
  1297.         push    [eax + BOX.height] \
  1298.                 [eax + BOX.width] \
  1299.                 [eax + BOX.top] \
  1300.                 [eax + BOX.left]
  1301.         mov     eax, esp
  1302. ;--------------------------------------
  1303. align 4
  1304. .set_box:
  1305.         test    bl, WSTATE_ROLLEDUP
  1306.         jz      @f
  1307.  
  1308.         xchg    eax, ecx
  1309.         call    window._.get_rolledup_height
  1310.         mov     [ecx + BOX.height], eax
  1311.         xchg    eax, ecx
  1312. ;--------------------------------------
  1313. align 4
  1314. @@:
  1315.         call    window._.set_window_box
  1316.         add     esp, sizeof.BOX
  1317. ;--------------------------------------
  1318. align 4
  1319. .exit:
  1320.         inc     [_display.mask_seqno]
  1321.         ret
  1322. ;------------------------------------------------------------------------------
  1323.  
  1324.  
  1325. align 4
  1326. ;> esi = process slot
  1327. sys_window_rollup_handler:
  1328.         mov     edx, esi
  1329.         shl     edx, BSF sizeof.APPDATA
  1330.         add     edx, SLOT_BASE
  1331.  
  1332.         ; toggle normal/rolled up window state
  1333.         mov     bl, [edi + WDATA.fl_wstate]
  1334.         xor     bl, WSTATE_ROLLEDUP
  1335.  
  1336.         ; calculate and set appropriate window bounds
  1337.         test    bl, WSTATE_ROLLEDUP
  1338.         jz      .restore_size
  1339.  
  1340.         call    window._.get_rolledup_height
  1341.         push    eax \
  1342.                 [edi + WDATA.box.width] \
  1343.                 [edi + WDATA.box.top] \
  1344.                 [edi + WDATA.box.left]
  1345.         mov     eax, esp
  1346.         jmp     .set_box
  1347. ;--------------------------------------
  1348. align 4
  1349. .restore_size:
  1350.         test    bl, WSTATE_MAXIMIZED
  1351.         jnz     @f
  1352.         add     esp, -sizeof.BOX
  1353.         lea     eax, [edx + APPDATA.saved_box]
  1354.         jmp     .set_box
  1355. ;--------------------------------------
  1356. align 4
  1357. @@:
  1358.         mov     eax, [screen_workarea.top]
  1359.         push    [screen_workarea.bottom] \
  1360.                 [edi + WDATA.box.width] \
  1361.                 eax \
  1362.                 [edi + WDATA.box.left]
  1363.         sub     [esp + BOX.height], eax
  1364.         mov     eax, esp
  1365. ;--------------------------------------
  1366. align 4
  1367. .set_box:
  1368.         call    window._.set_window_box
  1369.         add     esp, sizeof.BOX
  1370.         ret
  1371. ;------------------------------------------------------------------------------
  1372. align 4
  1373. ;------------------------------------------------------------------------------
  1374. ;sys_window_start_moving_handler:
  1375. ;------------------------------------------------------------------------------
  1376. ;? <description>
  1377. ;------------------------------------------------------------------------------
  1378. ;> eax = old (original) window box
  1379. ;> esi = process slot
  1380. ;------------------------------------------------------------------------------
  1381. ;        mov     edi, eax
  1382. ;        call    window._.draw_negative_box
  1383. ;        ret
  1384. ;------------------------------------------------------------------------------
  1385.  
  1386.  
  1387. align 4
  1388. ;> eax = old (original) window box
  1389. ;> ebx = new (final) window box
  1390. ;> esi = process slot
  1391. sys_window_end_moving_handler:
  1392. ;        mov     edi, ebx
  1393. ;        call    window._.end_moving__box
  1394.  
  1395.         mov     edi, esi
  1396.         shl     edi, BSF sizeof.WDATA
  1397.         add     edi, window_data
  1398.  
  1399.         test    [fl_moving], 1
  1400.         jz      @f
  1401.  
  1402.         push    edi
  1403.         mov     edi, ebx
  1404.         call    window._.draw_negative_box
  1405.         pop     edi
  1406.     @@:
  1407.  
  1408.         mov     eax, ebx
  1409.         mov     bl, [edi + WDATA.fl_wstate]
  1410.         call    window._.set_window_box
  1411.         ret
  1412. ;------------------------------------------------------------------------------
  1413.  
  1414.  
  1415. align 4
  1416. ;> eax = old (from previous call) window box
  1417. ;> ebx = new (current) window box
  1418. ;> esi = process_slot
  1419. sys_window_moving_handler:
  1420.         mov     edi, eax
  1421.         call    window._.draw_negative_box
  1422.         mov     edi, ebx
  1423.         call    window._.draw_negative_box
  1424.         ret
  1425.  
  1426.  
  1427.  
  1428.  
  1429. ;==============================================================================
  1430. ;      private functions
  1431. ;==============================================================================
  1432.  
  1433. iglobal
  1434. align 4
  1435. window_topleft  dd \
  1436.     1, 21, \ ;type 0
  1437.     0,  0, \ ;type 1
  1438.     5, 20, \ ;type 2
  1439.     5,  ?, \ ;type 3 {set by skin}
  1440.     5,  ?    ;type 4 {set by skin}
  1441. endg
  1442.  
  1443. ;------------------------------------------------------------------------------
  1444.  
  1445.  
  1446. align 4
  1447. ;> eax = old (original) window box
  1448. ;> ebx = new (final) window box
  1449. ;> edi = pointer to WDATA struct
  1450. window._.invalidate_screen:
  1451.         push    eax ebx
  1452.  
  1453.         ; TODO: do we really need `draw_limits`?
  1454.         ; Yes, they are used by background drawing code.
  1455.  
  1456. ; we need only to restore the background windows at the old place!
  1457.         mov     ecx, [ebx + BOX.left]
  1458.         mov     [draw_limits.left], ecx
  1459.         add     ecx, [ebx + BOX.width]
  1460.         mov     [draw_limits.right], ecx
  1461.         mov     ecx, [ebx + BOX.top]
  1462.         mov     [draw_limits.top], ecx
  1463.         add     ecx, [ebx + BOX.height]
  1464.         mov     [draw_limits.bottom], ecx
  1465. ; recalculate screen buffer at old position
  1466.         push    ebx
  1467.         mov     edx, [eax + BOX.height]
  1468.         mov     ecx, [eax + BOX.width]
  1469.         mov     ebx, [eax + BOX.top]
  1470.         mov     eax, [eax + BOX.left]
  1471.         add     ecx, eax
  1472.         add     edx, ebx
  1473.         call    calculatescreen
  1474.         pop     eax
  1475. ; recalculate screen buffer at new position
  1476.         mov     edx, [eax + BOX.height]
  1477.         mov     ecx, [eax + BOX.width]
  1478.         mov     ebx, [eax + BOX.top]
  1479.         mov     eax, [eax + BOX.left]
  1480.         add     ecx, eax
  1481.         add     edx, ebx
  1482.         call    calculatescreen
  1483.  
  1484.         mov     eax, edi
  1485.         call    redrawscreen
  1486.  
  1487.         ; tell window to redraw itself
  1488.         mov     [edi + WDATA.fl_redraw], 1
  1489.  
  1490.         pop     ebx eax
  1491.         ret
  1492. ;------------------------------------------------------------------------------
  1493.  
  1494.  
  1495. align 4
  1496. ;> eax = pointer to BOX struct
  1497. ;> bl = new window state flags
  1498. ;> edi = pointer to WDATA struct
  1499. window._.set_window_box:
  1500.         push    eax ebx esi
  1501.  
  1502. ; don't do anything if the new box is identical to the old
  1503.         cmp     bl, [edi + WDATA.fl_wstate]
  1504.         jnz     @f
  1505.         mov     esi, eax
  1506.         push    edi
  1507. if WDATA.box
  1508.         add     edi, WDATA.box
  1509. end if
  1510.         mov     ecx, 4
  1511.         repz cmpsd
  1512.         pop     edi
  1513.         jz      .exit
  1514. ;--------------------------------------
  1515. align 4
  1516. @@:
  1517.         add     esp, -sizeof.BOX
  1518.         mov     ebx, esp
  1519. if WDATA.box
  1520.         lea     esi, [edi + WDATA.box]
  1521. else
  1522.         mov     esi, edi ; optimization for WDATA.box = 0
  1523. end if
  1524.         xchg    eax, esi
  1525.         mov     ecx, sizeof.BOX
  1526.         call    memmove
  1527.         xchg    eax, esi
  1528.         xchg    ebx, esi
  1529.         call    memmove
  1530.         mov     eax, ebx
  1531.         mov     ebx, esi
  1532.         call    window._.check_window_position
  1533.         call    window._.set_window_clientbox
  1534.         call    window._.invalidate_screen
  1535.  
  1536.         add     esp, sizeof.BOX
  1537.  
  1538.         mov     cl, [esp + 4]
  1539.         mov     ch, cl
  1540.         xchg    cl, [edi + WDATA.fl_wstate]
  1541.  
  1542.         or      cl, ch
  1543.         test    cl, WSTATE_MAXIMIZED
  1544.         jnz     .exit
  1545.  
  1546.         mov     eax, edi
  1547.         sub     eax, window_data
  1548.         shl     eax, (BSF sizeof.APPDATA - BSF sizeof.WDATA)
  1549.         add     eax, SLOT_BASE
  1550.  
  1551.         lea     ebx, [edi + WDATA.box]
  1552.         xchg    esp, ebx
  1553.  
  1554.         pop     [eax + APPDATA.saved_box.left] \
  1555.                 [eax + APPDATA.saved_box.top] \
  1556.                 [eax + APPDATA.saved_box.width] \
  1557.                 edx
  1558.  
  1559.         xchg    esp, ebx
  1560.  
  1561.         test    ch, WSTATE_ROLLEDUP
  1562.         jnz     .exit
  1563.  
  1564.         mov     [eax + APPDATA.saved_box.height], edx
  1565. ;--------------------------------------
  1566. align 4
  1567. .exit:
  1568.         pop     esi ebx eax
  1569.         ret
  1570. ;------------------------------------------------------------------------------
  1571.  
  1572.  
  1573. align 4
  1574. ;> edi = pointer to WDATA struct
  1575. window._.set_window_clientbox:
  1576.         push    eax ecx edi
  1577.  
  1578.         mov     eax, [_skinh]
  1579.         mov     [window_topleft + 8 * 3 + 4], eax
  1580.         mov     [window_topleft + 8 * 4 + 4], eax
  1581.  
  1582.         mov     ecx, edi
  1583.         test    [ecx + WDATA.fl_wstyle], WSTYLE_CLIENTRELATIVE
  1584.         jz      .whole_window
  1585.  
  1586.         movzx   eax, [ecx + WDATA.fl_wstyle]
  1587.         and     eax, 0x0F
  1588.         mov     eax, [eax * 8 + window_topleft + 0]
  1589.         mov     [ecx + WDATA.clientbox.left], eax
  1590.         shl     eax, 1
  1591.         neg     eax
  1592.         add     eax, [ecx + WDATA.box.width]
  1593.         inc     eax  ;Leency: as window is created width+1 so client the same
  1594.         mov     [ecx + WDATA.clientbox.width], eax
  1595.  
  1596.         movzx   eax, [ecx + WDATA.fl_wstyle]
  1597.         and     eax, 0x0F
  1598.         push    [eax * 8 + window_topleft + 0]
  1599.         mov     eax, [eax * 8 + window_topleft + 4]
  1600.         mov     [ecx + WDATA.clientbox.top], eax
  1601.         neg     eax
  1602.         sub     eax, [esp]
  1603.         add     eax, [ecx + WDATA.box.height]
  1604.         inc     eax  ;Leency: as window is created height+1 so client the same
  1605.         mov     [ecx + WDATA.clientbox.height], eax
  1606.         add     esp, 4
  1607.         jmp     .exit
  1608. ;--------------------------------------
  1609. align 4
  1610. .whole_window:
  1611.         xor     eax, eax
  1612.         mov     [ecx + WDATA.clientbox.left], eax
  1613.         mov     [ecx + WDATA.clientbox.top], eax
  1614.         mov     eax, [ecx + WDATA.box.width]
  1615.         mov     [ecx + WDATA.clientbox.width], eax
  1616.         mov     eax, [ecx + WDATA.box.height]
  1617.         mov     [ecx + WDATA.clientbox.height], eax
  1618. ;--------------------------------------
  1619. align 4
  1620. .exit:
  1621.         pop     edi ecx eax
  1622.         ret
  1623. ;------------------------------------------------------------------------------
  1624.  
  1625.  
  1626. align 4
  1627. ;< edx = pointer to WDATA struct
  1628. window._.sys_set_window:
  1629.         mov     eax, [current_slot_idx]
  1630.         shl     eax, BSF sizeof.WDATA
  1631.         add     eax, window_data
  1632. ; save window colors
  1633.         mov     [eax + WDATA.cl_workarea], edx
  1634.         mov     [eax + WDATA.cl_titlebar], esi
  1635.         mov     [eax + WDATA.cl_frames], edi
  1636.         mov     edi, eax
  1637. ; Was it already defined before?
  1638.         test    [edi + WDATA.fl_wdrawn], 1
  1639.         jnz     .set_client_box
  1640. ; No, it wasn't. After first draw_window we need redraw mouse necessarily!
  1641. ; Otherwise the user can see cursor specified by f.37.5 from another window.
  1642. ; He will be really unhappy! Usually, he will be enraged!
  1643.         or      [edi + WDATA.fl_wdrawn], 1
  1644.         mov     [redrawmouse_unconditional], 1
  1645.         call    wakeup_osloop
  1646. ; performing initial window definition
  1647.         movzx   eax, bx
  1648.         mov     [edi + WDATA.box.width], eax
  1649.         movzx   eax, cx
  1650.         mov     [edi + WDATA.box.height], eax
  1651.         sar     ebx, 16
  1652.         sar     ecx, 16
  1653.         mov     [edi + WDATA.box.left], ebx
  1654.         mov     [edi + WDATA.box.top], ecx
  1655.  
  1656.         call    window._.check_window_position
  1657.  
  1658.         push    ecx edi
  1659.  
  1660.         mov     cl, [edi + WDATA.fl_wstyle]
  1661.         mov     eax, [edi + WDATA.cl_frames]
  1662.  
  1663.         mov     esi, [esp]
  1664.         sub     edi, window_data
  1665.         shl     edi, (BSF sizeof.APPDATA - BSF sizeof.WDATA)
  1666.  
  1667.         and     cl, 0x0F
  1668.         cmp     cl, 3
  1669.         je      @f
  1670.         cmp     cl, 4
  1671.         je      @f
  1672.  
  1673.         xor     eax, eax
  1674. ;--------------------------------------
  1675. align 4
  1676. @@:
  1677.         mov     [esi + WDATA.caption], eax
  1678.  
  1679.         add     edi, SLOT_BASE + APPDATA.saved_box
  1680.         movsd
  1681.         movsd
  1682.         movsd
  1683.         movsd
  1684.  
  1685.         pop     edi ecx
  1686.  
  1687.         mov     esi, [current_slot_idx]
  1688.         movzx   esi, word[WIN_STACK + esi * 2]
  1689.         lea     esi, [WIN_POS + esi * 2]
  1690.         call    waredraw
  1691.  
  1692.         mov     eax, [edi + WDATA.box.left]
  1693.         mov     ebx, [edi + WDATA.box.top]
  1694.         mov     ecx, [edi + WDATA.box.width]
  1695.         mov     edx, [edi + WDATA.box.height]
  1696.         add     ecx, eax
  1697.         add     edx, ebx
  1698.         call    calculatescreen
  1699.  
  1700.         mov     byte[KEY_COUNT], 0           ; empty keyboard buffer
  1701.         mov     byte[BTN_COUNT], 0           ; empty button buffer
  1702. ;--------------------------------------
  1703. align 4
  1704. .set_client_box:
  1705.         ; update window client box coordinates
  1706.         call    window._.set_window_clientbox
  1707.  
  1708.         ; reset window redraw flag and exit
  1709.         mov     [edi + WDATA.fl_redraw], 0
  1710.         mov     edx, edi
  1711.         ret
  1712. ;------------------------------------------------------------------------------
  1713.  
  1714.  
  1715. align 4
  1716. ;? Check if window is inside screen area
  1717. ;> edi = pointer to WDATA
  1718. window._.check_window_position:
  1719.         push    eax ebx ecx edx esi
  1720.  
  1721.         mov     eax, [edi + WDATA.box.left]
  1722.         mov     ebx, [edi + WDATA.box.top]
  1723.         mov     ecx, [edi + WDATA.box.width]
  1724.         mov     edx, [edi + WDATA.box.height]
  1725.  
  1726.         mov     esi, [_display.width]
  1727.         cmp     ecx, esi
  1728.         jae     .fix_width_high
  1729. ;--------------------------------------
  1730. align 4
  1731. .check_left:
  1732.         or      eax, eax
  1733.         jl      .fix_left_low
  1734.         add     eax, ecx
  1735.         cmp     eax, esi
  1736.         jge     .fix_left_high
  1737. ;--------------------------------------
  1738. align 4
  1739. .check_height:
  1740.         mov     esi, [_display.height]
  1741.         cmp     edx, esi
  1742.         jae     .fix_height_high
  1743. ;--------------------------------------
  1744. align 4
  1745. .check_top:
  1746.         or      ebx, ebx
  1747.         jl      .fix_top_low
  1748.         add     ebx, edx
  1749.         cmp     ebx, esi
  1750.         jge     .fix_top_high
  1751. ;--------------------------------------
  1752. align 4
  1753. .exit:
  1754.         pop     esi edx ecx ebx eax
  1755.         ret
  1756. ;--------------------------------------
  1757. align 4
  1758. .fix_width_high:
  1759.         mov     ecx, esi
  1760.         dec     ecx
  1761.         mov     [edi + WDATA.box.width], ecx
  1762.         jmp     .check_left
  1763. ;--------------------------------------
  1764. align 4
  1765. .fix_left_low:
  1766.         xor     eax, eax
  1767.         mov     [edi + WDATA.box.left], eax
  1768.         jmp     .check_height
  1769. ;--------------------------------------
  1770. align 4
  1771. .fix_left_high:
  1772.         mov     eax, esi
  1773.         sub     eax, ecx
  1774.         dec     eax
  1775.         mov     [edi + WDATA.box.left], eax
  1776.         jmp     .check_height
  1777. ;--------------------------------------
  1778. align 4
  1779. .fix_height_high:
  1780.         mov     edx, esi
  1781.         dec     edx
  1782.         mov     [edi + WDATA.box.height], edx
  1783.         jmp     .check_top
  1784. ;--------------------------------------
  1785. align 4
  1786. .fix_top_low:
  1787.         xor     ebx, ebx
  1788.         mov     [edi + WDATA.box.top], ebx
  1789.         jmp     .exit
  1790. ;--------------------------------------
  1791. align 4
  1792. .fix_top_high:
  1793.         mov     ebx, esi
  1794.         sub     ebx, edx
  1795.         dec     ebx
  1796.         mov     [edi + WDATA.box.top], ebx
  1797.         jmp     .exit
  1798. ;------------------------------------------------------------------------------
  1799.  
  1800.  
  1801. align 4
  1802. ;> edi = pointer to WDATA
  1803. window._.get_titlebar_height:
  1804.         mov     al, [edi + WDATA.fl_wstyle]
  1805.         and     al, 0x0f
  1806.         cmp     al, 0x03
  1807.         jne     @f
  1808.         mov     eax, [_skinh]
  1809.         ret
  1810. ;--------------------------------------
  1811. align 4
  1812. @@:
  1813.         mov     eax, 21
  1814.         ret
  1815. ;------------------------------------------------------------------------------
  1816.  
  1817.  
  1818. align 4
  1819. ;> edi = pointer to WDATA
  1820. window._.get_rolledup_height:
  1821.         mov     al, [edi + WDATA.fl_wstyle]
  1822.         and     al, 0x0f
  1823.         cmp     al, 0x03
  1824.         jb      @f
  1825.         mov     eax, [_skinh]
  1826.         add     eax, 3
  1827.         ret
  1828. ;--------------------------------------
  1829. align 4
  1830. @@:
  1831.         or      al, al
  1832.         jnz     @f
  1833.         mov     eax, 21
  1834.         ret
  1835. ;--------------------------------------
  1836. align 4
  1837. @@:
  1838.         mov     eax, 21 + 2
  1839.         ret
  1840. ;------------------------------------------------------------------------------
  1841.  
  1842.  
  1843. align 4
  1844. ;? Reserve window area in screen buffer
  1845. ;> eax = left
  1846. ;> ebx = top
  1847. ;> ecx = right
  1848. ;> edx = bottom
  1849. ;> esi = process number
  1850. window._.set_screen:
  1851. virtual at esp
  1852.   ff_x     dd ?
  1853.   ff_y     dd ?
  1854.   ff_width dd ?
  1855.   ff_xsz   dd ?
  1856.   ff_ysz   dd ?
  1857.   ff_scale dd ?
  1858. end virtual
  1859.  
  1860.         pushad
  1861.  
  1862.         mov     edi, esi
  1863.         shl     edi, BSF sizeof.WDATA
  1864.  
  1865.         cmp     esi, 1
  1866.         jz      .check_for_shaped_window
  1867.  
  1868.         cmp     [window_data + edi + WDATA.box.width], 0
  1869.         jnz     .check_for_shaped_window
  1870.         cmp     [window_data + edi + WDATA.box.height], 0
  1871.         jz      .exit
  1872. ;--------------------------------------
  1873. align 4
  1874. .check_for_shaped_window:
  1875.         cmp     [window_data + edi + WDATA.shape], 0
  1876.         jne     .shaped_window
  1877.  
  1878.         ; get x&y size
  1879.         sub     ecx, eax
  1880.         sub     edx, ebx
  1881.         inc     ecx
  1882.         inc     edx
  1883.  
  1884.         ; get WinMap start
  1885.         push    esi
  1886.         mov     esi, [_display.width]
  1887.         mov     edi, [d_width_calc_area + ebx*4]
  1888.  
  1889.         add     edi, eax
  1890.         add     edi, [_display.win_map]
  1891.         pop     eax
  1892.         mov     ah, al
  1893.         push    ax
  1894.         shl     eax, 16
  1895.         pop     ax
  1896. ;--------------------------------------
  1897. align 4
  1898. .next_line:
  1899.         push    ecx
  1900.         shr     ecx, 2
  1901.         rep stosd
  1902.         mov     ecx, [esp]
  1903.         and     ecx, 3
  1904.         rep stosb
  1905.         pop     ecx
  1906.         add     edi, esi
  1907.         sub     edi, ecx
  1908.         dec     edx
  1909.         jnz     .next_line
  1910.  
  1911.         jmp     .exit
  1912. ;--------------------------------------
  1913. align 4
  1914. .shaped_window:
  1915.         ;  for (y=0; y <= x_size; y++)
  1916.         ;      for (x=0; x <= x_size; x++)
  1917.         ;          if (shape[coord(x,y,scale)]==1)
  1918.         ;             set_pixel(x, y, process_number);
  1919.  
  1920.         sub     ecx, eax
  1921.         sub     edx, ebx
  1922.         inc     ecx
  1923.         inc     edx
  1924.  
  1925.         push    [window_data + edi + WDATA.shape_scale]  ; push scale first -> for loop
  1926.  
  1927.         ; get WinMap start  -> ebp
  1928.         push    eax
  1929.         mov     eax, [d_width_calc_area + ebx*4]
  1930.  
  1931.         add     eax, [esp]
  1932.         add     eax, [_display.win_map]
  1933.         mov     ebp, eax
  1934.  
  1935.         mov     edi, [window_data + edi + WDATA.shape]
  1936.         pop     eax
  1937.  
  1938.         ; eax = x_start
  1939.         ; ebx = y_start
  1940.         ; ecx = x_size
  1941.         ; edx = y_size
  1942.         ; esi = process_number
  1943.         ; edi = &shape
  1944.         ;       [scale]
  1945.         push    edx ecx ; for loop - x,y size
  1946.  
  1947.         mov     ecx, esi
  1948.         shl     ecx, BSF sizeof.WDATA
  1949.         mov     edx, [window_data + ecx + WDATA.box.top]
  1950.         push    [window_data + ecx + WDATA.box.width]           ; for loop - width
  1951.         mov     ecx, [window_data + ecx + WDATA.box.left]
  1952.         sub     ebx, edx
  1953.         sub     eax, ecx
  1954.         push    ebx eax ; for loop - x,y
  1955.  
  1956.         add     [ff_xsz], eax
  1957.         add     [ff_ysz], ebx
  1958.  
  1959.         mov     ebx, [ff_y]
  1960. ;--------------------------------------
  1961. align 4
  1962. .ff_new_y:
  1963.         mov     edx, [ff_x]
  1964. ;--------------------------------------
  1965. align 4
  1966. .ff_new_x:
  1967.         ; -- body --
  1968.         mov     ecx, [ff_scale]
  1969.         mov     eax, [ff_width]
  1970.         inc     eax
  1971.         shr     eax, cl
  1972.         push    ebx edx
  1973.         shr     ebx, cl
  1974.         shr     edx, cl
  1975.         imul    eax, ebx
  1976.         add     eax, edx
  1977.         pop     edx ebx
  1978.         add     eax, edi
  1979.         call    .read_byte
  1980.         test    al, al
  1981.         jz      @f
  1982.         mov     eax, esi
  1983.         mov     [ebp], al
  1984.         ; -- end body --
  1985. ;--------------------------------------
  1986. align 4
  1987. @@:
  1988.         inc     ebp
  1989.         inc     edx
  1990.         cmp     edx, [ff_xsz]
  1991.         jb      .ff_new_x
  1992.  
  1993.         sub     ebp, [ff_xsz]
  1994.         add     ebp, [ff_x]
  1995.         add     ebp, [_display.width]  ; screen.x
  1996.         inc     ebx
  1997.         cmp     ebx, [ff_ysz]
  1998.         jb      .ff_new_y
  1999.  
  2000.         add     esp, 24
  2001. ;--------------------------------------
  2002. align 4
  2003. .exit:
  2004.         popad
  2005.         inc     [_display.mask_seqno]
  2006.         ret
  2007. ;--------------------------------------
  2008. align 4
  2009. .read_byte:
  2010.         ; eax - address
  2011.         ; esi - slot
  2012.         push    eax ecx edx esi
  2013.         xchg    eax, esi
  2014.         lea     ecx, [esp + 12]
  2015.         mov     edx, 1
  2016.         call    read_process_memory
  2017.         pop     esi edx ecx eax
  2018.         ret
  2019. ;------------------------------------------------------------------------------
  2020.  
  2021.  
  2022. align 4
  2023. ; Activate window
  2024. ; esi = pointer to WIN_POS+ window data
  2025. window._.window_activate:
  2026.         push    eax ebx
  2027.  
  2028.         ; if type of current active window is 3 or 4, it must be redrawn
  2029.         mov     ebx, [thread_count]
  2030.  
  2031. ;       DEBUGF  1, "K : thread_count (0x%x)\n", ebx
  2032.  
  2033.         movzx   ebx, word[WIN_POS + ebx * 2]
  2034.         shl     ebx, BSF sizeof.WDATA
  2035.         add     eax, window_data
  2036.         mov     al, [window_data + ebx + WDATA.fl_wstyle]
  2037.         and     al, 0x0f
  2038.         cmp     al, 0x03
  2039.         je      .set_window_redraw_flag
  2040.         cmp     al, 0x04
  2041.         jne     .move_others_down
  2042. ;--------------------------------------
  2043. align 4
  2044. .set_window_redraw_flag:
  2045.         mov     [window_data + ebx + WDATA.fl_redraw], 1
  2046. ;--------------------------------------
  2047. align 4
  2048. .move_others_down:
  2049.         ; bx <- process no
  2050.         movzx   ebx, word[esi]
  2051.         ; bx <- position in window stack
  2052.         movzx   ebx, word[WIN_STACK + ebx * 2]
  2053.  
  2054.         ; drop others
  2055.         xor     eax, eax
  2056. ;--------------------------------------
  2057. align 4
  2058. .next_stack_window:
  2059.         cmp     eax, [thread_count]
  2060.         jae     .move_self_up
  2061.         inc     eax
  2062.  
  2063. ;       push    ebx
  2064. ;       xor     ebx,ebx
  2065. ;       mov     bx,[WIN_STACK + eax * 2]
  2066. ;       DEBUGF  1, "K : DEC WIN_STACK (0x%x)\n",ebx
  2067. ;       pop     ebx
  2068.  
  2069.         cmp     [WIN_STACK + eax * 2], bx
  2070.         jbe     .next_stack_window
  2071.         dec     word[WIN_STACK + eax * 2]
  2072.         jmp     .next_stack_window
  2073. ;--------------------------------------
  2074. align 4
  2075. .move_self_up:
  2076.         movzx   ebx, word[esi]
  2077.         ; number of thread
  2078.         mov     ax, word [thread_count]
  2079.         ; this is the last (and the upper)
  2080.         mov     [WIN_STACK + ebx * 2], ax
  2081.  
  2082.         ; update on screen - window stack
  2083.         xor     eax, eax
  2084. ;--------------------------------------
  2085. align 4
  2086. .next_window_pos:
  2087.         cmp     eax, [thread_count]
  2088.         jae     .reset_vars
  2089.         inc     eax
  2090.         movzx   ebx, word[WIN_STACK + eax * 2]
  2091.         mov     [WIN_POS + ebx * 2], ax
  2092.         jmp     .next_window_pos
  2093. ;--------------------------------------
  2094. align 4
  2095. .reset_vars:
  2096.         mov     byte[KEY_COUNT], 0
  2097.         mov     byte[BTN_COUNT], 0
  2098.         mov     word[MOUSE_SCROLL_H], 0
  2099.         mov     word[MOUSE_SCROLL_V], 0
  2100.  
  2101.         pop     ebx eax
  2102.         ret
  2103. ;------------------------------------------------------------------------------
  2104.  
  2105.  
  2106. ; Deactivate window
  2107. ; esi = pointer to WIN_POS+ window data
  2108. window._.window_deactivate:
  2109.         push    eax ebx
  2110. ;--------------------------------------
  2111. align 4
  2112. .move_others_up:
  2113.         ; ax <- process no
  2114.         movzx   ebx, word[esi]
  2115.         ; ax <- position in window stack
  2116.         movzx   ebx, word[WIN_STACK + ebx * 2]
  2117.         ; up others
  2118.         xor     eax, eax
  2119. ;--------------------------------------
  2120. align 4
  2121. .next_stack_window:
  2122.         cmp     eax, [thread_count]
  2123.         jae     .move_self_down
  2124.         inc     eax
  2125.         cmp     [WIN_STACK + eax * 2], bx
  2126.         jae     .next_stack_window
  2127.         inc     word[WIN_STACK + eax * 2]
  2128.         jmp     .next_stack_window
  2129. ;--------------------------------------
  2130. align 4
  2131. .move_self_down:
  2132.         movzx   ebx, word[esi]
  2133.         ; this is the last (and the low)
  2134.         mov     [WIN_STACK + ebx * 2], word 1
  2135.         ; update on screen - window stack
  2136.         xor     eax, eax
  2137. ;--------------------------------------
  2138. align 4
  2139. .next_window_pos:
  2140.         cmp     eax, [thread_count]
  2141.         jae     .reset_vars
  2142.         inc     eax
  2143.         movzx   ebx, word[WIN_STACK + eax * 2]
  2144.         mov     [WIN_POS + ebx * 2], ax
  2145.         jmp     .next_window_pos
  2146. ;--------------------------------------
  2147. align 4
  2148. .reset_vars:
  2149.         mov     byte[KEY_COUNT], 0
  2150.         mov     byte[BTN_COUNT], 0
  2151.         mov     word[MOUSE_SCROLL_H], 0
  2152.         mov     word[MOUSE_SCROLL_V], 0
  2153.         pop     ebx eax
  2154.         ret
  2155. ;------------------------------------------------------------------------------
  2156.  
  2157.  
  2158. align 4
  2159. ; Check if window is necessary to draw
  2160. ; edi = pointer to WDATA
  2161. window._.check_window_draw:
  2162.         mov     cl, [edi + WDATA.fl_wstyle]
  2163.         and     cl, 0x0f
  2164.         cmp     cl, 3
  2165.         je      .exit.redraw      ; window type 3
  2166.         cmp     cl, 4
  2167.         je      .exit.redraw      ; window type 4
  2168.  
  2169.         push    eax ebx edx esi
  2170.  
  2171.         mov     eax, edi
  2172.         sub     eax, window_data
  2173.         shr     eax, BSF sizeof.WDATA
  2174.  
  2175.         movzx   eax, word[WIN_STACK + eax * 2]  ; get value of the curr process
  2176.         lea     esi, [WIN_POS + eax * 2]        ; get address of this process at 0xC400
  2177. ;--------------------------------------
  2178. align 4
  2179. .next_window:
  2180.         add     esi, 2
  2181.  
  2182.         mov     eax, [thread_count]
  2183.         lea     eax, word[WIN_POS + eax * 2] ; number of the upper window
  2184.  
  2185.         cmp     esi, eax
  2186.         ja      .exit.no_redraw
  2187.  
  2188.         movzx   edx, word[esi]
  2189.         shl     edx, BSF sizeof.WDATA ; size of TASKDATA and WDATA is 32 bytes
  2190.         cmp     byte [SLOT_BASE + edx*(sizeof.APPDATA/sizeof.WDATA) - sizeof.APPDATA + APPDATA.state], TSTATE_FREE
  2191.         je      .next_window
  2192.  
  2193.         mov     eax, [edi + WDATA.box.top]
  2194.         mov     ebx, [edi + WDATA.box.height]
  2195.         add     ebx, eax
  2196.  
  2197.         mov     ecx, [window_data + edx + WDATA.box.top]
  2198.         cmp     ecx, ebx
  2199.         jge     .next_window
  2200.         add     ecx, [window_data + edx + WDATA.box.height]
  2201.         cmp     eax, ecx
  2202.         jge     .next_window
  2203.  
  2204.         mov     eax, [edi + WDATA.box.left]
  2205.         mov     ebx, [edi + WDATA.box.width]
  2206.         add     ebx, eax
  2207.  
  2208.         mov     ecx, [window_data + edx + WDATA.box.left]
  2209.         cmp     ecx, ebx
  2210.         jge     .next_window
  2211.         add     ecx, [window_data + edx + WDATA.box.width]
  2212.         cmp     eax, ecx
  2213.         jge     .next_window
  2214.  
  2215.         pop     esi edx ebx eax
  2216. ;--------------------------------------
  2217. align 4
  2218. .exit.redraw:
  2219.         xor     ecx, ecx
  2220.         inc     ecx
  2221.         ret
  2222. ;--------------------------------------
  2223. align 4
  2224. .exit.no_redraw:
  2225.         pop     esi edx ebx eax
  2226.         xor     ecx, ecx
  2227.         ret
  2228.  
  2229.  
  2230. ;------------------------------------------------------------------------------
  2231.  
  2232.  
  2233. align 4
  2234. window._.draw_window_caption:
  2235.         xor     eax, eax
  2236.         mov     edx, [thread_count]
  2237.         movzx   edx, word[WIN_POS + edx * 2]
  2238.         cmp     edx, [current_slot_idx]
  2239.         jne     @f
  2240.         inc     eax
  2241. ;--------------------------------------
  2242. align 4
  2243. @@:
  2244.         mov     edx, [current_slot_idx]
  2245.         shl     edx, BSF sizeof.WDATA
  2246.         add     edx, window_data
  2247.         movzx   ebx, [edx + WDATA.fl_wstyle]
  2248.         and     bl, 0x0F
  2249.         cmp     bl, 3
  2250.         je      .draw_caption_style_3
  2251.         cmp     bl, 4
  2252.         je      .draw_caption_style_3
  2253.  
  2254.         jmp     .not_style_3
  2255. ;--------------------------------------
  2256. align 4
  2257. .draw_caption_style_3:
  2258.         push    edx
  2259.         call    drawwindow_IV_caption
  2260.         add     esp, 4
  2261.         jmp     .2
  2262. ;--------------------------------------
  2263. align 4
  2264. .not_style_3:
  2265.         cmp     bl, 2
  2266.         jne     .not_style_2
  2267.  
  2268.         call    drawwindow_III_caption
  2269.         jmp     .2
  2270. ;--------------------------------------
  2271. align 4
  2272. .not_style_2:
  2273.         cmp     bl, 0
  2274.         jne     .2
  2275.  
  2276.         call    drawwindow_I_caption
  2277. ;--------------------------------------
  2278. align 4
  2279. .2:
  2280.         mov     edi, [current_slot_idx]
  2281.         shl     edi, BSF sizeof.WDATA
  2282.         test    [window_data + edi + WDATA.fl_wstyle], WSTYLE_HASCAPTION
  2283.         jz      .exit
  2284.         mov     edx, [window_data + edi + WDATA.caption]
  2285.         or      edx, edx
  2286.         jz      .exit
  2287.  
  2288.         mov     ebp, [edi + window_data + WDATA.box.left - 2]
  2289.         mov     bp, word[edi + window_data + WDATA.box.top]
  2290.         movzx   eax, [edi + window_data + WDATA.fl_wstyle]
  2291.         and     al, 0x0F
  2292.         cmp     al, 3
  2293.         je      .skinned
  2294.         cmp     al, 4
  2295.         je      .skinned
  2296.  
  2297.         jmp     .not_skinned
  2298. ;--------------------------------------
  2299. align 4
  2300. .skinned:
  2301.         movzx   eax, word[edi + window_data + WDATA.box.width]
  2302.         sub     ax, [_skinmargins.left]
  2303.         sub     ax, [_skinmargins.right]
  2304.         js      .exit
  2305.         mov     ebx, dword[_skinmargins.left - 2]
  2306.         mov     bx, word[_skinh]
  2307.         sub     bx, [_skinmargins.bottom]
  2308.         sub     bx, [_skinmargins.top]
  2309.         sar     bx, 1
  2310.         add     bx, [_skinmargins.top]
  2311.         sub     bx, 8
  2312.         jmp     .dodraw
  2313. ;--------------------------------------
  2314. align 4
  2315. .not_skinned:
  2316.         cmp     al, 1
  2317.         je      .exit
  2318.         movzx   eax, word[edi + window_data + WDATA.box.width]
  2319.         sub     eax, 16
  2320.         js      .exit
  2321.         mov     ebx, 80002h
  2322. .dodraw:
  2323.         shr     eax, 3
  2324.         mov     esi, eax
  2325.         add     ebx, ebp
  2326.         mov     ecx, [common_colours + 16]
  2327.         mov     al, [window_data + edi + WDATA.captionEncoding]
  2328.         test    al, al
  2329.         jnz     @f
  2330.         mov     al, 1
  2331.         cmp     byte [edx], 4
  2332.         jnc     @f
  2333.         mov     al, [edx]
  2334.         test    al, al
  2335.         jz      .exit
  2336.         inc     edx
  2337. @@:
  2338.         shl     eax, 28
  2339.         or      ecx, eax        
  2340.         xor     edi, edi
  2341.         stc
  2342.         call    dtext._
  2343. .exit:
  2344.         jmp     __sys_draw_pointer
  2345. ;------------------------------------------------------------------------------
  2346.  
  2347.  
  2348. align 4
  2349. ; Draw negative box
  2350. ; edi = pointer to BOX struct
  2351. window._.draw_negative_box:
  2352.         push    eax ebx esi
  2353.         mov     esi, 0x01000000
  2354. ;--------------------------------------
  2355. align 4
  2356. .1:
  2357.         mov     eax, [edi + BOX.left - 2]
  2358.         mov     ax, word[edi + BOX.left]
  2359.         add     ax, word[edi + BOX.width]
  2360.         mov     ebx, [edi + BOX.top - 2]
  2361.         mov     bx, word[edi + BOX.top]
  2362.         add     bx, word[edi + BOX.height]
  2363.         call    draw_rectangle.forced
  2364.         pop     esi ebx eax
  2365.         ret
  2366. ;------------------------------------------------------------------------------
  2367. ;align 4
  2368. ;------------------------------------------------------------------------------
  2369. ;window._.end_moving__box: ;//////////////////////////////////////////////////
  2370. ;------------------------------------------------------------------------------
  2371. ;? Draw positive box
  2372. ;------------------------------------------------------------------------------
  2373. ;> edi = pointer to BOX struct
  2374. ;------------------------------------------------------------------------------
  2375. ;        push    eax ebx esi
  2376. ;        xor     esi, esi
  2377. ;        jmp     window._.draw_negative_box.1
  2378. ;------------------------------------------------------------------------------
  2379.  
  2380.  
  2381. align 4
  2382. ; void __fastcall get_window_rect(struct RECT* rc);
  2383. ; ecx = pointer to RECT
  2384. window._.get_rect:
  2385.         mov     eax, [current_slot_idx]
  2386.         shl     eax, BSF sizeof.WDATA
  2387.  
  2388.         mov     edx, [eax + window_data + WDATA.box.left]
  2389.         mov     [ecx+RECT.left], edx
  2390.  
  2391.         add     edx, [eax + window_data + WDATA.box.width]
  2392.         mov     [ecx+RECT.right], edx
  2393.  
  2394.         mov     edx, [eax +window_data + WDATA.box.top]
  2395.         mov     [ecx+RECT.top], edx
  2396.  
  2397.         add     edx, [eax + window_data + WDATA.box.height]
  2398.         mov     [ecx+RECT.bottom], edx
  2399.         ret
  2400. ;------------------------------------------------------------------------------
  2401.  
  2402.  
  2403. align 4
  2404. ; redraw 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._.redraw_top_wnd:
  2412.         push    0
  2413.         jmp     window._.set_top_wnd.go
  2414. ;------------------------------------------------------------------------------
  2415.  
  2416.  
  2417. align 4
  2418. ; call set_screen for all windows one above the window
  2419. ;> eax = left
  2420. ;> ebx = top
  2421. ;> ecx = right
  2422. ;> edx = bottom
  2423. ;> esi = process number
  2424. ;! corrupted edi
  2425. window._.set_top_wnd:
  2426.         push    1
  2427. .go:
  2428.         push    esi
  2429.         pushfd
  2430.         cli
  2431.  
  2432.         push    ebp
  2433.         mov     ebp, [thread_count]
  2434.         cmp     ebp, 1
  2435.         jbe     .exit
  2436.  
  2437.         shl     esi, BSF sizeof.WDATA
  2438.         cmp     [esi + window_data + WDATA.z_modif], ZPOS_ALWAYS_TOP
  2439.         je      .exit
  2440.  
  2441.         push    eax ;for num layout
  2442.         push    edx ecx ebx eax
  2443.  
  2444.         movsx   eax, byte [esi + window_data + WDATA.z_modif]
  2445.         inc     eax
  2446.         mov     dword[esp+10h], eax
  2447. ;--------------------------------------
  2448. align 4
  2449. .layout:
  2450.         mov     esi, 1        ; = num in window stack
  2451.         mov     ebp, [thread_count]
  2452. ;--------------------------------------
  2453. align 4
  2454. .next_window:
  2455.         movzx   edi, word[WIN_POS + esi * 2]
  2456.         shl     edi, BSF sizeof.WDATA         ;size of TASKDATA and WDATA = 32 bytes
  2457.  
  2458.         cmp     byte [SLOT_BASE + edi*(sizeof.APPDATA/sizeof.WDATA) + APPDATA.state], TSTATE_FREE
  2459.         je      .skip_window
  2460.  
  2461.         add     edi, window_data
  2462.         test    [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  2463.         jnz     .skip_window
  2464.  
  2465.         mov     eax, [esp+10h]
  2466.         cmp     [edi + WDATA.z_modif], al
  2467.         jne     .skip_window
  2468.  
  2469.         mov     eax, [edi + WDATA.box.left]
  2470.         cmp     eax, [esp + RECT.right]
  2471.         jg      .skip_window
  2472.         mov     ebx, [edi + WDATA.box.top]
  2473.         cmp     ebx, [esp + RECT.bottom]
  2474.         jg      .skip_window
  2475.         mov     ecx, [edi + WDATA.box.width]
  2476.         add     ecx, eax
  2477.         cmp     ecx, [esp + RECT.left]
  2478.         jl      .skip_window
  2479.         mov     edx, [edi + WDATA.box.height]
  2480.         add     edx, ebx
  2481.         cmp     edx, [esp + RECT.top]
  2482.         jl      .skip_window
  2483.  
  2484.         cmp     eax, [esp + RECT.left]
  2485.         jae     @f
  2486.         mov     eax, [esp + RECT.left]
  2487. ;--------------------------------------
  2488. align 4
  2489. @@:
  2490.         cmp     ebx, [esp + RECT.top]
  2491.         jae     @f
  2492.         mov     ebx, [esp + RECT.top]
  2493. ;--------------------------------------
  2494. align 4
  2495. @@:
  2496.         cmp     ecx, [esp + RECT.right]
  2497.         jbe     @f
  2498.         mov     ecx, [esp + RECT.right]
  2499. ;--------------------------------------
  2500. align 4
  2501. @@:
  2502.         cmp     edx, [esp + RECT.bottom]
  2503.         jbe     @f
  2504.         mov     edx, [esp + RECT.bottom]
  2505. ;--------------------------------------
  2506. align 4
  2507. @@:
  2508.         cmp     dword[esp+32], 0
  2509.         je      .set_fl_redraw
  2510.  
  2511.         push    esi
  2512.         movzx   esi, word[WIN_POS + esi * 2]
  2513.         call    window._.set_screen
  2514.         pop     esi
  2515.         jmp     @f
  2516. .set_fl_redraw:
  2517.         mov     [edi + WDATA.fl_redraw], 1      ;set redraw flag
  2518.      @@:
  2519. ;--------------------------------------
  2520. align 4
  2521. .skip_window:
  2522.         inc     esi
  2523.         dec     ebp
  2524.         jnz     .next_window
  2525. ;--------------------------------------
  2526.         inc     dword[esp+10h]
  2527.         cmp     byte[esp+10h], ZPOS_ALWAYS_TOP
  2528.         jle     .layout
  2529. ;-------------------------------------
  2530.  
  2531.         pop     eax ebx ecx edx
  2532.         pop     ebp     ;del num layout
  2533. ;-------------------------------------
  2534. align 4
  2535. .exit:
  2536.  
  2537.         pop     ebp
  2538.         popfd
  2539.         pop     esi
  2540.  
  2541.         add     esp, 4   ;dword for 0/1 - set_screen/fl_redraw
  2542.         ret
  2543.