1<?xml version="1.0" encoding="UTF-8" ?>
2<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
3
4<chapter id='Composite_Widgets_and_Their_Children'>
5<title>Composite Widgets and Their Children</title>
6<para>
7Composite widgets (widgets whose class is a subclass of
8<function>compositeWidgetClass</function>)
9can have an arbitrary number of children.
10Consequently, they are responsible for much more than primitive widgets.
11Their responsibilities (either implemented directly by the widget class
12or indirectly by Intrinsics functions) include:
13</para>
14<itemizedlist spacing='compact'>
15  <listitem>
16    <para>
17Overall management of children from creation to destruction.
18    </para>
19  </listitem>
20  <listitem>
21    <para>
22Destruction of descendants when the composite widget is destroyed.
23    </para>
24  </listitem>
25  <listitem>
26    <para>
27Physical arrangement (geometry management) of a displayable subset of
28children (that is, the managed children).
29    </para>
30  </listitem>
31  <listitem>
32    <para>
33Mapping and unmapping of a subset of the managed children.
34    </para>
35  </listitem>
36</itemizedlist>
37<para>
38Overall management is handled by the generic procedures
39<xref linkend='XtCreateWidget' xrefstyle='select: title'/>
40and
41<xref linkend='XtDestroyWidget' xrefstyle='select: title'/>.
42<xref linkend='XtCreateWidget' xrefstyle='select: title'/>
43adds children to their parent by calling the parent's insert_child
44procedure.
45<xref linkend='XtDestroyWidget' xrefstyle='select: title'/>
46removes children from their parent by calling the parent's delete_child
47procedure and ensures that all children of a destroyed composite widget
48also get destroyed.
49</para>
50
51<para>
52Only a subset of the total number of children is actually managed by
53the geometry manager and hence possibly visible.
54For example, a composite editor widget
55supporting multiple editing buffers might allocate one child
56widget for each file buffer,
57but it might display only a small number of the existing buffers.
58Widgets that are in this displayable subset are called managed widgets
59and enter into geometry manager calculations.
60The other children are called unmanaged widgets
61and, by definition, are not mapped by the Intrinsics.
62</para>
63
64<para>
65Children are added to and removed from their parent's managed set by using
66<xref linkend='XtManageChild' xrefstyle='select: title'/>,
67<xref linkend='XtManageChildren' xrefstyle='select: title'/>,
68<xref linkend='XtUnmanageChild' xrefstyle='select: title'/>,
69<xref linkend='XtUnmanageChildren' xrefstyle='select: title'/>,
70and
71<xref linkend='XtChangeManagedSet' xrefstyle='select: title'/>,
72which notify the parent to recalculate the physical layout of its children
73by calling the parent's change_managed procedure.
74The
75<xref linkend='XtCreateManagedWidget' xrefstyle='select: title'/>
76convenience function calls
77<xref linkend='XtCreateWidget' xrefstyle='select: title'/>
78and
79<xref linkend='XtManageChild' xrefstyle='select: title'/>
80on the result.
81</para>
82
83<para>
84Most managed children are mapped,
85but some widgets can be in a state where they take up physical space
86but do not show anything.
87Managed widgets are not mapped automatically
88if their <emphasis remap='I'>map_when_managed</emphasis> field is
89<function>False</function>.
90The default is
91<function>True</function>
92and is changed by using
93<xref linkend='XtSetMappedWhenManaged' xrefstyle='select: title'/>.
94</para>
95
96<para>
97Each composite widget class declares a geometry manager,
98which is responsible for figuring out where the managed children
99should appear within the composite widget's window.
100Geometry management techniques fall into four classes:
101<variablelist>
102  <varlistentry>
103    <term>Fixed boxes</term>
104    <listitem>
105      <para>
106Fixed boxes have a fixed number of children created by the parent.
107All these children are managed,
108and none ever makes geometry manager requests.
109      </para>
110    </listitem>
111  </varlistentry>
112  <varlistentry>
113    <term>Homogeneous boxes</term>
114    <listitem>
115      <para>
116Homogeneous boxes treat all children equally and apply the same geometry
117constraints to each child.
118Many clients insert and delete widgets freely.
119      </para>
120    </listitem>
121  </varlistentry>
122  <varlistentry>
123    <term>Heterogeneous boxes</term>
124    <listitem>
125      <para>
126Heterogeneous boxes have a specific location where each child is placed.
127This location usually is not specified in pixels,
128because the window may be resized, but is expressed rather
129in terms of the relationship between a child
130and the parent or between the child and other specific children.
131The class of heterogeneous boxes is usually a subclass of
132Constraint.
133      </para>
134    </listitem>
135  </varlistentry>
136  <varlistentry>
137    <term>Shell boxes</term>
138    <listitem>
139      <para>
140Shell boxes typically have only one child,
141and the child's size is usually
142exactly the size of the shell.
143The geometry manager must communicate with the window manager, if it exists,
144and the box must also accept
145<function>ConfigureNotify</function>
146events when the window size is changed by the window manager.
147    </para>
148  </listitem>
149  </varlistentry>
150</variablelist>
151</para>
152<sect1 id="Addition_of_Children_to_a_Composite_Widget_The_insert_child_Procedure">
153<title>Addition of Children to a Composite Widget: The insert_child Procedure</title>
154<para>
155To add a child to
156the parent's list of children, the
157<xref linkend='XtCreateWidget' xrefstyle='select: title'/>
158function calls the parent's class routine insert_child.
159The insert_child procedure pointer in a composite widget is of type
160<xref linkend='XtWidgetProc' xrefstyle='select: title'/>.
161</para>
162
163<funcsynopsis id='XtWidgetProc_2'>
164<funcprototype>
165<funcdef>typedef void <function>(*XtWidgetProc)</function></funcdef>
166   <paramdef>Widget <parameter>w</parameter></paramdef>
167</funcprototype>
168</funcsynopsis>
169
170<variablelist>
171  <varlistentry>
172    <term>
173      <emphasis remap='I'>w</emphasis>
174    </term>
175    <listitem>
176      <para>
177Passes the newly created child.
178    </para>
179  </listitem>
180  </varlistentry>
181</variablelist>
182
183<para>
184Most composite widgets inherit their superclass's operation.
185The insert_child routine in
186<function>CompositeWidgetClass calls the insert_position procedure</function>
187and inserts the child at the specified position
188in the <emphasis remap='I'>children</emphasis> list, expanding it if necessary.
189</para>
190
191<para>
192Some composite widgets define their own insert_child routine
193so that they can order their children in some convenient way,
194create companion controller widgets for a new widget,
195or limit the number or class of their child widgets.
196A composite widget class that wishes
197to allow nonwidget children (see <xref linkend='Nonwidget_Objects' />) must specify a
198<function>CompositeClassExtension</function>
199extension record as described
200in <xref linkend='CompositeClassPart_Structure' />
201and set the <emphasis remap='I'>accepts_objects</emphasis> field in this record to
202<function>True</function>.
203If the
204<function>CompositeClassExtension</function>
205record is not specified or the
206<emphasis remap='I'>accepts_objects</emphasis> field is
207<function>False</function>,
208the composite widget can assume that all its children are of a subclass of Core
209without an explicit subclass test in the insert_child procedure.
210</para>
211
212<para>
213If there is not enough room to insert a new child in the <emphasis remap='I'>children</emphasis> array
214(that is, <emphasis remap='I'>num_children</emphasis> is equal to <emphasis remap='I'>num_slots</emphasis>),
215the insert_child procedure must first reallocate the array
216and update <emphasis remap='I'>num_slots</emphasis>.
217The insert_child procedure then places the child at the appropriate position
218in the array and increments the <emphasis remap='I'>num_children</emphasis> field.
219</para>
220</sect1>
221
222<sect1 id="Insertion_Order_of_Children_The_insert_position_Procedure">
223<title>Insertion Order of Children: The insert_position Procedure</title>
224<para>
225Instances of composite widgets sometimes need to specify more about the order in which
226their children are kept.
227For example,
228an application may want a set of command buttons in some logical order
229grouped by function,
230and it may want buttons that represent file names to be kept
231in alphabetical order without constraining the order in which the
232buttons are created.
233</para>
234
235<para>
236An application controls the presentation order of a set of children by
237supplying an
238XtNinsertPosition
239resource.
240The insert_position procedure pointer in a composite widget instance is of type
241<xref linkend='XtOrderProc' xrefstyle='select: title'/>.
242</para>
243
244<funcsynopsis id='XtOrderProc'>
245<funcprototype>
246<funcdef>typedef Cardinal <function>(*XtOrderProc)</function></funcdef>
247
248   <paramdef>Widget <parameter>w</parameter></paramdef>
249</funcprototype>
250</funcsynopsis>
251
252<variablelist>
253  <varlistentry>
254    <term>
255      <emphasis remap='I'>w</emphasis>
256    </term>
257    <listitem>
258      <para>
259Passes the newly created widget.
260    </para>
261  </listitem>
262  </varlistentry>
263</variablelist>
264
265<para>
266Composite widgets that allow clients to order their children (usually
267homogeneous boxes) can call their widget instance's insert_position
268procedure from the class's insert_child procedure to determine where a new
269child should go in its <emphasis remap='I'>children</emphasis> array.
270Thus, a client using a composite class can apply different sorting criteria
271to widget instances of the class, passing in a different insert_position
272procedure resource when it creates each composite widget instance.
273</para>
274
275<para>
276The return value of the insert_position procedure
277indicates how many children should go before the widget.
278Returning zero indicates that the widget should go before all other children,
279and returning <emphasis remap='I'>num_children</emphasis> indicates that it should go after all other children.
280The default insert_position function returns <emphasis remap='I'>num_children</emphasis>
281and can be overridden by a specific composite widget's resource list
282or by the argument list provided when the composite widget is created.
283</para>
284</sect1>
285
286<sect1 id="Deletion_of_Children_The_delete_child_Procedure">
287<title>Deletion of Children: The delete_child Procedure</title>
288
289<para>
290To remove the child from the parent's <emphasis remap='I'>children</emphasis> list, the
291<xref linkend='XtDestroyWidget' xrefstyle='select: title'/>
292function eventually causes a call to the Composite parent's class delete_child
293procedure.
294The delete_child procedure pointer is of type
295<xref linkend='XtWidgetProc' xrefstyle='select: title'/>.
296</para>
297
298<funcsynopsis id='_XtWidgetProc'>
299<funcprototype>
300<funcdef>typedef void <function>(*XtWidgetProc)</function></funcdef>
301   <paramdef>Widget <parameter>w</parameter></paramdef>
302</funcprototype>
303</funcsynopsis>
304
305<variablelist>
306  <varlistentry>
307    <term>
308      <emphasis remap='I'>w</emphasis>
309    </term>
310    <listitem>
311      <para>
312Passes the child being deleted.
313      </para>
314    </listitem>
315  </varlistentry>
316</variablelist>
317
318
319<para>
320Most widgets inherit the delete_child procedure from their superclass.
321Composite widgets that create companion widgets define their own
322delete_child procedure to remove these companion widgets.
323</para>
324</sect1>
325
326<sect1 id="Adding_and_Removing_Children_from_the_Managed_Set">
327<title>Adding and Removing Children from the Managed Set</title>
328<para>
329The Intrinsics provide a set of generic routines to permit the addition of
330widgets to or the removal of widgets from a composite widget's managed set.
331These generic routines eventually call the composite widget's change_managed
332procedure if the procedure pointer is non-NULL.
333The change_managed procedure pointer is of type
334<xref linkend='XtWidgetProc' xrefstyle='select: title'/>.
335The widget argument specifies the composite widget whose managed child
336set has been modified.
337</para>
338
339<sect2 id="Managing_Children">
340<title>Managing Children</title>
341<para>
342To add a list of widgets to the geometry-managed (and hence displayable)
343subset of their Composite parent, use
344<xref linkend='XtManageChildren' xrefstyle='select: title'/>.
345</para>
346
347<para>typedef Widget *WidgetList;</para>
348
349<funcsynopsis id='XtManageChildren'>
350<funcprototype>
351<funcdef>void <function>XtManageChildren</function></funcdef>
352   <paramdef>WidgetList <parameter>children</parameter></paramdef>
353   <paramdef>Cardinal <parameter>num_children</parameter></paramdef>
354</funcprototype>
355</funcsynopsis>
356
357<variablelist>
358  <varlistentry>
359    <term>
360      <emphasis remap='I'>children</emphasis>
361    </term>
362    <listitem>
363      <para>
364Specifies a list of child widgets.  Each child must be of class
365RectObj or any subclass thereof.
366      </para>
367    </listitem>
368  </varlistentry>
369  <varlistentry>
370    <term>
371      <emphasis remap='I'>num_children</emphasis>
372    </term>
373    <listitem>
374      <para>
375Specifies the number of children in the list.
376    </para>
377  </listitem>
378  </varlistentry>
379</variablelist>
380
381<para>
382The
383<xref linkend='XtManageChildren' xrefstyle='select: title'/>
384function performs the following:
385</para>
386<itemizedlist spacing='compact'>
387  <listitem>
388    <para>
389Issues an error if the children do not all have the same parent or
390if the parent's class is not a subclass of
391<function>compositeWidgetClass</function>.
392    </para>
393  </listitem>
394  <listitem>
395    <para>
396Returns immediately if the common parent is being destroyed;
397otherwise, for each unique child on the list,
398<xref linkend='XtManageChildren' xrefstyle='select: title'/>
399ignores the child if it already is managed or is being destroyed,
400and marks it if not.
401    </para>
402  </listitem>
403  <listitem>
404    <para>
405If the parent is realized and after all children have been marked,
406it makes some of the newly managed children viewable:
407    </para>
408    <itemizedlist spacing='compact'>
409      <listitem>
410        <para>
411Calls the change_managed routine of the widgets' parent.
412        </para>
413      </listitem>
414      <listitem>
415        <para>
416Calls
417<xref linkend='XtRealizeWidget' xrefstyle='select: title'/>
418on each previously unmanaged child that is unrealized.
419        </para>
420      </listitem>
421      <listitem>
422        <para>
423Maps each previously unmanaged child that has <emphasis remap='I'>map_when_managed</emphasis>
424<function>True</function>.
425        </para>
426      </listitem>
427    </itemizedlist>
428  </listitem>
429</itemizedlist>
430<para>
431Managing children is independent of the ordering of children and
432independent of creating and deleting children.
433The layout routine of the parent
434should consider children whose <emphasis remap='I'>managed</emphasis> field is
435<function>True</function>
436and should ignore all other children.
437Note that some composite widgets, especially fixed boxes, call
438<xref linkend='XtManageChild' xrefstyle='select: title'/>
439from their insert_child procedure.
440</para>
441
442<para>
443If the parent widget is realized,
444its change_managed procedure is called to notify it
445that its set of managed children has changed.
446The parent can reposition and resize any of its children.
447It moves each child as needed by calling
448<xref linkend='XtMoveWidget' xrefstyle='select: title'/>,
449which first updates the <emphasis remap='I'>x</emphasis> and <emphasis remap='I'>y</emphasis> fields and which then calls
450<function>XMoveWindow</function>.
451</para>
452
453<para>
454If the composite widget wishes to change the size or border width of any of
455its children, it calls
456<xref linkend='XtResizeWidget' xrefstyle='select: title'/>,
457which first updates the
458<emphasis remap='I'>width</emphasis>, <emphasis remap='I'>height</emphasis>, and <emphasis remap='I'>border_width</emphasis>
459fields and then calls
460<function>XConfigureWindow</function>.
461Simultaneous repositioning and resizing may be done with
462<xref linkend='XtConfigureWidget' xrefstyle='select: title'/>;
463see <xref linkend='Widget_Placement_and_Sizing' />.
464</para>
465
466<para>
467To add a single child to its parent widget's set of managed children, use
468<xref linkend='XtManageChild' xrefstyle='select: title'/>.
469</para>
470
471<funcsynopsis id='XtManageChild'>
472<funcprototype>
473<funcdef>void <function>XtManageChild</function></funcdef>
474   <paramdef>Widget <parameter>child</parameter></paramdef>
475</funcprototype>
476</funcsynopsis>
477
478<variablelist>
479  <varlistentry>
480    <term>
481      <emphasis remap='I'>child</emphasis>
482    </term>
483    <listitem>
484      <para>
485Specifies the child.  Must be of class RectObj or any subclass thereof.
486    </para>
487  </listitem>
488  </varlistentry>
489</variablelist>
490
491<para>
492The
493<xref linkend='XtManageChild' xrefstyle='select: title'/>
494function constructs a
495<function>WidgetList</function>
496of length 1 and calls
497<xref linkend='XtManageChildren' xrefstyle='select: title'/>.
498</para>
499
500<para>
501To create and manage a child widget in a single procedure, use
502<xref linkend='XtCreateManagedWidget' xrefstyle='select: title'/>
503or
504<xref linkend='XtVaCreateManagedWidget' xrefstyle='select: title'/>.
505</para>
506
507<funcsynopsis id='XtCreateManagedWidget'>
508<funcprototype>
509<funcdef>Widget <function>XtCreateManagedWidget</function></funcdef>
510   <paramdef>const char * <parameter>name</parameter></paramdef>
511   <paramdef>WidgetClass <parameter>widget_class</parameter></paramdef>
512   <paramdef>Widget <parameter>parent</parameter></paramdef>
513   <paramdef>ArgList <parameter>args</parameter></paramdef>
514   <paramdef>Cardinal <parameter>num_args</parameter></paramdef>
515</funcprototype>
516</funcsynopsis>
517
518<variablelist>
519  <varlistentry>
520    <term>
521      <emphasis remap='I'>name</emphasis>
522    </term>
523    <listitem>
524      <para>
525Specifies the resource instance name for the created widget.
526      </para>
527    </listitem>
528  </varlistentry>
529  <varlistentry>
530    <term>
531      <emphasis remap='I'>widget_class</emphasis>
532    </term>
533    <listitem>
534      <para>
535Specifies the widget class pointer for the created widget.  (rC
536      </para>
537    </listitem>
538  </varlistentry>
539  <varlistentry>
540    <term>
541      <emphasis remap='I'>parent</emphasis>
542    </term>
543    <listitem>
544      <para>
545Specifies the parent widget.  Must be of class Composite or any
546subclass thereof.
547      </para>
548    </listitem>
549  </varlistentry>
550  <varlistentry>
551    <term>
552      <emphasis remap='I'>args</emphasis>
553    </term>
554    <listitem>
555      <para>
556Specifies the argument list to override any other resource specifications.
557      </para>
558    </listitem>
559  </varlistentry>
560  <varlistentry>
561    <term>
562      <emphasis remap='I'>num_args</emphasis>
563    </term>
564    <listitem>
565      <para>
566Specifies the number of entries in the argument list.
567    </para>
568  </listitem>
569  </varlistentry>
570</variablelist>
571
572<para>
573The
574<xref linkend='XtCreateManagedWidget' xrefstyle='select: title'/>
575function is a convenience routine that calls
576<xref linkend='XtCreateWidget' xrefstyle='select: title'/>
577and
578<xref linkend='XtManageChild' xrefstyle='select: title'/>.
579</para>
580
581<funcsynopsis id='XtVaCreateManagedWidget'>
582<funcprototype>
583<funcdef>Widget <function>XtVaCreateManagedWidget</function></funcdef>
584   <paramdef>const char * <parameter>name</parameter></paramdef>
585   <paramdef>WidgetClass <parameter>widget_class</parameter></paramdef>
586   <paramdef>Widget <parameter>parent</parameter></paramdef>
587   <paramdef>...</paramdef>
588</funcprototype>
589</funcsynopsis>
590
591<variablelist>
592  <varlistentry>
593    <term>
594      <emphasis remap='I'>name</emphasis>
595    </term>
596    <listitem>
597      <para>
598Specifies the resource instance name for the created widget.
599      </para>
600    </listitem>
601  </varlistentry>
602  <varlistentry>
603    <term>
604      <emphasis remap='I'>widget_class</emphasis>
605    </term>
606    <listitem>
607      <para>
608Specifies the widget class pointer for the created widget.  (rC
609      </para>
610    </listitem>
611  </varlistentry>
612  <varlistentry>
613    <term>
614      <emphasis remap='I'>parent</emphasis>
615    </term>
616    <listitem>
617      <para>
618Specifies the parent widget.  Must be of class Composite or any
619subclass thereof.
620      </para>
621    </listitem>
622  </varlistentry>
623  <varlistentry>
624    <term>
625      ...
626    </term>
627    <listitem>
628      <para>
629Specifies the variable argument list to override any other
630resource specifications.
631    </para>
632  </listitem>
633  </varlistentry>
634</variablelist>
635
636<para>
637<xref linkend='XtVaCreateManagedWidget' xrefstyle='select: title'/>
638is identical in function to
639<xref linkend='XtCreateManagedWidget' xrefstyle='select: title'/>
640with the <emphasis remap='I'>args</emphasis> and <emphasis remap='I'>num_args</emphasis> parameters replaced
641by a varargs list, as described in Section 2.5.1.
642</para>
643</sect2>
644
645<sect2 id="Unmanaging_Children">
646<title>Unmanaging Children</title>
647<para>
648To remove a list of children from a parent widget's managed list, use
649<xref linkend='XtUnmanageChildren' xrefstyle='select: title'/>.
650</para>
651
652<funcsynopsis id='XtUnmanageChildren'>
653<funcprototype>
654<funcdef>void <function>XtUnmanageChildren</function></funcdef>
655   <paramdef>WidgetList <parameter>children</parameter></paramdef>
656   <paramdef>Cardinal <parameter>num_children</parameter></paramdef>
657</funcprototype>
658</funcsynopsis>
659
660<variablelist>
661  <varlistentry>
662    <term>
663      <emphasis remap='I'>children</emphasis>
664    </term>
665    <listitem>
666      <para>
667Specifies a list of child widgets.  Each child must be of class
668RectObj or any subclass thereof.
669      </para>
670    </listitem>
671  </varlistentry>
672  <varlistentry>
673    <term>
674      <emphasis remap='I'>num_children</emphasis>
675    </term>
676    <listitem>
677      <para>
678Specifies the number of children.
679    </para>
680  </listitem>
681  </varlistentry>
682</variablelist>
683
684<para>
685The
686<xref linkend='XtUnmanageChildren' xrefstyle='select: title'/>
687function performs the following:
688</para>
689<itemizedlist spacing='compact'>
690  <listitem>
691    <para>
692Returns immediately if the common parent is being destroyed.
693    </para>
694  </listitem>
695  <listitem>
696    <para>
697Issues an error if the children do not all have the same parent
698or if the parent is not a subclass of
699<function>compositeWidgetClass</function>.
700    </para>
701  </listitem>
702  <listitem>
703    <para>
704For each unique child on the list,
705<xref linkend='XtUnmanageChildren' xrefstyle='select: title'/>
706ignores the child if it is unmanaged; otherwise it performs the following:
707    </para>
708    <itemizedlist spacing='compact'>
709      <listitem>
710        <para>
711Marks the child as unmanaged.
712        </para>
713      </listitem>
714      <listitem>
715        <para>
716If the child is realized and the <emphasis remap='I'>map_when_managed</emphasis> field is
717<function>True</function>,
718it is unmapped.
719        </para>
720      </listitem>
721    </itemizedlist>
722  </listitem>
723  <listitem>
724    <para>
725If the parent is realized and if any children have become unmanaged,
726calls the change_managed routine of the widgets' parent.
727    </para>
728  </listitem>
729</itemizedlist>
730<para>
731<xref linkend='XtUnmanageChildren' xrefstyle='select: title'/>
732does not destroy the child widgets.
733Removing widgets from a parent's managed set is often a temporary banishment,
734and some time later the client may manage the children again.
735To destroy widgets entirely,
736<xref linkend='XtDestroyWidget' xrefstyle='select: title'/>
737should be called instead;
738see <xref linkend='Exiting_from_an_Application' />.
739</para>
740
741<para>
742To remove a single child from its parent widget's managed set, use
743<xref linkend='XtUnmanageChild' xrefstyle='select: title'/>.
744</para>
745
746<funcsynopsis id='XtUnmanageChild'>
747<funcprototype>
748<funcdef>void <function>XtUnmanageChild</function></funcdef>
749   <paramdef>Widget <parameter>child</parameter></paramdef>
750</funcprototype>
751</funcsynopsis>
752
753<variablelist>
754  <varlistentry>
755    <term>
756      <emphasis remap='I'>child</emphasis>
757    </term>
758    <listitem>
759      <para>
760Specifies the child.  Must be of class RectObj or any subclass thereof.
761    </para>
762  </listitem>
763  </varlistentry>
764</variablelist>
765
766<para>
767The
768<xref linkend='XtUnmanageChild' xrefstyle='select: title'/>
769function constructs a widget list
770of length 1 and calls
771<xref linkend='XtUnmanageChildren' xrefstyle='select: title'/>.
772</para>
773
774<para>
775These functions are low-level routines that are used by generic
776composite widget building routines.
777In addition, composite widgets can provide widget-specific,
778high-level convenience procedures.
779</para>
780</sect2>
781
782<sect2 id="Bundling_Changes_to_the_Managed_Set">
783<title>Bundling Changes to the Managed Set</title>
784<para>
785A client may simultaneously unmanage and manage children
786with a single call to the Intrinsics.  In this same call the
787client may provide a callback procedure that can modify the
788geometries of one or more children.  The composite widget class
789defines whether this single client call results in separate invocations
790of the change_managed method, one to unmanage and the other to
791manage, or in just a single invocation.
792</para>
793
794<para>
795To simultaneously remove from and add to the geometry-managed
796set of children of a composite parent, use
797<xref linkend='XtChangeManagedSet' xrefstyle='select: title'/>.
798</para>
799
800<funcsynopsis id='XtChangeManagedSet'>
801<funcprototype>
802<funcdef>void <function>XtChangeManagedSet</function></funcdef>
803   <paramdef>WidgetList <parameter>unmanage_children</parameter></paramdef>
804   <paramdef>Cardinal <parameter>num_unmanage_children</parameter></paramdef>
805   <paramdef>XtDoChangeProc <parameter>do_change_proc</parameter></paramdef>
806   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
807   <paramdef>WidgetList <parameter>manage_children</parameter></paramdef>
808   <paramdef>Cardinal <parameter>num_manage_children</parameter></paramdef>
809</funcprototype>
810</funcsynopsis>
811
812<variablelist>
813  <varlistentry>
814    <term>
815      <emphasis remap='I'>unmanage_children</emphasis>
816    </term>
817    <listitem>
818      <para>
819Specifies the list of widget children to initially remove from the managed set.
820      </para>
821    </listitem>
822  </varlistentry>
823  <varlistentry>
824    <term>
825      <emphasis remap='I'>num_unmanage_children</emphasis>
826    </term>
827    <listitem>
828      <para>
829Specifies the number of entries in the <emphasis remap='I'>unmanage_children</emphasis> list.
830      </para>
831    </listitem>
832  </varlistentry>
833  <varlistentry>
834    <term>
835      <emphasis remap='I'>do_change_proc</emphasis>
836    </term>
837    <listitem>
838      <para>
839Specifies a procedure to invoke between unmanaging
840and managing the children, or NULL.
841      </para>
842    </listitem>
843  </varlistentry>
844  <varlistentry>
845    <term>
846      <emphasis remap='I'>client_data</emphasis>
847    </term>
848    <listitem>
849      <para>
850Specifies client data to be passed to the do_change_proc.
851      </para>
852    </listitem>
853  </varlistentry>
854  <varlistentry>
855    <term>
856      <emphasis remap='I'>manage_children</emphasis>
857    </term>
858    <listitem>
859      <para>
860Specifies the list of widget children to finally add to the managed set.
861      </para>
862    </listitem>
863  </varlistentry>
864  <varlistentry>
865    <term>
866      <emphasis remap='I'>num_manage_children</emphasis>
867    </term>
868    <listitem>
869      <para>
870Specifies the number of entries in the <emphasis remap='I'>manage_children</emphasis> list.
871    </para>
872  </listitem>
873  </varlistentry>
874</variablelist>
875
876<para>
877The
878<xref linkend='XtChangeManagedSet' xrefstyle='select: title'/>
879function performs the following:
880</para>
881<itemizedlist spacing='compact'>
882  <listitem>
883    <para>
884Returns immediately if <emphasis remap='I'>num_unmanage_children</emphasis> and
885<emphasis remap='I'>num_manage_children</emphasis> are both 0.
886    </para>
887  </listitem>
888  <listitem>
889    <para>
890Issues a warning and returns if the widgets specified in the
891<emphasis remap='I'>manage_children</emphasis> and
892the <emphasis remap='I'>unmanage_children</emphasis> lists do not all have the same parent or if
893that parent is not a subclass of
894<function>compositeWidgetClass</function>.
895    </para>
896  </listitem>
897  <listitem>
898    <para>
899Returns immediately if the common parent is being destroyed.
900    </para>
901  </listitem>
902  <listitem>
903    <para>
904If <emphasis remap='I'>do_change_proc</emphasis> is not NULL and the parent's
905<function>CompositeClassExtension</function>
906<emphasis remap='I'>allows_change_managed_set</emphasis> field is
907<function>False</function>,
908then
909<xref linkend='XtChangeManagedSet' xrefstyle='select: title'/>
910performs the following:
911    </para>
912    <itemizedlist spacing='compact'>
913      <listitem>
914        <para>
915Calls
916<xref linkend='XtUnmanageChildren' xrefstyle='select: title'/>
917(<emphasis remap='I'>unmanage_children</emphasis>, <emphasis remap='I'>num_unmanage_children</emphasis>).
918        </para>
919      </listitem>
920      <listitem>
921    <para>
922Calls the <emphasis remap='I'>do_change_proc</emphasis>.
923        </para>
924      </listitem>
925      <listitem>
926        <para>
927Calls
928<xref linkend='XtManageChildren' xrefstyle='select: title'/>
929(<emphasis remap='I'>manage_children</emphasis>, <emphasis remap='I'>num_manage_children</emphasis>).
930        </para>
931      </listitem>
932    </itemizedlist>
933  </listitem>
934  <listitem>
935    <para>
936Otherwise, the following is performed:
937    </para>
938    <itemizedlist spacing='compact'>
939      <listitem>
940        <para>
941For each child on the <emphasis remap='I'>unmanage_children</emphasis> list; if the child is
942already unmanaged it is ignored, otherwise it is marked as unmanaged,
943and if it is realized and its <emphasis remap='I'>map_when_managed</emphasis> field is
944<function>True</function>,
945it is unmapped.
946        </para>
947      </listitem>
948      <listitem>
949        <para>
950If <emphasis remap='I'>do_change_proc</emphasis> is non-NULL, the procedure is invoked.
951        </para>
952      </listitem>
953      <listitem>
954        <para>
955For each child on the <emphasis remap='I'>manage_children</emphasis> list; if the child is already
956managed or is being destroyed, it is ignored; otherwise it is
957marked as managed.
958        </para>
959      </listitem>
960      <listitem>
961        <para>
962If the parent is realized and after all children have been marked,
963the change_managed method of the parent is invoked, and subsequently
964some of the newly managed children are made viewable by calling
965<xref linkend='XtRealizeWidget' xrefstyle='select: title'/>
966on each previously unmanaged child that is unrealized and
967mapping each previously unmanaged child that has <emphasis remap='I'>map_when_managed</emphasis>
968<function>True</function>.
969        </para>
970      </listitem>
971    </itemizedlist>
972  </listitem>
973</itemizedlist>
974<para>
975If no
976<function>CompositeClassExtension</function>
977record is found in the parent's composite class part <emphasis remap='I'>extension</emphasis> field
978with record type
979<emphasis role='strong'>NULLQUARK</emphasis>
980and version greater than 1, and if
981<function>XtInheritChangeManaged</function>
982was specified in the parent's class record during class initialization,
983the value of the <emphasis remap='I'>allows_change_managed_set</emphasis>
984field is inherited from the superclass.  The value inherited from
985<function>compositeWidgetClass</function>
986for the <emphasis remap='I'>allows_change_managed_set</emphasis> field is
987<function>False</function>.
988</para>
989
990<para>
991It is not an error to include a child in both the <emphasis remap='I'>unmanage_children</emphasis>
992and the <emphasis remap='I'>manage_children</emphasis> lists.  The effect of such a call is that
993the child remains managed following the call, but the <emphasis remap='I'>do_change_proc</emphasis> is
994able to affect the child while it is in an unmanaged state.
995</para>
996
997<para>
998The <emphasis remap='I'>do_change_proc</emphasis> is of type
999<xref linkend='XtDoChangeProc' xrefstyle='select: title'/>.
1000</para>
1001
1002<funcsynopsis id='XtDoChangeProc'>
1003<funcprototype>
1004<funcdef>typedef void *<function>XtDoChangeProc</function></funcdef>
1005
1006   <paramdef>Widget <parameter>composite_parent</parameter></paramdef>
1007   <paramdef>WidgetList <parameter>unmange_children</parameter></paramdef>
1008   <paramdef>Cardinal *<parameter>num_unmanage_children</parameter></paramdef>
1009   <paramdef>WidgetList <parameter>manage_children</parameter></paramdef>
1010   <paramdef>Cardinal *<parameter>num_manage_children</parameter></paramdef>
1011   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
1012</funcprototype>
1013</funcsynopsis>
1014
1015<variablelist>
1016  <varlistentry>
1017    <term>
1018      <emphasis remap='I'>composite_parent</emphasis>
1019    </term>
1020    <listitem>
1021      <para>
1022Passes the composite parent whose managed set is being altered.
1023      </para>
1024    </listitem>
1025  </varlistentry>
1026  <varlistentry>
1027    <term>
1028      <emphasis remap='I'>unmanage_children</emphasis>
1029    </term>
1030    <listitem>
1031      <para>
1032Passes the list of children just removed from the managed set.
1033      </para>
1034    </listitem>
1035  </varlistentry>
1036  <varlistentry>
1037    <term>
1038      <emphasis remap='I'>num_unmanage_children</emphasis>
1039    </term>
1040    <listitem>
1041      <para>
1042Passes the number of entries in the <emphasis remap='I'>unmanage_children</emphasis> list.
1043      </para>
1044    </listitem>
1045  </varlistentry>
1046  <varlistentry>
1047    <term>
1048      <emphasis remap='I'>manage_children</emphasis>
1049    </term>
1050    <listitem>
1051      <para>
1052Passes the list of children about to be added to the managed set.
1053      </para>
1054    </listitem>
1055  </varlistentry>
1056  <varlistentry>
1057    <term>
1058      <emphasis remap='I'>num_manage_children</emphasis>
1059    </term>
1060    <listitem>
1061      <para>
1062Passes the number of entries in the <emphasis remap='I'>manage_children</emphasis> list.
1063      </para>
1064    </listitem>
1065  </varlistentry>
1066  <varlistentry>
1067    <term>
1068      <emphasis remap='I'>client_data</emphasis>
1069    </term>
1070    <listitem>
1071      <para>
1072Passes the client data passed to
1073<xref linkend='XtChangeManagedSet' xrefstyle='select: title'/>.
1074    </para>
1075  </listitem>
1076  </varlistentry>
1077</variablelist>
1078
1079<para>
1080The <emphasis remap='I'>do_change_proc</emphasis> procedure is used by the caller of
1081<xref linkend='XtChangeManagedSet' xrefstyle='select: title'/>
1082to make changes to one or more children at the point when the
1083managed set contains the fewest entries.  These changes may
1084involve geometry requests, and in this case the caller of
1085<xref linkend='XtChangeManagedSet' xrefstyle='select: title'/>
1086may take advantage of the fact that the Intrinsics internally grant
1087geometry requests made by unmanaged children without invoking
1088the parent's geometry manager.  To achieve this advantage, if
1089the <emphasis remap='I'>do_change_proc</emphasis> procedure
1090changes the geometry of a child or of a descendant of a child, then
1091that child should be included in the <emphasis remap='I'>unmanage_children</emphasis> and
1092<emphasis remap='I'>manage_children</emphasis> lists.
1093</para>
1094</sect2>
1095
1096<sect2 id="Determining_if_a_Widget_Is_Managed">
1097<title>Determining if a Widget Is Managed</title>
1098<para>
1099To determine the managed state of a given child widget, use
1100<xref linkend='XtIsManaged' xrefstyle='select: title'/>.
1101</para>
1102
1103<funcsynopsis id='XtIsManaged'>
1104<funcprototype>
1105<funcdef>Boolean <function>XtIsManaged</function></funcdef>
1106   <paramdef>Widget <parameter>w</parameter></paramdef>
1107</funcprototype>
1108</funcsynopsis>
1109
1110<variablelist>
1111  <varlistentry>
1112    <term>
1113      <emphasis remap='I'>w</emphasis>
1114    </term>
1115    <listitem>
1116      <para>
1117Specifies the widget.  Must be of class Object or any subclass thereof.
1118    </para>
1119  </listitem>
1120  </varlistentry>
1121</variablelist>
1122
1123<para>
1124The
1125<xref linkend='XtIsManaged' xrefstyle='select: title'/>
1126function returns
1127<function>True</function>
1128if the specified widget is of class RectObj or any subclass thereof
1129and is managed, or
1130<function>False</function>
1131otherwise.
1132</para>
1133</sect2>
1134</sect1>
1135
1136<sect1 id="Controlling_When_Widgets_Get_Mapped">
1137<title>Controlling When Widgets Get Mapped</title>
1138<para>
1139A widget is normally mapped if it is managed.
1140However,
1141this behavior can be overridden by setting the XtNmappedWhenManaged resource
1142for the widget when it is created
1143or by setting the <emphasis remap='I'>map_when_managed</emphasis> field to
1144<function>False</function>.
1145</para>
1146
1147<para>
1148To change the value of a given widget's <emphasis remap='I'>map_when_managed</emphasis> field, use
1149<xref linkend='XtSetMappedWhenManaged' xrefstyle='select: title'/>.
1150</para>
1151
1152<funcsynopsis id='XtSetMappedWhenManaged'>
1153<funcprototype>
1154<funcdef>void <function>XtSetMappedWhenManaged</function></funcdef>
1155   <paramdef>Widget <parameter>w</parameter></paramdef>
1156   <paramdef>Boolean <parameter>map_when_managed</parameter></paramdef>
1157</funcprototype>
1158</funcsynopsis>
1159
1160<variablelist>
1161  <varlistentry>
1162    <term>
1163      <emphasis remap='I'>w</emphasis>
1164    </term>
1165    <listitem>
1166      <para>
1167Specifies the widget.  Must be of class Core or any subclass thereof.
1168      </para>
1169    </listitem>
1170  </varlistentry>
1171  <varlistentry>
1172    <term>
1173      <emphasis remap='I'>map_when_managed</emphasis>
1174    </term>
1175    <listitem>
1176      <para>
1177Specifies a Boolean value that indicates the new value
1178that is stored into the widget's <emphasis remap='I'>map_when_managed</emphasis>
1179field.
1180    </para>
1181  </listitem>
1182  </varlistentry>
1183</variablelist>
1184
1185<para>
1186If the widget is realized and managed,
1187and if <emphasis remap='I'>map_when_managed</emphasis> is
1188<function>True</function>,
1189<xref linkend='XtSetMappedWhenManaged' xrefstyle='select: title'/>
1190maps the window.
1191If the widget is realized and managed,
1192and if <emphasis remap='I'>map_when_managed</emphasis> is
1193<function>False</function>,
1194it unmaps the window.
1195<xref linkend='XtSetMappedWhenManaged' xrefstyle='select: title'/>
1196is a convenience function that is equivalent to (but slightly faster than)
1197calling
1198<xref linkend='XtSetValues' xrefstyle='select: title'/>
1199and setting the new value for the XtNmappedWhenManaged resource
1200then mapping the widget as appropriate.
1201As an alternative to using
1202<xref linkend='XtSetMappedWhenManaged' xrefstyle='select: title'/>
1203to control mapping,
1204a client may set <emphasis remap='I'>mapped_when_managed</emphasis> to
1205<function>False</function>
1206and use
1207<xref linkend='XtMapWidget' xrefstyle='select: title'/>
1208and
1209<xref linkend='XtUnmapWidget' xrefstyle='select: title'/>
1210explicitly.
1211</para>
1212
1213<para>
1214To map a widget explicitly, use
1215<xref linkend='XtMapWidget' xrefstyle='select: title'/>.
1216</para>
1217
1218<funcsynopsis id='XtMapWidget'>
1219<funcprototype>
1220<funcdef>void <function>XtMapWidget</function></funcdef>
1221   <paramdef>Widget <parameter>w</parameter></paramdef>
1222</funcprototype>
1223</funcsynopsis>
1224
1225<variablelist>
1226  <varlistentry>
1227    <term>
1228      <emphasis remap='I'>w</emphasis>
1229    </term>
1230    <listitem>
1231      <para>
1232Specifies the widget.  Must be of class Core or any subclass thereof.
1233    </para>
1234  </listitem>
1235  </varlistentry>
1236</variablelist>
1237
1238<para>
1239To unmap a widget explicitly, use
1240<xref linkend='XtUnmapWidget' xrefstyle='select: title'/>.
1241</para>
1242
1243<funcsynopsis id='XtUnmapWidget'>
1244<funcprototype>
1245<funcdef>void <function>XtUnmapWidget</function></funcdef>
1246   <paramdef>Widget <parameter>w</parameter></paramdef>
1247</funcprototype>
1248</funcsynopsis>
1249
1250<variablelist>
1251  <varlistentry>
1252    <term>
1253      <emphasis remap='I'>w</emphasis>
1254    </term>
1255    <listitem>
1256      <para>
1257Specifies the widget.  Must be of class Core or any subclass thereof.
1258    </para>
1259  </listitem>
1260  </varlistentry>
1261</variablelist>
1262
1263
1264</sect1>
1265
1266<sect1 id="Constrained_Composite_Widgets">
1267<title>Constrained Composite Widgets</title>
1268<para>
1269The Constraint
1270widget class is a subclass of
1271<function>compositeWidgetClass</function>.
1272The name is derived from the fact that constraint widgets
1273may manage the geometry
1274of their children based on constraints associated with each child.
1275These constraints can be as simple as the maximum width and height
1276the parent will allow the child to occupy or can be as complicated as
1277how other children should change if this child is moved or resized.
1278Constraint
1279widgets let a parent define constraints as resources that are supplied for their children.
1280For example, if the
1281Constraint
1282parent defines the maximum sizes for its children,
1283these new size resources are retrieved for each child as if they were
1284resources that were defined by the child widget's class.
1285Accordingly,
1286constraint resources may be included in the argument list or resource file just
1287like any other resource for the child.
1288</para>
1289
1290<para>
1291Constraint
1292widgets have all the responsibilities of normal composite widgets
1293and, in addition, must process and act upon the constraint information
1294associated with each of their children.
1295</para>
1296
1297<para>
1298To make it easy for widgets and the Intrinsics to keep track of the
1299constraints associated with a child,
1300every widget has a <emphasis remap='I'>constraints</emphasis> field,
1301which is the address of a parent-specific structure that contains
1302constraint information about the child.
1303If a child's parent does not belong to a subclass of
1304<function>constraintWidgetClass</function>,
1305then the child's <emphasis remap='I'>constraints</emphasis> field is NULL.
1306</para>
1307
1308<para>
1309Subclasses of
1310Constraint
1311can add constraint data to the constraint record defined by their superclass.
1312To allow this, widget writers should define the constraint
1313records in their private .h file by using the same conventions as used for
1314widget records.
1315For example, a widget class that needs to maintain a maximum
1316width and height for each child might define its constraint record as
1317follows:
1318</para>
1319<programlisting>
1320typedef struct {
1321        Dimension max_width, max_height;
1322} MaxConstraintPart;
1323typedef struct {
1324        MaxConstraintPart max;
1325} MaxConstraintRecord, *MaxConstraint;
1326</programlisting>
1327<para>
1328A subclass of this widget class that also needs to maintain a minimum size would
1329define its constraint record as follows:
1330</para>
1331<programlisting>
1332typedef struct {
1333        Dimension min_width, min_height;
1334} MinConstraintPart;
1335typedef struct {
1336        MaxConstraintPart max;
1337        MinConstraintPart min;
1338} MaxMinConstraintRecord, *MaxMinConstraint;
1339</programlisting>
1340<para>
1341Constraints are allocated, initialized, deallocated, and otherwise maintained
1342insofar as possible by the Intrinsics.
1343The Constraint class record part has several entries that facilitate this.
1344All entries in
1345<function>ConstraintClassPart</function>
1346are fields and procedures that are defined and implemented by the parent,
1347but they are called whenever actions are performed on the parent's children.
1348</para>
1349
1350<para>
1351The
1352<xref linkend='XtCreateWidget' xrefstyle='select: title'/>
1353function uses the <emphasis remap='I'>constraint_size</emphasis> field in the parent's class record
1354to allocate a constraint record when a child is created.
1355<xref linkend='XtCreateWidget' xrefstyle='select: title'/>
1356also uses the constraint resources to fill in resource fields in the
1357constraint record associated with a child.
1358It then calls the constraint initialize procedure so that the parent
1359can compute constraint fields that are derived from constraint resources
1360and can possibly move or resize the child to conform to the given constraints.
1361</para>
1362
1363<para>
1364When the
1365<xref linkend='XtGetValues' xrefstyle='select: title'/>
1366and
1367<xref linkend='XtSetValues' xrefstyle='select: title'/>
1368functions are executed
1369on a child, they use the constraint resources to get the values or
1370set the values of constraints associated with that child.
1371<xref linkend='XtSetValues' xrefstyle='select: title'/>
1372then calls the constraint set_values procedures so that the parent can
1373recompute derived constraint fields and move or resize the child
1374as appropriate.
1375If a
1376Constraint
1377widget class or any of its superclasses have declared a
1378<function>ConstraintClassExtension</function>
1379record in the
1380<function>ConstraintClassPart</function>
1381<emphasis remap='I'>extension</emphasis>
1382fields with a record type of
1383<emphasis role='strong'>NULLQUARK</emphasis>
1384and the <emphasis remap='I'>get_values_hook</emphasis> field in
1385the extension record is non-NULL,
1386<xref linkend='XtGetValues' xrefstyle='select: title'/>
1387calls the get_values_hook
1388procedure(s) to allow the parent to return derived constraint fields.
1389</para>
1390
1391<para>
1392The
1393<xref linkend='XtDestroyWidget' xrefstyle='select: title'/>
1394function calls the constraint destroy procedure to deallocate any
1395dynamic storage associated with a constraint record.
1396The constraint record itself must not be deallocated by the constraint
1397destroy procedure;
1398<xref linkend='XtDestroyWidget' xrefstyle='select: title'/>
1399does this automatically.
1400</para>
1401</sect1>
1402</chapter>
1403