gtkcellrendererpixbuf.c 19.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* gtkcellrendererpixbuf.c
 * Copyright (C) 2000  Red Hat, Inc.,  Jonathan Blandford <jrb@redhat.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
Javier Jardón's avatar
Javier Jardón committed
15
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 17
 */

18
#include "config.h"
19
#include <stdlib.h>
20
#include <cairo-gobject.h>
21
#include "gtkcellrendererpixbuf.h"
22
#include "deprecated/gtkiconfactory.h"
23
#include "gtkiconhelperprivate.h"
24
#include "gtkicontheme.h"
25
#include "gtkintl.h"
26
#include "gtkprivate.h"
27
#include "gtkstylecontextprivate.h"
28
#include "a11y/gtkimagecellaccessible.h"
29

30

31 32 33 34 35 36 37
/**
 * SECTION:gtkcellrendererpixbuf
 * @Short_description: Renders a pixbuf in a cell
 * @Title: GtkCellRendererPixbuf
 *
 * A #GtkCellRendererPixbuf can be used to render an image in a cell. It allows
 * to render either a given #GdkPixbuf (set via the
38 39
 * #GtkCellRendererPixbuf:pixbuf property) or a named icon (set via the
 * #GtkCellRendererPixbuf:icon-name property).
40 41 42 43 44 45 46 47 48 49 50
 *
 * To support the tree view, #GtkCellRendererPixbuf also supports rendering two
 * alternative pixbufs, when the #GtkCellRenderer:is-expander property is %TRUE.
 * If the #GtkCellRenderer:is-expanded property is %TRUE and the
 * #GtkCellRendererPixbuf:pixbuf-expander-open property is set to a pixbuf, it
 * renders that pixbuf, if the #GtkCellRenderer:is-expanded property is %FALSE
 * and the #GtkCellRendererPixbuf:pixbuf-expander-closed property is set to a
 * pixbuf, it renders that one.
 */


51 52 53
static void gtk_cell_renderer_pixbuf_get_property  (GObject                    *object,
						    guint                       param_id,
						    GValue                     *value,
Tim Janik's avatar
Tim Janik committed
54
						    GParamSpec                 *pspec);
55 56 57
static void gtk_cell_renderer_pixbuf_set_property  (GObject                    *object,
						    guint                       param_id,
						    const GValue               *value,
Tim Janik's avatar
Tim Janik committed
58
						    GParamSpec                 *pspec);
59 60
static void gtk_cell_renderer_pixbuf_get_size   (GtkCellRenderer            *cell,
						 GtkWidget                  *widget,
61
						 const GdkRectangle         *rectangle,
62 63
						 gint                       *x_offset,
						 gint                       *y_offset,
64 65 66
						 gint                       *width,
						 gint                       *height);
static void gtk_cell_renderer_pixbuf_render     (GtkCellRenderer            *cell,
67
						 cairo_t                    *cr,
68
						 GtkWidget                  *widget,
69 70
						 const GdkRectangle         *background_area,
						 const GdkRectangle         *cell_area,
71
						 GtkCellRendererState        flags);
72 73 74


enum {
75 76 77 78
  PROP_0,
  PROP_PIXBUF,
  PROP_PIXBUF_EXPANDER_OPEN,
  PROP_PIXBUF_EXPANDER_CLOSED,
79
  PROP_SURFACE,
80 81 82 83
  PROP_STOCK_ID,
  PROP_STOCK_SIZE,
  PROP_STOCK_DETAIL,
  PROP_FOLLOW_STATE,
Matthias Clasen's avatar
Matthias Clasen committed
84 85
  PROP_ICON_NAME,
  PROP_GICON
86 87
};

88

89
struct _GtkCellRendererPixbufPrivate
90
{
91 92
  GtkImageDefinition *image_def;
  GtkIconSize         icon_size;
93

94 95 96
  GdkPixbuf *pixbuf_expander_open;
  GdkPixbuf *pixbuf_expander_closed;

97
  gboolean follow_state;
98 99

  gchar *stock_detail;
100
};
101

102
G_DEFINE_TYPE_WITH_PRIVATE (GtkCellRendererPixbuf, gtk_cell_renderer_pixbuf, GTK_TYPE_CELL_RENDERER)
103

