[gtk+/composite-templates: 3/17] Implemented GtkDialog and GtkMessageDialog using new template API.



commit 04444664a4b6da818fcfdc6823122824b8098921
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date:   Tue Jul 31 13:47:00 2012 -0300

    Implemented GtkDialog and GtkMessageDialog using new template API.

 gtk/gtk.gresource.xml   |    2 +
 gtk/gtkdialog.c         |  145 ++++++++++++---------------
 gtk/gtkdialog.ui        |   24 +++++
 gtk/gtkmessagedialog.c  |  256 +++++++++++++++++++----------------------------
 gtk/gtkmessagedialog.ui |   76 ++++++++++++++
 5 files changed, 273 insertions(+), 230 deletions(-)
---
diff --git a/gtk/gtk.gresource.xml b/gtk/gtk.gresource.xml
index 939d35f..d3deedb 100644
--- a/gtk/gtk.gresource.xml
+++ b/gtk/gtk.gresource.xml
@@ -11,5 +11,7 @@
     <file alias="cursor/dnd-none.png">cursor_dnd_none.png</file>
     <file alias="cursor/dnd-move.png">cursor_dnd_move.png</file>
     <file alias="cursor/dnd-copy.png">cursor_dnd_copy.png</file>
+    <file preprocess="xml-stripblanks">gtkdialog.ui</file>
+    <file preprocess="xml-stripblanks">gtkmessagedialog.ui</file>
   </gresource>
 </gresources>
diff --git a/gtk/gtkdialog.c b/gtk/gtkdialog.c
index b88ca5f..ecb87d5 100644
--- a/gtk/gtkdialog.c
+++ b/gtk/gtkdialog.c
@@ -195,9 +195,6 @@ static ResponseData * get_response_data          (GtkWidget    *widget,
                                                   gboolean      create);
 
 static void      gtk_dialog_buildable_interface_init     (GtkBuildableIface *iface);
-static GObject * gtk_dialog_buildable_get_internal_child (GtkBuildable  *buildable,
-                                                          GtkBuilder    *builder,
-                                                          const gchar   *childname);
 static gboolean  gtk_dialog_buildable_custom_tag_start   (GtkBuildable  *buildable,
                                                           GtkBuilder    *builder,
                                                           GObject       *child,
@@ -210,12 +207,6 @@ static void      gtk_dialog_buildable_custom_finished    (GtkBuildable  *buildab
                                                           const gchar   *tagname,
                                                           gpointer       user_data);
 
-
-enum {
-  PROP_0,
-  PROP_HAS_SEPARATOR
-};
-
 enum {
   RESPONSE,
   CLOSE,
@@ -227,17 +218,68 @@ static guint dialog_signals[LAST_SIGNAL];
 G_DEFINE_TYPE_WITH_CODE (GtkDialog, gtk_dialog, GTK_TYPE_WINDOW,
 			 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
 						gtk_dialog_buildable_interface_init))
+static void
+update_spacings (GtkDialog *dialog)
+{
+  GtkDialogPrivate *priv = dialog->priv;
+  gint content_area_border;
+  gint content_area_spacing;
+  gint button_spacing;
+  gint action_area_border;
+
+  gtk_widget_style_get (GTK_WIDGET (dialog),
+                        "content-area-border", &content_area_border,
+                        "content-area-spacing", &content_area_spacing,
+                        "button-spacing", &button_spacing,
+                        "action-area-border", &action_area_border,
+                        NULL);
+
+  
+  gtk_container_set_border_width (GTK_CONTAINER (priv->vbox),
+                                  content_area_border);
+  if (!_gtk_box_get_spacing_set (GTK_BOX (priv->vbox)))
+    {
+      gtk_box_set_spacing (GTK_BOX (priv->vbox), content_area_spacing);
+      _gtk_box_set_spacing_set (GTK_BOX (priv->vbox), FALSE);
+    }
+  gtk_box_set_spacing (GTK_BOX (priv->action_area), button_spacing);
+  gtk_container_set_border_width (GTK_CONTAINER (priv->action_area),
+                                  action_area_border);
+}
+
+static GObject *
+gtk_dialog_constructor (GType                  type,
+                        guint                  n_construct_properties,
+                        GObjectConstructParam *construct_properties)
+{
+  GObject *obj;
+  
+  obj = G_OBJECT_CLASS (gtk_dialog_parent_class)->constructor (type,
+                                                               n_construct_properties,
+                                                               construct_properties);
+
+  update_spacings (GTK_DIALOG (obj));
+
+  gtk_window_set_type_hint (GTK_WINDOW (obj), GDK_WINDOW_TYPE_HINT_DIALOG);
+  gtk_window_set_position (GTK_WINDOW (obj), GTK_WIN_POS_CENTER_ON_PARENT);
+
+  return obj;
+}
 
 static void
 gtk_dialog_class_init (GtkDialogClass *class)
 {
+  GtkContainerClass *container_class;
   GObjectClass *gobject_class;
   GtkWidgetClass *widget_class;
   GtkBindingSet *binding_set;
 
   gobject_class = G_OBJECT_CLASS (class);
   widget_class = GTK_WIDGET_CLASS (class);
+  container_class = GTK_CONTAINER_CLASS (class);
 
+  gobject_class->constructor = gtk_dialog_constructor;
+  
   widget_class->map = gtk_dialog_map;
   widget_class->style_updated = gtk_dialog_style_updated;
 
@@ -333,48 +375,30 @@ gtk_dialog_class_init (GtkDialogClass *class)
   binding_set = gtk_binding_set_by_class (class);
 
   gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "close", 0);
-}
 
