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