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