]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtkmenushellaccessible.c
Add accessibility for GtkLevelBar and value test
[~andy/gtk] / gtk / a11y / gtkmenushellaccessible.c
1 /* GTK+ - accessibility implementations
2  * Copyright 2001 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 <gtk/gtk.h>
21 #include "gtkmenushellaccessible.h"
22
23
24 static void atk_selection_interface_init (AtkSelectionIface *iface);
25
26 G_DEFINE_TYPE_WITH_CODE (GtkMenuShellAccessible, gtk_menu_shell_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
27                          G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init))
28
29 static void
30 gtk_menu_shell_accessible_initialize (AtkObject *accessible,
31                                       gpointer   data)
32 {
33   ATK_OBJECT_CLASS (gtk_menu_shell_accessible_parent_class)->initialize (accessible, data);
34
35   accessible->role = ATK_ROLE_UNKNOWN;
36 }
37
38 static void
39 gtk_menu_shell_accessible_class_init (GtkMenuShellAccessibleClass *klass)
40 {
41   AtkObjectClass *atk_object_class = ATK_OBJECT_CLASS (klass);
42
43   atk_object_class->initialize = gtk_menu_shell_accessible_initialize;
44 }
45
46 static void
47 gtk_menu_shell_accessible_init (GtkMenuShellAccessible *menu_shell)
48 {
49 }
50
51 static gboolean
52 gtk_menu_shell_accessible_add_selection (AtkSelection *selection,
53                                          gint          i)
54 {
55   GList *kids;
56   GtkWidget *item;
57   guint length;
58   GtkWidget *widget;
59
60   widget =  gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
61   if (widget == NULL)
62     return FALSE;
63
64   kids = gtk_container_get_children (GTK_CONTAINER (widget));
65   length = g_list_length (kids);
66   if (i < 0 || i > length)
67     {
68       g_list_free (kids);
69       return FALSE;
70     }
71
72   item = g_list_nth_data (kids, i);
73   g_list_free (kids);
74   g_return_val_if_fail (GTK_IS_MENU_ITEM (item), FALSE);
75   gtk_menu_shell_select_item (GTK_MENU_SHELL (widget), item);
76   return TRUE;
77 }
78
79 static gboolean
80 gtk_menu_shell_accessible_clear_selection (AtkSelection *selection)
81 {
82   GtkMenuShell *shell;
83   GtkWidget *widget;
84
85   widget =  gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
86   if (widget == NULL)
87     return FALSE;
88
89   shell = GTK_MENU_SHELL (widget);
90
91   gtk_menu_shell_deselect (shell);
92   return TRUE;
93 }
94
95 static AtkObject *
96 gtk_menu_shell_accessible_ref_selection (AtkSelection *selection,
97                                          gint          i)
98 {
99   GtkMenuShell *shell;
100   AtkObject *obj;
101   GtkWidget *widget;
102   GtkWidget *item;
103
104   widget =  gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
105   if (widget == NULL)
106     return NULL;
107
108   if (i != 0)
109     return NULL;
110
111   shell = GTK_MENU_SHELL (widget);
112
113   item = gtk_menu_shell_get_selected_item (shell);
114   if (item != NULL)
115     {
116       obj = gtk_widget_get_accessible (item);
117       g_object_ref (obj);
118       return obj;
119     }
120   return NULL;
121 }
122
123 static gint
124 gtk_menu_shell_accessible_get_selection_count (AtkSelection *selection)
125 {
126   GtkMenuShell *shell;
127   GtkWidget *widget;
128
129   widget =  gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
130   if (widget == NULL)
131     return 0;
132
133   shell = GTK_MENU_SHELL (widget);
134
135   if (gtk_menu_shell_get_selected_item (shell) != NULL)
136     return 1;
137
138   return 0;
139 }
140
141 static gboolean
142 gtk_menu_shell_accessible_is_child_selected (AtkSelection *selection,
143                                              gint          i)
144 {
145   GtkMenuShell *shell;
146   GList *kids;
147   gint j;
148   GtkWidget *widget;
149   GtkWidget *item;
150
151   widget =  gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
152   if (widget == NULL)
153     return FALSE;
154
155   shell = GTK_MENU_SHELL (widget);
156   item = gtk_menu_shell_get_selected_item (shell);
157   if (item == NULL)
158     return FALSE;
159
160   kids = gtk_container_get_children (GTK_CONTAINER (shell));
161   j = g_list_index (kids, item);
162   g_list_free (kids);
163
164   return j==i;
165 }
166
167 static gboolean
168 gtk_menu_shell_accessible_remove_selection (AtkSelection *selection,
169                                             gint          i)
170 {
171   GtkMenuShell *shell;
172   GtkWidget *widget;
173   GtkWidget *item;
174
175   widget =  gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
176   if (widget == NULL)
177     return FALSE;
178
179   if (i != 0)
180     return FALSE;
181
182   shell = GTK_MENU_SHELL (widget);
183
184   item = gtk_menu_shell_get_selected_item (shell);
185   if (item && gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)))
186     gtk_menu_shell_deselect (shell);
187   return TRUE;
188 }
189
190 static void
191 atk_selection_interface_init (AtkSelectionIface *iface)
192 {
193   iface->add_selection = gtk_menu_shell_accessible_add_selection;
194   iface->clear_selection = gtk_menu_shell_accessible_clear_selection;
195   iface->ref_selection = gtk_menu_shell_accessible_ref_selection;
196   iface->get_selection_count = gtk_menu_shell_accessible_get_selection_count;
197   iface->is_child_selected = gtk_menu_shell_accessible_is_child_selected;
198   iface->remove_selection = gtk_menu_shell_accessible_remove_selection;
199 }