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