gtkcellrendererpixbuf.c 18.3 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 "a11y/gtkimagecellaccessible.h"
28

29

30 31 32 33 34 35 36
/**
 * 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
37 38
 * #GtkCellRendererPixbuf:pixbuf property) or a named icon (set via the
 * #GtkCellRendererPixbuf:icon-name property).
39 40 41 42 43 44 45 46 47 48 49
 *
 * 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.
 */


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


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

87

88
struct _GtkCellRendererPixbufPrivate
89
{
90
  GtkIconHelper *icon_helper;
91
  GtkIconSize    icon_size;
92

93 94 95
  GdkPixbuf *pixbuf_expander_open;
  GdkPixbuf *pixbuf_expander_closed;

96
  gboolean follow_state;
97 98

  gchar *stock_detail;
99
};
100

101
G_DEFINE_TYPE_WITH_PRIVATE (GtkCellRendererPixbuf, gtk_cell_renderer_pixbuf, GTK_TYPE_CELL_RENDERER)
102

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

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

111
  priv->icon_helper = _gtk_icon_helper_new ();
112
  _gtk_icon_helper_set_force_scale_pixbuf (priv->icon_helper, TRUE);
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 124 125 126 127 128 129 130 131 132
  g_clear_object (&priv->icon_helper);

  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_icon_helper_peek_pixbuf (priv->icon_helper));
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 296 297
    case PROP_SURFACE:
      g_value_set_boxed (value, _gtk_icon_helper_peek_surface (priv->icon_helper));
      break;
298
    case PROP_STOCK_ID:
299
      g_value_set_string (value, _gtk_icon_helper_get_stock_id (priv->icon_helper));
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_icon_helper_get_icon_name (priv->icon_helper));
312
      break;
Matthias Clasen's avatar
Matthias Clasen committed
313
    case PROP_GICON:
314
      g_value_set_object (value, _gtk_icon_helper_peek_gicon (priv->icon_helper));
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 323 324 325 326 327 328 329
static void
gtk_cell_renderer_pixbuf_reset (GtkCellRendererPixbuf *cellpixbuf)
{
  GtkCellRendererPixbufPrivate *priv = cellpixbuf->priv;
  GtkImageType storage_type = _gtk_icon_helper_get_storage_type (priv->icon_helper);

  switch (storage_type)
    {
330 331 332
    case GTK_IMAGE_SURFACE:
      g_object_notify (G_OBJECT (cellpixbuf), "surface");
      break;
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
    case GTK_IMAGE_PIXBUF:
      g_object_notify (G_OBJECT (cellpixbuf), "pixbuf");
      break;
    case GTK_IMAGE_STOCK:
      g_object_notify (G_OBJECT (cellpixbuf), "stock-id");      
      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;
    case GTK_IMAGE_EMPTY:
    default:
      break;
    }

  _gtk_icon_helper_clear (priv->icon_helper);
}

353
static void
354 355 356
gtk_cell_renderer_pixbuf_set_property (GObject      *object,
				       guint         param_id,
				       const GValue *value,
Tim Janik's avatar
Tim Janik committed
357
				       GParamSpec   *pspec)
