1 module gobject.gobject;
2 
3 import gobject.gtype;
4 import gobject.gvalue;
5 import gobject.gparam;
6 import gobject.gclosure;
7 import gobject.gsignal;
8 import gobject.gboxed;
9 
10 import glib;
11 
12 import core.stdc.stdarg;
13 
14 extern (C):
15 
16 // /**
17 //  * G_TYPE_IS_OBJECT:
18 //  * @type: Type id to check
19 //  *
20 //  * Check if the passed in type id is a %G_TYPE_OBJECT or derived from it.
21 //  *
22 //  * Returns: %FALSE or %TRUE, indicating whether @type is a %G_TYPE_OBJECT.
23 //  */
24 bool G_TYPE_IS_OBJECT(T)(T t) { return G_TYPE_FUNDAMENTAL(t) == G_TYPE_OBJECT; }
25 // #define G_TYPE_IS_OBJECT(type)      (G_TYPE_FUNDAMENTAL (type) == G_TYPE_OBJECT)
26 
27 // /**
28 //  * G_OBJECT:
29 //  * @object: Object which is subject to casting.
30 //  *
31 //  * Casts a #GObject or derived pointer into a (GObject*) pointer.
32 //  * Depending on the current debugging level, this function may invoke
33 //  * certain runtime checks to identify invalid casts.
34 //  */
35 // #define G_OBJECT(object)            (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_OBJECT, GObject))
36 // /**
37 //  * G_OBJECT_CLASS:
38 //  * @class: a valid #GObjectClass
39 //  *
40 //  * Casts a derived #GObjectClass structure into a #GObjectClass structure.
41 //  */
42 // #define G_OBJECT_CLASS(class)       (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_OBJECT, GObjectClass))
43 // /**
44 //  * G_IS_OBJECT:
45 //  * @object: Instance to check for being a %G_TYPE_OBJECT.
46 //  *
47 //  * Checks whether a valid #GTypeInstance pointer is of type %G_TYPE_OBJECT.
48 //  */
49 // #if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_42
50 // #define G_IS_OBJECT(object)         (G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE ((object), G_TYPE_OBJECT))
51 // #else
52 // #define G_IS_OBJECT(object)         (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_OBJECT))
53 // #endif
54 // /**
55 //  * G_IS_OBJECT_CLASS:
56 //  * @class: a #GObjectClass
57 //  *
58 //  * Checks whether @class "is a" valid #GObjectClass structure of type
59 //  * %G_TYPE_OBJECT or derived.
60 //  */
61 // #define G_IS_OBJECT_CLASS(class)    (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_OBJECT))
62 // /**
63 //  * G_OBJECT_GET_CLASS:
64 //  * @object: a #GObject instance.
65 //  *
66 //  * Get the class structure associated to a #GObject instance.
67 //  *
68 //  * Returns: pointer to object class structure.
69 //  */
70 // #define G_OBJECT_GET_CLASS(object)  (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_OBJECT, GObjectClass))
71 // /**
72 //  * G_OBJECT_TYPE:
73 //  * @object: Object to return the type id for.
74 //  *
75 //  * Get the type id of an object.
76 //  *
77 //  * Returns: Type id of @object.
78 //  */
79 auto G_OBJECT_TYPE(O)(O object) { return G_TYPE_FROM_INSTANCE(object); }
80 // #define G_OBJECT_TYPE(object)       (G_TYPE_FROM_INSTANCE (object))
81 
82 // /**
83 //  * G_OBJECT_TYPE_NAME:
84 //  * @object: Object to return the type name for.
85 //  *
86 //  * Get the name of an object's type.
87 //  *
88 //  * Returns: Type name of @object. The string is owned by the type system and
89 //  *  should not be freed.
90 //  */
91 auto G_OBJECT_TYPE_NAME(O)(O object) { return g_type_name(G_OBJECT_TYPE(object)); }
92 // #define G_OBJECT_TYPE_NAME(object)  (g_type_name (G_OBJECT_TYPE (object)))
93 
94 // /**
95 //  * G_OBJECT_CLASS_TYPE:
96 //  * @class: a valid #GObjectClass
97 //  *
98 //  * Get the type id of a class structure.
99 //  *
100 //  * Returns: Type id of @class.
101 //  */
102 // #define G_OBJECT_CLASS_TYPE(class)  (G_TYPE_FROM_CLASS (class))
103 // /**
104 //  * G_OBJECT_CLASS_NAME:
105 //  * @class: a valid #GObjectClass
106 //  *
107 //  * Return the name of a class structure's type.
108 //  *
109 //  * Returns: Type name of @class. The string is owned by the type system and
110 //  *  should not be freed.
111 //  */
112 // #define G_OBJECT_CLASS_NAME(class)  (g_type_name (G_OBJECT_CLASS_TYPE (class)))
113 // /**
114 //  * G_VALUE_HOLDS_OBJECT:
115 //  * @value: a valid #GValue structure
116 //  *
117 //  * Checks whether the given #GValue can hold values derived from type %G_TYPE_OBJECT.
118 //  *
119 //  * Returns: %TRUE on success.
120 //  */
121 // #define G_VALUE_HOLDS_OBJECT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_OBJECT))
122 //
123 // /* --- type macros --- */
124 // /**
125 //  * G_TYPE_INITIALLY_UNOWNED:
126 //  *
127 //  * The type for #GInitiallyUnowned.
128 //  */
129 // #define G_TYPE_INITIALLY_UNOWNED	      (g_initially_unowned_get_type())
130 // /**
131 //  * G_INITIALLY_UNOWNED:
132 //  * @object: Object which is subject to casting.
133 //  *
134 //  * Casts a #GInitiallyUnowned or derived pointer into a (GInitiallyUnowned*)
135 //  * pointer. Depending on the current debugging level, this function may invoke
136 //  * certain runtime checks to identify invalid casts.
137 //  */
138 // #define G_INITIALLY_UNOWNED(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnowned))
139 // /**
140 //  * G_INITIALLY_UNOWNED_CLASS:
141 //  * @class: a valid #GInitiallyUnownedClass
142 //  *
143 //  * Casts a derived #GInitiallyUnownedClass structure into a
144 //  * #GInitiallyUnownedClass structure.
145 //  */
146 // #define G_INITIALLY_UNOWNED_CLASS(class)      (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnownedClass))
147 // /**
148 //  * G_IS_INITIALLY_UNOWNED:
149 //  * @object: Instance to check for being a %G_TYPE_INITIALLY_UNOWNED.
150 //  *
151 //  * Checks whether a valid #GTypeInstance pointer is of type %G_TYPE_INITIALLY_UNOWNED.
152 //  */
153 // #define G_IS_INITIALLY_UNOWNED(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_INITIALLY_UNOWNED))
154 // /**
155 //  * G_IS_INITIALLY_UNOWNED_CLASS:
156 //  * @class: a #GInitiallyUnownedClass
157 //  *
158 //  * Checks whether @class "is a" valid #GInitiallyUnownedClass structure of type
159 //  * %G_TYPE_INITIALLY_UNOWNED or derived.
160 //  */
161 // #define G_IS_INITIALLY_UNOWNED_CLASS(class)   (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_INITIALLY_UNOWNED))
162 // /**
163 //  * G_INITIALLY_UNOWNED_GET_CLASS:
164 //  * @object: a #GInitiallyUnowned instance.
165 //  *
166 //  * Get the class structure associated to a #GInitiallyUnowned instance.
167 //  *
168 //  * Returns: pointer to object class structure.
169 //  */
170 // #define G_INITIALLY_UNOWNED_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnownedClass))
171 // /* GInitiallyUnowned ia a GObject with initially floating reference count */
172 
173 
174 /* --- typedefs & structures --- */
175 alias GInitiallyUnowned = GObject;
176 alias GInitiallyUnownedClass = GObjectClass;
177 //typedef struct _GObjectConstructParam    GObjectConstructParam;
178 
179 alias GObjectGetPropertyFunc = void function (GObject      *object,
180                                          guint         property_id,
181                                          GValue       *value,
182                                          GParamSpec   *pspec);
183 
184 alias GObjectSetPropertyFunc = void function (GObject      *object,
185                                          guint         property_id,
186                                          const GValue *value,
187                                          GParamSpec   *pspec);
188 
189 alias GObjectFinalizeFunc = void function (GObject      *object);
190 
191 alias GWeakNotify = void function (gpointer      data,
192 					 GObject      *where_the_object_was);
193 
194 struct GObject
195 {
196   GTypeInstance  g_type_instance;
197 
198   /*< private >*/
199   guint ref_count;
200   GData         *qdata;
201 }
202 
203 struct  GObjectClass
204 {
205   GTypeClass   g_type_class;
206 
207   /*< private >*/
208   GSList      *construct_properties;
209 
210   /*< public >*/
211   /* seldom overidden */
212   GObject*   function     (GType                  type,
213                                  guint                  n_construct_properties,
214                                  GObjectConstructParam *construct_properties) constructor;
215   /* overridable methods */
216   void       function		(GObject        *object,
217                                          guint           property_id,
218                                          const(GValue)   *value,
219                                          GParamSpec     *pspec) set_property;
220   void       function		(GObject        *object,
221                                          guint           property_id,
222                                          GValue         *value,
223                                          GParamSpec     *pspec) get_property;
224   void       function			(GObject        *object) dispose;
225   void       function		(GObject        *object) finalize;
226   /* seldom overidden */
227   void       function (GObject      *object,
228 					     guint	   n_pspecs,
229 					     GParamSpec  **pspecs) dispatch_properties_changed;
230   /* signals */
231   void	     function			(GObject	*object,
232 					 GParamSpec	*pspec) notify;
233 
234   /* called when done constructing */
235   void	     function		(GObject	*object) constructed;
236 
237   /*< private >*/
238   gsize		flags;
239 
240   /* padding */
241   gpointer[6]	pdummy;
242 }
243 
244 struct GObjectConstructParam
245 {
246   GParamSpec *pspec;
247   GValue     *value;
248 }
249 
250 /**
251  * GInitiallyUnowned:
252  *
253  * All the fields in the GInitiallyUnowned structure
254  * are private to the #GInitiallyUnowned implementation and should never be
255  * accessed directly.
256  */
257 /**
258  * GInitiallyUnownedClass:
259  *
260  * The class structure for the GInitiallyUnowned type.
261  */
262 
263 
264 /* --- prototypes --- */
265 
266 GType       g_initially_unowned_get_type      ();
267 
268 void        g_object_class_install_property   (GObjectClass   *oclass,
269 					       guint           property_id,
270 					       GParamSpec     *pspec);
271 
272 GParamSpec* g_object_class_find_property      (GObjectClass   *oclass,
273 					       const(gchar)    *property_name);
274 
275 GParamSpec**g_object_class_list_properties    (GObjectClass   *oclass,
276 					       guint	      *n_properties);
277 
278 void        g_object_class_override_property  (GObjectClass   *oclass,
279 					       guint           property_id,
280 					       const(gchar)    *name);
281 
282 void        g_object_class_install_properties (GObjectClass   *oclass,
283                                                guint           n_pspecs,
284                                                GParamSpec    **pspecs);
285 
286 
287 void        g_object_interface_install_property (gpointer     g_iface,
288 						 GParamSpec  *pspec);
289 
290 GParamSpec* g_object_interface_find_property    (gpointer     g_iface,
291 						 const(gchar) *property_name);
292 
293 GParamSpec**g_object_interface_list_properties  (gpointer     g_iface,
294 						 guint       *n_properties_p);
295 
296 
297 pure GType       g_object_get_type                 ();
298 
299 gpointer    g_object_new                      (GType           object_type,
300 					       const(gchar)    *first_property_name,
301 					       ...);
302 
303 gpointer    g_object_newv		      (GType           object_type,
304 					       guint	       n_parameters,
305 					       GParameter     *parameters);
306 
307 GObject*    g_object_new_valist               (GType           object_type,
308 					       const(gchar)    *first_property_name,
309 					       va_list         var_args);
310 
311 void	    g_object_set                      (gpointer	       object,
312 					       const(gchar)    *first_property_name,
313 					       ...);
314 
315 void        g_object_get                      (gpointer        object,
316 					       const(gchar)    *first_property_name,
317 					       ...);
318 
319 gpointer    g_object_connect                  (gpointer	       object,
320 					       const(gchar)    *signal_spec,
321 					       ...);
322 
323 void	    g_object_disconnect               (gpointer	       object,
324 					       const(gchar)    *signal_spec,
325 					       ...);
326 
327 void        g_object_set_valist               (GObject        *object,
328 					       const(gchar)    *first_property_name,
329 					       va_list         var_args);
330 
331 void        g_object_get_valist               (GObject        *object,
332 					       const(gchar)    *first_property_name,
333 					       va_list         var_args);
334 
335 void        g_object_set_property             (GObject        *object,
336 					       const(gchar)    *property_name,
337 					       const(GValue)   *value);
338 
339 void        g_object_get_property             (GObject        *object,
340 					       const(gchar)    *property_name,
341 					       GValue         *value);
342 
343 void        g_object_freeze_notify            (GObject        *object);
344 
345 void        g_object_notify                   (GObject        *object,
346 					       const(gchar)    *property_name);
347 
348 void        g_object_notify_by_pspec          (GObject        *object,
349 					       GParamSpec     *pspec);
350 
351 void        g_object_thaw_notify              (GObject        *object);
352 
353 gboolean    g_object_is_floating    	      (gpointer        object);
354 
355 gpointer    g_object_ref_sink       	      (gpointer	       object);
356 
357 gpointer    g_object_ref                      (gpointer        object);
358 
359 void        g_object_unref                    (gpointer        object);
360 
361 void	    g_object_weak_ref		      (GObject	      *object,
362 					       GWeakNotify     notify,
363 					       gpointer	       data);
364 
365 void	    g_object_weak_unref		      (GObject	      *object,
366 					       GWeakNotify     notify,
367 					       gpointer	       data);
368 
369 void        g_object_add_weak_pointer         (GObject        *object,
370                                                gpointer       *weak_pointer_location);
371 
372 void        g_object_remove_weak_pointer      (GObject        *object,
373                                                gpointer       *weak_pointer_location);
374 
375 alias GToggleNotify = void function (gpointer      data,
376 			       GObject      *object,
377 			       gboolean      is_last_ref);
378 
379 
380 void g_object_add_toggle_ref    (GObject       *object,
381 				 GToggleNotify  notify,
382 				 gpointer       data);
383 
384 void g_object_remove_toggle_ref (GObject       *object,
385 				 GToggleNotify  notify,
386 				 gpointer       data);
387 
388 
389 gpointer    g_object_get_qdata                (GObject        *object,
390 					       GQuark          quark);
391 
392 void        g_object_set_qdata                (GObject        *object,
393 					       GQuark          quark,
394 					       gpointer        data);
395 
396 void        g_object_set_qdata_full           (GObject        *object,
397 					       GQuark          quark,
398 					       gpointer        data,
399 					       GDestroyNotify  destroy);
400 
401 gpointer    g_object_steal_qdata              (GObject        *object,
402 					       GQuark          quark);
403 
404 
405 gpointer    g_object_dup_qdata                (GObject        *object,
406                                                GQuark          quark,
407                                                GDuplicateFunc  dup_func,
408 					       gpointer         user_data);
409 
410 gboolean    g_object_replace_qdata            (GObject        *object,
411                                                GQuark          quark,
412                                                gpointer        oldval,
413                                                gpointer        newval,
414                                                GDestroyNotify  destroy,
415 					       GDestroyNotify *old_destroy);
416 
417 
418 gpointer    g_object_get_data                 (GObject        *object,
419 					       const(gchar)    *key);
420 
421 void        g_object_set_data                 (GObject        *object,
422 					       const(gchar)    *key,
423 					       gpointer        data);
424 
425 void        g_object_set_data_full            (GObject        *object,
426 					       const(gchar)    *key,
427 					       gpointer        data,
428 					       GDestroyNotify  destroy);
429 
430 gpointer    g_object_steal_data               (GObject        *object,
431 					       const(gchar)    *key);
432 
433 
434 gpointer    g_object_dup_data                 (GObject        *object,
435                                                const(gchar)    *key,
436                                                GDuplicateFunc  dup_func,
437 					       gpointer         user_data);
438 
439 gboolean    g_object_replace_data             (GObject        *object,
440                                                const(gchar)    *key,
441                                                gpointer        oldval,
442                                                gpointer        newval,
443                                                GDestroyNotify  destroy,
444 					       GDestroyNotify *old_destroy);
445 
446 
447 
448 void        g_object_watch_closure            (GObject        *object,
449 					       GClosure       *closure);
450 
451 GClosure*   g_cclosure_new_object             (GCallback       callback_func,
452 					       GObject	      *object);
453 
454 GClosure*   g_cclosure_new_object_swap        (GCallback       callback_func,
455 					       GObject	      *object);
456 
457 GClosure*   g_closure_new_object              (guint           sizeof_closure,
458 					       GObject        *object);
459 
460 void        g_value_set_object                (GValue         *value,
461 					       gpointer        v_object);
462 
463 gpointer    g_value_get_object                (const(GValue)   *value);
464 
465 gpointer    g_value_dup_object                (const(GValue)   *value);
466 
467 gulong	    g_signal_connect_object           (gpointer	       instance,
468 					       const(gchar)    *detailed_signal,
469 					       GCallback       c_handler,
470 					       gpointer	       gobject,
471 					       GConnectFlags   connect_flags);
472 
473 /*< protected >*/
474 
475 void        g_object_force_floating           (GObject        *object);
476 
477 void        g_object_run_dispose	      (GObject	      *object);
478 
479 
480 
481 void        g_value_take_object               (GValue         *value,
482 					       gpointer        v_object);
483 deprecated("use g_value_take_object")
484 void        g_value_set_object_take_ownership (GValue         *value,
485                                                gpointer        v_object);
486 
487 deprecated
488 gsize	    g_object_compat_control	      (gsize	       what,
489 					       gpointer	       data);
490 
491 /* --- implementation macros --- */
492 // #define G_OBJECT_WARN_INVALID_PSPEC(object, pname, property_id, pspec) \
493 // G_STMT_START { \
494 //   GObject *_glib__object = (GObject*) (object); \
495 //   GParamSpec *_glib__pspec = (GParamSpec*) (pspec); \
496 //   guint _glib__property_id = (property_id); \
497 //   g_warning ("%s: invalid %s id %u for \"%s\" of type '%s' in '%s'", \
498 //              G_STRLOC, \
499 //              (pname), \
500 //              _glib__property_id, \
501 //              _glib__pspec->name, \
502 //              g_type_name (G_PARAM_SPEC_TYPE (_glib__pspec)), \
503 //              G_OBJECT_TYPE_NAME (_glib__object)); \
504 // } G_STMT_END
505 // /**
506 //  * G_OBJECT_WARN_INVALID_PROPERTY_ID:
507 //  * @object: the #GObject on which set_property() or get_property() was called
508 //  * @property_id: the numeric id of the property
509 //  * @pspec: the #GParamSpec of the property
510 //  *
511 //  * This macro should be used to emit a standard warning about unexpected
512 //  * properties in set_property() and get_property() implementations.
513 //  */
514 // #define G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec) \
515 //     G_OBJECT_WARN_INVALID_PSPEC ((object), "property", (property_id), (pspec))
516 
517 
518 void    g_clear_object (GObject **object_ptr);
519 // #define g_clear_object(object_ptr) g_clear_pointer ((object_ptr), g_object_unref)
520 
521 struct GWeakRef {
522     /*<private>*/
523     union priv_t { gpointer p; }
524     priv_t priv;
525 }
526 
527 
528 void     g_weak_ref_init       (GWeakRef *weak_ref,
529                                 gpointer  object);
530 
531 void     g_weak_ref_clear      (GWeakRef *weak_ref);
532 
533 gpointer g_weak_ref_get        (GWeakRef *weak_ref);
534 
535 void     g_weak_ref_set        (GWeakRef *weak_ref,
536                                 gpointer  object);
537 
538