2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 Ximian, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 /* table.c : implements the Table interface */
28 #include <bonobo/bonobo-exception.h>
29 #include <atk/atktable.h>
30 #include <libspi/accessible.h>
31 #include <libspi/table.h>
35 spi_table_interface_new (AtkObject *obj)
37 SpiTable *new_table = g_object_new (SPI_TABLE_TYPE, NULL);
39 spi_base_construct (SPI_BASE (new_table), G_OBJECT(obj));
46 get_table_from_servant (PortableServer_Servant servant)
48 SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
50 g_return_val_if_fail (object, NULL);
51 g_return_val_if_fail (ATK_IS_OBJECT(object->gobj), NULL);
52 return ATK_TABLE (object->gobj);
56 static Accessibility_Accessible
57 impl__get_caption (PortableServer_Servant servant,
58 CORBA_Environment *ev)
60 AtkObject *atk_object;
61 AtkTable *table = get_table_from_servant (servant);
63 g_return_val_if_fail (table != NULL, CORBA_OBJECT_NIL);
65 atk_object = atk_table_get_caption (table);
67 return spi_accessible_new_return (atk_object, FALSE, ev);
71 static Accessibility_Accessible
72 impl__get_summary (PortableServer_Servant servant,
73 CORBA_Environment *ev)
75 AtkObject *atk_object;
76 AtkTable *table = get_table_from_servant (servant);
78 g_return_val_if_fail (table != NULL, CORBA_OBJECT_NIL);
80 atk_object = atk_table_get_summary (table);
82 return spi_accessible_new_return (atk_object, FALSE, ev);
87 impl__get_nRows (PortableServer_Servant servant,
88 CORBA_Environment *ev)
90 AtkTable *table = get_table_from_servant (servant);
92 g_return_val_if_fail (table != NULL, 0);
94 return atk_table_get_n_rows (table);
99 impl__get_nColumns (PortableServer_Servant servant,
100 CORBA_Environment *ev)
102 AtkTable *table = get_table_from_servant (servant);
104 g_return_val_if_fail (table != NULL, 0);
106 return atk_table_get_n_columns (table);
110 static Accessibility_Accessible
111 impl_getAccessibleAt (PortableServer_Servant servant,
112 const CORBA_long row,
113 const CORBA_long column,
114 CORBA_Environment *ev)
116 AtkObject *atk_object;
117 AtkTable *table = get_table_from_servant (servant);
119 g_return_val_if_fail (table != NULL, CORBA_OBJECT_NIL);
121 atk_object = atk_table_ref_at (table, row, column);
123 return spi_accessible_new_return (atk_object, TRUE, ev);
128 impl_getIndexAt (PortableServer_Servant servant,
129 const CORBA_long row,
130 const CORBA_long column,
131 CORBA_Environment *ev)
133 AtkTable *table = get_table_from_servant (servant);
135 g_return_val_if_fail (table != NULL, 0);
137 return atk_table_get_index_at (table, row, column);
142 impl_getRowAtIndex (PortableServer_Servant servant,
143 const CORBA_long index,
144 CORBA_Environment *ev)
146 AtkTable *table = get_table_from_servant (servant);
148 g_return_val_if_fail (table != NULL, 0);
150 return atk_table_get_row_at_index (table, index);
155 impl_getColumnAtIndex (PortableServer_Servant servant,
156 const CORBA_long index,
157 CORBA_Environment *ev)
159 AtkTable *table = get_table_from_servant (servant);
161 g_return_val_if_fail (table != NULL, 0);
163 return atk_table_get_column_at_index (table, index);
168 impl_getRowDescription (PortableServer_Servant servant,
169 const CORBA_long row,
170 CORBA_Environment *ev)
173 AtkTable *table = get_table_from_servant (servant);
175 g_return_val_if_fail (table != NULL, 0);
177 rv = atk_table_get_row_description (table, row);
181 return CORBA_string_dup (rv);
185 return CORBA_string_dup ("");
191 impl_getColumnDescription (PortableServer_Servant servant,
192 const CORBA_long column,
193 CORBA_Environment *ev)
196 AtkTable *table = get_table_from_servant (servant);
198 g_return_val_if_fail (table != NULL, CORBA_string_dup (""));
200 rv = atk_table_get_row_description (table, column);
204 return CORBA_string_dup (rv);
208 return CORBA_string_dup ("");
214 impl_getRowExtentAt (PortableServer_Servant servant,
215 const CORBA_long row,
216 const CORBA_long column,
217 CORBA_Environment *ev)
219 AtkTable *table = get_table_from_servant (servant);
221 g_return_val_if_fail (table != NULL, -1);
223 return atk_table_get_row_extent_at (table, row, column);
228 impl_getColumnExtentAt (PortableServer_Servant servant,
229 const CORBA_long row,
230 const CORBA_long column,
231 CORBA_Environment *ev)
233 AtkTable *table = get_table_from_servant (servant);
235 g_return_val_if_fail (table != NULL, -1);
237 return atk_table_get_column_extent_at (table, row, column);
241 static Accessibility_Table
242 impl_getRowHeader (PortableServer_Servant servant,
243 const CORBA_long row,
244 CORBA_Environment *ev)
247 AtkTable *table = get_table_from_servant (servant);
249 g_return_val_if_fail (table != NULL, CORBA_OBJECT_NIL);
251 header = atk_table_get_row_header (table, row);
253 return spi_accessible_new_return (header, FALSE, ev);
257 static Accessibility_Table
258 impl_getColumnHeader (PortableServer_Servant servant,
259 const CORBA_long column,
260 CORBA_Environment *ev)
263 AtkTable *table = get_table_from_servant (servant);
265 g_return_val_if_fail (table != NULL, CORBA_OBJECT_NIL);
267 header = atk_table_get_column_header (table, column);
269 return spi_accessible_new_return (header, FALSE, ev);
273 static Accessibility_LongSeq *
274 impl_getSelectedRows (PortableServer_Servant servant,
275 CORBA_Environment *ev)
279 Accessibility_LongSeq *retval;
280 AtkTable *table = get_table_from_servant (servant);
282 bonobo_return_val_if_fail (table != NULL, NULL, ev);
284 length = atk_table_get_selected_rows (table, &selectedRows);
286 bonobo_return_val_if_fail (length > 0, NULL, ev);
288 retval = Accessibility_LongSeq__alloc ();
289 retval->_maximum = retval->_length = length;
290 retval->_buffer = Accessibility_LongSeq_allocbuf (length);
292 while (--length >= 0)
294 retval->_buffer[length] = selectedRows[length];
297 g_free (selectedRows);
303 static Accessibility_LongSeq *
304 impl_getSelectedColumns (PortableServer_Servant servant,
305 CORBA_Environment *ev)
307 gint *selectedColumns;
309 Accessibility_LongSeq *retval;
310 AtkTable *table = get_table_from_servant (servant);
312 bonobo_return_val_if_fail (table != NULL, NULL, ev);
314 length = atk_table_get_selected_columns (table, &selectedColumns);
316 bonobo_return_val_if_fail (length >= 0, NULL, ev);
318 retval = Accessibility_LongSeq__alloc ();
319 retval->_maximum = retval->_length = length;
320 retval->_buffer = Accessibility_LongSeq_allocbuf (length);
322 while (--length >= 0)
324 retval->_buffer[length] = (CORBA_long) selectedColumns[length];
327 g_free (selectedColumns);
334 impl_isRowSelected (PortableServer_Servant servant,
335 const CORBA_long row,
336 CORBA_Environment *ev)
338 AtkTable *table = get_table_from_servant (servant);
340 g_return_val_if_fail (table != NULL, FALSE);
342 return atk_table_is_row_selected (table, row);
347 impl_isColumnSelected (PortableServer_Servant servant,
348 const CORBA_long column,
349 CORBA_Environment *ev)
351 AtkTable *table = get_table_from_servant (servant);
353 g_return_val_if_fail (table != NULL, FALSE);
355 return atk_table_is_column_selected (table, column);
359 impl_addRowSelection (PortableServer_Servant servant,
360 const CORBA_long row,
361 CORBA_Environment *ev)
363 AtkTable *table = get_table_from_servant (servant);
365 g_return_val_if_fail (table != NULL, FALSE);
367 return atk_table_add_row_selection (table, row);
372 impl_addColumnSelection (PortableServer_Servant servant,
373 const CORBA_long column,
374 CORBA_Environment *ev)
376 AtkTable *table = get_table_from_servant (servant);
378 g_return_val_if_fail (table != NULL, FALSE);
380 return atk_table_add_column_selection (table, column);
385 impl_removeRowSelection (PortableServer_Servant servant,
386 const CORBA_long row,
387 CORBA_Environment *ev)
389 AtkTable *table = get_table_from_servant (servant);
391 g_return_val_if_fail (table != NULL, FALSE);
393 return atk_table_remove_row_selection (table, row);
398 impl_removeColumnSelection (PortableServer_Servant servant,
399 const CORBA_long column,
400 CORBA_Environment *ev)
402 AtkTable *table = get_table_from_servant (servant);
404 g_return_val_if_fail (table != NULL, FALSE);
406 return atk_table_remove_column_selection (table, column);
411 impl_isSelected (PortableServer_Servant servant,
412 const CORBA_long row,
413 const CORBA_long column,
414 CORBA_Environment *ev)
416 AtkTable *table = get_table_from_servant (servant);
418 g_return_val_if_fail (table != NULL, FALSE);
420 return atk_table_is_selected (table,
426 spi_table_class_init (SpiTableClass *klass)
428 POA_Accessibility_Table__epv *epv = &klass->epv;
430 /* Initialize epv table */
432 epv->_get_caption = impl__get_caption;
433 epv->_get_summary = impl__get_summary;
434 epv->_get_nRows = impl__get_nRows;
435 epv->_get_nColumns = impl__get_nColumns;
436 epv->getAccessibleAt = impl_getAccessibleAt;
437 epv->getIndexAt = impl_getIndexAt;
438 epv->getRowAtIndex = impl_getRowAtIndex;
439 epv->getColumnAtIndex = impl_getColumnAtIndex;
440 epv->getRowDescription = impl_getRowDescription;
441 epv->getColumnDescription = impl_getColumnDescription;
442 epv->getRowExtentAt = impl_getRowExtentAt;
443 epv->getColumnExtentAt = impl_getColumnExtentAt;
444 epv->getRowHeader = impl_getRowHeader;
445 epv->getColumnHeader = impl_getColumnHeader;
446 epv->getSelectedRows = impl_getSelectedRows;
447 epv->getSelectedColumns = impl_getSelectedColumns;
448 epv->isRowSelected = impl_isRowSelected;
449 epv->isColumnSelected = impl_isColumnSelected;
450 epv->addRowSelection = impl_addRowSelection;
451 epv->addColumnSelection = impl_addColumnSelection;
452 epv->removeRowSelection = impl_removeRowSelection;
453 epv->removeColumnSelection = impl_removeColumnSelection;
454 epv->isSelected = impl_isSelected;
458 spi_table_init (SpiTable *table)
462 BONOBO_TYPE_FUNC_FULL (SpiTable,