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 #ifndef __G_SIGNAL_H__
20 #define __G_SIGNAL_H__
22 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
23 #error "Only <glib-object.h> can be included directly."
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 * GSignalCVaMarshaller:
49 * This is the signature of va_list marshaller functions, an optional
50 * marshaller that can be used in some situations to avoid
51 * marshalling the signal argument into GValues.
53 typedef GVaClosureMarshal GSignalCVaMarshaller;
55 * GSignalEmissionHook:
56 * @ihint: Signal invocation hint, see #GSignalInvocationHint.
57 * @n_param_values: the number of parameters to the function, including
58 * the instance on which the signal was emitted.
59 * @param_values: (array length=n_param_values): the instance on which
60 * the signal was emitted, followed by the parameters of the emission.
61 * @data: user data associated with the hook.
63 * A simple function pointer to get invoked when the signal is emitted. This
64 * allows you to tie a hook to the signal type, so that it will trap all
65 * emissions of that signal, from any object.
67 * You may not attach these to signals created with the #G_SIGNAL_NO_HOOKS flag.
69 * Returns: whether it wants to stay connected. If it returns %FALSE, the signal
70 * hook is disconnected (and destroyed).
72 typedef gboolean (*GSignalEmissionHook) (GSignalInvocationHint *ihint,
74 const GValue *param_values,
78 * @ihint: Signal invocation hint, see #GSignalInvocationHint.
79 * @return_accu: Accumulator to collect callback return values in, this
80 * is the return value of the current signal emission.
81 * @handler_return: A #GValue holding the return value of the signal handler.
82 * @data: Callback data that was specified when creating the signal.
84 * The signal accumulator is a special callback function that can be used
85 * to collect return values of the various callbacks that are called
86 * during a signal emission. The signal accumulator is specified at signal
87 * creation time, if it is left %NULL, no accumulation of callback return
88 * values is performed. The return value of signal emissions is then the
89 * value returned by the last callback.
91 * Returns: The accumulator function returns whether the signal emission
92 * should be aborted. Returning %FALSE means to abort the
93 * current emission and %TRUE is returned for continuation.
95 typedef gboolean (*GSignalAccumulator) (GSignalInvocationHint *ihint,
97 const GValue *handler_return,
101 /* --- run, match and connect types --- */
104 * @G_SIGNAL_RUN_FIRST: Invoke the object method handler in the first emission stage.
105 * @G_SIGNAL_RUN_LAST: Invoke the object method handler in the third emission stage.
106 * @G_SIGNAL_RUN_CLEANUP: Invoke the object method handler in the last emission stage.
107 * @G_SIGNAL_NO_RECURSE: Signals being emitted for an object while currently being in
108 * emission for this very object will not be emitted recursively,
109 * but instead cause the first emission to be restarted.
110 * @G_SIGNAL_DETAILED: This signal supports "::detail" appendices to the signal name
111 * upon handler connections and emissions.
112 * @G_SIGNAL_ACTION: Action signals are signals that may freely be emitted on alive
113 * objects from user code via g_signal_emit() and friends, without
114 * the need of being embedded into extra code that performs pre or
115 * post emission adjustments on the object. They can also be thought
116 * of as object methods which can be called generically by
118 * @G_SIGNAL_NO_HOOKS: No emissions hooks are supported for this signal.
119 * @G_SIGNAL_MUST_COLLECT: Varargs signal emission will always collect the
120 * arguments, even if there are no signal handlers connected. Since 2.30.
121 * @G_SIGNAL_DEPRECATED: The signal is deprecated and will be removed
122 * in a future version. A warning will be generated if it is connected while
123 * running with G_ENABLE_DIAGNOSTIC=1. Since 2.32.
125 * The signal flags are used to specify a signal's behaviour, the overall
126 * signal description outlines how especially the RUN flags control the
127 * stages of a signal emission.
131 G_SIGNAL_RUN_FIRST = 1 << 0,
132 G_SIGNAL_RUN_LAST = 1 << 1,
133 G_SIGNAL_RUN_CLEANUP = 1 << 2,
134 G_SIGNAL_NO_RECURSE = 1 << 3,
135 G_SIGNAL_DETAILED = 1 << 4,
136 G_SIGNAL_ACTION = 1 << 5,
137 G_SIGNAL_NO_HOOKS = 1 << 6,
138 G_SIGNAL_MUST_COLLECT = 1 << 7,
139 G_SIGNAL_DEPRECATED = 1 << 8
142 * G_SIGNAL_FLAGS_MASK:
144 * A mask for all #GSignalFlags bits.
146 #define G_SIGNAL_FLAGS_MASK 0x1ff
149 * @G_CONNECT_AFTER: whether the handler should be called before or after the
150 * default handler of the signal.
151 * @G_CONNECT_SWAPPED: whether the instance and data should be swapped when
152 * calling the handler.
154 * The connection flags are used to specify the behaviour of a signal's
159 G_CONNECT_AFTER = 1 << 0,
160 G_CONNECT_SWAPPED = 1 << 1
164 * @G_SIGNAL_MATCH_ID: The signal id must be equal.
165 * @G_SIGNAL_MATCH_DETAIL: The signal detail be equal.
166 * @G_SIGNAL_MATCH_CLOSURE: The closure must be the same.
167 * @G_SIGNAL_MATCH_FUNC: The C closure callback must be the same.
168 * @G_SIGNAL_MATCH_DATA: The closure data must be the same.
169 * @G_SIGNAL_MATCH_UNBLOCKED: Only unblocked signals may matched.
171 * The match types specify what g_signal_handlers_block_matched(),
172 * g_signal_handlers_unblock_matched() and g_signal_handlers_disconnect_matched()
177 G_SIGNAL_MATCH_ID = 1 << 0,
178 G_SIGNAL_MATCH_DETAIL = 1 << 1,
179 G_SIGNAL_MATCH_CLOSURE = 1 << 2,
180 G_SIGNAL_MATCH_FUNC = 1 << 3,
181 G_SIGNAL_MATCH_DATA = 1 << 4,
182 G_SIGNAL_MATCH_UNBLOCKED = 1 << 5
185 * G_SIGNAL_MATCH_MASK:
187 * A mask for all #GSignalMatchType bits.
189 #define G_SIGNAL_MATCH_MASK 0x3f
191 * G_SIGNAL_TYPE_STATIC_SCOPE:
193 * This macro flags signal argument types for which the signal system may
194 * assume that instances thereof remain persistent across all signal emissions
195 * they are used in. This is only useful for non ref-counted, value-copy types.
197 * To flag a signal argument in this way, add
198 * <literal>| G_SIGNAL_TYPE_STATIC_SCOPE</literal> to the corresponding argument
201 * g_signal_new ("size_request",
202 * G_TYPE_FROM_CLASS (gobject_class),
203 * G_SIGNAL_RUN_FIRST,
204 * G_STRUCT_OFFSET (GtkWidgetClass, size_request),
206 * _gtk_marshal_VOID__BOXED,
208 * GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
211 #define G_SIGNAL_TYPE_STATIC_SCOPE (G_TYPE_FLAG_RESERVED_ID_BIT)
214 /* --- signal information --- */
216 * GSignalInvocationHint:
217 * @signal_id: The signal id of the signal invoking the callback
218 * @detail: The detail passed on for this emission
219 * @run_type: The stage the signal emission is currently in, this
220 * field will contain one of %G_SIGNAL_RUN_FIRST,
221 * %G_SIGNAL_RUN_LAST or %G_SIGNAL_RUN_CLEANUP.
223 * The #GSignalInvocationHint structure is used to pass on additional information
224 * to callbacks during a signal emission.
226 struct _GSignalInvocationHint
230 GSignalFlags run_type;
234 * @signal_id: The signal id of the signal being queried, or 0 if the
235 * signal to be queried was unknown.
236 * @signal_name: The signal name.
237 * @itype: The interface/instance type that this signal can be emitted for.
238 * @signal_flags: The signal flags as passed in to g_signal_new().
239 * @return_type: The return type for user callbacks.
240 * @n_params: The number of parameters that user callbacks take.
241 * @param_types: (array length=n_params): The individual parameter types for
242 * user callbacks, note that the effective callback signature is:
244 * @return_type callback (#gpointer data1,
245 * [param_types param_names,]
249 * A structure holding in-depth information for a specific signal. It is
250 * filled in by the g_signal_query() function.
255 const gchar *signal_name;
257 GSignalFlags signal_flags;
258 GType return_type; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
260 const GType *param_types; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
264 /* --- signals --- */
265 GLIB_AVAILABLE_IN_ALL
266 guint g_signal_newv (const gchar *signal_name,
268 GSignalFlags signal_flags,
269 GClosure *class_closure,
270 GSignalAccumulator accumulator,
272 GSignalCMarshaller c_marshaller,
276 GLIB_AVAILABLE_IN_ALL
277 guint g_signal_new_valist (const gchar *signal_name,
279 GSignalFlags signal_flags,
280 GClosure *class_closure,
281 GSignalAccumulator accumulator,
283 GSignalCMarshaller c_marshaller,
287 GLIB_AVAILABLE_IN_ALL
288 guint g_signal_new (const gchar *signal_name,
290 GSignalFlags signal_flags,
292 GSignalAccumulator accumulator,
294 GSignalCMarshaller c_marshaller,
298 GLIB_AVAILABLE_IN_ALL
299 guint g_signal_new_class_handler (const gchar *signal_name,
301 GSignalFlags signal_flags,
302 GCallback class_handler,
303 GSignalAccumulator accumulator,
305 GSignalCMarshaller c_marshaller,
309 GLIB_AVAILABLE_IN_ALL
310 void g_signal_set_va_marshaller (guint signal_id,
312 GSignalCVaMarshaller va_marshaller);
314 GLIB_AVAILABLE_IN_ALL
315 void g_signal_emitv (const GValue *instance_and_params,
318 GValue *return_value);
319 GLIB_AVAILABLE_IN_ALL
320 void g_signal_emit_valist (gpointer instance,
324 GLIB_AVAILABLE_IN_ALL
325 void g_signal_emit (gpointer instance,
329 GLIB_AVAILABLE_IN_ALL
330 void g_signal_emit_by_name (gpointer instance,
331 const gchar *detailed_signal,
333 GLIB_AVAILABLE_IN_ALL
334 guint g_signal_lookup (const gchar *name,
336 GLIB_AVAILABLE_IN_ALL
337 const gchar * g_signal_name (guint signal_id);
338 GLIB_AVAILABLE_IN_ALL
339 void g_signal_query (guint signal_id,
340 GSignalQuery *query);
341 GLIB_AVAILABLE_IN_ALL
342 guint* g_signal_list_ids (GType itype,
344 GLIB_AVAILABLE_IN_ALL
345 gboolean g_signal_parse_name (const gchar *detailed_signal,
349 gboolean force_detail_quark);
350 GLIB_AVAILABLE_IN_ALL
351 GSignalInvocationHint* g_signal_get_invocation_hint (gpointer instance);
354 /* --- signal emissions --- */
355 GLIB_AVAILABLE_IN_ALL
356 void g_signal_stop_emission (gpointer instance,
359 GLIB_AVAILABLE_IN_ALL
360 void g_signal_stop_emission_by_name (gpointer instance,
361 const gchar *detailed_signal);
362 GLIB_AVAILABLE_IN_ALL
363 gulong g_signal_add_emission_hook (guint signal_id,
365 GSignalEmissionHook hook_func,
367 GDestroyNotify data_destroy);
368 GLIB_AVAILABLE_IN_ALL
369 void g_signal_remove_emission_hook (guint signal_id,
373 /* --- signal handlers --- */
374 GLIB_AVAILABLE_IN_ALL
375 gboolean g_signal_has_handler_pending (gpointer instance,
378 gboolean may_be_blocked);
379 GLIB_AVAILABLE_IN_ALL
380 gulong g_signal_connect_closure_by_id (gpointer instance,
385 GLIB_AVAILABLE_IN_ALL
386 gulong g_signal_connect_closure (gpointer instance,
387 const gchar *detailed_signal,
390 GLIB_AVAILABLE_IN_ALL
391 gulong g_signal_connect_data (gpointer instance,
392 const gchar *detailed_signal,
395 GClosureNotify destroy_data,
396 GConnectFlags connect_flags);
397 GLIB_AVAILABLE_IN_ALL
398 void g_signal_handler_block (gpointer instance,
400 GLIB_AVAILABLE_IN_ALL
401 void g_signal_handler_unblock (gpointer instance,
403 GLIB_AVAILABLE_IN_ALL
404 void g_signal_handler_disconnect (gpointer instance,
406 GLIB_AVAILABLE_IN_ALL
407 gboolean g_signal_handler_is_connected (gpointer instance,
409 GLIB_AVAILABLE_IN_ALL
410 gulong g_signal_handler_find (gpointer instance,
411 GSignalMatchType mask,
417 GLIB_AVAILABLE_IN_ALL
418 guint g_signal_handlers_block_matched (gpointer instance,
419 GSignalMatchType mask,
425 GLIB_AVAILABLE_IN_ALL
426 guint g_signal_handlers_unblock_matched (gpointer instance,
427 GSignalMatchType mask,
433 GLIB_AVAILABLE_IN_ALL
434 guint g_signal_handlers_disconnect_matched (gpointer instance,
435 GSignalMatchType mask,
443 /* --- overriding and chaining --- */
444 GLIB_AVAILABLE_IN_ALL
445 void g_signal_override_class_closure (guint signal_id,
447 GClosure *class_closure);
448 GLIB_AVAILABLE_IN_ALL
449 void g_signal_override_class_handler (const gchar *signal_name,
451 GCallback class_handler);
452 GLIB_AVAILABLE_IN_ALL
453 void g_signal_chain_from_overridden (const GValue *instance_and_params,
454 GValue *return_value);
455 GLIB_AVAILABLE_IN_ALL
456 void g_signal_chain_from_overridden_handler (gpointer instance,
460 /* --- convenience --- */
463 * @instance: the instance to connect to.
464 * @detailed_signal: a string of the form "signal-name::detail".
465 * @c_handler: the #GCallback to connect.
466 * @data: data to pass to @c_handler calls.
468 * Connects a #GCallback function to a signal for a particular object.
470 * The handler will be called before the default handler of the signal.
472 * Returns: the handler id
474 #define g_signal_connect(instance, detailed_signal, c_handler, data) \
475 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, (GConnectFlags) 0)
477 * g_signal_connect_after:
478 * @instance: the instance to connect to.
479 * @detailed_signal: a string of the form "signal-name::detail".
480 * @c_handler: the #GCallback to connect.
481 * @data: data to pass to @c_handler calls.
483 * Connects a #GCallback function to a signal for a particular object.
485 * The handler will be called after the default handler of the signal.
487 * Returns: the handler id
489 #define g_signal_connect_after(instance, detailed_signal, c_handler, data) \
490 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_AFTER)
492 * g_signal_connect_swapped:
493 * @instance: the instance to connect to.
494 * @detailed_signal: a string of the form "signal-name::detail".
495 * @c_handler: the #GCallback to connect.
496 * @data: data to pass to @c_handler calls.
498 * Connects a #GCallback function to a signal for a particular object.
500 * The instance on which the signal is emitted and @data will be swapped when
501 * calling the handler.
503 * Returns: the handler id
505 #define g_signal_connect_swapped(instance, detailed_signal, c_handler, data) \
506 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_SWAPPED)
508 * g_signal_handlers_disconnect_by_func:
509 * @instance: The instance to remove handlers from.
510 * @func: The C closure callback of the handlers (useless for non-C closures).
511 * @data: The closure data of the handlers' closures.
513 * Disconnects all handlers on an instance that match @func and @data.
515 * Returns: The number of handlers that matched.
517 #define g_signal_handlers_disconnect_by_func(instance, func, data) \
518 g_signal_handlers_disconnect_matched ((instance), \
519 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
520 0, 0, NULL, (func), (data))
523 * g_signal_handlers_disconnect_by_data:
524 * @instance: The instance to remove handlers from
525 * @data: the closure data of the handlers' closures
527 * Disconnects all handlers on an instance that match @data.
529 * Returns: The number of handlers that matched.
533 #define g_signal_handlers_disconnect_by_data(instance, data) \
534 g_signal_handlers_disconnect_matched ((instance), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, (data))
537 * g_signal_handlers_block_by_func:
538 * @instance: The instance to block handlers from.
539 * @func: The C closure callback of the handlers (useless for non-C closures).
540 * @data: The closure data of the handlers' closures.
542 * Blocks all handlers on an instance that match @func and @data.
544 * Returns: The number of handlers that matched.
546 #define g_signal_handlers_block_by_func(instance, func, data) \
547 g_signal_handlers_block_matched ((instance), \
548 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
549 0, 0, NULL, (func), (data))
551 * g_signal_handlers_unblock_by_func:
552 * @instance: The instance to unblock handlers from.
553 * @func: The C closure callback of the handlers (useless for non-C closures).
554 * @data: The closure data of the handlers' closures.
556 * Unblocks all handlers on an instance that match @func and @data.
558 * Returns: The number of handlers that matched.
560 #define g_signal_handlers_unblock_by_func(instance, func, data) \
561 g_signal_handlers_unblock_matched ((instance), \
562 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
563 0, 0, NULL, (func), (data))
566 GLIB_AVAILABLE_IN_ALL
567 gboolean g_signal_accumulator_true_handled (GSignalInvocationHint *ihint,
569 const GValue *handler_return,
572 GLIB_AVAILABLE_IN_ALL
573 gboolean g_signal_accumulator_first_wins (GSignalInvocationHint *ihint,
575 const GValue *handler_return,
579 GLIB_AVAILABLE_IN_ALL
580 void g_signal_handlers_destroy (gpointer instance);
581 void _g_signals_destroy (GType itype);
585 #endif /* __G_SIGNAL_H__ */