-- 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, June 3, 1983 12:31 pm
-- Willie-Sue on: January 21, 1983 8:48 am
-- Donahue, May 31, 1983 4:44 pm

DIRECTORY
DB,
Icons USING [IconFlavor],
MBQueue USING [Queue],
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: BOOLFALSE] 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: BOOLFALSE] 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 ANYNIL, border: BOOLFALSE, width: INTEGER← 0,
guarded: BOOLFALSE, font: VFonts.Font ← VFonts.defaultFont,
newLine: BOOLFALSE] 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 ANYNIL, documentation: REF ANYNIL, fork: BOOLTRUE,
guarded: BOOLFALSE] 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: DB.Entity, segment: DB.Segment ← NIL] RETURNS[viewer: ViewerClasses.Viewer];
-- Tries to find a viewer displaying the given entity.

ConvertViewerToEntity: PROCEDURE[
v: ViewerClasses.Viewer] RETURNS[e: DB.Entity];
-- Guesses at an appropriate entity for the given viewer.
-- If a TextViewer or a ToolViewer is found, then an entity with that name will be created
-- in the $Squirrel segment.

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

-- **********************************************************
END.