X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkcssvalue.c;h=6d77cf80c94fe299ddb11897e658de4991fab853;hb=190dcfe050814e979c364bf74ae83530aba4c686;hp=7bd1a55e45abedf28e3e0503f84d2bd37b8890d4;hpb=df45983fcb26b0cab9fa95b40c87f5029eecb133;p=~andy%2Fgtk diff --git a/gtk/gtkcssvalue.c b/gtk/gtkcssvalue.c index 7bd1a55e4..6d77cf80c 100644 --- a/gtk/gtkcssvalue.c +++ b/gtk/gtkcssvalue.c @@ -17,322 +17,18 @@ #include "config.h" +#include "gtkprivate.h" #include "gtkcssvalueprivate.h" -#include "gtkcssstylefuncsprivate.h" -#include "gtktypebuiltins.h" -#include "gtkgradient.h" -#include -#include "gtkprivatetypebuiltins.h" -#include "fallback-c89.c" +#include "gtkcsscomputedvaluesprivate.h" +#include "gtkstyleproviderprivate.h" -struct _GtkCssValue -{ +struct _GtkCssValue { GTK_CSS_VALUE_BASE - GType type; - union { - gpointer ptr; - gint gint; - guint guint; - double dbl; - float flt; - } u; -}; - -static void -gtk_css_value_default_free (GtkCssValue *value) -{ - GType type = value->type; - - if (g_type_is_a (type, G_TYPE_OBJECT)) - { - if (value->u.ptr != NULL) - g_object_unref (value->u.ptr); - } - else if (g_type_is_a (type, G_TYPE_BOXED)) - { - if (value->u.ptr != NULL) - g_boxed_free (type, value->u.ptr); - } - else if (g_type_is_a (type, G_TYPE_STRING)) - g_free (value->u.ptr); - else if (g_type_is_a (type, G_TYPE_INT)) - {} - else if (g_type_is_a (type, G_TYPE_UINT)) - {} - else if (g_type_is_a (type, G_TYPE_BOOLEAN)) - {} - else if (g_type_is_a (type, G_TYPE_ENUM)) - {} - else if (g_type_is_a (type, G_TYPE_FLAGS)) - {} - else if (g_type_is_a (type, G_TYPE_DOUBLE)) - {} - else if (g_type_is_a (type, G_TYPE_FLOAT)) - {} - else - { - g_value_unset (value->u.ptr); - g_slice_free (GValue, value->u.ptr); - } - - g_slice_free (GtkCssValue, value); -} - -static void -gtk_css_value_default_print (const GtkCssValue *value, - GString *string) -{ - GValue g_value = G_VALUE_INIT; - - _gtk_css_value_init_gvalue (value, &g_value); - _gtk_css_style_print_value (&g_value, string); - g_value_unset (&g_value); -} - -static const GtkCssValueClass GTK_CSS_VALUE_DEFAULT = { - gtk_css_value_default_free, - gtk_css_value_default_print }; G_DEFINE_BOXED_TYPE (GtkCssValue, _gtk_css_value, _gtk_css_value_ref, _gtk_css_value_unref) -static GtkCssValue * -gtk_css_value_new (GType type) -{ - GtkCssValue *value; - - value = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_DEFAULT); - - value->type = type; - - return value; -} - -GtkCssValue * -_gtk_css_value_new_from_gvalue (const GValue *g_value) -{ - GtkCssValue *value; - GType type; - - g_return_val_if_fail (g_value != NULL, NULL); - - type = G_VALUE_TYPE (g_value); - - /* Make sure we reuse the int/number singletons */ - if (type == G_TYPE_INT) - value = _gtk_css_value_new_from_int (g_value_get_int (g_value)); - else if (type == GTK_TYPE_CSS_NUMBER) - value = _gtk_css_value_new_from_number (g_value_get_boxed (g_value)); - else - { - value = gtk_css_value_new (type); - - if (g_type_is_a (type, G_TYPE_OBJECT)) - value->u.ptr = g_value_dup_object (g_value); - else if (g_type_is_a (type, G_TYPE_BOXED)) - value->u.ptr = g_value_dup_boxed (g_value); - else if (g_type_is_a (type, G_TYPE_INT)) - value->u.gint = g_value_get_int (g_value); - else if (g_type_is_a (type, G_TYPE_UINT)) - value->u.guint = g_value_get_uint (g_value); - else if (g_type_is_a (type, G_TYPE_BOOLEAN)) - value->u.gint = g_value_get_boolean (g_value); - else if (g_type_is_a (type, G_TYPE_ENUM)) - value->u.gint = g_value_get_enum (g_value); - else if (g_type_is_a (type, G_TYPE_FLAGS)) - value->u.guint = g_value_get_flags (g_value); - else if (g_type_is_a (type, G_TYPE_STRING)) - value->u.ptr = g_value_dup_string (g_value); - else if (g_type_is_a (type, G_TYPE_DOUBLE)) - value->u.dbl = g_value_get_double (g_value); - else if (g_type_is_a (type, G_TYPE_FLOAT)) - value->u.flt = g_value_get_float (g_value); - else - { - value->u.ptr = g_slice_new0 (GValue); - g_value_init (value->u.ptr, G_VALUE_TYPE (g_value)); - g_value_copy (g_value, value->u.ptr); - } - } - - return value; -} - -GtkCssValue * -_gtk_css_value_new_from_int (gint val) -{ - GtkCssValue *value; - static GtkCssValue *singletons[4] = {NULL}; - - if (val >= 0 && val < G_N_ELEMENTS (singletons)) - { - if (singletons[val] == NULL) - { - value = gtk_css_value_new (G_TYPE_INT); - value->u.gint = val; - singletons[val] = value; - } - return _gtk_css_value_ref (singletons[val]); - } - - value = gtk_css_value_new (G_TYPE_INT); - value->u.gint = val; - - return value; -} - -GtkCssValue * -_gtk_css_value_new_take_string (char *string) -{ - GtkCssValue *value; - - value = gtk_css_value_new (G_TYPE_STRING); - value->u.ptr = string; - - return value; -} - -static gpointer -g_boxed_copy0 (GType boxed_type, - gconstpointer src_boxed) -{ - if (src_boxed == NULL) - return NULL; - return g_boxed_copy (boxed_type, src_boxed); -} - -GtkCssValue * -_gtk_css_value_new_take_pattern (cairo_pattern_t *v) -{ - GtkCssValue *value; - - value = gtk_css_value_new (CAIRO_GOBJECT_TYPE_PATTERN); - value->u.ptr = v; - - return value; -} - -GtkCssValue * -_gtk_css_value_new_take_shadow (GtkShadow *v) -{ - GtkCssValue *value; - - value = gtk_css_value_new (GTK_TYPE_SHADOW); - value->u.ptr = v; - - return value; -} - -GtkCssValue * -_gtk_css_value_new_take_image (GtkCssImage *v) -{ - GtkCssValue *value; - - value = gtk_css_value_new (GTK_TYPE_CSS_IMAGE); - value->u.ptr = v; - - return value; -} - -GtkCssValue * -_gtk_css_value_new_from_number (const GtkCssNumber *v) -{ - GtkCssValue *value; - static GtkCssValue *zero_singleton = NULL; - static GtkCssValue *px_singletons[5] = {NULL}; - - if (v->unit == GTK_CSS_NUMBER && - v->value == 0) - { - if (zero_singleton == NULL) - { - value = gtk_css_value_new (GTK_TYPE_CSS_NUMBER); - value->u.ptr = g_boxed_copy0 (GTK_TYPE_CSS_NUMBER, v); - zero_singleton = value; - } - return _gtk_css_value_ref (zero_singleton); - } - - if (v->unit == GTK_CSS_PX && - (v->value == 0 || - v->value == 1 || - v->value == 2 || - v->value == 3 || - v->value == 4)) - { - int i = round (v->value); - if (px_singletons[i] == NULL) - { - value = gtk_css_value_new (GTK_TYPE_CSS_NUMBER); - value->u.ptr = g_boxed_copy0 (GTK_TYPE_CSS_NUMBER, v); - px_singletons[i] = value; - } - - return _gtk_css_value_ref (px_singletons[i]); - } - - value = gtk_css_value_new (GTK_TYPE_CSS_NUMBER); - value->u.ptr = g_boxed_copy0 (GTK_TYPE_CSS_NUMBER, v); - - return value; -} - -GtkCssValue * -_gtk_css_value_new_from_rgba (const GdkRGBA *v) -{ - GtkCssValue *value; - - value = gtk_css_value_new (GDK_TYPE_RGBA); - value->u.ptr = g_boxed_copy0 (GDK_TYPE_RGBA, v); - - return value; -} - -GtkCssValue * -_gtk_css_value_new_from_color (const GdkColor *v) -{ - GtkCssValue *value; - - value = gtk_css_value_new (GDK_TYPE_COLOR); - value->u.ptr = g_boxed_copy0 (GDK_TYPE_COLOR, v); - - return value; -} - -GtkCssValue * -_gtk_css_value_new_from_background_size (const GtkCssBackgroundSize *v) -{ - GtkCssValue *value; - - value = gtk_css_value_new (GTK_TYPE_CSS_BACKGROUND_SIZE); - value->u.ptr = g_boxed_copy0 (GTK_TYPE_CSS_BACKGROUND_SIZE, v); - - return value; -} - -GtkCssValue * -_gtk_css_value_new_from_background_position (const GtkCssBackgroundPosition *v) -{ - GtkCssValue *value; - - value = gtk_css_value_new (GTK_TYPE_CSS_BACKGROUND_POSITION); - value->u.ptr = g_boxed_copy0 (GTK_TYPE_CSS_BACKGROUND_POSITION, v); - - return value; -} - -GtkCssValue * -_gtk_css_value_new_take_symbolic_color (GtkSymbolicColor *v) -{ - GtkCssValue *value; - - value = gtk_css_value_new (GTK_TYPE_SYMBOLIC_COLOR); - value->u.ptr = v; - - return value; -} - GtkCssValue * _gtk_css_value_alloc (const GtkCssValueClass *klass, gsize size) @@ -350,7 +46,7 @@ _gtk_css_value_alloc (const GtkCssValueClass *klass, GtkCssValue * _gtk_css_value_ref (GtkCssValue *value) { - g_return_val_if_fail (value != NULL, NULL); + gtk_internal_return_val_if_fail (value != NULL, NULL); g_atomic_int_add (&value->ref_count, 1); @@ -369,243 +65,120 @@ _gtk_css_value_unref (GtkCssValue *value) value->class->free (value); } -void -_gtk_css_value_print (const GtkCssValue *value, - GString *string) -{ - g_return_if_fail (value != NULL); - g_return_if_fail (string != NULL); - - value->class->print (value, string); -} - -GType -_gtk_css_value_get_content_type (const GtkCssValue *value) +/** + * _gtk_css_value_compute: + * @value: the value to compute from + * @property_id: the ID of the property to compute + * @provider: Style provider for looking up extra information + * @values: values to compute for + * @parent_values: parent values to use for inherited values + * @dependencies: (out) (allow-none): Set to the dependencies of the + * computed values that indicate when this value needs to be + * recomputed and how. + * + * Converts the specified @value into the computed value for the CSS + * property given by @property_id using the information in @context. + * This step is explained in detail in + *