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