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 Lesser General Public
11
 * License as published by the Free Software Foundation; either
12
 * version 2.1 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
 * Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public
20
 * License along with this library; if not, write to the
21
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22
 * Boston, MA 02110-1301, USA.
23
 */
24

            
25
#include "bridge.h"
26
#include <atk/atk.h>
27
#include <droute/droute.h>
28

            
29
#include "spi-dbus.h"
30

            
31
#include "introspection.h"
32
#include "object.h"
33

            
34
static dbus_bool_t
35
impl_get_Version (DBusMessageIter *iter, void *user_data)
36
{
37
  return droute_return_v_uint32 (iter, SPI_DBUS_SELECTION_VERSION);
38
}
39

            
40
static dbus_bool_t
41
14
impl_get_NSelectedChildren (DBusMessageIter *iter, void *user_data)
42
{
43
14
  AtkSelection *selection = (AtkSelection *) user_data;
44
14
  g_return_val_if_fail (ATK_IS_SELECTION (user_data), FALSE);
45
14
  return droute_return_v_int32 (iter,
46
14
                                atk_selection_get_selection_count (selection));
47
}
48

            
49
/*static char *
50
impl_get_NSelectedChildren_str (void *datum)
51
{
52
  g_return_val_if_fail (ATK_IS_SELECTION (user_data), FALSE);
53
  return g_strdup_printf ("%d",
54
                          atk_selection_get_selection_count ((AtkSelection *)
55
                                                             datum));
56
}*/
57

            
58
static DBusMessage *
59
3
impl_GetSelectedChild (DBusConnection *bus, DBusMessage *message, void *user_data)
60
{
61
3
  AtkSelection *selection = (AtkSelection *) user_data;
62
  DBusMessage *reply;
63
  dbus_int32_t selectedChildIndex;
64
  AtkObject *atk_object;
65

            
66
3
  g_return_val_if_fail (ATK_IS_SELECTION (user_data),
67
                        droute_not_yet_handled_error (message));
68
3
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &selectedChildIndex,
69
                              DBUS_TYPE_INVALID))
70
    {
71
      return droute_invalid_arguments_error (message);
72
    }
73
3
  atk_object = atk_selection_ref_selection (selection, selectedChildIndex);
74
3
  reply = spi_object_return_reference (message, atk_object);
75
3
  if (atk_object)
76
3
    g_object_unref (atk_object);
77

            
78
3
  return reply;
79
}
80

            
81
static DBusMessage *
82
6
impl_SelectChild (DBusConnection *bus, DBusMessage *message, void *user_data)
83
{
84
6
  AtkSelection *selection = (AtkSelection *) user_data;
85
  dbus_int32_t childIndex;
86
  dbus_bool_t rv;
87
  DBusMessage *reply;
88

            
89
6
  g_return_val_if_fail (ATK_IS_SELECTION (user_data),
90
                        droute_not_yet_handled_error (message));
91
6
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &childIndex, DBUS_TYPE_INVALID))
92
    {
93
      return droute_invalid_arguments_error (message);
94
    }
95
6
  rv = atk_selection_add_selection (selection, childIndex);
96
6
  reply = dbus_message_new_method_return (message);
97
6
  if (reply)
98
    {
99
6
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
100
                                DBUS_TYPE_INVALID);
101
    }
102
6
  return reply;
103
}
104

            
105
static DBusMessage *
106
1
impl_DeselectSelectedChild (DBusConnection *bus, DBusMessage *message, void *user_data)
107
{
108
1
  AtkSelection *selection = (AtkSelection *) user_data;
109
  dbus_int32_t selectedChildIndex;
110
  dbus_bool_t rv;
111
  DBusMessage *reply;
112

            
113
1
  g_return_val_if_fail (ATK_IS_SELECTION (user_data),
114
                        droute_not_yet_handled_error (message));
115
1
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &selectedChildIndex,
116
                              DBUS_TYPE_INVALID))
117
    {
118
      return droute_invalid_arguments_error (message);
119
    }
120
1
  rv = atk_selection_remove_selection (selection, selectedChildIndex);
121
1
  reply = dbus_message_new_method_return (message);
122
1
  if (reply)
123
    {
124
1
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
125
                                DBUS_TYPE_INVALID);
126
    }
127
1
  return reply;
128
}
129

            
130
static DBusMessage *
131
5
impl_IsChildSelected (DBusConnection *bus, DBusMessage *message, void *user_data)
132
{
133
5
  AtkSelection *selection = (AtkSelection *) user_data;
134
  dbus_int32_t childIndex;
135
  dbus_bool_t rv;
136
  DBusMessage *reply;
137

            
138
5
  g_return_val_if_fail (ATK_IS_SELECTION (user_data),
139
                        droute_not_yet_handled_error (message));
140
5
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &childIndex, DBUS_TYPE_INVALID))
141
    {
142
      return droute_invalid_arguments_error (message);
143
    }
