Subversion Repositories Kolibri OS

Rev

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

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