2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2008 Novell, Inc.
6 * Copyright 2001, 2002 Sun Microsystems Inc.,
7 * Copyright 2001, 2002 Ximian, Inc.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
25 #include "accessible.h"
28 get_selection (DBusMessage * message)
30 AtkObject *obj = spi_dbus_get_object (dbus_message_get_path (message));
33 return ATK_SELECTION (obj);
37 get_selection_from_path (const char *path, void *user_data)
39 AtkObject *obj = spi_dbus_get_object (path);
40 if (!obj || ~ATK_IS_SELECTION(obj))
42 return ATK_SELECTION (obj);
46 impl_get_nSelectedChildren (const char *path, DBusMessageIter * iter,
49 AtkSelection *selection = get_selection_from_path (path, user_data);
52 return droute_return_v_int32 (iter,
53 atk_selection_get_selection_count
58 impl_get_nSelectedChildren_str (void *datum)
60 g_assert (ATK_IS_HYPERLINK (datum));
61 return g_strdup_printf ("%d",
62 atk_selection_get_selection_count ((AtkSelection *)
67 impl_getSelectedChild (DBusConnection * bus, DBusMessage * message,
70 AtkSelection *selection = get_selection (message);
72 dbus_int32_t selectedChildIndex;
73 AtkObject *atk_object;
76 return spi_dbus_general_error (message);
77 dbus_error_init (&error);
78 if (!dbus_message_get_args
79 (message, &error, DBUS_TYPE_INT32, &selectedChildIndex,
82 return SPI_DBUS_RETURN_ERROR (message, &error);
84 atk_object = atk_selection_ref_selection (selection, selectedChildIndex);
85 return spi_dbus_return_object (message, atk_object, TRUE);
89 impl_selectChild (DBusConnection * bus, DBusMessage * message,
92 AtkSelection *selection = get_selection (message);
94 dbus_int32_t childIndex;
99 return spi_dbus_general_error (message);
100 dbus_error_init (&error);
101 if (!dbus_message_get_args
102 (message, &error, DBUS_TYPE_INT32, &childIndex, DBUS_TYPE_INVALID))
104 return SPI_DBUS_RETURN_ERROR (message, &error);
106 rv = atk_selection_add_selection (selection, childIndex);
107 reply = dbus_message_new_method_return (message);
110 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
117 impl_deselectSelectedChild (DBusConnection * bus, DBusMessage * message,
120 AtkSelection *selection = get_selection (message);
122 dbus_int32_t selectedChildIndex;
127 return spi_dbus_general_error (message);
128 dbus_error_init (&error);
129 if (!dbus_message_get_args
130 (message, &error, DBUS_TYPE_INT32, &selectedChildIndex,
133 return SPI_DBUS_RETURN_ERROR (message, &error);
135 rv = atk_selection_remove_selection (selection, selectedChildIndex);
136 reply = dbus_message_new_method_return (message);
139 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
146 impl_isChildSelected (DBusConnection * bus, DBusMessage * message,
149 AtkSelection *selection = get_selection (message);
151 dbus_int32_t childIndex;
156 return spi_dbus_general_error (message);
157 dbus_error_init (&error);
158 if (!dbus_message_get_args
159 (message, &error, DBUS_TYPE_INT32, &childIndex, DBUS_TYPE_INVALID))
161 return SPI_DBUS_RETURN_ERROR (message, &error);
163 rv = atk_selection_is_child_selected (selection, childIndex);
164 reply = dbus_message_new_method_return (message);
167 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
174 impl_selectAll (DBusConnection * bus, DBusMessage * message, void *user_data)
176 AtkSelection *selection = get_selection (message);
181 return spi_dbus_general_error (message);
182 rv = atk_selection_select_all_selection (selection);
183 reply = dbus_message_new_method_return (message);
186 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
193 impl_clearSelection (DBusConnection * bus, DBusMessage * message,
196 AtkSelection *selection = get_selection (message);
201 return spi_dbus_general_error (message);
202 rv = atk_selection_clear_selection (selection);
203 reply = dbus_message_new_method_return (message);
206 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
213 impl_deselectChild (DBusConnection * bus, DBusMessage * message,
216 AtkSelection *selection = get_selection (message);
218 dbus_int32_t selectedChildIndex;
219 dbus_bool_t rv = FALSE;
224 return spi_dbus_general_error (message);
225 dbus_error_init (&error);
226 if (!dbus_message_get_args
227 (message, &error, DBUS_TYPE_INT32, &selectedChildIndex,
230 return SPI_DBUS_RETURN_ERROR (message, &error);
232 nselected = atk_selection_get_selection_count (selection);
233 for (i = 0; i < nselected; ++i)
235 AtkObject *selected_obj = atk_selection_ref_selection (selection, i);
236 if (atk_object_get_index_in_parent (selected_obj) == selectedChildIndex)
238 g_object_unref (G_OBJECT (selected_obj));
239 rv = atk_selection_remove_selection (selection, i);
242 g_object_unref (G_OBJECT (selected_obj));
244 reply = dbus_message_new_method_return (message);
247 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
253 static DRouteMethod methods[] = {
254 {DROUTE_METHOD, impl_getSelectedChild, "getSelectedChild",
255 "i,selectedChildIndex,i:o,,o"},
256 {DROUTE_METHOD, impl_selectChild, "selectChild", "i,childIndex,i:b,,o"},
257 {DROUTE_METHOD, impl_deselectSelectedChild, "deselectSelectedChild",
258 "i,selectedChildIndex,i:b,,o"},
259 {DROUTE_METHOD, impl_isChildSelected, "isChildSelected",
260 "i,childIndex,i:b,,o"},
261 {DROUTE_METHOD, impl_selectAll, "selectAll", "b,,o"},
262 {DROUTE_METHOD, impl_clearSelection, "clearSelection", "b,,o"},
263 {DROUTE_METHOD, impl_deselectChild, "deselectChild", "i,childIndex,i:b,,o"},
264 {0, NULL, NULL, NULL}
267 static DRouteProperty properties[] = {
268 {impl_get_nSelectedChildren, impl_get_nSelectedChildren_str, NULL, NULL,
269 "nSelectedChildren"},
270 {NULL, NULL, NULL, NULL, NULL}
274 spi_initialize_selection (DRouteData * data)
276 droute_add_interface (data, "org.freedesktop.atspi.Selection",
278 (DRouteGetDatumFunction) get_selection_from_path,