DEADSOFTWARE

* -> old; Trurl-based -> new
[bbcp.git] / new / Std / Mod / Cmds.txt
1 MODULE StdCmds;
3 (* THIS IS TEXT COPY OF BlackBox 1.6-rc6 Std/Mod/Cmds.odc *)
4 (* DO NOT EDIT *)
6 IMPORT
7 Fonts, Ports, Services, Stores, Sequencers, Models, Views,
8 Controllers, Containers, Properties, Dialog, Documents, Windows, Strings,
9 StdDialog, StdApi;
11 CONST
12 illegalSizeKey = "#System:IllegalFontSize";
13 defaultAllocator = "TextViews.Deposit; StdCmds.Open";
15 (* wType, hType *)
16 fix = 0; page = 1; window = 2;
18 VAR
19 size*: RECORD
20 size*: INTEGER
21 END;
22 layout*: RECORD
23 wType*, hType*: INTEGER;
24 width*, height*: REAL;
25 doc: Documents.Document;
26 u: INTEGER
27 END;
28 allocator*: Dialog.String;
30 propEra: INTEGER; (* (propEra, props) form cache for StdProps() *)
31 props: Properties.StdProp; (* valid iff propEra = Props.era *)
33 prop: Properties.Property; (* usef for copy/paste properties *)
35 (* auxiliary procedures *)
37 PROCEDURE StdProp (): Properties.StdProp;
38 BEGIN
39 IF propEra # Properties.era THEN
40 Properties.CollectStdProp(props);
41 propEra := Properties.era
42 END;
43 RETURN props
44 END StdProp;
46 PROCEDURE Append (VAR s: ARRAY OF CHAR; t: ARRAY OF CHAR);
47 VAR len, i, j: INTEGER; ch: CHAR;
48 BEGIN
49 len := LEN(s);
50 i := 0; WHILE s[i] # 0X DO INC(i) END;
51 j := 0; REPEAT ch := t[j]; s[i] := ch; INC(j); INC(i) UNTIL (ch = 0X) OR (i = len);
52 s[len - 1] := 0X
53 END Append;
55 (* standard commands *)
57 PROCEDURE OpenAuxDialog* (file, title: ARRAY OF CHAR);
58 VAR v: Views.View;
59 BEGIN
60 StdApi.OpenAuxDialog(file, title, v)
61 END OpenAuxDialog;
63 PROCEDURE OpenToolDialog* (file, title: ARRAY OF CHAR);
64 VAR v: Views.View;
65 BEGIN
66 StdApi.OpenToolDialog(file, title, v)
67 END OpenToolDialog;
69 PROCEDURE OpenDoc* (file: ARRAY OF CHAR);
70 VAR v: Views.View;
71 BEGIN
72 StdApi.OpenDoc(file, v)
73 END OpenDoc;
75 PROCEDURE OpenCopyOf* (file: ARRAY OF CHAR);
76 VAR v: Views.View;
77 BEGIN
78 StdApi.OpenCopyOf(file, v)
79 END OpenCopyOf;
81 PROCEDURE OpenAux* (file, title: ARRAY OF CHAR);
82 VAR v: Views.View;
83 BEGIN
84 StdApi.OpenAux(file, title, v)
85 END OpenAux;
87 PROCEDURE OpenBrowser* (file, title: ARRAY OF CHAR);
88 VAR v: Views.View;
89 BEGIN
90 StdApi.OpenBrowser(file, title, v)
91 END OpenBrowser;
93 PROCEDURE CloseDialog*;
94 VAR v: Views.View;
95 BEGIN
96 StdApi.CloseDialog(v)
97 END CloseDialog;
100 PROCEDURE Open*;
101 VAR i: INTEGER; v: Views.View;
102 BEGIN
103 i := Views.Available();
104 IF i > 0 THEN Views.Fetch(v); Views.OpenView(v)
105 ELSE Dialog.ShowMsg("#System:DepositExpected")
106 END
107 END Open;
109 PROCEDURE PasteView*;
110 VAR i: INTEGER; v: Views.View;
111 BEGIN
112 i := Views.Available();
113 IF i > 0 THEN
114 Views.Fetch(v);
115 Controllers.PasteView(v, Views.undefined, Views.undefined, FALSE)
116 ELSE Dialog.ShowMsg("#System:DepositExpected")
117 END
118 END PasteView;
120 (* file menu commands *)
122 PROCEDURE New*;
123 VAR res: INTEGER;
124 BEGIN
125 Dialog.Call(allocator, " ", res)
126 END New;
129 (* edit menu commands *)
131 PROCEDURE Undo*;
132 VAR w: Windows.Window;
133 BEGIN
134 w := Windows.dir.Focus(Controllers.frontPath);
135 IF w # NIL THEN w.seq.Undo END
136 END Undo;
138 PROCEDURE Redo*;
139 VAR w: Windows.Window;
140 BEGIN
141 w := Windows.dir.Focus(Controllers.frontPath);
142 IF w # NIL THEN w.seq.Redo END
143 END Redo;
145 PROCEDURE CopyProp*;
146 BEGIN
147 Properties.CollectProp(prop)
148 END CopyProp;
150 PROCEDURE PasteProp*;
151 BEGIN
152 Properties.EmitProp(NIL, prop)
153 END PasteProp;
155 PROCEDURE Clear*;
156 (** remove the selection of the current focus **)
157 VAR msg: Controllers.EditMsg;
158 BEGIN
159 msg.op := Controllers.cut; msg.view := NIL;
160 msg.clipboard := FALSE;
161 Controllers.Forward(msg)
162 END Clear;
164 PROCEDURE SelectAll*;
165 (** select whole content of current focus **)
166 VAR msg: Controllers.SelectMsg;
167 BEGIN
168 msg.set := TRUE; Controllers.Forward(msg)
169 END SelectAll;
171 PROCEDURE DeselectAll*;
172 (** select whole content of current focus **)
173 VAR msg: Controllers.SelectMsg;
174 BEGIN
175 msg.set := FALSE; Controllers.Forward(msg)
176 END DeselectAll;
178 PROCEDURE SelectDocument*;
179 (** select whole document **)
180 VAR w: Windows.Window; c: Containers.Controller;
181 BEGIN
182 w := Windows.dir.Focus(Controllers.path);
183 IF w # NIL THEN
184 c := w.doc.ThisController();
185 IF (c # NIL) & ~(Containers.noSelection IN c.opts) & (c.Singleton() = NIL) THEN
186 c.SetSingleton(w.doc.ThisView())
187 END
188 END
189 END SelectDocument;
191 PROCEDURE SelectNextView*;
192 VAR c: Containers.Controller; v: Views.View;
193 BEGIN
194 c := Containers.Focus();
195 IF (c # NIL) & ~(Containers.noSelection IN c.opts) THEN
196 IF c.HasSelection() THEN v := c.Singleton() ELSE v := NIL END;
197 IF v = NIL THEN
198 c.GetFirstView(Containers.any, v)
199 ELSE
200 c.GetNextView(Containers.any, v);
201 IF v = NIL THEN c.GetFirstView(Containers.any, v) END
202 END;
203 c.SelectAll(FALSE);
204 IF v # NIL THEN c.SetSingleton(v) END
205 ELSE Dialog.ShowMsg("#Dev:NoTargetFocusFound")
206 END
207 END SelectNextView;
210 (** font menu commands **)
212 PROCEDURE Font* (typeface: Fonts.Typeface);
213 (** set the selection to the given font family **)
214 VAR p: Properties.StdProp;
215 BEGIN
216 NEW(p); p.valid := {Properties.typeface}; p.typeface := typeface;
217 Properties.EmitProp(NIL, p)
218 END Font;
220 PROCEDURE DefaultFont*;
221 (** set the selection to the default font family **)
222 VAR p: Properties.StdProp;
223 BEGIN
224 NEW(p); p.valid := {Properties.typeface}; p.typeface := Fonts.default;
225 Properties.EmitProp(NIL, p)
226 END DefaultFont;
229 (** attributes menu commands **)
231 PROCEDURE Plain*;
232 (** reset the font attribute "weight" and all font style attributes of the selection **)
233 VAR p: Properties.StdProp;
234 BEGIN
235 NEW(p); p.valid := {Properties.style, Properties.weight};
236 p.style.val := {}; p.style.mask := {Fonts.italic, Fonts.underline, Fonts.strikeout};
237 p.weight := Fonts.normal;
238 Properties.EmitProp(NIL, p)
239 END Plain;
241 PROCEDURE Bold*;
242 (** change the font attribute "weight" in the selection;
243 if the selection has a homogeneously bold weight: toggle to normal, else force to bold **)
244 VAR p, p0: Properties.StdProp;
245 BEGIN
246 Properties.CollectStdProp(p0);
247 NEW(p); p.valid := {Properties.weight};
248 IF (Properties.weight IN p0.valid) & (p0.weight # Fonts.normal) THEN
249 p.weight := Fonts.normal
250 ELSE p.weight := Fonts.bold
251 END;
252 Properties.EmitProp(NIL, p)
253 END Bold;
255 PROCEDURE Italic*;
256 (** change the font style attribute "italic" in the selection;
257 if the selection is homogeneous wrt this attribute: toggle, else force to italic **)
258 VAR p, p0: Properties.StdProp;
259 BEGIN
260 Properties.CollectStdProp(p0);
261 NEW(p); p.valid := {Properties.style}; p.style.mask := {Fonts.italic};
262 IF (Properties.style IN p0.valid) & (Fonts.italic IN p0.style.val) THEN
263 p.style.val := {}
264 ELSE p.style.val := {Fonts.italic}
265 END;
266 Properties.EmitProp(NIL, p)
267 END Italic;
269 PROCEDURE Underline*;
270 (** change the font style attribute "underline" in the selection;
271 if the selection is homogeneous wrt this attribute: toggle, else force to underline **)
272 VAR p, p0: Properties.StdProp;
273 BEGIN
274 Properties.CollectStdProp(p0);
275 NEW(p); p.valid := {Properties.style}; p.style.mask := {Fonts.underline};
276 IF (Properties.style IN p0.valid) & (Fonts.underline IN p0.style.val) THEN
277 p.style.val := {}
278 ELSE p.style.val := {Fonts.underline}
279 END;
280 Properties.EmitProp(NIL, p)
281 END Underline;
283 PROCEDURE Strikeout*;
284 (** change the font style attribute "strikeout" in the selection,
285 without changing other attributes;
286 if the selection is homogeneous wrt this attribute: toggle,
287 else force to strikeout **)
288 VAR p, p0: Properties.StdProp;
289 BEGIN
290 Properties.CollectStdProp(p0);
291 NEW(p); p.valid := {Properties.style}; p.style.mask := {Fonts.strikeout};
292 IF (Properties.style IN p0.valid) & (Fonts.strikeout IN p0.style.val) THEN
293 p.style.val := {}
294 ELSE p.style.val := {Fonts.strikeout}
295 END;
296 Properties.EmitProp(NIL, p)
297 END Strikeout;
299 PROCEDURE Size* (size: INTEGER);
300 (** set the selection to the given font size **)
301 VAR p: Properties.StdProp;
302 BEGIN
303 NEW(p); p.valid := {Properties.size};
304 p.size := size * Ports.point;
305 Properties.EmitProp(NIL, p)
306 END Size;
308 PROCEDURE SetSize*;
309 VAR p: Properties.StdProp;
310 BEGIN
311 IF (0 <= size.size) & (size.size < 32768) THEN
312 NEW(p); p.valid := {Properties.size};
313 p.size := size.size * Fonts.point;
314 Properties.EmitProp(NIL, p)
315 ELSE
316 Dialog.ShowMsg(illegalSizeKey)
317 END
318 END SetSize;
320 PROCEDURE InitSizeDialog*;
321 VAR p: Properties.StdProp;
322 BEGIN
323 Properties.CollectStdProp(p);
324 IF Properties.size IN p.valid THEN size.size := p.size DIV Fonts.point END
325 END InitSizeDialog;
327 PROCEDURE Color* (color: Ports.Color);
328 (** set the color attributes of the selection **)
329 VAR p: Properties.StdProp;
330 BEGIN
331 NEW(p); p.valid := {Properties.color};
332 p.color.val := color;
333 Properties.EmitProp(NIL, p)
334 END Color;
336 PROCEDURE UpdateAll*; (* for HostCmds.Toggle *)
337 VAR w: Windows.Window; pw, ph: INTEGER; dirty: BOOLEAN; msg: Models.UpdateMsg;
338 BEGIN
339 w := Windows.dir.First();
340 WHILE w # NIL DO
341 IF ~w.sub THEN
342 dirty := w.seq.Dirty();
343 Models.Domaincast(w.doc.Domain(), msg);
344 IF ~dirty THEN w.seq.SetDirty(FALSE) END (* not perfect: "undoable dirt" ... *)
345 END;
346 w.port.GetSize(pw, ph);
347 w.Restore(0, 0, pw, ph);
348 w := Windows.dir.Next(w)
349 END
350 END UpdateAll;
352 PROCEDURE RestoreAll*;
353 VAR w: Windows.Window; pw, ph: INTEGER;
354 BEGIN
355 w := Windows.dir.First();
356 WHILE w # NIL DO
357 w.port.GetSize(pw, ph);
358 w.Restore(0, 0, pw, ph);
359 w := Windows.dir.Next(w)
360 END
361 END RestoreAll;
364 (** document layout dialog **)
366 PROCEDURE SetLayout*;
367 VAR opts: SET; l, t, r, b, r0, b0: INTEGER; c: Containers.Controller; script: Stores.Operation;
368 BEGIN
369 c := layout.doc.ThisController();
370 opts := c.opts - {Documents.pageWidth..Documents.winHeight};
371 IF layout.wType = page THEN INCL(opts, Documents.pageWidth)
372 ELSIF layout.wType = window THEN INCL(opts, Documents.winWidth)
373 END;
374 IF layout.hType = page THEN INCL(opts, Documents.pageHeight)
375 ELSIF layout.hType = window THEN INCL(opts, Documents.winHeight)
376 END;
377 layout.doc.PollRect(l, t, r, b); r0 := r; b0 := b;
378 IF layout.wType = fix THEN r := l + SHORT(ENTIER(layout.width * layout.u)) END;
379 IF layout.hType = fix THEN b := t + SHORT(ENTIER(layout.height * layout.u)) END;
380 IF (opts # c.opts) OR (r # r0) OR (b # b0) THEN
381 Views.BeginScript(layout.doc, "#System:ChangeLayout", script);
382 c.SetOpts(opts);
383 layout.doc.SetRect(l, t, r, b);
384 Views.EndScript(layout.doc, script)
385 END
386 END SetLayout;
388 PROCEDURE InitLayoutDialog*;
389 (* guard: WindowGuard *)
390 VAR w: Windows.Window; c: Containers.Controller; l, t, r, b: INTEGER;
391 BEGIN
392 w := Windows.dir.First();
393 IF w # NIL THEN
394 layout.doc := w.doc;
395 c := w.doc.ThisController();
396 IF Documents.pageWidth IN c.opts THEN layout.wType := page
397 ELSIF Documents.winWidth IN c.opts THEN layout.wType := window
398 ELSE layout.wType := fix
399 END;
400 IF Documents.pageHeight IN c.opts THEN layout.hType := page
401 ELSIF Documents.winHeight IN c.opts THEN layout.hType := window
402 ELSE layout.hType := fix
403 END;
404 IF Dialog.metricSystem THEN layout.u := Ports.mm * 10 ELSE layout.u := Ports.inch END;
405 w.doc.PollRect(l, t, r, b);
406 layout.width := (r - l) DIV (layout.u DIV 100) / 100;
407 layout.height := (b - t) DIV (layout.u DIV 100) / 100
408 END
409 END InitLayoutDialog;
411 PROCEDURE WidthGuard* (VAR par: Dialog.Par);
412 BEGIN
413 IF layout.wType # fix THEN par.readOnly := TRUE END
414 END WidthGuard;
416 PROCEDURE HeightGuard* (VAR par: Dialog.Par);
417 BEGIN
418 IF layout.hType # fix THEN par.readOnly := TRUE END
419 END HeightGuard;
421 PROCEDURE TypeNotifier* (op, from, to: INTEGER);
422 VAR w, h, l, t, r, b: INTEGER; d: BOOLEAN;
423 BEGIN
424 layout.doc.PollRect(l, t, r, b);
425 IF layout.wType = page THEN
426 layout.doc.PollPage(w, h, l, t, r, b, d)
427 ELSIF layout.wType = window THEN
428 layout.doc.context.GetSize(w, h); r := w - l
429 END;
430 layout.width := (r - l) DIV (layout.u DIV 100) / 100;
431 layout.doc.PollRect(l, t, r, b);
432 IF layout.hType = page THEN
433 layout.doc.PollPage(w, h, l, t, r, b, d)
434 ELSIF layout.hType = window THEN
435 layout.doc.context.GetSize(w, h); b := h - t
436 END;
437 layout.height := (b - t) DIV (layout.u DIV 100) / 100;
438 Dialog.Update(layout)
439 END TypeNotifier;
442 (** window menu command **)
444 PROCEDURE NewWindow*;
445 (** guard ModelViewGuard **)
446 VAR win: Windows.Window; doc: Documents.Document; v: Views.View; title: Views.Title;
447 seq: ANYPTR; clean: BOOLEAN;
448 BEGIN
449 win := Windows.dir.Focus(Controllers.frontPath);
450 IF win # NIL THEN
451 v := win.doc.ThisView();
452 IF v.Domain() # NIL THEN seq := v.Domain().GetSequencer() ELSE seq := NIL END;
453 clean := (seq # NIL) & ~seq(Sequencers.Sequencer).Dirty();
454 doc := win.doc.DocCopyOf(v);
455 (* Stores.InitDomain(doc, v.Domain()); *)
456 ASSERT(doc.Domain() = v.Domain(), 100);
457 win.GetTitle(title);
458 Windows.dir.OpenSubWindow(Windows.dir.New(), doc, win.flags, title);
459 IF clean THEN seq(Sequencers.Sequencer).SetDirty(FALSE) END
460 END
461 END NewWindow;
463 (* properties *)
465 PROCEDURE GetCmd (name: ARRAY OF CHAR; OUT cmd: ARRAY OF CHAR);
466 VAR i, j: INTEGER; ch, lch: CHAR; key: ARRAY 256 OF CHAR;
467 BEGIN
468 i := 0; ch := name[0]; key[0] := "#"; j := 1;
469 REPEAT
470 key[j] := ch; INC(j); lch := ch; INC(i); ch := name[i]
471 UNTIL (ch = 0X) OR (ch = ".")
472 OR ((ch >= "A") & (ch <= "Z") OR (ch >= "À") & (ch # "×") & (ch <= "Þ"))
473 & ((lch < "A") OR (lch > "Z") & (lch < "À") OR (lch = "×") OR (lch > "Þ"));
474 IF ch = "." THEN
475 key := "#System:" + name
476 ELSE
477 key[j] := ":"; INC(j); key[j] := 0X; j := 0;
478 WHILE ch # 0X DO name[j] := ch; INC(i); INC(j); ch := name[i] END;
479 name[j] := 0X; key := key + name
480 END;
481 Dialog.MapString(key, cmd);
482 IF cmd = name THEN cmd := "" END
483 END GetCmd;
485 PROCEDURE SearchCmd (call: BOOLEAN; OUT found: BOOLEAN);
486 VAR p: Properties.Property; std: BOOLEAN; v: Views.View; cmd: ARRAY 256 OF CHAR; pos, res: INTEGER;
487 BEGIN
488 Controllers.SetCurrentPath(Controllers.targetPath);
489 v := Containers.FocusSingleton(); found := FALSE;
490 IF v # NIL THEN
491 Services.GetTypeName(v, cmd);
492 GetCmd(cmd, cmd);
493 IF cmd # "" THEN found := TRUE;
494 IF call THEN Dialog.Call(cmd, "", res) END
495 END
496 END;
497 std := FALSE;
498 Properties.CollectProp(p);
499 WHILE p # NIL DO
500 IF p IS Properties.StdProp THEN std := TRUE
501 ELSE
502 Services.GetTypeName(p, cmd);
503 GetCmd(cmd, cmd);
504 IF cmd # "" THEN found := TRUE;
505 IF call THEN Dialog.Call(cmd, "", res) END
506 ELSE
507 Services.GetTypeName(p, cmd);
508 Strings.Find(cmd, "Desc", LEN(cmd$)-4, pos);
509 IF LEN(cmd$)-4 = pos THEN
510 cmd[pos] := 0X; GetCmd(cmd, cmd);
511 IF cmd # "" THEN found := TRUE;
512 IF call THEN Dialog.Call(cmd, "", res) END
513 END
514 END
515 END
516 END;
517 p := p.next
518 END;
519 IF std & ~found THEN
520 Dialog.MapString("#Host:Properties.StdProp", cmd);
521 IF cmd # "Properties.StdProp" THEN found := TRUE;
522 IF call THEN Dialog.Call(cmd, "", res) END
523 END
524 END;
525 IF ~found THEN
526 Dialog.MapString("#System:ShowProp", cmd);
527 IF cmd # "ShowProp" THEN found := TRUE;
528 IF call THEN Dialog.Call(cmd, "", res) END
529 END
530 END;
531 Controllers.ResetCurrentPath
532 END SearchCmd;
534 PROCEDURE ShowProp*;
535 VAR found: BOOLEAN;
536 BEGIN
537 SearchCmd(TRUE, found)
538 END ShowProp;
540 PROCEDURE ShowPropGuard* (VAR par: Dialog.Par);
541 VAR found: BOOLEAN;
542 BEGIN
543 SearchCmd(FALSE, found);
544 IF ~found THEN par.disabled := TRUE END
545 END ShowPropGuard;
548 (* container commands *)
550 PROCEDURE ActFocus (): Containers.Controller;
551 VAR c: Containers.Controller; v: Views.View;
552 BEGIN
553 c := Containers.Focus();
554 IF c # NIL THEN
555 v := c.ThisView();
556 IF v IS Documents.Document THEN
557 v := v(Documents.Document).ThisView();
558 IF v IS Containers.View THEN
559 c := v(Containers.View).ThisController()
560 ELSE c := NIL
561 END
562 END
563 END;
564 RETURN c
565 END ActFocus;
567 PROCEDURE ToggleNoFocus*;
568 VAR c: Containers.Controller; v: Views.View;
569 BEGIN
570 c := ActFocus();
571 IF c # NIL THEN
572 v := c.ThisView();
573 IF ~((v IS Documents.Document) OR (Containers.noSelection IN c.opts)) THEN
574 IF Containers.noFocus IN c.opts THEN
575 c.SetOpts(c.opts - {Containers.noFocus})
576 ELSE
577 c.SetOpts(c.opts + {Containers.noFocus})
578 END
579 END
580 END
581 END ToggleNoFocus;
583 PROCEDURE OpenAsAuxDialog*;
584 (** create a new sub-window onto the focus view shown in the top window, mask mode **)
585 VAR win: Windows.Window; doc: Documents.Document; v, u: Views.View; title: Views.Title;
586 c: Containers.Controller;
587 BEGIN
588 v := Controllers.FocusView();
589 IF (v # NIL) & (v IS Containers.View) & ~(v IS Documents.Document) THEN
590 win := Windows.dir.Focus(Controllers.frontPath); ASSERT(win # NIL, 100);
591 doc := win.doc.DocCopyOf(v);
592 u := doc.ThisView();
593 c := u(Containers.View).ThisController();
594 c.SetOpts(c.opts - {Containers.noFocus} + {Containers.noCaret, Containers.noSelection});
595 IF v # win.doc.ThisView() THEN
596 c := doc.ThisController();
597 c.SetOpts(c.opts - {Documents.pageWidth, Documents.pageHeight}
598 + {Documents.winWidth, Documents.winHeight})
599 END;
600 (* Stores.InitDomain(doc, v.Domain()); already done in DocCopyOf *)
601 win.GetTitle(title);
602 Windows.dir.OpenSubWindow(Windows.dir.New(), doc,
603 {Windows.isAux, Windows.neverDirty, Windows.noResize, Windows.noHScroll, Windows.noVScroll},
604 title)
605 ELSE Dialog.Beep
606 END
607 END OpenAsAuxDialog;
609 PROCEDURE OpenAsToolDialog*;
610 (** create a new sub-window onto the focus view shown in the top window, mask mode **)
611 VAR win: Windows.Window; doc: Documents.Document; v, u: Views.View; title: Views.Title;
612 c: Containers.Controller;
613 BEGIN
614 v := Controllers.FocusView();
615 IF (v # NIL) & (v IS Containers.View) & ~(v IS Documents.Document) THEN
616 win := Windows.dir.Focus(Controllers.frontPath); ASSERT(win # NIL, 100);
617 doc := win.doc.DocCopyOf(v);
618 u := doc.ThisView();
619 c := u(Containers.View).ThisController();
620 c.SetOpts(c.opts - {Containers.noFocus} + {Containers.noCaret, Containers.noSelection});
621 IF v # win.doc.ThisView() THEN
622 c := doc.ThisController();
623 c.SetOpts(c.opts - {Documents.pageWidth, Documents.pageHeight}
624 + {Documents.winWidth, Documents.winHeight})
625 END;
626 (* Stores.InitDomain(doc, v.Domain()); already done in DocCopyOf *)
627 win.GetTitle(title);
628 Windows.dir.OpenSubWindow(Windows.dir.New(), doc,
629 {Windows.isTool, Windows.neverDirty, Windows.noResize, Windows.noHScroll, Windows.noVScroll},
630 title)
631 ELSE Dialog.Beep
632 END
633 END OpenAsToolDialog;
635 PROCEDURE RecalcFocusSize*;
636 VAR c: Containers.Controller; v: Views.View; bounds: Properties.BoundsPref;
637 BEGIN
638 c := Containers.Focus();
639 IF c # NIL THEN
640 v := c.ThisView();
641 bounds.w := Views.undefined; bounds.h := Views.undefined;
642 Views.HandlePropMsg(v, bounds);
643 v.context.SetSize(bounds.w, bounds.h)
644 END
645 END RecalcFocusSize;
647 PROCEDURE RecalcAllSizes*;
648 VAR w: Windows.Window;
649 BEGIN
650 w := Windows.dir.First();
651 WHILE w # NIL DO
652 StdDialog.RecalcView(w.doc.ThisView());
653 w := Windows.dir.Next(w)
654 END
655 END RecalcAllSizes;
657 PROCEDURE SetMode(opts: SET);
658 VAR
659 c: Containers.Controller; v: Views.View;
660 gm: Containers.GetOpts; sm: Containers.SetOpts;
661 w: Windows.Window;
662 BEGIN
663 c := Containers.Focus();
664 gm.valid := {};
665 IF (c # NIL) & (c.Singleton() # NIL) THEN
666 v := c.Singleton();
667 Views.HandlePropMsg(v, gm);
668 END;
669 IF gm.valid = {} THEN
670 w := Windows.dir.Focus(Controllers.path);
671 IF (w # NIL) & (w.doc.ThisView() IS Containers.View) THEN v := w.doc.ThisView() ELSE v := NIL END
672 END;
673 IF v # NIL THEN
674 sm.valid := {Containers.noSelection, Containers.noFocus, Containers.noCaret};
675 sm.opts := opts;
676 Views.HandlePropMsg(v, sm);
677 END;
678 END SetMode;
680 PROCEDURE GetMode(OUT found: BOOLEAN; OUT opts: SET);
681 VAR c: Containers.Controller; gm: Containers.GetOpts; w: Windows.Window;
682 BEGIN
683 c := Containers.Focus();
684 gm.valid := {};
685 IF (c # NIL) & (c.Singleton() # NIL) THEN
686 Views.HandlePropMsg(c.Singleton(), gm);
687 END;
688 IF gm.valid = {} THEN
689 w := Windows.dir.Focus(Controllers.path);
690 IF (w # NIL) & (w.doc.ThisView() IS Containers.View) THEN
691 Views.HandlePropMsg(w.doc.ThisView(), gm);
692 END
693 END;
694 found := gm.valid # {};
695 opts := gm.opts
696 END GetMode;
698 PROCEDURE SetMaskMode*;
699 (* Guard: SetMaskGuard *)
700 BEGIN
701 SetMode({Containers.noSelection, Containers.noCaret})
702 END SetMaskMode;
704 PROCEDURE SetEditMode*;
705 (* Guard: SetEditGuard *)
706 BEGIN
707 SetMode({})
708 END SetEditMode;
710 PROCEDURE SetLayoutMode*;
711 (* Guard: SetLayoutGuard *)
712 BEGIN
713 SetMode({Containers.noFocus})
714 END SetLayoutMode;
716 PROCEDURE SetBrowserMode*;
717 (* Guard: SetBrowserGuard *)
718 BEGIN
719 SetMode({Containers.noCaret})
720 END SetBrowserMode;
723 (* standard guards *)
725 PROCEDURE ToggleNoFocusGuard* (VAR par: Dialog.Par);
726 VAR c: Containers.Controller; v: Views.View;
727 BEGIN
728 c := ActFocus();
729 IF c # NIL THEN
730 v := c.ThisView();
731 IF ~((v IS Documents.Document) OR (Containers.noSelection IN c.opts)) THEN
732 IF Containers.noFocus IN c.opts THEN par.label := "#System:AllowFocus"
733 ELSE par.label := "#System:PreventFocus"
734 END
735 ELSE par.disabled := TRUE
736 END
737 ELSE par.disabled := TRUE
738 END
739 END ToggleNoFocusGuard;
741 PROCEDURE ReadOnlyGuard* (VAR par: Dialog.Par);
742 BEGIN
743 par.readOnly := TRUE
744 END ReadOnlyGuard;
746 PROCEDURE WindowGuard* (VAR par: Dialog.Par);
747 VAR w: Windows.Window;
748 BEGIN
749 w := Windows.dir.First();
750 IF w = NIL THEN par.disabled := TRUE END
751 END WindowGuard;
753 PROCEDURE ModelViewGuard* (VAR par: Dialog.Par);
754 VAR w: Windows.Window;
755 BEGIN
756 w := Windows.dir.Focus(Controllers.frontPath);
757 par.disabled := (w = NIL) OR (w.doc.ThisView().ThisModel() = NIL)
758 END ModelViewGuard;
760 PROCEDURE SetMaskModeGuard* (VAR par: Dialog.Par);
761 CONST mode = {Containers.noSelection, Containers.noFocus, Containers.noCaret};
762 VAR opts: SET; found: BOOLEAN;
763 BEGIN
764 GetMode(found, opts);
765 IF found THEN
766 par.checked := opts * mode = {Containers.noSelection, Containers.noCaret}
767 ELSE
768 par.disabled := TRUE
769 END
770 END SetMaskModeGuard;
772 PROCEDURE SetEditModeGuard* (VAR par: Dialog.Par);
773 CONST mode = {Containers.noSelection, Containers.noFocus, Containers.noCaret};
774 VAR opts: SET; found: BOOLEAN;
775 BEGIN
776 GetMode(found, opts);
777 IF found THEN
778 par.checked := opts * mode = {}
779 ELSE
780 par.disabled := TRUE
781 END
782 END SetEditModeGuard;
784 PROCEDURE SetLayoutModeGuard* (VAR par: Dialog.Par);
785 CONST mode = {Containers.noSelection, Containers.noFocus, Containers.noCaret};
786 VAR opts: SET; found: BOOLEAN;
787 BEGIN
788 GetMode(found, opts);
789 IF found THEN
790 par.checked := opts * mode = {Containers.noFocus}
791 ELSE
792 par.disabled := TRUE
793 END
794 END SetLayoutModeGuard;
796 PROCEDURE SetBrowserModeGuard* (VAR par: Dialog.Par);
797 CONST mode = {Containers.noSelection, Containers.noFocus, Containers.noCaret};
798 VAR opts: SET; found: BOOLEAN;
799 BEGIN
800 GetMode(found, opts);
801 IF found THEN
802 par.checked := opts * mode = {Containers.noCaret}
803 ELSE
804 par.disabled := TRUE
805 END
806 END SetBrowserModeGuard;
808 PROCEDURE SelectionGuard* (VAR par: Dialog.Par);
809 VAR ops: Controllers.PollOpsMsg;
810 BEGIN
811 Controllers.PollOps(ops);
812 IF ops.valid * {Controllers.cut, Controllers.copy} = {} THEN par.disabled := TRUE END
813 END SelectionGuard;
815 PROCEDURE SingletonGuard* (VAR par: Dialog.Par);
816 VAR ops: Controllers.PollOpsMsg;
817 BEGIN
818 Controllers.PollOps(ops);
819 IF ops.singleton = NIL THEN par.disabled := TRUE END
820 END SingletonGuard;
822 PROCEDURE SelectAllGuard* (VAR par: Dialog.Par);
823 VAR ops: Controllers.PollOpsMsg;
824 BEGIN
825 Controllers.PollOps(ops);
826 IF ~ops.selectable THEN par.disabled := TRUE END
827 END SelectAllGuard;
829 PROCEDURE CaretGuard* (VAR par: Dialog.Par);
830 VAR ops: Controllers.PollOpsMsg;
831 BEGIN
832 Controllers.PollOps(ops);
833 IF ops.valid * {Controllers.pasteChar .. Controllers.paste} = {} THEN par.disabled := TRUE END
834 END CaretGuard;
836 PROCEDURE PasteCharGuard* (VAR par: Dialog.Par);
837 VAR ops: Controllers.PollOpsMsg;
838 BEGIN
839 Controllers.PollOps(ops);
840 IF ~(Controllers.pasteChar IN ops.valid) THEN par.disabled := TRUE END
841 END PasteCharGuard;
843 PROCEDURE PasteLCharGuard* (VAR par: Dialog.Par);
844 VAR ops: Controllers.PollOpsMsg;
845 BEGIN
846 Controllers.PollOps(ops);
847 IF ~(Controllers.pasteChar IN ops.valid) THEN par.disabled := TRUE END
848 END PasteLCharGuard;
850 PROCEDURE PasteViewGuard* (VAR par: Dialog.Par);
851 VAR ops: Controllers.PollOpsMsg;
852 BEGIN
853 Controllers.PollOps(ops);
854 IF ~(Controllers.paste IN ops.valid) THEN par.disabled := TRUE END
855 END PasteViewGuard;
857 PROCEDURE ContainerGuard* (VAR par: Dialog.Par);
858 BEGIN
859 IF Containers.Focus() = NIL THEN par.disabled := TRUE END
860 END ContainerGuard;
862 PROCEDURE UndoGuard* (VAR par: Dialog.Par);
863 VAR f: Windows.Window; opName: Stores.OpName;
864 BEGIN
865 Dialog.MapString("#System:Undo", par.label);
866 f := Windows.dir.Focus(Controllers.frontPath);
867 IF (f # NIL) & f.seq.CanUndo() THEN
868 f.seq.GetUndoName(opName);
869 Dialog.MapString(opName, opName);
870 Append(par.label, " ");
871 Append(par.label, opName)
872 ELSE
873 par.disabled := TRUE
874 END
875 END UndoGuard;
877 PROCEDURE RedoGuard* (VAR par: Dialog.Par);
878 VAR f: Windows.Window; opName: Stores.OpName;
879 BEGIN
880 Dialog.MapString("#System:Redo", par.label);
881 f := Windows.dir.Focus(Controllers.frontPath);
882 IF (f # NIL) & f.seq.CanRedo() THEN
883 f.seq.GetRedoName(opName);
884 Dialog.MapString(opName, opName);
885 Append(par.label, " ");
886 Append(par.label, opName)
887 ELSE
888 par.disabled := TRUE
889 END
890 END RedoGuard;
892 PROCEDURE PlainGuard* (VAR par: Dialog.Par);
893 VAR props: Properties.StdProp;
894 BEGIN
895 props := StdProp();
896 IF props.known * {Properties.style, Properties.weight} # {} THEN
897 par.checked := (Properties.style IN props.valid)
898 & (props.style.val = {}) & ({Fonts.italic, Fonts.underline, Fonts.strikeout} - props.style.mask = {})
899 & (Properties.weight IN props.valid) & (props.weight = Fonts.normal)
900 ELSE
901 par.disabled := TRUE
902 END
903 END PlainGuard;
905 PROCEDURE BoldGuard* (VAR par: Dialog.Par);
906 VAR props: Properties.StdProp;
907 BEGIN
908 props := StdProp();
909 IF Properties.weight IN props.known THEN
910 par.checked := (Properties.weight IN props.valid) & (props.weight = Fonts.bold)
911 ELSE
912 par.disabled := TRUE
913 END
914 END BoldGuard;
916 PROCEDURE ItalicGuard* (VAR par: Dialog.Par);
917 VAR props: Properties.StdProp;
918 BEGIN
919 props := StdProp();
920 IF Properties.style IN props.known THEN
921 par.checked := (Properties.style IN props.valid) & (Fonts.italic IN props.style.val)
922 ELSE
923 par.disabled := TRUE
924 END
925 END ItalicGuard;
927 PROCEDURE UnderlineGuard* (VAR par: Dialog.Par);
928 VAR props: Properties.StdProp;
929 BEGIN
930 props := StdProp();
931 IF Properties.style IN props.known THEN
932 par.checked := (Properties.style IN props.valid) & (Fonts.underline IN props.style.val)
933 ELSE
934 par.disabled := TRUE
935 END
936 END UnderlineGuard;
938 PROCEDURE StrikeoutGuard* (VAR par: Dialog.Par);
939 VAR props: Properties.StdProp;
940 BEGIN
941 props := StdProp();
942 IF Properties.style IN props.known THEN
943 par.checked := (Properties.style IN props.valid) & (Fonts.strikeout IN props.style.val)
944 ELSE
945 par.disabled := TRUE
946 END
947 END StrikeoutGuard;
949 PROCEDURE SizeGuard* (size: INTEGER; VAR par: Dialog.Par);
950 VAR props: Properties.StdProp;
951 BEGIN
952 props := StdProp();
953 IF Properties.size IN props.known THEN
954 par.checked := (Properties.size IN props.valid) & (size = props.size DIV Ports.point)
955 ELSE
956 par.disabled := TRUE
957 END
958 END SizeGuard;
960 PROCEDURE ColorGuard* (color: INTEGER; VAR par: Dialog.Par);
961 VAR props: Properties.StdProp;
962 BEGIN
963 props := StdProp();
964 IF Properties.color IN props.known THEN
965 par.checked := (Properties.color IN props.valid) & (color = props.color.val)
966 ELSE
967 par.disabled := TRUE
968 END
969 END ColorGuard;
971 PROCEDURE DefaultFontGuard* (VAR par: Dialog.Par);
972 VAR props: Properties.StdProp;
973 BEGIN
974 props := StdProp();
975 IF Properties.typeface IN props.known THEN
976 par.checked := (Properties.typeface IN props.valid) & (props.typeface = Fonts.default)
977 ELSE
978 par.disabled := TRUE
979 END
980 END DefaultFontGuard;
982 PROCEDURE TypefaceGuard* (VAR par: Dialog.Par);
983 VAR props: Properties.StdProp;
984 BEGIN
985 props := StdProp();
986 IF ~(Properties.typeface IN props.known) THEN par.disabled := TRUE END
987 END TypefaceGuard;
990 (* standard notifiers *)
992 PROCEDURE DefaultOnDoubleClick* (op, from, to: INTEGER);
993 VAR msg: Controllers.EditMsg; c: Containers.Controller;
994 BEGIN
995 IF (op = Dialog.pressed) & (from = 1) THEN
996 Controllers.SetCurrentPath(Controllers.frontPath);
997 c := Containers.Focus();
998 Controllers.ResetCurrentPath;
999 IF {Containers.noSelection, Containers.noCaret} - c.opts = {} THEN
1000 msg.op := Controllers.pasteChar;
1001 msg.char := 0DX; msg.modifiers := {};
1002 Controllers.ForwardVia(Controllers.frontPath, msg)
1003 END
1004 END
1005 END DefaultOnDoubleClick;
1008 PROCEDURE Init;
1009 BEGIN
1010 allocator := defaultAllocator;
1011 propEra := -1
1012 END Init;
1014 BEGIN
1015 Init
1016 END StdCmds.