1 module gobject.gsignal;
2 
3 import gobject.gclosure;
4 import gobject.gvalue;
5 import gobject.gparam;
6 import gobject.gmarshal;
7 import gobject.gtype;
8 
9 import glib;
10 
11 import core.stdc.stdarg;
12 
13 
14 extern (C):
15 
16 alias GSignalCMarshaller = GClosureMarshal;
17 alias GSignalCVaMarshaller = GVaClosureMarshal;
18 
19 
20 alias GSignalEmissionHook = gboolean function (GSignalInvocationHint *ihint,
21 					 guint			n_param_values,
22 					 const(GValue)	       *param_values,
23 					 gpointer		data);
24 alias GSignalAccumulator = gboolean function (GSignalInvocationHint *ihint,
25 					 GValue		       *return_accu,
26 					 const(GValue)	       *handler_return,
27 					 gpointer               data);
28 
29 
30 enum GSignalFlags
31 {
32   G_SIGNAL_RUN_FIRST	= 1 << 0,
33   G_SIGNAL_RUN_LAST	= 1 << 1,
34   G_SIGNAL_RUN_CLEANUP	= 1 << 2,
35   G_SIGNAL_NO_RECURSE	= 1 << 3,
36   G_SIGNAL_DETAILED	= 1 << 4,
37   G_SIGNAL_ACTION	= 1 << 5,
38   G_SIGNAL_NO_HOOKS	= 1 << 6,
39   G_SIGNAL_MUST_COLLECT = 1 << 7,
40   G_SIGNAL_DEPRECATED   = 1 << 8
41 }
42 enum G_SIGNAL_FLAGS_MASK = 0x1ff;
43 
44 enum GConnectFlags
45 {
46   G_CONNECT_AFTER	= 1 << 0,
47   G_CONNECT_SWAPPED	= 1 << 1
48 }
49 
50 enum GSignalMatchType
51 {
52   G_SIGNAL_MATCH_ID	   = 1 << 0,
53   G_SIGNAL_MATCH_DETAIL	   = 1 << 1,
54   G_SIGNAL_MATCH_CLOSURE   = 1 << 2,
55   G_SIGNAL_MATCH_FUNC	   = 1 << 3,
56   G_SIGNAL_MATCH_DATA	   = 1 << 4,
57   G_SIGNAL_MATCH_UNBLOCKED = 1 << 5
58 }
59 enum G_SIGNAL_MATCH_MASK = 0x3f;
60 
61 
62 //#define	G_SIGNAL_TYPE_STATIC_SCOPE (G_TYPE_FLAG_RESERVED_ID_BIT)
63 
64 struct GSignalInvocationHint
65 {
66   guint		signal_id;
67   GQuark	detail;
68   GSignalFlags	run_type;
69 }
70 
71 struct GSignalQuery
72 {
73   guint		signal_id;
74   const(gchar)  *signal_name;
75   GType		itype;
76   GSignalFlags	signal_flags;
77   GType		return_type; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
78   guint		n_params;
79   const(GType)  *param_types; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
80 }
81 
82 
83 /* --- signals --- */
84 
85 guint                 g_signal_newv         (const(gchar)        *signal_name,
86 					     GType               itype,
87 					     GSignalFlags        signal_flags,
88 					     GClosure           *class_closure,
89 					     GSignalAccumulator	 accumulator,
90 					     gpointer		 accu_data,
91 					     GSignalCMarshaller  c_marshaller,
92 					     GType               return_type,
93 					     guint               n_params,
94 					     GType              *param_types);
95 
96 guint                 g_signal_new_valist   (const(gchar)        *signal_name,
97 					     GType               itype,
98 					     GSignalFlags        signal_flags,
99 					     GClosure           *class_closure,
100 					     GSignalAccumulator	 accumulator,
101 					     gpointer		 accu_data,
102 					     GSignalCMarshaller  c_marshaller,
103 					     GType               return_type,
104 					     guint               n_params,
105 					     va_list             args);
106 
107 guint                 g_signal_new          (const(gchar)        *signal_name,
108 					     GType               itype,
109 					     GSignalFlags        signal_flags,
110 					     guint               class_offset,
111 					     GSignalAccumulator	 accumulator,
112 					     gpointer		 accu_data,
113 					     GSignalCMarshaller  c_marshaller,
114 					     GType               return_type,
115 					     guint               n_params,
116 					     ...);
117 
118 guint            g_signal_new_class_handler (const(gchar)        *signal_name,
119                                              GType               itype,
120                                              GSignalFlags        signal_flags,
121                                              GCallback           class_handler,
122                                              GSignalAccumulator  accumulator,
123                                              gpointer            accu_data,
124                                              GSignalCMarshaller  c_marshaller,
125                                              GType               return_type,
126                                              guint               n_params,
127                                              ...);
128 
129 void             g_signal_set_va_marshaller (guint              signal_id,
130 					     GType              instance_type,
131 					     GSignalCVaMarshaller va_marshaller);
132 
133 
134 void                  g_signal_emitv        (const(GValue)       *instance_and_params,
135 					     guint               signal_id,
136 					     GQuark              detail,
137 					     GValue             *return_value);
138 
139 void                  g_signal_emit_valist  (gpointer            instance,
140 					     guint               signal_id,
141 					     GQuark              detail,
142 					     va_list             var_args);
143 
144 void                  g_signal_emit         (gpointer            instance,
145 					     guint               signal_id,
146 					     GQuark              detail,
147 					     ...);
148 
149 void                  g_signal_emit_by_name (gpointer            instance,
150 					     const(gchar)        *detailed_signal,
151 					     ...);
152 
153 guint                 g_signal_lookup       (const(gchar)        *name,
154 					     GType               itype);
155 
156 const(gchar) *         g_signal_name         (guint               signal_id);
157 
158 void                  g_signal_query        (guint               signal_id,
159 					     GSignalQuery       *query);
160 
161 guint*                g_signal_list_ids     (GType               itype,
162 					     guint              *n_ids);
163 
164 gboolean	      g_signal_parse_name   (const(gchar)	*detailed_signal,
165 					     GType		 itype,
166 					     guint		*signal_id_p,
167 					     GQuark		*detail_p,
168 					     gboolean		 force_detail_quark);
169 
170 GSignalInvocationHint* g_signal_get_invocation_hint (gpointer    instance);
171 
172 
173 /* --- signal emissions --- */
174 
175 void	g_signal_stop_emission		    (gpointer		  instance,
176 					     guint		  signal_id,
177 					     GQuark		  detail);
178 
179 void	g_signal_stop_emission_by_name	    (gpointer		  instance,
180 					     const(gchar)	 *detailed_signal);
181 
182 gulong	g_signal_add_emission_hook	    (guint		  signal_id,
183 					     GQuark		  detail,
184 					     GSignalEmissionHook  hook_func,
185 					     gpointer	       	  hook_data,
186 					     GDestroyNotify	  data_destroy);
187 
188 void	g_signal_remove_emission_hook	    (guint		  signal_id,
189 					     gulong		  hook_id);
190 
191 
192 /* --- signal handlers --- */
193 
194 gboolean g_signal_has_handler_pending	      (gpointer		  instance,
195 					       guint		  signal_id,
196 					       GQuark		  detail,
197 					       gboolean		  may_be_blocked);
198 
199 gulong	 g_signal_connect_closure_by_id	      (gpointer		  instance,
200 					       guint		  signal_id,
201 					       GQuark		  detail,
202 					       GClosure		 *closure,
203 					       gboolean		  after);
204 
205 gulong	 g_signal_connect_closure	      (gpointer		  instance,
206 					       const(gchar)       *detailed_signal,
207 					       GClosure		 *closure,
208 					       gboolean		  after);
209 
210 gulong	 g_signal_connect_data		      (gpointer		  instance,
211 					       const(gchar)	 *detailed_signal,
212 					       GCallback	  c_handler,
213 					       gpointer		  data,
214 					       GClosureNotify	  destroy_data,
215 					       GConnectFlags	  connect_flags);
216 
217 void	 g_signal_handler_block		      (gpointer		  instance,
218 					       gulong		  handler_id);
219 
220 void	 g_signal_handler_unblock	      (gpointer		  instance,
221 					       gulong		  handler_id);
222 
223 void	 g_signal_handler_disconnect	      (gpointer		  instance,
224 					       gulong		  handler_id);
225 
226 gboolean g_signal_handler_is_connected	      (gpointer		  instance,
227 					       gulong		  handler_id);
228 
229 gulong	 g_signal_handler_find		      (gpointer		  instance,
230 					       GSignalMatchType	  mask,
231 					       guint		  signal_id,
232 					       GQuark		  detail,
233 					       GClosure		 *closure,
234 					       gpointer		  func,
235 					       gpointer		  data);
236 
237 guint	 g_signal_handlers_block_matched      (gpointer		  instance,
238 					       GSignalMatchType	  mask,
239 					       guint		  signal_id,
240 					       GQuark		  detail,
241 					       GClosure		 *closure,
242 					       gpointer		  func,
243 					       gpointer		  data);
244 
245 guint	 g_signal_handlers_unblock_matched    (gpointer		  instance,
246 					       GSignalMatchType	  mask,
247 					       guint		  signal_id,
248 					       GQuark		  detail,
249 					       GClosure		 *closure,
250 					       gpointer		  func,
251 					       gpointer		  data);
252 
253 guint	 g_signal_handlers_disconnect_matched (gpointer		  instance,
254 					       GSignalMatchType	  mask,
255 					       guint		  signal_id,
256 					       GQuark		  detail,
257 					       GClosure		 *closure,
258 					       gpointer		  func,
259 					       gpointer		  data);
260 
261 
262 /* --- overriding and chaining --- */
263 
264 void    g_signal_override_class_closure       (guint              signal_id,
265                                                GType              instance_type,
266                                                GClosure          *class_closure);
267 
268 void    g_signal_override_class_handler       (const(gchar)       *signal_name,
269                                                GType              instance_type,
270                                                GCallback          class_handler);
271 
272 void    g_signal_chain_from_overridden        (const(GValue)      *instance_and_params,
273                                                GValue            *return_value);
274 
275 void   g_signal_chain_from_overridden_handler (gpointer           instance,
276                                                ...);
277 
278 
279 // /* --- convenience --- */
280 // /**
281 //  * g_signal_connect:
282 //  * @instance: the instance to connect to.
283 //  * @detailed_signal: a string of the form "signal-name::detail".
284 //  * @c_handler: the #GCallback to connect.
285 //  * @data: data to pass to @c_handler calls.
286 //  *
287 //  * Connects a #GCallback function to a signal for a particular object.
288 //  *
289 //  * The handler will be called before the default handler of the signal.
290 //  *
291 //  * Returns: the handler id (always greater than 0 for successful connections)
292 //  */
293 // #define g_signal_connect(instance, detailed_signal, c_handler, data) \
294 //     g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, (GConnectFlags) 0)
295 // /**
296 //  * g_signal_connect_after:
297 //  * @instance: the instance to connect to.
298 //  * @detailed_signal: a string of the form "signal-name::detail".
299 //  * @c_handler: the #GCallback to connect.
300 //  * @data: data to pass to @c_handler calls.
301 //  *
302 //  * Connects a #GCallback function to a signal for a particular object.
303 //  *
304 //  * The handler will be called after the default handler of the signal.
305 //  *
306 //  * Returns: the handler id (always greater than 0 for successful connections)
307 //  */
308 // #define g_signal_connect_after(instance, detailed_signal, c_handler, data) \
309 //     g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_AFTER)
310 // /**
311 //  * g_signal_connect_swapped:
312 //  * @instance: the instance to connect to.
313 //  * @detailed_signal: a string of the form "signal-name::detail".
314 //  * @c_handler: the #GCallback to connect.
315 //  * @data: data to pass to @c_handler calls.
316 //  *
317 //  * Connects a #GCallback function to a signal for a particular object.
318 //  *
319 //  * The instance on which the signal is emitted and @data will be swapped when
320 //  * calling the handler. This is useful when calling pre-existing functions to
321 //  * operate purely on the @data, rather than the @instance: swapping the
322 //  * parameters avoids the need to write a wrapper function.
323 //  *
324 //  * For example, this allows the shorter code:
325 //  * |[<!-- language="C" -->
326 //  * g_signal_connect_swapped (button, "clicked",
327 //  *                           (GCallback) gtk_widget_hide, other_widget);
328 //  * ]|
329 //  *
330 //  * Rather than the cumbersome:
331 //  * |[<!-- language="C" -->
332 //  * static void
333 //  * button_clicked_cb (GtkButton *button, GtkWidget *other_widget)
334 //  * {
335 //  *     gtk_widget_hide (other_widget);
336 //  * }
337 //  *
338 //  * …
339 //  *
340 //  * g_signal_connect (button, "clicked",
341 //  *                   (GCallback) button_clicked_cb, other_widget);
342 //  * ]|
343 //  *
344 //  * Returns: the handler ID (always greater than 0 for successful connections)
345 //  */
346 // #define g_signal_connect_swapped(instance, detailed_signal, c_handler, data) \
347 //     g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_SWAPPED)
348 // /**
349 //  * g_signal_handlers_disconnect_by_func:
350 //  * @instance: The instance to remove handlers from.
351 //  * @func: The C closure callback of the handlers (useless for non-C closures).
352 //  * @data: The closure data of the handlers' closures.
353 //  *
354 //  * Disconnects all handlers on an instance that match @func and @data.
355 //  *
356 //  * Returns: The number of handlers that matched.
357 //  */
358 // #define	g_signal_handlers_disconnect_by_func(instance, func, data)						\
359 //     g_signal_handlers_disconnect_matched ((instance),								\
360 // 					  (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA),	\
361 // 					  0, 0, NULL, (func), (data))
362 //
363 // /**
364 //  * g_signal_handlers_disconnect_by_data:
365 //  * @instance: The instance to remove handlers from
366 //  * @data: the closure data of the handlers' closures
367 //  *
368 //  * Disconnects all handlers on an instance that match @data.
369 //  *
370 //  * Returns: The number of handlers that matched.
371 //  *
372 //  * Since: 2.32
373 //  */
374 // #define g_signal_handlers_disconnect_by_data(instance, data) \
375 //   g_signal_handlers_disconnect_matched ((instance), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, (data))
376 //
377 // /**
378 //  * g_signal_handlers_block_by_func:
379 //  * @instance: The instance to block handlers from.
380 //  * @func: The C closure callback of the handlers (useless for non-C closures).
381 //  * @data: The closure data of the handlers' closures.
382 //  *
383 //  * Blocks all handlers on an instance that match @func and @data.
384 //  *
385 //  * Returns: The number of handlers that matched.
386 //  */
387 // #define	g_signal_handlers_block_by_func(instance, func, data)							\
388 //     g_signal_handlers_block_matched      ((instance),								\
389 // 				          (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA),	\
390 // 				          0, 0, NULL, (func), (data))
391 // /**
392 //  * g_signal_handlers_unblock_by_func:
393 //  * @instance: The instance to unblock handlers from.
394 //  * @func: The C closure callback of the handlers (useless for non-C closures).
395 //  * @data: The closure data of the handlers' closures.
396 //  *
397 //  * Unblocks all handlers on an instance that match @func and @data.
398 //  *
399 //  * Returns: The number of handlers that matched.
400 //  */
401 // #define	g_signal_handlers_unblock_by_func(instance, func, data)							\
402 //     g_signal_handlers_unblock_matched    ((instance),								\
403 // 				          (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA),	\
404 // 				          0, 0, NULL, (func), (data))
405 
406 
407 
408 gboolean g_signal_accumulator_true_handled (GSignalInvocationHint *ihint,
409 					    GValue                *return_accu,
410 					    const(GValue)          *handler_return,
411 					    gpointer               dummy);
412 
413 
414 gboolean g_signal_accumulator_first_wins   (GSignalInvocationHint *ihint,
415                                             GValue                *return_accu,
416                                             const(GValue)          *handler_return,
417                                             gpointer               dummy);
418 
419 /*< private >*/
420 
421 void	 g_signal_handlers_destroy	      (gpointer		  instance);
422 void	 _g_signals_destroy		      (GType		  itype);
423