JaMIViewerImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Last change by Bill Paxton, October 5, 1982 3:19 pm
Last change by McGregor, June 15, 1982 10:05 am
Last Edited by: Stone, September 6, 1984 3:53:00 pm PDT
Tim Diebert: October 11, 1985 2:39:05 pm PDT
DIRECTORY
FileNames USING [FileWithSearchRules],
Imager USING [SetFont, VEC],
ImagerBackdoor USING [ClientFromView],
ImagerFont USING [Find, Scale],
ImagerViewer USING [FancyCreate, ClientDataFromViewer, Erase, GetViewer, Reset],
JaM USING [State, SetAbort, Register, PushReal, Execute, ExecuteRope, Stop, TryToLoad, RopeToAtom],
JaMImager,
JaMImagerContexts,
JaMIPrivate,
Menus USING [Menu, MenuProc, CreateEntry, CreateMenu, InsertMenuEntry],
MessageWindow USING [Blink, Append],
Rope USING [Concat, ROPE],
TIPUser USING [TIPScreenCoords],
ViewerClasses USING [Viewer, ViewerClass, NotifyProc],
ViewerOps USING [DestroyViewer]
;
JaMIViewerImpl: CEDAR MONITOR
LOCKS info USING info: JaMIPrivate.Info
IMPORTS FileNames, Imager, ImagerBackdoor, ImagerFont, ImagerViewer, JaM, JaMIPrivate, Menus, MessageWindow, Rope, ViewerOps
EXPORTS JaMImager, JaMImagerContexts =
BEGIN
Info: TYPE = JaMIPrivate.Info;
State: TYPE = JaM.State;
ROPE: TYPE ~ Rope.ROPE;
JReloadTIP: PROC [state: State] = { ReloadTIP[] };
ReloadTIP: PUBLIC PROC = {
jamImagerClass.tipTable ← TIPUser.InstantiateNewTIPTable["JaMImager.TIP"] };
Create: PUBLIC PROC [state: State, typescript: ViewerClasses.Viewer, iconic: BOOLEANFALSE]
RETURNS [viewer: ViewerClasses.Viewer] = {
info: Info← NIL;
menu: Menus.Menu;
tipTable: ROPE;
{ -- extra block to make info defined in scope of UNWIND
ENABLE UNWIND => -- something went wrong while creating the viewer
IF viewer#NIL THEN DestroyViewer[viewer]
ELSE IF info#NIL THEN JaMIPrivate.ForgetInfo[state];
IF (info ← JaMIPrivate.GetInfo[state]) # NIL THEN ERROR;
info ← JaMIPrivate.CreateInfo[state];
menu ← Menus.CreateMenu[];
Menus.InsertMenuEntry[menu, Menus.CreateEntry["Reset", Reset]];
Menus.InsertMenuEntry[menu, Menus.CreateEntry["Interrupt", InterruptButton]];
Menus.InsertMenuEntry[menu, Menus.CreateEntry["InitDC", InitDCButton]];
info.typescript ← typescript;
info.venabled ← TRUE;
tipTable ← FullName["JaMImager", "tip", state];
info.vdc ← ImagerViewer.FancyCreate[
info: [data: info,
name: Rope.Concat[typescript.name," Imager"], menu: menu,
iconic: iconic, scrollable: FALSE],
units: pixels, notify: InputNotify, destroy: AboutToDestroy, tipTable: tipTable, clientData: info
];
Imager.SetFont[info.vdc, (info.font← ImagerFont.Scale[ImagerFont.Find["Xerox/PressFonts/TimesRoman-MRR"], 40])];
viewer ← ImagerViewer.GetViewer[info.vdc];
info.viewer ← viewer;
Register[state];
JaMIPrivate.RegisterImager[state];
JaMIPrivate.RegisterColor[state];
JaMIPrivate.RegisterInterpress[state];
JaMIPrivate.RegisterVector2[state];
}};
FullName: PROC [name, extension: ROPE, self: State] RETURNS [fullName: ROPE] = {
rules: REF ANY;
found: BOOL;
[found, rules] ← JaM.TryToLoad[self, JaM.RopeToAtom[".searchrules"]];
IF ~found THEN rules ← NIL;
[fullName,] ← FileNames.FileWithSearchRules[root: name, defaultExtension: extension, requireExtension: FALSE, requireExact: FALSE, searchRules: rules];
IF fullName=NIL THEN RETURN [NIL] ELSE RETURN[fullName];
};
Reset: Menus.MenuProc = {
viewer: ViewerClasses.Viewer ← NARROW[parent];
info: Info ← NARROW[ImagerViewer.ClientDataFromViewer[viewer]];
ImagerViewer.Erase[info.vdc];
};
InterruptButton: Menus.MenuProc = {
viewer: ViewerClasses.Viewer ← NARROW[parent];
info: Info ← NARROW[ImagerViewer.ClientDataFromViewer[viewer]];
state: State ← info.state;
JaM.SetAbort[state,TRUE];
SetPlace[info,0,0];
SetBug[info,0,0] };
InitDCButton: Menus.MenuProc = {
viewer: ViewerClasses.Viewer ← NARROW[parent];
info: Info ← NARROW[ImagerViewer.ClientDataFromViewer[viewer]];
state: State ← info.state;
InitDC[state];
};
DestroyViewer: PROC [viewer: ViewerClasses.Viewer] = {
AboutToDestroy[viewer];
ViewerOps.DestroyViewer[viewer];
};
AboutToDestroy: PROC [self: ViewerClasses.Viewer] = {
info: Info ← NARROW[ImagerViewer.ClientDataFromViewer[self]];
JaMIPrivate.ForgetInfo[info.state];
};
InitDC: PROCEDURE [state: State] = {
info: Info ← JaMIPrivate.GetInfo[state];
IF info.venabled THEN {
ImagerViewer.Reset[info.vdc];
};
FOR l: JaMImagerContexts.DCList ← info.dcList, l.next UNTIL l=NIL DO
IF l.enabled THEN l.dc ← l.callMe[l.dc, initdc];
ENDLOOP;
};
Erase: PROCEDURE [state: State] = {
info: Info ← JaMIPrivate.GetInfo[state];
IF info.venabled THEN {
ImagerViewer.Erase[info.vdc];
};
FOR l: JaMImagerContexts.DCList ← info.dcList, l.next UNTIL l=NIL DO
IF l.enabled THEN l.dc ← l.callMe[l.dc, erase];
ENDLOOP;
};
EnableViewer: PUBLIC PROC [state: State] = {
JaMIPrivate.GetInfo[state].venabled ← TRUE;
};
DisableViewer: PUBLIC PROC [state: State] = {
JaMIPrivate.GetInfo[state].venabled ← FALSE;
};
Mouse: PROC [state: State] = {
x,y: REAL;
[x,y] ← GetPlace[JaMIPrivate.GetInfo[state]];
JaM.PushReal[state, x];
JaM.PushReal[state, y]
};
Touch: PROC [state: State] = {
x,y: REAL;
[x,y] ← GetBug[JaMIPrivate.GetInfo[state]];
JaM.PushReal[state, x];
JaM.PushReal[state, y]
};
GetBug: ENTRY PROC [info: Info] RETURNS[x,y: REAL] = { OPEN info;
ENABLE UNWIND => NULL;
bugflag ← FALSE;
UNTIL viewer.destroyed OR bugflag DO WAIT bugged ENDLOOP;
IF viewer.destroyed THEN x ← y ← 0
ELSE { x ← bugX; y ← bugY; bugflag ← FALSE };
};
SetBug: PUBLIC ENTRY PROC [info: Info, x,y: REAL] = { OPEN info;
ENABLE UNWIND => NULL;
bugflag ← TRUE; bugX ← x; bugY ← y;
NOTIFY bugged };
GetPlace: ENTRY PROC [info: Info] RETURNS[x,y: REAL] = { OPEN info;
ENABLE UNWIND => NULL;
mouseflag ← FALSE;
UNTIL viewer.destroyed OR mouseflag DO WAIT mouse ENDLOOP;
IF viewer.destroyed THEN x ← y ← 0
ELSE { x ← mouseX; y ← mouseY; mouseflag ← FALSE };
};
SetPlace: ENTRY PROC [info: Info, x,y: REAL] = { OPEN info;
ENABLE UNWIND => NULL;
mouseflag ← TRUE; mouseX ← x; mouseY ← y; NOTIFY mouse;
};
DoAtom: PROC [state: State, atom: ATOM] = {
generic proc for TIP atoms. Normal TIP table never comes here
JaM.Execute[state, atom ! JaM.Stop => CONTINUE];
};
DoButton: PROC [state: State, button: ATOM, x,y: REAL] = {
all the *Down, *Up and *Track atoms
JaM.PushReal[state, x];
JaM.PushReal[state, y];
SELECT button FROM
$RedDown, $CtrlRedDown,
$ShiftRedDown, $CtrlShiftRedDown => JaM.ExecuteRope[state,".reddown" ! JaM.Stop => CONTINUE];
$YellowDown, $CtrlYellowDown,
$ShiftYellowDown, $CtrlShiftYellowDown => JaM.ExecuteRope[state,".yellowdown" ! JaM.Stop => CONTINUE];
$BlueDown, $CtrlBlueDown,
$ShiftBlueDown, $CtrlShiftBlueDown => JaM.ExecuteRope[state,".bluedown" ! JaM.Stop => CONTINUE];
$Track, $CtrlTrack,
$ShiftTrack, $CtrlShiftTrack => JaM.ExecuteRope[state,".track" ! JaM.Stop => CONTINUE];
$RedUp, $CtrlRedUp,
$ShiftRedUp, $CtrlShiftRedUp => JaM.ExecuteRope[state,".redup" ! JaM.Stop => CONTINUE];
$YellowUp, $CtrlYellowUp,
$ShiftYellowUp, $CtrlShiftYellowUp => JaM.ExecuteRope[state,".yellowup" ! JaM.Stop => CONTINUE];
$BlueUp, $CtrlBlueUp,
$ShiftBlueUp, $CtrlShiftBlueUp => JaM.ExecuteRope[state,".blueup" ! JaM.Stop => CONTINUE];
ENDCASE => ERROR; 
};
[self: ViewerClasses.Viewer, input: LIST OF REF ANY]
InputNotify: PUBLIC ViewerClasses.NotifyProc = {
mx, my: INTEGER;
x, y: REAL← 0.0;
FOR l: LIST OF REF ANY ← input, l.rest UNTIL l = NIL DO
WITH l.first SELECT FROM
z: ATOM => SELECT z FROM
$RedDown, $CtrlRedDown, $ShiftRedDown, $CtrlShiftRedDown => {
info: Info ← NARROW[ImagerViewer.ClientDataFromViewer[self] ,Info];
SetBug[info,x,y];
SetPlace[info,x,y];
DoButton[info.state,z,x,y];
};
$YellowDown, $CtrlYellowDown, $ShiftYellowDown, $CtrlShiftYellowDown,
$BlueDown, $CtrlBlueDown, $ShiftBlueDown, $CtrlShiftBlueDown,
$Track, $CtrlTrack, $ShiftTrack, $CtrlShiftTrack,
$RedUp, $CtrlRedUp, $ShiftRedUp, $CtrlShiftRedUp,
$YellowUp, $CtrlYellowUp, $ShiftYellowUp, $CtrlShiftYellowUp,
$BlueUp, $CtrlBlueUp, $ShiftBlueUp, $CtrlShiftBlueUp =>
DoButton[NARROW[ImagerViewer.ClientDataFromViewer[self], Info].state, z, x, y]; 
$Place => SetPlace[NARROW[ImagerViewer.ClientDataFromViewer[self], Info],x,y];
ENDCASE => DoAtom[NARROW[ImagerViewer.ClientDataFromViewer[self], Info].state, z]; 
z: TIPUser.TIPScreenCoords => { p, v: Imager.VEC;
[mx, my, -- color -- ] ← z^; p.x← mx; p.y← my;
v← ImagerBackdoor.ClientFromView[ NARROW[ImagerViewer.ClientDataFromViewer[self], Info].vdc, p]; x← v.x; y← v.y};
ENDCASE => {
MessageWindow.Blink[];
MessageWindow.Append["unknown TIP Atom (JaMImager)", TRUE];
};
ENDLOOP;
};
Register: PROC[state: State] = {
JaM.Register[state,".initdc",InitDC];
JaM.Register[state,".erase",Erase];
JaM.Register[state,".reloadTIP",JReloadTIP];
JaM.Register[state,".enableviewer",EnableViewer];
JaM.Register[state,".disableviewer",DisableViewer];
JaM.Register[state,".mouse", Mouse];
JaM.Register[state,".touch",Touch];
};
END...