diff options
author | Christian Persch <chpe@gnome.org> | 2007-06-28 14:32:58 +0000 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2007-06-28 14:32:58 +0000 |
commit | 33a8559784260d77601cf9da5ed6dc3455dfb1ac (patch) | |
tree | f6348f4e59ffeee1f7cbab7486ff9245af321e19 /gtk/gtkvolumebutton.c | |
parent | 8ea696676742660d8d98d434f2cfad1879a428c9 (diff) | |
download | gtk+-33a8559784260d77601cf9da5ed6dc3455dfb1ac.tar.gz |
Make the volume button use range 0.0 to 1.0 by default, and fix tooltips
2007-06-28 Christian Persch <chpe@gnome.org>
* gtk/gtkvolumebutton.c: (gtk_volume_button_class_init),
(gtk_volume_button_init), (gtk_volume_button_dispose),
(gtk_volume_button_update_tooltip): Make the volume button use range
0.0 to 1.0 by default, and fix tooltips code to cope with different ranges.
Bug #354181.
svn path=/trunk/; revision=18279
Diffstat (limited to 'gtk/gtkvolumebutton.c')
-rw-r--r-- | gtk/gtkvolumebutton.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/gtk/gtkvolumebutton.c b/gtk/gtkvolumebutton.c index 52bc9aebb5..41a7373fba 100644 --- a/gtk/gtkvolumebutton.c +++ b/gtk/gtkvolumebutton.c @@ -38,6 +38,7 @@ #include "gtkalias.h" +#define EPSILON (1e-10) struct _GtkVolumeButton { @@ -53,8 +54,6 @@ static void cb_value_changed (GtkVolumeButton *button, gdouble value, gpointer user_data); -static GtkScaleButtonClass *parent_class = NULL; - G_DEFINE_TYPE (GtkVolumeButton, gtk_volume_button, GTK_TYPE_SCALE_BUTTON) static void @@ -62,7 +61,6 @@ gtk_volume_button_class_init (GtkVolumeButtonClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - parent_class = g_type_class_peek_parent (klass); gobject_class->dispose = gtk_volume_button_dispose; } @@ -88,7 +86,7 @@ gtk_volume_button_init (GtkVolumeButton *button) gtk_scale_button_set_icons (sbutton, icons); - adj = gtk_adjustment_new (0, 0, 100, 2, 10 * 2, 0); + 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, @@ -113,7 +111,7 @@ gtk_volume_button_dispose (GObject *object) g_object_unref (button->tooltips); button->tooltips = NULL; - G_OBJECT_CLASS (parent_class)->dispose (object); + G_OBJECT_CLASS (gtk_volume_button_parent_class)->dispose (object); } /** @@ -138,16 +136,19 @@ gtk_volume_button_new (void) static void gtk_volume_button_update_tooltip (GtkVolumeButton *button) { + GtkScaleButton *scale_button = GTK_SCALE_BUTTON (button); + GtkAdjustment *adj; gdouble val; char *str; - val = gtk_scale_button_get_value (GTK_SCALE_BUTTON (button)); + adj = gtk_scale_button_get_adjustment (scale_button); + val = gtk_scale_button_get_value (scale_button); - if (val == 0.0) + if (val < (adj->lower + EPSILON)) { str = g_strdup (_("Muted")); } - else if (val == 100.0) + else if (val >= (adj->upper - EPSILON)) { str = g_strdup (_("Full Volume")); } @@ -155,10 +156,15 @@ gtk_volume_button_update_tooltip (GtkVolumeButton *button) { int percent; - percent = (int) val; - /* translators, this is the percentage of the current volume, - * as used in the tooltip, eg. "49 %" - * do not translate the part before the | */ + percent = (int) (100. * val / (adj->upper - adj->lower) + .5); + + /* Translators: this is the percentage of the current volume, + * as used in the tooltip, eg. "49 %". + * Translate the "%d" to "%Id" if you want to use localised digits, + * or otherwise translate the "%d" to "%d". + * Do not translate and do not include the "volume percentage|" + * part in the translation! + */ str = g_strdup_printf (Q_("volume percentage|%d %%"), percent); } |