packaging: exclude on non X11 configuration
[platform/core/uifw/at-spi2-core.git] / atspi / atspi-text.c
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  * Copyright 2010, 2011 Novell, 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 "atspi-private.h"
26 /**
27  * atspi_range_copy:
28  * @src: a pointer to the source #AtspiRange object that will be copied.
29  *
30  * Gets a copy of an #AtspiRange object.
31  *
32  * Returns: the #AtspiRange copy of an #AtspiRange object.
33  **/
34 AtspiRange *
35 atspi_range_copy (AtspiRange *src)
36 {
37   AtspiRange *dst = g_new (AtspiRange, 1);
38
39   dst->start_offset = src->start_offset;
40   dst->end_offset = src->end_offset;
41   return dst;
42 }
43
44 G_DEFINE_BOXED_TYPE (AtspiRange, atspi_range, atspi_range_copy, g_free)
45
46 static AtspiTextRange *
47 atspi_text_range_copy (AtspiTextRange *src)
48 {
49   AtspiTextRange *dst = g_new (AtspiTextRange, 1);
50
51   dst->content = g_strdup (src->content);
52   dst->start_offset = src->start_offset;
53   dst->end_offset = src->end_offset;
54   return dst;
55 }
56
57 static void
58 atspi_text_range_free (AtspiTextRange *range)
59 {
60   g_free (range->content);
61   g_free (range);
62 }
63
64 G_DEFINE_BOXED_TYPE (AtspiTextRange, atspi_text_range, atspi_text_range_copy,
65                      atspi_text_range_free)
66
67 /**
68  * atspi_text_get_character_count:
69  * @obj: a pointer to the #AtspiText object to query.
70  *
71  * Gets the character count of an #AccessibleText object.
72  *
73  * Returns: a #gint indicating the total number of
74  *              characters in the #AccessibleText object.
75  **/
76 gint
77 atspi_text_get_character_count (AtspiText *obj, GError **error)
78 {
79   dbus_int32_t retval = 0;
80
81   g_return_val_if_fail (obj != NULL, -1);
82
83   _atspi_dbus_get_property (obj, atspi_interface_text, "CharacterCount", error, "i", &retval);
84
85   return retval;
86 }
87
88 /**
89  * atspi_text_get_text:
90  * @obj: a pointer to the #AtspiText object to query.
91  * @start_offset: a #gint indicating the start of the desired text range.
92  * @end_offset: a #gint indicating the first character past the desired range.
93  *
94  * Gets a range of text from an #AtspiText object.  The number of bytes
95  *          in the returned string may exceed either end_offset or start_offset, since
96  *          UTF-8 is a variable-width encoding.
97  *
98  * Returns: a text string containing characters from @start_offset
99  *          to @end_offset-1, inclusive, encoded as UTF-8.
100  **/
101 gchar *
102 atspi_text_get_text (AtspiText *obj,
103                         gint start_offset,
104                         gint end_offset,
105                         GError **error)
106 {
107   gchar *retval = NULL;
108   dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
109
110   g_return_val_if_fail (obj != NULL, g_strdup (""));
111
112   _atspi_dbus_call (obj, atspi_interface_text, "GetText", error, "ii=>s", d_start_offset, d_end_offset, &retval);
113
114   if (!retval)
115     retval = g_strdup ("");
116
117   return retval;
118 }
119
120 /**
121  * atspi_text_get_caret_offset:
122  * @obj: a pointer to the #AtspiText object to query.
123  *
124  * Gets the current offset of the text caret in an #AtspiText object.
125  *
126  * Returns: a #gint indicating the current position of the text caret.
127  **/
128 gint
129 atspi_text_get_caret_offset (AtspiText *obj, GError **error)
130 {
131   dbus_int32_t retval = -1;
132
133   g_return_val_if_fail (obj != NULL, -1);
134
135   _atspi_dbus_get_property (obj, atspi_interface_text, "CaretOffset", error, "i", &retval);
136
137   return retval;
138 }
139
140 /**
141  * atspi_text_get_attributes:
142  * @obj: a pointer to the #AtspiText object to query.
143  * @offset: a #gint indicating the offset from which the attribute
144  *        search is based.
145  * @start_offset: (out): a #gint pointer indicating the start of the desired text
146  *                range.
147  * @end_offset: (out): a #gint pointer indicating the first character past the desired
148  *              range.
149  *
150  * Gets the attributes applied to a range of text from an #AtspiText
151  * object. The text attributes correspond to CSS attributes
152  * where possible.
153  * <em>DEPRECATED</em>
154  *
155  * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable
156  * describing the attributes at the given character offset.
157  **/
158 GHashTable *
159 atspi_text_get_attributes (AtspiText *obj,
160                            gint offset,
161                            gint *start_offset,
162                            gint *end_offset,
163                            GError **error)
164 {
165   dbus_int32_t d_offset = offset;
166   dbus_int32_t d_start_offset, d_end_offset;
167   DBusMessage *reply;
168   DBusMessageIter iter;
169   GHashTable *ret = NULL;
170
171   if (obj == NULL)
172    return NULL;
173
174   reply = _atspi_dbus_call_partial (obj, atspi_interface_text, "GetAttributes", error, "i", d_offset);
175   _ATSPI_DBUS_CHECK_SIG (reply, "a{ss}ii", error, ret)
176
177   dbus_message_iter_init (reply, &iter);
178   ret = _atspi_dbus_hash_from_iter (&iter);
179   dbus_message_iter_next (&iter);
180
181   dbus_message_iter_get_basic (&iter, &d_start_offset);
182   if (start_offset)
183     *start_offset = d_start_offset;
184   dbus_message_iter_next (&iter);
185   dbus_message_iter_get_basic (&iter, &d_end_offset);
186   if (end_offset)
187     *end_offset = d_end_offset;
188
189   dbus_message_unref (reply);
190   return ret;
191 }
192
193 /**
194  * atspi_text_get_attribute_run:
195  * @obj: a pointer to the #AtspiText object to query.
196  * @offset: a #gint indicating the offset from which the attribute
197  *        search is based.
198  * @include_defaults: a #bool that, when set as #FALSE, indicates the call
199  * should only return those attributes which are explicitly set on the current
200  * attribute run, omitting any attributes which are inherited from the 
201  * default values.
202  * @start_offset: (out): a #gint pointer indicating the start of the desired text
203  *                range.
204  * @end_offset: (out): a #gint pointer indicating the first character past the desired
205  *              range.
206  *
207  * Gets a set of attributes applied to a range of text from an #AtspiText object, optionally
208  * including its 'default' attributes.
209  *
210  * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable with attributes
211  *          defined at the indicated offset, optionally including the 'default' ones.
212  **/
213 GHashTable *
214 atspi_text_get_attribute_run (AtspiText *obj,
215                               gint offset,
216                               gboolean include_defaults,
217                               gint *start_offset,
218                               gint *end_offset,
219                               GError **error)
220 {
221   dbus_int32_t d_offset = offset;
222   dbus_int32_t d_start_offset, d_end_offset;
223   DBusMessage *reply;
224   DBusMessageIter iter;
225   GHashTable *ret = NULL;
226
227   if (obj == NULL)
228    return NULL;
229
230   reply = _atspi_dbus_call_partial (obj, atspi_interface_text,
231                                     "GetAttributeRun", error, "ib", d_offset,
232                                     include_defaults);
233   _ATSPI_DBUS_CHECK_SIG (reply, "a{ss}ii", error, ret)
234
235   dbus_message_iter_init (reply, &iter);
236   ret = _atspi_dbus_hash_from_iter (&iter);
237   dbus_message_iter_next (&iter);
238
239   dbus_message_iter_get_basic (&iter, &d_start_offset);
240   if (start_offset)
241     *start_offset = d_start_offset;
242   dbus_message_iter_next (&iter);
243   dbus_message_iter_get_basic (&iter, &d_end_offset);
244   if (end_offset)
245     *end_offset = d_end_offset;
246
247   dbus_message_unref (reply);
248   return ret;
249 }
250
251 /**
252  * atspi_text_get_attribute_value:
253  * @obj: a pointer to the #AtspiText object to query.
254  * @offset: The character offset at which to query the attribute.
255  * @attribute_name: The attribute to query.
256  *
257  * Gets the value of a named attribute at a given offset.
258  *
259  * Returns: the value of a given attribute at the given offset, or NULL if
260  * not present.
261  **/
262 gchar *
263 atspi_text_get_attribute_value (AtspiText *obj,
264                                 gint offset,
265                                 gchar *attribute_value,
266                                 GError **error)
267 {
268   gchar *retval = NULL;
269
270   g_return_val_if_fail (obj != NULL, NULL);
271
272   _atspi_dbus_call (obj, atspi_interface_text, "GetAttributeValue", error, "i=>s", offset, &retval);
273
274   return retval;
275 }
276
277 /**
278  * atspi_text_get_default_attributes:
279  * @obj: a pointer to the #AtspiText object to query.
280  *
281  * Gets the default attributes applied to an #AtspiText
282  * object. The text attributes correspond to CSS attributes 
283  * where possible. The combination of this attribute set and
284  * the attributes reported by #atspi_text_get_attributes
285  * describes the entire set of text attributes over a range.
286  *
287  * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable
288  *          containing the default attributes applied to a text object,
289  *          (exclusive of explicitly-set attributes), encoded as UTF-8.
290  **/
291 GHashTable *
292 atspi_text_get_default_attributes (AtspiText *obj, GError **error)
293 {
294   DBusMessage *reply;
295
296     g_return_val_if_fail (obj != NULL, NULL);
297
298   reply = _atspi_dbus_call_partial (obj, atspi_interface_text, "GetDefaultAttributes", error, "");
299   return _atspi_dbus_return_hash_from_message (reply);
300 }
301
302
303 /**
304  * atspi_text_set_caret_offset:
305  * @obj: a pointer to the #AtspiText object on which to operate.
306  * @new_offset: the offset to which the text caret is to be moved.
307  *
308  * Moves the text caret to a given position.
309  *
310  * Returns: #TRUE if successful, #FALSE otherwise.
311  **/
312 gboolean
313 atspi_text_set_caret_offset (AtspiText *obj,
314                                gint new_offset,
315                                GError **error)
316 {
317   dbus_int32_t d_new_offset = new_offset;
318   dbus_bool_t retval = FALSE;
319
320   g_return_val_if_fail (obj != NULL, FALSE);
321
322   _atspi_dbus_call (obj, atspi_interface_text, "SetCaretOffset", error, "i=>b", d_new_offset, &retval);
323
324   return retval;
325 }
326
327 /**
328  * atspi_text_get_text_before_offset:
329  * @obj: a pointer to the #AtspiText object on which to operate.
330  * @offset: a #gint indicating the offset from which the delimiter
331  *        search is based.
332  * @type: an #AtspiTextBoundaryType indicating whether the desired
333  *       text string is a word, sentence, line, or attribute run.
334  *
335  * Gets delimited text from an #AtspiText object which precedes a given
336  *          text offset.
337  *
338  * Returns: an #AtspiTextRange containing a UTF-8 string representing the
339  *          delimited text, both of whose delimiting boundaries are before the
340  *          current offset, or an empty string if no such text exists.
341  **/
342 AtspiTextRange *
343 atspi_text_get_text_before_offset (AtspiText *obj,
344                                     gint offset,
345                                     AtspiTextBoundaryType type,
346                                     GError **error)
347 {
348   dbus_int32_t d_offset = offset;
349   dbus_uint32_t d_type = type;
350   dbus_int32_t d_start_offset = -1, d_end_offset = -1;
351   AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
352
353   range->start_offset = range->end_offset = -1;
354   if (!obj)
355     return range;
356
357   _atspi_dbus_call (obj, atspi_interface_text, "GetTextBeforeOffset", error,
358                     "iu=>sii", d_offset, d_type, &range->content,
359                     &d_start_offset, &d_end_offset);
360
361   range->start_offset = d_start_offset;
362   range->end_offset = d_end_offset;
363   if (!range->content)
364     range->content = g_strdup ("");
365
366   return range;
367 }
368
369 /**
370  * atspi_text_get_text_at_offset:
371  * @obj: a pointer to the #AtspiText object on which to operate.
372  * @offset: a #gint indicating the offset from which the delimiter
373  *        search is based.
374  * @type: an #AtspiTextBoundaryType indicating whether the desired
375  *       text string is a word, sentence, line, or attribute run.
376  *
377  * Gets delimited text from an #AtspiText object which includes a given
378  *          text offset.
379  *
380  * Returns: an #AtspiTextRange containing a UTF-8 string representing the
381  *          delimited text, whose delimiting boundaries bracket the
382  *          current offset, or an empty string if no such text exists.
383  **/
384 AtspiTextRange *
385 atspi_text_get_text_at_offset (AtspiText *obj,
386                                     gint offset,
387                                     AtspiTextBoundaryType type,
388                                     GError **error)
389 {
390   dbus_int32_t d_offset = offset;
391   dbus_uint32_t d_type = type;
392   dbus_int32_t d_start_offset = -1, d_end_offset = -1;
393   AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
394
395   range->start_offset = range->end_offset = -1;
396   if (!obj)
397     return range;
398
399   _atspi_dbus_call (obj, atspi_interface_text, "GetTextAtOffset", error,
400                     "iu=>sii", d_offset, d_type, &range->content,
401                     &d_start_offset, &d_end_offset);
402
403   range->start_offset = d_start_offset;
404   range->end_offset = d_end_offset;
405   if (!range->content)
406     range->content = g_strdup ("");
407
408   return range;
409 }
410
411 /**
412  * atspi_text_get_text_after_offset:
413  * @obj: a pointer to the #AtspiText object on which to operate.
414  * @offset: a #gint indicating the offset from which the delimiter
415  *        search is based.
416  * @type: an #AtspiTextBoundaryType indicating whether the desired
417  *       text string is a word, sentence, line, or attribute run.
418  *
419  * Gets delimited text from an #AtspiText object which follows a given
420  *          text offset.
421  *
422  * Returns: an #AtspiTextRange containing a UTF-8 string representing the
423  *          delimited text, both of whose delimiting boundaries are after or
424  *          inclusive of the current offset, or an empty string if no such
425  *          text exists.
426  **/
427 AtspiTextRange *
428 atspi_text_get_text_after_offset (AtspiText *obj,
429                                     gint offset,
430                                     AtspiTextBoundaryType type,
431                                     GError **error)
432 {
433   dbus_int32_t d_offset = offset;
434   dbus_uint32_t d_type = type;
435   dbus_int32_t d_start_offset = -1, d_end_offset = -1;
436   AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
437
438   range->start_offset = range->end_offset = -1;
439   if (!obj)
440     return range;
441
442   _atspi_dbus_call (obj, atspi_interface_text, "GetTextAfterOffset", error,
443                     "iu=>sii", d_offset, d_type, &range->content,
444                     &d_start_offset, &d_end_offset);
445
446   range->start_offset = d_start_offset;
447   range->end_offset = d_end_offset;
448   if (!range->content)
449     range->content = g_strdup ("");
450
451   return range;
452 }
453
454 /**
455  * atspi_text_get_character_at_offset:
456  * @obj: a pointer to the #AtspiText object on which to operate.
457  * @offset: a #gint indicating the text offset where the desired
458  *          character is located.
459  *
460  * Gets the character at a given offset for an #AtspiText object.
461  *
462  * Returns: a #guint  representing the
463  *        UCS-4 unicode code point of the given character, or
464  *        0xFFFFFFFF if the character in question cannot be represented
465  *        in the UCS-4 encoding.
466  **/
467 guint
468 atspi_text_get_character_at_offset (AtspiText *obj,
469                                      gint offset,
470                                      GError **error)
471 {
472   dbus_int32_t d_offset = offset;
473   dbus_int32_t retval = -1;
474
475   g_return_val_if_fail (obj != NULL, -1);
476
477   _atspi_dbus_call (obj, atspi_interface_text, "GetCharacterAtOffset", error, "i=>i", d_offset, &retval);
478
479   return retval;
480 }
481
482 /**
483  * atspi_text_get_character_extents:
484  * @obj: a pointer to the #AtspiText object on which to operate.
485  * @offset: a #gint indicating the offset of the text character for
486  *        whom boundary information is requested.
487  * @type: an #AccessibleCoordType indicating the coordinate system to use
488  *        for the returned values.
489  *
490  * Gets a bounding box containing the glyph representing
491  *        the character at a particular text offset.
492  *
493  * Returns: An #AtspiRect specifying the position and size of the character.
494  *
495  **/
496 AtspiRect *
497 atspi_text_get_character_extents (AtspiText *obj,
498                                     gint offset,
499                                     AtspiCoordType type,
500                                     GError **error)
501 {
502   dbus_int32_t d_offset = offset;
503   dbus_uint32_t d_type = type;
504   dbus_int32_t d_x, d_y, d_width, d_height;
505   AtspiRect ret;
506
507   ret.x = ret.y = ret.width = ret.height = -1;
508
509   if (obj == NULL)
510     return atspi_rect_copy (&ret);
511
512   _atspi_dbus_call (obj, atspi_interface_text, "GetCharacterExtents", error, "iu=>iiii", d_offset, d_type, &d_x, &d_y, &d_width, &d_height);
513
514   ret.x = d_x;
515   ret.y = d_y;
516   ret.width = d_width;
517   ret.height = d_height;
518   return atspi_rect_copy (&ret);
519 }
520
521 /**
522  * atspi_text_get_offset_at_point:
523  * @obj: a pointer to the #AtspiText object on which to operate.
524  * @x: the x coordinate of the point to be queried.
525  * @y: the y coordinate of the point to be queried.
526  * @type: an #AtspiCoordType indicating the coordinate system in which
527  *       the values should be returned.
528  *
529  * Gets the character offset into the text at a given point.
530  *
531  * Returns: the offset (as a #gint) at the point (@x, @y)
532  *       in the specified coordinate system.
533  *
534  **/
535 gint
536 atspi_text_get_offset_at_point (AtspiText *obj,
537                                  gint x,
538                                  gint y,
539                                  AtspiCoordType type,
540                                  GError **error)
541 {
542   dbus_int32_t d_x = x, d_y = y;
543   dbus_uint32_t d_type = type;
544   dbus_int32_t retval = -1;
545
546   g_return_val_if_fail (obj != NULL, -1);
547
548   _atspi_dbus_call (obj, atspi_interface_text, "GetOffsetAtPoint", error, "iiu=>i", d_x, d_y, d_type, &retval);
549
550   return retval;
551 }
552
553 /**
554  * atspi_text_get_range_extents:
555  * @obj: a pointer to the #AtspiText object on which to operate.
556  * @start_offset: a #gint indicating the offset of the first text character for
557  *        whom boundary information is requested.
558  * @end_offset: a #gint indicating the offset of the text character
559  *        after the last character for whom boundary information is requested.
560  * @type: an #AtspiCoordType indicating the coordinate system to use
561  *        for the returned values.
562  *
563  * Gets the bounding box for text within a range in an  #AtspiText object.
564  *
565  * Returns: An #AtspiRect giving the position and size of the specified range
566  *          of text.
567  *
568  **/
569 AtspiRect *
570 atspi_text_get_range_extents (AtspiText *obj,
571                                 gint start_offset,
572                                 gint end_offset,
573                                 AtspiCoordType type,
574                                 GError **error)
575 {
576   dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
577   dbus_uint32_t d_type = type;
578   dbus_int32_t d_x, d_y, d_width, d_height;
579   AtspiRect ret;
580
581   ret.x = ret.y = ret.width = ret.height = -1;
582
583   if (obj == NULL)
584     return atspi_rect_copy (&ret);
585
586   _atspi_dbus_call (obj, atspi_interface_text, "GetRangeExtents", error, "iiu=>iiii", d_start_offset, d_end_offset, d_type, &d_x, &d_y, &d_width, &d_height);
587
588   ret.x = d_x;
589   ret.y = d_y;
590   ret.width = d_width;
591   ret.height = d_height;
592   return atspi_rect_copy (&ret);
593 }
594
595 /**
596  * atspi_text_get_bounded_ranges:
597  * @obj: a pointer to the #AtspiText object on which to operate.
598  * @x: the 'starting' x coordinate of the bounding box.
599  * @y: the 'starting' y coordinate of the bounding box.
600  * @width: the x extent of the bounding box.
601  * @height: the y extent of the bounding box.
602  * @type: an #AccessibleCoordType indicating the coordinate system to use
603  *        for the returned values.
604  * @clipTypeX: an #AtspiTextClipType indicating how to treat characters that
605  *        intersect the bounding box's x extents.
606  * @clipTypeY: an #AtspiTextClipType indicating how to treat characters that
607  *        intersect the bounding box's y extents.
608  *
609  * Gets the ranges of text from an #AtspiText object which lie within the
610  *          bounds defined by (@x, @y) and (@x+@width, @y+@height).
611  *
612  * Returns: (transfer full) (element-type AtspiTextRange*): a null-terminated list of
613  *          pointers to #AtspiTextRange structs detailing the bounded text.
614  **/
615 GArray *
616 atspi_text_get_bounded_ranges (AtspiText *obj,
617                                  gint x,
618                                  gint y,
619                                  gint width,
620                                  gint height,
621                                  AtspiCoordType type,
622                                  AtspiTextClipType clipTypeX,
623                                  AtspiTextClipType clipTypeY,
624                                  GError **error)
625 {
626   dbus_int32_t d_x = x, d_y = y, d_width = width, d_height = height;
627   dbus_uint32_t d_type = type;
628   dbus_uint32_t d_clipTypeX = clipTypeX, d_clipTypeY = clipTypeY;
629   GArray *range_seq;
630
631   g_return_val_if_fail (obj != NULL, NULL);
632
633   _atspi_dbus_call (obj, atspi_interface_text, "GetBoundedRanges", error, "iiiiuuu=>a(iisv)", d_x, d_y, d_width, d_height, d_type, d_clipTypeX, d_clipTypeY, &range_seq);
634
635   return range_seq;
636 }
637
638 /**
639  * atspi_text_get_n_selections:
640  * @obj: a pointer to the #AtspiText object on which to operate.
641  *
642  * Gets the number of active non-contiguous selections for an
643  *          #AtspiText object.
644  *
645  * Returns: a #gint indicating the current
646  *          number of non-contiguous text selections active
647  *          within an #AtspiText object.
648  **/
649 gint
650 atspi_text_get_n_selections (AtspiText *obj, GError **error)
651 {
652   dbus_int32_t retval = 0;
653
654   g_return_val_if_fail (obj != NULL, -1);
655
656   _atspi_dbus_call (obj, atspi_interface_text, "GetNSelections", error, "=>i", &retval);
657
658   return retval;
659 }
660
661 /**
662  * atspi_text_get_selection:
663  * @obj: a pointer to the #AtspiText object on which to operate.
664  * @selection_num: a #gint indicating which selection to query.
665  *
666  * Gets the bounds of the @selection_num-th active text selection for an
667  *         #AtspiText object.
668  **/
669 AtspiRange *
670 atspi_text_get_selection (AtspiText *obj,
671                              gint selection_num,
672                              GError **error)
673 {
674   dbus_int32_t d_selection_num = selection_num;
675   dbus_int32_t d_start_offset, d_end_offset;
676   AtspiRange *ret = g_new (AtspiRange, 1);
677
678   ret->start_offset = ret->end_offset = -1;
679
680   if (!obj)
681     return ret;
682
683   _atspi_dbus_call (obj, atspi_interface_text, "GetSelection", error, "i=>ii", d_selection_num, &d_start_offset, &d_end_offset);
684
685   ret->start_offset = d_start_offset;
686   ret->end_offset = d_end_offset;
687   return ret;
688 }
689
690 /**
691  * atspi_text_add_selection:
692  * @obj: a pointer to the #AtspiText object on which to operate.
693  * @start_offset: the starting offset of the desired new selection.
694  * @end_offset: the offset of the first character after the new selection.
695  *
696  * Selects some text (adds a text selection) in an #AtspiText object.
697  *
698  * Returns: #TRUE if successful, #FALSE otherwise.
699  **/
700 gboolean
701 atspi_text_add_selection (AtspiText *obj,
702                              gint start_offset, gint end_offset,
703                              GError **error)
704 {
705   dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
706   dbus_bool_t retval = FALSE;
707
708   _atspi_dbus_call (obj, atspi_interface_text, "AddSelection", error, "ii=>b", d_start_offset, d_end_offset, &retval);
709
710   return retval;
711 }
712
713 /**
714  * atspi_text_remove_selection:
715  * @obj: a pointer to the #AtspiText object on which to operate.
716  * @selection_num: a #gint indicating which text selection to remove.
717  *
718  * De-selects a text selection.
719  *
720  * Returns: #TRUE if successful, #FALSE otherwise.
721  **/
722 gboolean
723 atspi_text_remove_selection (AtspiText *obj,
724                                 gint selection_num,
725                                 GError **error)
726 {
727   dbus_int32_t d_selection_num = selection_num;
728   dbus_bool_t retval = FALSE;
729
730   g_return_val_if_fail (obj != NULL, FALSE);
731
732   _atspi_dbus_call (obj, atspi_interface_text, "RemoveSelection", error, "i=>b", d_selection_num, &retval);
733
734   return retval;
735 }
736
737 /**
738  * atspi_text_set_selection:
739  * @obj: a pointer to the #AtspiText object on which to operate.
740  * @selection_num: a zero-offset index indicating which text selection to modify.
741  * @start_offset: a #gint indicating the new starting offset for the selection.
742  * @end_offset: a #gint indicating the desired new offset of the first character
743  *             after the selection.
744  *
745  * Changes the bounds of an existing #AtspiText text selection.
746  *
747  * Returns: #TRUE if successful, #FALSE otherwise.
748  **/
749 gboolean
750 atspi_text_set_selection (AtspiText *obj,
751                              gint selection_num,
752                              gint start_offset,
753                              gint end_offset,
754                              GError **error)
755 {
756   dbus_int32_t d_selection_num = selection_num, d_start_offset = start_offset, d_end_offset = end_offset;
757   dbus_bool_t retval = FALSE;
758
759   g_return_val_if_fail (obj != NULL, FALSE);
760
761   _atspi_dbus_call (obj, atspi_interface_text, "SetSelection", error, "iii=>b", d_selection_num, d_start_offset, d_end_offset, &retval);
762
763   return retval;
764 }
765
766 static void
767 atspi_text_base_init (AtspiText *klass)
768 {
769 }
770
771 GType
772 atspi_text_get_type (void)
773 {
774   static GType type = 0;
775
776   if (!type) {
777     static const GTypeInfo tinfo =
778     {
779       sizeof (AtspiText),
780       (GBaseInitFunc) atspi_text_base_init,
781       (GBaseFinalizeFunc) NULL,
782     };
783
784     type = g_type_register_static (G_TYPE_INTERFACE, "AtspiText", &tinfo, 0);
785
786   }
787   return type;
788 }