#include "gtkprivatetypebuiltins.h"
#include "gtkstylepropertiesprivate.h"
-#include <math.h>
-#include <cairo-gobject.h>
-#include "gtkcssimagegradientprivate.h"
-#include "gtkcssimageprivate.h"
-
/* this is in case round() is not provided by the compiler,
* such as in the case of C89 compilers, like MSVC
*/
GtkStyleQueryFunc query_func,
gpointer query_data)
{
+ GtkCssStyleProperty *style_property = GTK_CSS_STYLE_PROPERTY (property);
GtkCssValue *css_value;
css_value = (* query_func) (GTK_CSS_STYLE_PROPERTY (property)->id, query_data);
- if (css_value)
- {
- /* Somebody make this a vfunc */
- if (_gtk_css_value_holds (css_value, GTK_TYPE_CSS_IMAGE))
- {
- GtkCssImage *image = _gtk_css_value_get_image (css_value);
- cairo_pattern_t *pattern;
- cairo_surface_t *surface;
- cairo_matrix_t matrix;
-
- g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
-
- if (GTK_IS_CSS_IMAGE_GRADIENT (image))
- g_value_set_boxed (value, GTK_CSS_IMAGE_GRADIENT (image)->pattern);
- else if (image != NULL)
- {
- double width, height;
-
- /* the 100, 100 is rather random */
- _gtk_css_image_get_concrete_size (image, 0, 0, 100, 100, &width, &height);
- surface = _gtk_css_image_get_surface (image, NULL, width, height);
- pattern = cairo_pattern_create_for_surface (surface);
- cairo_matrix_init_scale (&matrix, width, height);
- cairo_pattern_set_matrix (pattern, &matrix);
- cairo_surface_destroy (surface);
- g_value_take_boxed (value, pattern);
- }
- }
- else if (_gtk_css_value_holds (css_value, GTK_TYPE_CSS_NUMBER))
- {
- g_value_init (value, G_TYPE_INT);
- g_value_set_int (value, round (_gtk_css_number_get (_gtk_css_value_get_number (css_value), 100)));
- }
- else
- {
- _gtk_css_value_init_gvalue (css_value, value);
- }
- }
- else
- {
- _gtk_css_value_init_gvalue (_gtk_css_style_property_get_initial_value (GTK_CSS_STYLE_PROPERTY (property)),
- value);
- }
+ if (css_value == NULL)
+ css_value =_gtk_css_style_property_get_initial_value (style_property);
+
+ style_property->query_value (style_property, css_value, value);
}
static GtkCssValue *
/* the actual parsers we have */
#include "gtkanimationdescription.h"
#include "gtkbindings.h"
+#include "gtkcssimagegradientprivate.h"
+#include "gtkcssimageprivate.h"
#include "gtkcssimageprivate.h"
#include "gtkgradient.h"
#include "gtkshadowprivate.h"
GtkCssStylePropertyParseFunc parse_value,
GtkCssStylePropertyPrintFunc print_value,
GtkCssStylePropertyComputeFunc compute_value,
+ GtkCssStylePropertyQueryFunc query_value,
GtkCssStylePropertyEqualFunc equal_func,
GtkCssValue * initial_value)
{
g_assert (initial_value != NULL);
g_assert (parse_value != NULL);
+ g_assert (value_type == G_TYPE_NONE || query_value != NULL);
node = g_object_new (GTK_TYPE_CSS_STYLE_PROPERTY,
"value-type", value_type,
node->print_value = print_value;
if (compute_value)
node->compute_value = compute_value;
+ node->query_value = query_value;
if (equal_func)
node->equal_func = equal_func;
/*** IMPLEMENTATIONS ***/
+static void
+query_simple (GtkCssStyleProperty *property,
+ const GtkCssValue *css_value,
+ GValue *value)
+{
+ _gtk_css_value_init_gvalue (css_value, value);
+}
+
+static void
+query_length_as_int (GtkCssStyleProperty *property,
+ const GtkCssValue *css_value,
+ GValue *value)
+{
+ g_value_init (value, G_TYPE_INT);
+ g_value_set_int (value, round (_gtk_css_number_get (_gtk_css_value_get_number (css_value), 100)));
+}
+
static GtkCssValue *
color_parse (GtkCssStyleProperty *property,
GtkCssParser *parser,
return _gtk_css_value_new_take_image (computed);
}
+static void
+css_image_value_query (GtkCssStyleProperty *property,
+ const GtkCssValue *css_value,
+ GValue *value)
+{
+ GtkCssImage *image = _gtk_css_value_get_image (css_value);
+ cairo_pattern_t *pattern;
+ cairo_surface_t *surface;
+ cairo_matrix_t matrix;
+
+ g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
+
+ if (GTK_IS_CSS_IMAGE_GRADIENT (image))
+ g_value_set_boxed (value, GTK_CSS_IMAGE_GRADIENT (image)->pattern);
+ else if (image != NULL)
+ {
+ double width, height;
+
+ /* the 100, 100 is rather random */
+ _gtk_css_image_get_concrete_size (image, 0, 0, 100, 100, &width, &height);
+ surface = _gtk_css_image_get_surface (image, NULL, width, height);
+ pattern = cairo_pattern_create_for_surface (surface);
+ cairo_matrix_init_scale (&matrix, width, height);
+ cairo_pattern_set_matrix (pattern, &matrix);
+ cairo_surface_destroy (surface);
+ g_value_take_boxed (value, pattern);
+ }
+}
+
static GtkCssValue *
font_size_parse (GtkCssStyleProperty *property,
GtkCssParser *parser,
GtkCssStyleProperty *style;
GtkBorderStyle border_style;
GtkCssNumber number;
- int value = 0;
/* The -1 is magic that is only true because we register the style
* properties directly after the width properties.
if (border_style == GTK_BORDER_STYLE_NONE ||
border_style == GTK_BORDER_STYLE_HIDDEN)
{
- value = 0;
+ _gtk_css_number_init (&number, 0, GTK_CSS_PX);
}
else
{
_gtk_css_number_compute (&number,
_gtk_css_value_get_number (specified),
context);
- value = round (number.value);
}
- return _gtk_css_value_new_from_int (value);
+ return _gtk_css_value_new_from_number (&number);
}
static GtkCssValue *
color_parse,
NULL,
color_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_symbolic_color (
gtk_symbolic_color_new_rgba (1, 1, 1, 1)));
font_size_parse,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_double (10.0));
color_parse,
NULL,
color_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_symbolic_color (
gtk_symbolic_color_new_rgba (0, 0, 0, 0)));
font_family_parse,
font_family_value_print,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_take_strv (g_strdupv (default_font_family)));
gtk_css_style_property_register ("font-style",
parse_pango_style,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_enum (PANGO_TYPE_STYLE,
PANGO_STYLE_NORMAL));
parse_pango_variant,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_enum (PANGO_TYPE_VARIANT,
PANGO_VARIANT_NORMAL));
parse_pango_weight,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_enum (PANGO_TYPE_WEIGHT,
PANGO_WEIGHT_NORMAL));
shadow_value_parse,
shadow_value_print,
shadow_value_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_shadow (NULL));
shadow_value_parse,
shadow_value_print,
shadow_value_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_shadow (NULL));
shadow_value_parse,
shadow_value_print,
shadow_value_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_shadow (NULL));
parse_margin,
NULL,
compute_margin,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
gtk_css_style_property_register ("margin-left",
parse_margin,
NULL,
compute_margin,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
gtk_css_style_property_register ("margin-bottom",
parse_margin,
NULL,
compute_margin,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
gtk_css_style_property_register ("margin-right",
parse_margin,
NULL,
compute_margin,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
gtk_css_style_property_register ("padding-top",
parse_padding,
NULL,
compute_padding,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
gtk_css_style_property_register ("padding-left",
parse_padding,
NULL,
compute_padding,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
gtk_css_style_property_register ("padding-bottom",
parse_padding,
NULL,
compute_padding,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
gtk_css_style_property_register ("padding-right",
parse_padding,
NULL,
compute_padding,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
/* IMPORTANT: compute_border_width() requires that the border-width
parse_border_style,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_border_style (GTK_BORDER_STYLE_NONE));
gtk_css_style_property_register ("border-top-width",
parse_border_width,
NULL,
compute_border_width,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
gtk_css_style_property_register ("border-left-style",
parse_border_style,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_border_style (GTK_BORDER_STYLE_NONE));
gtk_css_style_property_register ("border-left-width",
parse_border_width,
NULL,
compute_border_width,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
gtk_css_style_property_register ("border-bottom-style",
parse_border_style,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_border_style (GTK_BORDER_STYLE_NONE));
gtk_css_style_property_register ("border-bottom-width",
parse_border_width,
NULL,
compute_border_width,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
gtk_css_style_property_register ("border-right-style",
parse_border_style,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_border_style (GTK_BORDER_STYLE_NONE));
gtk_css_style_property_register ("border-right-width",
parse_border_width,
NULL,
compute_border_width,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
border_corner_radius_value_parse,
border_corner_radius_value_print,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_border_corner_radius (&no_corner_radius));
gtk_css_style_property_register ("border-top-right-radius",
border_corner_radius_value_parse,
border_corner_radius_value_print,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_border_corner_radius (&no_corner_radius));
gtk_css_style_property_register ("border-bottom-right-radius",
border_corner_radius_value_parse,
border_corner_radius_value_print,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_border_corner_radius (&no_corner_radius));
gtk_css_style_property_register ("border-bottom-left-radius",
border_corner_radius_value_parse,
border_corner_radius_value_print,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_border_corner_radius (&no_corner_radius));
parse_border_style,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_border_style (GTK_BORDER_STYLE_NONE));
gtk_css_style_property_register ("outline-width",
parse_border_width,
NULL,
compute_border_width,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
gtk_css_style_property_register ("outline-offset",
outline_parse,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_int (0));
parse_css_area,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_enum (GTK_TYPE_CSS_AREA, GTK_CSS_AREA_BORDER_BOX));
gtk_css_style_property_register ("background-origin",
parse_css_area,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_enum (GTK_TYPE_CSS_AREA, GTK_CSS_AREA_PADDING_BOX));
gtk_css_style_property_register ("background-size",
background_size_print,
background_size_compute,
NULL,
+ NULL,
_gtk_css_value_new_from_background_size (&default_background_size));
gtk_css_style_property_register ("background-position",
G_TYPE_NONE,
background_position_print,
background_position_compute,
NULL,
+ NULL,
_gtk_css_value_new_from_background_position (&default_background_position));
gtk_css_style_property_register ("border-top-color",
color_parse,
NULL,
color_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_symbolic_color (
gtk_symbolic_color_ref (
color_parse,
NULL,
color_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_symbolic_color (
gtk_symbolic_color_ref (
color_parse,
NULL,
color_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_symbolic_color (
gtk_symbolic_color_ref (
color_parse,
NULL,
color_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_symbolic_color (
gtk_symbolic_color_ref (
color_parse,
NULL,
color_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_symbolic_color (
gtk_symbolic_color_ref (
background_repeat_value_parse,
background_repeat_value_print,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_enum (GTK_TYPE_CSS_BACKGROUND_REPEAT,
GTK_CSS_BACKGROUND_REPEAT |
css_image_value_parse,
css_image_value_print,
css_image_value_compute,
+ css_image_value_query,
NULL,
_gtk_css_value_new_take_image (NULL));
css_image_value_parse,
css_image_value_print,
css_image_value_compute,
+ css_image_value_query,
NULL,
_gtk_css_value_new_take_image (NULL));
gtk_css_style_property_register ("border-image-repeat",
border_image_repeat_parse,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_border_image_repeat (&border_image_repeat));
border_image_slice_parse,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_boxed (GTK_TYPE_BORDER, &border_of_ones));
gtk_css_style_property_register ("border-image-width",
border_image_width_parse,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_boxed (GTK_TYPE_BORDER, NULL));
gtk_css_style_property_register ("engine",
engine_parse,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_theming_engine (gtk_theming_engine_load (NULL)));
gtk_css_style_property_register ("transition",
transition_parse,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_boxed (GTK_TYPE_ANIMATION_DESCRIPTION, NULL));
bindings_value_parse,
bindings_value_print,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_take_binding_sets (NULL));
}