1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gobject.ObjectG;
26 
27 private import core.memory;
28 private import glib.ConstructionException;
29 private import glib.Str;
30 private import gobject.Binding;
31 private import gobject.Closure;
32 private import gobject.ObjectG;
33 private import gobject.ParamSpec;
34 private import gobject.Signals;
35 private import gobject.TypeInterface;
36 private import gobject.Value;
37 private import gtkc.gobject;
38 public  import gtkc.gobjecttypes;
39 private import gtkd.Loader;
40 private import std.algorithm;
41 private import std.traits;
42 
43 
44 /**
45  * All the fields in the GObject structure are private
46  * to the #GObject implementation and should never be accessed directly.
47  */
48 public class ObjectG
49 {
50 	/** the main Gtk struct */
51 	protected GObject* gObject;
52 	protected bool ownedRef;
53 
54 	/** Get the main Gtk struct */
55 	public GObject* getObjectGStruct(bool transferOwnership = false)
56 	{
57 		if (transferOwnership)
58 			ownedRef = false;
59 		return gObject;
60 	}
61 
62 	/** the main Gtk struct as a void* */
63 	protected void* getStruct()
64 	{
65 		return cast(void*)gObject;
66 	}
67 
68 	protected bool isGcRoot;
69 	
70 	/**
71 	 * Sets our main struct and passes store it on the gobject.
72 	 * Add a gabage collector root to the gtk+ struct so it doesn't get collect
73 	 */
74 	public this (GObject* gObject, bool ownedRef = false)
75 	{
76 		this.gObject = gObject;
77 		if ( gObject !is  null )
78 		{
79 			setDataFull("GObject", cast(void*)this, cast(GDestroyNotify)&destroyNotify);
80 			addToggleRef(cast(GToggleNotify)&toggleNotify, cast(void*)this);
81 			
82 			//If the refCount is larger then 1 toggleNotify isn't called
83 			if (gObject.refCount > 1 && !isGcRoot)
84 			{
85 				GC.addRoot(cast(void*)this);
86 				isGcRoot = true;
87 			}
88 			
89 			//Remove the floating reference if there is one.
90 			if ( isFloating() )
91 			{
92 				refSink();
93 				unref();
94 			}
95 			//If we already owned this reference remove the one added by addToggleRef.
96 			else if ( ownedRef )
97 			{
98 				unref();
99 			}
100 			
101 			//When constructed via GtkBuilder set the structs.
102 			if ( getStruct() is null)
103 			{
104 				setStruct(gObject);
105 			}
106 		}
107 	}
108 	
109 	extern(C)
110 	{
111 		static void destroyNotify(ObjectG obj)
112 		{
113 			if ( obj.isGcRoot )
114 			{
115 				GC.removeRoot(cast(void*)obj);
116 				obj.isGcRoot = false;
117 			}
118 			
119 			if ( obj.gObject.refCount > 0 )
120 				obj.removeToggleRef(cast(GToggleNotify)&toggleNotify, cast(void*)obj);
121 			
122 			obj.gObject = null;
123 		}
124 		
125 		static void toggleNotify(ObjectG obj, GObject* object, int isLastRef)
126 		{
127 			if ( isLastRef && obj.isGcRoot )
128 			{
129 				GC.removeRoot(cast(void*)obj);
130 				obj.isGcRoot = false;
131 			}
132 			else if ( !obj.isGcRoot )
133 			{
134 				GC.addRoot(cast(void*)obj);
135 				obj.isGcRoot = true;
136 			}
137 		}
138 	}
139 	
140 	~this()
141 	{
142 		static if ( isPointer!(typeof(g_object_steal_data)) )
143 			bool libLoaded = Linker.isLoaded(LIBRARY_GOBJECT);
144 		else
145 			enum libLoaded = true;
146 		
147 		if ( libLoaded && gObject !is null )
148 		{
149 			// Remove the GDestroyNotify callback,
150 			// for when the D object is destroyed before the C one.
151 			g_object_steal_data(gObject, cast(char*)"GObject");
152 			
153 			if ( isGcRoot )
154 			{
155 				GC.removeRoot(cast(void*)this);
156 				isGcRoot = false;
157 			}
158 			
159 			unref();
160 		}
161 	}
162 	
163 	/**
164 	 * Gets a D Object from the objects table of associations.
165 	 * Params:
166 	 *  obj = GObject containing the associations.
167 	 * Returns: the D Object if found, or a newly constructed object if no such Object exists.
168 	 */
169 	public static RT getDObject(T, RT=T, U)(U obj, bool ownedRef = false)
170 	{
171 		if ( obj is null )
172 		{
173 			return null;
174 		}
175 		
176 		static if ( is(T : ObjectG) )
177 		{
178 			auto p = g_object_get_data(cast(GObject*)obj, Str.toStringz("GObject"));
179 			
180 			if ( p !is null )
181 			{
182 				static if ( is(RT == interface ) )
183 				{
184 					return cast(RT)cast(ObjectG)p;
185 				}
186 				else
187 				{
188 					return cast(RT)p;
189 				}
190 			}
191 			else
192 			{
193 				return new T(obj, ownedRef);
194 			}
195 		}
196 		else
197 		{
198 			return new T(obj);
199 		}
200 	}
201 	
202 	protected void setStruct(GObject* obj)
203 	{
204 		gObject = cast(GObject*)obj;
205 	}
206 	
207 	/** */
208 	public void setProperty(string propertyName, int value)
209 	{
210 		setProperty(propertyName, new Value(value));
211 	}
212 	
213 	/** */
214 	public void setProperty(string propertyName, string value)
215 	{
216 		setProperty(propertyName, new Value(value));
217 	}
218 	
219 	/** */
220 	public void setProperty(string propertyName, long value)
221 	{
222 		//We use g_object_set instead of g_object_set_property, because Value doesn't like longs and ulongs for some reason.
223 		g_object_set( gObject, Str.toStringz(propertyName), value, null);
224 	}
225 	
226 	/** */
227 	public void setProperty(string propertyName, ulong value)
228 	{
229 		g_object_set( gObject, Str.toStringz(propertyName), value, null);
230 	}
231 	
232 	deprecated("Use the member function")
233 	public static void unref(ObjectG obj)
234 	{
235 		obj.unref();
236 	}
237 	
238 	deprecated("Use the member function")
239 	public static ObjectG doref(ObjectG obj)
240 	{
241 		return obj.doref();
242 	}
243 	
244 	protected class OnNotifyDelegateWrapper
245 	{
246 		static OnNotifyDelegateWrapper[] listeners;
247 		void delegate(ParamSpec, ObjectG) dlg;
248 		gulong handlerId;
249 		
250 		this(void delegate(ParamSpec, ObjectG) dlg)
251 		{
252 			this.dlg = dlg;
253 			this.listeners ~= this;
254 		}
255 		
256 		void remove(OnNotifyDelegateWrapper source)
257 		{
258 			foreach(index, wrapper; listeners)
259 			{
260 				if (wrapper.handlerId == source.handlerId)
261 				{
262 					listeners[index] = null;
263 					listeners = std.algorithm.remove(listeners, index);
264 					break;
265 				}
266 			}
267 		}
268 	}
269 	
270 	/**
271 	 * The notify signal is emitted on an object when one of its
272 	 * properties has been changed. Note that getting this signal
273 	 * doesn't guarantee that the value of the property has actually
274 	 * changed, it may also be emitted when the setter for the property
275 	 * is called to reinstate the previous value.
276 	 *
277 	 * This signal is typically used to obtain change notification for a
278 	 * single property.
279 	 *
280 	 * It is important to note that you must use
281 	 * canonical parameter names for the property.
282 	 *
283 	 * Params:
284 	 *     dlg          = The callback.
285 	 *     property     = Set this if you only want to receive the signal for a specific property.
286 	 *     connectFlags = The behavior of the signal's connection.
287 	 */
288 	gulong addOnNotify(void delegate(ParamSpec, ObjectG) dlg, string property = "", ConnectFlags connectFlags=cast(ConnectFlags)0)
289 	{
290 		string signalName;
291 		
292 		if ( property == "" )
293 			signalName = "notify";
294 		else
295 			signalName = "notify::"~ property;
296 		
297 		auto wrapper = new OnNotifyDelegateWrapper(dlg);
298 		wrapper.handlerId = Signals.connectData(
299 			this,
300 			signalName,
301 			cast(GCallback)&callBackNotify,
302 			cast(void*)wrapper,
303 			cast(GClosureNotify)&callBackNotifyDestroy,
304 			connectFlags);
305 		return wrapper.handlerId;
306 	}
307 	
308 	extern(C) static void callBackNotify(GObject* objectgStruct, GParamSpec* pspec,OnNotifyDelegateWrapper wrapper)
309 	{
310 		wrapper.dlg(ObjectG.getDObject!(ParamSpec)(pspec), wrapper.outer);
311 	}
312 	
313 	extern(C) static void callBackNotifyDestroy(OnNotifyDelegateWrapper wrapper, GClosure* closure)
314 	{
315 		wrapper.remove(wrapper);
316 	}
317 
318 	/**
319 	 */
320 
321 	/** */
322 	public static GType getType()
323 	{
324 		return g_initially_unowned_get_type();
325 	}
326 
327 	/**
328 	 * Creates a new instance of a #GObject subtype and sets its properties.
329 	 *
330 	 * Construction parameters (see #G_PARAM_CONSTRUCT, #G_PARAM_CONSTRUCT_ONLY)
331 	 * which are not explicitly specified are set to their default values.
332 	 *
333 	 * Params:
334 	 *     objectType = the type id of the #GObject subtype to instantiate
335 	 *     firstPropertyName = the name of the first property
336 	 *     varArgs = the value of the first property, followed optionally by more
337 	 *         name/value pairs, followed by %NULL
338 	 *
339 	 * Returns: a new instance of @object_type
340 	 *
341 	 * Throws: ConstructionException GTK+ fails to create the object.
342 	 */
343 	public this(GType objectType, string firstPropertyName, void* varArgs)
344 	{
345 		auto p = g_object_new_valist(objectType, Str.toStringz(firstPropertyName), varArgs);
346 		
347 		if(p is null)
348 		{
349 			throw new ConstructionException("null returned by new_valist");
350 		}
351 		
352 		this(cast(GObject*) p, true);
353 	}
354 
355 	/**
356 	 * Creates a new instance of a #GObject subtype and sets its properties.
357 	 *
358 	 * Construction parameters (see #G_PARAM_CONSTRUCT, #G_PARAM_CONSTRUCT_ONLY)
359 	 * which are not explicitly specified are set to their default values.
360 	 *
361 	 * Params:
362 	 *     objectType = the type id of the #GObject subtype to instantiate
363 	 *     nParameters = the length of the @parameters array
364 	 *     parameters = an array of #GParameter
365 	 *
366 	 * Returns: a new instance of
367 	 *     @object_type
368 	 *
369 	 * Throws: ConstructionException GTK+ fails to create the object.
370 	 */
371 	public this(GType objectType, GParameter[] parameters)
372 	{
373 		auto p = g_object_newv(objectType, cast(uint)parameters.length, parameters.ptr);
374 		
375 		if(p is null)
376 		{
377 			throw new ConstructionException("null returned by newv");
378 		}
379 		
380 		this(cast(GObject*) p, true);
381 	}
382 
383 	/** */
384 	public static size_t compatControl(size_t what, void* data)
385 	{
386 		return g_object_compat_control(what, data);
387 	}
388 
389 	/**
390 	 * Find the #GParamSpec with the given name for an
391 	 * interface. Generally, the interface vtable passed in as @g_iface
392 	 * will be the default vtable from g_type_default_interface_ref(), or,
393 	 * if you know the interface has already been loaded,
394 	 * g_type_default_interface_peek().
395 	 *
396 	 * Params:
397 	 *     gIface = any interface vtable for the
398 	 *         interface, or the default vtable for the interface
399 	 *     propertyName = name of a property to lookup.
400 	 *
401 	 * Returns: the #GParamSpec for the property of the
402 	 *     interface with the name @property_name, or %NULL if no
403 	 *     such property exists.
404 	 *
405 	 * Since: 2.4
406 	 */
407 	public static ParamSpec interfaceFindProperty(TypeInterface gIface, string propertyName)
408 	{
409 		auto p = g_object_interface_find_property((gIface is null) ? null : gIface.getTypeInterfaceStruct(), Str.toStringz(propertyName));
410 		
411 		if(p is null)
412 		{
413 			return null;
414 		}
415 		
416 		return ObjectG.getDObject!(ParamSpec)(cast(GParamSpec*) p);
417 	}
418 
419 	/**
420 	 * Add a property to an interface; this is only useful for interfaces
421 	 * that are added to GObject-derived types. Adding a property to an
422 	 * interface forces all objects classes with that interface to have a
423 	 * compatible property. The compatible property could be a newly
424 	 * created #GParamSpec, but normally
425 	 * g_object_class_override_property() will be used so that the object
426 	 * class only needs to provide an implementation and inherits the
427 	 * property description, default value, bounds, and so forth from the
428 	 * interface property.
429 	 *
430 	 * This function is meant to be called from the interface's default
431 	 * vtable initialization function (the @class_init member of
432 	 * #GTypeInfo.) It must not be called after after @class_init has
433 	 * been called for any object types implementing this interface.
434 	 *
435 	 * Params:
436 	 *     gIface = any interface vtable for the
437 	 *         interface, or the default
438 	 *         vtable for the interface.
439 	 *     pspec = the #GParamSpec for the new property
440 	 *
441 	 * Since: 2.4
442 	 */
443 	public static void interfaceInstallProperty(TypeInterface gIface, ParamSpec pspec)
444 	{
445 		g_object_interface_install_property((gIface is null) ? null : gIface.getTypeInterfaceStruct(), (pspec is null) ? null : pspec.getParamSpecStruct());
446 	}
447 
448 	/**
449 	 * Lists the properties of an interface.Generally, the interface
450 	 * vtable passed in as @g_iface will be the default vtable from
451 	 * g_type_default_interface_ref(), or, if you know the interface has
452 	 * already been loaded, g_type_default_interface_peek().
453 	 *
454 	 * Params:
455 	 *     gIface = any interface vtable for the
456 	 *         interface, or the default vtable for the interface
457 	 *
458 	 * Returns: a
459 	 *     pointer to an array of pointers to #GParamSpec
460 	 *     structures. The paramspecs are owned by GLib, but the
461 	 *     array should be freed with g_free() when you are done with
462 	 *     it.
463 	 *
464 	 * Since: 2.4
465 	 */
466 	public static ParamSpec[] interfaceListProperties(TypeInterface gIface)
467 	{
468 		uint nPropertiesP;
469 		
470 		auto p = g_object_interface_list_properties((gIface is null) ? null : gIface.getTypeInterfaceStruct(), &nPropertiesP);
471 		
472 		if(p is null)
473 		{
474 			return null;
475 		}
476 		
477 		ParamSpec[] arr = new ParamSpec[nPropertiesP];
478 		for(int i = 0; i < nPropertiesP; i++)
479 		{
480 			arr[i] = ObjectG.getDObject!(ParamSpec)(cast(GParamSpec*) p[i]);
481 		}
482 		
483 		return arr;
484 	}
485 
486 	/**
487 	 * Increases the reference count of the object by one and sets a
488 	 * callback to be called when all other references to the object are
489 	 * dropped, or when this is already the last reference to the object
490 	 * and another reference is established.
491 	 *
492 	 * This functionality is intended for binding @object to a proxy
493 	 * object managed by another memory manager. This is done with two
494 	 * paired references: the strong reference added by
495 	 * g_object_add_toggle_ref() and a reverse reference to the proxy
496 	 * object which is either a strong reference or weak reference.
497 	 *
498 	 * The setup is that when there are no other references to @object,
499 	 * only a weak reference is held in the reverse direction from @object
500 	 * to the proxy object, but when there are other references held to
501 	 * @object, a strong reference is held. The @notify callback is called
502 	 * when the reference from @object to the proxy object should be
503 	 * "toggled" from strong to weak (@is_last_ref true) or weak to strong
504 	 * (@is_last_ref false).
505 	 *
506 	 * Since a (normal) reference must be held to the object before
507 	 * calling g_object_add_toggle_ref(), the initial state of the reverse
508 	 * link is always strong.
509 	 *
510 	 * Multiple toggle references may be added to the same gobject,
511 	 * however if there are multiple toggle references to an object, none
512 	 * of them will ever be notified until all but one are removed.  For
513 	 * this reason, you should only ever use a toggle reference if there
514 	 * is important state in the proxy object.
515 	 *
516 	 * Params:
517 	 *     notify = a function to call when this reference is the
518 	 *         last reference to the object, or is no longer
519 	 *         the last reference.
520 	 *     data = data to pass to @notify
521 	 *
522 	 * Since: 2.8
523 	 */
524 	public void addToggleRef(GToggleNotify notify, void* data)
525 	{
526 		g_object_add_toggle_ref(gObject, notify, data);
527 	}
528 
529 	/**
530 	 * Adds a weak reference from weak_pointer to @object to indicate that
531 	 * the pointer located at @weak_pointer_location is only valid during
532 	 * the lifetime of @object. When the @object is finalized,
533 	 * @weak_pointer will be set to %NULL.
534 	 *
535 	 * Note that as with g_object_weak_ref(), the weak references created by
536 	 * this method are not thread-safe: they cannot safely be used in one
537 	 * thread if the object's last g_object_unref() might happen in another
538 	 * thread. Use #GWeakRef if thread-safety is required.
539 	 *
540 	 * Params:
541 	 *     weakPointerLocation = The memory address
542 	 *         of a pointer.
543 	 */
544 	public void addWeakPointer(ref void* weakPointerLocation)
545 	{
546 		g_object_add_weak_pointer(gObject, &weakPointerLocation);
547 	}
548 
549 	/**
550 	 * Creates a binding between @source_property on @source and @target_property
551 	 * on @target. Whenever the @source_property is changed the @target_property is
552 	 * updated using the same value. For instance:
553 	 *
554 	 * |[
555 	 * g_object_bind_property (action, "active", widget, "sensitive", 0);
556 	 * ]|
557 	 *
558 	 * Will result in the "sensitive" property of the widget #GObject instance to be
559 	 * updated with the same value of the "active" property of the action #GObject
560 	 * instance.
561 	 *
562 	 * If @flags contains %G_BINDING_BIDIRECTIONAL then the binding will be mutual:
563 	 * if @target_property on @target changes then the @source_property on @source
564 	 * will be updated as well.
565 	 *
566 	 * The binding will automatically be removed when either the @source or the
567 	 * @target instances are finalized. To remove the binding without affecting the
568 	 * @source and the @target you can just call g_object_unref() on the returned
569 	 * #GBinding instance.
570 	 *
571 	 * A #GObject can have multiple bindings.
572 	 *
573 	 * Params:
574 	 *     sourceProperty = the property on @source to bind
575 	 *     target = the target #GObject
576 	 *     targetProperty = the property on @target to bind
577 	 *     flags = flags to pass to #GBinding
578 	 *
579 	 * Returns: the #GBinding instance representing the
580 	 *     binding between the two #GObject instances. The binding is released
581 	 *     whenever the #GBinding reference count reaches zero.
582 	 *
583 	 * Since: 2.26
584 	 */
585 	public Binding bindProperty(string sourceProperty, ObjectG target, string targetProperty, GBindingFlags flags)
586 	{
587 		auto p = g_object_bind_property(gObject, Str.toStringz(sourceProperty), (target is null) ? null : target.getObjectGStruct(), Str.toStringz(targetProperty), flags);
588 		
589 		if(p is null)
590 		{
591 			return null;
592 		}
593 		
594 		return ObjectG.getDObject!(Binding)(cast(GBinding*) p);
595 	}
596 
597 	/**
598 	 * Complete version of g_object_bind_property().
599 	 *
600 	 * Creates a binding between @source_property on @source and @target_property
601 	 * on @target, allowing you to set the transformation functions to be used by
602 	 * the binding.
603 	 *
604 	 * If @flags contains %G_BINDING_BIDIRECTIONAL then the binding will be mutual:
605 	 * if @target_property on @target changes then the @source_property on @source
606 	 * will be updated as well. The @transform_from function is only used in case
607 	 * of bidirectional bindings, otherwise it will be ignored
608 	 *
609 	 * The binding will automatically be removed when either the @source or the
610 	 * @target instances are finalized. To remove the binding without affecting the
611 	 * @source and the @target you can just call g_object_unref() on the returned
612 	 * #GBinding instance.
613 	 *
614 	 * A #GObject can have multiple bindings.
615 	 *
616 	 * The same @user_data parameter will be used for both @transform_to
617 	 * and @transform_from transformation functions; the @notify function will
618 	 * be called once, when the binding is removed. If you need different data
619 	 * for each transformation function, please use
620 	 * g_object_bind_property_with_closures() instead.
621 	 *
622 	 * Params:
623 	 *     sourceProperty = the property on @source to bind
624 	 *     target = the target #GObject
625 	 *     targetProperty = the property on @target to bind
626 	 *     flags = flags to pass to #GBinding
627 	 *     transformTo = the transformation function
628 	 *         from the @source to the @target, or %NULL to use the default
629 	 *     transformFrom = the transformation function
630 	 *         from the @target to the @source, or %NULL to use the default
631 	 *     userData = custom data to be passed to the transformation functions,
632 	 *         or %NULL
633 	 *     notify = function to be called when disposing the binding, to free the
634 	 *         resources used by the transformation functions
635 	 *
636 	 * Returns: the #GBinding instance representing the
637 	 *     binding between the two #GObject instances. The binding is released
638 	 *     whenever the #GBinding reference count reaches zero.
639 	 *
640 	 * Since: 2.26
641 	 */
642 	public Binding bindPropertyFull(string sourceProperty, ObjectG target, string targetProperty, GBindingFlags flags, GBindingTransformFunc transformTo, GBindingTransformFunc transformFrom, void* userData, GDestroyNotify notify)
643 	{
644 		auto p = g_object_bind_property_full(gObject, Str.toStringz(sourceProperty), (target is null) ? null : target.getObjectGStruct(), Str.toStringz(targetProperty), flags, transformTo, transformFrom, userData, notify);
645 		
646 		if(p is null)
647 		{
648 			return null;
649 		}
650 		
651 		return ObjectG.getDObject!(Binding)(cast(GBinding*) p);
652 	}
653 
654 	/**
655 	 * Creates a binding between @source_property on @source and @target_property
656 	 * on @target, allowing you to set the transformation functions to be used by
657 	 * the binding.
658 	 *
659 	 * This function is the language bindings friendly version of
660 	 * g_object_bind_property_full(), using #GClosures instead of
661 	 * function pointers.
662 	 *
663 	 * Params:
664 	 *     sourceProperty = the property on @source to bind
665 	 *     target = the target #GObject
666 	 *     targetProperty = the property on @target to bind
667 	 *     flags = flags to pass to #GBinding
668 	 *     transformTo = a #GClosure wrapping the transformation function
669 	 *         from the @source to the @target, or %NULL to use the default
670 	 *     transformFrom = a #GClosure wrapping the transformation function
671 	 *         from the @target to the @source, or %NULL to use the default
672 	 *
673 	 * Returns: the #GBinding instance representing the
674 	 *     binding between the two #GObject instances. The binding is released
675 	 *     whenever the #GBinding reference count reaches zero.
676 	 *
677 	 * Since: 2.26
678 	 */
679 	public Binding bindPropertyWithClosures(string sourceProperty, ObjectG target, string targetProperty, GBindingFlags flags, Closure transformTo, Closure transformFrom)
680 	{
681 		auto p = g_object_bind_property_with_closures(gObject, Str.toStringz(sourceProperty), (target is null) ? null : target.getObjectGStruct(), Str.toStringz(targetProperty), flags, (transformTo is null) ? null : transformTo.getClosureStruct(), (transformFrom is null) ? null : transformFrom.getClosureStruct());
682 		
683 		if(p is null)
684 		{
685 			return null;
686 		}
687 		
688 		return ObjectG.getDObject!(Binding)(cast(GBinding*) p);
689 	}
690 
691 	/**
692 	 * This is a variant of g_object_get_data() which returns
693 	 * a 'duplicate' of the value. @dup_func defines the
694 	 * meaning of 'duplicate' in this context, it could e.g.
695 	 * take a reference on a ref-counted object.
696 	 *
697 	 * If the @key is not set on the object then @dup_func
698 	 * will be called with a %NULL argument.
699 	 *
700 	 * Note that @dup_func is called while user data of @object
701 	 * is locked.
702 	 *
703 	 * This function can be useful to avoid races when multiple
704 	 * threads are using object data on the same key on the same
705 	 * object.
706 	 *
707 	 * Params:
708 	 *     key = a string, naming the user data pointer
709 	 *     dupFunc = function to dup the value
710 	 *     userData = passed as user_data to @dup_func
711 	 *
712 	 * Returns: the result of calling @dup_func on the value
713 	 *     associated with @key on @object, or %NULL if not set.
714 	 *     If @dup_func is %NULL, the value is returned
715 	 *     unmodified.
716 	 *
717 	 * Since: 2.34
718 	 */
719 	public void* dupData(string key, GDuplicateFunc dupFunc, void* userData)
720 	{
721 		return g_object_dup_data(gObject, Str.toStringz(key), dupFunc, userData);
722 	}
723 
724 	/**
725 	 * This is a variant of g_object_get_qdata() which returns
726 	 * a 'duplicate' of the value. @dup_func defines the
727 	 * meaning of 'duplicate' in this context, it could e.g.
728 	 * take a reference on a ref-counted object.
729 	 *
730 	 * If the @quark is not set on the object then @dup_func
731 	 * will be called with a %NULL argument.
732 	 *
733 	 * Note that @dup_func is called while user data of @object
734 	 * is locked.
735 	 *
736 	 * This function can be useful to avoid races when multiple
737 	 * threads are using object data on the same key on the same
738 	 * object.
739 	 *
740 	 * Params:
741 	 *     quark = a #GQuark, naming the user data pointer
742 	 *     dupFunc = function to dup the value
743 	 *     userData = passed as user_data to @dup_func
744 	 *
745 	 * Returns: the result of calling @dup_func on the value
746 	 *     associated with @quark on @object, or %NULL if not set.
747 	 *     If @dup_func is %NULL, the value is returned
748 	 *     unmodified.
749 	 *
750 	 * Since: 2.34
751 	 */
752 	public void* dupQdata(GQuark quark, GDuplicateFunc dupFunc, void* userData)
753 	{
754 		return g_object_dup_qdata(gObject, quark, dupFunc, userData);
755 	}
756 
757 	/**
758 	 * This function is intended for #GObject implementations to re-enforce
759 	 * a [floating][floating-ref] object reference. Doing this is seldom
760 	 * required: all #GInitiallyUnowneds are created with a floating reference
761 	 * which usually just needs to be sunken by calling g_object_ref_sink().
762 	 *
763 	 * Since: 2.10
764 	 */
765 	public void forceFloating()
766 	{
767 		g_object_force_floating(gObject);
768 	}
769 
770 	/**
771 	 * Increases the freeze count on @object. If the freeze count is
772 	 * non-zero, the emission of "notify" signals on @object is
773 	 * stopped. The signals are queued until the freeze count is decreased
774 	 * to zero. Duplicate notifications are squashed so that at most one
775 	 * #GObject::notify signal is emitted for each property modified while the
776 	 * object is frozen.
777 	 *
778 	 * This is necessary for accessors that modify multiple properties to prevent
779 	 * premature notification while the object is still being modified.
780 	 */
781 	public void freezeNotify()
782 	{
783 		g_object_freeze_notify(gObject);
784 	}
785 
786 	/**
787 	 * Gets a named field from the objects table of associations (see g_object_set_data()).
788 	 *
789 	 * Params:
790 	 *     key = name of the key for that association
791 	 *
792 	 * Returns: the data if found, or %NULL if no such data exists.
793 	 */
794 	public void* getData(string key)
795 	{
796 		return g_object_get_data(gObject, Str.toStringz(key));
797 	}
798 
799 	/**
800 	 * Gets a property of an object. @value must have been initialized to the
801 	 * expected type of the property (or a type to which the expected type can be
802 	 * transformed) using g_value_init().
803 	 *
804 	 * In general, a copy is made of the property contents and the caller is
805 	 * responsible for freeing the memory by calling g_value_unset().
806 	 *
807 	 * Note that g_object_get_property() is really intended for language
808 	 * bindings, g_object_get() is much more convenient for C programming.
809 	 *
810 	 * Params:
811 	 *     propertyName = the name of the property to get
812 	 *     value = return location for the property value
813 	 */
814 	public void getProperty(string propertyName, Value value)
815 	{
816 		g_object_get_property(gObject, Str.toStringz(propertyName), (value is null) ? null : value.getValueStruct());
817 	}
818 
819 	/**
820 	 * This function gets back user data pointers stored via
821 	 * g_object_set_qdata().
822 	 *
823 	 * Params:
824 	 *     quark = A #GQuark, naming the user data pointer
825 	 *
826 	 * Returns: The user data pointer set, or %NULL
827 	 */
828 	public void* getQdata(GQuark quark)
829 	{
830 		return g_object_get_qdata(gObject, quark);
831 	}
832 
833 	/**
834 	 * Gets properties of an object.
835 	 *
836 	 * In general, a copy is made of the property contents and the caller
837 	 * is responsible for freeing the memory in the appropriate manner for
838 	 * the type, for instance by calling g_free() or g_object_unref().
839 	 *
840 	 * See g_object_get().
841 	 *
842 	 * Params:
843 	 *     firstPropertyName = name of the first property to get
844 	 *     varArgs = return location for the first property, followed optionally by more
845 	 *         name/return location pairs, followed by %NULL
846 	 */
847 	public void getValist(string firstPropertyName, void* varArgs)
848 	{
849 		g_object_get_valist(gObject, Str.toStringz(firstPropertyName), varArgs);
850 	}
851 
852 	/**
853 	 * Checks whether @object has a [floating][floating-ref] reference.
854 	 *
855 	 * Returns: %TRUE if @object has a floating reference
856 	 *
857 	 * Since: 2.10
858 	 */
859 	public bool isFloating()
860 	{
861 		return g_object_is_floating(gObject) != 0;
862 	}
863 
864 	/**
865 	 * Emits a "notify" signal for the property @property_name on @object.
866 	 *
867 	 * When possible, eg. when signaling a property change from within the class
868 	 * that registered the property, you should use g_object_notify_by_pspec()
869 	 * instead.
870 	 *
871 	 * Note that emission of the notify signal may be blocked with
872 	 * g_object_freeze_notify(). In this case, the signal emissions are queued
873 	 * and will be emitted (in reverse order) when g_object_thaw_notify() is
874 	 * called.
875 	 *
876 	 * Params:
877 	 *     propertyName = the name of a property installed on the class of @object.
878 	 */
879 	public void notify(string propertyName)
880 	{
881 		g_object_notify(gObject, Str.toStringz(propertyName));
882 	}
883 
884 	/**
885 	 * Emits a "notify" signal for the property specified by @pspec on @object.
886 	 *
887 	 * This function omits the property name lookup, hence it is faster than
888 	 * g_object_notify().
889 	 *
890 	 * One way to avoid using g_object_notify() from within the
891 	 * class that registered the properties, and using g_object_notify_by_pspec()
892 	 * instead, is to store the GParamSpec used with
893 	 * g_object_class_install_property() inside a static array, e.g.:
894 	 *
895 	 * |[<!-- language="C" -->
896 	 * enum
897 	 * {
898 	 * PROP_0,
899 	 * PROP_FOO,
900 	 * PROP_LAST
901 	 * };
902 	 *
903 	 * static GParamSpec *properties[PROP_LAST];
904 	 *
905 	 * static void
906 	 * my_object_class_init (MyObjectClass *klass)
907 	 * {
908 	 * properties[PROP_FOO] = g_param_spec_int ("foo", "Foo", "The foo",
909 	 * 0, 100,
910 	 * 50,
911 	 * G_PARAM_READWRITE);
912 	 * g_object_class_install_property (gobject_class,
913 	 * PROP_FOO,
914 	 * properties[PROP_FOO]);
915 	 * }
916 	 * ]|
917 	 *
918 	 * and then notify a change on the "foo" property with:
919 	 *
920 	 * |[<!-- language="C" -->
921 	 * g_object_notify_by_pspec (self, properties[PROP_FOO]);
922 	 * ]|
923 	 *
924 	 * Params:
925 	 *     pspec = the #GParamSpec of a property installed on the class of @object.
926 	 *
927 	 * Since: 2.26
928 	 */
929 	public void notifyByPspec(ParamSpec pspec)
930 	{
931 		g_object_notify_by_pspec(gObject, (pspec is null) ? null : pspec.getParamSpecStruct());
932 	}
933 
934 	/**
935 	 * Increases the reference count of @object.
936 	 *
937 	 * Returns: the same @object
938 	 */
939 	public ObjectG doref()
940 	{
941 		auto p = g_object_ref(gObject);
942 		
943 		if(p is null)
944 		{
945 			return null;
946 		}
947 		
948 		return ObjectG.getDObject!(ObjectG)(cast(GObject*) p);
949 	}
950 
951 	/**
952 	 * Increase the reference count of @object, and possibly remove the
953 	 * [floating][floating-ref] reference, if @object has a floating reference.
954 	 *
955 	 * In other words, if the object is floating, then this call "assumes
956 	 * ownership" of the floating reference, converting it to a normal
957 	 * reference by clearing the floating flag while leaving the reference
958 	 * count unchanged.  If the object is not floating, then this call
959 	 * adds a new normal reference increasing the reference count by one.
960 	 *
961 	 * Returns: @object
962 	 *
963 	 * Since: 2.10
964 	 */
965 	public ObjectG refSink()
966 	{
967 		auto p = g_object_ref_sink(gObject);
968 		
969 		if(p is null)
970 		{
971 			return null;
972 		}
973 		
974 		return ObjectG.getDObject!(ObjectG)(cast(GObject*) p);
975 	}
976 
977 	/**
978 	 * Removes a reference added with g_object_add_toggle_ref(). The
979 	 * reference count of the object is decreased by one.
980 	 *
981 	 * Params:
982 	 *     notify = a function to call when this reference is the
983 	 *         last reference to the object, or is no longer
984 	 *         the last reference.
985 	 *     data = data to pass to @notify
986 	 *
987 	 * Since: 2.8
988 	 */
989 	public void removeToggleRef(GToggleNotify notify, void* data)
990 	{
991 		g_object_remove_toggle_ref(gObject, notify, data);
992 	}
993 
994 	/**
995 	 * Removes a weak reference from @object that was previously added
996 	 * using g_object_add_weak_pointer(). The @weak_pointer_location has
997 	 * to match the one used with g_object_add_weak_pointer().
998 	 *
999 	 * Params:
1000 	 *     weakPointerLocation = The memory address
1001 	 *         of a pointer.
1002 	 */
1003 	public void removeWeakPointer(ref void* weakPointerLocation)
1004 	{
1005 		g_object_remove_weak_pointer(gObject, &weakPointerLocation);
1006 	}
1007 
1008 	/**
1009 	 * Compares the user data for the key @key on @object with
1010 	 * @oldval, and if they are the same, replaces @oldval with
1011 	 * @newval.
1012 	 *
1013 	 * This is like a typical atomic compare-and-exchange
1014 	 * operation, for user data on an object.
1015 	 *
1016 	 * If the previous value was replaced then ownership of the
1017 	 * old value (@oldval) is passed to the caller, including
1018 	 * the registered destroy notify for it (passed out in @old_destroy).
1019 	 * Its up to the caller to free this as he wishes, which may
1020 	 * or may not include using @old_destroy as sometimes replacement
1021 	 * should not destroy the object in the normal way.
1022 	 *
1023 	 * Params:
1024 	 *     key = a string, naming the user data pointer
1025 	 *     oldval = the old value to compare against
1026 	 *     newval = the new value
1027 	 *     destroy = a destroy notify for the new value
1028 	 *     oldDestroy = destroy notify for the existing value
1029 	 *
1030 	 * Returns: %TRUE if the existing value for @key was replaced
1031 	 *     by @newval, %FALSE otherwise.
1032 	 *
1033 	 * Since: 2.34
1034 	 */
1035 	public bool replaceData(string key, void* oldval, void* newval, GDestroyNotify destroy, GDestroyNotify* oldDestroy)
1036 	{
1037 		return g_object_replace_data(gObject, Str.toStringz(key), oldval, newval, destroy, oldDestroy) != 0;
1038 	}
1039 
1040 	/**
1041 	 * Compares the user data for the key @quark on @object with
1042 	 * @oldval, and if they are the same, replaces @oldval with
1043 	 * @newval.
1044 	 *
1045 	 * This is like a typical atomic compare-and-exchange
1046 	 * operation, for user data on an object.
1047 	 *
1048 	 * If the previous value was replaced then ownership of the
1049 	 * old value (@oldval) is passed to the caller, including
1050 	 * the registered destroy notify for it (passed out in @old_destroy).
1051 	 * Its up to the caller to free this as he wishes, which may
1052 	 * or may not include using @old_destroy as sometimes replacement
1053 	 * should not destroy the object in the normal way.
1054 	 *
1055 	 * Params:
1056 	 *     quark = a #GQuark, naming the user data pointer
1057 	 *     oldval = the old value to compare against
1058 	 *     newval = the new value
1059 	 *     destroy = a destroy notify for the new value
1060 	 *     oldDestroy = destroy notify for the existing value
1061 	 *
1062 	 * Returns: %TRUE if the existing value for @quark was replaced
1063 	 *     by @newval, %FALSE otherwise.
1064 	 *
1065 	 * Since: 2.34
1066 	 */
1067 	public bool replaceQdata(GQuark quark, void* oldval, void* newval, GDestroyNotify destroy, GDestroyNotify* oldDestroy)
1068 	{
1069 		return g_object_replace_qdata(gObject, quark, oldval, newval, destroy, oldDestroy) != 0;
1070 	}
1071 
1072 	/**
1073 	 * Releases all references to other objects. This can be used to break
1074 	 * reference cycles.
1075 	 *
1076 	 * This function should only be called from object system implementations.
1077 	 */
1078 	public void runDispose()
1079 	{
1080 		g_object_run_dispose(gObject);
1081 	}
1082 
1083 	/**
1084 	 * Each object carries around a table of associations from
1085 	 * strings to pointers.  This function lets you set an association.
1086 	 *
1087 	 * If the object already had an association with that name,
1088 	 * the old association will be destroyed.
1089 	 *
1090 	 * Params:
1091 	 *     key = name of the key
1092 	 *     data = data to associate with that key
1093 	 */
1094 	public void setData(string key, void* data)
1095 	{
1096 		g_object_set_data(gObject, Str.toStringz(key), data);
1097 	}
1098 
1099 	/**
1100 	 * Like g_object_set_data() except it adds notification
1101 	 * for when the association is destroyed, either by setting it
1102 	 * to a different value or when the object is destroyed.
1103 	 *
1104 	 * Note that the @destroy callback is not called if @data is %NULL.
1105 	 *
1106 	 * Params:
1107 	 *     key = name of the key
1108 	 *     data = data to associate with that key
1109 	 *     destroy = function to call when the association is destroyed
1110 	 */
1111 	public void setDataFull(string key, void* data, GDestroyNotify destroy)
1112 	{
1113 		g_object_set_data_full(gObject, Str.toStringz(key), data, destroy);
1114 	}
1115 
1116 	/**
1117 	 * Sets a property on an object.
1118 	 *
1119 	 * Params:
1120 	 *     propertyName = the name of the property to set
1121 	 *     value = the value
1122 	 */
1123 	public void setProperty(string propertyName, Value value)
1124 	{
1125 		g_object_set_property(gObject, Str.toStringz(propertyName), (value is null) ? null : value.getValueStruct());
1126 	}
1127 
1128 	/**
1129 	 * This sets an opaque, named pointer on an object.
1130 	 * The name is specified through a #GQuark (retrived e.g. via
1131 	 * g_quark_from_static_string()), and the pointer
1132 	 * can be gotten back from the @object with g_object_get_qdata()
1133 	 * until the @object is finalized.
1134 	 * Setting a previously set user data pointer, overrides (frees)
1135 	 * the old pointer set, using #NULL as pointer essentially
1136 	 * removes the data stored.
1137 	 *
1138 	 * Params:
1139 	 *     quark = A #GQuark, naming the user data pointer
1140 	 *     data = An opaque user data pointer
1141 	 */
1142 	public void setQdata(GQuark quark, void* data)
1143 	{
1144 		g_object_set_qdata(gObject, quark, data);
1145 	}
1146 
1147 	/**
1148 	 * This function works like g_object_set_qdata(), but in addition,
1149 	 * a void (*destroy) (gpointer) function may be specified which is
1150 	 * called with @data as argument when the @object is finalized, or
1151 	 * the data is being overwritten by a call to g_object_set_qdata()
1152 	 * with the same @quark.
1153 	 *
1154 	 * Params:
1155 	 *     quark = A #GQuark, naming the user data pointer
1156 	 *     data = An opaque user data pointer
1157 	 *     destroy = Function to invoke with @data as argument, when @data
1158 	 *         needs to be freed
1159 	 */
1160 	public void setQdataFull(GQuark quark, void* data, GDestroyNotify destroy)
1161 	{
1162 		g_object_set_qdata_full(gObject, quark, data, destroy);
1163 	}
1164 
1165 	/**
1166 	 * Sets properties on an object.
1167 	 *
1168 	 * Params:
1169 	 *     firstPropertyName = name of the first property to set
1170 	 *     varArgs = value for the first property, followed optionally by more
1171 	 *         name/value pairs, followed by %NULL
1172 	 */
1173 	public void setValist(string firstPropertyName, void* varArgs)
1174 	{
1175 		g_object_set_valist(gObject, Str.toStringz(firstPropertyName), varArgs);
1176 	}
1177 
1178 	/**
1179 	 * Remove a specified datum from the object's data associations,
1180 	 * without invoking the association's destroy handler.
1181 	 *
1182 	 * Params:
1183 	 *     key = name of the key
1184 	 *
1185 	 * Returns: the data if found, or %NULL if no such data exists.
1186 	 */
1187 	public void* stealData(string key)
1188 	{
1189 		return g_object_steal_data(gObject, Str.toStringz(key));
1190 	}
1191 
1192 	/**
1193 	 * This function gets back user data pointers stored via
1194 	 * g_object_set_qdata() and removes the @data from object
1195 	 * without invoking its destroy() function (if any was
1196 	 * set).
1197 	 * Usually, calling this function is only required to update
1198 	 * user data pointers with a destroy notifier, for example:
1199 	 * |[<!-- language="C" -->
1200 	 * void
1201 	 * object_add_to_user_list (GObject     *object,
1202 	 * const gchar *new_string)
1203 	 * {
1204 	 * // the quark, naming the object data
1205 	 * GQuark quark_string_list = g_quark_from_static_string ("my-string-list");
1206 	 * // retrive the old string list
1207 	 * GList *list = g_object_steal_qdata (object, quark_string_list);
1208 	 *
1209 	 * // prepend new string
1210 	 * list = g_list_prepend (list, g_strdup (new_string));
1211 	 * // this changed 'list', so we need to set it again
1212 	 * g_object_set_qdata_full (object, quark_string_list, list, free_string_list);
1213 	 * }
1214 	 * static void
1215 	 * free_string_list (gpointer data)
1216 	 * {
1217 	 * GList *node, *list = data;
1218 	 *
1219 	 * for (node = list; node; node = node->next)
1220 	 * g_free (node->data);
1221 	 * g_list_free (list);
1222 	 * }
1223 	 * ]|
1224 	 * Using g_object_get_qdata() in the above example, instead of
1225 	 * g_object_steal_qdata() would have left the destroy function set,
1226 	 * and thus the partial string list would have been freed upon
1227 	 * g_object_set_qdata_full().
1228 	 *
1229 	 * Params:
1230 	 *     quark = A #GQuark, naming the user data pointer
1231 	 *
1232 	 * Returns: The user data pointer set, or %NULL
1233 	 */
1234 	public void* stealQdata(GQuark quark)
1235 	{
1236 		return g_object_steal_qdata(gObject, quark);
1237 	}
1238 
1239 	/**
1240 	 * Reverts the effect of a previous call to
1241 	 * g_object_freeze_notify(). The freeze count is decreased on @object
1242 	 * and when it reaches zero, queued "notify" signals are emitted.
1243 	 *
1244 	 * Duplicate notifications for each property are squashed so that at most one
1245 	 * #GObject::notify signal is emitted for each property, in the reverse order
1246 	 * in which they have been queued.
1247 	 *
1248 	 * It is an error to call this function when the freeze count is zero.
1249 	 */
1250 	public void thawNotify()
1251 	{
1252 		g_object_thaw_notify(gObject);
1253 	}
1254 
1255 	/**
1256 	 * Decreases the reference count of @object. When its reference count
1257 	 * drops to 0, the object is finalized (i.e. its memory is freed).
1258 	 *
1259 	 * If the pointer to the #GObject may be reused in future (for example, if it is
1260 	 * an instance variable of another object), it is recommended to clear the
1261 	 * pointer to %NULL rather than retain a dangling pointer to a potentially
1262 	 * invalid #GObject instance. Use g_clear_object() for this.
1263 	 */
1264 	public void unref()
1265 	{
1266 		g_object_unref(gObject);
1267 	}
1268 
1269 	/**
1270 	 * This function essentially limits the life time of the @closure to
1271 	 * the life time of the object. That is, when the object is finalized,
1272 	 * the @closure is invalidated by calling g_closure_invalidate() on
1273 	 * it, in order to prevent invocations of the closure with a finalized
1274 	 * (nonexisting) object. Also, g_object_ref() and g_object_unref() are
1275 	 * added as marshal guards to the @closure, to ensure that an extra
1276 	 * reference count is held on @object during invocation of the
1277 	 * @closure.  Usually, this function will be called on closures that
1278 	 * use this @object as closure data.
1279 	 *
1280 	 * Params:
1281 	 *     closure = GClosure to watch
1282 	 */
1283 	public void watchClosure(Closure closure)
1284 	{
1285 		g_object_watch_closure(gObject, (closure is null) ? null : closure.getClosureStruct());
1286 	}
1287 
1288 	/**
1289 	 * Adds a weak reference callback to an object. Weak references are
1290 	 * used for notification when an object is finalized. They are called
1291 	 * "weak references" because they allow you to safely hold a pointer
1292 	 * to an object without calling g_object_ref() (g_object_ref() adds a
1293 	 * strong reference, that is, forces the object to stay alive).
1294 	 *
1295 	 * Note that the weak references created by this method are not
1296 	 * thread-safe: they cannot safely be used in one thread if the
1297 	 * object's last g_object_unref() might happen in another thread.
1298 	 * Use #GWeakRef if thread-safety is required.
1299 	 *
1300 	 * Params:
1301 	 *     notify = callback to invoke before the object is freed
1302 	 *     data = extra data to pass to notify
1303 	 */
1304 	public void weakRef(GWeakNotify notify, void* data)
1305 	{
1306 		g_object_weak_ref(gObject, notify, data);
1307 	}
1308 
1309 	/**
1310 	 * Removes a weak reference callback to an object.
1311 	 *
1312 	 * Params:
1313 	 *     notify = callback to search for
1314 	 *     data = data to search for
1315 	 */
1316 	public void weakUnref(GWeakNotify notify, void* data)
1317 	{
1318 		g_object_weak_unref(gObject, notify, data);
1319 	}
1320 
1321 	/**
1322 	 * Clears a reference to a #GObject.
1323 	 *
1324 	 * @object_ptr must not be %NULL.
1325 	 *
1326 	 * If the reference is %NULL then this function does nothing.
1327 	 * Otherwise, the reference count of the object is decreased and the
1328 	 * pointer is set to %NULL.
1329 	 *
1330 	 * A macro is also included that allows this function to be used without
1331 	 * pointer casts.
1332 	 *
1333 	 * Params:
1334 	 *     objectPtr = a pointer to a #GObject reference
1335 	 *
1336 	 * Since: 2.28
1337 	 */
1338 	public static void clearObject(ref ObjectG objectPtr)
1339 	{
1340 		GObject* outobjectPtr = objectPtr.getObjectGStruct();
1341 		
1342 		g_clear_object(&outobjectPtr);
1343 		
1344 		objectPtr = ObjectG.getDObject!(ObjectG)(outobjectPtr);
1345 	}
1346 }