Document interface properties and GParamSpecOverride.
[platform/upstream/glib.git] / docs / reference / gobject / tmpl / gparamspec.sgml
1 <!-- ##### SECTION Title ##### -->
2 GParamSpec
3
4 <!-- ##### SECTION Short_Description ##### -->
5 Metadata for parameter specifications
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
9 #GParamSpec is an object structure that encapsulates the metadata
10 required to specify parameters, such as e.g. #GObject properties.
11 </para>
12
13 <!-- ##### SECTION See_Also ##### -->
14 <para>
15 g_object_class_install_property(), g_object_set(), g_object_get(),
16 g_object_set_property(), g_object_get_property(), g_value_register_transform_func()
17 </para>
18
19 <!-- ##### MACRO G_TYPE_IS_PARAM ##### -->
20 <para>
21 Returns whether @type "is a" %G_TYPE_PARAM.
22 </para>
23
24 @type: a #GType ID
25
26
27 <!-- ##### MACRO G_PARAM_SPEC ##### -->
28 <para>
29 Casts a derived #GParamSpec object (e.g. of type #GParamSpecInt) into
30 a #GParamSpec object.
31 </para>
32
33 @pspec: a valid #GParamSpec
34
35
36 <!-- ##### MACRO G_IS_PARAM_SPEC ##### -->
37 <para>
38 Checks whether @pspec "is a" valid #GParamSpec structure of type %G_TYPE_PARAM
39 or derived.
40 </para>
41
42 @pspec: a #GParamSpec
43
44
45 <!-- ##### MACRO G_PARAM_SPEC_CLASS ##### -->
46 <para>
47 Casts a derived #GParamSpecClass structure into a #GParamSpecClass structure.
48 </para>
49
50 @pclass: a valid #GParamSpecClass
51
52
53 <!-- ##### MACRO G_IS_PARAM_SPEC_CLASS ##### -->
54 <para>
55 Checks whether @pclass "is a" valid #GParamSpecClass structure of type 
56 %G_TYPE_PARAM or derived.
57 </para>
58
59 @pclass: a #GParamSpecClass
60
61
62 <!-- ##### MACRO G_PARAM_SPEC_GET_CLASS ##### -->
63 <para>
64 Retrieves the #GParamSpecClass of a #GParamSpec.
65 </para>
66
67 @pspec: a valid #GParamSpec
68
69
70 <!-- ##### MACRO G_PARAM_SPEC_TYPE ##### -->
71 <para>
72 Retrieves the #GType of this @pspec.
73 </para>
74
75 @pspec: a valid #GParamSpec
76
77
78 <!-- ##### MACRO G_PARAM_SPEC_TYPE_NAME ##### -->
79 <para>
80 Retrieves the #GType name of this @pspec.
81 </para>
82
83 @pspec: a valid #GParamSpec
84
85
86 <!-- ##### MACRO G_PARAM_SPEC_VALUE_TYPE ##### -->
87 <para>
88 Retrieves the #GType to initialize a #GValue for this parameter.
89 </para>
90
91 @pspec: a valid #GParamSpec
92
93
94 <!-- ##### STRUCT GParamSpec ##### -->
95 <para>
96
97 </para>
98
99 @g_type_instance: private #GTypeInstance portion
100 @name:            name of this parameter
101 @flags:           #GParamFlags flags for this parameter
102 @value_type:      the #GValue type for this parameter
103 @owner_type:      #GType type that uses (introduces) this paremeter
104
105 <!-- ##### STRUCT GParamSpecClass ##### -->
106 <para>
107
108 </para>
109
110 @g_type_class: 
111 @value_type: 
112 @finalize: 
113 @value_set_default: 
114 @value_validate: 
115 @values_cmp: 
116 @dummy: 
117
118 <!-- ##### ENUM GParamFlags ##### -->
119 <para>
120 Through the #GParamFlags flag values, certain aspects of parameters
121 can be configured.
122 </para>
123
124 @G_PARAM_READABLE:       the parameter is readable
125 @G_PARAM_WRITABLE:       the parameter is writable
126 @G_PARAM_CONSTRUCT:      the parameter will be set upon object construction
127 @G_PARAM_CONSTRUCT_ONLY: the parameter will only be set upon object construction
128 @G_PARAM_LAX_VALIDATION: upon parameter conversion (see g_param_value_convert())
129                          strict validation is not required
130 @G_PARAM_PRIVATE: 
131
132 <!-- ##### MACRO G_PARAM_READWRITE ##### -->
133 <para>
134 #GParamFlags value alias for %G_PARAM_READABLE | %G_PARAM_WRITABLE.
135 </para>
136
137
138
139 <!-- ##### MACRO G_PARAM_MASK ##### -->
140 <para>
141 Mask containing the bits of #GParamSpec.flags which are reserved for GLib.
142 </para>
143
144
145
146 <!-- ##### MACRO G_PARAM_USER_SHIFT ##### -->
147 <para>
148 Minimum shift count to be used for user defined flags, to be stored in
149 #GParamSpec.flags.
150 </para>
151
152
153
154 <!-- ##### FUNCTION g_param_spec_ref ##### -->
155 <para>
156 Increments the reference count of @pspec.
157 </para>
158
159 @pspec:   a valid #GParamSpec
160 @Returns: the #GParamSpec that was passed into this function
161
162
163 <!-- ##### FUNCTION g_param_spec_unref ##### -->
164 <para>
165 Decrements the reference count of a @pspec.
166 </para>
167
168 @pspec: a valid #GParamSpec
169
170
171 <!-- ##### FUNCTION g_param_spec_sink ##### -->
172 <para>
173 The initial reference count of a newly created #GParamSpec is 1, even 
174 though no one has explicitly called g_param_spec_ref() on it yet. So the 
175 initial reference count is flagged as "floating", until someone calls 
176 <literal>g_param_spec_ref (@pspec); g_param_spec_sink (@pspec);</literal>
177 in sequence on it, taking over the initial reference count (thus
178 ending up with a @pspec that has a reference count of 1 still, but is
179 not flagged "floating" anymore).
180 </para>
181
182 @pspec: a valid #GParamSpec
183
184
185 <!-- ##### FUNCTION g_param_value_set_default ##### -->
186 <para>
187 Sets @value to its default value as specified in @pspec.
188 </para>
189
190 @pspec: a valid #GParamSpec
191 @value: a #GValue of correct type for @pspec
192
193
194 <!-- ##### FUNCTION g_param_value_defaults ##### -->
195 <para>
196 Checks whether @value contains the default value as specified in @pspec.
197 </para>
198
199 @pspec:   a valid #GParamSpec
200 @value:   a #GValue of correct type for @pspec
201 @Returns: whether @value contains the canonical defualt for this @pspec
202
203
204 <!-- ##### FUNCTION g_param_value_validate ##### -->
205 <para>
206 Ensures that the contents of @value comply with the specifications
207 set out by @pspec. For example, a #GParamSpecInt might require
208 that integers stored in @value may not be smaller than -42 and not be
209 greater than +42. If @value contains an integer outside of this range,
210 it is modified accordingly, so the resulting value will fit into the
211 range -42 .. +42.
212 </para>
213
214 @pspec:   a valid #GParamSpec
215 @value:   a #GValue of correct type for @pspec
216 @Returns: whether modifying @value was necessary to ensure validity
217
218
219 <!-- ##### FUNCTION g_param_value_convert ##### -->
220 <para>
221 Transforms @src_value into @dest_value if possible, and then validates 
222 @dest_value, in order for it to conform to @pspec.
223 If @strict_validation is %TRUE this function will only succeed if
224 the transformed @dest_value complied to @pspec without modifications.
225
226 See also g_value_type_transformable(), g_value_transform() and
227 g_param_value_validate().
228 </para>
229
230 @pspec:             a valid #GParamSpec
231 @src_value:         souce #GValue
232 @dest_value:        destination #GValue of correct type for @pspec
233 @strict_validation: %TRUE requires @dest_value to conform to @pspec without modifications
234 @Returns:           %TRUE if transformation and validation were successfull,
235                     %FALSE otherwise and @dest_value is left untouched.
236
237
238 <!-- ##### FUNCTION g_param_values_cmp ##### -->
239 <para>
240 Compares @value1 with @value2 according to @pspec, and return -1, 0 or +1,
241 if @value1 is found to be less than, equal to or greater than @value2, 
242 respectively.
243 </para>
244
245 @pspec:   a valid #GParamSpec
246 @value1:  a #GValue of correct type for @pspec
247 @value2:  a #GValue of correct type for @pspec
248 @Returns: -1, 0 or +1, for a less than, equal to or greater than result
249
250
251 <!-- ##### FUNCTION g_param_spec_get_name ##### -->
252 <para>
253 Returns the name of a #GParamSpec.
254 </para>
255
256 @pspec: a valid #GParamSpec
257 @Returns: the name of @pspec.
258
259
260 <!-- ##### FUNCTION g_param_spec_get_nick ##### -->
261 <para>
262 Returns the nickname of a #GParamSpec.
263 </para>
264
265 @pspec: a valid #GParamSpec
266 @Returns: the nickname of @pspec.
267
268
269 <!-- ##### FUNCTION g_param_spec_get_blurb ##### -->
270 <para>
271 Returns the short description of a #GParamSpec.
272 </para>
273
274 @pspec: a valid #GParamSpec
275 @Returns: the short description of @pspec.
276
277
278 <!-- ##### FUNCTION g_param_spec_get_qdata ##### -->
279 <para>
280 Gets back user data pointers stored via g_param_spec_set_qdata().
281 </para>
282
283 @pspec: a valid #GParamSpec
284 @quark: a #GQuark, naming the user data pointer
285 @Returns: the user data pointer set, or %NULL
286
287
288 <!-- ##### FUNCTION g_param_spec_set_qdata ##### -->
289 <para>
290 Sets an opaque, named pointer on a #GParamSpec. The name is specified 
291 through a #GQuark (retrieved e.g. via g_quark_from_static_string()), and 
292 the pointer can be gotten back from the @pspec with g_param_spec_get_qdata().
293 Setting a previously set user data pointer, overrides (frees)
294 the old pointer set, using #NULL as pointer essentially
295 removes the data stored.
296 </para>
297
298 @pspec: the #GParamSpec to set store a user data pointer
299 @quark: a #GQuark, naming the user data pointer
300 @data: an opaque user data pointer
301
302
303 <!-- ##### FUNCTION g_param_spec_set_qdata_full ##### -->
304 <para>
305 This function works like g_param_spec_set_qdata(), but in addition, 
306 a <literal>void (*destroy) (gpointer)</literal> function may be 
307 specified which is called with @data as argument when the @pspec is 
308 finalized, or the data is being overwritten by a call to 
309 g_param_spec_set_qdata() with the same @quark.
310 </para>
311
312 @pspec:   the #GParamSpec to set store a user data pointer
313 @quark:   a #GQuark, naming the user data pointer
314 @data:    an opaque user data pointer
315 @destroy: function to invoke with @data as argument, when @data needs to
316           be freed
317
318
319 <!-- ##### FUNCTION g_param_spec_steal_qdata ##### -->
320 <para>
321 Gets back user data pointers stored via g_param_spec_set_qdata() and 
322 removes the @data from @pspec without invoking it's destroy() function 
323 (if any was set).
324 Usually, calling this function is only required to update
325 user data pointers with a destroy notifier.
326 </para>
327
328 @pspec: the #GParamSpec to get a stored user data pointer from
329 @quark: a #GQuark, naming the user data pointer
330 @Returns: the user data pointer set, or %NULL
331
332
333 <!-- ##### FUNCTION g_param_spec_get_redirect_target ##### -->
334 <para>
335 If the paramspec redirects operations to another paramspec,
336 returns that paramspec. Redirect is used typically for
337 providing a new implementation of a property in a derived
338 type while perserving all the properties from the parent
339 type. Redirection is established by creating a property
340 of type #GParamSpecOverride. See g_object_override_property()
341 for an example of the use of this capability.
342 </para>
343
344 @pspec: a #GParamSpec
345 @Returns: paramspec to which requests on this paramspec should
346   be redirected, or %NULL if none.
347
348
349 <!-- ##### FUNCTION g_param_spec_internal ##### -->
350 <para>
351 Creates a new #GParamSpec instance.
352 </para>
353 <para>
354 A property name consists of segments consisting of ASCII letters and
355 digits, separated by either the '-' or '_' character. The first
356 character of a property name must be a letter. Names which violate these
357 rules lead to undefined behaviour. 
358 </para>
359 <para>
360 When creating and looking up a #GParamSpec, either separator can be used, 
361 but they cannot be mixed. Using '-' is considerably more efficient and in 
362 fact required when using property names as detail strings for signals.
363 </para>
364
365 @param_type: the #GType for the property; must be derived from #G_TYPE_PARAM
366 @name: the canonical name of the property
367 @nick: the nickname of the property
368 @blurb: a short description of the property
369 @flags: a combination of #GParamFlags
370 @Returns: a newly allocated #GParamSpec instance
371
372
373 <!-- ##### STRUCT GParamSpecTypeInfo ##### -->
374 <para>
375 This structure is used to provide the type system with the information
376 required to initialize and destruct (finalize) a parameter's class and
377 instances thereof.
378 The initialized structure is passed to the g_param_type_register_static() 
379 The type system will perform a deep copy of this structure, so it's memory 
380 does not need to be persistent across invocation of 
381 g_param_type_register_static().
382 </para>
383
384 @instance_size: Size of the instance (object) structure.
385 @n_preallocs: Number of pre-allocated (cached) instances to reserve memory for (0 indicates no caching).
386 @instance_init: Location of the instance initialization function (optional).
387 @value_type: The #GType of values conforming to this #GParamSpec
388 @finalize: The instance finalization function (optional).
389 @value_set_default: Resets a @value to the default value for @pspec 
390   (recommended, the default is g_value_reset()), see 
391   g_param_value_set_default().
392 @value_validate: Ensures that the contents of @value comply with the 
393   specifications set out by @pspec (optional), see 
394   g_param_value_set_validate().
395 @values_cmp: Compares @value1 with @value2 according to @pspec 
396   (recommended, the default is memcmp()), see g_param_values_cmp().
397
398 <!-- ##### FUNCTION g_param_type_register_static ##### -->
399 <para>
400 Registers @name as the name of a new static type derived from
401 #G_TYPE_PARAM. The type system uses the information contained in the
402 #GParamSpecTypeInfo structure pointed to by @info to manage the #GParamSpec 
403 type and its instances. 
404 </para>
405
406 @name: 0-terminated string used as the name of the new #GParamSpec type. 
407 @pspec_info: The #GParamSpecTypeInfo for this #GParamSpec type.
408 @Returns: The new type identifier.
409
410
411 <!-- ##### STRUCT GParamSpecPool ##### -->
412 <para>
413 A #GParamSpecPool maintains a collection of #GParamSpec<!-- -->s which can be
414 quickly accessed by owner and name. The implementation of the #GObject property
415 system uses such a pool to store the #GParamSpecs of the properties all object
416 types. 
417 </para>
418
419
420 <!-- ##### FUNCTION g_param_spec_pool_new ##### -->
421 <para>
422 Creates a new #GParamSpecPool.
423 </para>
424 <para>
425 If @type_prefixing is %TRUE, lookups in the newly created pool will
426 allow to specify the owner as a colon-separated prefix of the property name, 
427 like "GtkContainer:border-width". This feature is deprecated, so you should 
428 always set @type_prefixing to %FALSE.
429 </para>
430
431 @type_prefixing: Whether the pool will support type-prefixed property names.
432 @Returns: a newly allocated #GParamSpecPool.
433
434
435 <!-- ##### FUNCTION g_param_spec_pool_insert ##### -->
436 <para>
437 Inserts a #GParamSpec in the pool.
438 </para>
439
440 @pool: a #GParamSpecPool.
441 @pspec: the #GParamSpec to insert
442 @owner_type: a #GType identifying the owner of @pspec
443
444
445 <!-- ##### FUNCTION g_param_spec_pool_remove ##### -->
446 <para>
447 Removes a #GParamSpec from the pool.
448 </para>
449
450 @pool: a #GParamSpecPool
451 @pspec: the #GParamSpec to remove
452
453
454 <!-- ##### FUNCTION g_param_spec_pool_lookup ##### -->
455 <para>
456 Looks up a #GParamSpec in the pool.
457 </para>
458
459 @pool: a #GParamSpecPool
460 @param_name: the name to look for
461 @owner_type: the owner to look for
462 @walk_ancestors: If %TRUE, also try to find a #GParamSpec with @param_name 
463   owned by an ancestor of @owner_type.
464 @Returns: The found #GParamSpec, or %NULL if no matching #GParamSpec was found.
465
466
467 <!-- ##### FUNCTION g_param_spec_pool_list ##### -->
468 <para>
469 Gets an array of all #GParamSpec<!-- -->s owned by @owner_type in the pool. 
470 </para>
471
472 @pool: a #GParamSpecPool
473 @owner_type: the owner to look for
474 @n_pspecs_p: return location for the length of the returned array
475 @Returns: a newly allocated array containing pointers to all 
476   #GParamSpec<!-- -->s owned by @owner_type in the pool
477
478
479
480 <!-- ##### FUNCTION g_param_spec_pool_list_owned ##### -->
481 <para>
482 Gets an #GList of all #GParamSpec<!-- -->s owned by @owner_type in the pool. 
483 </para>
484
485 @pool: a #GParamSpecPool
486 @owner_type: the owner to look for
487 @Returns: a #GList of all #GParamSpec<!-- -->s owned by @owner_type in 
488   the pool#GParamSpec<!-- -->s.
489
490