1 /* This file contains both declaration and definition of the TestSimpleTable,
2 * a GObject that pretends to implement the AtkTableIface interface (it
3 * registers appropriate interface), but provides no implementation for any of the
4 * methods of this interface (NULL-filled vftbl).
7 #include "test-simple-table.h"
13 test_simple_table_get_type (void);
15 ///////////////////////////////////////////////////////////////////////////
16 // Helper functions and data
17 ///////////////////////////////////////////////////////////////////////////
19 // row/column selection schemes
20 gboolean ss_rows_none[NROWS] = {FALSE, FALSE, FALSE, FALSE};
21 gboolean ss_rows_02[NROWS] = {TRUE, FALSE, TRUE, FALSE};
23 gboolean ss_cols_none[NCOLS] = {FALSE, FALSE, FALSE, FALSE, FALSE};
24 gboolean ss_cols_24[NCOLS] = {FALSE, FALSE, TRUE, FALSE, TRUE};
26 // Select table rows or columns according to the specified selection scheme.
27 // TRUE means 'selected', FALSE - 'not selected'.
29 test_simple_table_select_rows (TestSimpleTable* table, gboolean sel_scheme[])
32 for (i = 0; i < NROWS; ++i)
34 table->row[i].selected = sel_scheme[i];
39 test_simple_table_select_columns (TestSimpleTable* table, gboolean sel_scheme[])
42 for (i = 0; i < NCOLS; ++i)
44 table->col[i].selected = sel_scheme[i];
48 // Reset row and column headers to their default values
50 test_simple_table_reset_headers (TestSimpleTable* table)
54 // initialize row and column descriptors
55 for (i = 0; i < NROWS; ++i)
57 sprintf (TEST_SIMPLE_TEXT (table->row[i].hdr)->text, DEF_ROW_DESCR_TPL, i);
60 for (j = 0; j < NCOLS; ++j)
62 sprintf (TEST_SIMPLE_TEXT (table->col[j].hdr)->text, DEF_COL_DESCR_TPL, j);
66 ///////////////////////////////////////////////////////////////////////////
68 ///////////////////////////////////////////////////////////////////////////
69 static GObjectClass *parent_class_simple_table = NULL;
72 test_simple_table_ref_at (AtkTable *table, gint row, gint column)
74 TestSimpleTable* self = (TestSimpleTable*)table;
75 if ((!self) || self->disposed)
80 if ((row >=0) && (row < self->nrows) &&
81 (column >= 0) && (column < self->ncols))
83 return ATK_OBJECT (self->tbl[row][column].elem);
92 test_simple_table_get_index_at (AtkTable *table, gint row, gint column)
94 TestSimpleTable* self = (TestSimpleTable*)table;
95 if ((!self) || self->disposed)
100 if ((row >=0) && (row < self->nrows) &&
101 (column >= 0) && (column < self->ncols))
103 // non-child objects have ID=-1 by default.
104 return (self->tbl[row][column].elem->id);
113 test_simple_table_get_column_at_index (AtkTable *table, gint index_)
115 TestSimpleTable* self = (TestSimpleTable*)table;
116 if ((!self) || self->disposed)
122 for (i = 0; i < self->nrows; ++i)
124 for (j = 0; j < self->ncols; ++j)
126 if (self->tbl[i][j].elem->id == index_)
137 test_simple_table_get_row_at_index (AtkTable *table, gint index_)
139 TestSimpleTable* self = (TestSimpleTable*)table;
140 if ((!self) || self->disposed)
151 for (i = 0; i < self->nrows; ++i)
153 for (j = 0; j < self->ncols; ++j)
155 if (self->tbl[i][j].elem->id == index_)
165 test_simple_table_get_n_columns (AtkTable *table)
167 TestSimpleTable* self = (TestSimpleTable*)table;
168 if ((!self) || self->disposed)
177 test_simple_table_get_n_rows (AtkTable *table)
179 TestSimpleTable* self = (TestSimpleTable*)table;
180 if ((!self) || self->disposed)
189 test_simple_table_get_column_extent_at (AtkTable *table, gint row, gint column)
191 TestSimpleTable* self = (TestSimpleTable*)table;
192 if ((!self) || self->disposed)
197 if ((row >=0) && (row < self->nrows) &&
198 (column >= 0) && (column < self->ncols))
200 return (self->tbl[row][column].ext_col);
209 test_simple_table_get_row_extent_at (AtkTable *table, gint row, gint column)
211 TestSimpleTable* self = (TestSimpleTable*)table;
212 if ((!self) || self->disposed)
217 if ((row >=0) && (row < self->nrows) &&
218 (column >= 0) && (column < self->ncols))
220 return (self->tbl[row][column].ext_row);
231 test_simple_table_get_caption (AtkTable *table)
233 TestSimpleTable* self = (TestSimpleTable*)table;
234 if ((!self) || self->disposed)
239 return (self->caption);
243 test_simple_table_get_column_description (AtkTable *table, gint column)
245 TestSimpleTable* self = (TestSimpleTable*)table;
246 if ((!self) || self->disposed)
251 if ((column < 0) || (column >= self->ncols))
256 return TEST_SIMPLE_TEXT (self->col[column].hdr)->text;
260 test_simple_table_get_column_header (AtkTable *table, gint column)
262 TestSimpleTable* self = (TestSimpleTable*)table;
263 if ((!self) || self->disposed)
268 if ((column < 0) || (column >= self->ncols))
273 return (self->col[column].hdr);
277 test_simple_table_get_row_description (AtkTable *table, gint row)
279 TestSimpleTable* self = (TestSimpleTable*)table;
280 if ((!self) || self->disposed)
285 if ((row < 0) || (row >= self->nrows))
290 return TEST_SIMPLE_TEXT (self->row[row].hdr)->text;
294 test_simple_table_get_row_header (AtkTable *table, gint row)
296 TestSimpleTable* self = (TestSimpleTable*)table;
297 if ((!self) || self->disposed)
302 if ((row < 0) || (row >= self->nrows))
307 return (self->row[row].hdr);
311 test_simple_table_get_summary (AtkTable *table)
313 TestSimpleTable* self = (TestSimpleTable*)table;
314 if ((!self) || self->disposed)
319 return (self->summary);
323 test_simple_table_set_caption (AtkTable *table, AtkObject *caption)
325 TestSimpleTable* self = (TestSimpleTable*)table;
326 if ((!self) || self->disposed || !caption)
331 // unref the old caption
332 g_object_unref (G_OBJECT (self->caption));
334 // and replace it with a new one
335 self->caption = caption;
336 g_object_ref (G_OBJECT (self->caption));
341 test_simple_table_set_column_description (AtkTable *table, gint column, const gchar *description)
343 TestSimpleTable* self = (TestSimpleTable*)table;
344 if ((!self) || self->disposed)
349 if ((column < 0) || (column >= self->ncols) || !description)
354 strncpy (TEST_SIMPLE_TEXT (self->col[column].hdr)->text, description, MAX_DESCR_LENGTH);
359 test_simple_table_set_column_header (AtkTable *table, gint column, AtkObject *header)
361 TestSimpleTable* self = (TestSimpleTable*)table;
362 if ((!self) || self->disposed)
367 if ((column < 0) || (column >= self->ncols) || !header)
373 g_object_unref (G_OBJECT (self->col[column].hdr));
375 // and replace it with a new one
376 g_object_ref (G_OBJECT (header));
377 self->col[column].hdr = header;
382 test_simple_table_set_row_description (AtkTable *table, gint row, const gchar *description)
384 TestSimpleTable* self = (TestSimpleTable*)table;
385 if ((!self) || self->disposed)
390 if ((row < 0) || (row >= self->nrows) || !description)
395 strncpy (TEST_SIMPLE_TEXT (self->row[row].hdr)->text, description, MAX_DESCR_LENGTH);
400 test_simple_table_set_row_header (AtkTable *table, gint row, AtkObject *header)
402 TestSimpleTable* self = (TestSimpleTable*)table;
403 if ((!self) || self->disposed)
408 if ((row < 0) || (row >= self->nrows) || !header)
414 g_object_unref (G_OBJECT (self->row[row].hdr));
416 // and replace it with a new one
417 g_object_ref (G_OBJECT (header));
418 self->row[row].hdr = header;
424 test_simple_table_set_summary (AtkTable *table, AtkObject *accessible)
426 TestSimpleTable* self = (TestSimpleTable*)table;
427 if ((!self) || self->disposed || !accessible)
432 // unref the old summary
433 g_object_unref (G_OBJECT (self->summary));
435 // and replace it with a new one
436 self->summary = accessible;
437 g_object_ref (G_OBJECT (self->summary));
442 test_simple_table_get_selected_columns (AtkTable *table, gint **selected)
444 TestSimpleTable* self = (TestSimpleTable*)table;
445 if ((!self) || self->disposed || !selected)
450 // count the selected columns
453 for (i = 0; i < self->ncols; ++i)
455 if (self->col[i].selected)
463 // store the indexes of the selected columns
465 *selected = g_new (gint, nsel);
466 for (i = 0; i < self->ncols; ++i)
468 if (self->col[i].selected)
470 (*selected)[pos] = i;
480 test_simple_table_get_selected_rows (AtkTable *table, gint **selected)
482 TestSimpleTable* self = (TestSimpleTable*)table;
483 if ((!self) || self->disposed || !selected)
488 // count the selected rows
491 for (i = 0; i < self->nrows; ++i)
493 if (self->row[i].selected)
501 // store the indexes of the selected rows
503 *selected = g_new (gint, nsel);
504 for (i = 0; i < self->nrows; ++i)
506 if (self->row[i].selected)
508 (*selected)[pos] = i;
518 test_simple_table_is_column_selected (AtkTable *table, gint column)
520 TestSimpleTable* self = (TestSimpleTable*)table;
521 if ((!self) || self->disposed)
526 if ((column < 0) || (column >= self->ncols))
531 return self->col[column].selected;
535 test_simple_table_is_row_selected (AtkTable *table, gint row)
537 TestSimpleTable* self = (TestSimpleTable*)table;
538 if ((!self) || self->disposed)
543 if ((row < 0) || (row >= self->nrows))
548 return self->row[row].selected;
552 test_simple_table_is_selected (AtkTable *table, gint row, gint column)
554 TestSimpleTable* self = (TestSimpleTable*)table;
555 if ((!self) || self->disposed)
560 if ((row < 0) || (row >= self->nrows) ||
561 (column < 0) || (column >= self->ncols))
566 // In this implementation a cell is selected if and only if the
567 // corresponding row and column are both selected.
569 return (self->row[row].selected && self->col[column].selected);
573 test_simple_table_add_row_selection (AtkTable *table, gint row)
575 TestSimpleTable* self = (TestSimpleTable*)table;
576 if ((!self) || self->disposed)
581 if ((row < 0) || (row >= self->nrows))
586 gboolean was_selected = self->row[row].selected;
587 self->row[row].selected = TRUE;
588 return !was_selected;
592 test_simple_table_remove_row_selection (AtkTable *table, gint row)
594 TestSimpleTable* self = (TestSimpleTable*)table;
595 if ((!self) || self->disposed)
600 gboolean was_selected = self->row[row].selected;
601 self->row[row].selected = FALSE;
606 test_simple_table_add_column_selection (AtkTable *table, gint column)
608 TestSimpleTable* self = (TestSimpleTable*)table;
609 if ((!self) || self->disposed)
614 if ((column < 0) || (column >= self->ncols))
619 gboolean was_selected = self->col[column].selected;
620 self->col[column].selected = TRUE;
621 return !was_selected;
625 test_simple_table_remove_column_selection (AtkTable *table, gint column)
627 TestSimpleTable* self = (TestSimpleTable*)table;
628 if ((!self) || self->disposed)
633 gboolean was_selected = self->col[column].selected;
634 self->col[column].selected = FALSE;
641 emit_column_deleted (TestSimpleTable* table, gint arg1, gint arg2)
643 g_signal_emit_by_name ((gpointer)table, "column-deleted", arg1, arg2);
649 emit_column_inserted (TestSimpleTable* table, gint arg1, gint arg2)
651 g_signal_emit_by_name ((gpointer)table, "column-inserted", arg1, arg2);
655 // "column-reordered"
657 emit_column_reordered (TestSimpleTable* table)
659 g_signal_emit_by_name ((gpointer)table, "column-reordered");
665 emit_model_changed (TestSimpleTable* table)
667 g_signal_emit_by_name ((gpointer)table, "model-changed");
673 emit_row_deleted (TestSimpleTable* table, gint arg1, gint arg2)
675 g_signal_emit_by_name ((gpointer)table, "row-deleted", arg1, arg2);
681 emit_row_inserted (TestSimpleTable* table, gint arg1, gint arg2)
683 g_signal_emit_by_name ((gpointer)table, "row-inserted", arg1, arg2);
689 emit_row_reordered (TestSimpleTable* table)
691 g_signal_emit_by_name ((gpointer)table, "row-reordered");
696 /******************************************************************/
698 simple_table_interface_init (gpointer g_iface, gpointer iface_data)
700 AtkTableIface *klass = (AtkTableIface *)g_iface;
702 /* set up overrides here */
704 (AtkObject* (*) (AtkTable *table, gint row, gint column)) test_simple_table_ref_at;
705 klass-> get_index_at =
706 (gint (*) (AtkTable *table, gint row, gint column)) test_simple_table_get_index_at;
707 klass-> get_column_at_index =
708 (gint (*) (AtkTable *table, gint index_)) test_simple_table_get_column_at_index;
709 klass-> get_row_at_index =
710 (gint (*) (AtkTable *table, gint index_)) test_simple_table_get_row_at_index;
711 klass-> get_n_columns =
712 (gint (*) (AtkTable *table)) test_simple_table_get_n_columns;
714 (gint (*) (AtkTable *table)) test_simple_table_get_n_rows;
715 klass-> get_column_extent_at =
716 (gint (*) (AtkTable *table, gint row, gint column)) test_simple_table_get_column_extent_at;
717 klass-> get_row_extent_at =
718 (gint (*) (AtkTable *table, gint row, gint column)) test_simple_table_get_row_extent_at;
719 klass-> get_caption =
720 (AtkObject* (*) (AtkTable *table)) test_simple_table_get_caption;
721 klass-> get_column_description =
722 (const gchar* (*) (AtkTable *table, gint column)) test_simple_table_get_column_description;
723 klass-> get_column_header =
724 (AtkObject* (*) (AtkTable *table, gint column)) test_simple_table_get_column_header;
725 klass-> get_row_description =
726 (const gchar* (*) (AtkTable *table, gint row)) test_simple_table_get_row_description;
727 klass-> get_row_header =
728 (AtkObject* (*) (AtkTable *table, gint row)) test_simple_table_get_row_header;
729 klass-> get_summary =
730 (AtkObject* (*) (AtkTable *table)) test_simple_table_get_summary;
731 klass-> set_caption =
732 (void (*) (AtkTable *table, AtkObject *caption)) test_simple_table_set_caption;
733 klass-> set_column_description =
734 (void (*) (AtkTable *table, gint column, const gchar *description)) test_simple_table_set_column_description;
735 klass-> set_column_header =
736 (void (*) (AtkTable *table, gint column, AtkObject *header)) test_simple_table_set_column_header;
737 klass-> set_row_description =
738 (void (*) (AtkTable *table, gint row, const gchar *description)) test_simple_table_set_row_description;
739 klass-> set_row_header =
740 (void (*) (AtkTable *table, gint row, AtkObject *header)) test_simple_table_set_row_header ;
741 klass-> set_summary =
742 (void (*) (AtkTable *table, AtkObject *accessible)) test_simple_table_set_summary ;
743 klass-> get_selected_columns =
744 (gint (*) (AtkTable *table, gint **selected)) test_simple_table_get_selected_columns;
745 klass-> get_selected_rows =
746 (gint (*) (AtkTable *table, gint **selected)) test_simple_table_get_selected_rows;
747 klass-> is_column_selected =
748 (gboolean (*) (AtkTable *table, gint column)) test_simple_table_is_column_selected;
749 klass-> is_row_selected =
750 (gboolean (*) (AtkTable *table, gint row)) test_simple_table_is_row_selected;
751 klass-> is_selected =
752 (gboolean (*) (AtkTable *table, gint row, gint column)) test_simple_table_is_selected;
753 klass-> add_row_selection =
754 (gboolean (*) (AtkTable *table, gint row)) test_simple_table_add_row_selection;
755 klass-> remove_row_selection =
756 (gboolean (*) (AtkTable *table, gint row)) test_simple_table_remove_row_selection;
757 klass-> add_column_selection =
758 (gboolean (*) (AtkTable *table, gint column)) test_simple_table_add_column_selection;
759 klass-> remove_column_selection =
760 (gboolean (*) (AtkTable *table, gint column)) test_simple_table_remove_column_selection;
764 simple_table_instance_init (GTypeInstance *instance, gpointer g_class)
766 TestSimpleTable *self = (TestSimpleTable *)instance;
768 self->disposed = FALSE;
773 /* create & initialize child objects */
775 for (i = 0; i < NCHILDREN; ++i)
777 self->child[i] = TEST_SIMPLE_CHILD (g_object_new (TEST_TYPE_SIMPLE_CHILD, NULL));
778 self->child[i]->id = i;
781 self->not_a_child = TEST_SIMPLE_CHILD (g_object_new (TEST_TYPE_SIMPLE_CHILD, NULL));
783 // initialize table cells
784 for (i = 0; i < NROWS; ++i)
786 for (j = 0; j < NCOLS; ++j)
790 self->tbl[i][j].elem = self->child[ids[i][j]];
794 self->tbl[i][j].elem = self->not_a_child;
797 self->tbl[i][j].ext_row = row_ext[i][j];
798 self->tbl[i][j].ext_col = col_ext[i][j];
802 self->caption = ATK_OBJECT (g_object_new (TEST_TYPE_SIMPLE_TEXT, NULL));
803 strncpy (TEST_SIMPLE_TEXT (self->caption)->text, DEF_CAPTION_TEXT, MAX_DESCR_LENGTH);
805 self->summary = ATK_OBJECT (g_object_new (TEST_TYPE_SIMPLE_TEXT, NULL));
806 strncpy (TEST_SIMPLE_TEXT (self->summary)->text, DEF_SUMMARY_TEXT, MAX_DESCR_LENGTH);
808 // initialize row and column descriptors
809 for (i = 0; i < NROWS; ++i)
811 self->row[i].hdr = ATK_OBJECT (g_object_new (TEST_TYPE_SIMPLE_TEXT, NULL));
812 self->row[i].selected = FALSE;
815 for (j = 0; j < NCOLS; ++j)
817 self->col[j].hdr = ATK_OBJECT (g_object_new (TEST_TYPE_SIMPLE_TEXT, NULL));
818 self->col[j].selected = FALSE;
821 test_simple_table_reset_headers(self);
825 test_simple_table_dispose (GObject *obj)
827 TestSimpleTable *self = (TestSimpleTable *)obj;
834 /* Make sure dispose does not run twice. */
835 self->disposed = TRUE;
838 for (i = 0; i < NCHILDREN; ++i)
840 g_object_unref (G_OBJECT (self->child[i]));
842 g_object_unref (G_OBJECT (self->not_a_child));
844 for (i = 0; i < NROWS; ++i)
846 g_object_unref (G_OBJECT (self->row[i].hdr));
849 for (i = 0; i < NCOLS; ++i)
851 g_object_unref (G_OBJECT (self->col[i].hdr));
854 g_object_unref (G_OBJECT (self->caption));
855 g_object_unref (G_OBJECT (self->summary));
857 /* Chain up to the parent class */
858 G_OBJECT_CLASS (parent_class_simple_table)->dispose (obj);
862 test_simple_table_finalize (GObject *obj)
864 /* Chain up to the parent class */
865 G_OBJECT_CLASS (parent_class_simple_table)->finalize (obj);
869 test_simple_table_class_init (gpointer g_class, gpointer g_class_data)
871 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
872 TestSimpleTableClass *klass = TEST_SIMPLE_TABLE_CLASS (g_class);
874 gobject_class->dispose = test_simple_table_dispose;
875 gobject_class->finalize = test_simple_table_finalize;
877 parent_class_simple_table = g_type_class_peek_parent (klass);
881 test_simple_table_get_type (void)
883 static GType type = 0;
886 static const GTypeInfo info =
888 sizeof (TestSimpleTableClass),
889 NULL, /* base_init */
890 NULL, /* base_finalize */
891 test_simple_table_class_init, /* class_init */
892 NULL, /* class_finalize */
893 NULL, /* class_data */
894 sizeof (TestSimpleTable),
896 simple_table_instance_init /* instance_init */
899 static const GInterfaceInfo iface_info =
901 (GInterfaceInitFunc) simple_table_interface_init, /* interface_init */
902 NULL, /* interface_finalize */
903 NULL /* interface_data */
905 type = g_type_register_static (ATK_TYPE_OBJECT,
906 "TestSimpleTableType",
908 g_type_add_interface_static (type,