GriffinViewerImpl.mesa
Written by Maureen Stone, December 16, 1982 3:30 pm
Last change by Stone, June 20, 1984 4:45:24 pm PDT
Last Edited by: Pier, February 14, 1984 10:29:09 am PST
DIRECTORY
Commander USING [CommandProc, Register],
ControllerDefs USING [DefaultControllers],
ControllerMenuDefs USING [InitColorMenu, InitCaptionMenu, InitShapeMenu],
CursorDefs USING [GetPointingCursor],
GriffinColor USING [Initialize],
GriffinDefs,
GriffinDisplay USING [ClearScreen],
GriffinFileDefs,
GriffinGrid USING [Initialize],
GriffinInputDefs,
GriffinMemoryDefs USING [Initialize, CZone],
GriffinText USING [GetFileName],
GriffinStyle USING [Initialize],
GriffinViewer,
Icons USING [NewIconFromFile],
Imager USING [Context, DoSave],
IO USING [PutRope],
List USING [Assoc],
MenuDefs USING[ InitMenuStyle],
Menus USING [Menu, CreateEntry, MenuProc, CreateMenu, InsertMenuEntry],
MessageWindow USING [Append],
ObjectDefs USING [ReplotAllObjects, InitObjectFns, ForAllPictureObjects, ObjectProc, DeSelectObject, ExpungeObjects, AdjustBoxForStyle, ObjectsToInterpress],
PointDefs USING [InitPointFns, ScrPt, X, Y],
ProcessProps USING [GetPropList],
Rope USING [ROPE, Cat, Substr],
FS USING [FileInfo, Error, ExpandName, ComponentPositions],
Terminal USING [BlinkBWDisplay, Current],
TIPUser USING [InstantiateNewTIPTable, TIPScreenCoords],
ViewerClasses USING [Viewer, ViewerClass, ViewerClassRec, ModifyProc, DestroyProc],
ViewerOps USING [CreateViewer, RegisterViewerClass, PaintViewer];
GriffinViewerImpl:
CEDAR MONITOR
IMPORTS Commander, ControllerDefs, ControllerMenuDefs, CursorDefs, FS, GriffinColor, GriffinDefs, GriffinDisplay, GriffinFileDefs, GriffinGrid, GriffinInputDefs, GriffinMemoryDefs, GriffinText, GriffinStyle, Icons, Imager, IO, List, MenuDefs, Menus, MessageWindow, ObjectDefs, PointDefs, ProcessProps, Rope, Terminal, TIPUser, ViewerOps
EXPORTS GriffinViewer =
BEGIN OPEN GriffinViewer;
griffinViewer: ViewerClasses.Viewer ← NIL;
ROPE: TYPE = Rope.ROPE;
currentWD: ROPE ← NIL;
GetViewer: PUBLIC PROC RETURNS [ViewerClasses.Viewer] = { RETURN[griffinViewer]};
griffinViewerClass: ViewerClasses.ViewerClass ←
NEW[ViewerClasses.ViewerClassRec ← [
paint: Paint,
notify: InputNotify,
destroy: AboutToDestroy,
tipTable: TIPUser.InstantiateNewTIPTable["Griffin.TIP"],
cursor: CursorDefs.GetPointingCursor[],
icon: Icons.NewIconFromFile["Griffin.icons",4]
]];
AboutToDestroy: ViewerClasses.DestroyProc = {
count: NAT ← 0;
proc: ObjectDefs.ObjectProc = {count ← count+1};
ObjectDefs.ForAllPictureObjects[proc];
IF count > 0
THEN
TRUSTED {
[] ← GriffinFileDefs.OpenFile [Rope.Cat[currentWD,"Destroyed.griffin"], TRUE];
[] ← GriffinFileDefs.WriteFigure[];
GriffinFileDefs.CloseFile[];
};
griffinViewer ← NIL;
};
Create:
PROC
RETURNS [ViewerClasses.Viewer] = {
IF griffinViewer=
NIL
THEN {
menu: Menus.Menu ← Menus.CreateMenu[];
Menus.InsertMenuEntry[menu, Menus.CreateEntry[name: "View", proc: View, fork: FALSE]];
Menus.InsertMenuEntry[menu, Menus.CreateEntry[name: "Overlap", proc: Overlap, fork: FALSE]];
Menus.InsertMenuEntry[menu, Menus.CreateEntry[name: "Transform", proc: Transform, fork: FALSE]];
Menus.InsertMenuEntry[menu, Menus.CreateEntry[name: "Style", proc: Style, fork: FALSE]];
Menus.InsertMenuEntry[menu, Menus.CreateEntry[name: "Objects", proc: Objects, fork: FALSE]];
Menus.InsertMenuEntry[menu, Menus.CreateEntry[name: " Edit", proc: Edit, fork: FALSE]];
Menus.InsertMenuEntry[menu, Menus.CreateEntry[name: "Interpress", proc: Interpress, fork: FALSE]];
Menus.InsertMenuEntry[menu, Menus.CreateEntry[name: "Save", proc: Save, fork: FALSE]];
Menus.InsertMenuEntry[menu, Menus.CreateEntry[name: "Store", proc: Store, fork: FALSE, guarded: TRUE, documentation: NEW[Menus.MenuProc ← PreStore]]];
Menus.InsertMenuEntry[menu, Menus.CreateEntry[name: "Restore", proc: Restore, fork: FALSE]];
Menus.InsertMenuEntry[menu, Menus.CreateEntry[name: "DeleteAll", proc: DeleteAll, fork: FALSE, guarded: TRUE, documentation: "Undo will still work"]];
currentWD ← NARROW[List.Assoc[key: $WorkingDirectory, aList: ProcessProps.GetPropList[]]];
ViewerOps.RegisterViewerClass[$Griffin,griffinViewerClass];
griffinViewer ← ViewerOps.CreateViewer[flavor: $Griffin,
info: [name: Rope.Cat[currentWD,"Griffin"], iconic: TRUE, scrollable: FALSE, menu: menu]];
};
RETURN[griffinViewer];
};
DeleteAll: Menus.MenuProc = {
count: NAT ← 0;
delete: ObjectDefs.ObjectProc = {
ObjectDefs.DeSelectObject[obj];
obj.deleted ← TRUE;
};
paintProc: GriffinViewer.PaintProc = {
GriffinDisplay.ClearScreen[dc];
ObjectDefs.ReplotAllObjects[dc];
};
ObjectDefs.ExpungeObjects[];
ObjectDefs.ForAllPictureObjects[delete];
DoPaint[paintProc];
};
Restore: Menus.MenuProc =
TRUSTED {
--GriffinFileDefs is unsafe
name: ROPE ← GriffinText.GetFileName[currentWD];
IF name=NIL THEN RETURN; --illegal file name
ObjectDefs.ExpungeObjects[];
IF GriffinFileDefs.OpenFile[name,
FALSE]
THEN {
proc: PaintProc = TRUSTED {ObjectDefs.ReplotAllObjects[dc]};
objProc: ObjectDefs.ObjectProc = TRUSTED {ObjectDefs.AdjustBoxForStyle[obj]};
GriffinFileDefs.ReadFigure[];
GriffinFileDefs.CloseFile[];
ObjectDefs.ForAllPictureObjects[objProc];
DoPaint[proc];
};
};
currentName: ROPE ← NIL;
storeName: ROPE ← NIL;
Store: Menus.MenuProc = {
IF storeName=NIL THEN RETURN; --illegal file name
currentName ← storeName;
griffinViewer.name ← currentName;
Save[parent, clientData, mouseButton, control];
ViewerOps.PaintViewer[griffinViewer, caption, FALSE];
};
PreStore: Menus.MenuProc = {
-- called when unguarding Store
new: BOOL ← FALSE;
storeName ← GriffinText.GetFileName[currentWD];
IF storeName=NIL THEN RETURN; --illegal file name
new ← IsNewFile[storeName];
MessageWindow.Append[Rope.Cat["Confirm Store to file: ", storeName, IF new THEN " [New File]" ELSE " [Old File]"], TRUE];
};
IsNewFile:
PROC [name:
ROPE]
RETURNS [new:
BOOL ←
FALSE] = {
[] ← FS.FileInfo[name ! FS.Error => { new ← TRUE; CONTINUE }];
};
Save: Menus.MenuProc = {
name: ROPE ← currentName;
IF currentName=NIL THEN SIGNAL GriffinDefs.UserMessage["no current file name"];
ObjectDefs.ExpungeObjects[];
TRUSTED {
[] ← GriffinFileDefs.OpenFile[name, TRUE];
[] ← GriffinFileDefs.WriteFigure[];
GriffinFileDefs.CloseFile[];
};
};
Interpress: Menus.MenuProc = {
name, fullFName: ROPE;
cp: FS.ComponentPositions;
IF currentName=NIL THEN SIGNAL GriffinDefs.UserMessage["no current file name"];
[fullFName: fullFName, cp: cp] ← FS.ExpandName[currentName];
name ← Rope.Cat[Rope.Substr[base: fullFName, start: 0, len: cp.ext.start-1], ".ip"];
ObjectDefs.ExpungeObjects[];
ObjectDefs.ObjectsToInterpress[name];
};
Edit: Menus.MenuProc = {GriffinDefs.ToggleEditMenus[]}; --DrawOps
Objects: Menus.MenuProc = {GriffinDefs.ToggleObjectMenu[]}; --ObjectOps
Style: Menus.MenuProc = {GriffinDefs.ToggleStyleMenu[]}; --DrawOps
Transform: Menus.MenuProc = {GriffinDefs.ToggleTransformMenu[]}; --ObjectOps
Overlap: Menus.MenuProc = {GriffinDefs.ToggleOverlapMenu[]}; --ObjectOps
View: Menus.MenuProc = {GriffinDefs.ToggleFigureMenus[]}; --FigureOps
myRec: REF GriffinViewer.ProcRec;
DoPaint:
PUBLIC
PROC [proc: GriffinViewer.PaintProc] =
TRUSTED {
myRec.proc ← proc;
ViewerOps.PaintViewer[griffinViewer,client,FALSE,myRec];
};
Paint:
ENTRY
PROCEDURE [self: ViewerClasses.Viewer, context: Imager.Context,
whatChanged: REF ANY, clear: BOOLEAN] RETURNS [quit: BOOL ← FALSE] = {
ENABLE UNWIND => NULL;
IF whatChanged=
NIL
THEN {
proc: PROC = {ObjectDefs.ReplotAllObjects[context]};
Imager.DoSave[context, proc];
}
ELSE {
rec: REF GriffinViewer.ProcRec ← NARROW[whatChanged];
proc: PROC = {rec.proc[context]};
Imager.DoSave[context, proc];
};
RETURN[FALSE];
};
handler: GriffinInputDefs.InputEventProc;
point: PointDefs.ScrPt;
InputNotify: PUBLIC PROCEDURE [self: ViewerClasses.Viewer, input: LIST OF REF ANY] = {
FOR l:
LIST
OF
REF
ANY ← input, l.rest
UNTIL l =
NIL
DO
WITH l.first
SELECT
FROM
z:
ATOM =>
SELECT z
FROM
$ShiftedRedDown => {handler[[red,,point,TRUE]]};
$ShiftedYellowDown => {handler[[yellow,,point,TRUE]]};
$ShiftedBlueDown => {handler[[blue,,point,TRUE]]};
$RedDown => {handler[[red,,point,FALSE]]};
$YellowDown => {handler[[yellow,,point,FALSE]]};
$BlueDown => {handler[[blue,,point,FALSE]]};
$RedUp,$YellowUp,$BlueUp => {handler[[up,,point,FALSE]]};
$ShiftedRedUp,$ShiftedYellowUp,$ShiftedBlueUp => {handler[[up,,point,TRUE]]};
$Abort => handler[[abort,,,]];
ENDCASE;
z: TIPUser.TIPScreenCoords => {
point[PointDefs.X] ← z.mouseX;
point[PointDefs.Y] ← z.mouseY;
};
z: REF CHARACTER => handler[[keyStroke, z^, point, FALSE]];
ENDCASE => Terminal.BlinkBWDisplay[Terminal.Current[]];
ENDLOOP;
};
crock: SIGNAL=CODE;
started: BOOLEAN ← FALSE;
DoGriffinInit:
PROC = {
GriffinMemoryDefs.Initialize[]; --Public Zone
ControllerDefs.DefaultControllers[]; --set up default coordinate systems
PointDefs.InitPointFns[]; --set up transformation matrices
GriffinColor.Initialize[];
GriffinStyle.Initialize[];
IF FALSE THEN SIGNAL crock; --for breakpoints in startup code
ObjectDefs.InitObjectFns[]; --initialize the object list
GriffinGrid.Initialize[]; --initialize the Grid objects.
start up menus
MenuDefs.InitMenuStyle[]; --start the menu package
GriffinDefs.StartFigureMenus[];
GriffinDefs.StartObjectMenus[];
GriffinDefs.StartDrawMenus[]; --also contains the "currently being edited object"
ControllerMenuDefs.InitShapeMenu[]; --next three are style menus
ControllerMenuDefs.InitCaptionMenu[];
ControllerMenuDefs.InitColorMenu[];
griffinViewer ← Create[];
myRec ← GriffinMemoryDefs.CZone.NEW[GriffinViewer.ProcRec];
handler ← GriffinInputDefs.StartInputHandler[];
started ← TRUE;
};
Command: Commander.CommandProc = {
IF started
THEN
IF griffinViewer#NIL THEN cmd.err.PutRope["Only one Griffin Viewer at a time.\n"]
ELSE cmd.err.PutRope["To restart Griffin, Run -a Griffin<cr> Griffin<cr> \n"]
ELSE DoGriffinInit[];
};
Commander.Register[key: "Griffin", proc: Command, doc: "Griffin Illustrator"];
END.