2011-12-31 12:43:31 +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 12:43:31 +00:00
|
|
|
|
*
|
|
|
|
|
* Authors: Benjamin Otte <otte@gnome.org>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include "gtkcssshorthandpropertyprivate.h"
|
|
|
|
|
|
2012-03-26 15:24:02 +00:00
|
|
|
|
#include "gtkcssarrayvalueprivate.h"
|
|
|
|
|
#include "gtkcssinheritvalueprivate.h"
|
|
|
|
|
#include "gtkcssinitialvalueprivate.h"
|
2014-05-11 01:08:40 +00:00
|
|
|
|
#include "gtkcssunsetvalueprivate.h"
|
2011-12-31 15:31:25 +00:00
|
|
|
|
#include "gtkintl.h"
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_SUBPROPERTIES,
|
|
|
|
|
};
|
|
|
|
|
|
2011-12-31 12:43:31 +00:00
|
|
|
|
G_DEFINE_TYPE (GtkCssShorthandProperty, _gtk_css_shorthand_property, GTK_TYPE_STYLE_PROPERTY)
|
|
|
|
|
|
2011-12-31 15:31:25 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_css_shorthand_property_set_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GtkCssShorthandProperty *property = GTK_CSS_SHORTHAND_PROPERTY (object);
|
|
|
|
|
const char **subproperties;
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_SUBPROPERTIES:
|
|
|
|
|
subproperties = g_value_get_boxed (value);
|
|
|
|
|
g_assert (subproperties);
|
|
|
|
|
for (i = 0; subproperties[i] != NULL; i++)
|
|
|
|
|
{
|
|
|
|
|
GtkStyleProperty *subproperty = _gtk_style_property_lookup (subproperties[i]);
|
|
|
|
|
g_assert (GTK_IS_CSS_STYLE_PROPERTY (subproperty));
|
|
|
|
|
g_ptr_array_add (property->subproperties, subproperty);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-26 15:24:02 +00:00
|
|
|
|
static GtkCssValue *
|
2012-01-02 01:05:05 +00:00
|
|
|
|
gtk_css_shorthand_property_parse_value (GtkStyleProperty *property,
|
2012-04-18 20:04:44 +00:00
|
|
|
|
GtkCssParser *parser)
|
2012-01-02 01:05:05 +00:00
|
|
|
|
{
|
|
|
|
|
GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property);
|
2020-04-18 16:17:46 +00:00
|
|
|
|
const guint n_props = shorthand->subproperties->len;
|
2012-03-26 15:24:02 +00:00
|
|
|
|
GtkCssValue **data;
|
|
|
|
|
GtkCssValue *result;
|
2012-01-02 01:05:05 +00:00
|
|
|
|
guint i;
|
|
|
|
|
|
2020-04-18 16:17:46 +00:00
|
|
|
|
data = g_newa (GtkCssValue *, n_props);
|
|
|
|
|
memset (data, 0, sizeof (GtkCssValue *) * n_props);
|
2012-01-02 01:05:05 +00:00
|
|
|
|
|
2019-03-31 09:39:24 +00:00
|
|
|
|
if (gtk_css_parser_try_ident (parser, "initial"))
|
2012-01-02 01:05:05 +00:00
|
|
|
|
{
|
|
|
|
|
/* the initial value can be explicitly specified with the
|
|
|
|
|
* ‘initial’ keyword which all properties accept.
|
|
|
|
|
*/
|
2020-04-18 08:55:15 +00:00
|
|
|
|
return _gtk_css_initial_value_new ();
|
2012-01-02 01:05:05 +00:00
|
|
|
|
}
|
2019-03-31 09:39:24 +00:00
|
|
|
|
else if (gtk_css_parser_try_ident (parser, "inherit"))
|
2012-01-02 01:05:05 +00:00
|
|
|
|
{
|
|
|
|
|
/* All properties accept the ‘inherit’ value which
|
|
|
|
|
* explicitly specifies that the value will be determined
|
|
|
|
|
* by inheritance. The ‘inherit’ value can be used to
|
|
|
|
|
* strengthen inherited values in the cascade, and it can
|
|
|
|
|
* also be used on properties that are not normally inherited.
|
|
|
|
|
*/
|
2020-04-18 08:55:15 +00:00
|
|
|
|
return _gtk_css_inherit_value_new ();
|
2012-01-02 01:05:05 +00:00
|
|
|
|
}
|
2019-03-31 09:39:24 +00:00
|
|
|
|
else if (gtk_css_parser_try_ident (parser, "unset"))
|
2014-05-11 01:08:40 +00:00
|
|
|
|
{
|
|
|
|
|
/* If the cascaded value of a property is the unset keyword,
|
|
|
|
|
* then if it is an inherited property, this is treated as
|
|
|
|
|
* inherit, and if it is not, this is treated as initial.
|
|
|
|
|
*/
|
2020-04-18 08:55:15 +00:00
|
|
|
|
return _gtk_css_unset_value_new ();
|
2014-05-11 01:08:40 +00:00
|
|
|
|
}
|
2012-04-18 19:48:05 +00:00
|
|
|
|
else if (!shorthand->parse (shorthand, data, parser))
|
2012-01-02 01:05:05 +00:00
|
|
|
|
{
|
2020-04-18 16:17:46 +00:00
|
|
|
|
for (i = 0; i < n_props; i++)
|
2012-03-26 15:24:02 +00:00
|
|
|
|
{
|
|
|
|
|
if (data[i] != NULL)
|
|
|
|
|
_gtk_css_value_unref (data[i]);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
2012-01-02 01:05:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-02 03:11:20 +00:00
|
|
|
|
/* All values that aren't set by the parse func are set to their
|
|
|
|
|
* default values here.
|
|
|
|
|
* XXX: Is the default always initial or can it be inherit? */
|
2020-04-18 16:17:46 +00:00
|
|
|
|
for (i = 0; i < n_props; i++)
|
2012-01-02 03:11:20 +00:00
|
|
|
|
{
|
2012-03-26 15:24:02 +00:00
|
|
|
|
if (data[i] == NULL)
|
|
|
|
|
data[i] = _gtk_css_initial_value_new ();
|
2012-01-02 03:11:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-18 16:17:46 +00:00
|
|
|
|
result = _gtk_css_array_value_new_from_array (data, n_props);
|
2020-04-18 08:54:44 +00:00
|
|
|
|
|
2012-03-26 15:24:02 +00:00
|
|
|
|
return result;
|
2012-01-02 01:05:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-12-31 12:43:31 +00:00
|
|
|
|
static void
|
|
|
|
|
_gtk_css_shorthand_property_class_init (GtkCssShorthandPropertyClass *klass)
|
|
|
|
|
{
|
2011-12-31 15:31:25 +00:00
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2012-01-01 20:58:45 +00:00
|
|
|
|
GtkStylePropertyClass *property_class = GTK_STYLE_PROPERTY_CLASS (klass);
|
2011-12-31 15:31:25 +00:00
|
|
|
|
|
|
|
|
|
object_class->set_property = gtk_css_shorthand_property_set_property;
|
|
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_SUBPROPERTIES,
|
2022-05-11 12:19:39 +00:00
|
|
|
|
g_param_spec_boxed ("subproperties", NULL, NULL,
|
2011-12-31 15:31:25 +00:00
|
|
|
|
G_TYPE_STRV,
|
|
|
|
|
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
|
2012-01-01 20:58:45 +00:00
|
|
|
|
|
2012-01-02 01:05:05 +00:00
|
|
|
|
property_class->parse_value = gtk_css_shorthand_property_parse_value;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-31 12:43:31 +00:00
|
|
|
|
static void
|
|
|
|
|
_gtk_css_shorthand_property_init (GtkCssShorthandProperty *shorthand)
|
|
|
|
|
{
|
2011-12-31 15:31:25 +00:00
|
|
|
|
shorthand->subproperties = g_ptr_array_new_with_free_func (g_object_unref);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GtkCssStyleProperty *
|
|
|
|
|
_gtk_css_shorthand_property_get_subproperty (GtkCssShorthandProperty *shorthand,
|
|
|
|
|
guint property)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CSS_SHORTHAND_PROPERTY (shorthand), NULL);
|
|
|
|
|
g_return_val_if_fail (property < shorthand->subproperties->len, NULL);
|
|
|
|
|
|
|
|
|
|
return g_ptr_array_index (shorthand->subproperties, property);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
guint
|
|
|
|
|
_gtk_css_shorthand_property_get_n_subproperties (GtkCssShorthandProperty *shorthand)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CSS_SHORTHAND_PROPERTY (shorthand), 0);
|
|
|
|
|
|
|
|
|
|
return shorthand->subproperties->len;
|
2011-12-31 12:43:31 +00:00
|
|
|
|
}
|
|
|
|
|
|