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 * A property name consists of segments consisting of ASCII letters and 43 * 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: a newly allocated #GParamSpec instance 108 */ 109 public static ParamSpec internal(GType paramType, string name, string nick, string blurb, GParamFlags flags) 110 { 111 auto __p = g_param_spec_internal(paramType, Str.toStringz(name), Str.toStringz(nick), Str.toStringz(blurb), flags); 112 113 if(__p is null) 114 { 115 return null; 116 } 117 118 return ObjectG.getDObject!(ParamSpec)(cast(GParamSpec*) __p); 119 } 120 121 /** 122 * Get the short description of a #GParamSpec. 123 * 124 * Returns: the short description of @pspec. 125 */ 126 public string getBlurb() 127 { 128 return Str.toString(g_param_spec_get_blurb(gParamSpec)); 129 } 130 131 /** 132 * Gets the default value of @pspec as a pointer to a #GValue. 133 * 134 * The #GValue will remain valid for the life of @pspec. 135 * 136 * Returns: a pointer to a #GValue which must not be modified 137 * 138 * Since: 2.38 139 */ 140 public Value getDefaultValue() 141 { 142 auto __p = g_param_spec_get_default_value(gParamSpec); 143 144 if(__p is null) 145 { 146 return null; 147 } 148 149 return ObjectG.getDObject!(Value)(cast(GValue*) __p); 150 } 151 152 /** 153 * Get the name of a #GParamSpec. 154 * 155 * The name is always an "interned" string (as per g_intern_string()). 156 * This allows for pointer-value comparisons. 157 * 158 * Returns: the name of @pspec. 159 */ 160 public string getName() 161 { 162 return Str.toString(g_param_spec_get_name(gParamSpec)); 163 } 164 165 /** 166 * Gets the GQuark for the name. 167 * 168 * Returns: the GQuark for @pspec->name. 169 * 170 * Since: 2.46 171 */ 172 public GQuark getNameQuark() 173 { 174 return g_param_spec_get_name_quark(gParamSpec); 175 } 176 177 /** 178 * Get the nickname of a #GParamSpec. 179 * 180 * Returns: the nickname of @pspec. 181 */ 182 public string getNick() 183 { 184 return Str.toString(g_param_spec_get_nick(gParamSpec)); 185 } 186 187 /** 188 * Gets back user data pointers stored via g_param_spec_set_qdata(). 189 * 190 * Params: 191 * quark = a #GQuark, naming the user data pointer 192 * 193 * Returns: the user data pointer set, or %NULL 194 */ 195 public void* getQdata(GQuark quark) 196 { 197 return g_param_spec_get_qdata(gParamSpec, quark); 198 } 199 200 /** 201 * If the paramspec redirects operations to another paramspec, 202 * returns that paramspec. Redirect is used typically for 203 * providing a new implementation of a property in a derived 204 * type while preserving all the properties from the parent 205 * type. Redirection is established by creating a property 206 * of type #GParamSpecOverride. See g_object_class_override_property() 207 * for an example of the use of this capability. 208 * 209 * Returns: paramspec to which requests on this 210 * paramspec should be redirected, or %NULL if none. 211 * 212 * Since: 2.4 213 */ 214 public ParamSpec getRedirectTarget() 215 { 216 auto __p = g_param_spec_get_redirect_target(gParamSpec); 217 218 if(__p is null) 219 { 220 return null; 221 } 222 223 return ObjectG.getDObject!(ParamSpec)(cast(GParamSpec*) __p); 224 } 225 226 alias doref = ref_; 227 /** 228 * Increments the reference count of @pspec. 229 * 230 * Returns: the #GParamSpec that was passed into this function 231 */ 232 public ParamSpec ref_() 233 { 234 auto __p = g_param_spec_ref(gParamSpec); 235 236 if(__p is null) 237 { 238 return null; 239 } 240 241 return ObjectG.getDObject!(ParamSpec)(cast(GParamSpec*) __p); 242 } 243 244 /** 245 * Convenience function to ref and sink a #GParamSpec. 246 * 247 * Returns: the #GParamSpec that was passed into this function 248 * 249 * Since: 2.10 250 */ 251 public ParamSpec refSink() 252 { 253 auto __p = g_param_spec_ref_sink(gParamSpec); 254 255 if(__p is null) 256 { 257 return null; 258 } 259 260 return ObjectG.getDObject!(ParamSpec)(cast(GParamSpec*) __p); 261 } 262 263 /** 264 * Sets an opaque, named pointer on a #GParamSpec. The name is 265 * specified through a #GQuark (retrieved e.g. via 266 * g_quark_from_static_string()), and the pointer can be gotten back 267 * from the @pspec with g_param_spec_get_qdata(). Setting a 268 * previously set user data pointer, overrides (frees) the old pointer 269 * set, using %NULL as pointer essentially removes the data stored. 270 * 271 * Params: 272 * quark = a #GQuark, naming the user data pointer 273 * data = an opaque user data pointer 274 */ 275 public void setQdata(GQuark quark, void* data) 276 { 277 g_param_spec_set_qdata(gParamSpec, quark, data); 278 } 279 280 /** 281 * This function works like g_param_spec_set_qdata(), but in addition, 282 * a `void (*destroy) (gpointer)` function may be 283 * specified which is called with @data as argument when the @pspec is 284 * finalized, or the data is being overwritten by a call to 285 * g_param_spec_set_qdata() with the same @quark. 286 * 287 * Params: 288 * quark = a #GQuark, naming the user data pointer 289 * data = an opaque user data pointer 290 * destroy = function to invoke with @data as argument, when @data needs to 291 * be freed 292 */ 293 public void setQdataFull(GQuark quark, void* data, GDestroyNotify destroy) 294 { 295 g_param_spec_set_qdata_full(gParamSpec, quark, data, destroy); 296 } 297 298 /** 299 * The initial reference count of a newly created #GParamSpec is 1, 300 * even though no one has explicitly called g_param_spec_ref() on it 301 * yet. So the initial reference count is flagged as "floating", until 302 * someone calls `g_param_spec_ref (pspec); g_param_spec_sink 303 * (pspec);` in sequence on it, taking over the initial 304 * reference count (thus ending up with a @pspec that has a reference 305 * count of 1 still, but is not flagged "floating" anymore). 306 */ 307 public void sink() 308 { 309 g_param_spec_sink(gParamSpec); 310 } 311 312 /** 313 * Gets back user data pointers stored via g_param_spec_set_qdata() 314 * and removes the @data from @pspec without invoking its destroy() 315 * function (if any was set). Usually, calling this function is only 316 * required to update user data pointers with a destroy notifier. 317 * 318 * Params: 319 * quark = a #GQuark, naming the user data pointer 320 * 321 * Returns: the user data pointer set, or %NULL 322 */ 323 public void* stealQdata(GQuark quark) 324 { 325 return g_param_spec_steal_qdata(gParamSpec, quark); 326 } 327 328 /** 329 * Decrements the reference count of a @pspec. 330 */ 331 public void unref() 332 { 333 g_param_spec_unref(gParamSpec); 334 } 335 336 /** 337 * Registers @name as the name of a new static type derived from 338 * #G_TYPE_PARAM. The type system uses the information contained in 339 * the #GParamSpecTypeInfo structure pointed to by @info to manage the 340 * #GParamSpec type and its instances. 341 * 342 * Params: 343 * name = 0-terminated string used as the name of the new #GParamSpec type. 344 * pspecInfo = The #GParamSpecTypeInfo for this #GParamSpec type. 345 * 346 * Returns: The new type identifier. 347 */ 348 public static GType paramTypeRegisterStatic(string name, GParamSpecTypeInfo* pspecInfo) 349 { 350 return g_param_type_register_static(Str.toStringz(name), pspecInfo); 351 } 352 353 /** 354 * Transforms @src_value into @dest_value if possible, and then 355 * validates @dest_value, in order for it to conform to @pspec. If 356 * @strict_validation is %TRUE this function will only succeed if the 357 * transformed @dest_value complied to @pspec without modifications. 358 * 359 * See also g_value_type_transformable(), g_value_transform() and 360 * g_param_value_validate(). 361 * 362 * Params: 363 * pspec = a valid #GParamSpec 364 * srcValue = souce #GValue 365 * destValue = destination #GValue of correct type for @pspec 366 * strictValidation = %TRUE requires @dest_value to conform to @pspec 367 * without modifications 368 * 369 * Returns: %TRUE if transformation and validation were successful, 370 * %FALSE otherwise and @dest_value is left untouched. 371 */ 372 public static bool paramValueConvert(ParamSpec pspec, Value srcValue, Value destValue, bool strictValidation) 373 { 374 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; 375 } 376 377 /** 378 * Checks whether @value contains the default value as specified in @pspec. 379 * 380 * Params: 381 * pspec = a valid #GParamSpec 382 * value = a #GValue of correct type for @pspec 383 * 384 * Returns: whether @value contains the canonical default for this @pspec 385 */ 386 public static bool paramValueDefaults(ParamSpec pspec, Value value) 387 { 388 return g_param_value_defaults((pspec is null) ? null : pspec.getParamSpecStruct(), (value is null) ? null : value.getValueStruct()) != 0; 389 } 390 391 /** 392 * Sets @value to its default value as specified in @pspec. 393 * 394 * Params: 395 * pspec = a valid #GParamSpec 396 * value = a #GValue of correct type for @pspec; since 2.64, you 397 * can also pass an empty #GValue, initialized with %G_VALUE_INIT 398 */ 399 public static void paramValueSetDefault(ParamSpec pspec, Value value) 400 { 401 g_param_value_set_default((pspec is null) ? null : pspec.getParamSpecStruct(), (value is null) ? null : value.getValueStruct()); 402 } 403 404 /** 405 * Ensures that the contents of @value comply with the specifications 406 * set out by @pspec. For example, a #GParamSpecInt might require 407 * that integers stored in @value may not be smaller than -42 and not be 408 * greater than +42. If @value contains an integer outside of this range, 409 * it is modified accordingly, so the resulting value will fit into the 410 * range -42 .. +42. 411 * 412 * Params: 413 * pspec = a valid #GParamSpec 414 * value = a #GValue of correct type for @pspec 415 * 416 * Returns: whether modifying @value was necessary to ensure validity 417 */ 418 public static bool paramValueValidate(ParamSpec pspec, Value value) 419 { 420 return g_param_value_validate((pspec is null) ? null : pspec.getParamSpecStruct(), (value is null) ? null : value.getValueStruct()) != 0; 421 } 422 423 /** 424 * Compares @value1 with @value2 according to @pspec, and return -1, 0 or +1, 425 * if @value1 is found to be less than, equal to or greater than @value2, 426 * respectively. 427 * 428 * Params: 429 * pspec = a valid #GParamSpec 430 * value1 = a #GValue of correct type for @pspec 431 * value2 = a #GValue of correct type for @pspec 432 * 433 * Returns: -1, 0 or +1, for a less than, equal to or greater than result 434 */ 435 public static int paramValuesCmp(ParamSpec pspec, Value value1, Value value2) 436 { 437 return g_param_values_cmp((pspec is null) ? null : pspec.getParamSpecStruct(), (value1 is null) ? null : value1.getValueStruct(), (value2 is null) ? null : value2.getValueStruct()); 438 } 439 }