-static void
-update_spacings (GtkDialog *dialog)
-{
-  GtkDialogPrivate *priv = dialog->priv;
-  gint content_area_border;
-  gint content_area_spacing;
-  gint button_spacing;
-  gint action_area_border;
+  gtk_container_class_set_template_from_resource (container_class,
+                                                  "/org/gtk/libgtk/gtkdialog.ui");
 
-  gtk_widget_style_get (GTK_WIDGET (dialog),
-                        "content-area-border", &content_area_border,
-                        "content-area-spacing", &content_area_spacing,
-                        "button-spacing", &button_spacing,
-                        "action-area-border", &action_area_border,
-                        NULL);
-
-  
-  gtk_container_set_border_width (GTK_CONTAINER (priv->vbox),
-                                  content_area_border);
-  if (!_gtk_box_get_spacing_set (GTK_BOX (priv->vbox)))
-    {
-      gtk_box_set_spacing (GTK_BOX (priv->vbox), content_area_spacing);
-      _gtk_box_set_spacing_set (GTK_BOX (priv->vbox), FALSE);
-    }
-  gtk_box_set_spacing (GTK_BOX (priv->action_area),
-                       button_spacing);
-  gtk_container_set_border_width (GTK_CONTAINER (priv->action_area),
-                                  action_area_border);
+  gtk_container_class_declare_internal_child (container_class, TRUE,
+                                              G_STRUCT_OFFSET (GtkDialogPrivate, vbox),
+                                              "vbox");
+  gtk_container_class_declare_internal_child (container_class, TRUE,
+                                              G_STRUCT_OFFSET (GtkDialogPrivate, action_area),
+                                              "action_area");
 }
 
 static void
 gtk_dialog_init (GtkDialog *dialog)
 {
   GtkDialogPrivate *priv;
+  
+  dialog->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
+                                                     GTK_TYPE_DIALOG,
+                                                     GtkDialogPrivate);
 
