diff --git a/gtk/a11y/Makefile.am b/gtk/a11y/Makefile.am index 8b29ae7a5a..b32099ef4c 100644 --- a/gtk/a11y/Makefile.am +++ b/gtk/a11y/Makefile.am @@ -31,6 +31,7 @@ gtka11y_c_sources = \ gtklistboxrowaccessible.c \ gtklockbuttonaccessible.c \ gtkmenuaccessible.c \ + gtkmenubuttonaccessible.c \ gtkmenushellaccessible.c \ gtkmenuitemaccessible.c \ gtknotebookaccessible.c \ @@ -82,6 +83,7 @@ gtka11yinclude_HEADERS = \ gtklistboxrowaccessible.h \ gtklockbuttonaccessible.h \ gtkmenuaccessible.h \ + gtkmenubuttonaccessible.h \ gtkmenuitemaccessible.h \ gtkmenushellaccessible.h \ gtknotebookaccessible.h \ diff --git a/gtk/a11y/gtkmenubuttonaccessible.c b/gtk/a11y/gtkmenubuttonaccessible.c new file mode 100644 index 0000000000..c5c897704c --- /dev/null +++ b/gtk/a11y/gtkmenubuttonaccessible.c @@ -0,0 +1,100 @@ +/* GTK+ - accessibility implementations + * Copyright 2001 Sun Microsystems Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "config.h" + +#include +#include "gtkmenubuttonaccessible.h" + + +G_DEFINE_TYPE (GtkMenuButtonAccessible, gtk_menu_button_accessible, GTK_TYPE_TOGGLE_BUTTON_ACCESSIBLE) + +static void +gtk_menu_button_accessible_initialize (AtkObject *accessible, + gpointer data) +{ + ATK_OBJECT_CLASS (gtk_menu_button_accessible_parent_class)->initialize (accessible, data); +} + +static gint +gtk_menu_button_accessible_get_n_children (AtkObject* obj) +{ + GtkWidget *widget; + GtkWidget *submenu; + gint count = 0; + + widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); + if (widget == NULL) + return count; + + submenu = gtk_menu_button_get_popup (GTK_MENU_BUTTON (widget)); + if (submenu) + { + GList *children; + + children = gtk_container_get_children (GTK_CONTAINER (submenu)); + count = g_list_length (children); + g_list_free (children); + } + return count; +} + +static AtkObject * +gtk_menu_button_accessible_ref_child (AtkObject *obj, + gint i) +{ + AtkObject *accessible; + GtkWidget *widget; + GtkWidget *submenu; + + widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); + if (widget == NULL) + return NULL; + + submenu = gtk_menu_button_get_popup (GTK_MENU_BUTTON (widget)); + if (submenu) + { + GList *children; + GList *tmp_list; + + children = gtk_container_get_children (GTK_CONTAINER (submenu)); + tmp_list = g_list_nth (children, i); + if (tmp_list) + { + accessible = gtk_widget_get_accessible (GTK_WIDGET (tmp_list->data)); + g_object_ref (accessible); + } + g_list_free (children); + } + + return accessible; +} + +static void +gtk_menu_button_accessible_class_init (GtkMenuButtonAccessibleClass *klass) +{ + AtkObjectClass *class = ATK_OBJECT_CLASS (klass); + + class->initialize = gtk_menu_button_accessible_initialize; + class->get_n_children = gtk_menu_button_accessible_get_n_children; + class->ref_child = gtk_menu_button_accessible_ref_child; +} + +static void +gtk_menu_button_accessible_init (GtkMenuButtonAccessible *menu_button) +{ +} diff --git a/gtk/a11y/gtkmenubuttonaccessible.h b/gtk/a11y/gtkmenubuttonaccessible.h new file mode 100644 index 0000000000..059f209fc9 --- /dev/null +++ b/gtk/a11y/gtkmenubuttonaccessible.h @@ -0,0 +1,57 @@ +/* GTK+ - accessibility implementations + * Copyright 2001 Sun Microsystems Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library. If not, see . + */ + +#ifndef __GTK_MENU_BUTTON_ACCESSIBLE_H__ +#define __GTK_MENU_BUTTON_ACCESSIBLE_H__ + +#if !defined (__GTK_A11Y_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only can be included directly." +#endif + +#include + +G_BEGIN_DECLS + +#define GTK_TYPE_MENU_BUTTON_ACCESSIBLE (gtk_menu_button_accessible_get_type ()) +#define GTK_MENU_BUTTON_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_MENU_BUTTON_ACCESSIBLE, GtkMenuButtonAccessible)) +#define GTK_MENU_BUTTON_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_MENU_BUTTON_ACCESSIBLE, GtkMenuButtonAccessibleClass)) +#define GTK_IS_MENU_BUTTON_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_MENU_BUTTON_ACCESSIBLE)) +#define GTK_IS_MENU_BUTTON_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_MENU_BUTTON_ACCESSIBLE)) +#define GTK_MENU_BUTTON_ACCESSIBLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_MENU_BUTTON_ACCESSIBLE, GtkMenuButtonAccessibleClass)) + +typedef struct _GtkMenuButtonAccessible GtkMenuButtonAccessible; +typedef struct _GtkMenuButtonAccessibleClass GtkMenuButtonAccessibleClass; +typedef struct _GtkMenuButtonAccessiblePrivate GtkMenuButtonAccessiblePrivate; + +struct _GtkMenuButtonAccessible +{ + GtkToggleButtonAccessible parent; + + GtkMenuButtonAccessiblePrivate *priv; +}; + +struct _GtkMenuButtonAccessibleClass +{ + GtkToggleButtonAccessibleClass parent_class; +}; + +GDK_AVAILABLE_IN_ALL +GType gtk_menu_button_accessible_get_type (void); + +G_END_DECLS + +#endif /* __GTK_MENU_BUTTON_ACCESSIBLE_H__ */ diff --git a/gtk/gtk-a11y.h b/gtk/gtk-a11y.h index 8e395a6486..6be98e6c71 100644 --- a/gtk/gtk-a11y.h +++ b/gtk/gtk-a11y.h @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include diff --git a/gtk/gtkmenubutton.c b/gtk/gtkmenubutton.c index 2ccb26e0ac..bef59c4fb7 100644 --- a/gtk/gtkmenubutton.c +++ b/gtk/gtkmenubutton.c @@ -149,6 +149,7 @@ #include "gtkwindow.h" #include "gtkmain.h" #include "gtkaccessible.h" +#include "a11y/gtkmenubuttonaccessible.h" #include "gtkprivate.h" #include "gtkintl.h" @@ -562,6 +563,8 @@ gtk_menu_button_class_init (GtkMenuButtonClass *klass) GTK_TYPE_ARROW_TYPE, GTK_ARROW_DOWN, G_PARAM_READWRITE)); + + gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_MENU_BUTTON_ACCESSIBLE); } static void diff --git a/testsuite/a11y/menubutton.txt b/testsuite/a11y/menubutton.txt index d61eb723cf..27a20fdabc 100644 --- a/testsuite/a11y/menubutton.txt +++ b/testsuite/a11y/menubutton.txt @@ -22,3 +22,18 @@ window1 action 0 name: click action 0 description: Clicks the button + imagemenuitem + "menu item" + parent: menu + index: 0 + name: New + state: enabled selectable sensitive visible + toolkit: gtk + + layer: popup + alpha: 1 + + action 0 name: click + action 0 description: Clicks the menuitem + action 0 keybinding: n;; +