Add AT-SPI mapping for ATK_RELATION_NODE_PARENT_OF
[platform/core/uifw/at-spi2-atk.git] / cspi / spi-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 <cspi/spi-private.h>
25
26 static Accessibility_TEXT_BOUNDARY_TYPE
27 get_accessible_text_boundary_type (AccessibleTextBoundaryType type)
28 {
29   switch (type)
30     {
31     case SPI_TEXT_BOUNDARY_CHAR:
32       return Accessibility_TEXT_BOUNDARY_CHAR;
33       break;
34     case SPI_TEXT_BOUNDARY_CURSOR_POS:
35       /* FixME */
36       return Accessibility_TEXT_BOUNDARY_CHAR;
37       break;
38     case SPI_TEXT_BOUNDARY_WORD_START:
39       return Accessibility_TEXT_BOUNDARY_WORD_START;
40       break;
41     case SPI_TEXT_BOUNDARY_WORD_END:
42       return Accessibility_TEXT_BOUNDARY_WORD_END;
43       break;
44     case SPI_TEXT_BOUNDARY_SENTENCE_START:
45       return Accessibility_TEXT_BOUNDARY_SENTENCE_START;
46       break;
47     case SPI_TEXT_BOUNDARY_SENTENCE_END:
48       return Accessibility_TEXT_BOUNDARY_SENTENCE_END;
49       break;
50     case SPI_TEXT_BOUNDARY_LINE_START:
51       return Accessibility_TEXT_BOUNDARY_LINE_START;
52       break;
53     case SPI_TEXT_BOUNDARY_LINE_END:
54       return Accessibility_TEXT_BOUNDARY_LINE_END;
55       break;
56     case SPI_TEXT_BOUNDARY_ATTRIBUTE_RANGE:
57       /* Fixme */
58       return Accessibility_TEXT_BOUNDARY_CHAR;
59       break;
60     default:
61       /* FIXME */
62       return Accessibility_TEXT_BOUNDARY_CHAR;
63     }
64 }
65
66 static Accessibility_TEXT_CLIP_TYPE
67 get_accessible_text_clip_type (AccessibleTextClipType type)
68 {
69   switch (type)
70     {
71     case SPI_TEXT_CLIP_NONE:
72       return Accessibility_TEXT_CLIP_NONE;
73       break;
74     case SPI_TEXT_CLIP_MIN:
75       return Accessibility_TEXT_CLIP_MIN;
76       break;
77     case SPI_TEXT_CLIP_MAX:      
78       return Accessibility_TEXT_CLIP_MAX;
79       break;
80     default:
81       return Accessibility_TEXT_CLIP_BOTH;
82     }
83 }
84
85 typedef struct
86 {
87   dbus_int32_t startOffset;
88   dbus_int32_t endOffset;
89   char *content;
90 } Accessibility_Range;
91
92 static AccessibleTextRange **
93 get_accessible_text_ranges_from_range_seq (GArray *range_seq)
94 {
95   AccessibleTextRange **ranges = NULL;
96   AccessibleTextRange *array = NULL;
97   int i;
98   if (range_seq && range_seq->len > 0) 
99     {
100       ranges = g_new0 (AccessibleTextRange *, range_seq->len + 1);
101     }
102   array = g_new0 (AccessibleTextRange, range_seq->len);
103   for (i = 0; i < range_seq->len; i++) 
104     {
105       Accessibility_Range *r = g_array_index (range_seq, Accessibility_Range *, i);
106       AccessibleTextRange *range;
107       range = &array[i];
108       range->start = r->startOffset;
109       range->end = r->endOffset;
110       range->contents = g_strdup (r->content);
111       ranges[i] = range;
112     }
113   ranges[i] = NULL; /* null-terminated list! */
114   // TODO: Figure out whether we're leaking strings
115   g_array_free (range_seq, TRUE);
116
117   return ranges;
118 }
119
120
121 /**
122  * AccessibleText_ref:
123  * @obj: a pointer to the #AccessibleText object on which to operate.
124  *
125  * Increment the reference count for an #AccessibleText object.
126  **/
127 void
128 AccessibleText_ref (AccessibleText *obj)
129 {
130   cspi_object_ref (obj);
131 }
132
133 /**
134  * AccessibleText_unref:
135  * @obj: a pointer to the #Accessible object on which to operate.
136  *
137  * Decrement the reference count for an #AccessibleText object.
138  **/
139 void
140 AccessibleText_unref (AccessibleText *obj)
141 {
142   cspi_object_unref (obj);
143 }
144
145 /**
146  * AccessibleText_getCharacterCount:
147  * @obj: a pointer to the #AccessibleText object to query.
148  *
149  * Get the character count of an #AccessibleText object.
150  *
151  * Returns: a long integer indicating the total number of
152  *              characters in the #AccessibleText object.
153  **/
154 long
155 AccessibleText_getCharacterCount (AccessibleText *obj)
156 {
157   dbus_int32_t retval;
158
159   cspi_return_val_if_fail (obj != NULL, -1);
160
161   cspi_dbus_get_property (obj, spi_interface_text, "characterCount", NULL, "i", &retval);
162
163   cspi_return_val_if_ev ("getCharacterCount", -1);
164
165   return retval;
166 }
167
168 /**
169  * AccessibleText_getText:
170  * @obj: a pointer to the #AccessibleText object to query.
171  * @startOffset: a #long indicating the start of the desired text range.
172  * @endOffset: a #long indicating the first character past the desired range.
173  *
174  * Get a range of text from an #AccessibleText object.  The number of bytes
175  *          in the returned string may exceed endOffset-startOffset, since
176  *          UTF-8 is a variable-width encoding.
177  *
178  * Returns: a text string containing characters from @startOffset
179  *          to @endOffset-1, inclusive, encoded as UTF-8.
180  **/
181 char *
182 AccessibleText_getText (AccessibleText *obj,
183                         long int startOffset,
184                         long int endOffset)
185 {
186   char *retval;
187   dbus_int32_t d_startOffset = startOffset, d_endOffset = endOffset;
188
189   cspi_return_val_if_fail (obj != NULL, NULL);
190
191   cspi_dbus_call (obj, spi_interface_text, "getText", NULL, "ii=>s", startOffset, endOffset, &retval);
192
193   cspi_return_val_if_ev ("getText", NULL);
194
195   return retval;
196 }
197
198 /**
199  * AccessibleText_getCaretOffset:
200  * @obj: a pointer to the #AccessibleText object to query.
201  *
202  * Get the current offset of the text caret in an #AccessibleText object.
203  *
204  * Returns: a long integer indicating the current position of the text caret.
205  **/
206 long
207 AccessibleText_getCaretOffset (AccessibleText *obj)
208 {
209   dbus_int32_t retval;
210
211   cspi_return_val_if_fail (obj != NULL, -1);
212
213   cspi_dbus_get_property (obj, spi_interface_text, "caretOffset", NULL, "i", &retval);
214
215   cspi_return_val_if_ev ("getCaretOffset", -1);
216
217   return retval;
218 }
219
220 /**
221  * AccessibleText_getAttributes:
222  * @obj: a pointer to the #AccessibleText object to query.
223  * @offset: a long integer indicating the offset from which the attribute
224  *        search is based.
225  * @startOffset: a #long indicating the start of the desired text range.
226  * @endOffset: a #long indicating the first character past the desired range.
227  *
228  * Get the attributes applied to a range of text from an #AccessibleText
229  *          object, and the bounds of the range.
230  *          The text attributes correspond to CSS attributes where possible,
231  *          keys and values are delimited from one another via ":", and
232  *          the delimiter between key/value pairs is ";". Thus 
233  *          "font-size:10;foreground-color:0,0,0" would be a valid
234  *          return string.
235  *
236  * Returns: a text string describing the attributes occurring within the
237  *          attribute run containing @offset, encoded as UTF-8.
238  **/
239 char *
240 AccessibleText_getAttributes (AccessibleText *obj,
241                               long int offset,
242                               long int *startOffset,
243                               long int *endOffset)
244 {
245   dbus_int32_t d_offset = offset;
246   dbus_int32_t retStartOffset, retEndOffset;
247   char *retval; 
248
249   if (obj == NULL)
250     {
251       *startOffset = *endOffset = -1;
252       return NULL;
253     }
254
255   cspi_dbus_call (obj, spi_interface_text, "getAttributes", NULL, "i=>sii", d_offset, &retval, &retStartOffset, &retEndOffset);
256
257   if (!cspi_check_ev ("getAttributes"))
258     {
259       *startOffset = *endOffset = -1;
260       retval = NULL;
261     }
262   else
263     {
264       *startOffset = retStartOffset;
265       *endOffset   = retEndOffset;
266     }
267
268   return retval;
269 }
270
271 /**
272  * AccessibleText_getDefaultAttributes:
273  * @obj: a pointer to the #AccessibleText object to query.
274  *
275  * Get the default attributes applied to an #AccessibleText
276  *          object.
277  *          The text attributes correspond to CSS attributes where possible,
278  *          keys and values are delimited from one another via ":", and
279  *          the delimiter between key/value pairs is ";". Thus 
280  *          "font-size:10;foreground-color:0,0,0" would be a valid
281  *          return string.  The combination of this attribute set and
282  *          the attributes reported by #AccessibleText_getAttributes
283  *          describes the entire set of text attributes over a range.
284  *
285  * @Since: AT-SPI 1.4
286  *
287  * Returns: a text string describing the default attributes 
288  *          applied to a text object, (exclusive of explicitly-set
289  *          attributes), encoded as UTF-8.
290  **/
291 char *
292 AccessibleText_getDefaultAttributes (AccessibleText *obj)
293 {
294   char *retval; 
295
296   if (obj == NULL)
297     {
298       return NULL;
299     }
300
301   cspi_dbus_call (obj, spi_interface_text, "getAttributes", NULL, "=>s", &retval);
302
303   if (!cspi_check_ev ("getAttributes"))
304     {
305       retval = NULL;
306     }
307
308   return retval;
309 }
310
311 /**
312  * AccessibleText_setCaretOffset:
313  * @obj: a pointer to the #AccessibleText object on which to operate.
314  * @newOffset: the offset to which the text caret is to be moved.
315  *
316  * Set the text caret position for an #AccessibleText object.
317  *
318  * Returns: #TRUE if successful, #FALSE otherwise.
319  **/
320 SPIBoolean
321 AccessibleText_setCaretOffset (AccessibleText *obj,
322                                long int newOffset)
323 {
324   dbus_int32_t d_newOffset = newOffset;
325   dbus_bool_t retval;
326
327   cspi_return_val_if_fail (obj != NULL, FALSE);
328
329   cspi_dbus_call (obj, spi_interface_text, "setCaretOffset", NULL, "i=>b", d_newOffset, &retval);
330
331   cspi_return_val_if_ev ("setCaretOffset", FALSE);
332
333   return retval;
334 }
335
336 /**
337  * AccessibleText_getTextBeforeOffset:
338  * @obj: a pointer to the #AccessibleText object on which to operate.
339  * @offset: a long integer indicating the offset from which the delimiter
340  *        search is based.
341  * @type: an #AccessibleTextBoundaryType indicating whether the desired
342  *       text string is a word, sentence, line, or attribute run.
343  * @startOffset: a pointer to a long integer which is assigned the
344  *       starting offset of the returned string, relative to the
345  *       original #AccessibleText.
346  * @endOffset: a pointer to a long integer which is assigned the
347  *       ending offset of the returned string, relative to the original
348  *       #AccessibleText.
349  *
350  * Get delimited text from an #AccessibleText object which precedes a given
351  *          text offset.
352  *
353  * Returns: a UTF-8 string representing the delimited text, both of whose
354  *          delimiting boundaries are before the current offset, or
355  *          an empty string if no such text exists.
356  **/
357 char *
358 AccessibleText_getTextBeforeOffset (AccessibleText *obj,
359                                     long int offset,
360                                     AccessibleTextBoundaryType type,
361                                     long int *startOffset,
362                                     long int *endOffset)
363 {
364   dbus_int32_t d_offset = offset;
365   dbus_uint32_t d_type = type;
366   dbus_int32_t retStartOffset, retEndOffset;
367   char *retval;
368
369   if (obj == NULL)
370     {
371       *startOffset = *endOffset = -1;
372       return NULL;
373     }
374
375   cspi_dbus_call (obj, spi_interface_text, "getTextBeforeOffset", NULL, "iu=>sii", d_offset, d_type, &retval, &retStartOffset, &retEndOffset);
376   if (!cspi_check_ev ("getTextBeforeOffset"))
377     {
378       *startOffset = *endOffset = -1;
379       retval = NULL;
380     }
381   else
382     {
383       *startOffset = retStartOffset;
384       *endOffset = retEndOffset;
385     }
386   return retval;
387 }
388
389 /**
390  * AccessibleText_getTextAtOffset:
391  * @obj: a pointer to the #AccessibleText object on which to operate.
392  * @offset: a long integer indicating the offset from which the delimiter
393  *        search is based.
394  * @type: an #AccessibleTextBoundaryType indicating whether the desired
395  *       text string is a word, sentence, line, or attribute run.
396  * @startOffset: a pointer to a long integer which is assigned the
397  *       starting offset of the returned string, relative to the
398  *       original #AccessibleText.
399  * @endOffset: a pointer to a long integer which is assigned the
400  *       ending offset of the returned string, relative to the original
401  *       #AccessibleText.
402  *
403  * Get delimited text from an #AccessibleText object which includes a given
404  *          text offset.
405  *
406  * Returns: a UTF-8 string representing the delimited text, whose
407  *          delimiting boundaries bracket the current offset, or
408  *          an empty string if no such text exists.
409  **/
410 char *
411 AccessibleText_getTextAtOffset (AccessibleText *obj,
412                                 long int offset,
413                                 AccessibleTextBoundaryType type,
414                                 long int *startOffset, long int *endOffset)
415 {
416   dbus_int32_t d_offset = offset;
417   dbus_uint32_t d_type = type;
418   dbus_int32_t retStartOffset, retEndOffset;
419   char *retval;
420
421   if (obj == NULL)
422     {
423       *startOffset = *endOffset = -1;
424       return NULL;
425     }
426
427   cspi_dbus_call (obj, spi_interface_text, "getTextAtOffset", NULL, "iu=>sii", d_offset, d_type, &retval, &retStartOffset, &retEndOffset);
428
429   if (!cspi_check_ev ("getTextAtOffset"))
430     {
431       *startOffset = *endOffset = -1;
432       retval = NULL;
433     }
434   else
435     {
436       *startOffset = retStartOffset;
437       *endOffset   = retEndOffset;
438     }
439   return retval;
440 }
441
442 /**
443  * AccessibleText_getTextAfterOffset:
444  * @obj: a pointer to the #AccessibleText object on which to operate.
445  * @offset: a long integer indicating the offset from which the delimiter
446  *        search is based.
447  * @type: an #AccessibleTextBoundaryType indicating whether the desired
448  *       text string is a word, sentence, line, or attribute run.
449  * @startOffset: a pointer to a long integer which is assigned the
450  *       starting offset of the returned string, relative to the
451  *       original #AccessibleText.
452  * @endOffset: a pointer to a long integer which is assigned the
453  *       ending offset of the returned string, relative to the original
454  *       #AccessibleText.
455  *
456  * Get delimited text from an #AccessibleText object which follows a given
457  *          text offset.
458  *
459  * Returns: a UTF-8 string representing the delimited text, both of whose
460  *          delimiting boundaries are after or inclusive of the current
461  *          offset, or an empty string if no such text exists.
462  **/
463 char *
464 AccessibleText_getTextAfterOffset (AccessibleText *obj,
465                                    long int offset,
466                                    AccessibleTextBoundaryType type,
467                                    long int *startOffset, long int *endOffset)
468 {
469   dbus_int32_t d_offset = offset;
470   dbus_uint32_t d_type = type;
471   dbus_int32_t retStartOffset, retEndOffset;
472   char *retval;
473
474   if (obj == NULL)
475     {
476       *startOffset = *endOffset = -1;
477       return NULL;
478     }
479
480   cspi_dbus_call (obj, spi_interface_text, "getTextAfterOffset", NULL, "iu=>sii", d_offset, d_type, &retval, &retStartOffset, &retEndOffset);
481
482   if (!cspi_check_ev ("getTextAfterOffset"))
483     {
484       *startOffset = *endOffset = -1;
485       retval = NULL;
486     }
487   else
488     {
489       *startOffset = retStartOffset;
490       *endOffset   = retEndOffset;
491     }
492   return retval;
493 }
494
495 /**
496  * AccessibleText_getCharacterAtOffset:
497  * @obj: a pointer to the #AccessibleText object on which to operate.
498  * @offset: a long integer indicating the text offset where the desired
499  *          character is located.
500  *
501  * Get the character at a given offset for an #AccessibleText object.
502  *
503  * Returns: an #unsigned long integer which represents the
504  *        UCS-4 unicode code point of the given character, or
505  *        0xFFFFFFFF if the character in question cannot be represented
506  *        in the UCS-4 encoding.
507  **/
508 unsigned long
509 AccessibleText_getCharacterAtOffset (AccessibleText *obj,
510                                      long int offset)
511 {
512   dbus_int32_t d_offset = offset;
513   dbus_int32_t retval;
514
515   cspi_return_val_if_fail (obj != NULL, -1);
516
517   cspi_dbus_call (obj, spi_interface_text, "getCharacterAtOffset", NULL, "i=>i", d_offset, &retval);
518
519   cspi_return_val_if_ev ("getCharacterAtOffset", -1);
520
521   return retval;
522 }
523
524 /**
525  * AccessibleText_getCharacterExtents:
526  * @obj: a pointer to the #AccessibleText object on which to operate.
527  * @offset: an integer indicating the offset of the text character for
528  *        whom boundary information is requested.
529  * @x: a pointer to a long integer into which the nominal x coordinate
530  *     of the corresponding glyph will be returned.
531  * @y:a pointer to a long integer into which the nominal y coordinate
532  *     of the corresponding glyph will be returned.
533  * @width:a pointer to a long integer into which the width
534  *     of the corresponding glyph will be returned.
535  * @height: a pointer to a long integer into which the height
536  *     of the corresponding glyph will be returned.
537  * @type: an #AccessibleCoordType indicating the coordinate system to use
538  *        for the returned values.
539  *
540  * Get the bounding box containing the glyph representing
541  *        the character at a particular text offset.
542  **/
543 void
544 AccessibleText_getCharacterExtents (AccessibleText *obj,
545                                     long int offset,
546                                     long int *x,
547                                     long int *y,
548                                     long int *width,
549                                     long int *height,
550                                     AccessibleCoordType type)
551 {
552   dbus_int32_t d_offset = offset;
553   dbus_uint16_t d_type = type;
554   dbus_int32_t retX, retY, retWidth, retHeight;
555
556   if (obj == NULL)
557     {
558       *x = *y = -1;
559       *width = *height = -1;
560       return;
561     }
562
563   cspi_dbus_call (obj, spi_interface_text, "getCharacterExtents", NULL, "in=>iiii", d_offset, d_type, &retX, &retY, &retWidth, &retHeight);
564
565   if (!cspi_check_ev ("getCharacterExtents"))
566     {
567       *x = *y = -1;
568       *width = *height = -1;
569     }
570   else
571     {
572       *x = retX;
573       *y = retY;
574       *width = retWidth;
575       *height = retHeight;
576     }
577 }
578
579 /**
580  * AccessibleText_getOffsetAtPoint:
581  * @obj: a pointer to the #AccessibleText object on which to operate.
582  * @x: the x coordinate of the point to be queried.
583  * @y: the y coordinate of the point to be queried.
584  * @type: an #AccessibleCoordType indicating the coordinate system in which
585  *       the values should be returned.
586  *
587  * Get the bounding box for a glyph at a certain #AccessibleText offset.
588  *
589  * Returns: the offset (as a long integer) at the point (@x, @y)
590  *       in the specified coordinate system.
591  *
592  **/
593 long
594 AccessibleText_getOffsetAtPoint (AccessibleText *obj,
595                                  long int x,
596                                  long int y,
597                                  AccessibleCoordType type)
598 {
599   dbus_int32_t d_x = x, d_y = y;
600   dbus_uint16_t d_type = type;
601   dbus_int32_t retval;
602
603   cspi_return_val_if_fail (obj != NULL, -1);
604
605   cspi_dbus_call (obj, spi_interface_text, "getOffsetAtPoint", NULL, "iin=>i", d_x, d_y, d_type, &retval);
606
607   cspi_return_val_if_ev ("getOffsetAtPoint", -1);
608
609   return retval;
610 }
611
612 /**
613  * AccessibleText_getRangeExtents:
614  * @obj: a pointer to the #AccessibleText object on which to operate.
615  * @startOffset: an integer indicating the offset of the first text character for
616  *        whom boundary information is requested.
617  * @endOffset: an integer indicating the offset of the text character 
618  *        after the last character for whom boundary information is requested.
619  * @x: a pointer to a long integer into which the nominal x coordinate
620  *     of the corresponding bounding box will be returned.
621  * @y:a pointer to a long integer into which the nominal y coordinate
622  *     of the corresponding bounding box will be returned.
623  * @width:a pointer to a long integer into which the width
624  *     of the corresponding bounding box will be returned.
625  * @height: a pointer to a long integer into which the height
626  *     of the corresponding bounding box will be returned.
627  * @type: an #AccessibleCoordType indicating the coordinate system to use
628  *        for the returned values.
629  *
630  * Get the bounding box for text within a range in an  #AccessibleText object.
631  *
632  * @Since: AT-SPI 1.2
633  **/
634 void
635 AccessibleText_getRangeExtents (AccessibleText *obj,
636                                 long int startOffset,
637                                 long int endOffset,
638                                 long int *x,
639                                 long int *y,
640                                 long int *width,
641                                 long int *height,
642                                 AccessibleCoordType type)
643 {
644   dbus_int32_t d_startOffset = startOffset, d_endOffset = endOffset;
645   dbus_int16_t d_type = type;
646   dbus_int32_t retX, retY, retWidth, retHeight;
647
648   if (obj == NULL)
649     {
650       *x = *y = -1;
651       *width = *height = -1;
652       return;
653     }
654
655   cspi_dbus_call (obj, spi_interface_text, "getRangeExtents", NULL, "iin=>iiii", d_startOffset, d_endOffset, d_type, &retX, &retY, &retWidth, &retHeight);
656
657   if (!cspi_check_ev ("getRangeExtents"))
658     {
659       *x = *y = -1;
660       *width = *height = -1;
661     }
662   else
663     {
664       *x = retX;
665       *y = retY;
666       *width = retWidth;
667       *height = retHeight;
668     }
669 }
670
671 /**
672  * AccessibleText_getBoundedRanges:
673  * @obj: a pointer to the #AccessibleText object on which to operate.
674  * @x: the 'starting' x coordinate of the bounding box.
675  * @y: the 'starting' y coordinate of the bounding box.
676  * @width: the x extent of the bounding box.
677  * @height: the y extent of the bounding box.
678  * @type: an #AccessibleCoordType indicating the coordinate system to use
679  *        for the returned values.
680  * @clipTypeX: an #AccessibleTextClipType indicating how to treat characters that
681  *        intersect the bounding box's x extents.
682  * @clipTypeY: an #AccessibleTextClipType indicating how to treat characters that
683  *        intersect the bounding box's y extents.
684  *
685  * Get the ranges of text from an #AccessibleText object which lie within the
686  *          bounds defined by (@x, @y) and (@x+@width, @y+@height).  
687  *
688  * @Since: AT-SPI 1.2
689  *
690  * Returns: a null-terminated list of pointers to AccessibleTextRange structs 
691  *          detailing the bounded text.
692  **/
693 AccessibleTextRange **
694 AccessibleText_getBoundedRanges (AccessibleText *obj,
695                                  long int x,
696                                  long int y,
697                                  long int width,
698                                  long int height,
699                                  AccessibleCoordType type,
700                                  AccessibleTextClipType clipTypeX,
701                                  AccessibleTextClipType clipTypeY)
702 {
703   dbus_int32_t d_x = x, d_y = y, d_width = width, d_height = height;
704   dbus_uint16_t d_type = type;
705   dbus_uint32_t d_clipTypeX = clipTypeX, d_clipTypeY = clipTypeY;
706   GArray *range_seq;
707
708   cspi_return_val_if_fail (obj != NULL, NULL);
709
710   cspi_dbus_call (obj, spi_interface_text, "getBoundedRanges", NULL, "iiiinuu=>a(iisv)", d_x, d_y, d_width, d_height, d_type, d_clipTypeX, d_clipTypeY, &range_seq);
711
712   cspi_return_val_if_ev ("getBoundedRanges", NULL); 
713  
714   return get_accessible_text_ranges_from_range_seq (range_seq);
715 }
716
717 /**
718  * AccessibleTextRange_freeRanges:
719  * @ranges: a pointer to an array of AccessibleTextRange structs.
720  *
721  * Free the memory used by a list of AccessibleTextRange structs.
722  * The argument passed in should be an array of pointers 
723  * AccessibleTextRange structs.  
724  *
725  * @Since: AT-SPI 1.2
726  **/
727 void
728 AccessibleTextRange_freeRanges (AccessibleTextRange **ranges)
729 {
730   /* this was a contiguously allocated block, only free the first element */
731   g_free (ranges[0]); 
732   g_free (ranges);
733 }
734
735 /**
736  * AccessibleText_getNSelections:
737  * @obj: a pointer to the #AccessibleText object on which to operate.
738  *
739  * Get the number of active non-contiguous selections for an
740  *          #AccessibleText object.
741  *
742  * Returns: a long integer indicating the current
743  *          number of non-contiguous text selections active
744  *          within an #AccessibleText object.
745  **/
746 long
747 AccessibleText_getNSelections (AccessibleText *obj)
748 {
749   dbus_int32_t retval;
750
751   cspi_return_val_if_fail (obj != NULL, -1);
752
753   cspi_dbus_call (obj, spi_interface_text, "getNSelections", NULL, "i", &retval);
754
755   cspi_return_val_if_ev ("getNSelections", -1);
756
757   return retval;
758 }
759
760 /**
761  * AccessibleText_getSelection:
762  * @obj: a pointer to the #AccessibleText object on which to operate.
763  * @selectionNum: an integer indicating which selection to query.
764  * @startOffset: a pointer to a long integer into which the start offset
765  *           of the selection will be returned.
766  * @endOffset: a pointer to a long integer into which the start offset
767  *           of the selection will be returned.
768  *
769  * Get the bounds of the @selectionNum-th active text selection for an
770  *         #AccessibleText object.
771  **/
772 void
773 AccessibleText_getSelection (AccessibleText *obj,
774                              long int selectionNum,
775                              long int *startOffset,
776                              long int *endOffset)
777 {
778   dbus_int32_t d_selectionNum = selectionNum;
779   dbus_int32_t retStartOffset, retEndOffset;
780
781   if (obj == NULL)
782     {
783       *endOffset = *startOffset = -1;
784       return;
785     }
786
787   cspi_dbus_call (obj, spi_interface_text, "getSelection", NULL, "i=>ii", d_selectionNum, &retStartOffset, &retEndOffset);
788
789   if (!cspi_check_ev ("getSelection"))
790     {
791       *startOffset = *endOffset = -1;
792     }
793   else
794     {
795       *startOffset = retStartOffset;
796       *endOffset   = retEndOffset;
797     }
798 }
799
800 /**
801  * AccessibleText_addSelection:
802  * @obj: a pointer to the #AccessibleText object on which to operate.
803  * @startOffset: the starting offset of the desired new selection.
804  * @endOffset: the offset of the first character after the new selection.
805  *
806  * Select some text (add a text selection) in an #AccessibleText object.
807  *
808  * Returns: #TRUE if successful, #FALSE otherwise.
809  **/
810 SPIBoolean
811 AccessibleText_addSelection (AccessibleText *obj,
812                              long int startOffset, long int endOffset)
813 {
814   dbus_int32_t d_startOffset = startOffset, d_endOffset = endOffset;
815   dbus_bool_t retval;
816
817   cspi_return_val_if_fail (obj != NULL, FALSE);
818
819   cspi_dbus_call (obj, spi_interface_text, "addSelection", NULL, "ii=>b", d_startOffset, d_endOffset, &retval);
820
821   cspi_return_val_if_ev ("addSelection", FALSE);
822
823   return retval;
824 }
825
826 /**
827  * AccessibleText_removeSelection:
828  * @obj: a pointer to the #AccessibleText object on which to operate.
829  * @selectionNum: an integer indicating which (possibly of several)
830  *         text selection to remove.
831  *
832  * De-select a text selection.
833  *
834  * Returns: #TRUE if successful, #FALSE otherwise.
835  **/
836 SPIBoolean
837 AccessibleText_removeSelection (AccessibleText *obj,
838                                 long int selectionNum)
839 {
840   dbus_int32_t d_selectionNum = selectionNum;
841   dbus_bool_t retval;
842
843   cspi_return_val_if_fail (obj != NULL, FALSE);
844
845   cspi_dbus_call (obj, spi_interface_text, "removeSelection", NULL, "i=>b", d_selectionNum, &retval);
846
847   cspi_return_val_if_ev ("removeSelection", FALSE);
848
849   return retval;
850 }
851
852 /**
853  * AccessibleText_setSelection:
854  * @obj: a pointer to the #AccessibleText object on which to operate.
855  * @selectionNum: a zero-offset index indicating which text selection to modify.
856  * @startOffset: a long int, the new starting offset for the selection.
857  * @endOffset: a long int, the desired new offset of the first character
858  *             after the selection.
859  *
860  * Change the bounds of an existing #AccessibleText text selection.
861  *
862  * Returns: #TRUE if successful, #FALSE otherwise.
863  **/
864 SPIBoolean
865 AccessibleText_setSelection (AccessibleText *obj,
866                              long int selectionNum,
867                              long int startOffset,
868                              long int endOffset)
869 {
870   dbus_int32_t d_selectionNum = selectionNum, d_startOffset = startOffset, d_endOffset = endOffset;
871   dbus_bool_t retval;
872
873   cspi_return_val_if_fail (obj != NULL, FALSE);
874
875   cspi_dbus_call (obj, spi_interface_text, "setSelection", NULL, "iii=>b", d_selectionNum, d_startOffset, d_endOffset, &retval);
876
877   cspi_return_val_if_ev ("setSelection", FALSE);
878
879   return retval;
880 }
881
882
883 /**
884  * AccessibleText_getAttributeRun:
885  * @obj: a pointer to the #AccessibleText object to query.
886  * @offset: a long integer indicating the offset from which the attribute
887  *        search is based.
888  * @startOffset: a #long indicating the start of the desired text range.
889  * @endOffset: a #long indicating the first character past the desired range.
890  * @includeDefaults: a #bool if False, the call should only return those 
891  *                 attributes which are explicitly set on the current attribute 
892  *                 run, omitting any attributes which are inherited from the 
893  *                 default values.
894  *
895  *  @Since: AT-SPI 1.7
896  *
897  * Returns: the AttributeSet defined at offset, optionally including the 'default' attributes.
898  **/
899
900 AccessibleAttributeSet *
901 AccessibleText_getAttributeRun (AccessibleText *obj,
902                                 long int offset,
903                                 long int *startOffset,
904                                 long int *endOffset,
905                                 long int includeDefaults){
906
907   dbus_int32_t d_offset = offset;
908   dbus_bool_t d_includeDefaults = includeDefaults;
909   dbus_int32_t retStartOffset, retEndOffset;
910   AccessibleAttributeSet *retval;
911   GArray *attributes;
912
913   if (obj == NULL)
914   {
915        *startOffset = *endOffset = -1;
916        return NULL;
917   }
918
919   cspi_dbus_call (obj, spi_interface_text, "getAttributeRun", NULL, "ib=>asii", d_offset, d_includeDefaults, &attributes, &retStartOffset, &retEndOffset);
920
921   if (!cspi_check_ev ("getAttributeRun"))
922     {
923       *startOffset = *endOffset = -1;
924       retval = NULL;
925     }
926   else 
927   {
928       *startOffset = retStartOffset;
929       *endOffset   = retEndOffset;
930       retval =  _cspi_attribute_set_from_sequence (attributes);
931   }
932
933   return retval;
934                                      
935 }
936
937 /**
938  * AccessibleText_getDefaultAttributeSet:
939  * @obj: a pointer to the #AccessibleText object to query.
940  *
941  *
942  *  @Since: AT-SPI 1.7
943  *
944  * Returns: an AttributeSet containing the text attributes 
945  * which apply to all text in the object by virtue of the
946  * default settings of the document, view, or user agent; e.g.
947  * those attributes which are implied rather than explicitly 
948  * applied to the text object. For instance, an object whose 
949  * entire text content has been explicitly marked as 'bold' 
950  * will report the 'bold' attribute via getAttributeRun(), 
951  * whereas an object whose text weight is inspecified may 
952  * report the default or implied text weight in the default AttributeSet.
953  *
954  **/
955
956 AccessibleAttributeSet *
957 AccessibleText_getDefaultAttributeSet (AccessibleText *obj){
958    AccessibleAttributeSet *retval;
959    GArray *attributes;
960
961    cspi_return_val_if_fail (obj != NULL, NULL);
962
963   cspi_dbus_call (obj, spi_interface_text, "getDefaultAttributes", NULL, "as", &attributes);
964   
965   retval = _cspi_attribute_set_from_sequence (attributes);
966   return retval;
967 }