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