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