diff --git a/gtk/gtksettings.c b/gtk/gtksettings.c index a40f82dcb2..6b47ee6a8c 100644 --- a/gtk/gtksettings.c +++ b/gtk/gtksettings.c @@ -1585,9 +1585,7 @@ settings_install_property_parser (GtkSettingsClass *class, GtkRcPropertyParser _gtk_rc_property_parser_from_type (GType type) { - if (type == g_type_from_name ("GdkColor")) - return gtk_rc_property_parse_color; - else if (type == GTK_TYPE_REQUISITION) + if (type == GTK_TYPE_REQUISITION) return gtk_rc_property_parse_requisition; else if (type == GTK_TYPE_BORDER) return gtk_rc_property_parse_border; @@ -1718,268 +1716,6 @@ gtk_rc_scanner_new (void) G_GNUC_BEGIN_IGNORE_DEPRECATIONS -static void -color_shade (const GdkColor *color, - GdkColor *color_return, - gdouble factor) -{ - GdkRGBA rgba; - GtkHSLA hsla; - - rgba.red = color->red / 65535.; - rgba.green = color->green / 65535.; - rgba.blue = color->blue / 65535.; - rgba.alpha = 1.0; - - _gtk_hsla_init_from_rgba (&hsla, &rgba); - _gtk_hsla_shade (&hsla, &hsla, factor); - _gdk_rgba_init_from_hsla (&rgba, &hsla); - - color_return->red = 65535. * rgba.red; - color_return->green = 65535. * rgba.green; - color_return->blue = 65535. * rgba.blue; -} - -/* - * gtk_parse_color: - * @scanner: a #GScanner - * @color: (out): a pointer to a #GdkColor in which to store - * the result - * - * Parses a color in the format expected - * in a RC file. If @style is not %NULL, it will be consulted to resolve - * references to symbolic colors. - * - * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token - * that was expected but not found - */ -static guint -gtk_parse_color (GScanner *scanner, - GdkColor *color) -{ - guint token; - - g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR); - - /* we don't need to set our own scope here, because - * we don't need own symbols - */ - - token = g_scanner_get_next_token (scanner); - switch (token) - { - gint token_int; - GdkColor c1, c2; - gboolean negate; - gdouble l; - - case G_TOKEN_LEFT_CURLY: - token = g_scanner_get_next_token (scanner); - if (token == G_TOKEN_INT) - token_int = scanner->value.v_int; - else if (token == G_TOKEN_FLOAT) - token_int = scanner->value.v_float * 65535.0; - else - return G_TOKEN_FLOAT; - color->red = CLAMP (token_int, 0, 65535); - - token = g_scanner_get_next_token (scanner); - if (token != G_TOKEN_COMMA) - return G_TOKEN_COMMA; - - token = g_scanner_get_next_token (scanner); - if (token == G_TOKEN_INT) - token_int = scanner->value.v_int; - else if (token == G_TOKEN_FLOAT) - token_int = scanner->value.v_float * 65535.0; - else - return G_TOKEN_FLOAT; - color->green = CLAMP (token_int, 0, 65535); - - token = g_scanner_get_next_token (scanner); - if (token != G_TOKEN_COMMA) - return G_TOKEN_COMMA; - - token = g_scanner_get_next_token (scanner); - if (token == G_TOKEN_INT) - token_int = scanner->value.v_int; - else if (token == G_TOKEN_FLOAT) - token_int = scanner->value.v_float * 65535.0; - else - return G_TOKEN_FLOAT; - color->blue = CLAMP (token_int, 0, 65535); - - token = g_scanner_get_next_token (scanner); - if (token != G_TOKEN_RIGHT_CURLY) - return G_TOKEN_RIGHT_CURLY; - return G_TOKEN_NONE; - - case G_TOKEN_STRING: - if (!gdk_color_parse (scanner->value.v_string, color)) - { - g_scanner_warn (scanner, "Invalid color constant '%s'", - scanner->value.v_string); - return G_TOKEN_STRING; - } - return G_TOKEN_NONE; - - case G_TOKEN_IDENTIFIER: - if (strcmp (scanner->value.v_identifier, "mix") == 0) - { - token = g_scanner_get_next_token (scanner); - if (token != G_TOKEN_LEFT_PAREN) - return G_TOKEN_LEFT_PAREN; - - negate = FALSE; - if (g_scanner_peek_next_token (scanner) == '-') - { - g_scanner_get_next_token (scanner); /* eat sign */ - negate = TRUE; - } - - token = g_scanner_get_next_token (scanner); - if (token != G_TOKEN_FLOAT) - return G_TOKEN_FLOAT; - - l = negate ? -scanner->value.v_float : scanner->value.v_float; - - token = g_scanner_get_next_token (scanner); - if (token != G_TOKEN_COMMA) - return G_TOKEN_COMMA; - - token = gtk_parse_color (scanner, &c1); - if (token != G_TOKEN_NONE) - return token; - - token = g_scanner_get_next_token (scanner); - if (token != G_TOKEN_COMMA) - return G_TOKEN_COMMA; - - token = gtk_parse_color (scanner, &c2); - if (token != G_TOKEN_NONE) - return token; - - token = g_scanner_get_next_token (scanner); - if (token != G_TOKEN_RIGHT_PAREN) - return G_TOKEN_RIGHT_PAREN; - - color->red = l * c1.red + (1.0 - l) * c2.red; - color->green = l * c1.green + (1.0 - l) * c2.green; - color->blue = l * c1.blue + (1.0 - l) * c2.blue; - - return G_TOKEN_NONE; - } - else if (strcmp (scanner->value.v_identifier, "shade") == 0) - { - token = g_scanner_get_next_token (scanner); - if (token != G_TOKEN_LEFT_PAREN) - return G_TOKEN_LEFT_PAREN; - - negate = FALSE; - if (g_scanner_peek_next_token (scanner) == '-') - { - g_scanner_get_next_token (scanner); /* eat sign */ - negate = TRUE; - } - - token = g_scanner_get_next_token (scanner); - if (token != G_TOKEN_FLOAT) - return G_TOKEN_FLOAT; - - l = negate ? -scanner->value.v_float : scanner->value.v_float; - - token = g_scanner_get_next_token (scanner); - if (token != G_TOKEN_COMMA) - return G_TOKEN_COMMA; - - token = gtk_parse_color (scanner, &c1); - if (token != G_TOKEN_NONE) - return token; - - token = g_scanner_get_next_token (scanner); - if (token != G_TOKEN_RIGHT_PAREN) - return G_TOKEN_RIGHT_PAREN; - - color_shade (&c1, color, l); - - return G_TOKEN_NONE; - } - else if (strcmp (scanner->value.v_identifier, "lighter") == 0 || - strcmp (scanner->value.v_identifier, "darker") == 0) - { - if (scanner->value.v_identifier[0] == 'l') - l = 1.3; - else - l = 0.7; - - token = g_scanner_get_next_token (scanner); - if (token != G_TOKEN_LEFT_PAREN) - return G_TOKEN_LEFT_PAREN; - - token = gtk_parse_color (scanner, &c1); - if (token != G_TOKEN_NONE) - return token; - - token = g_scanner_get_next_token (scanner); - if (token != G_TOKEN_RIGHT_PAREN) - return G_TOKEN_RIGHT_PAREN; - - color_shade (&c1, color, l); - - return G_TOKEN_NONE; - } - else - return G_TOKEN_IDENTIFIER; - - default: - return G_TOKEN_STRING; - } -} - - -/** - * gtk_rc_property_parse_color: - * @pspec: a #GParamSpec - * @gstring: the #GString to be parsed - * @property_value: a #GValue which must hold #GdkColor values. - * - * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser() - * or gtk_widget_class_install_style_property_parser() which parses a - * color given either by its name or in the form - * `{ red, green, blue }` where red, green and - * blue are integers between 0 and 65535 or floating-point numbers - * between 0 and 1. - * - * Returns: %TRUE if @gstring could be parsed and @property_value - * has been set to the resulting #GdkColor. - **/ -gboolean -gtk_rc_property_parse_color (const GParamSpec *pspec, - const GString *gstring, - GValue *property_value) -{ - GdkColor color = { 0, 0, 0, 0, }; - GScanner *scanner; - gboolean success; - - g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE); - g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE); - - scanner = gtk_rc_scanner_new (); - g_scanner_input_text (scanner, gstring->str, gstring->len); - if (gtk_parse_color (scanner, &color) == G_TOKEN_NONE && - g_scanner_get_next_token (scanner) == G_TOKEN_EOF) - { - g_value_set_boxed (property_value, &color); - success = TRUE; - } - else - success = FALSE; - g_scanner_destroy (scanner); - - return success; -} - /** * gtk_rc_property_parse_enum: * @pspec: a #GParamSpec