#include <cairo-gobject.h>
#include <math.h>
-#include "gtkborderimageprivate.h"
+#include "gtkcssimageprivate.h"
#include "gtkcssstylefuncsprivate.h"
#include "gtkcsstypesprivate.h"
+#include "gtkprivatetypebuiltins.h"
+#include "gtktypebuiltins.h"
/* this is in case round() is not provided by the compiler,
* such as in the case of C89 compilers, like MSVC
return TRUE;
}
+static gboolean
+parse_border_style (GtkCssShorthandProperty *shorthand,
+ GValue *values,
+ GtkCssParser *parser,
+ GFile *base)
+{
+ GtkBorderStyle styles[4];
+ guint i;
+
+ for (i = 0; i < 4; i++)
+ {
+ if (!_gtk_css_parser_try_enum (parser, GTK_TYPE_BORDER_STYLE, (int *)&styles[i]))
+ break;
+ }
+
+ if (i == 0)
+ {
+ _gtk_css_parser_error (parser, "Expected a border style");
+ return FALSE;
+ }
+
+ for (; i < G_N_ELEMENTS (styles); i++)
+ styles[i] = styles[(i - 1) >> 1];
+
+ for (i = 0; i < G_N_ELEMENTS (styles); i++)
+ {
+ g_value_init (&values[i], GTK_TYPE_BORDER_STYLE);
+ g_value_set_enum (&values[i], styles[i]);
+ }
+
+ return TRUE;
+}
+
static gboolean
parse_border_image (GtkCssShorthandProperty *shorthand,
GValue *values,
GtkCssParser *parser,
GFile *base)
{
- g_value_init (&values[0], CAIRO_GOBJECT_TYPE_PATTERN);
- if (!_gtk_css_style_parse_value (&values[0], parser, base))
- return FALSE;
+ GtkCssImage *image;
+
+ if (_gtk_css_parser_try (parser, "none", TRUE))
+ image = NULL;
+ else
+ {
+ image = _gtk_css_image_new_parse (parser, base);
+ if (!image)
+ return FALSE;
+ }
+ g_value_init (&values[0], GTK_TYPE_CSS_IMAGE);
+ g_value_set_object (&values[0], image);
if (value_is_done_parsing (parser))
return TRUE;
return TRUE;
}
+static gboolean
+parse_background (GtkCssShorthandProperty *shorthand,
+ GValue *values,
+ GtkCssParser *parser,
+ GFile *base)
+{
+ int enum_value;
+
+ do
+ {
+ /* the image part */
+ if (!G_IS_VALUE (&values[0]) &&
+ (_gtk_css_parser_has_prefix (parser, "none") ||
+ _gtk_css_image_can_parse (parser)))
+ {
+ GtkCssImage *image;
+
+ if (_gtk_css_parser_try (parser, "none", TRUE))
+ image = NULL;
+ else
+ {
+ image = _gtk_css_image_new_parse (parser, base);
+ if (image == NULL)
+ return FALSE;
+ }
+
+ g_value_init (&values[0], GTK_TYPE_CSS_IMAGE);
+ g_value_take_object (&values[0], image);
+ }
+ else if (!G_IS_VALUE (&values[1]) &&
+ _gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT, &enum_value))
+ {
+ if (enum_value <= GTK_CSS_BACKGROUND_REPEAT_MASK)
+ {
+ int vertical;
+
+ if (_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT, &vertical))
+ {
+ if (vertical >= GTK_CSS_BACKGROUND_REPEAT_MASK)
+ {
+ _gtk_css_parser_error (parser, "Not a valid 2nd value for border-repeat");
+ return FALSE;
+ }
+ else
+ enum_value |= vertical << GTK_CSS_BACKGROUND_REPEAT_SHIFT;
+ }
+ else
+ enum_value |= enum_value << GTK_CSS_BACKGROUND_REPEAT_SHIFT;
+ }
+
+ g_value_init (&values[1], GTK_TYPE_CSS_BACKGROUND_REPEAT);
+ g_value_set_enum (&values[1], enum_value);
+ }
+ else if ((!G_IS_VALUE (&values[2]) || !G_IS_VALUE (&values[3])) &&
+ _gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_AREA, &enum_value))
+ {
+ guint idx = !G_IS_VALUE (&values[2]) ? 2 : 3;
+ g_value_init (&values[idx], GTK_TYPE_CSS_AREA);
+ g_value_set_enum (&values[idx], enum_value);
+ }
+ else if (!G_IS_VALUE (&values[4]))
+ {
+ GtkSymbolicColor *symbolic;
+
+ symbolic = _gtk_css_parser_read_symbolic_color (parser);
+ if (symbolic == NULL)
+ return FALSE;
+
+ g_value_init (&values[4], GTK_TYPE_SYMBOLIC_COLOR);
+ g_value_take_boxed (&values[4], symbolic);
+ }
+ else
+ {
+ /* We parsed everything and there's still stuff left?
+ * Pretend we didn't notice and let the normal code produce
+ * a 'junk at end of value' error */
+ break;
+ }
+ }
+ while (!value_is_done_parsing (parser));
+
+ return TRUE;
+}
+
/*** PACKING ***/
static GParameter *
static void
pack_border_width (GValue *value,
GtkStyleProperties *props,
- GtkStateFlags state,
- GtkStylePropertyContext *context)
+ GtkStateFlags state)
{
pack_border (value, props, state,
"border-top-width", "border-left-width",
static void
pack_padding (GValue *value,
GtkStyleProperties *props,
- GtkStateFlags state,
- GtkStylePropertyContext *context)
+ GtkStateFlags state)
{
pack_border (value, props, state,
"padding-top", "padding-left",
static void
pack_margin (GValue *value,
GtkStyleProperties *props,
- GtkStateFlags state,
- GtkStylePropertyContext *context)
+ GtkStateFlags state)
{
pack_border (value, props, state,
"margin-top", "margin-left",
static void
pack_border_radius (GValue *value,
GtkStyleProperties *props,
- GtkStateFlags state,
- GtkStylePropertyContext *context)
+ GtkStateFlags state)
{
GtkCssBorderCornerRadius *top_left;
static void
pack_font_description (GValue *value,
GtkStyleProperties *props,
- GtkStateFlags state,
- GtkStylePropertyContext *context)
+ GtkStateFlags state)
{
PangoFontDescription *description;
char **families;
static void
pack_border_color (GValue *value,
GtkStyleProperties *props,
- GtkStateFlags state,
- GtkStylePropertyContext *context)
+ GtkStateFlags state)
{
/* NB: We are a color property, so we have to resolve to a color here.
* So we just resolve to a color. We pick one and stick to it.
gtk_style_properties_get_property (props, "border-top-color", state, value);
}
+static GParameter *
+unpack_border_style (const GValue *value,
+ guint *n_params)
+{
+ GParameter *parameter = g_new0 (GParameter, 4);
+ GtkBorderStyle style;
+
+ style = g_value_get_enum (value);
+
+ parameter[0].name = "border-top-style";
+ g_value_init (¶meter[0].value, GTK_TYPE_BORDER_STYLE);
+ g_value_set_enum (¶meter[0].value, style);
+ parameter[1].name = "border-right-style";
+ g_value_init (¶meter[1].value, GTK_TYPE_BORDER_STYLE);
+ g_value_set_enum (¶meter[1].value, style);
+ parameter[2].name = "border-bottom-style";
+ g_value_init (¶meter[2].value, GTK_TYPE_BORDER_STYLE);
+ g_value_set_enum (¶meter[2].value, style);
+ parameter[3].name = "border-left-style";
+ g_value_init (¶meter[3].value, GTK_TYPE_BORDER_STYLE);
+ g_value_set_enum (¶meter[3].value, style);
+
+ *n_params = 4;
+ return parameter;
+}
+
+static void
+pack_border_style (GValue *value,
+ GtkStyleProperties *props,
+ GtkStateFlags state)
+{
+ /* NB: We can just resolve to a style. We pick one and stick to it.
+ * Lesson learned: Don't query border-style shorthand, query the
+ * real properties instead. */
+ g_value_unset (value);
+ gtk_style_properties_get_property (props, "border-top-style", state, value);
+}
+
static void
_gtk_css_shorthand_property_register (const char *name,
GType value_type,
const char **subproperties,
GtkCssShorthandPropertyParseFunc parse_func,
GtkStyleUnpackFunc unpack_func,
- GtkStylePackFunc pack_func,
- GtkStyleParseFunc old_parse_func)
+ GtkStylePackFunc pack_func)
{
GtkStyleProperty *node;
- g_return_if_fail (pack_func != NULL);
- g_return_if_fail (unpack_func != NULL);
-
node = g_object_new (GTK_TYPE_CSS_SHORTHAND_PROPERTY,
"name", name,
"value-type", value_type,
"subproperties", subproperties,
NULL);
- if (parse_func)
- GTK_CSS_SHORTHAND_PROPERTY (node)->parse = parse_func;
+ GTK_CSS_SHORTHAND_PROPERTY (node)->parse = parse_func;
node->pack_func = pack_func;
node->unpack_func = unpack_func;
- node->parse_func = old_parse_func;
}
void
const char *border_radius_subproperties[] = { "border-top-left-radius", "border-top-right-radius",
"border-bottom-right-radius", "border-bottom-left-radius", NULL };
const char *border_color_subproperties[] = { "border-top-color", "border-right-color", "border-bottom-color", "border-left-color", NULL };
+ const char *border_style_subproperties[] = { "border-top-style", "border-right-style", "border-bottom-style", "border-left-style", NULL };
const char *border_image_subproperties[] = { "border-image-source", "border-image-slice", "border-image-width", "border-image-repeat", NULL };
+ const char *background_subproperties[] = { "background-image", "background-repeat", "background-clip", "background-origin",
+ "background-color", NULL };
_gtk_css_shorthand_property_register ("font",
PANGO_TYPE_FONT_DESCRIPTION,
font_subproperties,
parse_font,
unpack_font_description,
- pack_font_description,
- NULL);
+ pack_font_description);
_gtk_css_shorthand_property_register ("margin",
GTK_TYPE_BORDER,
margin_subproperties,
parse_border,
unpack_margin,
- pack_margin,
- NULL);
+ pack_margin);
_gtk_css_shorthand_property_register ("padding",
GTK_TYPE_BORDER,
padding_subproperties,
parse_border,
unpack_padding,
- pack_padding,
- NULL);
+ pack_padding);
_gtk_css_shorthand_property_register ("border-width",
GTK_TYPE_BORDER,
border_width_subproperties,
parse_border,
unpack_border_width,
- pack_border_width,
- NULL);
+ pack_border_width);
_gtk_css_shorthand_property_register ("border-radius",
G_TYPE_INT,
border_radius_subproperties,
parse_border_radius,
unpack_border_radius,
- pack_border_radius,
- NULL);
+ pack_border_radius);
_gtk_css_shorthand_property_register ("border-color",
GDK_TYPE_RGBA,
border_color_subproperties,
parse_border_color,
unpack_border_color,
- pack_border_color,
- NULL);
+ pack_border_color);
+ _gtk_css_shorthand_property_register ("border-style",
+ GTK_TYPE_BORDER_STYLE,
+ border_style_subproperties,
+ parse_border_style,
+ unpack_border_style,
+ pack_border_style);
_gtk_css_shorthand_property_register ("border-image",
- GTK_TYPE_BORDER_IMAGE,
+ G_TYPE_NONE,
border_image_subproperties,
parse_border_image,
- _gtk_border_image_unpack,
- _gtk_border_image_pack,
+ NULL,
+ NULL);
+ _gtk_css_shorthand_property_register ("background",
+ G_TYPE_NONE,
+ background_subproperties,
+ parse_background,
+ NULL,
NULL);
}