#include "gtkstylepropertyprivate.h"
#include <errno.h>
+#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "gtkcssprovider.h"
#include "gtkcssparserprivate.h"
+#include "gtkcssshorthandpropertyprivate.h"
+#include "gtkcssstylepropertyprivate.h"
#include "gtkcsstypesprivate.h"
+#include "gtkintl.h"
+#include "gtkprivatetypebuiltins.h"
+#include "gtkstylepropertiesprivate.h"
/* the actual parsers we have */
#include "gtkanimationdescription.h"
#include "gtkbindings.h"
-#include "gtkborderimageprivate.h"
#include "gtkgradient.h"
#include "gtkshadowprivate.h"
#include "gtkthemingengine.h"
#include "gtktypebuiltins.h"
+#include "gtkwin32themeprivate.h"
+
+/* this is in case round() is not provided by the compiler,
+ * such as in the case of C89 compilers, like MSVC
+ */
+#include "fallback-c89.c"
+
+enum {
+ PROP_0,
+ PROP_NAME
+};
static GHashTable *parse_funcs = NULL;
static GHashTable *print_funcs = NULL;
-static GHashTable *properties = NULL;
+static GPtrArray *__style_property_array = NULL;
+
+G_DEFINE_ABSTRACT_TYPE (GtkStyleProperty, _gtk_style_property, G_TYPE_OBJECT)
+
+static void
+gtk_style_property_finalize (GObject *object)
+{
+ GtkStyleProperty *property = GTK_STYLE_PROPERTY (object);
+
+ g_warning ("finalizing %s `%s', how could this happen?", G_OBJECT_TYPE_NAME (object), property->name);
+
+ G_OBJECT_CLASS (_gtk_style_property_parent_class)->finalize (object);
+}
+
+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;
+ }
+}
+
+static void
+_gtk_style_property_class_init (GtkStylePropertyClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gtk_style_property_finalize;
+ 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,
+ g_param_spec_string ("name",
+ P_("Property name"),
+ P_("The name of the property"),
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+ klass->properties = g_hash_table_new (g_str_hash, g_str_equal);
+}
+
+static void
+_gtk_style_property_init (GtkStyleProperty *property)
+{
+}
static void
register_conversion_function (GType type,
/*** IMPLEMENTATIONS ***/
static gboolean
+enum_parse (GtkCssParser *parser,
+ GType type,
+ int *res)
+{
+ char *str;
+
+ if (_gtk_css_parser_try_enum (parser, type, res))
+ return TRUE;
+
+ str = _gtk_css_parser_try_ident (parser, TRUE);
+ if (str == NULL)
+ {
+ _gtk_css_parser_error (parser, "Expected an identifier");
+ return FALSE;
+ }
+
+ _gtk_css_parser_error (parser,
+ "Unknown value '%s' for enum type '%s'",
+ str, g_type_name (type));
+ g_free (str);
+
+ return FALSE;
+}
+
+static void
+enum_print (int value,
+ GType type,
+ GString *string)
+{
+ GEnumClass *enum_class;
+ GEnumValue *enum_value;
+
+ enum_class = g_type_class_ref (type);
+ enum_value = g_enum_get_value (enum_class, value);
+
+ g_string_append (string, enum_value->value_nick);
+
+ g_type_class_unref (enum_class);
+}
+
+static gboolean
rgba_value_parse (GtkCssParser *parser,
GFile *base,
GValue *value)
}
}
+static gboolean
+font_family_parse (GtkCssParser *parser,
+ GFile *base,
+ GValue *value)
+{
+ GPtrArray *names;
+ char *name;
+
+ /* We don't special case generic families. Pango should do
+ * that for us */
+
+ names = g_ptr_array_new ();
+
+ do {
+ name = _gtk_css_parser_try_ident (parser, TRUE);
+ if (name)
+ {
+ GString *string = g_string_new (name);
+ g_free (name);
+ while ((name = _gtk_css_parser_try_ident (parser, TRUE)))
+ {
+ g_string_append_c (string, ' ');
+ g_string_append (string, name);
+ g_free (name);
+ }
+ name = g_string_free (string, FALSE);
+ }
+ else
+ {
+ name = _gtk_css_parser_read_string (parser);
+ if (name == NULL)
+ {
+ g_ptr_array_free (names, TRUE);
+ return FALSE;
+ }
+ }
+
+ g_ptr_array_add (names, name);
+ } while (_gtk_css_parser_try (parser, ",", TRUE));
+
+ /* NULL-terminate array */
+ g_ptr_array_add (names, NULL);
+ g_value_set_boxed (value, g_ptr_array_free (names, FALSE));
+ return TRUE;
+}
+
+static void
+font_family_value_print (const GValue *value,
+ GString *string)
+{
+ const char **names = g_value_get_boxed (value);
+
+ if (names == NULL || *names == NULL)
+ {
+ g_string_append (string, "none");
+ return;
+ }
+
+ string_append_string (string, *names);
+ names++;
+ while (*names)
+ {
+ g_string_append (string, ", ");
+ string_append_string (string, *names);
+ names++;
+ }
+}
+
static gboolean
font_description_value_parse (GtkCssParser *parser,
GFile *base,
GValue *value)
{
PangoFontDescription *font_desc;
+ guint mask;
char *str;
str = _gtk_css_parser_read_value (parser);
return FALSE;
font_desc = pango_font_description_from_string (str);
+ mask = pango_font_description_get_set_fields (font_desc);
+ /* These values are not really correct,
+ * but the fields must be set, so we set them to something */
+ if ((mask & PANGO_FONT_MASK_FAMILY) == 0)
+ pango_font_description_set_family_static (font_desc, "Sans");
+ if ((mask & PANGO_FONT_MASK_SIZE) == 0)
+ pango_font_description_set_size (font_desc, 10 * PANGO_SCALE);
g_free (str);
g_value_take_boxed (value, font_desc);
return TRUE;
{
gint i;
+ if (_gtk_css_parser_begins_with (parser, '-'))
+ {
+ int res = _gtk_win32_theme_int_parse (parser, base, &i);
+ if (res >= 0)
+ {
+ g_value_set_int (value, i);
+ return res > 0;
+ }
+ /* < 0 => continue */
+ }
+
if (!_gtk_css_parser_try_int (parser, &i))
{
_gtk_css_parser_error (parser, "Expected a valid integer value");
GtkThemingEngine *engine;
char *str;
+ if (_gtk_css_parser_try (parser, "none", TRUE))
+ {
+ g_value_set_object (value, gtk_theming_engine_load (NULL));
+ return TRUE;
+ }
+
str = _gtk_css_parser_try_ident (parser, TRUE);
if (str == NULL)
{
}
engine = gtk_theming_engine_load (str);
+
if (engine == NULL)
{
_gtk_css_parser_error (parser, "Themeing engine '%s' not found", str);
{
/* XXX: gtk_theming_engine_get_name()? */
g_object_get (engine, "name", &name, NULL);
- g_string_append (string, name);
+ g_string_append (string, name ? name : "none");
g_free (name);
}
}
for (i = 0; i < G_N_ELEMENTS (numbers); i++)
{
- if (!_gtk_css_parser_try_uint (parser, &numbers[i]))
- break;
+ if (_gtk_css_parser_begins_with (parser, '-'))
+ {
+ /* These are strictly speaking signed, but we want to be able to use them
+ for unsigned types too, as the actual ranges of values make this safe */
+ int res = _gtk_win32_theme_int_parse (parser, base, (int *)&numbers[i]);
+
+ if (res == 0) /* Parse error, report */
+ return FALSE;
+
+ if (res < 0) /* Nothing known to expand */
+ break;
+ }
+ else
+ {
+ if (!_gtk_css_parser_try_uint (parser, &numbers[i]))
+ break;
- /* XXX: shouldn't allow spaces here? */
- _gtk_css_parser_try (parser, "px", TRUE);
+ /* XXX: shouldn't allow spaces here? */
+ _gtk_css_parser_try (parser, "px", TRUE);
+ }
}
if (i == 0)
error = g_error_new_literal (GTK_CSS_PROVIDER_ERROR,
GTK_CSS_PROVIDER_ERROR_DEPRECATED,
- "Whitespace between 'url' and '(' is not allowed");
+ "Whitespace between 'url' and '(' is deprecated");
_gtk_css_parser_take_error (parser, error);
}
GFile *base,
GValue *value)
{
- if (_gtk_css_parser_begins_with (parser, '-'))
+ if (_gtk_css_parser_try (parser, "none", TRUE))
+ {
+ /* nothing to do here */
+ }
+ else if (_gtk_css_parser_begins_with (parser, '-'))
{
+ int res;
+ res = _gtk_win32_theme_part_parse (parser, base, value);
+ if (res >= 0)
+ return res > 0;
+ /* < 0 => continue */
g_value_unset (value);
g_value_init (value, GTK_TYPE_GRADIENT);
return gradient_value_parse (parser, base, value);
return TRUE;
}
+static cairo_status_t
+surface_write (void *closure,
+ const unsigned char *data,
+ unsigned int length)
+{
+ g_byte_array_append (closure, data, length);
+
+ return CAIRO_STATUS_SUCCESS;
+}
+
+static void
+surface_print (cairo_surface_t *surface,
+ GString * string)
+{
+#if CAIRO_HAS_PNG_FUNCTIONS
+ GByteArray *array;
+ char *base64;
+
+ array = g_byte_array_new ();
+ cairo_surface_write_to_png_stream (surface, surface_write, array);
+ base64 = g_base64_encode (array->data, array->len);
+ g_byte_array_free (array, TRUE);
+
+ g_string_append (string, "url(\"data:image/png;base64,");
+ g_string_append (string, base64);
+ g_string_append (string, "\")");
+
+ g_free (base64);
+#else
+ g_string_append (string, "none /* you need cairo png functions enabled to make this work */");
+#endif
+}
+
+static void
+pattern_value_print (const GValue *value,
+ GString *string)
+{
+ cairo_pattern_t *pattern;
+ cairo_surface_t *surface;
+
+ pattern = g_value_get_boxed (value);
+
+ if (pattern == NULL)
+ {
+ g_string_append (string, "none");
+ return;
+ }
+
+ switch (cairo_pattern_get_type (pattern))
+ {
+ case CAIRO_PATTERN_TYPE_SURFACE:
+ if (cairo_pattern_get_surface (pattern, &surface) != CAIRO_STATUS_SUCCESS)
+ {
+ g_assert_not_reached ();
+ }
+ surface_print (surface, string);
+ break;
+ case CAIRO_PATTERN_TYPE_SOLID:
+ case CAIRO_PATTERN_TYPE_LINEAR:
+ case CAIRO_PATTERN_TYPE_RADIAL:
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+}
+
static gboolean
shadow_value_parse (GtkCssParser *parser,
GFile *base,
GValue *value)
{
- gboolean inset;
+ gboolean have_inset, have_color, have_lengths;
gdouble hoffset, voffset, blur, spread;
GtkSymbolicColor *color;
GtkShadow *shadow;
+ guint i;
shadow = _gtk_shadow_new ();
+ if (_gtk_css_parser_try (parser, "none", TRUE))
+ return TRUE;
+
do
{
- inset = _gtk_css_parser_try (parser, "inset", TRUE);
+ have_inset = have_lengths = have_color = FALSE;
- if (!_gtk_css_parser_try_double (parser, &hoffset) ||
- !_gtk_css_parser_try_double (parser, &voffset))
+ for (i = 0; i < 3; i++)
{
- _gtk_css_parser_error (parser, "Horizontal and vertical offsets are required");
- _gtk_shadow_unref (shadow);
- return FALSE;
- }
+ if (!have_inset &&
+ _gtk_css_parser_try (parser, "inset", TRUE))
+ {
+ have_inset = TRUE;
+ continue;
+ }
+
+ if (!have_lengths &&
+ _gtk_css_parser_try_double (parser, &hoffset))
+ {
+ have_lengths = TRUE;
- if (!_gtk_css_parser_try_double (parser, &blur))
- blur = 0;
+ if (!_gtk_css_parser_try_double (parser, &voffset))
+ {
+ _gtk_css_parser_error (parser, "Horizontal and vertical offsets are required");
+ _gtk_shadow_unref (shadow);
+ return FALSE;
+ }
- if (!_gtk_css_parser_try_double (parser, &spread))
- spread = 0;
+ if (!_gtk_css_parser_try_double (parser, &blur))
+ blur = 0;
- /* XXX: the color is optional and UA-defined if it's missing,
- * but it doesn't really make sense for us...
- */
- color = _gtk_css_parser_read_symbolic_color (parser);
+ if (!_gtk_css_parser_try_double (parser, &spread))
+ spread = 0;
- if (color == NULL)
+ continue;
+ }
+
+ if (!have_color)
+ {
+ have_color = TRUE;
+
+ /* XXX: the color is optional and UA-defined if it's missing,
+ * but it doesn't really make sense for us...
+ */
+ color = _gtk_css_parser_read_symbolic_color (parser);
+
+ if (color == NULL)
+ {
+ _gtk_shadow_unref (shadow);
+ return FALSE;
+ }
+ }
+ }
+
+ if (!have_color || !have_lengths)
{
+ _gtk_css_parser_error (parser, "Must specify at least color and offsets");
_gtk_shadow_unref (shadow);
return FALSE;
}
_gtk_shadow_append (shadow,
hoffset, voffset,
blur, spread,
- inset, color);
+ have_inset, color);
gtk_symbolic_color_unref (color);
_gtk_shadow_print (shadow, string);
}
+static gboolean
+background_repeat_value_parse (GtkCssParser *parser,
+ GFile *file,
+ GValue *value)
+{
+ GtkCssBackgroundRepeat repeat;
+ int style;
+
+ if (!enum_parse (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT_STYLE, &style))
+ return FALSE;
+
+ repeat.repeat = style;
+
+ g_value_set_boxed (value, &repeat);
+
+ return TRUE;
+}
+
+static void
+background_repeat_value_print (const GValue *value,
+ GString *string)
+{
+ GtkCssBackgroundRepeat *repeat;
+
+ repeat = g_value_get_boxed (value);
+
+ enum_print (repeat->repeat, GTK_TYPE_CSS_BACKGROUND_REPEAT_STYLE, string);
+}
+
static gboolean
border_image_repeat_value_parse (GtkCssParser *parser,
GFile *file,
GValue *value)
{
GtkCssBorderImageRepeat image_repeat;
- GtkCssRepeatStyle styles[2];
- gint i;
+ GtkCssBorderRepeatStyle styles[2];
+ gint i, v;
for (i = 0; i < 2; i++)
{
- if (_gtk_css_parser_try (parser, "stretch", TRUE))
- styles[i] = GTK_CSS_REPEAT_STYLE_NONE;
- else if (_gtk_css_parser_try (parser, "repeat", TRUE))
- styles[i] = GTK_CSS_REPEAT_STYLE_REPEAT;
- else if (_gtk_css_parser_try (parser, "round", TRUE))
- styles[i] = GTK_CSS_REPEAT_STYLE_ROUND;
- else if (_gtk_css_parser_try (parser, "space", TRUE))
- styles[i] = GTK_CSS_REPEAT_STYLE_SPACE;
+ if (_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, &v))
+ styles[i] = v;
else if (i == 0)
{
- styles[1] = styles[0] = GTK_CSS_REPEAT_STYLE_NONE;
+ styles[1] = styles[0] = GTK_CSS_REPEAT_STYLE_STRETCH;
break;
}
else
return TRUE;
}
-static const gchar *
-border_image_repeat_style_to_string (GtkCssRepeatStyle repeat)
-{
- switch (repeat)
- {
- case GTK_CSS_REPEAT_STYLE_NONE:
- return "stretch";
- case GTK_CSS_REPEAT_STYLE_REPEAT:
- return "repeat";
- case GTK_CSS_REPEAT_STYLE_ROUND:
- return "round";
- case GTK_CSS_REPEAT_STYLE_SPACE:
- return "space";
- default:
- return NULL;
- }
-}
-
static void
border_image_repeat_value_print (const GValue *value,
GString *string)
image_repeat = g_value_get_boxed (value);
- g_string_append_printf (string, "%s %s",
- border_image_repeat_style_to_string (image_repeat->hrepeat),
- border_image_repeat_style_to_string (image_repeat->vrepeat));
-}
-
-static gboolean
-border_image_value_parse (GtkCssParser *parser,
- GFile *base,
- GValue *value)
-{
- GValue temp = { 0, };
- cairo_pattern_t *pattern = NULL;
- GtkGradient *gradient = NULL;
- GtkBorder border, *parsed_border;
- GtkCssBorderImageRepeat repeat, *parsed_repeat;
- gboolean retval = FALSE;
- GtkBorderImage *image = NULL;
-
- g_value_init (&temp, CAIRO_GOBJECT_TYPE_PATTERN);
-
- if (!pattern_value_parse (parser, base, &temp))
- return FALSE;
-
- if (G_VALUE_TYPE (&temp) == GTK_TYPE_GRADIENT)
- gradient = g_value_dup_boxed (&temp);
- else
- pattern = g_value_dup_boxed (&temp);
-
- g_value_unset (&temp);
- g_value_init (&temp, GTK_TYPE_BORDER);
-
- if (!border_value_parse (parser, base, &temp))
- goto out;
-
- parsed_border = g_value_get_boxed (&temp);
- border = *parsed_border;
-
- g_value_unset (&temp);
- g_value_init (&temp, GTK_TYPE_CSS_BORDER_IMAGE_REPEAT);
-
- if (!border_image_repeat_value_parse (parser, base, &temp))
- goto out;
-
- parsed_repeat = g_value_get_boxed (&temp);
- repeat = *parsed_repeat;
-
- g_value_unset (&temp);
-
- if (gradient != NULL)
- image = _gtk_border_image_new_for_gradient (gradient, &border, &repeat);
- else if (pattern != NULL)
- image = _gtk_border_image_new (pattern, &border, &repeat);
-
- if (image != NULL)
+ enum_print (image_repeat->hrepeat, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, string);
+ if (image_repeat->hrepeat != image_repeat->vrepeat)
{
- retval = TRUE;
- g_value_take_boxed (value, image);
+ g_string_append (string, " ");
+ enum_print (image_repeat->vrepeat, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, string);
}
-
- out:
- if (pattern != NULL)
- cairo_pattern_destroy (pattern);
-
- if (gradient != NULL)
- gtk_gradient_unref (gradient);
-
- return retval;
}
static gboolean
GFile *base,
GValue *value)
{
- GEnumClass *enum_class;
- GEnumValue *enum_value;
- char *str;
+ int v;
- str = _gtk_css_parser_try_ident (parser, TRUE);
- if (str == NULL)
+ if (enum_parse (parser, G_VALUE_TYPE (value), &v))
{
- _gtk_css_parser_error (parser, "Expected an identifier");
- return FALSE;
+ g_value_set_enum (value, v);
+ return TRUE;
}
- enum_class = g_type_class_ref (G_VALUE_TYPE (value));
- enum_value = g_enum_get_value_by_nick (enum_class, str);
-
- if (enum_value)
- g_value_set_enum (value, enum_value->value);
- else
- _gtk_css_parser_error (parser,
- "Unknown value '%s' for enum type '%s'",
- str, g_type_name (G_VALUE_TYPE (value)));
-
- g_type_class_unref (enum_class);
- g_free (str);
-
- return enum_value != NULL;
+ return FALSE;
}
static void
enum_value_print (const GValue *value,
GString *string)
{
- GEnumClass *enum_class;
- GEnumValue *enum_value;
-
- enum_class = g_type_class_ref (G_VALUE_TYPE (value));
- enum_value = g_enum_get_value (enum_class, g_value_get_enum (value));
-
- g_string_append (string, enum_value->value_nick);
-
- g_type_class_unref (enum_class);
+ enum_print (g_value_get_enum (value), G_VALUE_TYPE (value), string);
}
static gboolean
}
static gboolean
-border_radius_value_parse (GtkCssParser *parser,
- GFile *base,
- GValue *value)
+transparent_color_value_parse (GtkCssParser *parser,
+ GFile *base,
+ GValue *value)
{
- GtkCssBorderRadius border;
-
- if (!_gtk_css_parser_try_double (parser, &border.top_left.horizontal))
- {
- _gtk_css_parser_error (parser, "Expected a number");
- return FALSE;
- }
- else if (border.top_left.horizontal < 0)
- goto negative;
-
- if (_gtk_css_parser_try_double (parser, &border.top_right.horizontal))
+ if (_gtk_css_parser_try (parser, "transparent", TRUE))
{
- if (border.top_right.horizontal < 0)
- goto negative;
- if (_gtk_css_parser_try_double (parser, &border.bottom_right.horizontal))
- {
- if (border.bottom_right.horizontal < 0)
- goto negative;
- if (!_gtk_css_parser_try_double (parser, &border.bottom_left.horizontal))
- border.bottom_left.horizontal = border.top_right.horizontal;
- else if (border.bottom_left.horizontal < 0)
- goto negative;
- }
- else
- {
- border.bottom_right.horizontal = border.top_left.horizontal;
- border.bottom_left.horizontal = border.top_right.horizontal;
- }
- }
- else
- {
- border.top_right.horizontal = border.top_left.horizontal;
- border.bottom_right.horizontal = border.top_left.horizontal;
- border.bottom_left.horizontal = border.top_left.horizontal;
- }
-
- if (_gtk_css_parser_try (parser, "/", TRUE))
- {
- if (!_gtk_css_parser_try_double (parser, &border.top_left.vertical))
- {
- _gtk_css_parser_error (parser, "Expected a number");
- return FALSE;
- }
- else if (border.top_left.vertical < 0)
- goto negative;
-
- if (_gtk_css_parser_try_double (parser, &border.top_right.vertical))
- {
- if (border.top_right.vertical < 0)
- goto negative;
- if (_gtk_css_parser_try_double (parser, &border.bottom_right.vertical))
- {
- if (border.bottom_right.vertical < 0)
- goto negative;
- if (!_gtk_css_parser_try_double (parser, &border.bottom_left.vertical))
- border.bottom_left.vertical = border.top_right.vertical;
- else if (border.bottom_left.vertical < 0)
- goto negative;
- }
- else
- {
- border.bottom_right.vertical = border.top_left.vertical;
- border.bottom_left.vertical = border.top_right.vertical;
- }
- }
- else
- {
- border.top_right.vertical = border.top_left.vertical;
- border.bottom_right.vertical = border.top_left.vertical;
- border.bottom_left.vertical = border.top_left.vertical;
- }
- }
- else
- {
- border.top_left.vertical = border.top_left.horizontal;
- border.top_right.vertical = border.top_right.horizontal;
- border.bottom_right.vertical = border.bottom_right.horizontal;
- border.bottom_left.vertical = border.bottom_left.horizontal;
- }
-
- /* border-radius is an int property for backwards-compat reasons */
- g_value_unset (value);
- g_value_init (value, GTK_TYPE_CSS_BORDER_RADIUS);
- g_value_set_boxed (value, &border);
-
- return TRUE;
-
-negative:
- _gtk_css_parser_error (parser, "Border radius values cannot be negative");
- return FALSE;
-}
-
-static void
-border_radius_value_print (const GValue *value,
- GString *string)
-{
- GtkCssBorderRadius *border;
-
- border = g_value_get_boxed (value);
-
- if (border == NULL)
- {
- g_string_append (string, "none");
- return;
- }
-
- string_append_double (string, border->top_left.horizontal);
- if (border->top_left.horizontal != border->top_right.horizontal ||
- border->top_left.horizontal != border->bottom_right.horizontal ||
- border->top_left.horizontal != border->bottom_left.horizontal)
- {
- g_string_append_c (string, ' ');
- string_append_double (string, border->top_right.horizontal);
- if (border->top_left.horizontal != border->bottom_right.horizontal ||
- border->top_right.horizontal != border->bottom_left.horizontal)
- {
- g_string_append_c (string, ' ');
- string_append_double (string, border->bottom_right.horizontal);
- if (border->top_right.horizontal != border->bottom_left.horizontal)
- {
- g_string_append_c (string, ' ');
- string_append_double (string, border->bottom_left.horizontal);
- }
- }
- }
-
- if (border->top_left.horizontal != border->top_left.vertical ||
- border->top_right.horizontal != border->top_right.vertical ||
- border->bottom_right.horizontal != border->bottom_right.vertical ||
- border->bottom_left.horizontal != border->bottom_left.vertical)
- {
- g_string_append (string, " / ");
- string_append_double (string, border->top_left.vertical);
- if (border->top_left.vertical != border->top_right.vertical ||
- border->top_left.vertical != border->bottom_right.vertical ||
- border->top_left.vertical != border->bottom_left.vertical)
- {
- g_string_append_c (string, ' ');
- string_append_double (string, border->top_right.vertical);
- if (border->top_left.vertical != border->bottom_right.vertical ||
- border->top_right.vertical != border->bottom_left.vertical)
- {
- g_string_append_c (string, ' ');
- string_append_double (string, border->bottom_right.vertical);
- if (border->top_right.vertical != border->bottom_left.vertical)
- {
- g_string_append_c (string, ' ');
- string_append_double (string, border->bottom_left.vertical);
- }
- }
- }
+ GdkRGBA transparent = { 0, 0, 0, 0 };
+
+ g_value_set_boxed (value, &transparent);
+ return TRUE;
}
-}
-
-/*** PACKING ***/
-
-static GParameter *
-unpack_border (const GValue *value,
- guint *n_params,
- const char *top,
- const char *left,
- const char *bottom,
- const char *right)
-{
- GParameter *parameter = g_new0 (GParameter, 4);
- GtkBorder *border = g_value_get_boxed (value);
-
- parameter[0].name = top;
- g_value_init (¶meter[0].value, G_TYPE_INT);
- g_value_set_int (¶meter[0].value, border->top);
- parameter[1].name = left;
- g_value_init (¶meter[1].value, G_TYPE_INT);
- g_value_set_int (¶meter[1].value, border->left);
- parameter[2].name = bottom;
- g_value_init (¶meter[2].value, G_TYPE_INT);
- g_value_set_int (¶meter[2].value, border->bottom);
- parameter[3].name = right;
- g_value_init (¶meter[3].value, G_TYPE_INT);
- g_value_set_int (¶meter[3].value, border->right);
-
- *n_params = 4;
- return parameter;
-}
-static void
-pack_border (GValue *value,
- GtkStyleProperties *props,
- GtkStateFlags state,
- const char *top,
- const char *left,
- const char *bottom,
- const char *right)
-{
- GtkBorder border;
- int t, l, b, r;
-
- gtk_style_properties_get (props,
- state,
- top, &t,
- left, &l,
- bottom, &b,
- right, &r,
- NULL);
-
- border.top = t;
- border.left = l;
- border.bottom = b;
- border.right = r;
-
- g_value_set_boxed (value, &border);
-}
-
-static GParameter *
-unpack_border_width (const GValue *value,
- guint *n_params)
-{
- return unpack_border (value, n_params,
- "border-top-width", "border-left-width",
- "border-bottom-width", "border-right-width");
+ return rgba_value_parse (parser, base, value);
}
-static void
-pack_border_width (GValue *value,
- GtkStyleProperties *props,
- GtkStateFlags state)
-{
- pack_border (value, props, state,
- "border-top-width", "border-left-width",
- "border-bottom-width", "border-right-width");
-}
-
-static GParameter *
-unpack_padding (const GValue *value,
- guint *n_params)
-{
- return unpack_border (value, n_params,
- "padding-top", "padding-left",
- "padding-bottom", "padding-right");
-}
-
-static void
-pack_padding (GValue *value,
- GtkStyleProperties *props,
- GtkStateFlags state)
-{
- pack_border (value, props, state,
- "padding-top", "padding-left",
- "padding-bottom", "padding-right");
-}
-
-static GParameter *
-unpack_margin (const GValue *value,
- guint *n_params)
-{
- return unpack_border (value, n_params,
- "margin-top", "margin-left",
- "margin-bottom", "margin-right");
-}
+/*** API ***/
-static void
-pack_margin (GValue *value,
- GtkStyleProperties *props,
- GtkStateFlags state)
+guint
+_gtk_style_property_get_count (void)
{
- pack_border (value, props, state,
- "margin-top", "margin-left",
- "margin-bottom", "margin-right");
+ return __style_property_array ? __style_property_array->len : 0;
}
-static GParameter *
-unpack_border_radius (const GValue *value,
- guint *n_params)
+const GtkStyleProperty *
+_gtk_style_property_get (guint id)
{
- GParameter *parameter = g_new0 (GParameter, 4);
- GtkCssBorderRadius *border;
+ g_assert (__style_property_array);
- if (G_VALUE_HOLDS_BOXED (value))
- border = g_value_get_boxed (value);
- else
- border = NULL;
-
- parameter[0].name = "border-top-left-radius";
- g_value_init (¶meter[0].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
- parameter[1].name = "border-top-right-radius";
- g_value_init (¶meter[1].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
- parameter[2].name = "border-bottom-right-radius";
- g_value_init (¶meter[2].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
- parameter[3].name = "border-bottom-left-radius";
- g_value_init (¶meter[3].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
- if (border)
- {
- g_value_set_boxed (¶meter[0].value, &border->top_left);
- g_value_set_boxed (¶meter[1].value, &border->top_right);
- g_value_set_boxed (¶meter[2].value, &border->bottom_right);
- g_value_set_boxed (¶meter[3].value, &border->bottom_left);
- }
-
- *n_params = 4;
- return parameter;
+ return g_ptr_array_index (__style_property_array, id);
}
static void
-pack_border_radius (GValue *value,
- GtkStyleProperties *props,
- GtkStateFlags state)
+_gtk_style_property_generate_id (GtkStyleProperty *node)
{
- GtkCssBorderCornerRadius *top_left;
-
- /* NB: We are an int property, so we have to resolve to an int here.
- * So we just resolve to an int. We pick one and stick to it.
- * Lesson learned: Don't query border-radius shorthand, query the
- * real properties instead. */
- gtk_style_properties_get (props,
- state,
- "border-top-left-radius", &top_left,
- NULL);
-
- if (top_left)
- g_value_set_int (value, top_left->horizontal);
+ if (__style_property_array == NULL)
+ __style_property_array = g_ptr_array_new ();
- g_free (top_left);
+ node->id = __style_property_array->len;
+ g_ptr_array_add (__style_property_array, node);
}
-/*** API ***/
-
static void
css_string_funcs_init (void)
{
gradient_value_print);
register_conversion_function (CAIRO_GOBJECT_TYPE_PATTERN,
pattern_value_parse,
- NULL);
- register_conversion_function (GTK_TYPE_BORDER_IMAGE,
- border_image_value_parse,
- NULL);
+ pattern_value_print);
register_conversion_function (GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
border_image_repeat_value_parse,
border_image_repeat_value_print);
register_conversion_function (G_TYPE_FLAGS,
flags_value_parse,
flags_value_print);
+ register_conversion_function (GTK_TYPE_CSS_BACKGROUND_REPEAT,
+ background_repeat_value_parse,
+ background_repeat_value_print);
}
gboolean
if (property)
{
- if (_gtk_css_parser_try (parser, "none", TRUE))
+ if (_gtk_css_parser_try (parser, "initial", TRUE))
+ {
+ /* the initial value can be explicitly specified with the
+ * ‘initial’ keyword which all properties accept.
+ */
+ g_value_unset (value);
+ g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
+ g_value_set_enum (value, GTK_CSS_INITIAL);
+ return TRUE;
+ }
+ else if (_gtk_css_parser_try (parser, "inherit", TRUE))
{
- /* Insert the default value, so it has an opportunity
- * to override other style providers when merged
+ /* 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.
*/
- g_param_value_set_default (property->pspec, value);
+ g_value_unset (value);
+ g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
+ g_value_set_enum (value, GTK_CSS_INHERIT);
return TRUE;
}
else if (property->property_parse_func)
css_string_funcs_init ();
- if (property)
+ if (G_VALUE_HOLDS (value, GTK_TYPE_CSS_SPECIAL_VALUE))
+ func = enum_value_print;
+ else if (property)
func = property->print_func;
else
func = NULL;
func (value, string);
}
-void
+static void
_gtk_style_property_default_value (const GtkStyleProperty *property,
GtkStyleProperties *properties,
+ GtkStateFlags state,
GValue *value)
{
- if (property->default_value_func)
- property->default_value_func (properties, value);
- else if (property->pspec->value_type == GTK_TYPE_THEMING_ENGINE)
- g_value_set_object (value, gtk_theming_engine_load (NULL));
- else if (property->pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION)
- g_value_take_boxed (value, pango_font_description_from_string ("Sans 10"));
- else if (property->pspec->value_type == GDK_TYPE_RGBA)
- {
- GdkRGBA color;
- gdk_rgba_parse (&color, "pink");
- g_value_set_boxed (value, &color);
- }
- else if (property->pspec->value_type == GTK_TYPE_BORDER)
- {
- g_value_take_boxed (value, gtk_border_new ());
- }
- else
- g_param_value_set_default (property->pspec, value);
+ g_value_copy (&property->initial_value, value);
}
gboolean
return property->flags & GTK_STYLE_PROPERTY_INHERIT ? TRUE : FALSE;
}
+guint
+_gtk_style_property_get_id (const GtkStyleProperty *property)
+{
+ g_return_val_if_fail (property != NULL, FALSE);
+
+ return property->id;
+}
+
static gboolean
resolve_color (GtkStyleProperties *props,
GValue *value)
return TRUE;
}
+static gboolean
+resolve_win32_theme_part (GtkStyleProperties *props,
+ GValue *value,
+ GValue *value_out,
+ GtkStylePropertyContext *context)
+{
+ GtkWin32ThemePart *part;
+ cairo_pattern_t *pattern;
+
+ part = g_value_get_boxed (value);
+ if (part == NULL)
+ return FALSE;
+
+ pattern = _gtk_win32_theme_part_render (part, context->width, context->height);
+
+ g_value_take_boxed (value_out, pattern);
+
+ return TRUE;
+}
+
+
static gboolean
resolve_gradient (GtkStyleProperties *props,
GValue *value)
return TRUE;
}
-void
+static void
_gtk_style_property_resolve (const GtkStyleProperty *property,
GtkStyleProperties *props,
- GValue *val)
+ GtkStateFlags state,
+ GtkStylePropertyContext *context,
+ GValue *val,
+ GValue *val_out)
{
- if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
+ if (G_VALUE_TYPE (val) == GTK_TYPE_CSS_SPECIAL_VALUE)
+ {
+ GtkCssSpecialValue special = g_value_get_enum (val);
+
+ g_value_unset (val);
+ switch (special)
+ {
+ case GTK_CSS_CURRENT_COLOR:
+ g_assert (property->pspec->value_type == GDK_TYPE_RGBA);
+ gtk_style_properties_get_property (props, "color", state, val);
+ break;
+ case GTK_CSS_INHERIT:
+ case GTK_CSS_INITIAL:
+ default:
+ g_assert_not_reached ();
+ }
+ }
+ else if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
{
if (property->pspec->value_type == GDK_TYPE_RGBA)
{
- if (!resolve_color (props, val))
- _gtk_style_property_resolve (property, props, val);
+ if (resolve_color (props, val))
+ goto out;
}
else if (property->pspec->value_type == GDK_TYPE_COLOR)
{
- if (!resolve_color_rgb (props, val))
- _gtk_style_property_resolve (property, props, val);
+ if (resolve_color_rgb (props, val))
+ goto out;
}
- else
- _gtk_style_property_resolve (property, props, val);
+
+ g_value_unset (val);
+ g_value_init (val, property->pspec->value_type);
+ _gtk_style_property_default_value (property, props, state, val);
+ }
+ else if (G_VALUE_TYPE (val) == GDK_TYPE_RGBA)
+ {
+ if (g_value_get_boxed (val) == NULL)
+ _gtk_style_property_default_value (property, props, state, val);
}
else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
{
g_return_if_fail (property->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN);
if (!resolve_gradient (props, val))
- _gtk_style_property_resolve (property, props, val);
+ {
+ g_value_unset (val);
+ g_value_init (val, CAIRO_GOBJECT_TYPE_PATTERN);
+ _gtk_style_property_default_value (property, props, state, val);
+ }
}
else if (G_VALUE_TYPE (val) == GTK_TYPE_SHADOW)
{
if (!resolve_shadow (props, val))
- _gtk_style_property_resolve (property, props, val);
+ _gtk_style_property_default_value (property, props, state, val);
+ }
+ else if (G_VALUE_TYPE (val) == GTK_TYPE_WIN32_THEME_PART)
+ {
+ if (resolve_win32_theme_part (props, val, val_out, context))
+ return; /* Don't copy val, this sets val_out */
+ _gtk_style_property_default_value (property, props, state, val);
}
+
+ out:
+ g_value_copy (val, val_out);
}
-gboolean
-_gtk_style_property_is_shorthand (const GtkStyleProperty *property)
+const GValue *
+_gtk_style_property_get_initial_value (const GtkStyleProperty *property)
{
- g_return_val_if_fail (property != NULL, FALSE);
+ g_return_val_if_fail (property != NULL, NULL);
- return property->pack_func != NULL;
+ return &property->initial_value;
}
GParameter *
return property->unpack_func (value, n_params);
}
-void
+static void
_gtk_style_property_pack (const GtkStyleProperty *property,
GtkStyleProperties *props,
GtkStateFlags state,
+ GtkStylePropertyContext *context,
GValue *value)
{
g_return_if_fail (property != NULL);
g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
g_return_if_fail (G_IS_VALUE (value));
- property->pack_func (value, props, state);
+ property->pack_func (value, props, state, context);
+}
+
+void
+_gtk_style_property_query (const GtkStyleProperty *property,
+ GtkStyleProperties *props,
+ GtkStateFlags state,
+ GtkStylePropertyContext *context,
+ GValue *value)
+{
+ const GValue *val;
+
+ g_return_if_fail (property != NULL);
+ g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
+ g_return_if_fail (context != NULL);
+ g_return_if_fail (value != NULL);
+
+ val = _gtk_style_properties_peek_property (props, property, state);
+ g_value_init (value, property->pspec->value_type);
+
+ if (val)
+ _gtk_style_property_resolve (property, props, state, context, (GValue *) val, value);
+ else if (GTK_IS_CSS_SHORTHAND_PROPERTY (property))
+ _gtk_style_property_pack (property, props, state, context, value);
+ else
+ _gtk_style_property_default_value (property, props, state, value);
}
+#define rgba_init(rgba, r, g, b, a) G_STMT_START{ \
+ (rgba)->red = (r); \
+ (rgba)->green = (g); \
+ (rgba)->blue = (b); \
+ (rgba)->alpha = (a); \
+}G_STMT_END
static void
-gtk_style_property_init (void)
+gtk_style_property_init_properties (void)
{
- if (G_LIKELY (properties))
- return;
+ static gboolean initialized = FALSE;
+ GValue value = { 0, };
+ char *default_font_family[] = { "Sans", NULL };
+ GdkRGBA rgba;
- /* stuff is never freed, so no need for free functions */
- properties = g_hash_table_new (g_str_hash, g_str_equal);
+ if (G_LIKELY (initialized))
+ return;
- /* note that gtk_style_properties_register_property() calls this function,
- * so make sure we're sanely inited to avoid infloops */
+ initialized = TRUE;
+ g_value_init (&value, GDK_TYPE_RGBA);
+ rgba_init (&rgba, 1, 1, 1, 1);
+ g_value_set_boxed (&value, &rgba);
_gtk_style_property_register (g_param_spec_boxed ("color",
"Foreground color",
"Foreground color",
NULL,
NULL,
NULL,
+ &value);
+ rgba_init (&rgba, 0, 0, 0, 0);
+ g_value_set_boxed (&value, &rgba);
+ _gtk_style_property_register (g_param_spec_boxed ("background-color",
+ "Background color",
+ "Background color",
+ GDK_TYPE_RGBA, 0),
+ 0,
+ NULL,
+ transparent_color_value_parse,
+ NULL,
+ &value);
+ g_value_unset (&value);
+
+ g_value_init (&value, G_TYPE_STRV);
+ g_value_set_boxed (&value, default_font_family);
+ _gtk_style_property_register (g_param_spec_boxed ("font-family",
+ "Font family",
+ "Font family",
+ G_TYPE_STRV, 0),
+ GTK_STYLE_PROPERTY_INHERIT,
+ NULL,
+ font_family_parse,
+ font_family_value_print,
+ &value);
+ g_value_unset (&value);
+ _gtk_style_property_register (g_param_spec_enum ("font-style",
+ "Font style",
+ "Font style",
+ PANGO_TYPE_STYLE,
+ PANGO_STYLE_NORMAL, 0),
+ GTK_STYLE_PROPERTY_INHERIT,
+ NULL,
NULL,
NULL,
NULL);
-
- gtk_style_properties_register_property (NULL,
- g_param_spec_boxed ("background-color",
- "Background color",
- "Background color",
- GDK_TYPE_RGBA, 0));
-
- _gtk_style_property_register (g_param_spec_boxed ("font",
- "Font Description",
- "Font Description",
- PANGO_TYPE_FONT_DESCRIPTION, 0),
+ _gtk_style_property_register (g_param_spec_enum ("font-variant",
+ "Font variant",
+ "Font variant",
+ PANGO_TYPE_VARIANT,
+ PANGO_VARIANT_NORMAL, 0),
+ GTK_STYLE_PROPERTY_INHERIT,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+ /* xxx: need to parse this properly, ie parse the numbers */
+ _gtk_style_property_register (g_param_spec_enum ("font-weight",
+ "Font weight",
+ "Font weight",
+ PANGO_TYPE_WEIGHT,
+ PANGO_WEIGHT_NORMAL, 0),
GTK_STYLE_PROPERTY_INHERIT,
NULL,
NULL,
NULL,
- font_description_value_parse,
- font_description_value_print,
NULL);
+ g_value_init (&value, G_TYPE_DOUBLE);
+ g_value_set_double (&value, 10);
+ _gtk_style_property_register (g_param_spec_double ("font-size",
+ "Font size",
+ "Font size",
+ 0, G_MAXDOUBLE, 0, 0),
+ GTK_STYLE_PROPERTY_INHERIT,
+ NULL,
+ NULL,
+ NULL,
+ &value);
+ g_value_unset (&value);
_gtk_style_property_register (g_param_spec_boxed ("text-shadow",
"Text shadow",
NULL,
NULL,
NULL,
- NULL,
- NULL,
NULL);
_gtk_style_property_register (g_param_spec_boxed ("icon-shadow",
NULL,
NULL,
NULL,
- NULL,
- NULL,
NULL);
+ gtk_style_properties_register_property (NULL,
+ g_param_spec_boxed ("box-shadow",
+ "Box shadow",
+ "Box shadow",
+ GTK_TYPE_SHADOW, 0));
gtk_style_properties_register_property (NULL,
g_param_spec_int ("margin-top",
"margin top",
"margin right",
"Margin at right",
0, G_MAXINT, 0, 0));
- _gtk_style_property_register (g_param_spec_boxed ("margin",
- "Margin",
- "Margin",
- GTK_TYPE_BORDER, 0),
- 0,
- NULL,
- unpack_margin,
- pack_margin,
- NULL,
- NULL,
- NULL);
gtk_style_properties_register_property (NULL,
g_param_spec_int ("padding-top",
"padding top",
"padding right",
"Padding at right",
0, G_MAXINT, 0, 0));
- _gtk_style_property_register (g_param_spec_boxed ("padding",
- "Padding",
- "Padding",
- GTK_TYPE_BORDER, 0),
- 0,
- NULL,
- unpack_padding,
- pack_padding,
- NULL,
- NULL,
- NULL);
gtk_style_properties_register_property (NULL,
g_param_spec_int ("border-top-width",
"border top width",
"border right width",
"Border width at right",
0, G_MAXINT, 0, 0));
- _gtk_style_property_register (g_param_spec_boxed ("border-width",
- "Border width",
- "Border width, in pixels",
- GTK_TYPE_BORDER, 0),
- 0,
- NULL,
- unpack_border_width,
- pack_border_width,
- NULL,
- NULL,
- NULL);
_gtk_style_property_register (g_param_spec_boxed ("border-top-left-radius",
"Border top left radius",
GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
0,
NULL,
- NULL,
- NULL,
border_corner_radius_value_parse,
border_corner_radius_value_print,
NULL);
GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
0,
NULL,
- NULL,
- NULL,
border_corner_radius_value_parse,
border_corner_radius_value_print,
NULL);
GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
0,
NULL,
- NULL,
- NULL,
border_corner_radius_value_parse,
border_corner_radius_value_print,
NULL);
GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
0,
NULL,
- NULL,
- NULL,
border_corner_radius_value_parse,
border_corner_radius_value_print,
NULL);
- _gtk_style_property_register (g_param_spec_int ("border-radius",
- "Border radius",
- "Border radius, in pixels",
- 0, G_MAXINT, 0, 0),
- 0,
- NULL,
- unpack_border_radius,
- pack_border_radius,
- border_radius_value_parse,
- border_radius_value_print,
- NULL);
gtk_style_properties_register_property (NULL,
g_param_spec_enum ("border-style",
GTK_TYPE_BORDER_STYLE,
GTK_BORDER_STYLE_NONE, 0));
gtk_style_properties_register_property (NULL,
- g_param_spec_boxed ("border-color",
- "Border color",
- "Border color",
- GDK_TYPE_RGBA, 0));
+ g_param_spec_enum ("background-clip",
+ "Background clip",
+ "Background clip",
+ GTK_TYPE_CSS_AREA,
+ GTK_CSS_AREA_BORDER_BOX, 0));
+ gtk_style_properties_register_property (NULL,
+ g_param_spec_enum ("background-origin",
+ "Background origin",
+ "Background origin",
+ GTK_TYPE_CSS_AREA,
+ GTK_CSS_AREA_PADDING_BOX, 0));
+ g_value_init (&value, GTK_TYPE_CSS_SPECIAL_VALUE);
+ g_value_set_enum (&value, GTK_CSS_CURRENT_COLOR);
+ _gtk_style_property_register (g_param_spec_boxed ("border-top-color",
+ "Border top color",
+ "Border top color",
+ GDK_TYPE_RGBA, 0),
+ 0,
+ NULL,
+ transparent_color_value_parse,
+ NULL,
+ &value);
+ _gtk_style_property_register (g_param_spec_boxed ("border-right-color",
+ "Border right color",
+ "Border right color",
+ GDK_TYPE_RGBA, 0),
+ 0,
+ NULL,
+ transparent_color_value_parse,
+ NULL,
+ &value);
+ _gtk_style_property_register (g_param_spec_boxed ("border-bottom-color",
+ "Border bottom color",
+ "Border bottom color",
+ GDK_TYPE_RGBA, 0),
+ 0,
+ NULL,
+ transparent_color_value_parse,
+ NULL,
+ &value);
+ _gtk_style_property_register (g_param_spec_boxed ("border-left-color",
+ "Border left color",
+ "Border left color",
+ GDK_TYPE_RGBA, 0),
+ 0,
+ NULL,
+ transparent_color_value_parse,
+ NULL,
+ &value);
+ g_value_unset (&value);
+
gtk_style_properties_register_property (NULL,
g_param_spec_boxed ("background-image",
"Background Image",
"Background Image",
CAIRO_GOBJECT_TYPE_PATTERN, 0));
+ gtk_style_properties_register_property (NULL,
+ g_param_spec_boxed ("background-repeat",
+ "Background repeat",
+ "Background repeat",
+ GTK_TYPE_CSS_BACKGROUND_REPEAT, 0));
+
gtk_style_properties_register_property (NULL,
g_param_spec_boxed ("border-image-source",
"Border image source",
"Border image slice",
"Border image slice",
GTK_TYPE_BORDER, 0));
- _gtk_style_property_register (g_param_spec_boxed ("border-image",
- "Border Image",
- "Border Image",
- GTK_TYPE_BORDER_IMAGE, 0),
+ g_value_init (&value, GTK_TYPE_BORDER);
+ _gtk_style_property_register (g_param_spec_boxed ("border-image-width",
+ "Border image width",
+ "Border image width",
+ GTK_TYPE_BORDER, 0),
0,
NULL,
- _gtk_border_image_unpack,
- _gtk_border_image_pack,
NULL,
NULL,
- NULL);
+ &value);
+ g_value_unset (&value);
gtk_style_properties_register_property (NULL,
g_param_spec_object ("engine",
"Theming Engine",
G_TYPE_PTR_ARRAY, 0),
0,
NULL,
- NULL,
- NULL,
bindings_value_parse,
bindings_value_print,
NULL);
+
+ /* initialize shorthands last, they depend on the real properties existing */
+ _gtk_css_shorthand_property_init_properties ();
}
+/**
+ * _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.
+ *
+ * Returns: (transfer none): The property or %NULL if no
+ * property with the given name exists.
+ **/
const GtkStyleProperty *
_gtk_style_property_lookup (const char *name)
{
- gtk_style_property_init ();
+ GtkStylePropertyClass *klass;
+
+ g_return_val_if_fail (name != NULL, NULL);
+
+ gtk_style_property_init_properties ();
+
+ 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);
- return g_hash_table_lookup (properties, name);
+ return property->name;
}
+
void
_gtk_style_property_register (GParamSpec *pspec,
GtkStylePropertyFlags flags,
GtkStylePropertyParser property_parse_func,
- GtkStyleUnpackFunc unpack_func,
- GtkStylePackFunc pack_func,
GtkStyleParseFunc parse_func,
GtkStylePrintFunc print_func,
- GtkStyleDefaultValueFunc default_value_func)
+ const GValue * initial_value)
{
- const GtkStyleProperty *existing;
GtkStyleProperty *node;
- g_return_if_fail ((pack_func == NULL) == (unpack_func == NULL));
-
- gtk_style_property_init ();
-
- existing = _gtk_style_property_lookup (pspec->name);
- if (existing != NULL)
- {
- g_warning ("Property \"%s\" was already registered with type %s",
- pspec->name, g_type_name (existing->pspec->value_type));
- return;
- }
-
- node = g_slice_new0 (GtkStyleProperty);
+ node = g_object_new (GTK_TYPE_CSS_STYLE_PROPERTY,
+ "name", pspec->name,
+ NULL);
node->flags = flags;
node->pspec = pspec;
node->property_parse_func = property_parse_func;
- node->pack_func = pack_func;
- node->unpack_func = unpack_func;
node->parse_func = parse_func;
node->print_func = print_func;
- node->default_value_func = default_value_func;
- g_hash_table_insert (properties, pspec->name, node);
+ _gtk_style_property_generate_id (node);
+
+ /* initialize the initial value */
+ if (initial_value)
+ {
+ g_value_init (&node->initial_value, G_VALUE_TYPE (initial_value));
+ g_value_copy (initial_value, &node->initial_value);
+ }
+ else
+ {
+ g_value_init (&node->initial_value, pspec->value_type);
+ if (pspec->value_type == GTK_TYPE_THEMING_ENGINE)
+ g_value_set_object (&node->initial_value, gtk_theming_engine_load (NULL));
+ else if (pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION)
+ g_value_take_boxed (&node->initial_value, pango_font_description_from_string ("Sans 10"));
+ else if (pspec->value_type == GDK_TYPE_RGBA)
+ {
+ GdkRGBA color;
+ gdk_rgba_parse (&color, "pink");
+ g_value_set_boxed (&node->initial_value, &color);
+ }
+ else if (pspec->value_type == GTK_TYPE_BORDER)
+ {
+ g_value_take_boxed (&node->initial_value, gtk_border_new ());
+ }
+ else
+ g_param_value_set_default (pspec, &node->initial_value);
+ }
}