[gtk+/composite-templates] Cleaned up template API, we only provided a function to set a resource as a template



commit bc068a006ac6c605f582d45ae166fcf975a4dc00
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date:   Sun Jul 29 12:25:16 2012 -0300

    Cleaned up template API, we only provided a function to set a resource as a template

 gtk/gtkcontainer.c     |   43 ++++++++++++-------------------------------
 gtk/gtkcontainer.h     |   24 ++++++++----------------
 gtk/gtkdialog.c        |    5 ++---
 gtk/gtkmessagedialog.c |    5 ++---
 4 files changed, 24 insertions(+), 53 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 7ef0f83..5cf7789 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -249,7 +249,6 @@ struct _GtkContainerClassPrivate
   GSList *tmpl_classes;
 
   const gchar *tmpl;
-  GtkContainerTemplateType tmpl_type;
   GtkBuilderConnectFunc connect_func;
   GList *internal_children; /* InternalChildData list */
 };
@@ -1391,13 +1390,12 @@ gtk_container_class_list_child_properties (GObjectClass *cclass,
 }
 
 /**
- * gtk_container_class_set_template:
+ * gtk_container_class_set_template_from_resource:
  * @container_class: a #GtkContainerClass
- * @tmpl: the #GtkBuilder xml fragment used to build children
- * @type: the type of @tmpl
+ * @resource_path: the #GtkBuilder xml resource path
  *
  * This is used when implementing new composite widget types
- * to setup a UI template for instances of this type.
+ * to specify a UI template for instances of this type.
  *
  * Templates are in the <link linkend="BUILDER-UI">GtkBuilder UI description</link>
  * format and are used to implement composite widget types in
@@ -1406,30 +1404,25 @@ gtk_container_class_list_child_properties (GObjectClass *cclass,
  * Instances with an assigned template will have thier children
  * built at object construct time.
  *
- * The provided xml fragment is expected to start with <child>
- * instead of <object> and will be parsed with a fresh instance
- * of the implementing composite widget type in context as the 
- * parent container. The composite instance itself will be exposed
- * to the GtkBuilder as an external object named "this" and in this way can
- * be referred to in child signal and property declarations.
+ * The provided xml is expected to have a <template> tag instead of <object> 
+ * with id="this" and an extra 'parent' property specifying from with type 
+ * the new class derives from.
  * 
  * Since: 3.0
  */
 void
