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
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
19 #ifndef __GTK_TYPE_UTILS_H__
20 #define __GTK_TYPE_UTILS_H__
29 #endif /* __cplusplus */
55 /* structured types */
62 /* base type node of the object system */
66 /* bounds definitions for type sets, these are provided to distinct
67 * between fundamental types with if() statements, and to build
68 * up foreign fundamentals
70 #define GTK_TYPE_FLAT_FIRST GTK_TYPE_CHAR
71 #define GTK_TYPE_FLAT_LAST GTK_TYPE_POINTER
72 #define GTK_TYPE_STRUCTURED_FIRST GTK_TYPE_SIGNAL
73 #define GTK_TYPE_STRUCTURED_LAST GTK_TYPE_FOREIGN
74 #define GTK_TYPE_FUNDAMENTAL_LAST GTK_TYPE_OBJECT
77 /* retrive a structure offset */
79 #define GTK_STRUCT_OFFSET(struct, field) ((gint) offsetof (struct, field))
81 #define GTK_STRUCT_OFFSET(struct, field) ((gint) ((gchar*) &((struct*) 0)->field))
82 #endif /* !offsetof */
85 /* The debugging versions of the casting macros make sure the cast is "ok"
86 * before proceeding, but they are definately slower than their less
87 * careful counterparts as they involve extra ``is a'' checks.
89 #ifdef GTK_NO_CHECK_CASTS
90 # define GTK_CHECK_CAST(tobj, cast_type, cast) ((cast*) (tobj))
91 # define GTK_CHECK_CLASS_CAST(tclass,cast_type,cast) ((cast*) (tclass))
92 #else /* !GTK_NO_CHECK_CASTS */
93 # define GTK_CHECK_CAST(tobj, cast_type, cast) \
94 ((cast*) gtk_type_check_object_cast ((GtkTypeObject*) (tobj), (cast_type)))
95 # define GTK_CHECK_CLASS_CAST(tclass,cast_type,cast) \
96 ((cast*) gtk_type_check_class_cast ((GtkTypeClass*) (tclass), (cast_type)))
97 #endif /* GTK_NO_CHECK_CASTS */
99 /* Determines whether `type_object' and `type_class' are a type of `otype'.
101 #define GTK_CHECK_TYPE(type_object, otype) ( \
102 gtk_type_is_a (((GtkTypeObject*) (type_object))->klass->type, (otype)) \
104 #define GTK_CHECK_CLASS_TYPE(type_class, otype) ( \
105 gtk_type_is_a (((GtkTypeClass*) (type_class))->type, (otype)) \
111 /* A GtkType holds a unique type id
113 typedef guint GtkType;
115 typedef struct _GtkTypeObject GtkTypeObject;
116 typedef struct _GtkTypeClass GtkTypeClass;
121 #include <gtk/gtktypebuiltins.h>
123 #define GTK_TYPE_IDENTIFIER (gtk_identifier_get_type ())
124 GtkType gtk_identifier_get_type (void);
128 #define GTK_TYPE_MAKE(parent_t, seqno) (((seqno) << 8) | GTK_FUNDAMENTAL_TYPE (parent_t))
129 #define GTK_FUNDAMENTAL_TYPE(type) ((GtkFundamentalType) ((type) & 0xFF))
130 #define GTK_TYPE_SEQNO(type) ((type) > 0xFF ? (type) >> 8 : (type))
132 typedef struct _GtkArg GtkArg;
133 typedef struct _GtkObject GtkObject; /* forward declaration of object type */
134 typedef struct _GtkTypeInfo GtkTypeInfo;
135 typedef struct _GtkEnumValue GtkEnumValue;
136 typedef struct _GtkEnumValue GtkFlagValue;
139 #define GTK_SIGNAL_FUNC(f) ((GtkSignalFunc) f)
141 typedef void (*GtkClassInitFunc) (gpointer klass);
142 typedef void (*GtkObjectInitFunc) (gpointer object);
143 typedef void (*GtkSignalFunc) ();
144 typedef gint (*GtkFunction) (gpointer data);
145 typedef void (*GtkDestroyNotify) (gpointer data);
146 typedef void (*GtkCallbackMarshal) (GtkObject *object,
150 typedef void (*GtkSignalMarshaller) (GtkObject *object,
157 typedef void (*GtkArgGetFunc) (GtkObject*, GtkArg*, guint);
158 typedef void (*GtkArgSetFunc) (GtkObject*, GtkArg*, guint);
161 /* A GtkTypeObject defines the minimum structure requirements
162 * for type instances. Type instances returned from gtk_type_new ()
163 * and initialized through a GtkObjectInitFunc need to directly inherit
164 * from this structure or at least copy its fields one by one.
166 struct _GtkTypeObject
168 /* A pointer to the objects class. This will actually point to
169 * the derived objects class struct (which will be derived from
176 /* A GtkTypeClass defines the minimum structure requirements for
177 * a types class. Classes returned from gtk_type_class () and
178 * initialized through a GtkClassInitFunc need to directly inherit
179 * from this structure or at least copy its fields one by one.
183 /* The type identifier for the objects class. There is
184 * one unique identifier per class.
195 /* this union only defines the required storage types for
196 * the possibile values, thus there is no gint enum_data field,
197 * because that would just be a mere alias for gint int_data.
198 * use the GTK_VALUE_*() and GTK_RETLOC_*() macros to access
199 * the discrete memebers.
213 gpointer pointer_data;
214 GtkObject *object_data;
216 /* structured values */
226 GtkCallbackMarshal marshal;
228 GtkDestroyNotify notify;
236 GtkDestroyNotify notify;
241 /* argument value access macros, these must not contain casts,
242 * to allow the usage of these macros in combination with the
243 * adress operator, e.g. >K_VALUE_CHAR (*arg)
247 #define GTK_VALUE_CHAR(a) ((a).d.char_data)
248 #define GTK_VALUE_UCHAR(a) ((a).d.uchar_data)
249 #define GTK_VALUE_BOOL(a) ((a).d.bool_data)
250 #define GTK_VALUE_INT(a) ((a).d.int_data)
251 #define GTK_VALUE_UINT(a) ((a).d.uint_data)
252 #define GTK_VALUE_LONG(a) ((a).d.long_data)
253 #define GTK_VALUE_ULONG(a) ((a).d.ulong_data)
254 #define GTK_VALUE_FLOAT(a) ((a).d.float_data)
255 #define GTK_VALUE_DOUBLE(a) ((a).d.double_data)
256 #define GTK_VALUE_STRING(a) ((a).d.string_data)
257 #define GTK_VALUE_ENUM(a) ((a).d.int_data)
258 #define GTK_VALUE_FLAGS(a) ((a).d.uint_data)
259 #define GTK_VALUE_BOXED(a) ((a).d.pointer_data)
260 #define GTK_VALUE_POINTER(a) ((a).d.pointer_data)
261 #define GTK_VALUE_OBJECT(a) ((a).d.object_data)
263 /* structured values */
264 #define GTK_VALUE_SIGNAL(a) ((a).d.signal_data)
265 #define GTK_VALUE_ARGS(a) ((a).d.args_data)
266 #define GTK_VALUE_CALLBACK(a) ((a).d.callback_data)
267 #define GTK_VALUE_C_CALLBACK(a) ((a).d.c_callback_data)
268 #define GTK_VALUE_FOREIGN(a) ((a).d.foreign_data)
270 /* return location macros, these all narow down to
271 * pointer types, because return values need to be
272 * passed by reference
276 #define GTK_RETLOC_CHAR(a) ((gchar*) (a).d.pointer_data)
277 #define GTK_RETLOC_UCHAR(a) ((guchar*) (a).d.pointer_data)
278 #define GTK_RETLOC_BOOL(a) ((gboolean*) (a).d.pointer_data)
279 #define GTK_RETLOC_INT(a) ((gint*) (a).d.pointer_data)
280 #define GTK_RETLOC_UINT(a) ((guint*) (a).d.pointer_data)
281 #define GTK_RETLOC_LONG(a) ((glong*) (a).d.pointer_data)
282 #define GTK_RETLOC_ULONG(a) ((gulong*) (a).d.pointer_data)
283 #define GTK_RETLOC_FLOAT(a) ((gfloat*) (a).d.pointer_data)
284 #define GTK_RETLOC_DOUBLE(a) ((gdouble*) (a).d.pointer_data)
285 #define GTK_RETLOC_STRING(a) ((gchar**) (a).d.pointer_data)
286 #define GTK_RETLOC_ENUM(a) ((gint*) (a).d.pointer_data)
287 #define GTK_RETLOC_FLAGS(a) ((guint*) (a).d.pointer_data)
288 #define GTK_RETLOC_BOXED(a) ((gpointer*) (a).d.pointer_data)
289 #define GTK_RETLOC_POINTER(a) ((gpointer*) (a).d.pointer_data)
290 #define GTK_RETLOC_OBJECT(a) ((GtkObject**) (a).d.pointer_data)
297 GtkClassInitFunc class_init_func;
298 GtkObjectInitFunc object_init_func;
301 GtkClassInitFunc base_class_init_func;
312 void gtk_type_init (void);
313 GtkType gtk_type_unique (GtkType parent_type,
314 GtkTypeInfo *type_info);
315 void gtk_type_set_chunk_alloc (GtkType type,
317 gchar* gtk_type_name (guint type);
318 GtkType gtk_type_from_name (const gchar *name);
319 GtkType gtk_type_parent (GtkType type);
320 gpointer gtk_type_class (GtkType type);
321 gpointer gtk_type_parent_class (GtkType type);
322 GList* gtk_type_children_types (GtkType type);
323 gpointer gtk_type_new (GtkType type);
324 void gtk_type_free (GtkType type,
326 void gtk_type_describe_heritage (GtkType type);
327 void gtk_type_describe_tree (GtkType type,
329 gint gtk_type_is_a (GtkType type,
331 GtkTypeObject* gtk_type_check_object_cast (GtkTypeObject *type_object,
333 GtkTypeClass* gtk_type_check_class_cast (GtkTypeClass *klass,
335 GtkType gtk_type_register_enum (const gchar *type_name,
336 GtkEnumValue *values);
337 GtkType gtk_type_register_flags (const gchar *type_name,
338 GtkFlagValue *values);
339 GtkEnumValue* gtk_type_enum_get_values (GtkType enum_type);
340 GtkFlagValue* gtk_type_flags_get_values (GtkType flags_type);
341 GtkEnumValue* gtk_type_enum_find_value (GtkType enum_type,
342 const gchar *value_name);
343 GtkFlagValue* gtk_type_flags_find_value (GtkType flag_type,
344 const gchar *value_name);
345 /* set the argument collector alias for foreign fundamentals */
346 void gtk_type_set_varargs_type (GtkType foreign_type,
347 GtkType varargs_type);
348 GtkType gtk_type_get_varargs_type (GtkType foreign_type);
356 #endif /* __cplusplus */
359 #endif /* __GTK_TYPE_UTILS_H__ */