Cleaned up some suspect int* casts, and added assertions to text calls in libspi
[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 /*
24  * component.c : bonobo wrapper for accessible component implementation
25  *
26  */
27 #include <config.h>
28 #include <bonobo/Bonobo.h>
29
30 #include <stdio.h>
31
32 /*
33  * This pulls the CORBA definitions for the "Accessibility::Accessible" server
34  */
35 #include <libspi/Accessibility.h>
36
37 /*
38  * This pulls the definition of the Table bonobo object
39  */
40 #include "table.h"
41
42 /*
43  * Static function declarations
44  */
45
46 static void
47 table_class_init (TableClass *klass);
48 static void
49 table_init (Table *table);
50 static void
51 table_finalize (GObject *obj);
52 static Accessibility_Accessible
53 impl__get_caption (PortableServer_Servant _servant,
54                    CORBA_Environment * ev);
55 static Accessibility_Accessible
56 impl__get_summary (PortableServer_Servant _servant,
57                    CORBA_Environment * ev);
58 static CORBA_long
59 impl__get_nRows (PortableServer_Servant _servant,
60                  CORBA_Environment * ev);
61 static CORBA_long
62 impl__get_nRows (PortableServer_Servant _servant,
63                  CORBA_Environment * ev);
64 static CORBA_long
65 impl__get_nColumns (PortableServer_Servant _servant,
66                     CORBA_Environment * ev);
67 static Accessibility_Accessible
68 impl_getAccessibleAt (PortableServer_Servant _servant,
69                       const CORBA_long row,
70                       const CORBA_long column,
71                       CORBA_Environment * ev);
72 static CORBA_long
73 impl_getIndexAt (PortableServer_Servant _servant,
74                  const CORBA_long row, const CORBA_long column,
75                  CORBA_Environment * ev);
76 static CORBA_long
77 impl_getRowAtIndex (PortableServer_Servant _servant,
78                     const CORBA_long index,
79                     CORBA_Environment * ev);
80 static CORBA_long
81 impl_getColumnAtIndex (PortableServer_Servant _servant,
82                        const CORBA_long index,
83                        CORBA_Environment * ev);
84 static CORBA_string
85 impl_getRowDescription (PortableServer_Servant _servant,
86                         const CORBA_long row,
87                         CORBA_Environment * ev);
88 static CORBA_string
89 impl_getColumnDescription (PortableServer_Servant _servant,
90                            const CORBA_long column,
91                            CORBA_Environment * ev);
92 static CORBA_long
93 impl_getRowExtentAt (PortableServer_Servant _servant,
94                      const CORBA_long row,
95                      const CORBA_long column,
96                      CORBA_Environment * ev);
97 static CORBA_long
98 impl_getColumnExtentAt (PortableServer_Servant _servant,
99                         const CORBA_long row,
100                         const CORBA_long column,
101                         CORBA_Environment * ev);
102 static Accessibility_Table
103 impl_getRowHeader (PortableServer_Servant _servant,
104                    const CORBA_long row,
105                    CORBA_Environment * ev);
106 static        Accessibility_Table
107 impl_getColumnHeader (PortableServer_Servant _servant,
108                       const CORBA_long column,
109                       CORBA_Environment * ev);
110 static Accessibility_LongSeq *
111 impl_getSelectedRows (PortableServer_Servant _servant,
112                       CORBA_Environment * ev);
113 static Accessibility_LongSeq *
114 impl_getSelectedColumns (PortableServer_Servant _servant,
115                          CORBA_Environment * ev);
116 static CORBA_boolean
117 impl_isRowSelected (PortableServer_Servant _servant,
118                     const CORBA_long row,
119                     CORBA_Environment * ev);
120 static CORBA_boolean
121 impl_isColumnSelected (PortableServer_Servant _servant,
122                        const CORBA_long column,
123                        CORBA_Environment * ev);
124 static CORBA_boolean
125 impl_isSelected (PortableServer_Servant _servant,
126                  const CORBA_long row,
127                  const CORBA_long column,
128                  CORBA_Environment * ev);
129
130
131 static GObjectClass *parent_class;
132
133 GType
134 table_get_type (void)
135 {
136   static GType type = 0;
137
138   if (!type) {
139     static const GTypeInfo tinfo = {
140       sizeof (TableClass),
141       (GBaseInitFunc) NULL,
142       (GBaseFinalizeFunc) NULL,
143       (GClassInitFunc) table_class_init,
144       (GClassFinalizeFunc) NULL,
145       NULL, /* class data */
146       sizeof (Table),
147       0, /* n preallocs */
148       (GInstanceInitFunc) table_init,
149                         NULL /* value table */
150     };
151
152     /*
153      * Bonobo_type_unique auto-generates a load of
154      * CORBA structures for us. All derived types must
155      * use bonobo_type_unique.
156      */
157     type = bonobo_type_unique (
158                                BONOBO_OBJECT_TYPE,
159                                POA_Accessibility_Table__init,
160                                NULL,
161                                G_STRUCT_OFFSET (TableClass, epv),
162                                &tinfo,
163                                "AccessibleTable");
164   }
165
166   return type;
167 }
168
169 static void
170 table_class_init (TableClass *klass)
171 {
172   GObjectClass * object_class = (GObjectClass *) klass;
173   POA_Accessibility_Table__epv *epv = &klass->epv;
174   parent_class = g_type_class_peek_parent (klass);
175
176   object_class->finalize = table_finalize;
177
178
179   /* Initialize epv table */
180
181   epv->_get_caption = impl__get_caption;
182   epv->_get_summary = impl__get_summary;
183   epv->_get_nRows = impl__get_nRows;
184   epv->_get_nColumns = impl__get_nColumns;
185   epv->getAccessibleAt = impl_getAccessibleAt;
186   epv->getIndexAt = impl_getIndexAt;
187   epv->getRowAtIndex = impl_getRowAtIndex;
188   epv->getColumnAtIndex = impl_getColumnAtIndex;
189   epv->getRowDescription = impl_getRowDescription;
190   epv->getColumnDescription = impl_getColumnDescription;
191   epv->getRowExtentAt = impl_getRowExtentAt;
192   epv->getColumnExtentAt = impl_getColumnExtentAt;
193   epv->getRowHeader = impl_getRowHeader;
194   epv->getColumnHeader = impl_getColumnHeader;
195   epv->getSelectedRows = impl_getSelectedRows;
196   epv->getSelectedColumns = impl_getSelectedColumns;
197   epv->isRowSelected = impl_isRowSelected;
198   epv->isColumnSelected = impl_isColumnSelected;
199   epv->isSelected = impl_isSelected;
200 }
201
202 static void
203 table_init (Table *table)
204 {
205 }
206
207 static void
208 table_finalize (GObject *obj)
209 {
210   Table *table = TABLE (obj);
211   g_object_unref (table->atko);
212   table->atko = NULL;  
213   parent_class->finalize (obj);
214 }
215
216 Table *
217 table_interface_new (AtkObject *obj)
218 {
219   Table *new_table =
220     TABLE(g_object_new (TABLE_TYPE, NULL));
221   new_table->atko = obj;
222   g_object_ref (obj);
223   return new_table;
224 }
225
226
227
228 static Accessibility_Accessible
229 impl__get_caption (PortableServer_Servant _servant,
230                    CORBA_Environment * ev)
231 {
232   Table *table = TABLE (bonobo_object_from_servant (_servant));
233   AtkObject *atk_object;
234   Accessibility_Accessible rv;
235
236   atk_object = atk_table_get_caption (ATK_TABLE(table-> atko));
237   rv = bonobo_object_corba_objref (BONOBO_OBJECT(accessible_new(atk_object)));
238   return rv;
239 }
240
241
242
243 static Accessibility_Accessible
244 impl__get_summary (PortableServer_Servant _servant,
245                    CORBA_Environment * ev)
246 {
247   Table *table = TABLE (bonobo_object_from_servant (_servant));
248   AtkObject *atk_object;
249   Accessibility_Accessible rv;
250
251   atk_object = atk_table_get_summary (ATK_TABLE(table->atko));
252   rv = bonobo_object_corba_objref (BONOBO_OBJECT(accessible_new(atk_object)));
253   return rv;
254 }
255
256
257
258 static CORBA_long
259 impl__get_nRows (PortableServer_Servant _servant,
260                  CORBA_Environment * ev)
261 {
262   Table *table = TABLE (bonobo_object_from_servant (_servant));
263   return (CORBA_long)
264     atk_table_get_n_rows (ATK_TABLE(table->atko) );
265 }
266
267
268
269 static CORBA_long
270 impl__get_nColumns (PortableServer_Servant _servant,
271                     CORBA_Environment * ev)
272 {
273   Table *table = TABLE (bonobo_object_from_servant (_servant));
274   return (CORBA_long)
275     atk_table_get_n_columns (ATK_TABLE(table->atko));
276 }
277
278
279
280 static Accessibility_Accessible
281 impl_getAccessibleAt (PortableServer_Servant _servant,
282                       const CORBA_long row,
283                       const CORBA_long column,
284                       CORBA_Environment * ev)
285 {
286   Table *table = TABLE (bonobo_object_from_servant (_servant));
287   AtkObject *atk_object;
288   Accessibility_Accessible rv;
289
290   atk_object = atk_table_ref_at (ATK_TABLE(table->atko),
291                                              (gint) row, (gint) column);
292   rv = bonobo_object_corba_objref (BONOBO_OBJECT(accessible_new(atk_object)));
293   return rv;
294 }
295
296
297
298 static CORBA_long
299 impl_getIndexAt (PortableServer_Servant _servant,
300                  const CORBA_long row, const CORBA_long column,
301                  CORBA_Environment * ev)
302 {
303   Table *table = TABLE (bonobo_object_from_servant (_servant));
304   return (CORBA_long)
305     atk_table_get_index_at (ATK_TABLE(table->atko),
306                             (gint) row, (gint) column);
307 }
308
309
310
311 static CORBA_long
312 impl_getRowAtIndex (PortableServer_Servant _servant,
313                     const CORBA_long index,
314                     CORBA_Environment * ev)
315 {
316   Table *table = TABLE (bonobo_object_from_servant (_servant));
317   return (CORBA_long)
318     atk_table_get_row_at_index (ATK_TABLE(table->atko), (gint) index);
319 }
320
321
322
323 static CORBA_long
324 impl_getColumnAtIndex (PortableServer_Servant _servant,
325                        const CORBA_long index,
326                        CORBA_Environment * ev)
327 {
328   Table *table = TABLE (bonobo_object_from_servant (_servant));
329   return (CORBA_long)
330     atk_table_get_column_at_index (ATK_TABLE(table->atko), (gint) index);
331 }
332
333
334
335 static CORBA_string
336 impl_getRowDescription (PortableServer_Servant _servant,
337                         const CORBA_long row,
338                         CORBA_Environment * ev)
339 {
340   Table *table = TABLE (bonobo_object_from_servant (_servant));
341   CORBA_char *rv;
342
343   rv = atk_table_get_row_description (ATK_TABLE(table->atko), (gint) row);
344   if (rv)
345     return CORBA_string_dup (rv);
346   else
347     return CORBA_string_dup ("");
348 }
349
350
351
352 static CORBA_string
353 impl_getColumnDescription (PortableServer_Servant _servant,
354                            const CORBA_long column,
355                            CORBA_Environment * ev)
356 {
357   Table *table = TABLE (bonobo_object_from_servant (_servant));
358   CORBA_char *rv;
359
360   rv = atk_table_get_column_description (ATK_TABLE(table->atko), (gint) column);
361   if (rv)
362     return CORBA_string_dup (rv);
363   else
364     return CORBA_string_dup ("");
365 }
366
367
368
369 static CORBA_long
370 impl_getRowExtentAt (PortableServer_Servant _servant,
371                      const CORBA_long row,
372                      const CORBA_long column,
373                      CORBA_Environment * ev)
374 {
375   Table *table = TABLE (bonobo_object_from_servant (_servant));
376   return (CORBA_long)
377     atk_table_get_row_extent_at (ATK_TABLE(table->atko),
378                                  (gint) row, (gint) column);
379 }
380
381
382
383 static CORBA_long
384 impl_getColumnExtentAt (PortableServer_Servant _servant,
385                         const CORBA_long row,
386                         const CORBA_long column,
387                         CORBA_Environment * ev)
388 {
389   Table *table = TABLE (bonobo_object_from_servant (_servant));
390   return (CORBA_long)
391     atk_table_get_column_extent_at (ATK_TABLE(table->atko),
392                                  (gint) row, (gint) column);
393 }
394
395
396
397 static Accessibility_Table
398 impl_getRowHeader (PortableServer_Servant _servant,
399                    const CORBA_long row,
400                    CORBA_Environment * ev)
401 {
402   Table *table = TABLE (bonobo_object_from_servant (_servant));
403   AtkObject *header;
404   Accessibility_Table rv;
405
406   header = atk_table_get_row_header (ATK_TABLE(table->atko), (gint) row);
407   rv = bonobo_object_corba_objref (BONOBO_OBJECT(accessible_new(header)));
408   return rv;
409 }
410
411
412
413 static        Accessibility_Table
414 impl_getColumnHeader (PortableServer_Servant _servant,
415                       const CORBA_long column,
416                       CORBA_Environment * ev)
417 {
418   Table *table = TABLE (bonobo_object_from_servant (_servant));
419   AtkObject *header;
420   Accessibility_Table rv;
421
422   header = atk_table_get_column_header (ATK_TABLE(table->atko), (gint) column);
423   rv = bonobo_object_corba_objref (BONOBO_OBJECT(accessible_new(header)));
424   return rv;
425 }
426
427
428
429 static Accessibility_LongSeq *
430 impl_getSelectedRows (PortableServer_Servant _servant,
431                       CORBA_Environment * ev)
432 {
433   Table *table = TABLE (bonobo_object_from_servant (_servant));
434   gint *selectedRows;
435   gint length;
436   Accessibility_LongSeq *retval;
437
438   length = atk_table_get_selected_rows (ATK_TABLE(table->atko), &selectedRows);
439
440   g_return_val_if_fail (length, NULL);
441   retval = Accessibility_LongSeq__alloc ();
442   retval->_maximum = retval->_length = (CORBA_long) length;
443   retval->_buffer = Accessibility_LongSeq_allocbuf (length);
444
445   while (--length)
446     retval->_buffer[length] = (CORBA_long) selectedRows[length];
447   g_free ((gpointer) selectedRows);
448   return retval;
449 }
450
451
452
453 static Accessibility_LongSeq *
454 impl_getSelectedColumns (PortableServer_Servant _servant,
455                          CORBA_Environment * ev)
456 {
457   Table *table = TABLE (bonobo_object_from_servant (_servant));
458   gint *selectedColumns;
459   gint length;
460   Accessibility_LongSeq *retval;
461
462   length = atk_table_get_selected_columns (ATK_TABLE(table->atko), &selectedColumns);
463
464   g_return_val_if_fail (length, NULL);
465
466   retval = Accessibility_LongSeq__alloc ();
467   retval->_maximum = retval->_length = (CORBA_long) length;
468   retval->_buffer = Accessibility_LongSeq_allocbuf (length);
469
470   while (--length)
471     retval->_buffer[length] = (CORBA_long) selectedColumns[length];
472   g_free ((gpointer) selectedColumns);
473   return retval;
474 }
475
476
477
478 static CORBA_boolean
479 impl_isRowSelected (PortableServer_Servant _servant,
480                     const CORBA_long row,
481                     CORBA_Environment * ev)
482 {
483   Table *table = TABLE (bonobo_object_from_servant (_servant));
484   return (CORBA_boolean)
485     atk_table_is_row_selected (ATK_TABLE(table->atko), (gint) row);
486 }
487
488
489
490 static CORBA_boolean
491 impl_isColumnSelected (PortableServer_Servant _servant,
492                        const CORBA_long column,
493                        CORBA_Environment * ev)
494 {
495   Table *table = TABLE (bonobo_object_from_servant (_servant));
496   return (CORBA_boolean)
497     atk_table_is_column_selected (ATK_TABLE(table->atko), (gint) column);
498 }
499
500
501
502 static CORBA_boolean
503 impl_isSelected (PortableServer_Servant _servant,
504                  const CORBA_long row,
505                  const CORBA_long column,
506                  CORBA_Environment * ev)
507 {
508   Table *table = TABLE (bonobo_object_from_servant (_servant));
509   return (CORBA_boolean)
510     atk_table_is_selected (ATK_TABLE(table->atko),
511                            (gint) row, (gint) column);
512 }
513
514
515