From cf77c1695d0efba00078c4b3d8d4dc9ad98a2a86 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Mon, 7 Dec 2015 19:45:55 +0100 Subject: [PATCH] iconhelper: Pass only the CssStyle when loading iconsets --- gtk/deprecated/gtkiconfactory.c | 81 +++++++++++++++----------- gtk/deprecated/gtkiconfactoryprivate.h | 6 ++ gtk/gtkiconhelper.c | 46 ++++++++++----- gtk/gtkrender.c | 66 +++++++++------------ gtk/gtkrenderprivate.h | 6 ++ 5 files changed, 120 insertions(+), 85 deletions(-) diff --git a/gtk/deprecated/gtkiconfactory.c b/gtk/deprecated/gtkiconfactory.c index 1508da583a..c1fc37072c 100644 --- a/gtk/deprecated/gtkiconfactory.c +++ b/gtk/deprecated/gtkiconfactory.c @@ -46,6 +46,7 @@ #include "gtkstyle.h" #include "gtkstylecontextprivate.h" #include "gtkrender.h" +#include "gtkrenderprivate.h" /** * SECTION:gtkiconfactory @@ -1222,21 +1223,20 @@ ensure_filename_pixbuf (GtkIconSet *icon_set, } static GdkPixbuf * -render_icon_name_pixbuf (GtkIconSource *icon_source, - GtkStyleContext *context, - GtkIconSize size, - gint scale) +render_icon_name_pixbuf (GtkIconSource *icon_source, + GtkCssStyle *style, + GtkIconSize size, + gint scale) { GdkPixbuf *pixbuf; GdkPixbuf *tmp_pixbuf; - GtkIconSource tmp_source; GtkIconTheme *icon_theme; gint width, height, pixel_size; gint *sizes, *s, dist; GError *error = NULL; icon_theme = gtk_css_icon_theme_value_get_icon_theme - (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_THEME)); + (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_THEME)); if (!gtk_icon_size_lookup (size, &width, &height)) { @@ -1322,11 +1322,11 @@ render_icon_name_pixbuf (GtkIconSource *icon_source, return NULL; } - tmp_source = *icon_source; - tmp_source.type = GTK_ICON_SOURCE_PIXBUF; - tmp_source.source.pixbuf = tmp_pixbuf; - - pixbuf = gtk_render_icon_pixbuf (context, &tmp_source, -1); + pixbuf = gtk_render_icon_pixbuf_unpacked (tmp_pixbuf, + -1, + gtk_icon_source_get_state_wildcarded (icon_source) + ? _gtk_css_icon_effect_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_EFFECT)) + : GTK_CSS_ICON_EFFECT_NONE); if (!pixbuf) g_warning ("Failed to render icon"); @@ -1338,7 +1338,7 @@ render_icon_name_pixbuf (GtkIconSource *icon_source, static GdkPixbuf * find_and_render_icon_source (GtkIconSet *icon_set, - GtkStyleContext *context, + GtkCssStyle *style, GtkTextDirection direction, GtkStateType state, GtkIconSize size, @@ -1371,7 +1371,14 @@ find_and_render_icon_source (GtkIconSet *icon_set, break; /* Fall through */ case GTK_ICON_SOURCE_PIXBUF: - pixbuf = gtk_render_icon_pixbuf (context, source, size); +G_GNUC_BEGIN_IGNORE_DEPRECATIONS; + pixbuf = gtk_render_icon_pixbuf_unpacked (gtk_icon_source_get_pixbuf (source), + gtk_icon_source_get_size_wildcarded (source) ? size : -1, + gtk_icon_source_get_state_wildcarded (source) + ? _gtk_css_icon_effect_value_get ( + gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_EFFECT)) + : GTK_CSS_ICON_EFFECT_NONE); +G_GNUC_END_IGNORE_DEPRECATIONS; if (!pixbuf) { g_warning ("Failed to render icon"); @@ -1390,7 +1397,7 @@ find_and_render_icon_source (GtkIconSet *icon_set, break; case GTK_ICON_SOURCE_ICON_NAME: case GTK_ICON_SOURCE_STATIC_ICON_NAME: - pixbuf = render_icon_name_pixbuf (source, context, + pixbuf = render_icon_name_pixbuf (source, style, size, scale); if (!pixbuf) failed = g_slist_prepend (failed, source); @@ -1406,7 +1413,7 @@ find_and_render_icon_source (GtkIconSet *icon_set, } static GdkPixbuf* -render_fallback_image (GtkStyleContext *context, +render_fallback_image (GtkCssStyle *style, GtkTextDirection direction, GtkStateType state, GtkIconSize size) @@ -1421,29 +1428,25 @@ render_fallback_image (GtkStyleContext *context, fallback_source.direction = GTK_TEXT_DIR_NONE; } - return render_icon_name_pixbuf (&fallback_source, context, size, 1); + return render_icon_name_pixbuf (&fallback_source, style, size, 1); } -static GdkPixbuf* -gtk_icon_set_render_icon_pixbuf_for_scale (GtkIconSet *icon_set, - GtkStyleContext *context, - GtkIconSize size, - gint scale) +GdkPixbuf* +gtk_icon_set_render_icon_pixbuf_for_scale (GtkIconSet *icon_set, + GtkCssStyle *style, + GtkTextDirection direction, + GtkIconSize size, + gint scale) { GdkPixbuf *icon = NULL; GtkStateType state; - GtkTextDirection direction; GtkCssIconEffect effect; g_return_val_if_fail (icon_set != NULL, NULL); - g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL); - -G_GNUC_BEGIN_IGNORE_DEPRECATIONS; - direction = gtk_style_context_get_direction (context); -G_GNUC_END_IGNORE_DEPRECATIONS; + g_return_val_if_fail (GTK_IS_CSS_STYLE (style), NULL); effect = _gtk_css_icon_effect_value_get - (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_EFFECT)); + (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_EFFECT)); switch (effect) { @@ -1461,11 +1464,11 @@ G_GNUC_END_IGNORE_DEPRECATIONS; } if (icon_set->sources) - icon = find_and_render_icon_source (icon_set, context, direction, state, + icon = find_and_render_icon_source (icon_set, style, direction, state, size, scale); if (icon == NULL) - icon = render_fallback_image (context, direction, state, size); + icon = render_fallback_image (style, direction, state, size); return icon; } @@ -1498,7 +1501,13 @@ gtk_icon_set_render_icon_pixbuf (GtkIconSet *icon_set, g_return_val_if_fail (icon_set != NULL, NULL); g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL); - return gtk_icon_set_render_icon_pixbuf_for_scale (icon_set, context, size, 1); +G_GNUC_BEGIN_IGNORE_DEPRECATIONS; + return gtk_icon_set_render_icon_pixbuf_for_scale (icon_set, + gtk_style_context_lookup_style (context), + gtk_style_context_get_direction (context), + size, + 1); +G_GNUC_END_IGNORE_DEPRECATIONS; } /** @@ -1533,7 +1542,13 @@ gtk_icon_set_render_icon_surface (GtkIconSet *icon_set, GdkPixbuf *pixbuf; cairo_surface_t *surface; - pixbuf = gtk_icon_set_render_icon_pixbuf_for_scale (icon_set, context, size, scale); +G_GNUC_BEGIN_IGNORE_DEPRECATIONS; + pixbuf = gtk_icon_set_render_icon_pixbuf_for_scale (icon_set, + gtk_style_context_lookup_style (context), + gtk_style_context_get_direction (context), + size, + scale); +G_GNUC_END_IGNORE_DEPRECATIONS; surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, for_window); g_object_unref (pixbuf); @@ -1599,7 +1614,7 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS; } if (!context) - return render_fallback_image (context, direction, state, size); + return render_fallback_image (gtk_style_context_lookup_style (context), direction, state, size); gtk_style_context_save (context); diff --git a/gtk/deprecated/gtkiconfactoryprivate.h b/gtk/deprecated/gtkiconfactoryprivate.h index 8902b710a0..bc1136559f 100644 --- a/gtk/deprecated/gtkiconfactoryprivate.h +++ b/gtk/deprecated/gtkiconfactoryprivate.h @@ -23,4 +23,10 @@ GList * _gtk_icon_factory_list_ids (void); void _gtk_icon_factory_ensure_default_icons (void); +GdkPixbuf * gtk_icon_set_render_icon_pixbuf_for_scale (GtkIconSet *icon_set, + GtkCssStyle *style, + GtkTextDirection direction, + GtkIconSize size, + gint scale); + #endif /* __GTK_ICON_FACTORY_PRIVATE_H__ */ diff --git a/gtk/gtkiconhelper.c b/gtk/gtkiconhelper.c index 4ae5f9732a..3bc2507860 100644 --- a/gtk/gtkiconhelper.c +++ b/gtk/gtkiconhelper.c @@ -28,6 +28,7 @@ #include "gtkiconthemeprivate.h" #include "gtkrender.h" #include "gtkstylecontextprivate.h" +#include "deprecated/gtkiconfactoryprivate.h" #include "deprecated/gtkstock.h" struct _GtkIconHelperPrivate { @@ -351,17 +352,26 @@ ensure_surface_from_pixbuf (GtkIconHelper *self, } static cairo_surface_t * -ensure_surface_for_icon_set (GtkIconHelper *self, - GtkStyleContext *context, - gint scale, - GtkIconSet *icon_set) +ensure_surface_for_icon_set (GtkIconHelper *self, + GtkCssStyle *style, + GtkTextDirection direction, + gint scale, + GtkIconSet *icon_set) { -G_GNUC_BEGIN_IGNORE_DEPRECATIONS; - return gtk_icon_set_render_icon_surface (icon_set, context, - self->priv->icon_size, - scale, - self->priv->window); -G_GNUC_END_IGNORE_DEPRECATIONS; + cairo_surface_t *surface; + GdkPixbuf *pixbuf; + + pixbuf = gtk_icon_set_render_icon_pixbuf_for_scale (icon_set, + style, + direction, + self->priv->icon_size, + scale); + surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, + scale, + self->priv->window); + g_object_unref (pixbuf); + + return surface; } static cairo_surface_t * @@ -469,18 +479,26 @@ gtk_icon_helper_load_surface (GtkIconHelper *self, break; case GTK_IMAGE_STOCK: - G_GNUC_BEGIN_IGNORE_DEPRECATIONS; +G_GNUC_BEGIN_IGNORE_DEPRECATIONS; icon_set = gtk_icon_factory_lookup_default (gtk_image_definition_get_stock (self->priv->def)); if (icon_set != NULL) - surface = ensure_surface_for_icon_set (self, context, scale, icon_set); + surface = ensure_surface_for_icon_set (self, + gtk_style_context_lookup_style (context), + gtk_style_context_get_direction (context), + scale, icon_set); else surface = NULL; - G_GNUC_END_IGNORE_DEPRECATIONS; +G_GNUC_END_IGNORE_DEPRECATIONS; break; case GTK_IMAGE_ICON_SET: icon_set = gtk_image_definition_get_icon_set (self->priv->def); - surface = ensure_surface_for_icon_set (self, context, scale, icon_set); +G_GNUC_BEGIN_IGNORE_DEPRECATIONS; + surface = ensure_surface_for_icon_set (self, + gtk_style_context_lookup_style (context), + gtk_style_context_get_direction (context), + scale, icon_set); +G_GNUC_END_IGNORE_DEPRECATIONS; break; case GTK_IMAGE_ICON_NAME: diff --git a/gtk/gtkrender.c b/gtk/gtkrender.c index 1f44b2e401..27fd591747 100644 --- a/gtk/gtkrender.c +++ b/gtk/gtkrender.c @@ -23,7 +23,6 @@ #include #include "gtkcsscornervalueprivate.h" -#include "gtkcssenumvalueprivate.h" #include "gtkcssimagebuiltinprivate.h" #include "gtkcssimagevalueprivate.h" #include "gtkcssnumbervalueprivate.h" @@ -1045,53 +1044,37 @@ scale_or_ref (GdkPixbuf *src, GDK_INTERP_BILINEAR); } -static GdkPixbuf * -gtk_render_icon_pixbuf_for_style (GtkCssStyle *style, - const GtkIconSource *source, - GtkIconSize size) +GdkPixbuf * +gtk_render_icon_pixbuf_unpacked (GdkPixbuf *base_pixbuf, + GtkIconSize size, + GtkCssIconEffect icon_effect) { GdkPixbuf *scaled; GdkPixbuf *stated; - GdkPixbuf *base_pixbuf; - gint width = 1; - gint height = 1; cairo_surface_t *surface; - gboolean wildcarded; - GtkCssIconEffect icon_effect; - - G_GNUC_BEGIN_IGNORE_DEPRECATIONS; - base_pixbuf = gtk_icon_source_get_pixbuf (source); - G_GNUC_END_IGNORE_DEPRECATIONS; g_return_val_if_fail (base_pixbuf != NULL, NULL); - if (size != (GtkIconSize) -1 && - !gtk_icon_size_lookup (size, &width, &height)) - { - g_warning (G_STRLOC ": invalid icon size '%d'", size); - return NULL; - } - /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise, * leave it alone. */ - G_GNUC_BEGIN_IGNORE_DEPRECATIONS; - wildcarded = gtk_icon_source_get_size_wildcarded (source); - G_GNUC_END_IGNORE_DEPRECATIONS; - if (size != (GtkIconSize) -1 && wildcarded) - scaled = scale_or_ref (base_pixbuf, width, height); + if (size != (GtkIconSize) -1) + { + int width = 1; + int height = 1; + + if (!gtk_icon_size_lookup (size, &width, &height)) + { + g_warning (G_STRLOC ": invalid icon size '%d'", size); + return NULL; + } + + scaled = scale_or_ref (base_pixbuf, width, height); + } else - scaled = g_object_ref (base_pixbuf); - - /* If the state was wildcarded, then generate a state. */ - G_GNUC_BEGIN_IGNORE_DEPRECATIONS; - wildcarded = gtk_icon_source_get_state_wildcarded (source); - G_GNUC_END_IGNORE_DEPRECATIONS; - - if (!wildcarded) - return scaled; - - icon_effect = _gtk_css_icon_effect_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_EFFECT)); + { + scaled = g_object_ref (base_pixbuf); + } if (icon_effect != GTK_CSS_ICON_EFFECT_NONE) { @@ -1135,7 +1118,14 @@ gtk_render_icon_pixbuf (GtkStyleContext *context, g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == (GtkIconSize)-1, NULL); g_return_val_if_fail (source != NULL, NULL); - return gtk_render_icon_pixbuf_for_style (gtk_style_context_lookup_style (context), source, size); +G_GNUC_BEGIN_IGNORE_DEPRECATIONS; + return gtk_render_icon_pixbuf_unpacked (gtk_icon_source_get_pixbuf (source), + gtk_icon_source_get_size_wildcarded (source) ? size : -1, + gtk_icon_source_get_state_wildcarded (source) + ? _gtk_css_icon_effect_value_get ( + _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_EFFECT)) + : GTK_CSS_ICON_EFFECT_NONE); +G_GNUC_END_IGNORE_DEPRECATIONS; } /** diff --git a/gtk/gtkrenderprivate.h b/gtk/gtkrenderprivate.h index d81a098832..4747a23ff8 100644 --- a/gtk/gtkrenderprivate.h +++ b/gtk/gtkrenderprivate.h @@ -22,6 +22,8 @@ #include #include +#include "gtkcssenumvalueprivate.h" + void gtk_render_content_path (GtkStyleContext *context, cairo_t *cr, double x, @@ -29,4 +31,8 @@ void gtk_render_content_path (GtkStyleContext *context double width, double height); +GdkPixbuf * gtk_render_icon_pixbuf_unpacked (GdkPixbuf *base_pixbuf, + GtkIconSize size, + GtkCssIconEffect icon_effect); + #endif /* __GTK_RENDER_PRIVATE_H__ */