104 105 106
static void
gtk_cell_renderer_pixbuf_init (GtkCellRendererPixbuf *cellpixbuf)
{
107
  GtkCellRendererPixbufPrivate *priv;
108

109
  cellpixbuf->priv = gtk_cell_renderer_pixbuf_get_instance_private (cellpixbuf);
110
  priv = cellpixbuf->priv;
111

112
  priv->image_def = gtk_image_definition_new_empty ();
113
  priv->icon_size = GTK_ICON_SIZE_MENU;
114
  priv->follow_state = TRUE;
115 116 117 118 119 120 121
}

static void
gtk_cell_renderer_pixbuf_finalize (GObject *object)
{
  GtkCellRendererPixbuf *cellpixbuf = GTK_CELL_RENDERER_PIXBUF (object);
  GtkCellRendererPixbufPrivate *priv = cellpixbuf->priv;
122

123
  gtk_image_definition_unref (priv->image_def);
124 125 126 127 128 129 130 131 132

  if (priv->pixbuf_expander_open)
    g_object_unref (priv->pixbuf_expander_open);
  if (priv->pixbuf_expander_closed)
    g_object_unref (priv->pixbuf_expander_closed);

  g_free (priv->stock_detail);

  G_OBJECT_CLASS (gtk_cell_renderer_pixbuf_parent_class)->finalize (object);
133 134 135 136 137
}

static void
gtk_cell_renderer_pixbuf_class_init (GtkCellRendererPixbufClass *class)
{
Manish Singh's avatar
Manish Singh committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151
  GObjectClass *object_class = G_OBJECT_CLASS (class);
  GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);

  object_class->finalize = gtk_cell_renderer_pixbuf_finalize;

  object_class->get_property = gtk_cell_renderer_pixbuf_get_property;
  object_class->set_property = gtk_cell_renderer_pixbuf_set_property;

  cell_class->get_size = gtk_cell_renderer_pixbuf_get_size;
  cell_class->render = gtk_cell_renderer_pixbuf_render;

  g_object_class_install_property (object_class,
				   PROP_PIXBUF,
				   g_param_spec_object ("pixbuf",
152 153
							P_("Pixbuf Object"),
							P_("The pixbuf to render"),
Manish Singh's avatar
Manish Singh committed
154
							GDK_TYPE_PIXBUF,
155
							GTK_PARAM_READWRITE));
Manish Singh's avatar
Manish Singh committed
156 157 158

  g_object_class_install_property (object_class,
				   PROP_PIXBUF_EXPANDER_OPEN,
159
				   g_param_spec_object ("pixbuf-expander-open",
160 161
							P_("Pixbuf Expander Open"),
							P_("Pixbuf for open expander"),
Manish Singh's avatar
Manish Singh committed
162
							GDK_TYPE_PIXBUF,
163
							GTK_PARAM_READWRITE));
Manish Singh's avatar
Manish Singh committed
164 165 166

  g_object_class_install_property (object_class,
				   PROP_PIXBUF_EXPANDER_CLOSED,
167
				   g_param_spec_object ("pixbuf-expander-closed",
168 169
							P_("Pixbuf Expander Closed"),
							P_("Pixbuf for closed expander"),
Manish Singh's avatar
Manish Singh committed
170
							GDK_TYPE_PIXBUF,
171
							GTK_PARAM_READWRITE));
172 173 174 175 176
  /**
   * GtkCellRendererPixbuf:surface:
   *
   * Since: 3.10
   */
177 178 179 180 181 182 183
  g_object_class_install_property (object_class,
				   PROP_SURFACE,
				   g_param_spec_boxed ("surface",
						       P_("surface"),
						       P_("The surface to render"),
						       CAIRO_GOBJECT_TYPE_SURFACE,
						       GTK_PARAM_READWRITE));
Manish Singh's avatar
Manish Singh committed
184

185 186 187 188 189
  /**
   * GtkCellRendererPixbuf:stock-id:
   *
   * Deprecated: 3.10: Use #GtkCellRendererPixbuf:icon-name instead.
   */
