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 #include <string.h> /* strcmp */
29 #include "gtktypeutils.h"
30 #include "gtkobject.h"
33 /* --- functions --- */
35 gtk_type_unique (GtkType parent_type,
36 const GtkTypeInfo *gtkinfo)
38 GTypeInfo tinfo = { 0, };
40 g_return_val_if_fail (GTK_TYPE_IS_OBJECT (parent_type), 0);
41 g_return_val_if_fail (gtkinfo != NULL, 0);
42 g_return_val_if_fail (gtkinfo->type_name != NULL, 0);
43 g_return_val_if_fail (g_type_from_name (gtkinfo->type_name) == 0, 0);
45 tinfo.class_size = gtkinfo->class_size;
46 tinfo.base_init = gtkinfo->base_class_init_func;
47 tinfo.base_finalize = NULL;
48 tinfo.class_init = (GClassInitFunc) gtkinfo->class_init_func;
49 tinfo.class_finalize = NULL;
50 tinfo.class_data = NULL;
51 tinfo.instance_size = gtkinfo->object_size;
52 tinfo.n_preallocs = 0;
53 tinfo.instance_init = gtkinfo->object_init_func;
55 return g_type_register_static (parent_type, gtkinfo->type_name, &tinfo, 0);
59 gtk_type_class (GtkType type)
61 static GQuark quark_static_class = 0;
64 if (!G_TYPE_IS_ENUM (type) && !G_TYPE_IS_FLAGS (type))
65 g_return_val_if_fail (G_TYPE_IS_OBJECT (type), NULL);
67 /* ok, this is a bit ugly, GLib reference counts classes,
68 * and gtk_type_class() used to always return static classes.
69 * while we coud be faster with just peeking the glib class
70 * for the normal code path, we can't be sure that that
71 * class stays around (someone else might be holding the
72 * reference count and is going to drop it later). so to
73 * ensure that Gtk actually holds a static reference count
74 * on the class, we use GType qdata to store referenced
75 * classes, and only return those.
78 class = g_type_get_qdata (type, quark_static_class);
81 if (!quark_static_class)
82 quark_static_class = g_quark_from_static_string ("GtkStaticTypeClass");
84 class = g_type_class_ref (type);
85 g_assert (class != NULL);
86 g_type_set_qdata (type, quark_static_class, class);
93 gtk_type_new (GtkType type)
97 g_return_val_if_fail (GTK_TYPE_IS_OBJECT (type), NULL);
99 object = g_object_new (type, NULL);
104 /* includes for various places
105 * with enum definitions
107 #define GTK_ENABLE_BROKEN
108 #include "makeenums.h"
109 /* type variable declarations
111 #include "gtktypebuiltins_vars.c"
112 GType GTK_TYPE_IDENTIFIER = 0;
113 #include "gtktypebuiltins_evals.c" /* enum value definition arrays */
115 /* Hack to communicate with GLib object debugging for now
118 #define IMPORT __declspec(dllimport)
123 #include <gtk.h> /* for gtktypebuiltins_ids.c */
124 #include <gdk.h> /* gtktypebuiltins_ids.c */
127 gtk_type_init (GTypeDebugFlags debug_flags)
129 static gboolean initialized = FALSE;
137 gconstpointer pointer1;
139 } builtin_info[GTK_TYPE_N_BUILTINS + 1] = {
140 #include "gtktypebuiltins_ids.c" /* type entries */
143 GTypeInfo tinfo = { 0, };
148 /* initialize GLib type system
150 g_type_init_with_debug_flags (debug_flags);
154 gtk_object_get_type ();
156 /* GTK_TYPE_IDENTIFIER
158 GTK_TYPE_IDENTIFIER = g_type_register_static (G_TYPE_STRING, "GtkIdentifier", &tinfo, 0);
162 for (i = 0; i < GTK_TYPE_N_BUILTINS; i++)
166 if (builtin_info[i].parent == G_TYPE_ENUM)
167 type_id = g_enum_register_static (builtin_info[i].type_name, builtin_info[i].pointer1);
168 else if (builtin_info[i].parent == G_TYPE_FLAGS)
169 type_id = g_flags_register_static (builtin_info[i].type_name, builtin_info[i].pointer1);
170 else if (builtin_info[i].parent == GTK_TYPE_BOXED)
172 if (builtin_info[i].pointer1 && builtin_info[i].pointer2)
173 type_id = g_boxed_type_register_static (builtin_info[i].type_name,
174 builtin_info[i].pointer1,
175 builtin_info[i].pointer2);
177 type_id = g_type_register_static (GTK_TYPE_BOXED, builtin_info[i].type_name, &tinfo, 0);
180 g_assert_not_reached ();
182 *builtin_info[i].type_id = type_id;
188 gtk_type_enum_get_values (GtkType enum_type)
192 g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
194 class = gtk_type_class (enum_type);
196 return class->values;
200 gtk_type_flags_get_values (GtkType flags_type)
204 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), NULL);
206 class = gtk_type_class (flags_type);
208 return class->values;
212 gtk_type_enum_find_value (GtkType enum_type,
213 const gchar *value_name)
218 g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
219 g_return_val_if_fail (value_name != NULL, NULL);
221 class = gtk_type_class (enum_type);
222 value = g_enum_get_value_by_name (class, value_name);
224 value = g_enum_get_value_by_nick (class, value_name);
230 gtk_type_flags_find_value (GtkType flags_type,
231 const gchar *value_name)
236 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), NULL);
237 g_return_val_if_fail (value_name != NULL, NULL);
239 class = gtk_type_class (flags_type);
240 value = g_flags_get_value_by_name (class, value_name);
242 value = g_flags_get_value_by_nick (class, value_name);