Debian Codegraph @

gtk/a11y/gtkcheckmenuitemaccessible.c

raw
1 /* GTK+ - accessibility implementations
2 * Copyright 2002 Sun Microsystems Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "config.h"
19
20 #include <string.h>
21 #include <gtk/gtk.h>
22 #include "gtkcheckmenuitemaccessible.h"
23
24
25 G_DEFINE_TYPE (GtkCheckMenuItemAccessible, gtk_check_menu_item_accessible, GTK_TYPE_MENU_ITEM_ACCESSIBLE)
26
27 static void
28 toggled_cb (GtkWidget *widget)
29 {
30 AtkObject *accessible;
31 GtkCheckMenuItem *check_menu_item;
32 gboolean active;
33
34 check_menu_item = GTK_CHECK_MENU_ITEM (widget);
35 active = gtk_check_menu_item_get_active (check_menu_item);
36
37 accessible = gtk_widget_get_accessible (widget);
38 atk_object_notify_state_change (accessible, ATK_STATE_CHECKED, active);
39 }
40
41 static void
42 gtk_check_menu_item_accessible_initialize (AtkObject *obj,
43 gpointer data)
44 {
45 ATK_OBJECT_CLASS (gtk_check_menu_item_accessible_parent_class)->initialize (obj, data);
46
47 g_signal_connect (data, "toggled", G_CALLBACK (toggled_cb), NULL);
48
49 obj->role = ATK_ROLE_CHECK_MENU_ITEM;
50 }
51
52 static AtkStateSet *
53 gtk_check_menu_item_accessible_ref_state_set (AtkObject *accessible)
54 {
55 AtkStateSet *state_set;
56 GtkCheckMenuItem *check_menu_item;
57 GtkWidget *widget;
58
59 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
60 if (widget == NULL)
61 return NULL;
62
63 state_set = ATK_OBJECT_CLASS (gtk_check_menu_item_accessible_parent_class)->ref_state_set (accessible);
64
65 check_menu_item = GTK_CHECK_MENU_ITEM (widget);
66
67 if (gtk_check_menu_item_get_active (check_menu_item))
68 atk_state_set_add_state (state_set, ATK_STATE_CHECKED);
69
70 if (gtk_check_menu_item_get_inconsistent (check_menu_item))
71 {
72 atk_state_set_remove_state (state_set, ATK_STATE_ENABLED);
73 atk_state_set_add_state (state_set, ATK_STATE_INDETERMINATE);
74 }
75
76 return state_set;
77 }
78
79 static void
80 gtk_check_menu_item_accessible_notify_gtk (GObject *obj,
81 GParamSpec *pspec)
82 {
83 GtkCheckMenuItem *check_menu_item = GTK_CHECK_MENU_ITEM (obj);
84 AtkObject *atk_obj;
85 gboolean sensitive;
86 gboolean inconsistent;
87 gboolean active;
88
89 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (check_menu_item));
90 sensitive = gtk_widget_get_sensitive (GTK_WIDGET (check_menu_item));
91 inconsistent = gtk_check_menu_item_get_inconsistent (check_menu_item);
92 active = gtk_check_menu_item_get_active (check_menu_item);
93
94 if (strcmp (pspec->name, "inconsistent") == 0)
95 {
96 atk_object_notify_state_change (atk_obj, ATK_STATE_INDETERMINATE, inconsistent);
97 atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, (sensitive && !inconsistent));
98 }
99 else if (strcmp (pspec->name, "sensitive") == 0)
100 {
101 /* Need to override gailwidget behavior of notifying for ENABLED */
102 atk_object_notify_state_change (atk_obj, ATK_STATE_SENSITIVE, sensitive);
103 atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, (sensitive && !inconsistent));
104 }
105 else if (strcmp (pspec->name, "active") == 0)
106 {
107 atk_object_notify_state_change (atk_obj, ATK_STATE_CHECKED, active);
108 }
109 else
110 GTK_WIDGET_ACCESSIBLE_CLASS (gtk_check_menu_item_accessible_parent_class)->notify_gtk (obj, pspec);
111 }
112
113 static void
114 gtk_check_menu_item_accessible_class_init (GtkCheckMenuItemAccessibleClass *klass)
115 {
116 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
117 GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
118
119 widget_class->notify_gtk = gtk_check_menu_item_accessible_notify_gtk;
120
121 class->ref_state_set = gtk_check_menu_item_accessible_ref_state_set;
122 class->initialize = gtk_check_menu_item_accessible_initialize;
123 }
124
125 static void
126 gtk_check_menu_item_accessible_init (GtkCheckMenuItemAccessible *item)
127 {
128 }