]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcellrendererpixbuf.c
label: Fix memleak
[~andy/gtk] / gtk / gtkcellrendererpixbuf.c
index 25820b3ac80634acbf17b8954ac2cc739344a175..90fc9fece085141ccd7fb28a987963d1fd066844 100644 (file)
@@ -12,9 +12,7 @@
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "config.h"
@@ -25,6 +23,7 @@
 #include "gtkicontheme.h"
 #include "gtkintl.h"
 #include "gtkprivate.h"
+#include "a11y/gtkimagecellaccessible.h"
 
 
 /**
@@ -87,6 +86,7 @@ enum {
 struct _GtkCellRendererPixbufPrivate
 {
   GtkIconHelper *icon_helper;
+  GtkIconSize    icon_size;
 
   GdkPixbuf *pixbuf_expander_open;
   GdkPixbuf *pixbuf_expander_closed;
@@ -110,6 +110,7 @@ gtk_cell_renderer_pixbuf_init (GtkCellRendererPixbuf *cellpixbuf)
                                                   GtkCellRendererPixbufPrivate);
   priv = cellpixbuf->priv;
   priv->icon_helper = _gtk_icon_helper_new ();
+  priv->icon_size = GTK_ICON_SIZE_MENU;
 }
 
 static void
@@ -249,6 +250,8 @@ gtk_cell_renderer_pixbuf_class_init (GtkCellRendererPixbufClass *class)
 
 
   g_type_class_add_private (object_class, sizeof (GtkCellRendererPixbufPrivate));
+
+  gtk_cell_renderer_class_set_accessible_type (cell_class, GTK_TYPE_IMAGE_CELL_ACCESSIBLE);
 }
 
 static void
@@ -275,7 +278,7 @@ gtk_cell_renderer_pixbuf_get_property (GObject        *object,
       g_value_set_string (value, _gtk_icon_helper_get_stock_id (priv->icon_helper));
       break;
     case PROP_STOCK_SIZE:
-      g_value_set_uint (value, _gtk_icon_helper_get_icon_size (priv->icon_helper));
+      g_value_set_uint (value, priv->icon_size);
       break;
     case PROP_STOCK_DETAIL:
       g_value_set_string (value, priv->stock_detail);
@@ -350,10 +353,11 @@ gtk_cell_renderer_pixbuf_set_property (GObject      *object,
       break;
     case PROP_STOCK_ID:
       gtk_cell_renderer_pixbuf_reset (cellpixbuf);
-      _gtk_icon_helper_set_stock_id (priv->icon_helper, g_value_get_string (value), GTK_ICON_SIZE_MENU);
+      _gtk_icon_helper_set_stock_id (priv->icon_helper, g_value_get_string (value), priv->icon_size);
       break;
     case PROP_STOCK_SIZE:
-      _gtk_icon_helper_set_icon_size (priv->icon_helper, g_value_get_uint (value));
+      priv->icon_size = g_value_get_uint (value);
+      _gtk_icon_helper_set_icon_size (priv->icon_helper, priv->icon_size);
       break;
     case PROP_STOCK_DETAIL:
       g_free (priv->stock_detail);
@@ -361,14 +365,14 @@ gtk_cell_renderer_pixbuf_set_property (GObject      *object,
       break;
     case PROP_ICON_NAME:
       gtk_cell_renderer_pixbuf_reset (cellpixbuf);
-      _gtk_icon_helper_set_icon_name (priv->icon_helper, g_value_get_string (value), GTK_ICON_SIZE_MENU);
+      _gtk_icon_helper_set_icon_name (priv->icon_helper, g_value_get_string (value), priv->icon_size);
       break;
     case PROP_FOLLOW_STATE:
       priv->follow_state = g_value_get_boolean (value);
       break;
     case PROP_GICON:
       gtk_cell_renderer_pixbuf_reset (cellpixbuf);
-      _gtk_icon_helper_set_gicon (priv->icon_helper, g_value_get_object (value), GTK_ICON_SIZE_MENU);
+      _gtk_icon_helper_set_gicon (priv->icon_helper, g_value_get_object (value), priv->icon_size);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -411,12 +415,19 @@ gtk_cell_renderer_pixbuf_get_size (GtkCellRenderer    *cell,
   gint calc_width;
   gint calc_height;
   gint xpad, ypad;
+  GtkStyleContext *context;
+
+  context = gtk_widget_get_style_context (widget);
+  gtk_style_context_save (context);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
 
   if (!_gtk_icon_helper_get_is_empty (priv->icon_helper))
     _gtk_icon_helper_get_size (priv->icon_helper, 
                                gtk_widget_get_style_context (widget),
                                &pixbuf_width, &pixbuf_height);
 
+  gtk_style_context_restore (context);
+
   if (priv->pixbuf_expander_open)
     {
       pixbuf_width  = MAX (pixbuf_width, gdk_pixbuf_get_width (priv->pixbuf_expander_open));
@@ -512,6 +523,7 @@ gtk_cell_renderer_pixbuf_render (GtkCellRenderer      *cell,
     state = gtk_cell_renderer_get_state (cell, widget, flags);
 
   gtk_style_context_set_state (context, state);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
 
   g_object_get (cell, "is-expander", &is_expander, NULL);
   if (is_expander)