gtk+ r20391 - in trunk: . gtk



Author: matthiasc
Date: Sun Jun 15 04:54:20 2008
New Revision: 20391
URL: http://svn.gnome.org/viewvc/gtk+?rev=20391&view=rev

Log:
Add a gicon property


Modified:
   trunk/ChangeLog
   trunk/gtk/gtkcellrendererpixbuf.c

Modified: trunk/gtk/gtkcellrendererpixbuf.c
==============================================================================
--- trunk/gtk/gtkcellrendererpixbuf.c	(original)
+++ trunk/gtk/gtkcellrendererpixbuf.c	Sun Jun 15 04:54:20 2008
@@ -64,7 +64,8 @@
   PROP_STOCK_SIZE,
   PROP_STOCK_DETAIL,
   PROP_FOLLOW_STATE,
-  PROP_ICON_NAME
+  PROP_ICON_NAME,
+  PROP_GICON
 };
 
 
@@ -77,8 +78,8 @@
   GtkIconSize stock_size;
   gchar *stock_detail;
   gboolean follow_state;
-
   gchar *icon_name;
+  GIcon *gicon;
 };
 
 G_DEFINE_TYPE (GtkCellRendererPixbuf, gtk_cell_renderer_pixbuf, GTK_TYPE_CELL_RENDERER)
@@ -191,6 +192,24 @@
  							 FALSE,
  							 GTK_PARAM_READWRITE));
 
+  /**
+   * GtkCellRendererPixbuf:gicon:
+   *
+   * The GIcon representing the icon to display.
+   * If the icon theme is changed, the image will be updated
+   * automatically.
+   *
+   * Since: 2.16
+   */
+  g_object_class_install_property (object_class,
+                                   PROP_GICON,
+                                   g_param_spec_object ("gicon",
+                                                        P_("Icon"),
+                                                        P_("The GIcon being displayed"),
+                                                        G_TYPE_ICON,
+                                                        GTK_PARAM_READWRITE));
+
+
 
   g_type_class_add_private (object_class, sizeof (GtkCellRendererPixbufPrivate));
 }
@@ -214,6 +233,9 @@
   g_free (priv->stock_detail);
   g_free (priv->icon_name);
 
+  if (priv->gicon)
+    g_object_unref (priv->gicon);
+
   (* G_OBJECT_CLASS (gtk_cell_renderer_pixbuf_parent_class)->finalize) (object);
 }
 
@@ -231,13 +253,13 @@
   switch (param_id)
     {
     case PROP_PIXBUF:
-      g_value_set_object (value, G_OBJECT (cellpixbuf->pixbuf));
+      g_value_set_object (value, cellpixbuf->pixbuf);
       break;
     case PROP_PIXBUF_EXPANDER_OPEN:
-      g_value_set_object (value, G_OBJECT (cellpixbuf->pixbuf_expander_open));
+      g_value_set_object (value, cellpixbuf->pixbuf_expander_open);
       break;
     case PROP_PIXBUF_EXPANDER_CLOSED:
-      g_value_set_object (value, G_OBJECT (cellpixbuf->pixbuf_expander_closed));
+      g_value_set_object (value, cellpixbuf->pixbuf_expander_closed);
       break;
     case PROP_STOCK_ID:
       g_value_set_string (value, priv->stock_id);
@@ -254,12 +276,47 @@
     case PROP_ICON_NAME:
       g_value_set_string (value, priv->icon_name);
       break;
+    case PROP_GICON:
+      g_value_set_object (value, priv->gicon);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
       break;
     }
 }
 
