[gtk+] Convert GailScrolledWindow to GtkScrolledWindowAccessible



commit 53c90cebb28577745284c908fe08019e813b5148
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jun 28 23:13:27 2011 -0400

    Convert GailScrolledWindow to GtkScrolledWindowAccessible

 gtk/a11y/Makefile.am                   |    4 +-
 gtk/a11y/gail.c                        |    3 -
 gtk/a11y/gailscrolledwindow.c          |  214 --------------------------------
 gtk/a11y/gailscrolledwindow.h          |   51 --------
 gtk/a11y/gtkscrolledwindowaccessible.c |  195 +++++++++++++++++++++++++++++
 gtk/a11y/gtkscrolledwindowaccessible.h |   51 ++++++++
 gtk/gtkscrolledwindow.c                |    4 +-
 tests/a11y/appchooser.txt              |    8 +-
 8 files changed, 255 insertions(+), 275 deletions(-)
---
diff --git a/gtk/a11y/Makefile.am b/gtk/a11y/Makefile.am
index 00c2eea..202d96a 100644
--- a/gtk/a11y/Makefile.am
+++ b/gtk/a11y/Makefile.am
@@ -38,7 +38,7 @@ gail_c_sources =			\
 	gtkscaleaccessible.c		\
 	gtkscalebuttonaccessible.c	\
 	gtkscrollbaraccessible.c	\
-	gailscrolledwindow.c		\
+	gtkscrolledwindowaccessible.c	\
 	gtkspinbuttonaccessible.c	\
 	gailsubmenuitem.c		\
 	gailstatusbar.c			\
@@ -89,7 +89,7 @@ gail_private_h_sources =		\
 	gtkscaleaccessible.h		\
 	gtkscalebuttonaccessible.h	\
 	gtkscrollbaraccessible.h	\
-	gailscrolledwindow.h		\
+	gtkscrolledwindowaccessible.h	\
 	gtkspinbuttonaccessible.h	\
 	gailsubmenuitem.h		\
 	gailstatusbar.h			\
diff --git a/gtk/a11y/gail.c b/gtk/a11y/gail.c
index 18c8b2a..6b4ed4c 100644
--- a/gtk/a11y/gail.c
+++ b/gtk/a11y/gail.c
@@ -38,7 +38,6 @@
 #include "gailnotebook.h"
 #include "gailradiomenuitem.h"
 #include "gailrenderercell.h"
-#include "gailscrolledwindow.h"
 #include "gailstatusbar.h"
 #include "gailtextcell.h"
 #include "gailtoplevel.h"
@@ -104,7 +103,6 @@ GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_WINDOW, GailWindow, gail_window, GTK_TYPE_BIN)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_STATUSBAR, GailStatusbar, gail_statusbar, GTK_TYPE_STATUSBAR)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_NOTEBOOK, GailNotebook, gail_notebook, GTK_TYPE_NOTEBOOK)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_TREE_VIEW, GailTreeView, gail_tree_view, GTK_TYPE_TREE_VIEW)
-GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_SCROLLED_WINDOW, GailScrolledWindow, gail_scrolled_window, GTK_TYPE_SCROLLED_WINDOW)
 GAIL_IMPLEMENT_FACTORY_WITH_FUNC (GAIL_TYPE_CHECK_MENU_ITEM, GailCheckMenuItem, gail_check_menu_item, gail_check_menu_item_new)
 GAIL_IMPLEMENT_FACTORY_WITH_FUNC (GAIL_TYPE_RADIO_MENU_ITEM, GailRadioMenuItem, gail_radio_menu_item, gail_radio_menu_item_new)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_EXPANDER, GailExpander, gail_expander, GTK_TYPE_EXPANDER)
