ViewerToolsImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Doug Wyatt, March 28, 1985 5:10:33 pm PST
Russ Atkinson (RRA) June 17, 1985 3:18:15 pm PDT
DIRECTORY
InputFocus USING [GetInputFocus],
Rope USING [ROPE],
ViewerClasses USING [Viewer, ViewerRec],
ViewerOps USING [CreateViewer, FindViewer],
ViewerTools USING [SelPos, TiogaContents];
ViewerToolsImpl: CEDAR PROGRAM
IMPORTS InputFocus, ViewerOps
EXPORTS ViewerTools
= BEGIN OPEN ViewerTools;
ROPE: TYPE ~ Rope.ROPE;
Viewer: TYPE ~ ViewerClasses.Viewer;
ViewerRec: TYPE ~ ViewerClasses.ViewerRec;
Finding and Creating Viewers
FindExistingViewer: PUBLIC PROC [fileName: Rope.ROPE] RETURNS [viewer: Viewer] = {
RETURN[ViewerOps.FindViewer[fileName]]
};
MakeNewTextViewer: PUBLIC PROC [info: ViewerClasses.ViewerRec ← [],
paint: BOOLTRUE] RETURNS [viewer: Viewer] = {
RETURN[ViewerOps.CreateViewer[flavor: $Text, info: info, paint: paint]];
};
Operations on Selections
SetSelection: PUBLIC PROC [viewer: Viewer, selection: SelPos ← NIL] = {
IF viewer=NIL OR viewer.class.set=NIL THEN RETURN;
viewer.class.set[viewer, selection, TRUE, $SelPos]
};
GetSelectedViewer: PUBLIC PROC RETURNS [viewer: Viewer] = {
RETURN[InputFocus.GetInputFocus[].owner]
};
GetSelectionContents: PUBLIC PROC RETURNS [ROPE] = {
v: Viewer ~ GetSelectedViewer[];
IF v=NIL OR v.class.get=NIL THEN RETURN[NIL];
WITH v.class.get[v, $SelChars] SELECT FROM
contents: ROPE => RETURN[contents];
ENDCASE => RETURN[NIL];
};
GetSelection: PUBLIC PROC [viewer: Viewer] RETURNS [selection: SelPos] = {
IF viewer=NIL OR viewer.class.get=NIL THEN RETURN[NIL];
WITH viewer.class.get[viewer, $SelPos] SELECT FROM
selPos: SelPos => RETURN[selPos];
ENDCASE => RETURN[NIL];
};
Contents of Viewers
Works for text and maybe some other classes
GetContents: PUBLIC PROC [viewer: Viewer] RETURNS [ROPE] = {
IF viewer=NIL OR viewer.class.get=NIL THEN RETURN[NIL];
WITH viewer.class.get[viewer] SELECT FROM
contents: ROPE => RETURN[contents];
ENDCASE => RETURN[NIL];
};
SetContents: PUBLIC PROC [viewer: Viewer, contents: ROPE, paint: BOOLTRUE] = {
IF viewer=NIL OR viewer.class.set=NIL THEN RETURN;
viewer.class.set[viewer, contents, paint];
};
GetTiogaContents: PUBLIC PROC [viewer: Viewer] RETURNS [TiogaContents] = {
IF viewer=NIL OR viewer.class.get=NIL THEN RETURN[NIL];
WITH viewer.class.get[viewer, $TiogaContents] SELECT FROM
contents: TiogaContents => RETURN[contents];
ENDCASE => RETURN[NIL];
};
SetTiogaContents: PUBLIC PROC [viewer: Viewer, contents: TiogaContents,
paint: BOOLTRUE] = {
IF viewer=NIL OR viewer.class.set=NIL THEN RETURN;
viewer.class.set[viewer, contents, paint, $TiogaContents];
};
InhibitUserEdits: PUBLIC PROC [viewer: Viewer] = {
IF viewer=NIL OR viewer.class.set=NIL THEN RETURN;
viewer.class.set[viewer, NIL, FALSE, $ReadOnly];
};
EnableUserEdits: PUBLIC PROC [viewer: Viewer] = {
IF viewer=NIL OR viewer.class.set=NIL THEN RETURN;
viewer.class.set[viewer, NIL, FALSE, $ReadWrite];
};
END.