-  dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
-                                              GTK_TYPE_DIALOG,
-                                              GtkDialogPrivate);
-  priv = dialog->priv;
-
+  priv->vbox = NULL;
+  priv->action_area = NULL;
+  
   /* To avoid breaking old code that prevents destroy on delete event
    * by connecting a handler, we have to have the FIRST signal
    * connection on the dialog.
@@ -383,25 +407,6 @@ gtk_dialog_init (GtkDialog *dialog)
                     "delete-event",
                     G_CALLBACK (gtk_dialog_delete_event_handler),
                     NULL);
-
-  priv->vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
-  gtk_container_add (GTK_CONTAINER (dialog), priv->vbox);
-  gtk_widget_show (priv->vbox);
-
-  priv->action_area = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
-
-  gtk_button_box_set_layout (GTK_BUTTON_BOX (priv->action_area),
-                             GTK_BUTTONBOX_END);
-
-  gtk_box_pack_end (GTK_BOX (priv->vbox), priv->action_area,
-                    FALSE, TRUE, 0);
-  gtk_widget_show (priv->action_area);
-
-  gtk_window_set_type_hint (GTK_WINDOW (dialog),
-			    GDK_WINDOW_TYPE_HINT_DIALOG);
-  gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ON_PARENT);
-
-  update_spacings (dialog);
 }
 
 static GtkBuildableIface *parent_buildable_iface;
@@ -410,28 +415,10 @@ static void
 gtk_dialog_buildable_interface_init (GtkBuildableIface *iface)
 {
   parent_buildable_iface = g_type_interface_peek_parent (iface);
-  iface->get_internal_child = gtk_dialog_buildable_get_internal_child;
   iface->custom_tag_start = gtk_dialog_buildable_custom_tag_start;
   iface->custom_finished = gtk_dialog_buildable_custom_finished;
 }
 
-static GObject *
-gtk_dialog_buildable_get_internal_child (GtkBuildable *buildable,
-					 GtkBuilder   *builder,
-					 const gchar  *childname)
-{
-  GtkDialogPrivate *priv = GTK_DIALOG (buildable)->priv;
-
-  if (strcmp (childname, "vbox") == 0)
-    return G_OBJECT (priv->vbox);
-  else if (strcmp (childname, "action_area") == 0)
-    return G_OBJECT (priv->action_area);
-
-  return parent_buildable_iface->get_internal_child (buildable,
-                                                     builder,
-                                                     childname);
-}
-
 static gboolean
 gtk_dialog_delete_event_handler (GtkWidget   *widget,
                                  GdkEventAny *event,
diff --git a/gtk/gtkdialog.ui b/gtk/gtkdialog.ui
new file mode 100644
index 0000000..b078f5c
--- /dev/null
+++ b/gtk/gtkdialog.ui
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <template parent="GtkWindow" class="GtkDialog" id="this">
+    <child>
+      <object class="GtkBox" id="vbox">
+        <property name="visible">True</property>
+        <property name="orientation">GTK_ORIENTATION_VERTICAL</property>
+        <child>
+          <object class="GtkButtonBox" id="action_area">
+            <property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/gtk/gtkmessagedialog.c b/gtk/gtkmessagedialog.c
index 9261b49..284c018 100644
--- a/gtk/gtkmessagedialog.c
+++ b/gtk/gtkmessagedialog.c
@@ -100,33 +100,29 @@
 
 struct _GtkMessageDialogPrivate
 {
-  GtkWidget     *image;
-  GtkWidget     *label;
-  GtkWidget     *message_area; /* vbox for the primary and secondary labels, and any extra content from the caller */
-  GtkWidget     *secondary_label;
-
-  guint          has_primary_markup : 1;
-  guint          has_secondary_text : 1;
-  guint          message_type       : 3;
+  GtkWidget *label;
+  GtkWidget *secondary_label;
+  GtkWidget *image;
+  GtkWidget *message_area;
+  guint message_type : 3;
+  guint buttons_type : 3;
+  guint has_primary_markup : 1;
+  guint has_secondary_text : 1;
 };
 
-static void gtk_message_dialog_style_updated (GtkWidget             *widget);
-
-static void gtk_message_dialog_set_property (GObject          *object,
-					     guint             prop_id,
-					     const GValue     *value,
-					     GParamSpec       *pspec);
-static void gtk_message_dialog_get_property (GObject          *object,
-					     guint             prop_id,
-					     GValue           *value,
-					     GParamSpec       *pspec);
-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);
-
+static GObject *gtk_message_dialog_constructor  (GType                  type,
+						 guint                  n_construct_properties,
+						 GObjectConstructParam *construct_params);
+static void     gtk_message_dialog_set_property (GObject          *object,
+						 guint             prop_id,
+						 const GValue     *value,
+						 GParamSpec       *pspec);
+static void     gtk_message_dialog_get_property (GObject          *object,
+						 guint             prop_id,
+						 GValue           *value,
+						 GParamSpec       *pspec);
+static void     gtk_message_dialog_add_buttons  (GtkMessageDialog *message_dialog,
+						 GtkButtonsType    buttons);
 
 enum {
   PROP_0,
@@ -140,46 +136,45 @@ enum {
   PROP_MESSAGE_AREA
 };
 
-G_DEFINE_TYPE_WITH_CODE (GtkMessageDialog, gtk_message_dialog, GTK_TYPE_DIALOG,
-                         G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
-                                                gtk_message_dialog_buildable_interface_init))
-
-static GtkBuildableIface *parent_buildable_iface;
+G_DEFINE_TYPE (GtkMessageDialog, gtk_message_dialog, GTK_TYPE_DIALOG)
 
 static void
-gtk_message_dialog_buildable_interface_init (GtkBuildableIface *iface)
+gtk_message_dialog_style_updated (GtkWidget *widget)
 {
-  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;
-}
+  GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (widget);
+  GtkWidget *parent;
+  gint border_width;
 
-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)));
+  parent = gtk_widget_get_parent (gtk_message_dialog_get_image (dialog));
 
