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 * 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: The individual parameter types for user callbacks, note that the
242 * 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 guint g_signal_newv (const gchar *signal_name,
267 GSignalFlags signal_flags,
268 GClosure *class_closure,
269 GSignalAccumulator accumulator,
271 GSignalCMarshaller c_marshaller,
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 guint g_signal_new (const gchar *signal_name,
287 GSignalFlags signal_flags,
289 GSignalAccumulator accumulator,
291 GSignalCMarshaller c_marshaller,
295 guint g_signal_new_class_handler (const gchar *signal_name,
297 GSignalFlags signal_flags,
298 GCallback class_handler,
299 GSignalAccumulator accumulator,
301 GSignalCMarshaller c_marshaller,
305 void g_signal_set_va_marshaller (guint signal_id,
307 GSignalCVaMarshaller va_marshaller);
309 void g_signal_emitv (const GValue *instance_and_params,
312 GValue *return_value);
313 void g_signal_emit_valist (gpointer instance,
317 void g_signal_emit (gpointer instance,
321 void g_signal_emit_by_name (gpointer instance,
322 const gchar *detailed_signal,
324 guint g_signal_lookup (const gchar *name,
326 const gchar * g_signal_name (guint signal_id);
327 void g_signal_query (guint signal_id,
328 GSignalQuery *query);
329 guint* g_signal_list_ids (GType itype,
331 gboolean g_signal_parse_name (const gchar *detailed_signal,
335 gboolean force_detail_quark);
336 GSignalInvocationHint* g_signal_get_invocation_hint (gpointer instance);
339 /* --- signal emissions --- */
340 void g_signal_stop_emission (gpointer instance,
343 void g_signal_stop_emission_by_name (gpointer instance,
344 const gchar *detailed_signal);
345 gulong g_signal_add_emission_hook (guint signal_id,
347 GSignalEmissionHook hook_func,
349 GDestroyNotify data_destroy);
350 void g_signal_remove_emission_hook (guint signal_id,
354 /* --- signal handlers --- */
355 gboolean g_signal_has_handler_pending (gpointer instance,
358 gboolean may_be_blocked);
359 gulong g_signal_connect_closure_by_id (gpointer instance,
364 gulong g_signal_connect_closure (gpointer instance,
365 const gchar *detailed_signal,
368 gulong g_signal_connect_data (gpointer instance,
369 const gchar *detailed_signal,
372 GClosureNotify destroy_data,
373 GConnectFlags connect_flags);
374 void g_signal_handler_block (gpointer instance,
376 void g_signal_handler_unblock (gpointer instance,
378 void g_signal_handler_disconnect (gpointer instance,
380 gboolean g_signal_handler_is_connected (gpointer instance,
382 gulong g_signal_handler_find (gpointer instance,
383 GSignalMatchType mask,
389 guint g_signal_handlers_block_matched (gpointer instance,
390 GSignalMatchType mask,
396 guint g_signal_handlers_unblock_matched (gpointer instance,
397 GSignalMatchType mask,
403 guint g_signal_handlers_disconnect_matched (gpointer instance,
404 GSignalMatchType mask,
412 /* --- overriding and chaining --- */
413 void g_signal_override_class_closure (guint signal_id,
415 GClosure *class_closure);
416 void g_signal_override_class_handler (const gchar *signal_name,
418 GCallback class_handler);
419 void g_signal_chain_from_overridden (const GValue *instance_and_params,
420 GValue *return_value);
421 void g_signal_chain_from_overridden_handler (gpointer instance,
425 /* --- convenience --- */
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 before the default handler of the signal.
437 * Returns: the handler id
439 #define g_signal_connect(instance, detailed_signal, c_handler, data) \
440 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, (GConnectFlags) 0)
442 * g_signal_connect_after:
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 handler will be called after the default handler of the signal.
452 * Returns: the handler id
454 #define g_signal_connect_after(instance, detailed_signal, c_handler, data) \
455 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_AFTER)
457 * g_signal_connect_swapped:
458 * @instance: the instance to connect to.
459 * @detailed_signal: a string of the form "signal-name::detail".
460 * @c_handler: the #GCallback to connect.
461 * @data: data to pass to @c_handler calls.
463 * Connects a #GCallback function to a signal for a particular object.
465 * The instance on which the signal is emitted and @data will be swapped when
466 * calling the handler.
468 * Returns: the handler id
470 #define g_signal_connect_swapped(instance, detailed_signal, c_handler, data) \
471 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_SWAPPED)
473 * g_signal_handlers_disconnect_by_func:
474 * @instance: The instance to remove handlers from.
475 * @func: The C closure callback of the handlers (useless for non-C closures).
476 * @data: The closure data of the handlers' closures.
478 * Disconnects all handlers on an instance that match @func and @data.
480 * Returns: The number of handlers that matched.
482 #define g_signal_handlers_disconnect_by_func(instance, func, data) \
483 g_signal_handlers_disconnect_matched ((instance), \
484 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
485 0, 0, NULL, (func), (data))
488 * g_signal_handlers_disconnect_by_data:
489 * @instance: The instance to remove handlers from
490 * @data: the closure data of the handlers' closures
492 * Disconnects all handlers on an instance that match @data.
494 * Returns: The number of handlers that matched.
498 #define g_signal_handlers_disconnect_by_data(instance, data) \
499 g_signal_handlers_disconnect_matched ((instance), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, (data))
502 * g_signal_handlers_block_by_func:
503 * @instance: The instance to block handlers from.
504 * @func: The C closure callback of the handlers (useless for non-C closures).
505 * @data: The closure data of the handlers' closures.
507 * Blocks all handlers on an instance that match @func and @data.
509 * Returns: The number of handlers that matched.
511 #define g_signal_handlers_block_by_func(instance, func, data) \
512 g_signal_handlers_block_matched ((instance), \
513 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
514 0, 0, NULL, (func), (data))
516 * g_signal_handlers_unblock_by_func:
517 * @instance: The instance to unblock handlers from.
518 * @func: The C closure callback of the handlers (useless for non-C closures).
519 * @data: The closure data of the handlers' closures.
521 * Unblocks all handlers on an instance that match @func and @data.
523 * Returns: The number of handlers that matched.
525 #define g_signal_handlers_unblock_by_func(instance, func, data) \
526 g_signal_handlers_unblock_matched ((instance), \
527 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
528 0, 0, NULL, (func), (data))
531 gboolean g_signal_accumulator_true_handled (GSignalInvocationHint *ihint,
533 const GValue *handler_return,
536 gboolean g_signal_accumulator_first_wins (GSignalInvocationHint *ihint,
538 const GValue *handler_return,
542 void g_signal_handlers_destroy (gpointer instance);
543 void _g_signals_destroy (GType itype);
547 #endif /* __G_SIGNAL_H__ */