Subversion Repositories Kolibri OS

Rev

Rev 6802 | Rev 8012 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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