diff options
author | Matthias Clasen <mclasen@redhat.com> | 2014-03-28 22:10:27 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2014-04-06 01:44:36 -0400 |
commit | efcaaa524eed6d6836327e866d3b832da55613fe (patch) | |
tree | e4c6583c17fee1caa2d76d0ff1542ffc8ccb15f1 /gtk/a11y | |
parent | f652120347f6348dc895ba48f4c7b77bbab27114 (diff) | |
download | gtk+-efcaaa524eed6d6836327e866d3b832da55613fe.tar.gz |
list box: Update accessible implementation
Now that multi selection is supported, we can provide a more
complete AtkSelection implementation.
Diffstat (limited to 'gtk/a11y')
-rw-r--r-- | gtk/a11y/gtklistboxaccessible.c | 97 | ||||
-rw-r--r-- | gtk/a11y/gtklistboxaccessibleprivate.h | 5 | ||||
-rw-r--r-- | gtk/a11y/gtklistboxrowaccessible.c | 2 |
3 files changed, 84 insertions, 20 deletions
diff --git a/gtk/a11y/gtklistboxaccessible.c b/gtk/a11y/gtklistboxaccessible.c index f4f2690489..3343dc925c 100644 --- a/gtk/a11y/gtklistboxaccessible.c +++ b/gtk/a11y/gtklistboxaccessible.c @@ -85,6 +85,26 @@ gtk_list_box_accessible_add_selection (AtkSelection *selection, } static gboolean +gtk_list_box_accessible_remove_selection (AtkSelection *selection, + gint idx) +{ + GtkWidget *box; + GtkListBoxRow *row; + + box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection)); + if (box == NULL) + return FALSE; + + row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (box), idx); + if (row) + { + gtk_list_box_unselect_row (GTK_LIST_BOX (box), row); + return TRUE; + } + return FALSE; +} + +static gboolean gtk_list_box_accessible_clear_selection (AtkSelection *selection) { GtkWidget *box; @@ -93,49 +113,92 @@ gtk_list_box_accessible_clear_selection (AtkSelection *selection) if (box == NULL) return FALSE; - gtk_list_box_select_row (GTK_LIST_BOX (box), NULL); + gtk_list_box_unselect_all (GTK_LIST_BOX (box)); return TRUE; } +static gboolean +gtk_list_box_accessible_select_all (AtkSelection *selection) +{ + GtkWidget *box; + + box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection)); + if (box == NULL) + return FALSE; + + gtk_list_box_select_all (GTK_LIST_BOX (box)); + return TRUE; +} + +typedef struct +{ + gint idx; + GtkWidget *row; +} FindSelectedData; + +static void +find_selected_row (GtkListBox *box, + GtkListBoxRow *row, + gpointer data) +{ + FindSelectedData *d = data; + + if (d->idx == 0) + { + if (d->row == NULL) + d->row = GTK_WIDGET (row); + } + else + d->idx -= 1; +} + static AtkObject * gtk_list_box_accessible_ref_selection (AtkSelection *selection, gint idx) { GtkWidget *box; - GtkListBoxRow *row; AtkObject *accessible; - - if (idx != 0) - return NULL; + FindSelectedData data; box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection)); if (box == NULL) return NULL; - row = gtk_list_box_get_selected_row (GTK_LIST_BOX (box)); - if (row == NULL) + data.idx = idx; + data.row = NULL; + gtk_list_box_selected_foreach (GTK_LIST_BOX (box), find_selected_row, &data); + + if (data.row == NULL) return NULL; - accessible = gtk_widget_get_accessible (GTK_WIDGET (row)); + accessible = gtk_widget_get_accessible (data.row); g_object_ref (accessible); return accessible; } +static void +count_selected (GtkListBox *box, + GtkListBoxRow *row, + gpointer data) +{ + gint *count = data; + *count += 1; +} + static gint gtk_list_box_accessible_get_selection_count (AtkSelection *selection) { GtkWidget *box; - GtkListBoxRow *row; + gint count; box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection)); if (box == NULL) return 0; - row = gtk_list_box_get_selected_row (GTK_LIST_BOX (box)); - if (row == NULL) - return 0; + count = 0; + gtk_list_box_selected_foreach (GTK_LIST_BOX (box), count_selected, &count); - return 1; + return count; } static gboolean @@ -149,20 +212,20 @@ gtk_list_box_accessible_is_child_selected (AtkSelection *selection, if (box == NULL) return FALSE; - row = gtk_list_box_get_selected_row (GTK_LIST_BOX (box)); - if (row == NULL) - return FALSE; + row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (box), idx); - return row == gtk_list_box_get_row_at_index (GTK_LIST_BOX (box), idx); + return gtk_list_box_row_is_selected (row); } static void atk_selection_interface_init (AtkSelectionIface *iface) { iface->add_selection = gtk_list_box_accessible_add_selection; + iface->remove_selection = gtk_list_box_accessible_remove_selection; iface->clear_selection = gtk_list_box_accessible_clear_selection; iface->ref_selection = gtk_list_box_accessible_ref_selection; iface->get_selection_count = gtk_list_box_accessible_get_selection_count; iface->is_child_selected = gtk_list_box_accessible_is_child_selected; + iface->select_all_selection = gtk_list_box_accessible_select_all; } void diff --git a/gtk/a11y/gtklistboxaccessibleprivate.h b/gtk/a11y/gtklistboxaccessibleprivate.h index da3563b095..61ecea339f 100644 --- a/gtk/a11y/gtklistboxaccessibleprivate.h +++ b/gtk/a11y/gtklistboxaccessibleprivate.h @@ -22,8 +22,9 @@ G_BEGIN_DECLS -void _gtk_list_box_accessible_update_cursor (GtkListBox *box, GtkListBoxRow *child); -void _gtk_list_box_accessible_selection_changed (GtkListBox *box); +void _gtk_list_box_accessible_update_cursor (GtkListBox *box, + GtkListBoxRow *row); +void _gtk_list_box_accessible_selection_changed (GtkListBox *box); G_END_DECLS diff --git a/gtk/a11y/gtklistboxrowaccessible.c b/gtk/a11y/gtklistboxrowaccessible.c index 36e84a728d..d6812dfaaa 100644 --- a/gtk/a11y/gtklistboxrowaccessible.c +++ b/gtk/a11y/gtklistboxrowaccessible.c @@ -53,7 +53,7 @@ gtk_list_box_row_accessible_ref_state_set (AtkObject *obj) if (gtk_list_box_get_selection_mode (GTK_LIST_BOX (parent)) != GTK_SELECTION_NONE) atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE); - if (widget == (GtkWidget*)gtk_list_box_get_selected_row (GTK_LIST_BOX (parent))) + if (gtk_list_box_row_is_selected (GTK_LIST_BOX_ROW (widget))) atk_state_set_add_state (state_set, ATK_STATE_SELECTED); } |