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 	protected bool ownedRef;
68 
69 	/** Get the main Gtk struct */
70 	public GObjectClass* getObjectClassStruct()
71 	{
72 		return gObjectClass;
73 	}
74 
75 	/** the main Gtk struct as a void* */
76 	protected void* getStruct()
77 	{
78 		return cast(void*)gObjectClass;
79 	}
80 
81 	/**
82 	 * Sets our main struct and passes it to the parent class.
83 	 */
84 	public this (GObjectClass* gObjectClass, bool ownedRef = false)
85 	{
86 		this.gObjectClass = gObjectClass;
87 		this.ownedRef = ownedRef;
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 	 * Return: an array of
218 	 *     #GParamSpec* which should be freed after use
219 	 */
220 	public ParamSpec[] listProperties()
221 	{
222 		uint nProperties;
223 		
224 		auto p = g_object_class_list_properties(gObjectClass, &nProperties);
225 		
226 		if(p is null)
227 		{
228 			return null;
229 		}
230 		
231 		ParamSpec[] arr = new ParamSpec[nProperties];
232 		for(int i = 0; i < nProperties; i++)
233 		{
234 			arr[i] = ObjectG.getDObject!(ParamSpec)(cast(GParamSpec*) p[i]);
235 		}
236 		
237 		return arr;
238 	}
239 
240 	/**
241 	 * Registers @property_id as referring to a property with the name
242 	 * @name in a parent class or in an interface implemented by @oclass.
243 	 * This allows this class to "override" a property implementation in
244 	 * a parent class or to provide the implementation of a property from
245 	 * an interface.
246 	 *
247 	 * Internally, overriding is implemented by creating a property of type
248 	 * #GParamSpecOverride; generally operations that query the properties of
249 	 * the object class, such as g_object_class_find_property() or
250 	 * g_object_class_list_properties() will return the overridden
251 	 * property. However, in one case, the @construct_properties argument of
252 	 * the @constructor virtual function, the #GParamSpecOverride is passed
253 	 * instead, so that the @param_id field of the #GParamSpec will be
254 	 * correct.  For virtually all uses, this makes no difference. If you
255 	 * need to get the overridden property, you can call
256 	 * g_param_spec_get_redirect_target().
257 	 *
258 	 * Params:
259 	 *     propertyId = the new property ID
260 	 *     name = the name of a property registered in a parent class or
261 	 *         in an interface of this class.
262 	 *
263 	 * Since: 2.4
264 	 */
265 	public void overrideProperty(uint propertyId, string name)
266 	{
267 		g_object_class_override_property(gObjectClass, propertyId, Str.toStringz(name));
268 	}
269 }