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
#define ATK_DISABLE_DEPRECATION_WARNINGS
26
#include "bridge.h"
27
#include <atk/atk.h>
28
#include <droute/droute.h>
29
#include <string.h>
30

            
31
#include "spi-dbus.h"
32

            
33
#include "introspection.h"
34
#include "object.h"
35

            
36
static DBusMessage *
37
1
impl_Contains (DBusConnection *bus, DBusMessage *message, void *user_data)
38
{
39
1
  AtkComponent *component = (AtkComponent *) user_data;
40
  dbus_int32_t x, y;
41
  dbus_uint32_t coord_type;
42
  dbus_bool_t retval;
43
  DBusMessage *reply;
44

            
45
1
  g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
46
                        droute_not_yet_handled_error (message));
47

            
48
1
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y,
49
                              DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
50
    {
51
      return droute_invalid_arguments_error (message);
52
    }
53
1
  retval =
54
1
      atk_component_contains (component, x, y, (AtkCoordType) coord_type);
55
1
  reply = dbus_message_new_method_return (message);
56
1
  if (reply)
57
    {
58
1
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &retval,
59
                                DBUS_TYPE_INVALID);
60
    }
61
1
  return reply;
62
}
63

            
64
static DBusMessage *
65
1
impl_GetAccessibleAtPoint (DBusConnection *bus, DBusMessage *message, void *user_data)
66
{
67
1
  AtkComponent *component = (AtkComponent *) user_data;
68
  dbus_int32_t x, y;
69
  dbus_uint32_t coord_type;
70
  DBusMessage *reply;
71
  AtkObject *child;
72

            
73
1
  g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
74
                        droute_not_yet_handled_error (message));
75

            
76
1
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y,
77
                              DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
78
    {
79
      return droute_invalid_arguments_error (message);
80
    }
81
  child =
82
1
      atk_component_ref_accessible_at_point (component, x, y,
83
                                             (AtkCoordType) coord_type);
84
1
  reply = spi_object_return_reference (message, child);
85
1
  if (child)
86
1
    g_object_unref (child);
87

            
88
1
  return reply;
89
}
90

            
91
static DBusMessage *
92
3
impl_GetExtents (DBusConnection *bus, DBusMessage *message, void *user_data)
93
{
94
3
  AtkComponent *component = (AtkComponent *) user_data;
95
  dbus_uint32_t coord_type;
96
  gint ix, iy, iwidth, iheight;
97

            
98
3
  g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
99
                        droute_not_yet_handled_error (message));
100

            
101
3
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
102
    {
103
      return droute_invalid_arguments_error (message);
104
    }
105
3
  atk_component_get_extents (component, &ix, &iy, &iwidth, &iheight,
106
                             (AtkCoordType) coord_type);
107
3
  return spi_dbus_return_rect (message, ix, iy, iwidth, iheight);
108
}
109

            
110
static DBusMessage *
111
impl_GetPosition (DBusConnection *bus, DBusMessage *message, void *user_data)
112
{
113
  AtkComponent *component = (AtkComponent *) user_data;
114
  dbus_uint32_t coord_type;
115
  gint ix = 0, iy = 0;
116
  dbus_int32_t x, y;
117
  DBusMessage *reply;
118

            
119
  g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
120
                        droute_not_yet_handled_error (message));
121

            
122
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
123
    {
124
      return droute_invalid_arguments_error (message);
125
    }
126
  atk_component_get_position (component, &ix, &iy, (AtkCoordType) coord_type);
127
  x = ix;
128
  y = iy;
129
  reply = dbus_message_new_method_return (message);
130
  if (reply)
131
    {
132
      dbus_message_append_args (reply, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32,
133
                                &y, DBUS_TYPE_INVALID);
134
    }
135
  return reply;
136
}
137

            
138
static DBusMessage *
139
impl_GetSize (DBusConnection *bus, DBusMessage *message, void *user_data)
140
{
141
  AtkComponent *component = (AtkComponent *) user_data;
142
  gint iwidth = 0, iheight = 0;
143
  dbus_int32_t width, height;
144
  DBusMessage *reply;
145

            
146
  g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
147
                        droute_not_yet_handled_error (message));
