1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc.
3 * Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
21 #error "Only <glib-object.h> can be included directly."
24 #ifndef __G_OBJECT_H__
25 #define __G_OBJECT_H__
28 #include <gobject/gtype.h>
29 #include <gobject/gvalue.h>
30 #include <gobject/gparam.h>
31 #include <gobject/gclosure.h>
32 #include <gobject/gsignal.h>
36 /* --- type macros --- */
37 #define G_TYPE_IS_OBJECT(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_OBJECT)
38 #define G_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_OBJECT, GObject))
39 #define G_OBJECT_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_OBJECT, GObjectClass))
40 #define G_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_OBJECT))
41 #define G_IS_OBJECT_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_OBJECT))
42 #define G_OBJECT_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_OBJECT, GObjectClass))
43 #define G_OBJECT_TYPE(object) (G_TYPE_FROM_INSTANCE (object))
44 #define G_OBJECT_TYPE_NAME(object) (g_type_name (G_OBJECT_TYPE (object)))
45 #define G_OBJECT_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class))
46 #define G_OBJECT_CLASS_NAME(class) (g_type_name (G_OBJECT_CLASS_TYPE (class)))
47 #define G_VALUE_HOLDS_OBJECT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_OBJECT))
49 /* --- type macros --- */
50 #define G_TYPE_INITIALLY_UNOWNED (g_initially_unowned_get_type())
51 #define G_INITIALLY_UNOWNED(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnowned))
52 #define G_INITIALLY_UNOWNED_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnownedClass))
53 #define G_IS_INITIALLY_UNOWNED(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_INITIALLY_UNOWNED))
54 #define G_IS_INITIALLY_UNOWNED_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_INITIALLY_UNOWNED))
55 #define G_INITIALLY_UNOWNED_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnownedClass))
56 /* GInitiallyUnowned ia a GObject with initially floating reference count */
59 /* --- typedefs & structures --- */
60 typedef struct _GObject GObject;
61 typedef struct _GObjectClass GObjectClass;
62 typedef struct _GObject GInitiallyUnowned;
63 typedef struct _GObjectClass GInitiallyUnownedClass;
64 typedef struct _GObjectConstructParam GObjectConstructParam;
65 typedef void (*GObjectGetPropertyFunc) (GObject *object,
69 typedef void (*GObjectSetPropertyFunc) (GObject *object,
73 typedef void (*GObjectFinalizeFunc) (GObject *object);
74 typedef void (*GWeakNotify) (gpointer data,
75 GObject *where_the_object_was);
78 GTypeInstance g_type_instance;
81 volatile guint ref_count;
86 GTypeClass g_type_class;
89 GSList *construct_properties;
92 /* overridable methods */
93 GObject* (*constructor) (GType type,
94 guint n_construct_properties,
95 GObjectConstructParam *construct_properties);
96 void (*set_property) (GObject *object,
100 void (*get_property) (GObject *object,
104 void (*dispose) (GObject *object);
105 void (*finalize) (GObject *object);
107 /* seldomly overidden */
108 void (*dispatch_properties_changed) (GObject *object,
110 GParamSpec **pspecs);
113 void (*notify) (GObject *object,
119 struct _GObjectConstructParam
126 /* --- prototypes --- */
127 IMPORT_C GType g_initially_unowned_get_type (void);
128 IMPORT_C void g_object_class_install_property (GObjectClass *oclass,
131 IMPORT_C GParamSpec* g_object_class_find_property (GObjectClass *oclass,
132 const gchar *property_name);
133 IMPORT_C GParamSpec**g_object_class_list_properties (GObjectClass *oclass,
134 guint *n_properties);
135 IMPORT_C void g_object_class_override_property (GObjectClass *oclass,
139 IMPORT_C void g_object_interface_install_property (gpointer g_iface,
141 IMPORT_C GParamSpec* g_object_interface_find_property (gpointer g_iface,
142 const gchar *property_name);
143 IMPORT_C GParamSpec**g_object_interface_list_properties (gpointer g_iface,
144 guint *n_properties_p);
146 IMPORT_C gpointer g_object_new (GType object_type,
147 const gchar *first_property_name,
149 IMPORT_C gpointer g_object_newv (GType object_type,
151 GParameter *parameters);
152 IMPORT_C GObject* g_object_new_valist (GType object_type,
153 const gchar *first_property_name,
155 IMPORT_C void g_object_set (gpointer object,
156 const gchar *first_property_name,
157 ...) G_GNUC_NULL_TERMINATED;
158 IMPORT_C void g_object_get (gpointer object,
159 const gchar *first_property_name,
160 ...) G_GNUC_NULL_TERMINATED;
161 IMPORT_C gpointer g_object_connect (gpointer object,
162 const gchar *signal_spec,
163 ...) G_GNUC_NULL_TERMINATED;
164 IMPORT_C void g_object_disconnect (gpointer object,
165 const gchar *signal_spec,
166 ...) G_GNUC_NULL_TERMINATED;
167 IMPORT_C void g_object_set_valist (GObject *object,
168 const gchar *first_property_name,
170 IMPORT_C void g_object_get_valist (GObject *object,
171 const gchar *first_property_name,
173 IMPORT_C void g_object_set_property (GObject *object,
174 const gchar *property_name,
175 const GValue *value);
176 IMPORT_C void g_object_get_property (GObject *object,
177 const gchar *property_name,
179 IMPORT_C void g_object_freeze_notify (GObject *object);
180 IMPORT_C void g_object_notify (GObject *object,
181 const gchar *property_name);
182 IMPORT_C void g_object_thaw_notify (GObject *object);
183 IMPORT_C gboolean g_object_is_floating (gpointer object);
184 IMPORT_C gpointer g_object_ref_sink (gpointer object);
185 IMPORT_C gpointer g_object_ref (gpointer object);
186 IMPORT_C void g_object_unref (gpointer object);
187 IMPORT_C void g_object_weak_ref (GObject *object,
190 IMPORT_C void g_object_weak_unref (GObject *object,
193 IMPORT_C void g_object_add_weak_pointer (GObject *object,
194 gpointer *weak_pointer_location);
195 IMPORT_C void g_object_remove_weak_pointer (GObject *object,
196 gpointer *weak_pointer_location);
198 typedef void (*GToggleNotify) (gpointer data,
200 gboolean is_last_ref);
202 IMPORT_C void g_object_add_toggle_ref (GObject *object,
203 GToggleNotify notify,
205 IMPORT_C void g_object_remove_toggle_ref (GObject *object,
206 GToggleNotify notify,
209 IMPORT_C gpointer g_object_get_qdata (GObject *object,
211 IMPORT_C void g_object_set_qdata (GObject *object,
214 IMPORT_C void g_object_set_qdata_full (GObject *object,
217 GDestroyNotify destroy);
218 IMPORT_C gpointer g_object_steal_qdata (GObject *object,
220 IMPORT_C gpointer g_object_get_data (GObject *object,
222 IMPORT_C void g_object_set_data (GObject *object,
225 IMPORT_C void g_object_set_data_full (GObject *object,
228 GDestroyNotify destroy);
229 IMPORT_C gpointer g_object_steal_data (GObject *object,
231 IMPORT_C void g_object_watch_closure (GObject *object,
233 IMPORT_C GClosure* g_cclosure_new_object (GCallback callback_func,
235 IMPORT_C GClosure* g_cclosure_new_object_swap (GCallback callback_func,
237 IMPORT_C GClosure* g_closure_new_object (guint sizeof_closure,
239 IMPORT_C void g_value_set_object (GValue *value,
241 IMPORT_C gpointer g_value_get_object (const GValue *value);
242 IMPORT_C GObject* g_value_dup_object (const GValue *value);
243 IMPORT_C gulong g_signal_connect_object (gpointer instance,
244 const gchar *detailed_signal,
247 GConnectFlags connect_flags);
251 IMPORT_C void g_object_force_floating (GObject *object);
252 IMPORT_C void g_object_run_dispose (GObject *object);
255 IMPORT_C void g_value_take_object (GValue *value,
257 #ifndef G_DISABLE_DEPRECATED
258 IMPORT_C void g_value_set_object_take_ownership (GValue *value,
262 #if !defined(G_DISABLE_DEPRECATED) || defined(GTK_COMPILATION)
263 gsize g_object_compat_control (gsize what,
267 /* --- implementation macros --- */
268 #define G_OBJECT_WARN_INVALID_PSPEC(object, pname, property_id, pspec) \
270 GObject *_object = (GObject*) (object); \
271 GParamSpec *_pspec = (GParamSpec*) (pspec); \
272 guint _property_id = (property_id); \
273 g_warning ("%s: invalid %s id %u for \"%s\" of type `%s' in `%s'", \
278 g_type_name (G_PARAM_SPEC_TYPE (_pspec)), \
279 G_OBJECT_TYPE_NAME (_object)); \
281 #define G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec) \
282 G_OBJECT_WARN_INVALID_PSPEC ((object), "property", (property_id), (pspec))
286 #endif /* __G_OBJECT_H__ */