gtktypeutils.h 8.64 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1 2 3 4
/* GTK - The GIMP Toolkit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 *
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
Elliot Lee's avatar
Elliot Lee committed
6 7 8 9 10
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * 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.
Elliot Lee's avatar
Elliot Lee committed
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15 16 17
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
18
 */
19 20

/*
21
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22 23 24 25 26
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 */

Elliot Lee's avatar
Elliot Lee committed
27 28 29 30
#ifndef __GTK_TYPE_UTILS_H__
#define __GTK_TYPE_UTILS_H__


31
#include <glib-object.h>
Elliot Lee's avatar
Elliot Lee committed
32 33


34
G_BEGIN_DECLS
Elliot Lee's avatar
Elliot Lee committed
35

36
#ifndef GTK_DISABLE_DEPRECATED
Elliot Lee's avatar
Elliot Lee committed
37

38
/* Fundamental Types
39 40
 * many of these are just aliases for GLib types to maintain
 * compatibility
41
 */
42

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#define GTK_TYPE_INVALID G_TYPE_INVALID
#define GTK_TYPE_NONE    G_TYPE_NONE
#define GTK_TYPE_ENUM    G_TYPE_ENUM
#define GTK_TYPE_FLAGS   G_TYPE_FLAGS

/* GtkArg types */
#define GTK_TYPE_CHAR    G_TYPE_CHAR
#define GTK_TYPE_UCHAR   G_TYPE_UCHAR
#define GTK_TYPE_BOOL    G_TYPE_BOOLEAN
#define GTK_TYPE_INT     G_TYPE_INT
#define GTK_TYPE_UINT    G_TYPE_UINT
#define GTK_TYPE_LONG    G_TYPE_LONG
#define GTK_TYPE_ULONG   G_TYPE_ULONG
#define GTK_TYPE_FLOAT   G_TYPE_FLOAT
#define GTK_TYPE_DOUBLE  G_TYPE_DOUBLE
#define GTK_TYPE_STRING  G_TYPE_STRING
#define GTK_TYPE_BOXED   G_TYPE_BOXED
#define GTK_TYPE_POINTER G_TYPE_POINTER

typedef GType GtkFundamentalType;
Elliot Lee's avatar
Elliot Lee committed
63

64 65 66 67
/* --- type macros --- */
#define GTK_CLASS_NAME(class)		(g_type_name (G_TYPE_FROM_CLASS (class)))
#define GTK_CLASS_TYPE(class)		(G_TYPE_FROM_CLASS (class))
#define GTK_TYPE_IS_OBJECT(type)	(g_type_is_a ((type), GTK_TYPE_OBJECT))
Tim Janik's avatar
Tim Janik committed
68

69 70
/* outdated macros that really shouldn't e used anymore,
 * use the GLib type system instead
71
 */
72 73
#define	GTK_TYPE_FUNDAMENTAL_LAST        (G_TYPE_LAST_RESERVED_FUNDAMENTAL - 1)
#define	GTK_TYPE_FUNDAMENTAL_MAX         (G_TYPE_FUNDAMENTAL_MAX)
74 75 76 77

#define	GTK_FUNDAMENTAL_TYPE	G_TYPE_FUNDAMENTAL
#define GTK_STRUCT_OFFSET	G_STRUCT_OFFSET

78
#endif /* GTK_DISABLE_DEPRECATED */
79 80 81 82 83 84 85 86 87

/* glib macro wrappers (compatibility) */
#define	GTK_CHECK_CAST		G_TYPE_CHECK_INSTANCE_CAST
#define	GTK_CHECK_CLASS_CAST	G_TYPE_CHECK_CLASS_CAST
#define GTK_CHECK_GET_CLASS	G_TYPE_INSTANCE_GET_CLASS
#define	GTK_CHECK_TYPE		G_TYPE_CHECK_INSTANCE_TYPE
#define	GTK_CHECK_CLASS_TYPE	G_TYPE_CHECK_CLASS_TYPE

/* glib type wrappers (compatibility) */
88

89
typedef GType			GtkType;
90 91 92

#ifndef GTK_DISABLE_DEPRECATED

93 94 95 96
typedef GTypeInstance		GtkTypeObject;
typedef GTypeClass		GtkTypeClass;
typedef GBaseInitFunc		GtkClassInitFunc;
typedef GInstanceInitFunc	GtkObjectInitFunc;
97

98
#endif /* GTK_DISABLE_DEPRECATED */
99

100
G_END_DECLS
101

102 103
/* Builtin Types
 */
Elliot Lee's avatar
Elliot Lee committed
104 105
#include <gtk/gtktypebuiltins.h>

106
G_BEGIN_DECLS
107

