From 97003e3366eee6629aa50b95468e74939c38c68c Mon Sep 17 00:00:00 2001 From: Bolian Yin Date: Mon, 3 Nov 2003 06:40:50 +0000 Subject: *e-table/gal-a11y-e-table-item: defunct widget checking, selection 2003-10-30 Bolian Yin *e-table/gal-a11y-e-table-item: defunct widget checking, selection interface svn path=/trunk/; revision=23167 --- a11y/e-table/gal-a11y-e-table-item.c | 372 +++++++++++++++++++++++++++++++---- a11y/e-table/gal-a11y-e-table-item.h | 5 +- 2 files changed, 334 insertions(+), 43 deletions(-) (limited to 'a11y/e-table') diff --git a/a11y/e-table/gal-a11y-e-table-item.c b/a11y/e-table/gal-a11y-e-table-item.c index 6ee060caba..2cf544e8a5 100644 --- a/a11y/e-table/gal-a11y-e-table-item.c +++ b/a11y/e-table/gal-a11y-e-table-item.c @@ -2,6 +2,7 @@ /* * Authors: * Christopher James Lahey + * Bolian Yin * * Copyright (C) 2002 Ximian, Inc. */ @@ -10,6 +11,8 @@ #include "gal-a11y-e-table-item.h" #include "gal-a11y-e-cell-registry.h" #include "gal-a11y-util.h" +#include + #include #include #include @@ -41,6 +44,33 @@ unref_accessible (gpointer user_data, GObject *obj_loc) } #endif +inline static gint +view_to_model_row(ETableItem *eti, int row) +{ + if (eti->uses_source_model) { + ETableSubset *etss = E_TABLE_SUBSET(eti->table_model); + if (row >= 0 && row < etss->n_map) { + eti->row_guess = row; + return etss->map_table[row]; + } else + return -1; + } else + return row; +} + +inline static gint +view_to_model_col(ETableItem *eti, int col) +{ + ETableCol *ecol = e_table_header_get_column (eti->header, col); + return ecol ? ecol->col_idx : -1; +} + +inline static GObject * +eti_a11y_get_gobject (AtkObject *accessible) +{ + return atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible)); +} + static void eti_dispose (GObject *object) { @@ -61,54 +91,84 @@ eti_dispose (GObject *object) } /* Static functions */ -static AtkObject* +static AtkObject * eti_get_parent (AtkObject *accessible) { - GalA11yETableItem *a11y = GAL_A11Y_E_TABLE_ITEM (accessible); + AtkGObjectAccessible *atk_gobj; + GalA11yETableItem *a11y; + + g_return_val_if_fail (GAL_A11Y_IS_E_TABLE_ITEM (accessible), NULL); + if (!eti_a11y_get_gobject (accessible)) + /* defunct */ + return NULL; + + a11y = GAL_A11Y_E_TABLE_ITEM (accessible); return GET_PRIVATE (a11y)->parent; } static gint eti_get_n_children (AtkObject *accessible) { + AtkGObjectAccessible *atk_gobj; + + g_return_val_if_fail (GAL_A11Y_IS_E_TABLE_ITEM (accessible), 0); + if (!eti_a11y_get_gobject (accessible)) + return 0; + return atk_table_get_n_columns (ATK_TABLE (accessible)) * atk_table_get_n_rows (ATK_TABLE (accessible)); } static AtkObject* -eti_ref_child (AtkObject *accessible, - gint i) +eti_ref_child (AtkObject *accessible, gint i) { - AtkTable *table = ATK_TABLE (accessible); - ETableItem *item = E_TABLE_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible))); + AtkGObjectAccessible *atk_gobj; + ETableItem *item; + gint col, row; + + g_return_val_if_fail (GAL_A11Y_IS_E_TABLE_ITEM (accessible), NULL); + item = E_TABLE_ITEM (eti_a11y_get_gobject (accessible)); + if (!item) + return NULL; - int col = i % item->cols; - int row = i / item->cols; + col = i % item->cols; + row = i / item->cols; - return atk_table_ref_at (table, row, col); + return atk_table_ref_at (ATK_TABLE (accessible), row, col); } static gint eti_get_index_in_parent (AtkObject *accessible) { - GalA11yETableItem *a11y = GAL_A11Y_E_TABLE_ITEM (accessible); + AtkGObjectAccessible *atk_gobj; + GalA11yETableItem *a11y; + + g_return_val_if_fail (GAL_A11Y_IS_E_TABLE_ITEM (accessible), -1); + if (!eti_a11y_get_gobject (accessible)) + return -1; + + a11y = GAL_A11Y_E_TABLE_ITEM (accessible); return GET_PRIVATE (a11y)->index_in_parent; } static void eti_get_extents (AtkComponent *component, - gint *x, - gint *y, - gint *width, - gint *height, - AtkCoordType coord_type) + gint *x, + gint *y, + gint *width, + gint *height, + AtkCoordType coord_type) { - ETableItem *item = E_TABLE_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (component))); + ETableItem *item; double real_width; double real_height; int fake_width; int fake_height; + item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (component))); + if (!item) + return; + if (component_parent_iface && component_parent_iface->get_extents) component_parent_iface->get_extents (component, @@ -138,7 +198,11 @@ eti_ref_accessible_at_point (AtkComponent *component, int row = -1; int col = -1; int x_origin, y_origin; - ETableItem *item = E_TABLE_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (component))); + ETableItem *item; + + item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (component))); + if (!item) + return; atk_component_get_position (component, &x_origin, @@ -158,15 +222,16 @@ eti_ref_accessible_at_point (AtkComponent *component, } -/* Table IFace */ +/* atk table */ static AtkObject* -eti_ref_at (AtkTable *table, - gint row, - gint column) +eti_ref_at (AtkTable *table, gint row, gint column) { - AtkObject* accessible = ATK_OBJECT (table); - ETableItem *item = E_TABLE_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (table))); + ETableItem *item; + + item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); + if (!item) + return NULL; if (column >= 0 && column < item->cols && @@ -178,7 +243,7 @@ eti_ref_at (AtkTable *table, return gal_a11y_e_cell_registry_get_object (NULL, item, cell_view, - accessible, + ATK_OBJECT (table), ecol->col_idx, column, row); @@ -188,29 +253,37 @@ eti_ref_at (AtkTable *table, } static gint -eti_get_index_at (AtkTable *table, - gint row, - gint column) +eti_get_index_at (AtkTable *table, gint row, gint column) { - ETableItem *item = E_TABLE_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (table))); + ETableItem *item; + + item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); + if (!item) + return -1; return column + row * item->cols; } static gint -eti_get_column_at_index (AtkTable *table, - gint index) +eti_get_column_at_index (AtkTable *table, gint index) { - ETableItem *item = E_TABLE_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (table))); + ETableItem *item; + + item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); + if (!item) + return -1; return index % item->cols; } static gint -eti_get_row_at_index (AtkTable *table, - gint index) +eti_get_row_at_index (AtkTable *table, gint index) { - ETableItem *item = E_TABLE_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (table))); + ETableItem *item; + + item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); + if (!item) + return -1; return index / item->cols; } @@ -218,7 +291,11 @@ eti_get_row_at_index (AtkTable *table, static gint eti_get_n_columns (AtkTable *table) { - ETableItem *item = E_TABLE_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (table))); + ETableItem *item; + + item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); + if (!item) + return -1; return item->cols; } @@ -226,7 +303,11 @@ eti_get_n_columns (AtkTable *table) static gint eti_get_n_rows (AtkTable *table) { - ETableItem *item = E_TABLE_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (table))); + ETableItem *item; + + item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); + if (!item) + return -1; return item->rows; } @@ -236,9 +317,13 @@ eti_get_column_extent_at (AtkTable *table, gint row, gint column) { - ETableItem *item = E_TABLE_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (table))); + ETableItem *item; int width; + item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); + if (!item) + return -1; + e_table_item_get_cell_geometry (item, &row, &column, @@ -255,9 +340,13 @@ eti_get_row_extent_at (AtkTable *table, gint row, gint column) { - ETableItem *item = E_TABLE_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (table))); + ETableItem *item; int height; + item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); + if (!item) + return -1; + e_table_item_get_cell_geometry (item, &row, &column, @@ -280,15 +369,21 @@ static G_CONST_RETURN gchar * eti_get_column_description (AtkTable *table, gint column) { - ETableItem *item = E_TABLE_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (table))); - ETableCol *ecol = e_table_header_get_column (item->header, column); + ETableItem *item; + ETableCol *ecol; + + item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); + if (!item) + return NULL; + + ecol = e_table_header_get_column (item->header, column); return ecol->text; } static AtkObject * eti_get_column_header (AtkTable *table, - gint column) + gint column) { /* Unimplemented */ return NULL; @@ -317,6 +412,83 @@ eti_get_summary (AtkTable *table) return NULL; } +static gboolean +table_is_row_selected (AtkTable *table, gint row) +{ + ETableItem *item; + + item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); + if (!item) + return FALSE; + + return e_selection_model_is_row_selected(item->selection, row); +} + +static gboolean +table_is_selected (AtkTable *table, gint row, gint column) +{ + return table_is_row_selected (table, row); +} + +static gint +table_get_selected_rows (AtkTable *table, gint **rows_selected) +{ + ETableItem *item; + gint n_selected, row, index_selected; + + item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); + if (!item) + return 0; + + n_selected = e_selection_model_selected_count (item->selection); + if (rows_selected) { + *rows_selected = (gint *) g_malloc (n_selected * sizeof (gint)); + + index_selected = 0; + for (row = 0; row < item->rows && index_selected < n_selected; ++row) { + if (atk_table_is_row_selected (table, row)) { + (*rows_selected)[index_selected] = row; + ++index_selected; + } + } + } + return n_selected; +} + +static gboolean +table_add_row_selection (AtkTable *table, gint row) +{ + ETableItem *item; + gint cursor_row, cursor_col, row_count; + GdkModifierType state = GDK_CONTROL_MASK; + ESelectionModel *selection; + + item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); + if (!item) + return FALSE; + + if (table_is_row_selected (table, row)) + return TRUE; + e_selection_model_toggle_single_row (item->selection, view_to_model_row (item, row)); + + return TRUE; +} + +static gboolean +table_remove_row_selection (AtkTable *table, gint row) +{ + ETableItem *item; + + item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); + if (!item) + return FALSE; + + if (!atk_table_is_row_selected (table, row)) + return TRUE; + e_selection_model_toggle_single_row (item->selection, row); + return TRUE; +} + static void eti_atk_table_iface_init (AtkTableIface *iface) { @@ -334,6 +506,12 @@ eti_atk_table_iface_init (AtkTableIface *iface) iface->get_row_description = eti_get_row_description; iface->get_row_header = eti_get_row_header; iface->get_summary = eti_get_summary; + + iface->is_row_selected = table_is_row_selected; + iface->is_selected = table_is_selected; + iface->get_selected_rows = table_get_selected_rows; + iface->add_row_selection = table_add_row_selection; + iface->remove_row_selection = table_remove_row_selection; } static void @@ -374,6 +552,19 @@ eti_init (GalA11yETableItem *a11y) priv->index_in_parent = -1; } +/* atk selection */ + +static void atk_selection_interface_init (AtkSelectionIface *iface); +static gboolean selection_add_selection (AtkSelection *selection, + gint i); +static gboolean selection_clear_selection (AtkSelection *selection); +static AtkObject* selection_ref_selection (AtkSelection *selection, + gint i); +static gint selection_get_selection_count (AtkSelection *selection); +static gboolean selection_is_child_selected (AtkSelection *selection, + gint i); + + /** * gal_a11y_e_table_item_get_type: * @void: @@ -415,6 +606,13 @@ gal_a11y_e_table_item_get_type (void) NULL }; + static const GInterfaceInfo atk_selection_info = { + (GInterfaceInitFunc) atk_selection_interface_init, + (GInterfaceFinalizeFunc) NULL, + NULL + }; + + factory = atk_registry_get_factory (atk_get_default_registry (), GNOME_TYPE_CANVAS_ITEM); parent_type = atk_object_factory_get_accessible_type (factory); @@ -423,6 +621,7 @@ gal_a11y_e_table_item_get_type (void) g_type_add_interface_static (type, ATK_TYPE_COMPONENT, &atk_component_info); g_type_add_interface_static (type, ATK_TYPE_TABLE, &atk_table_info); + g_type_add_interface_static (type, ATK_TYPE_SELECTION, &atk_selection_info); } return type; @@ -454,3 +653,94 @@ gal_a11y_e_table_item_new (AtkObject *parent, return ATK_OBJECT (a11y); } + +/* atk selection */ + +static void atk_selection_interface_init (AtkSelectionIface *iface) +{ + g_return_if_fail (iface != NULL); + iface->add_selection = selection_add_selection; + iface->clear_selection = selection_clear_selection; + iface->ref_selection = selection_ref_selection; + iface->get_selection_count = selection_get_selection_count; + iface->is_child_selected = selection_is_child_selected; +} + +static gboolean +selection_add_selection (AtkSelection *selection, gint index) +{ + AtkTable *table; + gint row, col; + ETableItem *item; + + item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (selection))); + if (!item) + return FALSE; + + table = ATK_TABLE (selection); + + row = atk_table_get_row_at_index (table, index); + atk_table_add_row_selection (table, row); + + col = atk_table_get_column_at_index (table, index); + e_selection_model_change_cursor (item->selection, + view_to_model_row (item, row), + view_to_model_col (item, col)); + e_selection_model_cursor_changed (item->selection, + view_to_model_row (item, row), + view_to_model_col (item, col)); + e_selection_model_cursor_activated (item->selection, + view_to_model_row (item, row), + view_to_model_col (item, col)); + return TRUE; +} + +static gboolean +selection_clear_selection (AtkSelection *selection) +{ + ETableItem *item; + + item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (selection))); + if (!item) + return FALSE; + + e_selection_model_clear (item->selection); + return TRUE; +} + +static AtkObject* +selection_ref_selection (AtkSelection *selection, gint index) +{ + AtkTable *table; + gint row, col; + + table = ATK_TABLE (selection); + row = atk_table_get_row_at_index (table, index); + col = atk_table_get_column_at_index (table, index); + if (!atk_table_is_row_selected (table, row)) + return NULL; + + return atk_table_ref_at (table, row, col); +} + +static gint +selection_get_selection_count (AtkSelection *selection) +{ + AtkTable *table; + gint n_selected; + + table = ATK_TABLE (selection); + n_selected = atk_table_get_selected_rows (table, NULL); + if (n_selected > 0) + n_selected *= atk_table_get_n_columns (table); + return n_selected; +} + +static gboolean +selection_is_child_selected (AtkSelection *selection, gint i) +{ + gint row; + + row = atk_table_get_row_at_index (ATK_TABLE (selection), i); + return atk_table_is_row_selected (ATK_TABLE (selection), row); +} diff --git a/a11y/e-table/gal-a11y-e-table-item.h b/a11y/e-table/gal-a11y-e-table-item.h index 795fa64499..f3a447131d 100644 --- a/a11y/e-table/gal-a11y-e-table-item.h +++ b/a11y/e-table/gal-a11y-e-table-item.h @@ -11,6 +11,7 @@ #include #include +#include #define GAL_A11Y_TYPE_E_TABLE_ITEM (gal_a11y_e_table_item_get_type ()) #define GAL_A11Y_E_TABLE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAL_A11Y_TYPE_E_TABLE_ITEM, GalA11yETableItem)) @@ -26,11 +27,11 @@ typedef struct _GalA11yETableItemPrivate GalA11yETableItemPrivate; * The GalA11yETableItemPrivate comes right after the parent class structure. **/ struct _GalA11yETableItem { - AtkObject object; + AtkGObjectAccessible parent; }; struct _GalA11yETableItemClass { - AtkObject parent_class; + AtkGObjectAccessibleClass parent_class; }; -- cgit v1.2.3