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.
26 #include <droute/droute.h>
28 #include "common/spi-dbus.h"
30 #include "introspection.h"
33 impl_get_NSelectedChildren (DBusMessageIter * iter, void *user_data)
35 AtkSelection *selection = (AtkSelection *) user_data;
36 g_return_val_if_fail (ATK_IS_SELECTION (user_data), FALSE);
37 return droute_return_v_int32 (iter,
38 atk_selection_get_selection_count
43 impl_get_NSelectedChildren_str (void *datum)
45 g_return_val_if_fail (ATK_IS_SELECTION (user_data), FALSE);
46 return g_strdup_printf ("%d",
47 atk_selection_get_selection_count ((AtkSelection *)
52 impl_GetSelectedChild (DBusConnection * bus, DBusMessage * message,
55 AtkSelection *selection = (AtkSelection *) user_data;
58 dbus_int32_t selectedChildIndex;
59 AtkObject *atk_object;
61 g_return_val_if_fail (ATK_IS_SELECTION (user_data),
62 droute_not_yet_handled_error (message));
63 dbus_error_init (&error);
64 if (!dbus_message_get_args
65 (message, &error, DBUS_TYPE_INT32, &selectedChildIndex,
68 return droute_invalid_arguments_error (message);
70 atk_object = atk_selection_ref_selection (selection, selectedChildIndex);
71 reply = spi_object_return_reference (message, atk_object);
72 g_object_unref (atk_object);
78 impl_SelectChild (DBusConnection * bus, DBusMessage * message,
81 AtkSelection *selection = (AtkSelection *) user_data;
83 dbus_int32_t childIndex;
87 g_return_val_if_fail (ATK_IS_SELECTION (user_data),
88 droute_not_yet_handled_error (message));
89 dbus_error_init (&error);
90 if (!dbus_message_get_args
91 (message, &error, DBUS_TYPE_INT32, &childIndex, DBUS_TYPE_INVALID))
93 return droute_invalid_arguments_error (message);
95 rv = atk_selection_add_selection (selection, childIndex);
96 reply = dbus_message_new_method_return (message);
99 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
106 impl_DeselectSelectedChild (DBusConnection * bus, DBusMessage * message,
109 AtkSelection *selection = (AtkSelection *) user_data;
111 dbus_int32_t selectedChildIndex;
115 g_return_val_if_fail (ATK_IS_SELECTION (user_data),
116 droute_not_yet_handled_error (message));
117 dbus_error_init (&error);
118 if (!dbus_message_get_args
119 (message, &error, DBUS_TYPE_INT32, &selectedChildIndex,
122 return droute_invalid_arguments_error (message);
124 rv = atk_selection_remove_selection (selection, selectedChildIndex);
125 reply = dbus_message_new_method_return (message);
128 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
135 impl_IsChildSelected (DBusConnection * bus, DBusMessage * message,
138 AtkSelection *selection = (AtkSelection *) user_data;
140 dbus_int32_t childIndex;
144 g_return_val_if_fail (ATK_IS_SELECTION (user_data),
145 droute_not_yet_handled_error (message));
146 dbus_error_init (&error);
147 if (!dbus_message_get_args
148 (message, &error, DBUS_TYPE_INT32, &childIndex, DBUS_TYPE_INVALID))
150 return droute_invalid_arguments_error (message);
152 rv = atk_selection_is_child_selected (selection, childIndex);
153 reply = dbus_message_new_method_return (message);
156 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
163 impl_SelectAll (DBusConnection * bus, DBusMessage * message, void *user_data)
165 AtkSelection *selection = (AtkSelection *) user_data;
169 g_return_val_if_fail (ATK_IS_SELECTION (user_data),
170 droute_not_yet_handled_error (message));
171 rv = atk_selection_select_all_selection (selection);
172 reply = dbus_message_new_method_return (message);
175 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
182 impl_ClearSelection (DBusConnection * bus, DBusMessage * message,
185 AtkSelection *selection = (AtkSelection *) user_data;
189 g_return_val_if_fail (ATK_IS_SELECTION (user_data),
190 droute_not_yet_handled_error (message));
191 rv = atk_selection_clear_selection (selection);
192 reply = dbus_message_new_method_return (message);
195 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
202 impl_DeselectChild (DBusConnection * bus, DBusMessage * message,
205 AtkSelection *selection = (AtkSelection *) user_data;
207 dbus_int32_t selectedChildIndex;
208 dbus_bool_t rv = FALSE;
212 g_return_val_if_fail (ATK_IS_SELECTION (user_data),
213 droute_not_yet_handled_error (message));
214 dbus_error_init (&error);
215 if (!dbus_message_get_args
216 (message, &error, DBUS_TYPE_INT32, &selectedChildIndex,
219 return droute_invalid_arguments_error (message);
221 nselected = atk_selection_get_selection_count (selection);
222 for (i = 0; i < nselected; ++i)
224 AtkObject *selected_obj = atk_selection_ref_selection (selection, i);
225 if (atk_object_get_index_in_parent (selected_obj) == selectedChildIndex)
227 g_object_unref (G_OBJECT (selected_obj));
228 rv = atk_selection_remove_selection (selection, i);
231 g_object_unref (G_OBJECT (selected_obj));
233 reply = dbus_message_new_method_return (message);
236 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
242 static DRouteMethod methods[] = {
243 {impl_GetSelectedChild, "GetSelectedChild"},
244 {impl_SelectChild, "SelectChild"},
245 {impl_DeselectSelectedChild, "DeselectSelectedChild"},
246 {impl_IsChildSelected, "IsChildSelected"},
247 {impl_SelectAll, "SelectAll"},
248 {impl_ClearSelection, "ClearSelection"},
249 {impl_DeselectChild, "DeselectChild"},
253 static DRouteProperty properties[] = {
254 {impl_get_NSelectedChildren, NULL, "NSelectedChildren"},
259 spi_initialize_selection (DRoutePath * path)
261 droute_path_add_interface (path,
262 SPI_DBUS_INTERFACE_SELECTION,
263 spi_org_a11y_atspi_Selection,
264 methods, properties);