1
/*
2
 * AT-SPI - Assistive Technology Service Provider Interface
3
 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4
 *
5
 * Copyright 2001, 2002 Sun Microsystems Inc.,
6
 * Copyright 2001, 2002 Ximian, Inc.
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with this library; if not, write to the
20
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
 * Boston, MA 02110-1301, USA.
22
 */
23

            
24
/*
25
 *
26
 * AtspiComponent function implementations
27
 *
28
 */
29

            
30
#include "atspi-accessible-private.h"
31
#include "atspi-private.h"
32

            
33
/**
34
 * AtspiComponent
35
 *
36
 * An interface implemented by objects which have onscreen visual
37
 * representations.
38
 *
39
 * The Component interface is implemented by objects which occupy on-screen
40
 * space, e.g. objects which have onscreen visual representations. The methods
41
 * in Component allow clients to identify where the objects lie in the onscreen
42
 * coordinate system, their relative size, stacking order, and position. It
43
 * also provides a mechanism whereby keyboard focus may be transferred to
44
 * specific user interface elements programmatically.  This is a 2D API.
45
 * Coordinates of 3D objects are projected into the 2-dimensional screen view
46
 * for purposes of this interface.
47
 */
48

            
49
void
50
atspi_rect_free (AtspiRect *rect)
51
{
52
  g_free (rect);
53
}
54

            
55
AtspiRect *
56
6
atspi_rect_copy (AtspiRect *src)
57
{
58
6
  AtspiRect *dst = g_new (AtspiRect, 1);
59
6
  dst->x = src->x;
60
6
  dst->y = src->y;
61
6
  dst->height = src->height;
62
6
  dst->width = src->width;
63
6
  return dst;
64
}
65

            
66
G_DEFINE_BOXED_TYPE (AtspiRect, atspi_rect, atspi_rect_copy, atspi_rect_free)
67

            
68
AtspiPoint *
69
2
atspi_point_copy (AtspiPoint *src)
70
{
71
2
  AtspiPoint *dst = g_new (AtspiPoint, 1);
72
2
  dst->x = src->x;
73
2
  dst->y = src->y;
74
2
  return dst;
75
}
76

            
77
G_DEFINE_BOXED_TYPE (AtspiPoint, atspi_point, atspi_point_copy, g_free)
78

            
79
/**
80
 * atspi_component_contains:
81
 * @obj: a pointer to the #AtspiComponent to query.
82
 * @x: a #gint specifying the x coordinate in question.
83
 * @y: a #gint specifying the y coordinate in question.
84
 * @ctype: the desired coordinate system of the point (@x, @y)
85
 *         (e.g. CSPI_COORD_TYPE_WINDOW, CSPI_COORD_TYPE_SCREEN).
86
 *
87
 * Queries whether a given #AtspiComponent contains a particular point.
88
 *
89
 * Returns: #TRUE if the specified component contains the point (@x, @y),
90
 *          #FALSE otherwise.
91
 **/
92
gboolean
93
1
atspi_component_contains (AtspiComponent *obj,
94
                          gint x,
95
                          gint y,
96
                          AtspiCoordType ctype,
97
                          GError **error)
98
{
99
1
  dbus_bool_t retval = FALSE;
100
1
  dbus_int32_t d_x = x, d_y = y;
101
1
  dbus_uint32_t d_ctype = ctype;
102

            
103
1
  g_return_val_if_fail (obj != NULL, FALSE);
104

            
105
1
  _atspi_dbus_call (obj, atspi_interface_component, "Contains", error, "iiu=>b", d_x, d_y, d_ctype, &retval);
106

            
107
1
  return retval;
108
}
109

            
110
/**
111
 * atspi_component_get_accessible_at_point:
112
 * @obj: a pointer to the #AtspiComponent to query.
113
 * @x: a #gint specifying the x coordinate of the point in question.
114
 * @y: a #gint specifying the y coordinate of the point in question.
115
 * @ctype: the coordinate system of the point (@x, @y)
116
 *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
117
 *
118
 * Gets the accessible child at a given coordinate within an #AtspiComponent.
119
 *
120
 * Returns: (nullable) (transfer full): a pointer to an
121
 *          #AtspiAccessible child of the specified component which
122
 *          contains the point (@x, @y), or NULL if no child contains
123
 *          the point.
124
 **/
125
AtspiAccessible *
126
1
atspi_component_get_accessible_at_point (AtspiComponent *obj,
127
                                         gint x,
128
                                         gint y,
129
                                         AtspiCoordType ctype,
130
                                         GError **error)
