Remove X related lines
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / adaptors / selection-adaptor.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2008 Novell, Inc.
6  * Copyright 2001, 2002 Sun Microsystems Inc.,
7  * Copyright 2001, 2002 Ximian, Inc.
8  *
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.
13  *
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.
18  *
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.
23  */
24
25 #include <atk/atk.h>
26 #include <droute/droute.h>
27 #include "bridge.h"
28
29 #include "spi-dbus.h"
30 #include "object.h"
31 #include "introspection.h"
32
33 static dbus_bool_t
34 impl_get_NSelectedChildren (DBusMessageIter * iter, void *user_data)
35 {
36   AtkSelection *selection = (AtkSelection *) user_data;
37   g_return_val_if_fail (ATK_IS_SELECTION (user_data), FALSE);
38   return droute_return_v_int32 (iter,
39                                 atk_selection_get_selection_count
40                                 (selection));
41 }
42
43 /*static char *
44 impl_get_NSelectedChildren_str (void *datum)
45 {
46   g_return_val_if_fail (ATK_IS_SELECTION (user_data), FALSE);
47   return g_strdup_printf ("%d",
48                           atk_selection_get_selection_count ((AtkSelection *)
49                                                              datum));
50 }*/
51
52 static DBusMessage *
53 impl_GetSelectedChild (DBusConnection * bus, DBusMessage * message,
54                        void *user_data)
55 {
56   AtkSelection *selection = (AtkSelection *) user_data;
57   DBusMessage *reply;
58   dbus_int32_t selectedChildIndex;
59   AtkObject *atk_object;
60
61   g_return_val_if_fail (ATK_IS_SELECTION (user_data),
62                         droute_not_yet_handled_error (message));
63   if (!dbus_message_get_args
64       (message, NULL, DBUS_TYPE_INT32, &selectedChildIndex,
65        DBUS_TYPE_INVALID))
66     {
67       return droute_invalid_arguments_error (message);
68     }
69   atk_object = atk_selection_ref_selection (selection, selectedChildIndex);
70   reply = spi_object_return_reference (message, atk_object);
71   if (atk_object)
72     g_object_unref (atk_object);
73
74   return reply;
75 }
76
77 static DBusMessage *
78 impl_SelectChild (DBusConnection * bus, DBusMessage * message,
79                   void *user_data)
80 {
81   AtkSelection *selection = (AtkSelection *) user_data;
82   dbus_int32_t childIndex;
83   dbus_bool_t rv;
84   DBusMessage *reply;
85
86   g_return_val_if_fail (ATK_IS_SELECTION (user_data),
87                         droute_not_yet_handled_error (message));
88   if (!dbus_message_get_args
89       (message, NULL, DBUS_TYPE_INT32, &childIndex, DBUS_TYPE_INVALID))
90     {
91       return droute_invalid_arguments_error (message);
92     }
93   rv = atk_selection_add_selection (selection, childIndex);
94   reply = dbus_message_new_method_return (message);
95   if (reply)
96     {
97       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
98                                 DBUS_TYPE_INVALID);
99     }
100   return reply;
101 }
102
103 static DBusMessage *
104 impl_DeselectSelectedChild (DBusConnection * bus, DBusMessage * message,
105                             void *user_data)
106 {
107   AtkSelection *selection = (AtkSelection *) user_data;
108   dbus_int32_t selectedChildIndex;
109   dbus_bool_t rv;
110   DBusMessage *reply;
111
112   g_return_val_if_fail (ATK_IS_SELECTION (user_data),
113                         droute_not_yet_handled_error (message));
114   if (!dbus_message_get_args
115       (message, NULL, DBUS_TYPE_INT32, &selectedChildIndex,
116        DBUS_TYPE_INVALID))
117     {
118       return droute_invalid_arguments_error (message);
119     }
120   rv = atk_selection_remove_selection (selection, selectedChildIndex);
121   reply = dbus_message_new_method_return (message);
122   if (reply)
123     {
124       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
125                                 DBUS_TYPE_INVALID);
126     }
127   return reply;
128 }
129
130 static DBusMessage *
131 impl_IsChildSelected (DBusConnection * bus, DBusMessage * message,
132                       void *user_data)
133 {
134   AtkSelection *selection = (AtkSelection *) user_data;
135   dbus_int32_t childIndex;
136   dbus_bool_t rv;
137   DBusMessage *reply;
138
139   g_return_val_if_fail (ATK_IS_SELECTION (user_data),
140                         droute_not_yet_handled_error (message));
141   if (!dbus_message_get_args
142       (message, NULL, DBUS_TYPE_INT32, &childIndex, DBUS_TYPE_INVALID))
143     {
144       return droute_invalid_arguments_error (message);
145     }
146   rv = atk_selection_is_child_selected (selection, childIndex);
147   reply = dbus_message_new_method_return (message);
148   if (reply)
149     {
150       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
151                                 DBUS_TYPE_INVALID);
152     }
153   return reply;
154 }
155
156 static DBusMessage *
157 impl_SelectAll (DBusConnection * bus, DBusMessage * message, void *user_data)
158 {
159   AtkSelection *selection = (AtkSelection *) user_data;
160   dbus_bool_t rv;
161   DBusMessage *reply;
162
163   g_return_val_if_fail (ATK_IS_SELECTION (user_data),
164                         droute_not_yet_handled_error (message));
165   rv = atk_selection_select_all_selection (selection);
166   reply = dbus_message_new_method_return (message);
167   if (reply)
168     {
169       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
170                                 DBUS_TYPE_INVALID);
171     }
172   return reply;
173 }
174
175 static DBusMessage *
176 impl_ClearSelection (DBusConnection * bus, DBusMessage * message,
177                      void *user_data)
178 {
179   AtkSelection *selection = (AtkSelection *) user_data;
180   dbus_bool_t rv;
181   DBusMessage *reply;
182
183   g_return_val_if_fail (ATK_IS_SELECTION (user_data),
184                         droute_not_yet_handled_error (message));
185   rv = atk_selection_clear_selection (selection);
186   reply = dbus_message_new_method_return (message);
187   if (reply)
188     {
189       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
190                                 DBUS_TYPE_INVALID);
191     }
192   return reply;
193 }
194
195 static DBusMessage *
196 impl_DeselectChild (DBusConnection * bus, DBusMessage * message,
197                     void *user_data)
198 {
199   AtkSelection *selection = (AtkSelection *) user_data;
200   dbus_int32_t selectedChildIndex;
201   dbus_bool_t rv = FALSE;
202   gint i, nselected;
203   DBusMessage *reply;
204
205   g_return_val_if_fail (ATK_IS_SELECTION (user_data),
206                         droute_not_yet_handled_error (message));
207   if (!dbus_message_get_args
208       (message, NULL, DBUS_TYPE_INT32, &selectedChildIndex,
209        DBUS_TYPE_INVALID))
210     {
211       return droute_invalid_arguments_error (message);
212     }
213   nselected = atk_selection_get_selection_count (selection);
214   for (i = 0; i < nselected; ++i)
215     {
216       AtkObject *selected_obj = atk_selection_ref_selection (selection, i);
217       if (atk_object_get_index_in_parent (selected_obj) == selectedChildIndex)
218         {
219           g_object_unref (G_OBJECT (selected_obj));
220           rv = atk_selection_remove_selection (selection, i);
221           break;
222         }
223       g_object_unref (G_OBJECT (selected_obj));
224     }
225   reply = dbus_message_new_method_return (message);
226   if (reply)
227     {
228       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
229                                 DBUS_TYPE_INVALID);
230     }
231   return reply;
232 }
233
234 static DRouteMethod methods[] = {
235   {impl_GetSelectedChild, "GetSelectedChild"},
236   {impl_SelectChild, "SelectChild"},
237   {impl_DeselectSelectedChild, "DeselectSelectedChild"},
238   {impl_IsChildSelected, "IsChildSelected"},
239   {impl_SelectAll, "SelectAll"},
240   {impl_ClearSelection, "ClearSelection"},
241   {impl_DeselectChild, "DeselectChild"},
242   {NULL, NULL}
243 };
244
245 static DRouteProperty properties[] = {
246   {impl_get_NSelectedChildren, NULL, "NSelectedChildren"},
247   {NULL, NULL, NULL}
248 };
249
250 void
251 spi_initialize_selection (DRoutePath * path)
252 {
253   spi_atk_add_interface (path,
254                          ATSPI_DBUS_INTERFACE_SELECTION,
255                          spi_org_a11y_atspi_Selection,
256                          methods, properties);
257 };