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