Index: src/glade-widget-class.c
===================================================================
RCS file: /cvs/gnome/glade3/src/glade-widget-class.c,v
retrieving revision 1.114
diff -u -p -r1.114 glade-widget-class.c
--- src/glade-widget-class.c	22 Aug 2006 20:46:30 -0000	1.114
+++ src/glade-widget-class.c	24 Aug 2006 18:32:18 -0000
@@ -1040,6 +1040,30 @@ glade_widget_class_merge (GladeWidgetCla
 		(&widget_class->children, parent_class->children, widget_class);
 }
 
+static GType
+generate_type (const char *name, 
+	       const char *parent_name)
+{
+	GType parent_type;
+	GTypeQuery query;
+	GTypeInfo *type_info;
+
+	g_return_val_if_fail (name != NULL, 0);
+	g_return_val_if_fail (parent_name != NULL, 0);
+
+	parent_type = glade_util_get_type_from_name (parent_name);
+	g_return_val_if_fail (parent_type != 0, 0);
+	
+	g_type_query (parent_type, &query);
+	g_return_val_if_fail (query.type != 0, 0);
+
+	type_info = g_new0 (GTypeInfo, 1);
+	type_info->class_size = query.class_size;
+	type_info->instance_size = query.instance_size;
+	
+	return g_type_register_static (parent_type, name, type_info, 0);
+}
+
 /**
  * glade_widget_class_new:
  * @class_node: A #GladeXmlNode
@@ -1061,6 +1085,7 @@ glade_widget_class_new (GladeXmlNode *cl
 {
 	GladeWidgetClass *widget_class;
 	gchar            *name, *generic_name, *ptr;
+	gchar		 *parent_name;
 	gchar            *title;
 	GModule          *module;
 	GType             parent_type;
@@ -1084,6 +1109,20 @@ glade_widget_class_new (GladeXmlNode *cl
 		return NULL;
 	}
 
+	parent_name = glade_xml_get_property_string (class_node, GLADE_TAG_PARENT_NAME);
+
+	if (parent_name != NULL)
+	{
+		if (glade_widget_class_get_by_name (parent_name) == NULL)
+		{
+			g_warning ("Parent class '%s' for class '%s' is not defined", 
+				   parent_name, name);
+			g_free (parent_name);
+			g_free (name);
+			return NULL;
+		}
+	}
+
 	/* Perform a stupid fallback as generic_name is not required
 	 * for uninstantiatable classes
 	 */
@@ -1115,6 +1154,7 @@ glade_widget_class_new (GladeXmlNode *cl
 			g_warning ("Failed to load external library '%s'",
 				   library);
 			g_free (name);
+			g_free (parent_name);
 			g_free (generic_name);
 			g_free (title);
 			return NULL;
@@ -1126,11 +1166,22 @@ glade_widget_class_new (GladeXmlNode *cl
 	widget_class->module       = module;
 	widget_class->generic_name = generic_name;
 	widget_class->palette_name = title;
-	widget_class->type         = glade_util_get_type_from_name (name);
 	widget_class->cursor       = NULL;
 	widget_class->large_icon   = NULL;
 	widget_class->small_icon   = NULL;
 	widget_class->toplevel     = FALSE;
+	
+	if (parent_name)
+		widget_class->type = generate_type (name, parent_name);
+	else
+		widget_class->type = glade_util_get_type_from_name (name);
+
+	if (widget_class->type == 0)
+	{
+		glade_widget_class_free (widget_class);
+		g_free (parent_name);
+		return NULL;
+	}
 
 	if (G_TYPE_IS_INSTANTIATABLE (widget_class->type)    &&
 	    G_TYPE_IS_ABSTRACT (widget_class->type) == FALSE &&
@@ -1152,12 +1203,6 @@ glade_widget_class_new (GladeXmlNode *cl
 	if (book)
 		widget_class->book = g_strdup (book);
 
-	if (widget_class->type == 0)
-	{
-		glade_widget_class_free (widget_class);
-		return NULL;
-	}
-
 	widget_class->properties = glade_widget_class_list_properties (widget_class);
 	widget_class->signals    = glade_widget_class_list_signals (widget_class);
 	widget_class->children   = glade_widget_class_list_children (widget_class);
@@ -1165,21 +1210,26 @@ glade_widget_class_new (GladeXmlNode *cl
 	glade_widget_class_load_icons (widget_class);
 	glade_widget_class_create_cursor (widget_class);
 
-	for (parent_type = g_type_parent (widget_class->type);
-	     parent_type != 0;
-	     parent_type = g_type_parent (parent_type))
+	if (parent_name != NULL)
+		parent_type = glade_util_get_type_from_name (parent_name);
+	else
+		parent_type = g_type_parent (widget_class->type);
+
+	while (parent_type != 0)
 	{
-		const gchar      *parent_name;
-		GladeWidgetClass *parent_class;
+		const gchar      *class_name;
+		GladeWidgetClass *klass;
 
-		parent_name  = g_type_name (parent_type);
-		parent_class = glade_widget_class_get_by_name (parent_name);
+		class_name = g_type_name (parent_type);
+		klass = glade_widget_class_get_by_name (class_name);
 
-		if (parent_class) {
-			glade_widget_class_merge (widget_class, parent_class);
+		if (klass) {
+			glade_widget_class_merge (widget_class, klass);
 		}
+
+		parent_type = g_type_parent (parent_type);
 	}
-	
+
 	glade_widget_class_extend_with_node (widget_class, class_node, domain);
 	
 	/* store the GladeWidgetClass on the cache,
@@ -1190,6 +1240,7 @@ glade_widget_class_new (GladeXmlNode *cl
 		widget_classes = g_hash_table_new (g_str_hash, g_str_equal);		
 	g_hash_table_insert (widget_classes, widget_class->name, widget_class);
 	
+	g_free (parent_name);
 	return widget_class;
 }
 
Index: src/glade.h
===================================================================
RCS file: /cvs/gnome/glade3/src/glade.h,v
retrieving revision 1.73
diff -u -p -r1.73 glade.h
--- src/glade.h	16 Aug 2006 20:35:53 -0000	1.73
+++ src/glade.h	24 Aug 2006 18:32:19 -0000
@@ -113,6 +113,7 @@ typedef enum   _GladeItemAppearance Glad
 #define GLADE_TAG_VISIBLE                         "visible"
 #define GLADE_TAG_EXPANDED                        "expanded"
 #define GLADE_TAG_GENERIC_NAME                    "generic-name"
+#define GLADE_TAG_PARENT_NAME                     "parent"
 #define GLADE_TAG_NAME                            "name"
 #define GLADE_TAG_TITLE                           "title"
 #define GLADE_TAG_ID                              "id"
