1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 The base class of the Gtk type hierarchy.
7 <!-- ##### SECTION Long_Description ##### -->
9 <title>Description</title>
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.
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).
29 When you add a widget to its parent container, the parent container
32 g_object_ref (G_OBJECT (child_widget));
33 gtk_object_sink (GTK_OBJECT (child_widget));
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.
39 The purpose of the floating reference is to keep the child widget alive
40 until you add it to a parent container:
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 */
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.
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
70 Some simple rules for handling #GtkObject:
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.)
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.
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>
89 <!-- ##### SECTION See_Also ##### -->
94 <!-- ##### STRUCT GtkObject ##### -->
96 The object itself. You should never use these members directly -
97 use the accessing macros instead.
101 <!-- ##### MACRO GTK_OBJECT_TYPE ##### -->
103 Gets the type of an object.
106 @object: a #GtkObject.
109 <!-- ##### MACRO GTK_OBJECT_TYPE_NAME ##### -->
111 Gets the name of an objects type.
114 @object: a #GtkObject.
117 <!-- ##### ENUM GtkObjectFlags ##### -->
119 Tells about the state of the object.
123 @GTK_FLOATING: whether the object is orphaned. Objects that take
124 strong hold of an object may gtk_object_sink() it, after obtaining
125 there own references, if they believe they are nearly primary
126 ownership of the object.
127 GTK_CONNECTED: refers to whether are signals are connected to this
129 @GTK_RESERVED_1: reserved for future use
130 @GTK_RESERVED_2: reserved for future use
132 <!-- ##### MACRO GTK_OBJECT_FLAGS ##### -->
134 Gets the #GtkObjectFlags for an object without directly
135 accessing its members.
138 @obj: the object whose flags are returned.
141 <!-- ##### MACRO GTK_OBJECT_FLOATING ##### -->
143 Evaluates to %TRUE if the object still has its floating reference count.
144 See the overview documentation for #GtkObject.
147 @obj: the object to examine.
150 <!-- ##### MACRO GTK_OBJECT_CONNECTED ##### -->
152 Tests whether a #GtkObject has had a signal connected to it.
155 @obj: the object to examine.
158 <!-- ##### MACRO GTK_OBJECT_SET_FLAGS ##### -->
160 Turns on certain object flags. (Private)
163 @obj: the object to affect.
164 @flag: the flags to set.
167 <!-- ##### MACRO GTK_OBJECT_UNSET_FLAGS ##### -->
169 Turns off certain object flags. (Private)
172 @obj: the object to affect.
173 @flag: the flags to unset.
176 <!-- ##### ENUM GtkArgFlags ##### -->
178 Possible flags indicating how an argument should be treated.
179 Deprecated in favor of #GParamSpec features.
182 @GTK_ARG_READABLE: the argument is readable. (i.e. can be queried)
183 @GTK_ARG_WRITABLE: the argument is writable. (i.e. settable)
184 @GTK_ARG_CONSTRUCT: the argument needs construction.
185 @GTK_ARG_CONSTRUCT_ONLY: the argument needs construction (and will
186 be set once during object creation), but is otherwise cannot be
187 set. Hence this flag is not allowed with #GTK_ARG_WRITABLE,
188 and is redundant with #GTK_ARG_CONSTRUCT.
189 @GTK_ARG_CHILD_ARG: an argument type that applies to (and may be different for)
190 each child. Used by #GtkContainer.
192 <!-- ##### FUNCTION gtk_object_new ##### -->
194 Constructs an object given its arguments, enumerated in the call to the
195 function. Deprecated in favor of g_object_new().
198 @type: the type identifying this object. Returned by gtk_type_unique()
199 (although for a properly-written object it should be accessible through
200 a #GTK_TYPE_FOO macro.)
201 @first_property_name: name of the first property to set when constructing
203 @Varargs: the first argument's value, followed by any number of
204 name/argument-value pairs, terminated with %NULL.
205 @Returns: the new #GtkObject.
208 <!-- ##### FUNCTION gtk_object_sink ##### -->
210 Removes the floating reference from a #GtkObject, if it exists;
211 otherwise does nothing. See the #GtkObject overview documentation at
215 @object: the object to sink.
218 <!-- ##### FUNCTION gtk_object_ref ##### -->
220 Increases the reference count of the object.
221 Deprecated in favor of g_object_ref().
224 @object: the object to reference.
228 <!-- ##### FUNCTION gtk_object_unref ##### -->
230 Decreases the reference count of an object. When its reference count drops
231 to 0, the object is finalized (i.e. its memory is freed). Deprecated in
232 favor of g_object_unref().
235 @object: the object to dereference.
238 <!-- ##### FUNCTION gtk_object_weakref ##### -->
240 Adds a weak reference callback to an object. Deprecated in favor of
241 g_object_weak_ref(). Weak references are used for notification when an object is
242 finalized. They are called "weak references" because they allow you to safely
243 hold a pointer to an object without calling g_object_ref() (g_object_ref() adds
244 a strong reference, that is, forces the object to stay alive).
247 @object: object to weakly reference.
248 @notify: callback to invoke before the object is freed.
249 @data: extra data to pass to #notify.
252 <!-- ##### FUNCTION gtk_object_weakunref ##### -->
254 Removes a weak reference callback to an object.
257 @object: object stop weakly referencing.
258 @notify: callback to search for.
259 @data: data to search for.
262 <!-- ##### FUNCTION gtk_object_destroy ##### -->
264 Emits the "destroy" signal notifying all reference holders that they should
265 release the #GtkObject. See the overview documentation at the top of the
266 page for more details.
269 The memory for the object itself won't be deleted until
270 its reference count actually drops to 0; gtk_object_destroy() merely asks
271 reference holders to release their references, it does not free the object.
274 @object: the object to destroy.
277 <!-- ##### FUNCTION gtk_object_get ##### -->
279 Gets properties of an object. Deprecated in favor of g_object_get().
282 @object: a #GtkObject.
283 @first_property_name: name of first property to get the value for.
284 @Varargs: %NULL-terminated list of name-return location pairs.
287 <!-- ##### FUNCTION gtk_object_set ##### -->
289 Sets properties on an object. Deprecated in favor of g_object_set().
294 void set_box_properties(GtkBox* box)
296 gtk_object_set(GTK_OBJECT(box), "homogeneous", TRUE,
304 @object: a #GtkObject.
305 @first_property_name: name of the first property to set
306 @Varargs: the value of the first argument, followed optionally
307 by more name/value pairs, followed by %NULL.
310 <!-- ##### FUNCTION gtk_object_set_data ##### -->
312 Deprecated in favor of g_object_set_data().
313 Each object carries around a table of associations from
314 strings to pointers. This function lets you set an association.
317 If the object already had an association with that name,
318 the old association will be destroyed.
321 @object: object containing the associations.
322 @key: name of the key.
323 @data: data to associate with that key.
326 <!-- ##### FUNCTION gtk_object_set_data_full ##### -->
328 Deprecated in favor of g_object_set_data_full().
329 Like gtk_object_set_data() except it adds notification
330 for when the association is destroyed, either by
331 gtk_object_remove_data() or when the object is destroyed.
334 @object: object containing the associations.
335 @key: name of the key.
336 @data: data to associate with that key.
337 @destroy: function to call when the association is destroyed.
340 <!-- ##### FUNCTION gtk_object_remove_data ##### -->
342 Deprecated in favor of setting object data to %NULL using g_object_set_data().
343 Removes a specified datum from the object's data associations (the object_data).
344 Subsequent calls to gtk_object_get_data() will return %NULL.
347 If you specified a destroy handler with gtk_object_set_data_full(),
351 @object: the object maintaining the association.
352 @key: name of the key for that association.
355 <!-- ##### FUNCTION gtk_object_get_data ##### -->
357 Deprecated in favor of g_object_get_data().
358 Get a named field from the object's table of associations (the object_data).
361 @object: the object maintaining the associations.
362 @key: name of the key for that association.
363 @Returns: the data if found, or %NULL if no such data exists.
366 <!-- ##### FUNCTION gtk_object_remove_no_notify ##### -->
368 Deprecated in favor of g_object_steal_data().
369 Remove a specified datum from the object's data associations (the object_data),
370 without invoking the association's destroy handler.
373 Just like gtk_object_remove_data() except that any destroy handler
375 Therefore this only affects data set using gtk_object_set_data_full().
378 @object: the object maintaining the association.
379 @key: name of the key for that association.
382 <!-- ##### FUNCTION gtk_object_set_user_data ##### -->
384 Deprecated in favor of g_object_set_data().
385 For convenience, every object offers a generic user data
386 pointer. This function sets it.
389 This function is equivalent to:
392 gtk_object_set_data(object, "user_data", data);
397 @object: the object whose user data should be set.
398 @data: the new value for the user data.
401 <!-- ##### FUNCTION gtk_object_get_user_data ##### -->
403 Deprecated in favor of g_object_get_data().
404 Get the object's user data pointer.
407 This is intended to be a pointer for your convenience in
408 writing applications.
412 @Returns: the user data field for object.
415 <!-- ##### FUNCTION gtk_object_add_arg_type ##### -->
417 Deprecated in favor of the #GObject property system including #GParamSpec.
418 Add a new type of argument to an object class.
419 Usually this is called when registering a new type of object.
422 @arg_name: fully qualify object name, for example GtkObject::user_data.
423 @arg_type: type of the argument.
424 @arg_flags: bitwise-OR of the #GtkArgFlags enum. (Whether the argument is
425 settable or gettable, whether it is set when the object is constructed.)
426 @arg_id: an internal number, passed in from here to the "set_arg" and
427 "get_arg" handlers of the object.
430 <!-- ##### FUNCTION gtk_object_set_data_by_id ##### -->
432 Deprecated in favor of g_object_set_qdata().
433 Just like gtk_object_set_data() except that it takes
434 a #GQuark instead of a string, so it is slightly faster.
437 Use gtk_object_data_try_key() and gtk_object_data_force_id()
438 to get an id from a string.
441 @object: object containing the associations.
442 @data_id: quark of the key.
443 @data: data to associate with that key.
446 <!-- ##### FUNCTION gtk_object_set_data_by_id_full ##### -->
448 Deprecated in favor of g_object_set_qdata_full().
449 Just like gtk_object_set_data_full() except that it takes
450 a #GQuark instead of a string, so it is slightly faster.
453 Use gtk_object_data_try_key() and gtk_object_data_force_id()
454 to get an id from a string.
457 @object: object containing the associations.
458 @data_id: quark of the key.
459 @data: data to associate with that key.
460 @destroy: function to call when the association is destroyed.
463 <!-- ##### FUNCTION gtk_object_get_data_by_id ##### -->
465 Deprecated in favor of g_object_get_qdata().
466 Just like gtk_object_get_data() except that it takes
467 a #GQuark instead of a string, so it is slightly faster.
470 Use gtk_object_data_try_key() and gtk_object_data_force_id()
471 to get an id from a string.
474 @object: object containing the associations.
475 @data_id: quark of the key.
476 @Returns: the data if found, or %NULL if no such data exists.
479 <!-- ##### FUNCTION gtk_object_remove_data_by_id ##### -->
481 Deprecated in favor of g_object_set_qdata() called with data of %NULL.
482 Just like gtk_object_remove_data() except that it takes
483 a #GQuark instead of a string, so it is slightly faster.
486 Remove a specified datum from the object's data associations.
487 Subsequent calls to gtk_object_get_data() will return %NULL.
490 Use gtk_object_data_try_key() and gtk_object_data_force_id()
491 to get an id from a string.
494 @object: object containing the associations.
495 @data_id: quark of the key.
498 <!-- ##### FUNCTION gtk_object_remove_no_notify_by_id ##### -->
500 Deprecated in favor of g_object_steal_qdata().
501 Just like gtk_object_remove_no_notify() except that it takes
502 a #GQuark instead of a string, so it is slightly faster.
505 Use gtk_object_data_try_key() and gtk_object_data_force_id()
506 to get an id from a string.
509 @object: object containing the associations.
510 @key_id: quark of the key.
511 <!-- # Unused Parameters # -->
515 <!-- ##### MACRO gtk_object_data_try_key ##### -->
517 Useless deprecated macro. Ignore it.
522 <!-- ##### MACRO gtk_object_data_force_id ##### -->
524 Useless deprecated macro. Ignore it.
529 <!-- ##### SIGNAL GtkObject::destroy ##### -->
531 Signals that all holders of a reference to the #GtkObject should release
532 the reference that they hold. May result in finalization of the object
533 if all references are released.
536 @object: the object which received the signal.
538 <!-- ##### ARG GtkObject:user-data ##### -->
540 A pointer for convenience when programming applications.