forked from rochus-keller/OberonSystem3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Books.Mod
1225 lines (1170 loc) · 31.7 KB
/
Books.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 Books; (** portable *) (* ejz, further hacked by jm *)
IMPORT Books0, Panels, Objects, Documents, Gadgets, Display, Display3, TextGadgets, TextGadgets0, BasicGadgets,
Texts, Fonts, Oberon, Modules, Desktops, Effects;
CONST
(* some other special characters *)
EOL* = 0DX; Tab* = 09X; quote* = CHR(34);
(* constants used by Texts.ChangeLooks *)
looksLib* = 0; looksCol* = 1;
(* limit for chapter nesting *)
maxSect* = 4;
(* colors for special text *)
linkCol* = 3 (*Display3.blue*); callCol* = 1(*Display3.red*); noteCol* = 8;
(* more modes for Books0.Frame *)
link* = 1; call* = 2; note* = 3;
(* options for Panel *)
formated* = 0; resize* = 1; icon* = 2; usesnotes* = 3; formatText* = 4; twoRow*= 5;
invalid* = 15; left* = 16; middle* = 17; right* = 18; pad* = 19;
(* constants used to draw a tutorial *)
border* = 4;
borderL* = 1; borderR* = 0;
borderT* = 0; borderB* = 1;
barH* = 4;
buttonW* = 50; buttonH* = 20;
scrollBW* = 25;
TYPE
TGFrame* = POINTER TO TGFrameDesc;
Panel* = POINTER TO PanelDesc;
Chain = POINTER TO ChainDesc;
(* extended TextGadgets.Frame: lastPos: for searching; panel: easy find the owning panel *)
TGFrameDesc* = RECORD (TextGadgets.FrameDesc)
focus: BOOLEAN;
lastPos*: LONGINT;
panel*: Panel
END;
(* extended Panels.Panel: contains all data needed for a tutorial at runtime *)
PanelDesc* = RECORD (Panels.PanelDesc)
doc*: Documents.Document;
iconStr*: ARRAY 2*Books0.nameLen OF CHAR;
texts*, cur*: Books0.TextList;
cmds*, notes*: Texts.Text;
useStack*: Chain;
imps*: Books0.ImpList;
options*: SET;
curC: Books0.ContElem;
noteH*: INTEGER
END;
(* stack of changes to a tutorial *)
ChainDesc = RECORD
old: Books0.TextList;
pos: LONGINT;
next: Chain
END;
VAR
Wr: Texts.Writer;
B: Texts.Buffer;
tmpT: Texts.Text;
(* new methods for TGFrame *)
m: TextGadgets0.Methods;
(* set to open a tutorial at any position *)
newPos*, newInd*: LONGINT;
(* retrieve Text/Note-Gadgets from a panel *)
PROCEDURE GetText*(P: Panel; VAR T: TGFrame);
VAR obj: Objects.Object;
BEGIN
T := NIL;
IF P # NIL THEN
obj := Gadgets.FindObj(P, "Text");
IF (obj # NIL) & (obj IS TGFrame) THEN
T := obj(TGFrame)
END
END
END GetText;
PROCEDURE GetNote*(P: Panel; VAR T: TGFrame);
VAR obj: Objects.Object;
BEGIN
T := NIL;
IF P # NIL THEN
obj := Gadgets.FindObj(P, "Note");
IF (obj # NIL) & (obj IS TGFrame) THEN
T := obj(TGFrame)
END
END
END GetNote;
(* resize all TextGadgets.Style to w in a tutorial (P) *)
PROCEDURE ResizeControls*(P: Panel; T: TGFrame; w: INTEGER);
VAR
Fi: Texts.Finder;
t: Books0.TextList;
obj: Objects.Object;
BEGIN
IF T # NIL THEN
Texts.OpenFinder(Fi, T.text, 0);
Texts.FindObj(Fi, obj);
WHILE ~Fi.eot DO
IF (obj # NIL) & (obj IS TextGadgets.Style) THEN
obj(TextGadgets.Style).width := w
END;
Texts.FindObj(Fi, obj)
END
END;
t := P.texts;
WHILE t # NIL DO
Texts.OpenFinder(Fi, t.text, 0);
Texts.FindObj(Fi, obj);
WHILE ~Fi.eot DO
IF (obj # NIL) & (obj IS TextGadgets.Style) THEN
obj(TextGadgets.Style).width := w
END;
Texts.FindObj(Fi, obj)
END;
t := t.next
END
END ResizeControls;
(* redisplay a tutorial panel *)
PROCEDURE MoveBar(P: Panel; M: Display.ModifyMsg; name: ARRAY OF CHAR; Y, mode: INTEGER; broadcast: BOOLEAN);
VAR
obj: Objects.Object;
msg: Display.ModifyMsg;
BEGIN
obj := Gadgets.FindObj(P, name);
IF obj # NIL THEN
msg.id := Display.move;
msg.mode := mode;
msg.W := M.W-borderL-borderR+1;
msg.H := obj(Books0.Bar).H;
msg.dW := 0; msg.dH := 0;
msg.dX := 0; msg.dY := 0;
msg.x := 0; msg.y := 0;
msg.X := obj(Books0.Bar).X;
msg.Y := Y;
msg.F := obj(Books0.Bar);
msg.res := -1; msg.dlink := P;
msg.stamp := M.stamp;
IF broadcast THEN
Display.Broadcast(msg)
ELSE
obj.handle(obj, msg)
END
END
END MoveBar;
PROCEDURE ReDisplay*(VAR M: Display.ModifyMsg; mode: INTEGER; broadcast: BOOLEAN);
VAR
butH: INTEGER;
T, Tn: TGFrame;
P: Panel;
msg: Display.ModifyMsg;
BEGIN
P := M.F(Panel);
GetText(P, T);
IF twoRow IN P.options THEN
butH := 2*buttonH
ELSE
butH := buttonH
END;
MoveBar(P, M, "bar1", (*M.Y*) - M.H + 1 +borderB+butH+barH+P.noteH-1, mode, broadcast);
msg.id := M.id; msg.mode := mode;
msg.dX := 0; msg.dY := 0;
msg.W := M.W-borderL-borderR+1;
msg.H := M.H-borderB-butH-barH-P.noteH-barH-barH-borderT+1;
msg.dW := M.dW; msg.dH := msg.H-T.H;
msg.X := T.X; msg.Y := T.Y-msg.dH;
msg.F := T;
msg.res := -1;
msg.x := 0; msg.y := 0;
msg.dlink := P; msg.stamp := M.stamp;
IF broadcast THEN
Display.Broadcast(msg)
ELSE
T.handle(T, msg)
END;
GetNote(P, Tn);
msg.id := M.id; msg.mode := mode;
msg.dX := 0; msg.dY := 0;
msg.W := M.W-borderL-borderR+1;
msg.H := P.noteH;
msg.Y := Tn.Y-msg.dH;
msg.dW := M.dW; msg.dH := msg.H-Tn.H;
msg.X := Tn.X; msg.Y := msg.Y-msg.dH;
msg.F := Tn;
msg.res := -1;
msg.x := 0; msg.y := 0;
msg.dlink := P; msg.stamp := M.stamp;
IF broadcast THEN
Display.Broadcast(msg)
ELSE
Tn.handle(Tn, msg)
END
END ReDisplay;
(* make a copy of a given (from) text, replace styles by new ones *)
PROCEDURE CopyText*(from: Texts.Text; VAR to: Texts.Text);
VAR
B: Texts.Buffer;
F: Texts.Finder;
obj, obj2: Objects.Object;
beg, pos: LONGINT;
C: Objects.CopyMsg;
BEGIN
IF to = NIL THEN
NEW(to); Texts.Open(to, "")
ELSE
Texts.Delete(to, 0, to.len)
END;
NEW(B); Texts.OpenBuf(B);
beg := 0;
Texts.OpenFinder(F, from, 0);
pos := F.pos;
Texts.FindObj(F, obj);
WHILE ~F.eot DO
IF obj IS TextGadgets.Style THEN
IF pos >= beg THEN
Texts.Save(from, beg, pos, B);
Texts.Append(to, B)
END;
C.id := Objects.deep;
C.obj := NIL;
Objects.Stamp(C);
obj.handle(obj, C);
obj2 := C.obj;
Books0.AppendFrame(to, obj2(Gadgets.Frame));
beg := to.len
END;
pos := F.pos;
Texts.FindObj(F, obj)
END;
Texts.Save(from, beg, from.len, B);
Texts.Append(to, B)
END CopyText;
(* definiton of the Panel extension *)
PROCEDURE *PanelHandler(F: Objects.Object; VAR M: Objects.ObjMsg);
VAR
obj: Objects.Object;
P, F0: Panel;
T, T0, Tn: TGFrame;
butH, x, y, h: INTEGER;
R: Display3.Mask;
tl, tl2: Books0.TextList;
PROCEDURE MoveButton(name: ARRAY OF CHAR; dX, dY, nH: INTEGER);
VAR msg: Display.ModifyMsg;
BEGIN
obj := Gadgets.FindObj(P, name);
IF obj # NIL THEN
msg.id := Display.move; msg.mode := Display.state;
msg.W := buttonW; msg.H := buttonH;
msg.dW := 0; msg.dH := 0;
msg.dX := 0; msg.dY := 0;
msg.x := 0; msg.y := 0;
msg.X := obj(BasicGadgets.Button).X+dX;
(*
msg.Y := obj(BasicGadgets.Button).Y-M(Display.ModifyMsg).dH+dY;
*)
WITH obj: BasicGadgets.Button DO
msg.Y := (obj.Y - (-F(Display.Frame).H + 1)) + dY + (-nH + 1)
END;
msg.F := obj(BasicGadgets.Button);
msg.res := -1; msg.dlink := P;
msg.stamp := M.stamp;
obj.handle(obj, msg)
END
END MoveButton;
BEGIN
WITH F: Panel 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 := "Books.NewPanel";
M.res := 0
ELSE Panels.PanelHandler(F, M)
END
ELSE Panels.PanelHandler(F, M)
END
END
ELSIF M IS Objects.CopyMsg THEN
WITH M: Objects.CopyMsg DO
IF M.stamp = F.stamp THEN
M.obj := F.dlink
ELSE
NEW(F0);
F.stamp := M.stamp; F.dlink := F0;
Panels.CopyPanel(M, F, F0);
F0.iconStr := F.iconStr;
F0.cur := NIL;
F0.texts := NIL;
tl := F.texts;
WHILE tl # NIL DO
NEW(tl2);
tl2.next := NIL;
tl2.prev := F0.cur;
IF F0.cur = NIL THEN
F0.texts := tl2
ELSE
F0.cur.next := tl2
END;
F0.cur := tl2;
tl2.text := NIL;
CopyText(tl.text, tl2.text);
tl := tl.next
END;
F0.cur := F0.texts;
F0.doc := NIL;
F0.cmds := F.cmds;
F0.notes := F.notes;
F0.useStack := NIL;
F0.imps := F.imps;
F0.options := F.options;
F0.curC := NIL;
F0.noteH := F.noteH;
GetText(F, T); GetText(F0, T0);
CopyText(T.text, T0.text);
T0.panel := F0;
GetNote(F, T); GetNote(F0, T0);
CopyText(T.text, T0.text);
T0.panel := F0;
M.obj := F0
END
END
ELSIF M IS Display.FrameMsg THEN
WITH M: Display.FrameMsg DO
IF (M.F = F) OR (M.F = NIL) THEN
IF M IS Display.ModifyMsg THEN
WITH M: Display.ModifyMsg DO
P := F;
GetText(P, T);
GetNote(P, Tn);
IF (T # NIL) & (Tn # NIL) THEN
IF (twoRow IN P.options) = (M.W < (8*buttonW-2)) THEN
MoveButton("prev", 0, 0, M.H);
MoveButton("next", 0, 0, M.H);
MoveButton("cont", 0, 0, M.H);
MoveButton("ind", 0, 0, M.H);
MoveButton("old", 0, 0, M.H);
MoveButton("hist", 0, 0, M.H);
MoveButton("down", 0, 0, M.H);
MoveButton("up", 0, 0, M.H)
ELSE
IF M.W < (8*buttonW-2) THEN
INCL(P.options, twoRow)
ELSE
EXCL(P.options, twoRow)
END;
IF twoRow IN P.options THEN
DEC(P.noteH, buttonH);
MoveButton("prev", 0, buttonH, M.H);
MoveButton("next", 0, buttonH, M.H);
MoveButton("cont", 0, buttonH, M.H);
MoveButton("ind", 0, buttonH, M.H);
MoveButton("old", -4*buttonW, 0, M.H);
MoveButton("hist", -4*buttonW, 0, M.H);
MoveButton("down", -4*buttonW, 0, M.H);
MoveButton("up", -4*buttonW, 0, M.H)
ELSE
INC(P.noteH, buttonH);
MoveButton("prev", 0, -buttonH, M.H);
MoveButton("next", 0, -buttonH, M.H);
MoveButton("cont", 0, -buttonH, M.H);
MoveButton("ind", 0, -buttonH, M.H);
MoveButton("old", 4*buttonW, 0, M.H);
MoveButton("hist", 4*buttonW, 0, M.H);
MoveButton("down", 4*buttonW, 0, M.H);
MoveButton("up", 4*buttonW, 0, M.H)
END
END;
IF twoRow IN P.options THEN
butH := 2*buttonH
ELSE
butH := buttonH
END;
WHILE ((M.H-borderB-butH-barH-P.noteH-barH-barH-borderT) < 3) & (P.noteH > 3) DO
DEC(P.noteH)
END;
IF P.noteH < 3 THEN
P.noteH := 3
END;
MoveBar(P, M, "bar2", (*M.Y*) -M.H + 1+borderB+butH-1, Display.state, FALSE);
ReDisplay(M, Display.state, FALSE);
MoveBar(P, M, "bar0", (*M.Y+M.H*)-barH + 1, Display.state, FALSE);
IF resize IN P.options THEN
ResizeControls(P, T, M.W-borderL-borderR-scrollBW);
TextGadgets0.FormatFrame(T);
ResizeControls(P, Tn, M.W-borderL-borderR-scrollBW);
TextGadgets0.FormatFrame(Tn)
END;
Panels.PanelHandler(F, M)
ELSE Panels.PanelHandler(F, M)
END
END
ELSIF M IS Display.DisplayMsg THEN
WITH M: Display.DisplayMsg DO
Panels.PanelHandler(F, M);
IF M.device = Display.screen THEN
x := M.x + F.X; y := M.y + F.Y; h := F.H;
Gadgets.MakeMask(F, x, y, M.dlink, R);
Display3.ReplConst(R, Display3.white, x, y, 1, h, Display.replace)
END
END
ELSE Panels.PanelHandler(F, M)
END
ELSE Panels.PanelHandler(F, M)
END
END
ELSE Panels.PanelHandler(F, M)
END
END
END PanelHandler;
PROCEDURE NewPanel*;
VAR
F: Panel;
C: Objects.CopyMsg;
BEGIN
NEW(F);
Panels.NewPanel();
C.id := Objects.deep;
Objects.Stamp(C);
Panels.CopyPanel(C, Objects.NewObj(Panels.Panel), F);
F.texts := NIL; F.cur := NIL; F.useStack := NIL;
F.imps := NIL; F.cmds := NIL; F.notes := NIL;
F.options := {}; F.doc := NIL; F.curC := NIL;
F.handle := PanelHandler; F.noteH := 75;
F.borderW := 0;
Objects.NewObj := F
END NewPanel;
(* definiton of the TextGadget extension *)
PROCEDURE ^ShowText*(P: Panel; t: Books0.TextList; pos: LONGINT);
(* quick search on the index page *)
PROCEDURE HandleKey(F: TGFrame; M: Oberon.InputMsg);
VAR
R: Texts.Reader;
ch: CHAR;
P: Panel;
BEGIN
IF M.ch <= " " THEN
RETURN
END;
IF F.org < 8 THEN
Texts.OpenReader(R, F.text, 8)
ELSE
Texts.OpenReader(R, F.text, F.org+1)
END;
Texts.Read(R, ch);
IF ~R.eot THEN
WHILE ~R.eot & (CAP(ch) # CAP(M.ch)) DO
WHILE ~R.eot & ~((R.lib IS Fonts.Font) & (ch = EOL)) DO
Texts.Read(R, ch)
END;
IF ~R.eot THEN
Texts.Read(R, ch)
END
END;
P := M.dlink(Panel);
IF ~R.eot THEN
ShowText(P, P.cur, Texts.Pos(R))
ELSE
ShowText(P, P.cur, 0)
END
END
END HandleKey;
PROCEDURE ^Push*(P: Panel);
PROCEDURE *TextHandler(F: Objects.Object; VAR M: Objects.ObjMsg);
VAR
F0: TGFrame;
name: ARRAY 64 OF CHAR;
obj: Objects.Object;
x, y: INTEGER;
BEGIN
WITH F: TGFrame DO
IF M IS Objects.CopyMsg THEN
WITH M: Objects.CopyMsg DO
IF M.stamp = F.stamp THEN
M.obj := F.dlink
ELSE
NEW(F0);
F.stamp := M.stamp; F.dlink := F0;
TextGadgets.CopyFrame(M, F, F0);
F0.focus := FALSE;
F0.lastPos := 0;
F0.panel := NIL;
M.obj := F0
END
END
ELSIF 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 := "Books.NewText";
M.res := 0
ELSE TextGadgets.FrameHandler(F, M)
END
ELSE TextGadgets.FrameHandler(F, M)
END
END
ELSIF M IS Display.FrameMsg THEN
WITH M: Display.FrameMsg DO
IF (M.F = NIL) OR (M.F = F) THEN
IF M IS Oberon.InputMsg THEN
WITH M: Oberon.InputMsg DO
IF (M.id = Oberon.track) & Gadgets.InActiveArea(F, M) THEN
Gadgets.GetObjName(F, name);
x := M.x+F.X; y := M.y+F.Y;
IF (name = "Text") & (M.dlink(Panel).cur.next = NIL) & ~Effects.Inside(M.X, M.Y, x, y, F.left, F.H) THEN
IF ~F.focus & (M.keys = {2}) THEN
Oberon.Defocus();
F.focus := TRUE;
obj := Gadgets.FindObj(M.dlink, "bar0");
IF (obj # NIL) & (obj IS Books0.Bar) THEN
Books0.ColorBar(obj(Books0.Bar), Display3.red)
END
ELSE TextGadgets.FrameHandler(F, M)
END;
M.res := 0
ELSE TextGadgets.FrameHandler(F, M)
END
ELSIF F.focus & (M.id = Oberon.consume) THEN
HandleKey(F, M)
ELSE TextGadgets.FrameHandler(F, M);
END
END
ELSIF M IS Oberon.ControlMsg THEN
WITH M: Oberon.ControlMsg DO
IF M.id IN {Oberon.defocus, Oberon.neutralize} THEN
IF F.focus THEN
F.focus := FALSE;
obj := Gadgets.FindObj(M.dlink, "bar0");
IF (obj # NIL) & (obj IS Books0.Bar) THEN
Books0.ColorBar(obj(Books0.Bar), Display3.black)
END
END
END;
TextGadgets.FrameHandler(F, M)
END
ELSE TextGadgets.FrameHandler(F, M)
END
ELSE TextGadgets.FrameHandler(F, M)
END
END
ELSE TextGadgets.FrameHandler(F, M)
END
END
END TextHandler;
PROCEDURE NewText*(P: Panel);
VAR
obj: TextGadgets.Frame;
T: TGFrame;
C: Objects.CopyMsg;
BEGIN
TextGadgets.New();
obj := Objects.NewObj(TextGadgets.Frame);
EXCL(obj.state0, TextGadgets0.mayfocus);
EXCL(obj.state0, TextGadgets0.mayconsume);
EXCL(obj.state0, TextGadgets0.maymvchildren);
INCL(obj.state0, TextGadgets0.deepcopy);
INCL(obj.state0, TextGadgets0.locked);
INCL(obj.control, TextGadgets.nocontrol);
(* !! *)
INCL(obj.state, Gadgets.lockedcontents);
obj.do := m;
NEW(T);
C.id := Objects.deep; Objects.Stamp(C);
TextGadgets.CopyFrame(C, obj, T);
T.focus := FALSE;
T.lastPos := 0;
T.panel := P;
T.handle := TextHandler;
Objects.NewObj := T
END NewText;
(* try to retrieve a Panel in the current context *)
PROCEDURE GetPanel*(VAR P: Panel);
VAR
S: Texts.Scanner;
doc: Documents.Document;
obj: Objects.Object;
PROCEDURE SearchPanel(VAR obj: Objects.Object);
BEGIN
WHILE (obj # NIL) & ~(obj IS Panel) DO
obj := obj.dlink
END
END SearchPanel;
BEGIN
P := NIL;
Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos);
Texts.Scan(S);
IF (S.class = Texts.Char) & (S.c = "*") THEN
doc := Documents.MarkedDoc();
IF (doc # NIL) & (doc.dsc # NIL) & (doc.dsc IS Panel) THEN
P := doc.dsc(Panel);
RETURN
END
END;
IF (Gadgets.context # NIL) & (Gadgets.context IS Panel) THEN
P := Gadgets.context(Panel)
ELSIF Gadgets.context # NIL THEN
obj := Gadgets.context;
SearchPanel(obj);
IF obj # NIL THEN
P := obj(Panel)
END
END;
IF P = NIL THEN
IF (Oberon.Par # NIL) & (Oberon.Par.obj # NIL) & (Oberon.Par.obj IS TGFrame) THEN
P := Oberon.Par.obj(TGFrame).panel
ELSIF Documents.MarkedDoc() # NIL THEN
doc := Documents.MarkedDoc();
IF (doc # NIL) & (doc.dsc # NIL) & (doc.dsc IS Panel) THEN
P := doc.dsc(Panel)
END
ELSIF Desktops.CurDoc(Gadgets.context) # NIL THEN
doc := Desktops.CurDoc(Gadgets.context);
IF (doc # NIL) & (doc.dsc # NIL) & (doc.dsc IS Panel) THEN
P := doc.dsc(Panel)
END
END
END
END GetPanel;
(* show this tutorial (P) on page t at position pos *)
PROCEDURE ShowText*(P: Panel; t: Books0.TextList; pos: LONGINT);
VAR
T: TGFrame;
Fi: Texts.Finder;
obj: Objects.Object;
lCont: Books0.ContElem;
fPos, cPos: LONGINT;
C: Oberon.ControlMsg;
THETEXT: Texts.Text;
BEGIN
GetText(P, T);
IF T # NIL THEN
IF T.focus & (t.next # NIL) THEN
C.F := T;
C.id := Oberon.defocus;
C.dlink := P;
C.res := -1;
Objects.Stamp(C);
T.handle(T, C)
END;
IF (P.cur # t) OR (t.prev = NIL) THEN
T.org := 0;
THETEXT := T.text; NEW(T.text); Texts.Open(T.text, "");
Texts.Delete(THETEXT, 0, THETEXT.len);
IF t.prev = NIL THEN
(* special handling for contents page reqired*)
lCont := NIL;
Texts.OpenFinder(Fi, t.text, 0);
fPos := Fi.pos; cPos := -1;
Texts.FindObj(Fi, obj);
WHILE ~Fi.eot & (cPos < pos) DO
IF (obj IS Books0.ContElem) & (obj(Books0.ContElem).mode = Books0.node) THEN
cPos := fPos;
lCont := obj(Books0.ContElem)
END;
fPos := Fi.pos;
Texts.FindObj(Fi, obj)
END;
Texts.OpenFinder(Fi, t.text, cPos+1);
fPos := Fi.pos;
Texts.FindObj(Fi, obj);
IF (obj # NIL) & (obj IS Books0.Frame) THEN
Texts.Save(t.text, cPos+1, fPos+1, B);
Texts.Append(THETEXT, B);
Texts.WriteLn(Wr);
Texts.Append(THETEXT, Wr.buf)
ELSE
Texts.Save(t.text, cPos+1, fPos, B);
Texts.Append(THETEXT, B)
END;
Texts.Save(t.text, lCont.beg, lCont.end, B);
Texts.Append(THETEXT, B);
P.curC := lCont;
pos := 0
ELSE
Texts.Save(t.text, 0, t.text.len, B);
Texts.Append(THETEXT, B)
END;
T.text := THETEXT; T.trailer := NIL;
T.lastPos := 0;
P.cur := t;
IF T.trailer = NIL THEN
T.org := pos; T.car := FALSE; T.sel := FALSE; Gadgets.Update(T);
ELSE
TextGadgets0.ScrollTo(T, TextGadgets0.LinesUp(T.text, pos, 0))
END
ELSE
(*
IF pos < T.org THEN
TextGadgets0.Locate(T, pos);
TextGadgets0.RemoveCaret(T)
END;
*)
TextGadgets0.ScrollTo(T, TextGadgets0.LinesUp(T.text, pos, 0))
END
END
END ShowText;
(* get position of obj in t *)
PROCEDURE GetPos(t: Texts.Text; obj: Objects.Object): LONGINT;
VAR
Fi: Texts.Finder;
obj2: Objects.Object;
pos: LONGINT;
BEGIN
Texts.OpenFinder(Fi, t, 0);
pos := Fi.pos;
Texts.FindObj(Fi, obj2);
WHILE ~Fi.eot & (obj # obj2) DO
pos := Fi.pos;
Texts.FindObj(Fi, obj2)
END;
IF obj = obj2 THEN
RETURN pos
ELSE
RETURN 0
END
END GetPos;
(* save current state of P *)
PROCEDURE Push*(P: Panel);
VAR
c: Chain;
T: TGFrame;
PROCEDURE OnTop(pos: LONGINT): BOOLEAN;
BEGIN
RETURN (P.useStack # NIL) & (P.useStack.old = P.cur) & (P.useStack.pos = pos)
END OnTop;
BEGIN
GetText(P, T);
IF T # NIL THEN
IF P.cur = NIL THEN RETURN END;
IF (P.cur.prev = NIL) & ~OnTop(GetPos(P.cur.text, P.curC)) THEN
NEW(c);
c.old := P.cur;
IF P.curC # NIL THEN
c.pos := GetPos(P.cur.text, P.curC)
ELSE
c.pos := 0
END;
c.next := P.useStack;
P.useStack := c
ELSIF ~OnTop(T.org) THEN
NEW(c);
c.old := P.cur;
c.pos := T.org;
c.next := P.useStack;
P.useStack := c
END
END
END Push;
(* retrieve page-number of cur in P *)
PROCEDURE GetInd*(P: Panel; cur: Books0.TextList): LONGINT;
VAR
t: Books0.TextList;
ind: LONGINT;
BEGIN
ind := 0;
t := P.texts;
WHILE (t # NIL) & (t # cur) DO
INC(ind);
t := t.next
END;
RETURN ind
END GetInd;
(* go to the next/previous subchapter of the current tutorial *)
PROCEDURE ChapUp*;
VAR
P: Panel;
T: TGFrame;
Fi: Texts.Finder;
obj: Objects.Object;
pos, Ind, Pos: LONGINT;
BEGIN
GetPanel(P);
GetText(P, T);
IF T # NIL THEN
Ind := GetInd(P, P.cur);
Pos := T.org;
pos := MAX(LONGINT);
Texts.OpenFinder(Fi, P.texts.text, 0);
Texts.FindObj(Fi, obj);
WHILE ~Fi.eot DO
IF (obj # NIL) & (obj IS Books0.LocFrame) THEN
WITH obj: Books0.LocFrame DO
IF (obj.pos1 = Ind) & (obj.pos2 > Pos) & ((obj.pos2-Pos) < (pos-Pos)) THEN
pos := obj.pos2
END
END
END;
Texts.FindObj(Fi, obj)
END;
IF pos < MAX(LONGINT) THEN
Push(P);
ShowText(P, P.cur, pos)
ELSIF P.cur.next # NIL THEN
Push(P);
ShowText(P, P.cur.next, 0)
END
END
END ChapUp;
PROCEDURE ChapDown*;
VAR
P: Panel;
T: TGFrame;
Fi: Texts.Finder;
obj: Objects.Object;
pos, Ind, Pos: LONGINT;
BEGIN
GetPanel(P);
GetText(P, T);
IF T # NIL THEN
Ind := GetInd(P, P.cur);
Pos := T.org;
pos := -1;
Texts.OpenFinder(Fi, P.texts.text, 0);
Texts.FindObj(Fi, obj);
WHILE ~Fi.eot DO
IF (obj # NIL) & (obj IS Books0.LocFrame) THEN
WITH obj: Books0.LocFrame DO
IF (obj.pos1 = Ind) & (obj.pos2 < Pos) & ((Pos-obj.pos2) < (Pos-pos)) THEN
pos := obj.pos2
END
END
END;
Texts.FindObj(Fi, obj)
END;
IF pos >= 0 THEN
Push(P);
ShowText(P, P.cur, pos)
ELSIF P.cur.prev # NIL THEN
Push(P);
ShowText(P, P.cur.prev, 0)
END
END
END ChapDown;
(* save the usage-stack of P to a text (t) *)
PROCEDURE History*(P: Panel; t: Texts.Text);
VAR
cl: Chain;
R: Texts.Reader;
Fi: Texts.Finder;
ch: CHAR;
locF: Books0.LocFrame;
obj: Objects.Object;
pos, Pos, Ind: LONGINT;
BEGIN
cl := P.useStack;
WHILE cl # NIL DO
Books0.NewLoc();
locF := Objects.NewObj(Books0.LocFrame);
locF.mode := link;
locF.pos1 := GetInd(P, cl.old);
locF.pos2 := cl.pos;
Books0.InsertFrame(t, 0, locF);
IF cl.old.prev # NIL THEN
Texts.OpenReader(R, P.texts.text, 0);
Ind := GetInd(P, cl.old);
Pos := cl.pos;
pos := -1;
Texts.Read(R, ch);
WHILE ~R.eot DO
IF ~(R.lib IS Fonts.Font) THEN
Texts.OpenFinder(Fi, P.texts.text, Texts.Pos(R)-1);
Texts.FindObj(Fi, obj);
IF (obj # NIL) & (obj IS Books0.LocFrame) THEN
WITH obj: Books0.LocFrame DO
IF (obj.pos1 = Ind) & (obj.pos2 <= Pos) & ((Pos-obj.pos2) < (Pos-pos)) THEN
pos := obj.pos2
END
END
END
END;
Texts.Read(R, ch)
END;
Texts.OpenReader(R, cl.old.text, pos);
Texts.Read(R, ch);
WHILE ~R.eot & ~((R.lib IS Fonts.Font) & (ch = EOL)) DO
Texts.Read(R, ch)
END;
Texts.Save(cl.old.text, pos, Texts.Pos(R), B)
ELSE
Texts.OpenReader(R, cl.old.text, cl.pos);
Texts.Read(R, ch);
WHILE ~R.eot & ~((R.lib IS Fonts.Font) & (ch = EOL)) DO
Texts.Read(R, ch)
END;
Texts.Save(cl.old.text, cl.pos, Texts.Pos(R), B)
END;
Texts.Insert(t, 0, B);
cl := cl.next
END
END History;
(* go one step deeper in the contents-tree *)
PROCEDURE *OpenCont(F: Books0.ContElem);
VAR P: Panel;
BEGIN
IF (F.dlink # NIL) & (F.dlink IS TGFrame) THEN
P := F.dlink(TGFrame).panel;
Push(P);
ShowText(P, P.texts, GetPos(P.texts.text, F))
END
END OpenCont;
(* get the position of the line-end of the line containing pos *)
PROCEDURE EndOfLine(T: TGFrame; pos: LONGINT): LONGINT;
VAR
beg: LONGINT;
line: TextGadgets0.Line;
BEGIN
IF T.trailer = NIL THEN
RETURN pos
END;
beg := T.org;
line := T.trailer.next;
WHILE (line.next # T.trailer) & (beg <= pos) DO
INC(beg, line.len);
line := line.next
END;
IF beg > pos THEN
RETURN beg-1
ELSE
RETURN T.text.len
END
END EndOfLine;
(* show this tutorial (P) on page ind at position pos *)
PROCEDURE GotoText*(P: Panel; ind, pos: LONGINT; sel: BOOLEAN);
VAR
t: Books0.TextList;
i: INTEGER;
T: TGFrame;
BEGIN
i := 0;
t := P.texts;
WHILE (t # NIL) & (i < ind) DO
t := t.next;
INC(i)
END;
IF (t # NIL) & (i = ind) THEN
Push(P);
ShowText(P, t, pos);
IF sel THEN
GetText(P, T);
TextGadgets0.SetSelection(T, pos, EndOfLine(T, pos))
END
END
END GotoText;
(* get the index page of P *)
PROCEDURE GetIndex*(P: Panel): Books0.TextList;
VAR t: Books0.TextList;
BEGIN