[gtk+/drop-gail: 21/24] Move GailScrolledWindow to GtkScrolledWindowAccessible



commit 623964b779f850a82ad5bf90d998f89eac4bc211
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Feb 25 00:32:45 2011 -0500

    Move GailScrolledWindow to GtkScrolledWindowAccessible

 gtk/Makefile.am                   |    1 +
 gtk/gtkscrolledwindow.c           |  178 +++++++++++++++++++++++++++++++++++++
 gtk/gtkscrolledwindowaccessible.h |   57 ++++++++++++
 modules/other/gail/gail.c         |    6 +-
 4 files changed, 240 insertions(+), 2 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index cb1b723..f652c52 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -431,6 +431,7 @@ gtk_private_h_sources =		\
 	gtkrecentchooserprivate.h \
 	gtkrecentchooserutils.h	\
 	gtkscaleprivate.h	\
+	gtkscrolledwindowaccessible.h \
 	gtksearchengine.h	\
 	gtksearchenginesimple.h	\
 	gtkselectionprivate.h	\
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index d153c11..7c76352 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -2376,3 +2376,181 @@ gtk_scrolled_window_set_min_content_height (GtkScrolledWindow *scrolled_window,
       g_object_notify (G_OBJECT (scrolled_window), "min-content-height");
     }
 }
