]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gailmenu.c
gail: No need to include modules/other in CFLAGS anymore
[~andy/gtk] / gtk / a11y / gailmenu.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 "gailmenu.h"
23
24 static void gail_menu_class_init (GailMenuClass *klass);
25 static void gail_menu_init       (GailMenu      *accessible);
26
27 static void       gail_menu_real_initialize     (AtkObject *obj,
28                                                  gpointer  data);
29
30 static AtkObject* gail_menu_get_parent          (AtkObject *accessible);
31 static gint       gail_menu_get_index_in_parent (AtkObject *accessible);
32
33 G_DEFINE_TYPE (GailMenu, gail_menu, GAIL_TYPE_MENU_SHELL)
34
35 static void
36 gail_menu_class_init (GailMenuClass *klass)
37 {
38   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
39
40   class->get_parent = gail_menu_get_parent;
41   class->get_index_in_parent = gail_menu_get_index_in_parent;
42   class->initialize = gail_menu_real_initialize;
43 }
44
45 static void
46 gail_menu_init (GailMenu *accessible)
47 {
48 }
49
50 static void
51 gail_menu_real_initialize (AtkObject *obj,
52                            gpointer  data)
53 {
54   ATK_OBJECT_CLASS (gail_menu_parent_class)->initialize (obj, data);
55
56   obj->role = ATK_ROLE_MENU;
57
58   g_object_set_data (G_OBJECT (obj), "atk-component-layer",
59                      GINT_TO_POINTER (ATK_LAYER_POPUP));
60 }
61
62 static AtkObject*
63 gail_menu_get_parent (AtkObject *accessible)
64 {
65   AtkObject *parent;
66
67   parent = accessible->accessible_parent;
68
69   if (parent != NULL)
70     {
71       g_return_val_if_fail (ATK_IS_OBJECT (parent), NULL);
72     }
73   else
74     {
75       GtkWidget *widget, *parent_widget;
76
77       widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
78       if (widget == NULL)
79         {
80           /*
81            * State is defunct
82            */
83           return NULL;
84         }
85       g_return_val_if_fail (GTK_IS_MENU (widget), NULL);
86
87       /*
88        * If the menu is attached to a menu item or a button (Gnome Menu)
89        * report the menu item as parent.
90        */
91       parent_widget = gtk_menu_get_attach_widget (GTK_MENU (widget));
92
93       if (!GTK_IS_MENU_ITEM (parent_widget) && !GTK_IS_BUTTON (parent_widget) && !GTK_IS_COMBO_BOX (parent_widget))
94         parent_widget = gtk_widget_get_parent (widget);
95
96       if (parent_widget == NULL)
97         return NULL;
98
99       parent = gtk_widget_get_accessible (parent_widget);
100       atk_object_set_parent (accessible, parent);
101     }
102   return parent;
103 }
104
105 static gint
106 gail_menu_get_index_in_parent (AtkObject *accessible)
107 {
108   GtkWidget *widget;
109
110   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
111
112   if (widget == NULL)
113     {
114       /*
115        * State is defunct
116        */
117       return -1;
118     }
119   g_return_val_if_fail (GTK_IS_MENU (widget), -1);
120
121   if (gtk_menu_get_attach_widget (GTK_MENU (widget)))
122     {
123       return 0;
124     }
125   return ATK_OBJECT_CLASS (gail_menu_parent_class)->get_index_in_parent (accessible);
126 }