ATextVBT.Tis aVBTthat displays a text string.
The minimum size of aTextVBTis just large enough to display its text (surrounded by any margins that were supplied when theTextVBTwas created), except that if its text is empty its minimum size is just large enough to display the text “X”. Its preferred size is the same as its minimum size, and its maximum size is very large.
INTERFACE TextVBT;
IMPORT VBT, Font, PaintOp, Rect; TYPE
T <: Public;
Public = VBT.Leaf OBJECT METHODS <* LL.sup <= VBT.mu *>
init(txt: TEXT;
halign, valign: REAL := 0.5; hmargin: REAL := 0.5;
vmargin: REAL := 0.0;
fnt: Font.T := Font.BuiltIn; bgFg: PaintOp.ColorQuad := NIL): T END;
The callv.init(...)initializesvas aTextVBTthat displays the texttxtin the fontfnt, and returnsv.
The text will be painted withbgFg’s foreground; the background will be painted with bgFg’s background. If bgFg is NIL these default to PaintOp.Fg and
PaintOp.Bg. The text should not contain any newline characters: it will be treated as a single line. Ifhalign = 0.0, the west boundary of the text will be indented by the givenhmargin(in millimeters) from the west boundary of theVBT; ifhalign = 1.0, the east boundary of the text will be inside the east boundary of theVBTby the givenhmargin; for other values ofhalign, the horizontal position of the text is computed by linear interpolation. In particular,halign = 0.5centers the text horizontally. The vertical position is determined byvmarginandvalignin a similar way.
Control-left-click in the text sets the source selection to be a readonly version of the text. Thus you can copy the text out of anyTextVBT.
PROCEDURE New( txt: TEXT;
halign, valign: REAL := 0.5; hmargin: REAL := 0.5;
vmargin: REAL := 0.0;
bgFg: PaintOp.ColorQuad := NIL) : T; <* LL.sup <= VBT.mu *>
New(...)is equivalent toNEW(T).init(...).
PROCEDURE Put(v: T; txt: TEXT); <* LL.sup < v *>
Change the text displayed byvto betxtand markvfor redisplay.
PROCEDURE Get(v: T): TEXT; <* LL.sup < v *>
Return the text displayed by v.
PROCEDURE SetFont( v: T;
fnt: Font.T;
bgFg : PaintOp.ColorQuad := NIL); <* LL.sup = VBT.mu *>
Setv’sfontandbgFgto the given values and markvfor redisplay. IfbgFgis defaulted,PaintOp.bgFgis used.
PROCEDURE GetFont(v: T): Font.T; <* LL.sup = VBT.mu *>
Returnv’s font.
PROCEDURE GetQuad(v: T): PaintOp.ColorQuad; <* LL.sup = VBT.mu *>
Returnv’s color quad.
PROCEDURE GetTextRect(v: T): Rect.T; <* LL.sup = VBT.mu *>
Return the current bounding rectangle ofv’s text.
END TextVBT.
6.2
The TextureVBT interface
ATextureVBT.Tis aVBTthat displays a texture, possibly colored. Its preferred and minimum sizes are zero and its maximum size is very large, in each axis.
INTERFACE TextureVBT;
IMPORT VBT, PaintOp, Pixmap; TYPE
T <: Public;
Public = VBT.Leaf OBJECT METHODS <* LL.sup <= VBT.mu *>
6.3 The HVBar interface 73
txt: Pixmap.T := Pixmap.Solid; nwAlign: BOOLEAN := FALSE): T END;
The call v.init(...) initializesv as a TextureVBT displaying txt with the painting operationop.
The domain ofvwill be painted using the painting operationopand the texture
txt+delta, wheredeltais the origin unlessnwAlignis set toTRUE, in which case
deltawill be set to the northwest corner ofv.
PROCEDURE New(
op: PaintOp.T := PaintOp.BgFg; txt: Pixmap.T := Pixmap.Solid;
nwAlign: BOOLEAN := FALSE): T; <* LL.sup <= VBT.mu *> New(...)is equivalent toNEW(T).init(...).
PROCEDURE Set( v: T;
op: PaintOp.T := PaintOp.BgFg; txt: Pixmap.T := Pixmap.Solid; nwAlign: BOOLEAN := FALSE); <* LL.sup = VBT.mu *>
Changev’s texture and mark it for redisplay.
PROCEDURE Get( v: T;
VAR op: PaintOp.T; VAR txt: Pixmap.T;
VAR nwAlign: BOOLEAN); <* LL.sup = VBT.mu *>
Fetchv’s texture.
END TextureVBT.
6.3
The HVBar interface
An HVBar.Tis an adjustable bar that allows a user to adjust the division of space between the children of anHVSplit.
AnHVBarmust be a child of anHVSplit. When the user pushes a mouse button over the bar, the cursor changes shape and the outline of the bar is highlighted. The highlight follows the cursor as long as the button is down. When the button comes up, the bar callsHVSplit.Adjustto move the bar to the currently highlighted position. If the user tries to move the bar outside the range of positions that are consistent with the size constraints of the children of the parentHVSplit, the highlighted bar will not follow the cursor. If the user chords while dragging, then adjusting mode is cancelled.
The bar has methods that you can override that are called each time the bar is moved, or continuously during adjustment.
In order for the bar to highlight correctly, some ancestor of theHVSpliton which it is installed must be aHighlightVBT. Since Trestle.Installautomatically inserts aHighlightVBTover top-level windows, you usually don’t have to worry about this.
INTERFACE HVBar;
IMPORT VBT, PaintOp, Pixmap, TextureVBT; TYPE
T <: Public;
Public = TextureVBT.T OBJECT METHODS <* LL = VBT.mu *>
pre(READONLY cd: VBT.MouseRec); post(READONLY cd: VBT.MouseRec); during(n: INTEGER);
<* LL <= VBT.mu *>
init(size: REAL := DefaultSize; op: PaintOp.T := PaintOp.BgFg; txt: Pixmap.T := Pixmap.Gray): T END;
The callv.init(...)initializesvas anHVBarwith the given properties and returns
v. This includes callingTextureVBT.T.init(v, op, txt).
The argumentsizegives the number of millimeters that the bar will occupy in the parentHVSplit.
An adjusting bar bcalls b.pre(cd)when it begins adjusting in response to a mouse clickcd. It callsb.during(k)each time the mouse moves during dragging, wherekis the coordinate that thelo(i.e., west or north) edge of the bar would move to if dragging were stopped at that instant. Finally, the bar callsb.post(cd)when it stops adjusting in response to an upclick or chordcd. TheHVSplitwill be adjusted (but not redisplayed) beforeb.post(cd)is called.
The defaultpreandduringmethods highlight the position the bar would move to if dragging were stopped. The defaultpostmethod removes the highlighting.
CONST
DefaultSize = 2.5; PROCEDURE New(
size := DefaultSize; op := PaintOp.BgFg;
txt := Pixmap.Gray): T; <* LL.sup <= VBT.mu *> New(...)is equivalent toNEW(T).init(...).
75