Debian Codegraph @

gtk/a11y/gtkcontainercellaccessible.c

raw
1 /* GTK+ - accessibility implementations
2 * Copyright 2001 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 "gtkcontainercellaccessible.h"
22 #include "gtkcellaccessibleprivate.h"
23
24 struct _GtkContainerCellAccessiblePrivate
25 {
26 GList *children;
27 gint n_children;
28 };
29
30 G_DEFINE_TYPE_WITH_PRIVATE (GtkContainerCellAccessible, gtk_container_cell_accessible, GTK_TYPE_CELL_ACCESSIBLE)
31
32
33 static void
34 unset_child (gpointer child)
35 {
36 atk_object_set_parent (ATK_OBJECT (child), NULL);
37 g_object_unref (child);
38 }
39
40 static void
41 gtk_container_cell_accessible_finalize (GObject *obj)
42 {
43 GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (obj);
44
45 g_list_free_full (container->priv->children, unset_child);
46
47 G_OBJECT_CLASS (gtk_container_cell_accessible_parent_class)->finalize (obj);
48 }
49
50
51 static gint
52 gtk_container_cell_accessible_get_n_children (AtkObject *obj)
53 {
54 GtkContainerCellAccessible *cell = GTK_CONTAINER_CELL_ACCESSIBLE (obj);
55
56 return cell->priv->n_children;
57 }
58
59 static AtkObject *
60 gtk_container_cell_accessible_ref_child (AtkObject *obj,
61 gint child)
62 {
63 GtkContainerCellAccessible *cell = GTK_CONTAINER_CELL_ACCESSIBLE (obj);
64 GList *l;
65
66 l = g_list_nth (cell->priv->children, child);
67 if (l == NULL)
68 return NULL;
69
70 return g_object_ref (ATK_OBJECT (l->data));
71 }
72
73 static void
74 gtk_container_cell_accessible_update_cache (GtkCellAccessible *cell,
75 gboolean emit_signal)
76 {
77 GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (cell);
78 GList *l;
79
80 for (l = container->priv->children; l; l = l->next)
81 _gtk_cell_accessible_update_cache (l->data, emit_signal);
82 }
83
84 static void
85 gtk_container_cell_widget_set (GtkAccessible *accessible)
86 {
87 GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (accessible);
88 GList *l;
89
90 for (l = container->priv->children; l; l = l->next)
91 gtk_accessible_set_widget (l->data, gtk_accessible_get_widget (accessible));
92
93 GTK_ACCESSIBLE_CLASS (gtk_container_cell_accessible_parent_class)->widget_set (accessible);
94 }
95
96 static void
97 gtk_container_cell_widget_unset (GtkAccessible *accessible)
98 {
99 GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (accessible);
100 GList *l;
101
102 for (l = container->priv->children; l; l = l->next)
103 gtk_accessible_set_widget (l->data, NULL);
104
105 GTK_ACCESSIBLE_CLASS (gtk_container_cell_accessible_parent_class)->widget_unset (accessible);
106 }
107
108 static void
109 gtk_container_cell_accessible_class_init (GtkContainerCellAccessibleClass *klass)
110 {
111 GtkCellAccessibleClass *cell_class = GTK_CELL_ACCESSIBLE_CLASS (klass);
112 GtkAccessibleClass *accessible_class = GTK_ACCESSIBLE_CLASS (klass);
113 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
114 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
115
116 g_object_class->finalize = gtk_container_cell_accessible_finalize;
117
118 class->get_n_children = gtk_container_cell_accessible_get_n_children;
119 class->ref_child = gtk_container_cell_accessible_ref_child;
120
121 accessible_class->widget_set = gtk_container_cell_widget_set;
122 accessible_class->widget_unset = gtk_container_cell_widget_unset;
123
124 cell_class->update_cache = gtk_container_cell_accessible_update_cache;
125 }
126
127 static void
128 gtk_container_cell_accessible_init (GtkContainerCellAccessible *cell)
129 {
130 cell->priv = gtk_container_cell_accessible_get_instance_private (cell);
131 }
132
133 GtkContainerCellAccessible *
134 gtk_container_cell_accessible_new (void)
135 {
136 GObject *object;
137
138 object = g_object_new (GTK_TYPE_CONTAINER_CELL_ACCESSIBLE, NULL);
139
140 ATK_OBJECT (object)->role = ATK_ROLE_TABLE_CELL;
141
142 return GTK_CONTAINER_CELL_ACCESSIBLE (object);
143 }
144
145 void
146 gtk_container_cell_accessible_add_child (GtkContainerCellAccessible *container,
147 GtkCellAccessible *child)
148 {
149 g_return_if_fail (GTK_IS_CONTAINER_CELL_ACCESSIBLE (container));
150 g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (child));
151
152 g_object_ref (child);
153
154 container->priv->n_children++;
155 container->priv->children = g_list_append (container->priv->children, child);
156 atk_object_set_parent (ATK_OBJECT (child), ATK_OBJECT (container));
157 }
158
159 void
160 gtk_container_cell_accessible_remove_child (GtkContainerCellAccessible *container,
161 GtkCellAccessible *child)
162 {
163 g_return_if_fail (GTK_IS_CONTAINER_CELL_ACCESSIBLE (container));
164 g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (child));
165 g_return_if_fail (container->priv->n_children > 0);
166
167 atk_object_set_parent (ATK_OBJECT (child), NULL);
168 container->priv->children = g_list_remove (container->priv->children, child);
169 container->priv->n_children--;
170
171 g_object_unref (child);
172 }
173
174 /**
175 * gtk_container_cell_accessible_get_children:
176 * @container: the container
177 *
178 * Get a list of children.
179 *
180 * Returns: (transfer none) (element-type Gtk.CellAccessible)
181 */
182 GList *
183 gtk_container_cell_accessible_get_children (GtkContainerCellAccessible *container)
184 {
185 g_return_val_if_fail (GTK_IS_CONTAINER_CELL_ACCESSIBLE (container), NULL);
186
187 return container->priv->children;
188 }