1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2007 Red Hat, Inc.
5 * - Bastien Nocera <bnocera@redhat.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * Modified by the GTK+ Team and others 2007. See the AUTHORS
25 * file for a list of people on the GTK+ Team. See the ChangeLog
26 * files for a list of changes. These files are distributed with
27 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
34 #include "gtkvolumebutton.h"
36 #include "gtktooltip.h"
41 #define EPSILON (1e-10)
43 struct _GtkVolumeButton
45 GtkScaleButton parent;
48 static void gtk_volume_button_class_init (GtkVolumeButtonClass *klass);
49 static void gtk_volume_button_init (GtkVolumeButton *button);
50 static gboolean cb_query_tooltip (GtkWidget *button,
53 gboolean keyboard_mode,
56 static void cb_value_changed (GtkVolumeButton *button,
60 G_DEFINE_TYPE (GtkVolumeButton, gtk_volume_button, GTK_TYPE_SCALE_BUTTON)
63 gtk_volume_button_class_init (GtkVolumeButtonClass *klass)
68 gtk_volume_button_init (GtkVolumeButton *button)
70 GtkScaleButton *sbutton = GTK_SCALE_BUTTON (button);
72 const char *icons[] = {
76 "audio-volume-medium",
80 atk_object_set_name (gtk_widget_get_accessible (GTK_WIDGET (button)),
82 atk_object_set_name (gtk_widget_get_accessible (sbutton->minus_button),
84 atk_object_set_name (gtk_widget_get_accessible (sbutton->plus_button),
87 gtk_scale_button_set_icons (sbutton, icons);
89 adj = gtk_adjustment_new (0., 0., 1., 0.02, 0.2, 0.);
90 g_object_set (G_OBJECT (button),
92 "size", GTK_ICON_SIZE_SMALL_TOOLBAR,
96 g_signal_connect (G_OBJECT (button), "query-tooltip",
97 G_CALLBACK (cb_query_tooltip), NULL);
98 g_signal_connect (G_OBJECT (button), "value-changed",
99 G_CALLBACK (cb_value_changed), NULL);
103 * gtk_volume_button_new
105 * Creates a #GtkVolumeButton, with a range between 0.0 and 1.0, with
106 * a stepping of 0.02. Volume values can be obtained and modified using
107 * the functions from #GtkScaleButton.
109 * Return value: a new #GtkVolumeButton
114 gtk_volume_button_new (void)
117 button = g_object_new (GTK_TYPE_VOLUME_BUTTON, NULL);
118 return GTK_WIDGET (button);
122 cb_query_tooltip (GtkWidget *button,
125 gboolean keyboard_mode,
129 GtkScaleButton *scale_button = GTK_SCALE_BUTTON (button);
134 adj = gtk_scale_button_get_adjustment (scale_button);
135 val = gtk_scale_button_get_value (scale_button);
137 if (val < (adj->lower + EPSILON))
139 str = g_strdup (_("Muted"));
141 else if (val >= (adj->upper - EPSILON))
143 str = g_strdup (_("Full Volume"));
149 percent = (int) (100. * val / (adj->upper - adj->lower) + .5);
151 /* Translators: this is the percentage of the current volume,
152 * as used in the tooltip, eg. "49 %".
153 * Translate the "%d" to "%Id" if you want to use localised digits,
154 * or otherwise translate the "%d" to "%d".
155 * Do not translate and do not include the "volume percentage|"
156 * part in the translation!
158 str = g_strdup_printf (Q_("volume percentage|%d %%"), percent);
161 gtk_tooltip_set_text (tooltip, str);
168 cb_value_changed (GtkVolumeButton *button, gdouble value, gpointer user_data)
170 gtk_widget_trigger_tooltip_query (GTK_WIDGET (button));
174 #define __GTK_VOLUME_BUTTON_C__
175 #include "gtkaliasdef.c"