Manish Singh's avatar
Manish Singh committed
190 191
  g_object_class_install_property (object_class,
				   PROP_STOCK_ID,
192
				   g_param_spec_string ("stock-id",
193 194
							P_("Stock ID"),
							P_("The stock ID of the stock icon to render"),
Manish Singh's avatar
Manish Singh committed
195
							NULL,
196
							GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
Manish Singh's avatar
Manish Singh committed
197 198 199

  g_object_class_install_property (object_class,
				   PROP_STOCK_SIZE,
200
				   g_param_spec_uint ("stock-size",
201
						      P_("Size"),
202 203 204
						      P_("The GtkIconSize value that specifies the size of the rendered icon"),
						      0,
						      G_MAXUINT,
Manish Singh's avatar
Manish Singh committed
205
						      GTK_ICON_SIZE_MENU,
206
						      GTK_PARAM_READWRITE));
Manish Singh's avatar
Manish Singh committed
207 208 209

  g_object_class_install_property (object_class,
				   PROP_STOCK_DETAIL,
210
				   g_param_spec_string ("stock-detail",
211 212
							P_("Detail"),
							P_("Render detail to pass to the theme engine"),
Manish Singh's avatar
Manish Singh committed
213
							NULL,
214
							GTK_PARAM_READWRITE));
215

216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
  
  /**
   * GtkCellRendererPixbuf:icon-name:
   *
   * The name of the themed icon to display.
   * This property only has an effect if not overridden by "stock_id" 
   * or "pixbuf" properties.
   *
   * Since: 2.8 
   */
  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));

234 235 236 237 238 239 240
  /**
   * GtkCellRendererPixbuf:follow-state:
   *
   * Specifies whether the rendered pixbuf should be colorized
   * according to the #GtkCellRendererState.
   *
   * Since: 2.8
241 242
   *
   * Deprecated: 3.16: Cell renderers always follow state.
243 244 245
   */
  g_object_class_install_property (object_class,
				   PROP_FOLLOW_STATE,
246
				   g_param_spec_boolean ("follow-state",
247 248 249
 							 P_("Follow State"),
 							 P_("Whether the rendered pixbuf should be "
							    "colorized according to the state"),
250 251
 							 TRUE,
 							 GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
252

Matthias Clasen's avatar
Matthias Clasen committed
253 254 255 256 257 258 259
  /**
   * GtkCellRendererPixbuf:gicon:
   *
   * The GIcon representing the icon to display.
   * If the icon theme is changed, the image will be updated
   * automatically.
   *
260
   * Since: 2.14
Matthias Clasen's avatar
Matthias Clasen committed
261 262 263 264 265 266 267 268 269 270
   */
  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));


271

272
  gtk_cell_renderer_class_set_accessible_type (cell_class, GTK_TYPE_IMAGE_CELL_ACCESSIBLE);
273 274
}

275
static void
276 277 278
gtk_cell_renderer_pixbuf_get_property (GObject        *object,
				       guint           param_id,
				       GValue         *value,
Tim Janik's avatar
Tim Janik committed
279
				       GParamSpec     *pspec)
280
{
281
  GtkCellRendererPixbuf *cellpixbuf = GTK_CELL_RENDERER_PIXBUF (object);
282
  GtkCellRendererPixbufPrivate *priv = cellpixbuf->priv;
283

284 285 286
  switch (param_id)
    {
    case PROP_PIXBUF:
287
      g_value_set_object (value, gtk_image_definition_get_pixbuf (priv->image_def));
288
      break;
289
    case PROP_PIXBUF_EXPANDER_OPEN:
290
      g_value_set_object (value, priv->pixbuf_expander_open);
291 292
      break;
    case PROP_PIXBUF_EXPANDER_CLOSED:
293
      g_value_set_object (value, priv->pixbuf_expander_closed);
294
      break;
295
    case PROP_SURFACE:
296
      g_value_set_boxed (value, gtk_image_definition_get_surface (priv->image_def));
297
      break;
298
    case PROP_STOCK_ID:
299
      g_value_set_string (value, gtk_image_definition_get_stock (priv->image_def));
300 301
      break;
    case PROP_STOCK_SIZE:
302
      g_value_set_uint (value, priv->icon_size);
303 304
      break;
    case PROP_STOCK_DETAIL:
305
      g_value_set_string (value, priv->stock_detail);
306
      break;
307 308 309
    case PROP_FOLLOW_STATE:
      g_value_set_boolean (value, priv->follow_state);
      break;
310
    case PROP_ICON_NAME:
311
      g_value_set_string (value, gtk_image_definition_get_icon_name (priv->image_def));
312
      break;
Matthias Clasen's avatar
Matthias Clasen committed
313
    case PROP_GICON:
314
      g_value_set_object (value, gtk_image_definition_get_gicon (priv->image_def));
Matthias Clasen's avatar
Matthias Clasen committed
315
      break;
316 317 318 319
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
      break;
    }
320 321
}

