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.ParamSpec;
26 
27 private import glib.Str;
28 private import gobject.ObjectG;
29 private import gobject.Value;
30 private import gtkc.gobject;
31 public  import gtkc.gobjecttypes;
32 
33 
34 /**
35  * #GParamSpec is an object structure that encapsulates the metadata
36  * required to specify parameters, such as e.g. #GObject properties.
37  * 
38  * ## Parameter names # {#canonical-parameter-names}
39  * 
40  * Parameter names need to start with a letter (a-z or A-Z).
41  * Subsequent characters can be letters, numbers or a '-'.
42  * All other characters are replaced by a '-' during construction.
43  * The result of this replacement is called the canonical name of
44  * the parameter.
45  */
46 public class ParamSpec
47 {
48 	/** the main Gtk struct */
49 	protected GParamSpec* gParamSpec;
50 	protected bool ownedRef;
51 
52 	/** Get the main Gtk struct */
53 	public GParamSpec* getParamSpecStruct()
54 	{
55 		return gParamSpec;
56 	}
57 
58 	/** the main Gtk struct as a void* */
59 	protected void* getStruct()
60 	{
61 		return cast(void*)gParamSpec;
62 	}
63 
64 	/**
65 	 * Sets our main struct and passes it to the parent class.
66 	 */
67 	public this (GParamSpec* gParamSpec, bool ownedRef = false)
68 	{
69 		this.gParamSpec = gParamSpec;
70 		this.ownedRef = ownedRef;
71 	}
72 
73 
74 	/**
75 	 * Creates a new #GParamSpec instance.
76 	 *
77 	 * A property name consists of segments consisting of ASCII letters and
78 	 * digits, separated by either the '-' or '_' character. The first
79 	 * character of a property name must be a letter. Names which violate these
80 	 * rules lead to undefined behaviour.
81 	 *
82 	 * When creating and looking up a #GParamSpec, either separator can be
83 	 * used, but they cannot be mixed. Using '-' is considerably more
84 	 * efficient and in fact required when using property names as detail
85 	 * strings for signals.
86 	 *
87 	 * Beyond the name, #GParamSpecs have two more descriptive
88 	 * strings associated with them, the @nick, which should be suitable
89 	 * for use as a label for the property in a property editor, and the
90 	 * @blurb, which should be a somewhat longer description, suitable for
91 	 * e.g. a tooltip. The @nick and @blurb should ideally be localized.
92 	 *
93 	 * Params:
94 	 *     paramType = the #GType for the property; must be derived from #G_TYPE_PARAM
95 	 *     name = the canonical name of the property
96 	 *     nick = the nickname of the property
97 	 *     blurb = a short description of the property
98 	 *     flags = a combination of #GParamFlags
99 	 *
100 	 * Return: a newly allocated #GParamSpec instance
101 	 */
102 	public static void* internal(GType paramType, string name, string nick, string blurb, GParamFlags flags)
103 	{
104 		return g_param_spec_internal(paramType, Str.toStringz(name), Str.toStringz(nick), Str.toStringz(blurb), flags);
105 	}
106 
107 	/**
108 	 * Get the short description of a #GParamSpec.
109 	 *
110 	 * Return: the short description of @pspec.
111 	 */
112 	public string getBlurb()
113 	{
114 		return Str.toString(g_param_spec_get_blurb(gParamSpec));
115 	}
116 
117 	/**
118 	 * Gets the default value of @pspec as a pointer to a #GValue.
119 	 *
120 	 * The #GValue will remain value for the life of @pspec.
121 	 *
122 	 * Return: a pointer to a #GValue which must not be modified
123 	 *
124 	 * Since: 2.38
125 	 */
126 	public Value getDefaultValue()
127 	{
128 		auto p = g_param_spec_get_default_value(gParamSpec);
129 		
130 		if(p is null)
131 		{
132 			return null;
133 		}
134 		
135 		return ObjectG.getDObject!(Value)(cast(GValue*) p);
136 	}
137 
138 	/**
139 	 * Get the name of a #GParamSpec.
140 	 *
141 	 * The name is always an "interned" string (as per g_intern_string()).
142 	 * This allows for pointer-value comparisons.
143 	 *
144 	 * Return: the name of @pspec.
145 	 */
146 	public string getName()
147 	{
148 		return Str.toString(g_param_spec_get_name(gParamSpec));
149 	}
150 
151 	/**
152 	 * Gets the GQuark for the name.
153 	 *
154 	 * Return: the GQuark for @pspec->name.
155 	 *
156 	 * Since: 2.46
157 	 */
158 	public GQuark getNameQuark()
159 	{
160 		return g_param_spec_get_name_quark(gParamSpec);
161 	}
162 
163 	/**
164 	 * Get the nickname of a #GParamSpec.
165 	 *
166 	 * Return: the nickname of @pspec.
167 	 */
168 	public string getNick()
169 	{
170 		return Str.toString(g_param_spec_get_nick(gParamSpec));
171 	}
172 
173 	/**
174 	 * Gets back user data pointers stored via g_param_spec_set_qdata().
175 	 *
176 	 * Params:
177 	 *     quark = a #GQuark, naming the user data pointer
178 	 *
179 	 * Return: the user data pointer set, or %NULL
180 	 */
181 	public void* getQdata(GQuark quark)
182 	{
183 		return g_param_spec_get_qdata(gParamSpec, quark);
184 	}
185 
186 	/**
187 	 * If the paramspec redirects operations to another paramspec,
188 	 * returns that paramspec. Redirect is used typically for
189 	 * providing a new implementation of a property in a derived
190 	 * type while preserving all the properties from the parent
191 	 * type. Redirection is established by creating a property
192 	 * of type #GParamSpecOverride. See g_object_class_override_property()
193 	 * for an example of the use of this capability.
194 	 *
195 	 * Return: paramspec to which requests on this
196 	 *     paramspec should be redirected, or %NULL if none.
197 	 *
198 	 * Since: 2.4
199 	 */
200 	public ParamSpec getRedirectTarget()
201 	{
202 		auto p = g_param_spec_get_redirect_target(gParamSpec);
203 		
204 		if(p is null)
205 		{
206 			return null;
207 		}
208 		
209 		return ObjectG.getDObject!(ParamSpec)(cast(GParamSpec*) p);
210 	}
211 
212 	/**
213 	 * Increments the reference count of @pspec.
214 	 *
215 	 * Return: the #GParamSpec that was passed into this function
216 	 */
217 	public ParamSpec doref()
218 	{
219 		auto p = g_param_spec_ref(gParamSpec);
220 		
221 		if(p is null)
222 		{
223 			return null;
224 		}
225 		
226 		return ObjectG.getDObject!(ParamSpec)(cast(GParamSpec*) p);
227 	}
228 
229 	/**
230 	 * Convenience function to ref and sink a #GParamSpec.
231 	 *
232 	 * Return: the #GParamSpec that was passed into this function
233 	 *
234 	 * Since: 2.10
235 	 */
236 	public ParamSpec refSink()
237 	{
238 		auto p = g_param_spec_ref_sink(gParamSpec);
239 		
240 		if(p is null)
241 		{
242 			return null;
243 		}
244 		
245 		return ObjectG.getDObject!(ParamSpec)(cast(GParamSpec*) p);
246 	}
247 
248 	/**
249 	 * Sets an opaque, named pointer on a #GParamSpec. The name is
250 	 * specified through a #GQuark (retrieved e.g. via
251 	 * g_quark_from_static_string()), and the pointer can be gotten back
252 	 * from the @pspec with g_param_spec_get_qdata().  Setting a
253 	 * previously set user data pointer, overrides (frees) the old pointer
254 	 * set, using %NULL as pointer essentially removes the data stored.
255 	 *
256 	 * Params:
257 	 *     quark = a #GQuark, naming the user data pointer
258 	 *     data = an opaque user data pointer
259 	 */
260 	public void setQdata(GQuark quark, void* data)
261 	{
262 		g_param_spec_set_qdata(gParamSpec, quark, data);
263 	}
264 
265 	/**
266 	 * This function works like g_param_spec_set_qdata(), but in addition,
267 	 * a `void (*destroy) (gpointer)` function may be
268 	 * specified which is called with @data as argument when the @pspec is
269 	 * finalized, or the data is being overwritten by a call to
270 	 * g_param_spec_set_qdata() with the same @quark.
271 	 *
272 	 * Params:
273 	 *     quark = a #GQuark, naming the user data pointer
274 	 *     data = an opaque user data pointer
275 	 *     destroy = function to invoke with @data as argument, when @data needs to
276 	 *         be freed
277 	 */
278 	public void setQdataFull(GQuark quark, void* data, GDestroyNotify destroy)
279 	{
280 		g_param_spec_set_qdata_full(gParamSpec, quark, data, destroy);
281 	}
282 
283 	/**
284 	 * The initial reference count of a newly created #GParamSpec is 1,
285 	 * even though no one has explicitly called g_param_spec_ref() on it
286 	 * yet. So the initial reference count is flagged as "floating", until
287 	 * someone calls `g_param_spec_ref (pspec); g_param_spec_sink
288 	 * (pspec);` in sequence on it, taking over the initial
289 	 * reference count (thus ending up with a @pspec that has a reference
290 	 * count of 1 still, but is not flagged "floating" anymore).
291 	 */
292 	public void sink()
293 	{
294 		g_param_spec_sink(gParamSpec);
295 	}
296 
297 	/**
298 	 * Gets back user data pointers stored via g_param_spec_set_qdata()
299 	 * and removes the @data from @pspec without invoking its destroy()
300 	 * function (if any was set).  Usually, calling this function is only
301 	 * required to update user data pointers with a destroy notifier.
302 	 *
303 	 * Params:
304 	 *     quark = a #GQuark, naming the user data pointer
305 	 *
306 	 * Return: the user data pointer set, or %NULL
307 	 */
308 	public void* stealQdata(GQuark quark)
309 	{
310 		return g_param_spec_steal_qdata(gParamSpec, quark);
311 	}
312 
313 	/**
314 	 * Decrements the reference count of a @pspec.
315 	 */
316 	public void unref()
317 	{
318 		g_param_spec_unref(gParamSpec);
319 	}
320 
321 	/**
322 	 * Registers @name as the name of a new static type derived from
323 	 * #G_TYPE_PARAM. The type system uses the information contained in
324 	 * the #GParamSpecTypeInfo structure pointed to by @info to manage the
325 	 * #GParamSpec type and its instances.
326 	 *
327 	 * Params:
328 	 *     name = 0-terminated string used as the name of the new #GParamSpec type.
329 	 *     pspecInfo = The #GParamSpecTypeInfo for this #GParamSpec type.
330 	 *
331 	 * Return: The new type identifier.
332 	 */
333 	public static GType paramTypeRegisterStatic(string name, GParamSpecTypeInfo* pspecInfo)
334 	{
335 		return g_param_type_register_static(Str.toStringz(name), pspecInfo);
336 	}
337 
338 	/**
339 	 * Transforms @src_value into @dest_value if possible, and then
340 	 * validates @dest_value, in order for it to conform to @pspec.  If
341 	 * @strict_validation is %TRUE this function will only succeed if the
342 	 * transformed @dest_value complied to @pspec without modifications.
343 	 *
344 	 * See also g_value_type_transformable(), g_value_transform() and
345 	 * g_param_value_validate().
346 	 *
347 	 * Params:
348 	 *     pspec = a valid #GParamSpec
349 	 *     srcValue = souce #GValue
350 	 *     destValue = destination #GValue of correct type for @pspec
351 	 *     strictValidation = %TRUE requires @dest_value to conform to @pspec
352 	 *         without modifications
353 	 *
354 	 * Return: %TRUE if transformation and validation were successful,
355 	 *     %FALSE otherwise and @dest_value is left untouched.
356 	 */
357 	public static bool paramValueConvert(ParamSpec pspec, Value srcValue, Value destValue, bool strictValidation)
358 	{
359 		return g_param_value_convert((pspec is null) ? null : pspec.getParamSpecStruct(), (srcValue is null) ? null : srcValue.getValueStruct(), (destValue is null) ? null : destValue.getValueStruct(), strictValidation) != 0;
360 	}
361 
362 	/**
363 	 * Checks whether @value contains the default value as specified in @pspec.
364 	 *
365 	 * Params:
366 	 *     pspec = a valid #GParamSpec
367 	 *     value = a #GValue of correct type for @pspec
368 	 *
369 	 * Return: whether @value contains the canonical default for this @pspec
370 	 */
371 	public static bool paramValueDefaults(ParamSpec pspec, Value value)
372 	{
373 		return g_param_value_defaults((pspec is null) ? null : pspec.getParamSpecStruct(), (value is null) ? null : value.getValueStruct()) != 0;
374 	}
375 
376 	/**
377 	 * Sets @value to its default value as specified in @pspec.
378 	 *
379 	 * Params:
380 	 *     pspec = a valid #GParamSpec
381 	 *     value = a #GValue of correct type for @pspec
382 	 */
383 	public static void paramValueSetDefault(ParamSpec pspec, Value value)
384 	{
385 		g_param_value_set_default((pspec is null) ? null : pspec.getParamSpecStruct(), (value is null) ? null : value.getValueStruct());
386 	}
387 
388 	/**
389 	 * Ensures that the contents of @value comply with the specifications
390 	 * set out by @pspec. For example, a #GParamSpecInt might require
391 	 * that integers stored in @value may not be smaller than -42 and not be
392 	 * greater than +42. If @value contains an integer outside of this range,
393 	 * it is modified accordingly, so the resulting value will fit into the
394 	 * range -42 .. +42.
395 	 *
396 	 * Params:
397 	 *     pspec = a valid #GParamSpec
398 	 *     value = a #GValue of correct type for @pspec
399 	 *
400 	 * Return: whether modifying @value was necessary to ensure validity
401 	 */
402 	public static bool paramValueValidate(ParamSpec pspec, Value value)
403 	{
404 		return g_param_value_validate((pspec is null) ? null : pspec.getParamSpecStruct(), (value is null) ? null : value.getValueStruct()) != 0;
405 	}
406 
407 	/**
408 	 * Compares @value1 with @value2 according to @pspec, and return -1, 0 or +1,
409 	 * if @value1 is found to be less than, equal to or greater than @value2,
410 	 * respectively.
411 	 *
412 	 * Params:
413 	 *     pspec = a valid #GParamSpec
414 	 *     value1 = a #GValue of correct type for @pspec
415 	 *     value2 = a #GValue of correct type for @pspec
416 	 *
417 	 * Return: -1, 0 or +1, for a less than, equal to or greater than result
418 	 */
419 	public static int paramValuesCmp(ParamSpec pspec, Value value1, Value value2)
420 	{
421 		return g_param_values_cmp((pspec is null) ? null : pspec.getParamSpecStruct(), (value1 is null) ? null : value1.getValueStruct(), (value2 is null) ? null : value2.getValueStruct());
422 	}
423 }