Revved to 1.7.4; Fixes for cspi event handlers for EventDetails.
[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  * Returns: a text string describing the default attributes 
284  *          applied to a text object, (exclusive of explicitly-set
285  *          attributes), encoded as UTF-8.
286  **/
287 char *
288 AccessibleText_getDefaultAttributes (AccessibleText *obj)
289 {
290   char *retval; 
291
292   if (obj == NULL)
293     {
294       return NULL;
295     }
296
297   retval = Accessibility_Text_getDefaultAttributes (CSPI_OBJREF (obj),
298                                                     cspi_ev ());
299
300   if (!cspi_check_ev ("getAttributes"))
301     {
302       retval = NULL;
303     }
304
305   return retval;
306 }
307
308 /**
309  * AccessibleText_setCaretOffset:
310  * @obj: a pointer to the #AccessibleText object on which to operate.
311  * @newOffset: the offset to which the text caret is to be moved.
312  *
313  * Set the text caret position for an #AccessibleText object.
314  *
315  * Returns: #TRUE if successful, #FALSE otherwise.
316  **/
317 SPIBoolean
318 AccessibleText_setCaretOffset (AccessibleText *obj,
319                                long int newOffset)
320 {
321   SPIBoolean retval;
322
323   cspi_return_val_if_fail (obj != NULL, FALSE);
324
325   retval =
326     Accessibility_Text_setCaretOffset (CSPI_OBJREF (obj),
327                                        newOffset, cspi_ev ());
328
329   cspi_return_val_if_ev ("setCaretOffset", FALSE);
330
331   return retval;
332 }
333
334 /**
335  * AccessibleText_getTextBeforeOffset:
336  * @obj: a pointer to the #AccessibleText object on which to operate.
337  * @offset: a long integer indicating the offset from which the delimiter
338  *        search is based.
339  * @type: an #AccessibleTextBoundaryType indicating whether the desired
340  *       text string is a word, sentence, line, or attribute run.
341  * @startOffset: a pointer to a long integer which is assigned the
342  *       starting offset of the returned string, relative to the
343  *       original #AccessibleText.
344  * @endOffset: a pointer to a long integer which is assigned the
345  *       ending offset of the returned string, relative to the original
346  *       #AccessibleText.
347  *
348  * Get delimited text from an #AccessibleText object which precedes a given
349  *          text offset.
350  *
351  * Returns: a UTF-8 string representing the delimited text, both of whose
352  *          delimiting boundaries are before the current offset, or
353  *          an empty string if no such text exists.
354  **/
355 char *
356 AccessibleText_getTextBeforeOffset (AccessibleText *obj,
357                                     long int offset,
358                                     AccessibleTextBoundaryType type,
359                                     long int *startOffset,
360                                     long int *endOffset)
361 {
362   char *retval;
363   CORBA_long retStartOffset, retEndOffset;
364
365   if (obj == NULL)
366     {
367       *startOffset = *endOffset = -1;
368       return NULL;
369     }
370
371   retval = Accessibility_Text_getTextBeforeOffset (CSPI_OBJREF (obj),
372                                            offset,
373                         get_accessible_text_boundary_type (type),
374                                            &retStartOffset, &retEndOffset,
375                                            cspi_ev ());
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   CORBA_long corbaStartOffset;
417   CORBA_long corbaEndOffset;
418   char      *retval;
419
420   if (obj == NULL)
421     {
422       *startOffset = *endOffset = -1;
423       return NULL;
424     }
425
426   retval = Accessibility_Text_getTextAtOffset (CSPI_OBJREF (obj),
427                                                offset,
428                           get_accessible_text_boundary_type (type),
429                                                &corbaStartOffset,
430                                                &corbaEndOffset,
431                                                cspi_ev ());
432
433   if (!cspi_check_ev ("getTextAtOffset"))
434     {
435       *startOffset = *endOffset = -1;
436       retval = NULL;
437     }
438   else
439     {
440       *startOffset = corbaStartOffset;
441       *endOffset   = corbaEndOffset;
442     }
443   return retval;
444 }
445
446 /**
447  * AccessibleText_getTextAfterOffset:
448  * @obj: a pointer to the #AccessibleText object on which to operate.
449  * @offset: a long integer indicating the offset from which the delimiter
450  *        search is based.
451  * @type: an #AccessibleTextBoundaryType indicating whether the desired
452  *       text string is a word, sentence, line, or attribute run.
453  * @startOffset: a pointer to a long integer which is assigned the
454  *       starting offset of the returned string, relative to the
455  *       original #AccessibleText.
456  * @endOffset: a pointer to a long integer which is assigned the
457  *       ending offset of the returned string, relative to the original
458  *       #AccessibleText.
459  *
460  * Get delimited text from an #AccessibleText object which follows a given
461  *          text offset.
462  *
463  * Returns: a UTF-8 string representing the delimited text, both of whose
464  *          delimiting boundaries are after or inclusive of the current
465  *          offset, or an empty string if no such text exists.
466  **/
467 char *
468 AccessibleText_getTextAfterOffset (AccessibleText *obj,
469                                    long int offset,
470                                    AccessibleTextBoundaryType type,
471                                    long int *startOffset, long int *endOffset)
472 {
473   char *retval;
474   CORBA_long retStartOffset, retEndOffset;
475
476   if (obj == NULL)
477     {
478       *startOffset = *endOffset = -1;
479       return NULL;
480     }
481
482   retval = Accessibility_Text_getTextAfterOffset (CSPI_OBJREF (obj),
483                                            offset,
484                              get_accessible_text_boundary_type (type),
485                                            &retStartOffset, &retEndOffset,
486                                            cspi_ev ());
487
488   if (!cspi_check_ev ("getTextAfterOffset"))
489     {
490       *startOffset = *endOffset = -1;
491       retval = NULL;
492     }
493   else
494     {
495       *startOffset = retStartOffset;
496       *endOffset   = retEndOffset;
497     }
498   return retval;
499 }
500
501 /**
502  * AccessibleText_getCharacterAtOffset:
503  * @obj: a pointer to the #AccessibleText object on which to operate.
504  * @offset: a long integer indicating the text offset where the desired
505  *          character is located.
506  *
507  * Get the character at a given offset for an #AccessibleText object.
508  *
509  * Returns: an #unsigned long integer which represents the
510  *        UCS-4 unicode code point of the given character, or
511  *        0xFFFFFFFF if the character in question cannot be represented
512  *        in the UCS-4 encoding.
513  **/
514 unsigned long
515 AccessibleText_getCharacterAtOffset (AccessibleText *obj,
516                                      long int offset)
517 {
518   long retval;
519
520   cspi_return_val_if_fail (obj != NULL, -1);
521
522   retval =
523     Accessibility_Text_getCharacterAtOffset (CSPI_OBJREF (obj),
524                                              offset,
525                                              cspi_ev ());
526
527   cspi_return_val_if_ev ("getCharacterAtOffset", -1);
528
529   return retval;
530 }
531
532 /**
533  * AccessibleText_getCharacterExtents:
534  * @obj: a pointer to the #AccessibleText object on which to operate.
535  * @offset: an integer indicating the offset of the text character for
536  *        whom boundary information is requested.
537  * @x: a pointer to a long integer into which the nominal x coordinate
538  *     of the corresponding glyph will be returned.
539  * @y:a pointer to a long integer into which the nominal y coordinate
540  *     of the corresponding glyph will be returned.
541  * @width:a pointer to a long integer into which the width
542  *     of the corresponding glyph will be returned.
543  * @height: a pointer to a long integer into which the height
544  *     of the corresponding glyph will be returned.
545  * @type: an #AccessibleCoordType indicating the coordinate system to use
546  *        for the returned values.
547  *
548  * Get the bounding box containing the glyph representing
549  *        the character at a particular text offset.
550  **/
551 void
552 AccessibleText_getCharacterExtents (AccessibleText *obj,
553                                     long int offset,
554                                     long int *x,
555                                     long int *y,
556                                     long int *width,
557                                     long int *height,
558                                     AccessibleCoordType type)
559 {
560   CORBA_long retX, retY, retWidth, retHeight;
561
562   if (obj == NULL)
563     {
564       *x = *y = -1;
565       *width = *height = -1;
566       return;
567     }
568
569   Accessibility_Text_getCharacterExtents (CSPI_OBJREF (obj),
570                                           offset,
571                                           &retX,
572                                           &retY,
573                                           &retWidth,
574                                           &retHeight,
575                                           type, cspi_ev ());
576
577   if (!cspi_check_ev ("getCharacterExtents"))
578     {
579       *x = *y = -1;
580       *width = *height = -1;
581     }
582   else
583     {
584       *x = retX;
585       *y = retY;
586       *width = retWidth;
587       *height = retHeight;
588     }
589 }
590
591 /**
592  * AccessibleText_getOffsetAtPoint:
593  * @obj: a pointer to the #AccessibleText object on which to operate.
594  * @x: the x coordinate of the point to be queried.
595  * @y: the y coordinate of the point to be queried.
596  * @type: an #AccessibleCoordType indicating the coordinate system in which
597  *       the values should be returned.
598  *
599  * Get the bounding box for a glyph at a certain #AccessibleText offset.
600  *
601  * Returns: the offset (as a long integer) at the point (@x, @y)
602  *       in the specified coordinate system.
603  *
604  **/
605 long
606 AccessibleText_getOffsetAtPoint (AccessibleText *obj,
607                                  long int x,
608                                  long int y,
609                                  AccessibleCoordType type)
610 {
611   long retval;
612
613   cspi_return_val_if_fail (obj != NULL, -1);
614
615   retval =
616     Accessibility_Text_getOffsetAtPoint (CSPI_OBJREF (obj),
617                                          x,
618                                          y,
619                                          type, cspi_ev ());
620
621   cspi_return_val_if_ev ("getOffsetAtPoint", -1);
622
623   return retval;
624 }
625
626 /**
627  * AccessibleText_getRangeExtents:
628  * @obj: a pointer to the #AccessibleText object on which to operate.
629  * @startOffset: an integer indicating the offset of the first text character for
630  *        whom boundary information is requested.
631  * @endOffset: an integer indicating the offset of the text character 
632  *        after the last character for whom boundary information is requested.
633  * @x: a pointer to a long integer into which the nominal x coordinate
634  *     of the corresponding bounding box will be returned.
635  * @y:a pointer to a long integer into which the nominal y coordinate
636  *     of the corresponding bounding box will be returned.
637  * @width:a pointer to a long integer into which the width
638  *     of the corresponding bounding box will be returned.
639  * @height: a pointer to a long integer into which the height
640  *     of the corresponding bounding box will be returned.
641  * @type: an #AccessibleCoordType indicating the coordinate system to use
642  *        for the returned values.
643  *
644  * Get the bounding box for text within a range in an  #AccessibleText object.
645  *
646  **/
647 void
648 AccessibleText_getRangeExtents (AccessibleText *obj,
649                                 long int startOffset,
650                                 long int endOffset,
651                                 long int *x,
652                                 long int *y,
653                                 long int *width,
654                                 long int *height,
655                                 AccessibleCoordType type)
656 {
657   CORBA_long retX, retY, retWidth, retHeight;
658
659   if (obj == NULL)
660     {
661       *x = *y = -1;
662       *width = *height = -1;
663       return;
664     }
665
666   Accessibility_Text_getRangeExtents (CSPI_OBJREF (obj),
667                                       startOffset,
668                                       endOffset,
669                                       &retX,
670                                       &retY,
671                                       &retWidth,
672                                       &retHeight,
673                                       type, cspi_ev ());
674
675   if (!cspi_check_ev ("getRangeExtents"))
676     {
677       *x = *y = -1;
678       *width = *height = -1;
679     }
680   else
681     {
682       *x = retX;
683       *y = retY;
684       *width = retWidth;
685       *height = retHeight;
686     }
687 }
688
689 /**
690  * AccessibleText_getBoundedRanges:
691  * @obj: a pointer to the #AccessibleText object on which to operate.
692  * @x: the 'starting' x coordinate of the bounding box.
693  * @y: the 'starting' y coordinate of the bounding box.
694  * @width: the x extent of the bounding box.
695  * @height: the y extent of the bounding box.
696  * @type: an #AccessibleCoordType indicating the coordinate system to use
697  *        for the returned values.
698  * @clipTypeX: an #AccessibleTextClipType indicating how to treat characters that
699  *        intersect the bounding box's x extents.
700  * @clipTypeY: an #AccessibleTextClipType indicating how to treat characters that
701  *        intersect the bounding box's y extents.
702  *
703  * Get the ranges of text from an #AccessibleText object which lie within the
704  *          bounds defined by (@x, @y) and (@x+@width, @y+@height).  
705  *
706  * Returns: a null-terminated list of pointers to AccessibleTextRange structs 
707  *          detailing the bounded text.
708  **/
709 AccessibleTextRange **
710 AccessibleText_getBoundedRanges (AccessibleText *obj,
711                                  long int x,
712                                  long int y,
713                                  long int width,
714                                  long int height,
715                                  AccessibleCoordType type,
716                                  AccessibleTextClipType clipTypeX,
717                                  AccessibleTextClipType clipTypeY)
718 {
719   Accessibility_Text_RangeList *range_seq;
720
721   cspi_return_val_if_fail (obj != NULL, NULL);
722
723   range_seq =
724     Accessibility_Text_getBoundedRanges (CSPI_OBJREF (obj), 
725                                          x, y, width, height,
726                                          type, 
727                                          get_accessible_text_clip_type (clipTypeX), 
728                                          get_accessible_text_clip_type (clipTypeY),
729                                          cspi_ev ());
730
731   cspi_return_val_if_ev ("getBoundedRanges", NULL); 
732  
733   return get_accessible_text_ranges_from_range_seq (range_seq);
734 }
735
736 /**
737  * AccessibleTextRange_freeRanges:
738  * @ranges: a pointer to an array of AccessibleTextRange structs.
739  *
740  * Free the memory used by a list of AccessibleTextRange structs.
741  * The argument passed in should be an array of pointers 
742  * AccessibleTextRange structs.  
743  **/
744 void
745 AccessibleTextRange_freeRanges (AccessibleTextRange **ranges)
746 {
747   /* this was a contiguously allocated block, only free the first element */
748   g_free (ranges[0]); 
749   g_free (ranges);
750 }
751
752 /**
753  * AccessibleText_getNSelections:
754  * @obj: a pointer to the #AccessibleText object on which to operate.
755  *
756  * Get the number of active non-contiguous selections for an
757  *          #AccessibleText object.
758  *
759  * Returns: a long integer indicating the current
760  *          number of non-contiguous text selections active
761  *          within an #AccessibleText object.
762  **/
763 long
764 AccessibleText_getNSelections (AccessibleText *obj)
765 {
766   long retval;
767
768   cspi_return_val_if_fail (obj != NULL, -1);
769
770   retval =
771     Accessibility_Text_getNSelections (CSPI_OBJREF (obj), cspi_ev ());
772
773   cspi_return_val_if_ev ("getNSelections", -1);
774
775   return retval;
776 }
777
778 /**
779  * AccessibleText_getSelection:
780  * @obj: a pointer to the #AccessibleText object on which to operate.
781  * @selectionNum: an integer indicating which selection to query.
782  * @startOffset: a pointer to a long integer into which the start offset
783  *           of the selection will be returned.
784  * @endOffset: a pointer to a long integer into which the start offset
785  *           of the selection will be returned.
786  *
787  * Get the bounds of the @selectionNum-th active text selection for an
788  *         #AccessibleText object.
789  **/
790 void
791 AccessibleText_getSelection (AccessibleText *obj,
792                              long int selectionNum,
793                              long int *startOffset,
794                              long int *endOffset)
795 {
796   CORBA_long retStartOffset, retEndOffset;
797
798   if (obj == NULL)
799     {
800       *endOffset = *startOffset = -1;
801       return;
802     }
803
804   Accessibility_Text_getSelection (CSPI_OBJREF (obj),
805                                    selectionNum,
806                                    &retStartOffset, &retEndOffset,
807                                    cspi_ev ());
808
809   if (!cspi_check_ev ("getSelection"))
810     {
811       *startOffset = *endOffset = -1;
812     }
813   else
814     {
815       *startOffset = retStartOffset;
816       *endOffset   = retEndOffset;
817     }
818 }
819
820 /**
821  * AccessibleText_addSelection:
822  * @obj: a pointer to the #AccessibleText object on which to operate.
823  * @startOffset: the starting offset of the desired new selection.
824  * @endOffset: the offset of the first character after the new selection.
825  *
826  * Select some text (add a text selection) in an #AccessibleText object.
827  *
828  * Returns: #TRUE if successful, #FALSE otherwise.
829  **/
830 SPIBoolean
831 AccessibleText_addSelection (AccessibleText *obj,
832                              long int startOffset, long int endOffset)
833 {
834   SPIBoolean retval;
835
836   cspi_return_val_if_fail (obj != NULL, FALSE);
837
838   retval =
839     Accessibility_Text_addSelection (
840       CSPI_OBJREF (obj), startOffset,
841       endOffset, cspi_ev ());
842
843   cspi_return_val_if_ev ("addSelection", FALSE);
844
845   return retval;
846 }
847
848 /**
849  * AccessibleText_removeSelection:
850  * @obj: a pointer to the #AccessibleText object on which to operate.
851  * @selectionNum: an integer indicating which (possibly of several)
852  *         text selection to remove.
853  *
854  * De-select a text selection.
855  *
856  * Returns: #TRUE if successful, #FALSE otherwise.
857  **/
858 SPIBoolean
859 AccessibleText_removeSelection (AccessibleText *obj,
860                                 long int selectionNum)
861 {
862   SPIBoolean retval;
863
864   cspi_return_val_if_fail (obj != NULL, FALSE);
865
866   retval =
867     Accessibility_Text_removeSelection (
868       CSPI_OBJREF (obj), selectionNum, cspi_ev ());
869
870   cspi_return_val_if_ev ("removeSelection", FALSE);
871
872   return retval;
873 }
874
875 /**
876  * AccessibleText_setSelection:
877  * @obj: a pointer to the #AccessibleText object on which to operate.
878  * @selectionNum: a zero-offset index indicating which text selection to modify.
879  * @startOffset: a long int, the new starting offset for the selection.
880  * @endOffset: a long int, the desired new offset of the first character
881  *             after the selection.
882  *
883  * Change the bounds of an existing #AccessibleText text selection.
884  *
885  * Returns: #TRUE if successful, #FALSE otherwise.
886  **/
887 SPIBoolean
888 AccessibleText_setSelection (AccessibleText *obj,
889                              long int selectionNum,
890                              long int startOffset,
891                              long int endOffset)
892 {
893   SPIBoolean retval;
894
895   cspi_return_val_if_fail (obj != NULL, FALSE);
896
897   retval = Accessibility_Text_setSelection (CSPI_OBJREF (obj),
898                                    selectionNum,
899                                    startOffset,
900                                    endOffset, cspi_ev ());
901
902   cspi_return_val_if_ev ("setSelection", FALSE);
903
904   return retval;
905 }
906
907
908