Changeset 1391

Show
Ignore:
Timestamp:
02/06/2010 09:08:19 PM (5 weeks ago)
Author:
mikedld
Message:

gui/mouse.inc:

+ new file for GUI-related mouse events handling (old mouse.inc renamed)

gui/button.inc:

  • refactoring in regards of new mouse.inc:
    • obsolete code eliminated
    • old'n'ugly check_buttons and checkwindows removed
    • events handlers added

gui/window.inc:

  • moved GUI-related syscalls and auxilary functions from kernel.asm
  • removed registers cross-ordering from syscall 67 (window move/resize)

+ more comments added
known bugs include:

  1. apps using syscall 67 (kfar etc.) may not redraw their old screen area leaving ghost images
  2. possibility of mouse cursor artefacts may have increased (this *really* has to be reworked)
Location:
kernel/trunk
Files:
1 added
6 modified
1 copied

Legend:

Unmodified
Added
Removed
  • kernel/trunk/core/syscall.inc

    r1375 r1391  
    170170      dd syscall_putimage_palette; 65-PutImagePalette 
    171171      dd sys_process_def         ; 66-Process definitions - keyboard 
    172       dd sys_window_move         ; 67-Window move or resize 
     172      dd 0 
    173173      dd 0 
    174174      dd 0 
     
    181181  servetable2: 
    182182 
    183       dd sys_drawwindow          ; 0-DrawWindow 
     183      dd syscall_draw_window     ; 0-DrawWindow 
    184184      dd syscall_setpixel        ; 1-SetPixel 
    185185      dd sys_getkey              ; 2-GetKey 
     
    248248      dd cross_order             ; 65-PutImagePalette 
    249249      dd cross_order             ; 66-Process definitions - keyboard 
    250       dd cross_order             ; 67-Window move or resize 
     250      dd syscall_move_window     ; 67-Window move or resize 
    251251      dd f68                     ; 68-Some internal services 
    252252      dd sys_debug_services      ; 69-Debug 
    253253      dd cross_order             ; 70-Common file system interface, version 2 
    254       dd syscall_windowsettings ; 71-Window settings 
     254      dd syscall_window_settings ; 71-Window settings 
    255255      dd sys_sendwindowmsg       ; 72-Send window message 
    256256        times 255 - ( ($-servetable2) /4 )  dd undefined_syscall 
  • kernel/trunk/gui/button.inc

    r1381 r1391  
    11;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
    22;;                                                              ;; 
    3 ;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;; 
     3;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;; 
    44;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;; 
    55;; Distributed under terms of the GNU General Public License    ;; 
     
    99$Revision$ 
    1010 
    11  
    12 button._.MAX_BUTTONS = 4095 
    13  
    14  
    1511;============================================================================== 
    1612;///// public functions /////////////////////////////////////////////////////// 
    1713;============================================================================== 
     14 
     15button.MAX_BUTTONS = 4095 
    1816 
    1917struc SYS_BUTTON 
     
    2624  .height dw ? 
    2725  .id_hi  dw ? 
    28   .align  dw ? 
     26          dw ? 
    2927  .sizeof: 
    3028} 
     
    3230  SYS_BUTTON SYS_BUTTON 
    3331end virtual 
    34  
    35 iglobal 
    36   mx                dw 0x0 ; keeps the x mouse's position when it was clicked 
    37   my                dw 0x0 ; keeps the y mouse's position when it was clicked 
    38   bPressedMouseXY_B db 0x0 
    39   btn_down_determ   db 0x0 
    40 endg 
    4132 
    4233align 4 
     
    6859        mov     edi, [BTN_ADDR] 
    6960        mov     eax, [edi] 
    70         cmp     eax, button._.MAX_BUTTONS 
     61        cmp     eax, button.MAX_BUTTONS 
    7162        jge     .exit 
    7263 
     
    229220        xor     ecx, ecx 
    230221        add     ecx, -SYS_BUTTON.sizeof 
     222        add     esi, SYS_BUTTON.sizeof 
    231223 
    232224  .next_button: 
     
    264256align 4 
    265257;------------------------------------------------------------------------------ 
    266 check_buttons: ;/////////////////////////////////////////////////////////////// 
    267 ;------------------------------------------------------------------------------ 
    268 ;? <description> 
    269 ;------------------------------------------------------------------------------ 
    270         cmp     byte[BTN_DOWN], 0    ; mouse buttons pressed 
    271         jnz     @f 
    272         mov     [bPressedMouseXY_B], 0 
    273         ret 
    274  
    275     @@: pushad 
    276         xor     esi, esi 
    277         mov     edi, [BTN_ADDR] 
    278         mov     edx, [edi] 
    279         test    edx, edx 
    280         jne     @f 
    281         popad 
    282         ret 
    283  
    284         ;here i catch the coordinates when the mouse's button is clicked 
    285     @@: push    ax 
    286         cmp     [bPressedMouseXY_B], 0 ; FALSE 
    287         jnz     @f 
    288         mov     [bPressedMouseXY_B], 1 ; TRUE - it was already clicked 
    289         mov     ax, [MOUSE_X] 
    290         mov     [mx], ax 
    291         mov     ax, [MOUSE_Y] 
    292         mov     [my], ax 
    293     @@: pop     ax 
    294         ;and it is only refreshed after the mouse's button release 
    295  
    296         push    esi 
    297         inc     edx 
    298         push    edx 
    299  
    300   .buttonnewcheck: 
    301         pop     edx 
    302         pop     esi 
    303         inc     esi 
    304         cmp     edx, esi 
    305         jge     .bch 
    306  
    307         popad 
    308         ret 
    309  
    310   .bch: 
    311         push    esi 
    312         push    edx 
    313         mov     eax, esi 
    314         shl     eax, 4 
    315         add     eax, edi 
    316  
    317         ; check that button is at top of windowing stack 
    318         movzx   ebx, [eax + SYS_BUTTON.pslot] 
    319         movzx   ecx, word[WIN_STACK + ebx * 2] 
    320         cmp     ecx, [TASK_COUNT] 
    321         jne     .buttonnewcheck 
    322  
    323         ; check that button start is inside window x/y end 
    324         shl     ebx, 5 
    325  
    326         test    [ebx + window_data + WDATA.fl_wstate], WSTATE_MINIMIZED 
    327         jnz     .buttonnewcheck 
    328  
    329         movzx   edx, [eax + SYS_BUTTON.left] 
    330         cmp     edx, [window_data + ebx + WDATA.box.width] ;ecx 
    331         jge     .buttonnewcheck 
    332  
    333         movzx   edx, [eax + SYS_BUTTON.top] 
    334         cmp     edx, [window_data + ebx + WDATA.box.height] ;ecx 
    335         jge     .buttonnewcheck 
    336  
    337         ; check coordinates 
    338  
    339         ; mouse x >= button x ? 
    340         add     ebx, window_data 
    341         mov     ecx, [ebx + WDATA.box.left] 
    342         movzx   edx, [eax + SYS_BUTTON.left] 
    343         add     edx, ecx 
    344         mov     cx, [mx]   ;mov cx,[MOUSE_X] 
    345         cmp     edx, ecx 
    346         jg      .buttonnewcheck 
    347  
    348         movzx   ebx, [eax + SYS_BUTTON.width] 
    349         add     edx, ebx 
    350         cmp     ecx, edx 
    351         jg      .buttonnewcheck 
    352  
    353         ; mouse y >= button y ? 
    354         movzx   ebx, [eax + SYS_BUTTON.pslot] 
    355         shl     ebx, 5 
    356         add     ebx, window_data 
    357         mov     ecx, [ebx + WDATA.box.top] 
    358         movzx   edx, [eax + SYS_BUTTON.top] 
    359         add     edx, ecx 
    360         mov     cx, [my]  ;mov cx,[MOUSE_Y] 
    361         cmp     edx, ecx 
    362         jg      .buttonnewcheck 
    363  
    364         movzx   ebx, [eax + SYS_BUTTON.height] 
    365         add     edx, ebx 
    366         cmp     ecx, edx 
    367         jg      .buttonnewcheck 
    368  
    369         ; mouse on button 
    370  
    371         pop     edx 
    372         pop     esi 
    373  
    374         mov     ebx, dword[eax + SYS_BUTTON.id_hi - 2]     ; button id : bits 16-31 
    375         mov     bx, [eax + SYS_BUTTON.id_lo]       ; button id : bits 00-16 
    376         push    ebx 
    377  
    378         mov     byte[MOUSE_DOWN], 1  ; no mouse down checks 
     258sys_button_activate_handler: ;///////////////////////////////////////////////// 
     259;------------------------------------------------------------------------------ 
     260;? <description> 
     261;------------------------------------------------------------------------------ 
     262;> eax = pack[8(process slot), 24(button id)] 
     263;> ebx = pack[16(button x coord), 16(button y coord)] 
     264;> cl = mouse button mask this system button was pressed with 
     265;------------------------------------------------------------------------------ 
     266        call    button._.find_button 
     267        or      eax, eax 
     268        jz      .exit 
     269 
     270        mov     ebx, dword[eax + SYS_BUTTON.id_hi - 2] 
    379271        call    button._.negative_button 
    380272 
    381         pushad 
    382         push    eax 
    383         mov     al, [BTN_DOWN] 
    384         mov     byte[btn_down_determ], al 
    385         pop     eax 
    386  
    387   .cbwaitmouseup: 
    388         call    checkidle 
    389         call    [draw_pointer] 
    390  
    391         pushad 
    392         call    stack_handler 
    393         popad 
    394  
    395         cmp     byte[BTN_DOWN], 0  ; mouse buttons pressed ? 
    396         jnz     .cbwaitmouseup 
    397         popad 
    398  
     273  .exit: 
     274        ret 
     275 
     276align 4 
     277;------------------------------------------------------------------------------ 
     278sys_button_deactivate_handler: ;/////////////////////////////////////////////// 
     279;------------------------------------------------------------------------------ 
     280;? <description> 
     281;------------------------------------------------------------------------------ 
     282;> eax = pack[8(process slot), 24(button id)] 
     283;> ebx = pack[16(button x coord), 16(button y coord)] 
     284;> cl = mouse button mask this system button was pressed with 
     285;------------------------------------------------------------------------------ 
     286        call    button._.find_button 
     287        or      eax, eax 
     288        jz      .exit 
     289 
     290        mov     ebx, dword[eax + SYS_BUTTON.id_hi - 2] 
    399291        call    button._.negative_button 
    400         mov     byte[MOUSE_BACKGROUND], 0  ; no mouse background 
    401         mov     byte[DONT_DRAW_MOUSE], 0  ; draw mouse 
    402  
    403         ; check coordinates 
    404         pusha 
    405  
    406         ; mouse x >= button x ? 
    407         movzx   ebx, [eax + SYS_BUTTON.pslot] 
    408         shl     ebx, 5 
    409         add     ebx, window_data 
    410         mov     ecx, [ebx + WDATA.box.left] 
    411         movzx   edx, [eax + SYS_BUTTON.left] 
    412         add     edx, ecx 
    413         mov     cx, [MOUSE_X] 
    414         cmp     edx, ecx 
    415         jg      .no_on_button ;if we release the pointer out of the button area 
    416  
    417         movzx   ebx, [eax + SYS_BUTTON.width] 
    418         add     edx, ebx 
    419         cmp     ecx, edx 
    420         jg      .no_on_button 
    421  
    422         ; mouse y >= button y ? 
    423         movzx   ebx, [eax + SYS_BUTTON.pslot] 
    424         shl     ebx, 5 
    425         add     ebx, window_data 
    426         mov     ecx, [ebx + WDATA.box.top] 
    427         movzx   edx, [eax + SYS_BUTTON.top] 
    428         add     edx, ecx 
    429         mov     cx, [MOUSE_Y] 
    430         cmp     edx, ecx 
    431         jg      .no_on_button 
    432  
    433         movzx   ebx, [eax + SYS_BUTTON.height] 
    434         add     edx, ebx 
    435         cmp     ecx, edx 
    436         jg      .no_on_button 
    437  
    438         popa 
    439  
    440         mov     byte[BTN_COUNT], 1 ; no of buttons in buffer 
    441         pop     ebx 
    442         mov     [BTN_BUFF], ebx   ; lets put the button id in buffer 
    443         push    ebx 
    444         pusha 
    445         jmp     .yes_on_button 
    446  
    447   .no_on_button: 
    448         mov     byte[BTN_COUNT], 0 ; no of buttons in buffer 
    449  
    450   .yes_on_button: 
    451         mov     byte[MOUSE_DOWN], 0 ; mouse down -> do not draw 
    452         popa 
    453         pop     ebx 
    454         popa 
     292 
     293  .exit: 
     294        ret 
     295 
     296align 4 
     297;------------------------------------------------------------------------------ 
     298sys_button_perform_handler: ;////////////////////////////////////////////////// 
     299;------------------------------------------------------------------------------ 
     300;? <description> 
     301;------------------------------------------------------------------------------ 
     302;> eax = pack[8(process slot), 24(button id)] 
     303;> ebx = pack[16(button x coord), 16(button y coord)] 
     304;> cl = mouse button mask this system button was pressed with 
     305;------------------------------------------------------------------------------ 
     306        shl     eax, 8 
     307        mov     al, cl 
     308        movzx   ebx, byte[BTN_COUNT] 
     309        mov     [BTN_BUFF + ebx * 4], eax 
     310        inc     bl 
     311        mov     [BTN_COUNT], bl 
    455312        ret 
    456313 
     
    458315;///// private functions ////////////////////////////////////////////////////// 
    459316;============================================================================== 
     317 
     318;------------------------------------------------------------------------------ 
     319button._.find_button: ;//////////////////////////////////////////////////////// 
     320;------------------------------------------------------------------------------ 
     321;? Find system button by specified process slot, id and coordinates 
     322;------------------------------------------------------------------------------ 
     323;> eax = pack[8(process slot), 24(button id)] or 0 
     324;> ebx = pack[16(button x coord), 16(button y coord)] 
     325;------------------------------------------------------------------------------ 
     326;< eax = pointer to SYS_BUTTON struct or 0 
     327;------------------------------------------------------------------------------ 
     328        push    ecx edx esi edi 
     329 
     330        mov     edx, eax 
     331        shr     edx, 24 
     332        and     eax, 0x0ffffff 
     333 
     334        mov     edi, [BTN_ADDR] 
     335        mov     ecx, [edi] 
     336        imul    esi, ecx, SYS_BUTTON.sizeof 
     337        add     esi, edi 
     338        inc     ecx 
     339        add     esi, SYS_BUTTON.sizeof 
     340 
     341  .next_button: 
     342        dec     ecx 
     343        jz      .not_found 
     344 
     345        add     esi, -SYS_BUTTON.sizeof 
     346 
     347        ; does it belong to our process? 
     348        cmp     dx, [esi + SYS_BUTTON.pslot] 
     349        jne     .next_button 
     350 
     351        ; does id match? 
     352        mov     edi, dword[esi + SYS_BUTTON.id_hi - 2] 
     353        mov     di, [esi + SYS_BUTTON.id_lo] 
     354        and     edi, 0x0ffffff 
     355        cmp     eax, edi 
     356        jne     .next_button 
     357 
     358        ; does coordinates match? 
     359        mov     edi, dword[esi + SYS_BUTTON.left - 2] 
     360        mov     di, [esi + SYS_BUTTON.top] 
     361        cmp     ebx, edi 
     362        jne     .next_button 
     363 
     364        ; okay, return it 
     365        mov     eax, esi 
     366        jmp     .exit 
     367 
     368  .not_found: 
     369        xor     eax, eax 
     370 
     371  .exit: 
     372        pop     edi esi edx ecx 
     373        ret 
    460374 
    461375;------------------------------------------------------------------------------ 
     
    547461button._.negative_button: ;//////////////////////////////////////////////////// 
    548462;------------------------------------------------------------------------------ 
    549 ;? <description> 
     463;? Invert system button border 
    550464;------------------------------------------------------------------------------ 
    551465        ; if requested, do not display button border on press. 
  • kernel/trunk/gui/event.inc

    r1067 r1391  
    369369        sub     ecx,2 
    370370        je      .sendkey 
    371         loop    .retf 
     371        dec     ecx 
     372        jnz     .retf 
    372373.sendbtn: 
    373374        cmp     byte[BTN_COUNT],1 
    374375        jae     .result ;overflow 
    375376        inc     byte[BTN_COUNT] 
     377        shl     edx, 8 
    376378        mov     [BTN_BUFF],edx 
    377379        jmp     .result 
     
    468470        cmp     edx,[TASK_COUNT] 
    469471        jne     .loop          ; not Top ??? 
    470         cmp     dword[BTN_BUFF],0xFFFF ;-ID for Minimize-Button of Form 
     472        mov     edx, [BTN_BUFF] 
     473        shr     edx, 8 
     474        cmp     edx, 0xFFFF    ;-ID for Minimize-Button of Form 
    471475        jne     .result 
    472476        mov     [window_minimize],1 
  • kernel/trunk/gui/window.inc

    r1369 r1391  
    11;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
    22;;                                                              ;; 
    3 ;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;; 
     3;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;; 
    44;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;; 
    55;; Distributed under terms of the GNU General Public License    ;; 
     
    99$Revision$ 
    1010 
    11  
    1211;============================================================================== 
    1312;///// public functions /////////////////////////////////////////////////////// 
    1413;============================================================================== 
    1514 
    16 macro FuncTable name, [label] 
     15window.BORDER_SIZE = 5 
     16 
     17macro FuncTable name, table_name, [label] 
    1718{ 
    1819  common 
    1920    align 4 
    20     \label name#.ftable dword 
     21    \label name#.#table_name dword 
    2122  forward 
    2223    dd name#.#label 
    2324  common 
    24     name#.sizeof.ftable = $ - name#.ftable 
     25    name#.sizeof.#table_name = $ - name#.#table_name 
    2526} 
    2627 
    27 iglobal 
    28   FuncTable syscall_display_settings, \ 
    29     00, 01, 02, 03, 04, 05, 06, 07, 08 
     28uglobal 
     29  common_colours rd 32 
     30  draw_limits    RECT 
    3031endg 
    3132 
    32 uglobal 
    33   common_colours            rd 32 
    34   new_window_starting       dd ? 
    35   latest_window_touch       dd ? 
    36   latest_window_touch_delta dd ? 
    37   old_window_pos            BOX 
    38   new_window_pos            BOX 
    39   draw_limits               RECT 
    40   bPressedMouseXY_W         db ? 
    41   do_resize                 db ? 
    42   do_resize_from_corner     db ? 
    43   reposition                db ? 
    44 endg 
     33align 4 
     34;------------------------------------------------------------------------------ 
     35syscall_draw_window: ;///// system function 0 ///////////////////////////////// 
     36;------------------------------------------------------------------------------ 
     37;? <description> 
     38;------------------------------------------------------------------------------ 
     39        mov     eax, edx 
     40        shr     eax, 24 
     41        and     al, 0x0f 
     42        cmp     al, 5 
     43        jae     .exit 
     44 
     45        push    eax 
     46        inc     [mouse_pause] 
     47        call    [_display.disable_mouse] 
     48        call    window._.sys_set_window 
     49        call    [_display.disable_mouse] 
     50        pop     eax 
     51 
     52        or      al, al 
     53        jnz     @f 
     54 
     55        ; type I - original style 
     56        call    drawwindow_I 
     57        jmp     window._.draw_window_caption.2 
     58 
     59    @@: dec     al 
     60        jnz     @f 
     61 
     62        ; type II - only reserve area, no draw 
     63        call    sys_window_mouse 
     64        dec     [mouse_pause] 
     65        call    [draw_pointer] 
     66        jmp     .exit 
     67 
     68    @@: dec     al 
     69        jnz     @f 
     70 
     71        ; type III  - new style 
     72        call    drawwindow_III 
     73        jmp     window._.draw_window_caption.2 
     74 
     75        ; type IV & V - skinned window (resizable & not) 
     76    @@: mov     eax, [TASK_COUNT] 
     77        movzx   eax, word[WIN_POS + eax * 2] 
     78        cmp     eax, [CURRENT_TASK] 
     79        setz    al 
     80        movzx   eax, al 
     81        push    eax 
     82        call    drawwindow_IV 
     83        jmp     window._.draw_window_caption.2 
     84 
     85  .exit: 
     86        ret 
    4587 
    4688align 4 
     
    270312align 4 
    271313;------------------------------------------------------------------------------ 
     314syscall_move_window: ;///// system function 67 //////////////////////////////// 
     315;------------------------------------------------------------------------------ 
     316;? <description> 
     317;------------------------------------------------------------------------------ 
     318        mov     edi, [CURRENT_TASK] 
     319        shl     edi, 5 
     320        add     edi, window_data 
     321 
     322        test    [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED 
     323        jnz     .exit 
     324 
     325        cmp     ebx, -1 
     326        jne     @f 
     327        mov     ebx, [edi + WDATA.box.left] 
     328    @@: cmp     ecx, -1 
     329        jne     @f 
     330        mov     ecx, [edi + WDATA.box.top] 
     331    @@: cmp     edx, -1 
     332        jne     @f 
     333        mov     edx, [edi + WDATA.box.width] 
     334    @@: cmp     esi, -1 
     335        jne     @f 
     336        mov     esi, [edi + WDATA.box.height] 
     337 
     338    @@: push    esi edx ecx ebx 
     339        mov     eax, esp 
     340        mov     bl, [edi + WDATA.fl_wstate] 
     341        call    window._.set_window_box 
     342        add     esp, BOX.sizeof 
     343 
     344        ; NOTE: do we really need this? to be reworked 
     345;       mov     byte[DONT_DRAW_MOUSE], 0 ; mouse pointer 
     346;       mov     byte[MOUSE_BACKGROUND], 0 ; no mouse under 
     347;       mov     byte[MOUSE_DOWN], 0 ; react to mouse up/down 
     348 
     349        ; NOTE: do we really need this? to be reworked 
     350;       call    [draw_pointer] 
     351 
     352  .exit: 
     353        ret 
     354 
     355align 4 
     356;------------------------------------------------------------------------------ 
     357syscall_window_settings: ;///// system function 71 ///////////////////////////// 
     358;------------------------------------------------------------------------------ 
     359;? <description> 
     360;------------------------------------------------------------------------------ 
     361        dec     ebx     ; subfunction #1 - set window caption 
     362        jnz     .exit_fail 
     363 
     364        ; NOTE: only window owner thread can set its caption, 
     365        ;       so there's no parameter for PID/TID 
     366 
     367        mov     edi, [CURRENT_TASK] 
     368        shl     edi, 5 
     369 
     370        mov     [edi * 8 + SLOT_BASE + APPDATA.wnd_caption], ecx 
     371        or      [edi + window_data + WDATA.fl_wstyle], WSTYLE_HASCAPTION 
     372 
     373        call    window._.draw_window_caption 
     374 
     375        xor     eax, eax ; eax = 0 (success) 
     376        ret 
     377 
     378;  .get_window_caption: 
     379;        dec     eax     ; subfunction #2 - get window caption 
     380;        jnz     .exit_fail 
     381 
     382        ; not implemented yet 
     383 
     384  .exit_fail: 
     385        xor     eax, eax 
     386        inc     eax     ; eax = 1 (fail) 
     387        ret 
     388 
     389align 4 
     390;------------------------------------------------------------------------------ 
    272391set_window_defaults: ;///////////////////////////////////////////////////////// 
    273392;------------------------------------------------------------------------------ 
     
    430549 
    431550  .fix_client_box: 
    432         call    set_window_clientbox 
     551        call    window._.set_window_clientbox 
    433552 
    434553        add     edi, WDATA.sizeof 
     
    440559align 4 
    441560;------------------------------------------------------------------------------ 
    442 check_window_position: ;/////////////////////////////////////////////////////// 
    443 ;------------------------------------------------------------------------------ 
    444 ;? Check if window is inside screen area 
    445 ;------------------------------------------------------------------------------ 
    446 ;> edi = pointer to WDATA 
    447 ;------------------------------------------------------------------------------ 
    448         push    eax ebx ecx edx esi 
    449  
    450         mov     eax, [edi + WDATA.box.left] 
    451         mov     ebx, [edi + WDATA.box.top] 
    452         mov     ecx, [edi + WDATA.box.width] 
    453         mov     edx, [edi + WDATA.box.height] 
    454  
    455         mov     esi, [Screen_Max_X] 
    456         cmp     ecx, esi 
    457         ja      .fix_width 
    458  
    459   .check_left: 
    460         or      eax, eax 
    461         jl      .fix_left_low 
    462         add     eax, ecx 
    463         cmp     eax, esi 
    464         jg      .fix_left_high 
    465  
    466   .check_height: 
    467         mov     esi, [Screen_Max_Y] 
    468         cmp     edx, esi 
    469         ja      .fix_height 
    470  
    471   .check_top: 
    472         or      ebx, ebx 
    473         jl      .fix_top_low 
    474         add     ebx, edx 
    475         cmp     ebx, esi 
    476         jg      .fix_top_high 
    477  
    478   .exit: 
    479         pop     esi edx ecx ebx eax 
    480         ret 
    481  
    482   .fix_width: 
    483         mov     ecx, esi 
    484         mov     [edi + WDATA.box.width], esi 
    485         jmp     .check_left 
    486  
    487   .fix_left_low: 
    488         xor     eax, eax 
    489         mov     [edi + WDATA.box.left], eax 
    490         jmp     .check_height 
    491  
    492   .fix_left_high: 
    493         mov     eax, esi 
    494         sub     eax, ecx 
    495         mov     [edi + WDATA.box.left], eax 
    496         jmp     .check_height 
    497  
    498   .fix_height: 
    499         mov     edx, esi 
    500         mov     [edi + WDATA.box.height], esi 
    501         jmp     .check_top 
    502  
    503   .fix_top_low: 
    504         xor     ebx, ebx 
    505         mov     [edi + WDATA.box.top], ebx 
    506         jmp     .exit 
    507  
    508   .fix_top_high: 
    509         mov     ebx, esi 
    510         sub     ebx, edx 
    511         mov     [edi + WDATA.box.top], ebx 
    512         jmp     .exit 
    513  
    514 align 4 
    515 ;------------------------------------------------------------------------------ 
    516561sys_window_mouse: ;//////////////////////////////////////////////////////////// 
    517562;------------------------------------------------------------------------------ 
    518563;? <description> 
    519564;------------------------------------------------------------------------------ 
    520         push    eax 
    521  
    522         mov     eax, [timer_ticks] 
    523         cmp     [new_window_starting], eax 
    524         jb      .exit 
    525  
    526         mov     byte[MOUSE_BACKGROUND], 0 
    527         mov     byte[DONT_DRAW_MOUSE], 0 
    528  
    529         mov     [new_window_starting], eax 
    530  
    531   .exit: 
    532         pop     eax 
     565        ; NOTE: commented out since doesn't provide necessary functionality 
     566        ;       anyway, to be reworked 
     567;       push    eax 
     568; 
     569;       mov     eax, [timer_ticks] 
     570;       cmp     [new_window_starting], eax 
     571;       jb      .exit 
     572; 
     573;       mov     byte[MOUSE_BACKGROUND], 0 
     574;       mov     byte[DONT_DRAW_MOUSE], 0 
     575; 
     576;       mov     [new_window_starting], eax 
     577; 
     578; .exit: 
     579;       pop     eax 
    533580        ret 
    534581 
     
    810857;? Activate window, redrawing if necessary 
    811858;------------------------------------------------------------------------------ 
     859        push    -1 
     860        mov     eax, [TASK_COUNT] 
     861        lea     eax, [WIN_POS + eax * 2] 
     862        cmp     eax, esi 
     863        pop     eax 
     864        je      .exit 
     865 
    812866        ; is it overlapped by another window now? 
    813867        push    ecx 
     
    842896        ; tell application to redraw itself 
    843897        mov     [edi + WDATA.fl_redraw], 1 
    844         mov     byte[MOUSE_DOWN], 0 
    845         ret 
     898        xor     eax, eax 
     899        jmp     .exit 
    846900 
    847901  .do_not_draw: 
    848902        ; no it's not, just activate the window 
    849903        call    window._.window_activate 
    850         mov     byte[MOUSE_DOWN], 0 
    851904        mov     byte[MOUSE_BACKGROUND], 0 
    852905        mov     byte[DONT_DRAW_MOUSE], 0 
     906        xor     eax, eax 
     907 
     908  .exit: 
     909        mov     byte[MOUSE_DOWN], 0 
     910        inc     eax 
    853911        ret 
    854912 
     
    941999 
    9421000align 4 
    943 ;------------------------------------------------------------------------------ 
    944 checkwindows: ;//////////////////////////////////////////////////////////////// 
    945 ;------------------------------------------------------------------------------ 
    946 ;? Check for user-initiated window operations 
    947 ;------------------------------------------------------------------------------ 
    948         pushad 
    949  
     1001; TODO: remove this proc 
     1002;------------------------------------------------------------------------------ 
     1003window_check_events: ;///////////////////////////////////////////////////////// 
     1004;------------------------------------------------------------------------------ 
     1005;? <description> 
     1006;------------------------------------------------------------------------------ 
    9501007        ; do we have window minimize/restore request? 
    9511008        cmp     [window_minimize], 0 
    952         je      .check_for_mouse_buttons_state 
     1009        je      .exit 
    9531010 
    9541011        ; okay, minimize or restore top-most window and exit 
     
    9591016        jnz     @f 
    9601017        call    minimize_window 
    961         jmp     .check_for_mouse_buttons_state 
     1018        jmp     .exit 
     1019 
    9621020    @@: call    restore_minimized_window 
    9631021 
    964   .check_for_mouse_buttons_state: 
    965         ; do we have any mouse buttons pressed? 
    966         cmp     byte[BTN_DOWN], 0 
    967         jne     .mouse_buttons_pressed 
    968  
    969         mov     [bPressedMouseXY_W], 0 
    970         jmp     .exit 
    971  
    972   .mouse_buttons_pressed: 
    973         ; yes we do, iterate and ... 
    974         mov     esi, [TASK_COUNT] 
    975         inc     esi 
    976  
    977         cmp     [bPressedMouseXY_W], 1 
    978         ja      .next_window 
    979         inc     [bPressedMouseXY_W] 
    980         jnc     .next_window 
    981         push    dword[MOUSE_X] 
    982         pop     dword[mx] 
    983  
    984   .next_window: 
    985         cmp     esi, 2 
    986         jb      .exit 
    987  
    988         dec     esi 
    989  
    990         ; is that window not minimized? 
    991         movzx   edi, word[WIN_POS + esi * 2] 
     1022  .exit: 
     1023        ret 
     1024 
     1025align 4 
     1026;------------------------------------------------------------------------------ 
     1027sys_window_maximize_handler: ;///////////////////////////////////////////////// 
     1028;------------------------------------------------------------------------------ 
     1029;? <description> 
     1030;------------------------------------------------------------------------------ 
     1031;> esi = process slot 
     1032;------------------------------------------------------------------------------ 
     1033        mov     edi, esi 
    9921034        shl     edi, 5 
    9931035        add     edi, window_data 
    994         test    [edi + WDATA.fl_wstate], WSTATE_MINIMIZED 
    995         jnz     .next_window 
    996  
    997         movzx   eax, [mx] 
    998         movzx   ebx, [my] 
    999  
    1000         ; is the cursor inside screen bounds of that window? 
    1001         mov     ecx, [edi + WDATA.box.left] 
    1002         mov     edx, [edi + WDATA.box.top] 
    1003         cmp     eax, ecx 
    1004         jl      .next_window 
    1005         cmp     ebx, edx 
    1006         jl      .next_window 
    1007         add     ecx, [edi + WDATA.box.width] 
    1008         add     edx, [edi + WDATA.box.height] 
    1009         cmp     eax, ecx 
    1010         jge     .next_window 
    1011         cmp     ebx, edx 
    1012         jge     .next_window 
    1013  
    1014         ; is that a top-most (which means active) window? 
    1015         cmp     esi, [TASK_COUNT] 
    1016         je      .check_for_moving_or_resizing 
    1017  
    1018         ; no it's not, did we just press mouse button down above it or was it 
    1019         ; already pressed before? 
    1020         cmp     [bPressedMouseXY_W], 1 
    1021         ja      .exit 
    1022  
    1023         ; okay, we just pressed the button, activate this window and exit 
    1024         lea     esi, [WIN_POS + esi * 2] 
    1025         call    waredraw 
    1026         jmp     .exit 
    1027  
    1028   .check_for_moving_or_resizing: 
    1029         ; is that window movable? 
    1030         test    byte[edi + WDATA.cl_titlebar + 3], 0x01 
    1031         jnz     .exit 
    1032  
    1033         ; yes it is, is it rolled up? 
    1034         test    [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP 
    1035         jnz     .check_for_cursor_on_caption 
    1036  
    1037         ; no it's not, can it be resized then? 
    1038         mov     [do_resize_from_corner], 0 
    1039         mov     dl, [edi + WDATA.fl_wstyle] 
    1040         and     dl, 0x0f 
    1041         cmp     dl, 0x00 
    1042         je      .check_for_cursor_on_caption 
    1043         cmp     dl, 0x01 
    1044         je      .check_for_cursor_on_caption 
    1045         cmp     dl, 0x04 
    1046         je      .check_for_cursor_on_caption 
    1047  
    1048         ; are we going to resize it? 
    1049         mov     edx, [edi + WDATA.box.top] 
    1050         add     edx, [edi + WDATA.box.height] 
    1051         sub     edx, 6 
    1052         cmp     ebx, edx 
    1053         jl      .check_for_cursor_on_caption 
    1054  
    1055         ; yes we do, remember that 
    1056         mov     [do_resize_from_corner], 1 
    1057         jmp     .set_move_resize_flag 
    1058  
    1059   .check_for_cursor_on_caption: 
    1060         ; is the cursor inside window titlebar? 
    1061         push    eax 
    1062         call    window._.get_titlebar_height 
    1063         add     eax, [edi + WDATA.box.top] 
    1064         cmp     ebx, eax 
    1065         pop     eax 
    1066         jge     .exit 
    1067  
    1068         ; calculate duration between two clicks 
    1069         mov     ecx, [timer_ticks] 
    1070         mov     edx, ecx 
    1071         sub     edx, [latest_window_touch] 
    1072         mov     [latest_window_touch], ecx 
    1073         mov     [latest_window_touch_delta], edx 
    1074  
    1075   .set_move_resize_flag: 
    1076         mov     cl, [BTN_DOWN] 
    1077         mov     [do_resize], cl 
    1078  
    1079         mov     ecx, [edi + WDATA.box.left] 
    1080         mov     edx, [edi + WDATA.box.top] 
    1081  
    1082         push    ecx edx 
    1083         mov     [draw_limits.left], ecx 
    1084         mov     [draw_limits.top], edx 
    1085         add     ecx, [edi + WDATA.box.width] 
    1086         add     edx, [edi + WDATA.box.height] 
    1087         mov     [draw_limits.right], ecx 
    1088         mov     [draw_limits.bottom], edx 
    1089         pop     edx ecx 
    1090  
    1091         ; calculate window-relative cursor coordinates 
    1092         sub     eax, ecx 
    1093         sub     ebx, edx 
    1094  
    1095         push    dword[MOUSE_X] 
    1096         pop     dword[WIN_TEMP_XY] 
    1097  
    1098         ; save old window coordinates 
    1099         push    eax 
    1100         mov     eax, [edi + WDATA.box.left] 
    1101         mov     [old_window_pos.left], eax 
    1102         mov     [new_window_pos.left], eax 
    1103         mov     eax, [edi + WDATA.box.top] 
    1104         mov     [old_window_pos.top], eax 
    1105         mov     [new_window_pos.top], eax 
    1106         mov     eax, [edi + WDATA.box.width] 
    1107         mov     [old_window_pos.width], eax 
    1108         mov     [new_window_pos.width], eax 
    1109         mov     eax, [edi + WDATA.box.height] 
    1110         mov     [old_window_pos.height], eax 
    1111         mov     [new_window_pos.height], eax 
    1112         pop     eax 
    1113  
    1114         ; draw negative moving/sizing frame 
    1115         call    window._.draw_window_frames 
    1116  
    1117         mov     [reposition], 0 
    1118         mov     byte[MOUSE_DOWN], 1 
    1119  
    1120   .next_mouse_state_check: 
    1121         ; process OS events 
    1122         mov     byte[DONT_DRAW_MOUSE], 1 
    1123         call    checkidle 
    1124         call    checkVga_N13 
    1125         mov     byte[MOUSE_BACKGROUND], 0 
    1126         call    [draw_pointer] 
    1127         pushad 
    1128         call    stack_handler 
    1129         popad 
    1130  
    1131         ; did cursor position change? 
    1132         mov     esi, [WIN_TEMP_XY] 
    1133         cmp     esi, [MOUSE_X] 
    1134         je      .check_for_new_mouse_buttons_state 
    1135  
    1136         ; yes it did, calculate window-relative cursor coordinates 
    1137         movzx   ecx, word[MOUSE_X] 
    1138         movzx   edx, word[MOUSE_Y] 
    1139         sub     ecx, eax 
    1140         sub     edx, ebx 
    1141  
    1142         push    eax ebx 
    1143  
    1144         ; we're going to draw new frame, erasing the old one 
    1145         call    window._.draw_window_frames 
    1146  
    1147         ; are we moving it right now? 
    1148         cmp     [do_resize_from_corner], 0 
    1149         jne     .resize_window 
    1150  
    1151         ; yes we do, check if it's inside the screen area 
    1152         mov     eax, [Screen_Max_X] 
    1153         mov     ebx, [Screen_Max_Y] 
    1154  
    1155         mov     [new_window_pos.left], 0 
    1156         or      ecx, ecx 
    1157         jle     .check_for_new_vert_cursor_pos 
    1158         mov     [reposition], 1 
    1159         sub     eax, [new_window_pos.width] 
    1160         mov     [new_window_pos.left], eax 
    1161         cmp     ecx, eax 
    1162         jge     .check_for_new_vert_cursor_pos 
    1163         mov     [new_window_pos.left], ecx 
    1164  
    1165   .check_for_new_vert_cursor_pos: 
    1166         mov     [new_window_pos.top], 0 
    1167         or      edx, edx 
    1168         jle     .draw_new_window_frame 
    1169         mov     [reposition], 1 
    1170         sub     ebx, [new_window_pos.height] 
    1171         mov     [new_window_pos.top], ebx 
    1172         cmp     edx, ebx 
    1173         jge     .draw_new_window_frame 
    1174         mov     [new_window_pos.top], edx 
    1175         jmp     .draw_new_window_frame 
    1176  
    1177   .resize_window: 
    1178         push    eax ebx edx 
    1179  
    1180         mov     edx, edi 
    1181         sub     edx, window_data 
    1182         lea     edx, [SLOT_BASE + edx * 8] 
    1183  
    1184         movzx   eax, word[MOUSE_X] 
    1185         cmp     eax, [edi + WDATA.box.left] 
    1186         jb      .fix_new_vert_size 
    1187         sub     eax, [edi + WDATA.box.left] 
    1188         cmp     eax, 32 
    1189         jge     @f 
    1190         mov     eax, 32 
    1191     @@: mov     [new_window_pos.width], eax 
    1192  
    1193   .fix_new_vert_size: 
    1194         call    window._.get_rolledup_height 
    1195         mov     ebx, eax 
    1196         movzx   eax, word[MOUSE_Y] 
    1197         cmp     eax, [edi + WDATA.box.top] 
    1198         jb      .set_reposition_flag 
    1199         sub     eax, [edi + WDATA.box.top] 
    1200         cmp     eax, ebx 
    1201         jge     @f 
    1202         mov     eax, ebx 
    1203     @@: mov     [new_window_pos.height], eax 
    1204  
    1205   .set_reposition_flag: 
    1206         mov     [reposition], 1 
    1207  
    1208         pop     edx ebx eax 
    1209  
    1210   .draw_new_window_frame: 
    1211         pop     ebx eax 
    1212  
    1213         ; draw new window moving/sizing frame 
    1214         call    window._.draw_window_frames 
    1215  
    1216         mov     esi, [MOUSE_X] 
    1217         mov     [WIN_TEMP_XY], esi 
    1218  
    1219   .check_for_new_mouse_buttons_state: 
    1220         ; did user release mouse button(s)? 
    1221         cmp     byte[BTN_DOWN], 0 
    1222         jne     .next_mouse_state_check 
    1223  
    1224         ; yes he did, moving/sizing is over 
    1225         mov     byte[DONT_DRAW_MOUSE], 1 
    1226         mov     cl, 0 
    1227         test    [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED 
    1228         jnz     .check_other_actions 
    1229  
    1230         mov     cl, [reposition] 
    1231  
    1232         ; draw negative frame once again to hide it 
    1233         call    window._.draw_window_frames 
    1234  
    1235         ; save new window bounds 
    1236         mov     eax, [new_window_pos.left] 
    1237         mov     [edi + WDATA.box.left], eax 
    1238         mov     eax, [new_window_pos.top] 
    1239         mov     [edi + WDATA.box.top], eax 
    1240         mov     eax, [new_window_pos.width] 
    1241         mov     [edi + WDATA.box.width], eax 
    1242         mov     eax, [new_window_pos.height] 
    1243         mov     [edi + WDATA.box.height], eax 
    1244         call    set_window_clientbox 
    1245  
    1246         cmp     cl, 1 
    1247         jne     .check_other_actions 
    1248         push    esi edi ecx 
    1249         mov     esi, edi 
    1250         mov     ecx, 2 
    1251         test    [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP or WSTATE_MAXIMIZED 
    1252         jnz     @f 
    1253         add     ecx, 2 
    1254     @@: sub     edi, window_data 
    1255         shr     edi, 5 
    1256         shl     edi, 8 
    1257         add     edi, SLOT_BASE + APPDATA.saved_box 
    1258         cld 
    1259         rep     movsd 
    1260         pop     ecx edi esi 
    1261  
    1262   .check_other_actions: 
    1263         mov     [reposition], cl 
    1264  
    1265         pushad 
    1266  
    1267         mov     dl, [edi + WDATA.fl_wstyle] 
    1268         and     dl, 0x0f 
    1269         cmp     dl, 0x00 
    1270         je      .check_if_window_fits_screen 
    1271         cmp     dl, 0x01 
    1272         je      .check_if_window_fits_screen 
    1273  
    1274         cmp     cl, 1 
    1275         je      .no_window_sizing 
    1276         mov     edx, edi 
    1277         sub     edx, window_data 
    1278         shr     edx, 5 
    1279         shl     edx, 8 
    1280         add     edx, SLOT_BASE 
    1281  
    1282         ; did we right-click on titlebar? 
    1283         cmp     [do_resize], 2 
    1284         jne     .check_maximization_request 
    1285  
    1286         ; yes we did, toggle normal/rolled up window state 
    1287         xor     [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP 
    1288         mov     [reposition], 1 
    1289  
    1290         ; calculate and set appropriate window height 
    1291         test    [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP 
    1292         jz      @f 
    1293         call    window._.get_rolledup_height 
    1294         jmp     .set_new_window_height 
    1295     @@: mov     eax, [edx + APPDATA.saved_box.height] 
    1296         test    [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED 
    1297         jz      .set_new_window_height 
    1298         mov     eax, [screen_workarea.bottom] 
    1299         sub     eax, [screen_workarea.top] 
    1300  
    1301   .set_new_window_height: 
    1302         mov     [edi + WDATA.box.height], eax 
    1303         add     eax, [edi + WDATA.box.top] 
    1304         cmp     eax, [Screen_Max_Y] 
    1305         jbe     @f 
    1306         mov     eax, [Screen_Max_Y] 
    1307         sub     eax, [edi + WDATA.box.height] 
    1308         mov     [edi + WDATA.box.top], eax 
    1309     @@: call    check_window_position 
    1310         call    set_window_clientbox 
    1311  
    1312   .check_maximization_request: 
     1036 
    13131037        ; can window change its height? 
    1314         push    edx 
    13151038        mov     dl, [edi + WDATA.fl_wstyle] 
    13161039        and     dl, 0x0f 
    13171040        cmp     dl, 0x04 
    1318         pop     edx 
    1319         je      .check_if_window_fits_screen 
    1320  
    1321         ; was it really a maximize/restore request? 
    1322         cmp     [do_resize], 1 
    1323         jne     .check_if_window_fits_screen 
    1324         cmp     [do_resize_from_corner], 0 
    1325         jne     .check_if_window_fits_screen 
    1326         cmp     [latest_window_touch_delta], 50 
    1327         jg      .check_if_window_fits_screen 
    1328  
    1329         ; yes is was, toggle normal/maximized window state 
    1330         xor     [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED 
    1331         mov     [reposition], 1 
     1041        je      .exit 
     1042 
     1043        ; toggle normal/maximized window state 
     1044        mov     bl, [edi + WDATA.fl_wstate] 
     1045        xor     bl, WSTATE_MAXIMIZED 
    13321046 
    13331047        ; calculate and set appropriate window bounds 
    1334         test    [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED 
    1335         jz      .restore_normal_window_size 
     1048        test    bl, WSTATE_MAXIMIZED 
     1049        jz      .restore_size 
     1050 
    13361051        mov     eax, [screen_workarea.left] 
    1337         mov     [edi + WDATA.box.left], eax 
    1338         sub     eax, [screen_workarea.right] 
     1052        mov     ecx, [screen_workarea.top] 
     1053        push    [screen_workarea.bottom] \ 
     1054                [screen_workarea.right] \ 
     1055                ecx \ 
     1056                eax 
     1057        sub     [esp + BOX.width], eax 
     1058        sub     [esp + BOX.height], ecx 
     1059        mov     eax, esp 
     1060        jmp     .set_box 
     1061 
     1062  .restore_size: 
     1063        mov     eax, esi 
     1064        shl     eax, 8 
     1065        add     eax, SLOT_BASE + APPDATA.saved_box 
     1066        push    [eax + BOX.height] \ 
     1067                [eax + BOX.width] \ 
     1068                [eax + BOX.top] \ 
     1069                [eax + BOX.left] 
     1070        mov     eax, esp 
     1071 
     1072  .set_box: 
     1073        test    bl, WSTATE_ROLLEDUP 
     1074        jz      @f 
     1075 
     1076        xchg    eax, ecx 
     1077        call    window._.get_rolledup_height 
     1078        mov     [ecx + BOX.height], eax 
     1079        xchg    eax, ecx 
     1080 
     1081    @@: call    window._.set_window_box 
     1082        add     esp, BOX.sizeof 
     1083 
     1084  .exit: 
     1085        ret 
     1086 
     1087align 4 
     1088;------------------------------------------------------------------------------ 
     1089sys_window_rollup_handler: ;/////////////////////////////////////////////////// 
     1090;------------------------------------------------------------------------------ 
     1091;? <description> 
     1092;------------------------------------------------------------------------------ 
     1093;> esi = process slot 
     1094;------------------------------------------------------------------------------ 
     1095        mov     edx, esi 
     1096        shl     edx, 8 
     1097        add     edx, SLOT_BASE 
     1098 
     1099        ; toggle normal/rolled up window state 
     1100        mov     bl, [edi + WDATA.fl_wstate] 
     1101        xor     bl, WSTATE_ROLLEDUP 
     1102 
     1103        ; calculate and set appropriate window bounds 
     1104        test    bl, WSTATE_ROLLEDUP 
     1105        jz      .restore_size 
     1106 
     1107        call    window._.get_rolledup_height 
     1108        push    eax \ 
     1109                [edi + WDATA.box.width] \ 
     1110                [edi + WDATA.box.top] \ 
     1111                [edi + WDATA.box.left] 
     1112        mov     eax, esp 
     1113        jmp     .set_box 
     1114 
     1115  .restore_size: 
     1116        test    bl, WSTATE_MAXIMIZED 
     1117        jnz     @f 
     1118        add     esp, -BOX.sizeof 
     1119        lea     eax, [edx + APPDATA.saved_box] 
     1120        jmp     .set_box 
     1121 
     1122    @@: mov     eax, [screen_workarea.top] 
     1123        push    [screen_workarea.bottom] \ 
     1124                [edi + WDATA.box.width] \ 
     1125                eax \ 
     1126                [edi + WDATA.box.left] 
     1127        sub     [esp + BOX.height], eax 
     1128        mov     eax, esp 
     1129 
     1130  .set_box: 
     1131        call    window._.set_window_box 
     1132        add     esp, BOX.sizeof 
     1133 
     1134        ret 
     1135 
     1136align 4 
     1137;------------------------------------------------------------------------------ 
     1138sys_window_start_moving_handler: ;///////////////////////////////////////////// 
     1139;------------------------------------------------------------------------------ 
     1140;? <description> 
     1141;------------------------------------------------------------------------------ 
     1142;> eax = old (original) window box 
     1143;> esi = process slot 
     1144;------------------------------------------------------------------------------ 
     1145        mov     edi, eax 
     1146        call    window._.draw_negative_box 
     1147 
     1148        ret 
     1149 
     1150align 4 
     1151;------------------------------------------------------------------------------ 
     1152sys_window_end_moving_handler: ;/////////////////////////////////////////////// 
     1153;------------------------------------------------------------------------------ 
     1154;? <description> 
     1155;------------------------------------------------------------------------------ 
     1156;> eax = old (original) window box 
     1157;> ebx = new (final) window box 
     1158;> esi = process slot 
     1159;------------------------------------------------------------------------------ 
     1160        mov     edi, ebx 
     1161        call    window._.draw_negative_box 
     1162 
     1163        mov     edi, esi 
     1164        shl     edi, 5 
     1165        add     edi, window_data 
     1166 
     1167        mov     eax, ebx 
     1168        mov     bl, [edi + WDATA.fl_wstate] 
     1169        call    window._.set_window_box 
     1170        ret 
     1171 
     1172align 4 
     1173;------------------------------------------------------------------------------ 
     1174sys_window_moving_handler: ;/////////////////////////////////////////////////// 
     1175;------------------------------------------------------------------------------ 
     1176;? <description> 
     1177;------------------------------------------------------------------------------ 
     1178;> eax = old (from previous call) window box 
     1179;> ebx = new (current) window box 
     1180;> esi = process_slot 
     1181;------------------------------------------------------------------------------ 
     1182        mov     edi, eax 
     1183        call    window._.draw_negative_box 
     1184        mov     edi, ebx 
     1185        call    window._.draw_negative_box 
     1186        ret 
     1187 
     1188;============================================================================== 
     1189;///// private functions ////////////////////////////////////////////////////// 
     1190;============================================================================== 
     1191 
     1192iglobal 
     1193  FuncTable syscall_display_settings, ftable, \ 
     1194    00, 01, 02, 03, 04, 05, 06, 07, 08 
     1195 
     1196  align 4 
     1197  window_topleft dd \ 
     1198    1, 21, \ ;type 0 
     1199    0,  0, \ ;type 1 
     1200    5, 20, \ ;type 2 
     1201    5,  ?, \ ;type 3 {set by skin} 
     1202    5,  ?    ;type 4 {set by skin} 
     1203endg 
     1204 
     1205;uglobal 
     1206  ; NOTE: commented out since doesn't provide necessary functionality anyway, 
     1207  ;       to be reworked 
     1208; new_window_starting       dd ? 
     1209;endg 
     1210 
     1211align 4 
     1212;------------------------------------------------------------------------------ 
     1213window._.invalidate_screen: ;////////////////////////////////////////////////// 
     1214;------------------------------------------------------------------------------ 
     1215;? <description> 
     1216;------------------------------------------------------------------------------ 
     1217;> eax = old (original) window box 
     1218;> ebx = new (final) window box 
     1219;> edi = pointer to WDATA struct 
     1220;------------------------------------------------------------------------------ 
     1221        push    eax ebx 
     1222 
     1223        ; TODO: do we really need `draw_limits`? 
     1224        mov     ecx, [eax + BOX.left] 
     1225        mov     edx, [ebx + BOX.left] 
     1226        cmp     ecx, edx 
     1227        jle     @f 
     1228        xchg    ecx, edx 
     1229    @@: mov     [draw_limits.left], ecx 
     1230        mov     ecx, [eax + BOX.width] 
     1231        cmp     ecx, [ebx + BOX.width] 
     1232        jae     @f 
     1233        mov     ecx, [ebx + BOX.width] 
     1234    @@: add     ecx, edx 
     1235        mov     [draw_limits.right], ecx 
     1236        mov     ecx, [eax + BOX.top] 
     1237        mov     edx, [ebx + BOX.top] 
     1238        cmp     ecx, edx 
     1239        jle     @f 
     1240        xchg    ecx, edx 
     1241    @@: mov     [draw_limits.top], ecx 
     1242        mov     ecx, [eax + BOX.height] 
     1243        cmp     ecx, [ebx + BOX.height] 
     1244        jae     @f 
     1245        mov     ecx, [ebx + BOX.height] 
     1246    @@: add     ecx, edx 
     1247        mov     [draw_limits.bottom], ecx 
     1248 
     1249        ; recalculate screen buffer at old position 
     1250        push    ebx 
     1251        mov     edx, [eax + BOX.height] 
     1252        mov     ecx, [eax + BOX.width] 
     1253        mov     ebx, [eax + BOX.top] 
     1254        mov     eax, [eax + BOX.left] 
     1255        add     ecx, eax 
     1256        add     edx, ebx 
     1257        call    calculatescreen 
     1258        pop     eax 
     1259 
     1260        ; recalculate screen buffer at new position 
     1261        mov     edx, [eax + BOX.height] 
     1262        mov     ecx, [eax + BOX.width] 
     1263        mov     ebx, [eax + BOX.top] 
     1264        mov     eax, [eax + BOX.left] 
     1265        add     ecx, eax 
     1266        add     edx, ebx 
     1267        call    calculatescreen 
     1268 
     1269        mov     eax, edi 
     1270        call    redrawscreen 
     1271 
     1272        ; tell window to redraw itself 
     1273        mov     [edi + WDATA.fl_redraw], 1 
     1274 
     1275        pop     ebx eax 
     1276        ret 
     1277 
     1278align 4 
     1279;------------------------------------------------------------------------------ 
     1280window._.set_window_box: ;///////////////////////////////////////////////////// 
     1281;------------------------------------------------------------------------------ 
     1282;? <description> 
     1283;------------------------------------------------------------------------------ 
     1284;> eax = pointer to BOX struct 
     1285;> bl = new window state flags 
     1286;> edi = pointer to WDATA struct 
     1287;------------------------------------------------------------------------------ 
     1288        push    eax ebx esi 
     1289 
     1290        add     esp, -BOX.sizeof 
     1291 
     1292        mov     ebx, esp 
     1293        lea     esi, [edi + WDATA.box] 
     1294        xchg    eax, esi 
     1295        mov     ecx, BOX.sizeof 
     1296        call    memmove 
     1297        xchg    eax, esi 
     1298        xchg    ebx, esi 
     1299        call    memmove 
     1300        xchg    ebx, esi 
     1301 
     1302        call    window._.check_window_position 
     1303        call    window._.set_window_clientbox 
     1304        call    window._.invalidate_screen 
     1305 
     1306        add     esp, BOX.sizeof 
     1307 
     1308        mov     cl, [esp + 4] 
     1309        mov     ch, cl 
     1310        xchg    cl, [edi + WDATA.fl_wstate] 
     1311 
     1312        or      cl, ch 
     1313        test    cl, WSTATE_MAXIMIZED 
     1314        jnz     .exit 
     1315 
     1316        mov     eax, edi 
     1317        sub     eax, window_data 
     1318        shl     eax, 3 
     1319        add     eax, SLOT_BASE 
     1320 
     1321        lea     ebx, [edi + WDATA.box] 
     1322        xchg    esp, ebx 
     1323 
     1324        pop     [eax + APPDATA.saved_box.left] \ 
     1325                [eax + APPDATA.saved_box.top] \ 
     1326                [eax + APPDATA.saved_box.width] \ 
     1327                edx 
     1328 
     1329        xchg    esp, ebx 
     1330 
     1331        test    ch, WSTATE_ROLLEDUP 
     1332        jnz     .exit 
     1333 
     1334        mov     [eax + APPDATA.saved_box.height], edx 
     1335 
     1336  .exit: 
     1337        pop     esi ebx eax 
     1338        ret 
     1339 
     1340align 4 
     1341;------------------------------------------------------------------------------ 
     1342window._.set_window_clientbox: ;/////////////////////////////////////////////// 
     1343;------------------------------------------------------------------------------ 
     1344;? <description> 
     1345;------------------------------------------------------------------------------ 
     1346;> edi = pointer to WDATA struct 
     1347;------------------------------------------------------------------------------ 
     1348        push    eax ecx edi 
     1349 
     1350        mov     eax, [_skinh] 
     1351        mov     [window_topleft + 8 * 3 + 4], eax 
     1352        mov     [window_topleft + 8 * 4 + 4], eax 
     1353 
     1354        mov     ecx, edi 
     1355        sub     edi, window_data 
     1356        shl     edi, 3 
     1357        test    [ecx + WDATA.fl_wstyle], WSTYLE_CLIENTRELATIVE 
     1358        jz      .whole_window 
     1359 
     1360        movzx   eax, [ecx + WDATA.fl_wstyle] 
     1361        and     eax, 0x0F 
     1362        mov     eax, [eax * 8 + window_topleft + 0] 
     1363        mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.left], eax 
     1364        shl     eax, 1 
    13391365        neg     eax 
     1366        add     eax, [ecx + WDATA.box.width] 
     1367        mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.width], eax 
     1368 
     1369        movzx   eax, [ecx + WDATA.fl_wstyle] 
     1370        and     eax, 0x0F 
     1371        push    [eax * 8 + window_topleft + 0] 
     1372        mov     eax, [eax * 8 + window_topleft + 4] 
     1373        mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.top], eax 
     1374        neg     eax 
     1375        sub     eax, [esp] 
     1376        add     eax, [ecx + WDATA.box.height] 
     1377        mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.height], eax 
     1378        add     esp, 4 
     1379        jmp     .exit 
     1380 
     1381  .whole_window: 
     1382        xor     eax, eax 
     1383        mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.left], eax 
     1384        mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.top], eax 
     1385        mov     eax, [ecx + WDATA.box.width] 
     1386        mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.width], eax 
     1387        mov     eax, [ecx + WDATA.box.height] 
     1388        mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.height], eax 
     1389 
     1390  .exit: 
     1391        pop     edi ecx eax 
     1392        ret 
     1393 
     1394align 4 
     1395;------------------------------------------------------------------------------ 
     1396window._.sys_set_window: ;///////////////////////////////////////////////////// 
     1397;------------------------------------------------------------------------------ 
     1398;? <description> 
     1399;------------------------------------------------------------------------------ 
     1400;< edx = pointer to WDATA struct 
     1401;------------------------------------------------------------------------------ 
     1402        mov     eax, [CURRENT_TASK] 
     1403        shl     eax, 5 
     1404        add     eax, window_data 
     1405 
     1406        ; save window colors 
     1407        mov     [eax + WDATA.cl_workarea], edx 
     1408        mov     [eax + WDATA.cl_titlebar], esi 
     1409        mov     [eax + WDATA.cl_frames], edi 
     1410 
     1411        mov     edi, eax 
     1412 
     1413        ; was it already defined before? 
     1414        test    [edi + WDATA.fl_wdrawn], 1 
     1415        jnz     .set_client_box 
     1416 
     1417        ; NOTE: commented out since doesn't provide necessary functionality 
     1418        ;       anyway, to be reworked 
     1419;       mov     eax, [timer_ticks] ; [0xfdf0] 
     1420;       add     eax, 100 
     1421;       mov     [new_window_starting], eax 
     1422 
     1423        ; no it wasn't, performing initial window definition 
     1424        movzx   eax, bx 
    13401425        mov     [edi + WDATA.box.width], eax 
    1341         mov     eax, [screen_workarea.top] 
    1342         mov     [edi + WDATA.box.top], eax 
    1343         test    [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP 
    1344         jnz     .calculate_window_client_area 
    1345         sub     eax, [screen_workarea.bottom] 
    1346         neg     eax 
     1426        movzx   eax, cx 
    13471427        mov     [edi + WDATA.box.height], eax 
    1348         jmp     .calculate_window_client_area 
    1349  
    1350   .restore_normal_window_size: 
    1351         push    [edi + WDATA.box.height] 
    1352         push    edi 
    1353         lea     esi, [edx + APPDATA.saved_box] 
    1354         mov     ecx, 4 
    1355         cld 
    1356         rep     movsd 
    1357         pop     edi 
    1358         pop     eax 
    1359         test    [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP 
    1360         jz      .calculate_window_client_area 
    1361         mov     [edi + WDATA.box.height], eax 
    1362  
    1363   .calculate_window_client_area: 
    1364         call    set_window_clientbox 
    1365  
    1366   .check_if_window_fits_screen: 
    1367         ; does window fit into screen area? 
    1368         mov     eax, [edi + WDATA.box.top] 
    1369         add     eax, [edi + WDATA.box.height] 
    1370         cmp     eax, [Screen_Max_Y] 
    1371         jbe     .no_window_sizing 
    1372         mov     eax, [edi + WDATA.box.left] 
    1373         add     eax, [edi + WDATA.box.width] 
    1374         cmp     eax, [Screen_Max_X] 
    1375         jbe     .no_window_sizing 
    1376  
    1377         ; no it doesn't, fix that 
    1378         mov     eax, [Screen_Max_X] 
    1379         sub     eax, [edi + WDATA.box.width] 
    1380         mov     [edi + WDATA.box.left], eax 
    1381         mov     eax, [Screen_Max_Y] 
    1382         sub     eax, [edi + WDATA.box.height] 
    1383         mov     [edi + WDATA.box.top], eax 
    1384         call    set_window_clientbox 
    1385  
    1386   .no_window_sizing: 
    1387         popad 
    1388  
    1389         ; did somethins actually change its place? 
    1390         cmp     [reposition], 0 
    1391         je      .reset_vars 
    1392  
    1393         mov     byte[DONT_DRAW_MOUSE], 1 
    1394  
    1395         push    eax ebx ecx edx 
    1396  
    1397         ; recalculate screen buffer at new position 
     1428        sar     ebx, 16 
     1429        sar     ecx, 16 
     1430        mov     [edi + WDATA.box.left], ebx 
     1431        mov     [edi + WDATA.box.top], ecx 
     1432 
     1433        call    window._.check_window_position 
     1434 
     1435        push    ecx edi 
     1436 
     1437        mov     cl, [edi + WDATA.fl_wstyle] 
     1438        mov     eax, [edi + WDATA.cl_frames] 
     1439 
     1440        sub     edi, window_data 
     1441        shl     edi, 3 
     1442        add     edi, SLOT_BASE 
     1443 
     1444        and     cl, 0x0F 
     1445        cmp     cl, 3 
     1446        je      @f 
     1447        cmp     cl, 4 
     1448        je      @f 
     1449 
     1450        xor     eax, eax 
     1451 
     1452    @@: mov     [edi + APPDATA.wnd_caption], eax 
     1453 
     1454        mov     esi, [esp] 
     1455        add     edi, APPDATA.saved_box 
     1456        movsd 
     1457        movsd 
     1458        movsd 
     1459        movsd 
     1460 
     1461        pop     edi ecx 
     1462 
     1463        mov     esi, [CURRENT_TASK] 
     1464        movzx   esi, word[WIN_STACK + esi * 2] 
     1465        lea     esi, [WIN_POS + esi * 2] 
     1466        call    waredraw 
     1467 
    13981468        mov     eax, [edi + WDATA.box.left] 
    13991469        mov     ebx, [edi + WDATA.box.top] 
     
    14041474        call    calculatescreen 
    14051475 
    1406         ; recalculate screen buffer at old position 
    1407         mov     eax, [old_window_pos.left] 
    1408         mov     ebx, [old_window_pos.top] 
    1409         mov     ecx, [old_window_pos.width] 
    1410         mov     edx, [old_window_pos.height] 
    1411         add     ecx, eax 
    1412         add     edx, ebx 
    1413         call    calculatescreen 
    1414  
    1415         pop     edx ecx ebx eax 
    1416  
    1417         mov     eax, edi 
    1418         call    redrawscreen 
    1419  
    1420         ; tell window to redraw itself 
    1421         mov     [edi + WDATA.fl_redraw], 1 
    1422  
    1423         ; wait a bit for window to redraw itself 
    1424         mov     ecx, 100 
    1425  
    1426   .next_idle_cycle: 
    1427         mov     byte[DONT_DRAW_MOUSE], 1 
    1428         call    checkidle 
    1429         cmp     [edi + WDATA.fl_redraw], 0 
    1430         jz      .reset_vars 
    1431         loop    .next_idle_cycle 
    1432  
    1433   .reset_vars: 
    1434         mov     byte[DONT_DRAW_MOUSE], 0 ; mouse pointer 
    1435         mov     byte[MOUSE_BACKGROUND], 0 ; no mouse under 
    1436         mov     byte[MOUSE_DOWN], 0 ; react to mouse up/down 
     1476        mov     byte[KEY_COUNT], 0           ; empty keyboard buffer 
     1477        mov     byte[BTN_COUNT], 0           ; empty button buffer 
     1478 
     1479  .set_client_box: 
     1480        ; update window client box coordinates 
     1481        call    window._.set_window_clientbox 
     1482 
     1483        ; reset window redraw flag and exit 
     1484        mov     [edi + WDATA.fl_redraw], 0 
     1485        mov     edx, edi 
     1486        ret 
     1487 
     1488align 4 
     1489;------------------------------------------------------------------------------ 
     1490window._.check_window_position: ;////////////////////////////////////////////// 
     1491;------------------------------------------------------------------------------ 
     1492;? Check if window is inside screen area 
     1493;------------------------------------------------------------------------------ 
     1494;> edi = pointer to WDATA 
     1495;------------------------------------------------------------------------------ 
     1496        push    eax ebx ecx edx esi 
     1497 
     1498        mov     eax, [edi + WDATA.box.left] 
     1499        mov     ebx, [edi + WDATA.box.top] 
     1500        mov     ecx, [edi + WDATA.box.width] 
     1501        mov     edx, [edi + WDATA.box.height] 
     1502 
     1503        mov     esi, [Screen_Max_X] 
     1504        cmp     ecx, esi 
     1505        ja      .fix_width_high 
     1506 
     1507  .check_left: 
     1508        or      eax, eax 
     1509        jl      .fix_left_low 
     1510        add     eax, ecx 
     1511        cmp     eax, esi 
     1512        jg      .fix_left_high 
     1513 
     1514  .check_height: 
     1515        mov     esi, [Screen_Max_Y] 
     1516        cmp     edx, esi 
     1517        ja      .fix_height_high 
     1518 
     1519  .check_top: 
     1520        or      ebx, ebx 
     1521        jl      .fix_top_low 
     1522        add     ebx, edx 
     1523        cmp     ebx, esi 
     1524        jg      .fix_top_high 
    14371525 
    14381526  .exit: 
    1439         popad 
    1440         ret 
    1441  
    1442 ;============================================================================== 
    1443 ;///// private functions ////////////////////////////////////////////////////// 
    1444 ;============================================================================== 
     1527        pop     esi edx ecx ebx eax 
     1528        ret 
     1529 
     1530  .fix_width_high: 
     1531        mov     ecx, esi 
     1532        mov     [edi + WDATA.box.width], esi 
     1533        jmp     .check_left 
     1534 
     1535  .fix_left_low: 
     1536        xor     eax, eax 
     1537        mov     [edi + WDATA.box.left], eax 
     1538        jmp     .check_height 
     1539 
     1540  .fix_left_high: 
     1541        mov     eax, esi 
     1542        sub     eax, ecx 
     1543        mov     [edi + WDATA.box.left], eax 
     1544        jmp     .check_height 
     1545 
     1546  .fix_height_high: 
     1547        mov     edx, esi 
     1548        mov     [edi + WDATA.box.height], esi 
     1549        jmp     .check_top 
     1550 
     1551  .fix_top_low: 
     1552        xor     ebx, ebx 
     1553        mov     [edi + WDATA.box.top], ebx 
     1554        jmp     .exit 
     1555 
     1556  .fix_top_high: 
     1557        mov     ebx, esi 
     1558        sub     ebx, edx 
     1559        mov     [edi + WDATA.box.top], ebx 
     1560        jmp     .exit 
    14451561 
    14461562align 4 
    14471563;------------------------------------------------------------------------------ 
    14481564window._.get_titlebar_height: ;//////////////////////////////////////////////// 
     1565;------------------------------------------------------------------------------ 
     1566;? <description> 
    14491567;------------------------------------------------------------------------------ 
    14501568;> edi = pointer to WDATA 
     
    14621580;------------------------------------------------------------------------------ 
    14631581window._.get_rolledup_height: ;//////////////////////////////////////////////// 
     1582;------------------------------------------------------------------------------ 
     1583;? <description> 
    14641584;------------------------------------------------------------------------------ 
    14651585;> edi = pointer to WDATA 
     
    17331853        mov     cl, [edi + WDATA.fl_wstyle] 
    17341854        and     cl, 0x0f 
    1735         cmp     cl, 0x03 
     1855        cmp     cl, 3 
    17361856        je      .exit.redraw      ; window type 3 
    1737         cmp     cl, 0x04 
     1857        cmp     cl, 4 
    17381858        je      .exit.redraw      ; window type 4 
    17391859 
     
    17431863        sub     eax, window_data 
    17441864        shr     eax, 5 
    1745  
    1746         ; esi = process number 
    17471865 
    17481866        movzx   eax, word[WIN_STACK + eax * 2]  ; get value of the curr process 
     
    17991917align 4 
    18001918;------------------------------------------------------------------------------ 
    1801 window._.draw_window_frames: ;///////////////////////////////////////////////// 
    1802 ;------------------------------------------------------------------------------ 
    1803 ;? Draw negative window frames 
    1804 ;------------------------------------------------------------------------------ 
    1805 ;> edi = pointer to WDATA 
    1806 ;------------------------------------------------------------------------------ 
    1807         push    eax 
    1808         cli 
    1809  
    1810         test    [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED 
    1811         jnz     .exit 
    1812         mov     eax, [new_window_pos.left] 
    1813         cmp     eax, [edi + WDATA.box.left] 
    1814         jnz     .draw 
    1815         mov     eax, [new_window_pos.width] 
    1816         cmp     eax, [edi + WDATA.box.width] 
    1817         jnz     .draw 
    1818         mov     eax, [new_window_pos.top] 
    1819         cmp     eax, [edi + WDATA.box.top] 
    1820         jnz     .draw 
    1821         mov     eax, [new_window_pos.height] 
    1822         cmp     eax, [edi + WDATA.box.height] 
    1823         jnz     .draw 
    1824         xor     [edi + WDATA.fl_wdrawn], 2 
    1825  
    1826   .draw: 
    1827         push    ebx esi 
    1828         mov     eax, [new_window_pos.left - 2] 
    1829         mov     ax, word[new_window_pos.left] 
    1830         add     ax, word[new_window_pos.width] 
    1831         mov     ebx, [new_window_pos.top - 2] 
    1832         mov     bx, word[new_window_pos.top] 
    1833         add     bx, word[new_window_pos.height] 
     1919window._.draw_window_caption: ;//////////////////////////////////////////////// 
     1920;------------------------------------------------------------------------------ 
     1921;? <description> 
     1922;------------------------------------------------------------------------------ 
     1923        inc     [mouse_pause] 
     1924        call    [_display.disable_mouse] 
     1925 
     1926        xor     eax, eax 
     1927        mov     edx, [TASK_COUNT] 
     1928        movzx   edx, word[WIN_POS + edx * 2] 
     1929        cmp     edx, [CURRENT_TASK] 
     1930        jne     @f 
     1931        inc     eax 
     1932    @@: mov     edx, [CURRENT_TASK] 
     1933        shl     edx, 5 
     1934        add     edx, window_data 
     1935        movzx   ebx, [edx + WDATA.fl_wstyle] 
     1936        and     bl, 0x0F 
     1937        cmp     bl, 3 
     1938        je      .draw_caption_style_3 
     1939        cmp     bl, 4 
     1940        je      .draw_caption_style_3 
     1941 
     1942        jmp     .not_style_3 
     1943 
     1944  .draw_caption_style_3: 
     1945        push    edx 
     1946        call    drawwindow_IV_caption 
     1947        add     esp, 4 
     1948        jmp     .2 
     1949 
     1950  .not_style_3: 
     1951        cmp     bl, 2 
     1952        jne     .not_style_2 
     1953 
     1954        call    drawwindow_III_caption 
     1955        jmp     .2 
     1956 
     1957  .not_style_2: 
     1958        cmp     bl, 0 
     1959        jne     .2 
     1960 
     1961        call    drawwindow_I_caption 
     1962 
     1963  .2:   mov     edi, [CURRENT_TASK] 
     1964        shl     edi, 5 
     1965        test    [edi + window_data + WDATA.fl_wstyle], WSTYLE_HASCAPTION 
     1966        jz      .exit 
     1967        mov     edx, [edi * 8 + SLOT_BASE + APPDATA.wnd_caption] 
     1968        or      edx, edx 
     1969        jz      .exit 
     1970 
     1971        movzx   eax, [edi + window_data + WDATA.fl_wstyle] 
     1972        and     al, 0x0F 
     1973        cmp     al, 3 
     1974        je      .skinned 
     1975        cmp     al, 4 
     1976        je      .skinned 
     1977 
     1978        jmp     .not_skinned 
     1979 
     1980  .skinned: 
     1981        mov     ebp, [edi + window_data + WDATA.box.left - 2] 
     1982        mov     bp, word[edi + window_data + WDATA.box.top] 
     1983        movzx   eax, word[edi + window_data + WDATA.box.width] 
     1984        sub     ax, [_skinmargins.left] 
     1985        sub     ax, [_skinmargins.right] 
     1986        push    edx 
     1987        cwde 
     1988        cdq 
     1989        mov     ebx, 6 
     1990        idiv    ebx 
     1991        pop     edx 
     1992        or      eax, eax 
     1993        js      .exit 
     1994 
     1995        mov     esi, eax 
     1996        mov     ebx, dword[_skinmargins.left - 2] 
     1997        mov     bx, word[_skinh] 
     1998        sub     bx, [_skinmargins.bottom] 
     1999        sub     bx, [_skinmargins.top] 
     2000        sar     bx, 1 
     2001        adc     bx, 0 
     2002        add     bx, [_skinmargins.top] 
     2003        add     bx, -3 
     2004        add     ebx, ebp 
     2005        jmp     .dodraw 
     2006 
     2007  .not_skinned: 
     2008        cmp     al, 1 
     2009        je      .exit 
     2010 
     2011        mov     ebp, [edi + window_data + WDATA.box.left - 2] 
     2012        mov     bp, word[edi + window_data + WDATA.box.top] 
     2013        movzx   eax, word[edi + window_data + WDATA.box.width] 
     2014        sub     eax, 16 
     2015        push    edx 
     2016        cwde 
     2017        cdq 
     2018        mov     ebx, 6 
     2019        idiv    ebx 
     2020        pop     edx 
     2021        or      eax, eax 
     2022        js      .exit 
     2023 
     2024        mov     esi, eax 
     2025        mov     ebx, 0x00080007 
     2026        add     ebx, ebp 
     2027 
     2028  .dodraw: 
     2029        mov     ecx, [common_colours + 16] 
     2030        or      ecx, 0x80000000 
     2031        xor     edi, edi 
     2032        call    dtext_asciiz_esi 
     2033 
     2034  .exit: 
     2035        dec     [mouse_pause] 
     2036        call    [draw_pointer] 
     2037        ret 
     2038 
     2039align 4 
     2040;------------------------------------------------------------------------------ 
     2041window._.draw_negative_box: ;////////////////////////////////////////////////// 
     2042;------------------------------------------------------------------------------ 
     2043;? Draw negative box 
     2044;------------------------------------------------------------------------------ 
     2045;> edi = pointer to BOX struct 
     2046;------------------------------------------------------------------------------ 
     2047        push    eax ebx esi 
     2048        mov     eax, [edi + BOX.left - 2] 
     2049        mov     ax, word[edi + BOX.left] 
     2050        add     ax, word[edi + BOX.width] 
     2051        mov     ebx, [edi + BOX.top - 2] 
     2052        mov     bx, word[edi + BOX.top] 
     2053        add     bx, word[edi + BOX.height] 
    18342054        mov     esi, 0x01000000 
    18352055        call    draw_rectangle.forced 
    1836         pop     esi ebx 
    1837  
    1838   .exit: 
    1839         sti 
    1840         pop     eax 
    1841         ret 
    1842  
    1843   .forced: 
    1844         push    eax 
    1845         cli 
    1846         jmp     .draw 
     2056        pop     esi ebx eax 
     2057        ret 
  • kernel/trunk/kernel.asm

    r1380 r1391  
    10361036osloop: 
    10371037        call   [draw_pointer] 
    1038         call   check_buttons 
    1039         call   checkwindows 
    1040 ;       call   check_window_move_request 
     1038        call    window_check_events 
     1039        call    mouse_check_events 
    10411040        call   checkmisc 
    10421041        call   checkVga_N13 
     
    26762675        jz      .exit 
    26772676        mov     eax, [BTN_BUFF] 
    2678         shl     eax, 8 
    2679 ; // Alver 22.06.2008 // { 
    2680         mov       al, byte [btn_down_determ] 
    2681         and       al,0xFE                                       ; delete left button bit 
    2682 ; } \\ Alver \\ 
     2677        and     al, 0xFE                                    ; delete left button bit 
    26832678        mov     [BTN_COUNT], byte 0 
    26842679        mov     [esp + 32], eax 
     
    29112906  srl1: 
    29122907        ret 
    2913  
    2914  
    2915 sys_drawwindow: 
    2916  
    2917     mov   eax,edx 
    2918     shr   eax,16+8 
    2919     and   eax,15 
    2920  
    2921 ;    cmp   eax,0   ; type I    - original style 
    2922     jne   nosyswI 
    2923     inc   [mouse_pause] 
    2924     call  [_display.disable_mouse] 
    2925     call  sys_set_window 
    2926     call  [_display.disable_mouse] 
    2927     call  drawwindow_I 
    2928     ;dec   [mouse_pause] 
    2929     ;call   [draw_pointer] 
    2930     ;ret 
    2931     jmp   draw_window_caption.2 
    2932   nosyswI: 
    2933  
    2934     cmp   al,1    ; type II   - only reserve area, no draw 
    2935     jne   nosyswII 
    2936     inc   [mouse_pause] 
    2937     call  [_display.disable_mouse] 
    2938     call  sys_set_window 
    2939     call  [_display.disable_mouse] 
    2940     call  sys_window_mouse 
    2941     dec   [mouse_pause] 
    2942     call   [draw_pointer] 
    2943     ret 
    2944   nosyswII: 
    2945  
    2946     cmp   al,2    ; type III  - new style 
    2947     jne   nosyswIII 
    2948     inc   [mouse_pause] 
    2949     call  [_display.disable_mouse] 
    2950     call  sys_set_window 
    2951     call  [_display.disable_mouse] 
    2952     call  drawwindow_III 
    2953     ;dec   [mouse_pause] 
    2954     ;call   [draw_pointer] 
    2955     ;ret 
    2956     jmp   draw_window_caption.2 
    2957   nosyswIII: 
    2958  
    2959     cmp   al,3    ; type IV - skinned window 
    2960     je    draw_skin_window 
    2961     cmp   al,4    ; type V - skinned window not sized! {not_sized_skin_window} 
    2962     jne   nosyswV 
    2963   draw_skin_window: 
    2964  
    2965     inc   [mouse_pause] 
    2966     call  [_display.disable_mouse] 
    2967     call  sys_set_window 
    2968     call  [_display.disable_mouse] 
    2969     mov   eax, [TASK_COUNT] 
    2970     movzx eax, word [WIN_POS + eax*2] 
    2971     cmp   eax, [CURRENT_TASK] 
    2972     setz  al 
    2973     movzx eax, al 
    2974     push  eax 
    2975     call  drawwindow_IV 
    2976     ;dec   [mouse_pause] 
    2977     ;call   [draw_pointer] 
    2978     ;ret 
    2979     jmp   draw_window_caption.2 
    2980   nosyswV: 
    2981  
    2982     ret 
    2983  
    2984  
    2985 draw_window_caption: 
    2986         inc     [mouse_pause] 
    2987         call    [_display.disable_mouse] 
    2988  
    2989         xor     eax,eax 
    2990         mov     edx,[TASK_COUNT] 
    2991         movzx   edx,word[WIN_POS+edx*2] 
    2992         cmp     edx,[CURRENT_TASK] 
    2993         jne     @f 
    2994         inc     eax 
    2995     @@: mov     edx,[CURRENT_TASK] 
    2996         shl     edx,5 
    2997         add     edx,window_data 
    2998         movzx   ebx,[edx+WDATA.fl_wstyle] 
    2999         and     bl,0x0F 
    3000         cmp     bl,3 
    3001         je      .draw_caption_style_3           ;{for 3 and 4 style write caption} 
    3002         cmp     bl,4 
    3003         je      .draw_caption_style_3 
    3004  
    3005         jmp     .not_style_3 
    3006   .draw_caption_style_3: 
    3007  
    3008         push    edx 
    3009         call    drawwindow_IV_caption 
    3010         add     esp,4 
    3011         jmp     .2 
    3012  
    3013   .not_style_3: 
    3014         cmp     bl,2 
    3015         jne     .not_style_2 
    3016  
    3017         call    drawwindow_III_caption 
    3018         jmp     .2 
    3019  
    3020   .not_style_2: 
    3021         cmp     bl,0 
    3022         jne     .2 
    3023  
    3024         call    drawwindow_I_caption 
    3025  
    3026 ;-------------------------------------------------------------- 
    3027   .2:   ;jmp     @f 
    3028         mov     edi,[CURRENT_TASK] 
    3029         shl     edi,5 
    3030         test    [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION 
    3031         jz      @f 
    3032         mov     edx,[edi*8+SLOT_BASE+APPDATA.wnd_caption] 
    3033         or      edx,edx 
    3034         jz      @f 
    3035  
    3036         movzx   eax,[edi+window_data+WDATA.fl_wstyle] 
    3037         and     al,0x0F 
    3038         cmp     al,3 
    3039         je      .skinned 
    3040         cmp     al,4 
    3041         je      .skinned 
    3042  
    3043         jmp     .not_skinned 
    3044   .skinned: 
    3045         mov     ebp,[edi+window_data+WDATA.box.left-2] 
    3046         mov     bp,word[edi+window_data+WDATA.box.top] 
    3047         movzx   eax,word[edi+window_data+WDATA.box.width] 
    3048         sub     ax,[_skinmargins.left] 
    3049         sub     ax,[_skinmargins.right] 
    3050         push    edx 
    3051         cwde 
    3052         cdq 
    3053         mov     ebx,6 
    3054         idiv    ebx 
    3055         pop     edx 
    3056         or      eax,eax 
    3057         js      @f 
    3058         mov     esi,eax 
    3059         mov     ebx,dword[_skinmargins.left-2] 
    3060         mov     bx,word[_skinh] 
    3061         sub     bx,[_skinmargins.bottom] 
    3062         sub     bx,[_skinmargins.top] 
    3063         sar     bx,1 
    3064         adc     bx,0 
    3065         add     bx,[_skinmargins.top] 
    3066         add     bx,-3 
    3067         add     ebx,ebp 
    3068         jmp     .dodraw 
    3069  
    3070   .not_skinned: 
    3071         cmp     al,1 
    3072         je      @f 
    3073  
    3074         mov     ebp,[edi+window_data+WDATA.box.left-2] 
    3075         mov     bp,word[edi+window_data+WDATA.box.top] 
    3076         movzx   eax,word[edi+window_data+WDATA.box.width] 
    3077         sub     eax,16 
    3078         push    edx 
    3079         cwde 
    3080         cdq 
    3081         mov     ebx,6 
    3082         idiv    ebx 
    3083         pop     edx 
    3084         or      eax,eax 
    3085         js      @f 
    3086         mov     esi,eax 
    3087         mov     ebx,0x00080007 
    3088         add     ebx,ebp 
    3089 .dodraw: 
    3090         mov     ecx,[common_colours+16];0x00FFFFFF 
    3091         or      ecx, 0x80000000 
    3092         xor     edi,edi 
    3093 ; // Alver 22.06.2008 // { 
    3094 ;       call    dtext 
    3095         call dtext_asciiz_esi 
    3096 ; } \\ Alver \\ 
    3097  
    3098     @@: 
    3099 ;-------------------------------------------------------------- 
    3100         dec     [mouse_pause] 
    3101         call    [draw_pointer] 
    3102         ret 
    3103  
    3104 iglobal 
    3105 align 4 
    3106 window_topleft dd \ 
    3107   1, 21,\               ;type 0 
    3108   0,  0,\       ;type 1 
    3109   5, 20,\       ;type 2 
    3110   5,  ?,\       ;type 3 {set by skin} 
    3111   5,  ?         ;type 4 {set by skin} 
    3112 endg 
    3113  
    3114 set_window_clientbox: 
    3115         push    eax ecx edi 
    3116  
    3117         mov     eax,[_skinh] 
    3118         mov     [window_topleft+4*7],eax 
    3119         mov     [window_topleft+4*9],eax 
    3120  
    3121         mov     ecx,edi 
    3122         sub     edi,window_data 
    3123         shl     edi,3 
    3124         test    [ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE 
    3125         jz      @f 
    3126  
    3127         movzx   eax,[ecx+WDATA.fl_wstyle] 
    3128         and     eax,0x0F 
    3129         mov     eax,[eax*8+window_topleft+0] 
    3130         mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax 
    3131         shl     eax,1 
    3132         neg     eax 
    3133         add     eax,[ecx+WDATA.box.width] 
    3134         mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax 
    3135  
    3136         movzx   eax,[ecx+WDATA.fl_wstyle] 
    3137         and     eax,0x0F 
    3138         push    [eax*8+window_topleft+0] 
    3139         mov     eax,[eax*8+window_topleft+4] 
    3140         mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax 
    3141         neg     eax 
    3142         sub     eax,[esp] 
    3143         add     eax,[ecx+WDATA.box.height] 
    3144         mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax 
    3145         add     esp,4 
    3146  
    3147         pop     edi ecx eax 
    3148         ret 
    3149     @@: 
    3150         xor     eax,eax 
    3151         mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax 
    3152         mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax 
    3153         mov     eax,[ecx+WDATA.box.width] 
    3154         mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax 
    3155         mov     eax,[ecx+WDATA.box.height] 
    3156         mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax 
    3157  
    3158         pop     edi ecx eax 
    3159         ret 
    3160  
    3161 sys_set_window: 
    3162  
    3163     mov   eax,[CURRENT_TASK] 
    3164     shl   eax,5 
    3165     add   eax,window_data 
    3166  
    3167     ; colors 
    3168     mov   [eax+WDATA.cl_workarea],edx 
    3169     mov   [eax+WDATA.cl_titlebar],esi 
    3170     mov   [eax+WDATA.cl_frames],edi 
    3171  
    3172     mov   edi, eax 
    3173  
    3174     ; check flag (?) 
    3175     test  [edi+WDATA.fl_wdrawn],1 
    3176     jnz   newd 
    3177  
    3178     mov   eax,[timer_ticks] ;[0xfdf0] 
    3179     add   eax,100 
    3180     mov   [new_window_starting],eax 
    3181  
    3182     movsx eax,bx 
    3183     mov   [edi+WDATA.box.width],eax 
    3184     movsx eax,cx 
    3185     mov   [edi+WDATA.box.height],eax 
    3186     sar   ebx,16 
    3187     sar   ecx,16 
    3188     mov   [edi+WDATA.box.left],ebx 
    3189     mov   [edi+WDATA.box.top],ecx 
    3190  
    3191     call  check_window_position 
    3192  
    3193     push  ecx esi edi               ; save for window fullscreen/resize 
    3194     ;mov   esi,edi 
    3195  
    3196         mov     cl, [edi+WDATA.fl_wstyle] 
    3197         mov     eax, [edi+WDATA.cl_frames] 
    3198  
    3199     sub   edi,window_data 
    3200     shl   edi,3 
    3201     add   edi,SLOT_BASE 
    3202  
    3203         and     cl,0x0F 
    3204         mov     [edi+APPDATA.wnd_caption],0 
    3205         cmp     cl,3 
    3206         je      set_APPDATA_wnd_caption 
    3207         cmp     cl,4                                                            ; {SPraid.simba} 
    3208         je      set_APPDATA_wnd_caption 
    3209  
    3210         jmp     @f 
    3211     set_APPDATA_wnd_caption: 
    3212         mov     [edi+APPDATA.wnd_caption],eax 
    3213     @@: mov     esi,[esp+0] 
    3214  
    3215     add   edi, APPDATA.saved_box 
    3216         movsd 
    3217         movsd 
    3218         movsd 
    3219         movsd 
    3220     pop   edi esi ecx 
    3221  
    3222         mov     esi, [CURRENT_TASK] 
    3223         movzx   esi, word [WIN_STACK+esi*2] 
    3224         lea     esi, [WIN_POS+esi*2] 
    3225         call    waredraw 
    3226  
    3227 ;;;    mov   ebx, 1 
    3228 ;;;    call  delay_hs 
    3229     mov   eax, [edi+WDATA.box.left] 
    3230     mov   ebx, [edi+WDATA.box.top] 
    3231     mov   ecx, [edi+WDATA.box.width] 
    3232     mov   edx, [edi+WDATA.box.height] 
    3233     add   ecx, eax 
    3234     add   edx, ebx 
    3235     call  calculatescreen 
    3236  
    3237     mov   [KEY_COUNT],byte 0           ; empty keyboard buffer 
    3238     mov   [BTN_COUNT],byte 0           ; empty button buffer 
    3239  
    3240   newd: 
    3241     call  set_window_clientbox 
    3242  
    3243     mov   [edi+WDATA.fl_redraw],byte 0   ; no redraw 
    3244     mov   edx,edi 
    3245  
    3246     ret 
    3247  
    3248 syscall_windowsettings: 
    3249  
    3250   .set_window_caption: 
    3251         dec     ebx     ; subfunction #1 - set window caption 
    3252         jnz     .exit_fail 
    3253  
    3254         ; NOTE: only window owner thread can set its caption, 
    3255         ;       so there's no parameter for PID/TID 
    3256  
    3257         mov     edi,[CURRENT_TASK] 
    3258         shl     edi,5 
    3259  
    3260         ; have to check if caption is within application memory limit 
    3261         ; check is trivial, and if application resizes its memory, 
    3262         ;   caption still can become over bounds 
    3263 ; diamond, 31.10.2006: check removed because with new memory manager 
    3264 ; there can be valid data after APPDATA.mem_size bound 
    3265 ;        mov     ecx,[edi*8+SLOT_BASE+APPDATA.mem_size] 
    3266 ;        add     ecx,255 ; max caption length 
    3267 ;        cmp     ebx,ecx 
    3268 ;        ja      .exit_fail 
    3269  
    3270         mov     [edi*8+SLOT_BASE+APPDATA.wnd_caption],ecx 
    3271         or      [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION 
    3272  
    3273         call    draw_window_caption 
    3274  
    3275         xor     eax,eax ; eax = 0 (success) 
    3276         ret 
    3277  
    3278 ;  .get_window_caption: 
    3279 ;        dec     eax     ; subfunction #2 - get window caption 
    3280 ;        jnz     .exit_fail 
    3281  
    3282         ; not implemented yet 
    3283  
    3284   .exit_fail: 
    3285         xor     eax,eax 
    3286         inc     eax     ; eax = 1 (fail) 
    3287         ret 
    3288  
    3289  
    3290 sys_window_move: 
    3291  
    3292         mov     edi,[CURRENT_TASK] 
    3293         shl     edi,5 
    3294         add     edi,window_data 
    3295  
    3296         test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED 
    3297         jnz     .window_move_return 
    3298  
    3299         push    dword [edi + WDATA.box.left]  ; save old coordinates 
    3300         push    dword [edi + WDATA.box.top] 
    3301         push    dword [edi + WDATA.box.width] 
    3302         push    dword [edi + WDATA.box.height] 
    3303  
    3304         cmp   eax,-1                  ; set new position and size 
    3305         je    .no_x_reposition 
    3306         mov     [edi + WDATA.box.left], eax 
    3307       .no_x_reposition: 
    3308         cmp   ebx,-1 
    3309         je    .no_y_reposition 
    3310         mov     [edi + WDATA.box.top], ebx 
    3311       .no_y_reposition: 
    3312  
    3313         test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP 
    3314         jnz     .no_y_resizing 
    3315  
    3316         cmp   ecx,-1 
    3317         je    .no_x_resizing 
    3318         mov     [edi + WDATA.box.width], ecx 
    3319       .no_x_resizing: 
    3320         cmp   edx,-1 
    3321         je    .no_y_resizing 
    3322         mov     [edi + WDATA.box.height], edx 
    3323       .no_y_resizing: 
    3324  
    3325         call  check_window_position 
    3326         call  set_window_clientbox 
    3327  
    3328         pushad                       ; save for window fullscreen/resize 
    3329         mov   esi,edi 
    3330         sub   edi,window_data 
    3331         shr   edi,5 
    3332         shl   edi,8 
    3333         add   edi, SLOT_BASE + APPDATA.saved_box 
    3334         mov   ecx,4 
    3335         cld 
    3336         rep   movsd 
    3337         popad 
    3338  
    3339         pushad                       ; calculcate screen at new position 
    3340         mov   eax, [edi + WDATA.box.left] 
    3341         mov   ebx, [edi + WDATA.box.top] 
    3342         mov   ecx, [edi + WDATA.box.width] 
    3343         mov   edx, [edi + WDATA.box.height] 
    3344         add   ecx,eax 
    3345         add   edx,ebx 
    3346  
    3347         call  calculatescreen 
    3348         popad 
    3349  
    3350         pop   edx                   ; calculcate screen at old position 
    3351         pop   ecx 
    3352         pop   ebx 
    3353         pop   eax 
    3354         add   ecx,eax 
    3355         add   edx,ebx 
    3356         mov   [draw_limits.left],eax             ; save for drawlimits 
    3357         mov   [draw_limits.top],ebx 
    3358         mov   [draw_limits.right],ecx 
    3359         mov   [draw_limits.bottom],edx 
    3360         call  calculatescreen 
    3361  
    3362         mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw 
    3363  
    3364         mov   eax,edi               ; redraw screen at old position 
    3365         xor   esi,esi 
    3366         call  redrawscreen 
    3367  
    3368         mov   [DONT_DRAW_MOUSE],byte 0 ; mouse pointer 
    3369         mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under 
    3370         mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down 
    3371  
    3372         call  [draw_pointer] 
    3373  
    3374         mov   [window_move_pr],0 
    3375  
    3376       .window_move_return: 
    3377  
    3378         ret 
    3379  
    3380 uglobal 
    3381   window_move_pr   dd  0x0 
    3382   window_move_eax  dd  0x0 
    3383   window_move_ebx  dd  0x0 
    3384   window_move_ecx  dd  0x0 
    3385   window_move_edx  dd  0x0 
    3386 endg 
    33872908 
    33882909;ok - 100% work 
  • kernel/trunk/kernel32.inc

    r1379 r1391  
    4141;    display 'not used dt: ',`.,13,10 
    4242;  end if } 
     43 
     44struc POINT { 
     45  .x dd ? 
     46  .y dd ? 
     47  .sizeof: 
     48} 
     49virtual at 0 
     50 POINT POINT 
     51end virtual 
    4352 
    4453struc RECT { 
     
    4756  .right  dd ? 
    4857  .bottom dd ? 
     58  .sizeof: 
    4959} 
    5060virtual at 0 
     
    5767  .width  dd ? 
    5868  .height dd ? 
     69  .sizeof: 
    5970} 
    6071virtual at 0