[gtk+/quartz-integration: 516/563] Convert GailMenu to GtkMenuAccessible



commit c9c2cec43848de28b331e98b2782e8b19663a403
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jul 1 22:30:54 2011 -0400

    Convert GailMenu to GtkMenuAccessible

 gtk/a11y/Makefile.am         |    4 +-
 gtk/a11y/gail.c              |    3 -
 gtk/a11y/gailmenu.c          |  126 ------------------------------------------
 gtk/a11y/gailmenu.h          |   51 -----------------
 gtk/a11y/gtkmenuaccessible.c |  100 +++++++++++++++++++++++++++++++++
 gtk/a11y/gtkmenuaccessible.h |   51 +++++++++++++++++
 gtk/gtkmenu.c                |    3 +
 tests/a11y/pickers.txt       |   16 +++---
 8 files changed, 164 insertions(+), 190 deletions(-)
---
diff --git a/gtk/a11y/Makefile.am b/gtk/a11y/Makefile.am
index 7007fa6..5a9724b 100644
--- a/gtk/a11y/Makefile.am
+++ b/gtk/a11y/Makefile.am
@@ -23,7 +23,7 @@ gail_c_sources =			\
 	gtklabelaccessible.c		\
 	gtklinkbuttonaccessible.c	\
 	gailmisc.c			\
-	gailmenu.c			\
+	gtkmenuaccessible.c		\
 	gailmenushell.c			\
 	gtkmenuitemaccessible.c		\
 	gtknotebookaccessible.c		\
@@ -75,7 +75,7 @@ gail_private_h_sources =		\
 	gtklabelaccessible.h		\
 	gtklinkbuttonaccessible.h	\
 	gailmisc.h			\
-	gailmenu.h			\
+	gtkmenuaccessible.h		\
 	gailmenushell.h			\
 	gtkmenuitemaccessible.h		\
 	gtknotebookaccessible.h		\
diff --git a/gtk/a11y/gail.c b/gtk/a11y/gail.c
index 354d814..1c2a54d 100644
--- a/gtk/a11y/gail.c
+++ b/gtk/a11y/gail.c
@@ -28,7 +28,6 @@
 #include "gailcontainer.h"
 #include "gailcontainercell.h"
 #include "gailimagecell.h"
-#include "gailmenu.h"
 #include "gailmenushell.h"
 #include "gailrenderercell.h"
 #include "gailtextcell.h"
@@ -83,7 +82,6 @@ static GQuark quark_focus_object = 0;
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_WIDGET, GailWidget, gail_widget, GTK_TYPE_WIDGET)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_CONTAINER, GailContainer, gail_container, GTK_TYPE_CONTAINER)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_MENU_SHELL, GailMenuShell, gail_menu_shell, GTK_TYPE_MENU_SHELL)
-GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_MENU, GailMenu, gail_menu, GTK_TYPE_MENU)
 GAIL_IMPLEMENT_FACTORY_WITH_FUNC_DUMMY (GAIL_TYPE_RENDERER_CELL, GailRendererCell, gail_renderer_cell, GTK_TYPE_CELL_RENDERER, gail_renderer_cell_new)
 GAIL_IMPLEMENT_FACTORY_WITH_FUNC_DUMMY (GAIL_TYPE_BOOLEAN_CELL, GailBooleanCell, gail_boolean_cell, GTK_TYPE_CELL_RENDERER_TOGGLE, gail_boolean_cell_new)
 GAIL_IMPLEMENT_FACTORY_WITH_FUNC_DUMMY (GAIL_TYPE_IMAGE_CELL, GailImageCell, gail_image_cell, GTK_TYPE_CELL_RENDERER_PIXBUF, gail_image_cell_new)
