summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--docs/reference/ChangeLog5
-rw-r--r--docs/reference/gtk/gtk-sections.txt14
-rw-r--r--gtk/Makefile.am2
-rw-r--r--gtk/gtk.h1
-rw-r--r--gtk/gtk.symbols11
-rw-r--r--gtk/gtkvolumebutton.c176
-rw-r--r--gtk/gtkvolumebutton.h64
-rw-r--r--po/ChangeLog4
-rw-r--r--po/POTFILES.in1
-rw-r--r--tests/Makefile.am8
-rw-r--r--tests/testvolumebutton.c81
12 files changed, 370 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index f077076e40..e140806316 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-05-20 Bastien Nocera <hadess@hadess.net>
+
+ * gtk/Makefile.am:
+ * gtk/gtk.h:
+ * gtk/gtk.symbols:
+ * gtk/gtkvolumebutton.[ch]: Add the GtkVolumeButton widget,
+ a button that pops up a scale when clicked (Closes: #415775)
+ * tests/Makefile.am:
+ * tests/testvolumebutton.c: Add a test program for the
+ volume button
+
2007-05-19 Bastien Nocera <hadess@hadess.net>
reviewed by: Matthias Clasen <mclasen@redhat.com>
diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog
index acf974319d..110a07daaa 100644
--- a/docs/reference/ChangeLog
+++ b/docs/reference/ChangeLog
@@ -1,5 +1,10 @@
2007-05-20 Bastien Nocera <hadess@hadess.net>
+ * gtk/gtk-sections.txt: Add the GtkVolumeButton widget
+ to the docs
+
+2007-05-20 Bastien Nocera <hadess@hadess.net>
+
* gtk/gtk-docs.sgml:
* gtk/gtk-sections.txt: add the GtkScaleButton widget
to the docs
diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt
index 044e64711f..13a37c5d0e 100644
--- a/docs/reference/gtk/gtk-sections.txt
+++ b/docs/reference/gtk/gtk-sections.txt
@@ -4872,6 +4872,20 @@ gtk_viewport_get_type
</SECTION>
<SECTION>
+<FILE>gtkvolumebutton</FILE>
+<TITLE>GtkVolumeButton</TITLE>
+GtkVolumeButton
+gtk_volume_button_new
+<SUBSECTION Standard>
+GTK_VOLUME_BUTTON
+GTK_IS_VOLUME_BUTTON
+GTK_TYPE_VOLUME_BUTTON
+GTK_VOLUME_BUTTON_GET_CLASS
+<SUBSECTION Private>
+gtk_volume_button_get_type
+</SECTION>
+
+<SECTION>
<FILE>gtkvpaned</FILE>
<TITLE>GtkVPaned</TITLE>
GtkVPaned
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 0f514e80a8..c35c83423e 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -312,6 +312,7 @@ gtk_public_h_sources = \
gtkvbbox.h \
gtkvbox.h \
gtkviewport.h \
+ gtkvolumebutton.h \
gtkvpaned.h \
gtkvruler.h \
gtkvscale.h \
@@ -595,6 +596,7 @@ gtk_base_c_sources = \
gtkuimanager.c \
gtkvbbox.c \
gtkvbox.c \
+ gtkvolumebutton.c \
gtkviewport.c \
gtkvpaned.c \
gtkvruler.c \
diff --git a/gtk/gtk.h b/gtk/gtk.h
index d0ab19586f..1e9436fb5f 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -197,6 +197,7 @@
#include <gtk/gtkvbox.h>
#include <gtk/gtkversion.h>
#include <gtk/gtkviewport.h>
+#include <gtk/gtkvolumebutton.h>
#include <gtk/gtkvpaned.h>
#include <gtk/gtkvruler.h>
#include <gtk/gtkvscale.h>
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index 3bcd95b425..1d398d2ed1 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -4474,13 +4474,10 @@ gtk_viewport_set_vadjustment
#endif
#endif
-#if IN_HEADER(__GTK_SCALE_BUTTON_H__)
-#if IN_FILE(__GTK_SCALE_BUTTON_C__)
-gtk_scale_button_get_type G_GNUC_CONST
-gtk_scale_button_get_value
-gtk_scale_button_new
-gtk_scale_button_set_icons
-gtk_scale_button_set_value
+#if IN_HEADER(__GTK_VOLUME_BUTTON_H__)
+#if IN_FILE(__GTK_VOLUME_BUTTON_C__)
+gtk_volume_button_get_type G_GNUC_CONST
+gtk_volume_button_new
#endif
#endif
diff --git a/gtk/gtkvolumebutton.c b/gtk/gtkvolumebutton.c
new file mode 100644
index 0000000000..d913997179
--- /dev/null
+++ b/gtk/gtkvolumebutton.c
@@ -0,0 +1,176 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2007 Red Hat, Inc.
+ *
+ * Authors:
+ * - Bastien Nocera <bnocera@redhat.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 2007. See the AUTHORS
+ * file for a list of people on the GTK+ Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#include <config.h>
+
+#include <glib/gi18n.h>
+#include <atk/atk.h>
+
+#include "gtkvolumebutton.h"
+#include "gtktooltips.h"
+#include "gtkstock.h"
+
+struct _GtkVolumeButton
+{
+ GtkScaleButton parent;
+ GtkTooltips *tooltips;
+};
+
+static void gtk_volume_button_class_init (GtkVolumeButtonClass *klass);
+static void gtk_volume_button_init (GtkVolumeButton *button);
+static void gtk_volume_button_dispose (GObject *object);
+static void gtk_volume_button_update_tooltip(GtkVolumeButton *button);
+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
+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;
+}
+
+static void
+gtk_volume_button_init (GtkVolumeButton *button)
+{
+ GtkScaleButton *sbutton = GTK_SCALE_BUTTON (button);
+ GtkObject *adj;
+ const char *icons[] = {
+ "audio-volume-muted",
+ "audio-volume-high",
+ "audio-volume-low",
+ "audio-volume-medium",
+ NULL
+ };
+
+ atk_object_set_name (gtk_widget_get_accessible (GTK_WIDGET (button)),
+ _("Volume"));
+ atk_object_set_name (gtk_widget_get_accessible (sbutton->minus_button),
+ _("Volume Down"));
+ atk_object_set_name (gtk_widget_get_accessible (sbutton->plus_button),
+ _("Volume Up"));
+
+ gtk_scale_button_set_icons (sbutton, icons);
+
+ adj = gtk_adjustment_new (0, 0, 100, 2, 10 * 2, 0);
+ g_object_set (G_OBJECT (button),
+ "adjustment", adj,
+ "size", GTK_ICON_SIZE_SMALL_TOOLBAR,
+ NULL);
+
+ button->tooltips = gtk_tooltips_new ();
+ g_object_ref_sink (button->tooltips);
+ gtk_volume_button_update_tooltip (button);
+
+ g_signal_connect (G_OBJECT (button), "value-changed",
+ G_CALLBACK (cb_value_changed), NULL);
+}
+
+static void
+gtk_volume_button_dispose (GObject *object)
+{
+ GtkVolumeButton *button;
+
+ button = GTK_VOLUME_BUTTON (object);
+
+ if (button->tooltips)
+ g_object_unref (button->tooltips);
+ button->tooltips = NULL;
+
+ G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+/**
+ * gtk_volume_button_new
+ *
+ * Creates a #GtkVolumeButton, with a range between 0 and 100, with
+ * a stepping of 2. Volume values can be obtained and modified using
+ * the functions from #GtkScaleButton.
+ *
+ * Return value: a new #GtkVolumeButton
+ *
+ * Since: 2.12
+ */
+GtkWidget *
+gtk_volume_button_new (void)
+{
+ GObject *button;
+ button = g_object_new (GTK_TYPE_VOLUME_BUTTON, NULL);
+ return GTK_WIDGET (button);
+}
+
+static void
+gtk_volume_button_update_tooltip (GtkVolumeButton *button)
+{
+ gdouble val;
+ char *str;
+
+ val = gtk_scale_button_get_value (GTK_SCALE_BUTTON (button));
+
+ if (val == 0.0)
+ {
+ str = g_strdup (_("Muted"));
+ }
+ else if (val == 100.0)
+ {
+ str = g_strdup (_("Full Volume"));
+ }
+ else
+ {
+ 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 | */
+ str = g_strdup_printf (Q_("volume percentage|%d %%"), percent);
+ }
+
+ gtk_tooltips_set_tip (button->tooltips,
+ GTK_WIDGET (button),
+ str, NULL);
+ g_free (str);
+}
+
+static void
+cb_value_changed (GtkVolumeButton *button, gdouble value, gpointer user_data)
+{
+ gtk_volume_button_update_tooltip (button);
+}
+
+/*
+ * vim: sw=2 ts=8 cindent noai bs=2
+ */
diff --git a/gtk/gtkvolumebutton.h b/gtk/gtkvolumebutton.h
new file mode 100644
index 0000000000..069c1228a6
--- /dev/null
+++ b/gtk/gtkvolumebutton.h
@@ -0,0 +1,64 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2007 Red Hat, Inc.
+ *
+ * Authors:
+ * - Bastien Nocera <bnocera@redhat.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 2007. See the AUTHORS
+ * file for a list of people on the GTK+ Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#ifndef __GTK_VOLUME_BUTTON_H__
+#define __GTK_VOLUME_BUTTON_H__
+
+#include <gtk/gtkscalebutton.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_VOLUME_BUTTON (gtk_volume_button_get_type ())
+#define GTK_VOLUME_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_VOLUME_BUTTON, GtkVolumeButton))
+#define GTK_VOLUME_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_VOLUME_BUTTON, GtkVolumeeButtonClass))
+#define GTK_IS_VOLUME_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_VOLUME_BUTTON))
+#define GTK_IS_VOLUME_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_VOLUME_BUTTON))
+#define GTK_VOLUME_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_VOLUME_BUTTON, GtkVolumeButtonClass))
+
+typedef struct _GtkVolumeButton GtkVolumeButton;
+typedef struct _GtkVolumeButtonClass GtkVolumeButtonClass;
+
+struct _GtkVolumeButtonClass
+{
+ GtkScaleButtonClass parent_class;
+
+ /* Padding for future expansion */
+ void (*_gtk_reserved1) (void);
+ void (*_gtk_reserved2) (void);
+ void (*_gtk_reserved3) (void);
+ void (*_gtk_reserved4) (void);
+};
+
+GType gtk_volume_button_get_type (void) G_GNUC_CONST;
+GtkWidget* gtk_volume_button_new (void);
+
+G_END_DECLS
+
+#endif /* __GTK_VOLUME_BUTTON_H__ */
+
diff --git a/po/ChangeLog b/po/ChangeLog
index f8c199b9a0..ef3bab2dc9 100644
--- a/po/ChangeLog
+++ b/po/ChangeLog
@@ -1,3 +1,7 @@
+2007-05-20 Bastien Nocera <hadess@hadess.net>
+
+ * POTFILES.in: Add volume button to the list
+
2007-05-19 Bastien Nocera <hadess@hadess.net>
* POTFILES.in: Add scale button to the list
diff --git a/po/POTFILES.in b/po/POTFILES.in
index dead790028..195b8a07fb 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -229,6 +229,7 @@ gtk/gtkvbbox.c
gtk/gtkvbox.c
gtk/gtkwidget.c
gtk/gtkviewport.c
+gtk/gtkvolumebutton.c
gtk/gtkwindow.c
gtk/gtkwindow-decorate.c
gtk/gtkvpaned.c
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8aafd1ae67..0f2a739eba 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -85,7 +85,8 @@ noinst_PROGRAMS = \
testmerge \
testactions \
testgrouping \
- testtooltips
+ testtooltips \
+ testvolumebutton
autotestfilechooser_DEPENDENCIES = $(TEST_DEPS)
simple_DEPENDENCIES = $(TEST_DEPS)
@@ -140,6 +141,7 @@ testmerge_DEPENDENCIES = $(TEST_DEPS)
testactions_DEPENDENCIES = $(TEST_DEPS)
testgrouping_DEPENDENCIES = $(TEST_DEPS)
testtooltips_DEPENDENCIES = $(TEST_DEPS)
+testvolumebutton_DEPENDENCIES = $(TEST_DEPS)
autotestfilechooser_LDADD = $(LDADDS)
simple_LDADD = $(LDADDS)
@@ -201,6 +203,7 @@ testmerge_LDADD = $(LDADDS)
testactions_LDADD = $(LDADDS)
testgrouping_LDADD = $(LDADDS)
testtooltips_LDADD = $(LDADDS)
+testvolumebutton_LDADD = $(LDADDS)
autotestfilechooser_SOURCES = \
autotestfilechooser.c
@@ -285,6 +288,9 @@ testtooltips_SOURCES = \
testrecentchoosermenu_SOURCES = \
testrecentchoosermenu.c
+testvolumebutton_SOURCES = \
+ testvolumebutton.c
+
EXTRA_DIST = \
prop-editor.h \
testgtk.1 \
diff --git a/tests/testvolumebutton.c b/tests/testvolumebutton.c
new file mode 100644
index 0000000000..3e316ebd21
--- /dev/null
+++ b/tests/testvolumebutton.c
@@ -0,0 +1,81 @@
+/* testvolumebutton.c
+ * Copyright (C) 2007 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gtk/gtk.h>
+
+static void
+value_changed (GtkWidget *button,
+ gdouble volume,
+ gpointer user_data)
+{
+ g_message ("volume changed to %f", volume);
+}
+
+static void
+response_cb (GtkDialog *dialog,
+ gint arg1,
+ gpointer user_data)
+{
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+static gboolean
+show_error (gpointer data)
+{
+ GtkWindow *window = (GtkWindow *) data;
+ GtkWidget *dialog;
+
+ g_message ("showing error");
+
+ dialog = gtk_message_dialog_new (window,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_CLOSE,
+ "This should have unbroken the grab");
+ g_signal_connect (G_OBJECT (dialog),
+ "response",
+ G_CALLBACK (response_cb), NULL);
+ gtk_widget_show (dialog);
+
+ return FALSE;
+}
+
+int main (int argc, char **argv)
+{
+ GtkWidget *window;
+ GtkWidget *button;
+
+ gtk_init (&argc, &argv);
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ button = gtk_volume_button_new ();
+ g_signal_connect (G_OBJECT (button),
+ "value-changed",
+ G_CALLBACK (value_changed), NULL);
+ gtk_container_add (GTK_CONTAINER (window), button);
+
+ gtk_widget_show_all (window);
+ gtk_button_clicked (GTK_BUTTON (button));
+ g_timeout_add (4000, (GSourceFunc) show_error, window);
+
+ gtk_main ();
+
+ return 0;
+}
+