2011-04-08 14:08:28 +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/>.
|
2011-04-08 14:08:28 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2011-05-21 01:30:36 +00:00
|
|
|
#include "gtkstylepropertyprivate.h"
|
2011-04-08 14:08:28 +00:00
|
|
|
|
|
|
|
#include "gtkcssprovider.h"
|
2020-10-03 02:28:17 +00:00
|
|
|
#include <gtk/css/gtkcss.h>
|
|
|
|
#include "gtk/css/gtkcsstokenizerprivate.h"
|
|
|
|
#include "gtk/css/gtkcssparserprivate.h"
|
2011-12-31 12:43:31 +00:00
|
|
|
#include "gtkcssshorthandpropertyprivate.h"
|
|
|
|
#include "gtkcssstylepropertyprivate.h"
|
2011-05-26 01:50:53 +00:00
|
|
|
#include "gtkcsstypesprivate.h"
|
2011-12-31 13:34:42 +00:00
|
|
|
#include "gtkintl.h"
|
2011-11-25 13:36:27 +00:00
|
|
|
#include "gtkprivatetypebuiltins.h"
|
2011-04-08 14:08:28 +00:00
|
|
|
|
2011-12-31 13:34:42 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
2020-01-27 23:46:43 +00:00
|
|
|
PROP_NAME
|
2011-12-31 13:34:42 +00:00
|
|
|
};
|
|
|
|
|
2011-12-31 12:43:31 +00:00
|
|
|
G_DEFINE_ABSTRACT_TYPE (GtkStyleProperty, _gtk_style_property, G_TYPE_OBJECT)
|
2011-12-31 02:54:17 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_style_property_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkStyleProperty *property = GTK_STYLE_PROPERTY (object);
|
|
|
|
|
2015-09-20 06:32:48 +00:00
|
|
|
g_warning ("finalizing %s '%s', how could this happen?", G_OBJECT_TYPE_NAME (object), property->name);
|
2011-12-31 02:54:17 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (_gtk_style_property_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2011-12-31 13:34:42 +00:00
|
|
|
static void
|
|
|
|
gtk_style_property_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkStyleProperty *property = GTK_STYLE_PROPERTY (object);
|
|
|
|
GtkStylePropertyClass *klass = GTK_STYLE_PROPERTY_GET_CLASS (property);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_NAME:
|
|
|
|
property->name = g_value_dup_string (value);
|
|
|
|
g_assert (property->name);
|
|
|
|
g_assert (g_hash_table_lookup (klass->properties, property->name) == NULL);
|
|
|
|
g_hash_table_insert (klass->properties, property->name, property);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_style_property_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkStyleProperty *property = GTK_STYLE_PROPERTY (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_NAME:
|
|
|
|
g_value_set_string (value, property->name);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-31 02:54:17 +00:00
|
|
|
static void
|
|
|
|
_gtk_style_property_class_init (GtkStylePropertyClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = gtk_style_property_finalize;
|
2011-12-31 13:34:42 +00:00
|
|
|
object_class->set_property = gtk_style_property_set_property;
|
|
|
|
object_class->get_property = gtk_style_property_get_property;
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_NAME,
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_string ("name", NULL, NULL,
|
2011-12-31 13:34:42 +00:00
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
|
|
|
klass->properties = g_hash_table_new (g_str_hash, g_str_equal);
|
2011-12-31 02:54:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_style_property_init (GtkStyleProperty *property)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-01-02 09:06:47 +00:00
|
|
|
/**
|
|
|
|
* _gtk_style_property_parse_value:
|
|
|
|
* @property: the property
|
|
|
|
* @parser: the parser to parse from
|
|
|
|
*
|
|
|
|
* Tries to parse the given @property from the given @parser into
|
2020-05-28 08:00:03 +00:00
|
|
|
* @value. The type that @value will be assigned is dependent on
|
2012-01-02 09:06:47 +00:00
|
|
|
* the parser and no assumptions must be made about it. If the
|
|
|
|
* parsing fails, %FALSE will be returned and @value will be
|
|
|
|
* left uninitialized.
|
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* Only if @property is a `GtkCssShorthandProperty`, the @value will
|
|
|
|
* always be a `GtkCssValue` whose values can be queried with
|
2012-03-26 15:24:02 +00:00
|
|
|
* _gtk_css_array_value_get_nth().
|
2012-01-02 09:06:47 +00:00
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* Returns: (nullable): %NULL on failure or the parsed `GtkCssValue`
|
2012-01-02 09:06:47 +00:00
|
|
|
**/
|
2012-03-26 15:24:02 +00:00
|
|
|
GtkCssValue *
|
2012-01-01 17:14:51 +00:00
|
|
|
_gtk_style_property_parse_value (GtkStyleProperty *property,
|
2012-04-18 20:04:44 +00:00
|
|
|
GtkCssParser *parser)
|
2011-04-08 14:08:28 +00:00
|
|
|
{
|
2012-01-01 23:45:29 +00:00
|
|
|
GtkStylePropertyClass *klass;
|
|
|
|
|
2012-03-26 15:24:02 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_STYLE_PROPERTY (property), NULL);
|
|
|
|
g_return_val_if_fail (parser != NULL, NULL);
|
2011-04-08 14:08:28 +00:00
|
|
|
|
2012-01-01 23:45:29 +00:00
|
|
|
klass = GTK_STYLE_PROPERTY_GET_CLASS (property);
|
|
|
|
|
2012-04-18 20:04:44 +00:00
|
|
|
return klass->parse_value (property, parser);
|
2012-01-01 23:45:29 +00:00
|
|
|
}
|
|
|
|
|
2012-01-09 21:06:17 +00:00
|
|
|
void
|
|
|
|
_gtk_style_property_init_properties (void)
|
2011-05-21 02:17:28 +00:00
|
|
|
{
|
2011-12-31 13:34:42 +00:00
|
|
|
static gboolean initialized = FALSE;
|
2011-12-29 01:28:32 +00:00
|
|
|
|
2011-12-31 13:34:42 +00:00
|
|
|
if (G_LIKELY (initialized))
|
2011-05-21 02:17:28 +00:00
|
|
|
return;
|
|
|
|
|
2011-12-31 13:34:42 +00:00
|
|
|
initialized = TRUE;
|
2011-05-21 02:17:28 +00:00
|
|
|
|
2012-01-02 09:21:57 +00:00
|
|
|
_gtk_css_style_property_init_properties ();
|
2011-12-31 14:05:09 +00:00
|
|
|
/* initialize shorthands last, they depend on the real properties existing */
|
|
|
|
_gtk_css_shorthand_property_init_properties ();
|
2011-05-21 02:17:28 +00:00
|
|
|
}
|
|
|
|
|
2011-12-31 13:34:42 +00:00
|
|
|
/**
|
|
|
|
* _gtk_style_property_lookup:
|
|
|
|
* @name: name of the property to lookup
|
|
|
|
*
|
|
|
|
* Looks up the CSS property with the given @name. If no such
|
|
|
|
* property exists, %NULL is returned.
|
|
|
|
*
|
2021-05-21 00:45:06 +00:00
|
|
|
* Returns: (nullable) (transfer none): The property
|
2021-05-18 21:05:26 +00:00
|
|
|
*/
|
2011-12-31 15:08:23 +00:00
|
|
|
GtkStyleProperty *
|
2011-05-21 02:17:28 +00:00
|
|
|
_gtk_style_property_lookup (const char *name)
|
|
|
|
{
|
2011-12-31 13:34:42 +00:00
|
|
|
GtkStylePropertyClass *klass;
|
|
|
|
|
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
|
2012-01-09 21:06:17 +00:00
|
|
|
_gtk_style_property_init_properties ();
|
2011-12-31 13:34:42 +00:00
|
|
|
|
|
|
|
klass = g_type_class_peek (GTK_TYPE_STYLE_PROPERTY);
|
|
|
|
|
|
|
|
return g_hash_table_lookup (klass->properties, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _gtk_style_property_get_name:
|
|
|
|
* @property: the property to query
|
|
|
|
*
|
|
|
|
* Gets the name of the given property.
|
|
|
|
*
|
|
|
|
* Returns: the name of the property
|
|
|
|
**/
|
|
|
|
const char *
|
|
|
|
_gtk_style_property_get_name (GtkStyleProperty *property)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_STYLE_PROPERTY (property), NULL);
|
2011-05-21 02:17:28 +00:00
|
|
|
|
2011-12-31 13:34:42 +00:00
|
|
|
return property->name;
|
2011-05-21 02:17:28 +00:00
|
|
|
}
|