]> Pileus Git - ~andy/gtk/blob - gtk/gtkcellrendererpixbuf.c
Don't leak expander pixbufs. (#316946, Tommi Komulainen)
[~andy/gtk] / gtk / gtkcellrendererpixbuf.c
1 /* gtkcellrendererpixbuf.c
2  * Copyright (C) 2000  Red Hat, Inc.,  Jonathan Blandford <jrb@redhat.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <config.h>
21 #include <stdlib.h>
22 #include "gtkcellrendererpixbuf.h"
23 #include "gtkiconfactory.h"
24 #include "gtkicontheme.h"
25 #include "gtkintl.h"
26 #include "gtkprivate.h"
27 #include "gtkalias.h"
28
29 static void gtk_cell_renderer_pixbuf_get_property  (GObject                    *object,
30                                                     guint                       param_id,
31                                                     GValue                     *value,
32                                                     GParamSpec                 *pspec);
33 static void gtk_cell_renderer_pixbuf_set_property  (GObject                    *object,
34                                                     guint                       param_id,
35                                                     const GValue               *value,
36                                                     GParamSpec                 *pspec);
37 static void gtk_cell_renderer_pixbuf_init       (GtkCellRendererPixbuf      *celltext);
38 static void gtk_cell_renderer_pixbuf_class_init (GtkCellRendererPixbufClass *class);
39 static void gtk_cell_renderer_pixbuf_finalize   (GObject                    *object);
40 static void gtk_cell_renderer_pixbuf_create_stock_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
41                                                           GtkWidget             *widget);
42 static void gtk_cell_renderer_pixbuf_create_named_icon_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
43                                                                GtkWidget             *widget);
44 static void gtk_cell_renderer_pixbuf_get_size   (GtkCellRenderer            *cell,
45                                                  GtkWidget                  *widget,
46                                                  GdkRectangle               *rectangle,
47                                                  gint                       *x_offset,
48                                                  gint                       *y_offset,
49                                                  gint                       *width,
50                                                  gint                       *height);
51 static void gtk_cell_renderer_pixbuf_render     (GtkCellRenderer            *cell,
52                                                  GdkDrawable                *window,
53                                                  GtkWidget                  *widget,
54                                                  GdkRectangle               *background_area,
55                                                  GdkRectangle               *cell_area,
56                                                  GdkRectangle               *expose_area,
57                                                  GtkCellRendererState        flags);
58
59
60 enum {
61         PROP_ZERO,
62         PROP_PIXBUF,
63         PROP_PIXBUF_EXPANDER_OPEN,
64         PROP_PIXBUF_EXPANDER_CLOSED,
65         PROP_STOCK_ID,
66         PROP_STOCK_SIZE,
67         PROP_STOCK_DETAIL,
68         PROP_FOLLOW_STATE,
69         PROP_ICON_NAME
70 };
71
72 static gpointer parent_class;
73
74
75 #define GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CELL_RENDERER_PIXBUF, GtkCellRendererPixbufPrivate))
76
77 typedef struct _GtkCellRendererPixbufPrivate GtkCellRendererPixbufPrivate;
78 struct _GtkCellRendererPixbufPrivate
79 {
80   gchar *stock_id;
81   GtkIconSize stock_size;
82   gchar *stock_detail;
83   gboolean follow_state;
84
85   gchar *icon_name;
86 };
87
88
89 GType
90 gtk_cell_renderer_pixbuf_get_type (void)
91 {
92   static GType cell_pixbuf_type = 0;
93
94   if (!cell_pixbuf_type)
95     {
96       static const GTypeInfo cell_pixbuf_info =
97       {
98         sizeof (GtkCellRendererPixbufClass),
99         NULL,           /* base_init */
100         NULL,           /* base_finalize */
101         (GClassInitFunc) gtk_cell_renderer_pixbuf_class_init,
102         NULL,           /* class_finalize */
103         NULL,           /* class_data */
104         sizeof (GtkCellRendererPixbuf),
105         0,              /* n_preallocs */
106         (GInstanceInitFunc) gtk_cell_renderer_pixbuf_init,
107       };
108
109       cell_pixbuf_type =
110         g_type_register_static (GTK_TYPE_CELL_RENDERER, I_("GtkCellRendererPixbuf"),
111                                 &cell_pixbuf_info, 0);
112     }
113
114   return cell_pixbuf_type;
115 }
116
117 static void
118 gtk_cell_renderer_pixbuf_init (GtkCellRendererPixbuf *cellpixbuf)
119 {
120   GtkCellRendererPixbufPrivate *priv;
121
122   priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (cellpixbuf);
123   priv->stock_size = GTK_ICON_SIZE_MENU;
124 }
125
126 static void
127 gtk_cell_renderer_pixbuf_class_init (GtkCellRendererPixbufClass *class)
128 {
129   GObjectClass *object_class = G_OBJECT_CLASS (class);
130   GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
131
132   parent_class = g_type_class_peek_parent (class);
133
134   object_class->finalize = gtk_cell_renderer_pixbuf_finalize;
135
136   object_class->get_property = gtk_cell_renderer_pixbuf_get_property;
137   object_class->set_property = gtk_cell_renderer_pixbuf_set_property;
138
139   cell_class->get_size = gtk_cell_renderer_pixbuf_get_size;
140   cell_class->render = gtk_cell_renderer_pixbuf_render;
141
142   g_object_class_install_property (object_class,
143                                    PROP_PIXBUF,
144                                    g_param_spec_object ("pixbuf",
145                                                         P_("Pixbuf Object"),
146                                                         P_("The pixbuf to render"),
147                                                         GDK_TYPE_PIXBUF,
148                                                         GTK_PARAM_READWRITE));
149
150   g_object_class_install_property (object_class,
151                                    PROP_PIXBUF_EXPANDER_OPEN,
152                                    g_param_spec_object ("pixbuf-expander-open",
153                                                         P_("Pixbuf Expander Open"),
154                                                         P_("Pixbuf for open expander"),
155                                                         GDK_TYPE_PIXBUF,
156                                                         GTK_PARAM_READWRITE));
157
158   g_object_class_install_property (object_class,
159                                    PROP_PIXBUF_EXPANDER_CLOSED,
160                                    g_param_spec_object ("pixbuf-expander-closed",
161                                                         P_("Pixbuf Expander Closed"),
162                                                         P_("Pixbuf for closed expander"),
163                                                         GDK_TYPE_PIXBUF,
164                                                         GTK_PARAM_READWRITE));
165
166   g_object_class_install_property (object_class,
167                                    PROP_STOCK_ID,
168                                    g_param_spec_string ("stock-id",
169                                                         P_("Stock ID"),
170                                                         P_("The stock ID of the stock icon to render"),
171                                                         NULL,
172                                                         GTK_PARAM_READWRITE));
173
174   g_object_class_install_property (object_class,
175                                    PROP_STOCK_SIZE,
176                                    g_param_spec_uint ("stock-size",
177                                                       P_("Size"),
178                                                       P_("The GtkIconSize value that specifies the size of the rendered icon"),
179                                                       0,
180                                                       G_MAXUINT,
181                                                       GTK_ICON_SIZE_MENU,
182                                                       GTK_PARAM_READWRITE));
183
184   g_object_class_install_property (object_class,
185                                    PROP_STOCK_DETAIL,
186                                    g_param_spec_string ("stock-detail",
187                                                         P_("Detail"),
188                                                         P_("Render detail to pass to the theme engine"),
189                                                         NULL,
190                                                         GTK_PARAM_READWRITE));
191
192   
193   /**
194    * GtkCellRendererPixbuf:icon-name:
195    *
196    * The name of the themed icon to display.
197    * This property only has an effect if not overridden by "stock_id" 
198    * or "pixbuf" properties.
199    *
200    * Since: 2.8 
201    */
202   g_object_class_install_property (object_class,
203                                    PROP_ICON_NAME,
204                                    g_param_spec_string ("icon-name",
205                                                         P_("Icon Name"),
206                                                         P_("The name of the icon from the icon theme"),
207                                                         NULL,
208                                                         GTK_PARAM_READWRITE));
209
210   /**
211    * GtkCellRendererPixbuf:follow-state:
212    *
213    * Specifies whether the rendered pixbuf should be colorized
214    * according to the #GtkCellRendererState.
215    *
216    * Since: 2.8
217    */
218   g_object_class_install_property (object_class,
219                                    PROP_FOLLOW_STATE,
220                                    g_param_spec_boolean ("follow-state",
221                                                          P_("Follow State"),
222                                                          P_("Whether the rendered pixbuf should be "
223                                                             "colorized according to the state"),
224                                                          FALSE,
225                                                          GTK_PARAM_READWRITE));
226
227
228   g_type_class_add_private (object_class, sizeof (GtkCellRendererPixbufPrivate));
229 }
230
231 static void
232 gtk_cell_renderer_pixbuf_finalize (GObject *object)
233 {
234   GtkCellRendererPixbuf *cellpixbuf = GTK_CELL_RENDERER_PIXBUF (object);
235   GtkCellRendererPixbufPrivate *priv;
236
237   priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (object);
238   
239   if (cellpixbuf->pixbuf)
240     g_object_unref (cellpixbuf->pixbuf);
241   if (cellpixbuf->pixbuf_expander_open)
242     g_object_unref (cellpixbuf->pixbuf_expander_open);
243   if (cellpixbuf->pixbuf_expander_closed)
244     g_object_unref (cellpixbuf->pixbuf_expander_closed);
245
246   g_free (priv->stock_id);
247   g_free (priv->stock_detail);
248   g_free (priv->icon_name);
249
250   (* G_OBJECT_CLASS (parent_class)->finalize) (object);
251 }
252
253 static void
254 gtk_cell_renderer_pixbuf_get_property (GObject        *object,
255                                        guint           param_id,
256                                        GValue         *value,
257                                        GParamSpec     *pspec)
258 {
259   GtkCellRendererPixbuf *cellpixbuf = GTK_CELL_RENDERER_PIXBUF (object);
260   GtkCellRendererPixbufPrivate *priv;
261
262   priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (object);
263   
264   switch (param_id)
265     {
266     case PROP_PIXBUF:
267       g_value_set_object (value,
268                           cellpixbuf->pixbuf ? G_OBJECT (cellpixbuf->pixbuf) : NULL);
269       break;
270     case PROP_PIXBUF_EXPANDER_OPEN:
271       g_value_set_object (value,
272                           cellpixbuf->pixbuf_expander_open ? G_OBJECT (cellpixbuf->pixbuf_expander_open) : NULL);
273       break;
274     case PROP_PIXBUF_EXPANDER_CLOSED:
275       g_value_set_object (value,
276                           cellpixbuf->pixbuf_expander_closed ? G_OBJECT (cellpixbuf->pixbuf_expander_closed) : NULL);
277       break;
278     case PROP_STOCK_ID:
279       g_value_set_string (value, priv->stock_id);
280       break;
281     case PROP_STOCK_SIZE:
282       g_value_set_uint (value, priv->stock_size);
283       break;
284     case PROP_STOCK_DETAIL:
285       g_value_set_string (value, priv->stock_detail);
286       break;
287     case PROP_FOLLOW_STATE:
288       g_value_set_boolean (value, priv->follow_state);
289       break;
290     case PROP_ICON_NAME:
291       g_value_set_string (value, priv->icon_name);
292       break;
293     default:
294       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
295       break;
296     }
297 }
298
299
300 static void
301 gtk_cell_renderer_pixbuf_set_property (GObject      *object,
302                                        guint         param_id,
303                                        const GValue *value,
304                                        GParamSpec   *pspec)
305 {
306   GdkPixbuf *pixbuf;
307   GtkCellRendererPixbuf *cellpixbuf = GTK_CELL_RENDERER_PIXBUF (object);
308   GtkCellRendererPixbufPrivate *priv;
309
310   priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (object);
311   
312   switch (param_id)
313     {
314     case PROP_PIXBUF:
315       pixbuf = (GdkPixbuf*) g_value_get_object (value);
316       if (pixbuf)
317         g_object_ref (pixbuf);
318       if (cellpixbuf->pixbuf)
319         g_object_unref (cellpixbuf->pixbuf);
320       cellpixbuf->pixbuf = pixbuf;
321       break;
322     case PROP_PIXBUF_EXPANDER_OPEN:
323       pixbuf = (GdkPixbuf*) g_value_get_object (value);
324       if (pixbuf)
325         g_object_ref (pixbuf);
326       if (cellpixbuf->pixbuf_expander_open)
327         g_object_unref (cellpixbuf->pixbuf_expander_open);
328       cellpixbuf->pixbuf_expander_open = pixbuf;
329       break;
330     case PROP_PIXBUF_EXPANDER_CLOSED:
331       pixbuf = (GdkPixbuf*) g_value_get_object (value);
332       if (pixbuf)
333         g_object_ref (pixbuf);
334       if (cellpixbuf->pixbuf_expander_closed)
335         g_object_unref (cellpixbuf->pixbuf_expander_closed);
336       cellpixbuf->pixbuf_expander_closed = pixbuf;
337       break;
338     case PROP_STOCK_ID:
339       if (priv->stock_id)
340         {
341           if (cellpixbuf->pixbuf)
342             {
343               g_object_unref (cellpixbuf->pixbuf);
344               cellpixbuf->pixbuf = NULL;
345             }
346           g_free (priv->stock_id);
347           g_free (priv->icon_name);
348           priv->icon_name = NULL;
349         }
350       priv->stock_id = g_strdup (g_value_get_string (value));
351       break;
352     case PROP_STOCK_SIZE:
353       priv->stock_size = g_value_get_uint (value);
354       break;
355     case PROP_STOCK_DETAIL:
356       if (priv->stock_detail)
357         g_free (priv->stock_detail);
358       priv->stock_detail = g_strdup (g_value_get_string (value));
359       break;
360     case PROP_ICON_NAME:
361       if (priv->icon_name)
362         {
363           if (cellpixbuf->pixbuf)
364             {
365               g_object_unref (cellpixbuf->pixbuf);
366               cellpixbuf->pixbuf = NULL;
367             }
368           g_free (priv->stock_id);
369           g_free (priv->icon_name);
370         }
371       priv->icon_name = g_strdup (g_value_get_string (value));
372       break;
373     case PROP_FOLLOW_STATE:
374       priv->follow_state = g_value_get_boolean (value);
375       break;
376     default:
377       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
378       break;
379     }
380
381   if (cellpixbuf->pixbuf && priv->stock_id)
382     {
383       g_object_unref (cellpixbuf->pixbuf);
384       cellpixbuf->pixbuf = NULL;
385     }
386 }
387
388 /**
389  * gtk_cell_renderer_pixbuf_new:
390  * 
391  * Creates a new #GtkCellRendererPixbuf. Adjust rendering
392  * parameters using object properties. Object properties can be set
393  * globally (with g_object_set()). Also, with #GtkTreeViewColumn, you
394  * can bind a property to a value in a #GtkTreeModel. For example, you
395  * can bind the "pixbuf" property on the cell renderer to a pixbuf value
396  * in the model, thus rendering a different image in each row of the
397  * #GtkTreeView.
398  * 
399  * Return value: the new cell renderer
400  **/
401 GtkCellRenderer *
402 gtk_cell_renderer_pixbuf_new (void)
403 {
404   return g_object_new (GTK_TYPE_CELL_RENDERER_PIXBUF, NULL);
405 }
406
407 static void
408 gtk_cell_renderer_pixbuf_create_stock_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
409                                               GtkWidget             *widget)
410 {
411   GtkCellRendererPixbufPrivate *priv;
412
413   priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (cellpixbuf);
414
415   if (cellpixbuf->pixbuf)
416     g_object_unref (cellpixbuf->pixbuf);
417
418   cellpixbuf->pixbuf = gtk_widget_render_icon (widget,
419                                                priv->stock_id,
420                                                priv->stock_size,
421                                                priv->stock_detail);
422 }
423
424 static void 
425 gtk_cell_renderer_pixbuf_create_named_icon_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
426                                                    GtkWidget             *widget)
427 {
428   GtkCellRendererPixbufPrivate *priv;
429   GdkScreen *screen;
430   GtkIconTheme *icon_theme;
431   GtkSettings *settings;
432   gint width, height;
433   GError *error = NULL;
434
435   priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (cellpixbuf);
436
437   if (cellpixbuf->pixbuf)
438     g_object_unref (cellpixbuf->pixbuf);
439
440   screen = gtk_widget_get_screen (GTK_WIDGET (widget));
441   icon_theme = gtk_icon_theme_get_for_screen (screen);
442   settings = gtk_settings_get_for_screen (screen);
443
444   if (!gtk_icon_size_lookup_for_settings (settings,
445                                           priv->stock_size,
446                                           &width, &height))
447     {
448       g_warning ("Invalid icon size %d\n", priv->stock_size);
449       width = height = 24;
450     }
451
452   cellpixbuf->pixbuf =
453     gtk_icon_theme_load_icon (icon_theme,
454                               priv->icon_name,
455                               MIN (width, height), 0, &error);
456   if (!cellpixbuf->pixbuf) 
457     {
458       g_warning ("could not load image: %s\n", error->message);
459       g_error_free (error);
460     }
461 }
462
463 static GdkPixbuf *
464 create_colorized_pixbuf (GdkPixbuf *src, 
465                          GdkColor  *new_color)
466 {
467   gint i, j;
468   gint width, height, has_alpha, src_row_stride, dst_row_stride;
469   gint red_value, green_value, blue_value;
470   guchar *target_pixels;
471   guchar *original_pixels;
472   guchar *pixsrc;
473   guchar *pixdest;
474   GdkPixbuf *dest;
475   
476   red_value = new_color->red / 255.0;
477   green_value = new_color->green / 255.0;
478   blue_value = new_color->blue / 255.0;
479   
480   dest = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src),
481                          gdk_pixbuf_get_has_alpha (src),
482                          gdk_pixbuf_get_bits_per_sample (src),
483                          gdk_pixbuf_get_width (src),
484                          gdk_pixbuf_get_height (src));
485   
486   has_alpha = gdk_pixbuf_get_has_alpha (src);
487   width = gdk_pixbuf_get_width (src);
488   height = gdk_pixbuf_get_height (src);
489   src_row_stride = gdk_pixbuf_get_rowstride (src);
490   dst_row_stride = gdk_pixbuf_get_rowstride (dest);
491   target_pixels = gdk_pixbuf_get_pixels (dest);
492   original_pixels = gdk_pixbuf_get_pixels (src);
493   
494   for (i = 0; i < height; i++) {
495     pixdest = target_pixels + i*dst_row_stride;
496     pixsrc = original_pixels + i*src_row_stride;
497     for (j = 0; j < width; j++) {               
498       *pixdest++ = (*pixsrc++ * red_value) >> 8;
499       *pixdest++ = (*pixsrc++ * green_value) >> 8;
500       *pixdest++ = (*pixsrc++ * blue_value) >> 8;
501       if (has_alpha) {
502         *pixdest++ = *pixsrc++;
503       }
504     }
505   }
506   return dest;
507 }
508
509
510 static void
511 gtk_cell_renderer_pixbuf_get_size (GtkCellRenderer *cell,
512                                    GtkWidget       *widget,
513                                    GdkRectangle    *cell_area,
514                                    gint            *x_offset,
515                                    gint            *y_offset,
516                                    gint            *width,
517                                    gint            *height)
518 {
519   GtkCellRendererPixbuf *cellpixbuf = (GtkCellRendererPixbuf *) cell;
520   GtkCellRendererPixbufPrivate *priv;
521   gint pixbuf_width  = 0;
522   gint pixbuf_height = 0;
523   gint calc_width;
524   gint calc_height;
525
526   priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (cell);
527
528   if (!cellpixbuf->pixbuf)
529     {
530       if (priv->stock_id)
531         gtk_cell_renderer_pixbuf_create_stock_pixbuf (cellpixbuf, widget);
532       else if (priv->icon_name)
533         gtk_cell_renderer_pixbuf_create_named_icon_pixbuf (cellpixbuf, widget);
534     }
535   
536   if (cellpixbuf->pixbuf)
537     {
538       pixbuf_width  = gdk_pixbuf_get_width (cellpixbuf->pixbuf);
539       pixbuf_height = gdk_pixbuf_get_height (cellpixbuf->pixbuf);
540     }
541   if (cellpixbuf->pixbuf_expander_open)
542     {
543       pixbuf_width  = MAX (pixbuf_width, gdk_pixbuf_get_width (cellpixbuf->pixbuf_expander_open));
544       pixbuf_height = MAX (pixbuf_height, gdk_pixbuf_get_height (cellpixbuf->pixbuf_expander_open));
545     }
546   if (cellpixbuf->pixbuf_expander_closed)
547     {
548       pixbuf_width  = MAX (pixbuf_width, gdk_pixbuf_get_width (cellpixbuf->pixbuf_expander_closed));
549       pixbuf_height = MAX (pixbuf_height, gdk_pixbuf_get_height (cellpixbuf->pixbuf_expander_closed));
550     }
551   
552   calc_width  = (gint) cell->xpad * 2 + pixbuf_width;
553   calc_height = (gint) cell->ypad * 2 + pixbuf_height;
554   
555   if (x_offset) *x_offset = 0;
556   if (y_offset) *y_offset = 0;
557
558   if (cell_area && pixbuf_width > 0 && pixbuf_height > 0)
559     {
560       if (x_offset)
561         {
562           *x_offset = (((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ?
563                         1.0 - cell->xalign : cell->xalign) * 
564                        (cell_area->width - calc_width - 2 * cell->xpad));
565           *x_offset = MAX (*x_offset, 0) + cell->xpad;
566         }
567       if (y_offset)
568         {
569           *y_offset = (cell->yalign *
570                        (cell_area->height - calc_height - 2 * cell->ypad));
571           *y_offset = MAX (*y_offset, 0) + cell->ypad;
572         }
573     }
574
575   if (width)
576     *width = calc_width;
577   
578   if (height)
579     *height = calc_height;
580 }
581
582 static void
583 gtk_cell_renderer_pixbuf_render (GtkCellRenderer      *cell,
584                                  GdkWindow            *window,
585                                  GtkWidget            *widget,
586                                  GdkRectangle         *background_area,
587                                  GdkRectangle         *cell_area,
588                                  GdkRectangle         *expose_area,
589                                  GtkCellRendererState  flags)
590
591 {
592   GtkCellRendererPixbuf *cellpixbuf = (GtkCellRendererPixbuf *) cell;
593   GtkCellRendererPixbufPrivate *priv;
594   GdkPixbuf *pixbuf;
595   GdkPixbuf *invisible = NULL;
596   GdkPixbuf *colorized = NULL;
597   GdkRectangle pix_rect;
598   GdkRectangle draw_rect;
599   cairo_t *cr;
600
601   priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (cell);
602
603   gtk_cell_renderer_pixbuf_get_size (cell, widget, cell_area,
604                                      &pix_rect.x,
605                                      &pix_rect.y,
606                                      &pix_rect.width,
607                                      &pix_rect.height);
608
609   pix_rect.x += cell_area->x;
610   pix_rect.y += cell_area->y;
611   pix_rect.width  -= cell->xpad * 2;
612   pix_rect.height -= cell->ypad * 2;
613
614   if (!gdk_rectangle_intersect (cell_area, &pix_rect, &draw_rect) ||
615       !gdk_rectangle_intersect (expose_area, &draw_rect, &draw_rect))
616     return;
617
618   pixbuf = cellpixbuf->pixbuf;
619
620   if (cell->is_expander)
621     {
622       if (cell->is_expanded &&
623           cellpixbuf->pixbuf_expander_open != NULL)
624         pixbuf = cellpixbuf->pixbuf_expander_open;
625       else if (!cell->is_expanded &&
626                cellpixbuf->pixbuf_expander_closed != NULL)
627         pixbuf = cellpixbuf->pixbuf_expander_closed;
628     }
629
630   if (!pixbuf)
631     return;
632
633   if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE || !cell->sensitive)
634     {
635       GtkIconSource *source;
636       
637       source = gtk_icon_source_new ();
638       gtk_icon_source_set_pixbuf (source, pixbuf);
639       /* The size here is arbitrary; since size isn't
640        * wildcarded in the source, it isn't supposed to be
641        * scaled by the engine function
642        */
643       gtk_icon_source_set_size (source, GTK_ICON_SIZE_SMALL_TOOLBAR);
644       gtk_icon_source_set_size_wildcarded (source, FALSE);
645       
646      invisible = gtk_style_render_icon (widget->style,
647                                         source,
648                                         gtk_widget_get_direction (widget),
649                                         GTK_STATE_INSENSITIVE,
650                                         /* arbitrary */
651                                         (GtkIconSize)-1,
652                                         widget,
653                                         "gtkcellrendererpixbuf");
654      
655      gtk_icon_source_free (source);
656      
657      pixbuf = invisible;
658     }
659   else if (priv->follow_state && 
660            (flags & (GTK_CELL_RENDERER_SELECTED|GTK_CELL_RENDERER_PRELIT)) != 0)
661     {
662       GtkStateType state;
663
664       if ((flags & GTK_CELL_RENDERER_SELECTED) != 0)
665         {
666           if (GTK_WIDGET_HAS_FOCUS (widget))
667             state = GTK_STATE_SELECTED;
668           else
669             state = GTK_STATE_ACTIVE;
670         }
671       else
672         state = GTK_STATE_PRELIGHT;
673
674       colorized = create_colorized_pixbuf (pixbuf,
675                                            &widget->style->base[state]);
676
677       pixbuf = colorized;
678     }
679
680   cr = gdk_cairo_create (window);
681   
682   gdk_cairo_set_source_pixbuf (cr, pixbuf, pix_rect.x, pix_rect.y);
683   gdk_cairo_rectangle (cr, &draw_rect);
684   cairo_fill (cr);
685
686   cairo_destroy (cr);
687   
688   if (invisible)
689     g_object_unref (invisible);
690
691   if (colorized)
692     g_object_unref (colorized);
693 }
694
695 #define __GTK_CELL_RENDERER_PIXBUF_C__
696 #include "gtkaliasdef.c"