ViewerTools.mesa, Edited by McGregor on September 2, 1982 9:34 am
Last Edited by: Maxwell, January 3, 1983 12:14 pm
DIRECTORY
InputFocus USING [GetInputFocus],
Rope USING [ROPE],
ViewerClasses USING [Viewer, ViewerRec],
ViewerOps USING [CreateViewer, FindViewer];
ViewerTools: CEDAR DEFINITIONS IMPORTS InputFocus, ViewerOps =
BEGIN OPEN ViewerClasses, ViewerOps;
---------- Finding and Creating Viewers ----------
FindExistingViewer:
PROC [fileName: Rope.
ROPE]
RETURNS [viewer: Viewer] =
INLINE {RETURN[FindViewer[fileName]]};
Returns NIL if none could be found. Use VirtualDesktops.FindExistingViewer to search past current desktop.
MakeNewTextViewer:
PROC [info: ViewerClasses.ViewerRec ← [], paint:
BOOL ←
TRUE]
RETURNS [viewer: Viewer] =
INLINE {RETURN[CreateViewer[flavor: $Text, info: info, paint: paint]]};
If info.parent=NIL then creates a top-level viewer. Specify name and file in info. Otherwise, pass wx, wy, ww, wh in info for size. For initial contents, pass a rope as the data field in info, or pass a filename in the file field.
See Buttons.mesa for creating new buttons.
See Containers.mesa for creating new labels.
See Labels.mesa for creating new labels.
--------
---------- Operations on Selections ----------
SelPos: TYPE = REF SelPosRec;
SelPosRec:
TYPE =
RECORD [
start, length: LONG INTEGER ← 0,
pendingDelete: BOOL ← FALSE,
caretPos: {before, after} ← before];
SetSelection:
PROC [viewer: Viewer, selection: SelPos ←
NIL] =
INLINE
{viewer.class.set[viewer, selection, TRUE, $SelPos]};
Set and scroll to a selection. For typescripts, NIL => caret at end. For other text viewers, NIL => entire contents in pending-delete mode. Works only for Tioga and Typescript viewers.
GetSelectedViewer:
PROC
RETURNS [viewer: Viewer] =
INLINE
{RETURN[InputFocus.GetInputFocus[].owner]} ;
Returns the selected viewer.
GetSelectionContents:
PROC
RETURNS [contents: Rope.
ROPE] =
INLINE {
v: Viewer = GetSelectedViewer[];
RETURN[IF v=NIL OR v.class.get=NIL THEN NIL ELSE NARROW[v.class.get[v, $SelChars]]]};
Returns the contents of the selected viewer's selection. Works only when the input focus is in a Tioga and Typescript viewer.
GetSelection:
PROC [viewer: Viewer]
RETURNS [selection: SelPos] =
INLINE
{RETURN[NARROW[viewer.class.get[viewer, $SelPos]]]};
Returns the selected viewer and the position of its selection. Works only for Tioga viewers!
--------
---------- Contents of Viewers ----------
Works for text and maybe some other classes
GetContents:
PROC [viewer: Viewer]
RETURNS [contents: Rope.
ROPE] =
INLINE {
RETURN[IF viewer.class.get=NIL THEN NIL ELSE NARROW[viewer.class.get[viewer]]]};
Returns the contents of a Tioga document (formatting information is omitted).
SetContents:
PROC [viewer: Viewer, contents: Rope.
ROPE, paint:
BOOL ←
TRUE] =
INLINE {
IF viewer.class.set#NIL THEN viewer.class.set[viewer, contents, paint]};
Set the contents of a Tioga document.
TiogaContents: TYPE = REF TiogaContentsRec ;
TiogaContentsRec:
TYPE =
RECORD [
contents: Rope.ROPE ← NIL,
formatting: Rope.ROPE ← NIL
] ;
GetTiogaContents:
PROC [viewer: Viewer]
RETURNS [contents: TiogaContents] =
INLINE {
RETURN[
IF viewer.class.get=
NIL
THEN
NIL
ELSE
NARROW[viewer.class.get[viewer,
$TiogaContents]]]};
Returns the contents and formatting of a Tioga document.
SetTiogaContents:
PROC [viewer: Viewer, contents: TiogaContents, paint:
BOOL ←
TRUE] =
INLINE {
IF viewer.class.set#NIL THEN viewer.class.set[viewer, contents, paint, $TiogaContents]};
Set the contents and formatting of a Tioga document.
InhibitUserEdits:
PROC [viewer: Viewer] =
INLINE {
viewer.class.set[viewer, NIL, TRUE, $ReadOnly]} ;
Prevent the user from editing a text viewer.
EnableUserEdits:
PROC [viewer: Viewer] =
INLINE {
viewer.class.set[viewer, NIL, TRUE, $ReadWrite]} ;
Allow the user to edit a text viewer.
--------
END.