]> Pileus Git - ~andy/gtk/commitdiff
Add the GtkVolumeButton widget, a button that pops up a scale when clicked
authorBastien Nocera <hadess@hadess.net>
Sat, 19 May 2007 23:35:00 +0000 (23:35 +0000)
committerBastien Nocera <hadess@src.gnome.org>
Sat, 19 May 2007 23:35:00 +0000 (23:35 +0000)
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-20  Bastien Nocera  <hadess@hadess.net>

* POTFILES.in: Add volume button to the list

2007-05-20  Bastien Nocera  <hadess@hadess.net>

        * gtk/gtk-sections.txt: Add the GtkVolumeButton widget
to the docs

svn path=/trunk/; revision=17877

12 files changed:
ChangeLog
docs/reference/ChangeLog
docs/reference/gtk/gtk-sections.txt
gtk/Makefile.am
gtk/gtk.h
gtk/gtk.symbols
gtk/gtkvolumebutton.c [new file with mode: 0644]
gtk/gtkvolumebutton.h [new file with mode: 0644]
po/ChangeLog
po/POTFILES.in
tests/Makefile.am
tests/testvolumebutton.c [new file with mode: 0644]

index f077076e40bed96ec75d3fcd0956e1a912fa7419..e1408063164fcc3ecb8e1af22851d4c6c6dc782e 100644 (file)
--- 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>
index acf974319dd57acbf19a7fae23f3c383cc0ecf64..110a07daaa23b9fea78eff92f8976fdb918d1c8e 100644 (file)
@@ -1,3 +1,8 @@
+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:
index 044e64711f54d6014aa939ddfd5b0a4614a0af75..13a37c5d0efb4a0ebe1ccc95c44d20080d109bde 100644 (file)
@@ -4871,6 +4871,20 @@ GTK_VIEWPORT_GET_CLASS
 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>
index 0f514e80a893d37bd25606a7403655bf337ec5fd..c35c83423ec33ed3726fb3af2fd69801fb3c102e 100644 (file)
@@ -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             \
index d0ab19586f2a9df963cc8c1ba0c2f3d17da50e56..1e9436fb5f6d5f69bbcb040384b5684ac60a4d05 100644 (file)
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
 #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>
index 3bcd95b425a886bf71f67e492f16cbc64a1d1179..1d398d2ed1a5363bd0be29c5d73b7cf1247d1402 100644 (file)
@@ -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 (file)
index 0000000..d913997
--- /dev/null
@@ -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 (file)
index 0000000..069c122
--- /dev/null
@@ -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__ */
+
index f8c199b9a0f53b36510b98a96f4ab7efde3dbe6a..ef3bab2dc9f3d764c24b84976104e37f17476b20 100644 (file)
@@ -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
index dead7900288860c5f6bb162fc7b29f0417946aff..195b8a07fbad3d559735cbe21afb777d843c6346 100644 (file)
@@ -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
index 8aafd1ae67bcbc8b5847d7141517418c0e49678e..0f2a739ebaa15a85250c69cbede8b755b94eb013 100644 (file)
@@ -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 (file)
index 0000000..3e316eb
--- /dev/null
@@ -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;
+}
+