+
+
+/* --- Accessibility --- */
+
+#include "gtkaccessibility.h"
+#include "gtkscrolledwindowaccessible.h"
+
+G_DEFINE_TYPE (GtkScrolledWindowAccessible, gtk_scrolled_window_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE)
+
+static void
+gtk_scrolled_window_accessible_scrollbar_visibility_changed (GObject    *object,
+                                                             GParamSpec *pspec,
+                                                             gpointer   user_data)
+{
+  GtkScrolledWindowAccessible *accessible = GTK_SCROLLED_WINDOW_ACCESSIBLE (user_data);
+  gint index;
+  gint n_children;
+  gboolean child_added = FALSE;
+  GList *children;
+  AtkObject *child;
+  GtkScrolledWindow *sw;
+  GtkWidget *hscrollbar, *vscrollbar;
+  gchar *signal_name;
+
+  if (strcmp (pspec->name, "visible") != 0)
+    return;
+
+  sw = GTK_SCROLLED_WINDOW (gtk_accessible_get_widget (GTK_ACCESSIBLE (user_data)));
+  if (sw == NULL)
+    return;
+
+  children = gtk_container_get_children (GTK_CONTAINER (sw));
+  index = n_children = g_list_length (children);
+  g_list_free (children);
+
+  hscrollbar = gtk_scrolled_window_get_hscrollbar (sw);
+  vscrollbar = gtk_scrolled_window_get_vscrollbar (sw);
+
+  if ((gpointer) object == (gpointer) (hscrollbar))
+    {
+      if (gtk_scrolled_window_get_hscrollbar (sw))
+        child_added = TRUE;
+
+      child = gtk_widget_get_accessible (hscrollbar);
+    }
+  else if ((gpointer) object == (gpointer) (vscrollbar))
+    {
+      if (gtk_scrolled_window_get_vscrollbar (sw))
+        child_added = TRUE;
+
+      child = gtk_widget_get_accessible (vscrollbar);
+      if (gtk_scrolled_window_get_hscrollbar (sw))
+        index = n_children+1;
+    }
+  else
+    {
+      g_assert_not_reached ();
+      return;
+    }
+
+  if (child_added)
+    signal_name = "children_changed::add";
+  else
+    signal_name = "children_changed::delete";
+
+  g_signal_emit_by_name (accessible, signal_name, 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);
+  atk_object_set_role (obj, ATK_ROLE_SCROLL_PANE);
+
+  window = GTK_SCROLLED_WINDOW (data);
+
+  g_signal_connect_data (gtk_scrolled_window_get_hscrollbar (window), "notify::visible",
+                         G_CALLBACK (gtk_scrolled_window_accessible_scrollbar_visibility_changed),
+                         obj, NULL, FALSE);
+  g_signal_connect_data (gtk_scrolled_window_get_vscrollbar (window), "notify::visible",
+                         G_CALLBACK (gtk_scrolled_window_accessible_scrollbar_visibility_changed),
+                         obj, NULL, FALSE);
+}
+
+static AtkObject *
+gtk_scrolled_window_accessible_ref_child (AtkObject *obj,
+                                          gint      child)
+{
+  GtkWidget *widget;
+  GtkScrolledWindow *gtk_window;
+  GtkWidget *hscrollbar, *vscrollbar;
+  GList *children, *tmp_list;
+  gint n_children;
+  AtkObject  *accessible = NULL;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
+  if (widget == NULL)
+    return NULL;
+
+  gtk_window = GTK_SCROLLED_WINDOW (widget);
+  hscrollbar = gtk_scrolled_window_get_hscrollbar (gtk_window);
+  vscrollbar = gtk_scrolled_window_get_vscrollbar (gtk_window);
+
+  children = gtk_container_get_children (GTK_CONTAINER (gtk_window));
+  n_children = g_list_length (children);
+
+  if (child == n_children)
+    {
+      if (gtk_scrolled_window_get_hscrollbar (gtk_window))
+        accessible = gtk_widget_get_accessible (hscrollbar);
+      else if (gtk_scrolled_window_get_vscrollbar (gtk_window))
+        accessible = gtk_widget_get_accessible (vscrollbar);
+    }
+  else if (child == n_children + 1 &&
+           gtk_scrolled_window_get_hscrollbar (gtk_window) &&
+           gtk_scrolled_window_get_vscrollbar (gtk_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 gint
+gtk_scrolled_window_accessible_get_n_children (AtkObject *object)
+{
+  GtkWidget *widget;
+  GtkScrolledWindow *gtk_window;
+  GList *children;
+  gint n_children;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (object));
+  if (widget == NULL)
+    return 0;
+
+  gtk_window = GTK_SCROLLED_WINDOW (widget);
+  /* Get the number of children returned by the backing GtkScrolledWindow */
+
+  children = gtk_container_get_children (GTK_CONTAINER (gtk_window));
+  n_children = g_list_length (children);
+  g_list_free (children);
+
+  /* Add one to the count for each visible scrollbar */
+  if (gtk_scrolled_window_get_hscrollbar (gtk_window))
+    n_children++;
+  if (gtk_scrolled_window_get_vscrollbar (gtk_window))
+    n_children++;
+  return n_children;
+}
+
+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)
+{
+}
+
+GTK_ACCESSIBLE_FACTORY(GTK_TYPE_SCROLLED_WINDOW_ACCESSIBLE, gtk_scrolled_window_accessible)
diff --git a/gtk/gtkscrolledwindowaccessible.h b/gtk/gtkscrolledwindowaccessible.h
new file mode 100644
index 0000000..26b8afb
--- /dev/null
+++ b/gtk/gtkscrolledwindowaccessible.h
@@ -0,0 +1,57 @@
+/* GTK - The GIMP Toolkit
+ * Copyright 2011 Red Hat, 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.
+ */
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#ifndef __GTK_SCROLLED_WINDOW_ACCESSIBLE_H__
+#define __GTK_SCROLLED_WINDOW_ACCESSIBLE_H__
+
+#include <gtk/gtkcontaineraccessible.h>
+#include <gtk/gtkscrolledwindow.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_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
+{
+  GtkContainerAccessible parent;
+};
+
+struct _GtkScrolledWindowAccessibleClass
+{
+  GtkContainerAccessibleClass parent_class;
+};
+
+
+GType gtk_scrolled_window_accessible_get_type (void) G_GNUC_CONST;
+GType gtk_scrolled_window_accessible_factory_get_type (void) G_GNUC_CONST;
+
+
+G_END_DECLS
+
+#endif  /* __GTK_SCROLLED_WINDOW_ACCESSIBLE_H__ */
diff --git a/modules/other/gail/gail.c b/modules/other/gail/gail.c
index 0bb92eb..3278ce0 100644
--- a/modules/other/gail/gail.c
+++ b/modules/other/gail/gail.c
@@ -32,6 +32,7 @@
 #include <gtk/gtkimageaccessible.h>
 #include <gtk/gtkpanedaccessible.h>
 #include <gtk/gtkprogressbaraccessible.h>
+#include <gtk/gtkscrolledwindowaccessible.h>
 #include <gtk/gtkseparatoraccessible.h>
 #include <gtk/gtkwidgetaccessible.h>
 
@@ -103,7 +104,6 @@ GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_CALENDAR, GailCalendar, gail_calendar, GTK_TYP
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_SPIN_BUTTON, GailSpinButton, gail_spin_button, GTK_TYPE_SPIN_BUTTON)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_TREE_VIEW, GailTreeView, gail_tree_view, GTK_TYPE_TREE_VIEW)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_RADIO_BUTTON, GailRadioButton, gail_radio_button, GTK_TYPE_RADIO_BUTTON)
-GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_SCROLLED_WINDOW, GailScrolledWindow, gail_scrolled_window, GTK_TYPE_SCROLLED_WINDOW)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_SCROLLBAR, GailScrollbar, gail_scrollbar, GTK_TYPE_SCROLLBAR)
 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)
@@ -914,6 +914,9 @@ gail_accessibility_module_init (void)
   atk_registry_set_factory_type (atk_get_default_registry (),
                                  GTK_TYPE_FRAME,
                                  gtk_frame_accessible_factory_get_type ());
+  atk_registry_set_factory_type (atk_get_default_registry (),
+                                 GTK_TYPE_SCROLLED_WINDOW,
+                                 gtk_scrolled_window_accessible_factory_get_type ());
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_BUTTON, gail_button);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_LINK_BUTTON, gail_link_button);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_MENU_ITEM, gail_menu_item);
@@ -937,7 +940,6 @@ gail_accessibility_module_init (void)
   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_RADIO_BUTTON, gail_radio_button);
-  GAIL_WIDGET_SET_FACTORY (GTK_TYPE_SCROLLED_WINDOW, gail_scrolled_window);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_SCROLLBAR, gail_scrollbar);
   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);



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