@@ -867,7 +865,6 @@ gail_accessibility_module_init (void)
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_CELL_RENDERER_TOGGLE, gail_boolean_cell);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_CELL_RENDERER_PIXBUF, gail_image_cell);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_CELL_RENDERER, gail_renderer_cell);
-  GAIL_WIDGET_SET_FACTORY (GTK_TYPE_SCROLLED_WINDOW, gail_scrolled_window);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_CHECK_MENU_ITEM, gail_check_menu_item);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_RADIO_MENU_ITEM, gail_radio_menu_item);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_EXPANDER, gail_expander);
diff --git a/gtk/a11y/gtkscrolledwindowaccessible.c b/gtk/a11y/gtkscrolledwindowaccessible.c
new file mode 100644
index 0000000..110cb31
--- /dev/null
+++ b/gtk/a11y/gtkscrolledwindowaccessible.c
@@ -0,0 +1,195 @@
+/* GAIL - The GNOME Accessibility Enabling 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 <string.h>
+#include <gtk/gtk.h>
+#include "gtkscrolledwindowaccessible.h"
+
+
+G_DEFINE_TYPE (GtkScrolledWindowAccessible, gtk_scrolled_window_accessible, GAIL_TYPE_CONTAINER)
+
+static void
+visibility_changed (GObject    *object,
+                    GParamSpec *pspec,
+                    gpointer    user_data)
+{
+  if (!strcmp (pspec->name, "visible"))
+    {
+      gint index;
+      gint n_children;
+      gboolean child_added = FALSE;
+      GList *children;
+      AtkObject *child;
+      GtkWidget *widget;
+      GtkScrolledWindow *scrolled_window;
+      GtkWidget *hscrollbar, *vscrollbar;
+      GtkAccessible *accessible = GTK_ACCESSIBLE (user_data);
+
+      widget = gtk_accessible_get_widget (user_data);
+      if (widget == NULL)
+        return;
+
+      scrolled_window = GTK_SCROLLED_WINDOW (widget);
+      children = gtk_container_get_children (GTK_CONTAINER (widget));
+      index = n_children = g_list_length (children);
+      g_list_free (children);
+
+      hscrollbar = gtk_scrolled_window_get_hscrollbar (scrolled_window);
+      vscrollbar = gtk_scrolled_window_get_vscrollbar (scrolled_window);
+
+      if ((gpointer) object == (gpointer) (hscrollbar))
+        {
+          if (gtk_scrolled_window_get_hscrollbar (scrolled_window))
+            child_added = TRUE;
+
+          child = gtk_widget_get_accessible (hscrollbar);
+        }
+      else if ((gpointer) object == (gpointer) (vscrollbar))
+        {
+          if (gtk_scrolled_window_get_vscrollbar (scrolled_window))
+            child_added = TRUE;
+
+          child = gtk_widget_get_accessible (vscrollbar);
+          if (gtk_scrolled_window_get_hscrollbar (scrolled_window))
+            index = n_children + 1;
+        }
+      else
+        {
+          g_assert_not_reached ();
+          return;
+        }
+
+      if (child_added)
+        g_signal_emit_by_name (accessible, "children_changed::add", index, child, NULL);
+      else
+        g_signal_emit_by_name (accessible, "children_changed::delete", index, child, NULL);
+
+    }
+}
+static void
+gtk_scrolled_window_accessible_initialize (AtkObject *obj,
+                                           gpointer  data)
+{
+  GtkScrolledWindow *window;
+
+  ATK_OBJECT_CLASS (gtk_scrolled_window_accessible_parent_class)->initialize (obj, data);
+
+  window = GTK_SCROLLED_WINDOW (data);
+
+  g_signal_connect_data (gtk_scrolled_window_get_hscrollbar (window), "notify::visible",
+                         G_CALLBACK (visibility_changed),
+                         obj, NULL, FALSE);
+  g_signal_connect_data (gtk_scrolled_window_get_vscrollbar (window), "notify::visible",
+                         G_CALLBACK (visibility_changed),
+                         obj, NULL, FALSE);
+
+  obj->role = ATK_ROLE_SCROLL_PANE;
+}
+
+static gint
+gtk_scrolled_window_accessible_get_n_children (AtkObject *object)
+{
+  GtkWidget *widget;
+  GtkScrolledWindow *scrolled_window;
+  GList *children;
+  gint n_children;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (object));
+  if (widget == NULL)
+    return 0;
+
+  scrolled_window = GTK_SCROLLED_WINDOW (widget);
+
+  children = gtk_container_get_children (GTK_CONTAINER (widget));
+  n_children = g_list_length (children);
+  g_list_free (children);
+
+  if (gtk_scrolled_window_get_hscrollbar (scrolled_window))
+    n_children++;
+  if (gtk_scrolled_window_get_vscrollbar (scrolled_window))
+    n_children++;
+
+  return n_children;
+}
+
+static AtkObject *
+gtk_scrolled_window_accessible_ref_child (AtkObject *obj,
+                                          gint       child)
+{
+  GtkWidget *widget;
+  GtkScrolledWindow *scrolled_window;
+  GtkWidget *hscrollbar, *vscrollbar;
+  GList *children, *tmp_list;
+  gint n_children;
+  AtkObject  *accessible = NULL;
+
+  g_return_val_if_fail (child >= 0, NULL);
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
+  if (widget == NULL)
+    return NULL;
+
+  scrolled_window = GTK_SCROLLED_WINDOW (widget);
+  hscrollbar = gtk_scrolled_window_get_hscrollbar (scrolled_window);
+  vscrollbar = gtk_scrolled_window_get_vscrollbar (scrolled_window);
+
+  children = gtk_container_get_children (GTK_CONTAINER (widget));
+  n_children = g_list_length (children);
+
+  if (child == n_children)
+    {
+      if (gtk_scrolled_window_get_hscrollbar (scrolled_window))
+        accessible = gtk_widget_get_accessible (hscrollbar);
+      else if (gtk_scrolled_window_get_vscrollbar (scrolled_window))
+        accessible = gtk_widget_get_accessible (vscrollbar);
+    }
+  else if (child == n_children + 1 &&
+           gtk_scrolled_window_get_hscrollbar (scrolled_window) &&
+           gtk_scrolled_window_get_vscrollbar (scrolled_window))
+    accessible = gtk_widget_get_accessible (vscrollbar);
+  else if (child < n_children)
+    {
+      tmp_list = g_list_nth (children, child);
+      if (tmp_list)
+        accessible = gtk_widget_get_accessible (GTK_WIDGET (tmp_list->data));
+    }
+
+  g_list_free (children);
+  if (accessible)
+    g_object_ref (accessible);
+
+  return accessible;
+}
+
+static void
+gtk_scrolled_window_accessible_class_init (GtkScrolledWindowAccessibleClass *klass)
+{
+  AtkObjectClass  *class = ATK_OBJECT_CLASS (klass);
+
+  class->get_n_children = gtk_scrolled_window_accessible_get_n_children;
+  class->ref_child = gtk_scrolled_window_accessible_ref_child;
+  class->initialize = gtk_scrolled_window_accessible_initialize;
+}
+
+static void
+gtk_scrolled_window_accessible_init (GtkScrolledWindowAccessible *window)
+{
+}
diff --git a/gtk/a11y/gtkscrolledwindowaccessible.h b/gtk/a11y/gtkscrolledwindowaccessible.h
new file mode 100644
index 0000000..c3f1ac5
--- /dev/null
+++ b/gtk/a11y/gtkscrolledwindowaccessible.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_SCROLLED_WINDOW_ACCESSIBLE_H__
+#define __GTK_SCROLLED_WINDOW_ACCESSIBLE_H__
+
+#include "gailcontainer.h"
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_SCROLLED_WINDOW_ACCESSIBLE            (gtk_scrolled_window_accessible_get_type ())
+#define GTK_SCROLLED_WINDOW_ACCESSIBLE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SCROLLED_WINDOW_ACCESSIBLE, GtkScrolledWindowAccessible))
+#define GTK_SCROLLED_WINDOW_ACCESSIBLE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_SCROLLED_WINDOW_ACCESSIBLE, GtkScrolledWindowAccessibleClass))
+#define GTK_IS_SCROLLED_WINDOW_ACCESSIBLE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SCROLLED_WINDOW_ACCESSIBLE))
+#define GTK_IS_SCROLLED_WINDOW_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SCROLLED_WINDOW_ACCESSIBLE))
+#define GTK_SCROLLED_WINDOW_ACCESSIBLE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_SCROLLED_WINDOW_ACCESSIBLE, GtkScrolledWindowAccessibleClass))
+
+typedef struct _GtkScrolledWindowAccessible      GtkScrolledWindowAccessible;
+typedef struct _GtkScrolledWindowAccessibleClass GtkScrolledWindowAccessibleClass;
+
+struct _GtkScrolledWindowAccessible
+{
+  GailContainer parent;
+};
+
+struct _GtkScrolledWindowAccessibleClass
+{
+  GailContainerClass parent_class;
+};
+
+GType gtk_scrolled_window_accessible_get_type (void);
+
+G_END_DECLS
+
+#endif /* __GTK_SCROLLED_WINDOW_ACCESSIBLE_H__ */
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index 292b1e1..1f2d33b 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -37,7 +37,7 @@
 #include "gtkprivate.h"
 #include "gtktypebuiltins.h"
 #include "gtkintl.h"
