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