Subversion Repositories Kolibri OS

Rev

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

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