]> Pileus Git - ~andy/gtk/blob - docs/reference/gtk/tmpl/gtkobject.sgml
09b96e28d3837dca81166f87d93be89e94037f2f
[~andy/gtk] / docs / reference / gtk / tmpl / gtkobject.sgml
1 <!-- ##### SECTION Title ##### -->
2 GtkObject
3
4 <!-- ##### SECTION Short_Description ##### -->
5 The base class of the GTK+ type hierarchy.
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <refsect2>
9 <title>Description</title>
10 <para>
11 #GtkObject is the base class for all widgets, and for a few 
12 non-widget objects such as #GtkAdjustment. #GtkObject predates 
13 #GObject; non-widgets that derive from #GtkObject rather than 
14 #GObject do so for backward compatibility reasons.
15 </para>
16 <para>
17 The most interesting difference between #GtkObject and #GObject is the
18 "floating" reference count. A #GObject is created with a reference count of 1,
19 owned by the creator of the #GObject. (The owner of a reference is the code
20 section that has the right to call g_object_unref() in order to remove that
21 reference.)  A #GtkObject is created with a reference count of 1 also, but it
22 isn't owned by anyone; calling g_object_unref() on the newly-created #GtkObject
23 is incorrect. Instead, the initial reference count of a #GtkObject is "floating". 
24 The floating reference can be removed by anyone at any time, by calling
25 gtk_object_sink(). gtk_object_sink() does nothing if an object is already 
26 sunk (has no floating reference).
27 </para>
28 <para>
29 When you add a widget to its parent container, the parent container
30 will do this:
31 <informalexample><programlisting>
32   g_object_ref (G_OBJECT (child_widget));
33   gtk_object_sink (GTK_OBJECT (child_widget));
34 </programlisting></informalexample>
35 This means that the container now owns a reference to the child widget (since 
36 it called g_object_ref()), and the child widget has no floating reference.
37 </para>
38 <para>
39 The purpose of the floating reference is to keep the child widget alive 
40 until you add it to a parent container:
41 <informalexample><programlisting>
42    button = gtk_button_new (<!>);
43    /* button has one floating reference to keep it alive */
44    gtk_container_add (GTK_CONTAINER (container), button);
45    /* button has one non-floating reference owned by the container */
46 </programlisting></informalexample>
47 </para>
48 <para>
49 #GtkWindow is a special case, because GTK+ itself will ref/sink it on creation. 
50 That is, after calling gtk_window_new(), the #GtkWindow will have one 
51 reference which is owned by GTK+, and no floating references.
52 </para>
53
54 <para>
55 One more factor comes into play: the "destroy" signal, emitted by the
56 gtk_object_destroy() method. The "destroy" signal asks all code owning a
57 reference to an object to release said reference. So, for example, if you call
58 gtk_object_destroy() on a #GtkWindow, GTK+ will release the reference count that
59 it owns; if you call gtk_object_destroy() on a #GtkButton, then the button will
60 be removed from its parent container and the parent container will release its
61 reference to the button.  Because these references are released, calling
62 gtk_object_destroy() should result in freeing all memory associated with an
63 object, unless some buggy code fails to release its references in response to
64 the "destroy" signal. Freeing memory (referred to as
65 <firstterm>finalization</firstterm> only happens if the reference count reaches
66 zero.
67 </para>
68
69 <para>
70 Some simple rules for handling #GtkObject:
71 <itemizedlist>
72 <listitem><para>
73 Never call g_object_unref() unless you have previously called g_object_ref(), 
74 even if you created the #GtkObject. (Note: this is <emphasis>not</emphasis>
75 true for #GObject; for #GObject, the creator of the object owns a reference.)
76 </para></listitem>
77 <listitem><para>
78 Call gtk_object_destroy() to get rid of most objects in most cases. 
79 In particular, widgets are almost always destroyed in this way.
80 </para></listitem>
81 <listitem><para> Because of the floating reference count, you don't need to
82 worry about reference counting for widgets and toplevel windows, unless you
83 explicitly call g_object_ref() yourself.</para></listitem>
84 </itemizedlist>
85 </para>
86
87 </refsect2>
88
89 <!-- ##### SECTION See_Also ##### -->
90 <para>
91 #GObject
92 </para>
93
94 <!-- ##### STRUCT GtkObject ##### -->
95 <para>
96 The object itself.  You should never use these members directly -
97  use the accessing macros instead.
98 </para>
99
100
101 <!-- ##### MACRO GTK_OBJECT_TYPE ##### -->
102 <para>
103 Gets the type of an object.
104 </para>
105
106 @object: a #GtkObject.
107
108
109 <!-- ##### MACRO GTK_OBJECT_TYPE_NAME ##### -->
110 <para>
111 Gets the name of an objects type.
112 </para>
113
114 @object: a #GtkObject.
115
116
117 <!-- ##### ENUM GtkObjectFlags ##### -->
118 <para>
119 Tells about the state of the object.
120 </para>
121
122 @GTK_IN_DESTRUCTION: the object is currently being destroyed. This is used 
123   internally by GTK+ to prevent reinvokations during destruction.
124 @GTK_FLOATING: the object is orphaned.  Objects that take strong hold of an 
125   object may gtk_object_sink() it, after obtaining their own references, if 
126   they believe they are nearly primary ownership of the object.
127 GTK_CONNECTED: signals are connected to this object.
128 @GTK_RESERVED_1: reserved for future use
129 @GTK_RESERVED_2: reserved for future use
130
131 <!-- ##### MACRO GTK_OBJECT_FLAGS ##### -->
132 <para>
133 Gets the #GtkObjectFlags for an object without directly
134 accessing its members.
135 </para>
136
137 @obj: the object whose flags are returned.
138
139
140 <!-- ##### MACRO GTK_OBJECT_FLOATING ##### -->
141 <para>
142 Evaluates to %TRUE if the object still has its floating reference count.
143 See the overview documentation for #GtkObject.
144 </para>
145
146 @obj: the object to examine.
147
148
149 <!-- ##### MACRO GTK_OBJECT_CONNECTED ##### -->
150 <para>
151 Tests whether a #GtkObject has had a signal connected to it.
152 </para>
153
154 @obj: the object to examine.
155
156
157 <!-- ##### ENUM GtkArgFlags ##### -->
158 <para>
159 Possible flags indicating how an argument should be treated.
160 Deprecated in favor of #GParamSpec features.
161 </para>
162
163 @GTK_ARG_READABLE: the argument is readable. (i.e. can be queried)
164 @GTK_ARG_WRITABLE: the argument is writable. (i.e. settable)
165 @GTK_ARG_CONSTRUCT: the argument needs construction.
166 @GTK_ARG_CONSTRUCT_ONLY: the argument needs construction (and will
167 be set once during object creation), but is otherwise cannot be
168 set.  Hence this flag is not allowed with #GTK_ARG_WRITABLE,
169 and is redundant with #GTK_ARG_CONSTRUCT.
170 @GTK_ARG_CHILD_ARG: an argument type that applies to (and may be different for)
171 each child.  Used by #GtkContainer.
172
173 <!-- ##### FUNCTION gtk_object_new ##### -->
174 <para>
175 Constructs an object given its arguments, enumerated in the call to the
176 function. Deprecated in favor of g_object_new().
177 </para>
178
179 @type: the type identifying this object.  Returned by gtk_type_unique()
180 (although for a properly-written object it should be accessible through
181 a #GTK_TYPE_FOO macro.)
182 @first_property_name: name of the first property to set when constructing
183    the object.
184 @Varargs: the first argument's value, followed by any number of
185 name/argument-value pairs, terminated with %NULL.
186 @Returns: the new #GtkObject.
187
188
189 <!-- ##### FUNCTION gtk_object_sink ##### -->
190 <para>
191 Removes the floating reference from a #GtkObject, if it exists; 
192 otherwise does nothing. See the #GtkObject overview documentation at 
193 the top of the page.
194 </para>
195
196 @object: the object to sink.
197
198
199 <!-- ##### FUNCTION gtk_object_ref ##### -->
200 <para>
201 Increases the reference count of the object.
202 Deprecated in favor of g_object_ref().
203 </para>
204
205 @object: the object to reference.
206 @Returns: @object.
207
208
209 <!-- ##### FUNCTION gtk_object_unref ##### -->
210 <para>
211 Decreases the reference count of an object.  When its reference count drops 
212 to 0, the object is finalized (i.e. its memory is freed).  Deprecated in 
213 favor of g_object_unref(). 
214 </para>
215
216 @object: the object to dereference.
217
218
219 <!-- ##### FUNCTION gtk_object_weakref ##### -->
220 <para>
221 Adds a weak reference callback to an object. Deprecated in favor of
222 g_object_weak_ref(). Weak references are used for notification when an object is
223 finalized. They are called "weak references" because they allow you to safely
224 hold a pointer to an object without calling g_object_ref() (g_object_ref() adds
225 a strong reference, that is, forces the object to stay alive).
226 </para>
227
228 @object: object to weakly reference.
229 @notify: callback to invoke before the object is freed.
230 @data: extra data to pass to #notify.
231
232
233 <!-- ##### FUNCTION gtk_object_weakunref ##### -->
234 <para>
235 Removes a weak reference callback to an object.
236 </para>
237
238 @object: object stop weakly referencing.
239 @notify: callback to search for.
240 @data: data to search for.
241
242
243 <!-- ##### FUNCTION gtk_object_destroy ##### -->
244 <para>
245 Emits the "destroy" signal notifying all reference holders that they should
246 release the #GtkObject. See the overview documentation at the top of the 
247 page for more details.
248 </para>
249 <para>
250 The memory for the object itself won't be deleted until
251 its reference count actually drops to 0; gtk_object_destroy() merely asks 
252 reference holders to release their references, it does not free the object.
253 </para>
254
255 @object: the object to destroy.
256
257
258 <!-- ##### FUNCTION gtk_object_get ##### -->
259 <para>
260 Gets properties of an object. Deprecated in favor of g_object_get().  
261 </para>
262
263 @object: a #GtkObject.
264 @first_property_name: name of first property to get the value for.
265 @Varargs: %NULL-terminated list of name-return location pairs.
266
267
268 <!-- ##### FUNCTION gtk_object_set ##### -->
269 <para>
270 Sets properties on an object. Deprecated in favor of g_object_set().
271 </para>
272 <para>
273 <informalexample>
274 <programlisting>
275 void set_box_properties (GtkBox* box)
276 {
277   gtk_object_set (GTK_OBJECT (box), "homogeneous", TRUE,
278                                     "spacing", 8,
279                                     NULL);
280 }
281 </programlisting>
282 </informalexample>
283 </para>
284
285 @object: a #GtkObject.
286 @first_property_name: name of the first property to set
287 @Varargs: the value of the first argument, followed optionally
288 by more name/value pairs, followed by %NULL.
289
290
291 <!-- ##### FUNCTION gtk_object_set_data ##### -->
292 <para>
293 Deprecated in favor of g_object_set_data().
294 Each object carries around a table of associations from
295 strings to pointers.  This function lets you set an association.
296 </para>
297 <para>
298 If the object already had an association with that name,
299 the old association will be destroyed.
300 </para>
301
302 @object: object containing the associations.
303 @key: name of the key.
304 @data: data to associate with that key.
305
306
307 <!-- ##### FUNCTION gtk_object_set_data_full ##### -->
308 <para>
309 Deprecated in favor of g_object_set_data_full().
310 Like gtk_object_set_data() except it adds notification
311 for when the association is destroyed, either by
312 gtk_object_remove_data() or when the object is destroyed.
313 </para>
314
315 @object: object containing the associations.
316 @key: name of the key.
317 @data: data to associate with that key.
318 @destroy: function to call when the association is destroyed.
319
320
321 <!-- ##### FUNCTION gtk_object_remove_data ##### -->
322 <para>
323 Deprecated in favor of setting object data to %NULL using g_object_set_data().
324 Removes a specified datum from the object's data associations (the object_data).
325 Subsequent calls to gtk_object_get_data() will return %NULL.
326 </para>
327 <para>
328 If you specified a destroy handler with gtk_object_set_data_full(),
329 it will be invoked.
330 </para>
331
332 @object: the object maintaining the association.
333 @key: name of the key for that association.
334
335
336 <!-- ##### FUNCTION gtk_object_get_data ##### -->
337 <para>
338 Deprecated in favor of g_object_get_data().
339 Get a named field from the object's table of associations (the object_data).
340 </para>
341
342 @object: the object maintaining the associations.
343 @key: name of the key for that association.
344 @Returns: the data if found, or %NULL if no such data exists.
345
346
347 <!-- ##### FUNCTION gtk_object_remove_no_notify ##### -->
348 <para>
349 Deprecated in favor of g_object_steal_data().
350 Remove a specified datum from the object's data associations (the object_data),
351 without invoking the association's destroy handler.
352 </para>
353 <para>
354 Just like gtk_object_remove_data() except that any destroy handler
355 will be ignored.
356 Therefore this only affects data set using gtk_object_set_data_full().
357 </para>
358
359 @object: the object maintaining the association.
360 @key: name of the key for that association.
361
362
363 <!-- ##### FUNCTION gtk_object_set_user_data ##### -->
364 <para>
365 Deprecated in favor of g_object_set_data().
366 For convenience, every object offers a generic user data
367 pointer.  This function sets it.
368 </para>
369 <para>
370 This function is equivalent to
371 <literal>gtk_object_set_data (object, "user_data", data)</literal>.
372 </para>
373
374 @object: the object whose user data should be set.
375 @data: the new value for the user data.
376
377
378 <!-- ##### FUNCTION gtk_object_get_user_data ##### -->
379 <para>
380 Deprecated in favor of g_object_get_data().
381 Get the object's user data pointer.
382 </para>
383 <para>
384 This is intended to be a pointer for your convenience in
385 writing applications.
386 </para>
387
388 @object: the object.
389 @Returns: the user data field for object.
390
391
392 <!-- ##### FUNCTION gtk_object_add_arg_type ##### -->
393 <para>
394 Deprecated in favor of the #GObject property system including #GParamSpec.
395 Add a new type of argument to an object class.
396 Usually this is called when registering a new type of object.
397 </para>
398
399 @arg_name: fully qualify object name, for example GtkObject::user_data.
400 @arg_type: type of the argument.
401 @arg_flags: bitwise-OR of the #GtkArgFlags enum.  (Whether the argument is
402 settable or gettable, whether it is set when the object is constructed.)
403 @arg_id: an internal number, passed in from here to the "set_arg" and
404 "get_arg" handlers of the object.
405
406
407 <!-- ##### FUNCTION gtk_object_set_data_by_id ##### -->
408 <para>
409 Deprecated in favor of g_object_set_qdata().
410 Just like gtk_object_set_data() except that it takes
411 a #GQuark instead of a string, so it is slightly faster.
412 </para>
413 <para>
414 Use gtk_object_data_try_key() and gtk_object_data_force_id()
415 to get an id from a string.
416 </para>
417
418 @object: object containing the associations.
419 @data_id: quark of the key.
420 @data: data to associate with that key.
421
422
423 <!-- ##### FUNCTION gtk_object_set_data_by_id_full ##### -->
424 <para>
425 Deprecated in favor of g_object_set_qdata_full().
426 Just like gtk_object_set_data_full() except that it takes
427 a #GQuark instead of a string, so it is slightly faster.
428 </para>
429 <para>
430 Use gtk_object_data_try_key() and gtk_object_data_force_id()
431 to get an id from a string.
432 </para>
433
434 @object: object containing the associations.
435 @data_id: quark of the key.
436 @data: data to associate with that key.
437 @destroy: function to call when the association is destroyed.
438
439
440 <!-- ##### FUNCTION gtk_object_get_data_by_id ##### -->
441 <para>
442 Deprecated in favor of g_object_get_qdata().
443 Just like gtk_object_get_data() except that it takes
444 a #GQuark instead of a string, so it is slightly faster.
445 </para>
446 <para>
447 Use gtk_object_data_try_key() and gtk_object_data_force_id()
448 to get an id from a string.
449 </para>
450
451 @object: object containing the associations.
452 @data_id: quark of the key.
453 @Returns: the data if found, or %NULL if no such data exists.
454
455
456 <!-- ##### FUNCTION gtk_object_remove_data_by_id ##### -->
457 <para>
458 Deprecated in favor of g_object_set_qdata() called with data of %NULL.
459 Just like gtk_object_remove_data() except that it takes
460 a #GQuark instead of a string, so it is slightly faster.
461 </para>
462 <para>
463 Remove a specified datum from the object's data associations.
464 Subsequent calls to gtk_object_get_data() will return %NULL.
465 </para>
466 <para>
467 Use gtk_object_data_try_key() and gtk_object_data_force_id()
468 to get an id from a string.
469 </para>
470
471 @object: object containing the associations.
472 @data_id: quark of the key.
473
474
475 <!-- ##### FUNCTION gtk_object_remove_no_notify_by_id ##### -->
476 <para>
477 Deprecated in favor of g_object_steal_qdata().
478 Just like gtk_object_remove_no_notify() except that it takes
479 a #GQuark instead of a string, so it is slightly faster.
480 </para>
481 <para>
482 Use gtk_object_data_try_key() and gtk_object_data_force_id()
483 to get an id from a string.
484 </para>
485
486 @object: object containing the associations.
487 @key_id: quark of the key.
488 <!-- # Unused Parameters # -->
489 @data_id: 
490
491
492 <!-- ##### MACRO gtk_object_data_try_key ##### -->
493 <para>
494 Useless deprecated macro. Ignore it.
495 </para>
496
497
498
499 <!-- ##### MACRO gtk_object_data_force_id ##### -->
500 <para>
501 Useless deprecated macro. Ignore it. 
502 </para>
503
504
505
506 <!-- ##### SIGNAL GtkObject::destroy ##### -->
507 <para>
508 Signals that all holders of a reference to the #GtkObject should release
509 the reference that they hold. May result in finalization of the object
510 if all references are released.
511 </para>
512
513 @object: the object which received the signal.
514
515 <!-- ##### ARG GtkObject:user-data ##### -->
516 <para>
517 A pointer for convenience when programming applications.
518 Deprecated.
519 </para>
520