gtkcellrenderertoggle.c 19.9 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"
Benjamin Otte's avatar
Benjamin Otte committed
19

Kristian Rietveld's avatar
Kristian Rietveld committed
20
#include "gtkcellrenderertoggle.h"
Benjamin Otte's avatar
Benjamin Otte committed
21

22
#include "gtkcssnumbervalueprivate.h"
23
#include "gtkcsstransientnodeprivate.h"
24
#include "gtkmarshalers.h"
25
#include "gtkprivate.h"
26
#include "gtkrendericonprivate.h"
Benjamin Otte's avatar
Benjamin Otte committed
27
#include "gtksnapshot.h"
28
#include "gtkstylecontextprivate.h"
29
#include "gtkwidgetprivate.h"
30
#include "gtktreeprivate.h"
Benjamin Otte's avatar
Benjamin Otte committed
31
32

#include <stdlib.h>
33

34
/**
35
36
37
 * GtkCellRendererToggle:
 *
 * Renders a toggle button in a cell
38
 *
Matthias Clasen's avatar
Matthias Clasen committed
39
 * `GtkCellRendererToggle` renders a toggle button in a cell. The
40
 * button is drawn as a radio or a checkbutton, depending on the
Matthias Clasen's avatar
Matthias Clasen committed
41
42
 * `GtkCellRendererToggle:radio` property.
 * When activated, it emits the `GtkCellRendererToggle::toggled` signal.
43
44
45
 */


46
47
48
static void gtk_cell_renderer_toggle_get_property  (GObject                    *object,
						    guint                       param_id,
						    GValue                     *value,
Tim Janik's avatar
Tim Janik committed
49
						    GParamSpec                 *pspec);
50
51
52
static void gtk_cell_renderer_toggle_set_property  (GObject                    *object,
						    guint                       param_id,
						    const GValue               *value,
Tim Janik's avatar
Tim Janik committed
53
						    GParamSpec                 *pspec);
54
static void gtk_cell_renderer_toggle_get_size   (GtkCellRendererToggle      *self,
55
						 GtkWidget                  *widget,
56
						 const GdkRectangle         *cell_area,
Benjamin Otte's avatar
Benjamin Otte committed
57
58
59
60
						 int                        *x_offset,
						 int                        *y_offset,
						 int                        *width,
						 int                        *height);
61
62
static void gtk_cell_renderer_toggle_snapshot   (GtkCellRenderer            *cell,
						 GtkSnapshot                *snapshot,
63
						 GtkWidget                  *widget,
64
65
						 const GdkRectangle         *background_area,
						 const GdkRectangle         *cell_area,
66
						 GtkCellRendererState        flags);
67
68
69
static gboolean gtk_cell_renderer_toggle_activate  (GtkCellRenderer            *cell,
						    GdkEvent                   *event,
						    GtkWidget                  *widget,
Benjamin Otte's avatar
Benjamin Otte committed
70
						    const char                 *path,
71
72
						    const GdkRectangle         *background_area,
						    const GdkRectangle         *cell_area,
73
						    GtkCellRendererState        flags);
74
75
76
77
78
79
80
81


enum {
  TOGGLED,
  LAST_SIGNAL
};

enum {
82
  PROP_0,
83
  PROP_ACTIVATABLE,
Havoc Pennington's avatar
Havoc Pennington committed
84
  PROP_ACTIVE,
85
  PROP_RADIO,
86
  PROP_INCONSISTENT
87
88
89
90
};

static guint toggle_cell_signals[LAST_SIGNAL] = { 0 };

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
typedef struct _GtkCellRendererTogglePrivate       GtkCellRendererTogglePrivate;
typedef struct _GtkCellRendererToggleClass         GtkCellRendererToggleClass;

struct _GtkCellRendererToggle
{
  GtkCellRenderer parent;
};

struct _GtkCellRendererToggleClass
{
  GtkCellRendererClass parent_class;

  void (* toggled) (GtkCellRendererToggle *cell,
                    const char            *path);
};

107
struct _GtkCellRendererTogglePrivate
108
{
109
110
  guint active       : 1;
  guint activatable  : 1;
111
  guint inconsistent : 1;
112
  guint radio        : 1;
113
  GtkCssNode *cssnode;
114
115
};

116

117
G_DEFINE_TYPE_WITH_PRIVATE (GtkCellRendererToggle, gtk_cell_renderer_toggle, GTK_TYPE_CELL_RENDERER)
118

