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
GriffinViewer,
IO USING [PutRope],
Commander USING [CommandProc, Register],
Rope USING [ROPE, Cat],
List USING [Assoc],
ProcessProps USING [GetPropList],
DebuggerSwap USING[CallDebugger],
GriffinInputDefs,
MenuDefs USING[ InitMenuStyle],
GriffinDefs USING[StartFigureMenus, StartObjectMenus, StartDrawMenus, StartMainMenus],
Terminal USING [BlinkBWDisplay],
Interminal USING [terminal], --the default terminal
TIPUser USING [InstantiateNewTIPTable, TIPScreenCoords],
GriffinMemoryDefs USING [Initialize, CZone],
Graphics USING [Context],
PointDefs USING [InitPointFns, ScrPt, X, Y],
ScreenDefs USING [ClearScreen, SetViewport, ScreenFns],
ObjectDefs USING [ReplotAllObjects, ShowObjects, ObjectFns],
ControllerMenuDefs USING [InitColorMenu, InitCaptionMenu, InitShapeMenu],
CaretDefs USING [Initialize],
CursorDefs USING [GetPointingCursor],
RefreshDefs USING [Refresh],
ControllerDefs USING [DefaultControllers],
GriffinFileDefs USING[OpenFile, WriteFigure, CloseFile],
ViewerClasses USING [Viewer, ViewerClass, ViewerClassRec, ModifyProc, DestroyProc],
ViewerOps USING [CreateViewer, RegisterViewerClass, Top2Bottom, PaintViewer],
InputFocus USING [SetInputFocus],
Icons USING [NewIconFromFile],
Menus USING [Menu, MenuProc--, InsertMenuEntry, CreateEntry, CreateMenu--];
GriffinViewerImpl: MONITOR
IMPORTS GriffinMemoryDefs, PointDefs, ScreenDefs, ControllerMenuDefs, ControllerDefs, GriffinFileDefs, ViewerOps, ObjectDefs, TIPUser, CaretDefs, MenuDefs, GriffinDefs, RefreshDefs, CursorDefs, GriffinInputDefs, DebuggerSwap, Terminal, Interminal, Icons, InputFocus, Rope, List, ProcessProps, Commander, IO
EXPORTS GriffinViewer =
BEGIN
griffinViewer: ViewerClasses.Viewer ← NIL;
currentWD: Rope.ROPENIL;
GetViewer: PUBLIC PROC RETURNS [ViewerClasses.Viewer] = { RETURN[griffinViewer]};
griffinViewerClass: ViewerClasses.ViewerClass ← NEW[ViewerClasses.ViewerClassRec ← [
paint: Paint,
notify: InputNotify,
destroy: AboutToDestroy,
modify: Modify,
tipTable: TIPUser.InstantiateNewTIPTable["Griffin.TIP"],
cursor: CursorDefs.GetPointingCursor[],
icon: Icons.NewIconFromFile["Griffin.icons",4]
]];
AboutToDestroy: ViewerClasses.DestroyProc = TRUSTED {
[] ← GriffinFileDefs.OpenFile [Rope.Cat[currentWD,"Destroyed.griffin"], TRUE];
[] ← GriffinFileDefs.WriteFigure[];
GriffinFileDefs.CloseFile[];
griffinViewer ← NIL;
};
haveFocus: BOOLEANFALSE;
Modify: ViewerClasses.ModifyProc = TRUSTED {
IF self=griffinViewer THEN SELECT change FROM
kill => {haveFocus ← FALSE; handler[[abort,,,]]};
set => haveFocus ← TRUE;
ENDCASE;
};
Create: PROC RETURNS [ViewerClasses.Viewer] = {
IF griffinViewer=NIL THEN {
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]];
};
RETURN[griffinViewer];
};
menu: Menus.Menu ← Menus.CreateMenu[];
Menus.InsertMenuEntry[menu, Menus.CreateEntry["Refresh", Refresh]];
ViewerOps.RegisterViewerClass[$Griffin,griffinViewerClass];
griffinViewer ← ViewerOps.CreateViewer[flavor: $Griffin,
info: [name:"Griffin", iconic: TRUE, scrollable: FALSE, menu: menu]];
Refresh: Menus.MenuProc = TRUSTED {
paintProc: GriffinViewer.PaintProc = {
ScreenDefs.ClearScreen[dc];
ObjectDefs.ReplotAllObjects[dc];
};
DoPaint[paintProc];
};
myRec: REF GriffinViewer.ProcRec;
DoPaint: PUBLIC PROC [proc: GriffinViewer.PaintProc] = {
myRec.proc ← proc;
ViewerOps.PaintViewer[griffinViewer,client,FALSE,myRec];
};
painting: BOOLEANFALSE; 
Paint: ENTRY SAFE PROCEDURE [self: ViewerClasses.Viewer, context: Graphics.Context,
whatChanged: REF ANY, clear: BOOLEAN] = TRUSTED {
ENABLE UNWIND => NULL;
IF whatChanged=NIL THEN {
ScreenDefs.SetViewport[width: self.cw,height: self.ch];
ObjectDefs.ReplotAllObjects[context];
}
ELSE {
rec: REF GriffinViewer.ProcRec ← NARROW[whatChanged];
IF painting THEN DebuggerSwap.CallDebugger["Painting"] ELSE painting ← TRUE;
rec.proc[context];
painting ←FALSE;
};
};
handler: GriffinInputDefs.InputEventProc;
point: PointDefs.ScrPt;
InputNotify: PUBLIC SAFE PROCEDURE [self: ViewerClasses.Viewer, input: LIST OF REF ANY] = TRUSTED {
focus: PROC = INLINE {IF ~haveFocus THEN InputFocus.SetInputFocus[self]};
FOR l: LIST OF REF ANY ← input, l.rest UNTIL l = NIL DO
WITH l.first SELECT FROM
z: ATOM => SELECT z FROM
$ShiftedRedDown => {focus[]; handler[[red,,point,TRUE]]};
$ShiftedYellowDown => {focus[]; handler[[yellow,,point,TRUE]]};
$ShiftedBlueDown => {focus[]; handler[[blue,,point,TRUE]]};
$RedDown => {focus[]; handler[[red,,point,FALSE]]};
$YellowDown => {focus[]; handler[[yellow,,point,FALSE]]};
$BlueDown => {focus[]; handler[[blue,,point,FALSE]]};
$RedUp,$YellowUp,$BlueUp => {focus[]; handler[[up,,point,FALSE]]};
$ShiftedRedUp,$ShiftedYellowUp,$ShiftedBlueUp => {focus[]; handler[[up,,point,TRUE]]};
$Abort => handler[[abort,,,]];
ENDCASE;
z: TIPUser.TIPScreenCoords => {
point[PointDefs.X] ← z.mouseX;
point[PointDefs.Y] ← ViewerOps.Top2Bottom[griffinViewer,z.mouseY];
};
z: REF CHARACTER => handler[[keyStroke, z^, point, FALSE]];
ENDCASE => Terminal.BlinkBWDisplay[Interminal.terminal];
ENDLOOP;
};
crock: SIGNAL=CODE;
started: BOOLEANFALSE;
DoGriffinInit: PROC = {
GriffinMemoryDefs.Initialize[];
griffinViewer ← Create[];
myRec ← GriffinMemoryDefs.CZone.NEW[GriffinViewer.ProcRec];
ControllerDefs.DefaultControllers[];
IF FALSE THEN SIGNAL crock; --for breakpoints in startup code
PointDefs.InitPointFns[];
CaretDefs.Initialize[];
START the modules that allocate variables
START ObjectDefs.ShowObjects;
START ObjectDefs.ObjectFns;
START RefreshDefs.Refresh;
START ScreenDefs.ScreenFns;
start up menus
MenuDefs.InitMenuStyle[];
GriffinDefs.StartFigureMenus[]; 
GriffinDefs.StartObjectMenus[];
GriffinDefs.StartDrawMenus[];
ControllerMenuDefs.InitShapeMenu[];
ControllerMenuDefs.InitCaptionMenu[];
ControllerMenuDefs.InitColorMenu[];
GriffinDefs.StartMainMenus[];
handler ← GriffinInputDefs.StartInputHandler[];
started ← TRUE;
};
Command: Commander.CommandProc = TRUSTED {
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.