1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
|
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Modified by the GTK+ Team and others 1997-2001. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include "gtkcheckmenuitem.h"
#include "gtkmenuitemprivate.h"
#include "gtkaccellabel.h"
#include "deprecated/gtkactivatable.h"
#include "deprecated/gtktoggleaction.h"
#include "gtkmarshalers.h"
#include "gtkprivate.h"
#include "gtkintl.h"
#include "a11y/gtkcheckmenuitemaccessible.h"
#include "gtkcssnodeprivate.h"
#include "gtkcssstylepropertyprivate.h"
#include "gtkwidgetprivate.h"
/**
* SECTION:gtkcheckmenuitem
* @Short_description: A menu item with a check box
* @Title: GtkCheckMenuItem
*
* A #GtkCheckMenuItem is a menu item that maintains the state of a boolean
* value in addition to a #GtkMenuItem usual role in activating application
* code.
*
* A check box indicating the state of the boolean value is displayed
* at the left side of the #GtkMenuItem. Activating the #GtkMenuItem
* toggles the value.
*
* # CSS nodes
*
* |[<!-- language="plain" -->
* menuitem
* ├── ...
* ╰── check.right
* ]|
*
* GtkCheckMenuItem has a main CSS node with name menuitem, and a subnode
* with name check, which gets the .left or .right style class.
*/
#define INDICATOR_SIZE 16
struct _GtkCheckMenuItemPrivate
{
GtkCssNode *indicator_node;
guint active : 1;
guint draw_as_radio : 1;
guint inconsistent : 1;
};
enum {
TOGGLED,
LAST_SIGNAL
};
enum {
PROP_0,
PROP_ACTIVE,
PROP_INCONSISTENT,
PROP_DRAW_AS_RADIO
};
static gint gtk_check_menu_item_draw (GtkWidget *widget,
cairo_t *cr);
static void gtk_check_menu_item_activate (GtkMenuItem *menu_item);
static void gtk_check_menu_item_toggle_size_request (GtkMenuItem *menu_item,
gint *requisition);
static void gtk_real_check_menu_item_draw_indicator (GtkCheckMenuItem *check_menu_item,
cairo_t *cr);
static void gtk_check_menu_item_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gtk_check_menu_item_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void gtk_check_menu_item_state_flags_changed (GtkWidget *widget,
GtkStateFlags previous_state);
static void gtk_check_menu_item_direction_changed (GtkWidget *widget,
GtkTextDirection previous_dir);
static void gtk_check_menu_item_activatable_interface_init (GtkActivatableIface *iface);
static void gtk_check_menu_item_update (GtkActivatable *activatable,
GtkAction *action,
const gchar *property_name);
static void gtk_check_menu_item_sync_action_properties (GtkActivatable *activatable,
GtkAction *action);
static GtkActivatableIface *parent_activatable_iface;
static guint check_menu_item_signals[LAST_SIGNAL] = { 0 };
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
G_DEFINE_TYPE_WITH_CODE (GtkCheckMenuItem, gtk_check_menu_item, GTK_TYPE_MENU_ITEM,
G_ADD_PRIVATE (GtkCheckMenuItem)
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
gtk_check_menu_item_activatable_interface_init))
G_GNUC_END_IGNORE_DEPRECATIONS;
static void
gtk_check_menu_item_class_init (GtkCheckMenuItemClass *klass)
{
GObjectClass *gobject_class;
GtkWidgetClass *widget_class;
GtkMenuItemClass *menu_item_class;
gobject_class = G_OBJECT_CLASS (klass);
widget_class = (GtkWidgetClass*) klass;
menu_item_class = (GtkMenuItemClass*) klass;
gobject_class->set_property = gtk_check_menu_item_set_property;
gobject_class->get_property = gtk_check_menu_item_get_property;
widget_class->state_flags_changed = gtk_check_menu_item_state_flags_changed;
widget_class->direction_changed = gtk_check_menu_item_direction_changed;
g_object_class_install_property (gobject_class,
PROP_ACTIVE,
g_param_spec_boolean ("active",
P_("Active"),
P_("Whether the menu item is checked"),
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
g_object_class_install_property (gobject_class,
PROP_INCONSISTENT,
g_param_spec_boolean ("inconsistent",
P_("Inconsistent"),
P_("Whether to display an \"inconsistent\" state"),
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
g_object_class_install_property (gobject_class,
PROP_DRAW_AS_RADIO,
g_param_spec_boolean ("draw-as-radio",
P_("Draw as radio menu item"),
P_("Whether the menu item looks like a radio menu item"),
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("indicator-size",
P_("Indicator Size"),
P_("Size of check or radio indicator"),
0,
G_MAXINT,
INDICATOR_SIZE,
GTK_PARAM_READABLE));
widget_class->draw = gtk_check_menu_item_draw;
menu_item_class->activate = gtk_check_menu_item_activate;
menu_item_class->hide_on_activate = FALSE;
menu_item_class->toggle_size_request = gtk_check_menu_item_toggle_size_request;
klass->toggled = NULL;
klass->draw_indicator = gtk_real_check_menu_item_draw_indicator;
/**
* GtkCheckMenuItem::toggled:
* @checkmenuitem: the object which received the signal.
*
* This signal is emitted when the state of the check box is changed.
*
* A signal handler can use gtk_check_menu_item_get_active()
* to discover the new state.
*/
check_menu_item_signals[TOGGLED] =
g_signal_new (I_("toggled"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GtkCheckMenuItemClass, toggled),
NULL, NULL,
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_CHECK_MENU_ITEM_ACCESSIBLE);
gtk_widget_class_set_css_name (widget_class, "menuitem");
}
static void
gtk_check_menu_item_activatable_interface_init (GtkActivatableIface *iface)
{
parent_activatable_iface = g_type_interface_peek_parent (iface);
iface->update = gtk_check_menu_item_update;
iface->sync_action_properties = gtk_check_menu_item_sync_action_properties;
}
static void
gtk_check_menu_item_update (GtkActivatable *activatable,
GtkAction *action,
const gchar *property_name)
{
GtkCheckMenuItem *check_menu_item;
gboolean use_action_appearance;
check_menu_item = GTK_CHECK_MENU_ITEM (activatable);
parent_activatable_iface->update (activatable, action, property_name);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
if (strcmp (property_name, "active") == 0)
{
gtk_action_block_activate (action);
gtk_check_menu_item_set_active (check_menu_item, gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
gtk_action_unblock_activate (action);
}
use_action_appearance = gtk_activatable_get_use_action_appearance (activatable);
G_GNUC_END_IGNORE_DEPRECATIONS;
if (!use_action_appearance)
return;
if (strcmp (property_name, "draw-as-radio") == 0)
{
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
gtk_check_menu_item_set_draw_as_radio (check_menu_item,
gtk_toggle_action_get_draw_as_radio (GTK_TOGGLE_ACTION (action)));
G_GNUC_END_IGNORE_DEPRECATIONS;
}
}
static void
gtk_check_menu_item_sync_action_properties (GtkActivatable *activatable,
GtkAction *action)
{
GtkCheckMenuItem *check_menu_item;
gboolean use_action_appearance;
gboolean is_toggle_action;
check_menu_item = GTK_CHECK_MENU_ITEM (activatable);
parent_activatable_iface->sync_action_properties (activatable, action);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
is_toggle_action = GTK_IS_TOGGLE_ACTION (action);
G_GNUC_END_IGNORE_DEPRECATIONS;
if (!is_toggle_action)
return;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
gtk_action_block_activate (action);
gtk_check_menu_item_set_active (check_menu_item, gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
gtk_action_unblock_activate (action);
use_action_appearance = gtk_activatable_get_use_action_appearance (activatable);
G_GNUC_END_IGNORE_DEPRECATIONS;
if (!use_action_appearance)
return;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
gtk_check_menu_item_set_draw_as_radio (check_menu_item,
gtk_toggle_action_get_draw_as_radio (GTK_TOGGLE_ACTION (action)));
G_GNUC_END_IGNORE_DEPRECATIONS;
}
/**
* gtk_check_menu_item_new:
*
* Creates a new #GtkCheckMenuItem.
*
* Returns: a new #GtkCheckMenuItem.
*/
GtkWidget*
gtk_check_menu_item_new (void)
{
return g_object_new (GTK_TYPE_CHECK_MENU_ITEM, NULL);
}
/**
* gtk_check_menu_item_new_with_label:
* @label: the string to use for the label.
*
* Creates a new #GtkCheckMenuItem with a label.
*
* Returns: a new #GtkCheckMenuItem.
*/
GtkWidget*
gtk_check_menu_item_new_with_label (const gchar *label)
{
return g_object_new (GTK_TYPE_CHECK_MENU_ITEM,
"label", label,
NULL);
}
/**
* gtk_check_menu_item_new_with_mnemonic:
* @label: The text of the button, with an underscore in front of the
* character
*
* Creates a new #GtkCheckMenuItem containing a label. The label
* will be created using gtk_label_new_with_mnemonic(), so underscores
* in @label indicate the mnemonic for the menu item.
*
* Returns: a new #GtkCheckMenuItem
*/
GtkWidget*
gtk_check_menu_item_new_with_mnemonic (const gchar *label)
{
return g_object_new (GTK_TYPE_CHECK_MENU_ITEM,
"label", label,
"use-underline", TRUE,
NULL);
}
/**
* gtk_check_menu_item_set_active:
* @check_menu_item: a #GtkCheckMenuItem.
* @is_active: boolean value indicating whether the check box is active.
*
* Sets the active state of the menu item’s check box.
*/
void
gtk_check_menu_item_set_active (GtkCheckMenuItem *check_menu_item,
gboolean is_active)
{
GtkCheckMenuItemPrivate *priv;
g_return_if_fail (GTK_IS_CHECK_MENU_ITEM (check_menu_item));
priv = check_menu_item->priv;
is_active = is_active != 0;
if (priv->active != is_active)
gtk_menu_item_activate (GTK_MENU_ITEM (check_menu_item));
}
/**
* gtk_check_menu_item_get_active:
* @check_menu_item: a #GtkCheckMenuItem
*
* Returns whether the check menu item is active. See
* gtk_check_menu_item_set_active ().
*
* Returns: %TRUE if the menu item is checked.
*/
gboolean
gtk_check_menu_item_get_active (GtkCheckMenuItem *check_menu_item)
{
g_return_val_if_fail (GTK_IS_CHECK_MENU_ITEM (check_menu_item), FALSE);
return check_menu_item->priv->active;
}
static void
gtk_check_menu_item_toggle_size_request (GtkMenuItem *menu_item,
gint *requisition)
{
guint toggle_spacing;
guint indicator_size;
g_return_if_fail (GTK_IS_CHECK_MENU_ITEM (menu_item));
gtk_widget_style_get (GTK_WIDGET (menu_item),
"toggle-spacing", &toggle_spacing,
"indicator-size", &indicator_size,
NULL);
*requisition = indicator_size + toggle_spacing;
}
/**
* gtk_check_menu_item_toggled:
* @check_menu_item: a #GtkCheckMenuItem.
*
* Emits the #GtkCheckMenuItem::toggled signal.
*/
void
gtk_check_menu_item_toggled (GtkCheckMenuItem *check_menu_item)
{
g_signal_emit (check_menu_item, check_menu_item_signals[TOGGLED], 0);
}
static void
update_node_state (GtkCheckMenuItem *check_menu_item)
{
GtkCheckMenuItemPrivate *priv = check_menu_item->priv;
GtkStateFlags state;
state = gtk_widget_get_state_flags (GTK_WIDGET (check_menu_item));
if (priv->inconsistent)
state |= GTK_STATE_FLAG_INCONSISTENT;
if (priv->active)
state |= GTK_STATE_FLAG_CHECKED;
gtk_css_node_set_state (priv->indicator_node, state);
}
/**
* gtk_check_menu_item_set_inconsistent:
* @check_menu_item: a #GtkCheckMenuItem
* @setting: %TRUE to display an “inconsistent” third state check
*
* If the user has selected a range of elements (such as some text or
* spreadsheet cells) that are affected by a boolean setting, and the
* current values in that range are inconsistent, you may want to
* display the check in an “in between” state. This function turns on
* “in between” display. Normally you would turn off the inconsistent
* state again if the user explicitly selects a setting. This has to be
* done manually, gtk_check_menu_item_set_inconsistent() only affects
* visual appearance, it doesn’t affect the semantics of the widget.
*
**/
void
gtk_check_menu_item_set_inconsistent (GtkCheckMenuItem *check_menu_item,
gboolean setting)
{
GtkCheckMenuItemPrivate *priv;
g_return_if_fail (GTK_IS_CHECK_MENU_ITEM (check_menu_item));
priv = check_menu_item->priv;
setting = setting != FALSE;
if (setting != priv->inconsistent)
{
priv->inconsistent = setting;
update_node_state (check_menu_item);
gtk_widget_queue_draw (GTK_WIDGET (check_menu_item));
g_object_notify (G_OBJECT (check_menu_item), "inconsistent");
}
}
/**
* gtk_check_menu_item_get_inconsistent:
* @check_menu_item: a #GtkCheckMenuItem
*
* Retrieves the value set by gtk_check_menu_item_set_inconsistent().
*
* Returns: %TRUE if inconsistent
**/
gboolean
gtk_check_menu_item_get_inconsistent (GtkCheckMenuItem *check_menu_item)
{
g_return_val_if_fail (GTK_IS_CHECK_MENU_ITEM (check_menu_item), FALSE);
return check_menu_item->priv->inconsistent;
}
/**
* gtk_check_menu_item_set_draw_as_radio:
* @check_menu_item: a #GtkCheckMenuItem
* @draw_as_radio: whether @check_menu_item is drawn like a #GtkRadioMenuItem
*
* Sets whether @check_menu_item is drawn like a #GtkRadioMenuItem
*
* Since: 2.4
**/
void
gtk_check_menu_item_set_draw_as_radio (GtkCheckMenuItem *check_menu_item,
gboolean draw_as_radio)
{
GtkCheckMenuItemPrivate *priv;
g_return_if_fail (GTK_IS_CHECK_MENU_ITEM (check_menu_item));
priv = check_menu_item->priv;
draw_as_radio = draw_as_radio != FALSE;
if (draw_as_radio != priv->draw_as_radio)
{
priv->draw_as_radio = draw_as_radio;
if (draw_as_radio)
gtk_css_node_set_name (priv->indicator_node, I_("radio"));
else
gtk_css_node_set_name (priv->indicator_node, I_("check"));
gtk_widget_queue_draw (GTK_WIDGET (check_menu_item));
g_object_notify (G_OBJECT (check_menu_item), "draw-as-radio");
}
}
/**
* gtk_check_menu_item_get_draw_as_radio:
* @check_menu_item: a #GtkCheckMenuItem
*
* Returns whether @check_menu_item looks like a #GtkRadioMenuItem
*
* Returns: Whether @check_menu_item looks like a #GtkRadioMenuItem
*
* Since: 2.4
**/
gboolean
gtk_check_menu_item_get_draw_as_radio (GtkCheckMenuItem *check_menu_item)
{
g_return_val_if_fail (GTK_IS_CHECK_MENU_ITEM (check_menu_item), FALSE);
return check_menu_item->priv->draw_as_radio;
}
static void
node_style_changed_cb (GtkCssNode *node,
GtkCssStyle *old_style,
GtkCssStyle *new_style,
GtkWidget *widget)
{
GtkBitmask *changes;
static GtkBitmask *affects_size = NULL;
if (G_UNLIKELY (affects_size == NULL))
affects_size = _gtk_css_style_property_get_mask_affecting (GTK_CSS_AFFECTS_SIZE | GTK_CSS_AFFECTS_CLIP);
changes = _gtk_bitmask_new ();
changes = gtk_css_style_add_difference (changes, old_style, new_style);
if (_gtk_bitmask_intersects (changes, affects_size))
gtk_widget_queue_resize (widget);
else
gtk_widget_queue_draw (widget);
_gtk_bitmask_free (changes);
}
static void
gtk_check_menu_item_init (GtkCheckMenuItem *check_menu_item)
{
GtkCheckMenuItemPrivate *priv;
GtkCssNode *widget_node;
priv = check_menu_item->priv = gtk_check_menu_item_get_instance_private (check_menu_item);
priv->active = FALSE;
widget_node = gtk_widget_get_css_node (GTK_WIDGET (check_menu_item));
priv->indicator_node = gtk_css_node_new ();
gtk_css_node_set_name (priv->indicator_node, I_("check"));
gtk_css_node_set_parent (priv->indicator_node, widget_node);
gtk_css_node_set_state (priv->indicator_node, gtk_css_node_get_state (widget_node));
g_signal_connect_object (priv->indicator_node, "style-changed", G_CALLBACK (node_style_changed_cb), check_menu_item, 0);
g_object_unref (priv->indicator_node);
}
static gint
gtk_check_menu_item_draw (GtkWidget *widget,
cairo_t *cr)
{
GtkCheckMenuItem *check_menu_item = GTK_CHECK_MENU_ITEM (widget);
if (GTK_WIDGET_CLASS (gtk_check_menu_item_parent_class)->draw)
GTK_WIDGET_CLASS (gtk_check_menu_item_parent_class)->draw (widget, cr);
if (GTK_CHECK_MENU_ITEM_GET_CLASS (check_menu_item)->draw_indicator)
GTK_CHECK_MENU_ITEM_GET_CLASS (check_menu_item)->draw_indicator (check_menu_item, cr);
return FALSE;
}
static void
gtk_check_menu_item_activate (GtkMenuItem *menu_item)
{
GtkCheckMenuItemPrivate *priv;
GtkCheckMenuItem *check_menu_item = GTK_CHECK_MENU_ITEM (menu_item);
priv = check_menu_item->priv;
priv->active = !priv->active;
gtk_check_menu_item_toggled (check_menu_item);
update_node_state (check_menu_item);
gtk_widget_queue_draw (GTK_WIDGET (check_menu_item));
GTK_MENU_ITEM_CLASS (gtk_check_menu_item_parent_class)->activate (menu_item);
g_object_notify (G_OBJECT (check_menu_item), "active");
}
static void
gtk_check_menu_item_state_flags_changed (GtkWidget *widget,
GtkStateFlags previous_state)
{
GtkCheckMenuItem *check_menu_item = GTK_CHECK_MENU_ITEM (widget);
update_node_state (check_menu_item);
GTK_WIDGET_CLASS (gtk_check_menu_item_parent_class)->state_flags_changed (widget, previous_state);
}
static void
gtk_check_menu_item_direction_changed (GtkWidget *widget,
GtkTextDirection previous_dir)
{
GtkCheckMenuItem *check_menu_item = GTK_CHECK_MENU_ITEM (widget);
GtkCheckMenuItemPrivate *priv = check_menu_item->priv;
GtkCssNode *widget_node, *node;
widget_node = gtk_widget_get_css_node (widget);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
{
gtk_css_node_remove_class (priv->indicator_node, g_quark_from_static_string (GTK_STYLE_CLASS_LEFT));
gtk_css_node_add_class (priv->indicator_node, g_quark_from_static_string (GTK_STYLE_CLASS_RIGHT));
node = gtk_css_node_get_last_child (widget_node);
if (node != priv->indicator_node)
gtk_css_node_insert_after (widget_node, priv->indicator_node, node);
}
else
{
gtk_css_node_add_class (priv->indicator_node, g_quark_from_static_string (GTK_STYLE_CLASS_LEFT));
gtk_css_node_remove_class (priv->indicator_node, g_quark_from_static_string (GTK_STYLE_CLASS_RIGHT));
node = gtk_css_node_get_first_child (widget_node);
if (node != priv->indicator_node)
gtk_css_node_insert_before (widget_node, priv->indicator_node, node);
}
GTK_WIDGET_CLASS (gtk_check_menu_item_parent_class)->direction_changed (widget, previous_dir);
}
static void
gtk_real_check_menu_item_draw_indicator (GtkCheckMenuItem *check_menu_item,
cairo_t *cr)
{
GtkCheckMenuItemPrivate *priv = check_menu_item->priv;
GtkWidget *widget;
gint x, y;
widget = GTK_WIDGET (check_menu_item);
if (gtk_widget_is_drawable (widget))
{
GtkAllocation allocation;
GtkStyleContext *context;
guint border_width;
guint offset;
guint toggle_size;
guint toggle_spacing;
guint horizontal_padding;
guint indicator_size;
GtkStateFlags state;
GtkBorder padding;
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
gtk_style_context_get_padding (context, state, &padding);
gtk_widget_get_allocation (widget, &allocation);
gtk_widget_style_get (widget,
"toggle-spacing", &toggle_spacing,
"horizontal-padding", &horizontal_padding,
"indicator-size", &indicator_size,
NULL);
toggle_size = GTK_MENU_ITEM (check_menu_item)->priv->toggle_size;
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
offset = border_width + padding.left + 2;
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
{
x = offset + horizontal_padding +
(toggle_size - toggle_spacing - indicator_size) / 2;
}
else
{
x = allocation.width -
offset - horizontal_padding - toggle_size + toggle_spacing +
(toggle_size - toggle_spacing - indicator_size) / 2;
}
y = (allocation.height - indicator_size) / 2;
gtk_style_context_save_to_node (context, priv->indicator_node);
if (priv->draw_as_radio)
gtk_render_option (context, cr, x, y,
indicator_size, indicator_size);
else
gtk_render_check (context, cr, x, y,
indicator_size, indicator_size);
gtk_style_context_restore (context);
}
}
static void
gtk_check_menu_item_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkCheckMenuItem *checkitem = GTK_CHECK_MENU_ITEM (object);
GtkCheckMenuItemPrivate *priv = checkitem->priv;
switch (prop_id)
{
case PROP_ACTIVE:
g_value_set_boolean (value, priv->active);
break;
case PROP_INCONSISTENT:
g_value_set_boolean (value, priv->inconsistent);
break;
case PROP_DRAW_AS_RADIO:
g_value_set_boolean (value, priv->draw_as_radio);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_check_menu_item_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkCheckMenuItem *checkitem = GTK_CHECK_MENU_ITEM (object);
switch (prop_id)
{
case PROP_ACTIVE:
gtk_check_menu_item_set_active (checkitem, g_value_get_boolean (value));
break;
case PROP_INCONSISTENT:
gtk_check_menu_item_set_inconsistent (checkitem, g_value_get_boolean (value));
break;
case PROP_DRAW_AS_RADIO:
gtk_check_menu_item_set_draw_as_radio (checkitem, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/* Private */
/*
* _gtk_check_menu_item_set_active:
* @check_menu_item: a #GtkCheckMenuItem
* @is_active: whether the action is active or not
*
* Sets the #GtkCheckMenuItem:active property directly. This function does
* not emit signals or notifications: it is left to the caller to do so.
*/
void
_gtk_check_menu_item_set_active (GtkCheckMenuItem *check_menu_item,
gboolean is_active)
{
GtkCheckMenuItemPrivate *priv = check_menu_item->priv;
priv->active = is_active;
update_node_state (check_menu_item);
}
|