X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkcssstyleproperty.c;h=0b7491524e421174e64c9185dfbc85e64e601ffb;hb=0ba92bc26d1b716f2f9c0543593f13cd5a92c521;hp=70d88a721a7072aff8d70aaf774bed907af80288;hpb=fd3afa3606009fc61de487707b64fb860b8e5b01;p=~andy%2Fgtk diff --git a/gtk/gtkcssstyleproperty.c b/gtk/gtkcssstyleproperty.c index 70d88a721..0b7491524 100644 --- a/gtk/gtkcssstyleproperty.c +++ b/gtk/gtkcssstyleproperty.c @@ -12,8 +12,7 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * License along with this library. If not, see . * * Authors: Benjamin Otte */ @@ -22,17 +21,25 @@ #include "gtkcssstylepropertyprivate.h" +#include "gtkcssenumvalueprivate.h" +#include "gtkcssinheritvalueprivate.h" +#include "gtkcssinitialvalueprivate.h" #include "gtkcssstylefuncsprivate.h" #include "gtkcsstypesprivate.h" #include "gtkintl.h" #include "gtkprivatetypebuiltins.h" #include "gtkstylepropertiesprivate.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 + */ +#include "fallback-c89.c" enum { PROP_0, + PROP_ANIMATED, + PROP_AFFECTS_SIZE, + PROP_AFFECTS_FONT, PROP_ID, PROP_INHERIT, PROP_INITIAL @@ -40,6 +47,11 @@ enum { G_DEFINE_TYPE (GtkCssStyleProperty, _gtk_css_style_property, GTK_TYPE_STYLE_PROPERTY) +static GtkBitmask *_properties_affecting_size = NULL; +static GtkBitmask *_properties_affecting_font = NULL; + +static GtkCssStylePropertyClass *gtk_css_style_property_class = NULL; + static void gtk_css_style_property_constructed (GObject *object) { @@ -49,6 +61,12 @@ gtk_css_style_property_constructed (GObject *object) property->id = klass->style_properties->len; g_ptr_array_add (klass->style_properties, property); + if (property->affects_size) + _properties_affecting_size = _gtk_bitmask_set (_properties_affecting_size, property->id, TRUE); + + if (property->affects_font) + _properties_affecting_font = _gtk_bitmask_set (_properties_affecting_font, property->id, TRUE); + G_OBJECT_CLASS (_gtk_css_style_property_parent_class)->constructed (object); } @@ -59,18 +77,24 @@ gtk_css_style_property_set_property (GObject *object, GParamSpec *pspec) { GtkCssStyleProperty *property = GTK_CSS_STYLE_PROPERTY (object); - const GValue *initial; switch (prop_id) { + case PROP_ANIMATED: + property->animated = g_value_get_boolean (value); + break; + case PROP_AFFECTS_SIZE: + property->affects_size = g_value_get_boolean (value); + break; + case PROP_AFFECTS_FONT: + property->affects_font = g_value_get_boolean (value); + break; case PROP_INHERIT: property->inherit = g_value_get_boolean (value); break; case PROP_INITIAL: - initial = g_value_get_boxed (value); - g_assert (initial); - g_value_init (&property->initial_value, G_VALUE_TYPE (initial)); - g_value_copy (initial, &property->initial_value); + property->initial_value = g_value_dup_boxed (value); + g_assert (property->initial_value != NULL); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -88,6 +112,15 @@ gtk_css_style_property_get_property (GObject *object, switch (prop_id) { + case PROP_ANIMATED: + g_value_set_boolean (value, property->animated); + break; + case PROP_AFFECTS_SIZE: + g_value_set_boolean (value, property->affects_size); + break; + case PROP_AFFECTS_FONT: + g_value_set_boolean (value, property->affects_font); + break; case PROP_ID: g_value_set_boolean (value, property->id); break; @@ -95,7 +128,7 @@ gtk_css_style_property_get_property (GObject *object, g_value_set_boolean (value, property->inherit); break; case PROP_INITIAL: - g_value_set_boxed (value, &property->initial_value); + g_value_set_boxed (value, property->initial_value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -109,61 +142,99 @@ _gtk_css_style_property_assign (GtkStyleProperty *property, GtkStateFlags state, const GValue *value) { + GtkCssStyleProperty *style; + GtkCssValue *css_value; + + style = GTK_CSS_STYLE_PROPERTY (property); + css_value = style->assign_value (style, value); + _gtk_style_properties_set_property_by_property (props, - GTK_CSS_STYLE_PROPERTY (property), + style, state, - value); + css_value); + _gtk_css_value_unref (css_value); +} + +static gboolean +_gtk_css_style_property_query_special_case (GtkCssStyleProperty *property, + GValue *value, + GtkStyleQueryFunc query_func, + gpointer query_data) +{ + GtkBorderStyle border_style; + + switch (property->id) + { + case GTK_CSS_PROPERTY_BORDER_TOP_WIDTH: + border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_BORDER_TOP_STYLE, query_data)); + if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN) + { + g_value_init (value, G_TYPE_INT); + return TRUE; + } + break; + case GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH: + border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_BORDER_RIGHT_STYLE, query_data)); + if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN) + { + g_value_init (value, G_TYPE_INT); + return TRUE; + } + break; + case GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH: + border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_BORDER_BOTTOM_STYLE, query_data)); + if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN) + { + g_value_init (value, G_TYPE_INT); + return TRUE; + } + break; + case GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH: + border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_BORDER_LEFT_STYLE, query_data)); + if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN) + { + g_value_init (value, G_TYPE_INT); + return TRUE; + } + break; + case GTK_CSS_PROPERTY_OUTLINE_WIDTH: + border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_OUTLINE_STYLE, query_data)); + if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN) + { + g_value_init (value, G_TYPE_INT); + return TRUE; + } + break; + default: + break; + } + + return FALSE; } static void _gtk_css_style_property_query (GtkStyleProperty *property, - GtkStyleProperties *props, - GtkStateFlags state, - GValue *value) + GValue *value, + GtkStyleQueryFunc query_func, + gpointer query_data) { - const GValue *val; + GtkCssStyleProperty *style_property = GTK_CSS_STYLE_PROPERTY (property); + GtkCssValue *css_value; - val = _gtk_style_properties_peek_property (props, GTK_CSS_STYLE_PROPERTY (property), state); - if (val) - { - /* Somebody make this a vfunc */ - if (G_VALUE_TYPE (val) == GTK_TYPE_CSS_IMAGE) - { - GtkCssImage *image = g_value_get_object (val); - cairo_pattern_t *pattern; - cairo_surface_t *surface; - cairo_matrix_t matrix; - - if (image == NULL) - g_value_set_boxed (value, NULL); - else if (GTK_IS_CSS_IMAGE_GRADIENT (image)) - g_value_set_boxed (value, GTK_CSS_IMAGE_GRADIENT (image)->pattern); - else - { - 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 - g_value_copy (val, value); - } - else - g_value_copy (_gtk_css_style_property_get_initial_value (GTK_CSS_STYLE_PROPERTY (property)), value); + /* I don't like this special case being here in this generic code path, but no idea where else to put it. */ + if (_gtk_css_style_property_query_special_case (style_property, value, query_func, query_data)) + return; + + css_value = (* query_func) (GTK_CSS_STYLE_PROPERTY (property)->id, query_data); + 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 gboolean +static GtkCssValue * gtk_css_style_property_parse_value (GtkStyleProperty *property, - GValue *value, - GtkCssParser *parser, - GFile *base) + GtkCssParser *parser) { GtkCssStyleProperty *style_property = GTK_CSS_STYLE_PROPERTY (property); @@ -172,9 +243,7 @@ gtk_css_style_property_parse_value (GtkStyleProperty *property, /* the initial value can be explicitly specified with the * ‘initial’ keyword which all properties accept. */ - g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE); - g_value_set_enum (value, GTK_CSS_INITIAL); - return TRUE; + return _gtk_css_initial_value_new (); } else if (_gtk_css_parser_try (parser, "inherit", TRUE)) { @@ -184,19 +253,10 @@ gtk_css_style_property_parse_value (GtkStyleProperty *property, * strengthen inherited values in the cascade, and it can * also be used on properties that are not normally inherited. */ - g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE); - g_value_set_enum (value, GTK_CSS_INHERIT); - return TRUE; - } - - g_value_init (value, _gtk_style_property_get_value_type (property)); - if (!(* style_property->parse_value) (style_property, value, parser, base)) - { - g_value_unset (value); - return FALSE; + return _gtk_css_inherit_value_new (); } - return TRUE; + return (* style_property->parse_value) (style_property, parser); } static void @@ -209,6 +269,27 @@ _gtk_css_style_property_class_init (GtkCssStylePropertyClass *klass) object_class->set_property = gtk_css_style_property_set_property; object_class->get_property = gtk_css_style_property_get_property; + g_object_class_install_property (object_class, + PROP_ANIMATED, + g_param_spec_boolean ("animated", + P_("Animated"), + P_("Set if the value can be animated"), + FALSE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, + PROP_AFFECTS_SIZE, + g_param_spec_boolean ("affects-size", + P_("Affects size"), + P_("Set if the value affects the sizing of elements"), + TRUE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, + PROP_AFFECTS_FONT, + g_param_spec_boolean ("affects-font", + P_("Affects font"), + P_("Set if the value affects the font"), + FALSE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (object_class, PROP_ID, g_param_spec_uint ("id", @@ -228,7 +309,7 @@ _gtk_css_style_property_class_init (GtkCssStylePropertyClass *klass) g_param_spec_boxed ("initial-value", P_("Initial value"), P_("The initial specified value used for this property"), - G_TYPE_VALUE, + GTK_TYPE_CSS_VALUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); property_class->assign = _gtk_css_style_property_assign; @@ -236,41 +317,25 @@ _gtk_css_style_property_class_init (GtkCssStylePropertyClass *klass) property_class->parse_value = gtk_css_style_property_parse_value; klass->style_properties = g_ptr_array_new (); -} -static gboolean -gtk_css_style_property_real_parse_value (GtkCssStyleProperty *property, - GValue *value, - GtkCssParser *parser, - GFile *base) -{ - return _gtk_css_style_parse_value (value, parser, base); -} + _properties_affecting_size = _gtk_bitmask_new (); + _properties_affecting_font = _gtk_bitmask_new (); -static void -gtk_css_style_property_real_print_value (GtkCssStyleProperty *property, - const GValue *value, - GString *string) -{ - _gtk_css_style_print_value (value, string); + gtk_css_style_property_class = klass; } -static void -gtk_css_style_property_real_compute_value (GtkCssStyleProperty *property, - GValue *computed, - GtkStyleContext *context, - const GValue *specified) +static GtkCssValue * +gtk_css_style_property_real_parse_value (GtkCssStyleProperty *property, + GtkCssParser *parser) { - g_value_init (computed, _gtk_style_property_get_value_type (GTK_STYLE_PROPERTY (property))); - _gtk_css_style_compute_value (computed, context, specified); + g_assert_not_reached (); + return NULL; } static void _gtk_css_style_property_init (GtkCssStyleProperty *property) { property->parse_value = gtk_css_style_property_real_parse_value; - property->print_value = gtk_css_style_property_real_print_value; - property->compute_value = gtk_css_style_property_real_compute_value; } /** @@ -284,11 +349,13 @@ _gtk_css_style_property_init (GtkCssStyleProperty *property) guint _gtk_css_style_property_get_n_properties (void) { - GtkCssStylePropertyClass *klass; - - klass = g_type_class_peek (GTK_TYPE_CSS_STYLE_PROPERTY); + if (G_UNLIKELY (gtk_css_style_property_class == NULL)) + { + _gtk_style_property_init_properties (); + g_assert (gtk_css_style_property_class); + } - return klass->style_properties->len; + return gtk_css_style_property_class->style_properties->len; } /** @@ -304,11 +371,16 @@ _gtk_css_style_property_get_n_properties (void) GtkCssStyleProperty * _gtk_css_style_property_lookup_by_id (guint id) { - GtkCssStylePropertyClass *klass; - klass = g_type_class_peek (GTK_TYPE_CSS_STYLE_PROPERTY); + if (G_UNLIKELY (gtk_css_style_property_class == NULL)) + { + _gtk_style_property_init_properties (); + g_assert (gtk_css_style_property_class); + } + + g_return_val_if_fail (id < gtk_css_style_property_class->style_properties->len, NULL); - return g_ptr_array_index (klass->style_properties, id); + return g_ptr_array_index (gtk_css_style_property_class->style_properties, id); } /** @@ -324,11 +396,65 @@ _gtk_css_style_property_lookup_by_id (guint id) gboolean _gtk_css_style_property_is_inherit (GtkCssStyleProperty *property) { - g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), 0); + g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), FALSE); return property->inherit; } +/** + * _gtk_css_style_property_is_animated: + * @property: the property + * + * Queries if the given @property can be is animated. See + * - * the CSS documentation. - **/ -void -_gtk_css_style_property_compute_value (GtkCssStyleProperty *property, - GValue *computed, - GtkStyleContext *context, - const GValue *specified) +gboolean +_gtk_css_style_property_changes_affect_size (const GtkBitmask *changes) { - g_return_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property)); - g_return_if_fail (computed != NULL && !G_IS_VALUE (computed)); - g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); - g_return_if_fail (G_IS_VALUE (specified)); - - property->compute_value (property, computed, context, specified); + return _gtk_bitmask_intersects (changes, _properties_affecting_size); } -/** - * _gtk_css_style_property_print_value: - * @property: the property - * @value: the value to print - * @string: the string to print to - * - * Prints @value to the given @string in CSS format. The @value must be a - * valid specified value as parsed using the parse functions or as assigned - * via _gtk_style_property_assign(). - **/ -void -_gtk_css_style_property_print_value (GtkCssStyleProperty *property, - const GValue *value, - GString *string) +gboolean +_gtk_css_style_property_changes_affect_font (const GtkBitmask *changes) { - g_return_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property)); - g_return_if_fail (value != NULL); - g_return_if_fail (string != NULL); - - if (G_VALUE_HOLDS (value, GTK_TYPE_CSS_SPECIAL_VALUE)) - { - GEnumClass *enum_class; - GEnumValue *enum_value; - - enum_class = g_type_class_ref (GTK_TYPE_CSS_SPECIAL_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); - } - else - property->print_value (property, value, string); + return _gtk_bitmask_intersects (changes, _properties_affecting_font); } -