148

            
149
  atk_component_get_size (component, &iwidth, &iheight);
150
  width = iwidth;
151
  height = iheight;
152
  reply = dbus_message_new_method_return (message);
153
  if (reply)
154
    {
155
      dbus_message_append_args (reply, DBUS_TYPE_INT32, &width,
156
                                DBUS_TYPE_INT32, &height, DBUS_TYPE_INVALID);
157
    }
158
  return reply;
159
}
160

            
161
static DBusMessage *
162
1
impl_GetLayer (DBusConnection *bus, DBusMessage *message, void *user_data)
163
{
164
1
  AtkComponent *component = (AtkComponent *) user_data;
165
  AtkLayer atklayer;
166
  dbus_uint32_t rv;
167
  DBusMessage *reply;
168

            
169
1
  g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
170
                        droute_not_yet_handled_error (message));
171

            
172
1
  atklayer = atk_component_get_layer (component);
173

            
174
1
  switch (atklayer)
175
    {
176
    case ATK_LAYER_BACKGROUND:
177
      rv = ATSPI_LAYER_BACKGROUND;
178
      break;
179
    case ATK_LAYER_CANVAS:
180
      rv = ATSPI_LAYER_CANVAS;
181
      break;
182
1
    case ATK_LAYER_WIDGET:
183
1
      rv = ATSPI_LAYER_WIDGET;
184
1
      break;
185
    case ATK_LAYER_MDI:
186
      rv = ATSPI_LAYER_MDI;
187
      break;
188
    case ATK_LAYER_POPUP:
189
      rv = ATSPI_LAYER_POPUP;
190
      break;
191
    case ATK_LAYER_OVERLAY:
192
      rv = ATSPI_LAYER_OVERLAY;
193
      break;
194
    case ATK_LAYER_WINDOW:
195
      rv = ATSPI_LAYER_WINDOW;
196
      break;
197
    default:
198
      rv = ATSPI_LAYER_INVALID;
199
      break;
200
    }
201
1
  reply = dbus_message_new_method_return (message);
202
1
  if (reply)
203
    {
204
1
      dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv,
205
                                DBUS_TYPE_INVALID);
206
    }
207
1
  return reply;
208
}
209

            
210
static DBusMessage *
211
1
impl_GetMDIZOrder (DBusConnection *bus, DBusMessage *message, void *user_data)
212
{
213
1
  AtkComponent *component = (AtkComponent *) user_data;
214
  dbus_int16_t rv;
215
  DBusMessage *reply;
216

            
217
1
  g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
218
                        droute_not_yet_handled_error (message));
219

            
220
1
  rv = atk_component_get_mdi_zorder (component);
221
1
  reply = dbus_message_new_method_return (message);
222
1
  if (reply)
223
    {
224
1
      dbus_message_append_args (reply, DBUS_TYPE_INT16, &rv,
225
                                DBUS_TYPE_INVALID);
226
    }
227
1
  return reply;
228
}
229

            
230
static DBusMessage *
231
1
impl_GrabFocus (DBusConnection *bus, DBusMessage *message, void *user_data)
232
{
233
1
  AtkComponent *component = (AtkComponent *) user_data;
234
  dbus_bool_t rv;
235
  DBusMessage *reply;
236

            
237
1
  g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
238
                        droute_not_yet_handled_error (message));
239

            
240
1
  rv = atk_component_grab_focus (component);
241
1
  reply = dbus_message_new_method_return (message);
242
1
  if (reply)
243
    {
244
1
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
245
                                DBUS_TYPE_INVALID);
246
    }
247
1
  return reply;
248
}
249

            
250
static DBusMessage *
251
1
impl_GetAlpha (DBusConnection *bus, DBusMessage *message, void *user_data)
252
{
253
1
  AtkComponent *component = (AtkComponent *) user_data;
254
  double rv;
255
  DBusMessage *reply;
256

            
257
1
  g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
258
                        droute_not_yet_handled_error (message));
259

            
260
1
  rv = atk_component_get_alpha (component);
261
1
  reply = dbus_message_new_method_return (message);
262
1
  if (reply)