358
{
359
  GtkCellRendererPixbuf *cellpixbuf = GTK_CELL_RENDERER_PIXBUF (object);
360
  GtkCellRendererPixbufPrivate *priv = cellpixbuf->priv;
361

362 363 364
  switch (param_id)
    {
    case PROP_PIXBUF:
365 366
      gtk_cell_renderer_pixbuf_reset (cellpixbuf);
      _gtk_icon_helper_set_pixbuf (priv->icon_helper, g_value_get_object (value));
367
      break;
368
    case PROP_PIXBUF_EXPANDER_OPEN:
369 370 371
      if (priv->pixbuf_expander_open)
        g_object_unref (priv->pixbuf_expander_open);
      priv->pixbuf_expander_open = (GdkPixbuf*) g_value_dup_object (value);
372 373
      break;
    case PROP_PIXBUF_EXPANDER_CLOSED:
374 375 376
      if (priv->pixbuf_expander_closed)
        g_object_unref (priv->pixbuf_expander_closed);
      priv->pixbuf_expander_closed = (GdkPixbuf*) g_value_dup_object (value);
377
      break;
378 379 380 381
    case PROP_SURFACE:
      gtk_cell_renderer_pixbuf_reset (cellpixbuf);
      _gtk_icon_helper_set_surface (priv->icon_helper, g_value_get_boxed (value));
      break;
382
    case PROP_STOCK_ID:
383
      gtk_cell_renderer_pixbuf_reset (cellpixbuf);
384
      _gtk_icon_helper_set_stock_id (priv->icon_helper, g_value_get_string (value), priv->icon_size);
385 386
      break;
    case PROP_STOCK_SIZE:
387 388
      priv->icon_size = g_value_get_uint (value);
      _gtk_icon_helper_set_icon_size (priv->icon_helper, priv->icon_size);
389 390
      break;
    case PROP_STOCK_DETAIL:
391
      g_free (priv->stock_detail);
Michael Natterer's avatar
Michael Natterer committed
392
      priv->stock_detail = g_value_dup_string (value);
393
      break;
394
    case PROP_ICON_NAME:
395
      gtk_cell_renderer_pixbuf_reset (cellpixbuf);
396
      _gtk_icon_helper_set_icon_name (priv->icon_helper, g_value_get_string (value), priv->icon_size);
397
      break;
398 399 400
    case PROP_FOLLOW_STATE:
      priv->follow_state = g_value_get_boolean (value);
      break;
Matthias Clasen's avatar
Matthias Clasen committed
401
    case PROP_GICON:
402
      gtk_cell_renderer_pixbuf_reset (cellpixbuf);
403
      _gtk_icon_helper_set_gicon (priv->icon_helper, g_value_get_object (value), priv->icon_size);
Matthias Clasen's avatar
Matthias Clasen committed
404
      break;
405 406 407 408
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
      break;
    }
409 410
}

411 412 413 414 415 416 417
/**
 * 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
418
 * can bind the “pixbuf” property on the cell renderer to a pixbuf value
419 420 421
 * in the model, thus rendering a different image in each row of the
 * #GtkTreeView.
 * 
422
 * Returns: the new cell renderer
423
 **/
424 425 426
GtkCellRenderer *
gtk_cell_renderer_pixbuf_new (void)
{
Manish Singh's avatar
Manish Singh committed
427
  return g_object_new (GTK_TYPE_CELL_RENDERER_PIXBUF, NULL);
428 429 430
}

static void
431 432 433 434 435 436 437
gtk_cell_renderer_pixbuf_get_size (GtkCellRenderer    *cell,
				   GtkWidget          *widget,
				   const GdkRectangle *cell_area,
				   gint               *x_offset,
				   gint               *y_offset,
				   gint               *width,
				   gint               *height)
438
{
439
  GtkCellRendererPixbuf *cellpixbuf = (GtkCellRendererPixbuf *) cell;
440
  GtkCellRendererPixbufPrivate *priv = cellpixbuf->priv;
441
  gint pixbuf_width  = 0;
442
  gint pixbuf_height = 0;
443 444
  gint calc_width;
  gint calc_height;
445
  gint xpad, ypad;
446 447 448 449 450
  GtkStyleContext *context;

  context = gtk_widget_get_style_context (widget);
  gtk_style_context_save (context);
  gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
451

452 453 454 455 456
  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);

457 458
  gtk_style_context_restore (context);

459
  if (priv->pixbuf_expander_open)
460
    {
461 462
      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));
463
    }
464
  if (priv->pixbuf_expander_closed)
465
    {
466 467
      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));
468
    }