322
static void
323 324
notify_storage_type (GtkCellRendererPixbuf *cellpixbuf,
                     GtkImageType           storage_type)
325
{
326
  switch (storage_type)
327
    {
328 329 330
    case GTK_IMAGE_SURFACE:
      g_object_notify (G_OBJECT (cellpixbuf), "surface");
      break;
331 332 333 334
    case GTK_IMAGE_PIXBUF:
      g_object_notify (G_OBJECT (cellpixbuf), "pixbuf");
      break;
    case GTK_IMAGE_STOCK:
335
      g_object_notify (G_OBJECT (cellpixbuf), "stock-id");
336 337 338 339 340 341 342 343
      break;
    case GTK_IMAGE_ICON_NAME:
      g_object_notify (G_OBJECT (cellpixbuf), "icon-name");
      break;
    case GTK_IMAGE_GICON:
      g_object_notify (G_OBJECT (cellpixbuf), "gicon");
      break;
    default:
344 345 346
    case GTK_IMAGE_ANIMATION:
      g_assert_not_reached ();
    case GTK_IMAGE_EMPTY:
347 348 349 350
      break;
    }
}

351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
static void
take_image_definition (GtkCellRendererPixbuf *cellpixbuf,
                       GtkImageDefinition    *def)
{
  GtkCellRendererPixbufPrivate *priv;
  GtkImageType old_storage_type, new_storage_type;
  
  if (def == NULL)
    def = gtk_image_definition_new_empty ();

  priv = cellpixbuf->priv;
  old_storage_type = gtk_image_definition_get_storage_type (priv->image_def);
  new_storage_type = gtk_image_definition_get_storage_type (def);
 
  if (new_storage_type != old_storage_type)
    notify_storage_type (cellpixbuf, old_storage_type);

  gtk_image_definition_unref (priv->image_def);
  priv->image_def = def;
}

372
static void
373 374 375
gtk_cell_renderer_pixbuf_set_property (GObject      *object,
				       guint         param_id,
				       const GValue *value,
Tim Janik's avatar
Tim Janik committed
376
				       GParamSpec   *pspec)
377
{
378
  GtkCellRendererPixbuf *cellpixbuf = GTK_CELL_RENDERER_PIXBUF (object);
379
  GtkCellRendererPixbufPrivate *priv = cellpixbuf->priv;
380

381 382 383
  switch (param_id)
    {
    case PROP_PIXBUF:
384
      take_image_definition (cellpixbuf, gtk_image_definition_new_pixbuf (g_value_get_object (value), 1));
385
      break;
386
    case PROP_PIXBUF_EXPANDER_OPEN:
387 388 389
      if (priv->pixbuf_expander_open)
        g_object_unref (priv->pixbuf_expander_open);
      priv->pixbuf_expander_open = (GdkPixbuf*) g_value_dup_object (value);
390 391
      break;
    case PROP_PIXBUF_EXPANDER_CLOSED:
392 393 394
      if (priv->pixbuf_expander_closed)
        g_object_unref (priv->pixbuf_expander_closed);
      priv->pixbuf_expander_closed = (GdkPixbuf*) g_value_dup_object (value);
395
      break;
396
    case PROP_SURFACE:
397
      take_image_definition (cellpixbuf, gtk_image_definition_new_surface (g_value_get_boxed (value)));
398
      break;
399
    case PROP_STOCK_ID:
400
      take_image_definition (cellpixbuf, gtk_image_definition_new_stock (g_value_get_string (value)));
401 402
      break;
    case PROP_STOCK_SIZE:
403
      priv->icon_size = g_value_get_uint (value);
404 405
      break;
    case PROP_STOCK_DETAIL:
406
      g_free (priv->stock_detail);
Michael Natterer's avatar
Michael Natterer committed
407
      priv->stock_detail = g_value_dup_string (value);
408
      break;
409
    case PROP_ICON_NAME:
410
      take_image_definition (cellpixbuf, gtk_image_definition_new_icon_name (g_value_get_string (value)));
411
      break;
412 413 414
    case PROP_FOLLOW_STATE:
      priv->follow_state = g_value_get_boolean (value);
      break;
Matthias Clasen's avatar
Matthias Clasen committed
415
    case PROP_GICON:
416
      take_image_definition (cellpixbuf, gtk_image_definition_new_gicon (g_value_get_object (value)));
Matthias Clasen's avatar
Matthias Clasen committed
417
      break;
418 419 420 421
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
      break;
    }
422 423
}