@@ -831,7 +829,6 @@ gail_accessibility_module_init (void)
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_WIDGET, gail_widget);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_CONTAINER, gail_container);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_MENU_BAR, gail_menu_shell);
-  GAIL_WIDGET_SET_FACTORY (GTK_TYPE_MENU, gail_menu);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_CELL_RENDERER_TEXT, gail_text_cell);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_CELL_RENDERER_TOGGLE, gail_boolean_cell);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_CELL_RENDERER_PIXBUF, gail_image_cell);
diff --git a/gtk/a11y/gtkmenuaccessible.c b/gtk/a11y/gtkmenuaccessible.c
new file mode 100644
index 0000000..1a16318
--- /dev/null
+++ b/gtk/a11y/gtkmenuaccessible.c
@@ -0,0 +1,100 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001, 2002, 2003 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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "gtkmenuaccessible.h"
+
+
+G_DEFINE_TYPE (GtkMenuAccessible, gtk_menu_accessible, GAIL_TYPE_MENU_SHELL)
+
+static void
+gtk_menu_accessible_initialize (AtkObject *obj,
+                                gpointer   data)
+{
+  ATK_OBJECT_CLASS (gtk_menu_accessible_parent_class)->initialize (obj, data);
+
+  obj->role = ATK_ROLE_MENU;
+
+  g_object_set_data (G_OBJECT (obj), "atk-component-layer",
+                     GINT_TO_POINTER (ATK_LAYER_POPUP));
+}
+
+static AtkObject *
+gtk_menu_accessible_get_parent (AtkObject *accessible)
+{
+  AtkObject *parent;
+  GtkWidget *widget, *parent_widget;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
+  if (widget == NULL)
+    return NULL;
+
+  parent = accessible->accessible_parent;
+  if (parent != NULL)
+    return parent;
+
+  /* If the menu is attached to a menu item or a button (Gnome Menu)
+   * report the menu item as parent.
+   */
+  parent_widget = gtk_menu_get_attach_widget (GTK_MENU (widget));
+
+  if (!GTK_IS_MENU_ITEM (parent_widget) &&
+      !GTK_IS_BUTTON (parent_widget) &&
+      !GTK_IS_COMBO_BOX (parent_widget))
+    parent_widget = gtk_widget_get_parent (widget);
+
+  if (parent_widget == NULL)
+    return NULL;
+
+  parent = gtk_widget_get_accessible (parent_widget);
+  atk_object_set_parent (accessible, parent);
+
+  return parent;
+}
+
+static gint
+gtk_menu_accessible_get_index_in_parent (AtkObject *accessible)
+{
+  GtkWidget *widget;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
+  if (widget == NULL)
+    return -1;
+
+  if (gtk_menu_get_attach_widget (GTK_MENU (widget)))
+    return 0;
+
+  return ATK_OBJECT_CLASS (gtk_menu_accessible_parent_class)->get_index_in_parent (accessible);
+}
+
+static void
+gtk_menu_accessible_class_init (GtkMenuAccessibleClass *klass)
+{
+  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
+
+  class->get_parent = gtk_menu_accessible_get_parent;
+  class->get_index_in_parent = gtk_menu_accessible_get_index_in_parent;
+  class->initialize = gtk_menu_accessible_initialize;
+}
+
+static void
+gtk_menu_accessible_init (GtkMenuAccessible *accessible)
+{
+}
diff --git a/gtk/a11y/gtkmenuaccessible.h b/gtk/a11y/gtkmenuaccessible.h
new file mode 100644
index 0000000..fe8eabe
--- /dev/null
+++ b/gtk/a11y/gtkmenuaccessible.h
@@ -0,0 +1,51 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * 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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GTK_MENU_ACCESSIBLE_H__
+#define __GTK_MENU_ACCESSIBLE_H__
+
+#include "gailmenushell.h"
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_MENU_ACCESSIBLE                          (gtk_menu_accessible_get_type ())
+#define GTK_MENU_ACCESSIBLE(obj)                          (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_MENU_ACCESSIBLE, GtkMenuAccessible))
+#define GTK_MENU_ACCESSIBLE_CLASS(klass)                  (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_MENU_ACCESSIBLE, GtkMenuAccessibleClass))
+#define GTK_IS_MENU_ACCESSIBLE(obj)                       (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_MENU_ACCESSIBLE))
+#define GTK_IS_MENU_ACCESSIBLE_CLASS(klass)               (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_MENU_ACCESSIBLE))
+#define GTK_MENU_ACCESSIBLE_GET_CLASS(obj)                (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_MENU_ACCESSIBLE, GtkMenuAccessibleClass))
+
+typedef struct _GtkMenuAccessible      GtkMenuAccessible;
+typedef struct _GtkMenuAccessibleClass GtkMenuAccessibleClass;
+
+struct _GtkMenuAccessible
+{
+  GailMenuShell parent;
+};
+
+struct _GtkMenuAccessibleClass
+{
+  GailMenuShellClass parent_class;
+};
+
+GType gtk_menu_accessible_get_type (void);
+
+G_END_DECLS
+
+#endif /* __GTK_MENU_ACCESSIBLE_H__ */
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index 3dbbc04..c50abda 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -113,6 +113,7 @@
 #include "gtkwidgetprivate.h"
 #include "gtkintl.h"
 #include "gtktypebuiltins.h"
