[gtk+/gtk-style-context] Add a GtkStyleContext-variant of symbolic icon loading
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-style-context] Add a GtkStyleContext-variant of symbolic icon loading
- Date: Wed, 24 Nov 2010 19:41:12 +0000 (UTC)
commit da23708d41eaff5ae4b4a37dae4987d3f73f56ae
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Nov 24 14:40:31 2010 -0500
Add a GtkStyleContext-variant of symbolic icon loading
gtk/gtkicontheme.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkicontheme.h | 5 +++
2 files changed, 97 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index cd55c3f..da551e5 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -3071,6 +3071,16 @@ gdk_color_to_css (GdkColor *color)
color->blue >> 8);
}
+static gchar *
+gdk_rgba_to_css (GdkRGBA *color)
+{
+ return g_strdup_printf ("rgba(%d,%d,%d,%f)",
+ (gint)(color->red * 255),
+ (gint)(color->green * 255),
+ (gint)(color->blue * 255),
+ color->alpha);
+}
+
static GdkPixbuf *
_gtk_icon_info_load_symbolic_internal (GtkIconInfo *icon_info,
const gchar *css_fg,
@@ -3236,6 +3246,88 @@ gtk_icon_info_load_symbolic (GtkIconInfo *icon_info,
}
/**
+ * gtk_icon_info_load_symbolic_for_context:
+ * @icon_info: a #GtkIconInfo
+ * context: a #GtkStyleContext
+ * @was_symbolic: (allow-none): a #gboolean, returns whether the loaded icon
+ * was a symbolic one and whether the @fg color was applied to it.
+ * @error: (allow-none): location to store error information on failure,
+ * or %NULL.
+ *
+ * Loads an icon, modifying it to match the system colors for the foreground,
+ * success, warning and error colors provided. If the icon is not a symbolic
+ * one, the function will return the result from gtk_icon_info_load_icon().
+ *
+ * This allows loading symbolic icons that will match the system theme.
+ *
+ * See gtk_icon_info_load_symbolic() for more details.
+ *
+ * Return value: (transfer full): a #GdkPixbuf representing the loaded icon
+ *
+ * Since: 3.0
+ **/
+GdkPixbuf *
+gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info,
+ GtkStyleContext *context,
+ gboolean *was_symbolic,
+ GError **error)
+{
+ GdkPixbuf *pixbuf;
+ GdkRGBA *color;
+ gchar *css_fg, *css_success;
+ gchar *css_warning, *css_error;
+
+ if (!icon_info->filename ||
+ !g_str_has_suffix (icon_info->filename, "-symbolic.svg"))
+ {
+ if (was_symbolic)
+ *was_symbolic = FALSE;
+ return gtk_icon_info_load_icon (icon_info, error);
+ }
+
+ if (was_symbolic)
+ *was_symbolic = TRUE;
+
+ if (gtk_style_context_lookup_color (context, "color", 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", color))
+ {
+ css_success = gdk_rgba_to_css (color);
+ gdk_rgba_free (color);
+ }
+
+ if (gtk_style_context_lookup_color (context, "warning_color", color))
+ {
+ css_warning = gdk_rgba_to_css (color);
+ gdk_rgba_free (color);
+ }
+
+ if (gtk_style_context_lookup_color (context, "error_color", color))
+ {
+ css_error = gdk_rgba_to_css (color);
+ gdk_rgba_free (color);
+ }
+
+ pixbuf = _gtk_icon_info_load_symbolic_internal (icon_info,
+ css_fg, css_success,
+ css_warning, css_error,
+ error);
+
+ g_free (css_fg);
+ g_free (css_success);
+ g_free (css_warning);
+ g_free (css_error);
+
+ return pixbuf;
+}
+
+/**
* gtk_icon_info_load_symbolic_for_style:
* @icon_info: a #GtkIconInfo
* @style: a #GtkStyle to take the colors from
diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h
index f493ba9..07042ef 100644
--- a/gtk/gtkicontheme.h
+++ b/gtk/gtkicontheme.h
@@ -27,6 +27,7 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk/gdk.h>
#include <gtk/gtkstyle.h>
+#include <gtk/gtkstylecontext.h>
G_BEGIN_DECLS
@@ -178,6 +179,10 @@ GdkPixbuf * gtk_icon_info_load_symbolic (GtkIconInfo *icon_info
GdkRGBA *error_color,
gboolean *was_symbolic,
GError **error);
+GdkPixbuf * gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info,
+ GtkStyleContext *context,
+ gboolean *was_symbolic,
+ GError **error);
GdkPixbuf * gtk_icon_info_load_symbolic_for_style (GtkIconInfo *icon_info,
GtkStyle *style,
GtkStateType state,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]