424 425 426 427 428 429 430
/**
 * gtk_cell_renderer_pixbuf_new:
 * 
 * Creates a new #GtkCellRendererPixbuf. Adjust rendering
 * parameters using object properties. Object properties can be set
 * globally (with g_object_set()). Also, with #GtkTreeViewColumn, you
 * can bind a property to a value in a #GtkTreeModel. For example, you
431
 * can bind the “pixbuf” property on the cell renderer to a pixbuf value
432 433 434
 * in the model, thus rendering a different image in each row of the
 * #GtkTreeView.
 * 
435
 * Returns: the new cell renderer
436
 **/
437 438 439
GtkCellRenderer *
gtk_cell_renderer_pixbuf_new (void)
{
Manish Singh's avatar
Manish Singh committed
440
  return g_object_new (GTK_TYPE_CELL_RENDERER_PIXBUF, NULL);
441 442
}

443
static GtkIconHelper *
444 445
create_icon_helper (GtkCellRendererPixbuf *cellpixbuf,
                    GtkWidget             *widget)
446 447 448 449
{
  GtkCellRendererPixbufPrivate *priv = cellpixbuf->priv;
  GtkIconHelper *helper;

450
  helper = gtk_icon_helper_new (gtk_style_context_get_node (gtk_widget_get_style_context (widget)), widget);
451 452
  _gtk_icon_helper_set_force_scale_pixbuf (helper, TRUE);
  _gtk_icon_helper_set_definition (helper, priv->image_def);
453 454
  if (gtk_image_definition_get_storage_type (priv->image_def) != GTK_IMAGE_PIXBUF)
    _gtk_icon_helper_set_icon_size (helper, priv->icon_size);
455 456 457 458

  return helper;
}

459
static void
460 461 462 463 464 465 466
gtk_cell_renderer_pixbuf_get_size (GtkCellRenderer    *cell,
				   GtkWidget          *widget,
				   const GdkRectangle *cell_area,
				   gint               *x_offset,
				   gint               *y_offset,
				   gint               *width,
				   gint               *height)
