IPTool.mesa
Last edited by:
Doug Wyatt, March 9, 1984 4:26:19 pm PST
DIRECTORY
BasicTime USING [GMT],
Buttons USING [Button, ButtonProc, Create],
Commander USING [CommandProc, Register],
Containers USING [ChildXBound, Container, Create],
FS USING [ComponentPositions, ExpandName],
Icons USING [IconFlavor, NewIconFromFile],
Imager USING [Context, Create, NewPage, SpecialOp],
ImagerBridge USING [SetViewFromGraphicsContext],
ImagerPD USING [Gnat, Hornet, PDFileDescription, PlateMaker, Puffin, Raven, ReticleMaker],
IO USING [Close, int, PutChar, PutF, PutFR, PutRope, rope, STREAM, time],
IP USING [State],
IPExtras USING [DoPage, OpenMaster, PageCount],
IPUtils USING [ToEncoded, ToWritten],
Loader USING [BCDBuildTime],
Menus USING [AppendMenuEntry, CreateEntry, CreateMenu, Menu, MenuProc],
Process USING [Pause, SecondsToTicks],
Rope USING [Concat, Find, ROPE, Substr],
Rules USING [Create, Rule],
ViewerClasses USING [PaintProc, Viewer, ViewerClass, ViewerClassRec],
ViewerIO USING [CreateViewerStreams],
ViewerOps USING [CreateViewer, PaintViewer, RegisterViewerClass],
ViewerTools USING [MakeNewTextViewer, GetContents, SetContents, SetSelection];
IPTool: CEDAR MONITOR
LOCKS data USING data: Data
IMPORTS Buttons, Commander, Containers, FS, Icons, Imager, ImagerBridge, ImagerPD, IO, IPExtras, IPUtils, Loader, Menus, Process, Rope, Rules, ViewerIO, ViewerOps, ViewerTools = {
-- Here is the layout of the tool --
--========================================================================--
-- Interpress --
--========================================================================--
-- Load Show Next Write Read LoadSelection --
--========================================================================--
-- Master: Test.Interpress Written: Test.IPWritten --
-- Page: 2 --
--========================================================================--
-- Interpress Tool of March 31, 1983 --
-- Test.Interpress -> WTest.Interpress --
-- --
-- --
-- --
-- --
--========================================================================--
-- Here is the layout of a page viewer --
--========================================================================--
-- Test.Interpress, page 3 --
--========================================================================--
-- --
-- --
-- . . . --
-- --
--========================================================================--
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE = IO.STREAM;
Viewer: TYPE = ViewerClasses.Viewer;
Button: TYPE = Buttons.Button;
Data: TYPE = REF DataRep;
DataRep: TYPE = MONITORED RECORD [ -- the data for a particular tool instance
outer: Containers.Container ← NIL, -- handle for the enclosing container
busy: BOOLFALSE,
height: NAT ← 0, -- height measured from the top of the container
logViewer: Viewer, -- contains error log
log: STREAM, -- output stream for writing to error log
masterButton: Button, -- Master: button
masterField: Viewer, -- contains name of Master file
writtenButton: Button, -- Written: button
writtenField: Viewer, -- contains name of Written file
pageButton: Button, -- Page: button
pageField: Viewer, -- contains page number
page: Viewer, -- viewer for showing a page
masterName: ROPE, -- name of current master
pageNumber: NAT, -- current page number
state: IP.State -- state of the Interpress interpreter
];
Lock: ENTRY PROC[data: Data] RETURNS[BOOL] = INLINE {
IF data.busy THEN RETURN[FALSE]
ELSE RETURN[data.busy ← TRUE];
};
Unlock: ENTRY PROC[data: Data] = INLINE {
data.busy ← FALSE
};
lineHeight: CARDINAL = 15; -- how tall to make each line of items
lineLeading: CARDINAL = 2; -- vertical leading space between lines
totalWidth: CARDINAL = 444; -- width of the entire viewer
margin: CARDINAL = 8; -- left and right margins
entryHSpace: CARDINAL = 10; -- horizontal space between items in a line
MakeIPTool: Commander.CommandProc = { CreateTool[] };
CreateTool: PROC = {
data: Data = NEW[DataRep];
menu: Menus.Menu = MakeMenu[data];
buildTime: BasicTime.GMT ~ Loader.BCDBuildTime[CreateTool];
data.outer ← Containers.Create[[-- construct the outer container'
name: "Interpress Tool", -- name displayed in the caption
menu: menu,
iconic: FALSE,
column: right, -- initially in the right column
scrollable: FALSE
]];
build each (sub)viewer in turn
MakeFilePart[data];
MakeRule[data, 1];
MakeLogPart[data, 100];
data.page ← CreatePage[data];
data.log.PutF["Interpress Tool of %g\n", IO.time[buildTime]];
ViewerOps.PaintViewer[data.outer, all]; -- reflect above change
};
PageData: TYPE = REF PageDataRep;
PageDataRep: TYPE = RECORD[w: NAT]; -- instance data for Interpress viewers
CreatePage: PROC[data: Data] RETURNS[ViewerClasses.Viewer] = {
viewer: ViewerClasses.Viewer = ViewerOps.CreateViewer[
flavor: $Page,
info: [
name: "Interpress Page",
data: data,
iconic: FALSE,
column: left,
scrollable: FALSE
]
];
RETURN[viewer];
};
LongOperation: PROC[log: STREAM, n: NAT] = {
THROUGH [0..n) DO
log.PutChar['.];
Process.Pause[Process.SecondsToTicks[1]];
ENDLOOP;
};
MakeMenu: PROC[data: Data] RETURNS[Menus.Menu] = {
menu: Menus.Menu = Menus.CreateMenu[];
Menus.AppendMenuEntry[menu: menu,
entry: Menus.CreateEntry[name: "Load",
proc: LoadProc, clientData: data]
];
Menus.AppendMenuEntry[menu: menu,
entry: Menus.CreateEntry[name: "Show",
proc: ShowProc, clientData: data]
];
Menus.AppendMenuEntry[menu: menu,
entry: Menus.CreateEntry[name: "Next",
proc: NextProc, clientData: data]
];
Menus.AppendMenuEntry[menu: menu,
entry: Menus.CreateEntry[name: "Print",
proc: PrintProc, clientData: data]
];
Menus.AppendMenuEntry[menu: menu,
entry: Menus.CreateEntry[name: "PrintAll",
proc: PrintAllProc, clientData: data]
];
Menus.AppendMenuEntry[menu: menu,
entry: Menus.CreateEntry[name: "Write",
proc: WriteProc, clientData: data]
];
Menus.AppendMenuEntry[menu: menu,
entry: Menus.CreateEntry[name: "Read",
proc: ReadProc, clientData: data]
];
Menus.AppendMenuEntry[menu: menu,
entry: Menus.CreateEntry[name: "LoadSelection",
proc: LoadSelectionProc, clientData: data]
];
RETURN[menu];
};
PaintPageViewer: PROC[data: Data] = {
page: Viewer = data.page;
page.name ← IO.PutFR["%g, page %g", IO.rope[data.masterName], IO.int[data.pageNumber]];
ViewerOps.PaintViewer[viewer: page, hint: all];
[] ← IPExtras.DoPage[data.state, data.pageNumber];
};
pdType: ATOM ← $Hornet;
GetPDFileDescription: PROC[fileName: ROPE] RETURNS[ImagerPD.PDFileDescription] ~ {
RETURN[SELECT pdType FROM
$Hornet => ImagerPD.Hornet[fileName],
$Raven => ImagerPD.Raven[fileName],
$Gnat => ImagerPD.Gnat[fileName],
$PlateMaker => ImagerPD.PlateMaker[fileName],
$ReticleMaker => ImagerPD.ReticleMaker[fileName],
$Puffin => ImagerPD.Puffin[fileName],
ENDCASE => ImagerPD.Hornet[fileName]]
};
PrintPage: PROC[data: Data] = {
log: STREAM ~ data.log;
self: IP.State ~ data.state;
screen: Imager.Context ~ self.imager;
masterName: ROPE ~ data.masterName;
pdName: ROPE ~ PDName[masterName];
page: NAT ~ data.pageNumber;
pd: Imager.Context ← NIL;
log.PutF["Writing page %g of %g to %g ...",
IO.int[page], IO.rope[masterName], IO.rope[pdName]];
self.imager ← pd ← Imager.Create[$PD, GetPDFileDescription[pdName]];
[] ← IPExtras.DoPage[self, page];
[] ← Imager.SpecialOp[pd, $Close, NIL];
log.PutRope["done.\n"];
self.imager ← screen;
};
PrintAll: PROC[data: Data] = {
log: STREAM ~ data.log;
self: IP.State ~ data.state;
screen: Imager.Context ~ self.imager;
masterName: ROPE ~ data.masterName;
pdName: ROPE ~ PDName[masterName];
count: NAT ~ IPExtras.PageCount[self];
pd: Imager.Context ← NIL;
log.PutF["Writing %g to %g (%g pages) ...",
IO.rope[masterName], IO.rope[pdName], IO.int[count]];
self.imager ← pd ← Imager.Create[$PD, GetPDFileDescription[pdName]];
FOR page: NAT IN[1..count] DO
log.PutF[" %g", IO.int[page]];
[] ← IPExtras.DoPage[self, page];
IF page<count THEN Imager.NewPage[pd];
ENDLOOP;
[] ← Imager.SpecialOp[pd, $Close, NIL];
log.PutRope[" done.\n"];
self.imager ← screen;
};
PDName: PROC[name: ROPE] RETURNS[ROPE] = {
fname: ROPE; cp: FS.ComponentPositions;
[fullFName: fname, cp: cp] ← FS.ExpandName[name];
RETURN[fname.Substr[len: cp.base.start+cp.base.length].Concat[".pd"]];
};
Extend: PROC[name: ROPE, ext: ROPE] RETURNS[ROPE] = {
RETURN[IF name.Find["."]<0 THEN name.Concat[ext] ELSE name];
};
LoadMaster: PROC[data: Data] = {
name: ROPE = ViewerTools.GetContents[data.masterField];
file: ROPE = Extend[name, ".Interpress"];
log: STREAM = data.log;
log.PutF["Loading %g...", IO.rope[file]];
data.state ← IPExtras.OpenMaster[file, Imager.Create[$LFDisplay]];
log.PutRope["done.\n"];
data.state.log ← log;
data.masterName ← name;
data.pageNumber ← 1;
};
Do: PROC[proc: PROC[Data], data: Data] = {
IF Lock[data] THEN {
proc[data ! UNWIND => Unlock[data]];
Unlock[data];
};
};
LoadProc: Buttons.ButtonProc = {
Do[LoadMaster, NARROW[clientData]];
};
ShowProc: Menus.MenuProc = {
Do[PaintPageViewer, NARROW[clientData]];
};
PrintProc: Menus.MenuProc = {
Do[PrintPage, NARROW[clientData]];
};
PrintAllProc: Menus.MenuProc = {
Do[PrintAll, NARROW[clientData]];
};
NextProc: Menus.MenuProc = {
Next: PROC[data: Data] = {
n: NAT = data.pageNumber;
count: NAT = IPExtras.PageCount[data.state];
SELECT mouseButton FROM
red, yellow => {
IF n<count THEN {
data.pageNumber ← n+1;
PaintPageViewer[data];
};
};
blue => {
IF n>1 THEN {
data.pageNumber ← n-1;
PaintPageViewer[data];
};
};
ENDCASE;
};
Do[Next, NARROW[clientData]];
};
WriteProc: Menus.MenuProc = {
Write: PROC[data: Data] = {
master: ROPE = Extend[ViewerTools.GetContents[data.masterField], ".Interpress"];
written: ROPE = Extend[ViewerTools.GetContents[data.writtenField], ".Interpress"];
log: STREAM = data.log;
Dot: PROC = { log.PutChar['.] };
log.PutRope[IO.PutFR["%g -> %g ", IO.rope[master], IO.rope[written]]];
IPUtils.ToWritten[master, written, Dot];
log.PutRope["done\n"];
};
Do[Write, NARROW[clientData]];
};
ReadProc: Menus.MenuProc = {
Read: PROC[data: Data] = {
master: ROPE = Extend[ViewerTools.GetContents[data.masterField], ".Interpress"];
written: ROPE = Extend[ViewerTools.GetContents[data.writtenField], ".Interpress"];
log: STREAM = data.log;
Dot: PROC = { log.PutChar['.] };
log.PutRope[IO.PutFR["%g -> %g ", IO.rope[written], IO.rope[master]]];
IPUtils.ToEncoded[written, master, Dot];
log.PutRope["done\n"];
};
Do[Read, NARROW[clientData]];
};
LoadSelectionProc: Menus.MenuProc = {
LoadSelection: PROC[data: Data] = {
selection: ROPE = ViewerTools.GetSelectionContents[];
log: STREAM = data.log;
ViewerTools.SetContents[data.masterField, "Selection"];
log.PutRope[" Parsing selection ..."];
{ IPUtils.RopeToMaster[selection, "Selection.Interpress" ! ANY => GOTO Fail];
log.PutRope["ok\n"];
LoadMaster[data];
EXITS Fail => log.PutRope["failed\n"];
};
};
Do[LoadSelection, NARROW[clientData]];
};
MakeRule: PROC[data: Data, height: NAT] = {
rule: Rules.Rule ← Rules.Create[ [ -- create a horizontal rule to separate sections
parent: data.outer,
wy: data.height,
ww: data.outer.cw,
wh: height
]];
Containers.ChildXBound[data.outer, rule];
data.height ← rule.wy + rule.wh + lineLeading; -- spacing after rule
};
TSOpen: PROC[viewer: Viewer] RETURNS[STREAM] = {
in, out: STREAM;
[in: in, out: out] ← ViewerIO.CreateViewerStreams[name: NIL,
viewer: viewer, backingFile: NIL, editedStream: FALSE];
in.Close[];
RETURN[out];
};
MakeLogPart: PROC[data: Data, height: NAT] = {
viewer: Viewer = ViewerOps.CreateViewer[
flavor: $Typescript,
info: [parent: data.outer,
ww: totalWidth, wy: data.height, wh: height,
scrollable: TRUE, border: FALSE]
];
Containers.ChildXBound[data.outer, viewer];
data.logViewer ← viewer;
data.log ← TSOpen[viewer]; -- open an output stream on the typescript
data.height ← viewer.wy + viewer.wh + lineLeading; -- spacing after typescript
};
buttonBorders: BOOLTRUE;
MakeFilePart: PROC[data: Data] = {
middle: NAT = totalWidth/2;
rightEdge: NAT = totalWidth;
x: NAT ← margin; -- current x
y: NAT ← data.height; -- current y
container: Viewer = data.outer;
AddButton: PROC[name: ROPE, proc: Buttons.ButtonProc] RETURNS[Button] = {
button: Button = Buttons.Create[
info: [parent: container, name: name,
wx: x, wy: y, wh: lineHeight,
border: buttonBorders],
proc: proc, clientData: data
];
x ← button.wx+button.ww+entryHSpace;
RETURN[button];
};
AddPrompt: PROC[name: ROPE, proc: Buttons.ButtonProc] RETURNS[Button] = {
button: Button = Buttons.Create[
info: [parent: container, name: name,
wx: x, wy: y, wh: lineHeight,
border: FALSE],
proc: proc, clientData: data
];
x ← button.wx+button.ww; -- no extra space
RETURN[button];
};
AddField: PROC[nextX: NAT] RETURNS[Viewer] = {
field: Viewer = ViewerTools.MakeNewTextViewer[
info: [parent: container,
wx: x, wy: y+1, ww: nextX-entryHSpace-x, wh: lineHeight,
scrollable: TRUE, border: FALSE]
];
x ← nextX;
RETURN[field];
};
NextLine: PROC = { y ← y+lineHeight+lineLeading; x ← margin; };
data.masterButton ← AddPrompt["Master:", MasterPrompt];
data.masterField ← AddField[rightEdge];
NextLine[];
data.writtenButton ← AddPrompt["Written:", WrittenPrompt];
data.writtenField ← AddField[rightEdge];
NextLine[];
data.height ← y;
};
MasterPrompt: Buttons.ButtonProc = {
data: Data = NARROW[clientData];
IF mouseButton=blue THEN ViewerTools.SetContents[data.masterField, NIL];
ViewerTools.SetSelection[data.masterField]; -- force the selection
};
WrittenPrompt: Buttons.ButtonProc = {
data: Data = NARROW[clientData];
IF mouseButton=blue THEN ViewerTools.SetContents[data.writtenField, NIL];
ViewerTools.SetSelection[data.writtenField]; -- force the selection
};
PagePrompt: Buttons.ButtonProc = {
data: Data = NARROW[clientData];
IF mouseButton=blue THEN ViewerTools.SetContents[data.pageField, NIL];
ViewerTools.SetSelection[data.pageField]; -- force the selection
};
PutLine: PROC[data: Data, rope: ROPE] = {
log: STREAM = data.log;
log.PutRope[rope];
log.PutChar['\n];
};
PaintPage: ViewerClasses.PaintProc = {
data: Data = NARROW[self.data];
state: IP.State = data.state;
IF state#NIL THEN ImagerBridge.SetViewFromGraphicsContext[state.imager, context];
};
pageIcon: Icons.IconFlavor = Icons.NewIconFromFile["Interpress.icons", 2];
pageClass: ViewerClasses.ViewerClass = NEW[ViewerClasses.ViewerClassRec ← [
paint: PaintPage, icon: pageIcon]];
Register the Interpress class of viewer with the Window Manager
ViewerOps.RegisterViewerClass[$Page, pageClass];
Register a command with the executive.
Commander.Register[key: "Interpress", proc: MakeIPTool,
doc: "Create an Interpress tool" ];
}.