]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtkcontaineraccessible.c
Change FSF Address
[~andy/gtk] / gtk / a11y / gtkcontaineraccessible.c
1 /* GAIL - The GNOME Accessibility Implementation Library
2  * Copyright 2001, 2002, 2003 Sun Microsystems Inc.
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 #include "config.h"
19
20 #include <gtk/gtk.h>
21 #include "gtkcontaineraccessible.h"
22
23
24 G_DEFINE_TYPE (GtkContainerAccessible, _gtk_container_accessible, GTK_TYPE_WIDGET_ACCESSIBLE)
25
26 static gint
27 gtk_container_accessible_get_n_children (AtkObject* obj)
28 {
29   GtkWidget *widget;
30   GList *children;
31   gint count = 0;
32
33   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
34   if (widget == NULL)
35     return 0;
36
37   children = gtk_container_get_children (GTK_CONTAINER(widget));
38   count = g_list_length (children);
39   g_list_free (children);
40
41   return count;
42 }
43
44 static AtkObject *
45 gtk_container_accessible_ref_child (AtkObject *obj,
46                                     gint       i)
47 {
48   GList *children, *tmp_list;
49   AtkObject  *accessible;
50   GtkWidget *widget;
51
52   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
53   if (widget == NULL)
54     return NULL;
55
56   children = gtk_container_get_children (GTK_CONTAINER (widget));
57   tmp_list = g_list_nth (children, i);
58   if (!tmp_list)
59     {
60       g_list_free (children);
61       return NULL;
62     }
63   accessible = gtk_widget_get_accessible (GTK_WIDGET (tmp_list->data));
64
65   g_list_free (children);
66   g_object_ref (accessible);
67
68   return accessible;
69 }
70
71 static gint
72 gtk_container_accessible_add_gtk (GtkContainer *container,
73                                   GtkWidget    *widget,
74                                   gpointer      data)
75 {
76   GtkContainerAccessible *accessible = GTK_CONTAINER_ACCESSIBLE (data);
77   GtkContainerAccessibleClass *klass;
78
79   klass = GTK_CONTAINER_ACCESSIBLE_GET_CLASS (accessible);
80
81   if (klass->add_gtk)
82     return klass->add_gtk (container, widget, data);
83   else
84     return 1;
85 }
86  
87 static gint
88 gtk_container_accessible_remove_gtk (GtkContainer *container,
89                            GtkWidget    *widget,
90                            gpointer     data)
91 {
92   GtkContainerAccessible *accessible = GTK_CONTAINER_ACCESSIBLE (data);
93   GtkContainerAccessibleClass *klass;
94
95   klass = GTK_CONTAINER_ACCESSIBLE_GET_CLASS (accessible);
96
97   if (klass->remove_gtk)
98     return klass->remove_gtk (container, widget, data);
99   else
100     return 1;
101 }
102
103 static gint
104 gtk_container_accessible_real_add_gtk (GtkContainer *container,
105                                        GtkWidget    *widget,
106                                        gpointer      data)
107 {
108   AtkObject *atk_parent;
109   AtkObject *atk_child;
110   GtkContainerAccessible *accessible;
111   gint index;
112
113   atk_parent = ATK_OBJECT (data);
114   atk_child = gtk_widget_get_accessible (widget);
115   accessible = GTK_CONTAINER_ACCESSIBLE (atk_parent);
116
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);
122
123   return 1;
124 }
125
126 static gint
127 gtk_container_accessible_real_remove_gtk (GtkContainer *container,
128                                           GtkWidget    *widget,
129                                           gpointer      data)
130 {
131   AtkObject* atk_parent;
132   AtkObject *atk_child;
133   GtkContainerAccessible *accessible;
134   gint index;
135
136   atk_parent = ATK_OBJECT (data);
137   atk_child = gtk_widget_get_accessible (widget);
138   if (atk_child == NULL)
139     return 1;
140   accessible = GTK_CONTAINER_ACCESSIBLE (atk_parent);
141
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);
148
149   return 1;
150 }
151
152 static void
153 gtk_container_accessible_real_initialize (AtkObject *obj,
154                                           gpointer   data)
155 {
156   GtkContainerAccessible *accessible = GTK_CONTAINER_ACCESSIBLE (obj);
157
158   ATK_OBJECT_CLASS (_gtk_container_accessible_parent_class)->initialize (obj, data);
159
160   accessible->children = gtk_container_get_children (GTK_CONTAINER (data));
161
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);
164
165   obj->role = ATK_ROLE_PANEL;
166 }
167
168 static void
169 gtk_container_accessible_finalize (GObject *object)
170 {
171   GtkContainerAccessible *accessible = GTK_CONTAINER_ACCESSIBLE (object);
172
173   g_list_free (accessible->children);
174
175   G_OBJECT_CLASS (_gtk_container_accessible_parent_class)->finalize (object);
176 }
177
178 static void
179 _gtk_container_accessible_class_init (GtkContainerAccessibleClass *klass)
180 {
181   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
182   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
183
184   gobject_class->finalize = gtk_container_accessible_finalize;
185
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;
189
190   klass->add_gtk = gtk_container_accessible_real_add_gtk;
191   klass->remove_gtk = gtk_container_accessible_real_remove_gtk;
192 }
193
194 static void
195 _gtk_container_accessible_init (GtkContainerAccessible *container)
196 {
197 }
198