Include gtypes.h not gobject/gtype.h
[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 #ifndef __G_SIGNAL_H__
20 #define __G_SIGNAL_H__
21
22 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
23 #error "Only <glib-object.h> can be included directly."
24 #endif
25
26 #include        <gobject/gclosure.h>
27 #include        <gobject/gvalue.h>
28 #include        <gobject/gparam.h>
29 #include        <gobject/gmarshal.h>
30 #include        <signal.h>
31
32 G_BEGIN_DECLS
33
34 /* --- typedefs --- */
35 typedef struct _GSignalQuery             GSignalQuery;
36 typedef struct _GSignalInvocationHint    GSignalInvocationHint;
37 typedef GClosureMarshal                  GSignalCMarshaller;
38 typedef gboolean (*GSignalEmissionHook) (GSignalInvocationHint *ihint,
39                                          guint                  n_param_values,
40                                          const GValue          *param_values,
41                                          gpointer               data);
42 typedef gboolean (*GSignalAccumulator)  (GSignalInvocationHint *ihint,
43                                          GValue                *return_accu,
44                                          const GValue          *handler_return,
45                                          gpointer               data);
46
47
48 /* --- run, match and connect types --- */
49 typedef enum
50 {
51   G_SIGNAL_RUN_FIRST    = 1 << 0,
52   G_SIGNAL_RUN_LAST     = 1 << 1,
53   G_SIGNAL_RUN_CLEANUP  = 1 << 2,
54   G_SIGNAL_NO_RECURSE   = 1 << 3,
55   G_SIGNAL_DETAILED     = 1 << 4,
56   G_SIGNAL_ACTION       = 1 << 5,
57   G_SIGNAL_NO_HOOKS     = 1 << 6
58 } GSignalFlags;
59 #define G_SIGNAL_FLAGS_MASK  0x7f
60 typedef enum
61 {
62   G_CONNECT_AFTER       = 1 << 0,
63   G_CONNECT_SWAPPED     = 1 << 1
64 } GConnectFlags;
65 typedef enum
66 {
67   G_SIGNAL_MATCH_ID        = 1 << 0,
68   G_SIGNAL_MATCH_DETAIL    = 1 << 1,
69   G_SIGNAL_MATCH_CLOSURE   = 1 << 2,
70   G_SIGNAL_MATCH_FUNC      = 1 << 3,
71   G_SIGNAL_MATCH_DATA      = 1 << 4,
72   G_SIGNAL_MATCH_UNBLOCKED = 1 << 5
73 } GSignalMatchType;
74 #define G_SIGNAL_MATCH_MASK  0x3f
75 #define G_SIGNAL_TYPE_STATIC_SCOPE (G_TYPE_FLAG_RESERVED_ID_BIT)
76
77
78 /* --- signal information --- */
79 struct _GSignalInvocationHint
80 {
81   guint         signal_id;
82   GQuark        detail;
83   GSignalFlags  run_type;
84 };
85 struct _GSignalQuery
86 {
87   guint         signal_id;
88   const gchar  *signal_name;
89   GType         itype;
90   GSignalFlags  signal_flags;
91   GType         return_type; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
92   guint         n_params;
93   const GType  *param_types; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
94 };
95
96
97 /* --- signals --- */
98 guint                 g_signal_newv         (const gchar        *signal_name,
99                                              GType               itype,
100                                              GSignalFlags        signal_flags,
101                                              GClosure           *class_closure,
102                                              GSignalAccumulator  accumulator,
103                                              gpointer            accu_data,
104                                              GSignalCMarshaller  c_marshaller,
105                                              GType               return_type,
106                                              guint               n_params,
107                                              GType              *param_types);
108 guint                 g_signal_new_valist   (const gchar        *signal_name,
109                                              GType               itype,
110                                              GSignalFlags        signal_flags,
111                                              GClosure           *class_closure,
112                                              GSignalAccumulator  accumulator,
113                                              gpointer            accu_data,
114                                              GSignalCMarshaller  c_marshaller,
115                                              GType               return_type,
116                                              guint               n_params,
117                                              va_list             args);
118 guint                 g_signal_new          (const gchar        *signal_name,
119                                              GType               itype,
120                                              GSignalFlags        signal_flags,
121                                              guint               class_offset,
122                                              GSignalAccumulator  accumulator,
123                                              gpointer            accu_data,
124                                              GSignalCMarshaller  c_marshaller,
125                                              GType               return_type,
126                                              guint               n_params,
127                                              ...);
128 void                  g_signal_emitv        (const GValue       *instance_and_params,
129                                              guint               signal_id,
130                                              GQuark              detail,
131                                              GValue             *return_value);
132 void                  g_signal_emit_valist  (gpointer            instance,
133                                              guint               signal_id,
134                                              GQuark              detail,
135                                              va_list             var_args);
136 void                  g_signal_emit         (gpointer            instance,
137                                              guint               signal_id,
138                                              GQuark              detail,
139                                              ...);
140 void                  g_signal_emit_by_name (gpointer            instance,
141                                              const gchar        *detailed_signal,
142                                              ...);
143 guint                 g_signal_lookup       (const gchar        *name,
144                                              GType               itype);
145 G_CONST_RETURN gchar* g_signal_name         (guint               signal_id);
146 void                  g_signal_query        (guint               signal_id,
147                                              GSignalQuery       *query);
148 guint*                g_signal_list_ids     (GType               itype,
149                                              guint              *n_ids);
150 gboolean              g_signal_parse_name   (const gchar        *detailed_signal,
151                                              GType               itype,
152                                              guint              *signal_id_p,
153                                              GQuark             *detail_p,
154                                              gboolean            force_detail_quark);
155
156
157 /* --- signal emissions --- */
158 void    g_signal_stop_emission              (gpointer             instance,
159                                              guint                signal_id,
160                                              GQuark               detail);
161 void    g_signal_stop_emission_by_name      (gpointer             instance,
162                                              const gchar         *detailed_signal);
163 gulong  g_signal_add_emission_hook          (guint                signal_id,
164                                              GQuark               quark,
165                                              GSignalEmissionHook  hook_func,
166                                              gpointer             hook_data,
167                                              GDestroyNotify       data_destroy);
168 void    g_signal_remove_emission_hook       (guint                signal_id,
169                                              gulong               hook_id);
170
171
172 /* --- signal handlers --- */
173 gboolean g_signal_has_handler_pending         (gpointer           instance,
174                                                guint              signal_id,
175                                                GQuark             detail,
176                                                gboolean           may_be_blocked);
177 gulong   g_signal_connect_closure_by_id       (gpointer           instance,
178                                                guint              signal_id,
179                                                GQuark             detail,
180                                                GClosure          *closure,
181                                                gboolean           after);
182 gulong   g_signal_connect_closure             (gpointer           instance,
183                                                const gchar       *detailed_signal,
184                                                GClosure          *closure,
185                                                gboolean           after);
186 gulong   g_signal_connect_data                (gpointer           instance,
187                                                const gchar       *detailed_signal,
188                                                GCallback          c_handler,
189                                                gpointer           data,
190                                                GClosureNotify     destroy_data,
191                                                GConnectFlags      connect_flags);
192 void     g_signal_handler_block               (gpointer           instance,
193                                                gulong             handler_id);
194 void     g_signal_handler_unblock             (gpointer           instance,
195                                                gulong             handler_id);
196 void     g_signal_handler_disconnect          (gpointer           instance,
197                                                gulong             handler_id);
198 gboolean g_signal_handler_is_connected        (gpointer           instance,
199                                                gulong             handler_id);
200 gulong   g_signal_handler_find                (gpointer           instance,
201                                                GSignalMatchType   mask,
202                                                guint              signal_id,
203                                                GQuark             detail,
204                                                GClosure          *closure,
205                                                gpointer           func,
206                                                gpointer           data);
207 guint    g_signal_handlers_block_matched      (gpointer           instance,
208                                                GSignalMatchType   mask,
209                                                guint              signal_id,
210                                                GQuark             detail,
211                                                GClosure          *closure,
212                                                gpointer           func,
213                                                gpointer           data);
214 guint    g_signal_handlers_unblock_matched    (gpointer           instance,
215                                                GSignalMatchType   mask,
216                                                guint              signal_id,
217                                                GQuark             detail,
218                                                GClosure          *closure,
219                                                gpointer           func,
220                                                gpointer           data);
221 guint    g_signal_handlers_disconnect_matched (gpointer           instance,
222                                                GSignalMatchType   mask,
223                                                guint              signal_id,
224                                                GQuark             detail,
225                                                GClosure          *closure,
226                                                gpointer           func,
227                                                gpointer           data);
228
229
230 /* --- chaining for language bindings --- */
231 void    g_signal_override_class_closure       (guint              signal_id,
232                                                GType              instance_type,
233                                                GClosure          *class_closure);
234 void    g_signal_chain_from_overridden        (const GValue      *instance_and_params,
235                                                guint              signal_id,
236                                                GValue            *return_value);
237
238
239 /* --- convenience --- */
240 #define g_signal_connect(instance, detailed_signal, c_handler, data) \
241     g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, 0)
242 #define g_signal_connect_after(instance, detailed_signal, c_handler, data) \
243     g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_AFTER)
244 #define g_signal_connect_swapped(instance, detailed_signal, c_handler, data) \
245     g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_SWAPPED)
246 #define g_signal_handlers_disconnect_by_func(instance, func, data) \
247     g_signal_handlers_disconnect_matched ((instance), G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, \
248                                           0, 0, NULL, (func), (data))
249 #define g_signal_handlers_block_by_func(instance, func, data) \
250     g_signal_handlers_block_matched ((instance), G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, \
251                                      0, 0, NULL, (func), (data))
252 #define g_signal_handlers_unblock_by_func(instance, func, data) \
253     g_signal_handlers_unblock_matched ((instance), G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, \
254                                        0, 0, NULL, (func), (data))
255
256
257 /*< private >*/
258 void     g_signal_handlers_destroy            (gpointer           instance);
259 void     _g_signals_destroy                   (GType              itype);
260
261 G_END_DECLS
262
263 #endif /* __G_SIGNAL_H__ */