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