mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-16 07:04:29 +00:00
list box: Update accessible implementation
Now that multi selection is supported, we can provide a more complete AtkSelection implementation.
This commit is contained in:
parent
f652120347
commit
efcaaa524e
@ -84,6 +84,26 @@ gtk_list_box_accessible_add_selection (AtkSelection *selection,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user