1 /* GAIL - The GNOME Accessibility Implementation Library
2 * Copyright 2001 Sun Microsystems Inc.
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.
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.
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.
23 #include "gailmenushell.h"
25 static void gail_menu_shell_class_init (GailMenuShellClass *klass);
26 static void gail_menu_shell_init (GailMenuShell *menu_shell);
27 static void gail_menu_shell_initialize (AtkObject *accessible,
29 static void atk_selection_interface_init (AtkSelectionIface *iface);
30 static gboolean gail_menu_shell_add_selection (AtkSelection *selection,
32 static gboolean gail_menu_shell_clear_selection (AtkSelection *selection);
33 static AtkObject* gail_menu_shell_ref_selection (AtkSelection *selection,
35 static gint gail_menu_shell_get_selection_count (AtkSelection *selection);
36 static gboolean gail_menu_shell_is_child_selected (AtkSelection *selection,
38 static gboolean gail_menu_shell_remove_selection (AtkSelection *selection,
41 G_DEFINE_TYPE_WITH_CODE (GailMenuShell, gail_menu_shell, GAIL_TYPE_CONTAINER,
42 G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init))
45 gail_menu_shell_class_init (GailMenuShellClass *klass)
47 AtkObjectClass *atk_object_class = ATK_OBJECT_CLASS (klass);
49 atk_object_class->initialize = gail_menu_shell_initialize;
53 gail_menu_shell_init (GailMenuShell *menu_shell)
58 gail_menu_shell_initialize (AtkObject *accessible,
61 ATK_OBJECT_CLASS (gail_menu_shell_parent_class)->initialize (accessible, data);
63 if (GTK_IS_MENU_BAR (data))
64 accessible->role = ATK_ROLE_MENU_BAR;
67 * Accessible object for Menu is created in gailmenu.c
69 accessible->role = ATK_ROLE_UNKNOWN;
73 atk_selection_interface_init (AtkSelectionIface *iface)
75 iface->add_selection = gail_menu_shell_add_selection;
76 iface->clear_selection = gail_menu_shell_clear_selection;
77 iface->ref_selection = gail_menu_shell_ref_selection;
78 iface->get_selection_count = gail_menu_shell_get_selection_count;
79 iface->is_child_selected = gail_menu_shell_is_child_selected;
80 iface->remove_selection = gail_menu_shell_remove_selection;
82 * select_all_selection does not make sense for a menu_shell
83 * so no implementation is provided.
88 gail_menu_shell_add_selection (AtkSelection *selection,
96 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
99 /* State is defunct */
103 kids = gtk_container_get_children (GTK_CONTAINER (widget));
104 length = g_list_length (kids);
105 if (i < 0 || i > length)
111 item = g_list_nth_data (kids, i);
113 g_return_val_if_fail (GTK_IS_MENU_ITEM(item), FALSE);
114 gtk_menu_shell_select_item (GTK_MENU_SHELL (widget), item);
119 gail_menu_shell_clear_selection (AtkSelection *selection)
124 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
127 /* State is defunct */
131 shell = GTK_MENU_SHELL (widget);
133 gtk_menu_shell_deselect (shell);
138 gail_menu_shell_ref_selection (AtkSelection *selection,
149 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
152 /* State is defunct */
156 shell = GTK_MENU_SHELL (widget);
158 item = gtk_menu_shell_get_selected_item (shell);
161 obj = gtk_widget_get_accessible (item);
172 gail_menu_shell_get_selection_count (AtkSelection *selection)
177 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
180 /* State is defunct */
184 shell = GTK_MENU_SHELL (widget);
187 * Identifies the currently selected menu item
189 if (gtk_menu_shell_get_selected_item (shell) == NULL)
200 gail_menu_shell_is_child_selected (AtkSelection *selection,
209 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
212 /* State is defunct */
216 shell = GTK_MENU_SHELL (widget);
217 item = gtk_menu_shell_get_selected_item (shell);
221 kids = gtk_container_get_children (GTK_CONTAINER (shell));
222 j = g_list_index (kids, item);
229 gail_menu_shell_remove_selection (AtkSelection *selection,
239 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
242 /* State is defunct */
246 shell = GTK_MENU_SHELL (widget);
248 item = gtk_menu_shell_get_selected_item (shell);
249 if (item && gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)))
252 * Menu item contains a menu and it is the selected menu item
255 gtk_menu_shell_deselect (shell);