Browser2D.mesa
Copyright Ó 1992 by Xerox Corporation. All rights reserved.
Greene, June 1, 1990 8:23 pm PDT
DIRECTORY
Draw2d,
Imager,
QuadTree,
Rope,
Vector,
ViewerClasses;

Browser2D: CEDAR DEFINITIONS =
BEGIN
Item: TYPE = REF ItemRec;
ItemRec: TYPE = RECORD [
class: ItemClass,
data: REF ANY
];
ItemClass: TYPE = REF ItemClassRec;
ItemClassRec: TYPE = RECORD [
paint: ItemPaintProc ¬ NIL,
selectionNotify: ItemSelectionNotifyProc ¬ NIL,
distanceTo: ItemDistanceToProc ¬ NIL,
boundingBox: ItemBoundingBoxProc --must not be defaulted
];
ItemPaintProc: TYPE = PROC [self: Item, commonData: REF ANY, context: Imager.Context, zip: Draw2d.Zip, how: Instruction];
Client supplied procedure to draw the item.
Defaulting this means that the item's bounding box will be drawn.
Instruction: TYPE = {normal, userSelected, clientSelected, deSelect};
ItemSelectionNotifyProc: TYPE = PROC [self: Item, commonData: REF ANY, how: Instruction];
When an item is selected in the browser, the items paint proc is called with how = userSelected,
and then this procedure is called. Any work not related to painting should be included here to avoid locking problems.
ItemDistanceToProc: TYPE = PROC [self: Item, commonData: REF ANY, location: Vector.VEC] RETURNS [distance: REAL];
This procedure should report the distance from the "item" to the "location" to facilitate selecting the nearest item in the browser.
Here the default is the Manhattan distance to the bounding box.
ItemBoundingBoxProc: TYPE = PROC [self: Item, commonData: REF ANY] RETURNS [box: BoundingBox];
BoundingBox: TYPE = QuadTree.BoundingBox;
RECORD[lowerLeft, upperRight: Vector.VEC];
LeastCommonBoundingBox: PROC [a, b: BoundingBox] RETURNS [c: BoundingBox];
BrowserHandle: TYPE = REF BrowserHandleRec;
BrowserHandleRec: TYPE;
Create: PROC [size: BoundingBox, selectionDistance: REAL, icon: ViewerClasses.IconFlavor, caption: Rope.ROPE, commonData: REF ANY, Destroy: DestroyProc ¬ NIL] RETURNS [browser: BrowserHandle];
DestroyProc: TYPE = PROC [commonData: REF ANY];
AddItem: PROC [browser: BrowserHandle, item: Item, paint: BOOL ¬ FALSE];
RepaintBrowser: PROC [browser: BrowserHandle];
Normally used after a long sequence of AddItems with paint = FALSE, if AddItem is called with paint = TRUE then this is not needed.
SelectItem: PROC [browser: BrowserHandle, item: Item];
First the item's paint proc is called with how = clientSelected, then the item's notify proc is called with how = clientSelected.
BlinkSelections: PROC [browser: BrowserHandle, times: INT ¬ 3, delayMSecs: INT ¬ 1000];
The item's paint proc is called alternately with how = normal and how = clientSelected.
ClearAllSelections: PROC [browser: BrowserHandle];
CenterSelections: PROC [browser: BrowserHandle, margin: Vector.VEC, tolerance: Vector.VEC, force: BOOLEAN ¬ FALSE] RETURNS [moved: BOOLEAN];
Compute the bounding box of the selected items. If the box is closer than "tolerance" to the edges of the current viewport (or force = TRUE), then rescale the viewer so that the bounding box fits within the viewport with "margin" amount of space surrounding it.
CenterEverything: PROC [browser: BrowserHandle];
SetMessageWindow: PROC [browser: BrowserHandle, contents: Rope.ROPE, times: INT ¬ 0, delayMSecs: INT ¬ 1000];
Used to insert Ropes into a small message window at the top of a browser. Times > 0 blinks the message window.
END.