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