108 109 110
/* urg */
#define GTK_TYPE_IDENTIFIER (gtk_identifier_get_type ())
GType gtk_identifier_get_type (void);
111

112 113 114
/* --- typedefs --- */
/* here we come with some necessary forward declarations for structures and
 * provide some fundamental function signatures
115
 */
116 117
typedef struct _GtkArg	       	     GtkArg;
typedef struct _GtkObject   	     GtkObject; /* object forward declaration */
118
typedef gboolean (*GtkFunction)	    (gpointer      data);
119 120 121 122 123
typedef void (*GtkDestroyNotify)    (gpointer      data);
typedef void (*GtkCallbackMarshal)  (GtkObject    *object,
				     gpointer      data,
				     guint         n_args,
				     GtkArg       *args);
124
typedef void (*GtkSignalFunc)       (void);
125 126
#define GTK_SIGNAL_FUNC(f)	    ((GtkSignalFunc) (f))

127 128 129
#ifndef GTK_DISABLE_DEPRECATED
typedef struct _GtkTypeInfo 	     GtkTypeInfo;
typedef GSignalCMarshaller          GtkSignalMarshaller;
130 131 132 133
#endif

#if !defined (GTK_DISABLE_DEPRECATED) || defined (GTK_COMPILATION)
/* Used by gtk_container_foreach_unmarshal () */
134 135

/* GtkArg, used to hold differently typed values */
Elliot Lee's avatar
Elliot Lee committed
136 137 138
struct _GtkArg
{
  GtkType type;
139
  gchar *name;
Tim Janik's avatar
Tim Janik committed
140 141 142 143 144 145 146
  
  /* this union only defines the required storage types for
   * the possibile values, thus there is no gint enum_data field,
   * because that would just be a mere alias for gint int_data.
   * use the GTK_VALUE_*() and GTK_RETLOC_*() macros to access
   * the discrete memebers.
   */
Elliot Lee's avatar
Elliot Lee committed
147
  union {
Tim Janik's avatar
Tim Janik committed
148
    /* flat values */
Elliot Lee's avatar
Elliot Lee committed
149
    gchar char_data;
Tim Janik's avatar
Tim Janik committed
150 151
    guchar uchar_data;
    gboolean bool_data;
Elliot Lee's avatar
Elliot Lee committed
152 153 154 155 156
    gint int_data;
    guint uint_data;
    glong long_data;
    gulong ulong_data;
    gfloat float_data;
157
    gdouble double_data;
158 159
    gchar *string_data;
    GtkObject *object_data;
160
    gpointer pointer_data;
Tim Janik's avatar
Tim Janik committed
161 162
    
    /* structured values */
Elliot Lee's avatar
Elliot Lee committed
163
    struct {
Tim Janik's avatar
Tim Janik committed
164 165 166
      GtkSignalFunc f;
      gpointer d;
    } signal_data;
Elliot Lee's avatar
Elliot Lee committed
167 168 169
  } d;
};

Tim Janik's avatar
Tim Janik committed
170 171
/* argument value access macros, these must not contain casts,
 * to allow the usage of these macros in combination with the
Kristian Rietveld's avatar
Kristian Rietveld committed
172
 * address operator, e.g. &GTK_VALUE_CHAR (*arg)
Tim Janik's avatar
Tim Janik committed
173
 */
174
#define GTK_VALUE_CHAR(a)	((a).d.char_data)
Tim Janik's avatar
Tim Janik committed
175
#define GTK_VALUE_UCHAR(a)	((a).d.uchar_data)
176 177 178 179 180 181 182
#define GTK_VALUE_BOOL(a)	((a).d.bool_data)
#define GTK_VALUE_INT(a)	((a).d.int_data)
#define GTK_VALUE_UINT(a)	((a).d.uint_data)
#define GTK_VALUE_LONG(a)	((a).d.long_data)
#define GTK_VALUE_ULONG(a)	((a).d.ulong_data)
#define GTK_VALUE_FLOAT(a)	((a).d.float_data)
#define GTK_VALUE_DOUBLE(a)	((a).d.double_data)
183
#define GTK_VALUE_STRING(a)	((a).d.string_data)
184
#define GTK_VALUE_ENUM(a)	((a).d.int_data)
Tim Janik's avatar
Tim Janik committed
185
#define GTK_VALUE_FLAGS(a)	((a).d.uint_data)
186
#define GTK_VALUE_BOXED(a)	((a).d.pointer_data)
Tim Janik's avatar
Tim Janik committed
187
#define GTK_VALUE_OBJECT(a)	((a).d.object_data)
188
#define GTK_VALUE_POINTER(a)	((a).d.pointer_data)
189
#define GTK_VALUE_SIGNAL(a)	((a).d.signal_data)
190
#endif /* !GTK_DISABLE_DEPRECATED || GTK_COMPILATION */
Tim Janik's avatar
Tim Janik committed
191

