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/.
32 #include <glib/gi18n.h>
35 #include "gtkvolumebutton.h"
36 #include "gtktooltips.h"
39 struct _GtkVolumeButton
41 GtkScaleButton parent;
42 GtkTooltips *tooltips;
45 static void gtk_volume_button_class_init (GtkVolumeButtonClass *klass);
46 static void gtk_volume_button_init (GtkVolumeButton *button);
47 static void gtk_volume_button_dispose (GObject *object);
48 static void gtk_volume_button_update_tooltip(GtkVolumeButton *button);
49 static void cb_value_changed (GtkVolumeButton *button,
53 static GtkScaleButtonClass *parent_class = NULL;
55 G_DEFINE_TYPE (GtkVolumeButton, gtk_volume_button, GTK_TYPE_SCALE_BUTTON)
58 gtk_volume_button_class_init (GtkVolumeButtonClass *klass)
60 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
62 parent_class = g_type_class_peek_parent (klass);
63 gobject_class->dispose = gtk_volume_button_dispose;
67 gtk_volume_button_init (GtkVolumeButton *button)
69 GtkScaleButton *sbutton = GTK_SCALE_BUTTON (button);
71 const char *icons[] = {
75 "audio-volume-medium",
79 atk_object_set_name (gtk_widget_get_accessible (GTK_WIDGET (button)),
81 atk_object_set_name (gtk_widget_get_accessible (sbutton->minus_button),
83 atk_object_set_name (gtk_widget_get_accessible (sbutton->plus_button),
86 gtk_scale_button_set_icons (sbutton, icons);
88 adj = gtk_adjustment_new (0, 0, 100, 2, 10 * 2, 0);
89 g_object_set (G_OBJECT (button),
91 "size", GTK_ICON_SIZE_SMALL_TOOLBAR,
94 button->tooltips = gtk_tooltips_new ();
95 g_object_ref_sink (button->tooltips);
96 gtk_volume_button_update_tooltip (button);
98 g_signal_connect (G_OBJECT (button), "value-changed",
99 G_CALLBACK (cb_value_changed), NULL);
103 gtk_volume_button_dispose (GObject *object)
105 GtkVolumeButton *button;
107 button = GTK_VOLUME_BUTTON (object);
109 if (button->tooltips)
110 g_object_unref (button->tooltips);
111 button->tooltips = NULL;
113 G_OBJECT_CLASS (parent_class)->dispose (object);
117 * gtk_volume_button_new
119 * Creates a #GtkVolumeButton, with a range between 0 and 100, with
120 * a stepping of 2. Volume values can be obtained and modified using
121 * the functions from #GtkScaleButton.
123 * Return value: a new #GtkVolumeButton
128 gtk_volume_button_new (void)
131 button = g_object_new (GTK_TYPE_VOLUME_BUTTON, NULL);
132 return GTK_WIDGET (button);
136 gtk_volume_button_update_tooltip (GtkVolumeButton *button)
141 val = gtk_scale_button_get_value (GTK_SCALE_BUTTON (button));
145 str = g_strdup (_("Muted"));
147 else if (val == 100.0)
149 str = g_strdup (_("Full Volume"));
156 /* translators, this is the percentage of the current volume,
157 * as used in the tooltip, eg. "49 %"
158 * do not translate the part before the | */
159 str = g_strdup_printf (Q_("volume percentage|%d %%"), percent);
162 gtk_tooltips_set_tip (button->tooltips,
169 cb_value_changed (GtkVolumeButton *button, gdouble value, gpointer user_data)
171 gtk_volume_button_update_tooltip (button);
175 * vim: sw=2 ts=8 cindent noai bs=2