[gtk+/wip/cssvalue: 62/142] cssstyleproperty: Make query func a vfunc
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/cssvalue: 62/142] cssstyleproperty: Make query func a vfunc
- Date: Sat, 7 Apr 2012 19:51:35 +0000 (UTC)
commit d39ba901e1a51f10b08ccb7421363d22efbaefda
Author: Benjamin Otte <otte redhat com>
Date: Tue Mar 27 23:54:06 2012 +0200
cssstyleproperty: Make query func a vfunc
This will be needed soon.
gtk/gtkcssstyleproperty.c | 53 ++-----------------
gtk/gtkcssstylepropertyimpl.c | 108 ++++++++++++++++++++++++++++++++++++--
gtk/gtkcssstylepropertyprivate.h | 4 ++
3 files changed, 113 insertions(+), 52 deletions(-)
---
diff --git a/gtk/gtkcssstyleproperty.c b/gtk/gtkcssstyleproperty.c
index 6921b08..338f256 100644
--- a/gtk/gtkcssstyleproperty.c
+++ b/gtk/gtkcssstyleproperty.c
@@ -29,11 +29,6 @@
#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
*/
@@ -128,52 +123,14 @@ _gtk_css_style_property_query (GtkStyleProperty *property,
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 *
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index dfd209f..8bfc4c8 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -40,6 +40,8 @@
/* 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"
@@ -57,6 +59,7 @@ gtk_css_style_property_register (const char * name,
GtkCssStylePropertyParseFunc parse_value,
GtkCssStylePropertyPrintFunc print_value,
GtkCssStylePropertyComputeFunc compute_value,
+ GtkCssStylePropertyQueryFunc query_value,
GtkCssStylePropertyEqualFunc equal_func,
GtkCssValue * initial_value)
{
@@ -64,6 +67,7 @@ gtk_css_style_property_register (const char * name,
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,
@@ -77,6 +81,7 @@ gtk_css_style_property_register (const char * name,
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;
@@ -124,6 +129,23 @@ string_append_string (GString *str,
/*** 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,
@@ -600,6 +622,35 @@ css_image_value_compute (GtkCssStyleProperty *property,
return _gtk_css_value_new_take_image (image);
}
+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,
@@ -836,7 +887,6 @@ compute_border_width (GtkCssStyleProperty *property,
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.
@@ -848,16 +898,15 @@ compute_border_width (GtkCssStyleProperty *property,
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 *
@@ -1219,6 +1268,7 @@ _gtk_css_style_property_init_properties (void)
color_parse,
NULL,
color_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_symbolic_color (
gtk_symbolic_color_new_rgba (1, 1, 1, 1)));
@@ -1228,6 +1278,7 @@ _gtk_css_style_property_init_properties (void)
font_size_parse,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_double (10.0));
@@ -1239,6 +1290,7 @@ _gtk_css_style_property_init_properties (void)
color_parse,
NULL,
color_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_symbolic_color (
gtk_symbolic_color_new_rgba (0, 0, 0, 0)));
@@ -1249,6 +1301,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1257,6 +1310,7 @@ _gtk_css_style_property_init_properties (void)
parse_pango_style,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_enum (PANGO_TYPE_STYLE,
PANGO_STYLE_NORMAL));
@@ -1266,6 +1320,7 @@ _gtk_css_style_property_init_properties (void)
parse_pango_variant,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_enum (PANGO_TYPE_VARIANT,
PANGO_VARIANT_NORMAL));
@@ -1276,6 +1331,7 @@ _gtk_css_style_property_init_properties (void)
parse_pango_weight,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_enum (PANGO_TYPE_WEIGHT,
PANGO_WEIGHT_NORMAL));
@@ -1286,6 +1342,7 @@ _gtk_css_style_property_init_properties (void)
shadow_value_parse,
shadow_value_print,
shadow_value_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_shadow (NULL));
@@ -1295,6 +1352,7 @@ _gtk_css_style_property_init_properties (void)
shadow_value_parse,
shadow_value_print,
shadow_value_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_shadow (NULL));
@@ -1304,6 +1362,7 @@ _gtk_css_style_property_init_properties (void)
shadow_value_parse,
shadow_value_print,
shadow_value_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_shadow (NULL));
@@ -1314,6 +1373,7 @@ _gtk_css_style_property_init_properties (void)
parse_margin,
NULL,
compute_margin,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
gtk_css_style_property_register ("margin-left",
@@ -1322,6 +1382,7 @@ _gtk_css_style_property_init_properties (void)
parse_margin,
NULL,
compute_margin,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
gtk_css_style_property_register ("margin-bottom",
@@ -1330,6 +1391,7 @@ _gtk_css_style_property_init_properties (void)
parse_margin,
NULL,
compute_margin,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
gtk_css_style_property_register ("margin-right",
@@ -1338,6 +1400,7 @@ _gtk_css_style_property_init_properties (void)
parse_margin,
NULL,
compute_margin,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
gtk_css_style_property_register ("padding-top",
@@ -1346,6 +1409,7 @@ _gtk_css_style_property_init_properties (void)
parse_padding,
NULL,
compute_padding,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
gtk_css_style_property_register ("padding-left",
@@ -1354,6 +1418,7 @@ _gtk_css_style_property_init_properties (void)
parse_padding,
NULL,
compute_padding,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
gtk_css_style_property_register ("padding-bottom",
@@ -1362,6 +1427,7 @@ _gtk_css_style_property_init_properties (void)
parse_padding,
NULL,
compute_padding,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
gtk_css_style_property_register ("padding-right",
@@ -1370,6 +1436,7 @@ _gtk_css_style_property_init_properties (void)
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
@@ -1381,6 +1448,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1389,6 +1457,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1397,6 +1466,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1405,6 +1475,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1413,6 +1484,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1421,6 +1493,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1429,6 +1502,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1437,6 +1511,7 @@ _gtk_css_style_property_init_properties (void)
parse_border_width,
NULL,
compute_border_width,
+ query_length_as_int,
NULL,
_gtk_css_value_new_from_number (&number));
@@ -1446,6 +1521,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1454,6 +1530,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1462,6 +1539,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1470,6 +1548,7 @@ _gtk_css_style_property_init_properties (void)
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));
@@ -1479,6 +1558,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1487,6 +1567,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1495,6 +1576,7 @@ _gtk_css_style_property_init_properties (void)
outline_parse,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_int (0));
@@ -1504,6 +1586,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1512,6 +1595,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1521,6 +1605,7 @@ _gtk_css_style_property_init_properties (void)
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,
@@ -1529,6 +1614,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1537,6 +1623,7 @@ _gtk_css_style_property_init_properties (void)
color_parse,
NULL,
color_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_symbolic_color (
gtk_symbolic_color_ref (
@@ -1547,6 +1634,7 @@ _gtk_css_style_property_init_properties (void)
color_parse,
NULL,
color_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_symbolic_color (
gtk_symbolic_color_ref (
@@ -1557,6 +1645,7 @@ _gtk_css_style_property_init_properties (void)
color_parse,
NULL,
color_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_symbolic_color (
gtk_symbolic_color_ref (
@@ -1567,6 +1656,7 @@ _gtk_css_style_property_init_properties (void)
color_parse,
NULL,
color_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_symbolic_color (
gtk_symbolic_color_ref (
@@ -1577,6 +1667,7 @@ _gtk_css_style_property_init_properties (void)
color_parse,
NULL,
color_compute,
+ query_simple,
NULL,
_gtk_css_value_new_take_symbolic_color (
gtk_symbolic_color_ref (
@@ -1588,6 +1679,7 @@ _gtk_css_style_property_init_properties (void)
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 |
@@ -1598,6 +1690,7 @@ _gtk_css_style_property_init_properties (void)
css_image_value_parse,
css_image_value_print,
css_image_value_compute,
+ css_image_value_query,
NULL,
_gtk_css_value_new_take_image (NULL));
@@ -1607,6 +1700,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1615,6 +1709,7 @@ _gtk_css_style_property_init_properties (void)
border_image_repeat_parse,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_border_image_repeat (&border_image_repeat));
@@ -1625,6 +1720,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1633,6 +1729,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1641,6 +1738,7 @@ _gtk_css_style_property_init_properties (void)
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",
@@ -1649,6 +1747,7 @@ _gtk_css_style_property_init_properties (void)
transition_parse,
NULL,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_from_boxed (GTK_TYPE_ANIMATION_DESCRIPTION, NULL));
@@ -1659,6 +1758,7 @@ _gtk_css_style_property_init_properties (void)
bindings_value_parse,
bindings_value_print,
NULL,
+ query_simple,
NULL,
_gtk_css_value_new_take_binding_sets (NULL));
}
diff --git a/gtk/gtkcssstylepropertyprivate.h b/gtk/gtkcssstylepropertyprivate.h
index beb21e9..f16ece4 100644
--- a/gtk/gtkcssstylepropertyprivate.h
+++ b/gtk/gtkcssstylepropertyprivate.h
@@ -43,6 +43,9 @@ typedef void (* GtkCssStylePropertyPrintFunc) (GtkCssStyleProperty
typedef GtkCssValue * (* GtkCssStylePropertyComputeFunc)(GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified);
+typedef void (* GtkCssStylePropertyQueryFunc) (GtkCssStyleProperty *property,
+ const GtkCssValue *cssvalue,
+ GValue *value);
typedef gboolean (* GtkCssStylePropertyEqualFunc) (GtkCssStyleProperty *property,
GtkCssValue *value1,
GtkCssValue *value2);
@@ -57,6 +60,7 @@ struct _GtkCssStyleProperty
GtkCssStylePropertyParseFunc parse_value;
GtkCssStylePropertyPrintFunc print_value;
GtkCssStylePropertyComputeFunc compute_value;
+ GtkCssStylePropertyQueryFunc query_value;
GtkCssStylePropertyEqualFunc equal_func;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]