-
Notifications
You must be signed in to change notification settings - Fork 0
/
WMWindowManager.Mod
1178 lines (1004 loc) · 37.1 KB
/
WMWindowManager.Mod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
MODULE WMWindowManager; (** AUTHOR "TF"; PURPOSE "Generic window manager"; *)
IMPORT
Modules, KernelLog, Plugins, Locks, Strings,
Messages := WMMessages, Graphics := WMGraphics, Raster, Rectangles := WMRectangles;
CONST
FlagFrame* = 0; (** The window has a frame *)
FlagClose* = 1; (** The window offers a close button; only frame windows *)
FlagMinimize* = 2; (** The window offers a minimize button; only frame windows *)
FlagStayOnTop* = 3; (** The window will always stay above all non stay on top windows *)
FlagNonDispatched* = 4; (** The window has no message queue --> BE CAREFUL *)
FlagNoFocus* = 5; (** The window can never get the keyboard focus *)
FlagDecorWindow* = 6; (** The window is a decor window, associated to a master window *)
FlagStayOnBottom* = 7; (** The window can not be moved up *)
FlagNavigation* = 8; (** The window will always appear at the same position/size on the screen independent of the range of the viewport displaying it. *)
FlagHidden* = 9; (** This flag indicates whether a window should be managed by window navigation tools. It does not influence the visibiliy or behaviour of the window *)
FlagNoResizing* = 10; (** If set, window resizing is disabled *)
SizeMinHeight = 3; (* Minimum height of a window *)
SizeMinWidth = 3; (* Minimum width of a window *)
(* result codes for Window.OpenDocument *)
Ok* = 0;
Error* = 1;
NotSupported* = 2;
(* Window position for new windows added *)
X0 = 30;
Y0 = 80;
TYPE
Rectangle = Rectangles.Rectangle;
String = Strings.String;
Message = Messages.Message;
RealRect* = RECORD l*, t*, r*, b* : REAL END;
PointerInfo* = OBJECT
VAR hotX*, hotY* : LONGINT; img* : Graphics.Image;
END PointerInfo;
(** All fields are read-only except for the module SkinEngine.Mod!
Modifications of the instance that is owned by the window manager require
the window manager write lock being held!
Most of the information is used by WMDefaultWindows.Mod *)
WindowStyle* = OBJECT
VAR
(** use bitmaps for frame windows? *)
useBitmaps* : BOOLEAN;
(** frame color if not using bitmaps (a = active, i = inactive) *)
baCol*, biCol* : LONGINT;
(** frame shading width if not using bitmaps (a = active, i = inactive) *)
basw*, bisw* : LONGINT;
(** height / width of frame windows th = top height, bh = bottom height, lw = left width, rw = right width *)
th*, bh*, lw*, rw* : LONGINT;
(** frame window bitmaps
1st letter: t = top, l = left, r = right, b = bottom decor window
2nd letter: a = active, i = inactive
3rd letter: a = left bitmap, b = middle bitmap (repeated), c = right bitmap
*)
taa*, tab*, tac*, tia*, tib*, tic*,
laa*, lab*, lac*, lia*, lib*, lic*,
raa*, rab*, rac*, ria*, rib*, ric*,
baa*, bab*, bac*, bia*, bib*, bic* : Graphics.Image;
(** Close and minimize button images (a = active, i = inactive) *)
ca*, ci*, closeHover*,
ma*, mi*, minimizeHover* : Graphics.Image;
minimizeOffset* : LONGINT; (** offset correction for minimize button *)
(** Window title position and color (a = active, i = inactive) *)
atextX*, atextY*, atextColor*, itextX*, itextY*, itextColor* : LONGINT;
bgColor*, fgColor*, selectCol*, desktopColor* : Graphics.Color;
topFocusThreshold*, topThreshold*, bottomFocusThreshold*, bottomThreshold*,
leftFocusThreshold*, leftThreshold*, rightFocusThreshold*, rightThreshold* : LONGINT;
(* Initialize/reset to zero-style for windows *)
PROCEDURE &Init*;
BEGIN
useBitmaps := FALSE;
baCol := 0FFFFH; biCol := 0FF40H;
basw := 4; bisw := 3;
th := 20; bh := 3; lw := 3; rw := 3;
(* images *)
taa := NIL; tab := NIL; tac := NIL; tia := NIL; tib := NIL; tic := NIL;
laa := NIL; lab := NIL; lac := NIL; lia := NIL; lib := NIL; lic := NIL;
raa := NIL; rab := NIL; rac := NIL; ria := NIL; rib := NIL; ric := NIL;
baa := NIL; bab := NIL; bac := NIL; bia := NIL; bib := NIL; bic := NIL;
ca := Graphics.LoadImage("ZeroSkin.zip://aclose.png", TRUE);
ci := Graphics.LoadImage("ZeroSkin.zip://iclose.png", TRUE);
closeHover := NIL;
ma := NIL; mi := NIL; minimizeHover := NIL;
minimizeOffset := 0;
(* window caption *)
atextX := 5; atextY := 15; atextColor := SHORT(0FFFF00FFH);
itextX := 5; itextY := 15; itextColor := 04444FFH;
(* desktop *)
bgColor := SHORT(08080FFFFH);
fgColor := 0000000FFH;
selectCol := 0FFFFH;
desktopColor := SHORT(08080FFFFH);
topFocusThreshold := 0; topThreshold := 0;
bottomFocusThreshold := 0; bottomThreshold := 0;
leftFocusThreshold := 0; leftThreshold := 0;
rightFocusThreshold := 0; rightThreshold := 0;
END Init;
(** calculate distances from images *)
PROCEDURE Initialize*;
BEGIN
IF useBitmaps THEN
IF tab # NIL THEN th := tab.height END;
IF bab # NIL THEN bh := bab.height END;
IF lab # NIL THEN lw := lab.width END;
IF rab # NIL THEN rw := rab.width END;
END
END Initialize;
END WindowStyle;
DragInfo* = OBJECT
VAR
data*, sender* : ANY;
onAccept*, onReject* : Messages.CompCommand;
END DragInfo;
(** List of decoration - windows to a master window *)
DecorList* = OBJECT
VAR next* : DecorList;
w* : Window;
END DecorList;
(** A message preview procedure can set discard to TRUE to discard the message *)
MessagePreviewProc* = PROCEDURE (VAR msg : Message; VAR discard : BOOLEAN);
MessagePreviewList* = OBJECT
VAR proc*: MessagePreviewProc;
next*:MessagePreviewList;
END MessagePreviewList;
DocumentInfo* = RECORD
id* : LONGINT;
name* : ARRAY 32 OF CHAR; (* if name = "", this document info is not valid *)
fullname* : ARRAY 256 OF CHAR;
modified*, hasFocus* : BOOLEAN;
END;
VisualComponentInfo* = RECORD
width*, height* : LONGINT; (* preferred width and height of visual component *)
generator* : PROCEDURE {DELEGATE} () : ANY; (* NIL if no visual component available *)
END;
(** A window may provide information about currently opened documents. Additionally, it can provide a visual component that controls it. *)
WindowInfo* = RECORD
openDocuments* : ARRAY 16 OF DocumentInfo;
handleDocumentInfo* : PROCEDURE {DELEGATE} (CONST info : DocumentInfo; new : BOOLEAN; VAR res : LONGINT);
vc* : VisualComponentInfo;
END;
WindowInfoPtr = POINTER TO WindowInfo;
Window* = OBJECT
VAR
id- : LONGINT;
timestamp- : LONGINT; (* incremented at each call of procedure Draw *)
(** Ranges in global coordinates *)
bounds* : Rectangle; (** current range *)
initialBounds* : Rectangle; (** range at window creation *)
normalBounds* : Rectangle; (** range before toggling to fullscreen *)
manager* : WindowManager;
sequencer* : Messages.MsgSequencer;
(** window state that may only be accessed by the window manager *)
prev*, next* : Window; (** previous and next window in z order *)
title : String; (* window title *)
info* : WindowInfoPtr;
master* : Window; (** is only set if the window is a decor window *)
view* : ViewPort;
decor* : DecorList;
flags* : SET;
icon* : Graphics.Image; (** Optional icon for Window *)
topW*, bottomW*, leftW*, rightW* : Window; (** Optional decor windows *)
useAlpha* : BOOLEAN;
isVisible* : BOOLEAN;
pointerInfo* : PointerInfo;
acceptDrag : BOOLEAN;
reduceQuality- : BOOLEAN;
PROCEDURE &Init*(w, h : LONGINT; alpha : BOOLEAN);
BEGIN
id := GetId();
timestamp := 0;
bounds := Graphics.MakeRectangle(0, 0, w, h);
initialBounds := bounds;
normalBounds := bounds;
manager := NIL; sequencer := NIL;
prev := NIL; next := NIL;
title := NIL;
info := NIL;
master := NIL; decor := NIL;
view := NIL;
flags := {};
icon := NIL;
topW := NIL; bottomW := NIL; leftW := NIL; rightW := NIL;
useAlpha := alpha;
isVisible := TRUE;
pointerInfo := NIL;
acceptDrag := FALSE;
reduceQuality := FALSE;
END Init;
PROCEDURE IsCallFromSequencer*() : BOOLEAN;
BEGIN
RETURN (sequencer # NIL) & (sequencer.IsCallFromSequencer())
END IsCallFromSequencer;
(** Return the window manager that handles the window *)
PROCEDURE GetManager*() : WindowManager;
BEGIN
RETURN manager
END GetManager;
(** Set the window title as UTF8 string. *)
PROCEDURE SetTitle*(title : String);
BEGIN
IF manager # NIL THEN manager.SetWindowTitle(SELF, title) ELSE SELF.title := title END
END SetTitle;
(** Return the title as UTF8 string. Returns NIL if no title is set *)
PROCEDURE GetTitle*() : String;
BEGIN
IF manager # NIL THEN RETURN manager.GetWindowTitle(SELF) ELSE RETURN title END
END GetTitle;
PROCEDURE SetIcon*(icon : Graphics.Image);
BEGIN
IF (manager # NIL) THEN manager.SetWindowIcon(SELF, icon); ELSE SELF.icon := icon; END;
END SetIcon;
(** Return the height in client space *) (* go via manager *)
PROCEDURE GetHeight*() : LONGINT;
BEGIN
RETURN bounds.b - bounds.t
END GetHeight;
(** Return the width in client space *) (* go via manager *)
PROCEDURE GetWidth*() : LONGINT;
BEGIN
RETURN bounds.r - bounds.l
END GetWidth;
PROCEDURE SetInfo*(CONST info : WindowInfo);
BEGIN
IF (manager # NIL) THEN
manager.SetWindowInfo(SELF, info);
ELSE
IF (SELF.info = NIL) THEN NEW(SELF.info); END;
SELF.info^ := info;
END;
END SetInfo;
PROCEDURE GetInfo*(VAR info : WindowInfo) : BOOLEAN;
VAR infoPtr : WindowInfoPtr;
BEGIN
IF (manager # NIL) THEN
RETURN manager.GetWindowInfo(SELF, info);
ELSE
infoPtr := SELF.info;
IF (infoPtr # NIL) THEN
info := infoPtr^;
END;
RETURN (infoPtr # NIL);
END;
END GetInfo;
(** Resize is called by the WM if it wants to resize the window.
width and height contain the desired new size. The Window should set width and height to acceptable
values or return the current size, if resize is not supported *)
PROCEDURE Resizing*(VAR width, height : LONGINT);
BEGIN
IF FlagNoResizing IN flags THEN
width := GetWidth(); height := GetHeight();
ELSIF width < SizeMinWidth THEN
width := GetWidth();
ELSIF height < SizeMinHeight THEN
height := GetHeight();
END
END Resizing;
(** May replace the back-image, if needed. MUST check if requested size is reasonable (0 < x * y < memory) *)
PROCEDURE Resized*(width, height : LONGINT);
END Resized;
(** Invalidate a rectangle in window coordinates*)
PROCEDURE Invalidate*(rect : Rectangle);
BEGIN
Rectangles.MoveRel(rect, bounds.l, bounds.t);
Rectangles.ClipRect(rect, bounds);
IF manager # NIL THEN manager.AddVisibleDirty(SELF, rect) END
END Invalidate;
(** Message procedures *)
(** Pointer Messages *)
(** PointerDown is called via the generic message handler if the pointer (or a mouse button) is pressed down and
a) the pointer is in the bounding box of the window AND IsHit returns TRUE for this position
or
b) another mouse button was pressed down on a position where a) was met and has not yet been released.
x and y are in window coordinates but may lie out of the window boundaries in case b)
keys is the set of buttons that are down
*)
PROCEDURE PointerDown*(x, y : LONGINT; keys : SET);
END PointerDown;
(** PointerMove is called via the generic message handler if the pointer (mouse) is moved and
a) the pointer is in the bounding box of the window AND IsHit returns TRUE for this position
or
b) the pointer was pressed down on a position where a) was met and has not yet been released.
x and y are in window coordinates but may lie out of the window boundaries.
keys is the set of buttons that are down
*)
PROCEDURE PointerMove*(x, y : LONGINT; keys : SET);
END PointerMove;
PROCEDURE WheelMove*(dz : LONGINT);
END WheelMove;
(** PointerUp is called via the generic message handler if the pointer (or a mouse button) went up.
x and y are in window coordinates but may lie out of the window boundaries.
keys is the set of buttons that are STILL DOWN
*)
PROCEDURE PointerUp*(x, y : LONGINT; keys : SET);
END PointerUp;
(** PointerLeave is called via the generic message handler if the pointer has left the window with no button pressed. *)
PROCEDURE PointerLeave*;
END PointerLeave;
(** DragOver is called via the message handler. *)
PROCEDURE DragOver*(x, y: LONGINT; dragInfo : DragInfo);
END DragOver;
(** Dropped is called via the message handler to indicate an item has been dropped. *)
PROCEDURE DragDropped*(x, y: LONGINT; dragInfo : DragInfo);
END DragDropped;
(** send the srcWindow a confirmation for the completed drag operation *)
PROCEDURE ConfirmDrag*(accept : BOOLEAN; dragInfo : DragInfo);
BEGIN
IF dragInfo # NIL THEN
IF accept THEN
IF dragInfo.onAccept # NIL THEN dragInfo.onAccept(SELF, dragInfo) END
ELSE
IF dragInfo.onReject # NIL THEN dragInfo.onReject(SELF, dragInfo) END
END
END
END ConfirmDrag;
(** Start a drag operation. *)
PROCEDURE StartDrag*(sender, data : ANY; img : Graphics.Image; onAccept, onReject : Messages.CompCommand) : BOOLEAN;
BEGIN
RETURN manager.StartDrag(SELF, sender, data, img, onAccept, onReject)
END StartDrag;
(** Keyboard message *)
(** KeyEvent is called via the generic message handler to signal a keyboard event.
The window can determine wheter the key was pressed or released by examining the
Inputs.Release flag in flags. ucs contains the unicode equivalent of the key. Special input editors
send the generated unicode characters via KeyEvent. *)
PROCEDURE KeyEvent*(ucs : LONGINT; flags : SET; keysym : LONGINT);
END KeyEvent;
(** Focus messages *)
(** FocusGot is called via the generic message handler if the keyboard focus is transfered to this window *)
PROCEDURE FocusGot*;
END FocusGot;
(** FocusList is called via the generic message handler if the keyboard focus is transfered to some other window *)
PROCEDURE FocusLost*;
END FocusLost;
(** Style *)
(** StyleChanged is called via the generic message handler if a change in the global style occurs. The
Window should read all the style information it relies on and redraw itself *)
PROCEDURE StyleChanged*;
END StyleChanged;
(** Closing *)
PROCEDURE CanClose*() : BOOLEAN;
BEGIN
RETURN TRUE
END CanClose;
(** Close is called via the generic message handler. *)
PROCEDURE Close*;
BEGIN
IF manager # NIL THEN manager.Remove(SELF) END;
END Close;
(** Return true if the window is hit at the coordinates x and y (in window coordinates). Use
this to generate non-rectangular windows.
This Method will be called directly by the window manager. __> Don't block, don't crash !!
*)
PROCEDURE IsHit*(x, y : LONGINT) : BOOLEAN;
BEGIN
RETURN TRUE
END IsHit;
PROCEDURE SetPointerInfo*(pi : PointerInfo);
BEGIN
IF pi # pointerInfo THEN
pointerInfo := pi;
IF manager # NIL THEN manager.CheckPointerImage END
END
END SetPointerInfo;
(** Generic message handler distributes messages to the different msg-handler methods *)
PROCEDURE Handle*(VAR m : Message);
BEGIN
IF m.msgType = Messages.MsgKey THEN
KeyEvent(m.x, m.flags, m.y)
ELSIF m.msgType = Messages.MsgPointer THEN
IF m.msgSubType = Messages.MsgSubPointerMove THEN
IF (m.dz # 0) THEN WheelMove(m.dz) END;
PointerMove(m.x, m.y, m.flags)
ELSIF m.msgSubType = Messages.MsgSubPointerDown THEN PointerDown(m.x, m.y, m.flags)
ELSIF m.msgSubType = Messages.MsgSubPointerUp THEN PointerUp(m.x, m.y, m.flags)
ELSIF m.msgSubType = Messages.MsgSubPointerLeave THEN PointerLeave
END
ELSIF m.msgType = Messages.MsgDrag THEN
IF m.msgSubType = Messages.MsgDragOver THEN
IF (m.ext # NIL) THEN
DragOver(m.x, m.y, m.ext(DragInfo))
END
ELSIF m.msgSubType = Messages.MsgDragDropped THEN
IF (m.ext # NIL) THEN
DragDropped(m.x, m.y, m.ext(DragInfo))
END
END
ELSIF m.msgType = Messages.MsgClose THEN Close
ELSIF m.msgType = Messages.MsgFocus THEN
IF m.msgSubType = Messages.MsgSubFocusGot THEN FocusGot
ELSIF m.msgSubType = Messages.MsgSubFocusLost THEN FocusLost
END
ELSIF m.msgType = Messages.MsgStyleChanged THEN StyleChanged
ELSIF m.msgType = Messages.MsgResized THEN Resized(m.x, m.y)
END;
END Handle;
(** Draw request form the window manager. The canvas becomes invalid when the method ends. The
draw method may not modify window or WindowManager properties.
w, h is the area in view coordinates, q is the Quality 0 lowest 1 mid 2 high. A window may ignore q *)
PROCEDURE Draw*(canvas : Graphics.Canvas; w, h, q : LONGINT);
END Draw;
(** Is called by the windowmanager with reduce set, if the window is resized or moved on slow machines *)
PROCEDURE HintReduceQuality*(reduce : BOOLEAN);
BEGIN
IF reduce # reduceQuality THEN
reduceQuality := reduce;
IF ~reduceQuality THEN
IF manager # NIL THEN manager.AddVisibleDirty(SELF, bounds) END
END
END
END HintReduceQuality;
END Window;
(** assumes the window is size agnostic, handles all the zooming issues directly *)
BufferWindow* = OBJECT(Window)
VAR
img* : Graphics.Image;
canvas* : Graphics.BufferCanvas;
pointerThreshold* : LONGINT;
PROCEDURE &Init*(w, h : LONGINT; alpha : BOOLEAN);
BEGIN
Init^(w, h, alpha);
NEW(img);
IF alpha THEN Raster.Create(img, w, h, Raster.BGRA8888) ELSE Raster.Create(img, w, h, format) END;
NEW(canvas, img);
END Init;
PROCEDURE IsHit(x, y : LONGINT) : BOOLEAN;
VAR w, h : LONGINT; fx, fy : REAL;
BEGIN
w := GetWidth(); h := GetHeight();
IF (w > 0) & (h > 0) & ((w # img.width) OR (h # img.height)) THEN
fx := img.width / w; fy := img.height / h;
RETURN Graphics.IsBitmapHit(ENTIER(x * fx), ENTIER(y * fy), pointerThreshold, img)
ELSE RETURN Graphics.IsBitmapHit(x, y, pointerThreshold, img)
END
END IsHit;
PROCEDURE Draw*(canvas : Graphics.Canvas; w, h, q : LONGINT);
BEGIN
IF reduceQuality THEN q := 0 END;
IF img # NIL THEN
IF (w = img.width) & (h = img.height) THEN
IF useAlpha THEN canvas.DrawImage(0, 0, img, Graphics.ModeSrcOverDst)
ELSE canvas.DrawImage(0, 0, img, Graphics.ModeCopy)
END
ELSE
IF useAlpha THEN
canvas.ScaleImage(img, Rectangles.MakeRect(0, 0, img.width, img.height),
Rectangles.MakeRect(0, 0, w, h), Graphics.ModeSrcOverDst, q)
ELSE
canvas.ScaleImage(img, Rectangles.MakeRect(0, 0, img.width, img.height),
Rectangles.MakeRect(0, 0, w, h), Graphics.ModeCopy, q)
END
END
END;
INC(timestamp);
END Draw;
PROCEDURE Invalidate*(rect : Rectangle);
VAR w, h : LONGINT; fx, fy : REAL;
BEGIN
w := GetWidth(); h := GetHeight();
IF (w > 0) & (h > 0) & ((w # img.width) OR (h # img.height)) THEN
fx := w / img.width; fy := h / img.height;
rect.l := ENTIER(rect.l * fx); rect.t := ENTIER(rect.t * fy);
rect.r := ENTIER(rect.r * fx + 0.5); rect.b := ENTIER(rect.b * fy + 0.5)
END;
Invalidate^(rect)
END Invalidate;
PROCEDURE Handle*(VAR m : Message);
VAR w, h : LONGINT; fx, fy : REAL;
BEGIN
w := GetWidth(); h := GetHeight();
IF (w > 0) & (h > 0) & ((w # img.width) OR (h # img.height)) & (m.msgType = Messages.MsgPointer) THEN
fx := img.width / w; fy := img.height / h; m.x := ENTIER(m.x * fx); m.y := ENTIER(m.y * fy)
END;
Handle^(m)
END Handle;
END BufferWindow;
DoubleBufferWindow* = OBJECT(BufferWindow)
VAR
visibleCanvas : Graphics.BufferCanvas;
backImg* : Graphics.Image;
swapping, drawing : BOOLEAN;
PROCEDURE &Init*(w, h: LONGINT; alpha : BOOLEAN);
BEGIN
Init^(w, h, alpha);
NEW(backImg); Raster.Create(backImg, w, h, img.fmt);
visibleCanvas := canvas; NEW(canvas, backImg);
END Init;
PROCEDURE ReInit*(w, h : LONGINT);
BEGIN {EXCLUSIVE}
AWAIT(~drawing);
IF useAlpha THEN
Raster.Create(img, w, h, Raster.BGRA8888);
Raster.Create(backImg, w, h, Raster.BGRA8888)
ELSE
Raster.Create(img, w, h, format);
Raster.Create(backImg, w, h, format)
END;
NEW(visibleCanvas, img); NEW(canvas, backImg)
END ReInit;
PROCEDURE Draw*(canvas : Graphics.Canvas; w, h, q : LONGINT);
BEGIN
BEGIN{EXCLUSIVE}
AWAIT(~swapping); drawing := TRUE;
END;
IF reduceQuality THEN q := 0 END;
IF img # NIL THEN
IF (w = img.width) & (h = img.height) THEN
IF useAlpha THEN canvas.DrawImage(0, 0, img, Graphics.ModeSrcOverDst)
ELSE canvas.DrawImage(0, 0, img, Graphics.ModeCopy)
END
ELSE
IF useAlpha THEN
canvas.ScaleImage(img, Rectangles.MakeRect(0, 0, img.width, img.height),
Rectangles.MakeRect(0, 0, w, h), Graphics.ModeSrcOverDst, q)
ELSE
canvas.ScaleImage(img, Rectangles.MakeRect(0, 0, img.width, img.height),
Rectangles.MakeRect(0, 0, w, h), Graphics.ModeCopy, q)
END
END
END;
BEGIN{EXCLUSIVE}
drawing := FALSE;
END;
INC(timestamp);
END Draw;
PROCEDURE CopyRect*(rect : Rectangle);
BEGIN {EXCLUSIVE}
swapping := TRUE;
AWAIT(~drawing);
visibleCanvas.SetClipRect(rect);
visibleCanvas.DrawImage(0, 0, backImg, Graphics.ModeCopy);
visibleCanvas.SetClipRect(visibleCanvas.limits);
swapping := FALSE
END CopyRect;
PROCEDURE Swap*;
VAR tmp : Graphics.Image; tmpc : Graphics.BufferCanvas;
BEGIN {EXCLUSIVE}
swapping := TRUE;
AWAIT(~drawing);
tmp := img; img := backImg; backImg := tmp;
tmpc := canvas; canvas := visibleCanvas; visibleCanvas := tmpc;
swapping := FALSE
END Swap;
END DoubleBufferWindow;
(** A ViewPort observes the global coordinate space. The WindowManager calls the view on all changes that occur
in the observed range. *)
ViewPort* = OBJECT (Plugins.Plugin)
VAR
next* : ViewPort;
manager* : WindowManager;
range* : RealRect;
(* Width and height of viewport at 1:1 zoom. Will be set once in the constructor of the ViewPort implementation *)
width0*, height0* : LONGINT; (* read-only! *)
(** The WindowManager calls the Update Procedure in locked state. *)
PROCEDURE Update*(r : Rectangle; top : Window);
END Update;
(** The WindowManager calls the Update Procedure in locked state. *)
PROCEDURE Refresh*(top : Window);
END Refresh;
(** Set the observed range *)
PROCEDURE SetRange*(x, y, w, h : REAL; showTransition : BOOLEAN);
END SetRange;
(** Return the modifier keys that are pressed in the view *)
PROCEDURE GetKeyState*(VAR state : SET);
END GetKeyState;
END ViewPort;
Decorator* = PROCEDURE {DELEGATE} (w : Window);
WindowManager* = OBJECT(Plugins.Plugin)
VAR
pointerNull*, pointerStandard*, pointerMove*, pointerText*, pointerCrosshair*,
pointerLeftRight*, pointerUpDown*, pointerULDR*, pointerURDL*, pointerLink* : PointerInfo;
decorate* : Decorator;
viewRegistry- : Plugins.Registry;
sequencer- : Messages.MsgSequencer; (** PROTECTED *)
lock- : Locks.RWLock; (** PROTECTED *)
messagePreviewList : MessagePreviewList;
style : WindowStyle;
PROCEDURE &Init*;
BEGIN
NEW(pointerNull);
InitCursors;
decorate := NIL;
NEW(viewRegistry, "View#", "Views Port Window Manager");
NEW(sequencer, Handle); lock := sequencer.lock;
messagePreviewList := NIL;
NEW(style);
END Init;
PROCEDURE InitCursors;
BEGIN
LoadCursor("ZeroSkin.zip://arrow.png", 0, 0, pointerStandard);
LoadCursor("ZeroSkin.zip://move.png", 15, 15, pointerMove);
LoadCursor("ZeroSkin.zip://text.png", 13, 12, pointerText);
LoadCursor("ZeroSkin.zip://crosshair.png", 13, 12, pointerCrosshair);
LoadCursor("ZeroSkin.zip://leftright.png", 13, 12, pointerLeftRight);
LoadCursor("ZeroSkin.zip://updown.png", 13, 12, pointerUpDown);
LoadCursor("ZeroSkin.zip://uldr.png", 13, 12, pointerULDR);
LoadCursor("ZeroSkin.zip://urdl.png", 13, 12, pointerURDL);
LoadCursor("ZeroSkin.zip://hand.png", 6, 0, pointerLink);
END InitCursors;
PROCEDURE ZeroSkin*;
BEGIN
lock.AcquireWrite;
style.Init;
SetStyle(style);
InitCursors;
lock.ReleaseWrite
END ZeroSkin;
PROCEDURE ShutDown*;
BEGIN
ASSERT(lock.HasWriteLock());
Plugins.main.Remove(viewRegistry)
END ShutDown;
(** Window management *)
(** Add adds a window at pos l, t with flags *)
PROCEDURE Add*(l, t : LONGINT; item : Window; flags:SET);
END Add;
(** Remove removes a window *)
PROCEDURE Remove*(item : Window);
END Remove;
(** Set the position of a window *)
PROCEDURE SetWindowPos*(vs : Window; x, y : LONGINT);
END SetWindowPos;
(** Set the size of a window. Return the new size in width and height *)
(** If the window contains left, top, right or bottom, SetWindowSize is called
appropriately *)
PROCEDURE SetWindowSize*(vs : Window; VAR width, height : LONGINT);
END SetWindowSize;
(** Add a region to be refreshed *)
PROCEDURE AddDirty*(VAR rect:Rectangle);
END AddDirty;
(** Add a dirty region. The region is in window coordinates and will be clipped against non transparent
windows above *)
PROCEDURE AddVisibleDirty*(w : Window; rect : Rectangle);
END AddVisibleDirty;
(** Set the keyboard focus to the window w *)
PROCEDURE SetFocus*(w : Window);
END SetFocus;
(** Add a decoration window w to window to. The window w must separately be added to the wm *)
(** A window MUST NOT be added more than once *)
(** MUST hold lock *)
PROCEDURE AddDecorWindow*(to, decor : Window);
VAR dl : DecorList;
BEGIN
lock.AcquireWrite;
INCL(decor.flags, FlagDecorWindow);
INCL(decor.flags, FlagHidden);
decor.master := to;
NEW(dl); dl.w := decor; dl.next := to.decor; to.decor := dl;
lock.ReleaseWrite
END AddDecorWindow;
(** Remove a decoration window w from window from. The window w must separately be removed from the wm *)
(** MUST hold lock *)
PROCEDURE RemoveDecorWindow*(w, from : Window);
VAR dl : DecorList;
BEGIN
lock.AcquireWrite;
IF (from.decor # NIL) & (from.decor.w = w) THEN from.decor := from.decor.next
ELSE
dl := from.decor;
WHILE (dl.next # NIL) & (dl.next.w # w) DO dl := dl.next END;
IF dl.next # NIL THEN dl.next := dl.next.next END
END;
lock.ReleaseWrite
END RemoveDecorWindow;
PROCEDURE SetStyle*(x : WindowStyle);
VAR m : Message;
BEGIN
ASSERT(style # NIL);
style := x; m.msgType := Messages.MsgStyleChanged; m.ext := style;
Broadcast(m)
END SetStyle;
PROCEDURE GetStyle*() : WindowStyle;
BEGIN
ASSERT(style # NIL);
RETURN style
END GetStyle;
(** Move Window w to front. If FlagStayOnTop is not set in w.flags, w will stay behind all windows with this flag set *)
PROCEDURE ToFront*(w : Window);
END ToFront;
(** Move Window w to the background. If FlagStayOnTop is not set in w.flags, w will stay behind all windows *)
PROCEDURE ToBack*(w : Window);
END ToBack;
PROCEDURE SetIsVisible*(w : Window; isVisible : BOOLEAN);
VAR d : DecorList;
BEGIN
ASSERT(w # NIL);
lock.AcquireWrite;
IF (w.isVisible # isVisible) THEN
w.isVisible := isVisible;
IF (w.leftW # NIL) THEN w.leftW.isVisible := isVisible; END;
IF (w.rightW # NIL) THEN w.rightW.isVisible := isVisible; END;
IF (w.topW # NIL) THEN w.topW.isVisible := isVisible; END;
IF (w.bottomW # NIL) THEN w.bottomW.isVisible := isVisible; END;
AddDirty(w.bounds);
IF (w.decor # NIL) THEN
d := w.decor;
WHILE (d # NIL) & (d.w # NIL) DO
AddDirty(d.w.bounds);
d := d.next;
END;
END;
IncOTimestamp;
END;
lock.ReleaseWrite;
END SetIsVisible;
(** Set icon for a given window. Icon may be set to NIL. *)
PROCEDURE SetWindowIcon*(w : Window; icon : Graphics.Image);
VAR tw : Window;
BEGIN
ASSERT(w # NIL);
lock.AcquireWrite;
w.icon := icon;
tw := w.topW;
IF tw # NIL THEN AddVisibleDirty(tw, tw.bounds) END;
lock.ReleaseWrite;
IncOTimestamp;
END SetWindowIcon;
(** Return the window at postition x, y in global space. *)
(** Windows that have the FlagNavigate flag set will not be considered *)
(** Must hold WM lock *)
PROCEDURE GetPositionOwner*(x, y : LONGINT) : Window;
END GetPositionOwner;
PROCEDURE GetFocusOwner*() : Window;
END GetFocusOwner;
(** Set the title of a window as UTF-8 string *)
PROCEDURE SetWindowTitle*(w : Window; title : String);
VAR tw : Window;
BEGIN
lock.AcquireWrite;
w.title := title;
tw := w.topW;
IF tw # NIL THEN AddVisibleDirty(tw, tw.bounds) END;
lock.ReleaseWrite;
IncWTimestamp; (* since navigation elements care about window title *)
END SetWindowTitle;
(** Get the title of a window as UTF-8 string *)
PROCEDURE GetWindowTitle*(w : Window) : String;
BEGIN
RETURN w.title
END GetWindowTitle;
PROCEDURE SetWindowInfo*(w : Window; CONST info : WindowInfo);
BEGIN
ASSERT(w # NIL);
lock.AcquireWrite;
IF (w.info = NIL) THEN NEW(w.info); END;
w.info^ := info;
lock.ReleaseWrite;
IncOTimestamp;
END SetWindowInfo;
PROCEDURE GetWindowInfo*(w : Window; VAR info : WindowInfo) : BOOLEAN;
VAR infoPtr : WindowInfoPtr;
BEGIN
ASSERT(w # NIL);
lock.AcquireRead;
infoPtr := w.info;
IF (infoPtr # NIL) THEN
info := infoPtr^;
END;
lock.ReleaseRead;
RETURN (infoPtr # NIL);
END GetWindowInfo;
(** Set or unset a window flag
Note: Setting FlagStayOnTop unsets FlagStayOnBottom and vice versa *)
PROCEDURE SetWindowFlag*(w : Window; flag : LONGINT; value : BOOLEAN);
BEGIN
ASSERT(w # NIL);
ASSERT((flag = FlagFrame) OR (flag = FlagStayOnTop) OR (flag = FlagStayOnBottom) OR (flag = FlagHidden));
END SetWindowFlag;
(** Set if the window is willing to accept a dropped item *)
PROCEDURE SetAcceptDrag*(w : Window; accept : BOOLEAN);
BEGIN
lock.AcquireWrite;
w.acceptDrag := accept;
lock.ReleaseWrite
END SetAcceptDrag;
PROCEDURE StartDrag*(w : Window; sender, data : ANY; img : Graphics.Image; onAccept, onReject : Messages.CompCommand) : BOOLEAN;
END StartDrag;
(** a pointer button must be pressed *)
PROCEDURE TransferPointer*( to : Window) : BOOLEAN;
END TransferPointer;
(** Adjust pointer to new position / check picture *)
PROCEDURE CheckPointerImage*;
END CheckPointerImage;
(** View management *)
(** Add a view *)
PROCEDURE AddView*(v : ViewPort);
END AddView;
(** Add the whole View.range as dirty and cause a redraw *)
PROCEDURE RefreshView*(v : ViewPort);
END RefreshView;
(** RemoveView from windowmanager *)
PROCEDURE RemoveView*(v : ViewPort);
END RemoveView;
(** Messages *)
PROCEDURE Broadcast*(VAR m : Message);
END Broadcast;
PROCEDURE SendMessage*(dest : Window; VAR m : Message) : BOOLEAN;
BEGIN
IF dest.sequencer # NIL THEN RETURN dest.sequencer.Add(m)
ELSE dest.Handle(m); RETURN TRUE
END
END SendMessage;
(** Install a message preview procedure. The window manager calls the MessagePreviewProc for
all external messages so that they can be recorded, changed or discarded *)
PROCEDURE InstallMessagePreview*(x : MessagePreviewProc);
VAR mpl : MessagePreviewList;
BEGIN
lock.AcquireWrite;
NEW(mpl); mpl.next := messagePreviewList; mpl.proc := x; messagePreviewList := mpl;
lock.ReleaseWrite
END InstallMessagePreview;
(** Remove a MessagePreviewProc *)
PROCEDURE RemoveMessagePreview*(x : MessagePreviewProc);
VAR cur : MessagePreviewList;
BEGIN
lock.AcquireWrite;
IF (messagePreviewList # NIL) & (messagePreviewList.proc = x) THEN messagePreviewList := messagePreviewList.next
ELSE
cur := messagePreviewList;
WHILE cur # NIL DO
IF (cur.next # NIL) & (cur.next.proc = x) THEN cur.next := cur.next.next; lock.ReleaseWrite; RETURN
ELSE cur := cur.next END
END
END;
lock.ReleaseWrite
END RemoveMessagePreview;
(** Preview message to all installed message preview handlers. Only to be used by WindowManager itself *)
PROCEDURE PreviewMessage*(VAR m : Message; VAR discard : BOOLEAN); (* protected *)
VAR mpl : MessagePreviewList;
BEGIN
ASSERT(lock.HasReadLock());
discard := FALSE;
mpl := messagePreviewList;
WHILE (mpl # NIL) & ~discard DO mpl.proc(m, discard); mpl := mpl.next END;
END PreviewMessage;
(** Enumeration *)
(** Get the first "user" window --> May return NIL if only background and pointer window are installed *)
(** Must hold lock *)
PROCEDURE GetFirst*() : Window;
END GetFirst;
(** Get the window next "user" window on top of x *)
PROCEDURE GetNext*(x : Window) : Window;
END GetNext;
(** Get the "user" window below x *)
PROCEDURE GetPrev*(x : Window) : Window;
END GetPrev;
(** Replace the background window with w. Return the current background window *)
PROCEDURE ReplaceBackground*(w : Window) : Window;
END ReplaceBackground;
(** Return the area that is actually occupied *)
PROCEDURE GetPopulatedArea*(VAR r : Rectangle);
END GetPopulatedArea;
(** Internal handler for message that are directed to the window manager never call directly ! *)
PROCEDURE HandleInternal*(VAR msg : Messages.Message); (** PROTECTED *)
BEGIN