1 // Generated by gtkmmproc -- DO NOT MODIFY!
3 #include <libglademm/xml.h>
4 #include <libglademm/private/xml_p.h>
8 /* Copyright (C) 2002 The libglademm Development Team
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the Free
22 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <glade/glade-xml.h>
26 #include <gtkmm/button.h>
27 #include <gtkmm/menuitem.h>
35 XmlError::XmlError(const Glib::ustring& message)
40 XmlError::~XmlError() throw()
43 XmlError::XmlError(const XmlError& other)
45 Glib::Exception (other),
46 message_ (other.message_)
49 XmlError& XmlError::operator=(const XmlError& other)
51 message_ = other.message_;
55 Glib::ustring XmlError::what() const
61 Xml::Xml(const std::string& filename, const Glib::ustring& root, const Glib::ustring& domain)
63 Glib::ObjectBase(0), //Mark this class as gtkmmproc-generated, rather than a custom class, to allow vfunc optimisations.
64 Glib::Object(Glib::ConstructParams(xml_class_.init(), (char*) 0))
66 if(!glade_xml_construct(gobj(), filename.c_str(), root.empty() ? 0 : root.c_str(),
67 domain.empty() ? 0 : domain.c_str()))
69 throw XmlError("Failed to load glade file `" + Glib::filename_to_utf8(filename) + '\'');
73 // TODO: we need glade_xml_construct_from_buffer()
74 Xml::Xml(const char* buffer, int size, const Glib::ustring& root, const Glib::ustring& domain)
77 Glib::Object((GObject*) glade_xml_new_from_buffer(
78 buffer, size, root.empty() ? 0 : root.c_str(), domain.empty() ? 0 : domain.c_str()))
81 throw XmlError("Failed to read glade input buffer");
85 Glib::RefPtr<Xml> Xml::create(const std::string& filename,
86 const Glib::ustring& root, const Glib::ustring& domain)
88 return Glib::RefPtr<Xml>(new Xml(filename, root, domain));
92 Glib::RefPtr<Xml> Xml::create_from_buffer(const char* buffer, int size,
93 const Glib::ustring& root, const Glib::ustring& domain)
95 return Glib::RefPtr<Xml>(new Xml(buffer, size, root, domain));
98 void Xml::reparent_widget(const Glib::ustring& name, Gtk::Container& container)
100 Gtk::Widget* pWidget = 0;
101 get_widget(name, pWidget);
103 g_return_if_fail(pWidget != 0);
105 pWidget->reparent(container);
108 Gtk::Widget* Xml::get_widget_checked(const Glib::ustring& name, GType type)
110 // Get the widget from the glade file.
111 Gtk::Widget *const pWidget = get_widget(name);
115 g_critical("widget `%s' not found in glade file `%s'", name.c_str(), gobj()->filename);
119 // Check if it has the correct type.
120 if(!g_type_is_a(G_OBJECT_TYPE(pWidget->gobj()), type))
122 g_critical("widget `%s' (in glade file `%s') is of type `%s' but `%s' was expected",
123 name.c_str(), gobj()->filename, G_OBJECT_TYPE_NAME(pWidget->gobj()), g_type_name(type));
130 GtkWidget* Xml::get_cwidget(const Glib::ustring& name)
132 GtkWidget* pCWidget = glade_xml_get_widget(gobj(), name.c_str());
134 g_critical("Glade::Xml::get_cwidget(): glade_xml_get_widget() failed.");
139 // Custom coded so that we can custom-code the vfunc in the Xml class.
140 // This is marginally better than modifying gtkmmproc to allow this.
142 GType Xml_Class::lookup_type_vfunc_callback(GladeXML* self, const char* classname)
144 CppObjectType *const obj = dynamic_cast<CppObjectType*>(
145 Glib::ObjectBase::_get_current_wrapper((GObject*) self));
151 return obj->lookup_type_vfunc(Glib::convert_const_gchar_ptr_to_ustring(classname));
155 Glib::exception_handlers_invoke();
160 BaseClassType *const base = static_cast<BaseClassType*>(
161 g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class.
164 if(base && base->lookup_type)
165 return (*base->lookup_type)(self, classname);
171 GType Xml::lookup_type_vfunc(const Glib::ustring& classname)
173 // See if there is a gtkmm version of the gclass:
174 Glib::ustring classname_prefixed ("gtkmm__"); // gtkmm uses a prefix
175 classname_prefixed += classname;
177 GType gtype = g_type_from_name(classname_prefixed.c_str());
179 if(gtype == G_TYPE_INVALID) // if it's not a registered typename
181 // There's no gtkmm derived type, so just use the normal one.
182 gtype = g_type_from_name(classname.c_str());
188 void Xml::connect_clicked(const Glib::ustring& widget_name, const sigc::slot<void>& slot_ )
190 Gtk::Widget* pWidget = 0;
191 get_widget(widget_name, pWidget);
193 Gtk::Button* pButton = dynamic_cast<Gtk::Button*>(pWidget);
194 Gtk::MenuItem* pMenuItem = dynamic_cast<Gtk::MenuItem*>(pWidget);
197 pButton->signal_clicked().connect( slot_);
200 pMenuItem->signal_activate().connect( slot_ );
209 } // anonymous namespace
215 Glib::RefPtr<Gnome::Glade::Xml> wrap(GladeXML* object, bool take_copy)
217 return Glib::RefPtr<Gnome::Glade::Xml>( dynamic_cast<Gnome::Glade::Xml*> (Glib::wrap_auto ((GObject*)(object), take_copy)) );
218 //We use dynamic_cast<> in case of multiple inheritance.
221 } /* namespace Glib */
231 /* The *_Class implementation: */
233 const Glib::Class& Xml_Class::init()
235 if(!gtype_) // create the GType if necessary
237 // Glib::Class has to know the class init function to clone custom types.
238 class_init_func_ = &Xml_Class::class_init_function;
240 // This is actually just optimized away, apparently with no harm.
241 // Make sure that the parent type has been created.
242 //CppClassParent::CppObjectType::get_type();
244 // Create the wrapper type, with the same class/instance size as the base type.
245 register_derived_type(glade_xml_get_type());
247 // Add derived versions of interfaces, if the C type implements any interfaces:
253 void Xml_Class::class_init_function(void* g_class, void* class_data)
255 BaseClassType *const klass = static_cast<BaseClassType*>(g_class);
256 CppClassParent::class_init_function(klass, class_data);
258 klass->lookup_type = &lookup_type_vfunc_callback;
262 Glib::ObjectBase* Xml_Class::wrap_new(GObject* object)
264 return new Xml((GladeXML*)object);
268 /* The implementation: */
270 GladeXML* Xml::gobj_copy()
276 Xml::Xml(const Glib::ConstructParams& construct_params)
278 Glib::Object(construct_params)
281 Xml::Xml(GladeXML* castitem)
283 Glib::Object((GObject*)(castitem))
290 Xml::CppClassType Xml::xml_class_; // initialize static member
292 GType Xml::get_type()
294 return xml_class_.init().get_type();
297 GType Xml::get_base_type()
299 return glade_xml_get_type();
303 std::string Xml::get_filename() const
305 return Glib::convert_const_gchar_ptr_to_stdstring(gobj()->filename);
308 Gtk::Widget* Xml::get_widget(const Glib::ustring& name)
310 return Glib::wrap(glade_xml_get_widget(gobj(), name.c_str()));
313 Glib::ListHandle<Gtk::Widget*> Xml::get_widget_prefix(const Glib::ustring& name)
315 return Glib::ListHandle<Gtk::Widget*>(glade_xml_get_widget_prefix(gobj(), name.c_str()), Glib::OWNERSHIP_SHALLOW);
318 std::string Xml::relative_file(const std::string& filename) const
320 return Glib::convert_return_gchar_ptr_to_stdstring(glade_xml_relative_file(const_cast<GladeXML*>(gobj()), filename.c_str()));
323 Glib::ustring Xml::get_widget_name(Gtk::Widget& widget)
325 return Glib::convert_const_gchar_ptr_to_ustring(glade_get_widget_name((widget).gobj()));
328 Glib::RefPtr<Xml> Xml::get_widget_tree(Gtk::Widget& widget)
331 Glib::RefPtr<Xml> retvalue = Glib::wrap(glade_get_widget_tree((widget).gobj()));
334 retvalue->reference(); //The function does not do a ref for us.