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