2011-12-31 22:04:32 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2011 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* 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.1 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/>.
|
2011-12-31 22:04:32 +00:00
|
|
|
*
|
|
|
|
* Authors: Benjamin Otte <otte@gnome.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkcsscustompropertyprivate.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-01-02 09:37:04 +00:00
|
|
|
#include "gtkcssstylefuncsprivate.h"
|
2012-04-07 05:40:36 +00:00
|
|
|
#include "gtkcsstypedvalueprivate.h"
|
2014-10-24 20:12:33 +00:00
|
|
|
#include "deprecated/gtkstylepropertiesprivate.h"
|
2014-08-29 20:33:37 +00:00
|
|
|
|
|
|
|
#include "deprecated/gtkthemingengine.h"
|
2011-12-31 22:04:32 +00:00
|
|
|
|
2012-11-25 03:16:43 +00:00
|
|
|
#include "deprecated/gtksymboliccolor.h"
|
|
|
|
|
2011-12-31 22:04:32 +00:00
|
|
|
G_DEFINE_TYPE (GtkCssCustomProperty, _gtk_css_custom_property, GTK_TYPE_CSS_STYLE_PROPERTY)
|
|
|
|
|
2012-03-26 15:24:02 +00:00
|
|
|
static GtkCssValue *
|
2012-01-02 09:37:04 +00:00
|
|
|
gtk_css_custom_property_parse_value (GtkStyleProperty *property,
|
2012-04-18 20:04:44 +00:00
|
|
|
GtkCssParser *parser)
|
2012-01-02 09:37:04 +00:00
|
|
|
{
|
2015-11-20 23:51:22 +00:00
|
|
|
_gtk_css_parser_error_full (parser,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_NAME,
|
|
|
|
"Custom CSS properties are no longer supported.");
|
|
|
|
return NULL;
|
2012-01-02 09:37:04 +00:00
|
|
|
}
|
|
|
|
|
2012-03-27 21:23:11 +00:00
|
|
|
static void
|
|
|
|
gtk_css_custom_property_query (GtkStyleProperty *property,
|
|
|
|
GValue *value,
|
|
|
|
GtkStyleQueryFunc query_func,
|
|
|
|
gpointer query_data)
|
|
|
|
{
|
|
|
|
GtkCssStyleProperty *style = GTK_CSS_STYLE_PROPERTY (property);
|
2012-04-07 05:40:36 +00:00
|
|
|
GtkCssCustomProperty *custom = GTK_CSS_CUSTOM_PROPERTY (property);
|
2012-03-27 21:23:11 +00:00
|
|
|
GtkCssValue *css_value;
|
|
|
|
|
|
|
|
css_value = (* query_func) (_gtk_css_style_property_get_id (style), query_data);
|
|
|
|
if (css_value == NULL)
|
2012-04-07 05:40:36 +00:00
|
|
|
css_value = _gtk_css_style_property_get_initial_value (style);
|
2012-03-27 21:23:11 +00:00
|
|
|
|
2012-04-07 05:40:36 +00:00
|
|
|
g_value_init (value, custom->pspec->value_type);
|
|
|
|
g_value_copy (_gtk_css_typed_value_get (css_value), value);
|
2012-03-27 21:23:11 +00:00
|
|
|
}
|
|
|
|
|
2012-03-28 03:15:48 +00:00
|
|
|
static void
|
|
|
|
gtk_css_custom_property_assign (GtkStyleProperty *property,
|
|
|
|
GtkStyleProperties *props,
|
|
|
|
GtkStateFlags state,
|
|
|
|
const GValue *value)
|
|
|
|
{
|
2012-04-07 05:40:36 +00:00
|
|
|
GtkCssValue *css_value = _gtk_css_typed_value_new (value);
|
2012-03-28 03:15:48 +00:00
|
|
|
_gtk_style_properties_set_property_by_property (props,
|
|
|
|
GTK_CSS_STYLE_PROPERTY (property),
|
|
|
|
state,
|
|
|
|
css_value);
|
|
|
|
_gtk_css_value_unref (css_value);
|
|
|
|
}
|
|
|
|
|
2011-12-31 22:04:32 +00:00
|
|
|
static void
|
|
|
|
_gtk_css_custom_property_class_init (GtkCssCustomPropertyClass *klass)
|
|
|
|
{
|
2012-01-02 09:37:04 +00:00
|
|
|
GtkStylePropertyClass *property_class = GTK_STYLE_PROPERTY_CLASS (klass);
|
|
|
|
|
|
|
|
property_class->parse_value = gtk_css_custom_property_parse_value;
|
2012-03-27 21:23:11 +00:00
|
|
|
property_class->query = gtk_css_custom_property_query;
|
2012-03-28 03:15:48 +00:00
|
|
|
property_class->assign = gtk_css_custom_property_assign;
|
2011-12-31 22:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-03-27 05:51:20 +00:00
|
|
|
_gtk_css_custom_property_init (GtkCssCustomProperty *custom)
|
2011-12-31 22:04:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:16:32 +00:00
|
|
|
static GtkCssValue *
|
|
|
|
gtk_css_custom_property_create_initial_value (GParamSpec *pspec)
|
2011-12-31 22:04:32 +00:00
|
|
|
{
|
2012-03-06 13:16:32 +00:00
|
|
|
GValue value = G_VALUE_INIT;
|
2012-03-26 05:46:18 +00:00
|
|
|
GtkCssValue *result;
|
2012-03-06 13:16:32 +00:00
|
|
|
|
2012-04-09 01:05:12 +00:00
|
|
|
g_value_init (&value, pspec->value_type);
|
2011-12-31 22:04:32 +00:00
|
|
|
|
2014-06-15 14:05:16 +00:00
|
|
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
2011-12-31 22:04:32 +00:00
|
|
|
if (pspec->value_type == GTK_TYPE_THEMING_ENGINE)
|
2012-03-06 13:16:32 +00:00
|
|
|
g_value_set_object (&value, gtk_theming_engine_load (NULL));
|
2011-12-31 22:04:32 +00:00
|
|
|
else if (pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION)
|
2012-03-06 13:16:32 +00:00
|
|
|
g_value_take_boxed (&value, pango_font_description_from_string ("Sans 10"));
|
2012-04-09 01:05:12 +00:00
|
|
|
else if (pspec->value_type == GDK_TYPE_RGBA)
|
2011-12-31 22:04:32 +00:00
|
|
|
{
|
|
|
|
GdkRGBA color;
|
|
|
|
gdk_rgba_parse (&color, "pink");
|
2012-04-09 01:27:18 +00:00
|
|
|
g_value_set_boxed (&value, &color);
|
2012-04-09 01:05:12 +00:00
|
|
|
}
|
2014-05-22 13:05:58 +00:00
|
|
|
else if (pspec->value_type == g_type_from_name ("GdkColor"))
|
2012-04-09 01:05:12 +00:00
|
|
|
{
|
|
|
|
GdkColor color;
|
|
|
|
gdk_color_parse ("pink", &color);
|
2012-04-09 01:27:18 +00:00
|
|
|
g_value_set_boxed (&value, &color);
|
2011-12-31 22:04:32 +00:00
|
|
|
}
|
|
|
|
else if (pspec->value_type == GTK_TYPE_BORDER)
|
|
|
|
{
|
2012-03-06 13:16:32 +00:00
|
|
|
g_value_take_boxed (&value, gtk_border_new ());
|
2011-12-31 22:04:32 +00:00
|
|
|
}
|
|
|
|
else
|
2012-03-06 13:16:32 +00:00
|
|
|
g_param_value_set_default (pspec, &value);
|
2014-06-15 14:05:16 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
2012-03-06 13:16:32 +00:00
|
|
|
|
2012-04-07 05:40:36 +00:00
|
|
|
result = _gtk_css_typed_value_new (&value);
|
2012-03-26 05:46:18 +00:00
|
|
|
g_value_unset (&value);
|
|
|
|
|
|
|
|
return result;
|
2011-12-31 22:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Property registration functions */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_theming_engine_register_property: (skip)
|
|
|
|
* @name_space: namespace for the property name
|
2014-05-26 16:13:02 +00:00
|
|
|
* @parse_func: (nullable): parsing function to use, or %NULL
|
2011-12-31 22:04:32 +00:00
|
|
|
* @pspec: the #GParamSpec for the new property
|
|
|
|
*
|
|
|
|
* Registers a property so it can be used in the CSS file format,
|
|
|
|
* on the CSS file the property will look like
|
|
|
|
* "-${@name_space}-${property_name}". being
|
|
|
|
* ${property_name} the given to @pspec. @name_space will usually
|
|
|
|
* be the theme engine name.
|
|
|
|
*
|
|
|
|
* For any type a @parse_func may be provided, being this function
|
2014-02-07 19:03:49 +00:00
|
|
|
* used for turning any property value (between “:” and “;”) in
|
2011-12-31 22:04:32 +00:00
|
|
|
* CSS to the #GValue needed. For basic types there is already
|
|
|
|
* builtin parsing support, so %NULL may be provided for these
|
|
|
|
* cases.
|
|
|
|
*
|
|
|
|
* Engines must ensure property registration happens exactly once,
|
|
|
|
* usually GTK+ deals with theming engines as singletons, so this
|
|
|
|
* should be guaranteed to happen once, but bear this in mind
|
2014-02-09 22:24:06 +00:00
|
|
|
* when creating #GtkThemeEngines yourself.
|
2011-12-31 22:04:32 +00:00
|
|
|
*
|
|
|
|
* In order to make use of the custom registered properties in
|
|
|
|
* the CSS file, make sure the engine is loaded first by specifying
|
|
|
|
* the engine property, either in a previous rule or within the same
|
|
|
|
* one.
|
2014-01-27 17:12:55 +00:00
|
|
|
* |[
|
2014-02-15 04:34:22 +00:00
|
|
|
* * {
|
2011-12-31 22:04:32 +00:00
|
|
|
* engine: someengine;
|
|
|
|
* -SomeEngine-custom-property: 2;
|
|
|
|
* }
|
2014-01-27 17:12:55 +00:00
|
|
|
* ]|
|
2011-12-31 22:04:32 +00:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
2012-11-30 21:45:20 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.8: Code should use the default properties provided by CSS.
|
2011-12-31 22:04:32 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_theming_engine_register_property (const gchar *name_space,
|
|
|
|
GtkStylePropertyParser parse_func,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2012-01-02 09:41:41 +00:00
|
|
|
GtkCssCustomProperty *node;
|
2012-03-06 13:16:32 +00:00
|
|
|
GtkCssValue *initial;
|
2011-12-31 22:04:32 +00:00
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
g_return_if_fail (name_space != NULL);
|
|
|
|
g_return_if_fail (strchr (name_space, ' ') == NULL);
|
|
|
|
g_return_if_fail (G_IS_PARAM_SPEC (pspec));
|
|
|
|
|
|
|
|
name = g_strdup_printf ("-%s-%s", name_space, pspec->name);
|
2012-04-07 15:24:50 +00:00
|
|
|
|
|
|
|
/* This also initializes the default properties */
|
|
|
|
if (_gtk_style_property_lookup (pspec->name))
|
|
|
|
{
|
|
|
|
g_warning ("a property with name '%s' already exists", name);
|
|
|
|
g_free (name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:16:32 +00:00
|
|
|
initial = gtk_css_custom_property_create_initial_value (pspec);
|
2011-12-31 22:04:32 +00:00
|
|
|
|
|
|
|
node = g_object_new (GTK_TYPE_CSS_CUSTOM_PROPERTY,
|
2012-03-06 13:16:32 +00:00
|
|
|
"initial-value", initial,
|
2011-12-31 22:04:32 +00:00
|
|
|
"name", name,
|
|
|
|
"value-type", pspec->value_type,
|
|
|
|
NULL);
|
2012-01-02 11:12:29 +00:00
|
|
|
node->pspec = pspec;
|
2011-12-31 22:04:32 +00:00
|
|
|
node->property_parse_func = parse_func;
|
|
|
|
|
2012-03-06 13:16:32 +00:00
|
|
|
_gtk_css_value_unref (initial);
|
2011-12-31 22:04:32 +00:00
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_style_properties_register_property: (skip)
|
2016-09-22 11:56:47 +00:00
|
|
|
* @parse_func: (nullable): parsing function to use, or %NULL
|
2011-12-31 22:04:32 +00:00
|
|
|
* @pspec: the #GParamSpec for the new property
|
|
|
|
*
|
|
|
|
* Registers a property so it can be used in the CSS file format.
|
|
|
|
* This function is the low-level equivalent of
|
|
|
|
* gtk_theming_engine_register_property(), if you are implementing
|
|
|
|
* a theming engine, you want to use that function instead.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
2012-11-30 21:45:20 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.8: Code should use the default properties provided by CSS.
|
2011-12-31 22:04:32 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_style_properties_register_property (GtkStylePropertyParser parse_func,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2012-01-02 09:41:41 +00:00
|
|
|
GtkCssCustomProperty *node;
|
2012-03-06 13:16:32 +00:00
|
|
|
GtkCssValue *initial;
|
2011-12-31 22:04:32 +00:00
|
|
|
|
|
|
|
g_return_if_fail (G_IS_PARAM_SPEC (pspec));
|
|
|
|
|
2012-04-07 15:24:50 +00:00
|
|
|
/* This also initializes the default properties */
|
|
|
|
if (_gtk_style_property_lookup (pspec->name))
|
|
|
|
{
|
|
|
|
g_warning ("a property with name '%s' already exists", pspec->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:16:32 +00:00
|
|
|
initial = gtk_css_custom_property_create_initial_value (pspec);
|
2011-12-31 22:04:32 +00:00
|
|
|
|
|
|
|
node = g_object_new (GTK_TYPE_CSS_CUSTOM_PROPERTY,
|
2012-03-06 13:16:32 +00:00
|
|
|
"initial-value", initial,
|
2011-12-31 22:04:32 +00:00
|
|
|
"name", pspec->name,
|
|
|
|
"value-type", pspec->value_type,
|
|
|
|
NULL);
|
2012-01-02 11:12:29 +00:00
|
|
|
node->pspec = pspec;
|
2011-12-31 22:04:32 +00:00
|
|
|
node->property_parse_func = parse_func;
|
|
|
|
|
2012-03-06 13:16:32 +00:00
|
|
|
_gtk_css_value_unref (initial);
|
2011-12-31 22:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_style_properties_lookup_property: (skip)
|
|
|
|
* @property_name: property name to look up
|
|
|
|
* @parse_func: (out): return location for the parse function
|
|
|
|
* @pspec: (out) (transfer none): return location for the #GParamSpec
|
|
|
|
*
|
|
|
|
* Returns %TRUE if a property has been registered, if @pspec or
|
|
|
|
* @parse_func are not %NULL, the #GParamSpec and parsing function
|
|
|
|
* will be respectively returned.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the property is registered, %FALSE otherwise
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
2012-11-30 21:45:20 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.8: This code could only look up custom properties and
|
|
|
|
* those are deprecated.
|
2011-12-31 22:04:32 +00:00
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gtk_style_properties_lookup_property (const gchar *property_name,
|
|
|
|
GtkStylePropertyParser *parse_func,
|
|
|
|
GParamSpec **pspec)
|
|
|
|
{
|
|
|
|
GtkStyleProperty *node;
|
|
|
|
gboolean found = FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (property_name != NULL, FALSE);
|
|
|
|
|
|
|
|
node = _gtk_style_property_lookup (property_name);
|
|
|
|
|
2011-12-31 22:07:13 +00:00
|
|
|
if (GTK_IS_CSS_CUSTOM_PROPERTY (node))
|
2011-12-31 22:04:32 +00:00
|
|
|
{
|
2012-01-02 09:41:41 +00:00
|
|
|
GtkCssCustomProperty *custom = GTK_CSS_CUSTOM_PROPERTY (node);
|
|
|
|
|
2011-12-31 22:04:32 +00:00
|
|
|
if (pspec)
|
2012-01-02 11:12:29 +00:00
|
|
|
*pspec = custom->pspec;
|
2011-12-31 22:04:32 +00:00
|
|
|
|
|
|
|
if (parse_func)
|
2012-01-02 09:41:41 +00:00
|
|
|
*parse_func = custom->property_parse_func;
|
2011-12-31 22:04:32 +00:00
|
|
|
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|