119

120
121
122
static void
gtk_cell_renderer_toggle_init (GtkCellRendererToggle *celltoggle)
{
123
  GtkCellRendererTogglePrivate *priv = gtk_cell_renderer_toggle_get_instance_private (celltoggle);
124

125
126
127
  priv->activatable = TRUE;
  priv->active = FALSE;
  priv->radio = FALSE;
128

129
130
  g_object_set (celltoggle, "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL);
  gtk_cell_renderer_set_padding (GTK_CELL_RENDERER (celltoggle), 2, 2);
131
132

  priv->inconsistent = FALSE;
133
134
}

135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
static GtkSizeRequestMode
gtk_cell_renderer_toggle_get_request_mode (GtkCellRenderer *cell)
{
  return GTK_SIZE_REQUEST_CONSTANT_SIZE;
}

static void
gtk_cell_renderer_toggle_get_preferred_width (GtkCellRenderer *cell,
                                              GtkWidget       *widget,
                                              int             *minimum,
                                              int             *natural)
{
  int width = 0;

  gtk_cell_renderer_toggle_get_size (GTK_CELL_RENDERER_TOGGLE (cell), widget,
                                     NULL,
                                     NULL, NULL, &width, NULL);

  if (minimum)
    *minimum = width;
  if (natural)
    *natural = width;
}

static void
gtk_cell_renderer_toggle_get_preferred_height (GtkCellRenderer *cell,
                                               GtkWidget       *widget,
                                               int             *minimum,
                                               int             *natural)
{
  int height = 0;

  gtk_cell_renderer_toggle_get_size (GTK_CELL_RENDERER_TOGGLE (cell), widget,
                                     NULL,
                                     NULL, NULL, NULL, &height);

  if (minimum)
    *minimum = height;
  if (natural)
    *natural = height;
}

177
178
179
180
181
182
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);

183
184
  object_class->get_property = gtk_cell_renderer_toggle_get_property;
  object_class->set_property = gtk_cell_renderer_toggle_set_property;
185

186
187
188
  cell_class->get_request_mode = gtk_cell_renderer_toggle_get_request_mode;
  cell_class->get_preferred_width = gtk_cell_renderer_toggle_get_preferred_width;
  cell_class->get_preferred_height = gtk_cell_renderer_toggle_get_preferred_height;
189
  cell_class->snapshot = gtk_cell_renderer_toggle_snapshot;
190
  cell_class->activate = gtk_cell_renderer_toggle_activate;
