[gtk+/drop-gail: 7/24] Move GailContainer to GtkContainerAccessible
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/drop-gail: 7/24] Move GailContainer to GtkContainerAccessible
- Date: Sun, 15 May 2011 02:12:41 +0000 (UTC)
commit a5dcb00284a0016bc800ac378f2fdc66f6cc35c6
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Feb 21 02:29:34 2011 -0500
Move GailContainer to GtkContainerAccessible
gtk/Makefile.am | 1 +
gtk/gtkcontainer.c | 208 ++++++++++++++++++++++++++++++++++++++++++
gtk/gtkcontaineraccessible.h | 66 +++++++++++++
modules/other/gail/gail.c | 5 +-
4 files changed, 279 insertions(+), 1 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 78686ee..81e7915 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -387,6 +387,7 @@ gtk_private_h_sources = \
gtkbuilderprivate.h \
gtkbuttonprivate.h \
gtkcellareaboxcontextprivate.h \
+ gtkcontaineraccessible.h \
gtkcssproviderprivate.h \
gtkcustompaperunixdialog.h \
gtkdndcursors.h \
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 50a4514..ee20996 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -3376,3 +3376,211 @@ gtk_container_get_path_for_child (GtkContainer *container,
return GTK_CONTAINER_GET_CLASS (container)->get_path_for_child (container, child);
}
+
+
+/* --- Accessibility --- */
+
+#include "gtkaccessibility.h"
+#include "gtkcontaineraccessible.h"
+
+G_DEFINE_TYPE (GtkContainerAccessible, gtk_container_accessible, GTK_TYPE_WIDGET_ACCESSIBLE)
+
+static gint
+gtk_container_accessible_get_n_children (AtkObject* obj)
+{
+ GtkWidget *widget;
+ GList *children;
+ gint count = 0;
+
+ widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
+ if (widget == NULL)
+ return 0;
+
+ children = gtk_container_get_children (GTK_CONTAINER (widget));
+ count = g_list_length (children);
+ g_list_free (children);
+
+ return count;
+}
+
+static AtkObject*
+gtk_container_accessible_ref_child (AtkObject *obj,
+ gint i)
+{
+ GList *children, *tmp_list;
+ AtkObject *accessible;
+ GtkWidget *widget;
+
+ widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
+ if (widget == NULL)
+ return NULL;
+
+ children = gtk_container_get_children (GTK_CONTAINER (widget));
+ tmp_list = g_list_nth (children, i);
+ if (!tmp_list)
+ {
+ g_list_free (children);
+ return NULL;
+ }
+
+ accessible = gtk_widget_get_accessible (GTK_WIDGET (tmp_list->data));
+
+ g_list_free (children);
+ g_object_ref (accessible);
+
+ return accessible;
+}
+
+static void
+gtk_container_accessible_add_cb (GtkContainer *container,
+ GtkWidget *widget,
+ gpointer data)
+{
+ GtkContainerAccessible *accessible = GTK_CONTAINER_ACCESSIBLE (data);
+ GtkContainerAccessibleClass *klass;
+
+ klass = GTK_CONTAINER_ACCESSIBLE_GET_CLASS (accessible);
+
+ if (klass->add_gtk)
+ klass->add_gtk (container, widget, data);
+}
+
+static void
+gtk_container_accessible_remove_cb (GtkContainer *container,
+ GtkWidget *widget,
+ gpointer data)
+{
+ GtkContainerAccessible *accessible = GTK_CONTAINER_ACCESSIBLE (data);
+ GtkContainerAccessibleClass *klass;
+
+ klass = GTK_CONTAINER_ACCESSIBLE_GET_CLASS (accessible);
+
+ if (klass->remove_gtk)
+ klass->remove_gtk (container, widget, data);
+}
+
+static void
+gtk_container_accessible_add_gtk (GtkContainer *container,
+ GtkWidget *widget,
+ gpointer data)
+{
+ AtkObject* atk_parent = ATK_OBJECT (data);
+ AtkObject* atk_child = gtk_widget_get_accessible (widget);
+ GtkContainerAccessible *accessible = GTK_CONTAINER_ACCESSIBLE (atk_parent);
+ gint index;
+
+ g_object_notify (G_OBJECT (atk_child), "accessible_parent");
+
+ g_list_free (accessible->children);
+ accessible->children = gtk_container_get_children (container);
+ index = g_list_index (accessible->children, widget);
+ g_signal_emit_by_name (atk_parent, "children_changed::add",
+ index, atk_child, NULL);
+}
+
+static void
+gtk_container_accessible_remove_gtk (GtkContainer *container,
+ GtkWidget *widget,
+ gpointer data)
+{
+ AtkPropertyValues values = { NULL };
+ AtkObject* atk_parent;
+ AtkObject *atk_child;
+ GtkContainerAccessible *accessible;
+ gint index;
+
+ atk_parent = ATK_OBJECT (data);
+ atk_child = gtk_widget_get_accessible (widget);
+
+ if (atk_child)
+ {
+ g_value_init (&values.old_value, G_TYPE_POINTER);
+ g_value_set_pointer (&values.old_value, atk_parent);
+
+ values.property_name = "accessible-parent";
+
+ g_object_ref (atk_child);
+ g_signal_emit_by_name (atk_child,
+ "property_change::accessible-parent", &values, NULL);
+ g_object_unref (atk_child);
+ }
+
+ accessible = GTK_CONTAINER_ACCESSIBLE (atk_parent);
+ index = g_list_index (accessible->children, widget);
+ g_list_free (accessible->children);
+ accessible->children = gtk_container_get_children (container);
+ if (index >= 0 && index <= g_list_length (accessible->children))
+ g_signal_emit_by_name (atk_parent, "children_changed::remove",
+ index, atk_child, NULL);
+}
+
+static void
+gtk_container_accessible_initialize (AtkObject *obj,
+ gpointer data)
+{
+ GtkContainerAccessible *container = GTK_CONTAINER_ACCESSIBLE (obj);
+
+ ATK_OBJECT_CLASS (gtk_container_accessible_parent_class)->initialize (obj, data);
+
+ container->children = gtk_container_get_children (GTK_CONTAINER (data));
+
+ g_signal_connect (data, "add",
+ G_CALLBACK (gtk_container_accessible_add_cb), obj);
+ g_signal_connect (data, "remove",
+ G_CALLBACK (gtk_container_accessible_remove_cb), obj);
+
+ /* FIXME: move these to subclasses */
+#if 0
+ if (GTK_IS_TOOLBAR (data))
+ obj->role = ATK_ROLE_TOOL_BAR;
+ else if (GTK_IS_VIEWPORT (data))
+ obj->role = ATK_ROLE_VIEWPORT;
+ else
+#endif
+ obj->role = ATK_ROLE_PANEL;
+}
+
+static void
+gtk_container_accessible_finalize (GObject *object)
+{
+ GtkContainerAccessible *container = GTK_CONTAINER_ACCESSIBLE (object);
+
+ g_list_free (container->children);
+
+ G_OBJECT_CLASS (gtk_container_accessible_parent_class)->finalize (object);
+}
+
+static void
+gtk_container_accessible_class_init (GtkContainerAccessibleClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
+
+ gobject_class->finalize = gtk_container_accessible_finalize;
+
+ class->get_n_children = gtk_container_accessible_get_n_children;
+ class->ref_child = gtk_container_accessible_ref_child;
+ class->initialize = gtk_container_accessible_initialize;
+
+ klass->add_gtk = gtk_container_accessible_add_gtk;
+ klass->remove_gtk = gtk_container_accessible_remove_gtk;
+}
+
+static void
+gtk_container_accessible_init (GtkContainerAccessible *container)
+{
+ container->children = NULL;
+}
+
+static AtkObject *
+gtk_container_accessible_new (GtkWidget *widget)
+{
+ AtkObject *accessible;
+
+ accessible = g_object_new (GTK_TYPE_CONTAINER_ACCESSIBLE, NULL);
+ atk_object_initialize (accessible, widget);
+
+ return accessible;
+}
+
+GTK_ACCESSIBLE_FACTORY(GTK_TYPE_CONTAINER, gtk_container_accessible, gtk_container_accessible_new)
diff --git a/gtk/gtkcontaineraccessible.h b/gtk/gtkcontaineraccessible.h
new file mode 100644
index 0000000..0deac19
--- /dev/null
+++ b/gtk/gtkcontaineraccessible.h
@@ -0,0 +1,66 @@
+/* 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_CONTAINER_ACCESSIBLE_H__
+#define __GTK_CONTAINER_ACCESSIBLE_H__
+
+#include <gtk/gtkwidgetaccessible.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_CONTAINER_ACCESSIBLE (gtk_container_accessible_get_type ())
+#define GTK_CONTAINER_ACCESSIBLE(obj)(G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CONTAINER_ACCESSIBLE, GtkContainerAccessible))
+#define GTK_CONTAINER_ACCESSIBLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CONTAINER_ACCESSIBLE, GtkContainerAccessibleClass))
+
+typedef struct _GtkContainerAccessible GtkContainerAccessible;
+typedef struct _GtkContainerAccessibleClass GtkContainerAccessibleClass;
+
+struct _GtkContainerAccessible
+{
+ GtkWidgetAccessible parent;
+
+ /* FIXME: drop this */
+ GList *children;
+};
+
+struct _GtkContainerAccessibleClass
+{
+ GtkWidgetAccessibleClass parent_class;
+
+ /* FIXME: drop these */
+ void (*add_gtk) (GtkContainer *container,
+ GtkWidget *widget,
+ gpointer data);
+ void (*remove_gtk) (GtkContainer *container,
+ GtkWidget *widget,
+ gpointer data);
+};
+
+
+GType gtk_container_accessible_get_type (void) G_GNUC_CONST;
+GType gtk_container_accessible_factory_get_type (void) G_GNUC_CONST;
+
+
+G_END_DECLS
+
+#endif /* __GTK_CONTAINER_ACCESSIBLE_H__ */
diff --git a/modules/other/gail/gail.c b/modules/other/gail/gail.c
index 8248152..49e40a6 100644
--- a/modules/other/gail/gail.c
+++ b/modules/other/gail/gail.c
@@ -860,6 +860,7 @@ extern void gnome_accessibility_module_shutdown (void);
* to GTK+ proper
*/
extern GType gtk_widget_accessible_factory_get_type (void);
+extern GType gtk_container_accessible_factory_get_type (void);
static int gail_initialized = FALSE;
@@ -886,7 +887,9 @@ gail_accessibility_module_init (void)
atk_registry_set_factory_type (atk_get_default_registry (),
GTK_TYPE_WIDGET,
gtk_widget_accessible_factory_get_type ());
- GAIL_WIDGET_SET_FACTORY (GTK_TYPE_CONTAINER, gail_container);
+ atk_registry_set_factory_type (atk_get_default_registry (),
+ GTK_TYPE_CONTAINER,
+ gtk_container_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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]