]> Pileus Git - ~andy/gtk/blob - gtk/gtktypeutils.h
for unknown foreign fundamental types, collect an argument of the type
[~andy/gtk] / gtk / gtktypeutils.h
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
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  * Library General Public License for more details.
13  *
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.
18  */
19 #ifndef __GTK_TYPE_UTILS_H__
20 #define __GTK_TYPE_UTILS_H__
21
22
23 #include <glib.h>
24
25
26 #ifdef __cplusplus
27 extern "C" {
28 #pragma }
29 #endif /* __cplusplus */
30
31
32 /* Fundamental Types
33  */
34 typedef enum
35 {
36   GTK_TYPE_INVALID,
37   GTK_TYPE_NONE,
38   
39   /* flat types */
40   GTK_TYPE_CHAR,
41   GTK_TYPE_UCHAR,
42   GTK_TYPE_BOOL,
43   GTK_TYPE_INT,
44   GTK_TYPE_UINT,
45   GTK_TYPE_LONG,
46   GTK_TYPE_ULONG,
47   GTK_TYPE_FLOAT,
48   GTK_TYPE_DOUBLE,
49   GTK_TYPE_STRING,
50   GTK_TYPE_ENUM,
51   GTK_TYPE_FLAGS,
52   GTK_TYPE_BOXED,
53   GTK_TYPE_POINTER,
54   
55   /* structured types */
56   GTK_TYPE_SIGNAL,
57   GTK_TYPE_ARGS,
58   GTK_TYPE_CALLBACK,
59   GTK_TYPE_C_CALLBACK,
60   GTK_TYPE_FOREIGN,
61   
62   /* base type node of the object system */
63   GTK_TYPE_OBJECT
64 } GtkFundamentalType;
65
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
69  */
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
75
76
77 /* retrive a structure offset */
78 #ifdef offsetof
79 #define GTK_STRUCT_OFFSET(struct, field)        ((gint) offsetof (struct, field))
80 #else /* !offsetof */
81 #define GTK_STRUCT_OFFSET(struct, field)        ((gint) ((gchar*) &((struct*) 0)->field))
82 #endif /* !offsetof */
83
84
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.
88  */
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 */
98
99 /* Determines whether `type_object' and `type_class' are a type of `otype'.
100  */
101 #define GTK_CHECK_TYPE(type_object, otype)       ( \
102   gtk_type_is_a (((GtkTypeObject*) (type_object))->klass->type, (otype)) \
103 )
104 #define GTK_CHECK_CLASS_TYPE(type_class, otype)  ( \
105   gtk_type_is_a (((GtkTypeClass*) (type_class))->type, (otype)) \
106 )
107
108
109
110
111 /* A GtkType holds a unique type id
112  */
113 typedef guint GtkType;
114
115 typedef struct _GtkTypeObject   GtkTypeObject;
116 typedef struct _GtkTypeClass    GtkTypeClass;
117
118
119 /* Builtin Types
120  */
121 #include <gtk/gtktypebuiltins.h>
122
123 #define         GTK_TYPE_IDENTIFIER             (gtk_identifier_get_type ())
124 GtkType         gtk_identifier_get_type         (void);
125
126 /* Macros
127  */
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))
131
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;
137
138
139 #define GTK_SIGNAL_FUNC(f)  ((GtkSignalFunc) f)
140
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,
147                                     gpointer   data,
148                                     guint      n_args,
149                                     GtkArg    *args);
150 typedef void (*GtkSignalMarshaller) (GtkObject      *object,
151                                      GtkSignalFunc   func,
152                                      gpointer        func_data,
153                                      GtkArg         *args);
154
155
156 /* deprecated */
157 typedef void (*GtkArgGetFunc)      (GtkObject*, GtkArg*, guint);
158 typedef void (*GtkArgSetFunc)      (GtkObject*, GtkArg*, guint);
159
160
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.
165  */
166 struct _GtkTypeObject
167 {
168   /* A pointer to the objects class. This will actually point to
169    *  the derived objects class struct (which will be derived from
170    *  GtkTypeClass).
171    */
172   GtkTypeClass  *klass;
173 };
174
175
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.
180  */
181 struct _GtkTypeClass
182 {
183   /* The type identifier for the objects class. There is
184    *  one unique identifier per class.
185    */
186   GtkType type;
187 };
188
189
190 struct _GtkArg
191 {
192   GtkType type;
193   gchar *name;
194   
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.
200    */
201   union {
202     /* flat values */
203     gchar char_data;
204     guchar uchar_data;
205     gboolean bool_data;
206     gint int_data;
207     guint uint_data;
208     glong long_data;
209     gulong ulong_data;
210     gfloat float_data;
211     gdouble double_data;
212     gchar *string_data;
213     gpointer pointer_data;
214     GtkObject *object_data;
215     
216     /* structured values */
217     struct {
218       GtkSignalFunc f;
219       gpointer d;
220     } signal_data;
221     struct {
222       gint n_args;
223       GtkArg *args;
224     } args_data;
225     struct {
226       GtkCallbackMarshal marshal;
227       gpointer data;
228       GtkDestroyNotify notify;
229     } callback_data;
230     struct {
231       GtkFunction func;
232       gpointer func_data;
233     } c_callback_data;
234     struct {
235       gpointer data;
236       GtkDestroyNotify notify;
237     } foreign_data;
238   } d;
239 };
240
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. &GTK_VALUE_CHAR (*arg)
244  */
245
246 /* flat values */
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)
262
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)
269
270 /* return location macros, these all narow down to
271  * pointer types, because return values need to be
272  * passed by reference
273  */
274
275 /* flat values */
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)
291
292 struct _GtkTypeInfo
293 {
294   gchar                 *type_name;
295   guint                  object_size;
296   guint                  class_size;
297   GtkClassInitFunc       class_init_func;
298   GtkObjectInitFunc      object_init_func;
299   gpointer               reserved_1;
300   gpointer               reserved_2;
301   GtkClassInitFunc       base_class_init_func;
302 };
303
304 struct _GtkEnumValue
305 {
306   guint  value;
307   gchar *value_name;
308   gchar *value_nick;
309 };
310
311
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,
316                                                  guint           n_chunks);
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,
325                                                  gpointer        mem);
326 void            gtk_type_describe_heritage      (GtkType         type);
327 void            gtk_type_describe_tree          (GtkType         type,
328                                                  gboolean        show_size);
329 gint            gtk_type_is_a                   (GtkType         type,
330                                                  GtkType         is_a_type);
331 GtkTypeObject*  gtk_type_check_object_cast      (GtkTypeObject  *type_object,
332                                                  GtkType         cast_type);
333 GtkTypeClass*   gtk_type_check_class_cast       (GtkTypeClass   *klass,
334                                                  GtkType         cast_type);
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);
349
350
351
352
353
354 #ifdef __cplusplus
355 }
356 #endif /* __cplusplus */
357
358
359 #endif /* __GTK_TYPE_UTILS_H__ */