[gtk+/composite-templates-new: 17/18] GtkColorChooserDialog: 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: 17/18] GtkColorChooserDialog: Define children with a GtkBuilder template
- Date: Sun, 24 Mar 2013 16:53:38 +0000 (UTC)
commit 966d0158720d482651738b55d9ce0758d018aacf
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 | 69 ++++++-----------------------------
gtk/gtkcolorchooserdialog.ui | 82 ++++++++++++++++++++++++++++++++++++++++++
gtk/tests/templates.c | 11 ++++++
po/POTFILES.in | 1 +
6 files changed, 108 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..c9b0974 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,16 @@ gtk_color_chooser_dialog_class_init (GtkColorChooserDialogClass *class)
g_param_spec_boolean ("show-editor", P_("Show editor"), P_("Show editor"),
FALSE, GTK_PARAM_READWRITE));
+ /* Bind class to template
+ */
+ gtk_container_class_set_template_from_resource (container_class,
+ "/org/gtk/libgtk/gtkcolorchooserdialog.ui");
+ gtk_container_class_bind_child (container_class, GtkColorChooserDialogPrivate, chooser);
+ gtk_container_class_bind_child (container_class, GtkColorChooserDialogPrivate, cancel_button);
+ gtk_container_class_bind_child (container_class, GtkColorChooserDialogPrivate, select_button);
+ gtk_container_class_bind_callback (container_class, selected_cb);
+ gtk_container_class_bind_callback (container_class, propagate_notify);
+ gtk_container_class_bind_callback (container_class, color_activated_cb);
g_type_class_add_private (class, sizeof (GtkColorChooserDialogPrivate));
}
diff --git a/gtk/gtkcolorchooserdialog.ui b/gtk/gtkcolorchooserdialog.ui
new file mode 100644
index 0000000..c722c34
--- /dev/null
+++ b/gtk/gtkcolorchooserdialog.ui
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk30">
+ <!-- interface-requires gtk+ 3.10 -->
+ <template class="GtkColorChooserDialog" parent="GtkDialog">
+ <property name="can_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">Select a Color</property>
+ <property name="type_hint">dialog</property>
+ <child internal-child="vbox">
+ <object class="GtkBox" id="dialog-vbox1">
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="dialog-action_area1">
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="cancel_button">
+ <property name="label">gtk-cancel</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="select_button">
+ <property name="label" translatable="yes">_Select</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="has_default">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked" handler="selected_cb" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkColorChooserWidget" id="chooser">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="orientation">vertical</property>
+ <property name="rgba">rgb(255,255,255)</property>
+ <signal name="color-activated" handler="color_activated_cb" swapped="no"/>
+ <signal name="notify::rgba" handler="propagate_notify" swapped="no"/>
+ <signal name="notify::show-editor" handler="propagate_notify" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="-6">cancel_button</action-widget>
+ <action-widget response="-5">select_button</action-widget>
+ </action-widgets>
+ </template>
+</interface>
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]