144
5
  rv = atk_selection_is_child_selected (selection, childIndex);
145
5
  reply = dbus_message_new_method_return (message);
146
5
  if (reply)
147
    {
148
5
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
149
                                DBUS_TYPE_INVALID);
150
    }
151
5
  return reply;
152
}
153

            
154
static DBusMessage *
155
1
impl_SelectAll (DBusConnection *bus, DBusMessage *message, void *user_data)
156
{
157
1
  AtkSelection *selection = (AtkSelection *) user_data;
158
  dbus_bool_t rv;
159
  DBusMessage *reply;
160

            
161
1
  g_return_val_if_fail (ATK_IS_SELECTION (user_data),
162
                        droute_not_yet_handled_error (message));
163
1
  rv = atk_selection_select_all_selection (selection);
164
1
  reply = dbus_message_new_method_return (message);
165
1
  if (reply)
166
    {
167
1
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
168
                                DBUS_TYPE_INVALID);
169
    }
170
1
  return reply;
171
}
172

            
173
static DBusMessage *
174
1
impl_ClearSelection (DBusConnection *bus, DBusMessage *message, void *user_data)
175
{
176
1
  AtkSelection *selection = (AtkSelection *) user_data;
177
  dbus_bool_t rv;
178
  DBusMessage *reply;
179

            
180
1
  g_return_val_if_fail (ATK_IS_SELECTION (user_data),
181
                        droute_not_yet_handled_error (message));
182
1
  rv = atk_selection_clear_selection (selection);
183
1
  reply = dbus_message_new_method_return (message);
184
1
  if (reply)
185
    {
186
1
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
187
                                DBUS_TYPE_INVALID);
188
    }
189
1
  return reply;
190
}
191

            
192
static DBusMessage *
193
1
impl_DeselectChild (DBusConnection *bus, DBusMessage *message, void *user_data)
194
{
195
1
  AtkSelection *selection = (AtkSelection *) user_data;
196
  dbus_int32_t selectedChildIndex;
197
1
  dbus_bool_t rv = FALSE;
198
  gint i, nselected;
199
  DBusMessage *reply;
200

            
201
1
  g_return_val_if_fail (ATK_IS_SELECTION (user_data),
202
                        droute_not_yet_handled_error (message));
203
1
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &selectedChildIndex,
204
                              DBUS_TYPE_INVALID))
205
    {
206
      return droute_invalid_arguments_error (message);
207
    }
208
1
  nselected = atk_selection_get_selection_count (selection);
209
3
  for (i = 0; i < nselected; ++i)
210
    {
211
3
      AtkObject *selected_obj = atk_selection_ref_selection (selection, i);
212
3
      if (atk_object_get_index_in_parent (selected_obj) == selectedChildIndex)
213
        {
214
1
          g_object_unref (G_OBJECT (selected_obj));
215
1
          rv = atk_selection_remove_selection (selection, i);
216
1
          break;
217
        }
218
2
      g_object_unref (G_OBJECT (selected_obj));
219
    }
220
1
  reply = dbus_message_new_method_return (message);
221
1
  if (reply)
222
    {
223
1
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
224
                                DBUS_TYPE_INVALID);
225
    }
226
1
  return reply;
227
}
228

            
229
static DRouteMethod methods[] = {
230
  { impl_GetSelectedChild, "GetSelectedChild" },
231
  { impl_SelectChild, "SelectChild" },
232
  { impl_DeselectSelectedChild, "DeselectSelectedChild" },
233
  { impl_IsChildSelected, "IsChildSelected" },
234
  { impl_SelectAll, "SelectAll" },
235
  { impl_ClearSelection, "ClearSelection" },
236
  { impl_DeselectChild, "DeselectChild" },
237
  { NULL, NULL }
238
};
239

            
240
static DRouteProperty properties[] = {
241
  { impl_get_NSelectedChildren, NULL, "NSelectedChildren" },
242
  { impl_get_Version, NULL, "version" },
243
  { NULL, NULL, NULL }
244
};
245

            
246
void
247
161
spi_initialize_selection (DRoutePath *path)
248
{
249
161
  spi_atk_add_interface (path,
250
                         ATSPI_DBUS_INTERFACE_SELECTION,
251
                         spi_org_a11y_atspi_Selection,
252
                         methods, properties);
253
161
};