File: NutViewer.mesa
Contents: Handy Squirrel procedures for building database application Viewers.
Created by: Rick Cattell on 11-Dec-81 12:29:29
Last edited by:
Cattell, July 5, 1983 4:48 pm
Willie-Sue on: January 21, 1983 8:48 am
Donahue, July 29, 1983 9:41 am
DIRECTORY
DB,
Icons USING [IconFlavor],
MBQueue USING [Queue],
Nut USING [NutType],
Buttons, Menus, Rope, ViewerClasses, VFonts;
NutViewer:
CEDAR
DEFINITIONS
IMPORTS VFonts =
BEGIN OPEN DB;
Viewer: TYPE = ViewerClasses.Viewer;
ROPE: TYPE = Rope.ROPE;
Queue: TYPE = MBQueue.Queue;
iconAttribute: Attribute;
********************************************************************
Message procedures for interacting with user (in NutViewerMiscImpl.mesa).
********************************************************************
Message:
PUBLIC
PROC[v: Viewer, msg1, msg2, msg3, msg4:
ROPE←
NIL];
If the top level viewer in which v is nested has a $Typescript property, then
prints the concatenated values msg1 through msg4 on the stream that is the value
of that property. Otherwise, if the Squirrel window is on the screen, prints the
messages in the Squirrel window. Otherwise, sprint the messages in the Message area.
Error:
PUBLIC
PROC[v: Viewer, msg1, msg2, msg3, msg4:
ROPE←
NIL];
Same as Message proc above, but blinks the screen first.
MessageRope:
PUBLIC
PROC[v: Viewer, msg:
ROPE←
NIL];
Prints the given msg as with Message proc above, but without CR.
********************************************************************
Handy procedures for dealing with viewers (in NutViewerMiscImpl.mesa).
These procedures can be used by applications to created menus, buttons, labels, and text
viewers which are automatically placed at the next x/y position in the parent viewer.
In the case of menus and buttons, they are automatically given a top-level catch phrase
for database errors and are synchronized with an MBQueue specified as argument.
A default MBQueue may be used, or the synchronization and catch phrases may be
omitted by passing a NIL MBQueue. Some examples of the use of these procedures:
nV: Viewer← Initialize[parent];
nV← MakeButton[DBQueue[], "Name: ", SelectProc, nV]; (Makes button on top line)
nV← MakeTextViewer[sib: nV, fullLine: FALSE]; (Make text label on same line)
[]← MakeTypeScript[nV]; (Make a typescript at the end of the window).
********************************************************************
Initialize:
PROC[parent: Viewer]
RETURNS [nV: Viewer];
Initializes a viewer so that MakeButton, MakeLabel, MakeTextViewer, etc., may be used.
The argument nV returned is passed along through each call to keep track of sibling pos'n,
e.g.: nV← MakeLabel["Foo", nV].
MakeLabel:
PROC[name:
ROPE, sib: Viewer, newLine:
BOOL←
FALSE]
RETURNS [nV: Viewer];
The sib is a viewer to the left or above the label to be made, according to newLine.
MakeTextViewer:
PROC[sib: Viewer, w:
INTEGER← 0, fullLine:
BOOL←
FALSE]
RETURNS [nV: Viewer];
Creates a text viewer, next right on the same line as v, or full width of next line
if fullLine=TRUE
MakeButton:
PROC[q: Queue, name:
ROPE, proc: Buttons.ButtonProc, sib: Viewer, data:
REF
ANY←
NIL, border:
BOOL←
FALSE, width:
INTEGER← 0, guarded:
BOOL←
FALSE, font: VFonts.Font ← VFonts.defaultFont, newLine:
BOOL←
FALSE]
RETURNS [nV: Viewer];
Creates a new button, to the right or below sib, according to newLine.
MakeMenuEntry:
PROC[q: Queue, name:
ROPE, proc: Menus.MenuProc, clientData:
REF
ANY←
NIL, documentation:
REF
ANY←
NIL, fork:
BOOL←
TRUE, guarded:
BOOL←
FALSE]
RETURNS[Menus.MenuEntry];
Creates a menu entry, suitable to use as follows:
Menus.AppendMenuEntry[myMenu, MakeMenuEntry[...]].
Main purpose of this procedure is to allow menu items to be queued.
MakeTypescript:
PROC[sib: Viewer]
RETURNS [ts: Viewer];
The sib is sibling to create TS after, this must be last child of non-NIL sib.parent.
MakeRuler:
PROC[sib: Viewer, h:
INTEGER← 1]
RETURNS [r: Viewer];
Put a h-bit wide line after sib. We assume sib.parent#NIL.
MakeBigTextBox:
PUBLIC
PROC[sib: Viewer, contents:
ROPE]
RETURNS [nV: Viewer];
Makes editable text viewer taking rest of sib.parent's viewer, suitable for msg body or
whatever. The sib is a sibling to create text box after, this must be last child of sib.parent.
Again, we assume sib.parent#NIL.
DBQueue:
PROC
RETURNS[Queue];
Returns Squirrel's default Queue. E.g., can be used as follows:
nV ← MakeButton[DBQueue[], "Foo", FooProc, nV].
NextTextViewer:
PROC[sib: Viewer]
RETURNS [nV: Viewer] =
INLINE {
Backwards compatible: creates text viewer on line following sib, full width of sib.parent
RETURN[MakeTextViewer[sib, , TRUE]]};
NextRightTextViewer:
PROC[sib: Viewer, w:
INTEGER]
RETURNS [nV: Viewer] =
INLINE {
Backwards compatible: creates a text viewer, next right on the same line as v
RETURN[MakeTextViewer[sib, w, FALSE]]};
DBNotifier:
PUBLIC
PROC [q: MBQueue.Queue];
The notifier for database actions; tries to recover from DB.Error[Nullfied] and DB.Aborted,
calling Message procedure above to notify user. This notifier is automatically used on any
buttons created using AnotherButton below, if defaultDBQueue is used.
DefaultFreezeProc: Menus.MenuProc;
A standard proc for freezing a Nut (make it not reuseable).
ProcessSelection: Buttons.ButtonProc;
A standard ButtonProc that assumes the button's REF ANY data is the FieldHandle above.
Insures attribute of tuple is entity-valued and non-NIL, then calls Nut.Display on it.
FieldHandle: TYPE = REF FieldObject;
FieldObject: TYPE = RECORD[ tuple: Relship, attribute: Attribute ];
***************** Mapping between entities and viewers *******************
FindViewerForEntity:
PROCEDURE[e: Entity, segment: Segment ←
NIL]
RETURNS[viewer: ViewerClasses.Viewer];
Tries to find a viewer displaying the given entity.
ConvertViewerToEntity:
PROCEDURE[v: ViewerClasses.Viewer, create:
BOOL ←
TRUE]
RETURNS[e: Entity, name:
ROPE];
Guesses at an appropriate entity for the given viewer.
Returns the name (in DBNames format) if the entity would be in a segment that is
not open. If the entity is a ToolViewer or a TextViewer, then it will be added to the
database if create is TRUE; otherwise it will simply return the name
GetNutInfo:
PROC[v: Viewer]
RETURNS[segment: Segment, domain: Domain, entity:
ROPE];
Returns segment, domain, and entity name (if any) using the $Segment, $Domain, and
$Entity properties set up by the [default] create proc.
ToolViewer: Rope.ROPE; -- the name of the tool viewer domain used in Find and Convert
TextViewer: Rope.ROPE; -- the name of the text viewer domain used in Find and Convert
***************** Icon management (NutViewerIconImpl) *******************
SetIcon:
PROC[e: Entity, iconFile:
ROPE, fileIndex:
CARDINAL];
sets an icon for an entity or a domain
NewIcon: PROC[file: ROPE, index: CARDINAL] RETURNS[Icons.IconFlavor];
GetIcon:
PROC[e: Entity, seg:
DB.Segment ←
NIL]
RETURNS[Icons.IconFlavor];
gets e's icon, else gets DomainOf[e]'s icon, else returns the acorn icon
GetIconFromName:
PROC[ name:
ROPE ]
RETURNS[Icons.IconFlavor];
assumes the name is in the form produced by DBNames; same result as GetIcon, but
works if the entity doesn't exist
***************** Nut Viewers (NutViewerPrivateImpl) *******************
FindViewer: PROC[type: Nut.NutType, domain: Domain, eName: ROPE, seg: Segment] RETURNS[Viewer];
FindSpawned: PROC[v: Viewer] RETURNS[Viewer];
SetSpawned: PROC[parent, spawned: Viewer];
**********************************************************
END.