131
{
132
1
  dbus_int32_t d_x = x, d_y = y;
133
1
  dbus_uint32_t d_ctype = ctype;
134
  DBusMessage *reply;
135

            
136
1
  g_return_val_if_fail (obj != NULL, FALSE);
137

            
138
1
  reply = _atspi_dbus_call_partial (obj, atspi_interface_component, "GetAccessibleAtPoint", error, "iiu", d_x, d_y, d_ctype);
139

            
140
1
  return _atspi_dbus_return_accessible_from_message (reply);
141
}
142

            
143
/**
144
 * atspi_component_get_extents:
145
 * @obj: a pointer to the #AtspiComponent to query.
146
 * @ctype: the desired coordinate system into which to return the results,
147
 *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
148
 *
149
 * Gets the bounding box of the specified #AtspiComponent.
150
 * The returned values are meaningful only if the Component has both
151
 * STATE_VISIBLE and STATE_SHOWING.
152
 *
153
 * Returns: An #AtspiRect giving the accessible's extents.
154
 **/
155
AtspiRect *
156
3
atspi_component_get_extents (AtspiComponent *obj,
157
                             AtspiCoordType ctype,
158
                             GError **error)
159
{
160
3
  dbus_uint32_t d_ctype = ctype;
161
  AtspiRect bbox;
162

            
163
3
  bbox.x = bbox.y = bbox.width = bbox.height = -1;
164
3
  g_return_val_if_fail (obj != NULL, atspi_rect_copy (&bbox));
165

            
166
3
  _atspi_dbus_call (obj, atspi_interface_component, "GetExtents", error, "u=>(iiii)", d_ctype, &bbox);
167
3
  return atspi_rect_copy (&bbox);
168
}
169

            
170
/**
171
 * atspi_component_get_position:
172
 * @obj: a pointer to the #AtspiComponent to query.
173
 * @ctype: the desired coordinate system into which to return the results,
174
 *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
175
 *
176
 * Gets the minimum x and y coordinates of the specified #AtspiComponent.
177
 * The returned values are meaningful only if the Component has both
178
 * STATE_VISIBLE and STATE_SHOWING.
179
 *
180
 * returns: An #AtspiPoint giving the @obj's position.
181
 **/
182
AtspiPoint *
183
atspi_component_get_position (AtspiComponent *obj,
184
                              AtspiCoordType ctype,
185
                              GError **error)
186
{
187
  dbus_int32_t d_x = -1, d_y = -1;
188
  dbus_uint32_t d_ctype = ctype;
189
  AtspiPoint ret;
190

            
191
  ret.x = ret.y = -1;
192

            
193
  if (!obj)
194
    return atspi_point_copy (&ret);
195

            
196
  _atspi_dbus_call (obj, atspi_interface_component, "GetPosition", error, "u=>ii", d_ctype, &d_x, &d_y);
197

            
198
  ret.x = d_x;
199
  ret.y = d_y;
200
  return atspi_point_copy (&ret);
201
}
202

            
203
/**
204
 * atspi_component_get_size:
205
 * @obj: a pointer to the #AtspiComponent to query.
206
 *
207
 * Gets the size of the specified #AtspiComponent.
208
 * The returned values are meaningful only if the Component has both
209
 * STATE_VISIBLE and STATE_SHOWING.
210
 *
211
 * returns: An #AtspiPoint giving the @obj's size.
212
 **/
213
AtspiPoint *
214
atspi_component_get_size (AtspiComponent *obj, GError **error)
215
{
216
  dbus_int32_t d_w = -1, d_h = -1;
217
  AtspiPoint ret;
218

            
219
  ret.x = ret.y = -1;
220
  if (!obj)
221
    return atspi_point_copy (&ret);
222

            
223
  _atspi_dbus_call (obj, atspi_interface_component, "GetSize", error, "=>ii", &d_w, &d_h);
224
  ret.x = d_w;
225
  ret.y = d_h;
226
  return atspi_point_copy (&ret);
227
}
228

            
229
/**
230
 * atspi_component_get_layer:
231
 * @obj: a pointer to the #AtspiComponent to query.
232
 *
233
 * Queries which layer the component is painted into, to help determine its
234
 *      visibility in terms of stacking order.
235
 *
236
 * Returns: the #AtspiComponentLayer into which this component is painted.
237
 **/
238
AtspiComponentLayer
239
1
atspi_component_get_layer (AtspiComponent *obj, GError **error)
240
{
241
1
  dbus_uint32_t zlayer = -1;
242

            
243
1
  _atspi_dbus_call (obj, atspi_interface_component, "GetLayer", error, "=>u", &zlayer);
244

            
245
1
  return zlayer;
246
}
247

            
248
/**
249
 * atspi_component_get_mdi_z_order:
250
 * @obj: a pointer to the #AtspiComponent to query.
251
 *
252
 * Queries the z stacking order of a component which is in the MDI or window
253
 *       layer. (Bigger z-order numbers mean nearer the top)
254
 *
255
 * Returns: a #gshort indicating the stacking order of the component
256
 *       in the MDI layer, or -1 if the component is not in the MDI layer.
257
 **/
