2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 Ximian, Inc.
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.
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.
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.
24 #include <cspi/spi-private.h>
26 static Accessibility_TEXT_BOUNDARY_TYPE
27 get_accessible_text_boundary_type (AccessibleTextBoundaryType type)
31 case SPI_TEXT_BOUNDARY_CHAR:
32 return Accessibility_TEXT_BOUNDARY_CHAR;
34 case SPI_TEXT_BOUNDARY_CURSOR_POS:
36 return Accessibility_TEXT_BOUNDARY_CHAR;
38 case SPI_TEXT_BOUNDARY_WORD_START:
39 return Accessibility_TEXT_BOUNDARY_WORD_START;
41 case SPI_TEXT_BOUNDARY_WORD_END:
42 return Accessibility_TEXT_BOUNDARY_WORD_END;
44 case SPI_TEXT_BOUNDARY_SENTENCE_START:
45 return Accessibility_TEXT_BOUNDARY_SENTENCE_START;
47 case SPI_TEXT_BOUNDARY_SENTENCE_END:
48 return Accessibility_TEXT_BOUNDARY_SENTENCE_END;
50 case SPI_TEXT_BOUNDARY_LINE_START:
51 return Accessibility_TEXT_BOUNDARY_LINE_START;
53 case SPI_TEXT_BOUNDARY_LINE_END:
54 return Accessibility_TEXT_BOUNDARY_LINE_END;
56 case SPI_TEXT_BOUNDARY_ATTRIBUTE_RANGE:
58 return Accessibility_TEXT_BOUNDARY_CHAR;
62 return Accessibility_TEXT_BOUNDARY_CHAR;
66 static Accessibility_TEXT_CLIP_TYPE
67 get_accessible_text_clip_type (AccessibleTextClipType type)
71 case SPI_TEXT_CLIP_NONE:
72 return Accessibility_TEXT_CLIP_NONE;
74 case SPI_TEXT_CLIP_MIN:
75 return Accessibility_TEXT_CLIP_MIN;
77 case SPI_TEXT_CLIP_MAX:
78 return Accessibility_TEXT_CLIP_MAX;
81 return Accessibility_TEXT_CLIP_BOTH;
85 static AccessibleTextRange **
86 get_accessible_text_ranges_from_range_seq (Accessibility_Text_RangeList *range_seq)
88 AccessibleTextRange **ranges = NULL;
89 AccessibleTextRange *array = NULL;
91 if (range_seq && range_seq->_length > 0)
93 ranges = g_new0 (AccessibleTextRange *, range_seq->_length + 1);
95 array = g_new0 (AccessibleTextRange, range_seq->_length);
96 for (i = 0; i < range_seq->_length; i++)
98 AccessibleTextRange *range;
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);
105 ranges[i] = NULL; /* null-terminated list! */
106 CORBA_free (range_seq);
113 * AccessibleText_ref:
114 * @obj: a pointer to the #AccessibleText object on which to operate.
116 * Increment the reference count for an #AccessibleText object.
119 AccessibleText_ref (AccessibleText *obj)
121 cspi_object_ref (obj);
125 * AccessibleText_unref:
126 * @obj: a pointer to the #Accessible object on which to operate.
128 * Decrement the reference count for an #AccessibleText object.
131 AccessibleText_unref (AccessibleText *obj)
133 cspi_object_unref (obj);
137 * AccessibleText_getCharacterCount:
138 * @obj: a pointer to the #AccessibleText object to query.
140 * Get the character count of an #AccessibleText object.
142 * Returns: a long integer indicating the total number of
143 * characters in the #AccessibleText object.
146 AccessibleText_getCharacterCount (AccessibleText *obj)
150 cspi_return_val_if_fail (obj != NULL, -1);
152 retval = Accessibility_Text__get_characterCount (CSPI_OBJREF (obj), cspi_ev ());
154 cspi_return_val_if_ev ("getCharacterCount", -1);
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.
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.
169 * Returns: a text string containing characters from @startOffset
170 * to @endOffset-1, inclusive, encoded as UTF-8.
173 AccessibleText_getText (AccessibleText *obj,
174 long int startOffset,
179 cspi_return_val_if_fail (obj != NULL, NULL);
182 Accessibility_Text_getText (CSPI_OBJREF (obj),
187 cspi_return_val_if_ev ("getText", NULL);
193 * AccessibleText_getCaretOffset:
194 * @obj: a pointer to the #AccessibleText object to query.
196 * Get the current offset of the text caret in an #AccessibleText object.
198 * Returns: a long integer indicating the current position of the text caret.
201 AccessibleText_getCaretOffset (AccessibleText *obj)
205 cspi_return_val_if_fail (obj != NULL, -1);
208 Accessibility_Text__get_caretOffset (CSPI_OBJREF (obj), cspi_ev ());
210 cspi_return_val_if_ev ("getCaretOffset", -1);
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
220 * @startOffset: a #long indicating the start of the desired text range.
221 * @endOffset: a #long indicating the first character past the desired range.
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
231 * Returns: a text string describing the attributes occurring within the
232 * attribute run containing @offset, encoded as UTF-8.
235 AccessibleText_getAttributes (AccessibleText *obj,
237 long int *startOffset,
240 CORBA_long retStartOffset, retEndOffset;
245 *startOffset = *endOffset = -1;
249 retval = Accessibility_Text_getAttributes (CSPI_OBJREF (obj),
255 if (!cspi_check_ev ("getAttributes"))
257 *startOffset = *endOffset = -1;
262 *startOffset = retStartOffset;
263 *endOffset = retEndOffset;
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.
274 * Set the text caret position for an #AccessibleText object.
276 * Returns: #TRUE if successful, #FALSE otherwise.
279 AccessibleText_setCaretOffset (AccessibleText *obj,
284 cspi_return_val_if_fail (obj != NULL, FALSE);
287 Accessibility_Text_setCaretOffset (CSPI_OBJREF (obj),
288 newOffset, cspi_ev ());
290 cspi_return_val_if_ev ("setCaretOffset", FALSE);
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
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
309 * Get delimited text from an #AccessibleText object which precedes a given
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.
317 AccessibleText_getTextBeforeOffset (AccessibleText *obj,
319 AccessibleTextBoundaryType type,
320 long int *startOffset,
324 CORBA_long retStartOffset, retEndOffset;
328 *startOffset = *endOffset = -1;
332 retval = Accessibility_Text_getTextBeforeOffset (CSPI_OBJREF (obj),
334 get_accessible_text_boundary_type (type),
335 &retStartOffset, &retEndOffset,
337 if (!cspi_check_ev ("getTextBeforeOffset"))
339 *startOffset = *endOffset = -1;
344 *startOffset = retStartOffset;
345 *endOffset = retEndOffset;
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
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
364 * Get delimited text from an #AccessibleText object which includes a given
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.
372 AccessibleText_getTextAtOffset (AccessibleText *obj,
374 AccessibleTextBoundaryType type,
375 long int *startOffset, long int *endOffset)
377 CORBA_long corbaStartOffset;
378 CORBA_long corbaEndOffset;
383 *startOffset = *endOffset = -1;
387 retval = Accessibility_Text_getTextAtOffset (CSPI_OBJREF (obj),
389 get_accessible_text_boundary_type (type),
394 if (!cspi_check_ev ("getTextAtOffset"))
396 *startOffset = *endOffset = -1;
401 *startOffset = corbaStartOffset;
402 *endOffset = corbaEndOffset;
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
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
421 * Get delimited text from an #AccessibleText object which follows a given
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.
429 AccessibleText_getTextAfterOffset (AccessibleText *obj,
431 AccessibleTextBoundaryType type,
432 long int *startOffset, long int *endOffset)
435 CORBA_long retStartOffset, retEndOffset;
439 *startOffset = *endOffset = -1;
443 retval = Accessibility_Text_getTextAfterOffset (CSPI_OBJREF (obj),
445 get_accessible_text_boundary_type (type),
446 &retStartOffset, &retEndOffset,
449 if (!cspi_check_ev ("getTextAfterOffset"))
451 *startOffset = *endOffset = -1;
456 *startOffset = retStartOffset;
457 *endOffset = retEndOffset;
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.
468 * Get the character at a given offset for an #AccessibleText object.
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.
476 AccessibleText_getCharacterAtOffset (AccessibleText *obj,
481 cspi_return_val_if_fail (obj != NULL, -1);
484 Accessibility_Text_getCharacterAtOffset (CSPI_OBJREF (obj),
488 cspi_return_val_if_ev ("getCharacterAtOffset", -1);
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.
509 * Get the bounding box containing the glyph representing
510 * the character at a particular text offset.
513 AccessibleText_getCharacterExtents (AccessibleText *obj,
519 AccessibleCoordType type)
521 CORBA_long retX, retY, retWidth, retHeight;
526 *width = *height = -1;
530 Accessibility_Text_getCharacterExtents (CSPI_OBJREF (obj),
538 if (!cspi_check_ev ("getCharacterExtents"))
541 *width = *height = -1;
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.
560 * Get the bounding box for a glyph at a certain #AccessibleText offset.
562 * Returns: the offset (as a long integer) at the point (@x, @y)
563 * in the specified coordinate system.
567 AccessibleText_getOffsetAtPoint (AccessibleText *obj,
570 AccessibleCoordType type)
574 cspi_return_val_if_fail (obj != NULL, -1);
577 Accessibility_Text_getOffsetAtPoint (CSPI_OBJREF (obj),
582 cspi_return_val_if_ev ("getOffsetAtPoint", -1);
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.
605 * Get the bounding box for text within a range in an #AccessibleText object.
607 * Returns: the bounding-box extents of the specified text range,
608 * in the specified coordinate system.
612 AccessibleText_getRangeExtents (AccessibleText *obj,
613 long int startOffset,
619 AccessibleCoordType type)
621 CORBA_long retX, retY, retWidth, retHeight;
626 *width = *height = -1;
630 Accessibility_Text_getRangeExtents (CSPI_OBJREF (obj),
639 if (!cspi_check_ev ("getRangeExtents"))
642 *width = *height = -1;
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.
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).
670 * Returns: a null-terminated list of pointers to AccessibleTextRange structs
671 * detailing the bounded text.
673 AccessibleTextRange **
674 AccessibleText_getBoundedRanges (AccessibleText *obj,
679 AccessibleCoordType type,
680 AccessibleTextClipType clipTypeX,
681 AccessibleTextClipType clipTypeY)
683 Accessibility_Text_RangeList *range_seq;
685 cspi_return_val_if_fail (obj != NULL, NULL);
688 Accessibility_Text_getBoundedRanges (CSPI_OBJREF (obj),
691 get_accessible_text_clip_type (clipTypeX),
692 get_accessible_text_clip_type (clipTypeY),
695 cspi_return_val_if_ev ("getBoundedRanges", NULL);
697 return get_accessible_text_ranges_from_range_seq (range_seq);
701 * AccessibleTextRange_freeRanges:
702 * @ranges: a pointer to an array of AccessibleTextRange structs.
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.
709 AccessibleTextRange_freeRanges (AccessibleTextRange **ranges)
711 /* this was a contiguously allocated block, only free the first element */
717 * AccessibleText_getNSelections:
718 * @obj: a pointer to the #AccessibleText object on which to operate.
720 * Get the number of active non-contiguous selections for an
721 * #AccessibleText object.
723 * Returns: a long integer indicating the current
724 * number of non-contiguous text selections active
725 * within an #AccessibleText object.
728 AccessibleText_getNSelections (AccessibleText *obj)
732 cspi_return_val_if_fail (obj != NULL, -1);
735 Accessibility_Text_getNSelections (CSPI_OBJREF (obj), cspi_ev ());
737 cspi_return_val_if_ev ("getNSelections", -1);
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.
751 * Get the bounds of the @selectionNum-th active text selection for an
752 * #AccessibleText object.
755 AccessibleText_getSelection (AccessibleText *obj,
756 long int selectionNum,
757 long int *startOffset,
760 CORBA_long retStartOffset, retEndOffset;
764 *endOffset = *startOffset = -1;
768 Accessibility_Text_getSelection (CSPI_OBJREF (obj),
770 &retStartOffset, &retEndOffset,
773 if (!cspi_check_ev ("getSelection"))
775 *startOffset = *endOffset = -1;
779 *startOffset = retStartOffset;
780 *endOffset = retEndOffset;
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.
790 * Select some text (add a text selection) in an #AccessibleText object.
792 * Returns: #TRUE if successful, #FALSE otherwise.
795 AccessibleText_addSelection (AccessibleText *obj,
796 long int startOffset, long int endOffset)
800 cspi_return_val_if_fail (obj != NULL, FALSE);
803 Accessibility_Text_addSelection (
804 CSPI_OBJREF (obj), startOffset,
805 endOffset, cspi_ev ());
807 cspi_return_val_if_ev ("addSelection", FALSE);
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.
818 * De-select a text selection.
820 * Returns: #TRUE if successful, #FALSE otherwise.
823 AccessibleText_removeSelection (AccessibleText *obj,
824 long int selectionNum)
828 cspi_return_val_if_fail (obj != NULL, FALSE);
831 Accessibility_Text_removeSelection (
832 CSPI_OBJREF (obj), selectionNum, cspi_ev ());
834 cspi_return_val_if_ev ("removeSelection", FALSE);
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.
847 * Change the bounds of an existing #AccessibleText text selection.
849 * Returns: #TRUE if successful, #FALSE otherwise.
852 AccessibleText_setSelection (AccessibleText *obj,
853 long int selectionNum,
854 long int startOffset,
859 cspi_return_val_if_fail (obj != NULL, FALSE);
861 retval = Accessibility_Text_setSelection (CSPI_OBJREF (obj),
864 endOffset, cspi_ev ());
866 cspi_return_val_if_ev ("setSelection", FALSE);