gtkcellrenderertoggle.c 18.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* gtkcellrenderertoggle.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>
Kristian Rietveld's avatar
Kristian Rietveld committed
20
#include "gtkcellrenderertoggle.h"
Havoc Pennington's avatar
Havoc Pennington committed
21
#include "gtkintl.h"
22
#include "gtkmarshalers.h"
23
#include "gtkprivate.h"
24
#include "gtkstylecontextprivate.h"
25
#include "gtktreeprivate.h"
26
#include "a11y/gtkbooleancellaccessible.h"
27

28

29 30 31 32 33 34 35 36 37 38 39 40
/**
 * SECTION:gtkcellrenderertoggle
 * @Short_description: Renders a toggle button in a cell
 * @Title: GtkCellRendererToggle
 *
 * #GtkCellRendererToggle renders a toggle button in a cell. The
 * button is drawn as a radio or a checkbutton, depending on the
 * #GtkCellRendererToggle:radio property.
 * When activated, it emits the #GtkCellRendererToggle::toggled signal.
 */


41 42 43
static void gtk_cell_renderer_toggle_get_property  (GObject                    *object,
						    guint                       param_id,
						    GValue                     *value,
Tim Janik's avatar
Tim Janik committed
44
						    GParamSpec                 *pspec);
45 46 47
static void gtk_cell_renderer_toggle_set_property  (GObject                    *object,
						    guint                       param_id,
						    const GValue               *value,
Tim Janik's avatar
Tim Janik committed
48
						    GParamSpec                 *pspec);
49 50
static void gtk_cell_renderer_toggle_get_size   (GtkCellRenderer            *cell,
						 GtkWidget                  *widget,
51
						 const GdkRectangle         *cell_area,
52 53
						 gint                       *x_offset,
						 gint                       *y_offset,
54 55 56
						 gint                       *width,
						 gint                       *height);
static void gtk_cell_renderer_toggle_render     (GtkCellRenderer            *cell,
57
						 cairo_t                    *cr,
58
						 GtkWidget                  *widget,
59 60
						 const GdkRectangle         *background_area,
						 const GdkRectangle         *cell_area,
61
						 GtkCellRendererState        flags);
62 63 64
static gboolean gtk_cell_renderer_toggle_activate  (GtkCellRenderer            *cell,
						    GdkEvent                   *event,
						    GtkWidget                  *widget,
65
						    const gchar                *path,
66 67
						    const GdkRectangle         *background_area,
						    const GdkRectangle         *cell_area,
68
						    GtkCellRendererState        flags);
69 70 71 72 73 74 75 76


enum {
  TOGGLED,
  LAST_SIGNAL
};

enum {
77
  PROP_0,
78
  PROP_ACTIVATABLE,
Havoc Pennington's avatar
Havoc Pennington committed
79
  PROP_ACTIVE,
80
  PROP_RADIO,
81 82
  PROP_INCONSISTENT,
  PROP_INDICATOR_SIZE
83 84
};

85
#define TOGGLE_WIDTH 16
86 87 88

static guint toggle_cell_signals[LAST_SIGNAL] = { 0 };

89
struct _GtkCellRendererTogglePrivate
90
{
91 92
  gint indicator_size;

93 94
  guint active       : 1;
  guint activatable  : 1;
95
  guint inconsistent : 1;
96
  guint radio        : 1;
97 98
};

99

100
G_DEFINE_TYPE_WITH_PRIVATE (GtkCellRendererToggle, gtk_cell_renderer_toggle, GTK_TYPE_CELL_RENDERER)
101

102

