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, NULL);
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_column_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 impl__get_nSelectedRows (PortableServer_Servant servant,
274 CORBA_Environment *ev)
276 gint *selectedRows = NULL;
278 AtkTable *table = get_table_from_servant (servant);
280 bonobo_return_val_if_fail (table != NULL, 0, ev);
282 retval = atk_table_get_selected_rows (table, &selectedRows);
283 if (selectedRows) g_free (selectedRows);
289 impl__get_nSelectedColumns (PortableServer_Servant servant,
290 CORBA_Environment *ev)
292 gint *selectedColumns = NULL;
294 AtkTable *table = get_table_from_servant (servant);
296 bonobo_return_val_if_fail (table != NULL, 0, ev);
298 retval = atk_table_get_selected_columns (table, &selectedColumns);
299 if (selectedColumns) g_free (selectedColumns);
303 static Accessibility_LongSeq *
304 impl_getSelectedRows (PortableServer_Servant servant,
305 CORBA_Environment *ev)
307 gint *selectedRows = NULL;
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_rows (table, &selectedRows);
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] = selectedRows[length];
327 if (selectedRows) g_free (selectedRows);
333 static Accessibility_LongSeq *
334 impl_getSelectedColumns (PortableServer_Servant servant,
335 CORBA_Environment *ev)
337 gint *selectedColumns = NULL;
339 Accessibility_LongSeq *retval;
340 AtkTable *table = get_table_from_servant (servant);
342 bonobo_return_val_if_fail (table != NULL, NULL, ev);
344 length = atk_table_get_selected_columns (table, &selectedColumns);
346 bonobo_return_val_if_fail (length >= 0, NULL, ev);
348 retval = Accessibility_LongSeq__alloc ();
349 retval->_maximum = retval->_length = length;
350 retval->_buffer = Accessibility_LongSeq_allocbuf (length);
352 while (--length >= 0)
354 retval->_buffer[length] = (CORBA_long) selectedColumns[length];
357 if (selectedColumns) g_free (selectedColumns);
364 impl_isRowSelected (PortableServer_Servant servant,
365 const CORBA_long row,
366 CORBA_Environment *ev)
368 AtkTable *table = get_table_from_servant (servant);
370 g_return_val_if_fail (table != NULL, FALSE);
372 return atk_table_is_row_selected (table, row);
377 impl_isColumnSelected (PortableServer_Servant servant,
378 const CORBA_long column,
379 CORBA_Environment *ev)
381 AtkTable *table = get_table_from_servant (servant);
383 g_return_val_if_fail (table != NULL, FALSE);
385 return atk_table_is_column_selected (table, column);
389 impl_addRowSelection (PortableServer_Servant servant,
390 const CORBA_long row,
391 CORBA_Environment *ev)
393 AtkTable *table = get_table_from_servant (servant);
395 g_return_val_if_fail (table != NULL, FALSE);
397 return atk_table_add_row_selection (table, row);
402 impl_addColumnSelection (PortableServer_Servant servant,
403 const CORBA_long column,
404 CORBA_Environment *ev)
406 AtkTable *table = get_table_from_servant (servant);
408 g_return_val_if_fail (table != NULL, FALSE);
410 return atk_table_add_column_selection (table, column);
415 impl_removeRowSelection (PortableServer_Servant servant,
416 const CORBA_long row,
417 CORBA_Environment *ev)
419 AtkTable *table = get_table_from_servant (servant);
421 g_return_val_if_fail (table != NULL, FALSE);
423 return atk_table_remove_row_selection (table, row);
428 impl_removeColumnSelection (PortableServer_Servant servant,
429 const CORBA_long column,
430 CORBA_Environment *ev)
432 AtkTable *table = get_table_from_servant (servant);
434 g_return_val_if_fail (table != NULL, FALSE);
436 return atk_table_remove_column_selection (table, column);
441 impl_getRowColumnExtentsAtIndex (PortableServer_Servant servant,
442 const CORBA_long index,
445 CORBA_long *row_extents,
446 CORBA_long *col_extents,
447 CORBA_boolean *is_selected,
448 CORBA_Environment *ev)
453 AtkTable *table = get_table_from_servant (servant);
454 gint intColumn, intRow, intRow_extents, intCol_extents;
455 gboolean boolIs_selected;
457 g_return_val_if_fail (table != NULL, FALSE);
459 intColumn = atk_table_get_column_at_index (table, index);
460 intRow = atk_table_get_row_at_index (table, index);
461 intRow_extents = atk_table_get_row_extent_at (table, intRow, intColumn);
462 intCol_extents = atk_table_get_column_extent_at (table, intRow, intColumn);
463 boolIs_selected = atk_table_is_selected (table, intRow, intColumn);
467 *row_extents = intRow_extents;
468 *col_extents = intCol_extents;
469 *is_selected = boolIs_selected;
471 cell = atk_table_ref_at (table, intRow, intColumn);
472 role = atk_object_get_role (cell);
474 if (role == ATK_ROLE_TABLE_CELL)
482 impl_isSelected (PortableServer_Servant servant,
483 const CORBA_long row,
484 const CORBA_long column,
485 CORBA_Environment *ev)
487 AtkTable *table = get_table_from_servant (servant);
489 g_return_val_if_fail (table != NULL, FALSE);
491 return atk_table_is_selected (table,
497 spi_table_class_init (SpiTableClass *klass)
499 POA_Accessibility_Table__epv *epv = &klass->epv;
501 /* Initialize epv table */
503 epv->_get_caption = impl__get_caption;
504 epv->_get_summary = impl__get_summary;
505 epv->_get_nRows = impl__get_nRows;
506 epv->_get_nColumns = impl__get_nColumns;
507 epv->_get_nSelectedRows = impl__get_nSelectedRows;
508 epv->_get_nSelectedColumns = impl__get_nSelectedColumns;
509 epv->getAccessibleAt = impl_getAccessibleAt;
510 epv->getIndexAt = impl_getIndexAt;
511 epv->getRowAtIndex = impl_getRowAtIndex;
512 epv->getColumnAtIndex = impl_getColumnAtIndex;
513 epv->getRowDescription = impl_getRowDescription;
514 epv->getColumnDescription = impl_getColumnDescription;
515 epv->getRowExtentAt = impl_getRowExtentAt;
516 epv->getColumnExtentAt = impl_getColumnExtentAt;
517 epv->getRowHeader = impl_getRowHeader;
518 epv->getColumnHeader = impl_getColumnHeader;
519 epv->getSelectedRows = impl_getSelectedRows;
520 epv->getSelectedColumns = impl_getSelectedColumns;
521 epv->isRowSelected = impl_isRowSelected;
522 epv->isColumnSelected = impl_isColumnSelected;
523 epv->addRowSelection = impl_addRowSelection;
524 epv->addColumnSelection = impl_addColumnSelection;
525 epv->removeRowSelection = impl_removeRowSelection;
526 epv->removeColumnSelection = impl_removeColumnSelection;
527 epv->isSelected = impl_isSelected;
528 epv->getRowColumnExtentsAtIndex = impl_getRowColumnExtentsAtIndex;
532 spi_table_init (SpiTable *table)
536 BONOBO_TYPE_FUNC_FULL (SpiTable,