PopUpSelection2.Mesa
Copyright Ó 1983, 1985, 1986, 1991 by Xerox Corporation. All rights reserved.
Created by Christian Jacobi, August 3, 1983 9:47 am
Last edited by: Christian Jacobi, August 26, 1986 10:21:13 am PDT
Last tweaked by Mike Spreitzer on January 30, 1989 11:37:30 am PST
Willie-s, January 7, 1992 3:54 pm PST
DIRECTORY Imager, PopUpButtons, Rope, ViewerClasses;
PopUpSelection2: CEDAR DEFINITIONS =
A pop-up menu abstraction.
BEGIN
ROPE: TYPE = Rope.ROPE;
All coordinates and sizes are in pixels.
Create:
PROC [choices: ChoiceS, doc:
ROPE, allMayBeUp:
BOOL, header: Image ¬
NIL, left, top: Label ¬ nullLabel, columns:
NAT ¬ 1, fullRows:
NAT ¬ 0, timeOut:
NAT ¬ 0]
RETURNS [Menu];
IF NOT allMayBeUp
THEN Pop returns as soon as it notices all mouse buttons are up
ELSE Pop waits for down-click, then returns on up-click.
ChoiceList: TYPE ~ LIST OF RECORD [key: ROPE, doc: ROPE ¬ NIL];
ChoiceS: TYPE = REF ChoiceSequence;
ChoiceSequence: TYPE = RECORD [elts: SEQUENCE length: NAT OF Choice];
Choice:
TYPE =
RECORD [
image: Image,
doc: ROPE];
nullChoice: Choice = [NIL, NIL];
Image: TYPE ~ REF ImagePrivate;
ImagePrivate: TYPE ~ PopUpButtons.ImagePrivate;
defaultFont: Imager.Font;
Colors: TYPE ~ PopUpButtons.Colors;
defaultColors, inverseColors: Colors;
dontPaint: READONLY Imager.SpecialColor;
Align: TYPE ~ PopUpButtons.Align;
bottomLeft: Align ~ [0.0, 0.0];
center: Align ~ [0.5, 0.5];
ImageForRope: PROC [rope: ROPE, colors: Colors ¬ NIL, font: Imager.Font ¬ NIL, align: Align ¬ bottomLeft] RETURNS [image: Image];
nullLabel: Label = NIL;
Label: TYPE = REF LabelPrivate;
LabelPrivate:
TYPE =
RECORD [
minSpacing--parallel to edge being labelled--, minWidth--perpendicular--: NAT,
Draw: PROC [context: Imager.Context, org: Imager.VEC, n, spacing, width: NAT, data: REF ANY],
data: REF ANY
];
MouseButton: TYPE ~ ViewerClasses.MouseButton;
Menu: TYPE = REF MenuPrivate;
MenuPrivate: TYPE;
Pop:
PROC [menu: Menu, default:
NAT ¬ 0, position:
REF ¬
NIL,
InNotifier: Consumer ¬
NIL, notifyData:
REF
ANY ¬
NIL]
RETURNS [
INT, MouseButton];
Shows a pop-up menu and returns the number of the selected entry.
returns: 1 for first choice, 2 for second...
0 if selected outside menu or on header-line
-1 if timed out
default: Hint for initial selection by implicit mouse movement. 0 if no default.
position: Hint to override mouse position. See documentation for possible types.
Pop must not be called from inside a viewers-repaint or a TIP-notify procedure. You can get the answer in the notifier process, however, by supplying InNotifier & notifyData.
Consumer:
TYPE =
PROC [
INT, MouseButton,
REF
ANY];
Must not be in a local frame, because it will be called from a different process (maybe even after Pop returns, depending on scheduling).
Sequify: PROC [list: ChoiceList] RETURNS [seq: ChoiceS];
PopRopes:
PROC
[
choices: ChoiceList,
doc: ROPE,
allMayBeUp: BOOL,
default: NAT ¬ 0,
header: ROPE ¬ NIL,
left, top: Label ¬ nullLabel,
columns: NAT ¬ 1,
fullRows: NAT ¬ 0,
timeOut: NAT ¬ 0,
position: REF ¬ NIL,
InNotifier: Consumer ¬ NIL,
notifyData: REF ANY ¬ NIL]
RETURNS [sel:
INT, mb: MouseButton];
An easy way to go.
END.