CDVMain.mesa (part of ChipNDale)
Copyright © 1983, 1986 by Xerox Corporation. All rights reserved.
Ch. Jacobi, June 24, 1983 3:33 pm
Last Edited by: Christian Jacobi, August 28, 1986 6:37:55 pm PDT
DIRECTORY
CD,
CDBasics,
CDCells,
CDColors,
CDCommandOps,
CDDrawQueue,
CDEnvironment USING [GetTipTable, GetIcon],
CDEvents,
CDLayers USING [CurrentLayer, LayerWidth],
CDPanel,
CDProperties,
CDSequencer USING [Command, CommandRec, ExecuteCommand],
CDValue USING [Fetch, Store, FetchInt],
CDVFurtherPainters USING [CallFurther, FurtherPaintProc, InstallFurtherPaint],
CDViewer,
CDViewerBase,
CDVPrivate,
CDVScale,
CedarProcess USING [SetPriority, Priority],
Cursors USING [CursorType],
DebuggerSwap USING [WorryCallDebugger],
InputFocus USING [SetInputFocus, PopInputFocus],
InterminalBackdoor USING [terminal],
PrincOps USING [BBTableSpace],
PrincOpsUtils USING [AlignedBBTable],
Process USING [Detach, Yield],
Rope USING [ROPE, Cat],
RuntimeError USING [UNCAUGHT],
SafeStorage USING [ReclaimCollectibleObjects],
Terminal USING [GetColorMode],
TerminalIO USING [AddLock, WriteRope, WriteRopes],
TIPUser USING [TIPScreenCoords],
UserProfile USING [Boolean, ProfileChangedProc, CallWhenProfileChanges],
ViewerClasses USING [Viewer, ViewerClass, ViewerClassRec, PaintProc, ModifyProc, NotifyProc, Column, DestroyProc],
ViewerEvents USING [EventProc, RegisterEventProc],
ViewerOps USING [CreateViewer, RegisterViewerClass, PaintViewer, BlinkIcon, EnumProc, EnumerateViewers],
WindowManager USING [colorDisplayOn];
CDVMain:
CEDAR
MONITOR
--monitoring rule: aquire the ViewerLock first, the monitor's entry lock only after.
IMPORTS
CD, CDBasics, CDCells, CDColors, CDCommandOps, CDDrawQueue, CDEnvironment, CDEvents, CDLayers, CDPanel, CDProperties, CDSequencer, CDValue, CDVFurtherPainters, CDViewer, CDViewerBase, CDVPrivate, CDVScale, CedarProcess, DebuggerSwap, InputFocus, InterminalBackdoor, PrincOpsUtils, Process, Rope, RuntimeError, SafeStorage, Terminal, TerminalIO, UserProfile, ViewerEvents, ViewerOps, WindowManager
EXPORTS CDVPrivate
SHARES CDVFurtherPainters, TerminalIO, CDDrawQueue =
BEGIN
greeting: Rope.ROPE = "ChipNDale Version 2.3 for Cedar 6.1 ";
date: Rope.ROPE = "August 4, 1986";
copyRight: Rope.ROPE = "\nCopyright (C) 1984, 1986 by Xerox Corporation. All rights reserved.\n\n";
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
VRef: TYPE = CDVPrivate.VRef;
Viewer: TYPE = ViewerClasses.Viewer;
viewerClassAtom: ATOM = $ChipNDale;
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
tryToPaint: CONDITION;
notSupportedColorMode: PUBLIC ERROR = CODE;
putNewViewerOnColor: BOOL ← TRUE;
allVRefs: PUBLIC LIST OF VRef ← NIL;
catchCritical, catchWedging: BOOL ← TRUE;
errorRef: REF ← NIL;
errorMsg: Rope.ROPE ← NIL;
useForShallContinue: CDVPrivate.DebugProc ← DefaultDebug;
UseDebug:
PUBLIC PROC [proc: CDVPrivate.DebugProc] = {
useForShallContinue ← proc
};
DefaultDebug:
PROC [ref:
REF, wedge:
BOOL, msg: Rope.
ROPE]
RETURNS [shallCont:
BOOL] = {
errorRef ← ref;
errorMsg ← msg;
shallCont ← catchCritical OR (wedge AND catchWedging);
IF ~shallCont
THEN
DebuggerSwap.WorryCallDebugger["ChipNDale wedge"];
};
ShallContinue:
PUBLIC
PROC [ref:
REF←
NIL, wedge:
BOOL←
FALSE, msg: Rope.
ROPE←
NIL]
RETURNS [yes:
BOOL←
TRUE] = {
sc: CDVPrivate.DebugProc ← useForShallContinue;
IF sc#NIL THEN yes ← sc[ref, wedge, msg];
};
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
terminalLock: BOOL ← FALSE;
TerminalLock:
PROC [] = {
terminalLock ← TRUE;
viewerClassRec.cursor ← cursorWhileInput
};
TerminalFree:
PROC [] ={
terminalLock ← FALSE;
SetCursor[]
};
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- types used for parameters to the viewer paint procedure
--TrackRef: type to force cursor tracking
TrackRef: TYPE = REF TrackRecord;
TrackRecord:
TYPE =
RECORD [
pos: CD.Position
];
--the Get and Dispose proc's are a hack to reduce the memory allocator's work
track: TrackRef ← NIL;
GetTrackRef:
PROC [p:
CD.Position]
RETURNS [t: TrackRef] =
INLINE {
--may be called by viewers NotifyViewer proc only; monitored through viewers NotifyViewer proc
t ← track; track ← NIL;
IF t=NIL THEN t ← NEW[TrackRecord];
t.pos ← p
};
DisposeTrackRef:
PROC [t: TrackRef] =
INLINE {
track ← t
};
--RepaintRectAreaRef: type to force drawing a rectangular aera
RepaintRectAreaRef: TYPE = REF RepaintRectArea;
RepaintRectArea:
TYPE =
RECORD[
rect: CD.Rect ← CDBasics.universe,
erase: BOOL ← FALSE
];
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
viewerClassRec: ViewerClasses.ViewerClass ←
NEW[ViewerClasses.ViewerClassRec ← [
paint: PaintViewer,
notify: NotifyViewer,
modify: ModifyViewer,
destroy: DestroyViewer,
set: CDViewerBase.SetProc,
get: CDViewerBase.GetProc,
cursor: cursorNoFocus
]];
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
cursoredCDViewer: PUBLIC Viewer ← NIL;
inputFocussedViewer: Viewer ← NIL;
lastInputFocussedViewer: Viewer ← NIL;
cursorWithFocus: Cursors.CursorType = textPointer;
cursorNoFocus: Cursors.CursorType = pointDown;
cursorWhileInput: Cursors.CursorType = questionMark;
SetCursor:
PROC [] =
INLINE {
viewerClassRec.cursor ←
IF terminalLock THEN cursorWhileInput
ELSE IF cursoredCDViewer=inputFocussedViewer THEN cursorWithFocus
ELSE cursorNoFocus;
};
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
LastViewer:
PUBLIC
PROC []
RETURNS [Viewer] = {
RETURN [lastInputFocussedViewer]
};
SetUpAndRedraw:
ENTRY
PROC[vRef: VRef] = {
--logically inside the viewer's paint proc;
--reset viewer data and then sets up a buffered request for redrawing
ENABLE UNWIND => NULL;
IF vRef=NIL THEN RETURN WITH ERROR CD.Error[];
CDDrawQueue.Flush[vRef.ct];
vRef.onVC ← FALSE; --erasing viewer automaticaly makes cursor invisible
CDVPrivate.CreateDrawInformation[vRef];
CDDrawQueue.ChangeClipArea[vRef.ct, vRef.dClip];
-- erase to allow also backgrounds of arbitrary patterns or colors
CDDrawQueue.QueueInsertDrawCommand[vRef.ct, CDDrawQueue.Request[$redraw, CDBasics.universe]];
};
PaintViewer: ViewerClasses.PaintProc = {
--PROC [self: Viewer, context: Imager.Context, whatChanged: REF ANY, clear: BOOL]
--depending on whatChanged, the call must be protected or need not.
--Never call with modules entry monitor lock set.
ENABLE {
CDVPrivate.notSupportedColorMode => GOTO oops;
RuntimeError.
UNCAUGHT =>
IF ShallContinue[self, TRUE, "CDVMain.PV"] THEN GOTO oops ELSE REJECT;
};
vRef: VRef;
TrackRefTrack:
ENTRY
PROC [vRef: VRef, tr: TrackRef] =
INLINE {
--vRef ABSOLUTELY never NIL {proc is local}
ENABLE UNWIND => NULL;
IF vRef.cursorInhibitations=0
THEN {
--Proof hints: vRef.onVC initialized false; vRef.usedCursor not accessed outside
-- CDVMains monitorlock (use Grep)
IF vRef.onVC THEN vRef.usedCursor[vRef]
ELSE {
vRef.startVC ← vRef.designRec.startLC;
vRef.firstHorizontalVC ← vRef.designRec.firstHLC;
vRef.designRec.currentLayer ← CDLayers.CurrentLayer[vRef.actualDesign];
vRef.defaultWidthVC ← vRef.designRec.widthLC ←
CDLayers.LayerWidth[vRef.actualDesign, vRef.designRec.currentLayer];
vRef.onVC ← TRUE;
};
--now vRef.onVC is true
vRef.usedCursor ← vRef.designRec.outlineProcLC;
vRef.stopVC ← tr.pos;
vRef.usedCursor[vRef];
};
DisposeTrackRef[tr];
};
RemoveTrack:
ENTRY
PROC[vRef: VRef] =
INLINE {
--vRef ABSOLUTELY never NIL {proc is local}
ENABLE UNWIND => NULL;
IF vRef.onVC
THEN {
vRef.usedCursor[vRef];
vRef.onVC ← FALSE;
};
};
--PaintViewer
IF self.destroyed THEN RETURN;
WITH self.data
SELECT
FROM
vr: VRef => vRef ← vr;
ENDCASE => RETURN;
vRef.viewContext ← context;
--here it would have trapped if vRef=NIL
WITH whatChanged
SELECT
FROM
tr: TrackRef => TrackRefTrack[vRef, tr]; -- called by NotifyViewer
atom:
ATOM => {
IF atom=$RemoveTrack THEN RemoveTrack[vRef]
ELSE CDVFurtherPainters.CallFurther[vRef, atom]; -- called from anywhere, maybe not protected
};
area: RepaintRectAreaRef =>
-- protected by ProtectedRepaint
CDVPrivate.RepaintRectAreaInViewer[vRef, area.rect, area.erase];
ENDCASE => {
IF whatChanged=
NIL
THEN {
IF vRef.viewer#self THEN RETURN; --initialization not finished
SetUpAndRedraw[vRef] -- called from anywhere, maybe not protected
}
ELSE CDVFurtherPainters.CallFurther[vRef, whatChanged];
}
EXITS oops => NULL;
};
Flushed: CDVFurtherPainters.FurtherPaintProc = {
PROC [me: CDVPrivate.VRef, key: REF]
-- logicaly local to viewers paint proc (PaintViewer)
CDDrawQueue.Flush[me.ct];
me.scale ← me.intendedScale;
SetUpAndRedraw[me];
};
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--logically local to ProtectedRepaint and initialization--
--vRef never nil--
EnableCursoring:
ENTRY
PROC[vRef: VRef] =
INLINE {
--logically local to ProtectedRepaint
--is outside to make callable from catch-phrase and initialization
ENABLE UNWIND => NULL;
vRef.cursorInhibitations ← vRef.cursorInhibitations-1;
BROADCAST tryToPaint
};
ProtectedRepaint:
PROC[vRef: VRef, whatChanged:
REF
ANY] = {
--does:
--remove cursor and disables any cursoring process
--let only one client come through
--Caller must guarantee vRef#NIL (Use find; {proc neither exported nor assigned to variable})
ENABLE RuntimeError.
UNCAUGHT => {
EnableCursoring[vRef];
IF ShallContinue[vRef, TRUE, "CDVMain.PR"] THEN GOTO oops ELSE REJECT
};
DisableCursoring:
ENTRY
PROC[vRef: VRef]
RETURNS [mustRemoveCursor:
BOOL] =
INLINE {
--and enters protected region.
--vRef never nil; guaranteed from caller {proc is local}
ENABLE UNWIND => NULL;
vRef.cursorInhibitations ← vRef.cursorInhibitations+1;
WHILE vRef.cursorInhibitations>1
DO
vRef.cursorInhibitations ← vRef.cursorInhibitations-1;
WAIT tryToPaint;
vRef.cursorInhibitations ← vRef.cursorInhibitations+1;
ENDLOOP;
mustRemoveCursor ← vRef.onVC;
};
--ProtectedRepaint
IF DisableCursoring[vRef].mustRemoveCursor THEN RemoveCursor[vRef];
ViewerOps.PaintViewer[vRef.viewer, client,
FALSE, whatChanged
! RuntimeError.UNCAUGHT => IF ShallContinue[vRef, TRUE, "CDVMain.PR2"] THEN CONTINUE
];
EnableCursoring[vRef];
EXITS oops => NULL;
};
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
ViewerProcess:
PROC[vRef: VRef] = {
comm: REF CDDrawQueue.Request = NEW[CDDrawQueue.Request];
bBTableSpace1, bBTableSpace2: PrincOps.BBTableSpace;
--vRef.fooBBptr is a short pointer! (hardware) therefor must be local to some proc space.
IF vRef.running THEN ERROR;
TRUSTED {
vRef.pBBptr ← PrincOpsUtils.AlignedBBTable[@bBTableSpace1];
vRef.xBBptr ← PrincOpsUtils.AlignedBBTable[@bBTableSpace2];
};
vRef.running ← TRUE;
DO
comm^ ← CDDrawQueue.FetchCommand[vRef.ct];
SELECT comm.key
FROM
$redraw => {
paintArea: RepaintRectAreaRef = NEW[RepaintRectArea←[comm.rect, TRUE]];
ProtectedRepaint[vRef, paintArea];
};
$draw => {
paintArea: RepaintRectAreaRef = NEW[RepaintRectArea←[comm.rect, FALSE]];
ProtectedRepaint[vRef, paintArea];
};
CDDrawQueue.queueEmpty => {
ProtectedRepaint[vRef, $Temporaries];
CedarProcess.SetPriority[CedarProcess.Priority[background]];
--do the garbage collection now, when not to much else is to do,
--and also all the allocations of the drawing can be freed
SafeStorage.ReclaimCollectibleObjects[suspendMe: FALSE];
};
CDDrawQueue.finishedForEver => EXIT;
ENDCASE => ProtectedRepaint[vRef, comm];
ENDLOOP;
TerminalIO.WriteRope["viewer destroyed\n"];
vRef.running ← FALSE;
vRef.ct ← NIL;
vRef.actualDesign ← NIL;
vRef.deviceDrawRef ← NIL;
vRef.painterList ← NIL;
vRef.properties ← NIL;
};
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
SlowDown:
PROC [v: Viewer] = {
IF v#
NIL
THEN
WITH v.data
SELECT
FROM
vRef: VRef => {
--order important
vRef.hurryUp ← FALSE;
vRef.slowDown ← TRUE;
vRef.check ← TRUE;
vRef.deviceDrawRef.checkPriority ← TRUE;
};
ENDCASE => NULL;
};
SpeedUp:
PROC [v: Viewer] = {
IF v#
NIL
THEN
WITH v.data
SELECT
FROM
vRef: VRef => {
--order important
vRef.slowDown ← FALSE;
vRef.hurryUp ← TRUE;
vRef.check ← TRUE;
vRef.deviceDrawRef.checkPriority ← TRUE;
};
ENDCASE => NULL;
};
RemoveCursor:
PROC [vRef: VRef] =
INLINE {
--removes visible cursor, if there is
--monitores inside viewerpaintproc
IF vRef.onVC
THEN
ViewerOps.PaintViewer[vRef.viewer, client,
FALSE, $RemoveTrack
! RuntimeError.UNCAUGHT => IF ShallContinue[vRef, TRUE, "CDVMain.RC"] THEN CONTINUE
];
};
ModifyViewer: ViewerClasses.ModifyProc = {
-- PROC [self: Viewer, change: ModifyAction]
ENABLE UNWIND => NULL;
SELECT change
FROM
set, pop => lastInputFocussedViewer ← inputFocussedViewer ← self;
kill, push => inputFocussedViewer ← NIL;
ENDCASE => NULL;
SetCursor[];
};
NotifyViewer: ViewerClasses.NotifyProc = {
-- PROC [self: Viewer, input: LIST OF REF ANY]
-- ENTRY ommitted since sequential already by viewer package
ENABLE RuntimeError.
UNCAUGHT =>
IF ShallContinue[self, TRUE, "CDVMain.Notify"] THEN GOTO oops ELSE REJECT;
vRef: VRef;
mouse: CD.Position ← [0, 0]; --initialize, there are crazy tiptables.
LogicalTrack:
PROC [vRef: VRef, pos:
CD.Position] =
INLINE {
--makes cursor logically available
IF
NOT vRef.designRec.startLCValid
THEN {
vRef.designRec.startLC ← pos;
vRef.designRec.startLCValid ← TRUE;
}
};
LogicalTrackOff:
PROC [vRef: VRef, pos:
CD.Position] =
INLINE {
--makes cursor logically unavailable
vRef.designRec.stopLC ← pos;
vRef.designRec.startLCValid ← FALSE;
};
Track:
PROC [vRef: VRef] =
INLINE {
--uses intermediate layer variable mouse
VisibleTrack:
PROC [vRef: VRef, pos:
CD.Position] =
INLINE {
--makes cursor visible
ViewerOps.PaintViewer[vRef.viewer, client, FALSE, GetTrackRef[pos] ];
};
--Track
pos: CD.Position = CDVScale.ViewerToDesignPosition[vRef.scale, mouse];
LogicalTrack[vRef, pos];
IF vRef.cursorInhibitations=0 THEN VisibleTrack[vRef, pos];
};
StopTrack:
PROC [vRef: VRef] = {
--uses intermediate layer variable mouse
pos: CD.Position ~ CDVScale.ViewerToDesignPosition[vRef.scale, mouse];
vRef.hurryUp ← TRUE;
LogicalTrackOff[vRef, pos];
RemoveCursor[vRef];
CDVPrivate.SetCursorMode[vRef, NIL];
};
--NotifyViewer
WITH self.data
SELECT
FROM
vr: VRef => vRef ← vr;
ENDCASE => RETURN;
IF self#cursoredCDViewer
THEN {
tem: Viewer ~ cursoredCDViewer;
IF vRef.deviceDrawRef=
NIL
THEN {
--silly Cedar Viewer package allows calls of notify before
--the first call to the paint procedure happened;
--but in ChipNDale, some initializations happens in paint procedure only.
--luckily at that time cursoredCDViewer#self; so here is the only
--place to check.
RETURN
};
IF tem#
NIL
THEN
WITH tem.data
SELECT
FROM
vRef: VRef => RemoveCursor[vRef];
ENDCASE => NULL;
--avoid running in 24 bit per pixel mode
IF self.column=color
THEN
IF Terminal.GetColorMode[InterminalBackdoor.terminal].full
THEN {
IF self=inputFocussedViewer THEN InputFocus.PopInputFocus[];
RETURN;
};
cursoredCDViewer ← self;
SetCursor[];
};
WHILE input#
NIL
DO
WITH input.first
SELECT
FROM
atom:
ATOM => {
IF atom=$Track THEN Track[vRef]
ELSE IF atom=$StopTrack THEN StopTrack[vRef]
ELSE
IF terminalLock
THEN {
IF atom#$UseCursor
THEN
ViewerOps.BlinkIcon[viewer: self, millisecondsPerBlink: 100];
RETURN;
}
ELSE {
IF self#inputFocussedViewer
THEN {
SlowDown[inputFocussedViewer];
InputFocus.SetInputFocus[self];
SpeedUp[self];
IF atom=$CloseReSelectOnlyP THEN RETURN;
};
IF atom=$UseCursor
THEN {
--command involving 2 atoms
RemoveCursor[vRef];
input ← input.rest; IF input=NIL THEN RETURN;
CDVPrivate.SetCursorMode[vRef, input.first]
}
ELSE {
-- all other (standard) commands
StopTrack[vRef];
TRUSTED {Process.Detach[
FORK CDSequencer.ExecuteCommand[
design: vRef.actualDesign,
comm:
NEW[CDSequencer.CommandRec ← CDSequencer.CommandRec[
design: vRef.actualDesign,
key: atom,
pos: vRef.designRec.stopLC,
sPos: vRef.designRec.startLC,
l: vRef.designRec.currentLayer,
ref: vRef,
n: vRef.defaultWidthVC,
b: vRef.designRec.firstHLC
]]
]
]};
};
};
};
coords: TIPUser.TIPScreenCoords => {
-- range test,
-- [some crazy tiptables use coords without a mouse action first]
mouse.x ← MIN[MAX[coords.mouseX, 0], vRef.viewer.cw-1];
mouse.y ← MIN[MAX[coords.mouseY, 0], vRef.viewer.ch-1];
};
ENDCASE => NULL;
input ← input.rest
ENDLOOP;
EXITS oops => NULL;
};
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Caption:
PROC [design:
CD.Design]
RETURNS [Rope.
ROPE] = {
IF design=NIL THEN RETURN["nil design"]
ELSE
RETURN [Rope.Cat[
(IF design.name#NIL THEN design.name ELSE "no name"),
" (",
design.technology.name,
") cell: ",
CDCells.PushedCellName[design]
]]
};
CDEventHappened: CDEvents.EventProc = {
-- PROC [event: REF, design: CD.Design, x: REF]
-- repaint captions and sometimes the contents
name: Rope.ROPE = Caption[design];
FOR l: CDViewer.ViewerList ← CDViewer.ViewersOf[design], l.rest
WHILE l#
NIL
DO
WITH l.first.data
SELECT
FROM
vRef: VRef => {
l.first.name ← name;
ViewerOps.PaintViewer[l.first, caption];
IF event=$AfterPop
OR event=$AfterPush
THEN {
--redraw everything, because
-- after pop: cell change may have propagated
-- after push: background features must be redrawn greyish
CDDrawQueue.QueueInsertDrawCommand[vRef.ct, CDDrawQueue.Request[$redraw, CDBasics.universe]]
}
};
ENDCASE => NULL;
ENDLOOP;
};
IsNewVersion:
PROC [design:
CD.Design]
RETURNS [newVersion:
BOOL←
FALSE] = {
vList: CDViewer.ViewerList ← CDViewer.ViewersOf[design];
IF vList=NIL THEN RETURN [ CDValue.Fetch[design, $CDxNewVersion]=$T ];
FOR vl: CDViewer.ViewerList ← vList, vl.rest
WHILE vl#
NIL
DO
IF vl.first.newVersion
THEN {
CDValue.Store[design, $CDxNewVersion, $T];
RETURN [TRUE]
}
ENDLOOP;
CDValue.Store[design, $CDxNewVersion, NIL];
};
CreateViewer:
PUBLIC
PROC[design:
CD.Design]
RETURNS [v: Viewer] = {
bb: CD.Rect = CDCommandOps.BoundingBox[design, FALSE];
vRef: VRef = New[design];
TRUSTED {Process.Detach[FORK ViewerProcess[vRef]]};
IF CDProperties.GetDesignProp[design, $CDxDrawPanel]#$FALSE
THEN
[] ← CDPanel.CreatePanel[design];
--must wait until vRef.fooBBLT is initialized by ViewerProcess
WHILE NOT vRef.running DO Process.Yield[] ENDLOOP;
v ← vRef.viewer ← ViewerOps.CreateViewer[
flavor: viewerClassAtom,
info: [
name: Caption[design],
scrollable: FALSE,
icon: CDEnvironment.GetIcon[design],
iconic: FALSE,
column: ColumnForNewViewer[],
tipTable: CDEnvironment.GetTipTable[design],
newVersion: IsNewVersion[design],
data: vRef
],
paint: FALSE --important: vRef.viewer is initialized only after return
paint: TRUE --sorry, must check elsewhere for this case, otherwise viewerpackage blusters
];
vRef.dClip ← CDVScale.GetClipRecord[vRef.intendedScale, v.cw, v.ch];
IF CDBasics.NonEmpty[bb]
THEN {
--but redraw does not yet come through... (clip area empty!)
CDViewer.ShowAndScale[v, bb];
CDDrawQueue.Flush[vRef.ct]; --I don't trust vRef
vRef.scale ← vRef.intendedScale;
vRef.dClip ← CDVScale.GetClipRecord[vRef.intendedScale, v.cw, v.ch];
};
CDDrawQueue.Flush[vRef.ct]; --I don't trust vRef
CDDrawQueue.ChangeClipArea[vRef.ct, vRef.dClip];
ViewerOps.PaintViewer[v, all];
EnableCursoring[vRef];
Include[vRef];
};
ColumnForNewViewer:
PROC []
RETURNS [col: ViewerClasses.Column←left] = {
--selects colordisplay if it is on and free
colorDisplayEmpty: BOOL ← TRUE;
CheckColorScreen: ViewerOps.EnumProc = {
-- PROC [v: Viewer] RETURNS [BOOL ← TRUE]
IF v.column=color
AND ~v.iconic
AND ~v.offDeskTop
THEN
RETURN [colorDisplayEmpty ← FALSE]
};
IF WindowManager.colorDisplayOn
AND putNewViewerOnColor
THEN {
ViewerOps.EnumerateViewers[CheckColorScreen];
IF colorDisplayEmpty THEN col ← color
}
};
DestroyViewer: ViewerClasses.DestroyProc = {
WITH self.data
SELECT
FROM
vRef: VRef => {
CDValue.Store[vRef.actualDesign, $CDxNewVersion, (IF self.newVersion THEN $T ELSE NIL)];
Destroy[vRef];
self.data ← NIL;
};
ENDCASE => NULL;
};
ViewerCorDEvent: ViewerEvents.EventProc = {
-- PROC [viewer: Viewer, event: ViewerEvent, before: BOOL] RETURNS [abort: BOOL ← FALSE]
WITH viewer.data
SELECT
FROM
vRef: VRef => CDDrawQueue.ChangeClipArea[vRef.ct, CDBasics.empty];
ENDCASE => NULL;
IF cursoredCDViewer=viewer THEN cursoredCDViewer ← NIL
};
ViewerChangeColEvent: ViewerEvents.EventProc = {
--we do this to force Notify to check whether we are in 24 bit per pixel mode
IF viewer=cursoredCDViewer
THEN
IF Terminal.GetColorMode[InterminalBackdoor.terminal].full
THEN
cursoredCDViewer ← NIL;
};
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
New:
PUBLIC
ENTRY
PROC [design:
CD.Design]
RETURNS [vRef: VRef←
NIL] = {
ENABLE UNWIND => NULL;
NewScale:
PROC [design:
CD.Design]
RETURNS [CDVScale.ScaleRec] = {
scale: INT = CDValue.FetchInt[boundTo: design, key: $CDxInitScale, propagation: global, ifNotFound: 6];
grid: INT = CDValue.FetchInt[boundTo: design, key: $CDxInitGrid, propagation: global, ifNotFound: design.technology.lambda];
RETURN [ CDVScale.MakeScale[
nscale: MIN[MAX[scale, 0], CDVScale.scaleNum-1],
grid: MIN[MAX[grid, 0], 512],
off: [0, 0]
]];
};
InitDesignRec:
PROC [vRef: VRef] = {
FOR l:
LIST
OF VRef ← allVRefs, l.rest
WHILE l#
NIL
DO
IF vRef.actualDesign=l.first.actualDesign THEN { vRef.designRec ← l.first.designRec; RETURN };
ENDLOOP;
vRef.designRec ←
NEW[CDVPrivate.VPrivatePerDesign ← [
outlineProcLC: CDVPrivate.DefaultOutLine,
currentLayer: CD.errorLayer
]];
CDVPrivate.SetCursorMode[vRef, NIL];
};
InitVRef:
PROC [design:
CD.Design]
RETURNS [vRef: VRef] = {
b: REF BOOL = NEW[BOOL←FALSE];
vRef ←
NEW[CDVPrivate.VRec ← [
actualDesign: design,
ct: CDDrawQueue.Create[design, b, CDBasics.empty],
scale: NewScale[design],
dClip: CDBasics.empty,
intendedScale: NewScale[design],
stoprequest: b,
environment: CDProperties.GetDesignProp[design, $CDxDrawEnvironment]#$FALSE,
symbolics: CDProperties.GetDesignProp[design, $CDxDrawSymbolics]#$FALSE,
borders: CDProperties.GetDesignProp[design, $CDxSkipBorder]=$FALSE,
personalColors: CDColors.globalColors,
cursorInhibitations: 1, --disabled, not yet ready
properties: CD.InitPropRef[]
]];
InitDesignRec[vRef];
};
--New
--all critical work is done in procedures, so UNWIND really should work
vRef ← InitVRef[design];
};
Include:
ENTRY
PROC [vRef: VRef] = {
allVRefs ← CONS[vRef, allVRefs];
};
Destroy:
PUBLIC
ENTRY
PROC [vRef: VRef] = {
ENABLE UNWIND => NULL;
IF vRef#
NIL
THEN {
--allVRefs ← LO OPHOLE[List.DRemove[ref: vRef, list: LO OPHOLE[allVRefs]]];
IF allVRefs#
NIL
THEN {
IF allVRefs.first=vRef THEN allVRefs ← allVRefs.rest
ELSE {
t: LIST OF VRef ← allVRefs;
WHILE t.rest#
NIL
DO
-- Assert t#NIL
IF t.rest.first=vRef THEN t.rest ← t.rest.rest
ELSE t ← t.rest
ENDLOOP
}
};
CDDrawQueue.Destroy[vRef.ct];
}
};
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
NoteProfileChange: UserProfile.ProfileChangedProc = {
-- PROC [reason: ProfileChangeReason]
catchCritical ← UserProfile.Boolean["ChipNDale.CatchLowLevelErrors", TRUE];
catchWedging ← catchCritical OR UserProfile.Boolean["ChipNDale.CatchErrorsWhichCauseDeadlock", TRUE];
putNewViewerOnColor ← UserProfile.Boolean["ChipNDale.FirstViewerOnColor", TRUE];
};
UserProfile.CallWhenProfileChanges[NoteProfileChange];
TerminalIO.AddLock[TerminalLock, TerminalFree];
CDVFurtherPainters.InstallFurtherPaint[keyValue: $changeScale, proc: Flushed];
CDVFurtherPainters.InstallFurtherPaint[keyValue: $flushed, proc: Flushed];
CDEvents.RegisterEventProc[$ResetDesign, CDEventHappened];
CDEvents.RegisterEventProc[$RenameDesign, CDEventHappened];
CDEvents.RegisterEventProc[$AfterPush, CDEventHappened];
CDEvents.RegisterEventProc[$AfterPop, CDEventHappened];
ViewerOps.RegisterViewerClass[viewerClassAtom, viewerClassRec];
[] ← ViewerEvents.RegisterEventProc[proc: ViewerCorDEvent, event: close, filter: viewerClassAtom, before: TRUE];
[] ← ViewerEvents.RegisterEventProc[proc: ViewerCorDEvent, event: destroy, filter: viewerClassAtom, before: TRUE];
[] ← ViewerEvents.RegisterEventProc[proc: ViewerChangeColEvent, event: changeColumn, filter: viewerClassAtom, before: TRUE];
TerminalIO.WriteRopes[greeting, date, copyRight];
END.