Updates
[platform/upstream/glib.git] / gobject / gobject.h
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2  * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General
15  * Public License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
20 #error "Only <glib-object.h> can be included directly."
21 #endif
22
23 #ifndef __G_OBJECT_H__
24 #define __G_OBJECT_H__
25
26 #include        <gobject/gtype.h>
27 #include        <gobject/gvalue.h>
28 #include        <gobject/gparam.h>
29 #include        <gobject/gclosure.h>
30 #include        <gobject/gsignal.h>
31
32 G_BEGIN_DECLS
33
34 /* --- type macros --- */
35 #define G_TYPE_IS_OBJECT(type)      (G_TYPE_FUNDAMENTAL (type) == G_TYPE_OBJECT)
36 #define G_OBJECT(object)            (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_OBJECT, GObject))
37 #define G_OBJECT_CLASS(class)       (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_OBJECT, GObjectClass))
38 #define G_IS_OBJECT(object)         (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_OBJECT))
39 #define G_IS_OBJECT_CLASS(class)    (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_OBJECT))
40 #define G_OBJECT_GET_CLASS(object)  (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_OBJECT, GObjectClass))
41 #define G_OBJECT_TYPE(object)       (G_TYPE_FROM_INSTANCE (object))
42 #define G_OBJECT_TYPE_NAME(object)  (g_type_name (G_OBJECT_TYPE (object)))
43 #define G_OBJECT_CLASS_TYPE(class)  (G_TYPE_FROM_CLASS (class))
44 #define G_OBJECT_CLASS_NAME(class)  (g_type_name (G_OBJECT_CLASS_TYPE (class)))
45 #define G_VALUE_HOLDS_OBJECT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_OBJECT))
46
47 /* --- type macros --- */
48 #define G_TYPE_INITIALLY_UNOWNED              (g_initially_unowned_get_type())
49 #define G_INITIALLY_UNOWNED(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnowned))
50 #define G_INITIALLY_UNOWNED_CLASS(class)      (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnownedClass))
51 #define G_IS_INITIALLY_UNOWNED(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_INITIALLY_UNOWNED))
52 #define G_IS_INITIALLY_UNOWNED_CLASS(class)   (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_INITIALLY_UNOWNED))
53 #define G_INITIALLY_UNOWNED_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnownedClass))
54 /* GInitiallyUnowned ia a GObject with initially floating reference count */
55
56
57 /* --- typedefs & structures --- */
58 typedef struct _GObject                  GObject;
59 typedef struct _GObjectClass             GObjectClass;
60 typedef struct _GObject                  GInitiallyUnowned;
61 typedef struct _GObjectClass             GInitiallyUnownedClass;
62 typedef struct _GObjectConstructParam    GObjectConstructParam;
63 typedef void (*GObjectGetPropertyFunc)  (GObject      *object,
64                                          guint         property_id,
65                                          GValue       *value,
66                                          GParamSpec   *pspec);
67 typedef void (*GObjectSetPropertyFunc)  (GObject      *object,
68                                          guint         property_id,
69                                          const GValue *value,
70                                          GParamSpec   *pspec);
71 typedef void (*GObjectFinalizeFunc)     (GObject      *object);
72 typedef void (*GWeakNotify)             (gpointer      data,
73                                          GObject      *where_the_object_was);
74 struct  _GObject
75 {
76   GTypeInstance  g_type_instance;
77   
78   /*< private >*/
79   volatile guint ref_count;
80   GData         *qdata;
81 };
82 struct  _GObjectClass
83 {
84   GTypeClass   g_type_class;
85
86   /*< private >*/
87   GSList      *construct_properties;
88
89   /*< public >*/
90   /* seldomly overidden */
91   GObject*   (*constructor)     (GType                  type,
92                                  guint                  n_construct_properties,
93                                  GObjectConstructParam *construct_properties);
94   /* overridable methods */
95   void       (*set_property)            (GObject        *object,
96                                          guint           property_id,
97                                          const GValue   *value,
98                                          GParamSpec     *pspec);
99   void       (*get_property)            (GObject        *object,
100                                          guint           property_id,
101                                          GValue         *value,
102                                          GParamSpec     *pspec);
103   void       (*dispose)                 (GObject        *object);
104   void       (*finalize)                (GObject        *object);
105   /* seldomly overidden */
106   void       (*dispatch_properties_changed) (GObject      *object,
107                                              guint         n_pspecs,
108                                              GParamSpec  **pspecs);
109   /* signals */
110   void       (*notify)                  (GObject        *object,
111                                          GParamSpec     *pspec);
112
113   /* called when done constructing */
114   void       (*constructed)             (GObject        *object);
115
116   /*< private >*/
117   /* padding */
118   gpointer      pdummy[7];
119 };
120 struct _GObjectConstructParam
121 {
122   GParamSpec *pspec;
123   GValue     *value;
124 };
125
126
127 /* --- prototypes --- */
128 GType       g_initially_unowned_get_type      (void);
129 void        g_object_class_install_property   (GObjectClass   *oclass,
130                                                guint           property_id,
131                                                GParamSpec     *pspec);
132 GParamSpec* g_object_class_find_property      (GObjectClass   *oclass,
133                                                const gchar    *property_name);
134 GParamSpec**g_object_class_list_properties    (GObjectClass   *oclass,
135                                                guint          *n_properties);
136 void        g_object_class_override_property  (GObjectClass   *oclass,
137                                                guint           property_id,
138                                                const gchar    *name);
139
140 void        g_object_interface_install_property (gpointer     g_iface,
141                                                  GParamSpec  *pspec);
142 GParamSpec* g_object_interface_find_property    (gpointer     g_iface,
143                                                  const gchar *property_name);
144 GParamSpec**g_object_interface_list_properties  (gpointer     g_iface,
145                                                  guint       *n_properties_p);
146
147 gpointer    g_object_new                      (GType           object_type,
148                                                const gchar    *first_property_name,
149                                                ...);
150 gpointer    g_object_newv                     (GType           object_type,
151                                                guint           n_parameters,
152                                                GParameter     *parameters);
153 GObject*    g_object_new_valist               (GType           object_type,
154                                                const gchar    *first_property_name,
155                                                va_list         var_args);
156 void        g_object_set                      (gpointer        object,
157                                                const gchar    *first_property_name,
158                                                ...) G_GNUC_NULL_TERMINATED;
159 void        g_object_get                      (gpointer        object,
160                                                const gchar    *first_property_name,
161                                                ...) G_GNUC_NULL_TERMINATED;
162 gpointer    g_object_connect                  (gpointer        object,
163                                                const gchar    *signal_spec,
164                                                ...) G_GNUC_NULL_TERMINATED;
165 void        g_object_disconnect               (gpointer        object,
166                                                const gchar    *signal_spec,
167                                                ...) G_GNUC_NULL_TERMINATED;
168 void        g_object_set_valist               (GObject        *object,
169                                                const gchar    *first_property_name,
170                                                va_list         var_args);
171 void        g_object_get_valist               (GObject        *object,
172                                                const gchar    *first_property_name,
173                                                va_list         var_args);
174 void        g_object_set_property             (GObject        *object,
175                                                const gchar    *property_name,
176                                                const GValue   *value);
177 void        g_object_get_property             (GObject        *object,
178                                                const gchar    *property_name,
179                                                GValue         *value);
180 void        g_object_freeze_notify            (GObject        *object);
181 void        g_object_notify                   (GObject        *object,
182                                                const gchar    *property_name);
183 void        g_object_thaw_notify              (GObject        *object);
184 gboolean    g_object_is_floating              (gpointer        object);
185 gpointer    g_object_ref_sink                 (gpointer        object);
186 gpointer    g_object_ref                      (gpointer        object);
187 void        g_object_unref                    (gpointer        object);
188 void        g_object_weak_ref                 (GObject        *object,
189                                                GWeakNotify     notify,
190                                                gpointer        data);
191 void        g_object_weak_unref               (GObject        *object,
192                                                GWeakNotify     notify,
193                                                gpointer        data);
194 void        g_object_add_weak_pointer         (GObject        *object, 
195                                                gpointer       *weak_pointer_location);
196 void        g_object_remove_weak_pointer      (GObject        *object, 
197                                                gpointer       *weak_pointer_location);
198
199 typedef void (*GToggleNotify) (gpointer      data,
200                                GObject      *object,
201                                gboolean      is_last_ref);
202
203 void g_object_add_toggle_ref    (GObject       *object,
204                                  GToggleNotify  notify,
205                                  gpointer       data);
206 void g_object_remove_toggle_ref (GObject       *object,
207                                  GToggleNotify  notify,
208                                  gpointer       data);
209
210 gpointer    g_object_get_qdata                (GObject        *object,
211                                                GQuark          quark);
212 void        g_object_set_qdata                (GObject        *object,
213                                                GQuark          quark,
214                                                gpointer        data);
215 void        g_object_set_qdata_full           (GObject        *object,
216                                                GQuark          quark,
217                                                gpointer        data,
218                                                GDestroyNotify  destroy);
219 gpointer    g_object_steal_qdata              (GObject        *object,
220                                                GQuark          quark);
221 gpointer    g_object_get_data                 (GObject        *object,
222                                                const gchar    *key);
223 void        g_object_set_data                 (GObject        *object,
224                                                const gchar    *key,
225                                                gpointer        data);
226 void        g_object_set_data_full            (GObject        *object,
227                                                const gchar    *key,
228                                                gpointer        data,
229                                                GDestroyNotify  destroy);
230 gpointer    g_object_steal_data               (GObject        *object,
231                                                const gchar    *key);
232 void        g_object_watch_closure            (GObject        *object,
233                                                GClosure       *closure);
234 GClosure*   g_cclosure_new_object             (GCallback       callback_func,
235                                                GObject        *object);
236 GClosure*   g_cclosure_new_object_swap        (GCallback       callback_func,
237                                                GObject        *object);
238 GClosure*   g_closure_new_object              (guint           sizeof_closure,
239                                                GObject        *object);
240 void        g_value_set_object                (GValue         *value,
241                                                gpointer        v_object);
242 gpointer    g_value_get_object                (const GValue   *value);
243 gpointer    g_value_dup_object                (const GValue   *value);
244 gulong      g_signal_connect_object           (gpointer        instance,
245                                                const gchar    *detailed_signal,
246                                                GCallback       c_handler,
247                                                gpointer        gobject,
248                                                GConnectFlags   connect_flags);
249
250 /*< protected >*/
251 void        g_object_force_floating           (GObject        *object);
252 void        g_object_run_dispose              (GObject        *object);
253
254
255 void        g_value_take_object               (GValue         *value,
256                                                gpointer        v_object);
257 #ifndef G_DISABLE_DEPRECATED
258 void        g_value_set_object_take_ownership (GValue         *value,
259                                                gpointer        v_object);
260 #endif
261
262 #if !defined(G_DISABLE_DEPRECATED) || defined(GTK_COMPILATION)
263 gsize       g_object_compat_control           (gsize           what,
264                                                gpointer        data);
265 #endif
266
267 /* --- implementation macros --- */
268 #define G_OBJECT_WARN_INVALID_PSPEC(object, pname, property_id, pspec) \
269 G_STMT_START { \
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'", \
274              G_STRLOC, \
275              (pname), \
276              _property_id, \
277              _pspec->name, \
278              g_type_name (G_PARAM_SPEC_TYPE (_pspec)), \
279              G_OBJECT_TYPE_NAME (_object)); \
280 } G_STMT_END
281 #define G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec) \
282     G_OBJECT_WARN_INVALID_PSPEC ((object), "property", (property_id), (pspec))
283
284 G_END_DECLS
285
286 #endif /* __G_OBJECT_H__ */