Debian Codegraph @

modules/other/gail/gaillist.c

raw symbols SCIP
1 /* GAIL - The GNOME Accessibility Enabling Library
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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
19
20 #include "config.h"
21
22 #undef GTK_DISABLE_DEPRECATED
23
24 #include <gtk/gtk.h>
25 #include "gaillist.h"
26 #include "gailcombo.h"
27
28 static void gail_list_class_init (GailListClass *klass);
29
30 static void gail_list_init (GailList *list);
31
32 static void gail_list_initialize (AtkObject *accessible,
33 gpointer data);
34
35 static gint gail_list_get_index_in_parent (AtkObject *accessible);
36
37 static void atk_selection_interface_init (AtkSelectionIface *iface);
38 static gboolean gail_list_add_selection (AtkSelection *selection,
39 gint i);
40 static gboolean gail_list_clear_selection (AtkSelection *selection);
41 static AtkObject* gail_list_ref_selection (AtkSelection *selection,
42 gint i);
43 static gint gail_list_get_selection_count (AtkSelection *selection);
44 static gboolean gail_list_is_child_selected (AtkSelection *selection,
45 gint i);
46 static gboolean gail_list_remove_selection (AtkSelection *selection,
47 gint i);
48
49
50 G_DEFINE_TYPE_WITH_CODE (GailList, gail_list, GAIL_TYPE_CONTAINER,
51 G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init))
52
53 static void
54 gail_list_class_init (GailListClass *klass)
55 {
56 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
57
58 class->initialize = gail_list_initialize;
59 class->get_index_in_parent = gail_list_get_index_in_parent;
60 }
61
62 static void
63 gail_list_init (GailList *list)
64 {
65 }
66
67 static void
68 gail_list_initialize (AtkObject *accessible,
69 gpointer data)
70 {
71 ATK_OBJECT_CLASS (gail_list_parent_class)->initialize (accessible, data);
72
73 accessible->role = ATK_ROLE_LIST;
74 }
75
76 static gint
77 gail_list_get_index_in_parent (AtkObject *accessible)
78 {
79 /*
80 * If the parent widget is a combo box then the index is 0
81 * otherwise do the normal thing.
82 */
83 if (accessible->accessible_parent)
84 {
85 if (GAIL_IS_COMBO (accessible->accessible_parent))
86 return 0;
87 }
88 return ATK_OBJECT_CLASS (gail_list_parent_class)->get_index_in_parent (accessible);
89 }
90
91 static void
92 atk_selection_interface_init (AtkSelectionIface *iface)
93 {
94 iface->add_selection = gail_list_add_selection;
95 iface->clear_selection = gail_list_clear_selection;
96 iface->ref_selection = gail_list_ref_selection;
97 iface->get_selection_count = gail_list_get_selection_count;
98 iface->is_child_selected = gail_list_is_child_selected;
99 iface->remove_selection = gail_list_remove_selection;
100 /*
101 * select_all_selection does not make sense for a combo box
102 * so no implementation is provided.
103 */
104 }
105
106 static gboolean
107 gail_list_add_selection (AtkSelection *selection,
108 gint i)
109 {
110 GtkList *list;
111 GtkWidget *widget;
112
113 widget = GTK_ACCESSIBLE (selection)->widget;
114 if (widget == NULL)
115 /*
116 * State is defunct
117 */
118 return FALSE;
119
120 list = GTK_LIST (widget);
121
122 gtk_list_select_item (list, i);
123 return TRUE;
124 }
125
126 static gboolean
127 gail_list_clear_selection (AtkSelection *selection)
128 {
129 GtkList *list;
130 GtkWidget *widget;
131
132 widget = GTK_ACCESSIBLE (selection)->widget;
133 if (widget == NULL)
134 /*
135 * State is defunct
136 */
137 return FALSE;
138
139 list = GTK_LIST (widget);
140
141 gtk_list_unselect_all (list);
142 return TRUE;
143 }
144
145 static AtkObject*
146 gail_list_ref_selection (AtkSelection *selection,
147 gint i)
148 {
149 GtkList *list;
150 GList *g_list;
151 GtkWidget *item;
152 AtkObject *obj;
153 GtkWidget *widget;
154
155 widget = GTK_ACCESSIBLE (selection)->widget;
156 if (widget == NULL)
157 /*
158 * State is defunct
159 */
160 return NULL;
161
162 list = GTK_LIST (widget);
163
164 /*
165 * A combo box can have only one selection.
166 */
167 if (i != 0)
168 return NULL;
169
170 g_list = list->selection;
171
172 if (g_list == NULL)
173 return NULL;
174
175 item = GTK_WIDGET (g_list->data);
176
177 obj = gtk_widget_get_accessible (item);
178 g_object_ref (obj);
179 return obj;
180 }
181
182 static gint
183 gail_list_get_selection_count (AtkSelection *selection)
184 {
185 GtkList *list;
186 GList *g_list;
187 GtkWidget *widget;
188
189 widget = GTK_ACCESSIBLE (selection)->widget;
190 if (widget == NULL)
191 /*
192 * State is defunct
193 */
194 return 0;
195
196 list = GTK_LIST (widget);
197
198 g_list = list->selection;
199
200 return g_list_length (g_list);;
201 }
202
203 static gboolean
204 gail_list_is_child_selected (AtkSelection *selection,
205 gint i)
206 {
207 GtkList *list;
208 GList *g_list;
209 GtkWidget *item;
210 gint j;
211 GtkWidget *widget;
212
213 widget = GTK_ACCESSIBLE (selection)->widget;
214 if (widget == NULL)
215 /*
216 * State is defunct
217 */
218 return FALSE;
219
220 list = GTK_LIST (widget);
221
222 g_list = list->selection;
223
224 if (g_list == NULL)
225 return FALSE;
226
227 item = GTK_WIDGET (g_list->data);
228
229 j = g_list_index (list->children, item);
230
231 return (j == i);
232 }
233
234 static gboolean
235 gail_list_remove_selection (AtkSelection *selection,
236 gint i)
237 {
238 if (atk_selection_is_child_selected (selection, i))
239 atk_selection_clear_selection (selection);
240
241 return TRUE;
242 }