diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index f1784606ba..250f03c464 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1095,6 +1095,9 @@ DND_CURSORS = \
cursor_dnd_move.png \
cursor_dnd_none.png
+COMPOSITE_TEMPLATES = \
+ gtkdialog.ui
+
#
# rules to generate built sources
#
@@ -1139,7 +1142,7 @@ gtktypebuiltins.c: @REBUILD@ $(gtk_public_h_sources) $(deprecated_h_sources) gtk
gtkresources.h: gtk.gresource.xml
$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $(srcdir)/gtk.gresource.xml \
--target=$@ --sourcedir=$(srcdir) --c-name _gtk --generate-header --manual-register
-gtkresources.c: gtk.gresource.xml gtk-default.css gtk-win32.css gtk-win32-xp.css gtk-win32-base.css gtk-win32-classic.css $(DND_CURSORS)
+gtkresources.c: gtk.gresource.xml gtk-default.css gtk-win32.css gtk-win32-xp.css gtk-win32-base.css gtk-win32-classic.css $(DND_CURSORS) $(COMPOSITE_TEMPLATES)
$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $(srcdir)/gtk.gresource.xml \
--target=$@ --sourcedir=$(srcdir) --c-name _gtk --generate-source --manual-register
diff --git a/gtk/gtk.gresource.xml b/gtk/gtk.gresource.xml
index 939d35f48d..594d3ff994 100644
--- a/gtk/gtk.gresource.xml
+++ b/gtk/gtk.gresource.xml
@@ -11,5 +11,6 @@
cursor_dnd_none.png
cursor_dnd_move.png
cursor_dnd_copy.png
+ gtkdialog.ui
diff --git a/gtk/gtkdialog.c b/gtk/gtkdialog.c
index b88ca5f5ba..06cff85714 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,
@@ -331,8 +328,14 @@ gtk_dialog_class_init (GtkDialogClass *class)
GTK_PARAM_READABLE));
binding_set = gtk_binding_set_by_class (class);
-
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "close", 0);
+
+ /* Bind class to template
+ */
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/gtkdialog.ui");
+ gtk_widget_class_bind_child_internal (widget_class, GtkDialogPrivate, vbox);
+ gtk_widget_class_bind_child_internal (widget_class, GtkDialogPrivate, action_area);
+ gtk_widget_class_bind_callback (widget_class, gtk_dialog_delete_event_handler);
}
static void
@@ -350,7 +353,6 @@ update_spacings (GtkDialog *dialog)
"button-spacing", &button_spacing,
"action-area-border", &action_area_border,
NULL);
-
gtk_container_set_border_width (GTK_CONTAINER (priv->vbox),
content_area_border);
@@ -368,38 +370,11 @@ update_spacings (GtkDialog *dialog)
static void
gtk_dialog_init (GtkDialog *dialog)
{
- GtkDialogPrivate *priv;
-
dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
GTK_TYPE_DIALOG,
GtkDialogPrivate);
- priv = dialog->priv;
- /* 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.
- */
- g_signal_connect (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);
+ gtk_widget_init_template (GTK_WIDGET (dialog));
update_spacings (dialog);
}
@@ -410,28 +385,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 0000000000..9e81134eb2
--- /dev/null
+++ b/gtk/gtkdialog.ui
@@ -0,0 +1,30 @@
+
+
+
+
+ False
+ center-on-parent
+ dialog
+
+
+
+
+
+
diff --git a/gtk/tests/Makefile.am b/gtk/tests/Makefile.am
index 0f2dd781e8..1043839f82 100644
--- a/gtk/tests/Makefile.am
+++ b/gtk/tests/Makefile.am
@@ -78,6 +78,10 @@ builder_SOURCES = builder.c
builder_LDADD = $(progs_ldadd)
builder_LDFLAGS = -export-dynamic
+TEST_PROGS += templates
+templates_SOURCES = templates.c
+templates_LDADD = $(progs_ldadd)
+
if OS_UNIX
#TEST_PROGS += defaultvalue
#defaultvalue_SOURCES = defaultvalue.c
diff --git a/gtk/tests/templates.c b/gtk/tests/templates.c
new file mode 100644
index 0000000000..199c99cbc8
--- /dev/null
+++ b/gtk/tests/templates.c
@@ -0,0 +1,61 @@
+/* templates.c
+ * Copyright (C) 2013 Openismus GmbH
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library. If not, see .
+ *
+ * Authors: Tristan Van Berkom
+ */
+#include
+
+static void
+test_dialog_basic (void)
+{
+ GtkWidget *dialog;
+
+ dialog = gtk_dialog_new();
+ g_assert (GTK_IS_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+}
+
+static void
+test_dialog_override_property (void)
+{
+ GtkWidget *dialog;
+
+ dialog = g_object_new (GTK_TYPE_DIALOG,
+ "type-hint", GDK_WINDOW_TYPE_HINT_UTILITY,
+ NULL);
+ g_assert (GTK_IS_DIALOG (dialog));
+ g_assert (gtk_window_get_type_hint (GTK_WINDOW (dialog)) == GDK_WINDOW_TYPE_HINT_UTILITY);
+
+ gtk_widget_destroy (dialog);
+}
+
+int
+main (int argc, char **argv)
+{
+ /* initialize test program */
+ gtk_test_init (&argc, &argv);
+
+ /* This environment variable cooperates with gtk_widget_destroy()
+ * to assert that all automated compoenents are properly finalized
+ * when a given composite widget is destroyed.
+ */
+ g_assert (g_setenv ("GTK_WIDGET_ASSERT_COMPONENTS", "1", TRUE));
+
+ g_test_add_func ("/Template/GtkDialog/Basic", test_dialog_basic);
+ g_test_add_func ("/Template/GtkDialog/OverrideProperty", test_dialog_override_property);
+
+ return g_test_run();
+}