GtkVolumeButton: Define children with a GtkBuilder template

This commit is contained in:
Tristan Van Berkom 2013-03-30 18:51:58 +09:00
parent 36bacc4674
commit 92a8c76b31
5 changed files with 87 additions and 39 deletions

View File

@ -1117,7 +1117,8 @@ COMPOSITE_TEMPLATES = \
gtkprintunixdialog.ui \
gtkrecentchooserdefault.ui \
gtkscalebutton.ui \
gtkstatusbar.ui
gtkstatusbar.ui \
gtkvolumebutton.ui
#
# rules to generate built sources

View File

@ -33,5 +33,6 @@
<file compressed="true">gtkrecentchooserdefault.ui</file>
<file compressed="true">gtkscalebutton.ui</file>
<file compressed="true">gtkstatusbar.ui</file>
<file compressed="true">gtkvolumebutton.ui</file>
</gresource>
</gresources>

View File

@ -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"));
}
/**

61
gtk/gtkvolumebutton.ui Normal file
View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="gtk30">
<!-- interface-requires gtk+ 3.6 -->
<object class="GtkAdjustment" id="adjustment">
<property name="upper">1</property>
<property name="step_increment">0.02</property>
<property name="page_increment">0.20000000000000001</property>
</object>
<template class="GtkVolumeButton" parent="GtkScaleButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="has_tooltip">True</property>
<property name="relief">none</property>
<property name="focus_on_click">False</property>
<property name="orientation">vertical</property>
<property name="adjustment">adjustment</property>
<property name="icons">audio-volume-muted
audio-volume-high
audio-volume-low
audio-volume-medium</property>
<child internal-child="accessible">
<object class="AtkObject" id="GtkVolumeButton-atkobject">
<property name="AtkObject::accessible-name" translatable="yes">Volume</property>
<property name="AtkObject::accessible-description" translatable="yes">Turns volume up or down</property>
</object>
</child>
<signal name="query-tooltip" handler="cb_query_tooltip" swapped="no"/>
<signal name="value-changed" handler="cb_value_changed" swapped="no"/>
<child internal-child="plus_button">
<object class="GtkButton" id="scalebutton-plus_button1">
<property name="label" translatable="yes">+</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Volume Up</property>
<property name="relief">none</property>
<child internal-child="accessible">
<object class="AtkObject" id="scalebutton-plus_button1-atkobject">
<property name="AtkObject::accessible-name" translatable="yes">Volume Up</property>
<property name="AtkObject::accessible-description" translatable="yes">Increases the volume</property>
</object>
</child>
</object>
</child>
<child internal-child="minus_button">
<object class="GtkButton" id="scalebutton-minus_button1">
<property name="label" translatable="yes">-</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Volume Down</property>
<property name="relief">none</property>
<child internal-child="accessible">
<object class="AtkObject" id="scalebutton-minus_button1-atkobject">
<property name="AtkObject::accessible-name" translatable="yes">Volume Down</property>
<property name="AtkObject::accessible-description" translatable="yes">Decreases the volume</property>
</object>
</child>
</object>
</child>
</template>
</interface>

View File

@ -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);