Subversion Repositories Kolibri OS

Rev

Rev 5565 | Details | Compare with Previous | Last modification | View Log | RSS feed

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