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