192
#ifndef GTK_DISABLE_DEPRECATED
193
/* return location macros, these all narrow down to
Tim Janik's avatar
Tim Janik committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
 * pointer types, because return values need to be
 * passed by reference
 */
#define GTK_RETLOC_CHAR(a)	((gchar*)	(a).d.pointer_data)
#define GTK_RETLOC_UCHAR(a)	((guchar*)	(a).d.pointer_data)
#define GTK_RETLOC_BOOL(a)	((gboolean*)	(a).d.pointer_data)
#define GTK_RETLOC_INT(a)	((gint*)	(a).d.pointer_data)
#define GTK_RETLOC_UINT(a)	((guint*)	(a).d.pointer_data)
#define GTK_RETLOC_LONG(a)	((glong*)	(a).d.pointer_data)
#define GTK_RETLOC_ULONG(a)	((gulong*)	(a).d.pointer_data)
#define GTK_RETLOC_FLOAT(a)	((gfloat*)	(a).d.pointer_data)
#define GTK_RETLOC_DOUBLE(a)	((gdouble*)	(a).d.pointer_data)
#define GTK_RETLOC_STRING(a)	((gchar**)	(a).d.pointer_data)
#define GTK_RETLOC_ENUM(a)	((gint*)	(a).d.pointer_data)
#define GTK_RETLOC_FLAGS(a)	((guint*)	(a).d.pointer_data)
#define GTK_RETLOC_BOXED(a)	((gpointer*)	(a).d.pointer_data)
#define GTK_RETLOC_OBJECT(a)	((GtkObject**)	(a).d.pointer_data)
211 212
#define GTK_RETLOC_POINTER(a)	((gpointer*)	(a).d.pointer_data)
/* GTK_RETLOC_SIGNAL() - no such thing */
Elliot Lee's avatar
Elliot Lee committed
213

214 215 216 217
/* type registration, it is recommended to use
 * g_type_register_static() or
 * g_type_register_dynamic() instead
 */
Elliot Lee's avatar
Elliot Lee committed
218 219
struct _GtkTypeInfo
{
220 221 222 223 224 225 226 227
  gchar			*type_name;
  guint			 object_size;
  guint			 class_size;
  GtkClassInitFunc	 class_init_func;
  GtkObjectInitFunc	 object_init_func;
  gpointer		 reserved_1;
  gpointer		 reserved_2;
  GtkClassInitFunc	 base_class_init_func;
Elliot Lee's avatar
Elliot Lee committed
228 229
};

230
#endif /* GTK_DISABLE_DEPRECATED */
231

232
gpointer	gtk_type_class	(GtkType	 type);
233

234 235 236 237 238
#ifndef GTK_DISABLE_DEPRECATED

GtkType		gtk_type_unique	(GtkType	   parent_type,
				 const GtkTypeInfo *gtkinfo);
gpointer	gtk_type_new	(GtkType	 type);
Tim Janik's avatar
Tim Janik committed
239

240
/* --- compatibility defines --- */
241 242 243 244
#define	gtk_type_name(type)		 g_type_name (type)
#define	gtk_type_from_name(name)	 g_type_from_name (name)
#define	gtk_type_parent(type)		 g_type_parent (type)
#define	gtk_type_is_a(type, is_a_type)	 g_type_is_a ((type), (is_a_type))
Elliot Lee's avatar
Elliot Lee committed
245

246 247 248 249 250
/* enum/flags compatibility functions, we strongly
 * recommend to use the glib enum/flags classes directly
 */
typedef GEnumValue  GtkEnumValue;
typedef GFlagsValue GtkFlagValue;
251 252 253 254
GtkEnumValue*	gtk_type_enum_get_values	(GtkType	 enum_type);
GtkFlagValue*	gtk_type_flags_get_values	(GtkType	 flags_type);
GtkEnumValue*	gtk_type_enum_find_value	(GtkType	 enum_type,
						 const gchar	*value_name);
255
GtkFlagValue*	gtk_type_flags_find_value	(GtkType	 flags_type,
256
						 const gchar	*value_name);
257

258
#endif /* GTK_DISABLE_DEPRECATED */
Elliot Lee's avatar
Elliot Lee committed
259

260 261 262 263 264
#if !defined (GTK_DISABLE_DEPRECATED) || defined (GTK_COMPILATION)
/* deprecated, use g_type_init() instead */
void		gtk_type_init	(GTypeDebugFlags debug_flags);
#endif /* !GTK_DISABLE_DEPRECATED || GTK_COMPILATION */

265
G_END_DECLS
Elliot Lee's avatar
Elliot Lee committed
266 267

#endif /* __GTK_TYPE_UTILS_H__ */