2001-12-10 Michael Meeks <michael@ximian.com>
[platform/core/uifw/at-spi2-atk.git] / cspi / spi_table.c
1 #include <stdlib.h> /* for malloc */
2 #include <cspi/spi-private.h>
3
4 /**
5  * AccessibleTable_ref:
6  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
7  *
8  * Increment the reference count for an #AccessibleTable object.
9  **/
10 void
11 AccessibleTable_ref (AccessibleTable *obj)
12 {
13   cspi_object_ref (obj);
14 }
15
16 /**
17  * AccessibleTable_unref:
18  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
19  *
20  * Decrement the reference count for an #AccessibleTable object.
21  **/
22 void
23 AccessibleTable_unref (AccessibleTable *obj)
24 {
25   cspi_object_unref (obj);
26 }
27
28 /**
29  * AccessibleTable_getCaption:
30  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
31  *
32  * Get an accessible representation of the caption for an #AccessibleTable.
33  *
34  * Returns: an #Accessible object that serves as the table's caption.
35  **/
36 Accessible *
37 AccessibleTable_getCaption (AccessibleTable *obj)
38 {
39   return cspi_object_add (
40     Accessibility_Table__get_caption (CSPI_OBJREF (obj), cspi_ev ()));
41 }
42
43 /**
44  * AccessibleTable_getSummary:
45  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
46  *
47  * Get an accessible object which summarizes the contents of an #AccessibleTable.
48  *
49  * Returns: an #Accessible object that serves as the table's summary (often a
50  *          reduced #AccessibleTable).
51  **/
52 Accessible *
53 AccessibleTable_getSummary (AccessibleTable *obj)
54 {
55   return cspi_object_add (
56     Accessibility_Table__get_summary (CSPI_OBJREF (obj), cspi_ev ()));
57 }
58
59 /**
60  * AccessibleTable_getNRows:
61  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
62  *
63  * Get the number of rows in an #AccessibleTable,
64  *        exclusive of any rows that are programmatically hidden, but inclusive
65  *        of rows that may be outside of the current scrolling window or viewport.
66  *
67  * Returns: a #long integer indicating the number of rows in the table.
68  **/
69 long
70 AccessibleTable_getNRows (AccessibleTable *obj)
71 {
72   long retval;
73
74   cspi_return_val_if_fail (obj != NULL, -1);
75
76   retval =
77     Accessibility_Table__get_nRows (CSPI_OBJREF (obj), cspi_ev ());
78           
79   cspi_return_val_if_ev ("getNRows", -1);
80
81   return retval;
82           
83 }
84
85 /**
86  * AccessibleTable_getNColumns:
87  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
88  *
89  * Get the number of columns in an #AccessibleTable,
90  *        exclusive of any columns that are programmatically hidden, but inclusive
91  *        of columns that may be outside of the current scrolling window or viewport.
92  *
93  * Returns: a #long integer indicating the number of columns in the table.
94  **/
95 long
96 AccessibleTable_getNColumns (AccessibleTable *obj)
97 {
98   long retval;
99
100   cspi_return_val_if_fail (obj != NULL, -1);
101
102   retval =
103     Accessibility_Table__get_nColumns (CSPI_OBJREF (obj), cspi_ev ());
104           
105   cspi_return_val_if_ev ("", -1);
106
107   return retval;
108 }
109
110 /**
111  * AccessibleTable_getAccessibleAt:
112  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
113  * @row: the specified table row, zero-indexed.
114  * @column: the specified table column, zero-indexed.
115  *
116  * Get the table cell at the specified row and column indices.
117  *          To get the accessible object at a particular (x, y) screen coordinate,
118  *          use #Accessible_getAccessibleAtPoint ().
119  *
120  * Returns: an #Accessible object representing the specified table cell.
121  **/
122 Accessible *
123 AccessibleTable_getAccessibleAt (AccessibleTable *obj,
124                                  long int row,
125                                  long int column)
126 {
127   return cspi_object_add (
128     Accessibility_Table_getAccessibleAt (
129       CSPI_OBJREF (obj), (CORBA_long) row,
130       (CORBA_long) column, cspi_ev ()));
131 }
132
133 /**
134  * AccessibleTable_getIndexAt:
135  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
136  * @row: the specified table row, zero-indexed.
137  * @column: the specified table column, zero-indexed.
138  *
139  * Get the 1-D child index corresponding to the specified 2-D row and column indices.
140  *          To get the accessible object at a particular (x, y) screen coordinate,
141  *          use #Accessible_getAccessibleAtPoint ().
142  * @see #AccessibleTable_getRowAtIndex(), #AccessibleTable_getColumnAtIndex()
143  *
144  * Returns: a long integer which serves as the index of a specified cell in the
145  *          table, in a form usable by #Accessible_getChildAtIndex().
146  **/
147 long
148 AccessibleTable_getIndexAt (AccessibleTable *obj,
149                             long int row,
150                             long int column)
151 {
152   long retval;
153
154   cspi_return_val_if_fail (obj != NULL, -1);
155
156   retval =
157     Accessibility_Table_getIndexAt (
158       CSPI_OBJREF (obj), (CORBA_long) row,
159       (CORBA_long) column, cspi_ev ());
160           
161   cspi_return_val_if_ev ("getIndexAt", -1);
162
163   return retval;
164 }
165
166 /**
167  * AccessibleTable_getRowAtIndex:
168  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
169  * @index: the specified child index, zero-indexed.
170  *
171  * Get the table row index occupied by the child at a particular 1-D child index.
172  *
173  * @see #AccessibleTable_getIndexAt(), #AccessibleTable_getColumnAtIndex()
174  *
175  * Returns: a long integer indicating the first row spanned by the child of a
176  *          table, at the specified 1-D (zero-offset) @index.
177  **/
178 long
179 AccessibleTable_getRowAtIndex (AccessibleTable *obj,
180                                long index)
181 {
182   long retval;
183
184   cspi_return_val_if_fail (obj != NULL, -1);
185
186   retval =
187     Accessibility_Table_getRowAtIndex (CSPI_OBJREF (obj),
188                                        (CORBA_long) index, cspi_ev ());
189           
190   cspi_return_val_if_ev ("", -1);
191
192   return retval;
193 }
194
195 /**
196  * AccessibleTable_getColumnAtIndex:
197  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
198  * @index: the specified child index, zero-indexed.
199  *
200  * Get the table column index occupied by the child at a particular 1-D child index.
201  *
202  * @see #AccessibleTable_getIndexAt(), #AccessibleTable_getRowAtIndex()
203  *
204  * Returns: a long integer indicating the first column spanned by the child of a
205  *          table, at the specified 1-D (zero-offset) @index.
206  **/
207 long
208 AccessibleTable_getColumnAtIndex (AccessibleTable *obj,
209                                   long index)
210 {
211   long retval;
212
213   cspi_return_val_if_fail (obj != NULL, -1);
214
215   retval =
216     Accessibility_Table_getColumnAtIndex (CSPI_OBJREF (obj),
217                                           (CORBA_long) index, cspi_ev ());
218           
219   cspi_return_val_if_ev ("getColumnAtIndex", -1);
220
221   return retval;
222 }
223
224 /**
225  * AccessibleTable_getRowDescription:
226  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
227  * @row: the specified table row, zero-indexed.
228  *
229  * Get a text description of a particular table row.  This differs from
230  * AccessibleTable_getRowHeader, which returns an #Accessible.
231  *
232  * Returns: a UTF-8 string describing the specified table row, if available.
233  **/
234 char *
235 AccessibleTable_getRowDescription (AccessibleTable *obj,
236                                    long int         row)
237 {
238   char *retval;
239
240   cspi_return_val_if_fail (obj != NULL, NULL);
241
242   retval =
243     Accessibility_Table_getRowDescription (CSPI_OBJREF (obj),
244                                            (CORBA_long) row, cspi_ev ());
245           
246   cspi_return_val_if_ev ("getRowDescription", NULL);
247
248   return retval;
249 }
250
251 /**
252  * AccessibleTable_getColumnDescription:
253  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
254  * @column: the specified table column, zero-indexed.
255  *
256  * Get a text description of a particular table column.  This differs from
257  * AccessibleTable_getColumnHeader, which returns an #Accessible.
258  *
259  * Returns: a UTF-8 string describing the specified table column, if available.
260  **/
261 char *
262 AccessibleTable_getColumnDescription (AccessibleTable *obj,
263                                       long int         column)
264 {
265   char *retval;
266
267   cspi_return_val_if_fail (obj != NULL, NULL);
268
269   retval =
270     Accessibility_Table_getColumnDescription (CSPI_OBJREF (obj),
271                                               (CORBA_long) column, cspi_ev ());
272
273   cspi_return_val_if_ev ("getColumnDescription", NULL);
274
275   return retval;
276 }
277
278 /**
279  * AccessibleTable_getRowExtentAt:
280  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
281  * @row: the specified table row, zero-indexed.
282  * @column: the specified table column, zero-indexed.
283  *
284  * Get the number of rows spanned by the table cell at the specific row and column.
285  * (some tables can have cells which span multiple rows and/or columns).
286  *
287  * Returns: a long integer indicating the number of rows spanned by the specified cell.
288  **/
289 long
290 AccessibleTable_getRowExtentAt (AccessibleTable *obj,
291                                 long int         row,
292                                 long int         column)
293 {
294   long retval;
295
296   cspi_return_val_if_fail (obj != NULL, -1);
297
298   retval =
299     Accessibility_Table_getRowExtentAt (
300       CSPI_OBJREF (obj), (CORBA_long) row,
301       (CORBA_long) column, cspi_ev ());
302           
303   cspi_return_val_if_ev ("getRowExtentAt", -1);
304
305   return retval;
306 }
307
308 /**
309  * AccessibleTable_getColumnExtentAt:
310  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
311  * @row: the specified table row, zero-indexed.
312  * @column: the specified table column, zero-indexed.
313  *
314  * Get the number of columns spanned by the table cell at the specific row and column.
315  * (some tables can have cells which span multiple rows and/or columns).
316  *
317  * Returns: a long integer indicating the number of columns spanned by the specified cell.
318  **/
319 long
320 AccessibleTable_getColumnExtentAt (AccessibleTable *obj,
321                                    long int         row,
322                                    long int         column)
323 {
324   long retval;
325
326   cspi_return_val_if_fail (obj != NULL, -1);
327
328   retval =
329     Accessibility_Table_getColumnExtentAt (
330       CSPI_OBJREF (obj), (CORBA_long) row,
331       (CORBA_long) column, cspi_ev ());
332           
333   cspi_return_val_if_ev ("getColumnExtentAt", -1);
334
335   return retval;
336 }
337
338 /**
339  * AccessibleTable_getRowHeader:
340  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
341  * @row: the specified table row, zero-indexed.
342  *
343  * Get the header associated with a table row, if available.  This differs from
344  * AccessibleTable_getRowDescription, which returns a string.
345  *
346  * Returns: a #Accessible representatin of the specified table row, if available.
347  **/
348 Accessible *
349 AccessibleTable_getRowHeader (AccessibleTable *obj,
350                               long int         row)
351 {
352   return cspi_object_add (
353     Accessibility_Table_getRowHeader (CSPI_OBJREF (obj),
354                                       (CORBA_long) row, cspi_ev ()));
355 }
356
357 /**
358  * AccessibleTable_getColumnHeader:
359  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
360  * @column: the specified table column, zero-indexed.
361  *
362  * Get the header associated with a table column, if available.  This differs from
363  * AccessibleTable_getColumnDescription, which returns a string.
364  *
365  * Returns: a #Accessible representatin of the specified table column, if available.
366  **/
367 Accessible *
368 AccessibleTable_getColumnHeader (AccessibleTable *obj,
369                                  long int column)
370 {
371   return cspi_object_add (
372     Accessibility_Table_getColumnHeader (CSPI_OBJREF (obj),
373                                       (CORBA_long) column, cspi_ev ()));
374 }
375
376 /**
377  * AccessibleTable_getNSelectedRows:
378  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
379  *
380  * Query a table to find out how many rows are currently selected.  Not all tables
381  *  support row selection.
382  *
383  * Returns: a long integer indicating the number of rows currently selected.
384  **/
385 long
386 AccessibleTable_getNSelectedRows (AccessibleTable *obj)
387 {
388   long retval;
389
390   cspi_return_val_if_fail (obj != NULL, -1);
391
392   retval =
393     Accessibility_Table__get_nSelectedRows (CSPI_OBJREF (obj), cspi_ev ());
394           
395   cspi_return_val_if_ev ("getNSelectedRows", -1);
396
397   return retval;
398 }
399
400 static long
401 long_seq_to_array (Accessibility_LongSeq *seq, long int **array)
402 {
403   long *j, length, i;
404
405   if (!cspi_check_ev ("getSelectionItems"))
406     {
407       *array = NULL;
408       return 0;
409     }
410
411   length = seq->_length;
412
413   j = *array = g_new (long, length);
414
415   for (i = 0; i < length; i++)
416     {
417       j[i] = seq->_buffer [i];
418     }
419
420   CORBA_free (seq);
421
422   return length;
423 }
424
425 /**
426  * AccessibleTable_getSelectedRows:
427  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
428  * @selectedRows: a doubly indirected pointer which will be set to the address
429  *       of an array of long integers, specifying which rows are currently selected.
430  *
431  * Query a table for a list of indices of rows which are currently selected.
432  *
433  * Returns: a long integer indicating the length of the array returned in @selectedRows.
434  **/
435 long
436 AccessibleTable_getSelectedRows (AccessibleTable *obj,
437                                  long int       **selectedRows)
438 {
439   Accessibility_LongSeq *rows;
440
441   *selectedRows = NULL;
442
443   cspi_return_val_if_fail (obj != NULL, 0);
444
445   rows = Accessibility_Table_getSelectedRows (CSPI_OBJREF (obj), cspi_ev ());
446
447   return long_seq_to_array (rows, selectedRows);
448 }
449
450 /**
451  * AccessibleTable_getNSelectedColumns:
452  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
453  *
454  * Query a table to find out how many columnss are currently selected.  Not all tables
455  *  support column selection.
456  *
457  * Returns: a long integer indicating the number of columns currently selected.
458  **/
459 long
460 AccessibleTable_getNSelectedColumns (AccessibleTable *obj)
461 {
462   long retval;
463
464   cspi_return_val_if_fail (obj != NULL, -1);
465
466   retval =
467     Accessibility_Table__get_nSelectedColumns (CSPI_OBJREF (obj), cspi_ev ());
468           
469   cspi_return_val_if_ev ("getNSelectedColumns", -1);
470
471   return retval;
472 }
473
474 /**
475  * AccessibleTable_getSelectedColumns:
476  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
477  * @selectedColumns: a doubly indirected pointer which will be set to the address
478  *       of an array of long integers, specifying which columns are currently selected.
479  *
480  * Query a table for a list of indices of columns which are currently selected.
481  *       Not all tables support column selection.
482  *
483  * Returns: a long integer indicating the length of the array returned in @selectedColumns.
484  **/
485 long
486 AccessibleTable_getSelectedColumns (AccessibleTable *obj,
487                                     long int       **selectedColumns)
488 {
489   Accessibility_LongSeq *columns;
490
491   *selectedColumns = NULL;
492
493   cspi_return_val_if_fail (obj != NULL, 0);
494
495   columns = Accessibility_Table_getSelectedColumns (CSPI_OBJREF (obj), cspi_ev ());
496
497   return long_seq_to_array (columns, selectedColumns);
498 }
499
500 /**
501  * AccessibleTable_isRowSelected:
502  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
503  * @row:
504  *
505  * Determine whether a table row is selected.  Not all tables support row selection.
506  *
507  * Returns: #TRUE if the specified row is currently selected, #FALSE if not.
508  **/
509 SPIBoolean
510 AccessibleTable_isRowSelected (AccessibleTable *obj,
511                                long int         row)
512 {
513   SPIBoolean retval;
514
515   cspi_return_val_if_fail (obj != NULL, FALSE);
516
517   retval =
518     Accessibility_Table_isRowSelected (CSPI_OBJREF (obj),
519                                        (CORBA_long) row, cspi_ev ());
520
521   cspi_return_val_if_ev ("isRowSelected", FALSE);
522
523   return retval;
524 }
525
526 /**
527  * AccessibleTable_isColumnSelected:
528  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
529  * @column:
530  *
531  * Determine whether specified table column is selected.
532  * Not all tables support column selection.
533  *
534  * Returns: #TRUE if the specified column is currently selected, #FALSE if not.
535  **/
536 SPIBoolean
537 AccessibleTable_isColumnSelected (AccessibleTable *obj,
538                                   long int         column)
539 {
540   SPIBoolean retval;
541
542   cspi_return_val_if_fail (obj != NULL, FALSE);
543
544   retval =
545     Accessibility_Table_isColumnSelected (CSPI_OBJREF (obj),
546                                           (CORBA_long) column, cspi_ev ());
547           
548   cspi_return_val_if_ev ("isColumnSelected", FALSE);
549
550   return retval;
551 }
552
553 /**
554  * AccessibleTable_isSelected:
555  * @obj: a pointer to the #AccessibleTable implementor on which to operate.
556  * @row:
557  * @column:
558  *
559  * Determine whether the cell at a specific row and column is selected.
560  *
561  * Returns: #TRUE if the specified cell is currently selected, #FALSE if not.
562  **/
563 SPIBoolean
564 AccessibleTable_isSelected (AccessibleTable *obj,
565                             long int row,
566                             long int column)
567 {
568   SPIBoolean retval;
569
570   cspi_return_val_if_fail (obj != NULL, FALSE);
571
572   retval =
573     Accessibility_Table_isSelected (CSPI_OBJREF (obj),
574                                     (CORBA_long) row,
575                                     (CORBA_long) column, cspi_ev ());
576           
577   cspi_return_val_if_ev ("isSelected", FALSE);
578
579   return retval;
580 }
581