Correct return value. Fixes bug #116621. Problem reported by Mario Lang.
[atk.git] / atk / atktable.c
blob784b310a4571cd0b2035460e3bfb74c0fa8cf527
1 /* ATK - Accessibility Toolkit
2 * Copyright 2001 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include "atktable.h"
21 #include "atkmarshal.h"
23 enum {
24 ROW_INSERTED,
25 ROW_DELETED,
26 COLUMN_INSERTED,
27 COLUMN_DELETED,
28 ROW_REORDERED,
29 COLUMN_REORDERED,
30 MODEL_CHANGED,
31 LAST_SIGNAL
34 static void atk_table_base_init (gpointer *g_class);
36 static guint atk_table_signals[LAST_SIGNAL] = { 0 };
38 GType
39 atk_table_get_type (void)
41 static GType type = 0;
43 if (!type) {
44 GTypeInfo tinfo =
46 sizeof (AtkTableIface),
47 (GBaseInitFunc) atk_table_base_init,
48 (GBaseFinalizeFunc) NULL,
52 type = g_type_register_static (G_TYPE_INTERFACE, "AtkTable", &tinfo, 0);
55 return type;
59 static void
60 atk_table_base_init (gpointer *g_class)
62 static gboolean initialized = FALSE;
64 if (!initialized)
66 atk_table_signals[ROW_INSERTED] =
67 g_signal_new ("row_inserted",
68 ATK_TYPE_TABLE,
69 G_SIGNAL_RUN_LAST,
70 G_STRUCT_OFFSET (AtkTableIface, row_inserted),
71 (GSignalAccumulator) NULL, NULL,
72 atk_marshal_VOID__INT_INT,
73 G_TYPE_NONE,
74 2, G_TYPE_INT, G_TYPE_INT);
75 atk_table_signals[COLUMN_INSERTED] =
76 g_signal_new ("column_inserted",
77 ATK_TYPE_TABLE,
78 G_SIGNAL_RUN_LAST,
79 G_STRUCT_OFFSET (AtkTableIface, column_inserted),
80 (GSignalAccumulator) NULL, NULL,
81 atk_marshal_VOID__INT_INT,
82 G_TYPE_NONE,
83 2, G_TYPE_INT, G_TYPE_INT);
84 atk_table_signals[ROW_DELETED] =
85 g_signal_new ("row_deleted",
86 ATK_TYPE_TABLE,
87 G_SIGNAL_RUN_LAST,
88 G_STRUCT_OFFSET (AtkTableIface, row_deleted),
89 (GSignalAccumulator) NULL, NULL,
90 atk_marshal_VOID__INT_INT,
91 G_TYPE_NONE,
92 2, G_TYPE_INT, G_TYPE_INT);
93 atk_table_signals[COLUMN_DELETED] =
94 g_signal_new ("column_deleted",
95 ATK_TYPE_TABLE,
96 G_SIGNAL_RUN_LAST,
97 G_STRUCT_OFFSET (AtkTableIface, column_deleted),
98 (GSignalAccumulator) NULL, NULL,
99 atk_marshal_VOID__INT_INT,
100 G_TYPE_NONE,
101 2, G_TYPE_INT, G_TYPE_INT);
102 atk_table_signals[ROW_REORDERED] =
103 g_signal_new ("row_reordered",
104 ATK_TYPE_TABLE,
105 G_SIGNAL_RUN_LAST,
106 G_STRUCT_OFFSET (AtkTableIface, row_reordered),
107 (GSignalAccumulator) NULL, NULL,
108 g_cclosure_marshal_VOID__VOID,
109 G_TYPE_NONE,
111 atk_table_signals[COLUMN_REORDERED] =
112 g_signal_new ("column_reordered",
113 ATK_TYPE_TABLE,
114 G_SIGNAL_RUN_LAST,
115 G_STRUCT_OFFSET (AtkTableIface, column_reordered),
116 (GSignalAccumulator) NULL, NULL,
117 g_cclosure_marshal_VOID__VOID,
118 G_TYPE_NONE,
120 atk_table_signals[MODEL_CHANGED] =
121 g_signal_new ("model_changed",
122 ATK_TYPE_TABLE,
123 G_SIGNAL_RUN_LAST,
124 G_STRUCT_OFFSET (AtkTableIface, model_changed),
125 (GSignalAccumulator) NULL, NULL,
126 g_cclosure_marshal_VOID__VOID,
127 G_TYPE_NONE, 0);
129 initialized = TRUE;
134 * atk_table_ref_at:
135 * @table: a GObject instance that implements AtkTableIface
136 * @row: a #gint representing a row in @table
137 * @column: a #gint representing a column in @table
139 * Get a reference to the table cell at @row, @column.
141 * Returns: a AtkObject* representing the referred to accessible
143 AtkObject*
144 atk_table_ref_at (AtkTable *table,
145 gint row,
146 gint column)
148 AtkTableIface *iface;
150 g_return_val_if_fail (ATK_IS_TABLE (table), NULL);
152 iface = ATK_TABLE_GET_IFACE (table);
154 if (iface->ref_at)
155 return (iface->ref_at) (table, row, column);
156 else
157 return NULL;
161 * atk_table_get_index_at:
162 * @table: a GObject instance that implements AtkTableIface
163 * @row: a #gint representing a row in @table
164 * @column: a #gint representing a column in @table
166 * Gets a #gint representing the index at the specified @row and @column.
167 * The value -1 is returned if the object at row,column is not a child
168 * of table or table does not implement this interface.
170 * Returns: a #gint representing the index at specified position
172 gint
173 atk_table_get_index_at (AtkTable *table,
174 gint row,
175 gint column)
177 AtkTableIface *iface;
179 g_return_val_if_fail (ATK_IS_TABLE (table), -1);
180 g_return_val_if_fail (row >= 0, -1);
181 g_return_val_if_fail (column >= 0, -1);
183 iface = ATK_TABLE_GET_IFACE (table);
185 if (iface->get_index_at)
186 return (iface->get_index_at) (table, row, column);
187 else
188 return -1;
192 * atk_table_get_row_at_index:
193 * @table: a GObject instance that implements AtkTableInterface
194 * @index_: a #gint representing an index in @table
196 * Gets a #gint representing the row at the specified @index_, or -1
197 * if the table does not implement this interface
199 * Returns: a gint representing the row at the specified index.
201 gint
202 atk_table_get_row_at_index (AtkTable *table,
203 gint index)
205 AtkTableIface *iface;
207 g_return_val_if_fail (ATK_IS_TABLE (table), -1);
209 iface = ATK_TABLE_GET_IFACE (table);
211 if (iface->get_row_at_index)
212 return (iface->get_row_at_index) (table, index);
213 else
214 return -1;
218 * atk_table_get_column_at_index:
219 * @table: a GObject instance that implements AtkTableInterface
220 * @index_: a #gint representing an index in @table
222 * Gets a #gint representing the column at the specified @index_, or -1
223 * if the table does not implement this interface
225 * Returns: a gint representing the column at the specified index.
227 gint
228 atk_table_get_column_at_index (AtkTable *table,
229 gint index)
231 AtkTableIface *iface;
233 g_return_val_if_fail (ATK_IS_TABLE (table), 0);
235 iface = ATK_TABLE_GET_IFACE (table);
237 if (iface->get_column_at_index)
238 return (iface->get_column_at_index) (table, index);
239 else
240 return -1;
244 * atk_table_get_caption:
245 * @table: a GObject instance that implements AtkTableInterface
247 * Gets the caption for the @table.
249 * Returns: a AtkObject* representing the table caption, or %NULL
250 * if value does not implement this interface.
252 AtkObject*
253 atk_table_get_caption (AtkTable *table)
255 AtkTableIface *iface;
257 g_return_val_if_fail (ATK_IS_TABLE (table), NULL);
259 iface = ATK_TABLE_GET_IFACE (table);
261 if (iface->get_caption)
262 return (iface->get_caption) (table);
263 else
264 return NULL;
268 * atk_table_get_n_columns:
269 * @table: a GObject instance that implements AtkTableIface
271 * Gets the number of columns in the table.
273 * Returns: a gint representing the number of columns, or 0
274 * if value does not implement this interface.
276 gint
277 atk_table_get_n_columns (AtkTable *table)
279 AtkTableIface *iface;
281 g_return_val_if_fail (ATK_IS_TABLE (table), 0);
283 iface = ATK_TABLE_GET_IFACE (table);
285 if (iface->get_n_columns)
286 return (iface->get_n_columns) (table);
287 else
288 return 0;
292 * atk_table_get_column_description:
293 * @table: a GObject instance that implements AtkTableIface
294 * @column: a #gint representing a column in @table
296 * Gets the description text of the specified @column in the table
298 * Returns: a gchar* representing the column description, or %NULL
299 * if value does not implement this interface.
301 G_CONST_RETURN gchar*
302 atk_table_get_column_description (AtkTable *table,
303 gint column)
305 AtkTableIface *iface;
307 g_return_val_if_fail (ATK_IS_TABLE (table), NULL);
309 iface = ATK_TABLE_GET_IFACE (table);
311 if (iface->get_column_description)
312 return (iface->get_column_description) (table, column);
313 else
314 return NULL;
318 * atk_table_get_column_extent_at:
319 * @table: a GObject instance that implements AtkTableIface
320 * @row: a #gint representing a row in @table
321 * @column: a #gint representing a column in @table
323 * Gets the number of columns occupied by the accessible object
324 * at the specified @row and @column in the @table.
326 * Returns: a gint representing the column extent at specified position, or 0
327 * if value does not implement this interface.
329 gint
330 atk_table_get_column_extent_at (AtkTable *table,
331 gint row,
332 gint column)
334 AtkTableIface *iface;
336 g_return_val_if_fail (ATK_IS_TABLE (table), 0);
338 iface = ATK_TABLE_GET_IFACE (table);
340 if (iface->get_column_extent_at)
341 return (iface->get_column_extent_at) (table, row, column);
342 else
343 return 0;
347 * atk_table_get_column_header:
348 * @table: a GObject instance that implements AtkTableIface
349 * @column: a #gint representing a column in the table
351 * Gets the column header of a specified column in an accessible table.
353 * Returns: a AtkObject* representing the specified column header, or
354 * %NULL if value does not implement this interface.
356 AtkObject*
357 atk_table_get_column_header (AtkTable *table, gint column)
359 AtkTableIface *iface;
361 g_return_val_if_fail (ATK_IS_TABLE (table), NULL);
363 iface = ATK_TABLE_GET_IFACE (table);
365 if (iface->get_column_header)
366 return (iface->get_column_header) (table, column);
367 else
368 return NULL;
372 * atk_table_get_n_rows:
373 * @table: a GObject instance that implements AtkTableIface
375 * Gets the number of rows in the table.
377 * Returns: a gint representing the number of rows, or 0
378 * if value does not implement this interface.
380 gint
381 atk_table_get_n_rows (AtkTable *table)
383 AtkTableIface *iface;
385 g_return_val_if_fail (ATK_IS_TABLE (table), 0);
387 iface = ATK_TABLE_GET_IFACE (table);
389 if (iface->get_n_rows)
390 return (iface->get_n_rows) (table);
391 else
392 return 0;
396 * atk_table_get_row_description:
397 * @table: a GObject instance that implements AtkTableIface
398 * @row: a #gint representing a row in @table
400 * Gets the description text of the specified row in the table
402 * Returns: a gchar* representing the row description, or %NULL
403 * if value does not implement this interface.
405 G_CONST_RETURN gchar*
406 atk_table_get_row_description (AtkTable *table,
407 gint row)
409 AtkTableIface *iface;
411 g_return_val_if_fail (ATK_IS_TABLE (table), NULL);
413 iface = ATK_TABLE_GET_IFACE (table);
415 if (iface->get_row_description)
416 return (iface->get_row_description) (table, row);
417 else
418 return NULL;
422 * atk_table_get_row_extent_at:
423 * @table: a GObject instance that implements AtkTableIface
424 * @row: a #gint representing a row in @table
425 * @column: a #gint representing a column in @table
427 * Gets the number of rows occupied by the accessible object
428 * at a specified @row and @column in the @table.
430 * Returns: a gint representing the row extent at specified position, or 0
431 * if value does not implement this interface.
433 gint
434 atk_table_get_row_extent_at (AtkTable *table,
435 gint row,
436 gint column)
438 AtkTableIface *iface;
440 g_return_val_if_fail (ATK_IS_TABLE (table), 0);
442 iface = ATK_TABLE_GET_IFACE (table);
444 if (iface->get_row_extent_at)
445 return (iface->get_row_extent_at) (table, row, column);
446 else
447 return 0;
451 * atk_table_get_row_header:
452 * @table: a GObject instance that implements AtkTableIface
453 * @row: a #gint representing a row in the table
455 * Gets the row header of a specified row in an accessible table.
457 * Returns: a AtkObject* representing the specified row header, or
458 * %NULL if value does not implement this interface.
460 AtkObject*
461 atk_table_get_row_header (AtkTable *table, gint row)
463 AtkTableIface *iface;
465 g_return_val_if_fail (ATK_IS_TABLE (table), NULL);
467 iface = ATK_TABLE_GET_IFACE (table);
469 if (iface->get_row_header)
470 return (iface->get_row_header) (table, row);
471 else
472 return NULL;
476 * atk_table_get_summary:
477 * @table: a GObject instance that implements AtkTableIface
479 * Gets the summary description of the table.
481 * Returns: a AtkObject* representing a summary description of the table,
482 * or zero if value does not implement this interface.
484 AtkObject*
485 atk_table_get_summary (AtkTable *table)
487 AtkTableIface *iface;
489 g_return_val_if_fail (ATK_IS_TABLE (table), NULL);
491 iface = ATK_TABLE_GET_IFACE (table);
493 if (iface->get_summary)
494 return (iface->get_summary) (table);
495 else
496 return NULL;
500 * atk_table_get_selected_rows:
501 * @table: a GObject instance that implements AtkTableIface
502 * @selected: a #gint** that is to contain the selected row numbers
504 * Gets the selected rows of the table by initializing **selected with
505 * the selected row numbers. This array should be freed by the caller.
507 * Returns: a gint representing the number of selected rows,
508 * or zero if value does not implement this interface.
510 gint
511 atk_table_get_selected_rows (AtkTable *table, gint **selected)
513 AtkTableIface *iface;
515 g_return_val_if_fail (ATK_IS_TABLE (table), 0);
517 iface = ATK_TABLE_GET_IFACE (table);
519 if (iface->get_selected_rows)
520 return (iface->get_selected_rows) (table, selected);
521 else
522 return 0;
526 * atk_table_get_selected_columns:
527 * @table: a GObject instance that implements AtkTableIface
528 * @selected: a #gint** that is to contain the selected columns numbers
530 * Gets the selected columns of the table by initializing **selected with
531 * the selected column numbers. This array should be freed by the caller.
533 * Returns: a gint representing the number of selected columns,
534 * or %0 if value does not implement this interface.
536 gint
537 atk_table_get_selected_columns (AtkTable *table, gint **selected)
539 AtkTableIface *iface;
541 g_return_val_if_fail (ATK_IS_TABLE (table), 0);
543 iface = ATK_TABLE_GET_IFACE (table);
545 if (iface->get_selected_columns)
546 return (iface->get_selected_columns) (table, selected);
547 else
548 return 0;
552 * atk_table_is_column_selected:
553 * @table: a GObject instance that implements AtkTableIface
554 * @column: a #gint representing a column in @table
556 * Gets a boolean value indicating whether the specified @column
557 * is selected
559 * Returns: a gboolean representing if the column is selected, or 0
560 * if value does not implement this interface.
562 gboolean
563 atk_table_is_column_selected (AtkTable *table,
564 gint column)
566 AtkTableIface *iface;
568 g_return_val_if_fail (ATK_IS_TABLE (table), FALSE);
570 iface = ATK_TABLE_GET_IFACE (table);
572 if (iface->is_column_selected)
573 return (iface->is_column_selected) (table, column);
574 else
575 return FALSE;
579 * atk_table_is_row_selected:
580 * @table: a GObject instance that implements AtkTableIface
581 * @row: a #gint representing a row in @table
583 * Gets a boolean value indicating whether the specified @row
584 * is selected
586 * Returns: a gboolean representing if the row is selected, or 0
587 * if value does not implement this interface.
589 gboolean
590 atk_table_is_row_selected (AtkTable *table,
591 gint row)
593 AtkTableIface *iface;
595 g_return_val_if_fail (ATK_IS_TABLE (table), FALSE);
597 iface = ATK_TABLE_GET_IFACE (table);
599 if (iface->is_row_selected)
600 return (iface->is_row_selected) (table, row);
601 else
602 return FALSE;
606 * atk_table_is_selected:
607 * @table: a GObject instance that implements AtkTableIface
608 * @row: a #gint representing a row in @table
609 * @column: a #gint representing a column in @table
611 * Gets a boolean value indicating whether the accessible object
612 * at the specified @row and @column is selected
614 * Returns: a gboolean representing if the cell is selected, or 0
615 * if value does not implement this interface.
617 gboolean
618 atk_table_is_selected (AtkTable *table,
619 gint row,
620 gint column)
622 AtkTableIface *iface;
624 g_return_val_if_fail (ATK_IS_TABLE (table), FALSE);
626 iface = ATK_TABLE_GET_IFACE (table);
628 if (iface->is_selected)
629 return (iface->is_selected) (table, row, column);
630 else
631 return FALSE;
635 * atk_table_add_row_selection:
636 * @table: a GObject instance that implements AtkTableIface
637 * @row: a #gint representing a row in @table
639 * Adds the specified @row to the selection.
641 * Returns: a gboolean representing if row was successfully added to selection,
642 * or 0 if value does not implement this interface.
644 gboolean
645 atk_table_add_row_selection (AtkTable *table,
646 gint row)
648 AtkTableIface *iface;
650 g_return_val_if_fail (ATK_IS_TABLE (table), FALSE);
652 iface = ATK_TABLE_GET_IFACE (table);
654 if (iface->add_row_selection)
655 return (iface->add_row_selection) (table, row);
656 else
657 return FALSE;
660 * atk_table_remove_row_selection:
661 * @table: a GObject instance that implements AtkTableIface
662 * @row: a #gint representing a row in @table
664 * Removes the specified @row from the selection.
666 * Returns: a gboolean representing if the row was successfully removed from
667 * the selection, or 0 if value does not implement this interface.
669 gboolean
670 atk_table_remove_row_selection (AtkTable *table,
671 gint row)
673 AtkTableIface *iface;
675 g_return_val_if_fail (ATK_IS_TABLE (table), FALSE);
677 iface = ATK_TABLE_GET_IFACE (table);
679 if (iface->remove_row_selection)
680 return (iface->remove_row_selection) (table, row);
681 else
682 return FALSE;
685 * atk_table_add_column_selection:
686 * @table: a GObject instance that implements AtkTableIface
687 * @column: a #gint representing a column in @table
689 * Adds the specified @column to the selection.
691 * Returns: a gboolean representing if the column was successfully added to
692 * the selection, or 0 if value does not implement this interface.
694 gboolean
695 atk_table_add_column_selection (AtkTable *table,
696 gint column)
698 AtkTableIface *iface;
700 g_return_val_if_fail (ATK_IS_TABLE (table), FALSE);
702 iface = ATK_TABLE_GET_IFACE (table);
704 if (iface->add_column_selection)
705 return (iface->add_column_selection) (table, column);
706 else
707 return FALSE;
710 * atk_table_remove_column_selection:
711 * @table: a GObject instance that implements AtkTableIface
712 * @column: a #gint representing a column in @table
714 * Adds the specified @column to the selection.
716 * Returns: a gboolean representing if the column was successfully removed from
717 * the selection, or 0 if value does not implement this interface.
719 gboolean
720 atk_table_remove_column_selection (AtkTable *table,
721 gint column)
723 AtkTableIface *iface;
725 g_return_val_if_fail (ATK_IS_TABLE (table), FALSE);
727 iface = ATK_TABLE_GET_IFACE (table);
729 if (iface->remove_column_selection)
730 return (iface->remove_column_selection) (table, column);
731 else
732 return FALSE;
736 * atk_table_set_caption:
737 * @table: a GObject instance that implements AtkTableIface
738 * @caption: a #AtkObject representing the caption to set for @table
740 * Sets the caption for the table.
742 void
743 atk_table_set_caption (AtkTable *table,
744 AtkObject *caption)
746 AtkTableIface *iface;
748 g_return_if_fail (ATK_IS_TABLE (table));
750 iface = ATK_TABLE_GET_IFACE (table);
752 if (iface->set_caption)
753 (iface->set_caption) (table, caption);
757 * atk_table_set_column_description:
758 * @table: a GObject instance that implements AtkTableIface
759 * @column: a #gint representing a column in @table
760 * @description: a #gchar representing the description text
761 * to set for the specified @column of the @table
763 * Sets the description text for the specified @column of the @table.
765 void
766 atk_table_set_column_description (AtkTable *table,
767 gint column,
768 const gchar *description)
770 AtkTableIface *iface;
772 g_return_if_fail (ATK_IS_TABLE (table));
774 iface = ATK_TABLE_GET_IFACE (table);
776 if (iface->set_column_description)
777 (iface->set_column_description) (table, column, description);
781 * atk_table_set_column_header:
782 * @table: a GObject instance that implements AtkTableIface
783 * @column: a #gint representing a column in @table
784 * @header: an #AtkTable
786 * Sets the specified column header to @header.
788 void
789 atk_table_set_column_header (AtkTable *table,
790 gint column,
791 AtkObject *header)
793 AtkTableIface *iface;
795 g_return_if_fail (ATK_IS_TABLE (table));
797 iface = ATK_TABLE_GET_IFACE (table);
799 if (iface->set_column_header)
800 (iface->set_column_header) (table, column, header);
804 * atk_table_set_row_description:
805 * @table: a GObject instance that implements AtkTableIface
806 * @row: a #gint representing a row in @table
807 * @description: a #gchar representing the description text
808 * to set for the specified @row of @table
810 * Sets the description text for the specified @row of @table.
812 void
813 atk_table_set_row_description (AtkTable *table,
814 gint row,
815 const gchar *description)
817 AtkTableIface *iface;
819 g_return_if_fail (ATK_IS_TABLE (table));
821 iface = ATK_TABLE_GET_IFACE (table);
823 if (iface->set_row_description)
824 (iface->set_row_description) (table, row, description);
828 * atk_table_set_row_header:
829 * @table: a GObject instance that implements AtkTableIface
830 * @row: a #gint representing a row in @table
831 * @header: an #AtkTable
833 * Sets the specified row header to @header.
835 void
836 atk_table_set_row_header (AtkTable *table,
837 gint row,
838 AtkObject *header)
840 AtkTableIface *iface;
842 g_return_if_fail (ATK_IS_TABLE (table));
844 iface = ATK_TABLE_GET_IFACE (table);
846 if (iface->set_row_header)
847 (iface->set_row_header) (table, row, header);
851 * atk_table_set_summary:
852 * @table: a GObject instance that implements AtkTableIface
853 * @accessible: an #AtkObject representing the summary description
854 * to set for @table
856 * Sets the summary description of the table.
858 void
859 atk_table_set_summary (AtkTable *table,
860 AtkObject *accessible)
862 AtkTableIface *iface;
864 g_return_if_fail (ATK_IS_TABLE (table));
866 iface = ATK_TABLE_GET_IFACE (table);
868 if (iface->set_summary)
869 (iface->set_summary) (table, accessible);