diff -rNpu libglademm/ChangeLog libglademm-derived/ChangeLog
--- ChangeLog	2005-03-10 13:43:30.000000000 +0100
+++ ChangeLog	2005-05-12 17:14:22.000000000 +0200
@@ -1,3 +1,9 @@
+2005-05-12  Marek Materzok <tilk@lucifer.czad.org>
+
+	* libglade/libglademm/derived.[cc|h]: Added Glade::DerivedBase and
+	Glade::Derived classes.
+	* examples/deriveddialog: Added an example for Glade::Derived.
+
 2005-03-10  Cedric Gustin <cedric.gustin@swing.be>
 
 	* MSVC_Net2003/Makefile.am: Add blank.cpp to EXTRA_DIST.
diff -rNpu libglademm/configure.in libglademm-derived/configure.in
--- configure.in	2005-05-12 17:18:26.000000000 +0200
+++ configure.in	2005-05-12 16:59:06.000000000 +0200
@@ -209,6 +209,7 @@ AC_OUTPUT([
 	examples/Makefile
 		examples/basic/Makefile
 		examples/derived/Makefile
+		examples/derivedclass/Makefile
                 examples/menus/Makefile
                 examples/variablesmap/Makefile
 
diff -rNpu libglademm/examples/derivedclass/derivedclass.cc libglademm-derived/examples/derivedclass/derivedclass.cc
--- examples/derivedclass/derivedclass.cc	1970-01-01 01:00:00.000000000 +0100
+++ examples/derivedclass/derivedclass.cc	2005-05-12 17:11:04.000000000 +0200
@@ -0,0 +1,70 @@
+//$Id$ -*- c++ -*-
+
+/* 
+ * Copyright (C) 2003 Christer Palm <palm@nogui.se>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <libglademm/derived.h>
+#include <iostream>
+
+//
+// A button that prints a message when clicked
+//
+class MessageButton : public Gnome::Glade::Derived<Gtk::Button>
+{
+	public:
+		MessageButton
+			(Glib::RefPtr<Gnome::Glade::Xml> xml,
+			 const std::string& widgetname,
+			 const std::string& message) :
+				Gnome::Glade::Derived<Gtk::Button>(xml, widgetname),
+				message_(message)
+			{ }
+
+	private:
+		const std::string message_;
+		void on_clicked()
+			{ std::cout << message_ << std::endl; }
+};
+
+
+//
+// A Dialog which contains a Hello world MessageButton
+//
+class HelloDialog : public Gnome::Glade::Derived<Gtk::Dialog>
+{
+	public:
+		HelloDialog() :
+			Gnome::Glade::Derived<Gtk::Dialog>
+				("derivedclass.glade", "exampleDialog"),
+			button(get_xml(), "button", "Hello world!")
+			{ }
+
+	private:
+		MessageButton button;
+		void on_response(int)
+			{ std::cout << "Goodbye!" << std::endl; }
+};
+
+
+int main(int argc, char *argv[])
+{
+	Gtk::Main gtkmain(argc, argv);
+	HelloDialog* example = new HelloDialog();
+	example->run();
+	return 0;
+}
diff -rNpu libglademm/examples/derivedclass/derivedclass.glade libglademm-derived/examples/derivedclass/derivedclass.glade
--- examples/derivedclass/derivedclass.glade	1970-01-01 01:00:00.000000000 +0100
+++ examples/derivedclass/derivedclass.glade	2005-05-12 16:41:27.000000000 +0200
@@ -0,0 +1,66 @@
+<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
+<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
+
+<glade-interface>
+
+<widget class="GtkDialog" id="exampleDialog">
+  <property name="visible">True</property>
+  <property name="title" translatable="yes">XmlWidget Example</property>
+  <property name="type">GTK_WINDOW_TOPLEVEL</property>
+  <property name="window_position">GTK_WIN_POS_NONE</property>
+  <property name="modal">False</property>
+  <property name="resizable">True</property>
+  <property name="destroy_with_parent">False</property>
+  <property name="has_separator">True</property>
+
+  <child internal-child="vbox">
+    <widget class="GtkVBox" id="dialog-vbox2">
+      <property name="visible">True</property>
+      <property name="homogeneous">False</property>
+      <property name="spacing">0</property>
+
+      <child internal-child="action_area">
+	<widget class="GtkHButtonBox" id="dialog-action_area2">
+	  <property name="visible">True</property>
+	  <property name="layout_style">GTK_BUTTONBOX_DEFAULT_STYLE</property>
+
+	  <child>
+	    <widget class="GtkButton" id="closebutton1">
+	      <property name="visible">True</property>
+	      <property name="can_default">True</property>
+	      <property name="can_focus">True</property>
+	      <property name="label">gtk-close</property>
+	      <property name="use_stock">True</property>
+	      <property name="relief">GTK_RELIEF_NORMAL</property>
+	      <property name="response_id">-7</property>
+	    </widget>
+	  </child>
+	</widget>
+	<packing>
+	  <property name="padding">0</property>
+	  <property name="expand">False</property>
+	  <property name="fill">True</property>
+	  <property name="pack_type">GTK_PACK_END</property>
+	</packing>
+      </child>
+
+      <child>
+	<widget class="GtkButton" id="button">
+	  <property name="border_width">24</property>
+	  <property name="visible">True</property>
+	  <property name="can_focus">True</property>
+	  <property name="label" translatable="yes">Click me</property>
+	  <property name="use_underline">True</property>
+	  <property name="relief">GTK_RELIEF_NORMAL</property>
+	</widget>
+	<packing>
+	  <property name="padding">0</property>
+	  <property name="expand">False</property>
+	  <property name="fill">False</property>
+	</packing>
+      </child>
+    </widget>
+  </child>
+</widget>
+
+</glade-interface>
diff -rNpu libglademm/examples/derivedclass/Makefile.am libglademm-derived/examples/derivedclass/Makefile.am
--- examples/derivedclass/Makefile.am	1970-01-01 01:00:00.000000000 +0100
+++ examples/derivedclass/Makefile.am	2005-05-12 17:05:11.000000000 +0200
@@ -0,0 +1,7 @@
+include $(top_srcdir)/examples/Makefile.am_fragment
+
+#Build the executable, but don't install it.
+noinst_PROGRAMS = derivedclass
+derivedclass_SOURCES = derivedclass.h derivedclass.cc
+EXTRA_DIST = derivedclass.glade
+
diff -rNpu libglademm/examples/Makefile.am libglademm-derived/examples/Makefile.am
--- examples/Makefile.am	2003-11-06 19:38:33.000000000 +0100
+++ examples/Makefile.am	2005-05-12 16:55:30.000000000 +0200
@@ -1,4 +1,4 @@
-SUBDIRS = basic derived variablesmap menus
+SUBDIRS = basic derived variablesmap menus derivedclass
 
 EXTRA_DIST	= README Makefile.am_fragment
 
diff -rNpu libglademm/libglade/libglademm/derived.cc libglademm-derived/libglade/libglademm/derived.cc
--- libglade/libglademm/derived.cc	1970-01-01 01:00:00.000000000 +0100
+++ libglade/libglademm/derived.cc	2005-05-12 17:04:41.000000000 +0200
@@ -0,0 +1,88 @@
+// -*- c++ -*-
+/* $Id$ */
+
+/* 
+ * Copyright (C) 2003 Christer Palm <palm@nogui.se>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+ 
+#include "derived.h"
+#include <glade/glade-xml.h>
+
+namespace Gnome {
+namespace Glade {
+
+/** DerivedBase constructors
+ */
+DerivedBase::DerivedBase(const std::string& filename,
+	const std::string& widgetname)
+{
+	try {
+		xml_ = Gnome::Glade::Xml::create(filename);
+	} catch (Gnome::Glade::XmlError&) {
+		throw;
+	}
+	baseWidget = glade_xml_get_widget(xml_->gobj(), widgetname.c_str());
+	if (!baseWidget) {
+		throw WidgetNotFoundError("Base widget \"" + widgetname +
+			"not found in glade file \"" +
+			xml_->get_filename() + "\".");
+	}
+}
+
+/**
+ */
+DerivedBase::DerivedBase(Glib::RefPtr<Gnome::Glade::Xml> xml,
+	const std::string& widgetname)
+{
+	xml_ = xml;
+	baseWidget = glade_xml_get_widget(xml->gobj(), widgetname.c_str());
+	if (!baseWidget) {
+		throw WidgetNotFoundError("Base widget \"" + widgetname +
+			"not found in glade file \"" + xml->get_filename() + "\".");
+	}
+}
+
+/** DerivedBase::get_widget()
+ */
+Gtk::Widget* DerivedBase::get_widget(const Glib::ustring& name)
+{
+	Gtk::Widget* widget = xml_->get_widget(name);
+	if (!widget) {
+		throw WidgetNotFoundError("Widget \"" + name +
+			"\" not found in glade file \"" +
+			xml_->gobj()->filename + "\".");
+	}
+	return widget;
+}
+
+/** DerivedBase::get_widget_checked()
+ */
+Gtk::Widget* DerivedBase::get_widget_checked(const Glib::ustring& name,
+	GType type)
+{
+	Gtk::Widget* widget = get_widget(name);
+	if (!g_type_is_a(G_OBJECT_TYPE(widget->gobj()), type)) {
+		throw WidgetCastError("Widget \"" + name + "\" (in glade file \"" +
+			xml_->gobj()->filename + "\") is of type " +
+			G_OBJECT_TYPE_NAME(widget->gobj()) + " but " +
+			g_type_name(type) + " was expected.");
+	}
+	return widget;
+}
+
+} // namespace Glade
+} // namespace Gnome
diff -rNpu libglademm/libglade/libglademm/derived.h libglademm-derived/libglade/libglademm/derived.h
--- libglade/libglademm/derived.h	1970-01-01 01:00:00.000000000 +0100
+++ libglade/libglademm/derived.h	2005-05-12 17:00:17.000000000 +0200
@@ -0,0 +1,125 @@
+// -*- c++ -*-
+#ifndef _LIBGLADEMM_DERIVED_H
+#define _LIBGLADEMM_DERIVED_H
+/* $Id$ */
+
+/* 
+ * Copyright (C) 2003 Christer Palm <palm@nogui.se>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <gtkmm.h>
+#include <libglademm/xml.h>
+
+namespace Gnome
+{
+namespace Glade
+{
+
+
+/** Thrown when a requested widget is not found in XML file
+ */
+class WidgetNotFoundError : public XmlError
+{
+public:
+	explicit WidgetNotFoundError(const Glib::ustring& message) :
+		XmlError(message)
+		{ }
+	virtual ~WidgetNotFoundError() throw()
+		{ }
+};
+
+
+/** Thrown when an invalid cast is attempted
+ */
+class WidgetCastError : public XmlError
+{
+public:
+	explicit WidgetCastError(const Glib::ustring& message) :
+		XmlError(message)
+		{ }
+	virtual ~WidgetCastError() throw()
+		{ }
+};
+
+
+/** Base class for Derived widget
+ */
+class DerivedBase
+{
+private:
+	Glib::RefPtr<Gnome::Glade::Xml> xml_;
+	GtkWidget* baseWidget;
+
+protected:
+	DerivedBase(Glib::RefPtr<Gnome::Glade::Xml> xml,
+		const std::string& widgetname);
+	DerivedBase(const std::string& filename, const std::string& widgetname);
+
+	inline GtkWidget* get_base_widget()
+		{ return baseWidget; }
+
+private:
+	Gtk::Widget* get_widget_checked(const Glib::ustring& name, GType type);
+
+public:
+	/** Returns a Glib::RefPtr to the libglademm Xml object to which this
+	 *  widget belongs
+     */
+	Glib::RefPtr<Gnome::Glade::Xml> get_xml()
+		{ return xml_; }
+
+	/** Looks up the widget @a
+	 */
+	Gtk::Widget* get_widget(const Glib::ustring& name);
+
+	/**
+	 */
+	template <class T_Widget>
+	inline T_Widget* get_widget(const Glib::ustring& name, T_Widget*& widget)
+	{
+		widget = dynamic_cast<T_Widget*>
+			(get_widget_checked(name, T_Widget::get_base_type()));
+		if (!widget) {
+			throw WidgetCastError("dynamic_cast<> failed.");
+		}
+		return widget;
+	}
+};
+
+/** Convenience template for creating derived libGlade widgets
+ */
+template<class T_widget>
+class Derived : public DerivedBase, public T_widget
+{
+public:
+	Derived(const std::string& filename, const std::string& widgetname) :
+		DerivedBase(filename, widgetname),
+		T_widget((typename T_widget::BaseObjectType*)
+			DerivedBase::get_base_widget())
+		{ }
+
+	Derived(Glib::RefPtr<Gnome::Glade::Xml> xml, const std::string& widgetname) :
+		DerivedBase(xml, widgetname),
+		T_widget((typename T_widget::BaseObjectType*)
+			DerivedBase::get_base_widget())
+		{ }
+};
+
+} // namespace Glade
+} // namespace Gnome
+
+#endif // _LIBGLADEMM_DERIVED_H
diff -rNpu libglademm/libglade/libglademm/Makefile.am libglademm-derived/libglade/libglademm/Makefile.am
--- libglade/libglademm/Makefile.am	2004-04-12 13:37:01.000000000 +0200
+++ libglade/libglademm/Makefile.am	2005-05-12 16:59:33.000000000 +0200
@@ -10,8 +10,8 @@ sublib_namespace	= Glade
 sublib_cflags		= $(LIBGLADEMM_CFLAGS)
 sublib_topdir = libglade
 
-files_extra_h		=  init.h variablesmap.h
-files_extra_cc		=  init.cc variablesmap.cc
+files_extra_h		=  init.h variablesmap.h derived.h
+files_extra_cc		=  init.cc variablesmap.cc derived.cc
 
 include $(top_srcdir)/build_shared/Makefile_build_gensrc.am_fragment
 
