]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtkmenuaccessible.c
542ce98c0c185c436395ce2dc5aae6d5b0071192
[~andy/gtk] / gtk / a11y / gtkmenuaccessible.c
1 /* GAIL - The GNOME Accessibility Implementation Library
2  * Copyright 2001, 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 "config.h"
21
22 #include "gtkmenuaccessible.h"
23
24 #include <gtk/gtk.h>
25
26 G_DEFINE_TYPE (GtkMenuAccessible, _gtk_menu_accessible, GTK_TYPE_MENU_SHELL_ACCESSIBLE)
27
28 static void
29 gtk_menu_accessible_initialize (AtkObject *obj,
30                                 gpointer   data)
31 {
32   ATK_OBJECT_CLASS (_gtk_menu_accessible_parent_class)->initialize (obj, data);
33
34   obj->role = ATK_ROLE_MENU;
35
36   GTK_WIDGET_ACCESSIBLE (obj)->layer = ATK_LAYER_POPUP;
37 }
38
39 static AtkObject *
40 gtk_menu_accessible_get_parent (AtkObject *accessible)
41 {
42   AtkObject *parent;
43   GtkWidget *widget, *parent_widget;
44
45   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
46   if (widget == NULL)
47     return NULL;
48
49   parent = accessible->accessible_parent;
50   if (parent != NULL)
51     return parent;
52
53   /* If the menu is attached to a menu item or a button (Gnome Menu)
54    * report the menu item as parent.
55    */
56   parent_widget = gtk_menu_get_attach_widget (GTK_MENU (widget));
57
58   if (!GTK_IS_MENU_ITEM (parent_widget) &&
59       !GTK_IS_BUTTON (parent_widget) &&
60       !GTK_IS_COMBO_BOX (parent_widget))
61     parent_widget = gtk_widget_get_parent (widget);
62
63   if (parent_widget == NULL)
64     return NULL;
65
66   parent = gtk_widget_get_accessible (parent_widget);
67   atk_object_set_parent (accessible, parent);
68
69   return parent;
70 }
71
72 static gint
73 gtk_menu_accessible_get_index_in_parent (AtkObject *accessible)
74 {
75   GtkWidget *widget;
76
77   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
78   if (widget == NULL)
79     return -1;
80
81   if (gtk_menu_get_attach_widget (GTK_MENU (widget)))
82     return 0;
83
84   return ATK_OBJECT_CLASS (_gtk_menu_accessible_parent_class)->get_index_in_parent (accessible);
85 }
86
87 static void
88 _gtk_menu_accessible_class_init (GtkMenuAccessibleClass *klass)
89 {
90   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
91
92   class->get_parent = gtk_menu_accessible_get_parent;
93   class->get_index_in_parent = gtk_menu_accessible_get_index_in_parent;
94   class->initialize = gtk_menu_accessible_initialize;
95 }
96
97 static void
98 _gtk_menu_accessible_init (GtkMenuAccessible *accessible)
99 {
100 }