[gtk+] Add a variant of gtk_icon_theme_load_symbolic that takes a style



commit e9fc660d7ec07c74afe2d4114b88c44fd78f7759
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Jun 14 23:46:46 2010 -0400

    Add a variant of gtk_icon_theme_load_symbolic that takes a style
    
    As proposed by Owen in bug 621578 to reduce code duplication.

 docs/reference/gtk/gtk3-sections.txt |    1 +
 gtk/gtk.symbols                      |    1 +
 gtk/gtkcellrendererpixbuf.c          |   58 +++++++---------------------------
 gtk/gtkicontheme.c                   |   49 ++++++++++++++++++++++++++++
 gtk/gtkicontheme.h                   |    6 +++
 gtk/gtkimage.c                       |   54 ++++++-------------------------
 6 files changed, 79 insertions(+), 90 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index d8f868f..f2d5d82 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -5679,6 +5679,7 @@ gtk_icon_info_get_filename
 gtk_icon_info_get_builtin_pixbuf
 gtk_icon_info_load_icon
 gtk_icon_info_load_symbolic
+gtk_icon_info_load_symbolic_for_style
 gtk_icon_info_set_raw_coordinates
 gtk_icon_info_get_embedded_rect
 gtk_icon_info_get_attach_points
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index 958ae25..eba4e8e 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -1626,6 +1626,7 @@ gtk_icon_info_get_filename_utf8
 gtk_icon_info_get_type G_GNUC_CONST
 gtk_icon_info_load_icon
 gtk_icon_info_load_symbolic
+gtk_icon_info_load_symbolic_for_style
 gtk_icon_info_set_raw_coordinates
 gtk_icon_theme_add_builtin_icon
 #ifndef _WIN64
diff --git a/gtk/gtkcellrendererpixbuf.c b/gtk/gtkcellrendererpixbuf.c
index bde1d80..2337618 100644
--- a/gtk/gtkcellrendererpixbuf.c
+++ b/gtk/gtkcellrendererpixbuf.c
@@ -534,31 +534,15 @@ gtk_cell_renderer_pixbuf_create_themed_pixbuf (GtkCellRendererPixbuf *cellpixbuf
 
   if (info)
     {
-      GdkColor error_color, warning_color, success_color;
-      GdkColor *error_ptr, *warning_ptr, *success_ptr;
       GtkStyle *style;
 
       style = gtk_widget_get_style (GTK_WIDGET (widget));
-      if (!gtk_style_lookup_color (style, "error_color", &error_color))
-        error_ptr = NULL;
-      else
-        error_ptr = &error_color;
-      if (!gtk_style_lookup_color (style, "warning_color", &warning_color))
-        warning_ptr = NULL;
-      else
-        warning_ptr = &warning_color;
-      if (!gtk_style_lookup_color (style, "success_color", &success_color))
-        success_ptr = NULL;
-      else
-        success_ptr = &success_color;
-
-      cellpixbuf->pixbuf = gtk_icon_info_load_symbolic (info,
-                                                        &style->fg[GTK_STATE_NORMAL],
-                                                        success_ptr,
-                                                        warning_ptr,
-                                                        error_ptr,
-                                                        NULL,
-                                                        NULL);
+      cellpixbuf->pixbuf =
+        gtk_icon_info_load_symbolic_for_style (info,
+                                               style,
+                                               GTK_STATE_NORMAL,
+                                               NULL,
+                                               NULL);
       gtk_icon_info_free (info);
     }
 
@@ -568,7 +552,7 @@ gtk_cell_renderer_pixbuf_create_themed_pixbuf (GtkCellRendererPixbuf *cellpixbuf
 static GdkPixbuf *
 create_symbolic_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
 			GtkWidget             *widget,
-			GdkColor              *fg)
+			GtkStateType           state)
 {
   GtkCellRendererPixbufPrivate *priv;
   GdkScreen *screen;
@@ -623,34 +607,16 @@ create_symbolic_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
 
   if (info)
     {
-      GdkColor error_color, warning_color, success_color;
-      GdkColor *error_ptr, *warning_ptr, *success_ptr;
       GtkStyle *style;
 
       style = gtk_widget_get_style (GTK_WIDGET (widget));
-      if (!gtk_style_lookup_color (style, "error_color", &error_color))
-        error_ptr = NULL;
-      else
-        error_ptr = &error_color;
-      if (!gtk_style_lookup_color (style, "warning_color", &warning_color))
-        warning_ptr = NULL;
-      else
-        warning_ptr = &warning_color;
-      if (!gtk_style_lookup_color (style, "success_color", &success_color))
-        success_ptr = NULL;
-      else
-        success_ptr = &success_color;
-
-      pixbuf = gtk_icon_info_load_symbolic (info,
-                                            fg,
-                                            success_ptr,
-                                            warning_ptr,
-                                            error_ptr,
-                                            NULL,
-                                            NULL);
+      pixbuf = gtk_icon_info_load_symbolic_for_style (info,
+                                                      style, state,
+                                                      NULL, NULL);
       gtk_icon_info_free (info);
       return pixbuf;
     }
+
   return NULL;
 }
 
