1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
7 <!-- ##### SECTION Long_Description ##### -->
12 <!-- ##### SECTION See_Also ##### -->
17 <!-- ##### STRUCT GObject ##### -->
19 All the fields in the <structname>GObject</structname> structure are private
20 to the #GObject implementation and should never be accessed directly.
24 <!-- ##### SIGNAL GObject::notify ##### -->
26 The notify signal is emitted on an object when one of its properties
27 has been changed. Note that getting this signal doesn't guarantee that the
28 value of the property has actually changed, it may also be emitted when
29 the setter for the property is called to reinstate the previous value.
32 @gobject: the object which received the signal.
33 @pspec: the #GParamSpec of the property which changed
35 <!-- ##### STRUCT GObjectClass ##### -->
37 The class structure for the <structname>GObject</structname> type.
40 @g_type_class: the parent class
41 @constructor: the @constructor function is called by g_object_new () to
42 complete the object initialization after all the construction properties are
43 set. The first thing a @constructor implementation must do is chain up to the
44 @constructor of the parent class. Overriding @constructor should be rarely
46 @set_property: the generic setter for all properties of this type. Should be
47 overridden for every type with properties. Implementations of @set_property
48 don't need to emit property change notification explicitly, this is handled
50 @get_property: the generic getter for all properties of this type. Should be
51 overridden for every type with properties.
52 @dispose: the @dispose function is supposed to drop all references to other
53 objects, but keep the instance otherwise intact, so that client method
54 invocations still work. It may be run multiple times (due to reference
55 loops). Before returning, @dispose should chain up to the @dispose method
57 @finalize: instance finalization function, should finish the finalization of
58 the instance begun in @dispose and chain up to the @finalize method of the
60 @dispatch_properties_changed: emits property change notification for a bunch
61 of properties. Overriding @dispatch_properties_changed should be rarely
63 @notify: the class closure for the notify signal
65 <!-- ##### STRUCT GObjectConstructParam ##### -->
67 The <structname>GObjectConstructParam</structname> struct is an auxiliary
68 structure used to hand #GParamSpec/#GValue pairs to the @constructor of
72 @pspec: the #GParamSpec of the construct parameter
73 @value: the value to set the parameter to
75 <!-- ##### USER_FUNCTION GObjectGetPropertyFunc ##### -->
77 The type of the @get_property function of #GObjectClass.
81 @property_id: the numeric id under which the property was registered with
82 g_object_class_install_property().
83 @value: a #GValue to return the property value in
84 @pspec: the #GParamSpec describing the property
87 <!-- ##### USER_FUNCTION GObjectSetPropertyFunc ##### -->
89 The type of the @set_property function of #GObjectClass.
93 @property_id: the numeric id under which the property was registered with
94 g_object_class_install_property().
95 @value: the new value for the property
96 @pspec: the #GParamSpec describing the property
99 <!-- ##### USER_FUNCTION GObjectFinalizeFunc ##### -->
101 The type of the @finalize function of #GObjectClass.
104 @object: the #GObject being finalized
107 <!-- ##### MACRO G_TYPE_IS_OBJECT ##### -->
109 Returns a boolean value of %FALSE or %TRUE indicating whether
110 the passed in type id is a %G_TYPE_OBJECT or derived from it.
113 @type: Type id to check for is a %G_TYPE_OBJECT relationship.
114 @Returns: %FALSE or %TRUE, indicating whether @type is a %G_TYPE_OBJECT.
117 <!-- ##### MACRO G_OBJECT ##### -->
119 Casts a #GObject or derived pointer into a (GObject*) pointer.
120 Depending on the current debugging level, this function may invoke
121 certain runtime checks to identify invalid casts.
124 @object: Object which is subject to casting.
127 <!-- ##### MACRO G_IS_OBJECT ##### -->
129 Checks whether a valid #GTypeInstance pointer is of type %G_TYPE_OBJECT.
132 @object: Instance to check for being a %G_TYPE_OBJECT.
135 <!-- ##### MACRO G_OBJECT_CLASS ##### -->
137 Casts a derived #GObjectClass structure into a #GObjectClass structure.
140 @class: a valid #GObjectClass
143 <!-- ##### MACRO G_IS_OBJECT_CLASS ##### -->
145 Checks whether @class "is a" valid #GObjectClass structure of type
146 %G_TYPE_OBJECT or derived.
149 @class: a #GObjectClass
152 <!-- ##### MACRO G_OBJECT_GET_CLASS ##### -->
154 Returns the class structure associated to a #GObject instance.
157 @object: a #GObject instance.
160 <!-- ##### MACRO G_OBJECT_TYPE ##### -->
162 Return the type id of an object.
165 @object: Object to return the type id for.
166 @Returns: Type id of @object.
169 <!-- ##### MACRO G_OBJECT_TYPE_NAME ##### -->
171 Returns the name of an object's type.
174 @object: Object to return the type name for.
175 @Returns: Type name of @object. The string is owned by the type system and
179 <!-- ##### MACRO G_OBJECT_CLASS_TYPE ##### -->
181 Return the type id of a class structure.
184 @class: a valid #GObjectClass
185 @Returns: Type id of @class.
188 <!-- ##### MACRO G_OBJECT_CLASS_NAME ##### -->
190 Return the name of a class structure's type.
193 @class: a valid #GObjectClass
194 @Returns: Type name of @class. The string is owned by the type system and
198 <!-- ##### FUNCTION g_object_class_install_property ##### -->
200 Installs a new property. This is usually done in the class initializer.
203 @oclass: a #GObjectClass
204 @property_id: the id for the new property
205 @pspec: the #GParamSpec for the new property
208 <!-- ##### FUNCTION g_object_class_find_property ##### -->
210 Looks up the #GParamSpec for a property of a class.
213 @oclass: a #GObjectClass
214 @property_name: the name of the property to look up
215 @Returns: the #GParamSpec for the property, or %NULL if the class doesn't have
216 a property of that name
219 <!-- ##### FUNCTION g_object_class_list_properties ##### -->
221 Returns an array of #GParamSpec* for all properties of a class.
224 @oclass: a #GObjectClass
225 @n_properties: return location for the length of the returned array
226 @Returns: an array of #GParamSpec* which should be freed after use
229 <!-- ##### FUNCTION g_object_class_override_property ##### -->
231 Registers @property_id as referring to a property with the
232 name @name in a parent class or in an interface implemented
233 by @oclass. This allows this class to <firstterm>override</firstterm>
234 a property implementation in a parent class or to provide
235 the implementation of a property from an interface.
239 Internally, overriding is implemented by creating a property of type
240 #GParamSpecOverride; generally operations that query the properties of
241 the object class, such as g_object_class_find_property() or
242 g_object_class_list_properties() will return the overridden
243 property. However, in one case, the @construct_properties argument of
244 the @constructor virtual function, the #GParamSpecOverride is passed
245 instead, so that the @param_id field of the #GParamSpec will be
246 correct. For virtually all uses, this makes no difference. If you
247 need to get the overridden property, you can call
248 g_param_spec_get_redirect_target().
252 @oclass: a #GObjectClass
253 @property_id: the new property ID
254 @name: the name of a property registered in a parent class or
255 in an interface of this class.
258 <!-- ##### FUNCTION g_object_interface_install_property ##### -->
260 Add a property to an interface; this is only useful for interfaces
261 that are added to GObject-derived types. Adding a property to an
262 interface forces all objects classes with that interface to have a
263 compatible property. The compatible property could be a newly
264 created #GParamSpec, but normally
265 g_object_class_override_property() will be used so that the object
266 class only needs to provide an implementation and inherits the
267 property description, default value, bounds, and so forth from the
271 This function is meant to be called from the interface's default
272 vtable initialization function (the @class_init member of
273 #GTypeInfo.) It must not be called after after @class_init has
274 been called for any object types implementing this interface.
277 @g_iface: any interface vtable for the interface, or the default
278 vtable for the interface.
279 @pspec: the #GParamSpec for the new property
283 <!-- ##### FUNCTION g_object_interface_find_property ##### -->
285 Find the #GParamSpec with the given name for an
286 interface. Generally, the interface vtable passed in as @g_iface
287 will be the default vtable from g_type_default_interface_ref(), or,
288 if you know the interface has already been loaded,
289 g_type_default_interface_peek().
292 @g_iface: any interface vtable for the interface, or the default
293 vtable for the interface
294 @property_name: name of a property to lookup.
295 @Returns: the #GParamSpec for the property of the
296 interface with the name @property_name, or %NULL
297 if no such property exists.
301 <!-- ##### FUNCTION g_object_interface_list_properties ##### -->
303 Lists the properties of an interface.Generally, the interface
304 vtable passed in as @g_iface will be the default vtable from
305 g_type_default_interface_ref(), or, if you know the interface has
306 already been loaded, g_type_default_interface_peek().
309 @g_iface: any interface vtable for the interface, or the default
310 vtable for the interface
311 @n_properties_p: location to store number of properties returned.
312 @Returns: a pointer to an array of pointers to #GParamSpec structures.
313 The paramspecs are owned by GLib, but the array should
314 be freed with g_free() when you are done with it.
318 <!-- ##### FUNCTION g_object_new ##### -->
320 Creates a new instance of a #GObject subtype and sets its properties.
323 Construction parameters (see #G_PARAM_CONSTRUCT, #G_PARAM_CONSTRUCT_ONLY)
324 which are not explicitly specified are set to their default values.
327 @object_type: the type id of the #GObject subtype to instantiate
328 @first_property_name: the name of the first property
329 @Varargs: the value of the first property, followed optionally by more
330 name/value pairs, followed by %NULL
331 @Returns: a new instance of @object_type
334 <!-- ##### FUNCTION g_object_newv ##### -->
336 Creates a new instance of a #GObject subtype and sets its properties.
339 Construction parameters (see #G_PARAM_CONSTRUCT, #G_PARAM_CONSTRUCT_ONLY)
340 which are not explicitly specified are set to their default values.
343 @object_type: the type id of the #GObject subtype to instantiate
344 @n_parameters: the length of the @parameters array
345 @parameters: an array of #GParameter
346 @Returns: a new instance of @object_type
349 <!-- ##### STRUCT GParameter ##### -->
351 The <structname>GParameter</structname> struct is an auxiliary structure used
352 to hand parameter name/value pairs to g_object_newv().
355 @name: the parameter name
356 @value: the parameter value
358 <!-- ##### FUNCTION g_object_ref ##### -->
360 Increases the reference count of @object.
367 <!-- ##### FUNCTION g_object_unref ##### -->
369 Decreases the reference count if @object.
370 When its reference count drops to 0, the object is finalized (i.e. its memory is freed).
376 <!-- ##### USER_FUNCTION GWeakNotify ##### -->
378 A #GWeakNotify function can be added to an object as a callback that gets
379 triggered when the object is finalized. Since the object is already being
380 finalized when the #GWeakNotify is called, there's not much you could do
381 with the object, apart from e.g. using its adress as hash-index or the like.
384 @data: data that was provided when the weak reference was established
385 @where_the_object_was: the object being finalized
388 <!-- ##### FUNCTION g_object_weak_ref ##### -->
390 Adds a weak reference callback to an object. Weak references are used for
391 notification when an object is finalized. They are called "weak references"
392 because they allow you to safely hold a pointer to an object without calling
393 g_object_ref() (g_object_ref() adds a strong reference, that is, forces the
394 object to stay alive).
397 @object: #GObject to reference weakly
398 @notify: callback to invoke before the object is freed
399 @data: extra data to pass to notify
402 <!-- ##### FUNCTION g_object_weak_unref ##### -->
404 Removes a weak reference callback to an object.
407 @object: #GObject to remove a weak reference from
408 @notify: callback to search for
409 @data: data to search for
412 <!-- ##### FUNCTION g_object_add_weak_pointer ##### -->
414 Adds a weak reference from weak_pointer to @object to indicate that
415 the pointer located at @weak_pointer_location is only valid during the
416 lifetime of @object. When the @object is finalized, @weak_pointer will
420 @object: The object that should be weak referenced.
421 @weak_pointer_location: The memory address of a pointer.
424 <!-- ##### FUNCTION g_object_remove_weak_pointer ##### -->
426 Removes a weak reference from @object that was previously added
427 using g_object_add_weak_pointer(). The @weak_pointer_location has
428 to match the one used with g_object_add_weak_pointer().
431 @object: The object that is weak referenced.
432 @weak_pointer_location: The memory address of a pointer.
435 <!-- ##### FUNCTION g_object_connect ##### -->
437 A convenience function to connect multiple signals at once.
440 The signal specs expected by this function have the form
441 "modifier::signal_name", where modifier can be one of the following:
446 equivalent to <literal>g_signal_connect_data (...)</literal>
450 <term>object_signal</term>
451 <term>object-signal</term>
453 equivalent to <literal>g_signal_connect_object (...)</literal>
457 <term>swapped_signal</term>
458 <term>swapped-signal</term>
460 equivalent to <literal>g_signal_connect_data (..., G_CONNECT_SWAPPED)</literal>
464 <term>swapped_object_signal</term>
465 <term>swapped-object-signal</term>
467 equivalent to <literal>g_signal_connect_object (..., G_CONNECT_SWAPPED)</literal>
471 <term>signal_after</term>
472 <term>signal-after</term>
474 equivalent to <literal>g_signal_connect_data (..., G_CONNECT_AFTER)</literal>
478 <term>object_signal_after</term>
479 <term>object-signal-after</term>
481 equivalent to <literal>g_signal_connect_object (..., G_CONNECT_AFTER)</literal>
485 <term>swapped_signal_after</term>
486 <term>swapped-signal-after</term>
488 equivalent to <literal>g_signal_connect_data (..., G_CONNECT_SWAPPED | G_CONNECT_AFTER)</literal>
492 <term>swapped_object_signal_after</term>
493 <term>swapped-object-signal-after</term>
495 equivalent to <literal>g_signal_connect_object (..., G_CONNECT_SWAPPED | G_CONNECT_AFTER)</literal>
502 menu->toplevel = g_object_connect (g_object_new (GTK_TYPE_WINDOW,
503 "type", GTK_WINDOW_POPUP,
506 "signal::event", gtk_menu_window_event, menu,
507 "signal::size_request", gtk_menu_window_size_request, menu,
508 "signal::destroy", gtk_widget_destroyed, &menu->toplevel,
514 @signal_spec: the spec for the first signal
515 @Varargs: #GCallback for the first signal, followed by data for the first signal,
516 followed optionally by more signal spec/callback/data triples,
521 <!-- ##### FUNCTION g_object_disconnect ##### -->
523 A convenience function to disconnect multiple signals at once.
526 The signal specs expected by this function have the form "any_signal", which
527 means to disconnect any signal with matching callback and data, or
528 "any_signal::signal_name", which only disconnects the signal named "signal_name".
532 @signal_spec: the spec for the first signal
533 @Varargs: #GCallback for the first signal, followed by data for the first signal,
534 followed optionally by more signal spec/callback/data triples,
538 <!-- ##### FUNCTION g_object_set ##### -->
540 Sets properties on an object.
544 @first_property_name: name of the first property to set
545 @Varargs: value for the first property, followed optionally by more
546 name/value pairs, followed by %NULL
549 <!-- ##### FUNCTION g_object_get ##### -->
551 Gets properties of an object.
554 In general, a copy is made of the property contents and the caller is
555 responsible for freeing the memory in the appropriate manner for the type,
556 for instance by calling g_free() or g_object_unref().
559 <title>Using g_object_get(<!-- -->)</title>
561 An example of using g_object_get() to get the contents
562 of three properties - one of type #G_TYPE_INT,
563 one of type #G_TYPE_STRING, and one of type #G_TYPE_OBJECT:
570 g_object_get (my_object,
571 "intproperty", &intval,
572 "strproperty", &strval,
573 "objproperty", &objval,
576 /* Do something with intval, strval, objval */
579 g_object_unref (objval);
584 @first_property_name: name of the first property to get
585 @Varargs: return location for the first property, followed optionally by more
586 name/return location pairs, followed by %NULL
589 <!-- ##### FUNCTION g_object_notify ##### -->
591 Emits a "notify" signal for the property @property_name on @object.
595 @property_name: the name of a property installed on the class of @object.
598 <!-- ##### FUNCTION g_object_freeze_notify ##### -->
600 Stops emission of "notify" signals on @object. The signals are
601 queued until g_object_thaw_notify() is called on @object.
604 This is necessary for accessors that modify multiple properties to prevent
605 premature notification while the object is still being modified.
611 <!-- ##### FUNCTION g_object_thaw_notify ##### -->
613 Reverts the effect of a previous call to g_object_freeze_notify().
614 This causes all queued "notify" signals on @object to be emitted.
620 <!-- ##### FUNCTION g_object_get_data ##### -->
622 Gets a named field from the objects table of associations (see g_object_set_data()).
625 @object: #GObject containing the associations
626 @key: name of the key for that association
627 @Returns: the data if found, or %NULL if no such data exists.
630 <!-- ##### FUNCTION g_object_set_data ##### -->
632 Each object carries around a table of associations from
633 strings to pointers. This function lets you set an association.
636 If the object already had an association with that name,
637 the old association will be destroyed.
640 @object: #GObject containing the associations.
641 @key: name of the key
642 @data: data to associate with that key
645 <!-- ##### FUNCTION g_object_set_data_full ##### -->
647 Like g_object_set_data() except it adds notification
648 for when the association is destroyed, either by setting it
649 to a different value or when the object is destroyed.
652 @object: #GObject containing the associations
653 @key: name of the key
654 @data: data to associate with that key
655 @destroy: function to call when the association is destroyed
658 <!-- ##### FUNCTION g_object_steal_data ##### -->
660 Remove a specified datum from the object's data associations,
661 without invoking the association's destroy handler.
664 @object: #GObject containing the associations
665 @key: name of the key
666 @Returns: the data if found, or %NULL if no such data exists.
669 <!-- ##### FUNCTION g_object_get_qdata ##### -->
671 This function gets back user data pointers stored via
672 g_object_set_qdata().
675 @object: The GObject to get a stored user data pointer from
676 @quark: A #GQuark, naming the user data pointer
677 @Returns: The user data pointer set, or %NULL
680 <!-- ##### FUNCTION g_object_set_qdata ##### -->
682 This sets an opaque, named pointer on an object.
683 The name is specified through a #GQuark (retrived e.g. via
684 g_quark_from_static_string()), and the pointer
685 can be gotten back from the @object with g_object_get_qdata()
686 until the @object is finalized.
687 Setting a previously set user data pointer, overrides (frees)
688 the old pointer set, using #NULL as pointer essentially
689 removes the data stored.
692 @object: The GObject to set store a user data pointer
693 @quark: A #GQuark, naming the user data pointer
694 @data: An opaque user data pointer
697 <!-- ##### FUNCTION g_object_set_qdata_full ##### -->
699 This function works like g_object_set_qdata(), but in addition,
700 a void (*destroy) (gpointer) function may be specified which is
701 called with @data as argument when the @object is finalized, or
702 the data is being overwritten by a call to g_object_set_qdata()
703 with the same @quark.
706 @object: The GObject to set store a user data pointer
707 @quark: A #GQuark, naming the user data pointer
708 @data: An opaque user data pointer
709 @destroy: Function to invoke with @data as argument, when @data needs to be freed
712 <!-- ##### FUNCTION g_object_steal_qdata ##### -->
714 This function gets back user data pointers stored via
715 g_object_set_qdata() and removes the @data from object
716 without invoking it's destroy() function (if any was
718 Usually, calling this function is only required to update
719 user data pointers with a destroy notifier, for example:
722 object_add_to_user_list (GObject *object,
723 const gchar *new_string)
725 /* the quark, naming the object data */
726 GQuark quark_string_list = g_quark_from_static_string ("my-string-list");
727 /* retrive the old string list */
728 GList *list = g_object_steal_qdata (object, quark_string_list);
730 /* prepend new string */
731 list = g_list_prepend (list, g_strdup (new_string));
732 /* this changed 'list', so we need to set it again */
733 g_object_set_qdata_full (object, quark_string_list, list, free_string_list);
736 free_string_list (gpointer data)
738 GList *node, *list = data;
740 for (node = list; node; node = node->next)
745 Using g_object_get_qdata() in the above example, instead of g_object_steal_qdata()
746 would have left the destroy function set, and thus the partial string list would
747 have been freed upon g_object_set_qdata_full().
750 @object: The GObject to get a stored user data pointer from
751 @quark: A #GQuark, naming the user data pointer
752 @Returns: The user data pointer set, or %NULL
755 <!-- ##### FUNCTION g_object_set_property ##### -->
757 Sets a property on an object.
761 @property_name: the name of the property to set
765 <!-- ##### FUNCTION g_object_get_property ##### -->
767 Gets a property of an object.
770 In general, a copy is made of the property contents and the caller is
771 responsible for freeing the memory in the appropriate manner for the type,
772 for instance by calling g_free() or g_object_unref().
779 @property_name: the name of the property to get
780 @value: return location for the property value
783 <!-- ##### FUNCTION g_object_new_valist ##### -->
785 Creates a new instance of a #GObject subtype and sets its properties.
788 Construction parameters (see #G_PARAM_CONSTRUCT, #G_PARAM_CONSTRUCT_ONLY)
789 which are not explicitly specified are set to their default values.
792 @object_type: the type id of the #GObject subtype to instantiate
793 @first_property_name: the name of the first property
794 @var_args: the value of the first property, followed optionally by more
795 name/value pairs, followed by %NULL
796 @Returns: a new instance of @object_type
799 <!-- ##### FUNCTION g_object_set_valist ##### -->
801 Sets properties on an object.
805 @first_property_name: name of the first property to set
806 @var_args: value for the first property, followed optionally by more
807 name/value pairs, followed by %NULL
810 <!-- ##### FUNCTION g_object_get_valist ##### -->
812 Gets properties of an object.
815 In general, a copy is made of the property contents and the caller is
816 responsible for freeing the memory in the appropriate manner for the type,
817 for instance by calling g_free() or g_object_unref().
824 @first_property_name: name of the first property to get
825 @var_args: return location for the first property, followed optionally by more
826 name/return location pairs, followed by %NULL
829 <!-- ##### FUNCTION g_object_watch_closure ##### -->
831 This function essentially limits the life time of the @closure
832 to the life time of the object. That is, when the object is finalized,
833 the @closure is invalidated by calling g_closure_invalidate() on it,
834 in order to prevent invocations of the closure with a finalized
835 (nonexisting) object. Also, g_object_ref() and g_object_unref() are added
836 as marshal guards to the @closure, to ensure that an extra reference
837 count is held on @object during invocation of the @closure.
838 Usually, this function will be called on closures that use this @object
842 @object: GObject restricting lifetime of @closure
843 @closure: GClosure to watch
846 <!-- ##### FUNCTION g_object_run_dispose ##### -->
848 Releases all references to other objects. This can be used to break
852 This functions should only be called from object system implementations.
858 <!-- ##### MACRO G_OBJECT_WARN_INVALID_PROPERTY_ID ##### -->
860 This macros should be used to emit a standard warning about unexpected
861 properties in set_property() and get_property() implementations.
864 @object: the #GObject on which set_property() or get_property() was called
865 @property_id: the numeric id of the property
866 @pspec: the #GParamSpec of the property