[gtk+/list-selection: 4/6] list box: Update accessible implementation
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/list-selection: 4/6] list box: Update accessible implementation
- Date: Sat, 29 Mar 2014 03:55:20 +0000 (UTC)
commit 0e4a2a58f2d0971ab6faee2f4c706c3e60b9e3dc
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Mar 28 22:10:27 2014 -0400
list box: Update accessible implementation
Now that multi selection is supported, we can provide a more
complete AtkSelection implementation.
gtk/a11y/gtklistboxaccessible.c | 97 ++++++++++++++++++++++++++------
gtk/a11y/gtklistboxaccessibleprivate.h | 5 +-
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 f4f2690..3343dc9 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 da3563b..61ecea3 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 36e84a7..d6812df 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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]