? foo
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.6484
diff -u -r1.6484 ChangeLog
--- ChangeLog	1 Apr 2005 21:20:57 -0000	1.6484
+++ ChangeLog	2 Apr 2005 21:37:42 -0000
@@ -1,3 +1,14 @@
+2005-04-02  Anders Carlsson  <andersca@imendio.com>
+
+	* gtk/gtkcellrendererpixbuf.c:
+	(gtk_cell_renderer_pixbuf_class_init),
+	(gtk_cell_renderer_pixbuf_finalize),
+	(gtk_cell_renderer_pixbuf_get_property),
+	(gtk_cell_renderer_pixbuf_set_property),
+	(gtk_cell_renderer_pixbuf_create_named_icon_pixbuf),
+	(gtk_cell_renderer_pixbuf_get_size):
+	Add "icon-name" property. (#165777, Tommi Komulainen)
+	
 2005-04-01  Matthias Clasen  <mclasen@redhat.com>
 
 	* gtk/gtkselection.c: Move documentation inline, document
Index: gtk/gtkcellrendererpixbuf.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcellrendererpixbuf.c,v
retrieving revision 1.44
diff -u -r1.44 gtkcellrendererpixbuf.c
--- gtk/gtkcellrendererpixbuf.c	22 Mar 2005 02:14:54 -0000	1.44
+++ gtk/gtkcellrendererpixbuf.c	2 Apr 2005 21:37:42 -0000
@@ -21,6 +21,7 @@
 #include <stdlib.h>
 #include "gtkcellrendererpixbuf.h"
 #include "gtkiconfactory.h"
+#include "gtkicontheme.h"
 #include "gtkintl.h"
 #include "gtkprivate.h"
 #include "gtkalias.h"
@@ -38,6 +39,8 @@
 static void gtk_cell_renderer_pixbuf_finalize   (GObject                    *object);
 static void gtk_cell_renderer_pixbuf_create_stock_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
 							  GtkWidget             *widget);
+static void gtk_cell_renderer_pixbuf_create_named_icon_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
+							       GtkWidget             *widget);
 static void gtk_cell_renderer_pixbuf_get_size   (GtkCellRenderer            *cell,
 						 GtkWidget                  *widget,
 						 GdkRectangle               *rectangle,
@@ -62,7 +65,8 @@
 	PROP_STOCK_ID,
 	PROP_STOCK_SIZE,
 	PROP_STOCK_DETAIL,
-	PROP_FOLLOW_STATE
+	PROP_FOLLOW_STATE,
+	PROP_ICON_NAME
 };
 
 static gpointer parent_class;
@@ -77,6 +81,8 @@
   GtkIconSize stock_size;
   gchar *stock_detail;
   gboolean follow_state;
+
+  gchar *icon_name;
 };
 
 
@@ -183,6 +189,15 @@
 							NULL,
 							GTK_PARAM_READWRITE));
 
+  
+  g_object_class_install_property (object_class,
+				   PROP_ICON_NAME,
+				   g_param_spec_string ("icon-name",
+							P_("Icon Name"),
+							P_("The name of the icon from the icon theme"),
+							NULL,
+							GTK_PARAM_READWRITE));
+
   /**
    * GtkCellRendererPixbuf:follow-state:
    *
@@ -211,15 +226,13 @@
   GtkCellRendererPixbufPrivate *priv;
 
   priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (object);
-
+  
   if (cellpixbuf->pixbuf)
     g_object_unref (cellpixbuf->pixbuf);
 
-  if (priv->stock_id)
-    g_free (priv->stock_id);
-
-  if (priv->stock_detail)
-    g_free (priv->stock_detail);
+  g_free (priv->stock_id);
+  g_free (priv->stock_detail);
+  g_free (priv->icon_name);
 
   (* G_OBJECT_CLASS (parent_class)->finalize) (object);
 }
@@ -261,6 +274,9 @@
     case PROP_FOLLOW_STATE:
       g_value_set_boolean (value, priv->follow_state);
       break;
+    case PROP_ICON_NAME:
+      g_value_set_string (value, priv->icon_name);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
       break;
@@ -315,6 +331,8 @@
               cellpixbuf->pixbuf = NULL;
             }
           g_free (priv->stock_id);
+	  g_free (priv->icon_name);
+	  priv->icon_name = NULL;
         }
       priv->stock_id = g_strdup (g_value_get_string (value));
       break;
@@ -326,6 +344,19 @@
         g_free (priv->stock_detail);
       priv->stock_detail = g_strdup (g_value_get_string (value));
       break;
+    case PROP_ICON_NAME:
+      if (priv->icon_name)
+	{
+	  if (cellpixbuf->pixbuf)
+	    {
+	      g_object_unref (cellpixbuf->pixbuf);
+	      cellpixbuf->pixbuf = NULL;
+	    }
+	  g_free (priv->stock_id);
+	  g_free (priv->icon_name);
+	}
+      priv->icon_name = g_strdup (g_value_get_string (value));
+      break;
     case PROP_FOLLOW_STATE:
       priv->follow_state = g_value_get_boolean (value);
       break;
@@ -377,6 +408,45 @@
                                                priv->stock_detail);
 }
 
+static void 
+gtk_cell_renderer_pixbuf_create_named_icon_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
+						   GtkWidget             *widget)
+{
+  GtkCellRendererPixbufPrivate *priv;
+  GdkScreen *screen;
+  GtkIconTheme *icon_theme;
+  GtkSettings *settings;
+  gint width, height;
+  GError *error = NULL;
+
+  priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (cellpixbuf);
+
+  if (cellpixbuf->pixbuf)
+    g_object_unref (cellpixbuf->pixbuf);
+
+  screen = gtk_widget_get_screen (GTK_WIDGET (widget));
+  icon_theme = gtk_icon_theme_get_for_screen (screen);
+  settings = gtk_settings_get_for_screen (screen);
+
+  if (!gtk_icon_size_lookup_for_settings (settings,
+					  priv->stock_size,
+					  &width, &height))
+    {
+      g_warning ("Invalid icon size %d\n", priv->stock_size);
+      width = height = 24;
+    }
+
+  cellpixbuf->pixbuf =
+    gtk_icon_theme_load_icon (icon_theme,
+			      priv->icon_name,
+			      MIN (width, height), 0, &error);
+  if (!cellpixbuf->pixbuf) 
+    {
+      g_warning ("could not load image: %s\n", error->message);
+      g_error_free (error);
+    }
+}
+
 static GdkPixbuf *
 create_colorized_pixbuf (GdkPixbuf *src, 
 			 GdkColor  *new_color)
@@ -442,9 +512,14 @@
 
   priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (cell);
 
-  if (!cellpixbuf->pixbuf && priv->stock_id)
-    gtk_cell_renderer_pixbuf_create_stock_pixbuf (cellpixbuf, widget);
-
+  if (!cellpixbuf->pixbuf)
+    {
+      if (priv->stock_id)
+	gtk_cell_renderer_pixbuf_create_stock_pixbuf (cellpixbuf, widget);
+      else if (priv->icon_name)
+	gtk_cell_renderer_pixbuf_create_named_icon_pixbuf (cellpixbuf, widget);
+    }
+  
   if (cellpixbuf->pixbuf)
     {
       pixbuf_width  = gdk_pixbuf_get_width (cellpixbuf->pixbuf);
