Updated Serbian translation
[platform/upstream/glib.git] / gobject / gsignal.h
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2  * Copyright (C) 2000-2001 Red Hat, Inc.
3  *
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.
8  *
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.
13  *
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.
18  */
19 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
20 #error "Only <glib-object.h> can be included directly."
21 #endif
22
23 #ifndef __G_SIGNAL_H__
24 #define __G_SIGNAL_H__
25
26 #include        <gobject/gclosure.h>
27 #include        <gobject/gvalue.h>
28 #include        <gobject/gparam.h>
29 #include        <gobject/gmarshal.h>
30
31 G_BEGIN_DECLS
32
33 /* --- typedefs --- */
34 typedef struct _GSignalQuery             GSignalQuery;
35 typedef struct _GSignalInvocationHint    GSignalInvocationHint;
36 /**
37  * GSignalCMarshaller:
38  * 
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
43  * signal system.
44  */
45 typedef GClosureMarshal                  GSignalCMarshaller;
46 /**
47  * GSignalCVaMarshaller:
48  * 
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.
52  */
53 typedef GVaClosureMarshal                GSignalCVaMarshaller;
54 /**
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.
62  * 
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.
66  * 
67  * You may not attach these to signals created with the #G_SIGNAL_NO_HOOKS flag.
68  * 
69  * Returns: whether it wants to stay connected. If it returns %FALSE, the signal 
70  *  hook is disconnected (and destroyed).
71  */
72 typedef gboolean (*GSignalEmissionHook) (GSignalInvocationHint *ihint,
73                                          guint                  n_param_values,
74                                          const GValue          *param_values,
75                                          gpointer               data);
76 /**
77  * GSignalAccumulator:
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.
83  * 
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.
90  * 
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.
94  */
95 typedef gboolean (*GSignalAccumulator)  (GSignalInvocationHint *ihint,
96                                          GValue                *return_accu,
97                                          const GValue          *handler_return,
98                                          gpointer               data);
99
100
101 /* --- run, match and connect types --- */
102 /**
103  * GSignalFlags:
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 
117  *  third-party code.
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.
124  * 
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.
128  */
129 typedef enum
130 {
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
140 } GSignalFlags;
141 /**
142  * G_SIGNAL_FLAGS_MASK:
143  * 
144  * A mask for all #GSignalFlags bits.
145  */
146 #define G_SIGNAL_FLAGS_MASK  0x1ff
147 /**
148  * GConnectFlags:
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.
153  * 
154  * The connection flags are used to specify the behaviour of a signal's 
155  * connection.
156  */
157 typedef enum
158 {
159   G_CONNECT_AFTER       = 1 << 0,
160   G_CONNECT_SWAPPED     = 1 << 1
161 } GConnectFlags;
162 /**
163  * GSignalMatchType:
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.
170  * 
171  * The match types specify what g_signal_handlers_block_matched(),
172  * g_signal_handlers_unblock_matched() and g_signal_handlers_disconnect_matched()
173  * match signals by.
174  */
175 typedef enum
176 {
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
183 } GSignalMatchType;
184 /**
185  * G_SIGNAL_MATCH_MASK:
186  * 
187  * A mask for all #GSignalMatchType bits.
188  */
189 #define G_SIGNAL_MATCH_MASK  0x3f
190 /**
191  * G_SIGNAL_TYPE_STATIC_SCOPE:
192  * 
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.
196  * 
197  * To flag a signal argument in this way, add 
198  * <literal>| G_SIGNAL_TYPE_STATIC_SCOPE</literal> to the corresponding argument
199  * of g_signal_new().
200  * |[
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),
205  *       NULL, NULL,
206  *       _gtk_marshal_VOID__BOXED,
207  *       G_TYPE_NONE, 1,
208  *       GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
209  * ]|
210  */
211 #define G_SIGNAL_TYPE_STATIC_SCOPE (G_TYPE_FLAG_RESERVED_ID_BIT)
212
213
214 /* --- signal information --- */
215 /**
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.
222  * 
223  * The #GSignalInvocationHint structure is used to pass on additional information
224  * to callbacks during a signal emission.
225  */
226 struct _GSignalInvocationHint
227 {
228   guint         signal_id;
229   GQuark        detail;
230   GSignalFlags  run_type;
231 };
232 /**
233  * GSignalQuery:
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:
243  *  <programlisting>
244  *  @return_type callback (#gpointer     data1,
245  *  [param_types param_names,]
246  *  gpointer     data2);
247  *  </programlisting>
248  * 
249  * A structure holding in-depth information for a specific signal. It is
250  * filled in by the g_signal_query() function.
251  */
252 struct _GSignalQuery
253 {
254   guint         signal_id;
255   const gchar  *signal_name;
256   GType         itype;
257   GSignalFlags  signal_flags;
258   GType         return_type; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
259   guint         n_params;
260   const GType  *param_types; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
261 };
262
263
264 /* --- signals --- */
265 guint                 g_signal_newv         (const gchar        *signal_name,
266                                              GType               itype,
267                                              GSignalFlags        signal_flags,
268                                              GClosure           *class_closure,
269                                              GSignalAccumulator  accumulator,
270                                              gpointer            accu_data,
271                                              GSignalCMarshaller  c_marshaller,
272                                              GType               return_type,
273                                              guint               n_params,
274                                              GType              *param_types);
275 guint                 g_signal_new_valist   (const gchar        *signal_name,
276                                              GType               itype,
277                                              GSignalFlags        signal_flags,
278                                              GClosure           *class_closure,
279                                              GSignalAccumulator  accumulator,
280                                              gpointer            accu_data,
281                                              GSignalCMarshaller  c_marshaller,
282                                              GType               return_type,
283                                              guint               n_params,
284                                              va_list             args);
285 guint                 g_signal_new          (const gchar        *signal_name,
286                                              GType               itype,
287                                              GSignalFlags        signal_flags,
288                                              guint               class_offset,
289                                              GSignalAccumulator  accumulator,
290                                              gpointer            accu_data,
291                                              GSignalCMarshaller  c_marshaller,
292                                              GType               return_type,
293                                              guint               n_params,
294                                              ...);
295 guint            g_signal_new_class_handler (const gchar        *signal_name,
296                                              GType               itype,
297                                              GSignalFlags        signal_flags,
298                                              GCallback           class_handler,
299                                              GSignalAccumulator  accumulator,
300                                              gpointer            accu_data,
301                                              GSignalCMarshaller  c_marshaller,
302                                              GType               return_type,
303                                              guint               n_params,
304                                              ...);
305 void             g_signal_set_va_marshaller (guint              signal_id,
306                                              GType              instance_type,
307                                              GSignalCVaMarshaller va_marshaller);
308
309 void                  g_signal_emitv        (const GValue       *instance_and_params,
310                                              guint               signal_id,
311                                              GQuark              detail,
312                                              GValue             *return_value);
313 void                  g_signal_emit_valist  (gpointer            instance,
314                                              guint               signal_id,
315                                              GQuark              detail,
316                                              va_list             var_args);
317 void                  g_signal_emit         (gpointer            instance,
318                                              guint               signal_id,
319                                              GQuark              detail,
320                                              ...);
321 void                  g_signal_emit_by_name (gpointer            instance,
322                                              const gchar        *detailed_signal,
323                                              ...);
324 guint                 g_signal_lookup       (const gchar        *name,
325                                              GType               itype);
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,
330                                              guint              *n_ids);
331 gboolean              g_signal_parse_name   (const gchar        *detailed_signal,
332                                              GType               itype,
333                                              guint              *signal_id_p,
334                                              GQuark             *detail_p,
335                                              gboolean            force_detail_quark);
336 GSignalInvocationHint* g_signal_get_invocation_hint (gpointer    instance);
337
338
339 /* --- signal emissions --- */
340 void    g_signal_stop_emission              (gpointer             instance,
341                                              guint                signal_id,
342                                              GQuark               detail);
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,
346                                              GQuark               detail,
347                                              GSignalEmissionHook  hook_func,
348                                              gpointer             hook_data,
349                                              GDestroyNotify       data_destroy);
350 void    g_signal_remove_emission_hook       (guint                signal_id,
351                                              gulong               hook_id);
352
353
354 /* --- signal handlers --- */
355 gboolean g_signal_has_handler_pending         (gpointer           instance,
356                                                guint              signal_id,
357                                                GQuark             detail,
358                                                gboolean           may_be_blocked);
359 gulong   g_signal_connect_closure_by_id       (gpointer           instance,
360                                                guint              signal_id,
361                                                GQuark             detail,
362                                                GClosure          *closure,
363                                                gboolean           after);
364 gulong   g_signal_connect_closure             (gpointer           instance,
365                                                const gchar       *detailed_signal,
366                                                GClosure          *closure,
367                                                gboolean           after);
368 gulong   g_signal_connect_data                (gpointer           instance,
369                                                const gchar       *detailed_signal,
370                                                GCallback          c_handler,
371                                                gpointer           data,
372                                                GClosureNotify     destroy_data,
373                                                GConnectFlags      connect_flags);
374 void     g_signal_handler_block               (gpointer           instance,
375                                                gulong             handler_id);
376 void     g_signal_handler_unblock             (gpointer           instance,
377                                                gulong             handler_id);
378 void     g_signal_handler_disconnect          (gpointer           instance,
379                                                gulong             handler_id);
380 gboolean g_signal_handler_is_connected        (gpointer           instance,
381                                                gulong             handler_id);
382 gulong   g_signal_handler_find                (gpointer           instance,
383                                                GSignalMatchType   mask,
384                                                guint              signal_id,
385                                                GQuark             detail,
386                                                GClosure          *closure,
387                                                gpointer           func,
388                                                gpointer           data);
389 guint    g_signal_handlers_block_matched      (gpointer           instance,
390                                                GSignalMatchType   mask,
391                                                guint              signal_id,
392                                                GQuark             detail,
393                                                GClosure          *closure,
394                                                gpointer           func,
395                                                gpointer           data);
396 guint    g_signal_handlers_unblock_matched    (gpointer           instance,
397                                                GSignalMatchType   mask,
398                                                guint              signal_id,
399                                                GQuark             detail,
400                                                GClosure          *closure,
401                                                gpointer           func,
402                                                gpointer           data);
403 guint    g_signal_handlers_disconnect_matched (gpointer           instance,
404                                                GSignalMatchType   mask,
405                                                guint              signal_id,
406                                                GQuark             detail,
407                                                GClosure          *closure,
408                                                gpointer           func,
409                                                gpointer           data);
410
411
412 /* --- overriding and chaining --- */
413 void    g_signal_override_class_closure       (guint              signal_id,
414                                                GType              instance_type,
415                                                GClosure          *class_closure);
416 void    g_signal_override_class_handler       (const gchar       *signal_name,
417                                                GType              instance_type,
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,
422                                                ...);
423
424
425 /* --- convenience --- */
426 /**
427  * g_signal_connect:
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.
432  * 
433  * Connects a #GCallback function to a signal for a particular object.
434  * 
435  * The handler will be called before the default handler of the signal.
436  * 
437  * Returns: the handler id
438  */
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)
441 /**
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.
447  * 
448  * Connects a #GCallback function to a signal for a particular object.
449  * 
450  * The handler will be called after the default handler of the signal.
451  * 
452  * Returns: the handler id
453  */
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)
456 /**
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.
462  * 
463  * Connects a #GCallback function to a signal for a particular object.
464  * 
465  * The instance on which the signal is emitted and @data will be swapped when 
466  * calling the handler.
467  * 
468  * Returns: the handler id
469  */
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)
472 /**
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.
477  * 
478  * Disconnects all handlers on an instance that match @func and @data.
479  * 
480  * Returns: The number of handlers that matched.
481  */
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))
486
487 /**
488  * g_signal_handlers_disconnect_by_data:
489  * @instance: The instance to remove handlers from
490  * @data: the closure data of the handlers' closures
491  *
492  * Disconnects all handlers on an instance that match @data.
493  *
494  * Returns: The number of handlers that matched.
495  *
496  * Since: 2.32
497  */
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))
500
501 /**
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.
506  * 
507  * Blocks all handlers on an instance that match @func and @data.
508  * 
509  * Returns: The number of handlers that matched.
510  */
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))
515 /**
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.
520  * 
521  * Unblocks all handlers on an instance that match @func and @data.
522  * 
523  * Returns: The number of handlers that matched.
524  */
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))
529
530
531 gboolean g_signal_accumulator_true_handled (GSignalInvocationHint *ihint,
532                                             GValue                *return_accu,
533                                             const GValue          *handler_return,
534                                             gpointer               dummy);
535
536 gboolean g_signal_accumulator_first_wins   (GSignalInvocationHint *ihint,
537                                             GValue                *return_accu,
538                                             const GValue          *handler_return,
539                                             gpointer               dummy);
540
541 /*< private >*/
542 void     g_signal_handlers_destroy            (gpointer           instance);
543 void     _g_signals_destroy                   (GType              itype);
544
545 G_END_DECLS
546
547 #endif /* __G_SIGNAL_H__ */