More GSignal docs.
[platform/upstream/glib.git] / docs / reference / gobject / tmpl / signals.sgml
1 <!-- ##### SECTION Title ##### -->
2 Signals
3
4 <!-- ##### SECTION Short_Description ##### -->
5 A means for customization of object behaviour and a general purpose notification mechanism
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
9 The basic concept of the signal system is that of the <emphasis>emission</emphasis>
10 of a signal.
11 Signals are introduced per-type and are identified through strings.
12 Signals introduced for a parent type are available in derived types as well,
13 so basically they are a per-type facility that is inherited.
14 A signal emission mainly involves invocation of a certain set of callbacks in
15 precisely defined manner. There are two main categories of such callbacks,
16 per-object
17         <footnote><para>Although signals can deal with any kind of instantiatable type,
18         i'm referring to those types as "object types" in the following, simply
19         because that is the context most users will encounter signals in.
20         </para></footnote>
21 ones and user provided ones.
22 The per-object callbacks are most often referred to as "object method
23 handler" or "default (signal) handler", while user provided callbacks are
24 usually just called "signal handler".
25 The object method handler is provided at signal creation time (this most
26 frequently happens at the end of an object class' creation), while user
27 provided handlers are frequently connected and disconnected to/from a certain
28 signal on certain object instances.
29 </para>
30 <para>
31 A signal emission consists of five stages, unless prematurely stopped:
32 <variablelist>
33   <varlistentry><term></term><listitem><para>
34         1 - Invocation of the object method handler for %G_SIGNAL_RUN_FIRST signals
35   </para></listitem></varlistentry>
36   <varlistentry><term></term><listitem><para>
37         2 - Invocation of normal user-provided signal handlers (<emphasis>after</emphasis> flag %FALSE)
38   </para></listitem></varlistentry>
39   <varlistentry><term></term><listitem><para>
40         3 - Invocation of the object method handler for %G_SIGNAL_RUN_LAST signals
41   </para></listitem></varlistentry>
42   <varlistentry><term></term><listitem><para>
43         4 - Invocation of user provided signal handlers, connected with an <emphasis>after</emphasis> flag of %TRUE
44   </para></listitem></varlistentry>
45   <varlistentry><term></term><listitem><para>
46         5 - Invocation of the object method handler for %G_SIGNAL_RUN_CLEANUP signals
47   </para></listitem></varlistentry>
48 </variablelist>
49 The user provided signal handlers are called in the order they were
50 connected in.
51 All handlers may prematurely stop a signal emission, and any number of
52 handlers may be connected, disconnected, blocked or unblocked during
53 a signal emission.
54 There are certain criteria for skipping user handlers in stages 2 and 4
55 of a signal emission.
56 First, user handlers may be <emphasis>blocked</emphasis>, blocked handlers are omitted
57 during callback invocation, to return from the "blocked" state, a
58 handler has to get unblocked exactly the same amount of times
59 it has been blocked before.
60 Second, upon emission of a %G_SIGNAL_DETAILED signal, an additional
61 "detail" argument passed in to g_signal_emit() has to match the detail
62 argument of the signal handler currently subject to invocation.
63 Specification of no detail argument for signal handlers (omission of the
64 detail part of the signal specification upon connection) serves as a
65 wildcard and matches any detail argument passed in to emission.
66 </para>
67
68 <!-- ##### SECTION See_Also ##### -->
69 <para>
70
71 </para>
72
73 <!-- ##### STRUCT GSignalInvocationHint ##### -->
74 <para>
75 The #GSignalInvocationHint structure is used to pass on additional information
76 to callbacks during a signal emission.
77 </para>
78
79 @signal_id:     The signal id of the signal invoking the callback
80 @detail:        The detail passed on for this emission
81 @run_type:      The stage the signal emission is currently in, this
82                 field will contain one of %G_SIGNAL_RUN_FIRST,
83                 %G_SIGNAL_RUN_LAST or %G_SIGNAL_RUN_CLEANUP.
84
85 <!-- ##### USER_FUNCTION GSignalAccumulator ##### -->
86 <para>
87 The signal accumulator is a special callback function that can be used
88 to collect return values of the various callbacks that are called
89 during a signal emission. The signal accumulator is specified at signal
90 creation time, if it is left NULL, no accumulation of callback return
91 values is performed. The return value of signal emissions is then the
92 value returned by the last callback.
93 </para>
94
95 @ihint:         Signal invocation hint, see #GSignalInvocationHint.
96 @return_accu:   Accumulator to collect callback return values in, this
97                 is the return value of the current signal emission.
98 @handler_return: 
99 @data: 
100 @Returns:       The accumulator function returns whether the signal emission
101                 should be aborted. Returning %FALSE means to abort the
102                 current emission and %TRUE is returned for continuation.
103 <!-- # Unused Parameters # -->
104 @return_value:  The return value of the most recent callback function.
105
106
107 <!-- ##### TYPEDEF GSignalCMarshaller ##### -->
108 <para>
109 This is the signature of marshaller functions, required to marshall
110 arrays of parameter values to signal emissions into C language callback
111 invocations. It is merely an alias to #GClosureMarshal since the #GClosure
112 mechanism takes over responsibility of actual function invocation for the
113 signal system.
114 </para>
115
116
117 <!-- ##### USER_FUNCTION GSignalEmissionHook ##### -->
118 <para>
119 A simple function pointer to get invoked when the signal is emitted. This 
120 allows you tie a hook to the signal type, so that it will trap all emissions 
121 of that signal, from any object.
122 </para>
123 <para>
124 You may not attach these to signals created with the #G_SIGNAL_NO_HOOKS flag.
125 </para>
126
127 @ihint: Signal invocation hint, see #GSignalInvocationHint.
128 @n_param_values: the number of parameters to the function, including
129                  the instance on which the signal was emitted.
130 @param_values: the instance on which the signal was emitted, followed by the 
131                parameters of the emission.
132 @data: user data associated with the hook.
133 @Returns: whether it wished to be removed. If it returns %TRUE, the signal 
134           hook is disconnected (and destroyed).
135
136
137 <!-- ##### ENUM GSignalFlags ##### -->
138 <para>
139 The signal flags are used to specify a signal's behaviour, the overall
140 signal description outlines how especially the RUN flags control the
141 stages of a signal emission.
142 </para>
143
144 @G_SIGNAL_RUN_FIRST:   Invoke the object method handler in the first emission stage.
145 @G_SIGNAL_RUN_LAST:    Invoke the object method handler in the third emission stage.
146 @G_SIGNAL_RUN_CLEANUP: Invoke the object method handler in the last emission stage.
147 @G_SIGNAL_NO_RECURSE:  Signals being emitted for an object while currently being in
148                        emission for this very object will not be emitted recursively,
149                        but instead cause the first emission to be restarted.
150 @G_SIGNAL_DETAILED:    This signal supports "::detail" appendixes to the signal name
151                        upon handler connections and emissions.
152 @G_SIGNAL_ACTION:      Action signals are signals that may freely be emitted on alive
153                        objects from user code via g_signal_emit() and friends, without
154                        the need of being embedded into extra code that performs pre or
155                        post emission adjustments on the object. They can also be thought
156                        of as by third-party code generically callable object methods.
157 @G_SIGNAL_NO_HOOKS:    No emissions hooks are supported for this signal.
158
159 <!-- ##### ENUM GSignalMatchType ##### -->
160 <para>
161 The match types specify what g_signal_handlers_block_matched(),
162 g_signal_handlers_unblock_matched() and g_signal_handlers_disconnect_matched()
163 match signals by.
164 </para>
165
166 @G_SIGNAL_MATCH_ID: The signal id must be equal. 
167 @G_SIGNAL_MATCH_DETAIL: The signal detail be equal.  
168 @G_SIGNAL_MATCH_CLOSURE: The closure must be the same.
169 @G_SIGNAL_MATCH_FUNC: The C closure callback must be the same.
170 @G_SIGNAL_MATCH_DATA: The closure data must be the same.
171 @G_SIGNAL_MATCH_UNBLOCKED: Only unblocked signals may matched.
172
173 <!-- ##### STRUCT GSignalQuery ##### -->
174 <para>
175 A structure holding in-depth information for a specific signal. It is
176 filled in by the g_signal_query() function.
177 </para>
178
179 @signal_id:     The signal id of the signal being queried, or 0 if the
180                 signal to be queried was unknown.
181 @signal_name:   The signal name.
182 @itype:         The interface/instance type that this signal can be emitted for.
183 @signal_flags:  The signal flags as passed in to g_signal_new().
184 @return_type:   The return type for user callbacks.
185 @n_params:      The number of parameters that user callbacks take.
186 @param_types:   The individual parameter types for user callbacks, note that the
187                 effective callback signature is:
188 <programlisting>
189 @return_type callback (#gpointer     data1,
190                       [#param_types param_names,]
191                        #gpointer     data2);
192 </programlisting>
193
194 <!-- ##### MACRO G_SIGNAL_TYPE_STATIC_SCOPE ##### -->
195 <para>
196 This macro flags signal argument types for which the signal system may 
197 assume that instances thereof remain persistent across all signal emissions
198 they are used in. This is only useful for non ref-counted, value-copy types.
199 </para>
200 <para>
201 To flag a signal argument in this way, add 
202 <literal>| G_SIGNAL_TYPE_STATIC_SCOPE</literal> to the corresponding argument
203 of g_signal_new().
204 </para>
205 <informalexample>
206 <programlisting>
207     g_signal_new ("size_request",
208                   G_TYPE_FROM_CLASS (gobject_class),
209                   G_SIGNAL_RUN_FIRST,
210                   G_STRUCT_OFFSET (GtkWidgetClass, size_request),
211                   NULL, NULL,
212                   _gtk_marshal_VOID__BOXED,
213                   G_TYPE_NONE, 1,
214                   GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
215 </programlisting>
216 </informalexample>
217
218
219 <!-- ##### MACRO G_SIGNAL_MATCH_MASK ##### -->
220 <para>
221
222 </para>
223
224
225
226 <!-- ##### MACRO G_SIGNAL_FLAGS_MASK ##### -->
227 <para>
228
229 </para>
230
231
232
233 <!-- ##### FUNCTION g_signal_new ##### -->
234 <para>
235
236 </para>
237
238 @signal_name: 
239 @itype: 
240 @signal_flags: 
241 @class_offset: 
242 @accumulator: 
243 @accu_data: 
244 @c_marshaller: 
245 @return_type: 
246 @n_params: 
247 @Varargs: 
248 @Returns: 
249
250
251 <!-- ##### FUNCTION g_signal_newv ##### -->
252 <para>
253
254 </para>
255
256 @signal_name: 
257 @itype: 
258 @signal_flags: 
259 @class_closure: 
260 @accumulator: 
261 @accu_data: 
262 @c_marshaller: 
263 @return_type: 
264 @n_params: 
265 @param_types: 
266 @Returns: 
267
268
269 <!-- ##### FUNCTION g_signal_new_valist ##### -->
270 <para>
271
272 </para>
273
274 @signal_name: 
275 @itype: 
276 @signal_flags: 
277 @class_closure: 
278 @accumulator: 
279 @accu_data: 
280 @c_marshaller: 
281 @return_type: 
282 @n_params: 
283 @args: 
284 @Returns: 
285
286
287 <!-- ##### FUNCTION g_signal_query ##### -->
288 <para>
289 </para>
290
291 @signal_id: 
292 @query: 
293
294
295 <!-- ##### FUNCTION g_signal_lookup ##### -->
296 <para>
297
298 </para>
299
300 @name: 
301 @itype: 
302 @Returns: 
303
304
305 <!-- ##### FUNCTION g_signal_name ##### -->
306 <para>
307
308 </para>
309
310 @signal_id: 
311 @Returns: 
312
313
314 <!-- ##### FUNCTION g_signal_list_ids ##### -->
315 <para>
316 </para>
317
318 @itype: 
319 @n_ids: 
320 @Returns: 
321
322
323 <!-- ##### FUNCTION g_signal_emit ##### -->
324 <para>
325
326 </para>
327
328 @instance: 
329 @signal_id: 
330 @detail: 
331 @Varargs: 
332
333
334 <!-- ##### FUNCTION g_signal_emit_by_name ##### -->
335 <para>
336
337 </para>
338
339 @instance: 
340 @detailed_signal: 
341 @Varargs: 
342
343
344 <!-- ##### FUNCTION g_signal_emitv ##### -->
345 <para>
346
347 </para>
348
349 @instance_and_params: 
350 @signal_id: 
351 @detail: 
352 @return_value: 
353
354
355 <!-- ##### FUNCTION g_signal_emit_valist ##### -->
356 <para>
357
358 </para>
359
360 @instance: 
361 @signal_id: 
362 @detail: 
363 @var_args: 
364
365
366 <!-- ##### MACRO g_signal_connect ##### -->
367 <para>
368 Connects a #GCallback function to a signal for a particular object.
369 </para>
370 <para>
371 The handler will be called before the default handler of the signal.
372 </para>                  
373
374 @instance: the instance to connect to.
375 @detailed_signal: a string of the form "signal-name::detail".
376 @c_handler: the #GCallback to connect.
377 @data: data to pass to @c_handler calls. 
378 @Returns: the handler id 
379
380
381 <!-- ##### MACRO g_signal_connect_after ##### -->
382 <para>
383 Connects a #GCallback function to a signal for a particular object.
384 </para>
385 <para>
386 The handler will be called after the default handler of the signal.
387 </para>                  
388
389 @instance: the instance to connect to.
390 @detailed_signal: a string of the form "signal-name::detail".
391 @c_handler: the #GCallback to connect.
392 @data: data to pass to @c_handler calls. 
393 @Returns: the handler id 
394
395
396 <!-- ##### MACRO g_signal_connect_swapped ##### -->
397 <para>
398 Connects a #GCallback function to a signal for a particular object.
399 </para>
400 <para>
401 The instance on which the signal is emitted and @data will be swapped when 
402 calling the handler.
403 </para>
404
405 @instance: the instance to connect to.
406 @detailed_signal: a string of the form "signal-name::detail".
407 @c_handler: the #GCallback to connect.
408 @data: data to pass to @c_handler calls. 
409 @Returns: the handler id 
410
411
412 <!-- ##### FUNCTION g_signal_connect_object ##### -->
413 <para>
414
415 </para>
416
417 @instance: 
418 @detailed_signal: 
419 @c_handler: 
420 @gobject: 
421 @connect_flags: 
422 @Returns: 
423
424
425 <!-- ##### ENUM GConnectFlags ##### -->
426 <para>
427 The connection flags are used to specify the behaviour of a signal's 
428 connection.
429 </para>
430
431 @G_CONNECT_AFTER: whether the handler should be called before or after the 
432                   default handler of the signal.
433 @G_CONNECT_SWAPPED: whether the instance and data should be swapped when
434                   calling the handler.
435
436 <!-- ##### FUNCTION g_signal_connect_data ##### -->
437 <para>
438
439 </para>
440
441 @instance: 
442 @detailed_signal: 
443 @c_handler: 
444 @data: 
445 @destroy_data: 
446 @connect_flags: 
447 @Returns: 
448
449
450 <!-- ##### FUNCTION g_signal_connect_closure ##### -->
451 <para>
452
453 </para>
454
455 @instance: 
456 @detailed_signal: 
457 @closure: 
458 @after: 
459 @Returns: 
460
461
462 <!-- ##### FUNCTION g_signal_connect_closure_by_id ##### -->
463 <para>
464
465 </para>
466
467 @instance: 
468 @signal_id: 
469 @detail: 
470 @closure: 
471 @after: 
472 @Returns: 
473
474
475 <!-- ##### FUNCTION g_signal_handler_block ##### -->
476 <para>
477 </para>
478
479 @instance: 
480 @handler_id: 
481
482
483 <!-- ##### FUNCTION g_signal_handler_unblock ##### -->
484 <para>
485 </para>
486
487 @instance: 
488 @handler_id: 
489
490
491 <!-- ##### FUNCTION g_signal_handler_disconnect ##### -->
492 <para>
493 </para>
494
495 @instance: 
496 @handler_id: 
497
498
499 <!-- ##### FUNCTION g_signal_handler_find ##### -->
500 <para>
501 </para>
502
503 @instance: 
504 @mask: 
505 @signal_id: 
506 @detail: 
507 @closure: 
508 @func: 
509 @data: 
510 @Returns: 
511
512
513 <!-- ##### FUNCTION g_signal_handlers_block_matched ##### -->
514 <para>
515 </para>
516
517 @instance: 
518 @mask: 
519 @signal_id: 
520 @detail: 
521 @closure: 
522 @func: 
523 @data: 
524 @Returns: 
525
526
527 <!-- ##### FUNCTION g_signal_handlers_unblock_matched ##### -->
528 <para>
529 </para>
530
531 @instance: 
532 @mask: 
533 @signal_id: 
534 @detail: 
535 @closure: 
536 @func: 
537 @data: 
538 @Returns: 
539
540
541 <!-- ##### FUNCTION g_signal_handlers_disconnect_matched ##### -->
542 <para>
543 </para>
544
545 @instance: 
546 @mask: 
547 @signal_id: 
548 @detail: 
549 @closure: 
550 @func: 
551 @data: 
552 @Returns: 
553
554
555 <!-- ##### FUNCTION g_signal_handler_is_connected ##### -->
556 <para>
557
558 </para>
559
560 @instance: 
561 @handler_id: 
562 @Returns: 
563
564
565 <!-- ##### MACRO g_signal_handlers_block_by_func ##### -->
566 <para>
567 Blocks all handlers on an instance that match @func and @data.
568 </para>
569
570 @instance: The instance to block handlers from. 
571 @func: The C closure callback of the handlers (useless for non-C closures).
572 @data: The closure data of the handlers' closures.
573 @Returns: The number of handlers that got blocked.
574
575 <!-- ##### MACRO g_signal_handlers_unblock_by_func ##### -->
576 <para>
577 Unblocks all handlers on an instance that match @func and @data.
578 </para>
579
580 @instance: The instance to unblock handlers from. 
581 @func: The C closure callback of the handlers (useless for non-C closures).
582 @data: The closure data of the handlers' closures.
583 @Returns: The number of handlers that got unblocked.
584
585
586 <!-- ##### MACRO g_signal_handlers_disconnect_by_func ##### -->
587 <para>
588 Disconnects all handlers on an instance that match @func and @data.
589 </para>
590
591 @instance: The instance to remove handlers from. 
592 @func: The C closure callback of the handlers (useless for non-C closures).
593 @data: The closure data of the handlers' closures.
594 @Returns: The number of handlers that got disconnected.
595
596
597
598 <!-- ##### FUNCTION g_signal_has_handler_pending ##### -->
599 <para>
600
601 </para>
602
603 @instance: 
604 @signal_id: 
605 @detail: 
606 @may_be_blocked: 
607 @Returns: 
608
609
610 <!-- ##### FUNCTION g_signal_stop_emission ##### -->
611 <para>
612
613 </para>
614
615 @instance: 
616 @signal_id: 
617 @detail: 
618
619
620 <!-- ##### FUNCTION g_signal_stop_emission_by_name ##### -->
621 <para>
622
623 </para>
624
625 @instance: 
626 @detailed_signal: 
627
628
629 <!-- ##### FUNCTION g_signal_override_class_closure ##### -->
630 <para>
631
632 </para>
633
634 @signal_id: 
635 @instance_type: 
636 @class_closure: 
637
638
639 <!-- ##### FUNCTION g_signal_chain_from_overridden ##### -->
640 <para>
641
642 </para>
643
644 @instance_and_params: 
645 @return_value: 
646
647
648 <!-- ##### FUNCTION g_signal_add_emission_hook ##### -->
649 <para>
650
651 </para>
652
653 @signal_id: 
654 @detail: 
655 @hook_func: 
656 @hook_data: 
657 @data_destroy: 
658 @Returns: 
659
660
661 <!-- ##### FUNCTION g_signal_remove_emission_hook ##### -->
662 <para>
663
664 </para>
665
666 @signal_id: 
667 @hook_id: 
668
669
670 <!-- ##### FUNCTION g_signal_parse_name ##### -->
671 <para>
672 </para>
673
674 @detailed_signal: 
675 @itype: 
676 @signal_id_p: 
677 @detail_p: 
678 @force_detail_quark: 
679 @Returns: 
680
681
682 <!-- ##### FUNCTION g_signal_get_invocation_hint ##### -->
683 <para>
684
685 </para>
686
687 @instance: 
688 @Returns: 
689
690
691 <!-- ##### FUNCTION g_signal_type_cclosure_new ##### -->
692 <para>
693
694 </para>
695
696 @itype: 
697 @struct_offset: 
698 @Returns: 
699
700