<> <> <> <> <> 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], 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; <> IF ~CheckPSel[pSel] THEN RETURN; -- Checks that a selection has been made <> 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: BOOL _ FALSE] 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]]; <> <> ViewerOps.SetMenu[handle.sample.viewer, sampleMenu]; DisplaySampleText[handle]; END; SampleTextProc: Menus.MenuProc = { handle: StyleToolHandle _ NARROW[clientData]; DisplaySampleText[handle]; }; <> <> <> <> <> <<};>> 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.