|
Packit Service |
fb6fa5 |
/* GTK - The GIMP Toolkit
|
|
Packit Service |
fb6fa5 |
* Copyright (C) 2007 Red Hat, Inc.
|
|
Packit Service |
fb6fa5 |
*
|
|
Packit Service |
fb6fa5 |
* Authors:
|
|
Packit Service |
fb6fa5 |
* - Bastien Nocera <bnocera@redhat.com>
|
|
Packit Service |
fb6fa5 |
*
|
|
Packit Service |
fb6fa5 |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
fb6fa5 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
fb6fa5 |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
fb6fa5 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit Service |
fb6fa5 |
*
|
|
Packit Service |
fb6fa5 |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
fb6fa5 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
fb6fa5 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
fb6fa5 |
* Lesser General Public License for more details.
|
|
Packit Service |
fb6fa5 |
*
|
|
Packit Service |
fb6fa5 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
fb6fa5 |
* License along with this library; if not, write to the
|
|
Packit Service |
fb6fa5 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
Packit Service |
fb6fa5 |
* Boston, MA 02111-1307, USA.
|
|
Packit Service |
fb6fa5 |
*/
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/*
|
|
Packit Service |
fb6fa5 |
* Modified by the GTK+ Team and others 2007. See the AUTHORS
|
|
Packit Service |
fb6fa5 |
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
Packit Service |
fb6fa5 |
* files for a list of changes. These files are distributed with
|
|
Packit Service |
fb6fa5 |
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
|
Packit Service |
fb6fa5 |
*/
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
#include "config.h"
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
#include "gtkvolumebutton.h"
|
|
Packit Service |
fb6fa5 |
#include "gtkstock.h"
|
|
Packit Service |
fb6fa5 |
#include "gtktooltip.h"
|
|
Packit Service |
fb6fa5 |
#include "gtkintl.h"
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
#include "gtkalias.h"
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/**
|
|
Packit Service |
fb6fa5 |
* SECTION:gtkvolumebutton
|
|
Packit Service |
fb6fa5 |
* @Short_description: A button which pops up a volume control
|
|
Packit Service |
fb6fa5 |
* @Title: GtkVolumeButton
|
|
Packit Service |
fb6fa5 |
*
|
|
Packit Service |
fb6fa5 |
* #GtkVolumeButton is a subclass of #GtkScaleButton that has
|
|
Packit Service |
fb6fa5 |
* been tailored for use as a volume control widget with suitable
|
|
Packit Service |
fb6fa5 |
* icons, tooltips and accessible labels.
|
|
Packit Service |
fb6fa5 |
*/
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
#define EPSILON (1e-10)
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
static gboolean cb_query_tooltip (GtkWidget *button,
|
|
Packit Service |
fb6fa5 |
gint x,
|
|
Packit Service |
fb6fa5 |
gint y,
|
|
Packit Service |
fb6fa5 |
gboolean keyboard_mode,
|
|
Packit Service |
fb6fa5 |
GtkTooltip *tooltip,
|
|
Packit Service |
fb6fa5 |
gpointer user_data);
|
|
Packit Service |
fb6fa5 |
static void cb_value_changed (GtkVolumeButton *button,
|
|
Packit Service |
fb6fa5 |
gdouble value,
|
|
Packit Service |
fb6fa5 |
gpointer user_data);
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
G_DEFINE_TYPE (GtkVolumeButton, gtk_volume_button, GTK_TYPE_SCALE_BUTTON)
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
static void
|
|
Packit Service |
fb6fa5 |
gtk_volume_button_class_init (GtkVolumeButtonClass *klass)
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
static void
|
|
Packit Service |
fb6fa5 |
gtk_volume_button_init (GtkVolumeButton *button)
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
GtkScaleButton *sbutton = GTK_SCALE_BUTTON (button);
|
|
Packit Service |
fb6fa5 |
GtkObject *adj;
|
|
Packit Service |
fb6fa5 |
const char *icons[] = {
|
|
Packit Service |
fb6fa5 |
"audio-volume-muted",
|
|
Packit Service |
fb6fa5 |
"audio-volume-high",
|
|
Packit Service |
fb6fa5 |
"audio-volume-low",
|
|
Packit Service |
fb6fa5 |
"audio-volume-medium",
|
|
Packit Service |
fb6fa5 |
NULL
|
|
Packit Service |
fb6fa5 |
};
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
atk_object_set_name (gtk_widget_get_accessible (GTK_WIDGET (button)),
|
|
Packit Service |
fb6fa5 |
_("Volume"));
|
|
Packit Service |
fb6fa5 |
atk_object_set_description (gtk_widget_get_accessible (GTK_WIDGET (button)),
|
|
Packit Service |
fb6fa5 |
_("Turns volume down or up"));
|
|
Packit Service |
fb6fa5 |
atk_action_set_description (ATK_ACTION (gtk_widget_get_accessible (GTK_WIDGET (button))),
|
|
Packit Service |
fb6fa5 |
1,
|
|
Packit Service |
fb6fa5 |
_("Adjusts the volume"));
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
atk_object_set_name (gtk_widget_get_accessible (sbutton->minus_button),
|
|
Packit Service |
fb6fa5 |
_("Volume Down"));
|
|
Packit Service |
fb6fa5 |
atk_object_set_description (gtk_widget_get_accessible (sbutton->minus_button),
|
|
Packit Service |
fb6fa5 |
_("Decreases the volume"));
|
|
Packit Service |
fb6fa5 |
gtk_widget_set_tooltip_text (sbutton->minus_button, _("Volume Down"));
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
atk_object_set_name (gtk_widget_get_accessible (sbutton->plus_button),
|
|
Packit Service |
fb6fa5 |
_("Volume Up"));
|
|
Packit Service |
fb6fa5 |
atk_object_set_description (gtk_widget_get_accessible (sbutton->plus_button),
|
|
Packit Service |
fb6fa5 |
_("Increases the volume"));
|
|
Packit Service |
fb6fa5 |
gtk_widget_set_tooltip_text (sbutton->plus_button, _("Volume Up"));
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
gtk_scale_button_set_icons (sbutton, icons);
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
adj = gtk_adjustment_new (0., 0., 1., 0.02, 0.2, 0.);
|
|
Packit Service |
fb6fa5 |
g_object_set (G_OBJECT (button),
|
|
Packit Service |
fb6fa5 |
"adjustment", adj,
|
|
Packit Service |
fb6fa5 |
"size", GTK_ICON_SIZE_SMALL_TOOLBAR,
|
|
Packit Service |
fb6fa5 |
"has-tooltip", TRUE,
|
|
Packit Service |
fb6fa5 |
NULL);
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
g_signal_connect (G_OBJECT (button), "query-tooltip",
|
|
Packit Service |
fb6fa5 |
G_CALLBACK (cb_query_tooltip), NULL);
|
|
Packit Service |
fb6fa5 |
g_signal_connect (G_OBJECT (button), "value-changed",
|
|
Packit Service |
fb6fa5 |
G_CALLBACK (cb_value_changed), NULL);
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/**
|
|
Packit Service |
fb6fa5 |
* gtk_volume_button_new
|
|
Packit Service |
fb6fa5 |
*
|
|
Packit Service |
fb6fa5 |
* Creates a #GtkVolumeButton, with a range between 0.0 and 1.0, with
|
|
Packit Service |
fb6fa5 |
* a stepping of 0.02. Volume values can be obtained and modified using
|
|
Packit Service |
fb6fa5 |
* the functions from #GtkScaleButton.
|
|
Packit Service |
fb6fa5 |
*
|
|
Packit Service |
fb6fa5 |
* Return value: a new #GtkVolumeButton
|
|
Packit Service |
fb6fa5 |
*
|
|
Packit Service |
fb6fa5 |
* Since: 2.12
|
|
Packit Service |
fb6fa5 |
*/
|
|
Packit Service |
fb6fa5 |
GtkWidget *
|
|
Packit Service |
fb6fa5 |
gtk_volume_button_new (void)
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
GObject *button;
|
|
Packit Service |
fb6fa5 |
button = g_object_new (GTK_TYPE_VOLUME_BUTTON, NULL);
|
|
Packit Service |
fb6fa5 |
return GTK_WIDGET (button);
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
static gboolean
|
|
Packit Service |
fb6fa5 |
cb_query_tooltip (GtkWidget *button,
|
|
Packit Service |
fb6fa5 |
gint x,
|
|
Packit Service |
fb6fa5 |
gint y,
|
|
Packit Service |
fb6fa5 |
gboolean keyboard_mode,
|
|
Packit Service |
fb6fa5 |
GtkTooltip *tooltip,
|
|
Packit Service |
fb6fa5 |
gpointer user_data)
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
GtkScaleButton *scale_button = GTK_SCALE_BUTTON (button);
|
|
Packit Service |
fb6fa5 |
GtkAdjustment *adj;
|
|
Packit Service |
fb6fa5 |
gdouble val;
|
|
Packit Service |
fb6fa5 |
char *str;
|
|
Packit Service |
fb6fa5 |
AtkImage *image;
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
image = ATK_IMAGE (gtk_widget_get_accessible (button));
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
adj = gtk_scale_button_get_adjustment (scale_button);
|
|
Packit Service |
fb6fa5 |
val = gtk_scale_button_get_value (scale_button);
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
if (val < (adj->lower + EPSILON))
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
str = g_strdup (_("Muted"));
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
else if (val >= (adj->upper - EPSILON))
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
str = g_strdup (_("Full Volume"));
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
else
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
int percent;
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
percent = (int) (100. * val / (adj->upper - adj->lower) + .5);
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/* Translators: this is the percentage of the current volume,
|
|
Packit Service |
fb6fa5 |
* as used in the tooltip, eg. "49 %".
|
|
Packit Service |
fb6fa5 |
* Translate the "%d" to "%Id" if you want to use localised digits,
|
|
Packit Service |
fb6fa5 |
* or otherwise translate the "%d" to "%d".
|
|
Packit Service |
fb6fa5 |
*/
|
|
Packit Service |
fb6fa5 |
str = g_strdup_printf (C_("volume percentage", "%d %%"), percent);
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
gtk_tooltip_set_text (tooltip, str);
|
|
Packit Service |
fb6fa5 |
atk_image_set_image_description (image, str);
|
|
Packit Service |
fb6fa5 |
g_free (str);
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
return TRUE;
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
static void
|
|
Packit Service |
fb6fa5 |
cb_value_changed (GtkVolumeButton *button, gdouble value, gpointer user_data)
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
gtk_widget_trigger_tooltip_query (GTK_WIDGET (button));
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
#define __GTK_VOLUME_BUTTON_C__
|
|
Packit Service |
fb6fa5 |
#include "gtkaliasdef.c"
|