StyleToolSampleImpl.mesa
Written by Linda Gass August 31, 1982 2:59 pm
Last Edit by Linda Gass November 4, 1982 2:33 pm
Last Edited by: Plass, March 28, 1983 3:00 pm
DIRECTORY
Menus USING [CreateEntry, CreateMenu, InsertMenuEntry, Menu, MenuProc],
MessageWindow USING [Append, Blink],
Rope USING [ROPE],
StyleToolDefs,
StyleToolSample,
StyleToolToJaM USING [AppendFontInfoRope, AppendIndentInfoRope, AppendLeadingInfoRope,
 AppendMiscInfoRope, AppendPenaltyInfoRope, AppendPageInfoRope],
TextEdit USING [PutProp],
TextNode USING [FirstChild, Location, NarrowToTextNode, RefTextNode, Ref, Root],
TEditDocument USING [Selection, TEditDocumentData],
TEditOps USING [GetSelData],
TEditSelection USING [InsertionPoint],
ViewerClasses USING [Viewer, ViewerClass, ViewerClassRec],
ViewerMenus USING [Close],
ViewerOps USING [PaintViewer, SetMenu],
ViewerTools USING [GetSelectedViewer, MakeNewTextViewer, SetContents];
StyleToolSampleImpl: CEDAR PROGRAM
IMPORTS Menus, MessageWindow, StyleToolToJaM, TEditOps, TEditSelection, TextEdit, TextNode, ViewerMenus, ViewerOps, ViewerTools
EXPORTS StyleToolSample =
BEGIN OPEN StyleToolDefs;
ApplyFormat: PUBLIC PROCEDURE [handle: StyleToolHandle] = {
child: TextNode.RefTextNode;
root: TextNode.Ref;
jamRope: Rope.ROPE;
IF handle.sample.viewer = NIL THEN CreateSample[handle];
child ← GetDataNode[handle.sample.viewer];
root ← TextNode.Root[child];
jamRope ← GetJaMRope[handle];
TextEdit.PutProp[child, "Postfix", jamRope];
ViewerOps.PaintViewer[handle.sample.viewer, all];
};
ApplyToSelection: PUBLIC PROCEDURE [handle: StyleToolHandle] = {
pSel: TEditDocument.Selection = TEditOps.GetSelData[];
v: ViewerClasses.Viewer;
selection: TextNode.Location;

make sure the user has actually made a selection
IF ~CheckPSel[pSel] THEN RETURN;  -- Checks that a selection has been made
now find the node
selection ← TEditSelection.InsertionPoint[];
v ← ViewerTools.GetSelectedViewer[];
IF selection.node # NIL THEN {
 jamCode: Rope.ROPE ← GetJaMRope[handle];
 TextEdit.PutProp[selection.node, "Postfix", jamCode];
 ViewerOps.PaintViewer[v, all];
 }
ELSE { -- indicate an error condition
 MessageWindow.Append["Sorry can't do it. Node is NIL", TRUE];
 MessageWindow.Blink[];
 };
};
CheckPSel: PROCEDURE [pSel: TEditDocument.Selection, typescriptOK: BOOLFALSE]
RETURNS [ok: BOOLEAN] = {
OPEN MessageWindow;
IF pSel#NIL AND pSel.viewer#NIL AND
  (pSel.viewer.class.flavor=$Text OR (typescriptOK AND pSel.viewer.class.flavor=$Typescript))
  THEN RETURN [TRUE]
ELSE {
  Append["Please make a text selection.",TRUE];
  Blink[];
  RETURN [FALSE];
  };
  };
GetDataNode: PRIVATE PROC [arg: ViewerClasses.Viewer] RETURNS [TextNode.RefTextNode] = {
tdd: TEditDocument.TEditDocumentData = NARROW[arg.data];
RETURN [TextNode.NarrowToTextNode[TextNode.FirstChild[tdd.text]]] };
CreateSample: PRIVATE PROCEDURE [handle: StyleToolHandle] = BEGIN
sampleMenu: Menus.Menu;
handle.sample.viewer ← ViewerTools.MakeNewTextViewer[[
 name: "Sample",
 column: left,
 scrollable: TRUE,
 iconic: FALSE,
 openHeight: 300
 ]];
sampleMenu ← Menus.CreateMenu[lines:1];
Menus.InsertMenuEntry[menu: sampleMenu, entry: Menus.CreateEntry[name: "SampleText",
 proc: SampleTextProc, clientData: handle,
 documentation: "Replaces contents of sample viewer with sample text"]];
Menus.InsertMenuEntry[menu: sampleMenu, entry: Menus.CreateEntry[name: "Close",
 proc: ViewerMenus.Close, clientData: handle]];
--Menus.InsertMenuEntry[menu: sampleMenu, entry: Menus.CreateEntry[name: "Destroy",
-- proc: DestroyProc, clientData: handle, fork: TRUE]];
ViewerOps.SetMenu[handle.sample.viewer, sampleMenu];
DisplaySampleText[handle];
END;
SampleTextProc: Menus.MenuProc = {
handle: StyleToolHandle ← NARROW[clientData];
DisplaySampleText[handle];
};
DestroyProc: Menus.MenuProc = { (no longer used)
handle: StyleToolHandle ← NARROW[clientData];
IF ~MessageWindow.Confirm["Destroying Sample Viewer ... "] THEN RETURN;
ViewerOps.DestroyViewer[handle.sample.viewer];
handle.sample.viewer ← NIL;
};
DisplaySampleText: PROCEDURE [handle: StyleToolHandle] = BEGIN
sampleText: Rope.ROPE ← "What is Style? Up to now, we have taken the term for granted and not attempted to take an accurate measure of its meaning. The dictionary defines style as 'a particular distinctive mode or form of construction or execution in any work or art.' When a layout is successful, we consider its style to be a blend of the accumulated experience, personal taste, and creative force of the designer. A careful distinction is needed between the style arrived at by designers working toward a common objective and the merely fashionable solutions that grow out of imitation.";

ViewerTools.SetContents[handle.sample.viewer, sampleText];
END;
GetJaMRope: PRIVATE PROCEDURE [handle: StyleToolHandle] RETURNS [Rope.ROPE] = BEGIN
jamRope: Rope.ROPE ← "";
found: BOOLEAN;
[jamRope, found] ← StyleToolToJaM.AppendFontInfoRope[handle, handle.default, jamRope];
IF found THEN {
 jamRope ← StyleToolToJaM.AppendIndentInfoRope[handle, handle.default, jamRope];
 jamRope ← StyleToolToJaM.AppendLeadingInfoRope[handle, handle.default, jamRope];
 jamRope ← StyleToolToJaM.AppendMiscInfoRope[handle, handle.default, jamRope];
 jamRope ← StyleToolToJaM.AppendPenaltyInfoRope[handle, handle.default, jamRope];
 jamRope ← StyleToolToJaM.AppendPageInfoRope[handle, handle.default, jamRope];
 };
RETURN[jamRope];
END;
END.