2 /* $Id: class.cc 336 2006-10-04 12:06:14Z murrayc $ */
4 /* Copyright (C) 1998-2002 The gtkmm Development Team
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <glibmm/class.h>
22 #include <glibmm/property.h>
23 #include <glibmm/ustring.h>
24 #include <glibmm/utility.h>
30 void Class::register_derived_type(GType base_type)
33 return; // already initialized
35 GTypeQuery base_query = { 0, 0, 0, 0, };
36 g_type_query(base_type, &base_query);
38 const GTypeInfo derived_info =
40 base_query.class_size,
46 base_query.instance_size,
52 Glib::ustring derived_name = "gtkmm__";
53 derived_name += base_query.type_name;
55 gtype_ = g_type_register_static(base_type, derived_name.c_str(), &derived_info, GTypeFlags(0));
58 GType Class::clone_custom_type(const char* custom_type_name) const
60 std::string full_name ("gtkmm__CustomObject_");
61 Glib::append_canonical_typename(full_name, custom_type_name);
63 GType custom_type = g_type_from_name(full_name.c_str());
67 g_return_val_if_fail(gtype_ != 0, 0);
69 // Cloned custom types derive from the wrapper's parent type,
70 // so that g_type_class_peek_parent() works correctly.
71 const GType base_type = g_type_parent(gtype_);
73 GTypeQuery base_query = { 0, 0, 0, 0, };
74 g_type_query(base_type, &base_query);
76 const GTypeInfo derived_info =
78 base_query.class_size,
81 &Class::custom_class_init_function,
84 base_query.instance_size,
90 custom_type = g_type_register_static(
91 base_type, full_name.c_str(), &derived_info, GTypeFlags(0));
98 void Class::custom_class_init_function(void* g_class, void* class_data)
100 // The class_data pointer is set to 'this' by clone_custom_type().
101 const Class *const self = static_cast<Class*>(class_data);
103 g_return_if_fail(self->class_init_func_ != 0);
105 // Call the wrapper's class_init_function() to redirect
106 // the vfunc and default signal handler callbacks.
107 (*self->class_init_func_)(g_class, 0);
109 #ifdef GLIBMM_PROPERTIES_ENABLED
110 GObjectClass *const gobject_class = static_cast<GObjectClass*>(g_class);
111 gobject_class->get_property = &Glib::custom_get_property_callback;
112 gobject_class->set_property = &Glib::custom_set_property_callback;
113 #endif //GLIBMM_PROPERTIES_ENABLED