Fix most compiler warnings and various miscellaneous problems
[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", d_start_offset, d_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   DBusMessage *reply;
165   DBusMessageIter iter;
166   GHashTable *ret = NULL;
167
168   if (obj == NULL)
169    return NULL;
170
171   reply = _atspi_dbus_call_partial (obj, atspi_interface_text, "GetAttributes", error, "i", d_offset);
172   _ATSPI_DBUS_CHECK_SIG (reply, "a{ss}ii", error, ret)
173
174   dbus_message_iter_init (reply, &iter);
175   ret = _atspi_dbus_hash_from_iter (&iter);
176   dbus_message_iter_next (&iter);
177
178   dbus_message_iter_get_basic (&iter, &d_start_offset);
179   if (start_offset)
180     *start_offset = d_start_offset;
181   dbus_message_iter_next (&iter);
182   dbus_message_iter_get_basic (&iter, &d_end_offset);
183   if (end_offset)
184     *end_offset = d_start_offset;
185
186   dbus_message_unref (reply);
187   return ret;
188 }
189
190 /**
191  * atspi_text_get_attribute_run:
192  * @obj: a pointer to the #AtspiText object to query.
193  * @offset: an integer indicating the offset from which the attribute
194  *        search is based.
195  * @include_defaults: a #bool if False, the call should only return those 
196  *                 attributes which are explicitly set on the current attribute 
197  *                 run, omitting any attributes which are inherited from the 
198  *                 default values.
199  * @start_offset: (out): a #gint indicating the start of the desired text
200  *                range.
201  * @end_offset: (out): a #gint indicating the first character past the desired
202  *              range.
203  *
204  * Returns: (element-type gchar* gchar*) (transfer full): the AttributeSet
205  *          defined at offset, optionally including the 'default' attributes.
206  **/
207 GHashTable *
208 atspi_text_get_attribute_run (AtspiText *obj,
209                               gint offset,
210                               gboolean include_defaults,
211                               gint *start_offset,
212                               gint *end_offset,
213                               GError **error)
214 {
215   dbus_int32_t d_offset = offset;
216   dbus_int32_t d_start_offset, d_end_offset;
217   DBusMessage *reply;
218   DBusMessageIter iter;
219   GHashTable *ret = NULL;
220
221   if (obj == NULL)
222    return NULL;
223
224   reply = _atspi_dbus_call_partial (obj, atspi_interface_text,
225                                     "GetAttributeRun", error, "ib", d_offset,
226                                     include_defaults);
227   _ATSPI_DBUS_CHECK_SIG (reply, "a{ss}ii", error, ret)
228
229   dbus_message_iter_init (reply, &iter);
230   ret = _atspi_dbus_hash_from_iter (&iter);
231   dbus_message_iter_next (&iter);
232
233   dbus_message_iter_get_basic (&iter, &d_start_offset);
234   if (start_offset)
235     *start_offset = d_start_offset;
236   dbus_message_iter_next (&iter);
237   dbus_message_iter_get_basic (&iter, &d_end_offset);
238   if (end_offset)
239     *end_offset = d_end_offset;
240
241   dbus_message_unref (reply);
242   return ret;
243 }
244
245 /**
246  * atspi_text_get_attribute_value:
247  * @obj: a pointer to the #AtspiText object to query.
248  * @offset: The character offset at which to query the attribute.
249  * @attribute_name: The attribute to query.
250  *
251  * Returns: the value of a given attribute at the given offset, or NULL if
252  *          not present.
253  **/
254 gchar *
255 atspi_text_get_attribute_value (AtspiText *obj,
256                                 gint offset,
257                                 gchar *attribute_value,
258                                 GError **error)
259 {
260   gchar *retval = NULL;
261
262   g_return_val_if_fail (obj != NULL, NULL);
263
264   _atspi_dbus_call (obj, atspi_interface_text, "GetAttributeValue", error, "i=>s", offset, &retval);
265
266   return retval;
267 }
268
269 /**
270  * atspi_text_get_default_attributes:
271  * @obj: a pointer to the #AtspiText object to query.
272  *
273  * Get the default attributes applied to an #AtspiText
274  *          object.
275  *          The text attributes correspond to CSS attributes where possible,
276  *          keys and values are delimited from one another via ":", and
277  *          the delimiter between key/value pairs is ";". Thus
278  *          "font-size:10;foreground-color:0,0,0" would be a valid
279  *          return string.  The combination of this attribute set and
280  *          the attributes reported by #atspi_text_getAttributes
281  *          describes the entire set of text attributes over a range.
282  *
283  * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable
284  *          containing the default attributes applied to a text object,
285  *          (exclusive of explicitly-set attributes), encoded as UTF-8.
286  **/
287 GHashTable *
288 atspi_text_get_default_attributes (AtspiText *obj, GError **error)
289 {
290   DBusMessage *reply;
291
292     g_return_val_if_fail (obj != NULL, NULL);
293
294   reply = _atspi_dbus_call_partial (obj, atspi_interface_text, "GetDefaultAttributes", error, "");
295   return _atspi_dbus_return_hash_from_message (reply);
296 }
297
298
299 /**
300  * atspi_text_set_caret_offset:
301  * @obj: a pointer to the #AtspiText object on which to operate.
302  * @new_offset: the offset to which the text caret is to be moved.
303  *
304  * Set the text caret position for an #AtspiText object.
305  *
306  * Returns: #TRUE if successful, #FALSE otherwise.
307  **/
308 gboolean
309 atspi_text_set_caret_offset (AtspiText *obj,
310                                gint new_offset,
311                                GError **error)
312 {
313   dbus_int32_t d_new_offset = new_offset;
314   dbus_bool_t retval = FALSE;
315
316   g_return_val_if_fail (obj != NULL, FALSE);
317
318   _atspi_dbus_call (obj, atspi_interface_text, "SetCaretOffset", error, "i=>b", d_new_offset, &retval);
319
320   return retval;
321 }
322
323 /**
324  * atspi_text_get_text_before_offset:
325  * @obj: a pointer to the #AtspiText object on which to operate.
326  * @offset: an integer indicating the offset from which the delimiter
327  *        search is based.
328  * @type: an #AtspiTextBoundaryType indicating whether the desired
329  *       text string is a word, sentence, line, or attribute run.
330  *
331  * Get delimited text from an #AtspiText object which precedes a given
332  *          text offset.
333  *
334  * Returns: an #AtspiTextRange containing a UTF-8 string representing the
335  *          delimited text, both of whose delimiting boundaries are before the
336  *          current offset, or an empty string if no such text exists.
337  **/
338 AtspiTextRange *
339 atspi_text_get_text_before_offset (AtspiText *obj,
340                                     gint offset,
341                                     AtspiTextBoundaryType type,
342                                     GError **error)
343 {
344   dbus_int32_t d_offset = offset;
345   dbus_uint32_t d_type = type;
346   dbus_int32_t d_start_offset = -1, d_end_offset = -1;
347   AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
348
349   if (range)
350     range->start_offset = range->end_offset = -1;
351   if (!obj || !range)
352     return range;
353
354   _atspi_dbus_call (obj, atspi_interface_text, "GetTextBeforeOffset", error,
355                     "iu=>sii", d_offset, d_type, &range->content,
356                     &d_start_offset, &d_end_offset);
357
358   range->start_offset = d_start_offset;
359   range->end_offset = d_end_offset;
360   if (!range->content)
361     range->content = g_strdup ("");
362
363   return range;
364 }
365
366 /**
367  * atspi_text_get_text_at_offset:
368  * @obj: a pointer to the #AtspiText object on which to operate.
369  * @offset: a long integer indicating the offset from which the delimiter
370  *        search is based.
371  * @type: an #AtspiTextBoundaryType indicating whether the desired
372  *       text string is a word, sentence, line, or attribute run.
373  *
374  * Get delimited text from an #AtspiText object which includes a given
375  *          text offset.
376  *
377  * Returns: an #AtspiTextRange containing a UTF-8 string representing the
378  *          delimited text, whose delimiting boundaries bracket the
379  *          current offset, or an empty string if no such text exists.
380  **/
381 AtspiTextRange *
382 atspi_text_get_text_at_offset (AtspiText *obj,
383                                     gint offset,
384                                     AtspiTextBoundaryType type,
385                                     GError **error)
386 {
387   dbus_int32_t d_offset = offset;
388   dbus_uint32_t d_type = type;
389   dbus_int32_t d_start_offset = -1, d_end_offset = -1;
390   AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
391
392   if (range)
393     range->start_offset = range->end_offset = -1;
394   if (!obj || !range)
395     return range;
396
397   _atspi_dbus_call (obj, atspi_interface_text, "GetTextAtOffset", error,
398                     "iu=>sii", d_offset, d_type, &range->content,
399                     &d_start_offset, &d_end_offset);
400
401   range->start_offset = d_start_offset;
402   range->end_offset = d_end_offset;
403   if (!range->content)
404     range->content = g_strdup ("");
405
406   return range;
407 }
408
409 /**
410  * atspi_text_get_text_after_offset:
411  * @obj: a pointer to the #AtspiText object on which to operate.
412  * @offset: an integer indicating the offset from which the delimiter
413  *        search is based.
414  * @type: an #AtspiTextBoundaryType indicating whether the desired
415  *       text string is a word, sentence, line, or attribute run.
416  *
417  * Get delimited text from an #AtspiText object which follows a given
418  *          text offset.
419  *
420  * Returns: an #AtspiTextRange containing a UTF-8 string representing the
421  *          delimited text, both of whose delimiting boundaries are after or
422  *          inclusive of the current offset, or an empty string if no such
423  *          text exists.
424  **/
425 AtspiTextRange *
426 atspi_text_get_text_after_offset (AtspiText *obj,
427                                     gint offset,
428                                     AtspiTextBoundaryType type,
429                                     GError **error)
430 {
431   dbus_int32_t d_offset = offset;
432   dbus_uint32_t d_type = type;
433   dbus_int32_t d_start_offset = -1, d_end_offset = -1;
434   AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
435
436   if (range)
437     range->start_offset = range->end_offset = -1;
438   if (!obj || !range)
439     return range;
440
441   _atspi_dbus_call (obj, atspi_interface_text, "GetTextAfterOffset", error,
442                     "iu=>sii", d_offset, d_type, &range->content,
443                     &d_start_offset, &d_end_offset);
444
445   range->start_offset = d_start_offset;
446   range->end_offset = d_end_offset;
447   if (!range->content)
448     range->content = g_strdup ("");
449
450   return range;
451 }
452
453 /**
454  * atspi_text_get_character_at_offset:
455  * @obj: a pointer to the #AtspiText object on which to operate.
456  * @offset: a long integer indicating the text offset where the desired
457  *          character is located.
458  *
459  * Get the character at a given offset for an #AtspiText object.
460  *
461  * Returns: an #unsigned long integer which represents the
462  *        UCS-4 unicode code point of the given character, or
463  *        0xFFFFFFFF if the character in question cannot be represented
464  *        in the UCS-4 encoding.
465  **/
466 guint
467 atspi_text_get_character_at_offset (AtspiText *obj,
468                                      gint offset,
469                                      GError **error)
470 {
471   dbus_int32_t d_offset = offset;
472   dbus_int32_t retval = -1;
473
474   g_return_val_if_fail (obj != NULL, -1);
475
476   _atspi_dbus_call (obj, atspi_interface_text, "GetCharacterAtOffset", error, "i=>i", d_offset, &retval);
477
478   return retval;
479 }
480
481 /**
482  * atspi_text_get_character_extents:
483  * @obj: a pointer to the #AtspiText object on which to operate.
484  * @offset: an integer indicating the offset of the text character for
485  *        whom boundary information is requested.
486  * @type: an #AccessibleCoordType indicating the coordinate system to use
487  *        for the returned values.
488  *
489  * Returns: A #AtspiRect specifying the position and size of the character.
490  *
491  * Get the bounding box containing the glyph representing
492  *        the character at a particular text offset.
493  **/
494 AtspiRect *
495 atspi_text_get_character_extents (AtspiText *obj,
496                                     gint offset,
497                                     AtspiCoordType type,
498                                     GError **error)
499 {
500   dbus_int32_t d_offset = offset;
501   dbus_uint32_t d_type = type;
502   dbus_int32_t d_x, d_y, d_width, d_height;
503   AtspiRect ret;
504
505   ret.x = ret.y = ret.width = ret.height = -1;
506
507   if (obj == NULL)
508     return atspi_rect_copy (&ret);
509
510   _atspi_dbus_call (obj, atspi_interface_text, "GetCharacterExtents", error, "iu=>iiii", d_offset, d_type, &d_x, &d_y, &d_width, &d_height);
511
512   ret.x = d_x;
513   ret.y = d_y;
514   ret.width = d_width;
515   ret.height = d_height;
516   return atspi_rect_copy (&ret);
517 }
518
519 /**
520  * atspi_text_get_offset_at_point:
521  * @obj: a pointer to the #AtspiText object on which to operate.
522  * @x: the x coordinate of the point to be queried.
523  * @y: the y coordinate of the point to be queried.
524  * @type: an #AtspiCoordType indicating the coordinate system in which
525  *       the values should be returned.
526  *
527  * Get the character offset into the text at a given point.
528  *
529  * Returns: the offset (as an integer) at the point (@x, @y)
530  *       in the specified coordinate system.
531  *
532  **/
533 gint
534 atspi_text_get_offset_at_point (AtspiText *obj,
535                                  gint x,
536                                  gint y,
537                                  AtspiCoordType type,
538                                  GError **error)
539 {
540   dbus_int32_t d_x = x, d_y = y;
541   dbus_uint32_t d_type = type;
542   dbus_int32_t retval = -1;
543
544   g_return_val_if_fail (obj != NULL, -1);
545
546   _atspi_dbus_call (obj, atspi_interface_text, "GetOffsetAtPoint", error, "iiu=>i", d_x, d_y, d_type, &retval);
547
548   return retval;
549 }
550
551 /**
552  * atspi_text_get_range_extents:
553  * @obj: a pointer to the #AtspiText object on which to operate.
554  * @start_offset: an integer indicating the offset of the first text character for
555  *        whom boundary information is requested.
556  * @end_offset: an integer indicating the offset of the text character
557  *        after the last character for whom boundary information is requested.
558  * @type: an #AtspiCoordType indicating the coordinate system to use
559  *        for the returned values.
560  *
561  * Returns: A #AtspiRect giving the position and size of the specified range
562  *          of text.
563  *
564  * Get the bounding box for text within a range in an  #AtspiText object.
565  **/
566 AtspiRect *
567 atspi_text_get_range_extents (AtspiText *obj,
568                                 gint start_offset,
569                                 gint end_offset,
570                                 AtspiCoordType type,
571                                 GError **error)
572 {
573   dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
574   dbus_uint32_t d_type = type;
575   dbus_int32_t d_x, d_y, d_width, d_height;
576   AtspiRect ret;
577
578   ret.x = ret.y = ret.width = ret.height = -1;
579
580   if (obj == NULL)
581     return atspi_rect_copy (&ret);
582
583   _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);
584
585   ret.x = d_x;
586   ret.y = d_y;
587   ret.width = d_width;
588   ret.height = d_height;
589   return atspi_rect_copy (&ret);
590 }
591
592 /**
593  * atspi_text_get_bounded_ranges:
594  * @obj: a pointer to the #AtspiText object on which to operate.
595  * @x: the 'starting' x coordinate of the bounding box.
596  * @y: the 'starting' y coordinate of the bounding box.
597  * @width: the x extent of the bounding box.
598  * @height: the y extent of the bounding box.
599  * @type: an #AccessibleCoordType indicating the coordinate system to use
600  *        for the returned values.
601  * @clipTypeX: an #AtspiTextClipType indicating how to treat characters that
602  *        intersect the bounding box's x extents.
603  * @clipTypeY: an #AtspiTextClipType indicating how to treat characters that
604  *        intersect the bounding box's y extents.
605  *
606  * Get the ranges of text from an #AtspiText object which lie within the
607  *          bounds defined by (@x, @y) and (@x+@width, @y+@height).
608  *
609  * Returns: (transfer full) (element-type AtspiTextRange*): a null-terminated list of
610  *          pointers to #AtspiTextRange structs detailing the bounded text.
611  **/
612 GArray *
613 atspi_text_get_bounded_ranges (AtspiText *obj,
614                                  gint x,
615                                  gint y,
616                                  gint width,
617                                  gint height,
618                                  AtspiCoordType type,
619                                  AtspiTextClipType clipTypeX,
620                                  AtspiTextClipType clipTypeY,
621                                  GError **error)
622 {
623   dbus_int32_t d_x = x, d_y = y, d_width = width, d_height = height;
624   dbus_uint32_t d_type = type;
625   dbus_uint32_t d_clipTypeX = clipTypeX, d_clipTypeY = clipTypeY;
626   GArray *range_seq;
627
628   g_return_val_if_fail (obj != NULL, NULL);
629
630   _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);
631
632   return range_seq;
633 }
634
635 /**
636  * atspi_text_get_n_selections:
637  * @obj: a pointer to the #AtspiText object on which to operate.
638  *
639  * Get the number of active non-contiguous selections for an
640  *          #AtspiText object.
641  *
642  * Returns: a long integer indicating the current
643  *          number of non-contiguous text selections active
644  *          within an #AtspiText object.
645  **/
646 gint
647 atspi_text_get_n_selections (AtspiText *obj, GError **error)
648 {
649   dbus_int32_t retval;
650
651   g_return_val_if_fail (obj != NULL, -1);
652
653   _atspi_dbus_call (obj, atspi_interface_text, "GetNSelections", error, "i", &retval);
654
655   return retval;
656 }
657
658 /**
659  * atspi_text_get_sSelection:
660  * @obj: a pointer to the #AtspiText object on which to operate.
661  * @selection_num: an integer indicating which selection to query.
662  * @start_offset: a pointer to a long integer into which the start offset
663  *           of the selection will be returned.
664  * @end_offset: a pointer to a long integer into which the start offset
665  *           of the selection will be returned.
666  *
667  * Get the bounds of the @selection_num-th active text selection for an
668  *         #AtspiText object.
669  **/
670 AtspiRange *
671 atspi_text_get_selection (AtspiText *obj,
672                              gint selection_num,
673                              GError **error)
674 {
675   dbus_int32_t d_selection_num = selection_num;
676   dbus_int32_t d_start_offset, d_end_offset;
677   AtspiRange *ret = g_new (AtspiRange, 1);
678
679   if (ret)
680     ret->start_offset = ret->end_offset = -1;
681
682   if (!obj || !ret)
683     return ret;
684
685   _atspi_dbus_call (obj, atspi_interface_text, "GetSelection", error, "i=>ii", d_selection_num, &d_start_offset, &d_end_offset);
686
687   ret->start_offset = d_start_offset;
688   ret->end_offset = d_end_offset;
689   return ret;
690 }
691
692 /**
693  * atspi_text_add_selection:
694  * @obj: a pointer to the #AtspiText object on which to operate.
695  * @start_offset: the starting offset of the desired new selection.
696  * @end_offset: the offset of the first character after the new selection.
697  *
698  * Select some text (add a text selection) in an #AtspiText object.
699  *
700  * Returns: #TRUE if successful, #FALSE otherwise.
701  **/
702 gboolean
703 atspi_text_add_selection (AtspiText *obj,
704                              gint start_offset, gint end_offset,
705                              GError **error)
706 {
707   dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
708   dbus_bool_t retval = FALSE;
709
710   _atspi_dbus_call (obj, atspi_interface_text, "AddSelection", error, "ii=>b", d_start_offset, d_end_offset, &retval);
711
712   return retval;
713 }
714
715 /**
716  * atspi_text_remove_selection:
717  * @obj: a pointer to the #AtspiText object on which to operate.
718  * @selection_num: an integer indicating which (possibly of several)
719  *         text selection to remove.
720  *
721  * De-select a text selection.
722  *
723  * Returns: #TRUE if successful, #FALSE otherwise.
724  **/
725 gboolean
726 atspi_text_remove_selection (AtspiText *obj,
727                                 gint selection_num,
728                                 GError **error)
729 {
730   dbus_int32_t d_selection_num = selection_num;
731   dbus_bool_t retval = FALSE;
732
733   g_return_val_if_fail (obj != NULL, FALSE);
734
735   _atspi_dbus_call (obj, atspi_interface_text, "RemoveSelection", error, "i=>b", d_selection_num, &retval);
736
737   return retval;
738 }
739
740 /**
741  * atspi_text_set_selection:
742  * @obj: a pointer to the #AtspiText object on which to operate.
743  * @selection_num: a zero-offset index indicating which text selection to modify.
744  * @start_offset: a long int, the new starting offset for the selection.
745  * @end_offset: a long int, the desired new offset of the first character
746  *             after the selection.
747  *
748  * Change the bounds of an existing #AtspiText text selection.
749  *
750  * Returns: #TRUE if successful, #FALSE otherwise.
751  **/
752 gboolean
753 atspi_text_set_selection (AtspiText *obj,
754                              gint selection_num,
755                              gint start_offset,
756                              gint end_offset,
757                              GError **error)
758 {
759   dbus_int32_t d_selection_num = selection_num, d_start_offset = start_offset, d_end_offset = end_offset;
760   dbus_bool_t retval = FALSE;
761
762   g_return_val_if_fail (obj != NULL, FALSE);
763
764   _atspi_dbus_call (obj, atspi_interface_text, "SetSelection", error, "iii=>b", d_selection_num, d_start_offset, d_end_offset, &retval);
765
766   return retval;
767 }
768
769 static void
770 atspi_text_base_init (AtspiText *klass)
771 {
772 }
773
774 GType
775 atspi_text_get_type (void)
776 {
777   static GType type = 0;
778
779   if (!type) {
780     static const GTypeInfo tinfo =
781     {
782       sizeof (AtspiText),
783       (GBaseInitFunc) atspi_text_base_init,
784       (GBaseFinalizeFunc) NULL,
785     };
786
787     type = g_type_register_static (G_TYPE_INTERFACE, "AtspiText", &tinfo, 0);
788
789   }
790   return type;
791 }