[gtk+/composite-templates-new: 9/21] GtkMessageDialog: Define children with a GtkBuilder template



commit 1e53fa89c685fb64c0054cb607c0781abab84d7a
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Fri Mar 22 18:45:24 2013 +0900

    GtkMessageDialog: Define children with a GtkBuilder template

 gtk/Makefile.am         |    5 +-
 gtk/gtk.gresource.xml   |    1 +
 gtk/gtkmessagedialog.c  |   85 ++++---------------------------------
 gtk/gtkmessagedialog.ui |  106 +++++++++++++++++++++++++++++++++++++++++++++++
 gtk/tests/templates.c   |   14 ++++++
 po/POTFILES.in          |    1 +
 6 files changed, 135 insertions(+), 77 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index da0806b..a70b670 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1093,8 +1093,9 @@ DND_CURSORS = \
        cursor_dnd_move.png                             \
        cursor_dnd_none.png
 
-COMPOSITE_TEMPLATES = \
-       gtkdialog.ui
+COMPOSITE_TEMPLATES =          \
+       gtkdialog.ui            \
+       gtkmessagedialog.ui
 
 #
 # rules to generate built sources
diff --git a/gtk/gtk.gresource.xml b/gtk/gtk.gresource.xml
index 2704c7e..0989dad 100644
--- a/gtk/gtk.gresource.xml
+++ b/gtk/gtk.gresource.xml
@@ -12,5 +12,6 @@
     <file alias="cursor/dnd-move.png">cursor_dnd_move.png</file>
     <file alias="cursor/dnd-copy.png">cursor_dnd_copy.png</file>
     <file>gtkdialog.ui</file>
+    <file>gtkmessagedialog.ui</file>
   </gresource>
 </gresources>
diff --git a/gtk/gtkmessagedialog.c b/gtk/gtkmessagedialog.c
index 709fcfe..9755c70 100644
--- a/gtk/gtkmessagedialog.c
+++ b/gtk/gtkmessagedialog.c
@@ -123,10 +123,6 @@ static void gtk_message_dialog_get_property (GObject          *object,
 static void gtk_message_dialog_add_buttons  (GtkMessageDialog *message_dialog,
                                             GtkButtonsType    buttons);
 static void      gtk_message_dialog_buildable_interface_init     (GtkBuildableIface *iface);
-static GObject * gtk_message_dialog_buildable_get_internal_child (GtkBuildable  *buildable,
-                                                                  GtkBuilder    *builder,
-                                                                  const gchar   *childname);
-
 
 enum {
   PROP_0,
@@ -150,23 +146,10 @@ static void
 gtk_message_dialog_buildable_interface_init (GtkBuildableIface *iface)
 {
   parent_buildable_iface = g_type_interface_peek_parent (iface);
-  iface->get_internal_child = gtk_message_dialog_buildable_get_internal_child;
   iface->custom_tag_start = parent_buildable_iface->custom_tag_start;
   iface->custom_finished = parent_buildable_iface->custom_finished;
 }
 
-static GObject *
-gtk_message_dialog_buildable_get_internal_child (GtkBuildable *buildable,
-                                                 GtkBuilder   *builder,
-                                                 const gchar  *childname)
-{
-  if (strcmp (childname, "message_area") == 0)
-    return G_OBJECT (gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (buildable)));
-
-  return parent_buildable_iface->get_internal_child (buildable, builder, childname);
-}
-
-
 static void
 gtk_message_dialog_class_init (GtkMessageDialogClass *class)
 {
@@ -311,15 +294,19 @@ gtk_message_dialog_class_init (GtkMessageDialogClass *class)
                                                        GTK_TYPE_WIDGET,
                                                        GTK_PARAM_READABLE));
 
+  /* Setup Composite data */
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/gtkmessagedialog.ui");
+  gtk_widget_class_bind_child (widget_class, GtkMessageDialogPrivate, image);
+  gtk_widget_class_bind_child (widget_class, GtkMessageDialogPrivate, label);
+  gtk_widget_class_bind_child (widget_class, GtkMessageDialogPrivate, secondary_label);
+  gtk_widget_class_bind_child_internal (widget_class, GtkMessageDialogPrivate, message_area);
+
   g_type_class_add_private (gobject_class, sizeof (GtkMessageDialogPrivate));
 }
 
 static void
 gtk_message_dialog_init (GtkMessageDialog *dialog)
 {
-  GtkWidget *hbox;
-  GtkDialog *message_dialog = GTK_DIALOG (dialog);
-  GtkWidget *action_area, *content_area;
   GtkMessageDialogPrivate *priv;
 
   dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
@@ -327,65 +314,13 @@ gtk_message_dialog_init (GtkMessageDialog *dialog)
                                               GtkMessageDialogPrivate);
   priv = dialog->priv;
 
-  content_area = gtk_dialog_get_content_area (message_dialog);
-  action_area = gtk_dialog_get_action_area (message_dialog);
-
-  gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
-  gtk_window_set_title (GTK_WINDOW (dialog), "");
-  gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
-
   priv->has_primary_markup = FALSE;
   priv->has_secondary_text = FALSE;