@@ -868,7 +834,7 @@ gtk_cell_renderer_pixbuf_render (GtkCellRenderer      *cell,
       else
 	state = GTK_STATE_PRELIGHT;
 
-      symbolic = create_symbolic_pixbuf (cellpixbuf, widget, &widget->style->fg[state]);
+      symbolic = create_symbolic_pixbuf (cellpixbuf, widget, state);
       if (!symbolic) {
         colorized = create_colorized_pixbuf (pixbuf,
 					     &widget->style->base[state]);
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index 380595e..53f7149 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -3220,6 +3220,55 @@ gtk_icon_info_load_symbolic (GtkIconInfo  *icon_info,
 }
 
 /**
+ * gtk_icon_info_load_symbolic_for_style:
+ * @icon_info: a #GtkIconInfo
+ * @style: a #GtkStyle to take the colors from
+ * @state: the widget state to use for colors
+ * @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 colours 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: a #GdkPixbuf representing the loaded icon
+ *
+ * Since: 3.0
+ **/
+GdkPixbuf *
+gtk_icon_info_load_symbolic_for_style (GtkIconInfo   *icon_info,
+                                       GtkStyle      *style,
+                                       GtkStateType   state,
+                                       gboolean      *was_symbolic,
+                                       GError       **error)
+{
+  GdkColor success_color;
+  GdkColor warning_color;
+  GdkColor error_color;
+  GdkColor *fg;
+  GdkColor *success = NULL;
+  GdkColor *warning = NULL;
+  GdkColor *err = NULL;
+
+  fg = &style->fg[state];
+  if (gtk_style_lookup_color (style, "success_color", &success_color))
+    success = &success_color;
+  if (gtk_style_lookup_color (style, "warning_color", &warning_color))
+    warning = &warning_color;
+  if (gtk_style_lookup_color (style, "error_color", &error_color))
+    err = &error_color;
+
+  return gtk_icon_info_load_symbolic (icon_info, fg, success, warning, err,
+                                      &was_symbolic, error);
+}
+
+/**
  * gtk_icon_info_set_raw_coordinates:
  * @icon_info: a #GtkIconInfo
  * @raw_coordinates: whether the coordinates of embedded rectangles
diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h
index aa1fa51..441a72a 100644
--- a/gtk/gtkicontheme.h
+++ b/gtk/gtkicontheme.h
@@ -26,6 +26,7 @@
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gdk/gdk.h>
+#include <gtk/gtkstyle.h>
 
 G_BEGIN_DECLS
 
@@ -186,6 +187,11 @@ GdkPixbuf *           gtk_icon_info_load_symbolic      (GtkIconInfo   *icon_info
 							GdkColor      *error_color,
 							gboolean      *was_symbolic,
                                                         GError       **error);
+GdkPixbuf *           gtk_icon_info_load_symbolic_for_style  (GtkIconInfo   *icon_info,
+                                                              GtkStyle      *style,
+                                                              GtkStateType   state,
+                                                              gboolean      *was_symbolic,
+                                                              GError       **error);
 void                  gtk_icon_info_set_raw_coordinates (GtkIconInfo  *icon_info,
 							 gboolean      raw_coordinates);
 
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index 9edae99..df032f2 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -1697,32 +1697,15 @@ ensure_pixbuf_for_icon_name (GtkImage     *image,
                                          MIN (width, height), flags);
       if (info)
         {
-          GdkColor error_color, warning_color, success_color;
-          GdkColor *error_ptr, *warning_ptr, *success_ptr;
           GtkStyle *style;
           gboolean was_symbolic;
 
           style = gtk_widget_get_style (GTK_WIDGET (image));
-          if (!gtk_style_lookup_color (style, "error_color", &error_color))
-            error_ptr = NULL;
-          else
-            error_ptr = &error_color;
-          if (!gtk_style_lookup_color (style, "warning_color", &warning_color))
-            warning_ptr = NULL;
-          else
-            warning_ptr = &warning_color;
-          if (!gtk_style_lookup_color (style, "success_color", &success_color))
-            success_ptr = NULL;
-          else
-            success_ptr = &success_color;
-
-          image->data.name.pixbuf = gtk_icon_info_load_symbolic (info,
-                                                                 &style->fg[state],
-                                                                 success_ptr,
-                                                                 warning_ptr,
-                                                                 error_ptr,
-                                                                 &was_symbolic,
-                                                                 NULL);
+          image->data.name.pixbuf =
+            gtk_icon_info_load_symbolic_for_style (info,
+                                                   style, state,
+                                                   &was_symbolic,
+                                                   NULL);
           priv->was_symbolic = was_symbolic;
           gtk_icon_info_free (info);
         }
@@ -1790,32 +1773,15 @@ ensure_pixbuf_for_gicon (GtkImage     *image,
 					     MIN (width, height), flags);
       if (info)
         {
-          GdkColor error_color, warning_color, success_color;
-          GdkColor *error_ptr, *warning_ptr, *success_ptr;
           GtkStyle *style;
           gboolean was_symbolic;
 
           style = gtk_widget_get_style (GTK_WIDGET (image));
-          if (!gtk_style_lookup_color (style, "error_color", &error_color))
-            error_ptr = NULL;
-          else
-            error_ptr = &error_color;
-          if (!gtk_style_lookup_color (style, "warning_color", &warning_color))
-            warning_ptr = NULL;
-          else
-            warning_ptr = &warning_color;
-          if (!gtk_style_lookup_color (style, "success_color", &success_color))
-            success_ptr = NULL;
-          else
-            success_ptr = &success_color;
-
-          image->data.gicon.pixbuf = gtk_icon_info_load_symbolic (info,
-                                                                  &style->fg[state],
-                                                                  success_ptr,
-                                                                  warning_ptr,
-                                                                  error_ptr,
-                                                                  &was_symbolic,
-                                                                  NULL);
+          image->data.gicon.pixbuf =
+            gtk_icon_info_load_symbolic_for_style (info,
+                                                   style, state,
+                                                   &was_symbolic,
+                                                   NULL);
           priv->was_symbolic = was_symbolic;
           gtk_icon_info_free (info);
         }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]