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, see <http://www.gnu.org/licenses/>.
17 #ifndef __G_SIGNAL_H__
18 #define __G_SIGNAL_H__
20 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
21 #error "Only <glib-object.h> can be included directly."
24 #include <gobject/gclosure.h>
25 #include <gobject/gvalue.h>
26 #include <gobject/gparam.h>
27 #include <gobject/gmarshal.h>
31 /* --- typedefs --- */
32 typedef struct _GSignalQuery GSignalQuery
;
33 typedef struct _GSignalInvocationHint GSignalInvocationHint
;
37 * This is the signature of marshaller functions, required to marshall
38 * arrays of parameter values to signal emissions into C language callback
39 * invocations. It is merely an alias to #GClosureMarshal since the #GClosure
40 * mechanism takes over responsibility of actual function invocation for the
43 typedef GClosureMarshal GSignalCMarshaller
;
45 * GSignalCVaMarshaller:
47 * This is the signature of va_list marshaller functions, an optional
48 * marshaller that can be used in some situations to avoid
49 * marshalling the signal argument into GValues.
51 typedef GVaClosureMarshal GSignalCVaMarshaller
;
53 * GSignalEmissionHook:
54 * @ihint: Signal invocation hint, see #GSignalInvocationHint.
55 * @n_param_values: the number of parameters to the function, including
56 * the instance on which the signal was emitted.
57 * @param_values: (array length=n_param_values): the instance on which
58 * the signal was emitted, followed by the parameters of the emission.
59 * @data: user data associated with the hook.
61 * A simple function pointer to get invoked when the signal is emitted. This
62 * allows you to tie a hook to the signal type, so that it will trap all
63 * emissions of that signal, from any object.
65 * You may not attach these to signals created with the #G_SIGNAL_NO_HOOKS flag.
67 * Returns: whether it wants to stay connected. If it returns %FALSE, the signal
68 * hook is disconnected (and destroyed).
70 typedef gboolean (*GSignalEmissionHook
) (GSignalInvocationHint
*ihint
,
72 const GValue
*param_values
,
76 * @ihint: Signal invocation hint, see #GSignalInvocationHint.
77 * @return_accu: Accumulator to collect callback return values in, this
78 * is the return value of the current signal emission.
79 * @handler_return: A #GValue holding the return value of the signal handler.
80 * @data: Callback data that was specified when creating the signal.
82 * The signal accumulator is a special callback function that can be used
83 * to collect return values of the various callbacks that are called
84 * during a signal emission. The signal accumulator is specified at signal
85 * creation time, if it is left %NULL, no accumulation of callback return
86 * values is performed. The return value of signal emissions is then the
87 * value returned by the last callback.
89 * Returns: The accumulator function returns whether the signal emission
90 * should be aborted. Returning %FALSE means to abort the
91 * current emission and %TRUE is returned for continuation.
93 typedef gboolean (*GSignalAccumulator
) (GSignalInvocationHint
*ihint
,
95 const GValue
*handler_return
,
99 /* --- run, match and connect types --- */
102 * @G_SIGNAL_RUN_FIRST: Invoke the object method handler in the first emission stage.
103 * @G_SIGNAL_RUN_LAST: Invoke the object method handler in the third emission stage.
104 * @G_SIGNAL_RUN_CLEANUP: Invoke the object method handler in the last emission stage.
105 * @G_SIGNAL_NO_RECURSE: Signals being emitted for an object while currently being in
106 * emission for this very object will not be emitted recursively,
107 * but instead cause the first emission to be restarted.
108 * @G_SIGNAL_DETAILED: This signal supports "::detail" appendices to the signal name
109 * upon handler connections and emissions.
110 * @G_SIGNAL_ACTION: Action signals are signals that may freely be emitted on alive
111 * objects from user code via g_signal_emit() and friends, without
112 * the need of being embedded into extra code that performs pre or
113 * post emission adjustments on the object. They can also be thought
114 * of as object methods which can be called generically by
116 * @G_SIGNAL_NO_HOOKS: No emissions hooks are supported for this signal.
117 * @G_SIGNAL_MUST_COLLECT: Varargs signal emission will always collect the
118 * arguments, even if there are no signal handlers connected. Since 2.30.
119 * @G_SIGNAL_DEPRECATED: The signal is deprecated and will be removed
120 * in a future version. A warning will be generated if it is connected while
121 * running with G_ENABLE_DIAGNOSTIC=1. Since 2.32.
123 * The signal flags are used to specify a signal's behaviour, the overall
124 * signal description outlines how especially the RUN flags control the
125 * stages of a signal emission.
129 G_SIGNAL_RUN_FIRST
= 1 << 0,
130 G_SIGNAL_RUN_LAST
= 1 << 1,
131 G_SIGNAL_RUN_CLEANUP
= 1 << 2,
132 G_SIGNAL_NO_RECURSE
= 1 << 3,
133 G_SIGNAL_DETAILED
= 1 << 4,
134 G_SIGNAL_ACTION
= 1 << 5,
135 G_SIGNAL_NO_HOOKS
= 1 << 6,
136 G_SIGNAL_MUST_COLLECT
= 1 << 7,
137 G_SIGNAL_DEPRECATED
= 1 << 8
140 * G_SIGNAL_FLAGS_MASK:
142 * A mask for all #GSignalFlags bits.
144 #define G_SIGNAL_FLAGS_MASK 0x1ff
147 * @G_CONNECT_AFTER: whether the handler should be called before or after the
148 * default handler of the signal.
149 * @G_CONNECT_SWAPPED: whether the instance and data should be swapped when
150 * calling the handler.
152 * The connection flags are used to specify the behaviour of a signal's
157 G_CONNECT_AFTER
= 1 << 0,
158 G_CONNECT_SWAPPED
= 1 << 1
162 * @G_SIGNAL_MATCH_ID: The signal id must be equal.
163 * @G_SIGNAL_MATCH_DETAIL: The signal detail be equal.
164 * @G_SIGNAL_MATCH_CLOSURE: The closure must be the same.
165 * @G_SIGNAL_MATCH_FUNC: The C closure callback must be the same.
166 * @G_SIGNAL_MATCH_DATA: The closure data must be the same.
167 * @G_SIGNAL_MATCH_UNBLOCKED: Only unblocked signals may matched.
169 * The match types specify what g_signal_handlers_block_matched(),
170 * g_signal_handlers_unblock_matched() and g_signal_handlers_disconnect_matched()
175 G_SIGNAL_MATCH_ID
= 1 << 0,
176 G_SIGNAL_MATCH_DETAIL
= 1 << 1,
177 G_SIGNAL_MATCH_CLOSURE
= 1 << 2,
178 G_SIGNAL_MATCH_FUNC
= 1 << 3,
179 G_SIGNAL_MATCH_DATA
= 1 << 4,
180 G_SIGNAL_MATCH_UNBLOCKED
= 1 << 5
183 * G_SIGNAL_MATCH_MASK:
185 * A mask for all #GSignalMatchType bits.
187 #define G_SIGNAL_MATCH_MASK 0x3f
189 * G_SIGNAL_TYPE_STATIC_SCOPE:
191 * This macro flags signal argument types for which the signal system may
192 * assume that instances thereof remain persistent across all signal emissions
193 * they are used in. This is only useful for non ref-counted, value-copy types.
195 * To flag a signal argument in this way, add
196 * <literal>| G_SIGNAL_TYPE_STATIC_SCOPE</literal> to the corresponding argument
199 * g_signal_new ("size_request",
200 * G_TYPE_FROM_CLASS (gobject_class),
201 * G_SIGNAL_RUN_FIRST,
202 * G_STRUCT_OFFSET (GtkWidgetClass, size_request),
204 * _gtk_marshal_VOID__BOXED,
206 * GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
209 #define G_SIGNAL_TYPE_STATIC_SCOPE (G_TYPE_FLAG_RESERVED_ID_BIT)
212 /* --- signal information --- */
214 * GSignalInvocationHint:
215 * @signal_id: The signal id of the signal invoking the callback
216 * @detail: The detail passed on for this emission
217 * @run_type: The stage the signal emission is currently in, this
218 * field will contain one of %G_SIGNAL_RUN_FIRST,
219 * %G_SIGNAL_RUN_LAST or %G_SIGNAL_RUN_CLEANUP.
221 * The #GSignalInvocationHint structure is used to pass on additional information
222 * to callbacks during a signal emission.
224 struct _GSignalInvocationHint
228 GSignalFlags run_type
;
232 * @signal_id: The signal id of the signal being queried, or 0 if the
233 * signal to be queried was unknown.
234 * @signal_name: The signal name.
235 * @itype: The interface/instance type that this signal can be emitted for.
236 * @signal_flags: The signal flags as passed in to g_signal_new().
237 * @return_type: The return type for user callbacks.
238 * @n_params: The number of parameters that user callbacks take.
239 * @param_types: (array length=n_params): The individual parameter types for
240 * user callbacks, note that the effective callback signature is:
242 * @return_type callback (#gpointer data1,
243 * [param_types param_names,]
247 * A structure holding in-depth information for a specific signal. It is
248 * filled in by the g_signal_query() function.
253 const gchar
*signal_name
;
255 GSignalFlags signal_flags
;
256 GType return_type
; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
258 const GType
*param_types
; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
262 /* --- signals --- */
263 GLIB_AVAILABLE_IN_ALL
264 guint
g_signal_newv (const gchar
*signal_name
,
266 GSignalFlags signal_flags
,
267 GClosure
*class_closure
,
268 GSignalAccumulator accumulator
,
270 GSignalCMarshaller c_marshaller
,
274 GLIB_AVAILABLE_IN_ALL
275 guint
g_signal_new_valist (const gchar
*signal_name
,
277 GSignalFlags signal_flags
,
278 GClosure
*class_closure
,
279 GSignalAccumulator accumulator
,
281 GSignalCMarshaller c_marshaller
,
285 GLIB_AVAILABLE_IN_ALL
286 guint
g_signal_new (const gchar
*signal_name
,
288 GSignalFlags signal_flags
,
290 GSignalAccumulator accumulator
,
292 GSignalCMarshaller c_marshaller
,
296 GLIB_AVAILABLE_IN_ALL
297 guint
g_signal_new_class_handler (const gchar
*signal_name
,
299 GSignalFlags signal_flags
,
300 GCallback class_handler
,
301 GSignalAccumulator accumulator
,
303 GSignalCMarshaller c_marshaller
,
307 GLIB_AVAILABLE_IN_ALL
308 void g_signal_set_va_marshaller (guint signal_id
,
310 GSignalCVaMarshaller va_marshaller
);
312 GLIB_AVAILABLE_IN_ALL
313 void g_signal_emitv (const GValue
*instance_and_params
,
316 GValue
*return_value
);
317 GLIB_AVAILABLE_IN_ALL
318 void g_signal_emit_valist (gpointer instance
,
322 GLIB_AVAILABLE_IN_ALL
323 void g_signal_emit (gpointer instance
,
327 GLIB_AVAILABLE_IN_ALL
328 void g_signal_emit_by_name (gpointer instance
,
329 const gchar
*detailed_signal
,
331 GLIB_AVAILABLE_IN_ALL
332 guint
g_signal_lookup (const gchar
*name
,
334 GLIB_AVAILABLE_IN_ALL
335 const gchar
* g_signal_name (guint signal_id
);
336 GLIB_AVAILABLE_IN_ALL
337 void g_signal_query (guint signal_id
,
338 GSignalQuery
*query
);
339 GLIB_AVAILABLE_IN_ALL
340 guint
* g_signal_list_ids (GType itype
,
342 GLIB_AVAILABLE_IN_ALL
343 gboolean
g_signal_parse_name (const gchar
*detailed_signal
,
347 gboolean force_detail_quark
);
348 GLIB_AVAILABLE_IN_ALL
349 GSignalInvocationHint
* g_signal_get_invocation_hint (gpointer instance
);
352 /* --- signal emissions --- */
353 GLIB_AVAILABLE_IN_ALL
354 void g_signal_stop_emission (gpointer instance
,
357 GLIB_AVAILABLE_IN_ALL
358 void g_signal_stop_emission_by_name (gpointer instance
,
359 const gchar
*detailed_signal
);
360 GLIB_AVAILABLE_IN_ALL
361 gulong
g_signal_add_emission_hook (guint signal_id
,
363 GSignalEmissionHook hook_func
,
365 GDestroyNotify data_destroy
);
366 GLIB_AVAILABLE_IN_ALL
367 void g_signal_remove_emission_hook (guint signal_id
,
371 /* --- signal handlers --- */
372 GLIB_AVAILABLE_IN_ALL
373 gboolean
g_signal_has_handler_pending (gpointer instance
,
376 gboolean may_be_blocked
);
377 GLIB_AVAILABLE_IN_ALL
378 gulong
g_signal_connect_closure_by_id (gpointer instance
,
383 GLIB_AVAILABLE_IN_ALL
384 gulong
g_signal_connect_closure (gpointer instance
,
385 const gchar
*detailed_signal
,
388 GLIB_AVAILABLE_IN_ALL
389 gulong
g_signal_connect_data (gpointer instance
,
390 const gchar
*detailed_signal
,
393 GClosureNotify destroy_data
,
394 GConnectFlags connect_flags
);
395 GLIB_AVAILABLE_IN_ALL
396 void g_signal_handler_block (gpointer instance
,
398 GLIB_AVAILABLE_IN_ALL
399 void g_signal_handler_unblock (gpointer instance
,
401 GLIB_AVAILABLE_IN_ALL
402 void g_signal_handler_disconnect (gpointer instance
,
404 GLIB_AVAILABLE_IN_ALL
405 gboolean
g_signal_handler_is_connected (gpointer instance
,
407 GLIB_AVAILABLE_IN_ALL
408 gulong
g_signal_handler_find (gpointer instance
,
409 GSignalMatchType mask
,
415 GLIB_AVAILABLE_IN_ALL
416 guint
g_signal_handlers_block_matched (gpointer instance
,
417 GSignalMatchType mask
,
423 GLIB_AVAILABLE_IN_ALL
424 guint
g_signal_handlers_unblock_matched (gpointer instance
,
425 GSignalMatchType mask
,
431 GLIB_AVAILABLE_IN_ALL
432 guint
g_signal_handlers_disconnect_matched (gpointer instance
,
433 GSignalMatchType mask
,
441 /* --- overriding and chaining --- */
442 GLIB_AVAILABLE_IN_ALL
443 void g_signal_override_class_closure (guint signal_id
,
445 GClosure
*class_closure
);
446 GLIB_AVAILABLE_IN_ALL
447 void g_signal_override_class_handler (const gchar
*signal_name
,
449 GCallback class_handler
);
450 GLIB_AVAILABLE_IN_ALL
451 void g_signal_chain_from_overridden (const GValue
*instance_and_params
,
452 GValue
*return_value
);
453 GLIB_AVAILABLE_IN_ALL
454 void g_signal_chain_from_overridden_handler (gpointer instance
,
458 /* --- convenience --- */
461 * @instance: the instance to connect to.
462 * @detailed_signal: a string of the form "signal-name::detail".
463 * @c_handler: the #GCallback to connect.
464 * @data: data to pass to @c_handler calls.
466 * Connects a #GCallback function to a signal for a particular object.
468 * The handler will be called before the default handler of the signal.
470 * Returns: the handler id (always greater than 0 for successful connections)
472 #define g_signal_connect(instance, detailed_signal, c_handler, data) \
473 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, (GConnectFlags) 0)
475 * g_signal_connect_after:
476 * @instance: the instance to connect to.
477 * @detailed_signal: a string of the form "signal-name::detail".
478 * @c_handler: the #GCallback to connect.
479 * @data: data to pass to @c_handler calls.
481 * Connects a #GCallback function to a signal for a particular object.
483 * The handler will be called after the default handler of the signal.
485 * Returns: the handler id (always greater than 0 for successful connections)
487 #define g_signal_connect_after(instance, detailed_signal, c_handler, data) \
488 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_AFTER)
490 * g_signal_connect_swapped:
491 * @instance: the instance to connect to.
492 * @detailed_signal: a string of the form "signal-name::detail".
493 * @c_handler: the #GCallback to connect.
494 * @data: data to pass to @c_handler calls.
496 * Connects a #GCallback function to a signal for a particular object.
498 * The instance on which the signal is emitted and @data will be swapped when
499 * calling the handler.
501 * Returns: the handler id (always greater than 0 for successful connections)
503 #define g_signal_connect_swapped(instance, detailed_signal, c_handler, data) \
504 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_SWAPPED)
506 * g_signal_handlers_disconnect_by_func:
507 * @instance: The instance to remove handlers from.
508 * @func: The C closure callback of the handlers (useless for non-C closures).
509 * @data: The closure data of the handlers' closures.
511 * Disconnects all handlers on an instance that match @func and @data.
513 * Returns: The number of handlers that matched.
515 #define g_signal_handlers_disconnect_by_func(instance, func, data) \
516 g_signal_handlers_disconnect_matched ((instance), \
517 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
518 0, 0, NULL, (func), (data))
521 * g_signal_handlers_disconnect_by_data:
522 * @instance: The instance to remove handlers from
523 * @data: the closure data of the handlers' closures
525 * Disconnects all handlers on an instance that match @data.
527 * Returns: The number of handlers that matched.
531 #define g_signal_handlers_disconnect_by_data(instance, data) \
532 g_signal_handlers_disconnect_matched ((instance), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, (data))
535 * g_signal_handlers_block_by_func:
536 * @instance: The instance to block handlers from.
537 * @func: The C closure callback of the handlers (useless for non-C closures).
538 * @data: The closure data of the handlers' closures.
540 * Blocks all handlers on an instance that match @func and @data.
542 * Returns: The number of handlers that matched.
544 #define g_signal_handlers_block_by_func(instance, func, data) \
545 g_signal_handlers_block_matched ((instance), \
546 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
547 0, 0, NULL, (func), (data))
549 * g_signal_handlers_unblock_by_func:
550 * @instance: The instance to unblock handlers from.
551 * @func: The C closure callback of the handlers (useless for non-C closures).
552 * @data: The closure data of the handlers' closures.
554 * Unblocks all handlers on an instance that match @func and @data.
556 * Returns: The number of handlers that matched.
558 #define g_signal_handlers_unblock_by_func(instance, func, data) \
559 g_signal_handlers_unblock_matched ((instance), \
560 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
561 0, 0, NULL, (func), (data))
564 GLIB_AVAILABLE_IN_ALL
565 gboolean
g_signal_accumulator_true_handled (GSignalInvocationHint
*ihint
,
567 const GValue
*handler_return
,
570 GLIB_AVAILABLE_IN_ALL
571 gboolean
g_signal_accumulator_first_wins (GSignalInvocationHint
*ihint
,
573 const GValue
*handler_return
,
577 GLIB_AVAILABLE_IN_ALL
578 void g_signal_handlers_destroy (gpointer instance
);
579 void _g_signals_destroy (GType itype
);
583 #endif /* __G_SIGNAL_H__ */