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