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