Fixed refcounting issues with interface server
[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 = g_object_new (ATK_TYPE_OBJECT, NULL);
237   atk_object_set_name (atk_object, atk_table_get_caption (ATK_TABLE(table-> atko)));
238   rv = bonobo_object_corba_objref (BONOBO_OBJECT(accessible_new(atk_object)));
239   return rv;
240 }
241
242
243
244 static Accessibility_Accessible
245 impl__get_summary (PortableServer_Servant _servant,
246                    CORBA_Environment * ev)
247 {
248   Table *table = TABLE (bonobo_object_from_servant (_servant));
249   AtkObject *atk_object;
250   Accessibility_Accessible rv;
251
252   atk_object = atk_table_get_summary (ATK_TABLE(table->atko));
253   rv = bonobo_object_corba_objref (BONOBO_OBJECT(accessible_new(atk_object)));
254   return rv;
255 }
256
257
258
259 static CORBA_long
260 impl__get_nRows (PortableServer_Servant _servant,
261                  CORBA_Environment * ev)
262 {
263   Table *table = TABLE (bonobo_object_from_servant (_servant));
264   return (CORBA_long)
265     atk_table_get_n_rows (ATK_TABLE(table->atko) );
266 }
267
268
269
270 static CORBA_long
271 impl__get_nColumns (PortableServer_Servant _servant,
272                     CORBA_Environment * ev)
273 {
274   Table *table = TABLE (bonobo_object_from_servant (_servant));
275   return (CORBA_long)
276     atk_table_get_n_columns (ATK_TABLE(table->atko));
277 }
278
279
280
281 static Accessibility_Accessible
282 impl_getAccessibleAt (PortableServer_Servant _servant,
283                       const CORBA_long row,
284                       const CORBA_long column,
285                       CORBA_Environment * ev)
286 {
287   Table *table = TABLE (bonobo_object_from_servant (_servant));
288   AtkObject *atk_object;
289   Accessibility_Accessible rv;
290
291   atk_object = atk_table_ref_at (ATK_TABLE(table->atko),
292                                              (gint) row, (gint) column);
293   rv = bonobo_object_corba_objref (BONOBO_OBJECT(accessible_new(atk_object)));
294   return rv;
295 }
296
297
298
299 static CORBA_long
300 impl_getIndexAt (PortableServer_Servant _servant,
301                  const CORBA_long row, const CORBA_long column,
302                  CORBA_Environment * ev)
303 {
304   Table *table = TABLE (bonobo_object_from_servant (_servant));
305   return (CORBA_long)
306     atk_table_get_index_at (ATK_TABLE(table->atko),
307                             (gint) row, (gint) column);
308 }
309
310
311
312 static CORBA_long
313 impl_getRowAtIndex (PortableServer_Servant _servant,
314                     const CORBA_long index,
315                     CORBA_Environment * ev)
316 {
317   Table *table = TABLE (bonobo_object_from_servant (_servant));
318   return (CORBA_long)
319     atk_table_get_row_at_index (ATK_TABLE(table->atko), (gint) index);
320 }
321
322
323
324 static CORBA_long
325 impl_getColumnAtIndex (PortableServer_Servant _servant,
326                        const CORBA_long index,
327                        CORBA_Environment * ev)
328 {
329   Table *table = TABLE (bonobo_object_from_servant (_servant));
330   return (CORBA_long)
331     atk_table_get_column_at_index (ATK_TABLE(table->atko), (gint) index);
332 }
333
334
335
336 static CORBA_string
337 impl_getRowDescription (PortableServer_Servant _servant,
338                         const CORBA_long row,
339                         CORBA_Environment * ev)
340 {
341   Table *table = TABLE (bonobo_object_from_servant (_servant));
342   return CORBA_string_dup (
343                            atk_table_get_row_description (ATK_TABLE(table->atko), (gint) row));
344 }
345
346
347
348 static CORBA_string
349 impl_getColumnDescription (PortableServer_Servant _servant,
350                            const CORBA_long column,
351                            CORBA_Environment * ev)
352 {
353   Table *table = TABLE (bonobo_object_from_servant (_servant));
354   return CORBA_string_dup (
355                            atk_table_get_column_description (ATK_TABLE(table->atko), (gint) column));
356 }
357
358
359
360 static CORBA_long
361 impl_getRowExtentAt (PortableServer_Servant _servant,
362                      const CORBA_long row,
363                      const CORBA_long column,
364                      CORBA_Environment * ev)
365 {
366   Table *table = TABLE (bonobo_object_from_servant (_servant));
367   return (CORBA_long)
368     atk_table_get_row_extent_at (ATK_TABLE(table->atko),
369                                  (gint) row, (gint) column);
370 }
371
372
373
374 static CORBA_long
375 impl_getColumnExtentAt (PortableServer_Servant _servant,
376                         const CORBA_long row,
377                         const CORBA_long column,
378                         CORBA_Environment * ev)
379 {
380   Table *table = TABLE (bonobo_object_from_servant (_servant));
381   return (CORBA_long)
382     atk_table_get_column_extent_at (ATK_TABLE(table->atko),
383                                  (gint) row, (gint) column);
384 }
385
386
387
388 static Accessibility_Table
389 impl_getRowHeader (PortableServer_Servant _servant,
390                    const CORBA_long row,
391                    CORBA_Environment * ev)
392 {
393   Table *table = TABLE (bonobo_object_from_servant (_servant));
394   AtkObject *header;
395   Accessibility_Table rv;
396
397   header = atk_table_get_row_header (ATK_TABLE(table->atko), (gint) row);
398   rv = bonobo_object_corba_objref (BONOBO_OBJECT(accessible_new(header)));
399   return rv;
400 }
401
402
403
404 static        Accessibility_Table
405 impl_getColumnHeader (PortableServer_Servant _servant,
406                       const CORBA_long column,
407                       CORBA_Environment * ev)
408 {
409   Table *table = TABLE (bonobo_object_from_servant (_servant));
410   AtkObject *header;
411   Accessibility_Table rv;
412
413   header = atk_table_get_column_header (ATK_TABLE(table->atko), (gint) column);
414   rv = bonobo_object_corba_objref (BONOBO_OBJECT(accessible_new(header)));
415   return rv;
416 }
417
418
419
420 static Accessibility_LongSeq *
421 impl_getSelectedRows (PortableServer_Servant _servant,
422                       CORBA_Environment * ev)
423 {
424   Table *table = TABLE (bonobo_object_from_servant (_servant));
425   gint *selectedRows;
426   gint length;
427   Accessibility_LongSeq *retval;
428
429   length = atk_table_get_selected_rows (ATK_TABLE(table->atko), &selectedRows);
430
431   g_return_val_if_fail (length, NULL);
432   retval = Accessibility_LongSeq__alloc ();
433   retval->_maximum = retval->_length = (CORBA_long) length;
434   retval->_buffer = Accessibility_LongSeq_allocbuf (length);
435
436   while (--length)
437     retval->_buffer[length] = (CORBA_long) selectedRows[length];
438   g_free ((gpointer) selectedRows);
439   return retval;
440 }
441
442
443
444 static Accessibility_LongSeq *
445 impl_getSelectedColumns (PortableServer_Servant _servant,
446                          CORBA_Environment * ev)
447 {
448   Table *table = TABLE (bonobo_object_from_servant (_servant));
449   gint *selectedColumns;
450   gint length;
451   Accessibility_LongSeq *retval;
452
453   length = atk_table_get_selected_columns (ATK_TABLE(table->atko), &selectedColumns);
454
455   g_return_val_if_fail (length, NULL);
456
457   retval = Accessibility_LongSeq__alloc ();
458   retval->_maximum = retval->_length = (CORBA_long) length;
459   retval->_buffer = Accessibility_LongSeq_allocbuf (length);
460
461   while (--length)
462     retval->_buffer[length] = (CORBA_long) selectedColumns[length];
463   g_free ((gpointer) selectedColumns);
464   return retval;
465 }
466
467
468
469 static CORBA_boolean
470 impl_isRowSelected (PortableServer_Servant _servant,
471                     const CORBA_long row,
472                     CORBA_Environment * ev)
473 {
474   Table *table = TABLE (bonobo_object_from_servant (_servant));
475   return (CORBA_boolean)
476     atk_table_is_row_selected (ATK_TABLE(table->atko), (gint) row);
477 }
478
479
480
481 static CORBA_boolean
482 impl_isColumnSelected (PortableServer_Servant _servant,
483                        const CORBA_long column,
484                        CORBA_Environment * ev)
485 {
486   Table *table = TABLE (bonobo_object_from_servant (_servant));
487   return (CORBA_boolean)
488     atk_table_is_column_selected (ATK_TABLE(table->atko), (gint) column);
489 }
490
491
492
493 static CORBA_boolean
494 impl_isSelected (PortableServer_Servant _servant,
495                  const CORBA_long row,
496                  const CORBA_long column,
497                  CORBA_Environment * ev)
498 {
499   Table *table = TABLE (bonobo_object_from_servant (_servant));
500   return (CORBA_boolean)
501     atk_table_is_selected (ATK_TABLE(table->atko),
502                            (gint) row, (gint) column);
503 }
504
505
506