-  priv->secondary_label = gtk_label_new (NULL);
-  gtk_widget_set_no_show_all (priv->secondary_label, TRUE);
-
-  priv->label = gtk_label_new (NULL);
-  priv->image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
-  g_object_set (priv->image, "use-fallback", TRUE, NULL);
-  gtk_widget_set_halign (priv->image, GTK_ALIGN_CENTER);
-  gtk_widget_set_valign (priv->image, GTK_ALIGN_START);
-
-  gtk_label_set_line_wrap  (GTK_LABEL (priv->label), TRUE);
-  gtk_label_set_selectable (GTK_LABEL (priv->label), TRUE);
-  gtk_widget_set_halign (priv->label, GTK_ALIGN_START);
-  gtk_widget_set_valign (priv->label, GTK_ALIGN_START);
-
-  gtk_label_set_line_wrap  (GTK_LABEL (priv->secondary_label), TRUE);
-  gtk_label_set_selectable (GTK_LABEL (priv->secondary_label), TRUE);
-  gtk_widget_set_halign (priv->secondary_label, GTK_ALIGN_START);
-  gtk_widget_set_valign (priv->secondary_label, GTK_ALIGN_START);
-
-  gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.0);
-  gtk_misc_set_alignment (GTK_MISC (priv->secondary_label), 0.0, 0.0);
-
-  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
-  priv->message_area = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
-
-  gtk_box_pack_start (GTK_BOX (priv->message_area), priv->label,
-                      FALSE, FALSE, 0);
-
-  gtk_box_pack_start (GTK_BOX (priv->message_area), priv->secondary_label,
-                      TRUE, TRUE, 0);
-
-  gtk_box_pack_start (GTK_BOX (hbox), priv->image,
-                      FALSE, FALSE, 0);
-
-  gtk_box_pack_start (GTK_BOX (hbox), priv->message_area,
-                      TRUE, TRUE, 0);
-
-  gtk_box_pack_start (GTK_BOX (content_area),
-                      hbox,
-                      FALSE, FALSE, 0);
-
-  gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
-  gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
-  gtk_box_set_spacing (GTK_BOX (content_area), 14); /* 14 + 2 * 5 = 24 */
-  gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
-  gtk_box_set_spacing (GTK_BOX (action_area), 6);
+  priv->has_primary_markup = FALSE;
+  priv->has_secondary_text = FALSE;
 
+  gtk_widget_init_template (GTK_WIDGET (dialog));
   gtk_message_dialog_style_updated (GTK_WIDGET (dialog));
-
-  gtk_widget_show_all (hbox);
 }
 
 static void
diff --git a/gtk/gtkmessagedialog.ui b/gtk/gtkmessagedialog.ui
new file mode 100644
index 0000000..d7cc42b
--- /dev/null
+++ b/gtk/gtkmessagedialog.ui
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk30">
+  <!-- interface-requires gtk+ 3.10 -->
+  <template class="GtkMessageDialog" parent="GtkDialog">
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes"> </property>
+    <property name="resizable">False</property>
+    <property name="type_hint">dialog</property>
+    <property name="skip_taskbar_hint">True</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox1">
+        <property name="orientation">vertical</property>
+        <property name="spacing">14</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+           <property name="border_width">5</property>
+            <property name="spacing">6</property>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox" id="box">
+            <property name="visible">True</property>
+            <property name="border_width">5</property>
+            <property name="spacing">12</property>
+            <child>
+              <object class="GtkImage" id="image">
+                <property name="visible">True</property>
+                <property name="halign">center</property>
+                <property name="valign">start</property>
+                <property name="stock">gtk-missing-image</property>
+                <property name="use_fallback">True</property>
+                <property name="icon-size">6</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkBox" id="message_area">
+                <property name="visible">True</property>
+                <property name="orientation">vertical</property>
+                <property name="spacing">12</property>
+                <child>
+                  <object class="GtkLabel" id="label">
+                    <property name="visible">True</property>
+                    <property name="halign">start</property>
+                    <property name="valign">start</property>
+                    <property name="xalign">0</property>
+                    <property name="yalign">0</property>
+                    <property name="wrap">True</property>
+                    <property name="selectable">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="secondary_label">
+                    <property name="no_show_all">True</property>
+                    <property name="halign">start</property>
+                    <property name="valign">start</property>
+                    <property name="xalign">0</property>
+                    <property name="yalign">0</property>
+                    <property name="wrap">True</property>
+                    <property name="selectable">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/gtk/tests/templates.c b/gtk/tests/templates.c
index b23a503..7f289bf 100644
--- a/gtk/tests/templates.c
+++ b/gtk/tests/templates.c
@@ -42,6 +42,19 @@ test_dialog_override_property (void)
   gtk_widget_destroy (dialog);
 }
 
+static void
+test_message_dialog_basic (void)
+{
+  GtkWidget *dialog;
+
+  dialog = gtk_message_dialog_new (NULL, 0,
+                                  GTK_MESSAGE_INFO,
+                                  GTK_BUTTONS_CLOSE,
+                                  "Do it hard !");
+  g_assert (GTK_IS_DIALOG (dialog));
+  gtk_widget_destroy (dialog);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -50,6 +63,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);
 
   return g_test_run();
 }
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 52d21c7..d8add4d 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -275,3 +275,4 @@ 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/gtkmessagedialog.ui


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