forked from rochus-keller/OberonSystem3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BookDocs.Mod
2305 lines (2206 loc) · 60 KB
/
BookDocs.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 BookDocs; (** portable *)
IMPORT BooksHelp, Books, Books0, Oberon, Files, Texts, Fonts, Display, Display3, Objects, BasicGadgets, TextFields, Gadgets,
TextGadgets, TextGadgets0, TextDocs, Panels, Strings, Desktops, Documents, Printer, Effects;
CONST
(* size of document *)
W* = 8*Books.buttonW-2; H* = 400;
(* menu of document *)
Menu = "BookDocs.Search[Search] Desktops.StoreDoc[Store]";
(* default icon *)
defaultIcon = "Icons.Note";
(* constants for printing *)
all = 0; cont = 1;
(* constants for searching *)
text = 0; color = 1; object = 2;
MaxPatLen = 128;
(* prepare print id for Display.DisplayMsg, to be replaced by Display.prepare *)
(* see also the PrintDoc command *)
prepare = Display.contents+1;
TYPE
FrameList = POINTER TO FrameListDesc;
DocList = POINTER TO DocListDesc;
(* list of Books0.Frame for printing *)
FrameListDesc = RECORD
frame: Books0.Frame;
page, pos: LONGINT;
next: FrameList
END;
(* list of documents for deepsearch *)
DocListDesc = RECORD
doc: Documents.Document;
cur: Books0.TextList;
pos: LONGINT;
next: DocList
END;
(* is the tutorial F still visible *)
VisibleMsg = RECORD (Display.FrameMsg)
visible: BOOLEAN
END;
(* does a (valid) tutorial "name" exist *)
ExistMsg = RECORD (Display.FrameMsg)
name: ARRAY 64 OF CHAR
END;
(* does a (valid) import-list for the tutorial "name" exist *)
ExistImpMsg = RECORD (Display.FrameMsg)
name: ARRAY 64 OF CHAR;
il: Books0.ImpList
END;
(* all opened tutorials "name" are invalid *)
InValMsg* = RECORD (Display.FrameMsg)
name*: ARRAY 64 OF CHAR
END;
VAR
Wr: Texts.Writer;
B: Texts.Buffer;
tmpT: Texts.Text;
(* printer coordinates (here for A4) *)
printerTop, printerRight, printerWMiddle, printerPageW, printerTab: INTEGER;
(* default fonts *)
titleFont*, textFont*, noteFont*, linkFont*, callFont*: Fonts.Font;
sectionFonts*: ARRAY Books.maxSect OF Fonts.Font;
(* list of Books0.Frame to print *)
printFrames, index: FrameList;
(* variables used for printing *)
Tcont, T, Tindex, Tnotes: TextGadgets.Frame;
pageNr, maxWi, maxWc: LONGINT;
oldW: INTEGER;
prMode: SET;
(* global variables for searching *)
sPat: ARRAY MaxPatLen OF CHAR;
sDv: ARRAY MaxPatLen + 1 OF INTEGER;
sPatLen: INTEGER;
lTime: LONGINT;
lastDoc: Documents.Document;
lastDeep, docList: DocList;
(* initialize DefaultFonts *)
PROCEDURE GetFonts();
VAR i: INTEGER;
PROCEDURE Font(name: ARRAY OF CHAR): Fonts.Font;
VAR fnt: Fonts.Font;
BEGIN
fnt := Fonts.This(name);
IF fnt = NIL THEN
fnt := Fonts.Default
END;
RETURN fnt
END Font;
BEGIN
titleFont := Font("Default20b.Scn.Fnt");
sectionFonts[0] := Font("Default16b.Scn.Fnt");
sectionFonts[1] := Font("Default14b.Scn.Fnt");
sectionFonts[2] := Font("Default12b.Scn.Fnt");
i := 3;
WHILE i < Books.maxSect DO
sectionFonts[i] := Font("Default12i.Scn.Fnt");
INC(i)
END;
textFont := Font("Default12.Scn.Fnt");
linkFont := textFont;
callFont := textFont;
noteFont := textFont
END GetFonts;
(* load/store of tutorial-documents *)
(* create a new BasicGadgets.Button *)
PROCEDURE Button(X, Y: INTEGER; cmdStr, caption, name: ARRAY OF CHAR): Objects.Object;
VAR
obj: Objects.Object;
A: Objects.AttrMsg;
BEGIN
BasicGadgets.NewButton();
obj := Objects.NewObj;
WITH obj: BasicGadgets.Button DO
Gadgets.NameObj(obj, name);
obj.X := X; obj.Y := Y;
obj.W := Books.buttonW; obj.H := Books.buttonH;
obj.caption := caption;
obj.popout := TRUE;
obj.val := FALSE;
A.id := Objects.set;
A.name := "Cmd";
A.s := cmdStr;
A.class := Objects.String;
A.res := -1;
obj.handle(obj, A);
obj.slink := NIL
END;
RETURN obj
END Button;
(* create the Button-Bar used by tutorials *)
PROCEDURE MakeButtonBar(twoRow: BOOLEAN): Objects.Object;
VAR obj, old: Objects.Object;
BEGIN
obj := Button(0*Books.buttonW, -Books.buttonH, "BookDocs.Prev", "Prev", "prev");
BooksHelp.SetTutorial(obj, "Tutorials.Book Prev");
old := obj;
obj := Button(1*Books.buttonW, -Books.buttonH, "BookDocs.Next", "Next", "next");
BooksHelp.SetTutorial(obj, "Tutorials.Book Next");
obj.slink := old; old := obj;
obj := Button(2*Books.buttonW, -Books.buttonH, "BookDocs.Contents", "Contents", "cont");
BooksHelp.SetTutorial(obj, "Tutorials.Book ContentsB");
obj.slink := old; old := obj;
obj := Button(3*Books.buttonW, -Books.buttonH, "BookDocs.Index", "Index", "ind");
BooksHelp.SetTutorial(obj, "Tutorials.Book IndexB");
obj.slink := old; old := obj;
IF twoRow THEN
obj := Button(0*Books.buttonW, -2*Books.buttonH, "BookDocs.Pop", "Back", "old");
BooksHelp.SetTutorial(obj, "Tutorials.Book Back");
obj.slink := old; old := obj;
obj := Button(1*Books.buttonW, -2*Books.buttonH, "BookDocs.History", "History", "hist");
BooksHelp.SetTutorial(obj, "Tutorials.Book History");
obj.slink := old; old := obj;
obj := Button(2*Books.buttonW, -2*Books.buttonH, "Books.ChapDown", "Down", "down");
BooksHelp.SetTutorial(obj, "Tutorials.Book Down");
obj.slink := old; old := obj;
obj := Button(3*Books.buttonW, -2*Books.buttonH, "Books.ChapUp", "Up", "up");
BooksHelp.SetTutorial(obj, "Tutorials.Book Up")
ELSE
obj := Button(4*Books.buttonW, -Books.buttonH, "BookDocs.Pop", "Back", "old");
BooksHelp.SetTutorial(obj, "Tutorials.Book Back");
obj.slink := old; old := obj;
obj := Button(5*Books.buttonW, -Books.buttonH, "BookDocs.History", "History", "hist");
BooksHelp.SetTutorial(obj, "Tutorials.Book History");
obj.slink := old; old := obj;
obj := Button(6*Books.buttonW, -Books.buttonH, "Books.ChapDown", "Down", "down");
BooksHelp.SetTutorial(obj, "Tutorials.Book Down");
obj.slink := old; old := obj;
obj := Button(7*Books.buttonW, -Books.buttonH, "Books.ChapUp", "Up", "up");
BooksHelp.SetTutorial(obj, "Tutorials.Book Up")
END;
obj.slink := old;
RETURN obj
END MakeButtonBar;
(* create the main-text *)
PROCEDURE MakeText(P: Books.Panel; h: INTEGER): Objects.Object;
VAR obj: Objects.Object;
BEGIN
Books.NewText(P);
obj := Objects.NewObj;
WITH obj: TextGadgets.Frame DO
Gadgets.NameObj(obj, "Text");
obj.X := 0; obj.Y := 0;
obj.W := P.W-Books.borderL-Books.borderR+1;
obj.H := h;
obj.slink := NIL
END;
BooksHelp.SetTutorial(obj, "Tutorials.Book textC");
RETURN obj
END MakeText;
(* create the footnotes-text *)
PROCEDURE MakeNote(P: Books.Panel; h: INTEGER): Objects.Object;
VAR obj: Objects.Object;
BEGIN
Books.NewText(P);
obj := Objects.NewObj;
WITH obj: TextGadgets.Frame DO
Gadgets.NameObj(obj, "Note");
obj.X := 0; obj.Y := 0;
obj.W := P.W-Books.borderL-Books.borderR+1;
obj.H := h;
obj.slink := NIL
END;
BooksHelp.SetTutorial(obj, "Tutorials.Book NotesText");
RETURN obj
END MakeNote;
(* mouse-tracking to change the text-heigths *)
PROCEDURE TrackBarMouse(F: Books0.Bar; M: Oberon.InputMsg);
VAR
P: Books.Panel;
R: Display3.Mask;
x1, w, y1, y2, lastY: INTEGER;
msg: Display.ModifyMsg;
BEGIN
IF (M.dlink # NIL) & (M.dlink IS Books.Panel) THEN
Books0.ColorBar(F, Display3.red);
P := M.dlink(Books.Panel);
Gadgets.MakeMask(P, M.x, M.y(*+P.Y*) - P.H, P.dlink, R);
x1 := M.x+Books.borderL-1;
w := P.W-Books.borderL-Books.borderR;
IF Books.twoRow IN P.options THEN
y1 := M.y(*+P.Y*) - P.H+Books.borderB+2*Books.buttonH+Books.barH+5
ELSE
y1 := M.y(*+P.Y*) - P.H+Books.borderB+Books.buttonH+Books.barH+5
END;
y2 := M.y(*+P.Y*)- P.H +P.H-Books.borderT-Books.barH-10;
Oberon.FadeCursor(Oberon.Mouse);
Display3.ReplConst(R, Display3.invertC, x1, M.Y, w, 1, Display3.invert);
Display3.ReplConst(R, Display3.invertC, x1, M.Y+Books.barH, w, 1, Display3.invert);
lastY := M.Y;
REPEAT
Effects.TrackMouse(M.keys, M.X, M.Y, Effects.PointHand);
IF (lastY # M.Y) & (M.Y > y1) & (M.Y < y2) THEN
Oberon.FadeCursor(Oberon.Mouse);
Display3.ReplConst(R, Display3.invertC, x1, lastY, w, 1, Display3.invert);
Display3.ReplConst(R, Display3.invertC, x1, lastY+Books.barH, w, 1, Display3.invert);
Display3.ReplConst(R, Display3.invertC, x1, M.Y, w, 1, Display3.invert);
Display3.ReplConst(R, Display3.invertC, x1, M.Y+Books.barH, w, 1, Display3.invert);
lastY := M.Y
END
UNTIL M.keys = {};
Oberon.FadeCursor(Oberon.Mouse);
Display3.ReplConst(R, Display3.invertC, x1, lastY, w, 1, Display3.invert);
Display3.ReplConst(R, Display3.invertC, x1, lastY+Books.barH, w, 1, Display3.invert);
P.noteH := lastY-y1+ Books.barH + Books.barH DIV 2;
Books0.ColorBar(F, Display3.black);
msg.id := Display.restore;
msg.dX := 0; msg.dY := 0;
msg.W := P.W; msg.H := P.H;
msg.dW := 0; msg.dH := 0;
msg.X := P.X; msg.Y := P.Y;
msg.F := P;
msg.res := -1;
msg.x := 0; msg.y := 0;
msg.dlink := M.dlink;
Books.ReDisplay(msg, Display.display, TRUE)
END
END TrackBarMouse;
PROCEDURE *BarHandler(F: Objects.Object; VAR M: Objects.ObjMsg);
BEGIN
WITH F: Books0.Bar DO
IF M IS Oberon.InputMsg THEN
WITH M: Oberon.InputMsg DO
IF ((M.F = NIL) OR (M.F = F)) & (M.id = Oberon.track) & (M.keys # {}) THEN
TrackBarMouse(F, M);
M.res := 0
ELSE Books0.BarFrameHandler(F, M)
END
END
ELSE Books0.BarFrameHandler(F, M)
END
END
END BarHandler;
(* create a new Books0.Bar *)
PROCEDURE Bar(P: Books.Panel; Y, H: INTEGER; name: ARRAY OF CHAR): Objects.Object;
VAR obj: Objects.Object;
BEGIN
Books0.NewBar();
obj := Objects.NewObj;
WITH obj: Books0.Bar DO
Gadgets.NameObj(obj, name);
obj.X := 0; obj.Y := Y;
obj.W := P.W-Books.borderL-Books.borderR;
obj.H := H;
obj.slink := NIL
END;
RETURN obj
END Bar;
(* the black bars used by tutorials *)
PROCEDURE MakeBars(P: Books.Panel; hT: INTEGER): Objects.Object;
VAR obj, old: Objects.Object;
BEGIN
obj := Bar(P, Books.barH+P.noteH+Books.barH+hT, Books.barH, "bar0");
old := obj;
obj := Bar(P, Books.barH+P.noteH, Books.barH, "bar1");
BooksHelp.SetTutorial(obj, "Tutorials.Book MoveBar");
obj.handle := BarHandler;
obj.slink := old; old := obj;
obj := Bar(P, 0, Books.barH, "bar2");
obj.slink := old;
RETURN obj
END MakeBars;
(* drop all Gadgets on the doc.dsc-panel *)
PROCEDURE BuildInterface(P: Books.Panel);
VAR
C: Display.ConsumeMsg;
hT, hN, buttonH: INTEGER;
BEGIN
BooksHelp.SetTutorial(P, "Tutorials.Book Open");
IF P.W < (8*Books.buttonW-2) THEN
INCL(P.options, Books.twoRow)
ELSE
EXCL(P.options, Books.twoRow)
END;
IF Books.twoRow IN P.options THEN
buttonH := 2*Books.buttonH
ELSE
buttonH := Books.buttonH
END;
C.F := P;
C.id := Display.drop;
C.x := 0; C.y := 0;
C.dlink := NIL;
hT := P.H-Books.borderB-buttonH-Books.barH-P.noteH-Books.barH-Books.barH+1;
hN := P.noteH;
C.obj := MakeText(P, hT);
C.u := Books.borderL-1;
C.v := -P.H+Books.borderB+buttonH+Books.barH+hN+Books.barH;
C.res := -1;
P.handle(P, C);
C.obj := MakeNote(P, hN);
C.u := Books.borderL-1;
C.v := -P.H+Books.borderB+buttonH+Books.barH;
C.res := -1;
P.handle(P, C);
C.obj := MakeButtonBar(Books.twoRow IN P.options);
C.u := Books.borderL-2;
C.v := -P.H+Books.borderB;
C.res := -1;
P.handle(P, C);
C.obj := MakeBars(P, hT);
C.u := Books.borderL;
C.v := -P.H+Books.borderB+Books.buttonH;
C.res := -1;
P.handle(P, C);
P.state := P.state + {Gadgets.lockedcontents, Gadgets.lockedsize};
P.state0 := P.state0 + {Panels.noselect, Panels.noinsert, Panels.frozen};
(*!!
Panels.Freeze(P, TRUE);
*)
IF Books.resize IN P.options THEN
EXCL(P.state, Gadgets.lockedsize)
ELSE
INCL(P.state, Gadgets.lockedsize)
END;
Gadgets.Update(P);
Books.GotoText(P, Books.newInd, Books.newPos, FALSE)
END BuildInterface;
(* write a tutorial-document-file-header *)
PROCEDURE WriteHeader*(VAR R: Files.Rider; x, y, w, h: INTEGER; ind, pos: LONGINT; options: SET; iconStr: ARRAY OF CHAR);
BEGIN
Files.WriteInt(R, Documents.Id);
Files.WriteString(R, "BookDocs.NewDoc");
Files.WriteInt(R, x); Files.WriteInt(R, y);
Files.WriteInt(R, w); Files.WriteInt(R, h);
Files.WriteLInt(R, ind); Files.WriteLInt(R, pos);
Files.WriteSet(R, options);
IF Books.icon IN options THEN
Files.WriteString(R, iconStr)
ELSE
Files.WriteString(R, defaultIcon)
END
END WriteHeader;
PROCEDURE WriteHeaderP(VAR R: Files.Rider; P: Books.Panel);
VAR
T: Books.TGFrame;
D: Documents.Document;
BEGIN
D := P.doc;
Books.GetText(P, T);
WriteHeader(R, D.X, D.Y, D.W, D.H, Books.GetInd(P, P.cur), T.org, P.options, P.iconStr)
END WriteHeaderP;
(* skip over a tutorial-document-file-header *)
PROCEDURE SkipHeader*(VAR R: Files.Rider): BOOLEAN;
VAR
i: INTEGER;
li: LONGINT;
name: ARRAY 2*Books0.nameLen OF CHAR;
s: SET;
BEGIN
Files.ReadInt(R, i);
IF i # Documents.Id THEN
RETURN FALSE
END;
Files.ReadString(R, name);
IF name # "BookDocs.NewDoc" THEN
RETURN FALSE
END;
Files.ReadInt(R, i); Files.ReadInt(R, i);
Files.ReadInt(R, i); Files.ReadInt(R, i);
Files.ReadLInt(R, li); Files.ReadLInt(R, li);
Files.ReadSet(R, s);
Files.ReadString(R, name);
RETURN TRUE
END SkipHeader;
(* create an import list for il.name *)
PROCEDURE Import*(il: Books0.ImpList; new: BOOLEAN): BOOLEAN;
VAR
F: Files.File;
R: Files.Rider;
fix1, fix2, pos, len: LONGINT;
mode: SHORTINT;
el: Books0.ExtLabel;
E: ExistImpMsg;
BEGIN
IF ~new THEN
E.F := NIL;
E.name := il.name;
E.il := NIL;
E.res := -1;
Display.Broadcast(E);
IF E.il # NIL THEN
il.extLabels := E.il.extLabels;
Books.CopyText(E.il.notes, il.notes);
RETURN TRUE
END
END;
F := Files.Old(il.name);
IF F = NIL THEN
RETURN FALSE
END;
Files.Set(R, F, 0);
IF ~SkipHeader(R) THEN
RETURN FALSE
END;
Files.ReadLInt(R, fix1);
Files.ReadLInt(R, fix2);
Files.ReadLInt(R, len);
Files.Set(R, F, fix1);
Files.Read(R, mode);
WHILE mode > Books0.none DO
NEW(el);
el.frame := NIL;
el.mode := mode;
el.book := il;
Files.ReadLInt(R, el.pos1);
Files.ReadLInt(R, el.pos2);
Files.ReadString(R, el.name);
el.next := il.extLabels;
il.extLabels := el;
Files.Read(R, mode)
END;
NEW(il.notes); Texts.Open(il.notes, "");
Files.Set(R, F, fix2);
Files.ReadLInt(R, len);
IF len > 0 THEN
pos := Files.Pos(R)+1;
Texts.Load(il.notes, F, pos, len)
END;
RETURN TRUE
END Import;
(* look for an additional argument to Desktops.OpenDoc *)
PROCEDURE GetOpenLabel(VAR open: ARRAY OF CHAR);
VAR S: Texts.Scanner;
BEGIN
Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos);
Texts.Scan(S);
Texts.Scan(S);
IF S.class = Texts.Name THEN
open := S.s
ELSE
open := ""
END
END GetOpenLabel;
(* get values for label open *)
PROCEDURE GetLInts(D: Documents.Document; open: ARRAY OF CHAR);
VAR
il: Books0.ImpList;
el: Books0.ExtLabel;
BEGIN
IF open # "" THEN
NEW(il);
il.next := NIL;
il.extLabels := NIL;
il.name := D.name;
IF ~Import(il, FALSE) THEN
HALT(99)
END;
el := il.extLabels;
WHILE (el # NIL) & (el.name # open) DO
el := el.next
END;
IF (el # NIL) & (el.mode = Books.link) THEN
Books.newInd := el.pos1;
Books.newPos := el.pos2
END
END
END GetLInts;
(* load the document: D.name; TRUE: success; FALSE: error *)
PROCEDURE LoadDoc(D: Documents.Document): BOOLEAN;
VAR
P: Books.Panel;
tag, x, y, w, h: INTEGER;
F: Files.File;
R: Files.Rider;
name: ARRAY 2*Books0.nameLen OF CHAR;
open: ARRAY Books0.identLen OF CHAR;
len, ind, pos: LONGINT;
t: Books0.TextList;
il, oldL: Books0.ImpList;
T: Books.TGFrame;
BEGIN
oldL := Books0.loading;
GetOpenLabel(open);
Books0.error := FALSE;
Books.NewPanel();
P := Objects.NewObj(Books.Panel);
P.doc := D;
F := Files.Old(D.name);
IF F = NIL THEN RETURN FALSE END;
Files.Set(R, F, 0);
Files.ReadInt(R, tag);
IF tag = Documents.Id THEN
Files.ReadString(R, name);
Files.ReadInt(R, x); Files.ReadInt(R, y);
Files.ReadInt(R, w); Files.ReadInt(R, h)
ELSE
RETURN FALSE
END;
IF (Books.newInd < 0) OR (Books.newPos < 0) THEN
Files.ReadLInt(R, Books.newInd); Files.ReadLInt(R, Books.newPos)
ELSE
Files.ReadLInt(R, len); Files.ReadLInt(R, len)
END;
Files.ReadSet(R, P.options);
Files.ReadString(R, P.iconStr);
IF Gadgets.FindPublicObj(P.iconStr) = NIL THEN
P.iconStr := defaultIcon
END;
Files.ReadLInt(R, len);
Files.ReadLInt(R, len);
Files.ReadLInt(R, len);
P.X := x; P.Y := y; P.W := w; P.H := h;
ind := 0;
Files.ReadString(R, name);
WHILE name # "" DO
NEW(il);
il.next := P.imps;
P.imps := il;
il.extLabels := NIL;
il.ind := ind;
INC(ind);
il.name := name;
IF ~Import(il, FALSE) THEN
Texts.WriteString(Wr, "requires: ");
Texts.WriteString(Wr, name);
Texts.WriteLn(Wr);
Texts.Append(Oberon.Log, Wr.buf);
RETURN FALSE
END;
Files.ReadString(R, name)
END;
NEW(il);
il.next := P.imps;
P.imps := il;
il.extLabels := NIL;
il.ind := ind;
INC(ind);
il.name := D.name;
IF ~Import(il, FALSE) THEN
HALT(99)
END;
Books0.loading := P.imps;
Files.ReadLInt(R, len);
WHILE len >= 0 DO
NEW(t); NEW(t.text);
Texts.Open(t.text, "");
t.prev := P.cur; t.next := NIL;
IF P.cur = NIL THEN
P.texts := t
ELSE
P.cur.next := t
END;
P.cur := t;
IF len > 0 THEN
pos := Files.Pos(R)+1;
Texts.Load(t.text, F, pos, len);
IF Books0.error THEN
Texts.WriteString(Wr, "error with fixup");
Texts.WriteLn(Wr);
Texts.Append(Oberon.Log, Wr.buf);
RETURN FALSE
END;
Files.Set(R, F, pos+len)
END;
Files.ReadLInt(R, len)
END;
P.notes := t.text;
P.cmds := t.prev.text;
t.prev.prev.next := NIL;
t.prev.prev := NIL;
t.prev.next := NIL;
t.prev := NIL;
t.next := NIL;
GetLInts(D, open);
BuildInterface(P);
P.useStack := NIL;
IF (w # W) & (Books.resize IN P.options) THEN
Books.GetText(P, T);
Books.ResizeControls(P, T, w-Books.borderL-Books.borderR-Books.scrollBW)
END;
D.X := x; D.Y := y; D.W := w; D.H := h;
Documents.Init(D, P);
IF Books.newInd > 0 THEN
Books.GotoText(P, Books.newInd, Books.newPos, FALSE)
END;
Books.newInd := -1; Books.newPos := -1;
Books0.loading := oldL;
RETURN TRUE
END LoadDoc;
(* load the document: D.name; re-use data of already loaded tutorials, otherwise load it from file *)
PROCEDURE *Load(D: Documents.Document);
VAR
obj: Objects.Object;
M: ExistMsg;
C: Objects.CopyMsg;
P: Books.Panel;
open: ARRAY Books0.identLen OF CHAR;
T: Books.TGFrame;
BEGIN
M.F := NIL;
M.name := D.name;
M.res := -1;
Display.Broadcast(M);
IF (M.res >= 0) & (M.F # NIL) THEN
C.id := Objects.deep;
Objects.Stamp(C);
C.obj := NIL;
P := M.F(Documents.Document).dsc(Books.Panel);
P.handle(P, C);
P := C.obj(Books.Panel);
P.doc := D;
GetOpenLabel(open);
IF (open = "") & (Books.newInd < 0) THEN
open := "Open"
END;
GetLInts(D, open);
D.W := M.F.W;
D.H := M.F.H;
Documents.Init(D, P);
Books.GotoText(P, Books.newInd, Books.newPos, FALSE);
IF Books.newPos >= 0 THEN
Books.GetText(P, T);
T.org := TextGadgets0.LinesUp(T.text, Books.newPos, 0);
TextGadgets0.ScrollTo(T, TextGadgets0.LinesUp(T.text, Books.newPos, 0))
END;
Books.newInd := -1; Books.newPos := -1
ELSIF ~LoadDoc(D) THEN
TextDocs.NewDoc();
obj := Objects.NewObj;
D.handle := obj.handle;
obj := Gadgets.CreateObject("TextGadgets.New");
Texts.WriteString(Wr, "Can not load ");
Texts.WriteString(Wr, D.name);
Texts.WriteLn(Wr);
Texts.Append(obj(TextGadgets.Frame).text, Wr.buf);
Documents.Init(D, obj(Gadgets.Frame))
END
END Load;
(* store D.name *)
PROCEDURE *Store(D: Documents.Document);
VAR
F: Files.File;
R: Files.Rider;
P: Books.Panel;
BEGIN
IF ~(D.dsc IS Books.Panel) THEN
RETURN
END;
F := Files.Old(D.name);
IF F = NIL THEN
Texts.WriteString(Wr, D.name);
Texts.WriteString(Wr, " old file not found");
Texts.WriteLn(Wr);
Texts.Append(Oberon.Log, Wr.buf);
RETURN
END;
Files.Set(R, F, 0);
P := D.dsc(Books.Panel);
WriteHeaderP(R, P)
END Store;
(* printing of tutorial-documents *)
(* look for f in printFrames *)
PROCEDURE SearchFrame(f: Books0.Frame): FrameList;
VAR l: FrameList;
BEGIN
l := printFrames;
WHILE (l # NIL) & (l.frame # f) DO
l := l.next
END;
RETURN l
END SearchFrame;
(* print number at (X, Y) *)
PROCEDURE PrintInt(nr: LONGINT; X, Y: INTEGER);
VAR
str: ARRAY 8 OF CHAR;
BEGIN
Strings.IntToStr(nr, str);
Printer.String(X, Y, str, Fonts.Default)
END PrintInt;
(* overridden PrintLine-"method" for TextGadgets.Frame; translates Books0.Frame to page numbers *)
PROCEDURE *PrintLine(F: TextGadgets0.Frame; M: Display3.Mask; x, y: INTEGER; org: LONGINT; L: TextGadgets0.Line; dlink: Objects.Object);
VAR
Fi: Texts.Finder;
obj: Objects.Object;
l: FrameList;
pos: LONGINT;
BEGIN
Texts.OpenFinder(Fi, F.text, org);
pos := Fi.pos;
Texts.FindObj(Fi, obj);
WHILE ~Fi.eot & ~(obj IS Books0.LocFrame) & (pos <= (org+L.len)) DO
pos := Fi.pos;
Texts.FindObj(Fi, obj)
END;
TextGadgets.methods.Print(F, M, x, y, org, L, dlink);
IF (pos <= (org+L.len)) & (obj # NIL) & (obj IS Books0.LocFrame) THEN
WITH obj: Books0.LocFrame DO
l := SearchFrame(obj);
IF l = NIL THEN RETURN END;
IF obj.mode = Books.link THEN
PrintInt(l.page, TextGadgets0.PrinterleftX+printerTab+(Printer.Width DIV 10), L.base)
END
END
END
END PrintLine;
(* calculate an absolute position for the ind & pos pair; used for page number fixup *)
PROCEDURE AbsPos(P: Books.Panel; ind, pos: LONGINT): LONGINT;
VAR
t: Books0.TextList;
apos: LONGINT;
BEGIN
apos := pos;
t := P.texts.next;
WHILE ind > 1 DO
apos := apos+t.text.len;
DEC(ind);
t := t.next
END;
RETURN apos
END AbsPos;
(* fixup all frames with absolute position >= beg to page number pageNr *)
PROCEDURE Fixup(beg, pageNr: LONGINT);
VAR lF: FrameList;
BEGIN
lF := printFrames;
WHILE lF # NIL DO
IF lF.pos >= beg THEN
lF.page := pageNr
END;
lF := lF.next
END
END Fixup;
(* PrintText similar to TextGadgets0.PrintText; calculates page numbers, maximal width *)
PROCEDURE PrintText(T: TextGadgets.Frame; print, fix: BOOLEAN; VAR pageNr, maxW: LONGINT);
VAR
org, oldOrg: LONGINT;
L: TextGadgets0.Line;
Y: INTEGER;
output: BOOLEAN;
R: Display3.Mask;
break: BOOLEAN;
BEGIN
R := NIL;
org := 0; oldOrg := 0; maxW := 0;
Y := TextGadgets0.PrintertopY;
NEW(L); output := FALSE;
LOOP
IF L.eot THEN EXIT END;
T.do.PrintFormat(T, org, L, break);
IF (L.w > maxW) & (L.w < Printer.Width) THEN
maxW := L.w
END;
IF Y - L.h < TextGadgets0.PrinterbotY THEN
IF fix THEN
Fixup(oldOrg, pageNr)
END;
oldOrg := org;
IF print THEN
PrintInt(pageNr, printerRight, printerTop);
Printer.Page(1)
END;
INC(pageNr);
Y := TextGadgets0.PrintertopY;
output := FALSE
END;
DEC(Y, L.asr); L.base := Y;
IF print THEN
T.do.Print(T, R, TextGadgets0.PrinterleftX(*!! 0 *), 0, org, L, NIL)
END;
output := TRUE; DEC(Y, L.dsr); INC(org, L.len);
END;
IF output THEN
IF fix THEN
Fixup(oldOrg, pageNr)
END;
IF print THEN
PrintInt(pageNr, printerRight, printerTop);
Printer.Page(1)
END;
INC(pageNr)
END;
END PrintText;
(* replaces footnote references by numbers *)
PROCEDURE BuildNotesPrintList(t: Texts.Text);
VAR
lF, lF2, lastF: FrameList;
Fi: Texts.Finder;
obj: Objects.Object;
pos, nr: LONGINT;
PROCEDURE SearchSame(f: Books0.Frame): FrameList;
VAR
lF: FrameList;
a, b: Books0.LocFrame;
c, d: Books0.ExtFrame;
BEGIN
lF := printFrames;
LOOP
IF lF = NIL THEN EXIT END;
IF ABS(lF.frame.mode) = f.mode THEN
IF (f IS Books0.LocFrame) & (lF.frame IS Books0.LocFrame) THEN
a := f(Books0.LocFrame); b := lF.frame(Books0.LocFrame);
IF (a.pos1 = b.pos1) & (a.pos2 = b.pos2) THEN
EXIT
END
ELSIF (f IS Books0.ExtFrame) & (lF.frame IS Books0.ExtFrame) THEN
c := f(Books0.ExtFrame); d := lF.frame(Books0.ExtFrame);
IF c.imp = d.imp THEN
EXIT
END
END
END;
lF := lF.next
END;
RETURN lF
END SearchSame;
BEGIN
lastF := NIL;
lF := printFrames;
WHILE lF # NIL DO
lastF := lF;
lF := lF.next
END;
nr := 1;
Texts.OpenFinder(Fi, t, 0);
pos := Fi.pos;
Texts.FindObj(Fi, obj);
WHILE ~Fi.eot DO
IF (obj IS Books0.Frame) & (ABS(obj(Books0.Frame).mode) = Books.note) THEN
NEW(lF);
lF.frame := obj(Books0.Frame);
IF lF.frame.mode < 0 THEN
lF2 := SearchFrame(lF.frame);
lF.pos := lF2.pos
ELSE
lF2 := SearchSame(lF.frame);
lF.frame.mode := -lF.frame.mode;
IF lF2 # NIL THEN
lF.pos := lF2.pos
ELSE
lF.pos := nr;
INC(nr)
END
END;
lF.next := NIL;
lastF.next := lF;
lastF := lF;
Texts.Write(Wr, "[");
Texts.WriteInt(Wr, lF.pos, 0);
Texts.Write(Wr, "]");
Texts.Insert(t, pos+1, Wr.buf);
Texts.OpenFinder(Fi, t, pos+4)
END;
pos := Fi.pos;
Texts.FindObj(Fi, obj)
END
END BuildNotesPrintList;
(* copy footnote-numbers of popups to t; used for notes appendix *)
PROCEDURE CopyNotes(t, popups: Texts.Text);
VAR
lF: FrameList;
f: Books0.Frame;
style: TextGadgets.Style;
nr: LONGINT;
BEGIN
Texts.WriteString(Wr, "Appendix: Notes");
Texts.WriteLn(Wr); Texts.WriteLn(Wr);
Texts.Append(t, Wr.buf);
Texts.ChangeLooks(t, 0, t.len, {Books.looksLib}, sectionFonts[0], 0, 0);
style := TextGadgets.newStyle();
style.width := printerPageW;
Books0.AppendFrame(t, style);
lF := printFrames; nr := 0;
WHILE lF # NIL DO
f := lF.frame;
IF ABS(f.mode) = Books.note THEN
IF (f.mode < 0) & (lF.pos > nr) THEN
INC(nr);
Texts.Write(Wr, "[");
Texts.WriteInt(Wr, lF.pos, 0);
Texts.Write(Wr, "]");
Texts.Write(Wr, Books.Tab);
Texts.Append(t, Wr.buf);
IF f IS Books0.LocFrame THEN
Texts.Save(popups, f(Books0.LocFrame).pos1, f(Books0.LocFrame).pos2, B)
ELSIF f IS Books0.ExtFrame THEN
Texts.Save(f(Books0.ExtFrame).imp.book.notes, f(Books0.ExtFrame).imp.pos1, f(Books0.ExtFrame).imp.pos2, B)
END;
Texts.Append(t, B);
Texts.WriteLn(Wr);
Texts.WriteLn(Wr);
Texts.WriteLn(Wr);
Texts.Append(t, Wr.buf)
END;
f.mode := Books.note
END;
lF := lF.next
END
END CopyNotes;
(* count tabs beginning at beg *)
PROCEDURE CountTabs(t: Texts.Text; beg: LONGINT): INTEGER;
VAR
R: Texts.Reader;
ch: CHAR;
i: INTEGER;
BEGIN
i := 0;
Texts.OpenReader(R, t, beg);
Texts.Read(R, ch);
WHILE ~R.eot & (R.lib IS Fonts.Font) & (ch = Books.Tab) DO
INC(i);
Texts.Read(R, ch)
END;
RETURN i
END CountTabs;
(* add nTabs tabs to each line beginning in the text stretch (beg, end) in t *)