[gtk+/composite-templates-new: 4/4] GtkDialog: Define children with a GtkBuilder template
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/composite-templates-new: 4/4] GtkDialog: Define children with a GtkBuilder template
- Date: Thu, 21 Mar 2013 08:55:45 +0000 (UTC)
commit 5697c211c752a9237ccb8840dcd5a5312a3cf6bc
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Thu Mar 21 17:54:16 2013 +0900
GtkDialog: Define children with a GtkBuilder template
gtk/Makefile.am | 5 ++++-
gtk/gtk.gresource.xml | 1 +
gtk/gtkdialog.c | 44 +++++++++++++-------------------------------
3 files changed, 18 insertions(+), 32 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 03f3e31..da0806b 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1093,6 +1093,9 @@ DND_CURSORS = \
cursor_dnd_move.png \
cursor_dnd_none.png
+COMPOSITE_TEMPLATES = \
+ gtkdialog.ui
+
#
# rules to generate built sources
#
@@ -1137,7 +1140,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 939d35f..2704c7e 100644
--- a/gtk/gtk.gresource.xml
+++ b/gtk/gtk.gresource.xml
@@ -11,5 +11,6 @@
<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>gtkdialog.ui</file>
</gresource>
</gresources>
diff --git a/gtk/gtkdialog.c b/gtk/gtkdialog.c
index b88ca5f..4edcf16 100644
--- a/gtk/gtkdialog.c
+++ b/gtk/gtkdialog.c
@@ -233,10 +233,12 @@ gtk_dialog_class_init (GtkDialogClass *class)
{
GObjectClass *gobject_class;
GtkWidgetClass *widget_class;
+ GtkContainerClass *container_class;
GtkBindingSet *binding_set;
gobject_class = G_OBJECT_CLASS (class);
widget_class = GTK_WIDGET_CLASS (class);
+ container_class = GTK_CONTAINER_CLASS (class);
widget_class->map = gtk_dialog_map;
widget_class->style_updated = gtk_dialog_style_updated;
@@ -332,6 +334,17 @@ gtk_dialog_class_init (GtkDialogClass *class)
binding_set = gtk_binding_set_by_class (class);
+ /* Setup Composite data */
+ gtk_container_class_set_template_from_resource (container_class, "/org/gtk/libgtk/gtkdialog.ui");
+ gtk_container_class_declare_signal_callback (container_class, "gtk_dialog_delete_event_handler",
+ G_CALLBACK (gtk_dialog_delete_event_handler));
+ gtk_container_class_automate_child (container_class, "vbox", TRUE,
+ GTK_AUTOMATE_CHILD_PRIVATE,
+ G_STRUCT_OFFSET (GtkDialogPrivate, vbox));
+ gtk_container_class_automate_child (container_class, "action_area", TRUE,
+ GTK_AUTOMATE_CHILD_PRIVATE,
+ G_STRUCT_OFFSET (GtkDialogPrivate, action_area));
+
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "close", 0);
}
@@ -350,7 +363,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,39 +380,9 @@ 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);
-
update_spacings (dialog);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]