263
    {
264
1
      dbus_message_append_args (reply, DBUS_TYPE_DOUBLE, &rv,
265
                                DBUS_TYPE_INVALID);
266
    }
267
1
  return reply;
268
}
269

            
270
static DBusMessage *
271
1
impl_SetExtents (DBusConnection *bus, DBusMessage *message, void *user_data)
272
{
273
1
  AtkComponent *component = (AtkComponent *) user_data;
274
  DBusMessageIter iter, iter_struct;
275
  dbus_uint32_t coord_type;
276
  dbus_int32_t x, y, width, height;
277
  dbus_bool_t ret;
278
  DBusMessage *reply;
279

            
280
1
  g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
281
                        droute_not_yet_handled_error (message));
282

            
283
1
  if (strcmp (dbus_message_get_signature (message), "(iiii)u") != 0)
284
    {
285
      return droute_invalid_arguments_error (message);
286
    }
287

            
288
1
  dbus_message_iter_init (message, &iter);
289
1
  dbus_message_iter_recurse (&iter, &iter_struct);
290
1
  dbus_message_iter_get_basic (&iter_struct, &x);
291
1
  dbus_message_iter_next (&iter_struct);
292
1
  dbus_message_iter_get_basic (&iter_struct, &y);
293
1
  dbus_message_iter_next (&iter_struct);
294
1
  dbus_message_iter_get_basic (&iter_struct, &width);
295
1
  dbus_message_iter_next (&iter_struct);
296
1
  dbus_message_iter_get_basic (&iter_struct, &height);
297
1
  dbus_message_iter_next (&iter_struct);
298
1
  dbus_message_iter_next (&iter);
299
1
  dbus_message_iter_get_basic (&iter, &coord_type);
300

            
301
1
  ret = atk_component_set_extents (component, x, y, width, height, coord_type);
302

            
303
1
  reply = dbus_message_new_method_return (message);
304
1
  if (reply)
305
    {
306
1
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &ret,
307
                                DBUS_TYPE_INVALID);
308
    }
309

            
310
1
  return reply;
311
}
312

            
313
static DBusMessage *
314
impl_SetPosition (DBusConnection *bus, DBusMessage *message, void *user_data)
315
{
316
  AtkComponent *component = (AtkComponent *) user_data;
317
  dbus_uint32_t coord_type;
318
  dbus_int32_t x, y;
319
  dbus_bool_t ret;
320
  DBusMessage *reply;
321

            
322
  g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
323
                        droute_not_yet_handled_error (message));
324

            
325
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y,
326
                              DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
327
    {
328
      return droute_invalid_arguments_error (message);
329
    }
330

            
331
  ret = atk_component_set_position (component, x, y, coord_type);
332

            
333
  reply = dbus_message_new_method_return (message);
334
  if (reply)
335
    {
336
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &ret,
337
                                DBUS_TYPE_INVALID);
338
    }
339

            
340
  return reply;
341
}
342

            
343
static dbus_bool_t
344
impl_get_ScreenExtents (DBusMessageIter *iter, void *user_data)
345
{
346
  AtkComponent *component = (AtkComponent *) user_data;
347
  DBusMessageIter iter_variant, iter_struct;
348
  gint ix = -1, iy = -1, iwidth = -1, iheight = -1;
349
  dbus_uint32_t x, y, width, height;
350

            
351
  g_return_val_if_fail (ATK_IS_COMPONENT (user_data), FALSE);
352

            
353
  atk_component_get_extents (component, &ix, &iy, &iwidth, &iheight, ATK_XY_SCREEN);
354
  x = ix;
355
  y = iy;
356
  width = iwidth;
357
  height = iheight;
358
  dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "(uuuu)",
359
                                    &iter_variant);
360
  dbus_message_iter_open_container (&iter_variant, DBUS_TYPE_STRUCT, NULL,
361
                                    &iter_struct);
362
  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &x);
363
  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &y);
364
  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &width);
365
  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &height);
366
  dbus_message_iter_close_container (&iter_variant, &iter_struct);
367
  dbus_message_iter_close_container (iter, &iter_variant);
368
  return TRUE;
