From 92a8c76b314effa8c43c3fae1291c500f93f8839 Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Sat, 30 Mar 2013 18:51:58 +0900 Subject: [PATCH] GtkVolumeButton: Define children with a GtkBuilder template --- gtk/Makefile.am | 3 ++- gtk/gtk.gresource.xml | 1 + gtk/gtkvolumebutton.c | 50 +++++++++------------------------- gtk/gtkvolumebutton.ui | 61 ++++++++++++++++++++++++++++++++++++++++++ gtk/tests/templates.c | 11 ++++++++ 5 files changed, 87 insertions(+), 39 deletions(-) create mode 100644 gtk/gtkvolumebutton.ui diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 949fc625e3..c75f694516 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -1117,7 +1117,8 @@ COMPOSITE_TEMPLATES = \ gtkprintunixdialog.ui \ gtkrecentchooserdefault.ui \ gtkscalebutton.ui \ - gtkstatusbar.ui + gtkstatusbar.ui \ + gtkvolumebutton.ui # # rules to generate built sources diff --git a/gtk/gtk.gresource.xml b/gtk/gtk.gresource.xml index 7def35dd73..b93d83742a 100644 --- a/gtk/gtk.gresource.xml +++ b/gtk/gtk.gresource.xml @@ -33,5 +33,6 @@ gtkrecentchooserdefault.ui gtkscalebutton.ui gtkstatusbar.ui + gtkvolumebutton.ui diff --git a/gtk/gtkvolumebutton.c b/gtk/gtkvolumebutton.c index ceb64721f5..f05aa548c9 100644 --- a/gtk/gtkvolumebutton.c +++ b/gtk/gtkvolumebutton.c @@ -135,6 +135,7 @@ static void gtk_volume_button_class_init (GtkVolumeButtonClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); gobject_class->set_property = gtk_volume_button_set_property; gobject_class->get_property = gtk_volume_button_get_property; @@ -156,51 +157,24 @@ gtk_volume_button_class_init (GtkVolumeButtonClass *klass) P_("Whether to use symbolic icons"), FALSE, G_PARAM_READWRITE)); + + /* Bind class to template + */ + gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/gtkvolumebutton.ui"); + gtk_widget_class_bind_callback (widget_class, cb_query_tooltip); + gtk_widget_class_bind_callback (widget_class, cb_value_changed); } static void gtk_volume_button_init (GtkVolumeButton *button) { - GtkScaleButton *sbutton = GTK_SCALE_BUTTON (button); - GtkAdjustment *adj; - GtkWidget *minus_button, *plus_button; + GtkWidget *widget = GTK_WIDGET (button); - atk_object_set_name (gtk_widget_get_accessible (GTK_WIDGET (button)), - _("Volume")); - atk_object_set_description (gtk_widget_get_accessible (GTK_WIDGET (button)), - _("Turns volume down or up")); - atk_action_set_description (ATK_ACTION (gtk_widget_get_accessible (GTK_WIDGET (button))), - 1, - _("Adjusts the volume")); + gtk_widget_init_template (widget); - minus_button = gtk_scale_button_get_minus_button (sbutton); - plus_button = gtk_scale_button_get_plus_button (sbutton); - - atk_object_set_name (gtk_widget_get_accessible (minus_button), - _("Volume Down")); - atk_object_set_description (gtk_widget_get_accessible (minus_button), - _("Decreases the volume")); - gtk_widget_set_tooltip_text (minus_button, _("Volume Down")); - - atk_object_set_name (gtk_widget_get_accessible (plus_button), - _("Volume Up")); - atk_object_set_description (gtk_widget_get_accessible (plus_button), - _("Increases the volume")); - gtk_widget_set_tooltip_text (plus_button, _("Volume Up")); - - gtk_scale_button_set_icons (sbutton, (const char **) icons); - - adj = gtk_adjustment_new (0., 0., 1., 0.02, 0.2, 0.); - g_object_set (G_OBJECT (button), - "adjustment", adj, - "size", GTK_ICON_SIZE_SMALL_TOOLBAR, - "has-tooltip", TRUE, - NULL); - - g_signal_connect (G_OBJECT (button), "query-tooltip", - G_CALLBACK (cb_query_tooltip), NULL); - g_signal_connect (G_OBJECT (button), "value-changed", - G_CALLBACK (cb_value_changed), NULL); + /* The atk action description is not supported by GtkBuilder */ + atk_action_set_description (ATK_ACTION (gtk_widget_get_accessible (GTK_WIDGET (widget))), + 1, _("Adjusts the volume")); } /** diff --git a/gtk/gtkvolumebutton.ui b/gtk/gtkvolumebutton.ui new file mode 100644 index 0000000000..4c253a3050 --- /dev/null +++ b/gtk/gtkvolumebutton.ui @@ -0,0 +1,61 @@ + + + + + 1 + 0.02 + 0.20000000000000001 + + + diff --git a/gtk/tests/templates.c b/gtk/tests/templates.c index e666c1ce5c..32c1e68080 100644 --- a/gtk/tests/templates.c +++ b/gtk/tests/templates.c @@ -124,6 +124,16 @@ test_scale_button_basic (void) gtk_widget_destroy (widget); } +static void +test_volume_button_basic (void) +{ + GtkWidget *widget; + + widget = gtk_volume_button_new (); + g_assert (GTK_IS_VOLUME_BUTTON (widget)); + gtk_widget_destroy (widget); +} + static void test_statusbar_basic (void) { @@ -327,6 +337,7 @@ main (int argc, char **argv) g_test_add_func ("/Template/GtkLockButton/Basic", test_lock_button_basic); g_test_add_func ("/Template/GtkAssistant/Basic", test_assistant_basic); g_test_add_func ("/Template/GtkScaleButton/Basic", test_scale_button_basic); + g_test_add_func ("/Template/GtkVolumeButton/Basic", test_volume_button_basic); 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);