191
192
  
  g_object_class_install_property (object_class,
Havoc Pennington's avatar
Havoc Pennington committed
193
				   PROP_ACTIVE,
194
				   g_param_spec_boolean ("active", NULL, NULL,
195
							 FALSE,
196
							 GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
197
198
199

  g_object_class_install_property (object_class,
		                   PROP_INCONSISTENT,
200
				   g_param_spec_boolean ("inconsistent", NULL, NULL,
201
							 FALSE,
202
							 GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
203
  
204
205
  g_object_class_install_property (object_class,
				   PROP_ACTIVATABLE,
206
				   g_param_spec_boolean ("activatable", NULL, NULL,
207
							 TRUE,
208
							 GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
209

210
211
  g_object_class_install_property (object_class,
				   PROP_RADIO,
212
				   g_param_spec_boolean ("radio", NULL, NULL,
213
							 FALSE,
214
							 GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
215

216
217
218
219
  
  /**
   * GtkCellRendererToggle::toggled:
   * @cell_renderer: the object which received the signal
Matthias Clasen's avatar
Matthias Clasen committed
220
   * @path: string representation of `GtkTreePath` describing the 
221
222
223
   *        event location
   *
   * The ::toggled signal is emitted when the cell is toggled. 
224
225
   *
   * It is the responsibility of the application to update the model
226
227
   * with the correct value to store at @path.  Often this is simply the
   * opposite of the value currently stored at @path.
228
   **/
229
  toggle_cell_signals[TOGGLED] =
Matthias Clasen's avatar
Matthias Clasen committed
230
    g_signal_new (I_("toggled"),
Manish Singh's avatar
Manish Singh committed
231
232
233
234
		  G_OBJECT_CLASS_TYPE (object_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkCellRendererToggleClass, toggled),
		  NULL, NULL,
235
		  NULL,
Manish Singh's avatar
Manish Singh committed
236
237
		  G_TYPE_NONE, 1,
		  G_TYPE_STRING);
238
239
240
}

static void
241
242
243
gtk_cell_renderer_toggle_get_property (GObject     *object,
				       guint        param_id,
				       GValue      *value,
Tim Janik's avatar
Tim Janik committed
244
				       GParamSpec  *pspec)
245
246
{
  GtkCellRendererToggle *celltoggle = GTK_CELL_RENDERER_TOGGLE (object);
247
  GtkCellRendererTogglePrivate *priv = gtk_cell_renderer_toggle_get_instance_private (celltoggle);
248

249
250
  switch (param_id)
    {
Havoc Pennington's avatar
Havoc Pennington committed
251
    case PROP_ACTIVE:
252
      g_value_set_boolean (value, priv->active);
253
      break;
254
    case PROP_INCONSISTENT:
255
      g_value_set_boolean (value, priv->inconsistent);
256
      break;
257
    case PROP_ACTIVATABLE:
258
      g_value_set_boolean (value, priv->activatable);
259
      break;
260
    case PROP_RADIO:
261
      g_value_set_boolean (value, priv->radio);
262
263
      break;
    default:
264
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
265
266
267
268
269
270
      break;
    }
}


static void
271
272
273
gtk_cell_renderer_toggle_set_property (GObject      *object,
				       guint         param_id,
				       const GValue *value,
Tim Janik's avatar
Tim Janik committed
274
				       GParamSpec   *pspec)
275
276
{
  GtkCellRendererToggle *celltoggle = GTK_CELL_RENDERER_TOGGLE (object);
277
  GtkCellRendererTogglePrivate *priv = gtk_cell_renderer_toggle_get_instance_private (celltoggle);
278

279
280
  switch (param_id)
    {
Havoc Pennington's avatar
Havoc Pennington committed
281
    case PROP_ACTIVE:
282
283
284
285
286
      if (priv->active != g_value_get_boolean (value))
        {
          priv->active = g_value_get_boolean (value);
          g_object_notify_by_pspec (object, pspec);
        }
287
      break;
288
    case PROP_INCONSISTENT:
289
290
291
292
293
      if (priv->inconsistent != g_value_get_boolean (value))
        {
          priv->inconsistent = g_value_get_boolean (value);
          g_object_notify_by_pspec (object, pspec);
        }
294
      break;
295
    case PROP_ACTIVATABLE:
296
297
298
299
300
      if (priv->activatable != g_value_get_boolean (value))
        {
          priv->activatable = g_value_get_boolean (value);
          g_object_notify_by_pspec (object, pspec);
        }
301
      break;
302
    case PROP_RADIO:
303
304
      if (priv->radio != g_value_get_boolean (value))
        {
305
          gtk_cell_renderer_toggle_set_radio (celltoggle, g_value_get_boolean (value));
306
307
308
309
310
311
312
313
314
          g_object_notify_by_pspec (object, pspec);
        }
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
      break;
    }
}

315
316
/**
 * gtk_cell_renderer_toggle_new:
317
 *
Matthias Clasen's avatar
Matthias Clasen committed
318
 * Creates a new `GtkCellRendererToggle`. Adjust rendering
319
 * parameters using object properties. Object properties can be set
Matthias Clasen's avatar
Matthias Clasen committed
320
321
 * globally (with g_object_set()). Also, with `GtkTreeViewColumn`, you
 * can bind a property to a value in a `GtkTreeModel`. For example, you
William Jon McCann's avatar
William Jon McCann committed
322
 * can bind the “active” property on the cell renderer to a boolean value
323
324
 * in the model, thus causing the check button to reflect the state of
 * the model.
325
 *
326
 * Returns: the new cell renderer
327
 **/
328
329
330
GtkCellRenderer *
gtk_cell_renderer_toggle_new (void)
{
Manish Singh's avatar
Manish Singh committed
331
  return g_object_new (GTK_TYPE_CELL_RENDERER_TOGGLE, NULL);
332
333
}

334
static GtkStyleContext *
335
gtk_cell_renderer_toggle_save_context (GtkCellRendererToggle *cell,
336
                                       GtkWidget             *widget)
337
{
338
  GtkCellRendererTogglePrivate *priv = gtk_cell_renderer_toggle_get_instance_private (cell);
339
  GtkStyleContext *context;
340
  GtkCssNode *cssnode;
341
342
343

  context = gtk_widget_get_style_context (widget);

344
345
346
347
348
349
350
  cssnode = gtk_css_transient_node_new (gtk_widget_get_css_node (widget));
  if (priv->radio)
    gtk_css_node_set_name (cssnode, g_quark_from_static_string ("radio"));
  else
    gtk_css_node_set_name (cssnode, g_quark_from_static_string ("check"));
  gtk_style_context_save_to_node (context, cssnode);
  g_object_unref (cssnode);
351
352
353

  return context;
}
354

355
static void
356
357
358
359
360
361
gtk_cell_renderer_toggle_restore_context (GtkCellRendererToggle *cell,
                                          GtkStyleContext       *context)
{
  gtk_style_context_restore (context);
}

362
363
static int
calc_indicator_size (GtkStyleContext *context)
364
{
365
  GtkCssStyle *style = gtk_style_context_lookup_style (context);
Matthias Clasen's avatar
Matthias Clasen committed
366
  return _gtk_css_number_value_get (style->icon->icon_size, 100);
367
368
}

369
static void
370
371
372
373
374
375
376
gtk_cell_renderer_toggle_get_size (GtkCellRendererToggle *self,
				   GtkWidget             *widget,
				   const GdkRectangle    *cell_area,
				   int                   *x_offset,
				   int                   *y_offset,
				   int                   *width,
				   int                   *height)
377
{
378
  GtkCellRenderer *cell = GTK_CELL_RENDERER (self);
Benjamin Otte's avatar
Benjamin Otte committed
379
380
381
  int calc_width;
  int calc_height;
  int xpad, ypad;
382
383
  GtkStyleContext *context;
  GtkBorder border, padding;
384

385
  gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
386

387
  context = gtk_cell_renderer_toggle_save_context (self, widget);
388
389
  gtk_style_context_get_padding (context, &padding);
  gtk_style_context_get_border (context, &border);
390

391
  calc_width = calc_height = calc_indicator_size (context);
392
393
  calc_width += xpad * 2 + padding.left + padding.right + border.left + border.right;
  calc_height += ypad * 2 + padding.top + padding.bottom + border.top + border.bottom;
394

395
  gtk_cell_renderer_toggle_restore_context (self, context);
396

397
  if (width)
398
    *width = calc_width;
399
400

  if (height)
401
    *height = calc_height;
Jonathan Blandford's avatar
Jonathan Blandford committed
402

403
404
  if (cell_area)
    {
Benjamin Otte's avatar
Benjamin Otte committed
405
      float xalign, yalign;
406
407
408

      gtk_cell_renderer_get_alignment (cell, &xalign, &yalign);

409
410
      if (x_offset)
	{
Jonathan Blandford's avatar
Jonathan Blandford committed
411
	  *x_offset = ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ?
412
		       (1.0 - xalign) : xalign) * (cell_area->width - calc_width);
413
	  *x_offset = MAX (*x_offset, 0);
414
415
416
	}
      if (y_offset)
	{
417
	  *y_offset = yalign * (cell_area->height - calc_height);
418
	  *y_offset = MAX (*y_offset, 0);
419
420
	}
    }
421
422
  else
    {
423
424
425
426
      if (x_offset)
        *x_offset = 0;
      if (y_offset)
        *y_offset = 0;
427
    }
428
429
430
}

static void
431
432
433
434
435
436
gtk_cell_renderer_toggle_snapshot (GtkCellRenderer      *cell,
				   GtkSnapshot          *snapshot,
                                   GtkWidget            *widget,
                                   const GdkRectangle   *background_area,
                                   const GdkRectangle   *cell_area,
                                   GtkCellRendererState  flags)
437
{
438
  GtkCellRendererToggle *celltoggle = GTK_CELL_RENDERER_TOGGLE (cell);
439
  GtkCellRendererTogglePrivate *priv = gtk_cell_renderer_toggle_get_instance_private (celltoggle);
440
  GtkStyleContext *context;
Benjamin Otte's avatar
Benjamin Otte committed
441
442
443
  int width, height;
  int x_offset, y_offset;
  int xpad, ypad;
444
  GtkStateFlags state;
445
  GtkBorder padding, border;
446

447
  gtk_cell_renderer_toggle_get_size (celltoggle, widget, cell_area,
448
449
				     &x_offset, &y_offset,
				     &width, &height);
450
451
452
  gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
  width -= xpad * 2;
  height -= ypad * 2;
453

454
455
456
  if (width <= 0 || height <= 0)
    return;

457
458
  state = gtk_cell_renderer_get_state (cell, widget, flags);

459
  if (!priv->activatable)
460
461
    state |= GTK_STATE_FLAG_INSENSITIVE;

Benjamin Otte's avatar
Benjamin Otte committed
462
  state &= ~(GTK_STATE_FLAG_INCONSISTENT | GTK_STATE_FLAG_CHECKED);
463

464
465
  if (priv->inconsistent)
    state |= GTK_STATE_FLAG_INCONSISTENT;
466
467
  
  if (priv->active)
Benjamin Otte's avatar
Benjamin Otte committed
468
    state |= GTK_STATE_FLAG_CHECKED;
469

470
471
472
473
  gtk_snapshot_push_clip (snapshot,
                          &GRAPHENE_RECT_INIT (
                             cell_area->x, cell_area->y,
                             cell_area->width, cell_area->height
Benjamin Otte's avatar
Benjamin Otte committed
474
                          ));
475

476
  context = gtk_cell_renderer_toggle_save_context (celltoggle, widget);
477
  gtk_style_context_set_state (context, state);
478

479
480
481
482
483
484
485
486
  gtk_snapshot_render_background (snapshot, context,
                                  cell_area->x + x_offset + xpad,
                                  cell_area->y + y_offset + ypad,
                                  width, height);
  gtk_snapshot_render_frame (snapshot, context,
                             cell_area->x + x_offset + xpad,
                             cell_area->y + y_offset + ypad,
                             width, height);
487

488
489
  gtk_style_context_get_padding (context, &padding);
  gtk_style_context_get_border (context, &border);
490

491
492
493
  gtk_snapshot_translate (snapshot,
                          &GRAPHENE_POINT_INIT (cell_area->x + x_offset + xpad + padding.left + border.left,
                                                cell_area->y + y_offset + ypad + padding.top + border.top));
494
495
  gtk_css_style_snapshot_icon (gtk_style_context_lookup_style (context), snapshot,
                               width - padding.left - padding.right - border.left - border.right,
496
                               height - padding.top - padding.bottom - border.top - border.bottom);
497

498
  gtk_cell_renderer_toggle_restore_context (celltoggle, context);
Benjamin Otte's avatar
Benjamin Otte committed
499
  gtk_snapshot_pop (snapshot);
500
501
}

Benjamin Otte's avatar
Benjamin Otte committed
502
static int
503
504
505
gtk_cell_renderer_toggle_activate (GtkCellRenderer      *cell,
				   GdkEvent             *event,
				   GtkWidget            *widget,
Benjamin Otte's avatar
Benjamin Otte committed
506
				   const char           *path,
507
508
				   const GdkRectangle   *background_area,
				   const GdkRectangle   *cell_area,
509
				   GtkCellRendererState  flags)
510
{
511
512
  GtkCellRendererToggle *celltoggle = GTK_CELL_RENDERER_TOGGLE (cell);
  GtkCellRendererTogglePrivate *priv = gtk_cell_renderer_toggle_get_instance_private (celltoggle);
513
514

  if (priv->activatable)
515
    {
Manish Singh's avatar
Manish Singh committed
516
      g_signal_emit (cell, toggle_cell_signals[TOGGLED], 0, path);
517
      return TRUE;
518
    }
519
520

  return FALSE;
521
522
}

523
524
/**
 * gtk_cell_renderer_toggle_set_radio:
Matthias Clasen's avatar
Matthias Clasen committed
525
 * @toggle: a `GtkCellRendererToggle`
526
527
528
529
530
531
 * @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
Matthias Clasen's avatar
Matthias Clasen committed
532
533
 * before rendering each cell in the model (for `GtkTreeView`, you set
 * up a per-row setting using `GtkTreeViewColumn` to associate model
534
535
 * columns with cell renderer properties).
 **/
536
537
538
539
void
gtk_cell_renderer_toggle_set_radio (GtkCellRendererToggle *toggle,
				    gboolean               radio)
{
540
  GtkCellRendererTogglePrivate *priv = gtk_cell_renderer_toggle_get_instance_private (toggle);
541

542
543
  g_return_if_fail (GTK_IS_CELL_RENDERER_TOGGLE (toggle));

544
  priv->radio = radio;
545
}
Havoc Pennington's avatar
Havoc Pennington committed
546

547
548
/**
 * gtk_cell_renderer_toggle_get_radio:
Matthias Clasen's avatar
Matthias Clasen committed
549
 * @toggle: a `GtkCellRendererToggle`
Matthias Clasen's avatar
Matthias Clasen committed
550
 *
551
 * Returns whether we’re rendering radio toggles rather than checkboxes. 
552
 * 
553
 * Returns: %TRUE if we’re rendering radio toggles rather than checkboxes
554
 **/
Havoc Pennington's avatar
Havoc Pennington committed
555
gboolean
556
gtk_cell_renderer_toggle_get_radio (GtkCellRendererToggle *toggle)
Havoc Pennington's avatar
Havoc Pennington committed
557
{
558
559
  GtkCellRendererTogglePrivate *priv = gtk_cell_renderer_toggle_get_instance_private (toggle);

Havoc Pennington's avatar
Havoc Pennington committed
560
561
  g_return_val_if_fail (GTK_IS_CELL_RENDERER_TOGGLE (toggle), FALSE);

562
  return priv->radio;
Havoc Pennington's avatar
Havoc Pennington committed
563
}
564

Matthias Clasen's avatar
Matthias Clasen committed
565
566
/**
 * gtk_cell_renderer_toggle_get_active:
Matthias Clasen's avatar
Matthias Clasen committed
567
 * @toggle: a `GtkCellRendererToggle`
Matthias Clasen's avatar
Matthias Clasen committed
568
569
570
571
 *
 * Returns whether the cell renderer is active. See
 * gtk_cell_renderer_toggle_set_active().
 *
572
 * Returns: %TRUE if the cell renderer is active.
573
 **/
574
575
576
gboolean
gtk_cell_renderer_toggle_get_active (GtkCellRendererToggle *toggle)
{
577
578
  GtkCellRendererTogglePrivate *priv = gtk_cell_renderer_toggle_get_instance_private (toggle);

579
580
  g_return_val_if_fail (GTK_IS_CELL_RENDERER_TOGGLE (toggle), FALSE);

581
  return priv->active;
582
583
}

Matthias Clasen's avatar
Matthias Clasen committed
584
585
/**
 * gtk_cell_renderer_toggle_set_active:
Matthias Clasen's avatar
Matthias Clasen committed
586
 * @toggle: a `GtkCellRendererToggle`.
Matthias Clasen's avatar
Matthias Clasen committed
587
588
589
590
 * @setting: the value to set.
 *
 * Activates or deactivates a cell renderer.
 **/
591
592
593
594
595
596
void
gtk_cell_renderer_toggle_set_active (GtkCellRendererToggle *toggle,
				     gboolean               setting)
{
  g_return_if_fail (GTK_IS_CELL_RENDERER_TOGGLE (toggle));

597
  g_object_set (toggle, "active", setting ? TRUE : FALSE, NULL);
598
}
599

600
601
/**
 * gtk_cell_renderer_toggle_get_activatable:
Matthias Clasen's avatar
Matthias Clasen committed
602
 * @toggle: a `GtkCellRendererToggle`
603
604
605
606
 *
 * Returns whether the cell renderer is activatable. See
 * gtk_cell_renderer_toggle_set_activatable().
 *
607
 * Returns: %TRUE if the cell renderer is activatable.
608
609
610
611
 **/
gboolean
gtk_cell_renderer_toggle_get_activatable (GtkCellRendererToggle *toggle)
{
612
613
  GtkCellRendererTogglePrivate *priv = gtk_cell_renderer_toggle_get_instance_private (toggle);

614
615
  g_return_val_if_fail (GTK_IS_CELL_RENDERER_TOGGLE (toggle), FALSE);

616
  return priv->activatable;
617
618
619
620
}

/**
 * gtk_cell_renderer_toggle_set_activatable:
Matthias Clasen's avatar
Matthias Clasen committed
621
 * @toggle: a `GtkCellRendererToggle`.
622
623
624
625
626
627
628
629
 * @setting: the value to set.
 *
 * Makes the cell renderer activatable.
 **/
void
gtk_cell_renderer_toggle_set_activatable (GtkCellRendererToggle *toggle,
                                          gboolean               setting)
{
630
  GtkCellRendererTogglePrivate *priv = gtk_cell_renderer_toggle_get_instance_private (toggle);
631

632
633
  g_return_if_fail (GTK_IS_CELL_RENDERER_TOGGLE (toggle));

634
  if (priv->activatable != setting)
635
    {
636
      priv->activatable = setting ? TRUE : FALSE;
637
638
639
      g_object_notify (G_OBJECT (toggle), "activatable");
    }
}