[gtk+/composite-templates-new: 19/33] 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: 19/33] GtkColorChooserDialog: Define children with a GtkBuilder template
- Date: Mon, 8 Apr 2013 08:38:04 +0000 (UTC)
commit 70440476ce24bea665cf949bca93a98c0eb3781a
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 | 68 ++++++-----------------------------
gtk/gtkcolorchooserdialog.ui | 82 ++++++++++++++++++++++++++++++++++++++++++
gtk/tests/templates.c | 11 ++++++
5 files changed, 106 insertions(+), 57 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 99acbeb..7fd005d 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1100,6 +1100,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 9361124..2a83c2a 100644
--- a/gtk/gtk.gresource.xml
+++ b/gtk/gtk.gresource.xml
@@ -15,6 +15,7 @@
<file compressed="true">gtkappchooserdialog.ui</file>
<file compressed="true">gtkappchooserwidget.ui</file>
<file compressed="true">gtkassistant.ui</file>
+ <file compressed="true">gtkcolorchooserdialog.ui</file>
<file compressed="true">gtkdialog.ui</file>
<file compressed="true">gtkinfobar.ui</file>
<file compressed="true">gtklockbutton.ui</file>
diff --git a/gtk/gtkcolorchooserdialog.c b/gtk/gtkcolorchooserdialog.c
index fcde97f..61c3860 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_widget_init_template (GTK_WIDGET (cc));
}
static void
@@ -256,6 +200,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_widget_class_set_template_from_resource (widget_class,
+ "/org/gtk/libgtk/gtkcolorchooserdialog.ui");
+ gtk_widget_class_bind_child (widget_class, GtkColorChooserDialogPrivate, chooser);
+ gtk_widget_class_bind_child (widget_class, GtkColorChooserDialogPrivate, cancel_button);
+ gtk_widget_class_bind_child (widget_class, GtkColorChooserDialogPrivate, select_button);
+ gtk_widget_class_bind_callback (widget_class, selected_cb);
+ gtk_widget_class_bind_callback (widget_class, propagate_notify);
+ gtk_widget_class_bind_callback (widget_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 ea7b306..a76e20a 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)
{
@@ -162,6 +172,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();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]