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; see g_signal_connect_swapped() for an example.
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 `| G_SIGNAL_TYPE_STATIC_SCOPE`
196 * to the corresponding argument of g_signal_new().
198 * g_signal_new ("size_request",
199 * G_TYPE_FROM_CLASS (gobject_class),
200 * G_SIGNAL_RUN_FIRST,
201 * G_STRUCT_OFFSET (GtkWidgetClass, size_request),
203 * _gtk_marshal_VOID__BOXED,
205 * GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
208 #define G_SIGNAL_TYPE_STATIC_SCOPE (G_TYPE_FLAG_RESERVED_ID_BIT)
211 /* --- signal information --- */
213 * GSignalInvocationHint:
214 * @signal_id: The signal id of the signal invoking the callback
215 * @detail: The detail passed on for this emission
216 * @run_type: The stage the signal emission is currently in, this
217 * field will contain one of %G_SIGNAL_RUN_FIRST,
218 * %G_SIGNAL_RUN_LAST or %G_SIGNAL_RUN_CLEANUP.
220 * The #GSignalInvocationHint structure is used to pass on additional information
221 * to callbacks during a signal emission.
223 struct _GSignalInvocationHint
227 GSignalFlags run_type
;
231 * @signal_id: The signal id of the signal being queried, or 0 if the
232 * signal to be queried was unknown.
233 * @signal_name: The signal name.
234 * @itype: The interface/instance type that this signal can be emitted for.
235 * @signal_flags: The signal flags as passed in to g_signal_new().
236 * @return_type: The return type for user callbacks.
237 * @n_params: The number of parameters that user callbacks take.
238 * @param_types: (array length=n_params): The individual parameter types for
239 * user callbacks, note that the effective callback signature is:
240 * |[<!-- language="C" -->
241 * @return_type callback (#gpointer data1,
242 * [param_types param_names,]
246 * A structure holding in-depth information for a specific signal. It is
247 * filled in by the g_signal_query() function.
252 const gchar
*signal_name
;
254 GSignalFlags signal_flags
;
255 GType return_type
; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
257 const GType
*param_types
; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
261 /* --- signals --- */
262 GLIB_AVAILABLE_IN_ALL
263 guint
g_signal_newv (const gchar
*signal_name
,
265 GSignalFlags signal_flags
,
266 GClosure
*class_closure
,
267 GSignalAccumulator accumulator
,
269 GSignalCMarshaller c_marshaller
,
273 GLIB_AVAILABLE_IN_ALL
274 guint
g_signal_new_valist (const gchar
*signal_name
,
276 GSignalFlags signal_flags
,
277 GClosure
*class_closure
,
278 GSignalAccumulator accumulator
,
280 GSignalCMarshaller c_marshaller
,
284 GLIB_AVAILABLE_IN_ALL
285 guint
g_signal_new (const gchar
*signal_name
,
287 GSignalFlags signal_flags
,
289 GSignalAccumulator accumulator
,
291 GSignalCMarshaller c_marshaller
,
295 GLIB_AVAILABLE_IN_ALL
296 guint
g_signal_new_class_handler (const gchar
*signal_name
,
298 GSignalFlags signal_flags
,
299 GCallback class_handler
,
300 GSignalAccumulator accumulator
,
302 GSignalCMarshaller c_marshaller
,
306 GLIB_AVAILABLE_IN_ALL
307 void g_signal_set_va_marshaller (guint signal_id
,
309 GSignalCVaMarshaller va_marshaller
);
311 GLIB_AVAILABLE_IN_ALL
312 void g_signal_emitv (const GValue
*instance_and_params
,
315 GValue
*return_value
);
316 GLIB_AVAILABLE_IN_ALL
317 void g_signal_emit_valist (gpointer instance
,
321 GLIB_AVAILABLE_IN_ALL
322 void g_signal_emit (gpointer instance
,
326 GLIB_AVAILABLE_IN_ALL
327 void g_signal_emit_by_name (gpointer instance
,
328 const gchar
*detailed_signal
,
330 GLIB_AVAILABLE_IN_ALL
331 guint
g_signal_lookup (const gchar
*name
,
333 GLIB_AVAILABLE_IN_ALL
334 const gchar
* g_signal_name (guint signal_id
);
335 GLIB_AVAILABLE_IN_ALL
336 void g_signal_query (guint signal_id
,
337 GSignalQuery
*query
);
338 GLIB_AVAILABLE_IN_ALL
339 guint
* g_signal_list_ids (GType itype
,
341 GLIB_AVAILABLE_IN_ALL
342 gboolean
g_signal_parse_name (const gchar
*detailed_signal
,
346 gboolean force_detail_quark
);
347 GLIB_AVAILABLE_IN_ALL
348 GSignalInvocationHint
* g_signal_get_invocation_hint (gpointer instance
);
351 /* --- signal emissions --- */
352 GLIB_AVAILABLE_IN_ALL
353 void g_signal_stop_emission (gpointer instance
,
356 GLIB_AVAILABLE_IN_ALL
357 void g_signal_stop_emission_by_name (gpointer instance
,
358 const gchar
*detailed_signal
);
359 GLIB_AVAILABLE_IN_ALL
360 gulong
g_signal_add_emission_hook (guint signal_id
,
362 GSignalEmissionHook hook_func
,
364 GDestroyNotify data_destroy
);
365 GLIB_AVAILABLE_IN_ALL
366 void g_signal_remove_emission_hook (guint signal_id
,
370 /* --- signal handlers --- */
371 GLIB_AVAILABLE_IN_ALL
372 gboolean
g_signal_has_handler_pending (gpointer instance
,
375 gboolean may_be_blocked
);
376 GLIB_AVAILABLE_IN_ALL
377 gulong
g_signal_connect_closure_by_id (gpointer instance
,
382 GLIB_AVAILABLE_IN_ALL
383 gulong
g_signal_connect_closure (gpointer instance
,
384 const gchar
*detailed_signal
,
387 GLIB_AVAILABLE_IN_ALL
388 gulong
g_signal_connect_data (gpointer instance
,
389 const gchar
*detailed_signal
,
392 GClosureNotify destroy_data
,
393 GConnectFlags connect_flags
);
394 GLIB_AVAILABLE_IN_ALL
395 void g_signal_handler_block (gpointer instance
,
397 GLIB_AVAILABLE_IN_ALL
398 void g_signal_handler_unblock (gpointer instance
,
400 GLIB_AVAILABLE_IN_ALL
401 void g_signal_handler_disconnect (gpointer instance
,
403 GLIB_AVAILABLE_IN_ALL
404 gboolean
g_signal_handler_is_connected (gpointer instance
,
406 GLIB_AVAILABLE_IN_ALL
407 gulong
g_signal_handler_find (gpointer instance
,
408 GSignalMatchType mask
,
414 GLIB_AVAILABLE_IN_ALL
415 guint
g_signal_handlers_block_matched (gpointer instance
,
416 GSignalMatchType mask
,
422 GLIB_AVAILABLE_IN_ALL
423 guint
g_signal_handlers_unblock_matched (gpointer instance
,
424 GSignalMatchType mask
,
430 GLIB_AVAILABLE_IN_ALL
431 guint
g_signal_handlers_disconnect_matched (gpointer instance
,
432 GSignalMatchType mask
,
440 /* --- overriding and chaining --- */
441 GLIB_AVAILABLE_IN_ALL
442 void g_signal_override_class_closure (guint signal_id
,
444 GClosure
*class_closure
);
445 GLIB_AVAILABLE_IN_ALL
446 void g_signal_override_class_handler (const gchar
*signal_name
,
448 GCallback class_handler
);
449 GLIB_AVAILABLE_IN_ALL
450 void g_signal_chain_from_overridden (const GValue
*instance_and_params
,
451 GValue
*return_value
);
452 GLIB_AVAILABLE_IN_ALL
453 void g_signal_chain_from_overridden_handler (gpointer instance
,
457 /* --- convenience --- */
460 * @instance: the instance to connect to.
461 * @detailed_signal: a string of the form "signal-name::detail".
462 * @c_handler: the #GCallback to connect.
463 * @data: data to pass to @c_handler calls.
465 * Connects a #GCallback function to a signal for a particular object.
467 * The handler will be called before the default handler of the signal.
469 * See [memory management of signal handlers][signal-memory-management] for
470 * details on how to handle the return value and memory management of @data.
472 * Returns: the handler ID, of type #gulong (always greater than 0 for successful connections)
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, of type #gulong (always greater than 0 for successful connections)
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. This is useful when calling pre-existing functions to
502 * operate purely on the @data, rather than the @instance: swapping the
503 * parameters avoids the need to write a wrapper function.
505 * For example, this allows the shorter code:
506 * |[<!-- language="C" -->
507 * g_signal_connect_swapped (button, "clicked",
508 * (GCallback) gtk_widget_hide, other_widget);
511 * Rather than the cumbersome:
512 * |[<!-- language="C" -->
514 * button_clicked_cb (GtkButton *button, GtkWidget *other_widget)
516 * gtk_widget_hide (other_widget);
521 * g_signal_connect (button, "clicked",
522 * (GCallback) button_clicked_cb, other_widget);
525 * Returns: the handler ID, of type #gulong (always greater than 0 for successful connections)
527 #define g_signal_connect_swapped(instance, detailed_signal, c_handler, data) \
528 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_SWAPPED)
530 * g_signal_handlers_disconnect_by_func:
531 * @instance: The instance to remove handlers from.
532 * @func: The C closure callback of the handlers (useless for non-C closures).
533 * @data: The closure data of the handlers' closures.
535 * Disconnects all handlers on an instance that match @func and @data.
537 * Returns: The number of handlers that matched.
539 #define g_signal_handlers_disconnect_by_func(instance, func, data) \
540 g_signal_handlers_disconnect_matched ((instance), \
541 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
542 0, 0, NULL, (func), (data))
545 * g_signal_handlers_disconnect_by_data:
546 * @instance: The instance to remove handlers from
547 * @data: the closure data of the handlers' closures
549 * Disconnects all handlers on an instance that match @data.
551 * Returns: The number of handlers that matched.
555 #define g_signal_handlers_disconnect_by_data(instance, data) \
556 g_signal_handlers_disconnect_matched ((instance), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, (data))
559 * g_signal_handlers_block_by_func:
560 * @instance: The instance to block handlers from.
561 * @func: The C closure callback of the handlers (useless for non-C closures).
562 * @data: The closure data of the handlers' closures.
564 * Blocks all handlers on an instance that match @func and @data.
566 * Returns: The number of handlers that matched.
568 #define g_signal_handlers_block_by_func(instance, func, data) \
569 g_signal_handlers_block_matched ((instance), \
570 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
571 0, 0, NULL, (func), (data))
573 * g_signal_handlers_unblock_by_func:
574 * @instance: The instance to unblock handlers from.
575 * @func: The C closure callback of the handlers (useless for non-C closures).
576 * @data: The closure data of the handlers' closures.
578 * Unblocks all handlers on an instance that match @func and @data.
580 * Returns: The number of handlers that matched.
582 #define g_signal_handlers_unblock_by_func(instance, func, data) \
583 g_signal_handlers_unblock_matched ((instance), \
584 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
585 0, 0, NULL, (func), (data))
588 GLIB_AVAILABLE_IN_ALL
589 gboolean
g_signal_accumulator_true_handled (GSignalInvocationHint
*ihint
,
591 const GValue
*handler_return
,
594 GLIB_AVAILABLE_IN_ALL
595 gboolean
g_signal_accumulator_first_wins (GSignalInvocationHint
*ihint
,
597 const GValue
*handler_return
,
601 GLIB_AVAILABLE_IN_ALL
602 void g_signal_handlers_destroy (gpointer instance
);
603 void _g_signals_destroy (GType itype
);
607 #endif /* __G_SIGNAL_H__ */