467
{
468
  GtkCellRendererPixbuf *cellpixbuf = (GtkCellRendererPixbuf *) cell;
469
  GtkCellRendererPixbufPrivate *priv = cellpixbuf->priv;
470
  gint pixbuf_width  = 0;
471
  gint pixbuf_height = 0;
472 473
  gint calc_width;
  gint calc_height;
474
  gint xpad, ypad;
475
  GtkStyleContext *context;
476
  GtkIconHelper *icon_helper;
477 478 479 480

  context = gtk_widget_get_style_context (widget);
  gtk_style_context_save (context);
  gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
481
  icon_helper = create_icon_helper (cellpixbuf, widget);
482

483 484
  if (!_gtk_icon_helper_get_is_empty (icon_helper))
    _gtk_icon_helper_get_size (icon_helper, 
485 486
                               &pixbuf_width, &pixbuf_height);

487
  g_object_unref (icon_helper);
488 489
  gtk_style_context_restore (context);

490
  if (priv->pixbuf_expander_open)
491
    {
492 493
      pixbuf_width  = MAX (pixbuf_width, gdk_pixbuf_get_width (priv->pixbuf_expander_open));
      pixbuf_height = MAX (pixbuf_height, gdk_pixbuf_get_height (priv->pixbuf_expander_open));
494
    }
495
  if (priv->pixbuf_expander_closed)
496
    {
497 498
      pixbuf_width  = MAX (pixbuf_width, gdk_pixbuf_get_width (priv->pixbuf_expander_closed));
      pixbuf_height = MAX (pixbuf_height, gdk_pixbuf_get_height (priv->pixbuf_expander_closed));
499
    }
500 501 502 503

  gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
  calc_width  = (gint) xpad * 2 + pixbuf_width;
  calc_height = (gint) ypad * 2 + pixbuf_height;
504
  
505
  if (cell_area && pixbuf_width > 0 && pixbuf_height > 0)
506
    {
507 508 509
      gfloat xalign, yalign;

      gtk_cell_renderer_get_alignment (cell, &xalign, &yalign);
510 511
      if (x_offset)
	{
512
	  *x_offset = (((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ?
513
                        (1.0 - xalign) : xalign) *
514 515
                       (cell_area->width - calc_width));
	  *x_offset = MAX (*x_offset, 0);
516 517 518
	}
      if (y_offset)
	{
519
	  *y_offset = (yalign *
520 521
                       (cell_area->height - calc_height));
          *y_offset = MAX (*y_offset, 0);
522 523
	}
    }
524 525 526 527 528
  else
    {
      if (x_offset) *x_offset = 0;
      if (y_offset) *y_offset = 0;
    }
529

530
  if (width)
531
    *width = calc_width;
532 533
  
  if (height)
534
    *height = calc_height;
535 536 537
}

static void
538
gtk_cell_renderer_pixbuf_render (GtkCellRenderer      *cell,
539
                                 cairo_t              *cr,
540
				 GtkWidget            *widget,
541 542
				 const GdkRectangle   *background_area,
				 const GdkRectangle   *cell_area,
543
				 GtkCellRendererState  flags)
544 545

{
546
  GtkCellRendererPixbuf *cellpixbuf = (GtkCellRendererPixbuf *) cell;
547
  GtkCellRendererPixbufPrivate *priv = cellpixbuf->priv;
548
  GtkStyleContext *context;
549 550
  GdkRectangle pix_rect;
  GdkRectangle draw_rect;
551 552
  gboolean is_expander;
  gint xpad, ypad;
553
  GtkIconHelper *icon_helper = NULL;
554

555
  gtk_cell_renderer_pixbuf_get_size (cell, widget, (GdkRectangle *) cell_area,
556 557 558 559
				     &pix_rect.x, 
                                     &pix_rect.y,
                                     &pix_rect.width,
                                     &pix_rect.height);
560

561
  gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
562 563 564 565
  pix_rect.x += cell_area->x + xpad;
  pix_rect.y += cell_area->y + ypad;
  pix_rect.width -= xpad * 2;
  pix_rect.height -= ypad * 2;
566

567
  if (!gdk_rectangle_intersect (cell_area, &pix_rect, &draw_rect))
568 569
    return;

570
  context = gtk_widget_get_style_context (widget);
571 572
  gtk_style_context_save (context);

573
  gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
574 575 576

  g_object_get (cell, "is-expander", &is_expander, NULL);
  if (is_expander)
577
    {
578
      gboolean is_expanded;
579

580
      g_object_get (cell, "is-expanded", &is_expanded, NULL);
581

582 583
      if (is_expanded && priv->pixbuf_expander_open != NULL)
        {
584
          icon_helper = gtk_icon_helper_new (gtk_style_context_get_node (context), widget);
585 586 587 588
          _gtk_icon_helper_set_pixbuf (icon_helper, priv->pixbuf_expander_open);
        }
      else if (!is_expanded && priv->pixbuf_expander_closed != NULL)
        {
589
          icon_helper = gtk_icon_helper_new (gtk_style_context_get_node (context), widget);
590 591 592
          _gtk_icon_helper_set_pixbuf (icon_helper, priv->pixbuf_expander_closed);
        }
    }
593

594
  if (icon_helper == NULL)
595
    icon_helper = create_icon_helper (cellpixbuf, widget);
596 597

  _gtk_icon_helper_draw (icon_helper,
598
                         cr,
599 600
                         pix_rect.x, pix_rect.y);
  g_object_unref (icon_helper);
601

602
  gtk_style_context_restore (context);
603
}