Name
insert_child — Composite method to insert a child into the array of children.
Synopsis
typedef void (∗XtWidgetProc)(Widget);
Widget w;
Arguments
wSpecifies the widget.
Description
To add a child to the parent’s list of children, XtCreateWidget calls the parent’s insert_child method.
Most composite widgets inherit this method from their superclass by specifying XtInheritInsertChild for the insert_child field in the class record. Composite’s insert_child method calls the insert_position function (set with the XtNinsertPosition resource) and inserts the child at the specified position.
Some Composite widgets define their own insert_child method so that they can order their children in some convenient way, create companion controller widgets for a new widget, or limit the number or class of their children widgets.
A Composite widget class that wishes to allow non-widget children (i.e., Objects or RectObjs) must initialize a CompositeClassExtension extension record and set the accepts_objects field in this record to True. If the CompositeClassExtension record is not specified or the accepts_objects field is False, the Composite widget can assume that all its children are widgets without an explicit subclass test in the insert_child method.
This method can also be inherited dynamically and modified if the subclass widget wants to use it but wants to perform additional processing when the child is inserted. The example InsertChild method shown below does this:
static XtArgsProc InsertChild(w, args, num_args)
Widget w;
ArgList args;
Cardinal ∗num_args;
{
CompositeWidgetClass superclass;
/∗
∗ Satisfy parental responsibilities
∗/
superclass = (CompositeWidgetClass) compositeWidgetClass;
(∗superclass->composite_class.insert_child)(w,args,num_args);
}
If there is not enough room to insert a new child in the children array (that is, num_children = num_slots), the insert_child method must first reallocate the array and update num_slots. The insert_child method then places the child wherever it wants and increments the num_children field.
Examples
The following is the insert_child method of the Athena Paned widget class:
static void InsertChild(w, args, argcount)
register Widget w;
ArgList args;
Cardinal ∗argcount;
{
Pane pane = PaneInfo(w);
/∗ insert the child widget in the composite children list with the ∗/
/∗ superclass insert_child routine. ∗/
(∗SuperClass->composite_class.insert_child)(w, args, argcount);
if (!IsPane(w)) return;
/∗ ||| Panes will be added in the order they are ∗/
/∗ created, temporarily ∗/
if ( pane->show_grip == TRUE ) {
CreateGrip(w);
if (pane->min == PANED_GRIP_SIZE)
pane->min = PaneSize(pane->grip, IsVert((PanedWidget)\
XtParent(w)));
}
else {
if (pane->min == PANED_GRIP_SIZE)
pane->min = 1;
pane->grip = NULL;
}
pane->size = 0;
pane->paned_adjusted_me = FALSE;
} /∗ InsertChild ∗/