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