1 | /* GAIL - The GNOME Accessibility Implementation Library |
---|
2 | * Copyright 2002, 2003 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, write to the |
---|
16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
17 | * Boston, MA 02111-1307, USA. |
---|
18 | */ |
---|
19 | |
---|
20 | #include <string.h> |
---|
21 | #include <gtk/gtk.h> |
---|
22 | #include "gailcheckmenuitem.h" |
---|
23 | #include "gailchecksubmenuitem.h" |
---|
24 | |
---|
25 | static void gail_check_menu_item_class_init (GailCheckMenuItemClass *klass); |
---|
26 | |
---|
27 | static void gail_check_menu_item_toggled_gtk (GtkWidget *widget); |
---|
28 | |
---|
29 | static void gail_check_menu_item_real_notify_gtk (GObject *obj, |
---|
30 | GParamSpec *pspec); |
---|
31 | |
---|
32 | static void gail_check_menu_item_real_initialize (AtkObject *obj, |
---|
33 | gpointer data); |
---|
34 | |
---|
35 | static AtkStateSet* gail_check_menu_item_ref_state_set (AtkObject *accessible); |
---|
36 | |
---|
37 | static GailMenuItemClass *parent_class = NULL; |
---|
38 | |
---|
39 | GType |
---|
40 | gail_check_menu_item_get_type (void) |
---|
41 | { |
---|
42 | static GType type = 0; |
---|
43 | |
---|
44 | if (!type) |
---|
45 | { |
---|
46 | static const GTypeInfo tinfo = |
---|
47 | { |
---|
48 | sizeof (GailCheckMenuItemClass), |
---|
49 | (GBaseInitFunc) NULL, /* base init */ |
---|
50 | (GBaseFinalizeFunc) NULL, /* base finalize */ |
---|
51 | (GClassInitFunc) gail_check_menu_item_class_init, /* class init */ |
---|
52 | (GClassFinalizeFunc) NULL, /* class finalize */ |
---|
53 | NULL, /* class data */ |
---|
54 | sizeof (GailCheckMenuItem), /* instance size */ |
---|
55 | 0, /* nb preallocs */ |
---|
56 | (GInstanceInitFunc) NULL, /* instance init */ |
---|
57 | NULL /* value table */ |
---|
58 | }; |
---|
59 | |
---|
60 | type = g_type_register_static (GAIL_TYPE_MENU_ITEM, |
---|
61 | "GailCheckMenuItem", &tinfo, 0); |
---|
62 | } |
---|
63 | |
---|
64 | return type; |
---|
65 | } |
---|
66 | |
---|
67 | static void |
---|
68 | gail_check_menu_item_class_init (GailCheckMenuItemClass *klass) |
---|
69 | { |
---|
70 | GailWidgetClass *widget_class; |
---|
71 | AtkObjectClass *class = ATK_OBJECT_CLASS (klass); |
---|
72 | |
---|
73 | widget_class = (GailWidgetClass*)klass; |
---|
74 | widget_class->notify_gtk = gail_check_menu_item_real_notify_gtk; |
---|
75 | |
---|
76 | parent_class = g_type_class_peek_parent (klass); |
---|
77 | |
---|
78 | class->ref_state_set = gail_check_menu_item_ref_state_set; |
---|
79 | class->initialize = gail_check_menu_item_real_initialize; |
---|
80 | } |
---|
81 | |
---|
82 | AtkObject* |
---|
83 | gail_check_menu_item_new (GtkWidget *widget) |
---|
84 | { |
---|
85 | GObject *object; |
---|
86 | AtkObject *accessible; |
---|
87 | |
---|
88 | g_return_val_if_fail (GTK_IS_CHECK_MENU_ITEM (widget), NULL); |
---|
89 | |
---|
90 | if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget))) |
---|
91 | return gail_check_sub_menu_item_new (widget); |
---|
92 | |
---|
93 | object = g_object_new (GAIL_TYPE_CHECK_MENU_ITEM, NULL); |
---|
94 | |
---|
95 | accessible = ATK_OBJECT (object); |
---|
96 | atk_object_initialize (accessible, widget); |
---|
97 | |
---|
98 | return accessible; |
---|
99 | } |
---|
100 | |
---|
101 | static void |
---|
102 | gail_check_menu_item_real_initialize (AtkObject *obj, |
---|
103 | gpointer data) |
---|
104 | { |
---|
105 | ATK_OBJECT_CLASS (parent_class)->initialize (obj, data); |
---|
106 | |
---|
107 | g_signal_connect (data, |
---|
108 | "toggled", |
---|
109 | G_CALLBACK (gail_check_menu_item_toggled_gtk), |
---|
110 | NULL); |
---|
111 | |
---|
112 | obj->role = ATK_ROLE_CHECK_MENU_ITEM; |
---|
113 | } |
---|
114 | |
---|
115 | static void |
---|
116 | gail_check_menu_item_toggled_gtk (GtkWidget *widget) |
---|
117 | { |
---|
118 | AtkObject *accessible; |
---|
119 | GtkCheckMenuItem *check_menu_item; |
---|
120 | |
---|
121 | check_menu_item = GTK_CHECK_MENU_ITEM (widget); |
---|
122 | |
---|
123 | accessible = gtk_widget_get_accessible (widget); |
---|
124 | atk_object_notify_state_change (accessible, ATK_STATE_CHECKED, |
---|
125 | check_menu_item->active); |
---|
126 | } |
---|
127 | |
---|
128 | static AtkStateSet* |
---|
129 | gail_check_menu_item_ref_state_set (AtkObject *accessible) |
---|
130 | { |
---|
131 | AtkStateSet *state_set; |
---|
132 | GtkCheckMenuItem *check_menu_item; |
---|
133 | GtkWidget *widget; |
---|
134 | |
---|
135 | state_set = ATK_OBJECT_CLASS (parent_class)->ref_state_set (accessible); |
---|
136 | widget = GTK_ACCESSIBLE (accessible)->widget; |
---|
137 | |
---|
138 | if (widget == NULL) |
---|
139 | return state_set; |
---|
140 | |
---|
141 | check_menu_item = GTK_CHECK_MENU_ITEM (widget); |
---|
142 | |
---|
143 | if (gtk_check_menu_item_get_active (check_menu_item)) |
---|
144 | atk_state_set_add_state (state_set, ATK_STATE_CHECKED); |
---|
145 | |
---|
146 | if (gtk_check_menu_item_get_inconsistent (check_menu_item)) |
---|
147 | atk_state_set_remove_state (state_set, ATK_STATE_ENABLED); |
---|
148 | |
---|
149 | return state_set; |
---|
150 | } |
---|
151 | |
---|
152 | static void |
---|
153 | gail_check_menu_item_real_notify_gtk (GObject *obj, |
---|
154 | GParamSpec *pspec) |
---|
155 | { |
---|
156 | GtkCheckMenuItem *check_menu_item = GTK_CHECK_MENU_ITEM (obj); |
---|
157 | AtkObject *atk_obj; |
---|
158 | |
---|
159 | atk_obj = gtk_widget_get_accessible (GTK_WIDGET (check_menu_item)); |
---|
160 | |
---|
161 | if (strcmp (pspec->name, "inconsistent") == 0) |
---|
162 | atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, |
---|
163 | !gtk_check_menu_item_get_inconsistent (check_menu_item)); |
---|
164 | else |
---|
165 | GAIL_WIDGET_CLASS (parent_class)->notify_gtk (obj, pspec); |
---|
166 | } |
---|