258
gshort
259
1
atspi_component_get_mdi_z_order (AtspiComponent *obj, GError **error)
260
{
261
1
  dbus_uint16_t retval = -1;
262

            
263
1
  _atspi_dbus_call (obj, atspi_interface_component, "GetMDIZOrder", error, "=>n", &retval);
264

            
265
1
  return retval;
266
}
267

            
268
/**
269
 * atspi_component_grab_focus:
270
 * @obj: a pointer to the #AtspiComponent on which to operate.
271
 *
272
 * Attempts to set the keyboard input focus to the specified
273
 *         #AtspiComponent.
274
 *
275
 * Returns: #TRUE if successful, #FALSE otherwise.
276
 *
277
 **/
278
gboolean
279
1
atspi_component_grab_focus (AtspiComponent *obj, GError **error)
280
{
281
1
  dbus_bool_t retval = FALSE;
282

            
283
1
  _atspi_dbus_call (obj, atspi_interface_component, "GrabFocus", error, "=>b", &retval);
284

            
285
1
  return retval;
286
}
287

            
288
/**
289
 * atspi_component_get_alpha:
290
 * @obj: The #AtspiComponent to be queried.
291
 *
292
 * Gets the opacity/alpha value of a component, if alpha blending is in use.
293
 *
294
 * Returns: the opacity value of a component, as a #gdouble between 0.0 and 1.0.
295
 **/
296
gdouble
297
1
atspi_component_get_alpha (AtspiComponent *obj, GError **error)
298
{
299
1
  double retval = 1;
300

            
301
1
  _atspi_dbus_call (obj, atspi_interface_component, "GetAlpha", error, "=>d", &retval);
302

            
303
1
  return retval;
304
}
305

            
306
/**
307
 * atspi_component_set_extents:
308
 * @obj: a pointer to the #AtspiComponent to move.
309
 * @x: the new horizontal position to which the component should be moved.
310
 * @y: the new vertical position to which the component should be moved.
311
 * @width: the width to which the component should be resized.
312
 * @height: the height to which the component should be resized.
313
 * @ctype: the coordinate system in which the position is specified.
314
 *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
315
 *
316
 * Moves and resizes the specified component.
317
 *
318
 * Returns: #TRUE if successful; #FALSE otherwise.
319
 **/
320
gboolean
321
1
atspi_component_set_extents (AtspiComponent *obj,
322
                             gint x,
323
                             gint y,
324
                             gint width,
325
                             gint height,
326
                             AtspiCoordType ctype,
327
                             GError **error)
328
{
329
1
  dbus_int32_t d_x = x, d_y = y, d_width = width, d_height = height;
330
1
  dbus_uint32_t d_ctype = ctype;
331
  DBusMessageIter iter, iter_struct;
332
  DBusMessage *message, *reply;
333
1
  dbus_bool_t retval = FALSE;
334
1
  AtspiAccessible *aobj = ATSPI_ACCESSIBLE (obj);
335

            
336
1
  g_return_val_if_fail (obj != NULL, FALSE);
337

            
338
1
  if (!aobj->parent.app || !aobj->parent.app->bus_name)
339
    {
340
      g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_APPLICATION_GONE,
341
                           _ ("The application no longer exists"));
342
      return FALSE;
343
    }
344

            
345
1
  message = dbus_message_new_method_call (aobj->parent.app->bus_name,
346
1
                                          aobj->parent.path,
347
                                          atspi_interface_component,
348
                                          "SetExtents");
349
1
  if (!message)
350
    return FALSE;
351

            
352
1
  dbus_message_iter_init_append (message, &iter);
353
1
  if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &iter_struct))
354
    {
355
      dbus_message_unref (message);
356
      return FALSE;
357
    }
358
1
  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &d_x);
359
1
  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &d_y);
360
1
  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &d_width);
361
1
  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &d_height);
362
1
  dbus_message_iter_close_container (&iter, &iter_struct);
363
1
  dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &d_ctype);
364

            
365
1
  reply = _atspi_dbus_send_with_reply_and_block (message, error);
366
1
  dbus_message_get_args (reply, NULL, DBUS_TYPE_BOOLEAN, &retval,
367
                         DBUS_TYPE_INVALID);
368
1
  dbus_message_unref (reply);
369
1
  return retval;
