1 | /* |
---|
2 | * AT-SPI - Assistive Technology Service Provider Interface |
---|
3 | * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) |
---|
4 | * |
---|
5 | * Copyright 2001 Sun Microsystems Inc. |
---|
6 | * |
---|
7 | * This library is free software; you can redistribute it and/or |
---|
8 | * modify it under the terms of the GNU Library General Public |
---|
9 | * License as published by the Free Software Foundation; either |
---|
10 | * version 2 of the License, or (at your option) any later version. |
---|
11 | * |
---|
12 | * This library is distributed in the hope that it will be useful, |
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
15 | * Library General Public License for more details. |
---|
16 | * |
---|
17 | * You should have received a copy of the GNU Library General Public |
---|
18 | * License along with this library; if not, write to the |
---|
19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
20 | * Boston, MA 02111-1307, USA. |
---|
21 | */ |
---|
22 | |
---|
23 | /* table.c : implements the Table interface */ |
---|
24 | |
---|
25 | #include <config.h> |
---|
26 | #include <stdio.h> |
---|
27 | #include <bonobo/bonobo-exception.h> |
---|
28 | #include <atk/atktable.h> |
---|
29 | #include <libspi/accessible.h> |
---|
30 | #include <libspi/table.h> |
---|
31 | |
---|
32 | |
---|
33 | SpiTable * |
---|
34 | spi_table_interface_new (AtkObject *obj) |
---|
35 | { |
---|
36 | SpiTable *new_table = g_object_new (SPI_TABLE_TYPE, NULL); |
---|
37 | |
---|
38 | spi_base_construct (SPI_BASE (new_table), G_OBJECT(obj)); |
---|
39 | |
---|
40 | return new_table; |
---|
41 | } |
---|
42 | |
---|
43 | |
---|
44 | static AtkTable * |
---|
45 | get_table_from_servant (PortableServer_Servant servant) |
---|
46 | { |
---|
47 | SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant)); |
---|
48 | |
---|
49 | g_return_val_if_fail (object, NULL); |
---|
50 | g_return_val_if_fail (ATK_IS_OBJECT(object->gobj), NULL); |
---|
51 | return ATK_TABLE (object->gobj); |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | static Accessibility_Accessible |
---|
56 | impl__get_caption (PortableServer_Servant servant, |
---|
57 | CORBA_Environment *ev) |
---|
58 | { |
---|
59 | AtkObject *atk_object; |
---|
60 | AtkTable *table = get_table_from_servant (servant); |
---|
61 | |
---|
62 | g_return_val_if_fail (table != NULL, CORBA_OBJECT_NIL); |
---|
63 | |
---|
64 | atk_object = atk_table_get_caption (table); |
---|
65 | |
---|
66 | return spi_accessible_new_return (atk_object, FALSE, ev); |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | static Accessibility_Accessible |
---|
71 | impl__get_summary (PortableServer_Servant servant, |
---|
72 | CORBA_Environment *ev) |
---|
73 | { |
---|
74 | AtkObject *atk_object; |
---|
75 | AtkTable *table = get_table_from_servant (servant); |
---|
76 | |
---|
77 | g_return_val_if_fail (table != NULL, CORBA_OBJECT_NIL); |
---|
78 | |
---|
79 | atk_object = atk_table_get_summary (table); |
---|
80 | |
---|
81 | return spi_accessible_new_return (atk_object, FALSE, ev); |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | static CORBA_long |
---|
86 | impl__get_nRows (PortableServer_Servant servant, |
---|
87 | CORBA_Environment *ev) |
---|
88 | { |
---|
89 | AtkTable *table = get_table_from_servant (servant); |
---|
90 | |
---|
91 | g_return_val_if_fail (table != NULL, 0); |
---|
92 | |
---|
93 | return atk_table_get_n_rows (table); |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | static CORBA_long |
---|
98 | impl__get_nColumns (PortableServer_Servant servant, |
---|
99 | CORBA_Environment *ev) |
---|
100 | { |
---|
101 | AtkTable *table = get_table_from_servant (servant); |
---|
102 | |
---|
103 | g_return_val_if_fail (table != NULL, 0); |
---|
104 | |
---|
105 | return atk_table_get_n_columns (table); |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | static Accessibility_Accessible |
---|
110 | impl_getAccessibleAt (PortableServer_Servant servant, |
---|
111 | const CORBA_long row, |
---|
112 | const CORBA_long column, |
---|
113 | CORBA_Environment *ev) |
---|
114 | { |
---|
115 | AtkObject *atk_object; |
---|
116 | AtkTable *table = get_table_from_servant (servant); |
---|
117 | |
---|
118 | g_return_val_if_fail (table != NULL, CORBA_OBJECT_NIL); |
---|
119 | |
---|
120 | atk_object = atk_table_ref_at (table, row, column); |
---|
121 | |
---|
122 | return spi_accessible_new_return (atk_object, TRUE, ev); |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | static CORBA_long |
---|
127 | impl_getIndexAt (PortableServer_Servant servant, |
---|
128 | const CORBA_long row, |
---|
129 | const CORBA_long column, |
---|
130 | CORBA_Environment *ev) |
---|
131 | { |
---|
132 | AtkTable *table = get_table_from_servant (servant); |
---|
133 | |
---|
134 | g_return_val_if_fail (table != NULL, 0); |
---|
135 | |
---|
136 | return atk_table_get_index_at (table, row, column); |
---|
137 | } |
---|
138 | |
---|
139 | |
---|
140 | static CORBA_long |
---|
141 | impl_getRowAtIndex (PortableServer_Servant servant, |
---|
142 | const CORBA_long index, |
---|
143 | CORBA_Environment *ev) |
---|
144 | { |
---|
145 | AtkTable *table = get_table_from_servant (servant); |
---|
146 | |
---|
147 | g_return_val_if_fail (table != NULL, 0); |
---|
148 | |
---|
149 | return atk_table_get_row_at_index (table, index); |
---|
150 | } |
---|
151 | |
---|
152 | |
---|
153 | static CORBA_long |
---|
154 | impl_getColumnAtIndex (PortableServer_Servant servant, |
---|
155 | const CORBA_long index, |
---|
156 | CORBA_Environment *ev) |
---|
157 | { |
---|
158 | AtkTable *table = get_table_from_servant (servant); |
---|
159 | |
---|
160 | g_return_val_if_fail (table != NULL, 0); |
---|
161 | |
---|
162 | return atk_table_get_column_at_index (table, index); |
---|
163 | } |
---|
164 | |
---|
165 | |
---|
166 | static CORBA_string |
---|
167 | impl_getRowDescription (PortableServer_Servant servant, |
---|
168 | const CORBA_long row, |
---|
169 | CORBA_Environment *ev) |
---|
170 | { |
---|
171 | const char *rv; |
---|
172 | AtkTable *table = get_table_from_servant (servant); |
---|
173 | |
---|
174 | g_return_val_if_fail (table != NULL, 0); |
---|
175 | |
---|
176 | rv = atk_table_get_row_description (table, row); |
---|
177 | |
---|
178 | if (rv) |
---|
179 | { |
---|
180 | return CORBA_string_dup (rv); |
---|
181 | } |
---|
182 | else |
---|
183 | { |
---|
184 | return CORBA_string_dup (""); |
---|
185 | } |
---|
186 | } |
---|
187 | |
---|
188 | |
---|
189 | static CORBA_string |
---|
190 | impl_getColumnDescription (PortableServer_Servant servant, |
---|
191 | const CORBA_long column, |
---|
192 | CORBA_Environment *ev) |
---|
193 | { |
---|
194 | const char *rv; |
---|
195 | AtkTable *table = get_table_from_servant (servant); |
---|
196 | |
---|
197 | g_return_val_if_fail (table != NULL, CORBA_string_dup ("")); |
---|
198 | |
---|
199 | rv = atk_table_get_row_description (table, column); |
---|
200 | |
---|
201 | if (rv) |
---|
202 | { |
---|
203 | return CORBA_string_dup (rv); |
---|
204 | } |
---|
205 | else |
---|
206 | { |
---|
207 | return CORBA_string_dup (""); |
---|
208 | } |
---|
209 | } |
---|
210 | |
---|
211 | |
---|
212 | static CORBA_long |
---|
213 | impl_getRowExtentAt (PortableServer_Servant servant, |
---|
214 | const CORBA_long row, |
---|
215 | const CORBA_long column, |
---|
216 | CORBA_Environment *ev) |
---|
217 | { |
---|
218 | AtkTable *table = get_table_from_servant (servant); |
---|
219 | |
---|
220 | g_return_val_if_fail (table != NULL, -1); |
---|
221 | |
---|
222 | return atk_table_get_row_extent_at (table, row, column); |
---|
223 | } |
---|
224 | |
---|
225 | |
---|
226 | static CORBA_long |
---|
227 | impl_getColumnExtentAt (PortableServer_Servant servant, |
---|
228 | const CORBA_long row, |
---|
229 | const CORBA_long column, |
---|
230 | CORBA_Environment *ev) |
---|
231 | { |
---|
232 | AtkTable *table = get_table_from_servant (servant); |
---|
233 | |
---|
234 | g_return_val_if_fail (table != NULL, -1); |
---|
235 | |
---|
236 | return atk_table_get_column_extent_at (table, row, column); |
---|
237 | } |
---|
238 | |
---|
239 | |
---|
240 | static Accessibility_Table |
---|
241 | impl_getRowHeader (PortableServer_Servant servant, |
---|
242 | const CORBA_long row, |
---|
243 | CORBA_Environment *ev) |
---|
244 | { |
---|
245 | AtkObject *header; |
---|
246 | AtkTable *table = get_table_from_servant (servant); |
---|
247 | |
---|
248 | g_return_val_if_fail (table != NULL, CORBA_OBJECT_NIL); |
---|
249 | |
---|
250 | header = atk_table_get_row_header (table, row); |
---|
251 | |
---|
252 | return spi_accessible_new_return (header, FALSE, ev); |
---|
253 | } |
---|
254 | |
---|
255 | |
---|
256 | static Accessibility_Table |
---|
257 | impl_getColumnHeader (PortableServer_Servant servant, |
---|
258 | const CORBA_long column, |
---|
259 | CORBA_Environment *ev) |
---|
260 | { |
---|
261 | AtkObject *header; |
---|
262 | AtkTable *table = get_table_from_servant (servant); |
---|
263 | |
---|
264 | g_return_val_if_fail (table != NULL, CORBA_OBJECT_NIL); |
---|
265 | |
---|
266 | header = atk_table_get_column_header (table, column); |
---|
267 | |
---|
268 | return spi_accessible_new_return (header, FALSE, ev); |
---|
269 | } |
---|
270 | |
---|
271 | |
---|
272 | static Accessibility_LongSeq * |
---|
273 | impl_getSelectedRows (PortableServer_Servant servant, |
---|
274 | CORBA_Environment *ev) |
---|
275 | { |
---|
276 | gint *selectedRows; |
---|
277 | gint length; |
---|
278 | Accessibility_LongSeq *retval; |
---|
279 | AtkTable *table = get_table_from_servant (servant); |
---|
280 | |
---|
281 | bonobo_return_val_if_fail (table != NULL, NULL, ev); |
---|
282 | |
---|
283 | length = atk_table_get_selected_rows (table, &selectedRows); |
---|
284 | |
---|
285 | bonobo_return_val_if_fail (length > 0, NULL, ev); |
---|
286 | |
---|
287 | retval = Accessibility_LongSeq__alloc (); |
---|
288 | retval->_maximum = retval->_length = length; |
---|
289 | retval->_buffer = Accessibility_LongSeq_allocbuf (length); |
---|
290 | |
---|
291 | while (--length >= 0) |
---|
292 | { |
---|
293 | retval->_buffer[length] = selectedRows[length]; |
---|
294 | } |
---|
295 | |
---|
296 | g_free (selectedRows); |
---|
297 | |
---|
298 | return retval; |
---|
299 | } |
---|
300 | |
---|
301 | |
---|
302 | static Accessibility_LongSeq * |
---|
303 | impl_getSelectedColumns (PortableServer_Servant servant, |
---|
304 | CORBA_Environment *ev) |
---|
305 | { |
---|
306 | gint *selectedColumns; |
---|
307 | gint length; |
---|
308 | Accessibility_LongSeq *retval; |
---|
309 | AtkTable *table = get_table_from_servant (servant); |
---|
310 | |
---|
311 | bonobo_return_val_if_fail (table != NULL, NULL, ev); |
---|
312 | |
---|
313 | length = atk_table_get_selected_columns (table, &selectedColumns); |
---|
314 | |
---|
315 | bonobo_return_val_if_fail (length >= 0, NULL, ev); |
---|
316 | |
---|
317 | retval = Accessibility_LongSeq__alloc (); |
---|
318 | retval->_maximum = retval->_length = length; |
---|
319 | retval->_buffer = Accessibility_LongSeq_allocbuf (length); |
---|
320 | |
---|
321 | while (--length >= 0) |
---|
322 | { |
---|
323 | retval->_buffer[length] = (CORBA_long) selectedColumns[length]; |
---|
324 | } |
---|
325 | |
---|
326 | g_free (selectedColumns); |
---|
327 | |
---|
328 | return retval; |
---|
329 | } |
---|
330 | |
---|
331 | |
---|
332 | static CORBA_boolean |
---|
333 | impl_isRowSelected (PortableServer_Servant servant, |
---|
334 | const CORBA_long row, |
---|
335 | CORBA_Environment *ev) |
---|
336 | { |
---|
337 | AtkTable *table = get_table_from_servant (servant); |
---|
338 | |
---|
339 | g_return_val_if_fail (table != NULL, FALSE); |
---|
340 | |
---|
341 | return atk_table_is_row_selected (table, row); |
---|
342 | } |
---|
343 | |
---|
344 | |
---|
345 | static CORBA_boolean |
---|
346 | impl_isColumnSelected (PortableServer_Servant servant, |
---|
347 | const CORBA_long column, |
---|
348 | CORBA_Environment *ev) |
---|
349 | { |
---|
350 | AtkTable *table = get_table_from_servant (servant); |
---|
351 | |
---|
352 | g_return_val_if_fail (table != NULL, FALSE); |
---|
353 | |
---|
354 | return atk_table_is_column_selected (table, column); |
---|
355 | } |
---|
356 | |
---|
357 | static CORBA_boolean |
---|
358 | impl_addRowSelection (PortableServer_Servant servant, |
---|
359 | const CORBA_long row, |
---|
360 | CORBA_Environment *ev) |
---|
361 | { |
---|
362 | AtkTable *table = get_table_from_servant (servant); |
---|
363 | |
---|
364 | g_return_val_if_fail (table != NULL, FALSE); |
---|
365 | |
---|
366 | return atk_table_add_row_selection (table, row); |
---|
367 | } |
---|
368 | |
---|
369 | |
---|
370 | static CORBA_boolean |
---|
371 | impl_addColumnSelection (PortableServer_Servant servant, |
---|
372 | const CORBA_long column, |
---|
373 | CORBA_Environment *ev) |
---|
374 | { |
---|
375 | AtkTable *table = get_table_from_servant (servant); |
---|
376 | |
---|
377 | g_return_val_if_fail (table != NULL, FALSE); |
---|
378 | |
---|
379 | return atk_table_add_column_selection (table, column); |
---|
380 | } |
---|
381 | |
---|
382 | |
---|
383 | static CORBA_boolean |
---|
384 | impl_removeRowSelection (PortableServer_Servant servant, |
---|
385 | const CORBA_long row, |
---|
386 | CORBA_Environment *ev) |
---|
387 | { |
---|
388 | AtkTable *table = get_table_from_servant (servant); |
---|
389 | |
---|
390 | g_return_val_if_fail (table != NULL, FALSE); |
---|
391 | |
---|
392 | return atk_table_remove_row_selection (table, row); |
---|
393 | } |
---|
394 | |
---|
395 | |
---|
396 | static CORBA_boolean |
---|
397 | impl_removeColumnSelection (PortableServer_Servant servant, |
---|
398 | const CORBA_long column, |
---|
399 | CORBA_Environment *ev) |
---|
400 | { |
---|
401 | AtkTable *table = get_table_from_servant (servant); |
---|
402 | |
---|
403 | g_return_val_if_fail (table != NULL, FALSE); |
---|
404 | |
---|
405 | return atk_table_remove_column_selection (table, column); |
---|
406 | } |
---|
407 | |
---|
408 | |
---|
409 | static CORBA_boolean |
---|
410 | impl_isSelected (PortableServer_Servant servant, |
---|
411 | const CORBA_long row, |
---|
412 | const CORBA_long column, |
---|
413 | CORBA_Environment *ev) |
---|
414 | { |
---|
415 | AtkTable *table = get_table_from_servant (servant); |
---|
416 | |
---|
417 | g_return_val_if_fail (table != NULL, FALSE); |
---|
418 | |
---|
419 | return atk_table_is_selected (table, |
---|
420 | row, column); |
---|
421 | } |
---|
422 | |
---|
423 | |
---|
424 | static void |
---|
425 | spi_table_class_init (SpiTableClass *klass) |
---|
426 | { |
---|
427 | POA_Accessibility_Table__epv *epv = &klass->epv; |
---|
428 | |
---|
429 | /* Initialize epv table */ |
---|
430 | |
---|
431 | epv->_get_caption = impl__get_caption; |
---|
432 | epv->_get_summary = impl__get_summary; |
---|
433 | epv->_get_nRows = impl__get_nRows; |
---|
434 | epv->_get_nColumns = impl__get_nColumns; |
---|
435 | epv->getAccessibleAt = impl_getAccessibleAt; |
---|
436 | epv->getIndexAt = impl_getIndexAt; |
---|
437 | epv->getRowAtIndex = impl_getRowAtIndex; |
---|
438 | epv->getColumnAtIndex = impl_getColumnAtIndex; |
---|
439 | epv->getRowDescription = impl_getRowDescription; |
---|
440 | epv->getColumnDescription = impl_getColumnDescription; |
---|
441 | epv->getRowExtentAt = impl_getRowExtentAt; |
---|
442 | epv->getColumnExtentAt = impl_getColumnExtentAt; |
---|
443 | epv->getRowHeader = impl_getRowHeader; |
---|
444 | epv->getColumnHeader = impl_getColumnHeader; |
---|
445 | epv->getSelectedRows = impl_getSelectedRows; |
---|
446 | epv->getSelectedColumns = impl_getSelectedColumns; |
---|
447 | epv->isRowSelected = impl_isRowSelected; |
---|
448 | epv->isColumnSelected = impl_isColumnSelected; |
---|
449 | epv->addRowSelection = impl_addRowSelection; |
---|
450 | epv->addColumnSelection = impl_addColumnSelection; |
---|
451 | epv->removeRowSelection = impl_removeRowSelection; |
---|
452 | epv->removeColumnSelection = impl_removeColumnSelection; |
---|
453 | epv->isSelected = impl_isSelected; |
---|
454 | } |
---|
455 | |
---|
456 | static void |
---|
457 | spi_table_init (SpiTable *table) |
---|
458 | { |
---|
459 | } |
---|
460 | |
---|
461 | BONOBO_TYPE_FUNC_FULL (SpiTable, |
---|
462 | Accessibility_Table, |
---|
463 | SPI_TYPE_BASE, |
---|
464 | spi_table); |
---|