alternative to assert
[gtkD.git] / gtkD / src / gobject / ObjectG.d
blobf7bb0e79d1146bc6f5bed4bc642b869f318f3bfd
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD 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
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = gobject-The-Base-Object-Type.html
26 * outPack = gobject
27 * outFile = ObjectG
28 * strct = GObject
29 * realStrct=
30 * ctorStrct=
31 * clss = ObjectG
32 * interf =
33 * class Code: Yes
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_object_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * - g_object_set_data_full
44 * imports:
45 * - gobject.ParamSpec
46 * - gobject.Value
47 * - gobject.Closure
48 * - std.gc
49 * - glib.Str
50 * structWrap:
51 * - GClosure* -> Closure
52 * - GParamSpec* -> ParamSpec
53 * - GValue* -> Value
54 * module aliases:
55 * local aliases:
58 module gobject.ObjectG;
60 version(noAssert)
62 version(Tango)
64 import tango.io.Stdout; // use the tango loging?
68 private import gtkc.gobjecttypes;
70 private import gtkc.gobject;
73 private import gobject.ParamSpec;
74 private import gobject.Value;
75 private import gobject.Closure;
76 private import glib.Str;
79 version(Tango) {
80 private import tango.core.Memory;
81 } else {
82 private import std.gc;
88 /**
89 * Description
90 * GObject is the fundamental type providing the common attributes and methods
91 * for all object types in GTK+, Pango and other libraries based on GObject.
92 * The GObject class provides methods for object construction and destruction,
93 * property access methods, and signal support.
94 * Signals are described in detail in Signals(3).
95 * GInitiallyUnowned is derived from GObject. The only difference between
96 * the two is that the initial reference of a GInitiallyUnowned is flagged
97 * as a floating reference.
98 * This means that it is not specifically claimed to be "owned" by
99 * any code portion. The main motivation for providing floating references is
100 * C convenience. In particular, it allows code to be written as:
101 * Example1.
102 * container = create_container();
103 * container_add_child (container, create_child());
104 * If container_add_child() will g_object_ref_sink() the
105 * passed in child, no reference of the newly created child is leaked.
106 * Without floating references, container_add_child()
107 * can only g_object_ref() the new child, so to implement this code without
108 * reference leaks, it would have to be written as:
109 * Example2.
110 * Child *child;
111 * container = create_container();
112 * child = create_child();
113 * container_add_child (container, child);
114 * g_object_unref (child);
115 * The floating reference can be converted into
116 * an ordinary reference by calling g_object_ref_sink().
117 * For already sunken objects (objects that don't have a floating reference
118 * anymore), g_object_ref_sink() is equivalent to g_object_ref() and returns
119 * a new reference.
120 * Since floating references are useful almost exclusively for C convenience,
121 * language bindings that provide automated reference and memory ownership
122 * maintenance (such as smart pointers or garbage collection) therefore don't
123 * need to expose floating references in their API.
124 * Some object implementations may need to save an objects floating state
125 * across certain code portions (an example is GtkMenu), to achive this, the
126 * following sequence can be used:
127 * Example3.
128 * /+* save floating state +/
129 * gboolean was_floating = g_object_is_floating (object);
130 * g_object_ref_sink (object);
131 * /+* protected code portion +/
132 * ...;
133 * /+* restore floating state +/
134 * if (was_floating)
135 * g_object_force_floating (object);
136 * g_obejct_unref (object); /+* release previously acquired reference +/
138 public class ObjectG
141 /** the main Gtk struct */
142 protected GObject* gObject;
145 public GObject* getObjectGStruct()
147 return gObject;
151 /** the main Gtk struct as a void* */
152 protected void* getStruct()
154 return cast(void*)gObject;
159 * Sets our main struct and passes store it on the gobject.
160 * Add a gabage collector root to the gtk+ struct so it doesn't get collect
162 public this (GObject* gObject)
164 this.gObject = gObject;
165 if ( gObject !is null )
167 //writefln("ObjectG.this\n");
168 setDataFull("GObject",cast(void*)this);
173 * Sets a pointer on this object's has table
174 * @param key the data identifier
175 * @param data a pointer
177 public: void setDataFull(char[] key, gpointer data)
179 //writefln("setData objectG=%X data=%X type %s",gObject,data,key);
180 version(Tango) gc.addRoot(data);
181 else std.gc.addRoot(data);
182 g_object_set_data_full(gObject, Str.toStringz(key), data, cast(GDestroyNotify)&destroyNotify);
185 extern(C)
187 static void destroyNotify(gpointer* data)
189 //writefln("objectg.destroy entry");
190 //writefln("objectg.destroy");
191 //writefln("removing gc.root to %s",data);
192 version(Tango) gc.removeRoot(data);
193 else std.gc.removeRoot(data);
194 //writefln("objectg.destroy exit");
198 //debug = objectstore;
200 //debug(objectstore)
202 // private import std.stdio;
205 // /**
206 // * Maps Gtk structures to GtkD Objects
207 // */
208 // private static ObjectStore objectStore;
210 // /**
211 // * Creates the statis ObjectStore object
212 // */
213 // static this()
214 // {
215 // objectStore = new ObjectStore();
216 // }
218 // /**
219 // * Sets our main struct and passes store it on the gobject.
220 // * Adds a gabage collector root to the gtk+ struct so it doesn't get collect
221 // * adds the object to the objectStore
222 // */
223 // public this (GObject* gObject)
224 // {
225 // this.gObject = gObject;
226 // if ( gObject !is null )
227 // {
228 // //writefln("ObjectG.this\n");
229 // objectStore.putObject(this, gObject);
230 // setDestroyNotify("GObject",gObject);
231 // }
232 // }
236 // /**
237 // * Maintains the map from Gtk structures to GtkD objects
238 // */
239 // private static class ObjectStore
240 // {
241 // static ObjectG[void*] objectStore;
243 // /**
244 // * Puts a new gtk struct to GtkD objects
245 // */
246 // void putObject(ObjectG objectG, GObject* gtkStruct)
247 // {
248 // objectStore[gtkStruct] = objectG;
249 // debug(objectstore)
250 // {
251 // writefln("ObjectStore.putObject gtkStruct = %s (total=%s)", gtkStruct, objectStore.length);
252 // }
253 // }
255 // /**
256 // * Gets a GtkD object from a gtk struct.
257 // * Returns: the GtkD object or null if not found
258 // */
259 // ObjectG getObject(GObject* gtkStruct)
260 // {
261 // ObjectG objectG = null;
262 // synchronized ( this )
263 // {
264 // if ( gtkStruct in objectStore )
265 // {
266 // objectG = objectStore[gtkStruct];
267 // }
268 // }
269 // debug(objectstore)
270 // {
271 // //writefln("ObjectStore.removeObject objectStore.length = %s", objectStore.length);
272 // //writefln("ObjectStore.getObject gtkStruct = %s", gtkStruct);
273 // if ( objectG is null )
274 // {
275 // writefln("ObjectStore.getObject not found");
276 // }
277 // else
278 // {
279 // writefln("ObjectStore.getObject %s (total = %s)", objectG, objectStore.length);
280 // }
281 // }
282 // return objectG;
283 // }
285 // /**
286 // * Removes an entry from the gtk struct to GtkD object map
287 // */
288 // void removeObject(GObject* gtkStruct)
289 // {
290 // debug(objectstore)
291 // {
292 // writefln("ObjectStore.removeObject gtkStruct = %s", gtkStruct);
293 // ObjectG objectG = getObject(gtkStruct);
294 // if ( objectG is null )
295 // {
296 // writefln("ObjectStore.removeObject not found");
297 // }
298 // else
299 // {
300 // writefln("ObjectStore.removeObject %s",
301 // objectG);
302 // }
303 // }
304 // objectStore.remove(gtkStruct);
305 // //objectStore.rehash;
306 // debug(objectstore)
307 // {
308 // writefln("ObjectStore.removeObject objectStore.length = %s", objectStore.length);
309 // }
310 // }
311 // }
313 // /**
314 // * Gets a GtkD object from a Gtk Structure if the GtkD object was already created for the structure
315 // */
316 // public static ObjectG getStoredObject(GObject* gtkStruct)
317 // {
318 // return objectStore.getObject(gtkStruct);
319 // }
321 // /**
322 // * Sets a pointer on this object's has table
323 // * @param key the data identifier
324 // * @param data a pointer
325 // */
326 // private void setDestroyNotify(char[] key, gpointer data)
327 // {
328 // //writefln("setData objectG=%X data=%X type %s",gObject,data,key);
329 // //std.gc.addRoot(data);
331 // g_object_set_data_full(gObject, Str.toStringz(key), data, cast(GDestroyNotify)&destroyNotify);
332 // }
334 // private extern(C)
335 // {
336 // static void destroyNotify(gpointer data)
337 // {
338 // //printf("objectg.destroy entry\n");
339 // //printf("objectg.destroy\n");
340 // //writefln("removing gc.root to %s",data);
341 // //std.gc.removeRoot(data);
343 // objectStore.removeObject(cast(GObject*)data);
344 // //objectStore.removeObject(cast(GObject*)*data);
346 // //printf("objectg.destroy exit\n");
347 // }
348 // }
349 public void setProperty(char[] propertyName, int value)
351 setProperty(propertyName, new Value(value));
354 public void setProperty(char[] propertyName, char[] value)
356 setProperty(propertyName, new Value(value));
359 public void setProperty(char[] propertyName, long value)
361 //We use g_object_set instead of g_object_set_property, because Value doesn't like longs and ulongs for some reason.
362 g_object_set( gObject, Str.toStringz(propertyName), value, null);
365 public void setProperty(char[] propertyName, ulong value)
367 g_object_set( gObject, Str.toStringz(propertyName), value, null);
374 // imports for the signal processing
375 private import gobject.Signals;
376 private import gtkc.gdktypes;
377 int[char[]] connectedSignals;
379 void delegate(ParamSpec, ObjectG)[] onNotifyListeners;
380 void addOnNotify(void delegate(ParamSpec, ObjectG) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
382 if ( !("notify" in connectedSignals) )
384 Signals.connectData(
385 getStruct(),
386 "notify",
387 cast(GCallback)&callBackNotify,
388 cast(void*)this,
389 null,
390 connectFlags);
391 connectedSignals["notify"] = 1;
393 onNotifyListeners ~= dlg;
395 extern(C) static void callBackNotify(GObject* gobjectStruct, GParamSpec* arg1, ObjectG objectG)
397 bool consumed = false;
399 foreach ( void delegate(ParamSpec, ObjectG) dlg ; objectG.onNotifyListeners )
401 dlg(new ParamSpec(arg1), objectG);
404 return consumed;
425 * Installs a new property. This is usually done in the class initializer.
426 * oclass:
427 * a GObjectClass
428 * property_id:
429 * the id for the new property
430 * pspec:
431 * the GParamSpec for the new property
433 public static void classInstallProperty(GObjectClass* oclass, uint propertyId, ParamSpec pspec)
435 // void g_object_class_install_property (GObjectClass *oclass, guint property_id, GParamSpec *pspec);
436 g_object_class_install_property(oclass, propertyId, (pspec is null) ? null : pspec.getParamSpecStruct());
440 * Looks up the GParamSpec for a property of a class.
441 * oclass:
442 * a GObjectClass
443 * property_name:
444 * the name of the property to look up
445 * Returns:
446 * the GParamSpec for the property, or NULL if the class doesn't have
447 * a property of that name
449 public static ParamSpec classFindProperty(GObjectClass* oclass, char[] propertyName)
451 // GParamSpec* g_object_class_find_property (GObjectClass *oclass, const gchar *property_name);
452 return new ParamSpec( g_object_class_find_property(oclass, Str.toStringz(propertyName)) );
456 * Returns an array of GParamSpec* for all properties of a class.
457 * oclass:
458 * a GObjectClass
459 * n_properties:
460 * return location for the length of the returned array
461 * Returns:
462 * an array of GParamSpec* which should be freed after use
464 public static GParamSpec** classListProperties(GObjectClass* oclass, uint* nProperties)
466 // GParamSpec** g_object_class_list_properties (GObjectClass *oclass, guint *n_properties);
467 return g_object_class_list_properties(oclass, nProperties);
471 * Registers property_id as referring to a property with the
472 * name name in a parent class or in an interface implemented
473 * by oclass. This allows this class to override
474 * a property implementation in a parent class or to provide
475 * the implementation of a property from an interface.
476 * Note
477 * Internally, overriding is implemented by creating a property of type
478 * GParamSpecOverride; generally operations that query the properties of
479 * the object class, such as g_object_class_find_property() or
480 * g_object_class_list_properties() will return the overridden
481 * property. However, in one case, the construct_properties argument of
482 * the constructor virtual function, the GParamSpecOverride is passed
483 * instead, so that the param_id field of the GParamSpec will be
484 * correct. For virtually all uses, this makes no difference. If you
485 * need to get the overridden property, you can call
486 * g_param_spec_get_redirect_target().
487 * oclass:
488 * a GObjectClass
489 * property_id:
490 * the new property ID
491 * name:
492 * the name of a property registered in a parent class or
493 * in an interface of this class.
494 * Since 2.4
496 public static void classOverrideProperty(GObjectClass* oclass, uint propertyId, char[] name)
498 // void g_object_class_override_property (GObjectClass *oclass, guint property_id, const gchar *name);
499 g_object_class_override_property(oclass, propertyId, Str.toStringz(name));
503 * Add a property to an interface; this is only useful for interfaces
504 * that are added to GObject-derived types. Adding a property to an
505 * interface forces all objects classes with that interface to have a
506 * compatible property. The compatible property could be a newly
507 * created GParamSpec, but normally
508 * g_object_class_override_property() will be used so that the object
509 * class only needs to provide an implementation and inherits the
510 * property description, default value, bounds, and so forth from the
511 * interface property.
512 * This function is meant to be called from the interface's default
513 * vtable initialization function (the class_init member of
514 * GTypeInfo.) It must not be called after after class_init has
515 * been called for any object types implementing this interface.
516 * g_iface:
517 * any interface vtable for the interface, or the default
518 * vtable for the interface.
519 * pspec:
520 * the GParamSpec for the new property
521 * Since 2.4
523 public static void interfaceInstallProperty(void* gIface, ParamSpec pspec)
525 // void g_object_interface_install_property (gpointer g_iface, GParamSpec *pspec);
526 g_object_interface_install_property(gIface, (pspec is null) ? null : pspec.getParamSpecStruct());
530 * Find the GParamSpec with the given name for an
531 * interface. Generally, the interface vtable passed in as g_iface
532 * will be the default vtable from g_type_default_interface_ref(), or,
533 * if you know the interface has already been loaded,
534 * g_type_default_interface_peek().
535 * g_iface:
536 * any interface vtable for the interface, or the default
537 * vtable for the interface
538 * property_name:
539 * name of a property to lookup.
540 * Returns:
541 * the GParamSpec for the property of the
542 * interface with the name property_name, or NULL
543 * if no such property exists.
544 * Since 2.4
546 public static ParamSpec interfaceFindProperty(void* gIface, char[] propertyName)
548 // GParamSpec* g_object_interface_find_property (gpointer g_iface, const gchar *property_name);
549 return new ParamSpec( g_object_interface_find_property(gIface, Str.toStringz(propertyName)) );
553 * Lists the properties of an interface.Generally, the interface
554 * vtable passed in as g_iface will be the default vtable from
555 * g_type_default_interface_ref(), or, if you know the interface has
556 * already been loaded, g_type_default_interface_peek().
557 * g_iface:
558 * any interface vtable for the interface, or the default
559 * vtable for the interface
560 * n_properties_p:
561 * location to store number of properties returned.
562 * Returns:
563 * a pointer to an array of pointers to GParamSpec structures.
564 * The paramspecs are owned by GLib, but the array should
565 * be freed with g_free() when you are done with it.
566 * Since 2.4
568 public static GParamSpec** interfaceListProperties(void* gIface, uint* nPropertiesP)
570 // GParamSpec** g_object_interface_list_properties (gpointer g_iface, guint *n_properties_p);
571 return g_object_interface_list_properties(gIface, nPropertiesP);
575 * Creates a new instance of a GObject subtype and sets its properties.
576 * Construction parameters (see G_PARAM_CONSTRUCT, G_PARAM_CONSTRUCT_ONLY)
577 * which are not explicitly specified are set to their default values.
578 * object_type:
579 * the type id of the GObject subtype to instantiate
580 * first_property_name:
581 * the name of the first property
582 * ...:
583 * the value of the first property, followed optionally by more
584 * name/value pairs, followed by NULL
585 * Returns:
586 * a new instance of object_type
588 public this (GType objectType, char[] firstPropertyName, ... )
590 // gpointer g_object_new (GType object_type, const gchar *first_property_name, ...);
591 this(cast(GObject*)g_object_new(objectType, Str.toStringz(firstPropertyName)) );
595 * Creates a new instance of a GObject subtype and sets its properties.
596 * Construction parameters (see G_PARAM_CONSTRUCT, G_PARAM_CONSTRUCT_ONLY)
597 * which are not explicitly specified are set to their default values.
598 * object_type:
599 * the type id of the GObject subtype to instantiate
600 * n_parameters:
601 * the length of the parameters array
602 * parameters:
603 * an array of GParameter
604 * Returns:
605 * a new instance of object_type
607 public this (GType objectType, uint nParameters, GParameter* parameters)
609 // gpointer g_object_newv (GType object_type, guint n_parameters, GParameter *parameters);
610 this(cast(GObject*)g_object_newv(objectType, nParameters, parameters) );
615 * Increases the reference count of object.
616 * object:
617 * a GObject
618 * Returns:
619 * the same object
621 public static void* doref(void* object)
623 // gpointer g_object_ref (gpointer object);
624 return g_object_ref(object);
628 * Decreases the reference count of object.
629 * When its reference count drops to 0, the object is finalized
630 * (i.e. its memory is freed).
631 * object:
632 * a GObject
634 public static void unref(void* object)
636 // void g_object_unref (gpointer object);
637 g_object_unref(object);
641 * Increase the reference count of object, and possibly remove the
642 * floating reference, if object
643 * has a floating reference.
644 * In other words, if the object is floating, then this call "assumes
645 * ownership" of the floating reference, converting it to a normal reference
646 * by clearing the floating flag while leaving the reference count unchanged.
647 * If the object is not floating, then this call adds a new normal reference
648 * increasing the reference count by one.
649 * object:
650 * a GObject
651 * Returns:
652 * object
653 * Since 2.10
655 public static void* refSink(void* object)
657 // gpointer g_object_ref_sink (gpointer object);
658 return g_object_ref_sink(object);
665 * Checks wether object has a floating
666 * reference.
667 * object:
668 * a GObject
669 * Returns:
670 * TRUE if object has a floating reference
671 * Since 2.10
673 public static int isFloating(void* object)
675 // gboolean g_object_is_floating (gpointer object);
676 return g_object_is_floating(object);
680 * This function is intended for GObject implementations to re-enforce a
681 * floating object reference.
682 * Doing this is seldomly required, all
683 * GInitiallyUnowneds are created with a floating reference which
684 * usually just needs to be sunken by calling g_object_ref_sink().
685 * object:
686 * a GObject
687 * Since 2.10
689 public void forceFloating()
691 // void g_object_force_floating (GObject *object);
692 g_object_force_floating(gObject);
697 * Adds a weak reference callback to an object. Weak references are used for
698 * notification when an object is finalized. They are called "weak references"
699 * because they allow you to safely hold a pointer to an object without calling
700 * g_object_ref() (g_object_ref() adds a strong reference, that is, forces the
701 * object to stay alive).
702 * object:
703 * GObject to reference weakly
704 * notify:
705 * callback to invoke before the object is freed
706 * data:
707 * extra data to pass to notify
709 public void weakRef(GWeakNotify notify, void* data)
711 // void g_object_weak_ref (GObject *object, GWeakNotify notify, gpointer data);
712 g_object_weak_ref(gObject, notify, data);
716 * Removes a weak reference callback to an object.
717 * object:
718 * GObject to remove a weak reference from
719 * notify:
720 * callback to search for
721 * data:
722 * data to search for
724 public void weakUnref(GWeakNotify notify, void* data)
726 // void g_object_weak_unref (GObject *object, GWeakNotify notify, gpointer data);
727 g_object_weak_unref(gObject, notify, data);
731 * Adds a weak reference from weak_pointer to object to indicate that
732 * the pointer located at weak_pointer_location is only valid during the
733 * lifetime of object. When the object is finalized, weak_pointer will
734 * be set to NULL.
735 * object:
736 * The object that should be weak referenced.
737 * weak_pointer_location:
738 * The memory address of a pointer.
740 public void addWeakPointer(void** weakPointerLocation)
742 // void g_object_add_weak_pointer (GObject *object, gpointer *weak_pointer_location);
743 g_object_add_weak_pointer(gObject, weakPointerLocation);
747 * Removes a weak reference from object that was previously added
748 * using g_object_add_weak_pointer(). The weak_pointer_location has
749 * to match the one used with g_object_add_weak_pointer().
750 * object:
751 * The object that is weak referenced.
752 * weak_pointer_location:
753 * The memory address of a pointer.
755 public void removeWeakPointer(void** weakPointerLocation)
757 // void g_object_remove_weak_pointer (GObject *object, gpointer *weak_pointer_location);
758 g_object_remove_weak_pointer(gObject, weakPointerLocation);
763 * Increases the reference count of the object by one and sets a
764 * callback to be called when all other references to the object are
765 * dropped, or when this is already the last reference to the object
766 * and another reference is established.
767 * This functionality is intended for binding object to a proxy
768 * object managed by another memory manager. This is done with two
769 * paired references: the strong reference added by
770 * g_object_add_toggle_ref() and a reverse reference to the proxy
771 * object which is either a strong reference or weak reference.
772 * The setup is that when there are no other references to object,
773 * only a weak reference is held in the reverse direction from object
774 * to the proxy object, but when there are other references held to
775 * object, a strong reference is held. The notify callback is called
776 * when the reference from object to the proxy object should be
777 * toggled from strong to weak (is_last_ref
778 * true) or weak to strong (is_last_ref false).
779 * Since a (normal) reference must be held to the object before
780 * calling g_object_toggle_ref(), the initial state of the reverse
781 * link is always strong.
782 * Multiple toggle references may be added to the same gobject,
783 * however if there are multiple toggle references to an object, none
784 * of them will ever be notified until all but one are removed. For
785 * this reason, you should only ever use a toggle reference if there
786 * is important state in the proxy object.
787 * object:
788 * a GObject
789 * notify:
790 * a function to call when this reference is the
791 * last reference to the object, or is no longer
792 * the last reference.
793 * data:
794 * data to pass to notify
795 * Since 2.8
797 public void addToggleRef(GToggleNotify notify, void* data)
799 // void g_object_add_toggle_ref (GObject *object, GToggleNotify notify, gpointer data);
800 g_object_add_toggle_ref(gObject, notify, data);
804 * Removes a reference added with g_object_add_toggle_ref(). The
805 * reference count of the object is decreased by one.
806 * object:
807 * a GObject
808 * notify:
809 * a function to call when this reference is the
810 * last reference to the object, or is no longer
811 * the last reference.
812 * data:
813 * data to pass to notify
814 * Since 2.8
816 public void removeToggleRef(GToggleNotify notify, void* data)
818 // void g_object_remove_toggle_ref (GObject *object, GToggleNotify notify, gpointer data);
819 g_object_remove_toggle_ref(gObject, notify, data);
823 * A convenience function to connect multiple signals at once.
824 * The signal specs expected by this function have the form
825 * "modifier::signal_name", where modifier can be one of the following:
826 * signal
827 * equivalent to g_signal_connect_data (...)
828 * object_signal, object-signal
829 * equivalent to g_signal_connect_object (...)
830 * swapped_signal, swapped-signal
831 * equivalent to g_signal_connect_data (..., G_CONNECT_SWAPPED)
832 * swapped_object_signal, swapped-object-signal
833 * equivalent to g_signal_connect_object (..., G_CONNECT_SWAPPED)
834 * signal_after, signal-after
835 * equivalent to g_signal_connect_data (..., G_CONNECT_AFTER)
836 * object_signal_after, object-signal-after
837 * equivalent to g_signal_connect_object (..., G_CONNECT_AFTER)
838 * swapped_signal_after, swapped-signal-after
839 * equivalent to g_signal_connect_data (..., G_CONNECT_SWAPPED | G_CONNECT_AFTER)
840 * swapped_object_signal_after, swapped-object-signal-after
841 * equivalent to g_signal_connect_object (..., G_CONNECT_SWAPPED | G_CONNECT_AFTER)
842 * menu->toplevel = g_object_connect (g_object_new (GTK_TYPE_WINDOW,
843 * "type", GTK_WINDOW_POPUP,
844 * "child", menu,
845 * NULL),
846 * "signal::event", gtk_menu_window_event, menu,
847 * "signal::size_request", gtk_menu_window_size_request, menu,
848 * "signal::destroy", gtk_widget_destroyed, menu->toplevel,
849 * NULL);
850 * object:
851 * a GObject
852 * signal_spec:
853 * the spec for the first signal
854 * ...:
855 * GCallback for the first signal, followed by data for the first signal,
856 * followed optionally by more signal spec/callback/data triples,
857 * followed by NULL
858 * Returns:
859 * object
861 public static void* connect(void* object, char[] signalSpec, ... )
863 // gpointer g_object_connect (gpointer object, const gchar *signal_spec, ...);
864 return g_object_connect(object, Str.toStringz(signalSpec));
868 * A convenience function to disconnect multiple signals at once.
869 * The signal specs expected by this function have the form "any_signal", which
870 * means to disconnect any signal with matching callback and data, or
871 * "any_signal::signal_name", which only disconnects the signal named "signal_name".
872 * object:
873 * a GObject
874 * signal_spec:
875 * the spec for the first signal
876 * ...:
877 * GCallback for the first signal, followed by data for the first signal,
878 * followed optionally by more signal spec/callback/data triples,
879 * followed by NULL
881 public static void disconnect(void* object, char[] signalSpec, ... )
883 // void g_object_disconnect (gpointer object, const gchar *signal_spec, ...);
884 g_object_disconnect(object, Str.toStringz(signalSpec));
888 * Sets properties on an object.
889 * object:
890 * a GObject
891 * first_property_name:
892 * name of the first property to set
893 * ...:
894 * value for the first property, followed optionally by more
895 * name/value pairs, followed by NULL
897 public static void set(void* object, char[] firstPropertyName, ... )
899 // void g_object_set (gpointer object, const gchar *first_property_name, ...);
900 g_object_set(object, Str.toStringz(firstPropertyName));
904 * Gets properties of an object.
905 * In general, a copy is made of the property contents and the caller is
906 * responsible for freeing the memory in the appropriate manner for the type,
907 * for instance by calling g_free() or g_object_unref().
908 * Example5.Using g_object_get()
909 * An example of using g_object_get() to get the contents
910 * of three properties - one of type G_TYPE_INT,
911 * one of type G_TYPE_STRING, and one of type G_TYPE_OBJECT:
912 * gint intval;
913 * gchar *strval;
914 * GObject *objval;
915 * g_object_get (my_object,
916 * "intproperty", intval,
917 * "strproperty", strval,
918 * "objproperty", objval,
919 * NULL);
920 * /+* Do something with intval, strval, objval +/
921 * g_free (strval);
922 * g_object_unref (objval);
923 * object:
924 * a GObject
925 * first_property_name:
926 * name of the first property to get
927 * ...:
928 * return location for the first property, followed optionally by more
929 * name/return location pairs, followed by NULL
931 public static void get(void* object, char[] firstPropertyName, ... )
933 // void g_object_get (gpointer object, const gchar *first_property_name, ...);
934 g_object_get(object, Str.toStringz(firstPropertyName));
938 * Emits a "notify" signal for the property property_name on object.
939 * object:
940 * a GObject
941 * property_name:
942 * the name of a property installed on the class of object.
944 public void notify(char[] propertyName)
946 // void g_object_notify (GObject *object, const gchar *property_name);
947 g_object_notify(gObject, Str.toStringz(propertyName));
951 * Stops emission of "notify" signals on object. The signals are
952 * queued until g_object_thaw_notify() is called on object.
953 * This is necessary for accessors that modify multiple properties to prevent
954 * premature notification while the object is still being modified.
955 * object:
956 * a GObject
958 public void freezeNotify()
960 // void g_object_freeze_notify (GObject *object);
961 g_object_freeze_notify(gObject);
965 * Reverts the effect of a previous call to g_object_freeze_notify().
966 * This causes all queued "notify" signals on object to be emitted.
967 * object:
968 * a GObject
970 public void thawNotify()
972 // void g_object_thaw_notify (GObject *object);
973 g_object_thaw_notify(gObject);
977 * Gets a named field from the objects table of associations (see g_object_set_data()).
978 * object:
979 * GObject containing the associations
980 * key:
981 * name of the key for that association
982 * Returns:
983 * the data if found, or NULL if no such data exists.
985 public void* getData(char[] key)
987 // gpointer g_object_get_data (GObject *object, const gchar *key);
988 return g_object_get_data(gObject, Str.toStringz(key));
992 * Each object carries around a table of associations from
993 * strings to pointers. This function lets you set an association.
994 * If the object already had an association with that name,
995 * the old association will be destroyed.
996 * object:
997 * GObject containing the associations.
998 * key:
999 * name of the key
1000 * data:
1001 * data to associate with that key
1003 public void setData(char[] key, void* data)
1005 // void g_object_set_data (GObject *object, const gchar *key, gpointer data);
1006 g_object_set_data(gObject, Str.toStringz(key), data);
1011 * Remove a specified datum from the object's data associations,
1012 * without invoking the association's destroy handler.
1013 * object:
1014 * GObject containing the associations
1015 * key:
1016 * name of the key
1017 * Returns:
1018 * the data if found, or NULL if no such data exists.
1020 public void* stealData(char[] key)
1022 // gpointer g_object_steal_data (GObject *object, const gchar *key);
1023 return g_object_steal_data(gObject, Str.toStringz(key));
1027 * This function gets back user data pointers stored via
1028 * g_object_set_qdata().
1029 * object:
1030 * The GObject to get a stored user data pointer from
1031 * quark:
1032 * A GQuark, naming the user data pointer
1033 * Returns:
1034 * The user data pointer set, or NULL
1036 public void* getQdata(GQuark quark)
1038 // gpointer g_object_get_qdata (GObject *object, GQuark quark);
1039 return g_object_get_qdata(gObject, quark);
1043 * This sets an opaque, named pointer on an object.
1044 * The name is specified through a GQuark (retrived e.g. via
1045 * g_quark_from_static_string()), and the pointer
1046 * can be gotten back from the object with g_object_get_qdata()
1047 * until the object is finalized.
1048 * Setting a previously set user data pointer, overrides (frees)
1049 * the old pointer set, using NULL as pointer essentially
1050 * removes the data stored.
1051 * object:
1052 * The GObject to set store a user data pointer
1053 * quark:
1054 * A GQuark, naming the user data pointer
1055 * data:
1056 * An opaque user data pointer
1058 public void setQdata(GQuark quark, void* data)
1060 // void g_object_set_qdata (GObject *object, GQuark quark, gpointer data);
1061 g_object_set_qdata(gObject, quark, data);
1065 * This function works like g_object_set_qdata(), but in addition,
1066 * a void (*destroy) (gpointer) function may be specified which is
1067 * called with data as argument when the object is finalized, or
1068 * the data is being overwritten by a call to g_object_set_qdata()
1069 * with the same quark.
1070 * object:
1071 * The GObject to set store a user data pointer
1072 * quark:
1073 * A GQuark, naming the user data pointer
1074 * data:
1075 * An opaque user data pointer
1076 * destroy:
1077 * Function to invoke with data as argument, when data needs to be freed
1079 public void setQdataFull(GQuark quark, void* data, GDestroyNotify destroy)
1081 // void g_object_set_qdata_full (GObject *object, GQuark quark, gpointer data, GDestroyNotify destroy);
1082 g_object_set_qdata_full(gObject, quark, data, destroy);
1086 * This function gets back user data pointers stored via
1087 * g_object_set_qdata() and removes the data from object
1088 * without invoking it's destroy() function (if any was
1089 * set).
1090 * Usually, calling this function is only required to update
1091 * user data pointers with a destroy notifier, for example:
1092 * void
1093 * object_add_to_user_list (GObject *object,
1094 * const gchar *new_string)
1096 * /+* the quark, naming the object data +/
1097 * GQuark quark_string_list = g_quark_from_static_string ("my-string-list");
1098 * /+* retrive the old string list +/
1099 * GList *list = g_object_steal_qdata (object, quark_string_list);
1100 * /+* prepend new string +/
1101 * list = g_list_prepend (list, g_strdup (new_string));
1102 * /+* this changed 'list', so we need to set it again +/
1103 * g_object_set_qdata_full (object, quark_string_list, list, free_string_list);
1105 * static void
1106 * free_string_list (gpointer data)
1108 * GList *node, *list = data;
1109 * for (node = list; node; node = node->next)
1110 * g_free (node->data);
1111 * g_list_free (list);
1113 * Using g_object_get_qdata() in the above example, instead of g_object_steal_qdata()
1114 * would have left the destroy function set, and thus the partial string list would
1115 * have been freed upon g_object_set_qdata_full().
1116 * object:
1117 * The GObject to get a stored user data pointer from
1118 * quark:
1119 * A GQuark, naming the user data pointer
1120 * Returns:
1121 * The user data pointer set, or NULL
1123 public void* stealQdata(GQuark quark)
1125 // gpointer g_object_steal_qdata (GObject *object, GQuark quark);
1126 return g_object_steal_qdata(gObject, quark);
1130 * Sets a property on an object.
1131 * object:
1132 * a GObject
1133 * property_name:
1134 * the name of the property to set
1135 * value:
1136 * the value
1138 public void setProperty(char[] propertyName, Value value)
1140 // void g_object_set_property (GObject *object, const gchar *property_name, const GValue *value);
1141 g_object_set_property(gObject, Str.toStringz(propertyName), (value is null) ? null : value.getValueStruct());
1145 * Gets a property of an object.
1146 * In general, a copy is made of the property contents and the caller is
1147 * responsible for freeing the memory by calling g_value_unset().
1148 * Note that g_object_get_property() is really intended for language
1149 * bindings, g_object_get() is much more convenient for C programming.
1150 * object:
1151 * a GObject
1152 * property_name:
1153 * the name of the property to get
1154 * value:
1155 * return location for the property value
1157 public void getProperty(char[] propertyName, Value value)
1159 // void g_object_get_property (GObject *object, const gchar *property_name, GValue *value);
1160 g_object_get_property(gObject, Str.toStringz(propertyName), (value is null) ? null : value.getValueStruct());
1164 * Creates a new instance of a GObject subtype and sets its properties.
1165 * Construction parameters (see G_PARAM_CONSTRUCT, G_PARAM_CONSTRUCT_ONLY)
1166 * which are not explicitly specified are set to their default values.
1167 * object_type:
1168 * the type id of the GObject subtype to instantiate
1169 * first_property_name:
1170 * the name of the first property
1171 * var_args:
1172 * the value of the first property, followed optionally by more
1173 * name/value pairs, followed by NULL
1174 * Returns:
1175 * a new instance of object_type
1177 public this (GType objectType, char[] firstPropertyName, void* varArgs)
1179 // GObject* g_object_new_valist (GType object_type, const gchar *first_property_name, va_list var_args);
1180 this(cast(GObject*)g_object_new_valist(objectType, Str.toStringz(firstPropertyName), varArgs) );
1184 * Sets properties on an object.
1185 * object:
1186 * a GObject
1187 * first_property_name:
1188 * name of the first property to set
1189 * var_args:
1190 * value for the first property, followed optionally by more
1191 * name/value pairs, followed by NULL
1193 public void setValist(char[] firstPropertyName, void* varArgs)
1195 // void g_object_set_valist (GObject *object, const gchar *first_property_name, va_list var_args);
1196 g_object_set_valist(gObject, Str.toStringz(firstPropertyName), varArgs);
1200 * Gets properties of an object.
1201 * In general, a copy is made of the property contents and the caller is
1202 * responsible for freeing the memory in the appropriate manner for the type,
1203 * for instance by calling g_free() or g_object_unref().
1204 * See g_object_get().
1205 * object:
1206 * a GObject
1207 * first_property_name:
1208 * name of the first property to get
1209 * var_args:
1210 * return location for the first property, followed optionally by more
1211 * name/return location pairs, followed by NULL
1213 public void getValist(char[] firstPropertyName, void* varArgs)
1215 // void g_object_get_valist (GObject *object, const gchar *first_property_name, va_list var_args);
1216 g_object_get_valist(gObject, Str.toStringz(firstPropertyName), varArgs);
1220 * This function essentially limits the life time of the closure
1221 * to the life time of the object. That is, when the object is finalized,
1222 * the closure is invalidated by calling g_closure_invalidate() on it,
1223 * in order to prevent invocations of the closure with a finalized
1224 * (nonexisting) object. Also, g_object_ref() and g_object_unref() are added
1225 * as marshal guards to the closure, to ensure that an extra reference
1226 * count is held on object during invocation of the closure.
1227 * Usually, this function will be called on closures that use this object
1228 * as closure data.
1229 * object:
1230 * GObject restricting lifetime of closure
1231 * closure:
1232 * GClosure to watch
1234 public void watchClosure(Closure closure)
1236 // void g_object_watch_closure (GObject *object, GClosure *closure);
1237 g_object_watch_closure(gObject, (closure is null) ? null : closure.getClosureStruct());
1241 * Releases all references to other objects. This can be used to break
1242 * reference cycles.
1243 * Note
1244 * This functions should only be called from object system implementations.
1245 * object:
1246 * a GObject
1248 public void runDispose()
1250 // void g_object_run_dispose (GObject *object);
1251 g_object_run_dispose(gObject);