1 /* GAIL - The GNOME Accessibility Implementation Library
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"
24 G_DEFINE_TYPE (GtkContainerAccessible, _gtk_container_accessible, GTK_TYPE_WIDGET_ACCESSIBLE)
27 gtk_container_accessible_get_n_children (AtkObject* obj)
33 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
37 children = gtk_container_get_children (GTK_CONTAINER(widget));
38 count = g_list_length (children);
39 g_list_free (children);
45 gtk_container_accessible_ref_child (AtkObject *obj,
48 GList *children, *tmp_list;
49 AtkObject *accessible;
52 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
56 children = gtk_container_get_children (GTK_CONTAINER (widget));
57 tmp_list = g_list_nth (children, i);
60 g_list_free (children);
63 accessible = gtk_widget_get_accessible (GTK_WIDGET (tmp_list->data));
65 g_list_free (children);
66 g_object_ref (accessible);
72 gtk_container_accessible_add_gtk (GtkContainer *container,
76 GtkContainerAccessible *accessible = GTK_CONTAINER_ACCESSIBLE (data);
77 GtkContainerAccessibleClass *klass;
79 klass = GTK_CONTAINER_ACCESSIBLE_GET_CLASS (accessible);
82 return klass->add_gtk (container, widget, data);
88 gtk_container_accessible_remove_gtk (GtkContainer *container,
92 GtkContainerAccessible *accessible = GTK_CONTAINER_ACCESSIBLE (data);
93 GtkContainerAccessibleClass *klass;
95 klass = GTK_CONTAINER_ACCESSIBLE_GET_CLASS (accessible);
97 if (klass->remove_gtk)
98 return klass->remove_gtk (container, widget, data);
104 gtk_container_accessible_real_add_gtk (GtkContainer *container,
108 AtkObject *atk_parent;
109 AtkObject *atk_child;
110 GtkContainerAccessible *accessible;
113 atk_parent = ATK_OBJECT (data);
114 atk_child = gtk_widget_get_accessible (widget);
115 accessible = GTK_CONTAINER_ACCESSIBLE (atk_parent);
117 g_object_notify (G_OBJECT (atk_child), "accessible-parent");
118 g_list_free (accessible->children);
119 accessible->children = gtk_container_get_children (container);
120 index = g_list_index (accessible->children, widget);
121 g_signal_emit_by_name (atk_parent, "children-changed::add", index, atk_child, NULL);
127 gtk_container_accessible_real_remove_gtk (GtkContainer *container,
131 AtkObject* atk_parent;
132 AtkObject *atk_child;
133 GtkContainerAccessible *accessible;
136 atk_parent = ATK_OBJECT (data);
137 atk_child = gtk_widget_get_accessible (widget);
138 if (atk_child == NULL)
140 accessible = GTK_CONTAINER_ACCESSIBLE (atk_parent);
142 g_object_notify (G_OBJECT (atk_child), "accessible-parent");
143 index = g_list_index (accessible->children, widget);
144 g_list_free (accessible->children);
145 accessible->children = gtk_container_get_children (container);
146 if (index >= 0 && index <= g_list_length (accessible->children))
147 g_signal_emit_by_name (atk_parent, "children-changed::remove", index, atk_child, NULL);
153 gtk_container_accessible_real_initialize (AtkObject *obj,
156 GtkContainerAccessible *accessible = GTK_CONTAINER_ACCESSIBLE (obj);
158 ATK_OBJECT_CLASS (_gtk_container_accessible_parent_class)->initialize (obj, data);
160 accessible->children = gtk_container_get_children (GTK_CONTAINER (data));
162 g_signal_connect (data, "add", G_CALLBACK (gtk_container_accessible_add_gtk), obj);
163 g_signal_connect (data, "remove", G_CALLBACK (gtk_container_accessible_remove_gtk), obj);
165 obj->role = ATK_ROLE_PANEL;
169 gtk_container_accessible_finalize (GObject *object)
171 GtkContainerAccessible *accessible = GTK_CONTAINER_ACCESSIBLE (object);
173 g_list_free (accessible->children);
175 G_OBJECT_CLASS (_gtk_container_accessible_parent_class)->finalize (object);
179 _gtk_container_accessible_class_init (GtkContainerAccessibleClass *klass)
181 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
182 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
184 gobject_class->finalize = gtk_container_accessible_finalize;
186 class->get_n_children = gtk_container_accessible_get_n_children;
187 class->ref_child = gtk_container_accessible_ref_child;
188 class->initialize = gtk_container_accessible_real_initialize;
190 klass->add_gtk = gtk_container_accessible_real_add_gtk;
191 klass->remove_gtk = gtk_container_accessible_real_remove_gtk;
195 _gtk_container_accessible_init (GtkContainerAccessible *container)