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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
23 #include "gtkcontaineraccessible.h"
26 G_DEFINE_TYPE (GtkContainerAccessible, _gtk_container_accessible, GTK_TYPE_WIDGET_ACCESSIBLE)
29 gtk_container_accessible_get_n_children (AtkObject* obj)
35 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
39 children = gtk_container_get_children (GTK_CONTAINER(widget));
40 count = g_list_length (children);
41 g_list_free (children);
47 gtk_container_accessible_ref_child (AtkObject *obj,
50 GList *children, *tmp_list;
51 AtkObject *accessible;
54 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
58 children = gtk_container_get_children (GTK_CONTAINER (widget));
59 tmp_list = g_list_nth (children, i);
62 g_list_free (children);
65 accessible = gtk_widget_get_accessible (GTK_WIDGET (tmp_list->data));
67 g_list_free (children);
68 g_object_ref (accessible);
74 gtk_container_accessible_add_gtk (GtkContainer *container,
78 GtkContainerAccessible *accessible = GTK_CONTAINER_ACCESSIBLE (data);
79 GtkContainerAccessibleClass *klass;
81 klass = GTK_CONTAINER_ACCESSIBLE_GET_CLASS (accessible);
84 return klass->add_gtk (container, widget, data);
90 gtk_container_accessible_remove_gtk (GtkContainer *container,
94 GtkContainerAccessible *accessible = GTK_CONTAINER_ACCESSIBLE (data);
95 GtkContainerAccessibleClass *klass;
97 klass = GTK_CONTAINER_ACCESSIBLE_GET_CLASS (accessible);
99 if (klass->remove_gtk)
100 return klass->remove_gtk (container, widget, data);
106 gtk_container_accessible_real_add_gtk (GtkContainer *container,
110 AtkObject *atk_parent;
111 AtkObject *atk_child;
112 GtkContainerAccessible *accessible;
115 atk_parent = ATK_OBJECT (data);
116 atk_child = gtk_widget_get_accessible (widget);
117 accessible = GTK_CONTAINER_ACCESSIBLE (atk_parent);
119 g_object_notify (G_OBJECT (atk_child), "accessible_parent");
120 g_list_free (accessible->children);
121 accessible->children = gtk_container_get_children (container);
122 index = g_list_index (accessible->children, widget);
123 g_signal_emit_by_name (atk_parent, "children_changed::add", index, atk_child, NULL);
129 gtk_container_accessible_real_remove_gtk (GtkContainer *container,
133 AtkObject* atk_parent;
134 AtkObject *atk_child;
135 GtkContainerAccessible *accessible;
138 atk_parent = ATK_OBJECT (data);
139 atk_child = gtk_widget_get_accessible (widget);
140 if (atk_child == NULL)
142 accessible = GTK_CONTAINER_ACCESSIBLE (atk_parent);
144 g_object_notify (G_OBJECT (atk_child), "accessible_parent");
145 index = g_list_index (accessible->children, widget);
146 g_list_free (accessible->children);
147 accessible->children = gtk_container_get_children (container);
148 if (index >= 0 && index <= g_list_length (accessible->children))
149 g_signal_emit_by_name (atk_parent, "children_changed::remove", index, atk_child, NULL);
155 gtk_container_accessible_real_initialize (AtkObject *obj,
158 GtkContainerAccessible *accessible = GTK_CONTAINER_ACCESSIBLE (obj);
160 ATK_OBJECT_CLASS (_gtk_container_accessible_parent_class)->initialize (obj, data);
162 accessible->children = gtk_container_get_children (GTK_CONTAINER (data));
164 g_signal_connect (data, "add", G_CALLBACK (gtk_container_accessible_add_gtk), obj);
165 g_signal_connect (data, "remove", G_CALLBACK (gtk_container_accessible_remove_gtk), obj);
167 if (GTK_IS_TOOLBAR (data))
168 obj->role = ATK_ROLE_TOOL_BAR;
169 else if (GTK_IS_VIEWPORT (data))
170 obj->role = ATK_ROLE_VIEWPORT;
172 obj->role = ATK_ROLE_PANEL;
176 gtk_container_accessible_finalize (GObject *object)
178 GtkContainerAccessible *accessible = GTK_CONTAINER_ACCESSIBLE (object);
180 g_list_free (accessible->children);
182 G_OBJECT_CLASS (_gtk_container_accessible_parent_class)->finalize (object);
186 _gtk_container_accessible_class_init (GtkContainerAccessibleClass *klass)
188 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
189 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
191 gobject_class->finalize = gtk_container_accessible_finalize;
193 class->get_n_children = gtk_container_accessible_get_n_children;
194 class->ref_child = gtk_container_accessible_ref_child;
195 class->initialize = gtk_container_accessible_real_initialize;
197 klass->add_gtk = gtk_container_accessible_real_add_gtk;
198 klass->remove_gtk = gtk_container_accessible_real_remove_gtk;
202 _gtk_container_accessible_init (GtkContainerAccessible *container)