[gtk+/composite-templates-new: 14/14] GtkColorChooserDialog: Define children with a GtkBuilder template



commit e4fd3aad5f38a06f20238c049d360cfc5629e869
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Sun Mar 24 00:41:07 2013 +0900

    GtkColorChooserDialog: Define children with a GtkBuilder template

 gtk/Makefile.am             |    1 +
 gtk/gtk.gresource.xml       |    1 +
 gtk/gtkcolorchooserdialog.c |   73 +++++++++---------------------------------
 gtk/tests/templates.c       |   11 ++++++
 po/POTFILES.in              |    1 +
 5 files changed, 30 insertions(+), 57 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index abd15da..2551732 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1098,6 +1098,7 @@ COMPOSITE_TEMPLATES =                     \
        gtkappchooserdialog.ui          \
        gtkappchooserwidget.ui          \
        gtkassistant.ui                 \
+       gtkcolorchooserdialog.ui        \
        gtkdialog.ui                    \
        gtkinfobar.ui                   \
        gtklockbutton.ui                \
diff --git a/gtk/gtk.gresource.xml b/gtk/gtk.gresource.xml
index db5ce92..6e65b4b 100644
--- a/gtk/gtk.gresource.xml
+++ b/gtk/gtk.gresource.xml
@@ -15,6 +15,7 @@
     <file>gtkappchooserdialog.ui</file>
     <file>gtkappchooserwidget.ui</file>
     <file>gtkassistant.ui</file>
+    <file>gtkcolorchooserdialog.ui</file>
     <file>gtkdialog.ui</file>
     <file>gtkinfobar.ui</file>
     <file>gtklockbutton.ui</file>
diff --git a/gtk/gtkcolorchooserdialog.c b/gtk/gtkcolorchooserdialog.c
index fcde97f..8b35b95 100644
--- a/gtk/gtkcolorchooserdialog.c
+++ b/gtk/gtkcolorchooserdialog.c
@@ -101,67 +101,11 @@ selected_cb (GtkButton *button,
 static void
 gtk_color_chooser_dialog_init (GtkColorChooserDialog *cc)
 {
-  GtkColorChooserDialogPrivate *priv;
-  GtkDialog *dialog = GTK_DIALOG (cc);
-  GtkWidget *action_area, *content_area;
-
   cc->priv = G_TYPE_INSTANCE_GET_PRIVATE (cc,
                                           GTK_TYPE_COLOR_CHOOSER_DIALOG,
                                           GtkColorChooserDialogPrivate);
-  priv = cc->priv;
-
-  content_area = gtk_dialog_get_content_area (dialog);
-  action_area = gtk_dialog_get_action_area (dialog);
-
-  gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
-  gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
-  gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
-  gtk_box_set_spacing (GTK_BOX (action_area), 6);
-
-  gtk_widget_push_composite_child ();
-
-  gtk_window_set_resizable (GTK_WINDOW (cc), FALSE);
-
-  /* Create the content area */
-  priv->chooser = gtk_color_chooser_widget_new ();
-  gtk_container_set_border_width (GTK_CONTAINER (priv->chooser), 5);
-  gtk_widget_show (priv->chooser);
-  gtk_box_pack_start (GTK_BOX (content_area),
-                      priv->chooser, TRUE, TRUE, 0);
 
-  g_signal_connect (priv->chooser, "notify::rgba",
-                    G_CALLBACK (propagate_notify), cc);
-
-  g_signal_connect (priv->chooser, "notify::show-editor",
-                    G_CALLBACK (propagate_notify), cc);
-
-  g_signal_connect (priv->chooser, "color-activated",
-                    G_CALLBACK (color_activated_cb), cc);
-
-  /* Create the action area */
-  priv->cancel_button = gtk_dialog_add_button (dialog,
-                                               GTK_STOCK_CANCEL,
-                                               GTK_RESPONSE_CANCEL);
-
-  /* We emit the response for the Select button manually,
-   * since we want to save the color first
-   */
-  priv->select_button = gtk_button_new_from_stock (_("_Select"));
-  g_signal_connect (priv->select_button, "clicked",
-                    G_CALLBACK (selected_cb), dialog);
-  gtk_widget_set_can_default (priv->select_button, TRUE);
-  gtk_widget_show (priv->select_button);
-  gtk_dialog_add_action_widget (dialog, priv->select_button, GTK_RESPONSE_OK);
-  gtk_widget_grab_default (priv->select_button);
-
-  gtk_dialog_set_alternative_button_order (dialog,
-                                           GTK_RESPONSE_OK,
-                                           GTK_RESPONSE_CANCEL,
-                                           -1);
-
-  gtk_window_set_title (GTK_WINDOW (cc), _("Select a Color"));
-
-  gtk_widget_pop_composite_child ();
+  gtk_container_init_template (GTK_CONTAINER (cc));
 }
 
 static void
@@ -244,6 +188,7 @@ gtk_color_chooser_dialog_class_init (GtkColorChooserDialogClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+  GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
 
   object_class->get_property = gtk_color_chooser_dialog_get_property;
   object_class->set_property = gtk_color_chooser_dialog_set_property;
@@ -256,6 +201,20 @@ gtk_color_chooser_dialog_class_init (GtkColorChooserDialogClass *class)
       g_param_spec_boolean ("show-editor", P_("Show editor"), P_("Show editor"),
                             FALSE, GTK_PARAM_READWRITE));
 
+  gtk_container_class_set_template (container_class,
+                                   GTK_TEMPLATE_SOURCE_RESOURCE,
+                                   "/org/gtk/libgtk/gtkcolorchooserdialog.ui");
+  gtk_container_class_automate_child (container_class, "chooser", FALSE, GTK_AUTOMATE_CHILD_PRIVATE,
+                                     G_STRUCT_OFFSET (GtkColorChooserDialogPrivate, chooser));
+  gtk_container_class_automate_child (container_class, "cancel", FALSE, GTK_AUTOMATE_CHILD_PRIVATE,
+                                     G_STRUCT_OFFSET (GtkColorChooserDialogPrivate, cancel_button));
+  gtk_container_class_automate_child (container_class, "select", FALSE, GTK_AUTOMATE_CHILD_PRIVATE,
+                                     G_STRUCT_OFFSET (GtkColorChooserDialogPrivate, select_button));
+  gtk_container_class_declare_callbacks (container_class,
+                                        "selected_cb", (GCallback)selected_cb,
+                                        "propagate_notify", (GCallback)propagate_notify,
+                                        "color_activated_cb", (GCallback)color_activated_cb,
+                                        NULL);
 
   g_type_class_add_private (class, sizeof (GtkColorChooserDialogPrivate));
 }
