2 /* $Id: interface.cc 209 2005-03-07 15:42:20Z murrayc $ */
4 /* Copyright (C) 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/interface.h>
22 #include <glibmm/private/interface_p.h>
28 /**** Glib::Interface_Class ************************************************/
30 void Interface_Class::add_interface(GType instance_type) const
32 //This check is distabled, because it checks whether any of the types's bases implement the interface, not just the specific type.
33 //if( !g_type_is_a(instance_type, gtype_) ) //For convenience, don't complain about calling this twice.
35 const GInterfaceInfo interface_info =
38 0, // interface_finalize
42 g_type_add_interface_static(instance_type, gtype_, &interface_info);
47 /**** Interface Glib::Interface ********************************************/
49 Interface::Interface(const Interface_Class& interface_class)
51 //gobject_ will be set in the Object constructor.
52 //Any instantiable class that derives from Interface should also inherit from Object.
54 // If I understand it correctly, gobject_ shouldn't be 0 now. daniel.
55 // TODO: Make this a g_assert() if the assumption above is correct.
57 g_return_if_fail(gobject_ != 0);
59 if(custom_type_name_ && !is_anonymous_custom_())
61 void *const instance_class = G_OBJECT_GET_CLASS(gobject_);
63 if(!g_type_interface_peek(instance_class, interface_class.get_type()))
65 interface_class.add_interface(G_OBJECT_CLASS_TYPE(instance_class));
70 Interface::Interface(GObject* castitem)
72 // Connect GObject and wrapper instances.
73 ObjectBase::initialize(castitem);
76 Interface::~Interface()
79 GType Interface::get_type()
81 return G_TYPE_INTERFACE;
84 GType Interface::get_base_type()
86 return G_TYPE_INTERFACE;
89 RefPtr<ObjectBase> wrap_interface(GObject* object, bool take_copy)
91 return Glib::RefPtr<ObjectBase>( wrap_auto(object, take_copy) );