2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility)
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
27 #include "my-atk-object.h"
28 #include "my-atk-selection.h"
30 static void atk_selection_interface_init (AtkSelectionIface *iface);
32 G_DEFINE_TYPE_WITH_CODE (MyAtkSelection,
35 G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION,
36 atk_selection_interface_init));
39 my_atk_selection_init (MyAtkSelection *obj)
44 my_atk_selection_add_selection (AtkSelection *selection, gint i)
46 MyAtkSelection *self = MY_ATK_SELECTION(selection);
50 AtkObject *child = atk_object_ref_accessible_child (ATK_OBJECT (selection), i);
51 AtkStateSet *ss = atk_object_ref_state_set (child);
52 atk_state_set_add_state (ss, ATK_STATE_SELECTED);
53 return atk_state_set_contains_state (ss, ATK_STATE_SELECTED);
57 my_atk_selection_clear_selection (AtkSelection *selection)
59 MyAtkSelection *self = MY_ATK_SELECTION(selection);
62 AtkObject *child = NULL;
63 AtkStateSet *states = NULL;
65 int childs = atk_object_get_n_accessible_children (ATK_OBJECT (selection));
67 for (i=0; i<childs; i++) {
68 child = atk_object_ref_accessible_child (ATK_OBJECT (selection), i);
69 states = atk_object_ref_state_set (child);
70 atk_state_set_remove_state (states, ATK_STATE_SELECTED);
76 my_atk_selection_ref_selection (AtkSelection *selection, gint no)
78 MyAtkSelection *self = MY_ATK_SELECTION(selection);
81 AtkObject *child = NULL;
82 AtkStateSet *states = NULL;
83 GArray *array = g_array_new (FALSE, FALSE, sizeof (AtkObject *));
85 int childs = atk_object_get_n_accessible_children (ATK_OBJECT (selection));
87 for (i=0; i<childs; i++) {
88 child = atk_object_ref_accessible_child (ATK_OBJECT (selection), i);
89 states = atk_object_ref_state_set (child);
90 if (atk_state_set_contains_state (states, ATK_STATE_SELECTED))
91 g_array_append_val (array, child);
94 return g_array_index (array, AtkObject *, no);
98 my_atk_selection_get_selection_count (AtkSelection *selection)
100 MyAtkSelection *self = MY_ATK_SELECTION(selection);
103 AtkObject *child = NULL;
104 AtkStateSet *states = NULL;
106 int childs = atk_object_get_n_accessible_children (ATK_OBJECT (selection));
108 for (i=0; i<childs; i++) {
109 child = atk_object_ref_accessible_child (ATK_OBJECT (selection), i);
110 states = atk_object_ref_state_set (child);
111 if (atk_state_set_contains_state (states, ATK_STATE_SELECTED))
119 my_atk_selection_is_child_selected (AtkSelection *selection, gint i)
121 MyAtkSelection *self = MY_ATK_SELECTION(selection);
124 AtkObject *child = NULL;
125 AtkStateSet *states = NULL;
126 child = atk_object_ref_accessible_child (ATK_OBJECT (selection), i);
127 states = atk_object_ref_state_set (child);
128 if (atk_state_set_contains_state (states, ATK_STATE_SELECTED))
134 my_atk_selection_remove_selection (AtkSelection *selection, gint no)
136 MyAtkSelection *self = MY_ATK_SELECTION(selection);
137 AtkObject *child = NULL;
138 AtkStateSet *states = NULL;
139 GArray *array = NULL;
143 gboolean ret = FALSE;
147 array = g_array_new (FALSE, FALSE, sizeof (AtkObject *));
148 childs = atk_object_get_n_accessible_children (ATK_OBJECT (selection));
150 for (i=0; i<childs; i++) {
151 child = atk_object_ref_accessible_child (ATK_OBJECT (selection), i);
152 states = atk_object_ref_state_set (child);
153 if (atk_state_set_contains_state (states, ATK_STATE_SELECTED))
154 g_array_append_val (array, child);
156 g_object_unref (states);
158 o = g_array_index (array, AtkObject *, no);
159 states = atk_object_ref_state_set (o);
160 atk_state_set_remove_state (states, ATK_STATE_SELECTED);
162 ret = !atk_state_set_contains_state (states, ATK_STATE_SELECTED);
163 g_object_unref (states);
165 g_object_unref (self);
166 g_array_free (array, TRUE);
172 my_atk_selection_select_all_selection (AtkSelection *selection)
174 MyAtkSelection *self = MY_ATK_SELECTION(selection);
175 AtkObject *child = NULL;
176 AtkStateSet *states = NULL;
182 childs = atk_object_get_n_accessible_children (ATK_OBJECT (selection));
184 for (i=0; i<childs; i++) {
185 child = atk_object_ref_accessible_child (ATK_OBJECT (selection), i);
186 states = atk_object_ref_state_set (child);
187 atk_state_set_add_state (states, ATK_STATE_SELECTED);
188 g_object_unref (states);
189 g_object_unref (child);
192 g_object_unref (self);
197 atk_selection_interface_init (AtkSelectionIface *iface)
201 iface->add_selection = my_atk_selection_add_selection;
202 iface->clear_selection = my_atk_selection_clear_selection;
203 iface->ref_selection = my_atk_selection_ref_selection;
204 iface->get_selection_count = my_atk_selection_get_selection_count;
205 iface->is_child_selected = my_atk_selection_is_child_selected;
206 iface->remove_selection = my_atk_selection_remove_selection;
207 iface->select_all_selection = my_atk_selection_select_all_selection;
211 my_atk_selection_initialize (AtkObject *obj, gpointer data)
216 my_atk_selection_finalize (GObject *obj)
221 my_atk_selection_class_init (MyAtkSelectionClass *my_class)
223 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(my_class);
224 GObjectClass *gobject_class = G_OBJECT_CLASS(my_class);
226 gobject_class->finalize = my_atk_selection_finalize;
228 atk_class->initialize = my_atk_selection_initialize;