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 "gailcontainer.h"
25 static void gail_container_class_init (GailContainerClass *klass);
26 static void gail_container_init (GailContainer *container);
28 static gint gail_container_get_n_children (AtkObject *obj);
29 static AtkObject* gail_container_ref_child (AtkObject *obj,
31 static gint gail_container_add_gtk (GtkContainer *container,
34 static gint gail_container_remove_gtk (GtkContainer *container,
37 static gint gail_container_real_add_gtk (GtkContainer *container,
40 static gint gail_container_real_remove_gtk (GtkContainer *container,
44 static void gail_container_real_initialize (AtkObject *obj,
47 static void gail_container_finalize (GObject *object);
49 G_DEFINE_TYPE (GailContainer, gail_container, GAIL_TYPE_WIDGET)
52 gail_container_class_init (GailContainerClass *klass)
54 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
55 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
57 gobject_class->finalize = gail_container_finalize;
59 class->get_n_children = gail_container_get_n_children;
60 class->ref_child = gail_container_ref_child;
61 class->initialize = gail_container_real_initialize;
63 klass->add_gtk = gail_container_real_add_gtk;
64 klass->remove_gtk = gail_container_real_remove_gtk;
68 gail_container_init (GailContainer *container)
70 container->children = NULL;
74 gail_container_get_n_children (AtkObject* obj)
80 g_return_val_if_fail (GAIL_IS_CONTAINER (obj), count);
82 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
86 children = gtk_container_get_children (GTK_CONTAINER(widget));
87 count = g_list_length (children);
88 g_list_free (children);
94 gail_container_ref_child (AtkObject *obj,
97 GList *children, *tmp_list;
98 AtkObject *accessible;
101 g_return_val_if_fail (GAIL_IS_CONTAINER (obj), NULL);
102 g_return_val_if_fail ((i >= 0), NULL);
104 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
108 children = gtk_container_get_children (GTK_CONTAINER (widget));
109 tmp_list = g_list_nth (children, i);
112 g_list_free (children);
115 accessible = gtk_widget_get_accessible (GTK_WIDGET (tmp_list->data));
117 g_list_free (children);
118 g_object_ref (accessible);
123 gail_container_add_gtk (GtkContainer *container,
127 GailContainer *gail_container = GAIL_CONTAINER (data);
128 GailContainerClass *klass;
130 klass = GAIL_CONTAINER_GET_CLASS (gail_container);
133 return klass->add_gtk (container, widget, data);
139 gail_container_remove_gtk (GtkContainer *container,
143 GailContainer *gail_container = GAIL_CONTAINER (data);
144 GailContainerClass *klass;
146 klass = GAIL_CONTAINER_GET_CLASS (gail_container);
148 if (klass->remove_gtk)
149 return klass->remove_gtk (container, widget, data);
155 gail_container_real_add_gtk (GtkContainer *container,
159 AtkObject* atk_parent = ATK_OBJECT (data);
160 AtkObject* atk_child = gtk_widget_get_accessible (widget);
161 GailContainer *gail_container = GAIL_CONTAINER (atk_parent);
164 g_object_notify (G_OBJECT (atk_child), "accessible_parent");
166 g_list_free (gail_container->children);
167 gail_container->children = gtk_container_get_children (container);
168 index = g_list_index (gail_container->children, widget);
169 g_signal_emit_by_name (atk_parent, "children_changed::add",
170 index, atk_child, NULL);
176 gail_container_real_remove_gtk (GtkContainer *container,
180 AtkPropertyValues values = { NULL };
181 AtkObject* atk_parent;
182 AtkObject *atk_child;
183 GailContainer *gail_container;
186 atk_parent = ATK_OBJECT (data);
187 atk_child = gtk_widget_get_accessible (widget);
191 g_value_init (&values.old_value, G_TYPE_POINTER);
192 g_value_set_pointer (&values.old_value, atk_parent);
194 values.property_name = "accessible-parent";
196 g_object_ref (atk_child);
197 g_signal_emit_by_name (atk_child,
198 "property_change::accessible-parent", &values, NULL);
199 g_object_unref (atk_child);
201 gail_container = GAIL_CONTAINER (atk_parent);
202 index = g_list_index (gail_container->children, widget);
203 g_list_free (gail_container->children);
204 gail_container->children = gtk_container_get_children (container);
205 if (index >= 0 && index <= g_list_length (gail_container->children))
206 g_signal_emit_by_name (atk_parent, "children_changed::remove",
207 index, atk_child, NULL);
213 gail_container_real_initialize (AtkObject *obj,
216 GailContainer *container = GAIL_CONTAINER (obj);
218 ATK_OBJECT_CLASS (gail_container_parent_class)->initialize (obj, data);
220 container->children = gtk_container_get_children (GTK_CONTAINER (data));
222 g_signal_connect (data, "add",
223 G_CALLBACK (gail_container_add_gtk),
225 g_signal_connect (data, "remove",
226 G_CALLBACK (gail_container_remove_gtk),
229 if (GTK_IS_TOOLBAR (data))
230 obj->role = ATK_ROLE_TOOL_BAR;
231 else if (GTK_IS_VIEWPORT (data))
232 obj->role = ATK_ROLE_VIEWPORT;
234 obj->role = ATK_ROLE_PANEL;
238 gail_container_finalize (GObject *object)
240 GailContainer *container = GAIL_CONTAINER (object);
242 g_list_free (container->children);
243 G_OBJECT_CLASS (gail_container_parent_class)->finalize (object);