PrintManipImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
BJackson, October 29, 1986 10:03:36 pm PST
Bloomenthal, October 29, 1986 10:03:43 pm PST
DIRECTORY Buttons, CedarProcess, Commander, Imager, ImagerBackdoor, IO, PrintManip, TypeScript, UserProfile, ViewerClasses, ViewerIO, ViewerOps;
PrintManipImpl: CEDAR MONITOR
IMPORTS Buttons, CedarProcess, Commander, Imager, ImagerBackdoor, IO, TypeScript, UserProfile, ViewerIO, ViewerOps
EXPORTS PrintManip
~ BEGIN
OPEN PrintManip;
Globals
AutoOpen:    ROPE ~ "HardcopyWatcher.AutoOpen";
pendingPrintRequests: PrintRequestList ← NIL;
printManipViewerClass: ViewerClasses.ViewerClass;
watcher:     Data ← NIL;
Type Declarations
Viewer: TYPE ~ ViewerClasses.Viewer;
ButtonList: TYPE ~ LIST OF Viewer;
Data: TYPE ~ REF DataRec;
DataRec: TYPE ~ RECORD [
viewer: Viewer ← NIL,
buttons: ButtonList ← NIL,
typeScript: Viewer ← NIL,
typeScriptIn: STREAMNIL,
typeScriptOut: STREAMNIL,
autoOpen: BOOLFALSE,
printRequests: PrintRequestList ← NIL
];
Procedures
ClearWatcher: ENTRY PROC ~ {
watcher ← NIL;
};
ConditionallySetWatcher: ENTRY PROC [new: Data] RETURNS [old: Data] ~ {
old ← watcher;
IF watcher = NIL THEN watcher ← new;
};
PrintManipCmd: Commander.CommandProc ~ {
data: Data ← NEW[DataRec];
otherGuy: Data ← ConditionallySetWatcher[data];
IF otherGuy # NIL THEN {
UpdateViewer[otherGuy, TRUE];
RETURN;
};
data.autoOpen ← UserProfile.Boolean[AutoOpen, FALSE];
data.viewer ← ViewerOps.CreateViewer[
flavor: $PrintManip,
info: [name: "Print Request Manipulation", data: data]];
data.typeScript ← TypeScript.Create[[parent: data.viewer, border: TRUE, wh: 60]];
[data.typeScriptIn, data.typeScriptOut] ← ViewerIO.CreateViewerStreams[NIL, data.typeScript, "///Temp/PrintManip.TypeScript"];
TypeScriptWrite[data, "hi there teddy bear\n"];
TypeScriptWrite[data, "hi there teddy bare\n"];
UpdateViewer[data];
};
ButtonProc: Buttons.ButtonProc ~ {
data: Data ← NARROW[clientData];
TypeScriptWrite[data, "button pusher!\n"];
};
MakeButtons: PROC [data: Data] ~ {
nButtons: NAT ← 0;
height: INTEGER ← data.viewer.wh-12;
dummy: PrintRequest ← NEW[PrintRequestObject];
dummy.fileName ← "File Name";
dummy.service ← "Print Service";
FOR buttons: ButtonList ← data.buttons, buttons.rest WHILE buttons # NIL DO
Buttons.Destroy[buttons.first];
ENDLOOP;
data.buttons ← NIL;
FOR n: NAT IN [0..5) DO
nButtons ← nButtons+1;
MakeButton[dummy, data, height-20*nButtons];
ENDLOOP;
FOR pr: PrintRequestList ← data.printRequests, pr.rest WHILE pr # NIL DO
nButtons ← nButtons+1;
MakeButton[pr.first, data, height-20*nButtons];
ENDLOOP;
};
MakeButton: PROC [printRequest: PrintRequest, data: Data, y: INTEGER] ~ {
buttonName, id: ROPENIL;
IF printRequest = NIL THEN RETURN;
FOR n: NAT IN [0..5) DO
id ← IO.PutFR["%g %g", IO.rope[id], IO.card[printRequest.requestID[n]]];
ENDLOOP;
buttonName ← IO.PutFR["%g %g %g",
IO.rope[printRequest.service], IO.rope[id], IO.rope[printRequest.fileName]];
data.buttons ← CONS[
Buttons.Create[
info: [parent: data.viewer, name: buttonName, wx: 0, wy: y],
proc: ButtonProc,
clientData: data
],
data.buttons
];
};
TypeScriptWrite: PUBLIC PROC [data: Data, rope: ROPE] ~ {
IF data.typeScriptOut # NIL THEN IO.PutRope[data.typeScriptOut, rope];
};
AdjustProc: ViewerClasses.AdjustProc ~ {
data: Data ← NARROW[self.data];
nButtons: NAT ← 0;
height: INTEGER ← self.wh-12;
FOR buttons: ButtonList ← data.buttons, buttons.rest WHILE buttons # NIL DO
button: Viewer ← buttons.first;
nButtons ← nButtons+1;
ViewerOps.EstablishViewerPosition[button, 0, height-20*nButtons, button.ww, button.wh];
ENDLOOP;
ViewerOps.EstablishViewerPosition[data.typeScript, 0, 0, self.ww, height-20*nButtons-4];
RETURN[TRUE];
};
DestroyProc: ViewerClasses.DestroyProc ~ {
data: Data ← NARROW[self.data];
ClearWatcher[];
};
PaintProc: ViewerClasses.PaintProc = {
data: Data ← NARROW[self.data];
IF whatChanged = NIL THEN {
Imager.SetColor[context, Imager.white];
Imager.MaskRectangle[context, ImagerBackdoor.GetBounds[context]];
Imager.SetColor[context, Imager.black];
};
};
UpdateViewer: PROC [data: Data, forceOpen: BOOLFALSE] ~ {
data.printRequests ← GetPrintRequestList[];
MakeButtons[data];
IF data.autoOpen OR forceOpen THEN {
IF data.viewer.iconic THEN ViewerOps.OpenIcon[data.viewer];
};
};
WaitTilListChanged: ENTRY PROC ~ {WAIT ListChanged};
WatchRequestList: CedarProcess.ForkableProc ~ {
enum: ViewerOps.EnumProc ~ {
IF v.class = printManipViewerClass THEN UpdateViewer[NARROW[v.data]];
};
DO
WaitTilListChanged[];
ViewerOps.EnumerateViewers[enum];
ENDLOOP;
};
List Manager
ListChanged: PUBLIC CONDITION;
RegisterRequestID: PUBLIC PROC [requestID: RequestID] ~ {
};
UnRegisterRequestID: PUBLIC PROC [requestID: RequestID] ~ {
};
GetPrintRequestList: PUBLIC PROC RETURNS [list: PrintRequestList] ~ {
list ← NIL;
};
Start Code
printManipViewerClass ← NEW[ViewerClasses.ViewerClassRec ← [
paint: PaintProc,
adjust: AdjustProc,
destroy: DestroyProc
]];
ViewerOps.RegisterViewerClass[$PrintManip, printManipViewerClass];
Commander.Register["///Commands/PrintManip", PrintManipCmd, "Manipulate Print Requests"];
[] ← CedarProcess.Fork[WatchRequestList];
END.