CDInterestRectsImpl.mesa
Copyright © 1984 by Xerox Corporation. All rights reserved.
Created by: Jacobi, September 13, 1984 3:21:36 pm PDT
Last Edited: Jacobi, November 20, 1984 3:53:56 pm PST
DIRECTORY
CD,
CDInterestRects,
CDBasics,
CDEvents,
CDProperties,
CDX,
TerminalIO,
TokenIO;
CDInterestRectsImpl: CEDAR PROGRAM
IMPORTS CDBasics, CDEvents, CDProperties, CDX, TerminalIO, TokenIO
EXPORTS CDInterestRects =
BEGIN
-- InterestRect: A special rectangle associated to an object.
-- It defaults to the objects innerrect.
GetInterestRect: PUBLIC PROC [ob: CD.ObPtr] RETURNS [r: CD.DesignRect, useInnerrect: BOOL] =
BEGIN
WITH CDProperties.GetPropFromObject[from: ob, prop: interestRectProperty] SELECT FROM
pp: REF CD.DesignRect => RETURN [pp^, FALSE]
ENDCASE => RETURN [ ob.p.insideRect[ob], TRUE ]
END;
SetInterestRect: PUBLIC PROC [ob: CD.ObPtr, r: CD.DesignRect] =
BEGIN
IF ~ob.p.inDirectory THEN {
TerminalIO.WriteRope["do not set the interest rect for imutable object\n"];
RETURN
};
IF r.x1>r.x2 OR r.y1>r.y2 THEN
CDProperties.PutPropOnObject[onto: ob, prop: interestRectProperty, val: NIL]
ELSE
CDProperties.PutPropOnObject[onto: ob, prop: interestRectProperty, val: NEW[CD.DesignRect←r]]
END;
InternalWriteProperty: PROC [prop: REF, val: REF] =
BEGIN
p: REF CD.DesignRect ← NARROW[val];
TokenIO.WriteInt[p.x1];
TokenIO.WriteInt[p.y1];
TokenIO.WriteInt[p.x2];
TokenIO.WriteInt[p.y2];
END;
InternalReadProperty: PROC [prop: ATOM] RETURNS [val: REF] =
BEGIN
x1: INT = TokenIO.ReadInt[];
y1: INT = TokenIO.ReadInt[];
x2: INT = TokenIO.ReadInt[];
y2: INT = TokenIO.ReadInt[];
val ← NEW[CD.DesignRect←[x1, y1, x2, y2]]
END;
MoveOrigin: CDEvents.EventProc =
--PROC [event: REF, design: CD.Design, x: REF] RETURNS [dont: BOOL�LSE]
BEGIN
notificationRec: REF CDX.NotificationRec = NARROW[x];
WITH CDProperties.GetPropFromObject[from: notificationRec.me, prop: interestRectProperty] SELECT FROM
pp: REF CD.DesignRect => {
offset: CD.DesignPosition = CDBasics.SubPoints[notificationRec.new, notificationRec.old];
SetInterestRect[notificationRec.me, CDBasics.MoveRect[pp^, offset]];
};
ENDCASE => NULL; --since the innerrect is used
END;
interestRectProperty: REF ATOM = NEW[ATOM←$interestRect];
[] ← CDProperties.RegisterProperty[interestRectProperty];
CDProperties.InstallProcs[prop: interestRectProperty,
new: CDProperties.PropertyProcsRec[
makeCopy: CDProperties.CopyVal, --because we treat the coordinates readonly
internalWrite: InternalWriteProperty,
internalRead: InternalReadProperty,
exclusive: TRUE
]
];
CDEvents.RegisterEventProc[CDX.originMoveEvent, MoveOrigin];
END.