diff --git a/gtk/tests/templates.c b/gtk/tests/templates.c
index 4276011..5eb4fd0 100644
--- a/gtk/tests/templates.c
+++ b/gtk/tests/templates.c
@@ -139,6 +139,16 @@ test_app_chooser_dialog_basic (void)
   gtk_widget_destroy (widget);
 }
 
+static void
+test_color_chooser_dialog_basic (void)
+{
+  GtkWidget *widget;
+
+  widget = gtk_color_chooser_dialog_new (NULL, NULL);
+  g_assert (GTK_IS_COLOR_CHOOSER_DIALOG (widget));
+  gtk_widget_destroy (widget);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -156,6 +166,7 @@ main (int argc, char **argv)
   g_test_add_func ("/Template/GtkStatusBar/Basic", test_statusbar_basic);
   g_test_add_func ("/Template/GtkAppChooserWidget/Basic", test_app_chooser_widget_basic);
   g_test_add_func ("/Template/GtkAppChooserDialog/Basic", test_app_chooser_dialog_basic);
+  g_test_add_func ("/Template/GtkColorChooserDialog/Basic", test_color_chooser_dialog_basic);
 
   return g_test_run();
 }
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5755ba5..3455a40 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -278,6 +278,7 @@ modules/printbackends/test/gtkprintbackendtest.c
 [type: gettext/glade]gtk/gtkappchooserdialog.ui
 [type: gettext/glade]gtk/gtkappchooserwidget.ui
 [type: gettext/glade]gtk/gtkassistant.ui
+[type: gettext/glade]gtk/gtkcolorchooserdialog.ui
 [type: gettext/glade]gtk/gtkdialog.ui
 [type: gettext/glade]gtk/gtkinfobar.ui
 [type: gettext/glade]gtk/gtklockbutton.ui


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