added g_list_insert_before().
[platform/upstream/glib.git] / docs / reference / gobject / tmpl / signals.sgml
1 <!-- ##### SECTION Title ##### -->
2 Signals
3
4 <!-- ##### SECTION Short_Description ##### -->
5 Signals provide a means for customization of object behaviour and are used
6 as general purpose notification mechanism.
7
8 <!-- ##### SECTION Long_Description ##### -->
9 <para>
10 The basic concept of the signal system is that of the <emphasis>emission</emphasis>
11 of a signal.
12 Signals are introduced per-type and are identified through strings.
13 Signals introduced for a parent type are availale in derived types as well,
14 so basically they are a per-type facility that is inherited.
15 A signal emission mainly involves invocation of a certain set of callbacks in
16 precisely defined manner. There are two main categories of such callbacks,
17 per-object
18         <footnote><para> Although signals can deal with any kind of instantiatable type,
19         i'm referring to those types as "object types" in the following, simply
20         because that is the context most users will encounter signals in.
21         </para></footnote>
22 ones and user provided ones.
23 The per-object callbacks are most often referred to as "object method
24 handler" or "default (signal) handler", while user provided callbacks are
25 usually just called "signal handler".
26 The object method handler is provided at signal creation time (this most
27 frequently happens at the end of an object class' creation), while user
28 provided handlers are frequently connected and disconnected to/from a certain
29 signal on certain object instances.
30 </para>
31 <para>
32 A signal emission consists of five stages, unless prematurely stopped:
33 <variablelist>
34   <varlistentry><term></term><listitem><para>
35         1 - Invocation of the object method handler for %G_SIGNAL_RUN_FIRST signals
36   </para></listitem></varlistentry>
37   <varlistentry><term></term><listitem><para>
38         2 - Invocation of normal user-provided signal handlers (<emphasis>after</emphasis> flag %FALSE)
39   </para></listitem></varlistentry>
40   <varlistentry><term></term><listitem><para>
41         3 - Invocation of the object method handler for %G_SIGNAL_RUN_LAST signals
42   </para></listitem></varlistentry>
43   <varlistentry><term></term><listitem><para>
44         4 - Invocation of user provided signal handlers, connected with an <emphasis>after</emphasis> flag of %TRUE
45   </para></listitem></varlistentry>
46   <varlistentry><term></term><listitem><para>
47         5 - Invocation of the object method handler for %G_SIGNAL_RUN_CLEANUP signals
48   </para></listitem></varlistentry>
49 </variablelist>
50 The user provided signal handlers are called in the order they were
51 connected in.
52 All handlers may prematurely stop a signal emission, and any number of
53 handlers may be connected, disconnected, blocked or unblocked during
54 a signal emission.
55 There are certain criteria for skipping user handlers in stages 2 and 4
56 of a signal emission.
57 First, user handlers may be <emphasis>blocked</emphasis>, blocked handlers are omitted
58 during callback invocation, to return from the "blocked" state, a
59 handler has to get unblocked exactly the same amount of times
60 it has been blocked before.
61 Second, upon emission of a %G_SIGNAL_DETAILED signal, an additional
62 "detail" argument passed in to g_signal_emit() has to match the detail
63 argument of the signal handler currently subject to invocation.
64 Specification of no detail argument for signal handlers (omission of the
65 detail part of the signal specification upon connection) serves as a
66 wildcard and matches any detail argument passed in to emission.
67 </para>
68
69 <!-- ##### SECTION See_Also ##### -->
70 <para>
71
72 </para>
73
74 <!-- ##### STRUCT GSignalInvocationHint ##### -->
75 <para>
76 The #GSignalInvocationHint structure is used to pass on additional information
77 to callbacks during a signal emission.
78 </para>
79
80 @signal_id:     The signal id of the signal invoking the callback
81 @detail:        The detail passed on for this emission
82 @run_type:      The stage the signal emission is currently in, this
83                 field will contain one of %G_SIGNAL_RUN_FIRST,
84                 %G_SIGNAL_RUN_LAST or %G_SIGNAL_RUN_CLEANUP.
85
86 <!-- ##### USER_FUNCTION GSignalAccumulator ##### -->
87 <para>
88 The signal accumulator is a special callback function that can be used
89 to collect return values of the various callbacks that are called
90 during a signal emission. The signal accumulator is specified at signal
91 creation time, if it is left NULL, no accumulation of callback return
92 values is perfomed. The return value of signal emissions is then the
93 value returned by the last callback.
94 </para>
95
96 @ihint:         Signal invokation hint, see #GSignalInvocationHint.
97 @return_accu:   Accumulator to collect callback return values in, this
98                 is the return value of the current signal emission.
99 @handler_return: 
100 @data: 
101 @Returns:       The accumulator function returns whether the signal emission
102                 should be aborted. Returning %FALSE means to abort the
103                 current emission and %TRUE is returned for continuation.
104 <!-- # Unused Parameters # -->
105 @return_value:  The return value of the most recent callback function.
106
107
108 <!-- ##### TYPEDEF GSignalCMarshaller ##### -->
109 <para>
110 This is the signature of marshaller functions, required to marshall
111 arrays of parameter values to signal emissions into C language callback
112 invocations. It is merely an alias to #GClosureMarshal since the #GClosure
113 mechanism takes over responsibility of actuall function invocation for the
114 signal system.
115 </para>
116
117
118 <!-- ##### USER_FUNCTION GSignalEmissionHook ##### -->
119 <para>
120
121 </para>
122
123 @ihint: 
124 @n_param_values: 
125 @param_values: 
126 @data: 
127 @Returns: 
128 <!-- # Unused Parameters # -->
129 @signal_id: 
130 @n_values: 
131 @values: 
132
133
134 <!-- ##### ENUM GSignalFlags ##### -->
135 <para>
136 The signal flags are used to specify a signal's behaviour, the overrall
137 signal description outlines how especially the RUN flags controll the
138 stages of a signal emission.
139 </para>
140
141 @G_SIGNAL_RUN_FIRST:   Invoke the object method handler in the first emission stage.
142 @G_SIGNAL_RUN_LAST:    Invoke the object method handler in the third emission stage.
143 @G_SIGNAL_RUN_CLEANUP: Invoke the object method handler in the last emission stage.
144 @G_SIGNAL_NO_RECURSE:  Signals being emitted for an object while currently being in
145                        emission for this very object will not be emitted recursively,
146                        but instead cause the first emission to be restarted.
147 @G_SIGNAL_DETAILED:    This signal supports "::detail" appendixes to the signal name
148                        upon hanlder connections and emissions.
149 @G_SIGNAL_ACTION:      Action signals are signals that may freely be emitted on alive
150                        objects from user code via g_signal_emit() and friends, without
151                        the need of being embedded into extra code that performs pre or
152                        post emission adjustments on the object. They can also be thought
153                        of as by third-party code generically callable obejct methods.
154 @G_SIGNAL_NO_HOOKS:    No emissions hooks are supported for this signal.
155
156 <!-- ##### ENUM GSignalMatchType ##### -->
157 <para>
158
159 </para>
160
161 @G_SIGNAL_MATCH_ID: 
162 @G_SIGNAL_MATCH_DETAIL: 
163 @G_SIGNAL_MATCH_CLOSURE: 
164 @G_SIGNAL_MATCH_FUNC: 
165 @G_SIGNAL_MATCH_DATA: 
166 @G_SIGNAL_MATCH_UNBLOCKED: 
167
168 <!-- ##### STRUCT GSignalQuery ##### -->
169 <para>
170 A structure holding in-depth information for a specific signal. It is
171 filled in by the g_signal_query() function.
172 </para>
173
174 @signal_id:     The signal id of the signal being querried, or 0 if the
175                 signal to be querried was unknown.
176 @signal_name:   The signal name.
177 @itype:         The interface/instance type that this signal can be emitted for.
178 @signal_flags:  The signal flags as passed in to g_signal_new().
179 @return_type:   The return type for user callbacks.
180 @n_params:      The number of parameters that user callbacks take.
181 @param_types:   The individual parameter types for user callbacks, note that the
182                 effective callback signature is:
183 <msgtext><programlisting>
184 @return_type callback (#gpointer     data1,
185                       [#param_types param_names,]
186                        #gpointer     data2);
187 </programlisting></msgtext>
188
189 <!-- ##### MACRO G_SIGNAL_TYPE_STATIC_SCOPE ##### -->
190 <para>
191
192 </para>
193
194
195
196 <!-- ##### MACRO G_SIGNAL_MATCH_MASK ##### -->
197 <para>
198
199 </para>
200
201
202
203 <!-- ##### MACRO G_SIGNAL_FLAGS_MASK ##### -->
204 <para>
205
206 </para>
207
208
209
210 <!-- ##### FUNCTION g_signal_newv ##### -->
211 <para>
212
213 </para>
214
215 @signal_name: 
216 @itype: 
217 @signal_flags: 
218 @class_closure: 
219 @accumulator: 
220 @accu_data: 
221 @c_marshaller: 
222 @return_type: 
223 @n_params: 
224 @param_types: 
225 @Returns: 
226
227
228 <!-- ##### FUNCTION g_signal_new_valist ##### -->
229 <para>
230
231 </para>
232
233 @signal_name: 
234 @itype: 
235 @signal_flags: 
236 @class_closure: 
237 @accumulator: 
238 @accu_data: 
239 @c_marshaller: 
240 @return_type: 
241 @n_params: 
242 @args: 
243 @Returns: 
244
245
246 <!-- ##### FUNCTION g_signal_query ##### -->
247 <para>
248 Query the signal system for in-depth information about a
249 specific signal. This function will fill in a user-provided
250 structure to hold signal-specific information. If an invalid
251 dignal id is passed in, the @signal_id member of the #GSignalQuery
252 is 0. All members filled into the #GSignalQuery structure should
253 be considered constant and have to be left untouched.
254 </para>
255
256 @signal_id:     The signal id of the signal to query information for.
257 @query:         A user provided structure that is filled in with constant
258                 values upon success.
259
260
261 <!-- ##### FUNCTION g_signal_lookup ##### -->
262 <para>
263
264 </para>
265
266 @name: 
267 @itype: 
268 @Returns: 
269
270
271 <!-- ##### FUNCTION g_signal_name ##### -->
272 <para>
273
274 </para>
275
276 @signal_id: 
277 @Returns: 
278
279
280 <!-- ##### FUNCTION g_signal_list_ids ##### -->
281 <para>
282 List the signals by id, that a certain instance or interface type
283 created. Further information about the signals can be aquired through
284 g_signal_query().
285 </para>
286
287 @itype:         Instance or interface type.
288 @n_ids:         Location to store the number of signal ids for @itype.
289 @Returns:       Newly allocated array of signal IDs.
290
291
292 <!-- ##### FUNCTION g_signal_emit ##### -->
293 <para>
294
295 </para>
296
297 @instance: 
298 @signal_id: 
299 @detail: 
300 @Varargs: 
301
302
303 <!-- ##### FUNCTION g_signal_emit_by_name ##### -->
304 <para>
305
306 </para>
307
308 @instance: 
309 @detailed_signal: 
310 @Varargs: 
311
312
313 <!-- ##### FUNCTION g_signal_emitv ##### -->
314 <para>
315
316 </para>
317
318 @instance_and_params: 
319 @signal_id: 
320 @detail: 
321 @return_value: 
322
323
324 <!-- ##### FUNCTION g_signal_emit_valist ##### -->
325 <para>
326
327 </para>
328
329 @instance: 
330 @signal_id: 
331 @detail: 
332 @var_args: 
333
334
335 <!-- ##### FUNCTION g_signal_connect_data ##### -->
336 <para>
337
338 </para>
339
340 @instance: 
341 @detailed_signal: 
342 @c_handler: 
343 @data: 
344 @destroy_data: 
345 @connect_flags: 
346 @Returns: 
347 <!-- # Unused Parameters # -->
348 @swapped: 
349 @after: 
350
351
352 <!-- ##### FUNCTION g_signal_connect_object ##### -->
353 <para>
354
355 </para>
356
357 @instance: 
358 @detailed_signal: 
359 @c_handler: 
360 @gobject: 
361 @connect_flags: 
362 @Returns: 
363 <!-- # Unused Parameters # -->
364 @swapped: 
365 @after: 
366
367
368 <!-- ##### FUNCTION g_signal_connect_closure ##### -->
369 <para>
370
371 </para>
372
373 @instance: 
374 @detailed_signal: 
375 @closure: 
376 @after: 
377 @Returns: 
378 <!-- # Unused Parameters # -->
379 @signal_id: 
380 @detail: 
381
382
383 <!-- ##### FUNCTION g_signal_connect_closure_by_id ##### -->
384 <para>
385
386 </para>
387
388 @instance: 
389 @signal_id: 
390 @detail: 
391 @closure: 
392 @after: 
393 @Returns: 
394
395
396 <!-- ##### FUNCTION g_signal_handler_block ##### -->
397 <para>
398 g_signal_handler_block() blocks a handler of an
399 instance so it will not be called during any signal emissions
400 unless it is unblocked again. Thus "blocking" a signal handler
401 means to temporarily deactive it, a signal handler has to be
402 unblocked exactly the same amount of times it has been blocked
403 before to become active again.
404 The @handler_id passed into g_signal_handler_block() has
405 to be a valid signal handler id, connected to a signal of
406 @instance.
407 </para>
408
409 @instance:      The instance to block the signal handler of.
410 @handler_id:    Handler id of the handler to be blocked.
411
412
413 <!-- ##### FUNCTION g_signal_handler_unblock ##### -->
414 <para>
415 g_signal_handler_unblock() undoes the effect of a previous
416 g_signal_handler_block() call. A blocked handler is skipped
417 during signal emissions and will not be invoked, unblocking
418 it (for exactly the amount of times it has been blocked before)
419 reverts its "blocked" state, so the handler will be recognized
420 by the signal system and is called upon future or currently
421 ongoing signal emissions (since the order in which handlers are
422 called during signal emissions is deterministic, whether the
423 unblocked handler in question is called as part of a currently
424 ongoing emission depends on how far that emission has proceeded
425 yet).
426 The @handler_id passed into g_signal_handler_unblock() has
427 to be a valid id of a signal handler that is connected to a
428 signal of @instance and is currently blocked.
429 </para>
430
431 @instance:      The instance to unblock the signal handler of.
432 @handler_id:    Handler id of the handler to be unblocked.
433
434
435 <!-- ##### FUNCTION g_signal_handler_disconnect ##### -->
436 <para>
437 g_signal_handler_disconnect() disconnects a handler from an
438 instance so it will not be called during any future or currently
439 ongoing emissions of the signal it has been connected to.
440 The @handler_id becomes invalid and may be reused.
441 The @handler_id passed into g_signal_handler_disconnect() has
442 to be a valid signal handler id, connected to a signal of
443 @instance.
444 </para>
445
446 @instance:      The instance to remove the signal handler from.
447 @handler_id:    Handler id of the handler to be disconnected.
448
449
450 <!-- ##### FUNCTION g_signal_handler_find ##### -->
451 <para>
452 Find the first signal handler that matches certain selection criteria.
453 The criteria mask is passed as an OR-ed combination of #GSignalMatchType
454 flags, and the criteria values are passed as arguments.
455 The match @mask has to be non-0 for successfull matches.
456 If no handler was found, 0 is returned.
457 </para>
458
459 @instance:      The instance owning the signal handler to be found.
460 @mask:          Mask indicating which of @signal_id, @detail,
461                 @closure, @func and/or @data the handler has to match.
462 @signal_id:     Signal the handler has to be connected to.
463 @detail:        Signal detail the handler has to be connected to.
464 @closure:       The closure the handler will invoke.
465 @func:          The C closure callback of the handler (useless for non-C closures).
466 @data:          The closure data of the handler's closure.
467 @Returns:       A valid non-0 signal handler id for a successfull match.
468
469
470 <!-- ##### FUNCTION g_signal_handlers_block_matched ##### -->
471 <para>
472 This function blocks all handlers on an instance that match a certain
473 selection criteria. The criteria mask is passed as an OR-ed combination of
474 #GSignalMatchType flags, and the criteria values are passed as arguments.
475 Passing at least one of the %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC
476 or %G_SIGNAL_MATCH_DATA match flags is required for successfull matches.
477 If no handlers were found, 0 is returned, the number of blocked handlers
478 otherwise.
479 </para>
480
481 @instance:      The instance to block handlers from.
482 @mask:          Mask indicating which of @signal_id, @detail,
483                 @closure, @func and/or @data the handlers have to match.
484 @signal_id:     Signal the handlers have to be connected to.
485 @detail:        Signal detail the handlers have to be connected to.
486 @closure:       The closure the handlers will invoke.
487 @func:          The C closure callback of the handlers (useless for non-C closures).
488 @data:          The closure data of the handlers' closures.
489 @Returns:       The amount of handlers that got blocked.
490
491
492 <!-- ##### FUNCTION g_signal_handlers_unblock_matched ##### -->
493 <para>
494 This function unblocks all handlers on an instance that match a certain
495 selection criteria. The criteria mask is passed as an OR-ed combination of
496 #GSignalMatchType flags, and the criteria values are passed as arguments.
497 Passing at least one of the %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC
498 or %G_SIGNAL_MATCH_DATA match flags is required for successfull matches.
499 If no handlers were found, 0 is returned, the number of unblocked handlers
500 otherwise. The match criteria should not apply to any handlers that are
501 not currently blocked.
502 </para>
503
504 @instance:      The instance to unblock handlers from.
505 @mask:          Mask indicating which of @signal_id, @detail,
506                 @closure, @func and/or @data the handlers have to match.
507 @signal_id:     Signal the handlers have to be connected to.
508 @detail:        Signal detail the handlers have to be connected to.
509 @closure:       The closure the handlers will invoke.
510 @func:          The C closure callback of the handlers (useless for non-C closures).
511 @data:          The closure data of the handlers' closures.
512 @Returns:       The amount of handlers that got unblocked.
513
514
515 <!-- ##### FUNCTION g_signal_handlers_disconnect_matched ##### -->
516 <para>
517 This function disconnects all handlers on an instance that match a certain
518 selection criteria. The criteria mask is passed as an OR-ed combination of
519 #GSignalMatchType flags, and the criteria values are passed as arguments.
520 Passing at least one of the %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC
521 or %G_SIGNAL_MATCH_DATA match flags is required for successfull matches.
522 If no handlers were found, 0 is returned, the number of disconnected handlers
523 otherwise.
524 </para>
525
526 @instance:      The instance to remove handlers from.
527 @mask:          Mask indicating which of @signal_id, @detail,
528                 @closure, @func and/or @data the handlers have to match.
529 @signal_id:     Signal the handlers have to be connected to.
530 @detail:        Signal detail the handlers have to be connected to.
531 @closure:       The closure the handlers will invoke.
532 @func:          The C closure callback of the handlers (useless for non-C closures).
533 @data:          The closure data of the handlers' closures.
534 @Returns:       The amount of handlers that got disconnected.
535
536
537 <!-- ##### FUNCTION g_signal_has_handler_pending ##### -->
538 <para>
539
540 </para>
541
542 @instance: 
543 @signal_id: 
544 @detail: 
545 @may_be_blocked: 
546 @Returns: 
547
548
549 <!-- ##### FUNCTION g_signal_stop_emission ##### -->
550 <para>
551
552 </para>
553
554 @instance: 
555 @signal_id: 
556 @detail: 
557
558
559 <!-- ##### FUNCTION g_signal_remove_emission_hook ##### -->
560 <para>
561
562 </para>
563
564 @signal_id: 
565 @hook_id: 
566
567
568 <!-- ##### FUNCTION g_signal_parse_name ##### -->
569 <para>
570 Internal function to parse a signal names into its @signal_id
571 and @detail quark.
572 </para>
573
574 @detailed_signal:       A string of the form "signal-name::detail".
575 @itype:                 The interface/instance type that introduced "signal-name".
576 @signal_id_p:           Location to store the signal id.
577 @detail_p:              Location to stroe the detail quark.
578 @force_detail_quark:    %TRUE forces creation of a GQuark for the detail.
579 @Returns:               Whether the signal name could successfully be parsed and
580                         @signal_id_p and @detail_p contain valid return values.
581
582
583 <!-- ##### FUNCTION g_signal_handlers_destroy ##### -->
584 <para>
585
586 </para>
587
588 @instance: 
589
590
591 <!-- ##### FUNCTION g_signal_type_cclosure_new ##### -->
592 <para>
593
594 </para>
595
596 @itype: 
597 @struct_offset: 
598 @Returns: 
599
600