XTkCollections.mesa
Copyright Ó 1989, 1990, 1991 by Xerox Corporation. All rights reserved.
Created by Christian Jacobi, June 15, 1989 11:13:50 am PDT
Christian Jacobi, August 23, 1991 2:06 pm PDT
DIRECTORY
Xl USING [Geometry],
XTk USING [Class, ImplementorClass, Mapping, RemoveChildProc, Widget, WidgetSpec],
XTkFriends USING [InstPart];
XTkCollections: CEDAR DEFINITIONS
IMPORTS XTkFriends ~
BEGIN
A friends level interface to XTk, useful to define composite subclasses.
Basics
Widget: TYPE = XTk.Widget;
CollectionWidget: TYPE = XTk.Widget;
Create: PROC [widgetSpec: XTk.WidgetSpec ¬ [], children: LIST OF Widget ¬ NIL, childCount: NAT ¬ 0] RETURNS [CollectionWidget];
Creates a collection widget.
childCount: caller might guess a number; hint only.
RemoveChild: PROC [collection: CollectionWidget, child: Widget, reConsiderNow: BOOL ¬ TRUE, preventDestruction: BOOL ¬ FALSE];
Removes child from parent: Immediately unrealizes X window and removes childs data structures from parent.
Parent may delay reconsidering its layout until call of ReConsiderChildrenLR [or configure of collection].
Childs data structures will also be destroyed unless preventDestruction is TRUE.
Client callable for many subclasses.
RemoveChildLR: PROC [collection: CollectionWidget, child: Widget, reConsiderNow: BOOL ¬ TRUE, preventDestruction: BOOL ¬ FALSE];
Internal RemoveChild.
Callable from rootThread only; Client callable for many subclasses.
AddChild: PROC [collection: CollectionWidget, newChild: Widget, position: REF ¬ NIL, reConsiderNow: BOOL ¬ TRUE];
Adds child to parents data structures. Visibility and X window creation might be delayed until call of ReConsiderChildrenLR [or configure of collection].
Client callable for many subclasses.
AddChildLR: PROC [collection: CollectionWidget, newChild: Widget, position: REF ¬ NIL, reConsiderNow: BOOL ¬ TRUE];
Internal AddChild.
Callable from rootThread only [or while creation]; Client callable for many subclasses.
AddChildren: PROC [collection: CollectionWidget, children: LIST OF Widget, reConsiderNow: BOOL ¬ TRUE];
Conveniance procedure: like multiple calls to AddChild, but faster for some classes.
See AddChild for details.
AddChildrenLR: PROC [collection: CollectionWidget, children: LIST OF Widget, reConsiderNow: BOOL ¬ TRUE];
Internal AddChildren.
See AddChildLR for details.
EnumerateChildren: PROC [collection: CollectionWidget, eachChild: EachChildProc, data: REF ¬ NIL];
Shallow enumerates children.
Adding or removing children while enumeration might not be considered in time.
EachChildProc: TYPE = PROC [collection: CollectionWidget, child: Widget, data: REF, idx: NAT] RETURNS [stop: BOOL ¬ FALSE];
AssertEmptySlotsLR: PROC [collection: CollectionWidget, num: NAT ¬ 0];
Makes shure collection has at least num empty children slots.
Must be called on rootThread only!!.
GetCollectionInstPart: PROC [collection: Widget] RETURNS [CollectionInstPart] = INLINE {
RETURN [ NARROW[XTkFriends.InstPart[collection, collectionClass]] ];
};
Subclassing
collectionClass: READONLY XTk.Class;
Subclasses must choose a removeChildLR procedure!
AddChildProc: TYPE = PROC [collection: CollectionWidget, newChild: Widget, position: REF, reConsiderNow: BOOL];
When called procedure sees newChild.s.parent already assigned and screen bound if necessary.
AddChildrenProc: TYPE = PROC [collection: CollectionWidget, children: LIST OF Widget, reConsiderNow: BOOL];
Like AddChildProc, maybe faster for some classes.
EnumerateChildrenProc: TYPE = PROC [collection: CollectionWidget, eachChild: EachChildProc, data: REF];
CollectionClassPart: TYPE = REF CollectionClassPartRec;
CollectionClassPartRec: TYPE = RECORD [
enumerateChildren: EnumerateChildrenProc,
addChildLR: AddChildProc,
addChildrenLR: AddChildrenProc
];
NewCollectionClassPart: PROC [class: XTk.ImplementorClass] RETURNS [CollectionClassPart];
Modifies subClass to use a new copy of the CollectionClassPartRec. Returns a ref to the new copy which can be changed safely. (The new copy replaces the default original CollectionClassPartRec used for further sub-sub-classes).
CollectionInstPart: TYPE = REF CollectionInstPartRec;
CollectionInstPartRec: TYPE = RECORD [
slotsUsed: NAT ¬ 0,
hasEmptySlots: BOOL ¬ FALSE,
niloutSizingForked: BOOL ¬ FALSE,
reserved: REF ¬ NIL,
sizing: REF ConfigureData ¬ NIL, --allocated only while needed
children: REF ChildrenData ¬ NIL
];
ChildrenData: TYPE = RECORD [
children: SEQUENCE count: NAT OF ChildrenRec
];
ChildrenRec: TYPE = RECORD [
child: Widget
];
ConfigureData: TYPE = RECORD [
d: SEQUENCE count: NAT OF ConfigureRec
];
ConfigureRec: TYPE = RECORD [
g: Xl.Geometry ¬ [],
mapping: XTk.Mapping ¬ dontUse
];
RemoveChildInPlaceLR: XTk.RemoveChildProc;
To be used by subclasses only to implement inheritance.
RemoveChildAndSqueezeLR: XTk.RemoveChildProc;
To be used by subclasses only to implement inheritance.
AddChildInFirstPlaceLR: PROC [collection: CollectionWidget, newChild: Widget, position: REF ¬ NIL, reConsiderNow: BOOL ¬ TRUE];
To be used by subclasses only to implement inheritance.
BasicEnumerateChildren: PROC [collection: CollectionWidget, eachChild: EachChildProc, data: REF ¬ NIL];
To be used by subclasses only to implement inheritance.
END.