-  return parent_buildable_iface->get_internal_child (buildable, builder, childname);
-}
+  if (parent)
+    {
+      gtk_widget_style_get (widget, "message-border",
+                            &border_width, NULL);
 
+      gtk_container_set_border_width (GTK_CONTAINER (parent),
+                                      MAX (0, border_width - 7));
+    }
+
+  GTK_WIDGET_CLASS (gtk_message_dialog_parent_class)->style_updated (widget);
+}
 
 static void
 gtk_message_dialog_class_init (GtkMessageDialogClass *class)
 {
+  GtkContainerClass *container_class;
   GtkWidgetClass *widget_class;
   GObjectClass *gobject_class;
 
-  widget_class = GTK_WIDGET_CLASS (class);
   gobject_class = G_OBJECT_CLASS (class);
-  
+  widget_class = GTK_WIDGET_CLASS (class);
+  container_class = GTK_CONTAINER_CLASS (class);
+
   widget_class->style_updated = gtk_message_dialog_style_updated;
 
   gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_ALERT);
 
+  gobject_class->constructor  = gtk_message_dialog_constructor;
   gobject_class->set_property = gtk_message_dialog_set_property;
   gobject_class->get_property = gtk_message_dialog_get_property;
   
@@ -206,7 +201,7 @@ gtk_message_dialog_class_init (GtkMessageDialogClass *class)
 						      P_("The type of message"),
 						      GTK_TYPE_MESSAGE_TYPE,
                                                       GTK_MESSAGE_INFO,
-                                                      GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+                                                      GTK_PARAM_READWRITE));
   g_object_class_install_property (gobject_class,
                                    PROP_BUTTONS,
                                    g_param_spec_enum ("buttons",
@@ -294,32 +289,28 @@ gtk_message_dialog_class_init (GtkMessageDialogClass *class)
                                                         GTK_TYPE_WIDGET,
                                                         GTK_PARAM_READWRITE));
 
-  /**
-   * GtkMessageDialog:message-area:
-   *
-   * The #GtkVBox that corresponds to the message area of this dialog.  See
-   * gtk_message_dialog_get_message_area() for a detailed description of this
-   * area.
-   *
-   * Since: 2.22
-   */
-  g_object_class_install_property (gobject_class,
-				   PROP_MESSAGE_AREA,
-				   g_param_spec_object ("message-area",
-							P_("Message area"),
-							P_("GtkVBox that holds the dialog's primary and secondary labels"),
-							GTK_TYPE_WIDGET,
-							GTK_PARAM_READABLE));
-
   g_type_class_add_private (gobject_class, sizeof (GtkMessageDialogPrivate));
+
+  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),
+                                              "label");
+  gtk_container_class_declare_internal_child (container_class, TRUE,
+                                              G_STRUCT_OFFSET (GtkMessageDialogPrivate, secondary_label),
+                                              "secondary_label");
+  gtk_container_class_declare_internal_child (container_class, TRUE,
+                                              G_STRUCT_OFFSET (GtkMessageDialogPrivate, image),
+                                              "image");
+  gtk_container_class_declare_internal_child (container_class, TRUE,
+                                              G_STRUCT_OFFSET (GtkMessageDialogPrivate, message_area),
+                                              "action_area");
 }
 
 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,64 +318,14 @@ 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);
-  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);
-
-  gtk_message_dialog_style_updated (GTK_WIDGET (dialog));
-
-  gtk_widget_show_all (hbox);
 }
 
 static void
@@ -472,6 +413,30 @@ setup_type (GtkMessageDialog *dialog,
     }
 }
 
