aboutsummaryrefslogtreecommitdiff
path: root/libXt/specs/CH08
blob: 6dfb5290bb9b98ba47b834168c892eff29b8c172 (plain)
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
.\" $Xorg: CH08,v 1.3 2000/08/17 19:42:46 cpqbld Exp $
.\" Copyright \(co 1985, 1986, 1987, 1988, 1991, 1994
.\" X Consortium
.\" 
.\" Permission is hereby granted, free of charge, to any person obtaining
.\" a copy of this software and associated documentation files (the
.\" "Software"), to deal in the Software without restriction, including
.\" without limitation the rights to use, copy, modify, merge, publish,
.\" distribute, sublicense, and/or sell copies of the Software, and to
.\" permit persons to whom the Software is furnished to do so, subject to
.\" the following conditions:
.\" 
.\" The above copyright notice and this permission notice shall be included
.\" in all copies or substantial portions of the Software.
.\" 
.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
.\" IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
.\" OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
.\" ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
.\" OTHER DEALINGS IN THE SOFTWARE.
.\" 
.\" Except as contained in this notice, the name of the X Consortium shall
.\" not be used in advertising or otherwise to promote the sale, use or
.\" other dealings in this Software without prior written authorization
.\" from the X Consortium.
.\" 
.\" Copyright \(co 1985, 1986, 1987, 1988, 1991, 1994
.\" Digital Equipment Corporation, Maynard, Massachusetts.
.\" 
.\" Permission to use, copy, modify and distribute this documentation for any
.\" purpose and without fee is hereby granted, provided that the above copyright
.\" notice appears in all copies and that both that copyright notice and this
.\" permission notice appear in supporting documentation, and that the name of
.\" Digital not be used in in advertising or publicity pertaining
.\" to distribution of the software without specific, written prior permission.
.\" Digital makes no representations about the suitability of the
.\" software described herein for any purpose.
.\" It is provided ``as is'' without express or implied warranty.
.\"
\&
.sp 1
.ce 3
\s+1\fBChapter 8\fP\s-1

