Started fixing IDL docs.
[platform/core/uifw/at-spi2-atk.git] / libspi / table.c
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 <libspi/accessible.h>
28 #include <libspi/table.h>
29
30 /* A pointer to our parent object class */
31 static GObjectClass *parent_class;
32
33 static void
34 spi_table_finalize (GObject *obj)
35 {
36   SpiTable *table = SPI_TABLE (obj);
37   g_object_unref (table->atko);
38   table->atko = NULL;  
39   parent_class->finalize (obj);
40 }
41
42 SpiTable *
43 spi_table_interface_new (AtkObject *obj)
44 {
45   SpiTable *new_table = g_object_new (SPI_TABLE_TYPE, NULL);
46   new_table->atko = obj;
47   g_object_ref (obj);
48   return new_table;
49 }
50
51
52
53 static Accessibility_Accessible
54 impl__get_caption (PortableServer_Servant _servant,
55                    CORBA_Environment * ev)
56 {
57   SpiTable *table = SPI_TABLE (bonobo_object_from_servant (_servant));
58   AtkObject *atk_object;
59   Accessibility_Accessible rv;
60
61   atk_object = atk_table_get_caption (ATK_TABLE(table-> atko));
62   rv = bonobo_object_corba_objref (BONOBO_OBJECT(spi_accessible_new(atk_object)));
63   return CORBA_Object_duplicate (rv, ev);
64 }
65
66
67
68 static Accessibility_Accessible
69 impl__get_summary (PortableServer_Servant _servant,
70                    CORBA_Environment * ev)
71 {
72   SpiTable *table = SPI_TABLE (bonobo_object_from_servant (_servant));
73   AtkObject *atk_object;
74   Accessibility_Accessible rv;
75
76   atk_object = atk_table_get_summary (ATK_TABLE(table->atko));
77   rv = bonobo_object_corba_objref (BONOBO_OBJECT(spi_accessible_new(atk_object)));
78   return CORBA_Object_duplicate (rv, ev);
79 }
80
81
82
83 static CORBA_long
84 impl__get_nRows (PortableServer_Servant _servant,
85                  CORBA_Environment * ev)
86 {
87   SpiTable *table = SPI_TABLE (bonobo_object_from_servant (_servant));
88   return (CORBA_long)
89     atk_table_get_n_rows (ATK_TABLE(table->atko) );
90 }
91
92
93
94 static CORBA_long
95 impl__get_nColumns (PortableServer_Servant _servant,
96                     CORBA_Environment * ev)
97 {
98   SpiTable *table = SPI_TABLE (bonobo_object_from_servant (_servant));
99   return (CORBA_long)
100     atk_table_get_n_columns (ATK_TABLE(table->atko));
101 }
102
103
104
105 static Accessibility_Accessible
106 impl_getAccessibleAt (PortableServer_Servant _servant,
107                       const CORBA_long row,
108                       const CORBA_long column,
109                       CORBA_Environment * ev)
110 {
111   SpiTable *table = SPI_TABLE (bonobo_object_from_servant (_servant));
112   AtkObject *atk_object;
113   Accessibility_Accessible rv;
114
115   atk_object = atk_table_ref_at (ATK_TABLE(table->atko),
116                                              (gint) row, (gint) column);
117   rv = bonobo_object_corba_objref (BONOBO_OBJECT(spi_accessible_new(atk_object)));
118   return CORBA_Object_duplicate (rv, ev);
119 }
120
121
122
123 static CORBA_long
124 impl_getIndexAt (PortableServer_Servant _servant,
125                  const CORBA_long row, const CORBA_long column,
126                  CORBA_Environment * ev)
127 {
128   SpiTable *table = SPI_TABLE (bonobo_object_from_servant (_servant));
129   return (CORBA_long)
130     atk_table_get_index_at (ATK_TABLE(table->atko),
131                             (gint) row, (gint) column);
132 }
133
134
135
136 static CORBA_long
137 impl_getRowAtIndex (PortableServer_Servant _servant,
138                     const CORBA_long index,
139                     CORBA_Environment * ev)
140 {
141   SpiTable *table = SPI_TABLE (bonobo_object_from_servant (_servant));
142   return (CORBA_long)
143     atk_table_get_row_at_index (ATK_TABLE(table->atko), (gint) index);
144 }
145
146
147
148 static CORBA_long
149 impl_getColumnAtIndex (PortableServer_Servant _servant,
150                        const CORBA_long index,
151                        CORBA_Environment * ev)
152 {
153   SpiTable *table = SPI_TABLE (bonobo_object_from_servant (_servant));
154   return (CORBA_long)
155     atk_table_get_column_at_index (ATK_TABLE(table->atko), (gint) index);
156 }
157
158
159
160 static CORBA_string
161 impl_getRowDescription (PortableServer_Servant servant,
162                         const CORBA_long       row,
163                         CORBA_Environment     *ev)
164 {
165   const char *rv;
166   SpiTable   *table;
167
168   table = SPI_TABLE (bonobo_object_from_servant (servant));
169   
170   rv = atk_table_get_row_description (ATK_TABLE (table->atko), row);
171
172   if (rv)
173     return CORBA_string_dup (rv);
174   else
175     return CORBA_string_dup ("");
176 }
177
178
179
180 static CORBA_string
181 impl_getColumnDescription (PortableServer_Servant servant,
182                            const CORBA_long       column,
183                            CORBA_Environment     *ev)
184 {
185   const char *rv;
186   SpiTable   *table;
187
188   table = SPI_TABLE (bonobo_object_from_servant (servant));
189   
190   rv = atk_table_get_row_description (ATK_TABLE (table->atko), column);
191
192   if (rv)
193     return CORBA_string_dup (rv);
194   else
195     return CORBA_string_dup ("");
196 }
197
198
199
200 static CORBA_long
201 impl_getRowExtentAt (PortableServer_Servant _servant,
202                      const CORBA_long row,
203                      const CORBA_long column,
204                      CORBA_Environment * ev)
205 {
206   SpiTable *table = SPI_TABLE (bonobo_object_from_servant (_servant));
207   return (CORBA_long)
208     atk_table_get_row_extent_at (ATK_TABLE(table->atko),
209                                  (gint) row, (gint) column);
210 }
211
212
213
214 static CORBA_long
215 impl_getColumnExtentAt (PortableServer_Servant _servant,
216                         const CORBA_long row,
217                         const CORBA_long column,
218                         CORBA_Environment * ev)
219 {
220   SpiTable *table = SPI_TABLE (bonobo_object_from_servant (_servant));
221   return (CORBA_long)
222     atk_table_get_column_extent_at (ATK_TABLE(table->atko),
223                                  (gint) row, (gint) column);
224 }
225
226
227
228 static Accessibility_Table
229 impl_getRowHeader (PortableServer_Servant _servant,
230                    const CORBA_long row,
231                    CORBA_Environment * ev)
232 {
233   SpiTable *table = SPI_TABLE (bonobo_object_from_servant (_servant));
234   AtkObject *header;
235   Accessibility_Table rv;
236
237   header = atk_table_get_row_header (ATK_TABLE(table->atko), (gint) row);
238   rv = bonobo_object_corba_objref (BONOBO_OBJECT(spi_accessible_new(header)));
239   return CORBA_Object_duplicate (rv, ev);
240 }
241
242
243
244 static        Accessibility_Table
245 impl_getColumnHeader (PortableServer_Servant _servant,
246                       const CORBA_long column,
247                       CORBA_Environment * ev)
248 {
249   SpiTable *table = SPI_TABLE (bonobo_object_from_servant (_servant));
250   AtkObject *header;
251   Accessibility_Table rv;
252
253   header = atk_table_get_column_header (ATK_TABLE(table->atko), (gint) column);
254   rv = bonobo_object_corba_objref (BONOBO_OBJECT(spi_accessible_new(header)));
255   return CORBA_Object_duplicate (rv, ev);
256 }
257
258
259
260 static Accessibility_LongSeq *
261 impl_getSelectedRows (PortableServer_Servant _servant,
262                       CORBA_Environment * ev)
263 {
264   SpiTable *table = SPI_TABLE (bonobo_object_from_servant (_servant));
265   gint *selectedRows;
266   gint length;
267   Accessibility_LongSeq *retval;
268
269   length = atk_table_get_selected_rows (ATK_TABLE(table->atko), &selectedRows);
270
271   g_return_val_if_fail (length, NULL);
272   retval = Accessibility_LongSeq__alloc ();
273   retval->_maximum = retval->_length = (CORBA_long) length;
274   retval->_buffer = Accessibility_LongSeq_allocbuf (length);
275
276   while (--length)
277     retval->_buffer[length] = (CORBA_long) selectedRows[length];
278   g_free ((gpointer) selectedRows);
279   return retval;
280 }
281
282
283
284 static Accessibility_LongSeq *
285 impl_getSelectedColumns (PortableServer_Servant _servant,
286                          CORBA_Environment * ev)
287 {
288   SpiTable *table = SPI_TABLE (bonobo_object_from_servant (_servant));
289   gint *selectedColumns;
290   gint length;
291   Accessibility_LongSeq *retval;
292
293   length = atk_table_get_selected_columns (ATK_TABLE(table->atko), &selectedColumns);
294
295   g_return_val_if_fail (length, NULL);
296
297   retval = Accessibility_LongSeq__alloc ();
298   retval->_maximum = retval->_length = (CORBA_long) length;
299   retval->_buffer = Accessibility_LongSeq_allocbuf (length);
300
301   while (--length)
302     retval->_buffer[length] = (CORBA_long) selectedColumns[length];
303   g_free ((gpointer) selectedColumns);
304   return retval;
305 }
306
307
308
309 static CORBA_boolean
310 impl_isRowSelected (PortableServer_Servant _servant,
311                     const CORBA_long row,
312                     CORBA_Environment * ev)
313 {
314   SpiTable *table = SPI_TABLE (bonobo_object_from_servant (_servant));
315   return (CORBA_boolean)
316     atk_table_is_row_selected (ATK_TABLE(table->atko), (gint) row);
317 }
318
319
320
321 static CORBA_boolean
322 impl_isColumnSelected (PortableServer_Servant _servant,
323                        const CORBA_long column,
324                        CORBA_Environment * ev)
325 {
326   SpiTable *table = SPI_TABLE (bonobo_object_from_servant (_servant));
327   return (CORBA_boolean)
328     atk_table_is_column_selected (ATK_TABLE(table->atko), (gint) column);
329 }
330
331
332
333 static CORBA_boolean
334 impl_isSelected (PortableServer_Servant _servant,
335                  const CORBA_long row,
336                  const CORBA_long column,
337                  CORBA_Environment * ev)
338 {
339   SpiTable *table = SPI_TABLE (bonobo_object_from_servant (_servant));
340   return (CORBA_boolean)
341     atk_table_is_selected (ATK_TABLE(table->atko),
342                            (gint) row, (gint) column);
343 }
344
345 static void
346 spi_table_class_init (SpiTableClass *klass)
347 {
348   GObjectClass * object_class = (GObjectClass *) klass;
349   POA_Accessibility_Table__epv *epv = &klass->epv;
350   parent_class = g_type_class_peek_parent (klass);
351
352   object_class->finalize = spi_table_finalize;
353
354
355   /* Initialize epv table */
356
357   epv->_get_caption = impl__get_caption;
358   epv->_get_summary = impl__get_summary;
359   epv->_get_nRows = impl__get_nRows;
360   epv->_get_nColumns = impl__get_nColumns;
361   epv->getAccessibleAt = impl_getAccessibleAt;
362   epv->getIndexAt = impl_getIndexAt;
363   epv->getRowAtIndex = impl_getRowAtIndex;
364   epv->getColumnAtIndex = impl_getColumnAtIndex;
365   epv->getRowDescription = impl_getRowDescription;
366   epv->getColumnDescription = impl_getColumnDescription;
367   epv->getRowExtentAt = impl_getRowExtentAt;
368   epv->getColumnExtentAt = impl_getColumnExtentAt;
369   epv->getRowHeader = impl_getRowHeader;
370   epv->getColumnHeader = impl_getColumnHeader;
371   epv->getSelectedRows = impl_getSelectedRows;
372   epv->getSelectedColumns = impl_getSelectedColumns;
373   epv->isRowSelected = impl_isRowSelected;
374   epv->isColumnSelected = impl_isColumnSelected;
375   epv->isSelected = impl_isSelected;
376 }
377
378 static void
379 spi_table_init (SpiTable *table)
380 {
381 }
382
383 BONOBO_TYPE_FUNC_FULL (SpiTable,
384                        Accessibility_Table,
385                        BONOBO_TYPE_OBJECT,
386                        spi_table);