103 104 105
static void
gtk_cell_renderer_toggle_init (GtkCellRendererToggle *celltoggle)
{
106
  GtkCellRendererTogglePrivate *priv;
107

108
  celltoggle->priv = gtk_cell_renderer_toggle_get_instance_private (celltoggle);
109
  priv = celltoggle->priv;
110

111 112 113
  priv->activatable = TRUE;
  priv->active = FALSE;
  priv->radio = FALSE;
114

115 116
  g_object_set (celltoggle, "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL);
  gtk_cell_renderer_set_padding (GTK_CELL_RENDERER (celltoggle), 2, 2);
117

118
  priv->indicator_size = 0;
119
  priv->inconsistent = FALSE;
120 121 122 123 124 125 126 127
}

static void
gtk_cell_renderer_toggle_class_init (GtkCellRendererToggleClass *class)
{
  GObjectClass *object_class = G_OBJECT_CLASS (class);
  GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);

128 129
  object_class->get_property = gtk_cell_renderer_toggle_get_property;
  object_class->set_property = gtk_cell_renderer_toggle_set_property;
130 131 132

  cell_class->get_size = gtk_cell_renderer_toggle_get_size;
  cell_class->render = gtk_cell_renderer_toggle_render;
133
  cell_class->activate = gtk_cell_renderer_toggle_activate;
134 135
  
  g_object_class_install_property (object_class,
Havoc Pennington's avatar
Havoc Pennington committed
136 137
				   PROP_ACTIVE,
				   g_param_spec_boolean ("active",
138 139
							 P_("Toggle state"),
							 P_("The toggle state of the button"),
140
							 FALSE,
141
							 GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
142 143 144 145

  g_object_class_install_property (object_class,
		                   PROP_INCONSISTENT,
				   g_param_spec_boolean ("inconsistent",
146 147
					                 P_("Inconsistent state"),
							 P_("The inconsistent state of the button"),
148
							 FALSE,
149
							 GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
150
  
151 152 153
  g_object_class_install_property (object_class,
				   PROP_ACTIVATABLE,
				   g_param_spec_boolean ("activatable",
154 155
							 P_("Activatable"),
							 P_("The toggle button can be activated"),
156
							 TRUE,
157
							 GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
158

159 160 161
  g_object_class_install_property (object_class,
				   PROP_RADIO,
				   g_param_spec_boolean ("radio",
162 163
							 P_("Radio state"),
							 P_("Draw the toggle button as a radio button"),
164
							 FALSE,
165
							 GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
166

167 168 169 170 171 172 173
  g_object_class_install_property (object_class,
				   PROP_INDICATOR_SIZE,
				   g_param_spec_int ("indicator-size",
						     P_("Indicator size"),
						     P_("Size of check or radio indicator"),
						     0,
						     G_MAXINT,
174 175
						     0,
						     GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_DEPRECATED));
176

177 178 179 180 181 182 183 184
  
  /**
   * GtkCellRendererToggle::toggled:
   * @cell_renderer: the object which received the signal
   * @path: string representation of #GtkTreePath describing the 
   *        event location
   *
   * The ::toggled signal is emitted when the cell is toggled. 
185 186
   *
   * It is the responsibility of the application to update the model
187 188
   * with the correct value to store at @path.  Often this is simply the
   * opposite of the value currently stored at @path.
189
   **/
190
  toggle_cell_signals[TOGGLED] =
191
    g_signal_new (I_("toggled"),
Manish Singh's avatar
Manish Singh committed
192 193 194 195
		  G_OBJECT_CLASS_TYPE (object_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkCellRendererToggleClass, toggled),
		  NULL, NULL,
196
		  NULL,
Manish Singh's avatar
Manish Singh committed
197 198
		  G_TYPE_NONE, 1,
		  G_TYPE_STRING);
199

200
  gtk_cell_renderer_class_set_accessible_type (cell_class, GTK_TYPE_BOOLEAN_CELL_ACCESSIBLE);
201 202 203
}

static void
204 205 206
gtk_cell_renderer_toggle_get_property (GObject     *object,
				       guint        param_id,
				       GValue      *value,
Tim Janik's avatar
Tim Janik committed
207
				       GParamSpec  *pspec)
208 209
{
  GtkCellRendererToggle *celltoggle = GTK_CELL_RENDERER_TOGGLE (object);
210
  GtkCellRendererTogglePrivate *priv = celltoggle->priv;
211

212 213
  switch (param_id)
    {
Havoc Pennington's avatar
Havoc Pennington committed
214
    case PROP_ACTIVE:
215
      g_value_set_boolean (value, priv->active);
216
      break;
217
    case PROP_INCONSISTENT:
218
      g_value_set_boolean (value, priv->inconsistent);
219
      break;
220
    case PROP_ACTIVATABLE:
221
      g_value_set_boolean (value, priv->activatable);
222
      break;
223
    case PROP_RADIO:
224
      g_value_set_boolean (value, priv->radio);
225
      break;
226 227 228
    case PROP_INDICATOR_SIZE:
      g_value_set_int (value, priv->indicator_size);
      break;
229
    default:
230
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
231 232 233 234 235 236
      break;
    }
}


static void
237 238 239
gtk_cell_renderer_toggle_set_property (GObject      *object,
				       guint         param_id,
				       const GValue *value,
Tim Janik's avatar
Tim Janik committed
240
				       GParamSpec   *pspec)
241 242
{
  GtkCellRendererToggle *celltoggle = GTK_CELL_RENDERER_TOGGLE (object);
243
  GtkCellRendererTogglePrivate *priv = celltoggle->priv;
244

245 246
  switch (param_id)
    {
Havoc Pennington's avatar
Havoc Pennington committed
247
    case PROP_ACTIVE:
248 249 250 251 252
      if (priv->active != g_value_get_boolean (value))
        {
          priv->active = g_value_get_boolean (value);
          g_object_notify_by_pspec (object, pspec);
        }
253
      break;
254
    case PROP_INCONSISTENT:
255 256 257 258 259
      if (priv->inconsistent != g_value_get_boolean (value))
        {
          priv->inconsistent = g_value_get_boolean (value);
          g_object_notify_by_pspec (object, pspec);
        }
260
      break;
261
    case PROP_ACTIVATABLE:
262 263 264 265 266
      if (priv->activatable != g_value_get_boolean (value))
        {
          priv->activatable = g_value_get_boolean (value);
          g_object_notify_by_pspec (object, pspec);
        }
267
      break;
268
    case PROP_RADIO:
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
      if (priv->radio != g_value_get_boolean (value))
        {
          priv->radio = g_value_get_boolean (value);
          g_object_notify_by_pspec (object, pspec);
        }
      break;
    case PROP_INDICATOR_SIZE:
      if (priv->indicator_size != g_value_get_int (value))
        {
          priv->indicator_size = g_value_get_int (value);
          g_object_notify_by_pspec (object, pspec);
        }
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
      break;
    }
}

288 289
/**
 * gtk_cell_renderer_toggle_new:
290
 *
291 292 293 294
 * Creates a new #GtkCellRendererToggle. 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
295
 * can bind the “active” property on the cell renderer to a boolean value
296 297
 * in the model, thus causing the check button to reflect the state of
 * the model.
298
 *
299
 * Returns: the new cell renderer
300
 **/
301 302 303
GtkCellRenderer *
gtk_cell_renderer_toggle_new (void)
{
Manish Singh's avatar
Manish Singh committed
304
  return g_object_new (GTK_TYPE_CELL_RENDERER_TOGGLE, NULL);
305 306
}

307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
static GtkStyleContext *
gtk_cell_renderer_toggle_save_context (GtkCellRenderer *cell,
				       GtkWidget       *widget)
{
  GtkCellRendererTogglePrivate *priv = GTK_CELL_RENDERER_TOGGLE (cell)->priv;

  GtkStyleContext *context;

  context = gtk_widget_get_style_context (widget);

  if (priv->radio)
    gtk_style_context_save_named (context, "radio");
  else
    gtk_style_context_save_named (context, "check");

  return context;
}
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
 
static void
calc_indicator_size (GtkStyleContext *context,
                     gint             indicator_size,
                     gint            *width,
                     gint            *height)
{
  if (indicator_size != 0)
    {
      *width = *height = indicator_size;
      return;
    }

  gtk_style_context_get (context, gtk_style_context_get_state (context),
                         "min-width", width,
                         "min-height", height,
                         NULL);

  if (*width == 0)
    *width = TOGGLE_WIDTH;
  if (*height == 0)
    *height = TOGGLE_WIDTH;
}

348
static void
349 350 351 352 353 354 355
gtk_cell_renderer_toggle_get_size (GtkCellRenderer    *cell,
				   GtkWidget          *widget,
				   const GdkRectangle *cell_area,
				   gint               *x_offset,
				   gint               *y_offset,
				   gint               *width,
				   gint               *height)
356
{
357
  GtkCellRendererTogglePrivate *priv;
358 359
  gint calc_width;
  gint calc_height;
360
  gint xpad, ypad;
361 362
  GtkStyleContext *context;
  GtkBorder border, padding;
363

364
  priv = GTK_CELL_RENDERER_TOGGLE (cell)->priv;
365

366
  gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
367 368 369 370 371

  context = gtk_cell_renderer_toggle_save_context (cell, widget);
  gtk_style_context_get_padding (context, gtk_style_context_get_state (context), &padding);
  gtk_style_context_get_border (context, gtk_style_context_get_state (context), &border);

372 373 374
  calc_indicator_size (context, priv->indicator_size, &calc_width, &calc_height);
  calc_width += xpad * 2 + padding.left + padding.right + border.left + border.right;
  calc_height += ypad * 2 + padding.top + padding.bottom + border.top + border.bottom;
375 376

  gtk_style_context_restore (context);
377

378
  if (width)
379
    *width = calc_width;
380 381

  if (height)
382
    *height = calc_height;
383

384 385
  if (cell_area)
    {
386 387 388 389
      gfloat xalign, yalign;

      gtk_cell_renderer_get_alignment (cell, &xalign, &yalign);

390 391
      if (x_offset)
	{
Jonathan Blandford's avatar
Jonathan Blandford committed
392
	  *x_offset = ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ?
393
		       (1.0 - xalign) : xalign) * (cell_area->width - calc_width);
394
	  *x_offset = MAX (*x_offset, 0);
395 396 397
	}
      if (y_offset)
	{
398
	  *y_offset = yalign * (cell_area->height - calc_height);
399
	  *y_offset = MAX (*y_offset, 0);
400 401
	}
    }
402 403 404 405 406
  else
    {
      if (x_offset) *x_offset = 0;
      if (y_offset) *y_offset = 0;
    }
407 408 409
}

static void
410
gtk_cell_renderer_toggle_render (GtkCellRenderer      *cell,
411
				 cairo_t              *cr,
412
				 GtkWidget            *widget,
413 414
				 const GdkRectangle   *background_area,
				 const GdkRectangle   *cell_area,
415
				 GtkCellRendererState  flags)
416
{
417
  GtkCellRendererToggle *celltoggle = GTK_CELL_RENDERER_TOGGLE (cell);
418
  GtkCellRendererTogglePrivate *priv = celltoggle->priv;
419
  GtkStyleContext *context;
420
  gint width, height;
421
  gint x_offset, y_offset;
422
  gint xpad, ypad;
423
  GtkStateFlags state;
424
  GtkBorder padding, border;
425

426
  context = gtk_widget_get_style_context (widget);
427
  gtk_cell_renderer_toggle_get_size (cell, widget, cell_area,
428 429
				     &x_offset, &y_offset,
				     &width, &height);
430 431 432
  gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
  width -= xpad * 2;
  height -= ypad * 2;
433

434 435 436
  if (width <= 0 || height <= 0)
    return;

437 438
  state = gtk_cell_renderer_get_state (cell, widget, flags);

439
  if (!priv->activatable)
440 441
    state |= GTK_STATE_FLAG_INSENSITIVE;

442
  state &= ~(GTK_STATE_FLAG_INCONSISTENT | GTK_STATE_FLAG_CHECKED);
443

444 445
  if (priv->inconsistent)
    state |= GTK_STATE_FLAG_INCONSISTENT;
446 447
  
  if (priv->active)
448
    state |= GTK_STATE_FLAG_CHECKED;
449

450 451 452 453 454
  cairo_save (cr);

  gdk_cairo_rectangle (cr, cell_area);
  cairo_clip (cr);

455 456
  context = gtk_cell_renderer_toggle_save_context (cell, widget);
  gtk_style_context_set_state (context, state);
457

458
  gtk_render_background (context, cr,
459 460 461
                         cell_area->x + x_offset + xpad,
                         cell_area->y + y_offset + ypad,
                         width, height);
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
  gtk_render_frame (context, cr,
                    cell_area->x + x_offset + xpad,
                    cell_area->y + y_offset + ypad,
                    width, height);

  gtk_style_context_get_padding (context, gtk_style_context_get_state (context), &padding);
  gtk_style_context_get_border (context, gtk_style_context_get_state (context), &border);

  if (priv->radio)
    {
      gtk_render_option (context, cr,
                         cell_area->x + x_offset + xpad + padding.left + border.left,
                         cell_area->y + y_offset + ypad + padding.top + border.top,
                         width - padding.left - padding.right - border.left - border.right,
                         height - padding.top - padding.bottom - border.top - border.bottom);
477 478 479
    }
  else
    {
480
      gtk_render_check (context, cr,
481 482 483 484
                        cell_area->x + x_offset + xpad + padding.left + border.left,
                        cell_area->y + y_offset + ypad + padding.top + border.top,
                        width - padding.left - padding.right - border.left - border.right,
                        height - padding.top - padding.bottom - border.top - border.bottom);
485
    }
486

487
  gtk_style_context_restore (context);
488
  cairo_restore (cr);
489 490 491
}

static gint
492 493 494 495
gtk_cell_renderer_toggle_activate (GtkCellRenderer      *cell,
				   GdkEvent             *event,
				   GtkWidget            *widget,
				   const gchar          *path,
496 497
				   const GdkRectangle   *background_area,
				   const GdkRectangle   *cell_area,
498
				   GtkCellRendererState  flags)
499
{
500
  GtkCellRendererTogglePrivate *priv;
501
  GtkCellRendererToggle *celltoggle;
502

503
  celltoggle = GTK_CELL_RENDERER_TOGGLE (cell);
504 505 506
  priv = celltoggle->priv;

  if (priv->activatable)
507
    {
Manish Singh's avatar
Manish Singh committed
508
      g_signal_emit (cell, toggle_cell_signals[TOGGLED], 0, path);
509
      return TRUE;
510
    }
511 512

  return FALSE;
513 514
}

515 516 517 518 519 520 521 522 523 524 525 526 527
/**
 * gtk_cell_renderer_toggle_set_radio:
 * @toggle: a #GtkCellRendererToggle
 * @radio: %TRUE to make the toggle look like a radio button
 * 
 * If @radio is %TRUE, the cell renderer renders a radio toggle
 * (i.e. a toggle in a group of mutually-exclusive toggles).
 * If %FALSE, it renders a check toggle (a standalone boolean option).
 * This can be set globally for the cell renderer, or changed just
 * before rendering each cell in the model (for #GtkTreeView, you set
 * up a per-row setting using #GtkTreeViewColumn to associate model
 * columns with cell renderer properties).
 **/
528 529 530 531
void
gtk_cell_renderer_toggle_set_radio (GtkCellRendererToggle *toggle,
				    gboolean               radio)
{
532
  GtkCellRendererTogglePrivate *priv;
533

534 535
  g_return_if_fail (GTK_IS_CELL_RENDERER_TOGGLE (toggle));

536 537 538
  priv = toggle->priv;

  priv->radio = radio;
539
}
Havoc Pennington's avatar
Havoc Pennington committed
540

541 542 543
/**
 * gtk_cell_renderer_toggle_get_radio:
 * @toggle: a #GtkCellRendererToggle
Matthias Clasen's avatar
Matthias Clasen committed
544
 *
545
 * Returns whether we’re rendering radio toggles rather than checkboxes. 
546
 * 
547
 * Returns: %TRUE if we’re rendering radio toggles rather than checkboxes
548
 **/
Havoc Pennington's avatar
Havoc Pennington committed
549
gboolean
550
gtk_cell_renderer_toggle_get_radio (GtkCellRendererToggle *toggle)
Havoc Pennington's avatar
Havoc Pennington committed
551 552 553
{
  g_return_val_if_fail (GTK_IS_CELL_RENDERER_TOGGLE (toggle), FALSE);

554
  return toggle->priv->radio;
Havoc Pennington's avatar
Havoc Pennington committed
555
}
556

Matthias Clasen's avatar
Matthias Clasen committed
557 558
/**
 * gtk_cell_renderer_toggle_get_active:
559
 * @toggle: a #GtkCellRendererToggle
Matthias Clasen's avatar
Matthias Clasen committed
560 561 562 563
 *
 * Returns whether the cell renderer is active. See
 * gtk_cell_renderer_toggle_set_active().
 *
564
 * Returns: %TRUE if the cell renderer is active.
565
 **/
566 567 568 569 570
gboolean
gtk_cell_renderer_toggle_get_active (GtkCellRendererToggle *toggle)
{
  g_return_val_if_fail (GTK_IS_CELL_RENDERER_TOGGLE (toggle), FALSE);

571
  return toggle->priv->active;
572 573
}

Matthias Clasen's avatar
Matthias Clasen committed
574 575 576 577 578 579 580
/**
 * gtk_cell_renderer_toggle_set_active:
 * @toggle: a #GtkCellRendererToggle.
 * @setting: the value to set.
 *
 * Activates or deactivates a cell renderer.
 **/
581 582 583 584 585 586
void
gtk_cell_renderer_toggle_set_active (GtkCellRendererToggle *toggle,
				     gboolean               setting)
{
  g_return_if_fail (GTK_IS_CELL_RENDERER_TOGGLE (toggle));

587
  g_object_set (toggle, "active", setting ? TRUE : FALSE, NULL);
588
}
589

590 591 592 593 594 595 596
/**
 * gtk_cell_renderer_toggle_get_activatable:
 * @toggle: a #GtkCellRendererToggle
 *
 * Returns whether the cell renderer is activatable. See
 * gtk_cell_renderer_toggle_set_activatable().
 *
597
 * Returns: %TRUE if the cell renderer is activatable.
598 599 600 601 602 603 604 605
 *
 * Since: 2.18
 **/
gboolean
gtk_cell_renderer_toggle_get_activatable (GtkCellRendererToggle *toggle)
{
  g_return_val_if_fail (GTK_IS_CELL_RENDERER_TOGGLE (toggle), FALSE);

606
  return toggle->priv->activatable;
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
}

/**
 * gtk_cell_renderer_toggle_set_activatable:
 * @toggle: a #GtkCellRendererToggle.
 * @setting: the value to set.
 *
 * Makes the cell renderer activatable.
 *
 * Since: 2.18
 **/
void
gtk_cell_renderer_toggle_set_activatable (GtkCellRendererToggle *toggle,
                                          gboolean               setting)
{
622
  GtkCellRendererTogglePrivate *priv;
623

624 625
  g_return_if_fail (GTK_IS_CELL_RENDERER_TOGGLE (toggle));

626 627 628
  priv = toggle->priv;

  if (priv->activatable != setting)
629
    {
630
      priv->activatable = setting ? TRUE : FALSE;
631 632 633
      g_object_notify (G_OBJECT (toggle), "activatable");
    }
}