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 gobject.c.functions;
31 public  import gobject.c.types;
32 
33 
34 /**
35  * The class structure for the GObject type.
36  * 
37  * |[<!-- language="C" -->
38  * // Example of implementing a singleton using a constructor.
39  * static MySingleton *the_singleton = NULL;
40  * 
41  * static GObject*
42  * my_singleton_constructor (GType                  type,
43  * guint                  n_construct_params,
44  * GObjectConstructParam *construct_params)
45  * {
46  * GObject *object;
47  * 
48  * if (!the_singleton)
49  * {
50  * object = G_OBJECT_CLASS (parent_class)->constructor (type,
51  * n_construct_params,
52  * construct_params);
53  * the_singleton = MY_SINGLETON (object);
54  * }
55  * else
56  * object = g_object_ref (G_OBJECT (the_singleton));
57  * 
58  * return object;
59  * }
60  * ]|
61  */
62 public class ObjectClass
63 {
64 	/** the main Gtk struct */
65 	protected GObjectClass* gObjectClass;
66 	protected bool ownedRef;
67 
68 	/** Get the main Gtk struct */
69 	public GObjectClass* getObjectClassStruct(bool transferOwnership = false)
70 	{
71 		if (transferOwnership)
72 			ownedRef = false;
73 		return gObjectClass;
74 	}
75 
76 	/** the main Gtk struct as a void* */
77 	protected void* getStruct()
78 	{
79 		return cast(void*)gObjectClass;
80 	}
81 
82 	/**
83 	 * Sets our main struct and passes it to the parent class.
84 	 */
85 	public this (GObjectClass* gObjectClass, bool ownedRef = false)
86 	{
87 		this.gObjectClass = gObjectClass;
88 		this.ownedRef = ownedRef;
89 	}
90 
91 
92 	/**
93 	 * Looks up the #GParamSpec for a property of a class.
94 	 *
95 	 * Params:
96 	 *     propertyName = the name of the property to look up
97 	 *
98 	 * Returns: the #GParamSpec for the property, or
99 	 *     %NULL if the class doesn't have a property of that name
100 	 */
101 	public ParamSpec findProperty(string propertyName)
102 	{
103 		auto __p = g_object_class_find_property(gObjectClass, Str.toStringz(propertyName));
104 
105 		if(__p is null)
106 		{
107 			return null;
108 		}
109 
110 		return ObjectG.getDObject!(ParamSpec)(cast(GParamSpec*) __p);
111 	}
112 
113 	/**
114 	 * Installs new properties from an array of #GParamSpecs.
115 	 *
116 	 * All properties should be installed during the class initializer.  It
117 	 * is possible to install properties after that, but doing so is not
118 	 * recommend, and specifically, is not guaranteed to be thread-safe vs.
119 	 * use of properties on the same type on other threads.
120 	 *
121 	 * The property id of each property is the index of each #GParamSpec in
122 	 * the @pspecs array.
123 	 *
124 	 * The property id of 0 is treated specially by #GObject and it should not
125 	 * be used to store a #GParamSpec.
126 	 *
127 	 * This function should be used if you plan to use a static array of
128 	 * #GParamSpecs and g_object_notify_by_pspec(). For instance, this
129 	 * class initialization:
130 	 *
131 	 * |[<!-- language="C" -->
132 	 * enum {
133 	 * PROP_0, PROP_FOO, PROP_BAR, N_PROPERTIES
134 	 * };
135 	 *
136 	 * static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
137 	 *
138 	 * static void
139 	 * my_object_class_init (MyObjectClass *klass)
140 	 * {
141 	 * GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
142 	 *
143 	 * obj_properties[PROP_FOO] =
144 	 * g_param_spec_int ("foo", "Foo", "Foo",
145 	 * -1, G_MAXINT,
146 	 * 0,
147 	 * G_PARAM_READWRITE);
148 	 *
149 	 * obj_properties[PROP_BAR] =
150 	 * g_param_spec_string ("bar", "Bar", "Bar",
151 	 * NULL,
152 	 * G_PARAM_READWRITE);
153 	 *
154 	 * gobject_class->set_property = my_object_set_property;
155 	 * gobject_class->get_property = my_object_get_property;
156 	 * g_object_class_install_properties (gobject_class,
157 	 * N_PROPERTIES,
158 	 * obj_properties);
159 	 * }
160 	 * ]|
161 	 *
162 	 * allows calling g_object_notify_by_pspec() to notify of property changes:
163 	 *
164 	 * |[<!-- language="C" -->
165 	 * void
166 	 * my_object_set_foo (MyObject *self, gint foo)
167 	 * {
168 	 * if (self->foo != foo)
169 	 * {
170 	 * self->foo = foo;
171 	 * g_object_notify_by_pspec (G_OBJECT (self), obj_properties[PROP_FOO]);
172 	 * }
173 	 * }
174 	 * ]|
175 	 *
176 	 * Params:
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 	 * Returns: 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 }