Subversion Repositories Kolibri OS

Rev

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

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