-gtk_container_class_set_template (GtkContainerClass *container_class,
-				  const gchar       *tmpl,
-                                  GtkContainerTemplateType type)
+gtk_container_class_set_template_from_resource (GtkContainerClass *container_class,
+                                                const gchar       *resource_path)
 {
   GtkContainerClassPrivate *priv;
   GObjectClass  *oclass;
   
   g_return_if_fail (GTK_IS_CONTAINER_CLASS(container_class));
-  g_return_if_fail (tmpl && tmpl[0]);
+  g_return_if_fail (resource_path && resource_path[0]);
 
   priv = container_class->priv;
 
-  priv->tmpl = tmpl;
-  priv->tmpl_type = type;
+  priv->tmpl = resource_path;
 
   /* Collect an ordered list of class which have templates to build */
   for (oclass = G_OBJECT_CLASS (container_class);
@@ -1627,23 +1620,11 @@ gtk_container_constructor (GType                  type,
     {
       GtkContainerClassPrivate *cpriv = GTK_CONTAINER_CLASS (l->data)->priv;
       GList *children;
-      guint ret = 0;
+      guint ret;
         
       builder = gtk_builder_new ();
       gtk_builder_expose_object (builder, "this", object);
-
-      switch (cpriv->tmpl_type)
-        {
-          case GTK_CONTAINER_TEMPLATE_STRING:
-            ret = gtk_builder_add_to_parent_from_string (builder, object, cpriv->tmpl, -1, &error);
-          break;
-          case GTK_CONTAINER_TEMPLATE_FILE:
-            ret = gtk_builder_add_to_parent_from_file (builder, object, cpriv->tmpl, &error);
-          break;
-          case GTK_CONTAINER_TEMPLATE_RESOURCE:
-            ret = gtk_builder_add_to_parent_from_resource (builder, object, cpriv->tmpl, &error);
-          break;
-        }
+      ret = gtk_builder_add_to_parent_from_resource (builder, object, cpriv->tmpl, &error);
 
       if (ret)
         {
diff --git a/gtk/gtkcontainer.h b/gtk/gtkcontainer.h
index 5ef3828..a0164a0 100644
--- a/gtk/gtkcontainer.h
+++ b/gtk/gtkcontainer.h
@@ -49,13 +49,6 @@ typedef struct _GtkContainerPrivate       GtkContainerPrivate;
 typedef struct _GtkContainerClass         GtkContainerClass;
 typedef struct _GtkContainerClassPrivate  GtkContainerClassPrivate;
 
-typedef enum
-{
-  GTK_CONTAINER_TEMPLATE_STRING = 0,
-  GTK_CONTAINER_TEMPLATE_FILE,
-  GTK_CONTAINER_TEMPLATE_RESOURCE
-} GtkContainerTemplateType;
-
 struct _GtkContainer
 {
   GtkWidget widget;
@@ -229,15 +222,14 @@ void    gtk_container_forall		     (GtkContainer *container,
 void    gtk_container_class_handle_border_width (GtkContainerClass *klass);
 
 /* Class-level functions */
-void     gtk_container_class_set_template        (GtkContainerClass *container_class,
-						  const gchar       *tmpl,
-                                                  GtkContainerTemplateType type);
-void     gtk_container_class_set_connect_func    (GtkContainerClass *container_class,
-						  GtkBuilderConnectFunc connect_func);
-void     gtk_container_class_declare_internal_child (GtkContainerClass *container_class,
-                                                     gboolean use_private,
-                                                     guint struct_offset,
-                                                     const gchar *name);
+void    gtk_container_class_set_template_from_resource (GtkContainerClass *container_class,
+                                                         const gchar       *resource_path);
+void    gtk_container_class_set_connect_func           (GtkContainerClass *container_class,
+                                                        GtkBuilderConnectFunc connect_func);
+void    gtk_container_class_declare_internal_child     (GtkContainerClass *container_class,
+                                                        gboolean use_private,
+                                                        guint struct_offset,
+                                                        const gchar *name);
 /* Non-public methods */
 void	_gtk_container_queue_resize	     (GtkContainer *container);
 void    _gtk_container_clear_resize_widgets   (GtkContainer *container);
diff --git a/gtk/gtkdialog.c b/gtk/gtkdialog.c
index 3e1775c..ecb87d5 100644
--- a/gtk/gtkdialog.c
+++ b/gtk/gtkdialog.c
@@ -376,9 +376,8 @@ gtk_dialog_class_init (GtkDialogClass *class)
 
   gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "close", 0);
 
-  gtk_container_class_set_template (GTK_CONTAINER_CLASS (class),
-                                    "/org/gtk/libgtk/gtkdialog.ui",
-                                    GTK_CONTAINER_TEMPLATE_RESOURCE);
+  gtk_container_class_set_template_from_resource (container_class,
+                                                  "/org/gtk/libgtk/gtkdialog.ui");
 
   gtk_container_class_declare_internal_child (container_class, TRUE,
                                               G_STRUCT_OFFSET (GtkDialogPrivate, vbox),
diff --git a/gtk/gtkmessagedialog.c b/gtk/gtkmessagedialog.c
index 5f70742..dc19269 100644
--- a/gtk/gtkmessagedialog.c
+++ b/gtk/gtkmessagedialog.c
@@ -291,9 +291,8 @@ gtk_message_dialog_class_init (GtkMessageDialogClass *class)
 
   g_type_class_add_private (gobject_class, sizeof (GtkMessageDialogPrivate));
 
-  gtk_container_class_set_template (GTK_CONTAINER_CLASS (class),
-                                    "/org/gtk/libgtk/gtkmessagedialog.ui",
-                                    GTK_CONTAINER_TEMPLATE_RESOURCE);
+  gtk_container_class_set_template_from_resource (container_class,
+                                                  "/org/gtk/libgtk/gtkmessagedialog.ui");
 
   gtk_container_class_declare_internal_child (container_class, TRUE,
                                               G_STRUCT_OFFSET (GtkMessageDialogPrivate, label),



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]