ViewerAdjustImpl.mesa; written by S. McGregor
Edited by McGregor on August 4, 1983 1:27 pm
Last Edited by: Maxwell, May 20, 1983 9:58 am
Last Edited by: Pausch, August 15, 1983 10:46 am
DIRECTORY
Cursors USING [AddCursorCorner, SetCursor],
Imager USING [Context, MaskBits, SetColor],
InputFocus USING [CaptureButtons, ReleaseButtons],
MessageWindow USING [Append, Clear],
Process USING [Detach],
Rope USING [ROPE],
TIPUser USING [InstantiateNewTIPTable, TIPScreenCoords, TIPTable],
ViewerClasses USING [NotifyProc, Viewer],
ViewerLocks,
ViewerOps,
ViewerSpecs,
WindowManager USING [RestoreCursor];
ViewerAdjustImpl: CEDAR MONITOR
IMPORTS Cursors, Imager, InputFocus, MessageWindow, Process, TIPUser, ViewerLocks, ViewerOps, ViewerSpecs, WindowManager
EXPORTS ViewerOps
SHARES ViewerClasses, ViewerLocks, ViewerOps = BEGIN OPEN ViewerClasses;
viewerMinHeight: INTEGER ~ ViewerSpecs.captionHeight;
AdjustMode: TYPE = {top, bottom, column, none} ;
mode: AdjustMode ← none;
context: Imager.Context;
adjustBottom: BOOL;
xPos, width, minY, maxY: INTEGER;
lastX, lastY: INTEGERLAST[INTEGER];
Adjust: PUBLIC ENTRY PROC [viewer: Viewer] = BEGIN
ViewerLocks.LockViewerTree[];
InputFocus.CaptureButtons[BoundaryAdjustNotify, vaTIP, viewer];
context ← ViewerOps.AcquireContext[NIL];
Imager.SetColor[context, $XOR];
[minY, maxY] ← ComputeYBounds[viewer];
minY ← ViewerSpecs.openBottomY;
maxY ← ViewerSpecs.openLeftTopY;
xPos ← viewer.wx;
width ← viewer.ww;
adjustBottom ← FALSE;
END;
EndAdjust: PROC = BEGIN
ChangeMode[none, 0, 0];
InputFocus.ReleaseButtons[];
ViewerOps.ReleaseContext[context];
ViewerLocks.ReleaseViewerTree[];
END;
BoundaryAdjustNotify: NotifyProc = BEGIN
ENABLE UNWIND => EndAdjust[];
mouseX, mouseY: INTEGER;
FOR list: LIST OF REF ANY ← input, list.rest UNTIL list = NIL DO
WITH list.first SELECT FROM
x: ATOM => SELECT x FROM
$Abort => BEGIN
EndAdjust[];
IF self.openHeight = 0
THEN ViewerOps.PaintViewer[self, caption]
ELSE {self.openHeight ← 0; ViewerOps.ComputeColumn[self.column]};
END;
$Move => BEGIN
SELECT mode FROM
top  => IF mouseX NOT IN (self.wx..self.wx+self.ww) THEN
ChangeMode[column, mouseX, mouseY]
ELSE IF mouseY <= self.wy THEN
ChangeMode[bottom, mouseX, mouseY]
ELSE Feedback[mouseX, mouseY];
bottom => IF mouseX NOT IN [self.wx..self.wx+self.ww) THEN
ChangeMode[column, mouseX, mouseY]
ELSE IF mouseY >= self.wy+self.wh THEN
ChangeMode[top, mouseX, mouseY]
ELSE Feedback[mouseX, mouseY];
column => Feedback[mouseX, mouseY];
ENDCASE => BEGIN
ViewerOps.PaintViewer[self, caption];
ChangeMode[top, mouseX, mouseY];
END;
END;
$End  => BEGIN
change: AdjustMode ← mode;
EndAdjust[];
SELECT change FROM
top  => BEGIN
self.openHeight ← MAX[viewerMinHeight, mouseY-self.wy];
ViewerOps.ComputeColumn[self.column];
END;
bottom => BEGIN
self.openHeight ← MAX[viewerMinHeight, self.wy+self.wh-mouseY];
ViewerOps.ComputeColumn[self.column];
END;
column => ViewerOps.MoveBoundary[mouseX, mouseY];
ENDCASE;
END;
ENDCASE => NULL;
z: TIPUser.TIPScreenCoords => [mouseX, mouseY] ← Clip[z];
ENDCASE => ERROR;
ENDLOOP;
END;
ChangeMode: PROC [newMode: AdjustMode, mouseX, mouseY: INTEGER] = BEGIN
Feedback[LAST[INTEGER], LAST[INTEGER], TRUE];
SELECT newMode FROM
top  => {Cursors.SetCursor[pointUp]; Cursors.AddCursorCorner[upperSide]};
bottom => {Cursors.SetCursor[pointDown]; Cursors.AddCursorCorner[lowerSide]};
column => {Cursors.SetCursor[activate]; SetMsg[]};
ENDCASE => {WindowManager.RestoreCursor[]; SetMsg[]};
mode ← newMode;
IF mode#none THEN Feedback[mouseX, mouseY];
END;
SetMsg: PROC [msg: Rope.ROPENIL] = TRUSTED INLINE BEGIN
these are forked in case a client has done DisablePainting during an Adjust
IF msg=NIL THEN Process.Detach[FORK MessageWindow.Clear[]]
ELSE Process.Detach[FORK MessageWindow.Append[msg, TRUE]];
END;
grey: CARDINAL ← 122645B;
Feedback: PROC [x, y: INTEGER, remove: BOOLFALSE] = BEGIN
GreyRectangle: PROC [x, y, w, h: INTEGER] = TRUSTED INLINE BEGIN
Imager.MaskBits[context, @grey, 1, [0,0,16,1], [x,y,w,h]];
END;
Show: PROC [x, y: INTEGER] = BEGIN
IF mode=column THEN BEGIN
GreyRectangle[x-1, y, 2, ViewerSpecs.openLeftTopY-y+1];
GreyRectangle[0, y-1, ViewerSpecs.screenW, 2];
END
ELSE GreyRectangle[xPos, y+1, width, 2];
END;
IF lastX=x AND lastY=y THEN RETURN; -- no change
IF lastX#LAST[INTEGER] THEN Show[lastX, lastY];
IF remove THEN lastX ← lastY ← LAST[INTEGER]
ELSE {Show[x, y]; lastX ← x; lastY ← y};
END;
Clip: PROC [position: TIPUser.TIPScreenCoords] RETURNS [x, y: INTEGER] = BEGIN
OPEN ViewerSpecs;
fudge : INTEGER = 15; -- RFP addition, used to "snap" to default column boundary
-- RFP addition: "snap" to the default setting for the two columns, and center
IF ABS[position.mouseX-(screenW/2)] < fudge THEN x ← (screenW/2)
ELSE IF ABS[position.mouseX-initialOpenLeftWidth] < fudge THEN x ← initialOpenLeftWidth
ELSE x ← position.mouseX;
IF mode=column THEN BEGIN
IF position.mouseY <= openBottomY THEN adjustBottom ← TRUE;
IF adjustBottom THEN y ← SELECT position.mouseY FROM
< iconHeight => position.mouseY,
< iconHeight+iconSpacing+(iconHeight/2) => iconHeight+iconSpacing,
ENDCASE  => 2*(iconHeight+iconSpacing)
ELSE y ← openBottomY;
END
ELSE y ← SELECT position.mouseY FROM
< minY => minY,
> maxY => maxY,
ENDCASE => position.mouseY
END;
vaTIP: TIPUser.TIPTable ←
TIPUser.InstantiateNewTIPTable["/Indigo/CedarViewers/Viewers/ViewerAdjust.tip"];
END.
ComputeYBounds: PROC [viewer: Viewer] RETURNS [min, max: INTEGER] =
BEGIN OPEN ViewerSpecs;
LimitProc: ViewerOps.EnumProc = BEGIN
IF v.column=viewer.column AND NOT v.iconic THEN columnRequested ← columnRequested +
MAX[viewerMinHeight, (IF v.position#0 THEN v.position ELSE v.openHeight)];
END;
columnRequested: INTEGER ← 0;
columnFree, percent: INTEGER;
columnSpace: INTEGER ~ openLeftTopY-openBottomY;
ViewerOps.EnumerateViewers[LimitProc];
percent ← 10*((11*columnRequested-1)/columnSpace); -- round up
SetMsg[Rope.Cat["The ",
SELECT viewer.column FROM left => "left", right => "right", ENDCASE => "color",
" column is constrained ", Convert.ValueToRope[[signed[percent, 10]]], "%"]];
columnFree ← MAX[0, columnSpace - columnRequested -
(viewer.wh-(IF viewer.position#0 THEN viewer.position ELSE viewer.openHeight))];
min ← MAX[MIN[viewer.wy, viewer.wy-columnFree], openBottomY];
max ← MIN[MAX[viewer.wy+viewer.wh, viewer.wy+viewer.wh+columnFree], openLeftTopY];
END;