[gtk+] Make the message area available in gtkbuilder as well



commit f010eeb7d33afe557448c40fbaefba73aa5c647f
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jun 24 09:34:51 2010 -0400

    Make the message area available in gtkbuilder as well
    
    See bug 32069.

 gtk/gtkmessagedialog.c |   41 ++++++++++++++++++++++++++++++++++++++++-
 gtk/tests/builder.c    |   31 +++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkmessagedialog.c b/gtk/gtkmessagedialog.c
index 3c066a0..408cb44 100644
--- a/gtk/gtkmessagedialog.c
+++ b/gtk/gtkmessagedialog.c
@@ -30,6 +30,7 @@
 
 #include "gtkmessagedialog.h"
 #include "gtkaccessible.h"
+#include "gtkbuildable.h"
 #include "gtklabel.h"
 #include "gtkhbox.h"
 #include "gtkvbox.h"
@@ -85,6 +86,14 @@
  *                            dialog);
  * </programlisting>
  * </example>
+ *
+ * <refsect2 id="GtkMessageDialog-BUILDER-UI">
+ * <title>GtkMessageDialog as GtkBuildable</title>
+ * <para>
+ * The GtkMessageDialog implementation of the GtkBuildable interface exposes
+ * the message area as an internal child with the name "message_area".
+ * </para>
+ * </refsect2>
  */
 
 #define GTK_MESSAGE_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_MESSAGE_DIALOG, GtkMessageDialogPrivate))
@@ -113,6 +122,11 @@ static void gtk_message_dialog_get_property (GObject          *object,
 					     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);
+
 
 enum {
   PROP_0,
@@ -126,7 +140,32 @@ enum {
   PROP_MESSAGE_AREA
 };
 
-G_DEFINE_TYPE (GtkMessageDialog, gtk_message_dialog, GTK_TYPE_DIALOG)
+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;
+
+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)
diff --git a/gtk/tests/builder.c b/gtk/tests/builder.c
index 33f2f84..fde4f0e 100644
--- a/gtk/tests/builder.c
+++ b/gtk/tests/builder.c
@@ -1494,6 +1494,36 @@ test_dialog (void)
 }
 
 static void
+test_message_dialog (void)
+{
+  GtkBuilder * builder;
+  const gchar buffer1[] =
+    "<interface>"
+    "  <object class=\"GtkMessageDialog\" id=\"dialog1\">"
+    "    <child internal-child=\"message_area\">"
+    "      <object class=\"GtkVBox\" id=\"dialog-message-area\">"
+    "        <child>"
+    "          <object class=\"GtkExpander\" id=\"expander\"/>"
+    "        </child>"
+    "      </object>"
+    "    </child>"
+    "  </object>"
+    "</interface>";
+
+  GObject *dialog1;
+  GObject *expander;
+
+  builder = builder_new_from_string (buffer1, -1, NULL);
+  dialog1 = gtk_builder_get_object (builder, "dialog1");
+  expander = gtk_builder_get_object (builder, "expander");
+  g_assert (GTK_IS_EXPANDER (expander));
+  g_assert (gtk_widget_get_parent (GTK_WIDGET (expander)) == gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (dialog1)));
+
+  gtk_widget_destroy (GTK_WIDGET (dialog1));
+  g_object_unref (builder);
+}
+
+static void
 test_accelerators (void)
 {
   GtkBuilder *builder;
@@ -2586,6 +2616,7 @@ main (int argc, char **argv)
   g_test_add_func ("/Builder/AddObjects", test_add_objects);
   g_test_add_func ("/Builder/Menus", test_menus);
   g_test_add_func ("/Builder/MessageArea", test_message_area);
+  g_test_add_func ("/Builder/MessageDialog", test_message_dialog);
 
   return g_test_run();
 }



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