up version number to 1.3.7, interface age 0, binary age 0.
[glib.git] / docs / reference / gobject / tmpl / signals.sgml
blobbe5843e09cc97a48381c517c416dd75745a7677b
1 <!-- ##### SECTION Title ##### -->
2 Signals
4 <!-- ##### SECTION Short_Description ##### -->
5 Signals provide a means for customization of object behaviour and are used
6 as general purpose notification mechanism.
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>
69 <!-- ##### SECTION See_Also ##### -->
70 <para>
72 </para>
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>
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.
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>
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.
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>
118 <!-- ##### USER_FUNCTION GSignalEmissionHook ##### -->
119 <para>
121 </para>
123 @ihint:
124 @n_param_values:
125 @param_values:
126 @data:
127 @Returns:
128 <!-- # Unused Parameters # -->
129 @signal_id:
130 @n_values:
131 @values:
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>
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.
156 <!-- ##### ENUM GSignalMatchType ##### -->
157 <para>
159 </para>
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:
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>
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>
189 <!-- ##### MACRO G_SIGNAL_TYPE_STATIC_SCOPE ##### -->
190 <para>
192 </para>
196 <!-- ##### MACRO G_SIGNAL_MATCH_MASK ##### -->
197 <para>
199 </para>
203 <!-- ##### MACRO G_SIGNAL_FLAGS_MASK ##### -->
204 <para>
206 </para>
210 <!-- ##### MACRO g_signal_newc ##### -->
211 <para>
213 </para>
215 @Returns:
216 <!-- # Unused Parameters # -->
217 @signal_name:
218 @itype:
219 @signal_flags:
220 @class_offset:
221 @accumulator:
222 @accu_data:
223 @c_marshaller:
224 @return_type:
225 @n_params:
226 @Varargs:
229 <!-- ##### FUNCTION g_signal_newv ##### -->
230 <para>
232 </para>
234 @signal_name:
235 @itype:
236 @signal_flags:
237 @class_closure:
238 @accumulator:
239 @accu_data:
240 @c_marshaller:
241 @return_type:
242 @n_params:
243 @param_types:
244 @Returns:
247 <!-- ##### FUNCTION g_signal_new_valist ##### -->
248 <para>
250 </para>
252 @signal_name:
253 @itype:
254 @signal_flags:
255 @class_closure:
256 @accumulator:
257 @accu_data:
258 @c_marshaller:
259 @return_type:
260 @n_params:
261 @args:
262 @Returns:
265 <!-- ##### FUNCTION g_signal_query ##### -->
266 <para>
267 Query the signal system for in-depth information about a
268 specific signal. This function will fill in a user-provided
269 structure to hold signal-specific information. If an invalid
270 dignal id is passed in, the @signal_id member of the #GSignalQuery
271 is 0. All members filled into the #GSignalQuery structure should
272 be considered constant and have to be left untouched.
273 </para>
275 @signal_id: The signal id of the signal to query information for.
276 @query: A user provided structure that is filled in with constant
277 values upon success.
280 <!-- ##### FUNCTION g_signal_lookup ##### -->
281 <para>
283 </para>
285 @name:
286 @itype:
287 @Returns:
290 <!-- ##### FUNCTION g_signal_name ##### -->
291 <para>
293 </para>
295 @signal_id:
296 @Returns:
299 <!-- ##### FUNCTION g_signal_list_ids ##### -->
300 <para>
301 List the signals by id, that a certain instance or interface type
302 created. Further information about the signals can be aquired through
303 g_signal_query().
304 </para>
306 @itype: Instance or interface type.
307 @n_ids: Location to store the number of signal ids for @itype.
308 @Returns: Newly allocated array of signal IDs.
311 <!-- ##### FUNCTION g_signal_emit ##### -->
312 <para>
314 </para>
316 @instance:
317 @signal_id:
318 @detail:
319 @Varargs:
322 <!-- ##### FUNCTION g_signal_emit_by_name ##### -->
323 <para>
325 </para>
327 @instance:
328 @detailed_signal:
329 @Varargs:
332 <!-- ##### FUNCTION g_signal_emitv ##### -->
333 <para>
335 </para>
337 @instance_and_params:
338 @signal_id:
339 @detail:
340 @return_value:
343 <!-- ##### FUNCTION g_signal_emit_valist ##### -->
344 <para>
346 </para>
348 @instance:
349 @signal_id:
350 @detail:
351 @var_args:
354 <!-- ##### FUNCTION g_signal_connect_data ##### -->
355 <para>
357 </para>
359 @instance:
360 @detailed_signal:
361 @c_handler:
362 @data:
363 @destroy_data:
364 @connect_flags:
365 @Returns:
366 <!-- # Unused Parameters # -->
367 @swapped:
368 @after:
371 <!-- ##### FUNCTION g_signal_connect_object ##### -->
372 <para>
374 </para>
376 @instance:
377 @detailed_signal:
378 @c_handler:
379 @gobject:
380 @connect_flags:
381 @Returns:
382 <!-- # Unused Parameters # -->
383 @swapped:
384 @after:
387 <!-- ##### FUNCTION g_signal_connect_closure ##### -->
388 <para>
390 </para>
392 @instance:
393 @detailed_signal:
394 @closure:
395 @after:
396 @Returns:
397 <!-- # Unused Parameters # -->
398 @signal_id:
399 @detail:
402 <!-- ##### FUNCTION g_signal_connect_closure_by_id ##### -->
403 <para>
405 </para>
407 @instance:
408 @signal_id:
409 @detail:
410 @closure:
411 @after:
412 @Returns:
415 <!-- ##### FUNCTION g_signal_handler_block ##### -->
416 <para>
417 g_signal_handler_block() blocks a handler of an
418 instance so it will not be called during any signal emissions
419 unless it is unblocked again. Thus "blocking" a signal handler
420 means to temporarily deactive it, a signal handler has to be
421 unblocked exactly the same amount of times it has been blocked
422 before to become active again.
423 The @handler_id passed into g_signal_handler_block() has
424 to be a valid signal handler id, connected to a signal of
425 @instance.
426 </para>
428 @instance: The instance to block the signal handler of.
429 @handler_id: Handler id of the handler to be blocked.
432 <!-- ##### FUNCTION g_signal_handler_unblock ##### -->
433 <para>
434 g_signal_handler_unblock() undoes the effect of a previous
435 g_signal_handler_block() call. A blocked handler is skipped
436 during signal emissions and will not be invoked, unblocking
437 it (for exactly the amount of times it has been blocked before)
438 reverts its "blocked" state, so the handler will be recognized
439 by the signal system and is called upon future or currently
440 ongoing signal emissions (since the order in which handlers are
441 called during signal emissions is deterministic, whether the
442 unblocked handler in question is called as part of a currently
443 ongoing emission depends on how far that emission has proceeded
444 yet).
445 The @handler_id passed into g_signal_handler_unblock() has
446 to be a valid id of a signal handler that is connected to a
447 signal of @instance and is currently blocked.
448 </para>
450 @instance: The instance to unblock the signal handler of.
451 @handler_id: Handler id of the handler to be unblocked.
454 <!-- ##### FUNCTION g_signal_handler_disconnect ##### -->
455 <para>
456 g_signal_handler_disconnect() disconnects a handler from an
457 instance so it will not be called during any future or currently
458 ongoing emissions of the signal it has been connected to.
459 The @handler_id becomes invalid and may be reused.
460 The @handler_id passed into g_signal_handler_disconnect() has
461 to be a valid signal handler id, connected to a signal of
462 @instance.
463 </para>
465 @instance: The instance to remove the signal handler from.
466 @handler_id: Handler id of the handler to be disconnected.
469 <!-- ##### FUNCTION g_signal_handler_find ##### -->
470 <para>
471 Find the first signal handler that matches certain selection criteria.
472 The criteria mask is passed as an OR-ed combination of #GSignalMatchType
473 flags, and the criteria values are passed as arguments.
474 The match @mask has to be non-0 for successfull matches.
475 If no handler was found, 0 is returned.
476 </para>
478 @instance: The instance owning the signal handler to be found.
479 @mask: Mask indicating which of @signal_id, @detail,
480 @closure, @func and/or @data the handler has to match.
481 @signal_id: Signal the handler has to be connected to.
482 @detail: Signal detail the handler has to be connected to.
483 @closure: The closure the handler will invoke.
484 @func: The C closure callback of the handler (useless for non-C closures).
485 @data: The closure data of the handler's closure.
486 @Returns: A valid non-0 signal handler id for a successfull match.
489 <!-- ##### FUNCTION g_signal_handlers_block_matched ##### -->
490 <para>
491 This function blocks all handlers on an instance that match a certain
492 selection criteria. The criteria mask is passed as an OR-ed combination of
493 #GSignalMatchType flags, and the criteria values are passed as arguments.
494 Passing at least one of the %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC
495 or %G_SIGNAL_MATCH_DATA match flags is required for successfull matches.
496 If no handlers were found, 0 is returned, the number of blocked handlers
497 otherwise.
498 </para>
500 @instance: The instance to block handlers from.
501 @mask: Mask indicating which of @signal_id, @detail,
502 @closure, @func and/or @data the handlers have to match.
503 @signal_id: Signal the handlers have to be connected to.
504 @detail: Signal detail the handlers have to be connected to.
505 @closure: The closure the handlers will invoke.
506 @func: The C closure callback of the handlers (useless for non-C closures).
507 @data: The closure data of the handlers' closures.
508 @Returns: The amount of handlers that got blocked.
511 <!-- ##### FUNCTION g_signal_handlers_unblock_matched ##### -->
512 <para>
513 This function unblocks all handlers on an instance that match a certain
514 selection criteria. The criteria mask is passed as an OR-ed combination of
515 #GSignalMatchType flags, and the criteria values are passed as arguments.
516 Passing at least one of the %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC
517 or %G_SIGNAL_MATCH_DATA match flags is required for successfull matches.
518 If no handlers were found, 0 is returned, the number of unblocked handlers
519 otherwise. The match criteria should not apply to any handlers that are
520 not currently blocked.
521 </para>
523 @instance: The instance to unblock handlers from.
524 @mask: Mask indicating which of @signal_id, @detail,
525 @closure, @func and/or @data the handlers have to match.
526 @signal_id: Signal the handlers have to be connected to.
527 @detail: Signal detail the handlers have to be connected to.
528 @closure: The closure the handlers will invoke.
529 @func: The C closure callback of the handlers (useless for non-C closures).
530 @data: The closure data of the handlers' closures.
531 @Returns: The amount of handlers that got unblocked.
534 <!-- ##### FUNCTION g_signal_handlers_disconnect_matched ##### -->
535 <para>
536 This function disconnects all handlers on an instance that match a certain
537 selection criteria. The criteria mask is passed as an OR-ed combination of
538 #GSignalMatchType flags, and the criteria values are passed as arguments.
539 Passing at least one of the %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC
540 or %G_SIGNAL_MATCH_DATA match flags is required for successfull matches.
541 If no handlers were found, 0 is returned, the number of disconnected handlers
542 otherwise.
543 </para>
545 @instance: The instance to remove handlers from.
546 @mask: Mask indicating which of @signal_id, @detail,
547 @closure, @func and/or @data the handlers have to match.
548 @signal_id: Signal the handlers have to be connected to.
549 @detail: Signal detail the handlers have to be connected to.
550 @closure: The closure the handlers will invoke.
551 @func: The C closure callback of the handlers (useless for non-C closures).
552 @data: The closure data of the handlers' closures.
553 @Returns: The amount of handlers that got disconnected.
556 <!-- ##### FUNCTION g_signal_has_handler_pending ##### -->
557 <para>
559 </para>
561 @instance:
562 @signal_id:
563 @detail:
564 @may_be_blocked:
565 @Returns:
568 <!-- ##### FUNCTION g_signal_stop_emission ##### -->
569 <para>
571 </para>
573 @instance:
574 @signal_id:
575 @detail:
578 <!-- ##### FUNCTION g_signal_remove_emission_hook ##### -->
579 <para>
581 </para>
583 @signal_id:
584 @hook_id:
587 <!-- ##### FUNCTION g_signal_parse_name ##### -->
588 <para>
589 Internal function to parse a signal names into its @signal_id
590 and @detail quark.
591 </para>
593 @detailed_signal: A string of the form "signal-name::detail".
594 @itype: The interface/instance type that introduced "signal-name".
595 @signal_id_p: Location to store the signal id.
596 @detail_p: Location to stroe the detail quark.
597 @force_detail_quark: %TRUE forces creation of a GQuark for the detail.
598 @Returns: Whether the signal name could successfully be parsed and
599 @signal_id_p and @detail_p contain valid return values.
602 <!-- ##### FUNCTION g_signal_handlers_destroy ##### -->
603 <para>
605 </para>
607 @instance:
610 <!-- ##### FUNCTION g_signal_type_cclosure_new ##### -->
611 <para>
613 </para>
615 @itype:
616 @struct_offset:
617 @Returns: