2010-06-25 17:29:51 +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-06-25 17:29:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2012-11-25 02:34:08 +00:00
|
|
|
|
|
|
|
#define GDK_DISABLE_DEPRECATION_WARNINGS
|
|
|
|
|
2012-11-25 00:55:53 +00:00
|
|
|
#include "gtkcsscolorvalueprivate.h"
|
2012-03-28 04:28:13 +00:00
|
|
|
#include "gtkcssrgbavalueprivate.h"
|
2012-07-14 18:24:46 +00:00
|
|
|
#include "gtkcssstylepropertyprivate.h"
|
2012-11-08 14:26:33 +00:00
|
|
|
#include "gtkhslaprivate.h"
|
2012-07-14 18:24:46 +00:00
|
|
|
#include "gtkstylepropertyprivate.h"
|
2011-12-28 15:15:00 +00:00
|
|
|
#include "gtksymboliccolorprivate.h"
|
2010-10-29 04:47:32 +00:00
|
|
|
#include "gtkstyleproperties.h"
|
2010-06-25 17:29:51 +00:00
|
|
|
#include "gtkintl.h"
|
2011-11-18 09:16:38 +00:00
|
|
|
#include "gtkwin32themeprivate.h"
|
2010-06-25 17:29:51 +00:00
|
|
|
|
2010-11-26 01:39:53 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gtksymboliccolor
|
|
|
|
* @Short_description: Symbolic colors
|
|
|
|
* @Title: GtkSymbolicColor
|
|
|
|
*
|
|
|
|
* GtkSymbolicColor is a boxed type that represents a symbolic color.
|
|
|
|
* It is the result of parsing a
|
|
|
|
* <link linkend="gtkcssprovider-symbolic-colors">color expression</link>.
|
|
|
|
* To obtain the color represented by a GtkSymbolicColor, it has to
|
|
|
|
* be resolved with gtk_symbolic_color_resolve(), which replaces all
|
|
|
|
* symbolic color references by the colors they refer to (in a given
|
|
|
|
* context) and evaluates mix, shade and other expressions, resulting
|
|
|
|
* in a #GdkRGBA value.
|
|
|
|
*
|
|
|
|
* It is not normally necessary to deal directly with #GtkSymbolicColors,
|
|
|
|
* since they are mostly used behind the scenes by #GtkStyleContext and
|
|
|
|
* #GtkCssProvider.
|
2012-11-25 02:34:08 +00:00
|
|
|
*
|
|
|
|
* #GtkSymbolicColor is deprecated. Symbolic colors are considered an
|
|
|
|
* implementation detail of GTK+.
|
2010-11-26 01:39:53 +00:00
|
|
|
*/
|
|
|
|
|
2010-10-05 08:54:49 +00:00
|
|
|
G_DEFINE_BOXED_TYPE (GtkSymbolicColor, gtk_symbolic_color,
|
2010-11-26 01:39:53 +00:00
|
|
|
gtk_symbolic_color_ref, gtk_symbolic_color_unref)
|
2010-09-02 00:01:01 +00:00
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
struct _GtkSymbolicColor
|
2010-06-25 17:29:51 +00:00
|
|
|
{
|
2012-11-25 00:55:53 +00:00
|
|
|
GtkCssValue *value;
|
2012-11-24 21:04:24 +00:00
|
|
|
gint ref_count;
|
2010-06-25 17:29:51 +00:00
|
|
|
};
|
|
|
|
|
2012-11-24 21:04:24 +00:00
|
|
|
static GtkSymbolicColor *
|
2012-11-25 00:55:53 +00:00
|
|
|
gtk_symbolic_color_new (GtkCssValue *value)
|
2012-04-05 18:55:29 +00:00
|
|
|
{
|
2012-11-24 21:04:24 +00:00
|
|
|
GtkSymbolicColor *symbolic;
|
2012-04-05 18:55:29 +00:00
|
|
|
|
2012-11-24 21:04:24 +00:00
|
|
|
symbolic = g_slice_new0 (GtkSymbolicColor);
|
2012-11-25 00:55:53 +00:00
|
|
|
symbolic->value = value;
|
2012-11-24 21:04:24 +00:00
|
|
|
symbolic->ref_count = 1;
|
2012-04-05 18:55:29 +00:00
|
|
|
|
2012-11-24 21:04:24 +00:00
|
|
|
return symbolic;
|
2012-04-05 18:55:29 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
|
|
|
* gtk_symbolic_color_new_literal:
|
2010-10-22 10:41:19 +00:00
|
|
|
* @color: a #GdkRGBA
|
2010-10-19 08:59:46 +00:00
|
|
|
*
|
|
|
|
* Creates a symbolic color pointing to a literal color.
|
|
|
|
*
|
|
|
|
* Returns: a newly created #GtkSymbolicColor
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
2012-11-25 02:34:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.8: #GtkSymbolicColor is deprecated.
|
2010-10-19 08:59:46 +00:00
|
|
|
**/
|
2010-06-25 17:29:51 +00:00
|
|
|
GtkSymbolicColor *
|
2010-11-03 10:35:42 +00:00
|
|
|
gtk_symbolic_color_new_literal (const GdkRGBA *color)
|
2010-06-25 17:29:51 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (color != NULL, NULL);
|
|
|
|
|
2012-11-25 00:55:53 +00:00
|
|
|
return gtk_symbolic_color_new (_gtk_css_color_value_new_literal (color));
|
2010-06-25 17:29:51 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
|
|
|
* gtk_symbolic_color_new_name:
|
|
|
|
* @name: color name
|
|
|
|
*
|
|
|
|
* Creates a symbolic color pointing to an unresolved named
|
|
|
|
* color. See gtk_style_context_lookup_color() and
|
2010-10-29 04:47:32 +00:00
|
|
|
* gtk_style_properties_lookup_color().
|
2010-10-19 08:59:46 +00:00
|
|
|
*
|
|
|
|
* Returns: a newly created #GtkSymbolicColor
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
2012-11-25 02:34:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.8: #GtkSymbolicColor is deprecated.
|
2010-10-19 08:59:46 +00:00
|
|
|
**/
|
2010-06-25 17:29:51 +00:00
|
|
|
GtkSymbolicColor *
|
|
|
|
gtk_symbolic_color_new_name (const gchar *name)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
|
2012-11-25 00:55:53 +00:00
|
|
|
return gtk_symbolic_color_new (_gtk_css_color_value_new_name (name));
|
2010-06-25 17:29:51 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
2011-10-15 17:34:06 +00:00
|
|
|
* gtk_symbolic_color_new_shade: (constructor)
|
2010-10-19 08:59:46 +00:00
|
|
|
* @color: another #GtkSymbolicColor
|
|
|
|
* @factor: shading factor to apply to @color
|
|
|
|
*
|
|
|
|
* Creates a symbolic color defined as a shade of
|
|
|
|
* another color. A factor > 1.0 would resolve to
|
|
|
|
* a brighter color, while < 1.0 would resolve to
|
|
|
|
* a darker color.
|
|
|
|
*
|
|
|
|
* Returns: A newly created #GtkSymbolicColor
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
2012-11-25 02:34:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.8: #GtkSymbolicColor is deprecated.
|
2010-10-19 08:59:46 +00:00
|
|
|
**/
|
2010-06-25 17:29:51 +00:00
|
|
|
GtkSymbolicColor *
|
|
|
|
gtk_symbolic_color_new_shade (GtkSymbolicColor *color,
|
|
|
|
gdouble factor)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (color != NULL, NULL);
|
|
|
|
|
2012-11-25 00:55:53 +00:00
|
|
|
return gtk_symbolic_color_new (_gtk_css_color_value_new_shade (color->value,
|
|
|
|
factor));
|
2010-06-25 17:29:51 +00:00
|
|
|
}
|
|
|
|
|
2010-10-25 18:41:36 +00:00
|
|
|
/**
|
2011-10-15 17:34:06 +00:00
|
|
|
* gtk_symbolic_color_new_alpha: (constructor)
|
2010-10-25 18:41:36 +00:00
|
|
|
* @color: another #GtkSymbolicColor
|
|
|
|
* @factor: factor to apply to @color alpha
|
|
|
|
*
|
|
|
|
* Creates a symbolic color by modifying the relative alpha
|
|
|
|
* value of @color. A factor < 1.0 would resolve to a more
|
|
|
|
* transparent color, while > 1.0 would resolve to a more
|
|
|
|
* opaque color.
|
|
|
|
*
|
|
|
|
* Returns: A newly created #GtkSymbolicColor
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
2012-11-25 02:34:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.8: #GtkSymbolicColor is deprecated.
|
2010-10-25 18:41:36 +00:00
|
|
|
**/
|
|
|
|
GtkSymbolicColor *
|
|
|
|
gtk_symbolic_color_new_alpha (GtkSymbolicColor *color,
|
|
|
|
gdouble factor)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (color != NULL, NULL);
|
|
|
|
|
2012-11-25 00:55:53 +00:00
|
|
|
return gtk_symbolic_color_new (_gtk_css_color_value_new_alpha (color->value,
|
|
|
|
factor));
|
2010-10-25 18:41:36 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
2011-10-15 17:34:06 +00:00
|
|
|
* gtk_symbolic_color_new_mix: (constructor)
|
2010-10-19 08:59:46 +00:00
|
|
|
* @color1: color to mix
|
|
|
|
* @color2: another color to mix
|
|
|
|
* @factor: mix factor
|
|
|
|
*
|
|
|
|
* Creates a symbolic color defined as a mix of another
|
|
|
|
* two colors. a mix factor of 0 would resolve to @color1,
|
|
|
|
* while a factor of 1 would resolve to @color2.
|
|
|
|
*
|
|
|
|
* Returns: A newly created #GtkSymbolicColor
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
2012-11-25 02:34:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.8: #GtkSymbolicColor is deprecated.
|
2010-10-19 08:59:46 +00:00
|
|
|
**/
|
2010-06-25 17:29:51 +00:00
|
|
|
GtkSymbolicColor *
|
|
|
|
gtk_symbolic_color_new_mix (GtkSymbolicColor *color1,
|
|
|
|
GtkSymbolicColor *color2,
|
|
|
|
gdouble factor)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (color1 != NULL, NULL);
|
|
|
|
g_return_val_if_fail (color1 != NULL, NULL);
|
|
|
|
|
2012-11-25 00:55:53 +00:00
|
|
|
return gtk_symbolic_color_new (_gtk_css_color_value_new_mix (color1->value,
|
|
|
|
color2->value,
|
|
|
|
factor));
|
2010-06-25 17:29:51 +00:00
|
|
|
}
|
|
|
|
|
2011-11-18 09:16:38 +00:00
|
|
|
/**
|
2011-11-21 12:52:39 +00:00
|
|
|
* gtk_symbolic_color_new_win32: (constructor)
|
2011-11-18 09:16:38 +00:00
|
|
|
* @theme_class: The theme class to pull color from
|
|
|
|
* @id: The color id
|
|
|
|
*
|
|
|
|
* Creates a symbolic color based on the current win32
|
|
|
|
* theme.
|
|
|
|
*
|
2011-12-16 03:49:16 +00:00
|
|
|
* Note that while this call is available on all platforms
|
2011-11-21 12:52:39 +00:00
|
|
|
* the actual value returned is not reliable on non-win32
|
|
|
|
* platforms.
|
|
|
|
*
|
2011-11-18 09:16:38 +00:00
|
|
|
* Returns: A newly created #GtkSymbolicColor
|
|
|
|
*
|
|
|
|
* Since: 3.4
|
2012-11-25 02:34:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.8: #GtkSymbolicColor is deprecated.
|
2011-12-16 03:49:16 +00:00
|
|
|
*/
|
2011-11-18 09:16:38 +00:00
|
|
|
GtkSymbolicColor *
|
2011-12-16 03:49:16 +00:00
|
|
|
gtk_symbolic_color_new_win32 (const gchar *theme_class,
|
|
|
|
gint id)
|
2011-11-18 09:16:38 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (theme_class != NULL, NULL);
|
|
|
|
|
2012-11-25 00:55:53 +00:00
|
|
|
return gtk_symbolic_color_new (_gtk_css_color_value_new_win32 (theme_class, id));
|
2012-01-14 01:38:42 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
|
|
|
* gtk_symbolic_color_ref:
|
|
|
|
* @color: a #GtkSymbolicColor
|
|
|
|
*
|
|
|
|
* Increases the reference count of @color
|
|
|
|
*
|
|
|
|
* Returns: the same @color
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
2012-11-25 02:34:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.8: #GtkSymbolicColor is deprecated.
|
2010-10-19 08:59:46 +00:00
|
|
|
**/
|
2010-06-25 17:29:51 +00:00
|
|
|
GtkSymbolicColor *
|
|
|
|
gtk_symbolic_color_ref (GtkSymbolicColor *color)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (color != NULL, NULL);
|
|
|
|
|
2012-11-24 21:04:24 +00:00
|
|
|
color->ref_count++;
|
2010-06-25 17:29:51 +00:00
|
|
|
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
|
|
|
* gtk_symbolic_color_unref:
|
|
|
|
* @color: a #GtkSymbolicColor
|
|
|
|
*
|
|
|
|
* Decreases the reference count of @color, freeing its memory if the
|
|
|
|
* reference count reaches 0.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
2012-11-25 02:34:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.8: #GtkSymbolicColor is deprecated.
|
2010-10-19 08:59:46 +00:00
|
|
|
**/
|
2010-06-25 17:29:51 +00:00
|
|
|
void
|
|
|
|
gtk_symbolic_color_unref (GtkSymbolicColor *color)
|
|
|
|
{
|
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
|
2012-11-24 21:04:24 +00:00
|
|
|
if (--color->ref_count)
|
|
|
|
return;
|
|
|
|
|
2012-11-25 00:55:53 +00:00
|
|
|
_gtk_css_value_unref (color->value);
|
2012-11-24 21:04:24 +00:00
|
|
|
|
|
|
|
g_slice_free (GtkSymbolicColor, color);
|
2010-06-25 17:29:51 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
|
|
|
* gtk_symbolic_color_resolve:
|
|
|
|
* @color: a #GtkSymbolicColor
|
2011-01-08 16:25:39 +00:00
|
|
|
* @props: (allow-none): #GtkStyleProperties to use when resolving
|
|
|
|
* named colors, or %NULL
|
2010-10-19 08:59:46 +00:00
|
|
|
* @resolved_color: (out): return location for the resolved color
|
|
|
|
*
|
|
|
|
* If @color is resolvable, @resolved_color will be filled in
|
|
|
|
* with the resolved color, and %TRUE will be returned. Generally,
|
|
|
|
* if @color can't be resolved, it is due to it being defined on
|
2010-10-29 04:47:32 +00:00
|
|
|
* top of a named color that doesn't exist in @props.
|
2010-10-19 08:59:46 +00:00
|
|
|
*
|
2011-05-18 10:58:11 +00:00
|
|
|
* When @props is %NULL, resolving of named colors will fail, so if
|
|
|
|
* your @color is or references such a color, this function will
|
|
|
|
* return %FALSE.
|
2011-01-08 16:25:39 +00:00
|
|
|
*
|
2010-10-19 08:59:46 +00:00
|
|
|
* Returns: %TRUE if the color has been resolved
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
2012-11-25 02:34:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.8: #GtkSymbolicColor is deprecated.
|
2010-10-19 08:59:46 +00:00
|
|
|
**/
|
2010-06-25 17:39:15 +00:00
|
|
|
gboolean
|
2010-10-29 04:47:32 +00:00
|
|
|
gtk_symbolic_color_resolve (GtkSymbolicColor *color,
|
2012-03-08 13:52:10 +00:00
|
|
|
GtkStyleProperties *props,
|
|
|
|
GdkRGBA *resolved_color)
|
2010-06-25 17:39:15 +00:00
|
|
|
{
|
2012-04-05 20:12:37 +00:00
|
|
|
GdkRGBA pink = { 1.0, 0.5, 0.5, 1.0 };
|
|
|
|
GtkCssValue *v, *current;
|
2012-03-08 13:52:10 +00:00
|
|
|
|
2010-06-25 17:39:15 +00:00
|
|
|
g_return_val_if_fail (color != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (resolved_color != NULL, FALSE);
|
2011-05-18 10:58:11 +00:00
|
|
|
g_return_val_if_fail (props == NULL || GTK_IS_STYLE_PROPERTIES (props), FALSE);
|
2010-06-25 17:39:15 +00:00
|
|
|
|
2012-04-05 20:12:37 +00:00
|
|
|
current = _gtk_css_rgba_value_new_from_rgba (&pink);
|
2012-11-25 00:55:53 +00:00
|
|
|
v = _gtk_css_color_value_resolve (color->value,
|
|
|
|
GTK_STYLE_PROVIDER_PRIVATE (props),
|
|
|
|
current,
|
|
|
|
0,
|
2013-03-28 22:13:43 +00:00
|
|
|
NULL,
|
2012-11-25 00:55:53 +00:00
|
|
|
NULL);
|
2012-04-05 20:12:37 +00:00
|
|
|
_gtk_css_value_unref (current);
|
2012-03-08 13:52:10 +00:00
|
|
|
if (v == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-03-28 04:28:13 +00:00
|
|
|
*resolved_color = *_gtk_css_rgba_value_get_rgba (v);
|
2012-03-08 13:52:10 +00:00
|
|
|
_gtk_css_value_unref (v);
|
|
|
|
return TRUE;
|
2011-12-28 15:15:00 +00:00
|
|
|
}
|
|
|
|
|
2011-04-06 19:41:42 +00:00
|
|
|
/**
|
|
|
|
* gtk_symbolic_color_to_string:
|
|
|
|
* @color: color to convert to a string
|
|
|
|
*
|
|
|
|
* Converts the given @color to a string representation. This is useful
|
|
|
|
* both for debugging and for serialization of strings. The format of
|
|
|
|
* the string may change between different versions of GTK, but it is
|
|
|
|
* guaranteed that the GTK css parser is able to read the string and
|
|
|
|
* create the same symbolic color from it.
|
|
|
|
*
|
|
|
|
* Returns: a new string representing @color
|
2012-11-25 02:34:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.8: #GtkSymbolicColor is deprecated.
|
2011-04-06 19:41:42 +00:00
|
|
|
**/
|
|
|
|
char *
|
|
|
|
gtk_symbolic_color_to_string (GtkSymbolicColor *color)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (color != NULL, NULL);
|
|
|
|
|
2012-11-25 00:55:53 +00:00
|
|
|
return _gtk_css_value_to_string (color->value);
|
2012-04-05 19:09:35 +00:00
|
|
|
}
|
|
|
|
|
2012-11-25 00:55:53 +00:00
|
|
|
GtkSymbolicColor *
|
|
|
|
_gtk_css_symbolic_value_new (GtkCssParser *parser)
|
2012-04-05 19:09:35 +00:00
|
|
|
{
|
2012-11-25 00:55:53 +00:00
|
|
|
GtkCssValue *value;
|
2011-04-06 19:41:42 +00:00
|
|
|
|
2012-11-25 00:55:53 +00:00
|
|
|
value = _gtk_css_color_value_parse (parser);
|
|
|
|
if (value == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return gtk_symbolic_color_new (value);
|
2011-04-06 19:41:42 +00:00
|
|
|
}
|
2012-04-05 19:09:35 +00:00
|
|
|
|
2012-11-25 00:55:53 +00:00
|
|
|
GtkCssValue *
|
|
|
|
_gtk_symbolic_color_get_css_value (GtkSymbolicColor *symbolic)
|
2012-04-05 19:09:35 +00:00
|
|
|
{
|
2012-11-25 00:55:53 +00:00
|
|
|
return symbolic->value;
|
2012-04-05 19:09:35 +00:00
|
|
|
}
|
2012-11-25 00:55:53 +00:00
|
|
|
|