1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 2000-2001 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
19 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
20 #error "Only <glib-object.h> can be included directly."
23 #ifndef __G_SIGNAL_H__
24 #define __G_SIGNAL_H__
26 #include <gobject/gclosure.h>
27 #include <gobject/gvalue.h>
28 #include <gobject/gparam.h>
29 #include <gobject/gmarshal.h>
33 /* --- typedefs --- */
34 typedef struct _GSignalQuery GSignalQuery;
35 typedef struct _GSignalInvocationHint GSignalInvocationHint;
39 * This is the signature of marshaller functions, required to marshall
40 * arrays of parameter values to signal emissions into C language callback
41 * invocations. It is merely an alias to #GClosureMarshal since the #GClosure
42 * mechanism takes over responsibility of actual function invocation for the
45 typedef GClosureMarshal GSignalCMarshaller;
47 * GSignalEmissionHook:
48 * @ihint: Signal invocation hint, see #GSignalInvocationHint.
49 * @n_param_values: the number of parameters to the function, including
50 * the instance on which the signal was emitted.
51 * @param_values: (array length=n_param_values): the instance on which
52 * the signal was emitted, followed by the parameters of the emission.
53 * @data: user data associated with the hook.
55 * A simple function pointer to get invoked when the signal is emitted. This
56 * allows you to tie a hook to the signal type, so that it will trap all
57 * emissions of that signal, from any object.
59 * You may not attach these to signals created with the #G_SIGNAL_NO_HOOKS flag.
61 * Returns: whether it wants to stay connected. If it returns %FALSE, the signal
62 * hook is disconnected (and destroyed).
64 typedef gboolean (*GSignalEmissionHook) (GSignalInvocationHint *ihint,
66 const GValue *param_values,
70 * @ihint: Signal invocation hint, see #GSignalInvocationHint.
71 * @return_accu: Accumulator to collect callback return values in, this
72 * is the return value of the current signal emission.
73 * @handler_return: A #GValue holding the return value of the signal handler.
74 * @data: Callback data that was specified when creating the signal.
76 * The signal accumulator is a special callback function that can be used
77 * to collect return values of the various callbacks that are called
78 * during a signal emission. The signal accumulator is specified at signal
79 * creation time, if it is left %NULL, no accumulation of callback return
80 * values is performed. The return value of signal emissions is then the
81 * value returned by the last callback.
83 * Returns: The accumulator function returns whether the signal emission
84 * should be aborted. Returning %FALSE means to abort the
85 * current emission and %TRUE is returned for continuation.
87 typedef gboolean (*GSignalAccumulator) (GSignalInvocationHint *ihint,
89 const GValue *handler_return,
93 /* --- run, match and connect types --- */
96 * @G_SIGNAL_RUN_FIRST: Invoke the object method handler in the first emission stage.
97 * @G_SIGNAL_RUN_LAST: Invoke the object method handler in the third emission stage.
98 * @G_SIGNAL_RUN_CLEANUP: Invoke the object method handler in the last emission stage.
99 * @G_SIGNAL_NO_RECURSE: Signals being emitted for an object while currently being in
100 * emission for this very object will not be emitted recursively,
101 * but instead cause the first emission to be restarted.
102 * @G_SIGNAL_DETAILED: This signal supports "::detail" appendices to the signal name
103 * upon handler connections and emissions.
104 * @G_SIGNAL_ACTION: Action signals are signals that may freely be emitted on alive
105 * objects from user code via g_signal_emit() and friends, without
106 * the need of being embedded into extra code that performs pre or
107 * post emission adjustments on the object. They can also be thought
108 * of as object methods which can be called generically by
110 * @G_SIGNAL_NO_HOOKS: No emissions hooks are supported for this signal.
111 * @G_SIGNAL_MUST_COLLECT: Varargs signal emission will always collect the
112 * arguments, even if there are no signal handlers connected. Since 2.30.
113 * @G_SIGNAL_DEPRECATED: The signal is deprecated and will be removed
114 * in a future version. A warning will be generated if it is connected while
115 * running with G_ENABLE_DIAGNOSTIC=1. Since 2.32.
117 * The signal flags are used to specify a signal's behaviour, the overall
118 * signal description outlines how especially the RUN flags control the
119 * stages of a signal emission.
123 G_SIGNAL_RUN_FIRST = 1 << 0,
124 G_SIGNAL_RUN_LAST = 1 << 1,
125 G_SIGNAL_RUN_CLEANUP = 1 << 2,
126 G_SIGNAL_NO_RECURSE = 1 << 3,
127 G_SIGNAL_DETAILED = 1 << 4,
128 G_SIGNAL_ACTION = 1 << 5,
129 G_SIGNAL_NO_HOOKS = 1 << 6,
130 G_SIGNAL_MUST_COLLECT = 1 << 7,
131 G_SIGNAL_DEPRECATED = 1 << 8
134 * G_SIGNAL_FLAGS_MASK:
136 * A mask for all #GSignalFlags bits.
138 #define G_SIGNAL_FLAGS_MASK 0x1ff
141 * @G_CONNECT_AFTER: whether the handler should be called before or after the
142 * default handler of the signal.
143 * @G_CONNECT_SWAPPED: whether the instance and data should be swapped when
144 * calling the handler.
146 * The connection flags are used to specify the behaviour of a signal's
151 G_CONNECT_AFTER = 1 << 0,
152 G_CONNECT_SWAPPED = 1 << 1
156 * @G_SIGNAL_MATCH_ID: The signal id must be equal.
157 * @G_SIGNAL_MATCH_DETAIL: The signal detail be equal.
158 * @G_SIGNAL_MATCH_CLOSURE: The closure must be the same.
159 * @G_SIGNAL_MATCH_FUNC: The C closure callback must be the same.
160 * @G_SIGNAL_MATCH_DATA: The closure data must be the same.
161 * @G_SIGNAL_MATCH_UNBLOCKED: Only unblocked signals may matched.
163 * The match types specify what g_signal_handlers_block_matched(),
164 * g_signal_handlers_unblock_matched() and g_signal_handlers_disconnect_matched()
169 G_SIGNAL_MATCH_ID = 1 << 0,
170 G_SIGNAL_MATCH_DETAIL = 1 << 1,
171 G_SIGNAL_MATCH_CLOSURE = 1 << 2,
172 G_SIGNAL_MATCH_FUNC = 1 << 3,
173 G_SIGNAL_MATCH_DATA = 1 << 4,
174 G_SIGNAL_MATCH_UNBLOCKED = 1 << 5
177 * G_SIGNAL_MATCH_MASK:
179 * A mask for all #GSignalMatchType bits.
181 #define G_SIGNAL_MATCH_MASK 0x3f
183 * G_SIGNAL_TYPE_STATIC_SCOPE:
185 * This macro flags signal argument types for which the signal system may
186 * assume that instances thereof remain persistent across all signal emissions
187 * they are used in. This is only useful for non ref-counted, value-copy types.
189 * To flag a signal argument in this way, add
190 * <literal>| G_SIGNAL_TYPE_STATIC_SCOPE</literal> to the corresponding argument
193 * g_signal_new ("size_request",
194 * G_TYPE_FROM_CLASS (gobject_class),
195 * G_SIGNAL_RUN_FIRST,
196 * G_STRUCT_OFFSET (GtkWidgetClass, size_request),
198 * _gtk_marshal_VOID__BOXED,
200 * GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
203 #define G_SIGNAL_TYPE_STATIC_SCOPE (G_TYPE_FLAG_RESERVED_ID_BIT)
206 /* --- signal information --- */
208 * GSignalInvocationHint:
209 * @signal_id: The signal id of the signal invoking the callback
210 * @detail: The detail passed on for this emission
211 * @run_type: The stage the signal emission is currently in, this
212 * field will contain one of %G_SIGNAL_RUN_FIRST,
213 * %G_SIGNAL_RUN_LAST or %G_SIGNAL_RUN_CLEANUP.
215 * The #GSignalInvocationHint structure is used to pass on additional information
216 * to callbacks during a signal emission.
218 struct _GSignalInvocationHint
222 GSignalFlags run_type;
226 * @signal_id: The signal id of the signal being queried, or 0 if the
227 * signal to be queried was unknown.
228 * @signal_name: The signal name.
229 * @itype: The interface/instance type that this signal can be emitted for.
230 * @signal_flags: The signal flags as passed in to g_signal_new().
231 * @return_type: The return type for user callbacks.
232 * @n_params: The number of parameters that user callbacks take.
233 * @param_types: The individual parameter types for user callbacks, note that the
234 * effective callback signature is:
236 * @return_type callback (#gpointer data1,
237 * [param_types param_names,]
241 * A structure holding in-depth information for a specific signal. It is
242 * filled in by the g_signal_query() function.
247 const gchar *signal_name;
249 GSignalFlags signal_flags;
250 GType return_type; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
252 const GType *param_types; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
256 /* --- signals --- */
257 guint g_signal_newv (const gchar *signal_name,
259 GSignalFlags signal_flags,
260 GClosure *class_closure,
261 GSignalAccumulator accumulator,
263 GSignalCMarshaller c_marshaller,
267 guint g_signal_new_valist (const gchar *signal_name,
269 GSignalFlags signal_flags,
270 GClosure *class_closure,
271 GSignalAccumulator accumulator,
273 GSignalCMarshaller c_marshaller,
277 guint g_signal_new (const gchar *signal_name,
279 GSignalFlags signal_flags,
281 GSignalAccumulator accumulator,
283 GSignalCMarshaller c_marshaller,
287 guint g_signal_new_class_handler (const gchar *signal_name,
289 GSignalFlags signal_flags,
290 GCallback class_handler,
291 GSignalAccumulator accumulator,
293 GSignalCMarshaller c_marshaller,
298 void g_signal_emitv (const GValue *instance_and_params,
301 GValue *return_value);
302 void g_signal_emit_valist (gpointer instance,
306 void g_signal_emit (gpointer instance,
310 void g_signal_emit_by_name (gpointer instance,
311 const gchar *detailed_signal,
313 guint g_signal_lookup (const gchar *name,
315 const gchar * g_signal_name (guint signal_id);
316 void g_signal_query (guint signal_id,
317 GSignalQuery *query);
318 guint* g_signal_list_ids (GType itype,
320 gboolean g_signal_parse_name (const gchar *detailed_signal,
324 gboolean force_detail_quark);
325 GSignalInvocationHint* g_signal_get_invocation_hint (gpointer instance);
328 /* --- signal emissions --- */
329 void g_signal_stop_emission (gpointer instance,
332 void g_signal_stop_emission_by_name (gpointer instance,
333 const gchar *detailed_signal);
334 gulong g_signal_add_emission_hook (guint signal_id,
336 GSignalEmissionHook hook_func,
338 GDestroyNotify data_destroy);
339 void g_signal_remove_emission_hook (guint signal_id,
343 /* --- signal handlers --- */
344 gboolean g_signal_has_handler_pending (gpointer instance,
347 gboolean may_be_blocked);
348 gulong g_signal_connect_closure_by_id (gpointer instance,
353 gulong g_signal_connect_closure (gpointer instance,
354 const gchar *detailed_signal,
357 gulong g_signal_connect_data (gpointer instance,
358 const gchar *detailed_signal,
361 GClosureNotify destroy_data,
362 GConnectFlags connect_flags);
363 void g_signal_handler_block (gpointer instance,
365 void g_signal_handler_unblock (gpointer instance,
367 void g_signal_handler_disconnect (gpointer instance,
369 gboolean g_signal_handler_is_connected (gpointer instance,
371 gulong g_signal_handler_find (gpointer instance,
372 GSignalMatchType mask,
378 guint g_signal_handlers_block_matched (gpointer instance,
379 GSignalMatchType mask,
385 guint g_signal_handlers_unblock_matched (gpointer instance,
386 GSignalMatchType mask,
392 guint g_signal_handlers_disconnect_matched (gpointer instance,
393 GSignalMatchType mask,
401 /* --- overriding and chaining --- */
402 void g_signal_override_class_closure (guint signal_id,
404 GClosure *class_closure);
405 void g_signal_override_class_handler (const gchar *signal_name,
407 GCallback class_handler);
408 void g_signal_chain_from_overridden (const GValue *instance_and_params,
409 GValue *return_value);
410 void g_signal_chain_from_overridden_handler (gpointer instance,
414 /* --- convenience --- */
417 * @instance: the instance to connect to.
418 * @detailed_signal: a string of the form "signal-name::detail".
419 * @c_handler: the #GCallback to connect.
420 * @data: data to pass to @c_handler calls.
422 * Connects a #GCallback function to a signal for a particular object.
424 * The handler will be called before the default handler of the signal.
426 * Returns: the handler id
428 #define g_signal_connect(instance, detailed_signal, c_handler, data) \
429 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, (GConnectFlags) 0)
431 * g_signal_connect_after:
432 * @instance: the instance to connect to.
433 * @detailed_signal: a string of the form "signal-name::detail".
434 * @c_handler: the #GCallback to connect.
435 * @data: data to pass to @c_handler calls.
437 * Connects a #GCallback function to a signal for a particular object.
439 * The handler will be called after the default handler of the signal.
441 * Returns: the handler id
443 #define g_signal_connect_after(instance, detailed_signal, c_handler, data) \
444 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_AFTER)
446 * g_signal_connect_swapped:
447 * @instance: the instance to connect to.
448 * @detailed_signal: a string of the form "signal-name::detail".
449 * @c_handler: the #GCallback to connect.
450 * @data: data to pass to @c_handler calls.
452 * Connects a #GCallback function to a signal for a particular object.
454 * The instance on which the signal is emitted and @data will be swapped when
455 * calling the handler.
457 * Returns: the handler id
459 #define g_signal_connect_swapped(instance, detailed_signal, c_handler, data) \
460 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_SWAPPED)
462 * g_signal_handlers_disconnect_by_func:
463 * @instance: The instance to remove handlers from.
464 * @func: The C closure callback of the handlers (useless for non-C closures).
465 * @data: The closure data of the handlers' closures.
467 * Disconnects all handlers on an instance that match @func and @data.
469 * Returns: The number of handlers that matched.
471 #define g_signal_handlers_disconnect_by_func(instance, func, data) \
472 g_signal_handlers_disconnect_matched ((instance), \
473 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
474 0, 0, NULL, (func), (data))
476 * g_signal_handlers_block_by_func:
477 * @instance: The instance to block handlers from.
478 * @func: The C closure callback of the handlers (useless for non-C closures).
479 * @data: The closure data of the handlers' closures.
481 * Blocks all handlers on an instance that match @func and @data.
483 * Returns: The number of handlers that matched.
485 #define g_signal_handlers_block_by_func(instance, func, data) \
486 g_signal_handlers_block_matched ((instance), \
487 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
488 0, 0, NULL, (func), (data))
490 * g_signal_handlers_unblock_by_func:
491 * @instance: The instance to unblock handlers from.
492 * @func: The C closure callback of the handlers (useless for non-C closures).
493 * @data: The closure data of the handlers' closures.
495 * Unblocks all handlers on an instance that match @func and @data.
497 * Returns: The number of handlers that matched.
499 #define g_signal_handlers_unblock_by_func(instance, func, data) \
500 g_signal_handlers_unblock_matched ((instance), \
501 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
502 0, 0, NULL, (func), (data))
505 gboolean g_signal_accumulator_true_handled (GSignalInvocationHint *ihint,
507 const GValue *handler_return,
510 gboolean g_signal_accumulator_first_wins (GSignalInvocationHint *ihint,
512 const GValue *handler_return,
516 void g_signal_handlers_destroy (gpointer instance);
517 void _g_signals_destroy (GType itype);
521 #endif /* __G_SIGNAL_H__ */