1 /* GAIL - The GNOME Accessibility Implementation Library
2 * Copyright 2001, 2002, 2003 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.
22 #undef GTK_DISABLE_DEPRECATED
26 static void gail_menu_class_init (GailMenuClass *klass);
27 static void gail_menu_init (GailMenu *accessible);
29 static void gail_menu_real_initialize (AtkObject *obj,
32 static AtkObject* gail_menu_get_parent (AtkObject *accessible);
33 static gint gail_menu_get_index_in_parent (AtkObject *accessible);
35 G_DEFINE_TYPE (GailMenu, gail_menu, GAIL_TYPE_MENU_SHELL)
38 gail_menu_class_init (GailMenuClass *klass)
40 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
42 class->get_parent = gail_menu_get_parent;
43 class->get_index_in_parent = gail_menu_get_index_in_parent;
44 class->initialize = gail_menu_real_initialize;
48 gail_menu_init (GailMenu *accessible)
53 gail_menu_real_initialize (AtkObject *obj,
56 ATK_OBJECT_CLASS (gail_menu_parent_class)->initialize (obj, data);
58 obj->role = ATK_ROLE_MENU;
60 g_object_set_data (G_OBJECT (obj), "atk-component-layer",
61 GINT_TO_POINTER (ATK_LAYER_POPUP));
65 gail_menu_get_parent (AtkObject *accessible)
69 parent = accessible->accessible_parent;
73 g_return_val_if_fail (ATK_IS_OBJECT (parent), NULL);
77 GtkWidget *widget, *parent_widget;
79 widget = GTK_ACCESSIBLE (accessible)->widget;
87 g_return_val_if_fail (GTK_IS_MENU (widget), NULL);
90 * If the menu is attached to a menu item or a button (Gnome Menu)
91 * report the menu item as parent.
93 parent_widget = gtk_menu_get_attach_widget (GTK_MENU (widget));
95 if (!GTK_IS_MENU_ITEM (parent_widget) && !GTK_IS_BUTTON (parent_widget) && !GTK_IS_COMBO_BOX (parent_widget) && !GTK_IS_OPTION_MENU (parent_widget))
96 parent_widget = widget->parent;
98 if (parent_widget == NULL)
101 parent = gtk_widget_get_accessible (parent_widget);
102 atk_object_set_parent (accessible, parent);
108 gail_menu_get_index_in_parent (AtkObject *accessible)
112 widget = GTK_ACCESSIBLE (accessible)->widget;
121 g_return_val_if_fail (GTK_IS_MENU (widget), -1);
123 if (gtk_menu_get_attach_widget (GTK_MENU (widget)))
127 return ATK_OBJECT_CLASS (gail_menu_parent_class)->get_index_in_parent (accessible);