1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
|
<chapter id='Callbacks'>
<title>Callbacks</title>
<para>
Applications and other widgets often need to register a procedure
with a widget that gets called under certain prespecified conditions.
For example,
when a widget is destroyed,
every procedure on the widget's <emphasis remap='I'>destroy_callbacks</emphasis>
list is called to notify clients of the widget's impending doom.
</para>
<para>
Every widget has an XtNdestroyCallbacks callback list resource.
Widgets can define additional callback lists as they see fit.
For example, the Pushbutton widget has a callback
list to notify clients when the button has been activated.
</para>
<para>
Except where otherwise noted, it is the intent that all Intrinsics
functions may be called at any time, including from within callback
procedures, action routines, and event handlers.
</para>
<sect1 id="Using_Callback_Procedure_and_Callback_List_Definitions">
<title>Using Callback Procedure and Callback List Definitions</title>
<para>
Callback procedure pointers for use in callback lists are of type
<xref linkend='XtCallbackProc' xrefstyle='select: title'/>.
</para>
<funcsynopsis id='XtCallbackProc'>
<funcprototype>
<funcdef>typedef void <function>(*XtCallbackProc)</function></funcdef>
<paramdef>Widget <parameter>w</parameter></paramdef>
<paramdef>XtPointer <parameter>client_data</parameter></paramdef>
<paramdef>XtPointer <parameter>call_data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<variablelist>
<varlistentry>
<term>
<emphasis remap='I'>w</emphasis>
</term>
<listitem>
<para>
Specifies the widget owning the list in which the callback is registered.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis remap='I'>client_data</emphasis>
</term>
<listitem>
<para>
Specifies additional data supplied by the client when the procedure
was registered.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis remap='I'>call_data</emphasis>
</term>
<listitem>
<para>
Specifies any callback-specific data the widget wants to pass to the client.
For example, when Scrollbar executes its XtNthumbChanged callback list,
it passes the new position of the thumb.
</para>
</listitem>
</varlistentry>
</variablelist>
<para>
The <emphasis remap='I'>client_data</emphasis> argument provides a way for the
client registering the callback procedure also to register client-specific data,
for example, a pointer to additional information about the widget,
a reason for invoking the callback, and so on.
The <emphasis remap='I'>client_data</emphasis> value may be NULL
if all necessary information is in the widget.
The <emphasis remap='I'>call_data</emphasis> argument is a convenience to avoid having simple
cases where the client could otherwise always call
<xref linkend='XtGetValues' xrefstyle='select: title'/>
or a widget-specific function to retrieve data from the widget.
Widgets should generally avoid putting complex state information
in <emphasis remap='I'>call_data</emphasis>.
The client can use the more general data retrieval methods, if necessary.
</para>
<para>
Whenever a client wants to pass a callback list as an argument in an
<xref linkend='XtCreateWidget' xrefstyle='select: title'/>,
<xref linkend='XtSetValues' xrefstyle='select: title'/>,
or
<xref linkend='XtGetValues' xrefstyle='select: title'/>
call, it should specify the address
of a NULL-terminated array of type
<function>XtCallbackList</function>.
</para>
<literallayout >
typedef struct {
XtCallbackProc callback;
XtPointer closure;
} XtCallbackRec, *XtCallbackList;
</literallayout>
<para>
For example, the callback list for procedures A and B with client data
clientDataA and clientDataB, respectively, is
</para>
<literallayout >
static XtCallbackRec callbacks[] = {
{A, (XtPointer) clientDataA},
{B, (XtPointer) clientDataB},
{(XtCallbackProc) NULL, (XtPointer) NULL}
};
</literallayout>
<para>
Although callback lists are passed by address in arglists
and varargs lists,
the Intrinsics recognize callback lists
through the widget resource list and will copy the contents
when necessary.
Widget initialize and set_values procedures
should not allocate memory for the callback list contents.
The Intrinsics automatically do this,
potentially using a different structure for their
internal representation.
</para>
</sect1>
<sect1 id="Identifying_Callback_Lists">
<title>Identifying Callback Lists</title>
<para>
Whenever a widget contains a callback list for use by clients,
it also exports in its public .h file the resource name of the callback list.
Applications and client widgets never access callback list fields directly.
Instead, they always identify the desired callback list by using the exported
resource name.
All the callback manipulation functions described in this chapter
except
<xref linkend='XtCallCallbackList' xrefstyle='select: title'/>
check
to see that the requested callback list is indeed implemented by the widget.
</para>
<para>
For the Intrinsics to find and correctly handle callback lists,
they must be declared with a resource type of
<function>XtRCallback</function>.
The internal representation of a callback list is
implementation-dependent; widgets may make no assumptions about the
value stored in this resource if it is non-NULL. Except to compare
the value to NULL (which is equivalent to
<function>XtCallbackStatus</function>
<function>XtCallbackHasNone ),</function>
access to callback list resources must be made
through other Intrinsics procedures.
</para>
</sect1>
<sect1 id="Adding_Callback_Procedures">
<title>Adding Callback Procedures</title>
<para>
To add a callback procedure to a widget's callback list, use
<xref linkend='XtAddCallback' xrefstyle='select: title'/>.
</para>
<funcsynopsis id='XtAddCallback'>
<funcprototype>
<funcdef>void <function>XtAddCallback</function></funcdef>
<paramdef>Widget <parameter>w</parameter></paramdef>
<paramdef>String <parameter>callback_name</parameter></paramdef>
<paramdef>XtCallbackProc <parameter>callback</parameter></paramdef>
<paramdef>XtPointer <parameter>client_data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<variablelist>
<varlistentry>
<term>
<emphasis remap='I'>w</emphasis>
</term>
<listitem>
<para>
Specifies the widget. Must be of class Object or any subclass thereof.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis remap='I'>callback_name</emphasis>
</term>
<listitem>
<para>
Specifies the callback list to which the procedure is to be appended.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis remap='I'>callback</emphasis>
</term>
<listitem>
<para>
Specifies the callback procedure.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis remap='I'>client_data</emphasis>
</term>
<listitem>
<para>
Specifies additional data to be passed to the specified procedure
when it is invoked,
or NULL.
</para>
</listitem>
</varlistentry>
</variablelist>
<para>
A callback will be invoked as many times as it occurs in the callback list.
</para>
<para>
To add a list of callback procedures to a given widget's callback list, use
<xref linkend='XtAddCallbacks' xrefstyle='select: title'/>.
</para>
<funcsynopsis id='XtAddCallbacks'>
<funcprototype>
<funcdef>void <function>XtAddCallbacks</function></funcdef>
<paramdef>Widget <parameter>w</parameter></paramdef>
<paramdef>String <parameter>callback_name</parameter></paramdef>
<paramdef>XtCallbackList <parameter>callbacks</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<variablelist>
<varlistentry>
<term>
<emphasis remap='I'>w</emphasis>
</term>
<listitem>
<para>
Specifies the widget. Must be of class Object or any subclass thereof.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis remap='I'>callback_name</emphasis>
</term>
<listitem>
<para>
Specifies the callback list to which the procedures are to be appended.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis remap='I'>callbacks</emphasis>
</term>
<listitem>
<para>
Specifies the null-terminated list of callback procedures and corresponding
client data.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect1>
<sect1 id="Removing_Callback_Procedures">
<title>Removing Callback Procedures</title>
<para>
To delete a callback procedure from a widget's callback list, use
<xref linkend='XtRemoveCallback' xrefstyle='select: title'/>.
</para>
<funcsynopsis id='XtRemoveCallback'>
<funcprototype>
<funcdef>void <function>XtRemoveCallback</function></funcdef>
<paramdef>Widget <parameter>w</parameter></paramdef>
<paramdef>String <parameter>callback_name</parameter></paramdef>
<paramdef>XtCallbackProc <parameter>callback</parameter></paramdef>
<paramdef>XtPointer <parameter>client_data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<variablelist>
<varlistentry>
<term>
<emphasis remap='I'>w</emphasis>
</term>
<listitem>
<para>
Specifies the widget. Must be of class Object or any subclass thereof.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis remap='I'>callback_name</emphasis>
</term>
<listitem>
<para>
Specifies the callback list from which the procedure is to be deleted.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis remap='I'>callback</emphasis>
</term>
<listitem>
<para>
Specifies the callback procedure.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis remap='I'>client_data</emphasis>
</term>
<listitem>
<para>
Specifies the client data to match with the registered callback entry.
</para>
</listitem>
</varlistentry>
</variablelist>
<para>
The
<xref linkend='XtRemoveCallback' xrefstyle='select: title'/>
function removes a callback only if both the procedure and the client
data match.
</para>
<para>
To delete a list of callback procedures from a given widget's callback list, use
<xref linkend='XtRemoveCallbacks' xrefstyle='select: title'/>.
</para>
<funcsynopsis id='XtRemoveCallbacks'>
<funcprototype>
<funcdef>void <function>XtRemoveCallbacks</function></funcdef>
<paramdef>Widget <parameter>w</parameter></paramdef>
<paramdef>String <parameter>callback_name</parameter></paramdef>
<paramdef>XtCallbackList <parameter>callbacks</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<variablelist>
<varlistentry>
<term>
<emphasis remap='I'>w</emphasis>
</term>
<listitem>
<para>
Specifies the widget. Must be of class Object or any subclass thereof.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis remap='I'>callback_name</emphasis>
</term>
<listitem>
<para>
Specifies the callback list from which the procedures are to be deleted.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis remap='I'>callbacks</emphasis>
</term>
<listitem>
<para>
Specifies the null-terminated list of callback procedures and corresponding
client data.
</para>
</listitem>
</varlistentry>
</variablelist>
<para>
To delete all callback procedures from a given widget's callback list
and free all storage associated with the callback list, use
<xref linkend='XtRemoveAllCallbacks' xrefstyle='select: title'/>.
</para>
<funcsynopsis id='XtRemoveAllCallbacks'>
<funcprototype>
<funcdef>void <function>XtRemoveAllCallbacks</function></funcdef>
<paramdef>Widget <parameter>w</parameter></paramdef>
<paramdef>String <parameter>callback_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<variablelist>
<varlistentry>
<term>
<emphasis remap='I'>w</emphasis>
</term>
<listitem>
<para>
Specifies the widget. Must be of class Object or any subclass thereof.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis remap='I'>callback_name</emphasis>
</term>
<listitem>
<para>
Specifies the callback list to be cleared.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect1>
<sect1 id="Executing_Callback_Procedures">
<title>Executing Callback Procedures</title>
<para>
To execute the procedures in a given widget's callback list,
specifying the callback list by resource name, use
<xref linkend='XtCallCallbacks' xrefstyle='select: title'/>.
</para>
<funcsynopsis id='XtCallCallbacks'>
<funcprototype>
<funcdef>void <function>XtCallCallbacks</function></funcdef>
<paramdef>Widget <parameter>w</parameter></paramdef>
<paramdef>String <parameter>callback_name</parameter></paramdef>
<paramdef>XtPointer <parameter>call_data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<variablelist>
<varlistentry>
<term>
<emphasis remap='I'>w</emphasis>
</term>
<listitem>
<para>
Specifies the widget. Must be of class Object or any subclass thereof.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis remap='I'>callback_name</emphasis>
</term>
<listitem>
<para>
Specifies the callback list to be executed.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis remap='I'>call_data</emphasis>
</term>
<listitem>
<para>
Specifies a callback-list-specific data value to pass to each of the callback
procedure in the list, or NULL.
</para>
</listitem>
</varlistentry>
</variablelist>
<para>
<xref linkend='XtCallCallbacks' xrefstyle='select: title'/>
calls each of the callback procedures in the list
named by <emphasis remap='I'>callback_name</emphasis> in the specified widget, passing the client
data registered with the procedure and <emphasis remap='I'>call-data</emphasis>.
</para>
<para>
To execute the procedures in a callback list, specifying the callback
list by address, use
<xref linkend='XtCallCallbackList' xrefstyle='select: title'/>.
</para>
<funcsynopsis id='XtCallCallbackList'>
<funcprototype>
<funcdef>void <function>XtCallCallbackList</function></funcdef>
<paramdef>Widget <parameter>widget</parameter></paramdef>
<paramdef>XtCallbackList <parameter>callbacks</parameter></paramdef>
<paramdef>XtPointer <parameter>call_data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<variablelist>
<varlistentry>
<term>
<emphasis remap='I'>widget</emphasis>
</term>
<listitem>
<para>
Specifies the widget instance that contains the callback list. Must be of class Object or any subclass thereof.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis remap='I'>callbacks</emphasis>
</term>
<listitem>
<para>
Specifies the callback list to be executed.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis remap='I'>call_data</emphasis>
</term>
<listitem>
<para>
Specifies a callback-list-specific data value to pass
to each of the callback procedures in the list, or NULL.
</para>
</listitem>
</varlistentry>
</variablelist>
<para>
The <emphasis remap='I'>callbacks</emphasis> parameter must specify the contents of a widget or
object resource declared with representation type
<function>XtRCallback</function>.
If <emphasis remap='I'>callbacks</emphasis> is NULL,
<xref linkend='XtCallCallbackList' xrefstyle='select: title'/>
returns immediately; otherwise it calls each of the callback
procedures in the list, passing the client data and <emphasis remap='I'>call_data</emphasis>.
</para>
</sect1>
<sect1 id="Checking_the_Status_of_a_Callback_List">
<title>Checking the Status of a Callback List</title>
<para>
To find out the status of a given widget's callback list, use
<xref linkend='XtHasCallbacks' xrefstyle='select: title'/>.
</para>
<para>
typedef enum {XtCallbackNoList, XtCallbackHasNone, XtCallbackHasSome} XtCallbackStatus;
</para>
<funcsynopsis id='XtHasCallbacks'>
<funcprototype>
<funcdef>XtCallbackStatus <function>XtHasCallbacks</function></funcdef>
<paramdef>Widget <parameter>w</parameter></paramdef>
<paramdef>String <parameter>callback_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<variablelist>
<varlistentry>
<term>
<emphasis remap='I'>w</emphasis>
</term>
<listitem>
<para>
Specifies the widget. Must be of class Object or any subclass thereof.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis remap='I'>callback_name</emphasis>
</term>
<listitem>
<para>
Specifies the callback list to be checked.
</para>
</listitem>
</varlistentry>
</variablelist>
<para>
The
<xref linkend='XtHasCallbacks' xrefstyle='select: title'/>
function first checks to see if the widget has a callback list identified
by <emphasis remap='I'>callback_name</emphasis>.
If the callback list does not exist,
<xref linkend='XtHasCallbacks' xrefstyle='select: title'/>
returns
<function>XtCallbackNoList</function>.
If the callback list exists but is empty,
it returns
<function>XtCallbackHasNone</function>.
If the callback list exists and has at least one callback registered,
it returns
<function>XtCallbackHasSome</function>.
</para>
</sect1>
</chapter>
|