+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>
+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_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>
gtkvbbox.h \
gtkvbox.h \
gtkviewport.h \
+ gtkvolumebutton.h \
gtkvpaned.h \
gtkvruler.h \
gtkvscale.h \
gtkuimanager.c \
gtkvbbox.c \
gtkvbox.c \
+ gtkvolumebutton.c \
gtkviewport.c \
gtkvpaned.c \
gtkvruler.c \
#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>
#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
--- /dev/null
+/* 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
+ */
--- /dev/null
+/* 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__ */
+
+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
gtk/gtkvbox.c
gtk/gtkwidget.c
gtk/gtkviewport.c
+gtk/gtkvolumebutton.c
gtk/gtkwindow.c
gtk/gtkwindow-decorate.c
gtk/gtkvpaned.c
testmerge \
testactions \
testgrouping \
- testtooltips
+ testtooltips \
+ testvolumebutton
autotestfilechooser_DEPENDENCIES = $(TEST_DEPS)
simple_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)
testactions_LDADD = $(LDADDS)
testgrouping_LDADD = $(LDADDS)
testtooltips_LDADD = $(LDADDS)
+testvolumebutton_LDADD = $(LDADDS)
autotestfilechooser_SOURCES = \
autotestfilechooser.c
testrecentchoosermenu_SOURCES = \
testrecentchoosermenu.c
+testvolumebutton_SOURCES = \
+ testvolumebutton.c
+
EXTRA_DIST = \
prop-editor.h \
testgtk.1 \
--- /dev/null
+/* 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;
+}
+