\s+1\fBCallbacks\fP\s-1
.sp 2
.nr H1 8
.nr H2 0
.nr H3 0
.nr H4 0
.nr H5 0
.LP
.XS
Chapter 8 \(em Callbacks
.XE
.IN "Destroy Callbacks"
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 \fIdestroy_callbacks\fP
list is called to notify clients of the widget's impending doom.
.LP
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.
.LP
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.

.NH 2
Using Callback Procedure and Callback List Definitions
.XS
\fB\*(SN Using Callback Procedure and Callback List Definitions\fP
.XE
.IN "XtCallbackList"
.IN "XtCallbackProc"
.LP
Callback procedure pointers for use in callback lists are of type
.PN XtCallbackProc .
.LP
.IN "XtCallbackProc" "" "@DEF@"
.sM
.FD 0
typedef void (*XtCallbackProc)(Widget, XtPointer, XtPointer);
.br
      Widget \fIw\fP;
.br
      XtPointer \fIclient_data\fP;
.br
      XtPointer \fIcall_data\fP;
.FN
.IP \fIw\fP 1i
Specifies the widget owning the list in which the callback is registered.
.IP \fIclient_data\fP 1i
Specifies additional data supplied by the client when the procedure
was registered.
.IP \fIcall_data\fP 1i
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.
.LP
.eM
The \fIclient_data\fP 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 \fIclient_data\fP value may be NULL
if all necessary information is in the widget.
The \fIcall_data\fP argument is a convenience to avoid having simple
cases where the client could otherwise always call
.PN XtGetValues
or a widget-specific function to retrieve data from the widget.
Widgets should generally avoid putting complex state information 
in \fIcall_data\fP.
The client can use the more general data retrieval methods, if necessary.
.LP
Whenever a client wants to pass a callback list as an argument in an
.PN XtCreateWidget ,
.PN XtSetValues ,
or
.PN XtGetValues
call, it should specify the address
of a NULL-terminated array of type
.PN XtCallbackList .
.IN "XtCallbackList" "" "@DEF@"
.IN "XtCallbackRec" "" "@DEF@"
.LP
.sM
.Ds 0
.TA .5i 3i
.ta .5i 3i
typedef struct {
	XtCallbackProc callback;
	XtPointer closure;
} XtCallbackRec, *XtCallbackList;
.De
.LP
.eM
For example, the callback list for procedures A and B with client data
clientDataA and clientDataB, respectively, is
.LP
.KS
.Ds 5
.TA .5i 3i
.ta .5i 3i
static XtCallbackRec callbacks[] = {
	{A, (XtPointer) clientDataA},
	{B, (XtPointer) clientDataB},
	{(XtCallbackProc) NULL, (XtPointer) NULL}
};
.De
.KE
.LP
Although callback lists are passed by address in arglists
and varargs lists,
the \*(xI 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 \*(xI automatically do this,
potentially using a different structure for their
internal representation.

.NH 2
Identifying Callback Lists
.XS
\fB\*(SN Identifying Callback Lists\fP
.XE
.LP
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
.PN XtCallCallbackList
check 
to see that the requested callback list is indeed implemented by the widget.
.LP
For the \*(xI to find and correctly handle callback lists,
they must be declared with a resource type of
.PN XtRCallback .
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
.PN XtCallbackStatus
.PN XtCallbackHasNone ),
access to callback list resources must be made
through other \*(xI procedures.

.NH 2
Adding Callback Procedures
.XS
\fB\*(SN Adding Callback Procedures\fP
.XE
.LP
To add a callback procedure to a widget's callback list, use
.PN XtAddCallback .
.LP
.IN "XtAddCallback" "" "@DEF@"
.sM
.FD 0
void XtAddCallback(\fIw\fP, \fIcallback_name, \fP\fIcallback\fP, \
\fIclient_data\fP)
.br
      Widget \fIw\fP;
.br
      String \fIcallback_name\fP;
.br
      XtCallbackProc \fIcallback\fP;
.br
      XtPointer \fIclient_data\fP;
.FN
.IP \fIw\fP 1i
Specifies the widget.  \*(oI
.IP \fIcallback_name\fP 1i
Specifies the callback list to which the procedure is to be appended.
.IP \fIcallback\fP 1i
Specifies the callback procedure.
.IP \fIclient_data\fP 1i
Specifies additional data to be passed to the specified procedure
when it is invoked,
or NULL.
.LP
.eM
A callback will be invoked as many times as it occurs in the callback list.
.sp
.LP
To add a list of callback procedures to a given widget's callback list, use
.PN XtAddCallbacks .
.LP
.IN "XtAddCallbacks" "" "@DEF@"
.sM
.FD 0
void XtAddCallbacks(\fIw\fP, \fIcallback_name, \fP\fIcallbacks\fP)
.br
      Widget \fIw\fP;
.br
      String \fIcallback_name\fP;
.br
      XtCallbackList \fIcallbacks\fP;
.FN
.IP \fIw\fP 1i
Specifies the widget.  \*(oI
.IP \fIcallback_name\fP 1i
Specifies the callback list to which the procedures are to be appended.
.IP \fIcallbacks\fP 1i
Specifies the null-terminated list of callback procedures and corresponding
client data.
.LP
.eM
.NH 2
Removing Callback Procedures
.XS
\fB\*(SN Removing Callback Procedures\fP
.XE
.LP
To delete a callback procedure from a widget's callback list, use
.PN XtRemoveCallback .
.LP
.IN "XtRemoveCallback" "" "@DEF@"
.sM
.FD 0
void XtRemoveCallback(\fIw\fP, \fIcallback_name\fP, \fIcallback\fP, \
\fIclient_data\fP)
.br
      Widget \fIw\fP;
.br
      String \fIcallback_name\fP;
.br
      XtCallbackProc \fIcallback\fP;
.br
      XtPointer \fIclient_data\fP;
.FN
.IP \fIw\fP 1i
Specifies the widget.  \*(oI
.IP \fIcallback_name\fP 1i
Specifies the callback list from which the procedure is to be deleted.
.IP \fIcallback\fP 1i
Specifies the callback procedure.
.IP \fIclient_data\fP 1i
Specifies the client data to match with the registered callback entry.
.LP
.eM
The
.PN XtRemoveCallback
function removes a callback only if both the procedure and the client
data match.
.sp
.LP
To delete a list of callback procedures from a given widget's callback list, use
.PN XtRemoveCallbacks .
.LP
.IN "XtRemoveCallbacks" "" "@DEF@"
.sM
.FD 0
void XtRemoveCallbacks(\fIw\fP, \fIcallback_name\fP, \fIcallbacks\fP)
.br
      Widget \fIw\fP;
.br
      String \fIcallback_name\fP;
.br
      XtCallbackList \fIcallbacks\fP;
.FN
.IP \fIw\fP 1i
Specifies the widget.  \*(oI
.IP \fIcallback_name\fP 1i
Specifies the callback list from which the procedures are to be deleted.
.IP \fIcallbacks\fP 1i
Specifies the null-terminated list of callback procedures and corresponding
client data.
.LP
.eM
To delete all callback procedures from a given widget's callback list
and free all storage associated with the callback list, use
.PN XtRemoveAllCallbacks .
.LP
.IN "XtRemoveAllCallbacks" "" "@DEF@"
.sM
.FD 0
void XtRemoveAllCallbacks(\fIw\fP, \fIcallback_name\fP)
.br
      Widget \fIw\fP;
.br
      String \fIcallback_name\fP;
.FN
.IP \fIw\fP 1i
Specifies the widget.  \*(oI
.IP \fIcallback_name\fP 1i
Specifies the callback list to be cleared.
.LP
.eM
.NH 2
Executing Callback Procedures
.XS
\*(SN Executing Callback Procedures
.XE
.LP
To execute the procedures in a given widget's callback list,
specifying the callback list by resource name, use
.PN XtCallCallbacks .
.LP
.IN "XtCallCallbacks" "" "@DEF@"
.sM
.FD 0
void XtCallCallbacks(\fIw\fP, \fIcallback_name\fP, \fIcall_data\fP)
.br
      Widget \fIw\fP;
.br
      String \fIcallback_name\fP;
.br
      XtPointer \fIcall_data\fP;
.FN
.IP \fIw\fP 1i
Specifies the widget.  \*(oI
.IP \fIcallback_name\fP 1i
Specifies the callback list to be executed.
.IP \fIcall_data\fP 1i
Specifies a callback-list-specific data value to pass to each of the callback
procedure in the list, or NULL.
.LP
.eM
.LP
.PN XtCallCallbacks
calls each of the callback procedures in the list
named by \fIcallback_name\fP in the specified widget, passing the client
data registered with the procedure and \fIcall-data\fP.
.sp
.LP
To execute the procedures in a callback list, specifying the callback
list by address, use
.PN XtCallCallbackList .
.LP
.IN "XtCallCallbackList" "" "@DEF@"
.sM
.FD 0
void XtCallCallbackList(\fIwidget\fP, \fIcallbacks\fP, \fIcall_data\fP)
.br
      Widget \fIwidget\fP;
.br
      XtCallbackList \fIcallbacks\fP;
.br
      XtPointer \fIcall_data\fP;
.FN
.IP \fIwidget\fP 1i
Specifies the widget instance that contains the callback list.  \*(oI
.IP \fIcallbacks\fP 1i
Specifies the callback list to be executed.
.IP \fIcall_data\fP 1i
Specifies a callback-list-specific data value to pass
to each of the callback procedures in the list, or NULL.
.LP
.eM
The \fIcallbacks\fP parameter must specify the contents of a widget or
object resource declared with representation type
.PN XtRCallback .
If \fIcallbacks\fP is NULL,
.PN XtCallCallbackList
returns immediately; otherwise it calls each of the callback
procedures in the list, passing the client data and \fIcall_data\fP.

.NH 2
Checking the Status of a Callback List
.XS
\*(SN Checking the Status of a Callback List
.XE
.LP
To find out the status of a given widget's callback list, use
.PN XtHasCallbacks .
.LP
.IN "XtHasCallbacks" "" "@DEF@"
.sp
.sM
.FD 0
typedef enum {XtCallbackNoList, XtCallbackHasNone, XtCallbackHasSome} \
XtCallbackStatus;
.sp
XtCallbackStatus XtHasCallbacks(\fIw\fP, \fIcallback_name\fP)
.br
      Widget \fIw\fP;
.br
      String \fIcallback_name\fP;
.FN
.IP \fIw\fP 1i
Specifies the widget.  \*(oI
.IP \fIcallback_name\fP 1i
Specifies the callback list to be checked.
.LP
.eM
The
.PN XtHasCallbacks
function first checks to see if the widget has a callback list identified 
by \fIcallback_name\fP.
If the callback list does not exist,
.PN XtHasCallbacks
returns
.PN XtCallbackNoList .
If the callback list exists but is empty,
it returns
.PN XtCallbackHasNone .
If the callback list exists and has at least one callback registered,
it returns
.PN XtCallbackHasSome .
.bp