2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001 Sun Microsystems Inc.
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.
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.
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.
23 /* table.c : implements the Table interface */
27 #include <bonobo/bonobo-exception.h>
28 #include <atk/atktable.h>
29 #include <libspi/accessible.h>
30 #include <libspi/table.h>
34 spi_table_interface_new (AtkObject *obj)
36 SpiTable *new_table = g_object_new (SPI_TABLE_TYPE, NULL);
38 spi_base_construct (SPI_BASE (new_table), G_OBJECT(obj));
45 get_table_from_servant (PortableServer_Servant servant)
47 SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
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);
55 static Accessibility_Accessible
56 impl__get_caption (PortableServer_Servant servant,
57 CORBA_Environment *ev)
59 AtkObject *atk_object;
60 AtkTable *table = get_table_from_servant (servant);
62 g_return_val_if_fail (table != NULL, CORBA_OBJECT_NIL);
64 atk_object = atk_table_get_caption (table);
66 return spi_accessible_new_return (atk_object, FALSE, ev);
70 static Accessibility_Accessible
71 impl__get_summary (PortableServer_Servant servant,
72 CORBA_Environment *ev)
74 AtkObject *atk_object;
75 AtkTable *table = get_table_from_servant (servant);
77 g_return_val_if_fail (table != NULL, CORBA_OBJECT_NIL);
79 atk_object = atk_table_get_summary (table);
81 return spi_accessible_new_return (atk_object, FALSE, ev);
86 impl__get_nRows (PortableServer_Servant servant,
87 CORBA_Environment *ev)
89 AtkTable *table = get_table_from_servant (servant);
91 g_return_val_if_fail (table != NULL, 0);
93 return (CORBA_long) atk_table_get_n_rows (table);
98 impl__get_nColumns (PortableServer_Servant servant,
99 CORBA_Environment *ev)
101 AtkTable *table = get_table_from_servant (servant);
103 g_return_val_if_fail (table != NULL, 0);
105 return (CORBA_long) atk_table_get_n_columns (table);
109 static Accessibility_Accessible
110 impl_getAccessibleAt (PortableServer_Servant servant,
111 const CORBA_long row,
112 const CORBA_long column,
113 CORBA_Environment *ev)
115 AtkObject *atk_object;
116 AtkTable *table = get_table_from_servant (servant);
118 g_return_val_if_fail (table != NULL, CORBA_OBJECT_NIL);
120 atk_object = atk_table_ref_at (table,
121 (gint) row, (gint) 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);
138 atk_table_get_index_at (table, (gint) row, (gint) column);
143 impl_getRowAtIndex (PortableServer_Servant servant,
144 const CORBA_long index,
145 CORBA_Environment *ev)
147 AtkTable *table = get_table_from_servant (servant);
149 g_return_val_if_fail (table != NULL, 0);
152 atk_table_get_row_at_index (table, (gint) index);
157 impl_getColumnAtIndex (PortableServer_Servant servant,
158 const CORBA_long index,
159 CORBA_Environment *ev)
161 AtkTable *table = get_table_from_servant (servant);
163 g_return_val_if_fail (table != NULL, 0);
166 atk_table_get_column_at_index (table, (gint) index);
171 impl_getRowDescription (PortableServer_Servant servant,
172 const CORBA_long row,
173 CORBA_Environment *ev)
176 AtkTable *table = get_table_from_servant (servant);
178 g_return_val_if_fail (table != NULL, 0);
180 rv = atk_table_get_row_description (table, row);
184 return CORBA_string_dup (rv);
188 return CORBA_string_dup ("");
194 impl_getColumnDescription (PortableServer_Servant servant,
195 const CORBA_long column,
196 CORBA_Environment *ev)
199 AtkTable *table = get_table_from_servant (servant);
201 g_return_val_if_fail (table != NULL, CORBA_string_dup (""));
203 rv = atk_table_get_row_description (table, column);
207 return CORBA_string_dup (rv);
211 return CORBA_string_dup ("");
217 impl_getRowExtentAt (PortableServer_Servant servant,
218 const CORBA_long row,
219 const CORBA_long column,
220 CORBA_Environment *ev)
222 AtkTable *table = get_table_from_servant (servant);
224 g_return_val_if_fail (table != NULL, -1);
227 atk_table_get_row_extent_at (table,
228 (gint) row, (gint) column);
233 impl_getColumnExtentAt (PortableServer_Servant servant,
234 const CORBA_long row,
235 const CORBA_long column,
236 CORBA_Environment *ev)
238 AtkTable *table = get_table_from_servant (servant);
240 g_return_val_if_fail (table != NULL, -1);
243 atk_table_get_column_extent_at (table,
244 (gint) row, (gint) column);
248 static Accessibility_Table
249 impl_getRowHeader (PortableServer_Servant servant,
250 const CORBA_long row,
251 CORBA_Environment *ev)
254 AtkTable *table = get_table_from_servant (servant);
256 g_return_val_if_fail (table != NULL, CORBA_OBJECT_NIL);
258 header = atk_table_get_row_header (table, (gint) row);
260 return spi_accessible_new_return (header, FALSE, ev);
264 static Accessibility_Table
265 impl_getColumnHeader (PortableServer_Servant servant,
266 const CORBA_long column,
267 CORBA_Environment *ev)
270 AtkTable *table = get_table_from_servant (servant);
272 g_return_val_if_fail (table != NULL, CORBA_OBJECT_NIL);
274 header = atk_table_get_column_header (table, (gint) column);
276 return spi_accessible_new_return (header, FALSE, ev);
280 static Accessibility_LongSeq *
281 impl_getSelectedRows (PortableServer_Servant servant,
282 CORBA_Environment *ev)
286 Accessibility_LongSeq *retval;
287 AtkTable *table = get_table_from_servant (servant);
289 bonobo_return_val_if_fail (table != NULL, NULL, ev);
291 length = atk_table_get_selected_rows (table, &selectedRows);
293 bonobo_return_val_if_fail (length > 0, NULL, ev);
295 retval = Accessibility_LongSeq__alloc ();
296 retval->_maximum = retval->_length = (CORBA_long) length;
297 retval->_buffer = Accessibility_LongSeq_allocbuf (length);
301 retval->_buffer[length] = (CORBA_long) selectedRows[length];
304 g_free ((gpointer) selectedRows);
310 static Accessibility_LongSeq *
311 impl_getSelectedColumns (PortableServer_Servant servant,
312 CORBA_Environment *ev)
314 gint *selectedColumns;
316 Accessibility_LongSeq *retval;
317 AtkTable *table = get_table_from_servant (servant);
319 bonobo_return_val_if_fail (table != NULL, NULL, ev);
321 length = atk_table_get_selected_columns (table, &selectedColumns);
323 bonobo_return_val_if_fail (length >= 0, NULL, ev);
325 retval = Accessibility_LongSeq__alloc ();
326 retval->_maximum = retval->_length = (CORBA_long) length;
327 retval->_buffer = Accessibility_LongSeq_allocbuf (length);
331 retval->_buffer[length] = (CORBA_long) selectedColumns[length];
334 g_free ((gpointer) selectedColumns);
341 impl_isRowSelected (PortableServer_Servant servant,
342 const CORBA_long row,
343 CORBA_Environment *ev)
345 AtkTable *table = get_table_from_servant (servant);
347 g_return_val_if_fail (table != NULL, FALSE);
349 return (CORBA_boolean) atk_table_is_row_selected (table, (gint) row);
354 impl_isColumnSelected (PortableServer_Servant servant,
355 const CORBA_long column,
356 CORBA_Environment *ev)
358 AtkTable *table = get_table_from_servant (servant);
360 g_return_val_if_fail (table != NULL, FALSE);
362 return (CORBA_boolean) atk_table_is_column_selected (table, (gint) column);
367 impl_isSelected (PortableServer_Servant servant,
368 const CORBA_long row,
369 const CORBA_long column,
370 CORBA_Environment *ev)
372 AtkTable *table = get_table_from_servant (servant);
374 g_return_val_if_fail (table != NULL, FALSE);
376 return (CORBA_boolean) atk_table_is_selected (table,
377 (gint) row, (gint) column);
382 spi_table_class_init (SpiTableClass *klass)
384 POA_Accessibility_Table__epv *epv = &klass->epv;
386 /* Initialize epv table */
388 epv->_get_caption = impl__get_caption;
389 epv->_get_summary = impl__get_summary;
390 epv->_get_nRows = impl__get_nRows;
391 epv->_get_nColumns = impl__get_nColumns;
392 epv->getAccessibleAt = impl_getAccessibleAt;
393 epv->getIndexAt = impl_getIndexAt;
394 epv->getRowAtIndex = impl_getRowAtIndex;
395 epv->getColumnAtIndex = impl_getColumnAtIndex;
396 epv->getRowDescription = impl_getRowDescription;
397 epv->getColumnDescription = impl_getColumnDescription;
398 epv->getRowExtentAt = impl_getRowExtentAt;
399 epv->getColumnExtentAt = impl_getColumnExtentAt;
400 epv->getRowHeader = impl_getRowHeader;
401 epv->getColumnHeader = impl_getColumnHeader;
402 epv->getSelectedRows = impl_getSelectedRows;
403 epv->getSelectedColumns = impl_getSelectedColumns;
404 epv->isRowSelected = impl_isRowSelected;
405 epv->isColumnSelected = impl_isColumnSelected;
406 epv->isSelected = impl_isSelected;
410 spi_table_init (SpiTable *table)
414 BONOBO_TYPE_FUNC_FULL (SpiTable,