+#include "a11y/gtkmenuaccessible.h"
 
 #define NAVIGATION_REGION_OVERSHOOT 50  /* How much the navigation region
                                          * extends below the submenu
@@ -882,6 +883,8 @@ gtk_menu_class_init (GtkMenuClass *class)
                                 GTK_SCROLL_PAGE_DOWN);
 
   g_type_class_add_private (gobject_class, sizeof (GtkMenuPrivate));
+
+  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_MENU_ACCESSIBLE);
 }
 
 
diff --git a/tests/a11y/pickers.txt b/tests/a11y/pickers.txt
index 07e51ed..23eebff 100644
--- a/tests/a11y/pickers.txt
+++ b/tests/a11y/pickers.txt
@@ -51,7 +51,7 @@ window1
         <AtkAction>
         action 0 name: press
         <AtkSelection>
-        unnamed-GailMenu-2
+        unnamed-GtkMenuAccessible-2
           "menu"
           parent: unnamed-GtkComboBoxAccessible-1
           index: 0
@@ -63,7 +63,7 @@ window1
           <AtkSelection>
           unnamed-GtkMenuItemAccessible-3
             "menu item"
-            parent: unnamed-GailMenu-2
+            parent: unnamed-GtkMenuAccessible-2
             index: 0
             state: enabled selectable sensitive visible
             toolkit: gail
@@ -74,7 +74,7 @@ window1
             action 0 name: click
           unnamed-GtkMenuItemAccessible-4
             "menu item"
-            parent: unnamed-GailMenu-2
+            parent: unnamed-GtkMenuAccessible-2
             index: 1
             name: File System
             state: enabled selectable sensitive visible
@@ -86,7 +86,7 @@ window1
             action 0 name: click
           unnamed-GtkMenuItemAccessible-5
             "menu item"
-            parent: unnamed-GailMenu-2
+            parent: unnamed-GtkMenuAccessible-2
             index: 2
             name: _F15-Livecd-Desk
             state: enabled selectable sensitive visible
@@ -98,7 +98,7 @@ window1
             action 0 name: click
           unnamed-GtkMenuItemAccessible-6
             "separator"
-            parent: unnamed-GailMenu-2
+            parent: unnamed-GtkMenuAccessible-2
             index: 3
             state: enabled selectable sensitive visible
             toolkit: gail
@@ -109,7 +109,7 @@ window1
             action 0 name: click
           unnamed-GtkMenuItemAccessible-7
             "separator"
-            parent: unnamed-GailMenu-2
+            parent: unnamed-GtkMenuAccessible-2
             index: 4
             state: enabled selectable sensitive visible
             toolkit: gail
@@ -120,7 +120,7 @@ window1
             action 0 name: click
           unnamed-GtkMenuItemAccessible-8
             "menu item"
-            parent: unnamed-GailMenu-2
+            parent: unnamed-GtkMenuAccessible-2
             index: 5
             name: Other...
             state: enabled selectable sensitive visible
@@ -171,7 +171,7 @@ window1
       <AtkAction>
       action 0 name: press
       <AtkSelection>
-      unnamed-GailMenu-9
+      unnamed-GtkMenuAccessible-9
         "menu"
         parent: button1
         index: 0



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]