1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
14 * You should have received a copy of the GNU Lesser General Public
15 * 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.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #ifndef __GTK_OBJECT_H__
28 #define __GTK_OBJECT_H__
31 #include <gtk/gtkarg.h>
32 #include <gtk/gtkenums.h>
33 #include <gtk/gtktypeutils.h>
34 #include <gtk/gtkdebug.h>
39 #endif /* __cplusplus */
42 /* macros for casting a pointer to a GtkObject or GtkObjectClass pointer,
43 * and to test whether `object' and `klass' are of type GTK_TYPE_OBJECT.
44 * these are the standard macros for all GtkObject-derived classes.
46 #define GTK_TYPE_OBJECT (gtk_object_get_type ())
47 #define GTK_OBJECT(object) (GTK_CHECK_CAST ((object), GTK_TYPE_OBJECT, GtkObject))
48 #define GTK_OBJECT_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_OBJECT, GtkObjectClass))
49 #define GTK_IS_OBJECT(object) (GTK_CHECK_TYPE ((object), GTK_TYPE_OBJECT))
50 #define GTK_IS_OBJECT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_OBJECT))
51 #define GTK_OBJECT_GET_CLASS(object) (GTK_CHECK_GET_CLASS ((object), GTK_TYPE_OBJECT, GtkObjectClass))
53 /* Macros for extracting various fields from GtkObject and GtkObjectClass.
55 #define GTK_OBJECT_TYPE(object) (G_TYPE_FROM_INSTANCE (object))
56 #define GTK_OBJECT_TYPE_NAME(object) (g_type_name (GTK_OBJECT_TYPE (object)))
58 /* GtkObject only uses the first 4 bits of the flags field.
59 * Derived objects may use the remaining bits. Though this
60 * is a kinda nasty break up, it does make the size of
61 * derived objects smaller.
65 GTK_DESTROYED = 1 << 0,
66 GTK_FLOATING = 1 << 1,
67 GTK_RESERVED = 1 << 2,
68 GTK_CONSTRUCTED = 1 << 3
71 /* Macros for extracting the object_flags from GtkObject.
73 #define GTK_OBJECT_FLAGS(obj) (GTK_OBJECT (obj)->flags)
74 #define GTK_OBJECT_DESTROYED(obj) ((GTK_OBJECT_FLAGS (obj) & GTK_DESTROYED) != 0)
75 #define GTK_OBJECT_FLOATING(obj) ((GTK_OBJECT_FLAGS (obj) & GTK_FLOATING) != 0)
76 #define GTK_OBJECT_CONNECTED(obj) ((GTK_OBJECT_FLAGS (obj) & GTK_CONNECTED) != 0)
77 #define GTK_OBJECT_CONSTRUCTED(obj) ((GTK_OBJECT_FLAGS (obj) & GTK_CONSTRUCTED) != 0)
79 /* Macros for setting and clearing bits in the object_flags field of GtkObject.
81 #define GTK_OBJECT_SET_FLAGS(obj,flag) G_STMT_START{ (GTK_OBJECT_FLAGS (obj) |= (flag)); }G_STMT_END
82 #define GTK_OBJECT_UNSET_FLAGS(obj,flag) G_STMT_START{ (GTK_OBJECT_FLAGS (obj) &= ~(flag)); }G_STMT_END
84 /* GtkArg flag bits for gtk_object_add_arg_type
88 GTK_ARG_READABLE = 1 << 0,
89 GTK_ARG_WRITABLE = 1 << 1,
90 GTK_ARG_CONSTRUCT = 1 << 2,
91 GTK_ARG_CONSTRUCT_ONLY = 1 << 3,
92 GTK_ARG_CHILD_ARG = 1 << 4,
97 GTK_ARG_READWRITE = GTK_ARG_READABLE | GTK_ARG_WRITABLE
100 typedef struct _GtkObjectClass GtkObjectClass;
103 /* The GtkObject structure is the base of the Gtk+ objects hierarchy,
104 * it ``inherits'' from the GtkTypeObject by mirroring its fields,
105 * which must always be kept in sync completely. The GtkObject defines
106 * the few basic items that all derived classes contain.
110 GObject parent_instance;
112 /* 32 bits of flags. GtkObject only uses 4 of these bits and
113 * GtkWidget uses the rest. This is done because structs are
114 * aligned on 4 or 8 byte boundaries. If a new bitfield were
115 * used in GtkWidget much space would be wasted.
120 /* The GtkObjectClass is the base of the Gtk+ objects classes hierarchy,
121 * it ``inherits'' from the GtkTypeClass by mirroring its fields, which
122 * must always be kept in sync completely. The GtkObjectClass defines
123 * the basic necessities for the object inheritance mechanism to work.
124 * Namely, the `signals' and `nsignals' fields as well as the function
125 * pointers, required to end an object's lifetime.
127 struct _GtkObjectClass
129 GObjectClass parent_class;
131 /* The signals this object class handles. "signals" is an
132 * array of signal ID's.
136 /* The number of signals listed in "signals".
140 /* The number of arguments per class.
143 GSList *construct_args;
145 /* Non overridable class methods to set and get per class arguments */
146 void (*set_arg) (GtkObject *object,
149 void (*get_arg) (GtkObject *object,
153 /* The function that will end an objects life time. In one way ore
154 * another all three of them are defined for all objects. If an
155 * object class overrides one of the methods in order to perform class
156 * specific destruction then it must still invoke its superclass'
157 * implementation of the method after it is finished with its
158 * own cleanup. (See the destroy function for GtkWidget for
159 * an example of how to do this).
161 void (* destroy) (GtkObject *object);
166 /* Application-level methods */
168 GtkType gtk_object_get_type (void) G_GNUC_CONST;
170 /* Append a user defined signal without default handler to a class. */
171 guint gtk_object_class_user_signal_new (GtkObjectClass *klass,
173 GtkSignalRunType signal_flags,
174 GtkSignalMarshaller marshaller,
178 guint gtk_object_class_user_signal_newv (GtkObjectClass *klass,
180 GtkSignalRunType signal_flags,
181 GtkSignalMarshaller marshaller,
185 GtkObject* gtk_object_new (GtkType type,
186 const gchar *first_arg_name,
188 GtkObject* gtk_object_newv (GtkType object_type,
191 GtkObject* gtk_object_ref (GtkObject *object);
192 void gtk_object_unref (GtkObject *object);
193 void gtk_object_default_construct (GtkObject *object);
194 void gtk_object_constructed (GtkObject *object);
195 void gtk_object_sink (GtkObject *object);
196 void gtk_object_weakref (GtkObject *object,
197 GtkDestroyNotify notify,
199 void gtk_object_weakunref (GtkObject *object,
200 GtkDestroyNotify notify,
202 void gtk_object_destroy (GtkObject *object);
204 /* gtk_object_getv() sets an arguments type and value, or just
205 * its type to GTK_TYPE_INVALID.
206 * if GTK_FUNDAMENTAL_TYPE (arg->type) == GTK_TYPE_STRING, it's
207 * the callers response to do a g_free (GTK_VALUE_STRING (arg));
209 void gtk_object_getv (GtkObject *object,
212 /* gtk_object_get() sets the variable values pointed to by the adresses
213 * passed after the argument names according to the arguments value.
214 * if GTK_FUNDAMENTAL_TYPE (arg->type) == GTK_TYPE_STRING, it's
215 * the callers response to do a g_free (retrived_value);
217 void gtk_object_get (GtkObject *object,
218 const gchar *first_arg_name,
221 /* gtk_object_set() takes a variable argument list of the form:
222 * (..., gchar *arg_name, ARG_VALUES, [repeatedly name/value pairs,] NULL)
223 * where ARG_VALUES type depend on the argument and can consist of
224 * more than one c-function argument.
226 void gtk_object_set (GtkObject *object,
227 const gchar *first_arg_name,
229 void gtk_object_setv (GtkObject *object,
233 /* Allocate a GtkArg array of size nargs that hold the
234 * names and types of the args that can be used with
235 * gtk_object_set/gtk_object_get. if (arg_flags!=NULL),
236 * (*arg_flags) will be set to point to a newly allocated
237 * guint array that holds the flags of the args.
238 * It is the callers response to do a
239 * g_free (returned_args); g_free (*arg_flags).
241 GtkArg* gtk_object_query_args (GtkType class_type,
245 /* Set 'data' to the "object_data" field of the object. The
246 * data is indexed by the "key". If there is already data
247 * associated with "key" then the new data will replace it.
248 * If 'data' is NULL then this call is equivalent to
249 * 'gtk_object_remove_data'.
250 * The gtk_object_set_data_full variant acts just the same,
251 * but takes an additional argument which is a function to
252 * be called when the data is removed.
253 * `gtk_object_remove_data' is equivalent to the above,
254 * where 'data' is NULL
255 * `gtk_object_get_data' gets the data associated with "key".
257 void gtk_object_set_data (GtkObject *object,
260 void gtk_object_set_data_full (GtkObject *object,
263 GtkDestroyNotify destroy);
264 void gtk_object_remove_data (GtkObject *object,
266 gpointer gtk_object_get_data (GtkObject *object,
268 void gtk_object_remove_no_notify (GtkObject *object,
271 /* Set/get the "user_data" object data field of "object". It should
272 * be noted that these functions are no different than calling
273 * `gtk_object_set_data'/`gtk_object_get_data' with a key of "user_data".
274 * They are merely provided as a convenience.
276 void gtk_object_set_user_data (GtkObject *object,
278 gpointer gtk_object_get_user_data (GtkObject *object);
281 /* Object-level methods */
283 /* Append "signals" to those already defined in "class". */
284 void gtk_object_class_add_signals (GtkObjectClass *klass,
287 /* the `arg_name' argument needs to be a const static string */
288 void gtk_object_add_arg_type (const gchar *arg_name,
293 /* Object data method variants that operate on key ids. */
294 void gtk_object_set_data_by_id (GtkObject *object,
297 void gtk_object_set_data_by_id_full (GtkObject *object,
300 GtkDestroyNotify destroy);
301 gpointer gtk_object_get_data_by_id (GtkObject *object,
303 void gtk_object_remove_data_by_id (GtkObject *object,
305 void gtk_object_remove_no_notify_by_id (GtkObject *object,
307 #define gtk_object_data_try_key g_quark_try_string
308 #define gtk_object_data_force_id g_quark_from_string
311 /* Non-public methods */
313 void gtk_object_arg_set (GtkObject *object,
316 void gtk_object_arg_get (GtkObject *object,
319 gchar* gtk_object_args_collect (GtkType object_type,
321 GSList **info_list_p,
322 const gchar *first_arg_name,
324 gchar* gtk_object_arg_get_info (GtkType object_type,
325 const gchar *arg_name,
326 GtkArgInfo **info_p);
336 #endif /* __cplusplus */
339 #endif /* __GTK_OBJECT_H__ */