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
14
impl_get_NSelectedChildren (DBusMessageIter *iter, void *user_data)
36
{
37
14
  AtkSelection *selection = (AtkSelection *) user_data;
38
14
  g_return_val_if_fail (ATK_IS_SELECTION (user_data), FALSE);
39
14
  return droute_return_v_int32 (iter,
40
                                atk_selection_get_selection_count (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
3
impl_GetSelectedChild (DBusConnection *bus, DBusMessage *message, void *user_data)
54
{
55
3
  AtkSelection *selection = (AtkSelection *) user_data;
56
  DBusMessage *reply;
57
  dbus_int32_t selectedChildIndex;
58
  AtkObject *atk_object;
59

            
60
3
  g_return_val_if_fail (ATK_IS_SELECTION (user_data),
61
                        droute_not_yet_handled_error (message));
62
3
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &selectedChildIndex,
63
                              DBUS_TYPE_INVALID))
64
    {
65
      return droute_invalid_arguments_error (message);
66
    }
67
3
  atk_object = atk_selection_ref_selection (selection, selectedChildIndex);
68
3
  reply = spi_object_return_reference (message, atk_object);
69
3
  if (atk_object)
70
3
    g_object_unref (atk_object);
71

            
72
3
  return reply;
73
}
74

            
75
static DBusMessage *
76
6
impl_SelectChild (DBusConnection *bus, DBusMessage *message, void *user_data)
77
{
78
6
  AtkSelection *selection = (AtkSelection *) user_data;
79
  dbus_int32_t childIndex;
80
  dbus_bool_t rv;
81
  DBusMessage *reply;
82

            
83
6
  g_return_val_if_fail (ATK_IS_SELECTION (user_data),
84
                        droute_not_yet_handled_error (message));
85
6
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &childIndex, DBUS_TYPE_INVALID))
86
    {
87
      return droute_invalid_arguments_error (message);
88
    }
89
6
  rv = atk_selection_add_selection (selection, childIndex);
90
6
  reply = dbus_message_new_method_return (message);
91
6
  if (reply)
92
    {
93
6
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
94
                                DBUS_TYPE_INVALID);
95
    }
96
6
  return reply;
97
}
98

            
99
static DBusMessage *
100
1
impl_DeselectSelectedChild (DBusConnection *bus, DBusMessage *message, void *user_data)
101
{
102
1
  AtkSelection *selection = (AtkSelection *) user_data;
103
  dbus_int32_t selectedChildIndex;
104
  dbus_bool_t rv;
105
  DBusMessage *reply;
106

            
107
1
  g_return_val_if_fail (ATK_IS_SELECTION (user_data),
108
                        droute_not_yet_handled_error (message));
109
1
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &selectedChildIndex,
110
                              DBUS_TYPE_INVALID))
111
    {
112
      return droute_invalid_arguments_error (message);
113
    }
114
1
  rv = atk_selection_remove_selection (selection, selectedChildIndex);
115
1
  reply = dbus_message_new_method_return (message);
116
1
  if (reply)
117
    {
118
1
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
119
                                DBUS_TYPE_INVALID);
120
    }
121
1
  return reply;
122
}
123

            
124
static DBusMessage *
125
5
impl_IsChildSelected (DBusConnection *bus, DBusMessage *message, void *user_data)
126
{
127
5
  AtkSelection *selection = (AtkSelection *) user_data;
128
  dbus_int32_t childIndex;
129
  dbus_bool_t rv;
130
  DBusMessage *reply;
131

            
132
5
  g_return_val_if_fail (ATK_IS_SELECTION (user_data),
133
                        droute_not_yet_handled_error (message));
134
5
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &childIndex, DBUS_TYPE_INVALID))
135
    {
136
      return droute_invalid_arguments_error (message);
137
    }
138
5
  rv = atk_selection_is_child_selected (selection, childIndex);
139
5
  reply = dbus_message_new_method_return (message);
140
5
  if (reply)
141
    {
142
5
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
143
                                DBUS_TYPE_INVALID);
144
    }
145
5
  return reply;
146
}
147

            
148
static DBusMessage *
149
1
impl_SelectAll (DBusConnection *bus, DBusMessage *message, void *user_data)
150
{
151
1
  AtkSelection *selection = (AtkSelection *) user_data;
152
  dbus_bool_t rv;
153
  DBusMessage *reply;
154

            
155
1
  g_return_val_if_fail (ATK_IS_SELECTION (user_data),
156
                        droute_not_yet_handled_error (message));
157
1
  rv = atk_selection_select_all_selection (selection);
158
1
  reply = dbus_message_new_method_return (message);
159
1
  if (reply)
160
    {
161
1
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
162
                                DBUS_TYPE_INVALID);
163
    }
164
1
  return reply;
165
}
166

            
167
static DBusMessage *
168
1
impl_ClearSelection (DBusConnection *bus, DBusMessage *message, void *user_data)
169
{
170
1
  AtkSelection *selection = (AtkSelection *) user_data;
171
  dbus_bool_t rv;
172
  DBusMessage *reply;
173

            
174
1
  g_return_val_if_fail (ATK_IS_SELECTION (user_data),
175
                        droute_not_yet_handled_error (message));
176
1
  rv = atk_selection_clear_selection (selection);
177
1
  reply = dbus_message_new_method_return (message);
178
1
  if (reply)
179
    {
180
1
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
181
                                DBUS_TYPE_INVALID);
182
    }
183
1
  return reply;
184
}
185

            
186
static DBusMessage *
187
1
impl_DeselectChild (DBusConnection *bus, DBusMessage *message, void *user_data)
188
{
189
1
  AtkSelection *selection = (AtkSelection *) user_data;
190
  dbus_int32_t selectedChildIndex;
191
1
  dbus_bool_t rv = FALSE;
192
  gint i, nselected;
193
  DBusMessage *reply;
194

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

            
223
static DRouteMethod methods[] = {
224
  { impl_GetSelectedChild, "GetSelectedChild" },
225
  { impl_SelectChild, "SelectChild" },
226
  { impl_DeselectSelectedChild, "DeselectSelectedChild" },
227
  { impl_IsChildSelected, "IsChildSelected" },
228
  { impl_SelectAll, "SelectAll" },
229
  { impl_ClearSelection, "ClearSelection" },
230
  { impl_DeselectChild, "DeselectChild" },
231
  { NULL, NULL }
232
};
233

            
234
static DRouteProperty properties[] = {
235
  { impl_get_NSelectedChildren, NULL, "NSelectedChildren" },
236
  { NULL, NULL, NULL }
237
};
238

            
239
void
240
161
spi_initialize_selection (DRoutePath *path)
241
{
242
161
  spi_atk_add_interface (path,
243
                         ATSPI_DBUS_INTERFACE_SELECTION,
244
                         spi_org_a11y_atspi_Selection,
245
                         methods, properties);
246
161
};