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"
32 impl_get_NSelectedChildren (DBusMessageIter * iter, void *user_data)
34 AtkSelection *selection = (AtkSelection *) user_data;
35 g_return_val_if_fail (ATK_IS_SELECTION (user_data), FALSE);
36 return droute_return_v_int32 (iter,
37 atk_selection_get_selection_count
42 impl_get_NSelectedChildren_str (void *datum)
44 g_return_val_if_fail (ATK_IS_SELECTION (user_data), FALSE);
45 return g_strdup_printf ("%d",
46 atk_selection_get_selection_count ((AtkSelection *)
51 impl_GetSelectedChild (DBusConnection * bus, DBusMessage * message,
54 AtkSelection *selection = (AtkSelection *) user_data;
56 dbus_int32_t selectedChildIndex;
57 AtkObject *atk_object;
59 g_return_val_if_fail (ATK_IS_SELECTION (user_data),
60 droute_not_yet_handled_error (message));
61 dbus_error_init (&error);
62 if (!dbus_message_get_args
63 (message, &error, DBUS_TYPE_INT32, &selectedChildIndex,
66 return droute_invalid_arguments_error (message);
68 atk_object = atk_selection_ref_selection (selection, selectedChildIndex);
69 return spi_object_return_reference (message, atk_object);
73 impl_SelectChild (DBusConnection * bus, DBusMessage * message,
76 AtkSelection *selection = (AtkSelection *) user_data;
78 dbus_int32_t childIndex;
82 g_return_val_if_fail (ATK_IS_SELECTION (user_data),
83 droute_not_yet_handled_error (message));
84 dbus_error_init (&error);
85 if (!dbus_message_get_args
86 (message, &error, DBUS_TYPE_INT32, &childIndex, DBUS_TYPE_INVALID))
88 return droute_invalid_arguments_error (message);
90 rv = atk_selection_add_selection (selection, childIndex);
91 reply = dbus_message_new_method_return (message);
94 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
101 impl_DeselectSelectedChild (DBusConnection * bus, DBusMessage * message,
104 AtkSelection *selection = (AtkSelection *) user_data;
106 dbus_int32_t selectedChildIndex;
110 g_return_val_if_fail (ATK_IS_SELECTION (user_data),
111 droute_not_yet_handled_error (message));
112 dbus_error_init (&error);
113 if (!dbus_message_get_args
114 (message, &error, DBUS_TYPE_INT32, &selectedChildIndex,
117 return droute_invalid_arguments_error (message);
119 rv = atk_selection_remove_selection (selection, selectedChildIndex);
120 reply = dbus_message_new_method_return (message);
123 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
130 impl_IsChildSelected (DBusConnection * bus, DBusMessage * message,
133 AtkSelection *selection = (AtkSelection *) user_data;
135 dbus_int32_t childIndex;
139 g_return_val_if_fail (ATK_IS_SELECTION (user_data),
140 droute_not_yet_handled_error (message));
141 dbus_error_init (&error);
142 if (!dbus_message_get_args
143 (message, &error, DBUS_TYPE_INT32, &childIndex, DBUS_TYPE_INVALID))
145 return droute_invalid_arguments_error (message);
147 rv = atk_selection_is_child_selected (selection, childIndex);
148 reply = dbus_message_new_method_return (message);
151 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
158 impl_SelectAll (DBusConnection * bus, DBusMessage * message, void *user_data)
160 AtkSelection *selection = (AtkSelection *) user_data;
164 g_return_val_if_fail (ATK_IS_SELECTION (user_data),
165 droute_not_yet_handled_error (message));
166 rv = atk_selection_select_all_selection (selection);
167 reply = dbus_message_new_method_return (message);
170 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
177 impl_ClearSelection (DBusConnection * bus, DBusMessage * message,
180 AtkSelection *selection = (AtkSelection *) user_data;
184 g_return_val_if_fail (ATK_IS_SELECTION (user_data),
185 droute_not_yet_handled_error (message));
186 rv = atk_selection_clear_selection (selection);
187 reply = dbus_message_new_method_return (message);
190 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
197 impl_DeselectChild (DBusConnection * bus, DBusMessage * message,
200 AtkSelection *selection = (AtkSelection *) user_data;
202 dbus_int32_t selectedChildIndex;
203 dbus_bool_t rv = FALSE;
207 g_return_val_if_fail (ATK_IS_SELECTION (user_data),
208 droute_not_yet_handled_error (message));
209 dbus_error_init (&error);
210 if (!dbus_message_get_args
211 (message, &error, DBUS_TYPE_INT32, &selectedChildIndex,
214 return droute_invalid_arguments_error (message);
216 nselected = atk_selection_get_selection_count (selection);
217 for (i = 0; i < nselected; ++i)
219 AtkObject *selected_obj = atk_selection_ref_selection (selection, i);
220 if (atk_object_get_index_in_parent (selected_obj) == selectedChildIndex)
222 g_object_unref (G_OBJECT (selected_obj));
223 rv = atk_selection_remove_selection (selection, i);
226 g_object_unref (G_OBJECT (selected_obj));
228 reply = dbus_message_new_method_return (message);
231 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
237 static DRouteMethod methods[] = {
238 {impl_GetSelectedChild, "GetSelectedChild"},
239 {impl_SelectChild, "SelectChild"},
240 {impl_DeselectSelectedChild, "DeselectSelectedChild"},
241 {impl_IsChildSelected, "IsChildSelected"},
242 {impl_SelectAll, "SelectAll"},
243 {impl_ClearSelection, "ClearSelection"},
244 {impl_DeselectChild, "DeselectChild"},
248 static DRouteProperty properties[] = {
249 {impl_get_NSelectedChildren, NULL, "NSelectedChildren"},
254 spi_initialize_selection (DRoutePath * path)
256 droute_path_add_interface (path,
257 SPI_DBUS_INTERFACE_SELECTION,
258 methods, properties);