469 470 471 472

  gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
  calc_width  = (gint) xpad * 2 + pixbuf_width;
  calc_height = (gint) ypad * 2 + pixbuf_height;
473
  
474
  if (cell_area && pixbuf_width > 0 && pixbuf_height > 0)
475
    {
476 477 478
      gfloat xalign, yalign;

      gtk_cell_renderer_get_alignment (cell, &xalign, &yalign);
479 480
      if (x_offset)
	{
481
	  *x_offset = (((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ?
482
                        (1.0 - xalign) : xalign) *
483 484
                       (cell_area->width - calc_width));
	  *x_offset = MAX (*x_offset, 0);
485 486 487
	}
      if (y_offset)
	{
488
	  *y_offset = (yalign *
489 490
                       (cell_area->height - calc_height));
          *y_offset = MAX (*y_offset, 0);
491 492
	}
    }
493 494 495 496 497
  else
    {
      if (x_offset) *x_offset = 0;
      if (y_offset) *y_offset = 0;
    }
498

499
  if (width)
500
    *width = calc_width;
501 502
  
  if (height)
503
    *height = calc_height;
504 505 506
}

static void
507
gtk_cell_renderer_pixbuf_render (GtkCellRenderer      *cell,
508
                                 cairo_t              *cr,
509
				 GtkWidget            *widget,
510 511
				 const GdkRectangle   *background_area,
				 const GdkRectangle   *cell_area,
512
				 GtkCellRendererState  flags)
513 514

{
515
  GtkCellRendererPixbuf *cellpixbuf = (GtkCellRendererPixbuf *) cell;
516
  GtkCellRendererPixbufPrivate *priv = cellpixbuf->priv;
517
  GtkStyleContext *context;
518 519
  GdkRectangle pix_rect;
  GdkRectangle draw_rect;
520 521
  gboolean is_expander;
  gint xpad, ypad;
522
  GtkIconHelper *icon_helper = NULL;
523

524
  gtk_cell_renderer_pixbuf_get_size (cell, widget, (GdkRectangle *) cell_area,
525 526 527 528
				     &pix_rect.x, 
                                     &pix_rect.y,
                                     &pix_rect.width,
                                     &pix_rect.height);
529

530
  gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
531 532 533 534
  pix_rect.x += cell_area->x + xpad;
  pix_rect.y += cell_area->y + ypad;
  pix_rect.width -= xpad * 2;
  pix_rect.height -= ypad * 2;
535

536
  if (!gdk_rectangle_intersect (cell_area, &pix_rect, &draw_rect))
537 538
    return;

539
  context = gtk_widget_get_style_context (widget);
540 541
  gtk_style_context_save (context);

542
  gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
543 544 545

  g_object_get (cell, "is-expander", &is_expander, NULL);
  if (is_expander)
546
    {
547
      gboolean is_expanded;
548

549
      g_object_get (cell, "is-expanded", &is_expanded, NULL);
550

551 552 553 554 555 556 557 558 559 560 561
      if (is_expanded && priv->pixbuf_expander_open != NULL)
        {
          icon_helper = _gtk_icon_helper_new ();
          _gtk_icon_helper_set_pixbuf (icon_helper, priv->pixbuf_expander_open);
        }
      else if (!is_expanded && priv->pixbuf_expander_closed != NULL)
        {
          icon_helper = _gtk_icon_helper_new ();
          _gtk_icon_helper_set_pixbuf (icon_helper, priv->pixbuf_expander_closed);
        }
    }
562

563 564 565
  if (icon_helper == NULL)
    icon_helper = g_object_ref (priv->icon_helper);

566 567
  _gtk_icon_helper_set_window (icon_helper,
			       gtk_widget_get_window (widget));
568 569 570 571
  _gtk_icon_helper_draw (icon_helper,
                         context, cr,
                         pix_rect.x, pix_rect.y);
  g_object_unref (icon_helper);
572

573
  gtk_style_context_restore (context);
574
}