Subversion Repositories Kolibri OS

Rev

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