+static GObject *
+gtk_message_dialog_constructor (GType                  type,
+				guint                  n_construct_properties,
+				GObjectConstructParam *construct_params)
+{
+  GObject *object;
+  GtkMessageDialog *dialog;
+  GtkMessageDialogPrivate *priv;
+
+  object = 
+    G_OBJECT_CLASS (gtk_message_dialog_parent_class)->constructor (type, 
+								   n_construct_properties, 
+								   construct_params);
+
+  dialog = GTK_MESSAGE_DIALOG (object);
+  priv = dialog->priv;
+
+  /* Setup widget's now that they've been built */
+  setup_type (dialog, priv->message_type);
+  gtk_message_dialog_add_buttons (dialog, priv->buttons_type);
+
+  return object;
+}
+
 static void 
 gtk_message_dialog_set_property (GObject      *object,
 				 guint         prop_id,
@@ -484,10 +449,17 @@ gtk_message_dialog_set_property (GObject      *object,
   switch (prop_id)
     {
     case PROP_MESSAGE_TYPE:
-      setup_type (dialog, g_value_get_enum (value));
+
+      if (priv->image)
+	setup_type (dialog, g_value_get_enum (value));
+      else
+	/* Deffer assignment at construct time until image is built */
+	priv->message_type = g_value_get_enum (value);
+
       break;
+
     case PROP_BUTTONS:
-      gtk_message_dialog_add_buttons (dialog, g_value_get_enum (value));
+      priv->buttons_type = g_value_get_enum (value);
       break;
     case PROP_TEXT:
       if (priv->has_primary_markup)
@@ -532,7 +504,6 @@ gtk_message_dialog_set_property (GObject      *object,
     case PROP_IMAGE:
       gtk_message_dialog_set_image (dialog, g_value_get_object (value));
       break;
-
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -576,9 +547,6 @@ gtk_message_dialog_get_property (GObject     *object,
     case PROP_IMAGE:
       g_value_set_object (value, priv->image);
       break;
-    case PROP_MESSAGE_AREA:
-      g_value_set_object (value, priv->message_area);
-      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -745,12 +713,19 @@ gtk_message_dialog_set_image (GtkMessageDialog *dialog,
       gtk_widget_set_valign (image, GTK_ALIGN_START);
     }
 
-  priv->message_type = GTK_MESSAGE_OTHER;
-
-  parent = gtk_widget_get_parent (priv->image);
-  gtk_container_add (GTK_CONTAINER (parent), image);
-  gtk_container_remove (GTK_CONTAINER (parent), priv->image);
-  gtk_box_reorder_child (GTK_BOX (parent), image, 0);
+  /* Only change the message type and the image if
+   * the image is not already in the dialog (which is
+   * the case when GtkBuilder builds the image).
+   */
+  if (priv->image && priv->image != image)
+    {
+      priv->message_type = GTK_MESSAGE_OTHER;
+  
+      parent = gtk_widget_get_parent (priv->image);
+      gtk_container_add (GTK_CONTAINER (parent), image);
+      gtk_container_remove (GTK_CONTAINER (parent), priv->image);
+      gtk_box_reorder_child (GTK_BOX (parent), image, 0);
+    }
 
   priv->image = image;
 
@@ -994,24 +969,3 @@ gtk_message_dialog_add_buttons (GtkMessageDialog* message_dialog,
 
   g_object_notify (G_OBJECT (message_dialog), "buttons");
 }
-
-static void
-gtk_message_dialog_style_updated (GtkWidget *widget)
-{
-  GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (widget);
-  GtkWidget *parent;
-  gint border_width;
-
-  parent = gtk_widget_get_parent (gtk_message_dialog_get_image (dialog));
-
-  if (parent)
-    {
-      gtk_widget_style_get (widget, "message-border",
-                            &border_width, NULL);
-
-      gtk_container_set_border_width (GTK_CONTAINER (parent),
-                                      MAX (0, border_width - 7));
-    }
-
-  GTK_WIDGET_CLASS (gtk_message_dialog_parent_class)->style_updated (widget);
-}
diff --git a/gtk/gtkmessagedialog.ui b/gtk/gtkmessagedialog.ui
new file mode 100644
index 0000000..8f2332f
--- /dev/null
+++ b/gtk/gtkmessagedialog.ui
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <template parent="GtkDialog" class="GtkMessageDialog" id="this">
+    <child internal-child="vbox">
+      <object class="GtkBox" id="vbox">
+        <property name="spacing">14</property>
+        <child>
+          <object class="GtkBox" id="hbox1">
+            <property name="visible">True</property>
+            <property name="border_width">5</property>
+            <property name="spacing">12</property>
+            <property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
+            <child>
+              <object class="GtkImage" id="image">
+                <property name="visible">True</property>
+                <property name="yalign">0</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="vbox1">
+                <property name="visible">True</property>
+                <property name="spacing">12</property>
+                <property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
+                <child>
+                  <object class="GtkLabel" id="label">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="yalign">0</property>
+                    <property name="label" translatable="yes">primary message</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="visible">False</property>
+                    <property name="no_show_all">True</property>
+                    <property name="xalign">0</property>
+                    <property name="yalign">0</property>
+                    <property name="label" translatable="yes">secondary message</property>
+                    <property name="wrap">True</property>
+                    <property name="selectable">True</property>
+                  </object>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="action_area">
+            <property name="border_width">5</property>
+            <property name="spacing">6</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>



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