1 /* GTK+ - accessibility implementations
2 * Copyright 2001, 2002, 2003 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 #include "gtkcontaineraccessible.h"
23 struct _GtkContainerAccessiblePrivate
28 G_DEFINE_TYPE (GtkContainerAccessible, gtk_container_accessible, GTK_TYPE_WIDGET_ACCESSIBLE)
31 gtk_container_accessible_get_n_children (AtkObject* obj)
37 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
41 children = gtk_container_get_children (GTK_CONTAINER (widget));
42 count = g_list_length (children);
43 g_list_free (children);
49 gtk_container_accessible_ref_child (AtkObject *obj,
52 GList *children, *tmp_list;
53 AtkObject *accessible;
56 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
60 children = gtk_container_get_children (GTK_CONTAINER (widget));
61 tmp_list = g_list_nth (children, i);
64 g_list_free (children);
67 accessible = gtk_widget_get_accessible (GTK_WIDGET (tmp_list->data));
69 g_list_free (children);
70 g_object_ref (accessible);
76 gtk_container_accessible_add_gtk (GtkContainer *container,
80 GtkContainerAccessible *accessible = GTK_CONTAINER_ACCESSIBLE (data);
81 GtkContainerAccessibleClass *klass;
83 klass = GTK_CONTAINER_ACCESSIBLE_GET_CLASS (accessible);
86 return klass->add_gtk (container, widget, data);
92 gtk_container_accessible_remove_gtk (GtkContainer *container,
96 GtkContainerAccessible *accessible = GTK_CONTAINER_ACCESSIBLE (data);
97 GtkContainerAccessibleClass *klass;
99 klass = GTK_CONTAINER_ACCESSIBLE_GET_CLASS (accessible);
101 if (klass->remove_gtk)
102 return klass->remove_gtk (container, widget, data);
108 gtk_container_accessible_real_add_gtk (GtkContainer *container,
112 AtkObject *atk_parent;
113 AtkObject *atk_child;
114 GtkContainerAccessible *accessible;
117 atk_parent = ATK_OBJECT (data);
118 atk_child = gtk_widget_get_accessible (widget);
119 accessible = GTK_CONTAINER_ACCESSIBLE (atk_parent);
121 g_object_notify (G_OBJECT (atk_child), "accessible-parent");
122 g_list_free (accessible->priv->children);
123 accessible->priv->children = gtk_container_get_children (container);
124 index = g_list_index (accessible->priv->children, widget);
125 g_signal_emit_by_name (atk_parent, "children-changed::add", index, atk_child, NULL);
131 gtk_container_accessible_real_remove_gtk (GtkContainer *container,
135 AtkObject* atk_parent;
136 AtkObject *atk_child;
137 GtkContainerAccessible *accessible;
140 atk_parent = ATK_OBJECT (data);
141 atk_child = gtk_widget_get_accessible (widget);
142 if (atk_child == NULL)
144 accessible = GTK_CONTAINER_ACCESSIBLE (atk_parent);
146 g_object_notify (G_OBJECT (atk_child), "accessible-parent");
147 index = g_list_index (accessible->priv->children, widget);
148 g_list_free (accessible->priv->children);
149 accessible->priv->children = gtk_container_get_children (container);
150 if (index >= 0 && index <= g_list_length (accessible->priv->children))
151 g_signal_emit_by_name (atk_parent, "children-changed::remove", index, atk_child, NULL);
157 gtk_container_accessible_real_initialize (AtkObject *obj,
160 GtkContainerAccessible *accessible = GTK_CONTAINER_ACCESSIBLE (obj);
162 ATK_OBJECT_CLASS (gtk_container_accessible_parent_class)->initialize (obj, data);
164 accessible->priv->children = gtk_container_get_children (GTK_CONTAINER (data));
166 g_signal_connect (data, "add", G_CALLBACK (gtk_container_accessible_add_gtk), obj);
167 g_signal_connect (data, "remove", G_CALLBACK (gtk_container_accessible_remove_gtk), obj);
169 obj->role = ATK_ROLE_PANEL;
173 gtk_container_accessible_finalize (GObject *object)
175 GtkContainerAccessible *accessible = GTK_CONTAINER_ACCESSIBLE (object);
177 g_list_free (accessible->priv->children);
179 G_OBJECT_CLASS (gtk_container_accessible_parent_class)->finalize (object);
183 gtk_container_accessible_class_init (GtkContainerAccessibleClass *klass)
185 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
186 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
188 gobject_class->finalize = gtk_container_accessible_finalize;
190 class->get_n_children = gtk_container_accessible_get_n_children;
191 class->ref_child = gtk_container_accessible_ref_child;
192 class->initialize = gtk_container_accessible_real_initialize;
194 klass->add_gtk = gtk_container_accessible_real_add_gtk;
195 klass->remove_gtk = gtk_container_accessible_real_remove_gtk;
197 g_type_class_add_private (klass, sizeof (GtkContainerAccessiblePrivate));
201 gtk_container_accessible_init (GtkContainerAccessible *container)
203 container->priv = G_TYPE_INSTANCE_GET_PRIVATE (container,
204 GTK_TYPE_CONTAINER_ACCESSIBLE,
205 GtkContainerAccessiblePrivate);