1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 A means for customization of object behaviour and a general purpose notification mechanism
7 <!-- ##### SECTION Long_Description ##### -->
9 The basic concept of the signal system is that of the <emphasis>emission</emphasis>
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,
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.
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.
31 A signal emission consists of five stages, unless prematurely stopped:
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>
49 The user provided signal handlers are called in the order they were
51 All handlers may prematurely stop a signal emission, and any number of
52 handlers may be connected, disconnected, blocked or unblocked during
54 There are certain criteria for skipping user handlers in stages 2 and 4
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.
68 <!-- ##### SECTION See_Also ##### -->
73 <!-- ##### STRUCT GSignalInvocationHint ##### -->
75 The #GSignalInvocationHint structure is used to pass on additional information
76 to callbacks during a signal emission.
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.
85 <!-- ##### USER_FUNCTION GSignalAccumulator ##### -->
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.
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.
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.
107 <!-- ##### TYPEDEF GSignalCMarshaller ##### -->
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
117 <!-- ##### USER_FUNCTION GSignalEmissionHook ##### -->
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.
124 You may not attach these to signals created with the #G_SIGNAL_NO_HOOKS flag.
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).
137 <!-- ##### ENUM GSignalFlags ##### -->
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.
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.
159 <!-- ##### ENUM GSignalMatchType ##### -->
161 The match types specify what g_signal_handlers_block_matched(),
162 g_signal_handlers_unblock_matched() and g_signal_handlers_disconnect_matched()
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.
173 <!-- ##### STRUCT GSignalQuery ##### -->
175 A structure holding in-depth information for a specific signal. It is
176 filled in by the g_signal_query() function.
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:
189 @return_type callback (#gpointer data1,
190 [#param_types param_names,]
194 <!-- ##### MACRO G_SIGNAL_TYPE_STATIC_SCOPE ##### -->
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.
201 To flag a signal argument in this way, add
202 <literal>| G_SIGNAL_TYPE_STATIC_SCOPE</literal> to the corresponding argument
207 g_signal_new ("size_request",
208 G_TYPE_FROM_CLASS (gobject_class),
210 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
212 _gtk_marshal_VOID__BOXED,
214 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
219 <!-- ##### MACRO G_SIGNAL_MATCH_MASK ##### -->
226 <!-- ##### MACRO G_SIGNAL_FLAGS_MASK ##### -->
233 <!-- ##### FUNCTION g_signal_new ##### -->
251 <!-- ##### FUNCTION g_signal_newv ##### -->
269 <!-- ##### FUNCTION g_signal_new_valist ##### -->
287 <!-- ##### FUNCTION g_signal_query ##### -->
295 <!-- ##### FUNCTION g_signal_lookup ##### -->
305 <!-- ##### FUNCTION g_signal_name ##### -->
314 <!-- ##### FUNCTION g_signal_list_ids ##### -->
323 <!-- ##### FUNCTION g_signal_emit ##### -->
334 <!-- ##### FUNCTION g_signal_emit_by_name ##### -->
344 <!-- ##### FUNCTION g_signal_emitv ##### -->
349 @instance_and_params:
355 <!-- ##### FUNCTION g_signal_emit_valist ##### -->
366 <!-- ##### MACRO g_signal_connect ##### -->
368 Connects a #GCallback function to a signal for a particular object.
371 The handler will be called before the default handler of the signal.
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
381 <!-- ##### MACRO g_signal_connect_after ##### -->
383 Connects a #GCallback function to a signal for a particular object.
386 The handler will be called after the default handler of the signal.
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
396 <!-- ##### MACRO g_signal_connect_swapped ##### -->
398 Connects a #GCallback function to a signal for a particular object.
401 The instance on which the signal is emitted and @data will be swapped when
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
412 <!-- ##### FUNCTION g_signal_connect_object ##### -->
425 <!-- ##### ENUM GConnectFlags ##### -->
427 The connection flags are used to specify the behaviour of a signal's
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
436 <!-- ##### FUNCTION g_signal_connect_data ##### -->
450 <!-- ##### FUNCTION g_signal_connect_closure ##### -->
462 <!-- ##### FUNCTION g_signal_connect_closure_by_id ##### -->
475 <!-- ##### FUNCTION g_signal_handler_block ##### -->
483 <!-- ##### FUNCTION g_signal_handler_unblock ##### -->
491 <!-- ##### FUNCTION g_signal_handler_disconnect ##### -->
499 <!-- ##### FUNCTION g_signal_handler_find ##### -->
513 <!-- ##### FUNCTION g_signal_handlers_block_matched ##### -->
527 <!-- ##### FUNCTION g_signal_handlers_unblock_matched ##### -->
541 <!-- ##### FUNCTION g_signal_handlers_disconnect_matched ##### -->
555 <!-- ##### FUNCTION g_signal_handler_is_connected ##### -->
565 <!-- ##### MACRO g_signal_handlers_block_by_func ##### -->
567 Blocks all handlers on an instance that match @func and @data.
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.
575 <!-- ##### MACRO g_signal_handlers_unblock_by_func ##### -->
577 Unblocks all handlers on an instance that match @func and @data.
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.
586 <!-- ##### MACRO g_signal_handlers_disconnect_by_func ##### -->
588 Disconnects all handlers on an instance that match @func and @data.
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.
598 <!-- ##### FUNCTION g_signal_has_handler_pending ##### -->
610 <!-- ##### FUNCTION g_signal_stop_emission ##### -->
620 <!-- ##### FUNCTION g_signal_stop_emission_by_name ##### -->
629 <!-- ##### FUNCTION g_signal_override_class_closure ##### -->
639 <!-- ##### FUNCTION g_signal_chain_from_overridden ##### -->
644 @instance_and_params:
648 <!-- ##### FUNCTION g_signal_add_emission_hook ##### -->
661 <!-- ##### FUNCTION g_signal_remove_emission_hook ##### -->
670 <!-- ##### FUNCTION g_signal_parse_name ##### -->
682 <!-- ##### FUNCTION g_signal_get_invocation_hint ##### -->
691 <!-- ##### FUNCTION g_signal_type_cclosure_new ##### -->