forked from AuroraMiddleware/gtk
gtk: Add symbolic property for GtkVolumeButton
When the application prefers symbolic icons, avoids having to reimplement the button in the software itself. https://bugzilla.gnome.org/show_bug.cgi?id=636969
This commit is contained in:
parent
668604dcfd
commit
23c1d1cbc9
@ -47,6 +47,28 @@
|
|||||||
|
|
||||||
#define EPSILON (1e-10)
|
#define EPSILON (1e-10)
|
||||||
|
|
||||||
|
const char * const icons[] =
|
||||||
|
{
|
||||||
|
"audio-volume-muted",
|
||||||
|
"audio-volume-high",
|
||||||
|
"audio-volume-low",
|
||||||
|
"audio-volume-medium",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
const char * const icons_symbolic[] =
|
||||||
|
{
|
||||||
|
"audio-volume-muted-symbolic",
|
||||||
|
"audio-volume-high-symbolic",
|
||||||
|
"audio-volume-low-symbolic",
|
||||||
|
"audio-volume-medium-symbolic",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PROP_0,
|
||||||
|
PROP_SYMBOLIC
|
||||||
|
};
|
||||||
|
|
||||||
static gboolean cb_query_tooltip (GtkWidget *button,
|
static gboolean cb_query_tooltip (GtkWidget *button,
|
||||||
gint x,
|
gint x,
|
||||||
@ -60,9 +82,80 @@ static void cb_value_changed (GtkVolumeButton *button,
|
|||||||
|
|
||||||
G_DEFINE_TYPE (GtkVolumeButton, gtk_volume_button, GTK_TYPE_SCALE_BUTTON)
|
G_DEFINE_TYPE (GtkVolumeButton, gtk_volume_button, GTK_TYPE_SCALE_BUTTON)
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_volume_button_set_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
const GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
GtkScaleButton *button = GTK_SCALE_BUTTON (object);
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_SYMBOLIC:
|
||||||
|
if (g_value_get_boolean (value))
|
||||||
|
gtk_scale_button_set_icons (button, (const char **) icons_symbolic);
|
||||||
|
else
|
||||||
|
gtk_scale_button_set_icons (button, (const char **) icons);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_volume_button_get_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_SYMBOLIC: {
|
||||||
|
char **icon_list;
|
||||||
|
|
||||||
|
g_object_get (object, "icons", &icon_list, NULL);
|
||||||
|
if (icon_list != NULL &&
|
||||||
|
icon_list[0] != NULL &&
|
||||||
|
g_str_equal (icon_list[0], icons_symbolic[0]))
|
||||||
|
g_value_set_boolean (value, TRUE);
|
||||||
|
else
|
||||||
|
g_value_set_boolean (value, FALSE);
|
||||||
|
g_strfreev (icon_list);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_volume_button_class_init (GtkVolumeButtonClass *klass)
|
gtk_volume_button_class_init (GtkVolumeButtonClass *klass)
|
||||||
{
|
{
|
||||||
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||||
|
|
||||||
|
gobject_class->set_property = gtk_volume_button_set_property;
|
||||||
|
gobject_class->get_property = gtk_volume_button_get_property;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GtkVolumeButton:use-symbolic:
|
||||||
|
*
|
||||||
|
* Whether to use symbolic icons as the icons. Note that
|
||||||
|
* if the symbolic icons are not available in your installed
|
||||||
|
* theme, then the normal (potentially colorful) icons will
|
||||||
|
* be used.
|
||||||
|
*
|
||||||
|
* Since: 3.0
|
||||||
|
*/
|
||||||
|
g_object_class_install_property (gobject_class,
|
||||||
|
PROP_SYMBOLIC,
|
||||||
|
g_param_spec_boolean ("use-symbolic",
|
||||||
|
P_("Use symbolic icons"),
|
||||||
|
P_("Whether to use symbolic icons"),
|
||||||
|
FALSE,
|
||||||
|
G_PARAM_READWRITE));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -71,13 +164,6 @@ gtk_volume_button_init (GtkVolumeButton *button)
|
|||||||
GtkScaleButton *sbutton = GTK_SCALE_BUTTON (button);
|
GtkScaleButton *sbutton = GTK_SCALE_BUTTON (button);
|
||||||
GtkAdjustment *adj;
|
GtkAdjustment *adj;
|
||||||
GtkWidget *minus_button, *plus_button;
|
GtkWidget *minus_button, *plus_button;
|
||||||
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)),
|
atk_object_set_name (gtk_widget_get_accessible (GTK_WIDGET (button)),
|
||||||
_("Volume"));
|
_("Volume"));
|
||||||
@ -102,14 +188,14 @@ gtk_volume_button_init (GtkVolumeButton *button)
|
|||||||
_("Increases the volume"));
|
_("Increases the volume"));
|
||||||
gtk_widget_set_tooltip_text (plus_button, _("Volume Up"));
|
gtk_widget_set_tooltip_text (plus_button, _("Volume Up"));
|
||||||
|
|
||||||
gtk_scale_button_set_icons (sbutton, icons);
|
gtk_scale_button_set_icons (sbutton, (const char **) icons);
|
||||||
|
|
||||||
adj = gtk_adjustment_new (0., 0., 1., 0.02, 0.2, 0.);
|
adj = gtk_adjustment_new (0., 0., 1., 0.02, 0.2, 0.);
|
||||||
g_object_set (G_OBJECT (button),
|
g_object_set (G_OBJECT (button),
|
||||||
"adjustment", adj,
|
"adjustment", adj,
|
||||||
"size", GTK_ICON_SIZE_SMALL_TOOLBAR,
|
"size", GTK_ICON_SIZE_SMALL_TOOLBAR,
|
||||||
"has-tooltip", TRUE,
|
"has-tooltip", TRUE,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
g_signal_connect (G_OBJECT (button), "query-tooltip",
|
g_signal_connect (G_OBJECT (button), "query-tooltip",
|
||||||
G_CALLBACK (cb_query_tooltip), NULL);
|
G_CALLBACK (cb_query_tooltip), NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user