-
+#include "a11y/gtkscrolledwindowaccessible.h"
 
 /**
  * SECTION:gtkscrolledwindow
@@ -479,6 +479,8 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
   add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
 
   g_type_class_add_private (class, sizeof (GtkScrolledWindowPrivate));
+
+  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_SCROLLED_WINDOW_ACCESSIBLE);
 }
 
 static void
diff --git a/tests/a11y/appchooser.txt b/tests/a11y/appchooser.txt
index 491b93f..ea0ba6c 100644
--- a/tests/a11y/appchooser.txt
+++ b/tests/a11y/appchooser.txt
@@ -82,7 +82,7 @@ window1
           <AtkComponent>
           layer: widget
           alpha: 1
-          unnamed-GailScrolledWindow-4
+          unnamed-GtkScrolledWindowAccessible-4
             "scroll pane"
             parent: unnamed-GailContainer-3
             index: 0
@@ -93,7 +93,7 @@ window1
             alpha: 1
             unnamed-GailTreeView-5
               "table"
-              parent: unnamed-GailScrolledWindow-4
+              parent: unnamed-GtkScrolledWindowAccessible-4
               index: 0
               state: enabled focusable sensitive showing visible manages-descendants
               toolkit: gail
@@ -398,7 +398,7 @@ Click "Show other applications", for more options, or "Find applications online"
                   action 0 description: activate the cell
             unnamed-GtkScrollbarAccessible-8
               "scroll bar"
-              parent: unnamed-GailScrolledWindow-4
+              parent: unnamed-GtkScrolledWindowAccessible-4
               index: 1
               state: enabled horizontal sensitive
               toolkit: gail
@@ -414,7 +414,7 @@ Click "Show other applications", for more options, or "Find applications online"
               minimum increment: 39.800000
             unnamed-GtkScrollbarAccessible-9
               "scroll bar"
-              parent: unnamed-GailScrolledWindow-4
+              parent: unnamed-GtkScrolledWindowAccessible-4
               index: 2
               state: enabled sensitive vertical
               toolkit: gail



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