Revert "docs: Reinstate pixbufs section in GDK docs"

I committed my whole working tee instead of just one file. Ooops.
This reverts commit ded14b2562.
This commit is contained in:
Benjamin Otte 2010-12-09 23:55:33 +01:00
parent ded14b2562
commit 3070d6e3d5
14 changed files with 308 additions and 204 deletions

View File

@ -22,7 +22,6 @@
<xi:include href="xml/gdkdisplaymanager.xml" /> <xi:include href="xml/gdkdisplaymanager.xml" />
<xi:include href="xml/gdkscreen.xml" /> <xi:include href="xml/gdkscreen.xml" />
<xi:include href="xml/regions.xml" /> <xi:include href="xml/regions.xml" />
<xi:include href="xml/pixbufs.xml" />
<xi:include href="xml/colors.xml" /> <xi:include href="xml/colors.xml" />
<xi:include href="xml/rgba_colors.xml" /> <xi:include href="xml/rgba_colors.xml" />
<xi:include href="xml/visuals.xml" /> <xi:include href="xml/visuals.xml" />

View File

@ -226,6 +226,7 @@ gtk_gradient_unref (GtkGradient *gradient)
* gtk_gradient_resolve: * gtk_gradient_resolve:
* @gradient: a #GtkGradient * @gradient: a #GtkGradient
* @props: #GtkStyleProperties to use when resolving named colors * @props: #GtkStyleProperties to use when resolving named colors
* @resolved_gradient: (out): return location for the resolved pattern
* *
* If @gradient is resolvable, @resolved_gradient will be filled in * If @gradient is resolvable, @resolved_gradient will be filled in
* with the resolved gradient as a cairo_pattern_t, and %TRUE will * with the resolved gradient as a cairo_pattern_t, and %TRUE will
@ -233,20 +234,21 @@ gtk_gradient_unref (GtkGradient *gradient)
* due to it being defined on top of a named color that doesn't * due to it being defined on top of a named color that doesn't
* exist in @props. * exist in @props.
* *
* Returns: the resolved pattern. Use cairo_pattern_destroy() * Returns: %TRUE if the gradient has been resolved
* after use.
* *
* Since: 3.0 * Since: 3.0
**/ **/
cairo_pattern_t * gboolean
gtk_gradient_resolve (GtkGradient *gradient, gtk_gradient_resolve (GtkGradient *gradient,
GtkStyleProperties *props) GtkStyleProperties *props,
cairo_pattern_t **resolved_gradient)
{ {
cairo_pattern_t *pattern; cairo_pattern_t *pattern;
guint i; guint i;
g_return_val_if_fail (gradient != NULL, NULL); g_return_val_if_fail (gradient != NULL, FALSE);
g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), NULL); g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE);
g_return_val_if_fail (resolved_gradient != NULL, FALSE);
if (gradient->radius0 == 0 && gradient->radius1 == 0) if (gradient->radius0 == 0 && gradient->radius1 == 0)
pattern = cairo_pattern_create_linear (gradient->x0, gradient->y0, pattern = cairo_pattern_create_linear (gradient->x0, gradient->y0,
@ -264,12 +266,17 @@ gtk_gradient_resolve (GtkGradient *gradient,
stop = &g_array_index (gradient->stops, ColorStop, i); stop = &g_array_index (gradient->stops, ColorStop, i);
gtk_symbolic_color_resolve (stop->color, props, &color); if (!gtk_symbolic_color_resolve (stop->color, props, &color))
{
cairo_pattern_destroy (pattern);
return FALSE;
}
cairo_pattern_add_color_stop_rgba (pattern, stop->offset, cairo_pattern_add_color_stop_rgba (pattern, stop->offset,
color.red, color.green, color.red, color.green,
color.blue, color.alpha); color.blue, color.alpha);
} }
return pattern; *resolved_gradient = pattern;
return TRUE;
} }

View File