369
}
370

            
371
static DBusMessage *
372
impl_SetSize (DBusConnection *bus, DBusMessage *message, void *user_data)
373
{
374
  AtkComponent *component = (AtkComponent *) user_data;
375
  dbus_int32_t width, height;
376
  dbus_bool_t ret;
377
  DBusMessage *reply;
378

            
379
  g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
380
                        droute_not_yet_handled_error (message));
381

            
382
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &width, DBUS_TYPE_INT32, &height,
383
                              DBUS_TYPE_INVALID))
384
    {
385
      return droute_invalid_arguments_error (message);
386
    }
387

            
388
  ret = atk_component_set_size (component, width, height);
389

            
390
  reply = dbus_message_new_method_return (message);
391
  if (reply)
392
    {
393
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &ret,
394
                                DBUS_TYPE_INVALID);
395
    }
396

            
397
  return reply;
398
}
399

            
400
static DBusMessage *
401
impl_ScrollTo (DBusConnection *bus,
402
               DBusMessage *message,
403
               void *user_data)
404
{
405
  AtkComponent *component = (AtkComponent *) user_data;
406
  dbus_uint32_t type;
407
  dbus_bool_t ret;
408
  DBusMessage *reply = NULL;
409

            
410
  g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
411
                        droute_not_yet_handled_error (message));
412

            
413
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_UINT32, &type, DBUS_TYPE_INVALID))
414
    {
415
      return droute_invalid_arguments_error (message);
416
    }
417

            
418
  ret = atk_component_scroll_to (component, type);
419

            
420
  reply = dbus_message_new_method_return (message);
421
  if (reply)
422
    {
423
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &ret,
424
                                DBUS_TYPE_INVALID);
425
    }
426
  return reply;
427
}
428

            
429
static DBusMessage *
430
impl_ScrollToPoint (DBusConnection *bus,
431
                    DBusMessage *message,
432
                    void *user_data)
433
{
434
  AtkComponent *component = (AtkComponent *) user_data;
435
  dbus_uint32_t type;
436
  dbus_int32_t x, y;
437
  dbus_bool_t ret;
438
  DBusMessage *reply = NULL;
439

            
440
  g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
441
                        droute_not_yet_handled_error (message));
442

            
443
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_UINT32, &type,
444
                              DBUS_TYPE_INT32, &x,
445
                              DBUS_TYPE_INT32, &y,
446
                              DBUS_TYPE_INVALID))
447
    {
448
      return droute_invalid_arguments_error (message);
449
    }
450

            
451
  ret = atk_component_scroll_to_point (component, type, x, y);
452

            
453
  reply = dbus_message_new_method_return (message);
454
  if (reply)
455
    {
456
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &ret,
457
                                DBUS_TYPE_INVALID);
458
    }
459
  return reply;
460
}
461

            
462
static DRouteMethod methods[] = {
463
  { impl_Contains, "Contains" },
464
  { impl_GetAccessibleAtPoint, "GetAccessibleAtPoint" },
465
  { impl_GetExtents, "GetExtents" },
466
  { impl_GetPosition, "GetPosition" },
467
  { impl_GetSize, "GetSize" },
468
  { impl_GetLayer, "GetLayer" },
469
  { impl_GetMDIZOrder, "GetMDIZOrder" },
470
  { impl_GrabFocus, "GrabFocus" },
471
  { impl_GetAlpha, "GetAlpha" },
472
  { impl_SetExtents, "SetExtents" },
473
  { impl_SetPosition, "SetPosition" },
474
  { impl_SetSize, "SetSize" },
475
  { impl_ScrollTo, "ScrollTo" },
476
  { impl_ScrollToPoint, "ScrollToPoint" },
477
  { NULL, NULL }
478
};
479

            
480
static DRouteProperty properties[] = {
481
  { impl_get_ScreenExtents, NULL, "ScreenExtents" },
482
  { NULL, NULL, NULL }
483
};
484
void
485
161
spi_initialize_component (DRoutePath *path)
486
{
487
161
  spi_atk_add_interface (path,
488
                         ATSPI_DBUS_INTERFACE_COMPONENT, spi_org_a11y_atspi_Component, methods, properties);
489
161
};