source: appstream-generator/build/girepo/gobject/ObjectG.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

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