[gtk+/composite-templates-new: 6/11] GtkInfoBar: Define children with a GtkBuilder template



commit a85da5052602fec943ee14276646c4ed18a806e2
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Fri Mar 22 19:45:31 2013 +0900

    GtkInfoBar: Define children with a GtkBuilder template

 gtk/Makefile.am       |    3 +-
 gtk/gtk.gresource.xml |    1 +
 gtk/gtkinfobar.c      |   57 ++++++++++++-------------------------------------
 gtk/gtkinfobar.ui     |   39 +++++++++++++++++++++++++++++++++
 gtk/tests/templates.c |   11 +++++++++
 po/POTFILES.in        |    1 +
 6 files changed, 68 insertions(+), 44 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index a70b670..0b92543 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1095,7 +1095,8 @@ DND_CURSORS = \
 
 COMPOSITE_TEMPLATES =          \
        gtkdialog.ui            \
-       gtkmessagedialog.ui
+       gtkmessagedialog.ui     \
+       gtkinfobar.ui
 
 #
 # rules to generate built sources
diff --git a/gtk/gtk.gresource.xml b/gtk/gtk.gresource.xml
index 0989dad..df76b25 100644
--- a/gtk/gtk.gresource.xml
+++ b/gtk/gtk.gresource.xml
@@ -13,5 +13,6 @@
     <file alias="cursor/dnd-copy.png">cursor_dnd_copy.png</file>
     <file>gtkdialog.ui</file>
     <file>gtkmessagedialog.ui</file>
+    <file>gtkinfobar.ui</file>
   </gresource>
 </gresources>
diff --git a/gtk/gtkinfobar.c b/gtk/gtkinfobar.c
index a3a877d..188f1bc 100644
--- a/gtk/gtkinfobar.c
+++ b/gtk/gtkinfobar.c
@@ -167,9 +167,6 @@ static void     gtk_info_bar_get_preferred_height         (GtkWidget *widget,
 static gboolean gtk_info_bar_draw                         (GtkWidget      *widget,
                                                            cairo_t        *cr);
 static void     gtk_info_bar_buildable_interface_init     (GtkBuildableIface *iface);
-static GObject *gtk_info_bar_buildable_get_internal_child (GtkBuildable  *buildable,
-                                                           GtkBuilder    *builder,
-                                                           const gchar   *childname);
 static gboolean  gtk_info_bar_buildable_custom_tag_start   (GtkBuildable  *buildable,
                                                             GtkBuilder    *builder,
                                                             GObject       *child,
@@ -372,10 +369,12 @@ gtk_info_bar_draw (GtkWidget *widget,
 static void
 gtk_info_bar_class_init (GtkInfoBarClass *klass)
 {
+  GtkContainerClass *container_class;
   GtkWidgetClass *widget_class;
   GObjectClass *object_class;
   GtkBindingSet *binding_set;
 
+  container_class = GTK_CONTAINER_CLASS (klass);
   widget_class = GTK_WIDGET_CLASS (klass);
   object_class = G_OBJECT_CLASS (klass);
 
@@ -530,6 +529,17 @@ gtk_info_bar_class_init (GtkInfoBarClass *klass)
 
   gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "close", 0);
 
+  /* Setup Composite data */
+  gtk_container_class_set_template (container_class,
+                                   GTK_TEMPLATE_SOURCE_RESOURCE,
+                                   "/org/gtk/libgtk/gtkinfobar.ui");
+  gtk_container_class_automate_child (container_class, "content_area", TRUE,
+                                     GTK_AUTOMATE_CHILD_PRIVATE,
+                                     G_STRUCT_OFFSET (GtkInfoBarPrivate, content_area));
+  gtk_container_class_automate_child (container_class, "action_area", TRUE,
+                                     GTK_AUTOMATE_CHILD_PRIVATE,
+                                     G_STRUCT_OFFSET (GtkInfoBarPrivate, action_area));
+
   g_type_class_add_private (object_class, sizeof (GtkInfoBarPrivate));
 }
 
@@ -537,42 +547,19 @@ static void
 gtk_info_bar_init (GtkInfoBar *info_bar)
 {
   GtkWidget *widget = GTK_WIDGET (info_bar);
-  GtkWidget *content_area;
-  GtkWidget *action_area;
-
-  gtk_widget_push_composite_child ();
 
   info_bar->priv = G_TYPE_INSTANCE_GET_PRIVATE (info_bar,
                                                 GTK_TYPE_INFO_BAR,
                                                 GtkInfoBarPrivate);
 
-  content_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-  gtk_widget_show (content_area);
-  gtk_box_pack_start (GTK_BOX (info_bar), content_area, TRUE, TRUE, 0);
-
-  action_area = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
-  gtk_widget_show (action_area);
-  gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
-  gtk_box_pack_start (GTK_BOX (info_bar), action_area, FALSE, TRUE, 0);
-
-  gtk_widget_set_app_paintable (widget, TRUE);
   gtk_widget_set_redraw_on_allocate (widget, TRUE);
 
-  info_bar->priv->content_area = content_area;
-  info_bar->priv->action_area = action_area;
-
-  /* set default spacings */
-  gtk_box_set_spacing (GTK_BOX (info_bar->priv->action_area), ACTION_AREA_DEFAULT_SPACING);
-  gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->action_area), ACTION_AREA_DEFAULT_BORDER);
-  gtk_box_set_spacing (GTK_BOX (info_bar->priv->content_area), CONTENT_AREA_DEFAULT_SPACING);
-  gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->content_area), CONTENT_AREA_DEFAULT_BORDER);
-
   /* message-type is a CONSTRUCT property, so we init to a value
    * different from its default to trigger its property setter
    * during construction */
   info_bar->priv->message_type = GTK_MESSAGE_OTHER;
 
