Subversion Repositories Kolibri OS

Rev

Rev 4779 | Rev 4797 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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