+static void
+unset_image_properties (GtkCellRendererPixbuf *cell)
+{
+  GtkCellRendererPixbufPrivate *priv;
+
+  priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (cell);
+
+  if (priv->stock_id)
+    {
+      g_free (priv->stock_id);
+      priv->stock_id = NULL;
+      g_object_notify (G_OBJECT (cell), "stock-id");
+    }
+  if (priv->icon_name)
+    {
+      g_free (priv->icon_name);
+      priv->icon_name = NULL;
+      g_object_notify (G_OBJECT (cell), "icon-name");
+    }
+  if (cell->pixbuf)
+    {
+      g_object_unref (cell->pixbuf);
+      cell->pixbuf = NULL;
+      g_object_notify (G_OBJECT (cell), "pixbuf");
+    }
+  if (priv->gicon)
+    {
+      g_object_unref (priv->gicon);
+      priv->gicon = NULL;
+      g_object_notify (G_OBJECT (cell), "gicon");
+    }
+}
 
 static void
 gtk_cell_renderer_pixbuf_set_property (GObject      *object,
@@ -275,23 +332,10 @@
   switch (param_id)
     {
     case PROP_PIXBUF:
-      if (cellpixbuf->pixbuf)
-	g_object_unref (cellpixbuf->pixbuf);
-      cellpixbuf->pixbuf = (GdkPixbuf*) g_value_dup_object (value);
-      if (cellpixbuf->pixbuf)
+      if (g_value_get_object (value))
         {
-          if (priv->stock_id)
-            {
-              g_free (priv->stock_id);
-              priv->stock_id = NULL;
-              g_object_notify (object, "stock-id");
-            }
-          if (priv->icon_name)
-            {
-              g_free (priv->icon_name);
-              priv->icon_name = NULL;
-              g_object_notify (object, "icon-name");
-            }
+          unset_image_properties (cellpixbuf); 
+          cellpixbuf->pixbuf = (GdkPixbuf *) g_value_dup_object (value);
         }
       break;
     case PROP_PIXBUF_EXPANDER_OPEN:
@@ -305,31 +349,10 @@
       cellpixbuf->pixbuf_expander_closed = (GdkPixbuf*) g_value_dup_object (value);
       break;
     case PROP_STOCK_ID:
-      if (priv->stock_id)
+      if (g_value_get_string (value))
         {
-          if (cellpixbuf->pixbuf)
-            {
-              g_object_unref (cellpixbuf->pixbuf);
-              cellpixbuf->pixbuf = NULL;
-              g_object_notify (object, "pixbuf");
-            }
-          g_free (priv->stock_id);
-        }
-      priv->stock_id = g_value_dup_string (value);
-      if (priv->stock_id)
-        {
-          if (cellpixbuf->pixbuf)
-            {
-              g_object_unref (cellpixbuf->pixbuf);
-              cellpixbuf->pixbuf = NULL;
-              g_object_notify (object, "pixbuf");
-            }
-          if (priv->icon_name)
-            {
-              g_free (priv->icon_name);
-              priv->icon_name = NULL;
-              g_object_notify (object, "icon-name");
-            }
+          unset_image_properties (cellpixbuf);
+          priv->stock_id = g_value_dup_string (value);
         }
       break;
     case PROP_STOCK_SIZE:
@@ -340,36 +363,22 @@
       priv->stock_detail = g_value_dup_string (value);
       break;
     case PROP_ICON_NAME:
-      if (priv->icon_name)
-	{
-	  if (cellpixbuf->pixbuf)
-	    {
-	      g_object_unref (cellpixbuf->pixbuf);
-	      cellpixbuf->pixbuf = NULL;
-              g_object_notify (object, "pixbuf");
-	    }
-	  g_free (priv->icon_name);
-	}
-      priv->icon_name = g_value_dup_string (value);
-      if (priv->icon_name)
+      if (g_value_get_string (value))
         {
-	  if (cellpixbuf->pixbuf)
-	    {
-              g_object_unref (cellpixbuf->pixbuf);
-              cellpixbuf->pixbuf = NULL;
-              g_object_notify (object, "pixbuf");
-	    }
-          if (priv->stock_id)
-            {
-              g_free (priv->stock_id);
-              priv->stock_id = NULL;
-              g_object_notify (object, "stock-id");
-            }
+          unset_image_properties (cellpixbuf);
+          priv->icon_name = g_value_dup_string (value);
         }
       break;
     case PROP_FOLLOW_STATE:
       priv->follow_state = g_value_get_boolean (value);
       break;
+    case PROP_GICON:
+      if (g_value_get_object (value))
+        {
+          unset_image_properties (cellpixbuf); 
+          priv->gicon = (GIcon *) g_value_dup_object (value);
+        }
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
       break;
@@ -415,8 +424,8 @@
 }
 
 static void 
-gtk_cell_renderer_pixbuf_create_named_icon_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
-						   GtkWidget             *widget)
+gtk_cell_renderer_pixbuf_create_themed_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
+					       GtkWidget             *widget)
 {
   GtkCellRendererPixbufPrivate *priv;
   GdkScreen *screen;
@@ -428,7 +437,10 @@
   priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (cellpixbuf);
 
   if (cellpixbuf->pixbuf)
-    g_object_unref (cellpixbuf->pixbuf);
+    {
+      g_object_unref (cellpixbuf->pixbuf);
+      cellpixbuf->pixbuf = NULL;
+    }
 
   screen = gtk_widget_get_screen (GTK_WIDGET (widget));
   icon_theme = gtk_icon_theme_get_for_screen (screen);
@@ -442,12 +454,26 @@
       width = height = 24;
     }
 
-  cellpixbuf->pixbuf =
-    gtk_icon_theme_load_icon (icon_theme,
-			      priv->icon_name,
-			      MIN (width, height), 0, &error);
+  if (priv->icon_name)
+    cellpixbuf->pixbuf = gtk_icon_theme_load_icon (icon_theme,
+			                           priv->icon_name,
+			                           MIN (width, height), 
+                                                   GTK_ICON_LOOKUP_USE_BUILTIN,
+                                                   &error);
+  else if (priv->gicon)
+    {
+      GtkIconInfo *info;
+
+      info = gtk_icon_theme_lookup_by_gicon (icon_theme,
+                                             priv->gicon,
+			                     MIN (width, height), 
+                                             GTK_ICON_LOOKUP_USE_BUILTIN);
+      cellpixbuf->pixbuf = gtk_icon_info_load_icon (info, &error);
+      gtk_icon_info_free (info);
+    }
+
   if (!cellpixbuf->pixbuf) 
-    {
+  {
       g_warning ("could not load image: %s\n", error->message);
       g_error_free (error);
     }
@@ -524,8 +550,8 @@
     {
       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);
+      else if (priv->icon_name || priv->gicon)
+	gtk_cell_renderer_pixbuf_create_themed_pixbuf (cellpixbuf, widget);
     }
   
   if (cellpixbuf->pixbuf)



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