370
}
371

            
372
/**
373
 * atspi_component_set_position:
374
 * @obj: a pointer to the #AtspiComponent to move.
375
 * @x: the new horizontal position to which the component should be moved.
376
 * @y: the new vertical position to which the component should be moved.
377
 * @ctype: the coordinate system in which the position is specified.
378
 *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
379
 *
380
 * Moves the component to the specified position.
381
 *
382
 * Returns: #TRUE if successful; #FALSE otherwise.
383
 **/
384
gboolean
385
atspi_component_set_position (AtspiComponent *obj,
386
                              gint x,
387
                              gint y,
388
                              AtspiCoordType ctype,
389
                              GError **error)
390
{
391
  dbus_int32_t d_x = x, d_y = y;
392
  dbus_uint32_t d_ctype = ctype;
393
  dbus_bool_t ret = FALSE;
394

            
395
  g_return_val_if_fail (obj != NULL, FALSE);
396

            
397
  _atspi_dbus_call (obj, atspi_interface_component, "SetPosition", error,
398
                    "iiu=>b", d_x, d_y, d_ctype, &ret);
399

            
400
  return ret;
401
}
402

            
403
/**
404
 * atspi_component_set_size:
405
 * @obj: a pointer to the #AtspiComponent to query.
406
 * @width: the width to which the component should be resized.
407
 * @height: the height to which the component should be resized.
408
 *
409
 * Resizes the specified component to the given pixel dimensions.
410
 *
411
 * Returns: #TRUE if successful; #FALSE otherwise.
412
 **/
413
gboolean
414
atspi_component_set_size (AtspiComponent *obj,
415
                          gint width,
416
                          gint height,
417
                          GError **error)
418
{
419
  dbus_int32_t d_width = width, d_height = height;
420
  dbus_bool_t ret = FALSE;
421

            
422
  g_return_val_if_fail (obj != NULL, FALSE);
423

            
424
  _atspi_dbus_call (obj, atspi_interface_component, "SetSize", error, "ii=>b",
425
                    d_width, d_height, &ret);
426

            
427
  return ret;
428
}
429

            
430
/**
431
 * atspi_component_scroll_to:
432
 * @obj: a pointer to the #AtspiComponent object on which to operate.
433
 * @type: a #AtspiScrollType indicating where the object should be placed on the
434
 *        screen.
435
 *
436
 * Scrolls whatever container of the #AtspiComponent object so it becomes
437
 * visible on the screen.
438
 *
439
 * Returns: #TRUE if successful, #FALSE otherwise.
440
 **/
441
gboolean
442
atspi_component_scroll_to (AtspiComponent *obj,
443
                           AtspiScrollType type,
444
                           GError **error)
445
{
446
  dbus_bool_t retval = FALSE;
447

            
448
  g_return_val_if_fail (obj != NULL, FALSE);
449

            
450
  _atspi_dbus_call (obj, atspi_interface_component,
451
                    "ScrollTo", error, "u=>b", type, &retval);
452

            
453
  return retval;
454
}
455

            
456
/**
457
 * atspi_component_scroll_to_point:
458
 * @obj: a pointer to the #AtspiComponent object on which to operate.
459
 * @coords: a #AtspiCoordType indicating whether the coordinates are relative to
460
 *          the screen, to the window, or to the parent object.
461
 * @x: the x coordinate of the point to reach
462
 * @y: the y coordinate of the point to reach
463
 * @error: return location for a #GError
464
 *
465
 * Scrolls whatever container of the #AtspiComponent object so it becomes
466
 * visible on the screen at a given position.
467
 *
468
 * Returns: #TRUE if successful, #FALSE otherwise.
469
 **/
470
gboolean
471
atspi_component_scroll_to_point (AtspiComponent *obj,
472
                                 AtspiCoordType coords,
473
                                 gint x,
474
                                 gint y,
475
                                 GError **error)
476
{
477
  dbus_bool_t retval = FALSE;
478

            
479
  g_return_val_if_fail (obj != NULL, FALSE);
480

            
481
  _atspi_dbus_call (obj, atspi_interface_component,
482
                    "ScrollToPoint", error, "uii=>b", coords, x, y, &retval);
483

            
484
  return retval;
485
}
486

            
487
static void
488
4
atspi_component_base_init (AtspiComponent *klass)
489
{
490
4
}
491

            
492
GType
493
11
atspi_component_get_type (void)
494
{
495
  static GType type = 0;
496

            
497
11
  if (!type)
498
    {
499
      static const GTypeInfo tinfo = {
500
        sizeof (AtspiComponent),
501
        (GBaseInitFunc) atspi_component_base_init,
502
        (GBaseFinalizeFunc) NULL,
503
      };
504

            
505
2
      type = g_type_register_static (G_TYPE_INTERFACE, "AtspiComponent", &tinfo, 0);
506
    }
507
11
  return type;
508
}