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

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

Initial release

File size: 7.5 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.ObjectClass;
22
23private import gi.gobject;
24public  import gi.gobjecttypes;
25private import glib.Str;
26private import gobject.ObjectG;
27private import gobject.ParamSpec;
28
29
30/**
31 * The class structure for the GObject type.
32 *
33 * <example>
34 * <title>Implementing singletons using a constructor</title>
35 * <programlisting>
36 * static MySingleton *the_singleton = NULL;
37 *
38 * static GObject*
39 * my_singleton_constructor (GType                  type,
40 * guint                  n_construct_params,
41 * GObjectConstructParam *construct_params)
42 * {
43 * GObject *object;
44 *
45 * if (!the_singleton)
46 * {
47 * object = G_OBJECT_CLASS (parent_class)->constructor (type,
48 * n_construct_params,
49 * construct_params);
50 * the_singleton = MY_SINGLETON (object);
51 * }
52 * else
53 * object = g_object_ref (G_OBJECT (the_singleton));
54 *
55 * return object;
56 * }
57 * </programlisting></example>
58 */
59public class ObjectClass
60{
61        /** the main Gtk struct */
62        protected GObjectClass* gObjectClass;
63        protected bool ownedRef;
64
65        /** Get the main Gtk struct */
66        public GObjectClass* getObjectClassStruct()
67        {
68                return gObjectClass;
69        }
70
71        /** the main Gtk struct as a void* */
72        protected void* getStruct()
73        {
74                return cast(void*)gObjectClass;
75        }
76
77        /**
78         * Sets our main struct and passes it to the parent class.
79         */
80        public this (GObjectClass* gObjectClass, bool ownedRef = false)
81        {
82                this.gObjectClass = gObjectClass;
83                this.ownedRef = ownedRef;
84        }
85
86
87        /**
88         * Looks up the #GParamSpec for a property of a class.
89         *
90         * Params:
91         *     propertyName = the name of the property to look up
92         *
93         * Returns: the #GParamSpec for the property, or
94         *     %NULL if the class doesn't have a property of that name
95         */
96        public ParamSpec findProperty(string propertyName)
97        {
98                auto p = g_object_class_find_property(gObjectClass, Str.toStringz(propertyName));
99               
100                if(p is null)
101                {
102                        return null;
103                }
104               
105                return ObjectG.getDObject!(ParamSpec)(cast(GParamSpec*) p);
106        }
107
108        /**
109         * Installs new properties from an array of #GParamSpecs.
110         *
111         * All properties should be installed during the class initializer.  It
112         * is possible to install properties after that, but doing so is not
113         * recommend, and specifically, is not guaranteed to be thread-safe vs.
114         * use of properties on the same type on other threads.
115         *
116         * The property id of each property is the index of each #GParamSpec in
117         * the @pspecs array.
118         *
119         * The property id of 0 is treated specially by #GObject and it should not
120         * be used to store a #GParamSpec.
121         *
122         * This function should be used if you plan to use a static array of
123         * #GParamSpecs and g_object_notify_by_pspec(). For instance, this
124         * class initialization:
125         *
126         * |[<!-- language="C" -->
127         * enum {
128         * PROP_0, PROP_FOO, PROP_BAR, N_PROPERTIES
129         * };
130         *
131         * static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
132         *
133         * static void
134         * my_object_class_init (MyObjectClass *klass)
135         * {
136         * GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
137         *
138         * obj_properties[PROP_FOO] =
139         * g_param_spec_int ("foo", "Foo", "Foo",
140         * -1, G_MAXINT,
141         * 0,
142         * G_PARAM_READWRITE);
143         *
144         * obj_properties[PROP_BAR] =
145         * g_param_spec_string ("bar", "Bar", "Bar",
146         * NULL,
147         * G_PARAM_READWRITE);
148         *
149         * gobject_class->set_property = my_object_set_property;
150         * gobject_class->get_property = my_object_get_property;
151         * g_object_class_install_properties (gobject_class,
152         * N_PROPERTIES,
153         * obj_properties);
154         * }
155         * ]|
156         *
157         * allows calling g_object_notify_by_pspec() to notify of property changes:
158         *
159         * |[<!-- language="C" -->
160         * void
161         * my_object_set_foo (MyObject *self, gint foo)
162         * {
163         * if (self->foo != foo)
164         * {
165         * self->foo = foo;
166         * g_object_notify_by_pspec (G_OBJECT (self), obj_properties[PROP_FOO]);
167         * }
168         * }
169         * ]|
170         *
171         * Params:
172         *     nPspecs = the length of the #GParamSpecs array
173         *     pspecs = the #GParamSpecs array
174         *         defining the new properties
175         *
176         * Since: 2.26
177         */
178        public void installProperties(ParamSpec[] pspecs)
179        {
180                GParamSpec*[] pspecsArray = new GParamSpec*[pspecs.length];
181                for ( int i = 0; i < pspecs.length; i++ )
182                {
183                        pspecsArray[i] = pspecs[i].getParamSpecStruct();
184                }
185               
186                g_object_class_install_properties(gObjectClass, cast(uint)pspecs.length, pspecsArray.ptr);
187        }
188
189        /**
190         * Installs a new property.
191         *
192         * All properties should be installed during the class initializer.  It
193         * is possible to install properties after that, but doing so is not
194         * recommend, and specifically, is not guaranteed to be thread-safe vs.
195         * use of properties on the same type on other threads.
196         *
197         * Note that it is possible to redefine a property in a derived class,
198         * by installing a property with the same name. This can be useful at times,
199         * e.g. to change the range of allowed values or the default value.
200         *
201         * Params:
202         *     propertyId = the id for the new property
203         *     pspec = the #GParamSpec for the new property
204         */
205        public void installProperty(uint propertyId, ParamSpec pspec)
206        {
207                g_object_class_install_property(gObjectClass, propertyId, (pspec is null) ? null : pspec.getParamSpecStruct());
208        }
209
210        /**
211         * Get an array of #GParamSpec* for all properties of a class.
212         *
213         * Returns: an array of
214         *     #GParamSpec* which should be freed after use
215         */
216        public ParamSpec[] listProperties()
217        {
218                uint nProperties;
219               
220                auto p = g_object_class_list_properties(gObjectClass, &nProperties);
221               
222                if(p is null)
223                {
224                        return null;
225                }
226               
227                ParamSpec[] arr = new ParamSpec[nProperties];
228                for(int i = 0; i < nProperties; i++)
229                {
230                        arr[i] = ObjectG.getDObject!(ParamSpec)(cast(GParamSpec*) p[i]);
231                }
232               
233                return arr;
234        }
235
236        /**
237         * Registers @property_id as referring to a property with the name
238         * @name in a parent class or in an interface implemented by @oclass.
239         * This allows this class to "override" a property implementation in
240         * a parent class or to provide the implementation of a property from
241         * an interface.
242         *
243         * Internally, overriding is implemented by creating a property of type
244         * #GParamSpecOverride; generally operations that query the properties of
245         * the object class, such as g_object_class_find_property() or
246         * g_object_class_list_properties() will return the overridden
247         * property. However, in one case, the @construct_properties argument of
248         * the @constructor virtual function, the #GParamSpecOverride is passed
249         * instead, so that the @param_id field of the #GParamSpec will be
250         * correct.  For virtually all uses, this makes no difference. If you
251         * need to get the overridden property, you can call
252         * g_param_spec_get_redirect_target().
253         *
254         * Params:
255         *     propertyId = the new property ID
256         *     name = the name of a property registered in a parent class or
257         *         in an interface of this class.
258         *
259         * Since: 2.4
260         */
261        public void overrideProperty(uint propertyId, string name)
262        {
263                g_object_class_override_property(gObjectClass, propertyId, Str.toStringz(name));
264        }
265}
Note: See TracBrowser for help on using the repository browser.