forked from rochus-keller/OberonSystem3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Columbus.Mod
2318 lines (2065 loc) · 80.9 KB
/
Columbus.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
(* OBERON System 3, Release 2.3.
Copyright 1999 ETH Zürich Institute for Computer Systems,
ETH Center, CH-8092 Zürich. e-mail: [email protected].
This module may be used under the conditions of the general Oberon
System 3 license contract. The full text can be downloaded from
"ftp://ftp.inf.ethz.ch/pub/software/Oberon/System3/license.txt;A"
Under the license terms stated it is in particular (a) prohibited to modify
the interface of this module in any way that disagrees with the style
or content of the system and (b) requested to provide all conversions
of the source code to another platform with the name OBERON. *)
MODULE Columbus; (** portable *) (* PS *)
(** - an inspector tool for objects and libraries. *)
(*
5.6.96 opens a new document not at the pointer's position anymore (thanks pm)
5.6.96 removed bug when adding a string attribute (thanks pm)
12.7.96 added commads Remove & RemoveFrom (thanks ejz)
22.7.96 fixed bug in EnumLinks (thanks eos)
25.7.96 change size of a gadget works now for 'off screen' frames, too
15.1.97 StoreLib binds all objects to library first
24.4.97 values are only set when changed
*)
IMPORT
Files, Objects, Fonts, Texts, Strings, Attributes, Links, Display, Oberon, Gadgets, Panels, TextFields,
BasicGadgets, BasicFigures, RefGadgets, ScrollViews, TextGadgets, ListRiders, Documents, Desktops;
CONST
Version = "1.2";
DocName = "Objects.Panel";
(* object names in library editor panel *)
ObjList = "objlist";
ObjNameObj = "theobj"; LibNameObj = "thelib";
RNameObj = "rname"; NNameObj = "nname";
CopyStyleObj = "copystyle"; RefObj = "value";
(* object names in inspector panel *)
ViewModeObjName = "ViewMode";
(* messures used to build inspector panel *)
Border = 7; PanelW = 370;
LargeW = 300; MediumW = 100; SmallW = 20;
Height = 20;
(* max. number of tabs in a layout *)
Tabs = 6;
(* item classes *)
Attribute = 0; Link = 1; Coord = 2;
Control = 3; Title = 4;
(* inspector panel views *)
ObjAttrView = 0; ObjLinkView = 1; ObjCoordView = 2;
ObjDscView = 3; ObjDefView = 4;
LibOverView = 5; LibEditView = 6;
NoView = 7;
ObjViews = {ObjAttrView, ObjLinkView, ObjCoordView, ObjDscView, ObjDefView};
(* layout align ids *)
top = 0; middle = 1; bottom = 2;
TYPE
(* attribute or link items of current inspected object *)
Item = POINTER TO ItemDesc;
ItemDesc = RECORD
next: Item;
class: INTEGER;
name: ARRAY 32 OF CHAR; (* attr./link name *)
val: Objects.Object; (* model, representing attr./link value *)
END;
(* history of inspected objects *)
HistoryItem = POINTER TO HistoryItemDesc;
HistoryItemDesc = RECORD
next: HistoryItem;
obj: Objects.Object;
lib: Objects.Library;
view: INTEGER
END;
(* inspector panel *)
Panel = POINTER TO PanelDesc;
PanelDesc = RECORD (Panels.PanelDesc)
items: Item;
history: HistoryItem
END;
(* special frame to handle writing of layouts into layouts *)
LayoutFrame = POINTER TO LayoutFrameDesc;
LayoutFrameDesc = RECORD (Display.FrameDesc)
END;
Layout = RECORD
align: INTEGER; (* 0: top / 1: middle / 2: bottom *)
X, Y, maxH: INTEGER;
frames: Display.Frame;
items: Item;
tabs: ARRAY Tabs OF INTEGER
END;
(* miniframework to handle the different views *)
CanProc = PROCEDURE (obj: Objects.Object; lib: Objects.Library): BOOLEAN;
MakeProc = PROCEDURE (obj: Objects.Object; lib: Objects.Library; VAR L: Layout);
ButtonProc = PROCEDURE (model, obj: Objects.Object; lib: Objects.Library): Display.Frame;
ViewGenDesc = RECORD
canView: CanProc; (* can this view show info *)
makeView: MakeProc; (* make the view's depending panel *)
getButton: ButtonProc (* returns a button to insert in the view selection area *)
END;
VAR
W: Texts.Writer;
enumObj: Objects.Object;
oldValues: Item;
layout: Layout;
msgPrinted: BOOLEAN;
viewGens: ARRAY NoView OF ViewGenDesc;
(* ---------------------- string opearation ----------------------- *)
(* converts a referece into a string of the form "# <i>". *)
PROCEDURE RefToStr(i: LONGINT; VAR s: ARRAY OF CHAR);
VAR k, j: INTEGER; a: ARRAY 10 OF CHAR;
BEGIN k:= 0;
REPEAT
a[k] := CHR(i MOD 10 + 30H); i := i DIV 10; INC(k)
UNTIL i = 0;
j := 2;
s[0]:= "#"; s[1]:= " ";
REPEAT DEC(k); s[j] := a[k]; INC(j); UNTIL k = 0;
s[j] := 0X
END RefToStr;
(* Appends <this> to <to>. *)
PROCEDURE Append(this: ARRAY OF CHAR; VAR to: ARRAY OF CHAR);
VAR i, j, l: LONGINT;
BEGIN
i := 0; WHILE to[i] # 0X DO INC(i) END;
l := LEN(to)-1; j := 0;
WHILE (i < l) & (this[j] # 0X) DO to[i] := this[j]; INC(i); INC(j) END;
to[i] := 0X
END Append;
(* Appends <this> to <to>. *)
PROCEDURE AppendCh(this: CHAR; VAR to: ARRAY OF CHAR);
VAR i: LONGINT;
BEGIN
i := 0; WHILE to[i] # 0X DO INC(i) END;
IF i < LEN(to) - 1 THEN to[i] := this; to[i+1] := 0X END
END AppendCh;
(* ---------------------- output proceudre to writer ----------------------- *)
PROCEDURE Char(ch: CHAR); (* writes a char to W *)
BEGIN Texts.Write(W, ch)
END Char;
PROCEDURE String(IN str: ARRAY OF CHAR); (* writes a string to W *)
BEGIN Texts.WriteString(W, str)
END String;
PROCEDURE Int(i: LONGINT); (* writes an integer to W *)
BEGIN Texts.WriteInt(W, i, 0)
END Int;
PROCEDURE Ln; (* writes a line feed to W *)
BEGIN Texts.WriteLn(W)
END Ln;
PROCEDURE ToLog; (* writes content of W to the Oberon log *)
BEGIN Texts.Append(Oberon.Log, W.buf)
END ToLog;
PROCEDURE PrintMsg; (* writes program's name and version to the Oberon log *)
BEGIN
Texts.SetFont(W, Fonts.This("Default10b.Scn.Fnt"));
String("Columbus "); String(Version);
Texts.SetFont(W, Fonts.Default);
String(" / PS November 95"); Ln; ToLog;
msgPrinted:= TRUE
END PrintMsg;
(* ---------------------- forward declarations ----------------------- *)
PROCEDURE ^InspectThis(VAR P: Panel; obj: Objects.Object; lib: Objects.Library; view: INTEGER);
(* ---------------------- document related procedures ----------------------- *)
PROCEDURE LoadDoc(D: Documents.Document);
VAR lib: Objects.Library; i: LONGINT; view: INTEGER; p: Panel; name: ARRAY 64 OF CHAR;
BEGIN
name := D.name;
p:= NIL; lib := NIL; view := NoView;
IF (name # "") & (name # DocName) THEN
i := 0;
WHILE name[i] # 0X DO INC(i) END;
REPEAT DEC(i) UNTIL (i = 0) OR (name[i] = ".");
IF i > 0 THEN
name[i + 1] := "L"; name[i + 2] := "i"; name[i + 3] := "b"; name[i + 4] := 0X;
lib := Objects.ThisLibrary(name);
IF lib # NIL THEN view := LibEditView END
END
END;
InspectThis(p, NIL, lib, view);
D.name := DocName; D.W:= p.W; D.H:= p.H;
Documents.Init(D, p)
END LoadDoc;
PROCEDURE StoreDoc(D: Documents.Document);
VAR f: Files.File; R: Files.Rider; filename: ARRAY 64 OF CHAR;
BEGIN
String("Store "); ToLog;
IF D.name # "" THEN
f:= Files.New(D.name); IF f = NIL THEN HALT(99) END;
Files.Set(R, f, 0); Files.WriteInt(R, Documents.Id); Files.WriteString(R, "Columbus.NewDoc");
Files.WriteInt(R, D.X); Files.WriteInt(R, D.Y); Files.WriteInt(R, D.W); Files.WriteInt(R, D.H);
Files.Register(f);
Char(22X); String(filename); Char(22X)
ELSE String("[Untitled document]")
END;
Ln; ToLog
END StoreDoc;
PROCEDURE DocHandler(D: Objects.Object; VAR M: Objects.ObjMsg);
BEGIN
WITH D: Documents.Document DO
IF M IS Objects.AttrMsg THEN
WITH M: Objects.AttrMsg DO
IF M.id = Objects.get THEN
IF M.name = "Gen" THEN M.class := Objects.String; M.s := "Columbus.NewDoc"; M.res := 0
ELSIF M.name = "Adaptive" THEN M.class := Objects.Bool; M.b := FALSE; M.res := 0
ELSIF M.name = "Icon" THEN M.class := Objects.String; M.s := "Columbus.Icon"; M.res := 0
ELSE Documents.Handler(D, M)
END
ELSE Documents.Handler(D, M)
END
END (* WITH *)
ELSIF M IS Objects.LinkMsg THEN
WITH M: Objects.LinkMsg DO
IF (M.name = "SystemMenu") OR (M.name = "UserMenu") OR (M.name = "DeskMenu") THEN
M.obj := Desktops.NewMenu(""); M.res := 0
ELSE Documents.Handler(D, M)
END
END
ELSE Documents.Handler(D, M)
END
END (* WITH *)
END DocHandler;
PROCEDURE NewDoc*;
VAR D: Documents.Document;
BEGIN
NEW(D);
D.Load := LoadDoc; D.Store := StoreDoc; D.handle := DocHandler;
D.W := 200; D.H := 200;
Objects.NewObj := D
END NewDoc;
(* ---------------------- panel related procedures ----------------------- *)
(*
PROCEDURE CopyPanel(VAR M: Objects.CopyMsg; from, to: Panel);
VAR h, newH: HistoryItem; i, newI: Item;
BEGIN
Log.Str("copying panel"); Log.Ln;
Panels.CopyPanel(M, from, to);
(* copy history *)
h:= from.history; NEW(newH); to.history:= newH;
WHILE h # NIL DO NEW(newH.next); newH:= newH.next; newH^:= h^; h:= h.next END;
to.history:= to.history.next;
(* copy items *)
i:= from.items; NEW(newI); to.items:= newI;
WHILE i # NIL DO NEW(newI.next); newI:= newI.next; newI^:= i^; i:= i.next END;
to.items:= to.items.next
END CopyPanel;
*)
PROCEDURE PanelHandler(P: Objects.Object; VAR M: Objects.ObjMsg);
VAR P1: Panel; f: Display.Frame; x, y, w, h, count: INTEGER;
BEGIN
WITH P: Panel DO
IF M IS Objects.AttrMsg THEN
WITH M: Objects.AttrMsg DO
IF (M.id = Objects.get) & (M.name = "Gen") THEN
M.class:= Objects.String; M.s := "Columbus.NewPanel"; M.res:= 0
ELSE Panels.PanelHandler(P, M)
END
END (* WITH *)
ELSIF M IS Objects.CopyMsg THEN
WITH M: Objects.CopyMsg DO
IF M.stamp = P.stamp THEN M.obj := P.dlink (* non-first arrival *)
ELSE (* first arrival -> make a new panel *)
InspectThis(P1, NIL, NIL, NoView); P.stamp := M.stamp; P.dlink := P1; M.obj := P1
END
END (* WITH *)
ELSIF M IS Objects.FileMsg THEN
WITH M: Objects.FileMsg DO
IF M.id = Objects.store THEN
Gadgets.framehandle(P, M)
ELSIF M.id = Objects.load THEN
Gadgets.framehandle(P, M);
P.history:= NIL;
InspectThis(P, NIL, NIL, NoView);
(* size panel *)
f:= P.dsc; WHILE f # NIL DO f.slink:= f.next; f:= f.next END;
Panels.BoundingBox(P.dsc, x, y, w, h, count);
P.W:= w + 2*Border; P.H:= h + 2*Border
END
END (* WITH *)
ELSE Panels.PanelHandler(P, M)
END
END (* WITH *)
END PanelHandler;
PROCEDURE InitPanel(P: Panel);
BEGIN
Panels.InitPanel(P); P.items:= NIL; P.history:= NIL;
P.handle:= PanelHandler
END InitPanel;
PROCEDURE NewPanel*;
VAR P: Panel;
BEGIN NEW(P); InitPanel(P); Objects.NewObj:= P
END NewPanel;
(* ---------------------- aux. proceudres ----------------------- *)
PROCEDURE Max(x, x0: INTEGER): INTEGER;
BEGIN IF x >= x0 THEN RETURN x ELSE RETURN x0 END
END Max;
(* ---------------------- frame generators ----------------------- *)
PROCEDURE MakeCaption(IN s: ARRAY OF CHAR; col: SHORTINT; bold: BOOLEAN): Display.Frame;
VAR F: TextFields.Caption; nolines: INTEGER;
BEGIN
TextFields.NewCaption; F:= Objects.NewObj(TextFields.Caption);
Attributes.StrToTxt(s, F.text);
Texts.ChangeLooks(F.text, 0, F.text.len, {1}, NIL, col, 0);
IF bold THEN
Texts.ChangeLooks(F.text, 0, F.text.len, {0}, Fonts.This("Default10b.Scn.Fnt"), 0, 0)
END;
TextFields.CalcSize(F, F.W, F.H, nolines, TRUE);
RETURN F
END MakeCaption;
(* Makes a button. If <isPict> is true, <caption> is interpreted as name of a public picture. *)
PROCEDURE MakeCmd(IN caption, cmd: ARRAY OF CHAR; isPict: BOOLEAN): Display.Frame;
VAR F: BasicGadgets.Button; A: Objects.AttrMsg;
BEGIN
BasicGadgets.NewButton; F:= Objects.NewObj(BasicGadgets.Button);
IF isPict THEN F.caption:= ""; F.look:= Gadgets.FindPublicObj(caption)
ELSE F.caption := caption
END;
F.val:= FALSE; F.popout:= TRUE;
A.id:= Objects.set; A.class:= Objects.String; A.name:= "Cmd"; A.s := cmd; A.res:= -1;
F.handle(F, A);
F.W:= 50; F.H:= 25;
RETURN F
END MakeCmd;
PROCEDURE MakeBool(val: BOOLEAN): Display.Frame;
VAR F: BasicGadgets.CheckBox;
BEGIN
BasicGadgets.NewCheckBox; F:= Objects.NewObj(BasicGadgets.CheckBox);
BasicGadgets.NewBoolean; F.obj:= Objects.NewObj;
F.obj(BasicGadgets.Boolean).val:= val; F.val:= val;
F.W:= SmallW; F.H:= Height;
RETURN F
END MakeBool;
PROCEDURE MakeString(IN val: ARRAY OF CHAR): Display.Frame;
VAR F: TextFields.TextField;
BEGIN
TextFields.NewTextField; F:= Objects.NewObj(TextFields.TextField);
BasicGadgets.NewString; F.obj:= Objects.NewObj;
F.W:= F.W*3;
F.obj(BasicGadgets.String).val := val; F.val := val;
F.W:= LargeW; F.H:= Height;
RETURN F
END MakeString;
PROCEDURE MakeInt(val: LONGINT): Display.Frame;
VAR F: TextFields.TextField;
BEGIN
TextFields.NewTextField; F:= Objects.NewObj(TextFields.TextField);
BasicGadgets.NewInteger; F.obj:= Objects.NewObj;
F.obj(BasicGadgets.Integer).val:= val; Strings.IntToStr(val, F.val);
F.W:= MediumW; F.H:= Height;
RETURN F
END MakeInt;
PROCEDURE MakeReal(val: LONGREAL): Display.Frame;
VAR F: TextFields.TextField;
BEGIN
TextFields.NewTextField; F:= Objects.NewObj(TextFields.TextField);
BasicGadgets.NewReal; F.obj:= Objects.NewObj;
F.obj(BasicGadgets.Real).val:= val; Strings.RealToStr(val, F.val);
F.W:= MediumW; F.H:= Height;
RETURN F
END MakeReal;
PROCEDURE MakeLink(val: Objects.Object; locked: BOOLEAN): Display.Frame;
VAR F: RefGadgets.Frame; A: Objects.AttrMsg;
BEGIN
RefGadgets.NewFrame; F:= Objects.NewObj(RefGadgets.Frame);
RefGadgets.NewReference; F.obj:= Objects.NewObj;
A.id:= Objects.set; A.class:= Objects.String; A.name:= "Cmd"; A.s:= "Columbus.InspectLink Value";
A.res:= -1;F.handle(F, A);
F.obj(RefGadgets.Reference).val:= val; F.val:= val;
F.W:= SmallW; F.H:= Height; F.locked:= locked;
RETURN F
END MakeLink;
(* ---------------------- layout proceudres ----------------------- *)
PROCEDURE ClearTabs(VAR L: Layout);
VAR i: INTEGER;
BEGIN i:= 0; WHILE i < Tabs DO L.tabs[i]:= 0; INC(i) END
END ClearTabs;
PROCEDURE OpenLayout(VAR L: Layout);
BEGIN
L.X:= 0; L.Y:= 0; L.maxH:= 0; L.align:= top; L.frames:= NIL; L.items:= NIL;
ClearTabs(L)
END OpenLayout;
PROCEDURE SetTab(VAR L: Layout);
VAR i: INTEGER;
BEGIN
i:= 0; WHILE (i < Tabs) & (L.tabs[i] > 0) DO INC(i) END;
IF i < Tabs THEN L.tabs[i]:= L.X END
END SetTab;
(* Adjusts the position of all frames line <L.Y>, corresponding to <L.align>. <L.Y> is decremented
by <L.maxH> and <L.X> and <L.maxH> are set to zero. Inserts any subframes into <L.frames>. *)
PROCEDURE WriteLn(VAR L: Layout);
VAR f, p, sf: Objects.Object;
BEGIN
f:= L.frames; p:= NIL;
WHILE f # NIL DO
WITH f: Display.Frame DO
IF f.Y+f.H-1 = L.Y THEN (* on the same line *)
IF L.align = top THEN (* top *)
ELSIF L.align = middle THEN (* middle *)
f.Y:= L.Y - L.maxH DIV 2 - (f.H + 1) DIV 2 ;
ELSE (* bottom *)
f.Y:= L.Y - L.maxH + 1
END
END; (* IF *)
IF f IS LayoutFrame THEN
IF p # NIL THEN p.slink:= f.dsc
ELSE L.frames:= f.dsc
END;
sf:= f.dsc; p:= NIL;
WHILE sf # NIL DO
WITH sf: Display.Frame DO INC(sf.X, f.X); INC(sf.Y, f.Y+f.H-1) END;
p:= sf; sf:= sf.slink
END;
p.slink:= f.slink; f:= p(Display.Frame)
END
END; (* WITH *)
p:= f; f:= f.slink
END; (* WHILE *)
DEC(L.Y, L.maxH); L.maxH:= 0; L.X:= 0
END WriteLn;
PROCEDURE WriteHSpace(VAR L: Layout; w: INTEGER);
BEGIN INC(L.X, w)
END WriteHSpace;
(* Sets <L.X> to the next tab position or increments <L.X> by 20, if there is no
tab position anymore. *)
PROCEDURE WriteTab(VAR L: Layout);
VAR i: INTEGER;
BEGIN
i:= 0; WHILE (i < Tabs) & (L.tabs[i] # 0) & (L.tabs[i] <= L.X) DO INC(i) END;
IF (i < Tabs) & (L.tabs[i] # 0) THEN L.X:= L.tabs[i]
ELSE L.X:= ((L.X+20) DIV 20)*20
END
END WriteTab;
(* Writes a vertical space of length <h>. *)
PROCEDURE WriteVSpace(VAR L: Layout; h: INTEGER);
BEGIN DEC(L.Y, h)
END WriteVSpace;
(* Writes <F> to <L>. Sets <F.X> and <F.Y>, adds frame to <L.frames> and
adjusts <L.X> and <L.maxH>.*)
PROCEDURE WriteFrame(VAR L: Layout; F: Display.Frame);
BEGIN
F.X:= L.X; F.Y:= L.Y-F.H+1; INC(L.X, F.W); L.maxH:= Max(L.maxH, F.H);
F.slink:= L.frames; L.frames:= F
END WriteFrame;
PROCEDURE WriteLine(VAR L: Layout);
VAR F: BasicFigures.Figure;
BEGIN
NEW(F); BasicFigures.InitLine(F, 0, 0, PanelW-10, 0);
WriteLn(L); WriteVSpace(L, 2);
F.X:= L.X; F.Y:= L.Y-F.H+1; INC(L.X, F.W); L.maxH:= Max(L.maxH, F.H);
F.slink:= L.frames; L.frames:= F
END WriteLine;
PROCEDURE WriteCaption(VAR L: Layout; IN s: ARRAY OF CHAR; col: SHORTINT; bold: BOOLEAN);
VAR F: Display.Frame;
BEGIN
F:= MakeCaption(s, col, bold);
F.X:= L.X; F.Y:= L.Y-F.H+1; INC(L.X, F.W); L.maxH:= Max(L.maxH, F.H);
F.slink:= L.frames; L.frames:= F
END WriteCaption;
PROCEDURE WriteCmd(VAR L: Layout; IN caption, cmd: ARRAY OF CHAR; isPict: BOOLEAN);
VAR F: Display.Frame;
BEGIN
F:= MakeCmd(caption, cmd, isPict);
F.X:= L.X; F.Y:= L.Y-F.H+1; INC(L.X, F.W); L.maxH:= Max(L.maxH, F.H);
F.slink:= L.frames; L.frames:= F
END WriteCmd;
(* Inserts a special frame, containing <l.frames> as its desc.. The subframes are added to <L> when
the next WriteLn is performed. *)
PROCEDURE WriteLayout(VAR L, l: Layout);
VAR F: LayoutFrame; cnt: INTEGER;
BEGIN
NEW(F); Panels.BoundingBox(l.frames, F.X, F.Y, F.W, F.H, cnt);
F.dsc:= l.frames;
F.X:= L.X; F.Y:= L.Y-F.H+1; INC(L.X, F.W); L.maxH:= Max(L.maxH, F.H);
F.slink:= L.frames; L.frames:= F
END WriteLayout;
PROCEDURE WriteLogo(VAR L: Layout; W: INTEGER);
VAR obj: Objects.Object; F: Display.Frame; C: Objects.CopyMsg;
BEGIN
obj:= Gadgets.FindPublicObj("Columbus.Logo");
IF (obj # NIL) THEN
C.id:= Objects.deep; Objects.Stamp(C); C.obj:= NIL; obj.handle(obj, C);
IF (C.obj # NIL) & (C.obj IS Display.Frame) THEN F:= C.obj(Display.Frame)
ELSE F:= MakeCaption("COLUMBUS", Display.FG, TRUE)
END
ELSE F:= MakeCaption("COLUMBUS", Display.FG, TRUE)
END;
IF F # NIL THEN
F.X:= L.X + (W - F.W) DIV 2; F.Y:= L.Y-F.H+1; L.X:= F.X + F.W; L.maxH:= Max(L.maxH, F.H);
F.slink:= L.frames; L.frames:= F
END
END WriteLogo;
(* Write a list of items to <L>. *)
PROCEDURE WriteItems(VAR L: Layout; classes: SET);
(* index calculation:
0 1 2 3 4
---------------------------
LLLLLLLLLLLLLLLLLLLLLLLLLLL
MMMMMMMMMMM MMMMMMMMMMM
MMMMMMMMMMM SS SS
SS MMMMMMMMMMM SS
SS SS MMMMMMMMMMM
SS SS SS SS
*)
VAR width: ARRAY 6 OF INTEGER; index: INTEGER;
PROCEDURE AdjustIndex(W: INTEGER);
BEGIN
(*
IF index > 5 THEN index:= 0
ELSIF (W = MediumW) & (index > 3) THEN index:= 0
ELSIF W = LargeW THEN index:= 0
END
*)
IF index > 4 THEN index:= 0
ELSIF (W = MediumW) & (index > 3) THEN index:= 0
ELSIF W = LargeW THEN index:= 0
END
END AdjustIndex;
PROCEDURE NextIndex(W: INTEGER);
BEGIN
(*
IF index = 0 THEN index:= -1 END;
IF W = SmallW THEN INC(index, 2)
ELSIF (W = MediumW) & (index # 2) THEN INC(index, 3)
ELSE INC(index, 7)
END
*)
IF W = SmallW THEN IF index = 2 THEN INC(index, 2) ELSE INC(index, 1) END
ELSIF W = MediumW THEN INC(index, 3)
ELSE INC(index, 5)
END
END NextIndex;
PROCEDURE CalcWidth(VAR i: Item);
BEGIN
IF i.next # NIL THEN CalcWidth(i.next) END;
IF i.class IN classes / {Title} THEN
AdjustIndex(i.val(Display.Frame).W);
width[index]:= Max(width[index], i.val(Display.Frame).next.W);
NextIndex(i.val(Display.Frame).W)
END
END CalcWidth;
PROCEDURE Write(i: Item);
VAR n, f: Display.Frame; F: Gadgets.Frame;
BEGIN
IF i.next # NIL THEN Write(i.next) END;
IF i.class IN classes THEN
F:= i.val(Gadgets.Frame);
IF i.class = Title THEN
WriteLn(L); WriteVSpace(L, 4);
L.align:= bottom; WriteFrame(L, F);
WriteHSpace(L, PanelW - L.X); n:= F.next;
WHILE n # NIL DO
f:= n; n:= f.next;
WriteHSpace(L, -f.W); WriteFrame(L, f); WriteHSpace(L, - f.W - 5)
END;
WriteLn(L); L.align:= middle; WriteVSpace(L, 2);
index:= 0; i.val:= NIL
ELSE
AdjustIndex(F.W);
IF index = 0 THEN
IF L.maxH # 0 THEN L.maxH:= Max(L.maxH, Height) END;
WriteLn(L)
ELSE WriteHSpace(L, 10)
END;
WriteHSpace(L, width[index]-F.next.W); WriteFrame(L, F.next);
WriteHSpace(L, 3); WriteFrame(L, F);
NextIndex(F.W);
F.next:= NIL; i.val:= F.obj
END
END
END Write;
BEGIN
index:= 0; WHILE index < 6 DO width[index] := 0; INC(index) END;
index:= 0; CalcWidth(L.items);
index:= 0; Write(L.items)
END WriteItems;
(* ---------------------- procs to create new items and add them to a layout ----------------------- *)
PROCEDURE AddItem(VAR L: Layout; IN name: ARRAY OF CHAR; class: INTEGER; val: Display.Frame);
VAR new: Item;
BEGIN
val.next:= MakeCaption(name, Display.FG, FALSE);
NEW(new); new.name := name; new.val:= val; new.class:= class;
new.next:= L.items; L.items:= new
END AddItem;
PROCEDURE AddTitleItem(VAR L: Layout; IN str: ARRAY OF CHAR; cmds: Display.Frame);
VAR f: Display.Frame; new: Item;
BEGIN
f:= MakeCaption(str, Display.FG, TRUE); f.next:= cmds;
NEW(new); new.class:= Title; new.name:= "Title"; new.val:= f;
new.next:= L.items; L.items:= new
END AddTitleItem;
PROCEDURE AddControlItem(VAR L: Layout; IN name, caption: ARRAY OF CHAR; val: Display.Frame);
VAR new: Item;
BEGIN
val.next:= MakeCaption(caption, Display.FG, FALSE);
NEW(new); new.class:= Control; new.name := name; new.val:= val;
new.next:= L.items; L.items:= new
END AddControlItem;
(* ---------------------- enumerators ----------------------- *)
(* Attribute enumerator: an attr. item is added to <layout>, if not already there. *)
PROCEDURE EnumAttr(IN name: ARRAY OF CHAR);
VAR A: Objects.AttrMsg; i: Item; val: Display.Frame; s: ARRAY 2 OF CHAR;
BEGIN
i:= layout.items; WHILE (i # NIL) & ((i.name # name) OR (i.class # Attribute)) DO i:= i.next END;
IF i # NIL THEN RETURN END;
A.id:= Objects.get; A.class:= Objects.Inval; A.name := name; A.res:= -1;
enumObj.handle(enumObj, A);
IF (A.res = -1) OR (A.class = Objects.Inval) THEN val:= MakeCaption("has no value", Display.FG, FALSE)
ELSIF A.class = Objects.Bool THEN val:= MakeBool(A.b)
ELSIF A.class = Objects.String THEN val:= MakeString(A.s)
ELSIF A.class = Objects.Int THEN val:= MakeInt(A.i)
ELSIF A.class = Objects.Real THEN val:= MakeReal(A.x)
ELSIF A.class = Objects.LongReal THEN val:= MakeReal(A.y)
ELSIF A.class = Objects.Char THEN s[0]:= A.c; s[1]:= 0X; val:= MakeString(s)
ELSE val:= MakeCaption("has unknown type", Display.FG, FALSE)
END;
AddItem(layout, name, Attribute, val)
END EnumAttr;
(* Link enumerator: a link item is add to <layout>, if not already there. *)
PROCEDURE EnumLink(IN name: ARRAY OF CHAR);
VAR L: Objects.LinkMsg; i: Item;
BEGIN
i:= layout.items; WHILE (i # NIL) & ((i.name # name) OR (i.class # Link)) DO i:= i.next END;
IF i # NIL THEN RETURN END;
L.id:= Objects.get; L.name := name; L.obj:= NIL; L.res := -1;
enumObj.handle(enumObj, L);
AddItem(layout, name, Link, MakeLink(L.obj, FALSE))
END EnumLink;
(* ---------------------- main explore procedure ----------------------- *)
(* Inserts <frames> into <P> and resizes the it. Old objects in the panel are removed. *)
PROCEDURE MakePanel(P: Panels.Panel; frames: Display.Frame; border: INTEGER; new: BOOLEAN);
VAR f: Display.Frame; x, y, w, h, cnt: INTEGER; A: Objects.AttrMsg; R: Display.ControlMsg;
C: Display.ConsumeMsg; M: Display.ModifyMsg;
BEGIN
Panels.BoundingBox(frames, x, y, w, h, cnt);
(* remove old objects in panel *)
R.id:= Display.remove; R.F:= NIL;
f:= P.dsc;
WHILE f # NIL DO f.slink:= R.F; R.F:= f; f:= f.next END;
IF R.F # NIL THEN Display.Broadcast(R) END;
(* size panel *)
IF w + border*2 < Desktops.recDocWidth THEN w := Desktops.recDocWidth - 2*border END;
IF new THEN P.W:= w + border*2; P.H:= h + border*2
ELSE
M.id:= Display.extend; M.F:= P; M.mode:= Display.display;
M.W:= w + border*2; M.dW:= M.W - P.W; M.H:= h + border*2; M.dH:= M.H - P.H;
M.X:= P.X; M.dX:= 0; M.Y:= P.Y + P.H - M.H; M.dY:= M.Y - P.Y;
Display.Broadcast(M);
A.id:= Objects.set; A.class:= Objects.Bool; A.name:= "Locked"; A.b:= FALSE; A.res:= -1;
P.handle(P, A)
END;
(* insert new objects in panel *)
C.id:= Display.drop; C.F:= P; C.obj:= frames; C.x:= 0; C.y:= 0;
C.u:= border; C.v:= -border - h + 1; C.res:= -1; C.dlink:= NIL;
P.handle(P, C);
A.id:= Objects.set; A.class:= Objects.Bool; A.name:= "Locked"; A.b:= TRUE; A.res:= -1;
P.handle(P, A)
END MakePanel;
(* Writes a reference, the library name and the lib. reference to the top right corner of the panel *)
PROCEDURE WriteGeneralObjInfo(obj: Objects.Object; VAR L: Layout);
VAR f: Display.Frame; A: Objects.AttrMsg;
BEGIN
WriteCaption(L, "Current Object", Display.FG, TRUE); WriteHSpace(L, 4); SetTab(L);
f:= MakeLink(obj, FALSE);
A.id:= Objects.set; A.class:= Objects.String; A.name:= "ConsumeCmd"; A.s:= "Columbus.InspectLink Value";
A.res:= -1; f.handle(f, A);
f(Gadgets.Frame).obj:= NIL;
WriteFrame(L, f); WriteLn(L); WriteVSpace(L, 2);
END WriteGeneralObjInfo;
(* Writes library's name to the top, right corner of the panel *)
PROCEDURE WriteGeneralLibInfo(lib: Objects.Library; VAR L: Layout);
BEGIN
WriteCaption(L, "Current Library", Display.FG, TRUE); WriteHSpace(L, 3);
IF lib.name = "" THEN WriteCaption(L, "(Private)", Display.FG, FALSE)
ELSE WriteCaption(L, lib.name, Display.FG, FALSE)
END
END WriteGeneralLibInfo;
PROCEDURE InspectThis(VAR P: Panel; obj: Objects.Object; lib: Objects.Library; view: INTEGER);
VAR int: BasicGadgets.Integer; h: HistoryItem; availViews:
SET; i: INTEGER; new: BOOLEAN; subLay: Layout;
BEGIN
new:= FALSE;
IF P = NIL THEN NEW(P); InitPanel(P); new:= TRUE END;
(* update panel's history *)
h:= P.history;
IF h = NIL THEN (* no history yet *)
NEW(h); h.next:= P.history; P.history:= h; h.view:= NoView
ELSIF h.view = NoView THEN (* current view is empty -> check if last was same *)
h:= h.next;
IF (h = NIL) OR (h.obj # obj) OR (h.lib # lib) THEN h:= P.history
ELSE P.history:= h
END
ELSIF (h.obj # obj) OR (h.lib # lib) OR (h.view # view) THEN (* check if not same *)
h:= NIL; NEW(h); h.next:= P.history; P.history:= h; h.view:= NoView
END;
IF h.view = NoView THEN h.obj:= obj; h.lib:= lib; h.view:= view END;
(* write top, left corner *)
OpenLayout(layout); layout.align:= middle;
WriteLogo(layout, 104); WriteHSpace(layout, 104 - layout.X);
WriteCmd(layout, "Columbus.Mag", "Columbus.Inspect", TRUE); WriteHSpace(layout, 2);
IF P.history.next # NIL THEN WriteCmd(layout, "Columbus.Back", "Columbus.Back", TRUE) END;
IF (obj = NIL) & (lib = NIL) THEN view:= NoView END;
IF view < NoView THEN
(* Get all available views *)
i:= 0; availViews:= {};
WHILE i < NoView DO
IF (viewGens[i].canView # NIL) & viewGens[i].canView(obj, lib) THEN INCL(availViews, i) END;
INC(i)
END;
(* Check if we can show desired view. If not, get first available view *)
IF ~(view IN availViews) THEN
view:= 0; WHILE ~(view IN availViews) & (view < NoView) DO INC(view) END;
END;
(* if there is a view, make panel *)
IF view < NoView THEN
(* write object or lib area (top, right corner) *)
OpenLayout(subLay); subLay.align:= middle;
IF view IN ObjViews THEN WriteGeneralObjInfo(obj, subLay)
ELSE WriteGeneralLibInfo(lib, subLay)
END;
WriteLayout(layout, subLay);
layout.frames.X:= PanelW - layout.frames.W - 1; (* hack *)
WriteLn(layout);
(* write view selection area *)
OpenLayout(subLay);
WriteVSpace(layout, 5);
BasicGadgets.NewInteger; int:= Objects.NewObj(BasicGadgets.Integer);
Gadgets.NameObj(int, ViewModeObjName);
int.val:= view;
i:= 0;
WHILE i < NoView DO
IF i IN availViews THEN
IF i IN ObjViews THEN
WriteFrame(layout, viewGens[i].getButton(int, obj, lib)); WriteHSpace(layout, 2)
ELSE
WriteHSpace(subLay, 2); WriteFrame(subLay, viewGens[i].getButton(int, obj, lib))
END
END;
INC(i)
END;
IF subLay.frames # NIL THEN
WriteLayout(layout, subLay);
layout.frames.X:= PanelW - layout.frames.W - 1 (* hack *)
END;
(* write private area *)
WriteLine(layout); WriteLn(layout);
viewGens[view].makeView(obj, lib, layout)
ELSE view:= NoView
END
END;
WriteLn(layout);
MakePanel(P, layout.frames, Border, new);
P.items:= layout.items;
END InspectThis;
(* ---------------------- attribute view ----------------------- *)
PROCEDURE CanViewAttr(obj: Objects.Object; lib: Objects.Library): BOOLEAN;
BEGIN RETURN obj # NIL
END CanViewAttr;
PROCEDURE AttrViewButton(model, obj: Objects.Object; lib: Objects.Library): Display.Frame;
VAR f: Display.Frame;
BEGIN
f:= MakeCmd("Attr", "Columbus.InspectCurrent", FALSE);
WITH f: BasicGadgets.Button DO
f.obj:= model;
f.setval:= ObjAttrView; f.popout:= FALSE; f.val:= (f.setval = model(BasicGadgets.Integer).val)
END;
RETURN f
END AttrViewButton;
PROCEDURE MakeAttrView(obj: Objects.Object; lib: Objects.Library; VAR L: Layout);
VAR A: Objects.AttrMsg; cmds: Display.Frame;
BEGIN
(* write attributes *)
cmds:= MakeCmd("Apply", "Columbus.Apply", FALSE);
AddTitleItem(L, "Attributes", cmds);
A.id:= Objects.get; A.class:= Objects.String; A.name:= "Gen"; A.res:= -1; obj.handle(obj, A);
AddItem(L, "Generator", Attribute, MakeCaption(A.s, Display.FG, FALSE));
Gadgets.GetObjName(obj, A.s); AddItem(L, "Name", Attribute, MakeString(A.s));
enumObj:= obj;
A.id:= Objects.enum; A.Enum:= EnumAttr; obj.handle(obj, A);
enumObj:= NIL;
(* write attribute controls *)
cmds:= MakeCmd("Add", "Columbus.Add", FALSE);
cmds.next := MakeCmd("Del", "Columbus.Remove", FALSE);
AddTitleItem(L, "New Attribute", cmds);
AddControlItem(L, "AName", "Attr. Name", MakeString(""));
AddControlItem(L, "AValue", "Attr. Value", MakeString(""));
WriteItems(L, {Title, Attribute, Control})
END MakeAttrView;
(* ---------------------- link view ----------------------- *)
PROCEDURE CanViewLink(obj: Objects.Object; lib: Objects.Library): BOOLEAN;
BEGIN RETURN obj # NIL
END CanViewLink;
PROCEDURE LinkViewButton(model, obj: Objects.Object; lib: Objects.Library): Display.Frame;
VAR f: Display.Frame;
BEGIN
f:= MakeCmd("Link", "Columbus.InspectCurrent", FALSE);
WITH f: BasicGadgets.Button DO
f.obj:= model;
f.setval:= ObjLinkView; f.popout:= FALSE; f.val:= (f.setval = model(BasicGadgets.Integer).val)
END;
RETURN f
END LinkViewButton;
PROCEDURE MakeLinkView(obj: Objects.Object; lib: Objects.Library; VAR L: Layout);
VAR cmds: Display.Frame; LM: Objects.LinkMsg;
BEGIN
(* write links *)
cmds:= MakeCmd("Apply", "Columbus.Apply", FALSE);
AddTitleItem(L, "Links", cmds);
enumObj:= obj;
LM.id:= Objects.enum; LM.Enum:= EnumLink; obj.handle(obj, LM);
enumObj:= NIL;
IF L.items.class = Title THEN L.items:= L.items.next END;
(* write link controls *)
cmds:= MakeCmd("Add", "Columbus.Add", FALSE);
cmds.next := MakeCmd("Del", "Columbus.Remove", FALSE);
AddTitleItem(L, "New Link", cmds);
AddControlItem(L, "LName", "Link Name", MakeString(""));
AddControlItem(L, "LValue", "Link Value", MakeLink(NIL, FALSE));
WriteItems(L, {Title, Link, Control})
END MakeLinkView;
(* ---------------------- coord view ----------------------- *)
PROCEDURE CanViewCoord(obj: Objects.Object; lib: Objects.Library): BOOLEAN;
BEGIN RETURN (obj # NIL) & (obj IS Gadgets.Frame)
END CanViewCoord;
PROCEDURE CoordViewButton(model, obj: Objects.Object; lib: Objects.Library): Display.Frame;
VAR f: Display.Frame;
BEGIN
f:= MakeCmd("Coords", "Columbus.InspectCurrent", FALSE);
WITH f: BasicGadgets.Button DO
f.obj:= model;
f.setval:= ObjCoordView; f.popout:= FALSE; f.val:= (f.setval = model(BasicGadgets.Integer).val)
END;
RETURN f
END CoordViewButton;
PROCEDURE MakeCoordView(obj: Objects.Object; lib: Objects.Library; VAR L: Layout);
VAR cmds: Display.Frame;
BEGIN
WITH obj: Gadgets.Frame DO
(* write Coords *)
cmds:= MakeCmd("Apply", "Columbus.Apply", FALSE);
AddTitleItem(L, "Coordinates", cmds);
AddItem(L, "X", Coord, MakeInt(obj.X));
AddItem(L, "Y", Coord, MakeInt(obj.Y));
AddItem(L, "W", Coord, MakeInt(obj.W));
AddItem(L, "H", Coord, MakeInt(obj.H));
WriteItems(L, {Coord, Title})
END
END MakeCoordView;
(* ---------------------- def view ----------------------- *)
PROCEDURE CanViewDef(obj: Objects.Object; lib: Objects.Library): BOOLEAN;
BEGIN RETURN obj # NIL
END CanViewDef;
PROCEDURE DefViewButton(model, obj: Objects.Object; lib: Objects.Library): Display.Frame;
VAR A: Objects.AttrMsg; str: ARRAY 64 OF CHAR;
BEGIN
A.id:= Objects.get; A.name:= "Gen"; A.res:= -1; obj.handle(obj, A);
Append("Watson.ShowObj ", str); AppendCh(Oberon.OptionChar, str); Append("TMD ", str); Append(A.s, str);
RETURN MakeCmd("Columbus.Def", str, TRUE)
END DefViewButton;
(* ---------------------- desc view ----------------------- *)
PROCEDURE CanViewDsc(obj: Objects.Object; lib: Objects.Library): BOOLEAN;
BEGIN RETURN (obj # NIL) & (obj IS Display.Frame) & (obj(Display.Frame).dsc # NIL)
END CanViewDsc;
PROCEDURE DscViewButton(model, obj: Objects.Object; lib: Objects.Library): Display.Frame;
VAR f: Display.Frame;
BEGIN
f:= MakeCmd("Comp", "Columbus.InspectCurrent", FALSE);
WITH f: BasicGadgets.Button DO
f.obj:= model;
f.setval:= ObjDscView; f.popout:= FALSE; f.val:= (f.setval = model(BasicGadgets.Integer).val)
END;
RETURN f
END DscViewButton;
PROCEDURE MakeDscView(obj: Objects.Object; lib: Objects.Library; VAR L: Layout);
VAR p: Panels.Panel; v: ScrollViews.View; o: Display.Frame; cnt: INTEGER;
subLay: Layout; A: Objects.AttrMsg; M: Display.ModifyMsg;