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: the instance on which the signal was emitted, followed by the
52 * 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.
114 * The signal flags are used to specify a signal's behaviour, the overall
115 * signal description outlines how especially the RUN flags control the
116 * stages of a signal emission.
120 G_SIGNAL_RUN_FIRST
= 1 << 0,
121 G_SIGNAL_RUN_LAST
= 1 << 1,
122 G_SIGNAL_RUN_CLEANUP
= 1 << 2,
123 G_SIGNAL_NO_RECURSE
= 1 << 3,
124 G_SIGNAL_DETAILED
= 1 << 4,
125 G_SIGNAL_ACTION
= 1 << 5,
126 G_SIGNAL_NO_HOOKS
= 1 << 6,
127 G_SIGNAL_MUST_COLLECT
= 1 << 7
130 * G_SIGNAL_FLAGS_MASK:
132 * A mask for all #GSignalFlags bits.
134 #define G_SIGNAL_FLAGS_MASK 0xff
137 * @G_CONNECT_AFTER: whether the handler should be called before or after the
138 * default handler of the signal.
139 * @G_CONNECT_SWAPPED: whether the instance and data should be swapped when
140 * calling the handler.
142 * The connection flags are used to specify the behaviour of a signal's
147 G_CONNECT_AFTER
= 1 << 0,
148 G_CONNECT_SWAPPED
= 1 << 1
152 * @G_SIGNAL_MATCH_ID: The signal id must be equal.
153 * @G_SIGNAL_MATCH_DETAIL: The signal detail be equal.
154 * @G_SIGNAL_MATCH_CLOSURE: The closure must be the same.
155 * @G_SIGNAL_MATCH_FUNC: The C closure callback must be the same.
156 * @G_SIGNAL_MATCH_DATA: The closure data must be the same.
157 * @G_SIGNAL_MATCH_UNBLOCKED: Only unblocked signals may matched.
159 * The match types specify what g_signal_handlers_block_matched(),
160 * g_signal_handlers_unblock_matched() and g_signal_handlers_disconnect_matched()
165 G_SIGNAL_MATCH_ID
= 1 << 0,
166 G_SIGNAL_MATCH_DETAIL
= 1 << 1,
167 G_SIGNAL_MATCH_CLOSURE
= 1 << 2,
168 G_SIGNAL_MATCH_FUNC
= 1 << 3,
169 G_SIGNAL_MATCH_DATA
= 1 << 4,
170 G_SIGNAL_MATCH_UNBLOCKED
= 1 << 5
173 * G_SIGNAL_MATCH_MASK:
175 * A mask for all #GSignalMatchType bits.
177 #define G_SIGNAL_MATCH_MASK 0x3f
179 * G_SIGNAL_TYPE_STATIC_SCOPE:
181 * This macro flags signal argument types for which the signal system may
182 * assume that instances thereof remain persistent across all signal emissions
183 * they are used in. This is only useful for non ref-counted, value-copy types.
185 * To flag a signal argument in this way, add
186 * <literal>| G_SIGNAL_TYPE_STATIC_SCOPE</literal> to the corresponding argument
189 * g_signal_new ("size_request",
190 * G_TYPE_FROM_CLASS (gobject_class),
191 * G_SIGNAL_RUN_FIRST,
192 * G_STRUCT_OFFSET (GtkWidgetClass, size_request),
194 * _gtk_marshal_VOID__BOXED,
196 * GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
199 #define G_SIGNAL_TYPE_STATIC_SCOPE (G_TYPE_FLAG_RESERVED_ID_BIT)
202 /* --- signal information --- */
204 * GSignalInvocationHint:
205 * @signal_id: The signal id of the signal invoking the callback
206 * @detail: The detail passed on for this emission
207 * @run_type: The stage the signal emission is currently in, this
208 * field will contain one of %G_SIGNAL_RUN_FIRST,
209 * %G_SIGNAL_RUN_LAST or %G_SIGNAL_RUN_CLEANUP.
211 * The #GSignalInvocationHint structure is used to pass on additional information
212 * to callbacks during a signal emission.
214 struct _GSignalInvocationHint
218 GSignalFlags run_type
;
222 * @signal_id: The signal id of the signal being queried, or 0 if the
223 * signal to be queried was unknown.
224 * @signal_name: The signal name.
225 * @itype: The interface/instance type that this signal can be emitted for.
226 * @signal_flags: The signal flags as passed in to g_signal_new().
227 * @return_type: The return type for user callbacks.
228 * @n_params: The number of parameters that user callbacks take.
229 * @param_types: The individual parameter types for user callbacks, note that the
230 * effective callback signature is:
232 * @return_type callback (#gpointer data1,
233 * [#param_types param_names,]
237 * A structure holding in-depth information for a specific signal. It is
238 * filled in by the g_signal_query() function.
243 const gchar
*signal_name
;
245 GSignalFlags signal_flags
;
246 GType return_type
; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
248 const GType
*param_types
; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
252 /* --- signals --- */
253 guint
g_signal_newv (const gchar
*signal_name
,
255 GSignalFlags signal_flags
,
256 GClosure
*class_closure
,
257 GSignalAccumulator accumulator
,
259 GSignalCMarshaller c_marshaller
,
263 guint
g_signal_new_valist (const gchar
*signal_name
,
265 GSignalFlags signal_flags
,
266 GClosure
*class_closure
,
267 GSignalAccumulator accumulator
,
269 GSignalCMarshaller c_marshaller
,
273 guint
g_signal_new (const gchar
*signal_name
,
275 GSignalFlags signal_flags
,
277 GSignalAccumulator accumulator
,
279 GSignalCMarshaller c_marshaller
,
283 guint
g_signal_new_class_handler (const gchar
*signal_name
,
285 GSignalFlags signal_flags
,
286 GCallback class_handler
,
287 GSignalAccumulator accumulator
,
289 GSignalCMarshaller c_marshaller
,
294 void g_signal_emitv (const GValue
*instance_and_params
,
297 GValue
*return_value
);
298 void g_signal_emit_valist (gpointer instance
,
302 void g_signal_emit (gpointer instance
,
306 void g_signal_emit_by_name (gpointer instance
,
307 const gchar
*detailed_signal
,
309 guint
g_signal_lookup (const gchar
*name
,
311 const gchar
* g_signal_name (guint signal_id
);
312 void g_signal_query (guint signal_id
,
313 GSignalQuery
*query
);
314 guint
* g_signal_list_ids (GType itype
,
316 gboolean
g_signal_parse_name (const gchar
*detailed_signal
,
320 gboolean force_detail_quark
);
321 GSignalInvocationHint
* g_signal_get_invocation_hint (gpointer instance
);
324 /* --- signal emissions --- */
325 void g_signal_stop_emission (gpointer instance
,
328 void g_signal_stop_emission_by_name (gpointer instance
,
329 const gchar
*detailed_signal
);
330 gulong
g_signal_add_emission_hook (guint signal_id
,
332 GSignalEmissionHook hook_func
,
334 GDestroyNotify data_destroy
);
335 void g_signal_remove_emission_hook (guint signal_id
,
339 /* --- signal handlers --- */
340 gboolean
g_signal_has_handler_pending (gpointer instance
,
343 gboolean may_be_blocked
);
344 gulong
g_signal_connect_closure_by_id (gpointer instance
,
349 gulong
g_signal_connect_closure (gpointer instance
,
350 const gchar
*detailed_signal
,
353 gulong
g_signal_connect_data (gpointer instance
,
354 const gchar
*detailed_signal
,
357 GClosureNotify destroy_data
,
358 GConnectFlags connect_flags
);
359 void g_signal_handler_block (gpointer instance
,
361 void g_signal_handler_unblock (gpointer instance
,
363 void g_signal_handler_disconnect (gpointer instance
,
365 gboolean
g_signal_handler_is_connected (gpointer instance
,
367 gulong
g_signal_handler_find (gpointer instance
,
368 GSignalMatchType mask
,
374 guint
g_signal_handlers_block_matched (gpointer instance
,
375 GSignalMatchType mask
,
381 guint
g_signal_handlers_unblock_matched (gpointer instance
,
382 GSignalMatchType mask
,
388 guint
g_signal_handlers_disconnect_matched (gpointer instance
,
389 GSignalMatchType mask
,
397 /* --- overriding and chaining --- */
398 void g_signal_override_class_closure (guint signal_id
,
400 GClosure
*class_closure
);
401 void g_signal_override_class_handler (const gchar
*signal_name
,
403 GCallback class_handler
);
404 void g_signal_chain_from_overridden (const GValue
*instance_and_params
,
405 GValue
*return_value
);
406 void g_signal_chain_from_overridden_handler (gpointer instance
,
410 /* --- convenience --- */
413 * @instance: the instance to connect to.
414 * @detailed_signal: a string of the form "signal-name::detail".
415 * @c_handler: the #GCallback to connect.
416 * @data: data to pass to @c_handler calls.
418 * Connects a #GCallback function to a signal for a particular object.
420 * The handler will be called before the default handler of the signal.
422 * Returns: the handler id
424 #define g_signal_connect(instance, detailed_signal, c_handler, data) \
425 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, (GConnectFlags) 0)
427 * g_signal_connect_after:
428 * @instance: the instance to connect to.
429 * @detailed_signal: a string of the form "signal-name::detail".
430 * @c_handler: the #GCallback to connect.
431 * @data: data to pass to @c_handler calls.
433 * Connects a #GCallback function to a signal for a particular object.
435 * The handler will be called after the default handler of the signal.
437 * Returns: the handler id
439 #define g_signal_connect_after(instance, detailed_signal, c_handler, data) \
440 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_AFTER)
442 * g_signal_connect_swapped:
443 * @instance: the instance to connect to.
444 * @detailed_signal: a string of the form "signal-name::detail".
445 * @c_handler: the #GCallback to connect.
446 * @data: data to pass to @c_handler calls.
448 * Connects a #GCallback function to a signal for a particular object.
450 * The instance on which the signal is emitted and @data will be swapped when
451 * calling the handler.
453 * Returns: the handler id
455 #define g_signal_connect_swapped(instance, detailed_signal, c_handler, data) \
456 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_SWAPPED)
458 * g_signal_handlers_disconnect_by_func:
459 * @instance: The instance to remove handlers from.
460 * @func: The C closure callback of the handlers (useless for non-C closures).
461 * @data: The closure data of the handlers' closures.
463 * Disconnects all handlers on an instance that match @func and @data.
465 * Returns: The number of handlers that matched.
467 #define g_signal_handlers_disconnect_by_func(instance, func, data) \
468 g_signal_handlers_disconnect_matched ((instance), \
469 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
470 0, 0, NULL, (func), (data))
472 * g_signal_handlers_block_by_func:
473 * @instance: The instance to block handlers from.
474 * @func: The C closure callback of the handlers (useless for non-C closures).
475 * @data: The closure data of the handlers' closures.
477 * Blocks all handlers on an instance that match @func and @data.
479 * Returns: The number of handlers that matched.
481 #define g_signal_handlers_block_by_func(instance, func, data) \
482 g_signal_handlers_block_matched ((instance), \
483 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
484 0, 0, NULL, (func), (data))
486 * g_signal_handlers_unblock_by_func:
487 * @instance: The instance to unblock handlers from.
488 * @func: The C closure callback of the handlers (useless for non-C closures).
489 * @data: The closure data of the handlers' closures.
491 * Unblocks all handlers on an instance that match @func and @data.
493 * Returns: The number of handlers that matched.
495 #define g_signal_handlers_unblock_by_func(instance, func, data) \
496 g_signal_handlers_unblock_matched ((instance), \
497 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
498 0, 0, NULL, (func), (data))
501 gboolean
g_signal_accumulator_true_handled (GSignalInvocationHint
*ihint
,
503 const GValue
*handler_return
,
506 gboolean
g_signal_accumulator_first_wins (GSignalInvocationHint
*ihint
,
508 const GValue
*handler_return
,
512 void g_signal_handlers_destroy (gpointer instance
);
513 void _g_signals_destroy (GType itype
);
517 #endif /* __G_SIGNAL_H__ */