08f0ff569004f9f690c38a0cd4bff14159539014
[framework/uifw/xorg/lib/libxaw.git] / specs / CH2.xml
1 <chapter><title>Using Widgets</title>
2 <sect1 id="using_widgets">
3 <title>Using Widgets</title>
4 <para>
5 Widgets serve as the primary tools for building a user interface or
6 application environment.  The Athena widget set consists of primitive
7 widgets that contain no children (for example, a command button) and
8 composite widgets which may contain one or more widget children (for
9 example, a Box widget).
10 </para>
11 <para>
12 The remaining chapters explain the widgets that are provided
13 by the Athena widget set.
14 These user-interface components serve as an interface for
15 application programmers who do not want to implement their own widgets.
16 In addition, they serve as a starting point
17 for those widget programmers who, using the Intrinsics mechanisms,
18 want to implement alternative application programming interfaces.
19 </para>
20 <para>
21 This chapter is a brief introduction to widget programming.  The
22 examples provided use the Athena widgets, though most of the concepts
23 will apply to all widget sets.  Although there are several programming
24 interfaces to the X Toolkit, only one is described here.  A full
25 description of the programming interface is provided in the document
26 <emphasis remap='I'>X Toolkit Intrinsics - C Language Interface</emphasis>.
27 </para>
28 <sect2 id="Setting_the_Locale">
29 <title>Setting the Locale</title>
30 <para>
31 <!-- .LP -->
32 <!-- .XS -->
33 <!--    Setting the Locale -->
34 <!-- .XE -->
35 If it is desirable that the application take advantage of
36 internationalization (i18n), you must establish locale with
37 <function>XtSetLanguageProc</function>
38 before <function>XtDisplayInitialize</function> or <function>XtAppInitialize</function>
39 is called.  For full details, please refer to the document
40 <emphasis remap='I'>X Toolkit Intrinsics - C Language Interface</emphasis>, section 2.2. However, the following simplest-case
41 call is sufficient in many or most applications.
42 </para>
43 <para>
44 <!-- .LP -->
45 <!-- .IN "internationalization" "" "" -->
46 <!-- .IN "XtSetLanguageProc" "" "@DEF@" -->
47 <!-- .IN "locale" "" "" -->
48 <literallayout class="monospaced">
49 <!-- .TA .5i 2i -->
50 <!-- .ta .5i 2i -->
51         XtSetLanguageProc(NULL, NULL, NULL);
52 </literallayout>
53 </para>
54 <para>
55 <!-- .LP -->
56 Most notably, this will affect the Standard C locale, determine which
57 resource files will be loaded, and what fonts will be required of FontSet
58 specifications.  In many cases, the addition of this line is the only source change
59 required to internationalize Xaw programs, and will not disturb the function
60 of programs in the default "C" locale.
61 </para>
62 </sect2>
63 <sect2 id="Initializing_the_Toolkit">
64 <title>Initializing the Toolkit</title>
65 <para>
66 <!-- .LP -->
67 <!-- .XS -->
68 <!--    Initializing the Toolkit -->
69 <!-- .XE -->
70 You must call a toolkit initialization function before invoking any
71 other toolkit routines (besides locale setting, above).
72 <function>XtAppInitialize</function>
73 opens the X server connection, parses the command line,
74 and creates an initial widget that will serve as the root of
75 a tree of widgets created by this application.
76 <!-- .IN "initialization" "" "@DEF@" -->
77 <!-- .IN "toolkit initialization" "" "@DEF@" -->
78 <!-- .IN "XtAppInitialize" "" "@DEF@" -->
79 <!-- .IN "fallback resources" "" "@DEF@" -->
80 <funcsynopsis>
81 <funcprototype>
82   <funcdef>Widget<function> XtAppInitialize</function></funcdef>
83   <paramdef>XtAppContext<parameter> app_context_return</parameter></paramdef>
84   <paramdef>String<parameter> application_class</parameter></paramdef>
85   <paramdef>XrmOptionDescRec<parameter> options</parameter></paramdef>
86   <paramdef>Cardinal<parameter> num_options</parameter></paramdef>
87   <paramdef>int<parameter> *argc_in_out</parameter></paramdef>
88   <paramdef>String<parameter> *argv_in_out</parameter></paramdef>
89   <paramdef>String<parameter> *fallback_resources</parameter></paramdef>
90   <paramdef>ArgList<parameter> args</parameter></paramdef>
91   <paramdef>Cardinal<parameter> num_args</parameter></paramdef>
92 </funcprototype>
93 </funcsynopsis>
94 <!-- .FN -->
95 <variablelist>
96   <varlistentry>
97     <term>
98       <emphasis remap='I'>app_con_return</emphasis>
99     </term>
100     <listitem>
101       <para>
102 Returns the application context of this application, if non-NULL.
103       </para>
104     </listitem>
105   </varlistentry>
106   <varlistentry>
107     <term>
108       <emphasis remap='I'>application_class</emphasis>
109     </term>
110     <listitem>
111       <para>
112 Specifies the class name of this application,
113 which is usually the generic name for all instances of this application.
114 A useful convention is to form the class name by capitalizing the
115 first letter of the application name. For example, the application named
116 ``xman'' has a class name of ``Xman''.
117       </para>
118     </listitem>
119   </varlistentry>
120   <varlistentry>
121     <term>
122       <emphasis remap='I'>options</emphasis>
123     </term>
124     <listitem>
125       <para>
126 Specifies how to parse the command line for any application-specific
127 resources.
128 The options argument is passed as a parameter to
129 <function>XrmParseCommand</function> . 
130 For further information,
131 see <emphasis remap='I'>Xlib - C Language Interface</emphasis>.
132       </para>
133     </listitem>
134   </varlistentry>
135   <varlistentry>
136     <term>
137       <emphasis remap='I'>num_options</emphasis>
138     </term>
139     <listitem>
140       <para>
141 Specifies the number of entries in the options list.
142       </para>
143     </listitem>
144   </varlistentry>
145   <varlistentry>
146     <term>
147       <emphasis remap='I'>argc_in_out</emphasis>
148     </term>
149     <listitem>
150       <para>
151 Specifies a pointer to the number of command line parameters.
152       </para>
153     </listitem>
154   </varlistentry>
155   <varlistentry>
156     <term>
157       <emphasis remap='I'>argv_in_out</emphasis>
158     </term>
159     <listitem>
160       <para>
161 Specifies the command line parameters.
162       </para>
163     </listitem>
164   </varlistentry>
165   <varlistentry>
166     <term>
167       <emphasis remap='I'>fallback_resources</emphasis>
168     </term>
169     <listitem>
170       <para>
171 Specifies resource values to be used if the site-wide application class
172 defaults file cannot be opened, or NULL.
173       </para>
174     </listitem>
175   </varlistentry>
176   <varlistentry>
177     <term>
178       <emphasis remap='I'>args</emphasis>
179     </term>
180     <listitem>
181       <para>
182 Specifies the argument list to use when creating the Application shell.
183       </para>
184     </listitem>
185   </varlistentry>
186   <varlistentry>
187     <term>
188       <emphasis remap='I'>num_args</emphasis>
189     </term>
190     <listitem>
191       <para>
192 Specifies the number of arguments in <emphasis remap='I'>args</emphasis>.
193     </para>
194   </listitem>
195   </varlistentry>
196 </variablelist>
197 </para>
198 <para>
199 <!-- .LP -->
200 This function will remove the command line arguments that the toolkit
201 reads from <emphasis remap='I'>argc_in_out</emphasis>, and <emphasis remap='I'>argv_in_out</emphasis>.  It will then
202 attempt to open the display.  If the display cannot be opened, an error
203 message is issued and XtAppInitialize terminates the application.  Once
204 the display is opened, all resources are read from the locations
205 specified by the Intrinsics.  This function returns an ApplicationShell
206 widget to be used as the root of the application's widget tree.
207 </para>
208 </sect2>
209 <sect2 id="Creating_a_Widget">
210 <title>Creating a Widget</title>
211 <para>
212 <!-- .LP -->
213 <!-- .XS -->
214 <!--    Creating a Widget -->
215 <!-- .XE -->
216 <!-- .IN "widget creation" "" "@DEF@" -->
217 <!-- .IN "creating widgets" "" "@DEF@" -->
218 <!-- .IN "XtRealizeWidget" "" "" -->
219 Creating a widget is a three-step process.  First, the widget instance
220 is allocated, and various instance-specific attributes are set by
221 using <function>XtCreateWidget</function>.  Second, the widget's parent is informed
222 of the new child by using <function>XtManageChild</function>.  Finally, X windows are
223 created for the parent and all its children by using <function>XtRealizeWidget</function>
224 and specifying the top-most widget. The first two steps can be
225 combined by using <function>XtCreateManagedWidget</function>.  In addition,
226 <function>XtRealizeWidget</function> is automatically called when the child becomes
227 managed if the parent is already realized.
228 </para>
229 <para>
230 <!-- .LP -->
231 To allocate, initialize, and manage a widget, use
232 <function>XtCreateManagedWidget .</function>
233 <!-- .IN "XtCreateManagedWidget" "" "@DEF@" -->
234 <funcsynopsis>
235 <funcprototype>
236   <funcdef>Widget<function> XtCreateManagedWidget</function></funcdef>
237   <paramdef>String<parameter> name</parameter></paramdef>
238   <paramdef>WidgetClass<parameter> widget_class</parameter></paramdef>
239   <paramdef>Widget<parameter> parent</parameter></paramdef>
240   <paramdef>ArgList<parameter> args</parameter></paramdef>
241   <paramdef>Cardinal<parameter> num_args</parameter></paramdef>
242 </funcprototype>
243 </funcsynopsis>
244 <!-- .FN -->
245 <variablelist>
246   <varlistentry>
247     <term>
248       <emphasis remap='I'>name</emphasis>
249     </term>
250     <listitem>
251       <para>
252 Specifies the instance name for the created widget that is used for retrieving
253 widget resources.
254       </para>
255     </listitem>
256   </varlistentry>
257   <varlistentry>
258     <term>
259       <emphasis remap='I'>widget_class</emphasis>
260     </term>
261     <listitem>
262       <para>
263 Specifies the widget class pointer for the created widget.
264       </para>
265     </listitem>
266   </varlistentry>
267   <varlistentry>
268     <term>
269       <emphasis remap='I'>parent</emphasis>
270     </term>
271     <listitem>
272       <para>
273 Specifies the parent widget ID.
274       </para>
275     </listitem>
276   </varlistentry>
277   <varlistentry>
278     <term>
279       <emphasis remap='I'>args</emphasis>
280     </term>
281     <listitem>
282       <para>
283 Specifies the argument list.  The argument list is a variable-length
284 list composed of name and value pairs that contain information
285 pertaining to the specific widget instance being created.  For further
286 information, see Section 2.7.2. <!-- xref> -->
287       </para>
288     </listitem>
289   </varlistentry>
290   <varlistentry>
291     <term>
292       <emphasis remap='I'>num_args</emphasis>
293     </term>
294     <listitem>
295       <para>
296 Specifies the number of arguments in the argument list.
297 If the num_args is zero, the argument list is never referenced.
298     </para>
299   </listitem>
300   </varlistentry>
301 </variablelist>
302 </para>
303 <para>
304 <!-- .LP -->
305 When a widget instance is successfully created, the widget identifier
306 is returned to the application.  If an error is encountered, the
307 <function>XtError</function>
308 routine is invoked to inform the user of the error.
309 <!-- .IN "XtError" "" "" -->
310 </para>
311 <para>
312 <!-- .LP -->
313 For further information, see <emphasis remap='I'>X Toolkit Intrinsics - C Language Interface</emphasis>.
314 </para>
315 </sect2>
316 <sect2 id="Common_Resources">
317 <title>Common Resources</title>
318 <!-- .XS -->
319 <!--    Common Resources -->
320 <!-- .XE -->
321 <!-- .IN "resource" "" -->
322 <para>
323 <!-- .LP -->
324 Although a widget can have unique arguments that it understands, all
325 widgets have common arguments that provide some regularity of operation.
326 The common arguments allow arbitrary widgets to be managed by
327 higher-level components without regard for the individual widget type.
328 Widgets will ignore any argument that they do not understand.
329 </para>
330 <para>
331 <!-- .LP -->
332 The following resources are retrieved from the argument list
333 or from the resource database by all of the Athena widgets:
334 <informaltable>
335   <tgroup cols='4' align='center'>
336   <colspec colname='c1'/>
337   <colspec colname='c2'/>
338   <colspec colname='c3'/>
339   <colspec colname='c4'/>
340   <thead>
341     <row>
342       <entry>Name</entry>
343       <entry>Class</entry>
344       <entry>Type</entry>
345       <entry>Default Value</entry>
346     </row>
347   </thead>
348   <tbody>
349     <row>
350       <entry>accelerators</entry>
351       <entry>Accelerators</entry>
352       <entry>AcceleratorTable</entry>
353       <entry>NULL</entry>
354     </row>
355     <row>
356       <entry>ancestorSensitive</entry>
357       <entry>AncestorSensitive</entry>
358       <entry>Boolean</entry>
359       <entry>True</entry>
360     </row>
361     <row>
362       <entry>background</entry>
363       <entry>Background</entry>
364       <entry>Pixel</entry>
365       <entry>XtDefaultBackground</entry>
366     </row>
367     <row>
368       <entry>backgroundPixmap</entry>
369       <entry>Pixmap</entry>
370       <entry>Pixmap</entry>
371       <entry>XtUnspecifiedPixmap</entry>
372     </row>
373     <row>
374       <entry>borderColor</entry>
375       <entry>BorderColor</entry>
376       <entry>Pixel</entry>
377       <entry>XtDefaultForeground</entry>
378     </row>
379     <row>
380       <entry>borderPixmap</entry>
381       <entry>Pixmap</entry>
382       <entry>Pixmap</entry>
383       <entry>XtUnspecifiedPixmap</entry>
384     </row>
385     <row>
386       <entry>borderWidth</entry>
387       <entry>BorderWidth</entry>
388       <entry>Dimension</entry>
389       <entry>1</entry>
390     </row>
391     <row>
392       <entry>colormap</entry>
393       <entry>Colormap</entry>
394       <entry>Colormap</entry>
395       <entry>Parent's Colormap</entry>
396     </row>
397     <row>
398       <entry>depth</entry>
399       <entry>Depth</entry>
400       <entry>int</entry>
401       <entry>Parent's Depth</entry>
402     </row>
403     <row>
404       <entry>destroyCallback</entry>
405       <entry>Callback</entry>
406       <entry>XtCallbackList</entry>
407       <entry>NULL</entry>
408     </row>
409     <row>
410       <entry>height</entry>
411       <entry>Height</entry>
412       <entry>Dimension</entry>
413       <entry><emphasis remap='I'>widget dependent</emphasis></entry>
414     </row>
415     <row>
416       <entry>mappedWhenManaged</entry>
417       <entry>MappedWhenManaged</entry>
418       <entry>Boolean</entry>
419       <entry>True</entry>
420     </row>
421     <row>
422       <entry>screen</entry>
423       <entry>Screen</entry>
424       <entry>Screen</entry>
425       <entry>Parent's Screen</entry>
426     </row>
427     <row>
428       <entry>sensitive</entry>
429       <entry>Sensitive</entry>
430       <entry>Boolean</entry>
431       <entry>True</entry>
432     </row>
433     <row>
434       <entry>translations</entry>
435       <entry>Translations</entry>
436       <entry>TranslationTable</entry>
437       <entry><emphasis remap='I'>widget dependent</emphasis></entry>
438     </row>
439     <row>
440       <entry>width</entry>
441       <entry>Width</entry>
442       <entry>Dimension</entry>
443       <entry><emphasis remap='I'>widget dependent</emphasis></entry>
444     </row>
445     <row>
446       <entry>x</entry>
447       <entry>Position</entry>
448       <entry>Position</entry>
449       <entry>0</entry>
450     </row>
451     <row>
452       <entry>y</entry>
453       <entry>Position</entry>
454       <entry>Position</entry>
455       <entry>0</entry>
456     </row>
457   </tbody>
458   </tgroup>
459 </informaltable>
460 <!-- .IN "XtDefaultForeground" "" "" -->
461 <!-- .IN "XtDefaultBackground" "" "" -->
462 </para>
463 <para>
464 <!-- .LP -->
465 The following additional resources are retrieved from the argument list
466 or from the resource database by many of the Athena widgets:
467 <informaltable>
468   <tgroup cols='4' align='center'>
469   <colspec colname='c1'/>
470   <colspec colname='c2'/>
471   <colspec colname='c3'/>
472   <colspec colname='c4'/>
473   <thead>
474     <row>
475       <entry>Name</entry>
476       <entry>Class</entry>
477       <entry>Type</entry>
478       <entry>Default Value</entry>
479     </row>
480   </thead>
481   <tbody>
482     <row>
483       <entry>callback</entry>
484       <entry>Callback</entry>
485       <entry>XtCallbackList</entry>
486       <entry>NULL</entry>
487     </row>
488     <row>
489       <entry>cursor</entry>
490       <entry>Cursor</entry>
491       <entry>Cursor</entry>
492       <entry><emphasis remap='I'>widget dependent</emphasis></entry>
493     </row>
494     <row>
495       <entry>foreground</entry>
496       <entry>Foreground</entry>
497       <entry>Pixel</entry>
498       <entry>XtDefaultForeground</entry>
499     </row>
500     <row>
501       <entry>insensitiveBorder</entry>
502       <entry>Insensitive</entry>
503       <entry>Pixmap</entry>
504       <entry>GreyPixmap</entry>
505     </row>
506   </tbody>
507   </tgroup>
508 </informaltable>
509 <!-- .IN "XtDefaultForeground" "" "" -->
510 </para>
511 </sect2>
512 <sect2 id="Resource_Conversions">
513 <title>Resource Conversions</title>
514 <!-- .XS -->
515 <!--    Resource Conversions -->
516 <!-- .XE -->
517 <!-- .IN "conversions" "" "@DEF@" -->
518 <!-- .IN "string conversions" "" "@DEF@" -->
519 <!-- .IN "type conversions" "" "@DEF@" -->
520 <para>
521 <!-- .LP -->
522 Most resources in the Athena widget set have a converter registered that
523 will translate the string in a resource file to the correct internal
524 representation.  While some are obvious (string to integer, for example),
525 others need specific mention of the allowable values.  Three general
526 converters are described here:
527 </para>
528 <itemizedlist>
529   <listitem>
530     <para>
531 Cursor
532     </para>
533   </listitem>
534   <listitem>
535     <para>
536 Pixel
537     </para>
538   </listitem>
539   <listitem>
540     <para>
541 Bitmap
542     </para>
543   </listitem>
544 </itemizedlist>
545 <para>
546 <!-- .LP -->
547 Many widgets have defined special converters that apply only to that
548 widget.  When these occur, the documentation section for that widget
549 will describe the converter.
550 </para>
551 <sect3 id="Cursor_Conversion">
552 <title>Cursor Conversion</title>
553 <!-- .IN "conversions" "ColorCursor" "@DEF@" -->
554 <!-- .IN "conversions" "Cursor" "@DEF@" -->
555 <!-- .IN "cursor" "" "" -->
556 <para>
557 <!-- .LP -->
558 The value for the <function>cursorName</function> resource is specified in the resource
559 database as a string, and is of the following forms:
560 </para>
561 <itemizedlist>
562   <listitem>
563     <para>
564 A standard X cursor name from <function>&lt; X11/cursorfont.h &gt;</function>.
565 The names in <function>cursorfont.h</function> each describe a specific cursor.  The
566 resource names for these cursors are exactly like the names in this file
567 except the <function>XC_</function> is not used.  The cursor definition <function>XC_gumby</function>
568 has a resource name of <function>gumby</function>.
569     </para>
570   </listitem>
571   <listitem>
572     <para>
573 Glyphs, as in <emphasis remap='I'>FONT font-name glyph-index [[ font-name ] glyph-index ]</emphasis>.
574 The first font and glyph specify the cursor source pixmap.
575 The second font and glyph specify the cursor mask pixmap.
576 The mask font defaults to the source font,
577 and the mask glyph index defaults to the source glyph index.
578     </para>
579   </listitem>
580   <listitem>
581     <para>
582 A relative or absolute file name.
583 If a relative or absolute file name is specified, that file is used to
584 create the source pixmap.  Then the string "Mask" is appended to
585 locate the cursor mask pixmap.  If the "Mask" file does not exist, the
586 suffix "msk" is tried.  If "msk" fails, no cursor mask will be used.
587 If the filename does not start with '/' or './' the the bitmap
588 file path is used (see section 2.4.3). <!-- xref -->
589     </para>
590   </listitem>
591 </itemizedlist>
592 </sect3>
593 <sect3 id="Pixel_Conversion">
594 <title>Pixel Conversion</title>
595 <para>
596 <!-- .LP -->
597 <!-- .IN "conversions" "Pixel" "@DEF@" -->
598 <!-- .IN "pixel" "" "" -->
599 <!-- .IN "rgb.txt" "" "" -->
600 <!-- .IN "XtDefaultForeground" "" "" -->
601 <!-- .IN "XtDefaultBackground" "" "" -->
602 The string-to-pixel converter takes any name that is acceptable to
603 XParseColor (see <emphasis remap='I'>Xlib - C Language Interface</emphasis>).  In addition this routine understands
604 the special toolkit symbols `XtDefaultForeground' and
605 `XtDefaultBackground', described in <emphasis remap='I'>X Toolkit Intrinsics - C Language Interface</emphasis>.  In short the acceptable
606 pixel names are:
607 </para>
608 <itemizedlist>
609   <listitem>
610     <para>
611 Any color name for the rgb.txt file (typically in the directory
612 /usr/lib/X11 on POSIX systems).
613     </para>
614   </listitem>
615   <listitem>
616     <para>
617 A numeric specification of the form #&lt;red&gt;&lt;green&gt;&lt;blue&gt; where these
618 numeric values are hexadecimal digits (both upper and lower case).
619     </para>
620   </listitem>
621   <listitem>
622     <para>
623 The special strings `XtDefaultForeground' and `XtDefaultBackground'
624     </para>
625   </listitem>
626 </itemizedlist>
627 </sect3>
628 <sect3 id="Bitmap_Conversion">
629 <title>Bitmap Conversion</title>
630 <!-- .IN "bitmap conversions" "" "@DEF@" -->
631 <!-- .IN "conversions" "Bitmap" "@DEF@" -->
632 <!-- .IN "bitmapFilePath" "" "@DEF@" -->
633 <!-- .IN "BitmapFilePath" "" "@DEF@" -->
634 <!-- .IN "/usr/include/X11/bitmaps" "" "" -->
635 <para>
636 <!-- .LP -->
637 The string-to-bitmap converter attempts to locate a file containing
638 bitmap data whose name is specified by the input string.  If the file
639 name is relative (i.e. does not begin with / or ./), the directories to
640 be searched are specified in the <function>bitmapFilePath</function> resource--class
641 <function>BitmapFilePath</function>.  This resource specifies a colon (:) separated
642 list of directories that will be searched for the named bitmap or
643 cursor glyph (see section 2.4.1).  The <function>bitmapFilePath</function> resource is
644 global to the application, and may <function>not</function> be specified differently
645 for each widget that wishes to convert a cursor to bitmap.  In addition
646 to the directories specified in the <function>bitmapFilePath</function> resource a
647 default directory is searched.  When using POSIX the default
648 directory is
649 <function>/usr/include/X11/bitmaps .</function>
650 </para>
651 </sect3>
652 </sect2>
653 <sect2 id="Realizing_a_Widget">
654 <title>Realizing a Widget</title>
655 <para>
656 <!-- .LP -->
657 <!-- .XS -->
658 <!--    Realizing a Widget -->
659 <!-- .XE -->
660 <!-- .IN "realizing widgets" "" "@DEF@" -->
661 The
662 <function>XtRealizeWidget</function>
663 function performs two tasks:
664 </para>
665 <itemizedlist>
666   <listitem>
667     <para>
668 Calculates the geometry constraints of all managed descendants
669 of this widget.  The actual calculation is put off until realize time
670 for performance reasons.
671     </para>
672   </listitem>
673   <listitem>
674     <para>
675 Creates an X window for the widget and, if it is a composite widget,
676 realizes each of its managed children.
677 <!-- .IN "XtRealizeWidget" "" "@DEF@" -->
678 <funcsynopsis>
679 <funcprototype>
680   <funcdef>void<function> XtRealizeWidget</function></funcdef>
681   <paramdef>Widget<parameter> w</parameter></paramdef>
682 </funcprototype>
683 </funcsynopsis>
684 <!-- .FN -->
685     </para>
686   </listitem>
687   <listitem>
688     <para>
689 Specifies the widget.
690     </para>
691   </listitem>
692 </itemizedlist>
693 <para>
694 <!-- .LP -->
695 For further information about this function,
696 see the <emphasis remap='I'>X Toolkit Intrinsics - C Language Interface</emphasis>.
697 </para>
698 </sect2>
699 <sect2 id="Processing_Events">
700 <title>Processing Events</title>
701 <para>
702 <!-- .LP -->
703 <!-- .XS -->
704 <!--    Processing Events -->
705 <!-- .XE -->
706 <!-- .IN "events" "" "" -->
707 <!-- .IN "XtAppInitialize" "" "" -->
708 Now that the application has created, managed and realized its
709 widgets, it is ready to process the events that will be delivered by the
710 X Server to this client.  A function call that will process the
711 events is <function>XtAppMainLoop</function>.
712 <!-- .IN "XtAppMainLoop" "" "@DEF@" -->
713 <funcsynopsis>
714 <funcprototype>
715   <funcdef>void<function> XtAppMainLoop</function></funcdef>
716   <paramdef>XtAppContext<parameter> app_context</parameter></paramdef>
717 </funcprototype>
718 </funcsynopsis>
719 <!-- .FN -->
720 <variablelist>
721   <varlistentry>
722     <term>
723       <emphasis remap='I'>app_context</emphasis>
724     </term>
725     <listitem>
726       <para>
727 Specifies the application context of this application.  The value is
728 normally returned by <function>XtAppInitialize</function>.
729     </para>
730   </listitem>
731   </varlistentry>
732 </variablelist>
733 </para>
734 <para>
735 <!-- .LP -->
736 This function never returns: it is an infinite loop that processes the
737 X events.  User input can be handled through callback procedures and
738 application defined action routines.  More details are provided in
739 <emphasis remap='I'>X Toolkit Intrinsics - C Language Interface</emphasis>.
740 </para>
741 </sect2>
742 <sect2 id="Standard_Widget_Manipulation_Functions">
743 <title>Standard Widget Manipulation Functions</title>
744 <!-- .XS -->
745 <!--    Standard Widget Manipulation Functions -->
746 <!-- .XE -->
747 <para>
748 <!-- .LP -->
749 After a widget has been created, a client can interact with that
750 widget by calling one of the standard widget manipulation routines
751 provided by the Intrinsics, or a widget class-specific manipulation routine.
752 </para>
753 <para>
754 <!-- .LP -->
755 The Intrinsics provide generic routines to give the application programmer
756 access to a set of standard widget functions.  The common widget
757 routines let an application or composite widget perform the following
758 operations on widgets without requiring explicit knowledge of the widget
759 type.
760 </para>
761 <itemizedlist>
762   <listitem>
763     <para>
764 Control the mapping of widget windows
765     </para>
766   </listitem>
767   <listitem>
768     <para>
769 Destroy a widget instance
770     </para>
771   </listitem>
772   <listitem>
773     <para>
774 Obtain an argument value
775     </para>
776   </listitem>
777   <listitem>
778     <para>
779 Set an argument value
780     </para>
781   </listitem>
782 </itemizedlist>
783 <sect3 id="Mapping_Widgets">
784 <title>Mapping Widgets</title>
785 <para>
786 <!-- .LP -->
787 By default,
788 widget windows are mapped (made viewable) automatically by
789 <function>XtRealizeWidget</function>.  This behavior can be disabled by using
790 <function>XtSetMappedWhenManaged</function>, making the client responsible for calling
791 <function>XtMapWidget</function> to make the widget viewable.
792 <!-- .IN "XtSetMappedWhenManaged" "" "@DEF@" -->
793 <!-- .IN "XtMapWidget" "" "" -->
794 <!-- .IN "XtRealizeWidget" "" "" -->
795 <funcsynopsis>
796 <funcprototype>
797   <funcdef>void<function> XtSetMappedWhenManaged</function></funcdef>
798   <paramdef>Widget<parameter> w</parameter></paramdef>
799   <paramdef>Boolean<parameter> map_when_managed</parameter></paramdef>
800 </funcprototype>
801 </funcsynopsis>
802 <!-- .FN -->
803 <variablelist>
804   <varlistentry>
805     <term>
806       <emphasis remap='I'>w</emphasis>
807     </term>
808     <listitem>
809       <para>
810 Specifies the widget.
811       </para>
812     </listitem>
813   </varlistentry>
814   <varlistentry>
815     <term>
816       <emphasis remap='I'>map_when_managed</emphasis>
817     </term>
818     <listitem>
819       <para>
820 Specifies the new value.
821 If map_when_managed is <function>True</function>, the widget is mapped automatically
822 when it is realized.  If map_when_managed is <function>False</function>, the client
823 must call
824 <function>XtMapWidget</function>
825 or make a second call to
826 <function>XtSetMappedWhenManaged</function>
827 to cause the child window to be mapped.
828     </para>
829   </listitem>
830   </varlistentry>
831 </variablelist>
832 </para>
833 <para>
834 <!-- .LP -->
835 <!-- .sp -->
836 The definition for
837 <function>XtMapWidget</function>
838 is:
839 <!-- .IN "XtMapWidget" "" "@DEF@" -->
840 <funcsynopsis>
841 <funcprototype>
842   <funcdef>void<function> XtMapWidget</function></funcdef>
843   <paramdef>Widget<parameter> w</parameter></paramdef>
844 </funcprototype>
845 </funcsynopsis>
846 <!-- .FN -->
847 <variablelist>
848   <varlistentry>
849     <term>
850       <emphasis remap='I'>w</emphasis>
851     </term>
852     <listitem>
853       <para>
854 Specifies the widget.
855     </para>
856   </listitem>
857   </varlistentry>
858 </variablelist>
859 </para>
860 <para>
861 <!-- .LP -->
862 When you are creating several children in sequence for a previously
863 realized common parent it is generally more efficient to construct a
864 list of children as they are created (using <function>XtCreateWidget</function>) and
865 then use <function>XtManageChildren</function> to request that their parent managed
866 them all at once.  By managing a list of children at one time, the
867 parent can avoid wasteful duplication of geometry processing and the
868 associated ``screen flash''.
869 <!-- .IN "XtManageChildren" "" "@DEF@" -->
870 <!-- .IN "XtCreateWidget" "" "" -->
871 <funcsynopsis>
872 <funcprototype>
873   <funcdef>void<function> XtManageChildren</function></funcdef>
874   <paramdef>WidgetList<parameter> children</parameter></paramdef>
875   <paramdef>Cardinal<parameter> num_children</parameter></paramdef>
876 </funcprototype>
877 </funcsynopsis>
878 <!-- .FN -->
879 <variablelist>
880   <varlistentry>
881     <term>
882       <emphasis remap='I'>children</emphasis>
883     </term>
884     <listitem>
885       <para>
886 Specifies a list of children to add.
887       </para>
888     </listitem>
889   </varlistentry>
890   <varlistentry>
891     <term>
892       <emphasis remap='I'>num_children</emphasis>
893     </term>
894     <listitem>
895       <para>
896 Specifies the number of children to add.
897     </para>
898   </listitem>
899   </varlistentry>
900 </variablelist>
901 </para>
902 <para>
903 <!-- .LP -->
904 If the parent is already visible on the screen, it is especially
905 important to batch updates so that the minimum amount of visible window
906 reconfiguration is performed.
907 </para>
908 <para>
909 <!-- .LP -->
910 For further information about these functions,
911 see the <emphasis remap='I'>X Toolkit Intrinsics - C Language Interface</emphasis>.
912 </para>
913 </sect3>
914 <sect3 id="Destroying_Widgets">
915 <title>Destroying Widgets</title>
916 <para>
917 <!-- .LP -->
918 To destroy a widget instance of any type, use
919 <function>XtDestroyWidget</function>
920 <!-- .IN "XtDestroyWidget" "" "@DEF@" -->
921 <funcsynopsis>
922 <funcprototype>
923   <funcdef>void<function> XtDestroyWidget</function></funcdef>
924   <paramdef>Widget<parameter> w</parameter></paramdef>
925 </funcprototype>
926 </funcsynopsis>
927 <!-- .FN -->
928 <variablelist>
929   <varlistentry>
930     <term>
931       <emphasis remap='I'>w</emphasis>
932     </term>
933     <listitem>
934       <para>
935 Specifies the widget.
936     </para>
937   </listitem>
938   </varlistentry>
939 </variablelist>
940 </para>
941 <para>
942 <!-- .LP -->
943 <function>XtDestroyWidget</function>
944 destroys the widget and recursively destroys any children that it may have,
945 including the windows created by its children.
946 After calling
947 <function>XtDestroyWidget ,</function>
948 no further references should be made to the widget or any children
949 that the destroyed widget may have had.
950 </para>
951 </sect3>
952 <sect3 id="Retrieving_Widget_Resource_Values">
953 <title>Retrieving Widget Resource Values</title>
954 <para>
955 <!-- .LP -->
956 To retrieve the current value of a resource attribute associated
957 with a widget instance, use
958 <function>XtGetValues .</function>
959 <!-- .IN "XtGetValues" "" "@DEF@" -->
960 <funcsynopsis>
961 <funcprototype>
962   <funcdef>void<function> XtGetValues</function></funcdef>
963   <paramdef>Widget<parameter> w</parameter></paramdef>
964   <paramdef>ArgList<parameter> args</parameter></paramdef>
965   <paramdef>Cardinal<parameter> num_args</parameter></paramdef>
966 </funcprototype>
967 </funcsynopsis>
968 <!-- .FN -->
969 <variablelist>
970   <varlistentry>
971     <term>
972       <emphasis remap='I'>w</emphasis>
973     </term>
974     <listitem>
975       <para>
976 Specifies the widget.
977       </para>
978     </listitem>
979   </varlistentry>
980   <varlistentry>
981     <term>
982       <emphasis remap='I'>args</emphasis>
983     </term>
984     <listitem>
985       <para>
986 Specifies a variable-length argument list of name and <function>address</function>
987 pairs that contain the resource name and the address into which the
988 resource value is stored.
989       </para>
990     </listitem>
991   </varlistentry>
992   <varlistentry>
993     <term>
994       <emphasis remap='I'>num_args</emphasis>
995     </term>
996     <listitem>
997       <para>
998 Specifies the number of arguments in the argument list.
999     </para>
1000   </listitem>
1001   </varlistentry>
1002 </variablelist>
1003 </para>
1004 <para>
1005 <!-- .LP -->
1006 The arguments and values passed in the argument list are dependent on
1007 the widget. Note that the caller is responsible for providing space
1008 into which the returned resource value is copied; the <function>ArgList</function>
1009 contains a pointer to this storage (e.g. x and y must be
1010 allocated as Position).  For further information, see the <emphasis remap='I'>X Toolkit Intrinsics - C Language Interface</emphasis>.
1011 </para>
1012 </sect3>
1013 <sect3 id="Modifying_Widget_Resource_Values">
1014 <title>Modifying Widget Resource Values</title>
1015 <para>
1016 <!-- .LP -->
1017 To modify the current value of a resource attribute associated with a
1018 widget instance, use
1019 <function>XtSetValues .</function>
1020 <!-- .IN "XtSetValues" "" "@DEF@" -->
1021 <funcsynopsis>
1022 <funcprototype>
1023   <funcdef>void<function> XtSetValues</function></funcdef>
1024   <paramdef>Widget<parameter> w</parameter></paramdef>
1025   <paramdef>ArgList<parameter> args</parameter></paramdef>
1026   <paramdef>Cardinal<parameter> num_args</parameter></paramdef>
1027 </funcprototype>
1028 </funcsynopsis>
1029 <!-- .FN -->
1030 <variablelist>
1031   <varlistentry>
1032     <term>
1033       <emphasis remap='I'>w</emphasis>
1034     </term>
1035     <listitem>
1036       <para>
1037 Specifies the widget.
1038       </para>
1039     </listitem>
1040   </varlistentry>
1041   <varlistentry>
1042     <term>
1043       <emphasis remap='I'>args</emphasis>
1044     </term>
1045     <listitem>
1046       <para>
1047 Specifies an array of name and <function>value</function> pairs that contain the
1048 arguments to be modified and their new values.
1049       </para>
1050     </listitem>
1051   </varlistentry>
1052   <varlistentry>
1053     <term>
1054       <emphasis remap='I'>num_args</emphasis>
1055     </term>
1056     <listitem>
1057       <para>
1058 Specifies the number of arguments in the argument list.
1059     </para>
1060   </listitem>
1061   </varlistentry>
1062 </variablelist>
1063 </para>
1064 <para>
1065 <!-- .LP -->
1066 The arguments and values that are passed will depend on the widget
1067 being modified.  Some widgets may not allow certain resources to be
1068 modified after the widget instance has been created or realized.
1069 No notification is given if any part of a <function>XtSetValues</function> request is
1070 ignored.
1071 </para>
1072 <para>
1073 <!-- .LP -->
1074 For further information about these functions, see the <emphasis remap='I'>X Toolkit Intrinsics - C Language Interface</emphasis>.
1075 <!-- .IN "XtGetValues" "" "" -->
1076 <!-- .IN "XtSetValues" "" "" -->
1077 <!-- .NT -->
1078 The argument list entry for
1079 <function>XtGetValues</function>
1080 specifies the address to which the caller wants the value copied.  The
1081 argument list entry for
1082 <function>XtSetValues ,</function>
1083 however, contains the new value itself, if the size of value is less than
1084 sizeof(XtArgVal) (architecture dependent, but at least sizeof(long));
1085 otherwise, it is a pointer to the value.  String resources are always
1086 passed as pointers, regardless of the length of the string.
1087 <!-- .NE -->
1088 </para>
1089 </sect3>
1090 </sect2>
1091 <sect2 id="Using_the_Client_Callback_Interface">
1092 <title>Using the Client Callback Interface</title>
1093 <para>
1094 <!-- .LP -->
1095 <!-- .XS -->
1096 <!--    Using the Client Callback Interface -->
1097 <!-- .XE -->
1098 <!-- .IN "callbacks" "" "" -->
1099 Widgets can communicate changes in their state to their clients
1100 by means of a callback facility.
1101 The format for a client's callback handler is:
1102 <!-- .IN "CallbackProc" "" "@DEF@" -->
1103 <funcsynopsis>
1104 <funcprototype>
1105   <funcdef>void<function> CallbackProc</function></funcdef>
1106   <paramdef>Widget<parameter> w</parameter></paramdef>
1107   <paramdef>XtPointer<parameter> client_data</parameter></paramdef>
1108   <paramdef>XtPointer<parameter> call_data</parameter></paramdef>
1109 </funcprototype>
1110 </funcsynopsis>
1111 <!-- .FN -->
1112 <variablelist>
1113   <varlistentry>
1114     <term>
1115       <emphasis remap='I'>w</emphasis>
1116     </term>
1117     <listitem>
1118       <para>
1119 Specifies widget for which the callback is registered.
1120       </para>
1121     </listitem>
1122   </varlistentry>
1123   <varlistentry>
1124     <term>
1125       <emphasis remap='I'>client_data</emphasis>
1126     </term>
1127     <listitem>
1128       <para>
1129 Specifies arbitrary client-supplied data that the widget should pass
1130 back to the client when the widget executes the client's callback
1131 procedure.  This is a way for the client registering the callback to
1132 also register client-specific data: a pointer to additional information
1133 about the widget, a reason for invoking the callback, and so on. If no
1134 additional information is necessary, NULL may be passed as this argument.
1135 This field is also frequently known as the <emphasis remap='I'>closure</emphasis>.
1136       </para>
1137     </listitem>
1138   </varlistentry>
1139   <varlistentry>
1140     <term>
1141       <emphasis remap='I'>call_data</emphasis>
1142     </term>
1143     <listitem>
1144       <para>
1145 Specifies any callback-specific data the widget wants to pass to the client.
1146 For example, when Scrollbar executes its <function>jumpProc</function> callback list,
1147 it passes the current position of the thumb in <emphasis remap='I'>call_data</emphasis>.
1148     </para>
1149   </listitem>
1150   </varlistentry>
1151 </variablelist>
1152 </para>
1153 <para>
1154 <!-- .LP -->
1155 Callbacks can be registered either by creating an argument containing
1156 the callback list described below or by using the special convenience
1157 routines <function>XtAddCallback</function> and <function>XtAddCallbacks</function>.  When the widget
1158 is created, a pointer to a list of callback procedure and data pairs can
1159 be passed in the argument list to
1160 <function>XtCreateWidget .</function>
1161 The list is of type
1162 <function>XtCallbackList :</function>
1163 <!-- .IN "XtCallbackProc" -->
1164 <!-- .IN "XtAddCallbacks" -->
1165 <!-- .IN "XtAddCallback" -->
1166 <!-- .IN "XtCallbackList" "" "@DEF@" -->
1167 <!-- .IN "XtCallbackRec" "" "@DEF@" -->
1168 </para>
1169 <para>
1170 <!-- .LP -->
1171 <literallayout class="monospaced">
1172 <!-- .TA .5i 3i -->
1173 <!-- .ta .5i 3i -->
1174 typedef struct {
1175         XtCallbackProc callback;
1176         XtPointer closure;
1177 } XtCallbackRec, *XtCallbackList;
1178 </literallayout>
1179 </para>
1180 <para>
1181 <!-- .LP -->
1182 The callback list must be allocated and initialized before calling
1183 <function>XtCreateWidget .</function>
1184 <!-- .IN "XtCreateWidget" -->
1185 The end of the list is identified by an entry containing NULL in
1186 callback and closure.  Once the widget is created, the client can change
1187 or de-allocate this list; the widget itself makes no further reference
1188 to it.  The closure field contains the client_data passed to the
1189 callback when the callback list is executed.
1190 </para>
1191 <para>
1192 <!-- .LP -->
1193 The second method for registering callbacks is to use
1194 <function>XtAddCallback</function>
1195 after the widget has been created.
1196 <!-- .IN "XtAddCallback" "" "@DEF@" -->
1197 <funcsynopsis>
1198 <funcprototype>
1199   <funcdef>void<function> XtAddCallback</function></funcdef>
1200   <paramdef>Widget<parameter> w</parameter></paramdef>
1201   <paramdef>String<parameter> callback_name</parameter></paramdef>
1202   <paramdef>XtCallbackProc<parameter> callback</parameter></paramdef>
1203   <paramdef>XtPointer<parameter> client_data</parameter></paramdef>
1204 </funcprototype>
1205 </funcsynopsis>
1206 <!-- .FN -->
1207 <variablelist>
1208   <varlistentry>
1209     <term>
1210       <emphasis remap='I'>w</emphasis>
1211     </term>
1212     <listitem>
1213       <para>
1214 Specifies the widget to add the callback to.
1215       </para>
1216     </listitem>
1217   </varlistentry>
1218   <varlistentry>
1219     <term>
1220       <emphasis remap='I'>callback_name</emphasis>
1221     </term>
1222     <listitem>
1223       <para>
1224 Specifies the callback list within the widget to append to.
1225       </para>
1226     </listitem>
1227   </varlistentry>
1228   <varlistentry>
1229     <term>
1230       <emphasis remap='I'>callback</emphasis>
1231     </term>
1232     <listitem>
1233       <para>
1234 Specifies the callback procedure to add.
1235       </para>
1236     </listitem>
1237   </varlistentry>
1238   <varlistentry>
1239     <term>
1240       <emphasis remap='I'>client_data</emphasis>
1241     </term>
1242     <listitem>
1243       <para>
1244 Specifies the data to be passed to the callback when it is invoked.
1245     </para>
1246   </listitem>
1247   </varlistentry>
1248 </variablelist>
1249 </para>
1250 <para>
1251 <!-- .LP -->
1252 <function>XtAddCallback</function>
1253 adds the specified callback to the list for the named widget.
1254 </para>
1255 <para>
1256 <!-- .LP -->
1257 All widgets provide a callback list named
1258 <function>destroyCallback</function>
1259 <!-- .IN "destroyCallback" "" "@DEF@" -->
1260 where clients can register procedures that are to be executed when the
1261 widget is destroyed.  The destroy callbacks are executed when the widget
1262 or an ancestor is destroyed.  The <emphasis remap='I'>call_data</emphasis> argument is unused for
1263 destroy callbacks.
1264 </para>
1265 </sect2>
1266 <sect2 id="Programming_Considerations">
1267 <title>Programming Considerations</title>
1268 <para>
1269 <!-- .LP -->
1270 <!-- .XS -->
1271 <!--    Programming Considerations -->
1272 <!-- .XE -->
1273 This section provides some guidelines on how to set up an application
1274 program that uses the X Toolkit.
1275 </para>
1276 <sect3 id="Writing_Applications">
1277 <title>Writing Applications</title>
1278 <para>
1279 <!-- .LP -->
1280 <!-- .IN "writing applications" -->
1281 <!-- .IN "StringDefs.h" -->
1282 <!-- .IN "Intrinsic.h" -->
1283 When writing an application that uses the X Toolkit,
1284 you should make sure that your application performs the following:
1285 </para>
1286 <orderedlist>
1287   <listitem>
1288     <para>
1289 Include
1290 <function>&lt; X11/Intrinsic.h &gt;</function>
1291 in your application programs.
1292 This header file automatically includes
1293 <function>&lt; X11/Xlib.h &gt;,</function>
1294 so all Xlib functions also are defined.
1295 It may also be necessary to include <function>&lt; X11/StringDefs.h &gt;</function> when setting
1296 up argument lists, as many of the XtN<emphasis remap='I'>something</emphasis> definitions are
1297 only defined in this file.
1298     </para>
1299   </listitem>
1300   <listitem>
1301     <para>
1302 Include the widget-specific header files for each widget type
1303 that you need to use.
1304 For example,
1305 <function>&lt; X11/Xaw/Label.h &gt;</function>
1306 and
1307 <function>&lt; X11/Xaw/Command.h &gt;.</function>
1308     </para>
1309   </listitem>
1310   <listitem>
1311     <para>
1312 Call the
1313 <function>XtAppInitialize</function>
1314 <!-- .IN "XtAppInitialize" -->
1315 function before invoking any other toolkit or Xlib functions.
1316 For further information,
1317 see Section 2.1 and the <emphasis remap='I'>X Toolkit Intrinsics - C Language Interface</emphasis>.
1318     </para>
1319   </listitem>
1320   <listitem>
1321     <para>
1322 To pass attributes to the widget creation routines that will override
1323 any site or user customizations, set up argument lists.  In this
1324 document, a list of valid argument names is provided in the discussion
1325 of each widget.  The names each have a global symbol defined that begins
1326 with <function>XtN</function> to help catch spelling errors.  For example,
1327 <function>XtNlabel</function> is defined for the <function>label</function> resource of many widgets.
1328 <!-- .IN "XtN" "" "@DEF@" -->
1329     </para>
1330   </listitem>
1331   <listitem>
1332     <para>
1333 For further information, see Section 2.9.2.2.  <!-- xref -->
1334     </para>
1335   </listitem>
1336   <listitem>
1337     <para>
1338 When the argument list is set up, create the widget with the
1339 <function>XtCreateManagedWidget</function> function.  For further information, see
1340 Section 2.2 and the <emphasis remap='I'>X Toolkit Intrinsics - C Language Interface</emphasis>.
1341 <!-- .IN "XtCreateManagedWidget" -->
1342     </para>
1343   </listitem>
1344   <listitem>
1345     <para>
1346 If the widget has any callback routines, set by the
1347 <function>XtNcallback</function>
1348 argument or the
1349 <function>XtAddCallback</function>
1350 function, declare these routines within the application.
1351 <!-- .IN "XtAddCallback" -->
1352     </para>
1353   </listitem>
1354   <listitem>
1355     <para>
1356 After creating the initial widget hierarchy, windows must be created
1357 for each widget by calling
1358 <function>XtRealizeWidget</function>
1359 on the top level widget.
1360 <!-- .IN "XtRealizeWidget" -->
1361     </para>
1362   </listitem>
1363   <listitem>
1364     <para>
1365 Most applications now sit in a loop processing events using
1366 <function>XtAppMainLoop ,</function>
1367 for example:
1368 <!-- .IN "XtAppMainLoop" -->
1369     </para>
1370   </listitem>
1371   <listitem>
1372     <para>
1373 <literallayout class="monospaced">
1374 XtCreateManagedWidget(<emphasis remap='I'>name</emphasis>, <emphasis remap='I'>class</emphasis>, <emphasis remap='I'>parent</emphasis>, <emphasis remap='I'>args</emphasis>, <emphasis remap='I'>num_args</emphasis>);
1375 XtRealizeWidget(<emphasis remap='I'>shell</emphasis>);
1376 XtAppMainLoop(<emphasis remap='I'>app_context</emphasis>);
1377 </literallayout>
1378     </para>
1379   </listitem>
1380   <listitem>
1381     <para>
1382 For information about this function, see the <emphasis remap='I'>X Toolkit Intrinsics - C Language Interface</emphasis>.
1383     </para>
1384   </listitem>
1385   <listitem>
1386     <para>
1387 Link your application with
1388 <function>libXaw</function>
1389 (the Athena widgets),
1390 <function>libXmu</function>
1391 (miscellaneous utilities),
1392 <function>libXt</function>
1393 (the X Toolkit Intrinsics),
1394 <function>libSM</function>
1395 (Session Management),
1396 <function>libICE</function>
1397 (Inter-Client Exchange),
1398 <function>libXext</function>
1399 (the extension library needed for the shape extension code which allows
1400 rounded Command buttons), and
1401 <function>libX11</function>
1402 (the core X library).
1403 The following provides a sample command line:
1404 <!-- .IN "libXaw" -->
1405 <!-- .IN "libXmu" -->
1406 <!-- .IN "libXt" -->
1407 <!-- .IN "libSM" -->
1408 <!-- .IN "libICE" -->
1409 <!-- .IN "libXext" -->
1410 <!-- .IN "libX11" -->
1411 <!-- .IN "linking applications" -->
1412 <!-- .IN "compiling applications" -->
1413     </para>
1414   </listitem>
1415   <listitem>
1416     <para>
1417 <literallayout class="monospaced">
1418 cc -o <emphasis remap='I'>application</emphasis> <emphasis remap='I'>application</emphasis>.c \-lXaw \-lXmu \-lXt \
1419 \-lSM \-lICE \-lXext \-lX11
1420 </literallayout>
1421     </para>
1422   </listitem>
1423 </orderedlist>
1424 </sect3>
1425 <sect3 id="Changing_Resource_Values">
1426 <title>Changing Resource Values</title>
1427 <!-- .IN "resource" "" -->
1428 <para>
1429 <!-- .LP -->
1430 The Intrinsics support two methods of changing the default resource
1431 values; the resource manager, and an argument list passed into
1432 XtCreateWidget.  While resources values will get updated no matter
1433 which method you use, the two methods provide slightly different
1434 functionality.
1435 <variablelist>
1436   <varlistentry>
1437     <term>Resource Manager</term>
1438     <listitem>
1439       <para>
1440 This method picks up resource definitions described in <emphasis remap='I'>Xlib - C Language Interface</emphasis> from
1441 many different locations at run time.  The locations most important to
1442 the application programmer are the <emphasis remap='I'>fallback resources</emphasis> and the
1443 <emphasis remap='I'>app-defaults</emphasis> file, (see <emphasis remap='I'>X Toolkit Intrinsics - C Language Interface</emphasis> for the complete list).
1444 Since these resource are loaded at run time, they can be overridden by
1445 the user, allowing an application to be customized to fit the
1446 particular needs of each individual user.  These values can also be
1447 modified without the need to rebuild the application, allowing rapid
1448 prototyping of user interfaces.  Application programmers should use
1449 resources in preference to hard-coded values whenever possible.
1450       </para>
1451     </listitem>
1452   </varlistentry>
1453   <varlistentry>
1454     <term>Argument Lists</term>
1455     <listitem>
1456       <para>
1457 The values passed into the widget at creation time via an argument list
1458 cannot be modified by the user, and allow no opportunity for
1459 customization.  It is used to set resources that cannot be specified as
1460 strings (e.g. callback lists) or resources that should not be
1461 overridden (e.g. window depth) by the user.
1462     </para>
1463   </listitem>
1464   </varlistentry>
1465 </variablelist>
1466 </para>
1467 <sect4 id="Specifying_Resources">
1468 <title>Specifying Resources</title>
1469 <para>
1470 <!-- .LP -->
1471 It is important for all X Toolkit application programmers to
1472 understand how to use the X Resource Manager to specify resources for
1473 widgets in an X application.  This section will describe the most common
1474 methods used to specify these resources, and how to use the X Resource
1475 manager.
1476 <!-- .IN "xrdb" -->
1477 <variablelist>
1478   <varlistentry>
1479     <term>
1480       <function>Xrdb</function>
1481     </term>
1482     <listitem>
1483       <para>
1484 The <function>xrdb</function> utility may be used to load a file containing
1485 resources into the X server.   Once the resources are loaded, the
1486 resources will affect any new applications started on the display that
1487 they were loaded onto.
1488 <!-- .IN "application defaults" -->
1489 <!-- .IN "app-defaults" -->
1490 <!-- .IN "/usr/lib/X11/app-defaults" -->
1491       </para>
1492     </listitem>
1493   </varlistentry>
1494   <varlistentry>
1495     <term>Application Defaults</term>
1496     <listitem>
1497       <para>
1498 The application defaults (app-defaults) file (normally in
1499 /usr/lib/X11/app-defaults/<emphasis remap='I'>classname</emphasis>) for an application is loaded
1500 whenever the application is started.
1501     </para>
1502   </listitem>
1503   </varlistentry>
1504 </variablelist>
1505 </para>
1506 <para>
1507 <!-- .LP -->
1508 The resource specification has two colon-separated parts, a name, and
1509 a value.  The <emphasis remap='I'>value</emphasis> is a string whose format is dependent on the
1510 resource specified by <emphasis remap='I'>name</emphasis>.  <emphasis remap='I'>Name</emphasis> is constructed by
1511 appending a resource name to a full widget name.
1512 </para>
1513 <para>
1514 <!-- .LP -->
1515 The full widget name is a list of the name of every ancestor of the
1516 desired widget separated by periods (.).  Each widget also has a class
1517 associated with it.  A class is a type of widget (e.g. Label or
1518 Scrollbar or Box).  Notice that class names, by convention, begin with
1519 capital letters and instance names begin with lower case letters.  The
1520 class of any widget may be used in place of its name in a resource
1521 specification.  Here are a few examples:
1522 <variablelist>
1523   <varlistentry>
1524     <term>
1525       xman.form.button1
1526     </term>
1527     <listitem>
1528       <para>
1529 This is a fully specified resource name, and will affect only widgets
1530 called button1 that are children of widgets called form that are
1531 children of
1532 applications named xman.  (Note that while typically two widgets that
1533 are siblings will have different names, it is not prohibited.)
1534
1535       </para>
1536     </listitem>
1537   </varlistentry>
1538   <varlistentry>
1539     <term>
1540       Xman.Form.Command
1541     </term>
1542     <listitem>
1543       <para>
1544 This will match any Command widget that is a child of a Form widget
1545 that is itself a child of an application of class <emphasis remap='I'>Xman</emphasis>.
1546       </para>
1547     </listitem>
1548   </varlistentry>
1549   <varlistentry>
1550     <term>
1551       Xman.Form.button1
1552     </term>
1553     <listitem>
1554       <para>
1555 This is a mixed resource name with both widget names and classes specified.
1556     </para>
1557   </listitem>
1558   </varlistentry>
1559 </variablelist>
1560 </para>
1561 <para>
1562 <!-- .LP -->
1563 This syntax allows an application programmer to specify any widget
1564 in the widget tree.  To match more than one widget (for example a user
1565 may want to make all Command buttons blue), use an asterisk (*)
1566 instead of a period.  When an asterisk is used, any number of widgets
1567 (including zero) may exist between the two widget names. For example:
1568 <variablelist>
1569   <varlistentry>
1570     <term>
1571       Xman*Command
1572     </term>
1573     <listitem>
1574       <para>
1575 This matches all Command widgets in the Xman application.
1576       </para>
1577     </listitem>
1578   </varlistentry>
1579   <varlistentry>
1580     <term>
1581       Foo*button1
1582     </term>
1583     <listitem>
1584       <para>
1585 This matches any widget in the Foo application that is named <emphasis remap='I'>button1</emphasis>.
1586     </para>
1587   </listitem>
1588   </varlistentry>
1589 </variablelist>
1590 </para>
1591 <para>
1592 <!-- .LP -->
1593 The root of all application widget trees is the widget returned by
1594 <function>XtAppInitialize</function>.  Even though this is actually an
1595 ApplicationShell widget, the toolkit replaces its widget class with the
1596 class name of the application.  The name of this widget is either
1597 the name used to invoke the application (<function>argv[0]</function>) or the name of
1598 the application specified using the standard <emphasis remap='I'>-name</emphasis> command line
1599 option supported by the Intrinsics.
1600 </para>
1601 <para>
1602 <!-- .LP -->
1603 The last step in constructing the resource name is to append the name of
1604 the resource with either a period or asterisk to the full or partial
1605 widget name already constructed.
1606 <variablelist>
1607   <varlistentry>
1608     <term>
1609       *foreground:Blue
1610     </term>
1611     <listitem>
1612       <para>
1613 Specifies that all widgets in all applications will have a foreground
1614 color of blue.
1615       </para>
1616     </listitem>
1617   </varlistentry>
1618   <varlistentry>
1619     <term>
1620       Xman*borderWidth:10
1621     </term>
1622     <listitem>
1623       <para>
1624 Specifies that all widgets in an application whose class is Xman will
1625 have a border width of 10 (pixels).
1626       </para>
1627     </listitem>
1628   </varlistentry>
1629   <varlistentry>
1630     <term>
1631       xman.form.button1.label:Testing
1632     </term>
1633     <listitem>
1634       <para>
1635 Specifies that a particular widget in the xman application will have a
1636 label named <emphasis remap='I'>Testing</emphasis>.
1637     </para>
1638   </listitem>
1639   </varlistentry>
1640 </variablelist>
1641 </para>
1642 <para>
1643 <!-- .LP -->
1644 An exclamation point (!) in the first column of a line indicates
1645 that the rest of the line should be treated as a comment.
1646 </para>
1647 <para>
1648 <!-- .LP -->
1649 <function>Final Words</function>
1650 </para>
1651 <para>
1652 <!-- .LP -->
1653 The Resource manager is a powerful tool that can be used very
1654 effectively to customize X Toolkit applications at run time by either the
1655 application programmer or the user.  Some final points to note:
1656 </para>
1657 <itemizedlist>
1658   <listitem>
1659     <para>
1660 An application programmer may add new resources to their
1661 application.  These resources are associated with the global
1662 application, and not any particular widget.  The X Toolkit function used for
1663 adding the application resources is <function>XtGetApplicationResources</function>.
1664 <!-- .IN "XtGetApplicationResources" -->
1665     </para>
1666   </listitem>
1667   <listitem>
1668     <para>
1669 Be careful when creating resource files.  Since widgets will
1670 ignore resources that they do not understand, any spelling
1671 errors will cause a resource to have no effect.
1672     </para>
1673   </listitem>
1674   <listitem>
1675     <para>
1676 Only one resource line will match any given resource.  There is a set
1677 of precedence rules, which take the following general stance.
1678 <!-- .ta 10n -->
1679     </para>
1680   </listitem>
1681   <listitem>
1682     <itemizedlist>
1683       <listitem>
1684         <para>
1685 More specific overrides less specific, thus period always overrides asterisk.
1686         </para>
1687       </listitem>
1688       <listitem>
1689         <para>
1690 Names on the left are more specific and override names on the right.
1691         </para>
1692       </listitem>
1693       <listitem>
1694         <para>
1695 When resource specifications are exactly the same, user defaults
1696 will override program defaults.
1697         </para>
1698       </listitem>
1699     </itemizedlist>
1700   </listitem>
1701 </itemizedlist>
1702 <para>
1703 <!-- .LP -->
1704 For a complete explanation of the rules of precedence, and
1705 other specific topics see <emphasis remap='I'>X Toolkit Intrinsics - C Language Interface</emphasis> and <emphasis remap='I'>Xlib - C Language Interface</emphasis>.
1706 </para>
1707 </sect4>
1708 <sect4 id="Creating_Argument_Lists">
1709 <title>Creating Argument Lists</title>
1710 <!-- .IN "argument lists" "" "@DEF@" -->
1711 <para>
1712 <!-- .LP -->
1713 To set up an argument list for the inline specification of widget attributes,
1714 you may use any of the four approaches discussed in this section.
1715 Each resource name has a global symbol associated with it.  This
1716 global symbol has the form XtN<emphasis remap='I'>resource name</emphasis>.  For example, the
1717 symbol for ``foreground'' is <function>XtNforeground</function>. For further information,
1718 see the <emphasis remap='I'>X Toolkit Intrinsics - C Language Interface</emphasis>.
1719 </para>
1720 <para>
1721 <!-- .LP -->
1722 Argument are specified by using the following structure:
1723 <!-- .IN "ArgList" "" "@DEF@" -->
1724 <!-- .IN "Arg" "" "@DEF@" -->
1725 </para>
1726 <para>
1727 <!-- .LP -->
1728 <literallayout class="monospaced">
1729 <!-- .TA .5i 1.5i -->
1730 <!-- .ta .5i 1.5i -->
1731 typedef struct {
1732         String name;
1733         XtArgVal value;
1734 } Arg, *ArgList;
1735 </literallayout>
1736 </para>
1737 <para>
1738 <!-- .LP -->
1739 The first approach is to statically initialize the argument list.
1740 For example:
1741 </para>
1742 <para>
1743 <!-- .LP -->
1744 <literallayout class="monospaced">
1745 <!-- .TA .5i -->
1746 <!-- .ta .5i -->
1747 static Arg arglist[] = {
1748         {XtNwidth, (XtArgVal) 400},
1749         {XtNheight, (XtArgVal) 300},
1750 };
1751 </literallayout>
1752 </para>
1753 <para>
1754 <!-- .LP -->
1755 This approach is convenient for lists that do not need to be computed
1756 at runtime and makes adding or deleting new elements easy.
1757 The
1758 <!-- .IN "XtNumber" -->
1759 <function>XtNumber</function>
1760 macro is used to compute the number of elements in the argument list,
1761 preventing simple programming errors:
1762 </para>
1763 <para>
1764 <!-- .LP -->
1765 <literallayout class="monospaced">
1766 XtCreateWidget(<emphasis remap='I'>name</emphasis>, <emphasis remap='I'>class</emphasis>, <emphasis remap='I'>parent</emphasis>, <emphasis remap='I'>arglist</emphasis>, XtNumber(<emphasis remap='I'>arglist</emphasis>));
1767 </literallayout>
1768 <!-- .IN "XtSetArg" "" "@DEF@" -->
1769 </para>
1770 <para>
1771 <!-- .LP -->
1772 The second approach is to use the
1773 <function>XtSetArg</function>
1774 macro.
1775 For example:
1776 </para>
1777 <para>
1778 <!-- .LP -->
1779 <literallayout class="monospaced">
1780 <!-- .TA .5i -->
1781 <!-- .ta .5i -->
1782 Arg arglist[10];
1783 XtSetArg(arglist[1], XtNwidth, 400);
1784 XtSetArg(arglist[2], XtNheight, 300);
1785 </literallayout>
1786 </para>
1787 <para>
1788 <!-- .LP -->
1789 To make it easier to insert and delete entries,
1790 you also can use a variable index:
1791 </para>
1792 <para>
1793 <!-- .LP -->
1794 <literallayout class="monospaced">
1795 <!-- .TA .5i -->
1796 <!-- .ta .5i -->
1797 Arg arglist[10];
1798 Cardinal i=0;
1799 XtSetArg(arglist[i], XtNwidth,  400);       i++;
1800 XtSetArg(arglist[i], XtNheight, 300);       i++;
1801 </literallayout>
1802 </para>
1803 <para>
1804 <!-- .LP -->
1805 The i variable can then be used as the argument list count in the widget
1806 create function.
1807 In this example,
1808 <!-- .IN "XtNumber" -->
1809 <function>XtNumber</function>
1810 would return 10, not 2, and therefore is not useful.
1811 <!-- .NT -->
1812 You should not use auto-increment or auto-decrement
1813 within the first argument to
1814 <function>XtSetArg .</function>
1815 As it is currently implemented,
1816 <function>XtSetArg</function>
1817 is a macro that dereferences the first argument twice.
1818 <!-- .NE -->
1819 </para>
1820 <para>
1821 <!-- .LP -->
1822 The third approach is to individually set the elements of the
1823 argument list array:
1824 </para>
1825 <para>
1826 <!-- .LP -->
1827 <literallayout class="monospaced">
1828 <!-- .TA .5i -->
1829 <!-- .ta .5i -->
1830 Arg arglist[10];
1831 arglist[0].name  = XtNwidth;
1832 arglist[0].value = (XtArgVal) 400;
1833 arglist[1].name  = XtNheight;
1834 arglist[1].value = (XtArgVal) 300;
1835 </literallayout>
1836 </para>
1837 <para>
1838 <!-- .LP -->
1839 Note that in this example, as in the previous example,
1840 <!-- .IN "XtNumber" -->
1841 <function>XtNumber</function>
1842 would return 10, not 2, and therefore would not be useful.
1843 </para>
1844 <para>
1845 <!-- .LP -->
1846 The fourth approach is to use a mixture of the first and third approaches:
1847 you can statically define the argument list but modify some entries at runtime.
1848 For example:
1849 </para>
1850 <para>
1851 <!-- .LP -->
1852 <literallayout class="monospaced">
1853 <!-- .TA .5i -->
1854 <!-- .ta .5i -->
1855 static Arg arglist[] = {
1856         {XtNwidth, (XtArgVal) 400},
1857         {XtNheight, (XtArgVal) NULL},
1858 };
1859 arglist[1].value = (XtArgVal) 300;
1860 </literallayout>
1861 </para>
1862 <para>
1863 <!-- .LP -->
1864 In this example,
1865 <!-- .IN "XtNumber" -->
1866 <function>XtNumber</function>
1867 can be used, as in the first approach, for easier code maintenance.
1868 </para>
1869 </sect4>
1870 </sect3>
1871 </sect2>
1872 <sect2 id="Example_Programs">
1873 <title>Example Programs</title>
1874 <!-- .XS -->
1875 <!--    Example Programs -->
1876 <!-- .XE -->
1877 <!-- .IN "examples" -->
1878 <para>
1879 <!-- .LP -->
1880 The best way to understand how to use any programming library is by
1881 trying some simple examples.  A collection of example programs that
1882 introduces each of the widgets in that Athena widget set, as well as many
1883 important toolkit programming concepts, is available in the X11R6
1884 release as distributed by the X Consortium.  It can be found in the
1885 distribution directory <function>contrib/examples/mit/Xaw</function>, but see your
1886 site administrator for the exact location of these files on your system.
1887 See the README file from that directory for a guide to the examples.
1888 </para>
1889 </sect2>
1890 </sect1>
1891 </chapter>