2010-12-02 19:28:09 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
|
|
|
|
*
|
|
|
|
* 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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2010-12-02 19:28:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "gtkmodifierstyle.h"
|
2011-12-28 21:59:55 +00:00
|
|
|
#include "gtkstyleproviderprivate.h"
|
2010-12-02 19:28:09 +00:00
|
|
|
#include "gtkintl.h"
|
|
|
|
|
|
|
|
typedef struct StylePropertyValue StylePropertyValue;
|
|
|
|
|
2011-12-28 14:46:15 +00:00
|
|
|
struct _GtkModifierStylePrivate
|
2010-12-02 19:28:09 +00:00
|
|
|
{
|
|
|
|
GtkStyleProperties *style;
|
|
|
|
GHashTable *color_properties;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CHANGED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals [LAST_SIGNAL] = { 0 };
|
|
|
|
|
2011-12-28 21:59:55 +00:00
|
|
|
static void gtk_modifier_style_provider_init (GtkStyleProviderIface *iface);
|
|
|
|
static void gtk_modifier_style_provider_private_init (GtkStyleProviderPrivateInterface *iface);
|
|
|
|
static void gtk_modifier_style_finalize (GObject *object);
|
2010-12-02 19:28:09 +00:00
|
|
|
|
2011-02-09 04:19:21 +00:00
|
|
|
G_DEFINE_TYPE_EXTENDED (GtkModifierStyle, _gtk_modifier_style, G_TYPE_OBJECT, 0,
|
2013-06-27 19:02:52 +00:00
|
|
|
G_ADD_PRIVATE (GtkModifierStyle)
|
2010-12-02 19:28:09 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
|
2011-12-28 21:59:55 +00:00
|
|
|
gtk_modifier_style_provider_init)
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER_PRIVATE,
|
|
|
|
gtk_modifier_style_provider_private_init));
|
2010-12-02 19:28:09 +00:00
|
|
|
|
|
|
|
static void
|
2011-02-09 04:19:21 +00:00
|
|
|
_gtk_modifier_style_class_init (GtkModifierStyleClass *klass)
|
2010-12-02 19:28:09 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class;
|
|
|
|
|
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = gtk_modifier_style_finalize;
|
|
|
|
|
|
|
|
signals[CHANGED] =
|
|
|
|
g_signal_new (I_("changed"),
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0, NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-02-09 04:19:21 +00:00
|
|
|
_gtk_modifier_style_init (GtkModifierStyle *modifier_style)
|
2010-12-02 19:28:09 +00:00
|
|
|
{
|
|
|
|
GtkModifierStylePrivate *priv;
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
priv = modifier_style->priv = _gtk_modifier_style_get_instance_private (modifier_style);
|
2010-12-02 19:28:09 +00:00
|
|
|
|
|
|
|
priv->color_properties = g_hash_table_new_full (g_str_hash,
|
|
|
|
g_str_equal,
|
|
|
|
(GDestroyNotify) g_free,
|
|
|
|
(GDestroyNotify) gdk_rgba_free);
|
|
|
|
priv->style = gtk_style_properties_new ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_modifier_style_get_style_property (GtkStyleProvider *provider,
|
|
|
|
GtkWidgetPath *path,
|
|
|
|
GtkStateFlags state,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GValue *value)
|
|
|
|
{
|
|
|
|
GtkModifierStylePrivate *priv;
|
2010-12-04 16:44:53 +00:00
|
|
|
GdkRGBA *rgba;
|
|
|
|
GdkColor color;
|
2010-12-02 19:28:09 +00:00
|
|
|
gchar *str;
|
|
|
|
|
2014-05-22 13:05:58 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
|
2010-12-02 19:28:09 +00:00
|
|
|
/* Reject non-color types for now */
|
|
|
|
if (pspec->value_type != GDK_TYPE_COLOR)
|
|
|
|
return FALSE;
|
|
|
|
|
2014-05-22 13:05:58 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
|
|
|
2010-12-02 19:28:09 +00:00
|
|
|
priv = GTK_MODIFIER_STYLE (provider)->priv;
|
|
|
|
str = g_strdup_printf ("-%s-%s",
|
|
|
|
g_type_name (pspec->owner_type),
|
|
|
|
pspec->name);
|
|
|
|
|
2010-12-04 16:44:53 +00:00
|
|
|
rgba = g_hash_table_lookup (priv->color_properties, str);
|
2010-12-02 19:28:09 +00:00
|
|
|
g_free (str);
|
|
|
|
|
2010-12-04 16:44:53 +00:00
|
|
|
if (!rgba)
|
2010-12-02 19:28:09 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-12-04 16:44:53 +00:00
|
|
|
color.red = (guint) (rgba->red * 65535.) + 0.5;
|
|
|
|
color.green = (guint) (rgba->green * 65535.) + 0.5;
|
|
|
|
color.blue = (guint) (rgba->blue * 65535.) + 0.5;
|
|
|
|
|
|
|
|
g_value_set_boxed (value, &color);
|
2010-12-02 19:28:09 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_modifier_style_provider_init (GtkStyleProviderIface *iface)
|
|
|
|
{
|
|
|
|
iface->get_style_property = gtk_modifier_style_get_style_property;
|
|
|
|
}
|
|
|
|
|
2012-11-25 01:28:59 +00:00
|
|
|
static GtkCssValue *
|
2011-12-28 21:59:55 +00:00
|
|
|
gtk_modifier_style_provider_get_color (GtkStyleProviderPrivate *provider,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
GtkModifierStyle *style = GTK_MODIFIER_STYLE (provider);
|
|
|
|
|
|
|
|
return _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (style->priv->style), name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_modifier_style_provider_lookup (GtkStyleProviderPrivate *provider,
|
2012-03-17 01:36:11 +00:00
|
|
|
const GtkCssMatcher *matcher,
|
2011-12-28 21:59:55 +00:00
|
|
|
GtkCssLookup *lookup)
|
|
|
|
{
|
|
|
|
GtkModifierStyle *style = GTK_MODIFIER_STYLE (provider);
|
|
|
|
|
|
|
|
_gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (style->priv->style),
|
2012-03-17 01:36:11 +00:00
|
|
|
matcher,
|
2011-12-28 21:59:55 +00:00
|
|
|
lookup);
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:09:51 +00:00
|
|
|
static GtkCssChange
|
|
|
|
gtk_modifier_style_provider_get_change (GtkStyleProviderPrivate *provider,
|
|
|
|
const GtkCssMatcher *matcher)
|
|
|
|
{
|
|
|
|
GtkModifierStyle *style = GTK_MODIFIER_STYLE (provider);
|
|
|
|
|
|
|
|
return _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (style->priv->style),
|
|
|
|
matcher);
|
|
|
|
}
|
|
|
|
|
2011-12-28 21:59:55 +00:00
|
|
|
static void
|
|
|
|
gtk_modifier_style_provider_private_init (GtkStyleProviderPrivateInterface *iface)
|
|
|
|
{
|
|
|
|
iface->get_color = gtk_modifier_style_provider_get_color;
|
|
|
|
iface->lookup = gtk_modifier_style_provider_lookup;
|
2012-03-17 20:09:51 +00:00
|
|
|
iface->get_change = gtk_modifier_style_provider_get_change;
|
2011-12-28 21:59:55 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 19:28:09 +00:00
|
|
|
static void
|
|
|
|
gtk_modifier_style_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkModifierStylePrivate *priv;
|
|
|
|
|
|
|
|
priv = GTK_MODIFIER_STYLE (object)->priv;
|
|
|
|
g_hash_table_destroy (priv->color_properties);
|
|
|
|
g_object_unref (priv->style);
|
|
|
|
|
2011-02-09 04:19:21 +00:00
|
|
|
G_OBJECT_CLASS (_gtk_modifier_style_parent_class)->finalize (object);
|
2010-12-02 19:28:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkModifierStyle *
|
2011-02-09 04:19:21 +00:00
|
|
|
_gtk_modifier_style_new (void)
|
2010-12-02 19:28:09 +00:00
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_MODIFIER_STYLE, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
modifier_style_set_color (GtkModifierStyle *style,
|
|
|
|
const gchar *prop,
|
|
|
|
GtkStateFlags state,
|
|
|
|
const GdkRGBA *color)
|
|
|
|
{
|
|
|
|
GtkModifierStylePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MODIFIER_STYLE (style));
|
|
|
|
|
|
|
|
priv = style->priv;
|
|
|
|
|
|
|
|
if (color)
|
|
|
|
gtk_style_properties_set (priv->style, state,
|
|
|
|
prop, color,
|
|
|
|
NULL);
|
|
|
|
else
|
|
|
|
gtk_style_properties_unset_property (priv->style, prop, state);
|
|
|
|
|
|
|
|
g_signal_emit (style, signals[CHANGED], 0);
|
2012-04-08 15:35:24 +00:00
|
|
|
_gtk_style_provider_private_changed (GTK_STYLE_PROVIDER_PRIVATE (style));
|
2010-12-02 19:28:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-09 04:19:21 +00:00
|
|
|
_gtk_modifier_style_set_background_color (GtkModifierStyle *style,
|
|
|
|
GtkStateFlags state,
|
|
|
|
const GdkRGBA *color)
|
2010-12-02 19:28:09 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_MODIFIER_STYLE (style));
|
|
|
|
|
|
|
|
modifier_style_set_color (style, "background-color", state, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-09 04:19:21 +00:00
|
|
|
_gtk_modifier_style_set_color (GtkModifierStyle *style,
|
|
|
|
GtkStateFlags state,
|
|
|
|
const GdkRGBA *color)
|
2010-12-02 19:28:09 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_MODIFIER_STYLE (style));
|
|
|
|
|
|
|
|
modifier_style_set_color (style, "color", state, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-09 04:19:21 +00:00
|
|
|
_gtk_modifier_style_set_font (GtkModifierStyle *style,
|
|
|
|
const PangoFontDescription *font_desc)
|
2010-12-02 19:28:09 +00:00
|
|
|
{
|
|
|
|
GtkModifierStylePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MODIFIER_STYLE (style));
|
|
|
|
|
|
|
|
priv = style->priv;
|
|
|
|
|
|
|
|
if (font_desc)
|
|
|
|
gtk_style_properties_set (priv->style, 0,
|
|
|
|
"font", font_desc,
|
|
|
|
NULL);
|
|
|
|
else
|
|
|
|
gtk_style_properties_unset_property (priv->style, "font", 0);
|
|
|
|
|
|
|
|
g_signal_emit (style, signals[CHANGED], 0);
|
2012-04-08 15:35:24 +00:00
|
|
|
_gtk_style_provider_private_changed (GTK_STYLE_PROVIDER_PRIVATE (style));
|
2010-12-02 19:28:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-09 04:19:21 +00:00
|
|
|
_gtk_modifier_style_map_color (GtkModifierStyle *style,
|
|
|
|
const gchar *name,
|
|
|
|
const GdkRGBA *color)
|
2010-12-02 19:28:09 +00:00
|
|
|
{
|
|
|
|
GtkModifierStylePrivate *priv;
|
|
|
|
GtkSymbolicColor *symbolic_color = NULL;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MODIFIER_STYLE (style));
|
|
|
|
g_return_if_fail (name != NULL);
|
|
|
|
|
|
|
|
priv = style->priv;
|
|
|
|
|
2012-11-25 02:34:08 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
|
|
|
|
2010-12-02 19:28:09 +00:00
|
|
|
if (color)
|
|
|
|
symbolic_color = gtk_symbolic_color_new_literal (color);
|
|
|
|
|
|
|
|
gtk_style_properties_map_color (priv->style,
|
|
|
|
name, symbolic_color);
|
|
|
|
|
2012-11-25 02:34:08 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
|
|
|
|
2010-12-02 19:28:09 +00:00
|
|
|
g_signal_emit (style, signals[CHANGED], 0);
|
2012-04-08 15:35:24 +00:00
|
|
|
_gtk_style_provider_private_changed (GTK_STYLE_PROVIDER_PRIVATE (style));
|
2010-12-02 19:28:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-09 04:19:21 +00:00
|
|
|
_gtk_modifier_style_set_color_property (GtkModifierStyle *style,
|
|
|
|
GType widget_type,
|
|
|
|
const gchar *prop_name,
|
|
|
|
const GdkRGBA *color)
|
2010-12-02 19:28:09 +00:00
|
|
|
{
|
|
|
|
GtkModifierStylePrivate *priv;
|
2010-12-04 16:44:53 +00:00
|
|
|
const GdkRGBA *old_color;
|
2010-12-02 19:28:09 +00:00
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MODIFIER_STYLE (style));
|
|
|
|
g_return_if_fail (g_type_is_a (widget_type, GTK_TYPE_WIDGET));
|
|
|
|
g_return_if_fail (prop_name != NULL);
|
|
|
|
|
|
|
|
priv = style->priv;
|
|
|
|
str = g_strdup_printf ("-%s-%s", g_type_name (widget_type), prop_name);
|
|
|
|
|
|
|
|
old_color = g_hash_table_lookup (priv->color_properties, str);
|
|
|
|
|
|
|
|
if ((!color && !old_color) ||
|
2010-12-04 16:44:53 +00:00
|
|
|
(color && old_color && gdk_rgba_equal (color, old_color)))
|
2010-12-02 19:28:09 +00:00
|
|
|
{
|
|
|
|
g_free (str);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (color)
|
2010-12-05 11:30:28 +00:00
|
|
|
{
|
|
|
|
g_hash_table_insert (priv->color_properties, str,
|
|
|
|
gdk_rgba_copy (color));
|
|
|
|
}
|
2010-12-02 19:28:09 +00:00
|
|
|
else
|
2010-12-05 11:30:28 +00:00
|
|
|
{
|
|
|
|
g_hash_table_remove (priv->color_properties, str);
|
|
|
|
g_free (str);
|
|
|
|
}
|
2010-12-02 19:28:09 +00:00
|
|
|
|
|
|
|
g_signal_emit (style, signals[CHANGED], 0);
|
2012-04-08 15:35:24 +00:00
|
|
|
_gtk_style_provider_private_changed (GTK_STYLE_PROVIDER_PRIVATE (style));
|
2010-12-02 19:28:09 +00:00
|
|
|
}
|