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