@ -52,9 +52,9 @@ void gtk_gradient_add_color_stop (GtkGradient *gradient,
GtkGradient * gtk_gradient_ref (GtkGradient *gradient); GtkGradient * gtk_gradient_ref (GtkGradient *gradient);
void gtk_gradient_unref (GtkGradient *gradient); void gtk_gradient_unref (GtkGradient *gradient);
cairo_pattern_t * gboolean gtk_gradient_resolve (GtkGradient *gradient,
gtk_gradient_resolve (GtkGradient *gradient, GtkStyleProperties *props,
GtkStyleProperties *props); cairo_pattern_t **resolved_gradient);
G_END_DECLS G_END_DECLS

View File

@ -3060,7 +3060,16 @@ gtk_icon_info_load_icon (GtkIconInfo *icon_info,
} }
static gchar * static gchar *
gdk_rgba_to_css (const GdkRGBA *color) gdk_color_to_css (GdkColor *color)
{
return g_strdup_printf ("rgb(%d,%d,%d)",
color->red >> 8,
color->green >> 8,
color->blue >> 8);
}
static gchar *
gdk_rgba_to_css (GdkRGBA *color)
{ {
return g_strdup_printf ("rgba(%d,%d,%d,%f)", return g_strdup_printf ("rgba(%d,%d,%d,%f)",
(gint)(color->red * 255), (gint)(color->red * 255),
@ -3069,40 +3078,41 @@ gdk_rgba_to_css (const GdkRGBA *color)
color->alpha); color->alpha);
} }
static char *
_gtk_icon_info_color_to_css (const GdkRGBA *rgba,
const char *color_name)
{
GdkRGBA color;
if (rgba)
return gdk_rgba_to_css (rgba);
gtk_style_context_lookup_default_color (color_name, &color);
return gdk_rgba_to_css (&color);
}
static GdkPixbuf * static GdkPixbuf *
_gtk_icon_info_load_symbolic_internal (GtkIconInfo *icon_info, _gtk_icon_info_load_symbolic_internal (GtkIconInfo *icon_info,
const GdkRGBA *fg, const gchar *css_fg,
const GdkRGBA *success_rgba, const gchar *css_success,
const GdkRGBA *warning_rgba, const gchar *css_warning,
const GdkRGBA *error_rgba, const gchar *css_error,
GError **error) GError **error)
{ {
GInputStream *stream; GInputStream *stream;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
gchar *data; gchar *data;
char *css_fg, *css_success, *css_warning, *css_error; gchar *success, *warning, *err;
/* css_fg can't possibly have failed, otherwise /* css_fg can't possibly have failed, otherwise
* that would mean we have a broken style */ * that would mean we have a broken style */
g_return_val_if_fail (fg != NULL, NULL); g_return_val_if_fail (css_fg != NULL, NULL);
success = warning = err = NULL;
if (!css_success)
{
GdkColor success_default_color = { 0, 0x4e00, 0x9a00, 0x0600 };
success = gdk_color_to_css (&success_default_color);
}
if (!css_warning)
{
GdkColor warning_default_color = { 0, 0xf500, 0x7900, 0x3e00 };
warning = gdk_color_to_css (&warning_default_color);
}
if (!css_error)
{
GdkColor error_default_color = { 0, 0xcc00, 0x0000, 0x0000 };
err = gdk_color_to_css (&error_default_color);
}
css_fg = _gtk_icon_info_color_to_css (fg, "color");
css_warning = _gtk_icon_info_color_to_css (warning_rgba, "warning_color");
css_error = _gtk_icon_info_color_to_css (error_rgba, "error_color");
css_success = _gtk_icon_info_color_to_css (success_rgba, "success_color");
data = g_strconcat ("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" data = g_strconcat ("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
"<svg version=\"1.1\"\n" "<svg version=\"1.1\"\n"
@ -3112,26 +3122,24 @@ _gtk_icon_info_load_symbolic_internal (GtkIconInfo *icon_info,
" height=\"16\">\n" " height=\"16\">\n"
" <style type=\"text/css\">\n" " <style type=\"text/css\">\n"
" rect,path {\n" " rect,path {\n"
" fill: ", css_fg, " !important;\n" " fill: ", css_fg," !important;\n"
" }\n" " }\n"
" .warning {\n" " .warning {\n"
" fill: ", css_warning, " !important;\n" " fill: ", css_warning ? css_warning : warning," !important;\n"
" }\n" " }\n"
" .error {\n" " .error {\n"
" fill: ", css_error, " !important;\n" " fill: ", css_error ? css_error : err," !important;\n"
" }\n" " }\n"
" .success {\n" " .success {\n"
" fill: ", css_success, " !important;\n" " fill: ", css_success ? css_success : success," !important;\n"
" }\n" " }\n"
" </style>\n" " </style>\n"
" <xi:include href=\"", icon_info->filename, "\"/>\n" " <xi:include href=\"", icon_info->filename, "\"/>\n"
"</svg>", "</svg>",
NULL); NULL);
g_free (warning);
g_free (css_fg); g_free (err);
g_free (css_warning); g_free (success);
g_free (css_error);
g_free (css_success);
stream = g_memory_input_stream_new_from_data (data, -1, g_free); stream = g_memory_input_stream_new_from_data (data, -1, g_free);
pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream, pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream,
@ -3191,6 +3199,10 @@ gtk_icon_info_load_symbolic (GtkIconInfo *icon_info,
GError **error) GError **error)
{ {
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
gchar *css_fg;
gchar *css_success;
gchar *css_warning;
gchar *css_error;
g_return_val_if_fail (fg != NULL, NULL); g_return_val_if_fail (fg != NULL, NULL);
@ -3205,10 +3217,27 @@ gtk_icon_info_load_symbolic (GtkIconInfo *icon_info,
if (was_symbolic) if (was_symbolic)
*was_symbolic = TRUE; *was_symbolic = TRUE;
css_fg = gdk_rgba_to_string (fg);
css_success = css_warning = css_error = NULL;
if (warning_color)
css_warning = gdk_rgba_to_string (warning_color);
if (error_color)
css_error = gdk_rgba_to_string (error_color);
if (success_color)
css_success = gdk_rgba_to_string (success_color);
pixbuf = _gtk_icon_info_load_symbolic_internal (icon_info, pixbuf = _gtk_icon_info_load_symbolic_internal (icon_info,
fg, success_color, css_fg, css_success,
warning_color, error_color, css_warning, css_error,
error); error);
g_free (css_fg);
g_free (css_warning);
g_free (css_success);
g_free (css_error);
return pixbuf; return pixbuf;
} }
@ -3242,7 +3271,9 @@ gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info,
{ {
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
GdkRGBA *color = NULL; GdkRGBA *color = NULL;
GdkRGBA success_color, warning_color, error_color; GdkRGBA rgba;
gchar *css_fg = NULL, *css_success;
gchar *css_warning, *css_error;
GtkStateFlags state; GtkStateFlags state;
if (!icon_info->filename || if (!icon_info->filename ||
@ -3258,30 +3289,36 @@ gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info,
state = gtk_style_context_get_state (context); state = gtk_style_context_get_state (context);
gtk_style_context_get (context, state, "color", &color, NULL); gtk_style_context_get (context, state, "color", &color, NULL);
gtk_style_context_lookup_color (context, "success_color", &success_color); if (color)
gtk_style_context_lookup_color (context, "warning_color", &warning_color); {
gtk_style_context_lookup_color (context, "error_color", &error_color); css_fg = gdk_rgba_to_css (color);
gdk_rgba_free (color);
}
css_success = css_warning = css_error = NULL;
if (gtk_style_context_lookup_color (context, "success_color", &rgba))
css_success = gdk_rgba_to_css (&rgba);
if (gtk_style_context_lookup_color (context, "warning_color", &rgba))
css_warning = gdk_rgba_to_css (&rgba);
if (gtk_style_context_lookup_color (context, "error_color", &rgba))
css_error = gdk_rgba_to_css (&rgba);
pixbuf = _gtk_icon_info_load_symbolic_internal (icon_info, pixbuf = _gtk_icon_info_load_symbolic_internal (icon_info,
color, &success_color, css_fg, css_success,
&warning_color, &error_color, css_warning, css_error,
error); error);
gdk_rgba_free (color); g_free (css_fg);
g_free (css_success);
g_free (css_warning);
g_free (css_error);
return pixbuf; return pixbuf;
} }
static void
_color_to_rgba (const GdkColor *color,
GdkRGBA *rgba)
{
rgba->red = color->red / 65535.0;
rgba->green = color->green / 65535.0;
rgba->blue = color->blue / 65535.0;
rgba->alpha = 1.0;
}
/** /**
* gtk_icon_info_load_symbolic_for_style: * gtk_icon_info_load_symbolic_for_style:
* @icon_info: a #GtkIconInfo * @icon_info: a #GtkIconInfo
@ -3314,8 +3351,12 @@ gtk_icon_info_load_symbolic_for_style (GtkIconInfo *icon_info,
GError **error) GError **error)
{ {
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
GdkColor success_color, warning_color, error_color; GdkColor success_color;
GdkRGBA fg_rgba, success_rgba, warning_rgba, error_rgba; GdkColor warning_color;
GdkColor error_color;
GdkColor *fg;
gchar *css_fg, *css_success;
gchar *css_warning, *css_error;
if (!icon_info->filename || if (!icon_info->filename ||
!g_str_has_suffix (icon_info->filename, "-symbolic.svg")) !g_str_has_suffix (icon_info->filename, "-symbolic.svg"))
@ -3328,22 +3369,30 @@ gtk_icon_info_load_symbolic_for_style (GtkIconInfo *icon_info,
if (was_symbolic) if (was_symbolic)
*was_symbolic = TRUE; *was_symbolic = TRUE;
_color_to_rgba (&style->fg[state], &fg_rgba); fg = &style->fg[state];
css_fg = gdk_color_to_css (fg);
gtk_style_lookup_color (style, "success_color", &success_color); css_success = css_warning = css_error = NULL;
_color_to_rgba (&success_color, &success_rgba);
gtk_style_lookup_color (style, "warning_color", &warning_color); if (gtk_style_lookup_color (style, "success_color", &success_color))
_color_to_rgba (&warning_color, &warning_rgba); css_success = gdk_color_to_css (&success_color);
gtk_style_lookup_color (style, "error_color", &error_color); if (gtk_style_lookup_color (style, "warning_color", &warning_color))
_color_to_rgba (&error_color, &error_rgba); css_warning = gdk_color_to_css (&warning_color);
if (gtk_style_lookup_color (style, "error_color", &error_color))
css_error = gdk_color_to_css (&error_color);
pixbuf = _gtk_icon_info_load_symbolic_internal (icon_info, pixbuf = _gtk_icon_info_load_symbolic_internal (icon_info,
&fg_rgba, &success_rgba, css_fg, css_success,
&warning_rgba, &error_rgba, css_warning, css_error,
error); error);
g_free (css_fg);
g_free (css_success);
g_free (css_warning);
g_free (css_error);
return pixbuf; return pixbuf;
} }

View File

@ -495,7 +495,18 @@ gtk_info_bar_update_colors (GtkInfoBar *info_bar)
{ {
GtkWidget *widget = GTK_WIDGET (info_bar); GtkWidget *widget = GTK_WIDGET (info_bar);
GtkInfoBarPrivate *priv = info_bar->priv; GtkInfoBarPrivate *priv = info_bar->priv;
GdkRGBA fg, bg; GdkRGBA info_default_border_color = { 0.71, 0.67, 0.61, 1.0 };
GdkRGBA info_default_fill_color = { 0.99, 0.99, 0.74, 1.0 };
GdkRGBA warning_default_border_color = { 0.68, 0.47, 0.16, 1.0 };
GdkRGBA warning_default_fill_color = { 0.98, 0.68, 0.24, 1.0 };
GdkRGBA question_default_border_color = { 0.38, 0.48, 0.84, 1.0 };
GdkRGBA question_default_fill_color = { 0.54, 0.68, 0.83, 1.0 };
GdkRGBA error_default_border_color = { 0.65, 0.15, 0.15, 1.0 };
GdkRGBA error_default_fill_color = { 0.93, 0.21, 0.21, 1.0 };
GdkRGBA other_default_border_color = { 0.71, 0.67, 0.61, 1.0 };
GdkRGBA other_default_fill_color = { 0.99, 0.99, 0.74, 1.0 };
GdkRGBA *fg, *bg;
GdkRGBA sym_fg, sym_bg;
GdkRGBA *color, *bg_color; GdkRGBA *color, *bg_color;
GtkStyleContext *context; GtkStyleContext *context;
@ -516,17 +527,56 @@ gtk_info_bar_update_colors (GtkInfoBar *info_bar)
context = gtk_widget_get_style_context (widget); context = gtk_widget_get_style_context (widget);
gtk_style_context_lookup_color (context, fg_color_name[priv->message_type], &fg); if (gtk_style_context_lookup_color (context, fg_color_name[priv->message_type], &sym_fg) &&
gtk_style_context_lookup_color (context, bg_color_name[priv->message_type], &bg); gtk_style_context_lookup_color (context, bg_color_name[priv->message_type], &sym_bg))
{
fg = &sym_fg;
bg = &sym_bg;
}
else
{
switch (priv->message_type)
{
case GTK_MESSAGE_INFO:
fg = &info_default_border_color;
bg = &info_default_fill_color;
break;
case GTK_MESSAGE_WARNING:
fg = &warning_default_border_color;
bg = &warning_default_fill_color;
break;
case GTK_MESSAGE_QUESTION:
fg = &question_default_border_color;
bg = &question_default_fill_color;
break;
case GTK_MESSAGE_ERROR:
fg = &error_default_border_color;
bg = &error_default_fill_color;
break;
case GTK_MESSAGE_OTHER:
fg = &other_default_border_color;
bg = &other_default_fill_color;
break;
default:
g_assert_not_reached();
fg = NULL;
bg = NULL;
}
}
gtk_style_context_get (context, 0, gtk_style_context_get (context, 0,
"color", &color, "color", &color,
"background-color", &bg_color, "background-color", &bg_color,
NULL); NULL);
if (!gdk_rgba_equal (bg_color, &bg)) if (!gdk_rgba_equal (bg_color, bg))
gtk_widget_override_background_color (widget, 0, &bg); gtk_widget_override_background_color (widget, 0, bg);
if (!gdk_rgba_equal (color, &fg)) if (!gdk_rgba_equal (color, fg))
gtk_widget_override_color (widget, 0, &fg); gtk_widget_override_color (widget, 0, fg);
gdk_rgba_free (color); gdk_rgba_free (color);
gdk_rgba_free (bg_color); gdk_rgba_free (bg_color);

View File

@ -1071,25 +1071,35 @@ gtk_style_lookup_icon_set (GtkStyle *style,
* *
* Deprecated:3.0: Use gtk_style_context_lookup_color() instead * Deprecated:3.0: Use gtk_style_context_lookup_color() instead
**/ **/
void gboolean
gtk_style_lookup_color (GtkStyle *style, gtk_style_lookup_color (GtkStyle *style,
const char *color_name, const char *color_name,
GdkColor *color) GdkColor *color)
{ {
GtkStylePrivate *priv; GtkStylePrivate *priv;
gboolean result;
GdkRGBA rgba; GdkRGBA rgba;
g_return_if_fail (GTK_IS_STYLE (style)); g_return_val_if_fail (GTK_IS_STYLE (style), FALSE);
g_return_if_fail (color_name != NULL); g_return_val_if_fail (color_name != NULL, FALSE);
g_return_val_if_fail (color != NULL, FALSE);
priv = GTK_STYLE_GET_PRIVATE (style); priv = GTK_STYLE_GET_PRIVATE (style);
gtk_style_context_lookup_color (priv->context, color_name, &rgba); if (!priv->context)
return FALSE;
color->red = (guint16) (rgba.red * 65535); result = gtk_style_context_lookup_color (priv->context, color_name, &rgba);
color->green = (guint16) (rgba.green * 65535);
color->blue = (guint16) (rgba.blue * 65535); if (color)
color->pixel = 0; {
color->red = (guint16) (rgba.red * 65535);
color->green = (guint16) (rgba.green * 65535);
color->blue = (guint16) (rgba.blue * 65535);
color->pixel = 0;
}
return result;
} }
/** /**

View File

@ -402,7 +402,7 @@ void gtk_style_apply_default_background (GtkStyle *style,
GtkIconSet* gtk_style_lookup_icon_set (GtkStyle *style, GtkIconSet* gtk_style_lookup_icon_set (GtkStyle *style,
const gchar *stock_id); const gchar *stock_id);
void gtk_style_lookup_color (GtkStyle *style, gboolean gtk_style_lookup_color (GtkStyle *style,
const gchar *color_name, const gchar *color_name,
GdkColor *color); GdkColor *color);

View File

@ -2317,25 +2317,29 @@ _gtk_style_context_peek_style_property (GtkStyleContext *context,
color = g_value_get_boxed (&pcache->value); color = g_value_get_boxed (&pcache->value);
gtk_symbolic_color_resolve (color, data->store, &rgba); if (gtk_symbolic_color_resolve (color, data->store, &rgba))
g_value_unset (&pcache->value);
if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
{ {
g_value_init (&pcache->value, GDK_TYPE_RGBA); g_value_unset (&pcache->value);
g_value_set_boxed (&pcache->value, &rgba);
if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
{
g_value_init (&pcache->value, GDK_TYPE_RGBA);
g_value_set_boxed (&pcache->value, &rgba);
}
else
{
GdkColor rgb;
rgb.red = rgba.red * 65535. + 0.5;
rgb.green = rgba.green * 65535. + 0.5;
rgb.blue = rgba.blue * 65535. + 0.5;
g_value_init (&pcache->value, GDK_TYPE_COLOR);
g_value_set_boxed (&pcache->value, &rgb);
}
} }
else else
{ g_param_value_set_default (pspec, &pcache->value);
GdkColor rgb;
rgb.red = rgba.red * 65535. + 0.5;
rgb.green = rgba.green * 65535. + 0.5;
rgb.blue = rgba.blue * 65535. + 0.5;
g_value_init (&pcache->value, GDK_TYPE_COLOR);
g_value_set_boxed (&pcache->value, &rgb);
}
} }
return &pcache->value; return &pcache->value;
@ -2704,44 +2708,6 @@ gtk_style_context_get_junction_sides (GtkStyleContext *context)
return info->junction_sides; return info->junction_sides;
} }
gboolean
gtk_style_context_lookup_default_color (const gchar *color_name,
GdkRGBA *color)
{
static const GdkRGBA fallback_color = { 1.0, 0.0, 1.0, 1.0 };
static const struct {
const char *name;
const GdkRGBA rgba;
} colors[] = {
{ "success_color", { 0.3, 0.6, 0.02, 1.0 } },
{ "warning_color", { 0.96, 0.474, 0.24, 1.0 } },
{ "error_color", { 0.8, 0.0, 0.0, 1.0 } },
{ "info_fg_color", { 0.71, 0.67, 0.61, 1.0 } },
{ "info_bg_color", { 0.99, 0.99, 0.74, 1.0 } },
{ "warning_fg_color", { 0.68, 0.47, 0.16, 1.0 } },
{ "warning_bg_color", { 0.98, 0.68, 0.24, 1.0 } },
{ "question_fg_color", { 0.38, 0.48, 0.84, 1.0 } },
{ "question_bg_color", { 0.54, 0.68, 0.83, 1.0 } },
{ "error_fg_color", { 0.65, 0.15, 0.15, 1.0 } },
{ "error_bg_color", { 0.93, 0.21, 0.21, 1.0 } },
{ "other_fg_color", { 0.71, 0.67, 0.61, 1.0 } },
{ "other_bg_color", { 0.99, 0.99, 0.74, 1.0 } }
};
guint i;
for (i = 0; i < G_N_ELEMENTS (colors); i++)
{
if (g_str_equal (color_name, colors[i].name))
{
*color = colors[i].rgba;
return TRUE;
}
}
*color = fallback_color;
return FALSE;
}
/** /**
* gtk_style_context_lookup_color: * gtk_style_context_lookup_color:
* @context: a #GtkStyleContext * @context: a #GtkStyleContext
@ -2752,7 +2718,7 @@ gtk_style_context_lookup_default_color (const gchar *color_name,
* *
* Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
**/ **/
void gboolean
gtk_style_context_lookup_color (GtkStyleContext *context, gtk_style_context_lookup_color (GtkStyleContext *context,
const gchar *color_name, const gchar *color_name,
GdkRGBA *color) GdkRGBA *color)
@ -2761,20 +2727,20 @@ gtk_style_context_lookup_color (GtkStyleContext *context,
GtkSymbolicColor *sym_color; GtkSymbolicColor *sym_color;
StyleData *data; StyleData *data;
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
g_return_if_fail (color_name != NULL); g_return_val_if_fail (color_name != NULL, FALSE);
g_return_if_fail (color != NULL); g_return_val_if_fail (color != NULL, FALSE);
priv = context->priv; priv = context->priv;
g_return_if_fail (priv->widget_path != NULL); g_return_val_if_fail (priv->widget_path != NULL, FALSE);
data = style_data_lookup (context); data = style_data_lookup (context);
sym_color = gtk_style_properties_lookup_color (data->store, color_name); sym_color = gtk_style_properties_lookup_color (data->store, color_name);
if (sym_color) if (!sym_color)
gtk_symbolic_color_resolve (sym_color, data->store, color); return FALSE;
else
gtk_style_context_lookup_default_color (color_name, color); return gtk_symbolic_color_resolve (sym_color, data->store, color);
} }
/** /**

View File

@ -415,11 +415,9 @@ void gtk_style_context_set_junction_sides (GtkStyleContext *context
GtkJunctionSides sides); GtkJunctionSides sides);
GtkJunctionSides gtk_style_context_get_junction_sides (GtkStyleContext *context); GtkJunctionSides gtk_style_context_get_junction_sides (GtkStyleContext *context);
void gtk_style_context_lookup_color (GtkStyleContext *context, gboolean gtk_style_context_lookup_color (GtkStyleContext *context,
const gchar *color_name, const gchar *color_name,
GdkRGBA *color); GdkRGBA *color);
gboolean gtk_style_context_lookup_default_color (const gchar *color_name,
GdkRGBA *color);
void gtk_style_context_notify_state_change (GtkStyleContext *context, void gtk_style_context_notify_state_change (GtkStyleContext *context,
GdkWindow *window, GdkWindow *window,

View File

@ -566,7 +566,7 @@ gtk_style_properties_map_color (GtkStyleProperties *props,
* Returns the symbolic color that is mapped * Returns the symbolic color that is mapped
* to @name. * to @name.
* *
* Returns: The mapped color or %NULL if no color is mapped to @name * Returns: The mapped color
* *
* Since: 3.0 * Since: 3.0
**/ **/
@ -760,29 +760,33 @@ gtk_style_properties_set (GtkStyleProperties *props,
va_end (args); va_end (args);
} }
static void static gboolean
resolve_color (GtkStyleProperties *props, resolve_color (GtkStyleProperties *props,
GValue *value) GValue *value)
{ {
GdkRGBA color; GdkRGBA color;
/* Resolve symbolic color to GdkRGBA */ /* Resolve symbolic color to GdkRGBA */
gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color); if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color))
return FALSE;
/* Store it back, this is where GdkRGBA caching happens */ /* Store it back, this is where GdkRGBA caching happens */
g_value_unset (value); g_value_unset (value);
g_value_init (value, GDK_TYPE_RGBA); g_value_init (value, GDK_TYPE_RGBA);
g_value_set_boxed (value, &color); g_value_set_boxed (value, &color);
return TRUE;
} }
static void static gboolean
resolve_color_rgb (GtkStyleProperties *props, resolve_color_rgb (GtkStyleProperties *props,
GValue *value) GValue *value)
{ {
GdkColor color = { 0 }; GdkColor color = { 0 };
GdkRGBA rgba; GdkRGBA rgba;
gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &rgba); if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &rgba))
return FALSE;
color.red = rgba.red * 65535. + 0.5; color.red = rgba.red * 65535. + 0.5;
color.green = rgba.green * 65535. + 0.5; color.green = rgba.green * 65535. + 0.5;
@ -791,6 +795,8 @@ resolve_color_rgb (GtkStyleProperties *props,
g_value_unset (value); g_value_unset (value);
g_value_init (value, GDK_TYPE_COLOR); g_value_init (value, GDK_TYPE_COLOR);
g_value_set_boxed (value, &color); g_value_set_boxed (value, &color);
return TRUE;
} }
static gboolean static gboolean
@ -799,7 +805,8 @@ resolve_gradient (GtkStyleProperties *props,
{ {
cairo_pattern_t *gradient; cairo_pattern_t *gradient;
gradient = gtk_gradient_resolve (g_value_get_boxed (value), props); if (!gtk_gradient_resolve (g_value_get_boxed (value), props, &gradient))
return FALSE;
/* Store it back, this is where cairo_pattern_t caching happens */ /* Store it back, this is where cairo_pattern_t caching happens */
g_value_unset (value); g_value_unset (value);
@ -817,9 +824,15 @@ style_properties_resolve_type (GtkStyleProperties *props,
if (val && G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR) if (val && G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
{ {
if (node->pspec->value_type == GDK_TYPE_RGBA) if (node->pspec->value_type == GDK_TYPE_RGBA)
resolve_color (props, val); {
if (!resolve_color (props, val))
return FALSE;
}
else if (node->pspec->value_type == GDK_TYPE_COLOR) else if (node->pspec->value_type == GDK_TYPE_COLOR)
resolve_color_rgb (props, val); {
if (!resolve_color_rgb (props, val))
return FALSE;
}
else else
return FALSE; return FALSE;
} }
@ -827,7 +840,8 @@ style_properties_resolve_type (GtkStyleProperties *props,
{ {
g_return_val_if_fail (node->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN, FALSE); g_return_val_if_fail (node->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN, FALSE);
resolve_gradient (props, val); if (!resolve_gradient (props, val))
return FALSE;
} }
return TRUE; return TRUE;

View File

@ -19,7 +19,6 @@
#include "config.h" #include "config.h"
#include "gtksymboliccolor.h" #include "gtksymboliccolor.h"
#include "gtkstylecontext.h"
#include "gtkstyleproperties.h" #include "gtkstyleproperties.h"
#include "gtkintl.h" #include "gtkintl.h"
@ -469,81 +468,91 @@ _shade_color (GdkRGBA *color,
* @props: #GtkStyleProperties to use when resolving named colors * @props: #GtkStyleProperties to use when resolving named colors
* @resolved_color: (out): return location for the resolved color * @resolved_color: (out): return location for the resolved color
* *
* Resolves @color using @props. @resolved_color will be filled in * If @color is resolvable, @resolved_color will be filled in
* with the resolved color. * with the resolved color, and %TRUE will be returned. Generally,
* if @color can't be resolved, it is due to it being defined on
* top of a named color that doesn't exist in @props.
* *
* If @props does not contain information for resolving @color or * Returns: %TRUE if the color has been resolved
* any of the colors it depends on, then solid pink (#FF00FF) will
* be assumed for the missing colors. This is to make it visually
* obvious when a color is missing.
* *
* Since: 3.0 * Since: 3.0
**/ **/
void gboolean
gtk_symbolic_color_resolve (GtkSymbolicColor *color, gtk_symbolic_color_resolve (GtkSymbolicColor *color,
GtkStyleProperties *props, GtkStyleProperties *props,
GdkRGBA *resolved_color) GdkRGBA *resolved_color)
{ {
g_return_if_fail (color != NULL); g_return_val_if_fail (color != NULL, FALSE);
g_return_if_fail (resolved_color != NULL); g_return_val_if_fail (resolved_color != NULL, FALSE);
g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
switch (color->type) switch (color->type)
{ {
case COLOR_TYPE_LITERAL: case COLOR_TYPE_LITERAL:
*resolved_color = color->color; *resolved_color = color->color;
break; return TRUE;
case COLOR_TYPE_NAME: case COLOR_TYPE_NAME:
{ {
GtkSymbolicColor *named_color; GtkSymbolicColor *named_color;
g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE);
named_color = gtk_style_properties_lookup_color (props, color->name); named_color = gtk_style_properties_lookup_color (props, color->name);
if (!named_color) if (!named_color)
gtk_style_context_lookup_default_color (color->name, resolved_color); return FALSE;
gtk_symbolic_color_resolve (named_color, props, resolved_color); return gtk_symbolic_color_resolve (named_color, props, resolved_color);
} }
break;
break;
case COLOR_TYPE_SHADE: case COLOR_TYPE_SHADE:
{ {
GdkRGBA shade; GdkRGBA shade;
gtk_symbolic_color_resolve (color->shade.color, props, &shade); if (!gtk_symbolic_color_resolve (color->shade.color, props, &shade))
return FALSE;
_shade_color (&shade, color->shade.factor); _shade_color (&shade, color->shade.factor);
*resolved_color = shade; *resolved_color = shade;
}
break;
return TRUE;
}
break;
case COLOR_TYPE_ALPHA: case COLOR_TYPE_ALPHA:
{ {
GdkRGBA alpha; GdkRGBA alpha;
gtk_symbolic_color_resolve (color->alpha.color, props, &alpha); if (!gtk_symbolic_color_resolve (color->alpha.color, props, &alpha))
return FALSE;
*resolved_color = alpha; *resolved_color = alpha;
resolved_color->alpha = CLAMP (alpha.alpha * color->alpha.factor, 0, 1); resolved_color->alpha = CLAMP (alpha.alpha * color->alpha.factor, 0, 1);
}
break;
return TRUE;
}
case COLOR_TYPE_MIX: case COLOR_TYPE_MIX:
{ {
GdkRGBA color1, color2; GdkRGBA color1, color2;
gtk_symbolic_color_resolve (color->mix.color1, props, &color1); if (!gtk_symbolic_color_resolve (color->mix.color1, props, &color1))
gtk_symbolic_color_resolve (color->mix.color2, props, &color2); return FALSE;
if (!gtk_symbolic_color_resolve (color->mix.color2, props, &color2))
return FALSE;
resolved_color->red = CLAMP (color1.red + ((color2.red - color1.red) * color->mix.factor), 0, 1); resolved_color->red = CLAMP (color1.red + ((color2.red - color1.red) * color->mix.factor), 0, 1);
resolved_color->green = CLAMP (color1.green + ((color2.green - color1.green) * color->mix.factor), 0, 1); resolved_color->green = CLAMP (color1.green + ((color2.green - color1.green) * color->mix.factor), 0, 1);
resolved_color->blue = CLAMP (color1.blue + ((color2.blue - color1.blue) * color->mix.factor), 0, 1); resolved_color->blue = CLAMP (color1.blue + ((color2.blue - color1.blue) * color->mix.factor), 0, 1);
resolved_color->alpha = CLAMP (color1.alpha + ((color2.alpha - color1.alpha) * color->mix.factor), 0, 1); resolved_color->alpha = CLAMP (color1.alpha + ((color2.alpha - color1.alpha) * color->mix.factor), 0, 1);
}
break;
return TRUE;
}
break;
default: default:
g_assert_not_reached (); g_assert_not_reached ();
} }
return FALSE;
} }

View File

@ -46,7 +46,7 @@ GtkSymbolicColor * gtk_symbolic_color_new_mix (GtkSymbolicColor *color1,
GtkSymbolicColor * gtk_symbolic_color_ref (GtkSymbolicColor *color); GtkSymbolicColor * gtk_symbolic_color_ref (GtkSymbolicColor *color);
void gtk_symbolic_color_unref (GtkSymbolicColor *color); void gtk_symbolic_color_unref (GtkSymbolicColor *color);
void gtk_symbolic_color_resolve (GtkSymbolicColor *color, gboolean gtk_symbolic_color_resolve (GtkSymbolicColor *color,
GtkStyleProperties *props, GtkStyleProperties *props,
GdkRGBA *resolved_color); GdkRGBA *resolved_color);

View File

@ -549,19 +549,21 @@ gtk_theming_engine_get_style (GtkThemingEngine *engine,
* @color: (out): Return location for the looked up color * @color: (out): Return location for the looked up color
* *
* Looks up and resolves a color name in the current style's color map. * Looks up and resolves a color name in the current style's color map.
*
* Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
**/ **/
void gboolean
gtk_theming_engine_lookup_color (GtkThemingEngine *engine, gtk_theming_engine_lookup_color (GtkThemingEngine *engine,
const gchar *color_name, const gchar *color_name,
GdkRGBA *color) GdkRGBA *color)
{ {
GtkThemingEnginePrivate *priv; GtkThemingEnginePrivate *priv;
g_return_if_fail (GTK_IS_THEMING_ENGINE (engine)); g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
g_return_if_fail (color_name != NULL); g_return_val_if_fail (color_name != NULL, FALSE);
priv = engine->priv; priv = engine->priv;
gtk_style_context_lookup_color (priv->context, color_name, color); return gtk_style_context_lookup_color (priv->context, color_name, color);
} }
/** /**

View File

@ -198,9 +198,9 @@ void gtk_theming_engine_get_style_valist (GtkThemingEngine *engine,
void gtk_theming_engine_get_style (GtkThemingEngine *engine, void gtk_theming_engine_get_style (GtkThemingEngine *engine,
...); ...);
void gtk_theming_engine_lookup_color (GtkThemingEngine *engine, gboolean gtk_theming_engine_lookup_color (GtkThemingEngine *engine,
const gchar *color_name, const gchar *color_name,
GdkRGBA *color); GdkRGBA *color);
G_CONST_RETURN GtkWidgetPath * gtk_theming_engine_get_path (GtkThemingEngine *engine); G_CONST_RETURN GtkWidgetPath * gtk_theming_engine_get_path (GtkThemingEngine *engine);