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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #ifndef __GTK_OBJECT_H__
19 #define __GTK_OBJECT_H__
22 #include <gtk/gtkenums.h>
23 #include <gtk/gtktypeutils.h>
28 #endif /* __cplusplus */
31 /* GtkObject only uses the first 3 bits of the "flags" field.
32 * They refer to the following flags.
33 * GtkWidget uses the remaining bits. Though this is a kinda nasty
34 * break up, it does make the size of GtkWidget smaller.
38 GTK_NEED_DESTROY = 1 << 0,
39 GTK_BEING_DESTROYED = 1 << 1,
44 /* The debugging versions of the casting macros make sure the cast is "ok"
45 * before proceeding, but they are definately slower than their less
46 * careful counterparts as they involve no less than 3 function calls.
50 #define GTK_CHECK_CAST(obj,cast_type,cast) ((cast*) obj)
51 #define GTK_CHECK_CLASS_CAST(klass,cast_type,cast) ((cast*) klass)
55 #define GTK_CHECK_CAST(obj,cast_type,cast) \
56 ((cast*) gtk_object_check_cast ((GtkObject*) obj, cast_type))
58 #define GTK_CHECK_CLASS_CAST(klass,cast_type,cast) \
59 ((cast*) gtk_object_check_class_cast ((GtkObjectClass*) klass, cast_type))
64 /* Determines whether 'obj' is a type of 'otype'.
66 #define GTK_CHECK_TYPE(obj,otype) (gtk_type_is_a (((GtkObject*) obj)->klass->type, otype))
69 /* Macro for casting a pointer to a GtkObject pointer.
71 #define GTK_OBJECT(obj) GTK_CHECK_CAST (obj, gtk_object_get_type (), GtkObject)
73 /* Macros for extracting various fields from GtkObject and
76 #define GTK_OBJECT_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_object_get_type (), GtkObjectClass)
77 #define GTK_OBJECT_FLAGS(obj) (GTK_OBJECT (obj)->flags)
78 #define GTK_OBJECT_NEED_DESTROY(obj) (GTK_OBJECT_FLAGS (obj) & GTK_NEED_DESTROY)
79 #define GTK_OBJECT_BEING_DESTROYED(obj) (GTK_OBJECT_FLAGS (obj) & GTK_BEING_DESTROYED)
80 #define GTK_OBJECT_IN_CALL(obj) (GTK_OBJECT_FLAGS (obj) & GTK_IN_CALL)
81 #define GTK_OBJECT_DESTROY(obj) (GTK_OBJECT (obj)->klass->destroy)
82 #define GTK_OBJECT_TYPE(obj) (GTK_OBJECT (obj)->klass->type)
83 #define GTK_OBJECT_SIGNALS(obj) (GTK_OBJECT (obj)->klass->signals)
84 #define GTK_OBJECT_NSIGNALS(obj) (GTK_OBJECT (obj)->klass->signals)
86 /* Macro for testing whether "obj" is of type GtkObject.
88 #define GTK_IS_OBJECT(obj) GTK_CHECK_TYPE (obj, gtk_object_get_type ())
90 /* Macros for setting and clearing bits in the "flags" field of GtkObject.
92 #define GTK_OBJECT_SET_FLAGS(obj,flag) (GTK_OBJECT_FLAGS (obj) |= (flag))
93 #define GTK_OBJECT_UNSET_FLAGS(obj,flag) (GTK_OBJECT_FLAGS (obj) &= ~(flag))
96 typedef struct _GtkObjectClass GtkObjectClass;
99 /* GtkObject is the base of the object hierarchy. It defines
100 * the few basic items that all derived classes contain.
104 /* 32 bits of flags. GtkObject only uses 3 of these bits and
105 * GtkWidget uses the rest. This is done because structs are
106 * aligned on 4 or 8 byte boundaries. If bitfields were used
107 * both here and in GtkWidget much space would be wasted.
111 /* 16 bit reference count. "gtk_object_destroy" actually only
112 * destroys an object when its ref count is 0. (Decrementing
113 * a reference count of 0 is defined as a no-op).
117 /* A pointer to the objects class. This will actually point to
118 * the derived objects class struct (which will be derived from
121 GtkObjectClass *klass;
123 /* The list of signal handlers and other data
124 * fields for this object.
126 gpointer object_data;
129 /* GtkObjectClass is the base of the class hierarchy. It defines
130 * the basic necessities for the class mechanism to work. Namely,
131 * the "type", "signals" and "nsignals" fields.
133 struct _GtkObjectClass
135 /* The type identifier for the objects class. There is
136 * one unique identifier per class.
140 /* The signals this object class handles. "signals" is an
141 * array of signal ID's.
145 /* The number of signals listed in "signals".
149 /* The destroy function for objects. In one way ore another
150 * this is defined for all objects. If an object class overrides
151 * this method in order to perform class specific destruction
152 * then it should still call it after it is finished with its
153 * own cleanup. (See the destroy function for GtkWidget for
154 * an example of how to do this).
156 void (* destroy) (GtkObject *object);
160 /* Get the type identifier for GtkObject's.
162 guint gtk_object_get_type (void);
164 /* Append "signals" to those already defined in "class".
166 void gtk_object_class_add_signals (GtkObjectClass *klass,
170 void gtk_object_ref (GtkObject *object);
172 void gtk_object_unref (GtkObject *object);
174 GtkObject* gtk_object_new (guint type,
177 GtkObject* gtk_object_newv (guint type,
181 void gtk_object_set (GtkObject *obj,
184 void gtk_object_setv (GtkObject *obj,
188 void gtk_object_add_arg_type (const char *arg_name,
191 GtkType gtk_object_get_arg_type (const char *arg_name);
193 /* Emit the "destroy" signal for "object". Normally it is
194 * permissible to emit a signal for an object instead of
195 * calling the corresponding convenience routine, however
196 * "gtk_object_destroy" should be called instead of emitting
197 * the signal manually as it checks to see if the object is
198 * currently handling another signal emittion (very likely)
199 * and sets the GTK_NEED_DESTROY flag which tells the object
200 * to be destroyed when it is done handling the signal emittion.
202 void gtk_object_destroy (GtkObject *object);
204 /* Set 'data' to the "object_data" field of the object. The
205 * data is indexed by the "key". If there is already data
206 * associated with "key" then the new data will replace it.
207 * If 'data' is NULL then this call is equivalent to
208 * 'gtk_object_remove_data'.
210 void gtk_object_set_data (GtkObject *object,
214 /* Get the data associated with "key".
216 gpointer gtk_object_get_data (GtkObject *object,
219 /* Remove the data associated with "key". This call is
220 * equivalent to 'gtk_object_set_data' where 'data' is NULL.
222 void gtk_object_remove_data (GtkObject *object,
225 /* Set the "user_data" object data field of "object". It should
226 * be noted that this is no different than calling 'gtk_object_data_add'
227 * with a key of "user_data". It is merely provided as a convenience.
229 void gtk_object_set_user_data (GtkObject *object,
232 /* Get the "user_data" object data field of "object". It should
233 * be noted that this is no different than calling 'gtk_object_data_find'
234 * with a key of "user_data". It is merely provided as a convenience.
236 gpointer gtk_object_get_user_data (GtkObject *object);
238 GtkObject* gtk_object_check_cast (GtkObject *obj,
241 GtkObjectClass* gtk_object_check_class_cast (GtkObjectClass *klass,
247 #endif /* __cplusplus */
250 #endif /* __GTK_OBJECT_H__ */