Subversion Repositories Kolibri OS

Rev

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

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