-  gtk_widget_pop_composite_child ();
+  gtk_container_init_template (GTK_CONTAINER (info_bar));
 }
 
 static GtkBuildableIface *parent_buildable_iface;
@@ -581,26 +568,10 @@ static void
 gtk_info_bar_buildable_interface_init (GtkBuildableIface *iface)
 {
   parent_buildable_iface = g_type_interface_peek_parent (iface);
-  iface->get_internal_child = gtk_info_bar_buildable_get_internal_child;
   iface->custom_tag_start = gtk_info_bar_buildable_custom_tag_start;
   iface->custom_finished = gtk_info_bar_buildable_custom_finished;
 }
 
-static GObject *
-gtk_info_bar_buildable_get_internal_child (GtkBuildable *buildable,
-                                           GtkBuilder   *builder,
-                                           const gchar  *childname)
-{
-  if (strcmp (childname, "content_area") == 0)
-    return G_OBJECT (GTK_INFO_BAR (buildable)->priv->content_area);
-  else if (strcmp (childname, "action_area") == 0)
-    return G_OBJECT (GTK_INFO_BAR (buildable)->priv->action_area);
-
-  return parent_buildable_iface->get_internal_child (buildable,
-                                                     builder,
-                                                     childname);
-}
-
 static gint
 get_response_for_widget (GtkInfoBar *info_bar,
                          GtkWidget  *widget)
diff --git a/gtk/gtkinfobar.ui b/gtk/gtkinfobar.ui
new file mode 100644
index 0000000..914b3ea
--- /dev/null
+++ b/gtk/gtkinfobar.ui
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk30">
+  <!-- interface-requires gtk+ 3.10 -->
+  <template class="GtkInfoBar" parent="GtkBox">
+    <property name="app_paintable">True</property>
+    <child>
+      <object class="GtkBox" id="content_area">
+        <property name="visible">True</property>
+        <property name="border_width">8</property>
+        <property name="spacing">16</property>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+      <packing>
+        <property name="expand">True</property>
+        <property name="fill">True</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkButtonBox" id="action_area">
+        <property name="visible">True</property>
+        <property name="border_width">5</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">6</property>
+        <property name="layout_style">end</property>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">1</property>
+      </packing>
+    </child>
+  </template>
+</interface>
diff --git a/gtk/tests/templates.c b/gtk/tests/templates.c
index 7f289bf..0c4e350 100644
--- a/gtk/tests/templates.c
+++ b/gtk/tests/templates.c
@@ -55,6 +55,16 @@ test_message_dialog_basic (void)
   gtk_widget_destroy (dialog);
 }
 
+static void
+test_info_bar_basic (void)
+{
+  GtkWidget *infobar;
+
+  infobar = gtk_info_bar_new ();
+  g_assert (GTK_IS_INFO_BAR (infobar));
+  gtk_widget_destroy (infobar);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -64,6 +74,7 @@ main (int argc, char **argv)
   g_test_add_func ("/Template/GtkDialog/Basic", test_dialog_basic);
   g_test_add_func ("/Template/GtkDialog/OverrideProperty", test_dialog_override_property);
   g_test_add_func ("/Template/GtkMessageDialog/Basic", test_message_dialog_basic);
+  g_test_add_func ("/Template/GtkInfoBar/Basic", test_info_bar_basic);
 
   return g_test_run();
 }
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d8add4d..bfb50a4 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -275,4 +275,5 @@ modules/printbackends/lpr/gtkprintbackendlpr.c
 modules/printbackends/papi/gtkprintbackendpapi.c
 modules/printbackends/test/gtkprintbackendtest.c
 [type: gettext/glade]gtk/gtkdialog.ui
+[type: gettext/glade]gtk/gtkinfobar.ui
 [type: gettext/glade]gtk/gtkmessagedialog.ui


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