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;
65 static Accessibility_TEXT_CLIP_TYPE
66 get_accessible_text_clip_type (AccessibleTextClipType type)
70 case SPI_TEXT_CLIP_NONE:
71 return Accessibility_TEXT_CLIP_NONE;
73 case SPI_TEXT_CLIP_MIN:
74 return Accessibility_TEXT_CLIP_MIN;
76 case SPI_TEXT_CLIP_MAX:
77 return Accessibility_TEXT_CLIP_MAX;
80 return Accessibility_TEXT_CLIP_BOTH;
83 static AccessibleTextRange **
84 get_accessible_text_ranges_from_range_seq (Accessibility_Text_RangeList *range_seq)
86 AccessibleTextRange **ranges = NULL;
87 AccessibleTextRange *array = NULL;
89 if (range_seq && range_seq->_length > 0)
91 ranges = g_new0 (AccessibleTextRange *, range_seq->_length + 1);
93 array = g_new0 (AccessibleTextRange, range_seq->_length);
94 for (i = 0; i < range_seq->_length; i++)
96 AccessibleTextRange *range;
98 range->start = range_seq->_buffer[i].startOffset;
99 range->end = range_seq->_buffer[i].endOffset;
100 range->contents = CORBA_string_dup (range_seq->_buffer[i].content);
103 ranges[i] = NULL; /* null-terminated list! */
104 CORBA_free (range_seq);
111 * AccessibleText_ref:
112 * @obj: a pointer to the #AccessibleText object on which to operate.
114 * Increment the reference count for an #AccessibleText object.
117 AccessibleText_ref (AccessibleText *obj)
119 cspi_object_ref (obj);
123 * AccessibleText_unref:
124 * @obj: a pointer to the #Accessible object on which to operate.
126 * Decrement the reference count for an #AccessibleText object.
129 AccessibleText_unref (AccessibleText *obj)
131 cspi_object_unref (obj);
135 * AccessibleText_getCharacterCount:
136 * @obj: a pointer to the #AccessibleText object to query.
138 * Get the character count of an #AccessibleText object.
140 * Returns: a long integer indicating the total number of
141 * characters in the #AccessibleText object.
144 AccessibleText_getCharacterCount (AccessibleText *obj)
148 cspi_return_val_if_fail (obj != NULL, -1);
150 retval = Accessibility_Text__get_characterCount (CSPI_OBJREF (obj), cspi_ev ());
152 cspi_return_val_if_ev ("getCharacterCount", -1);
158 * AccessibleText_getText:
159 * @obj: a pointer to the #AccessibleText object to query.
160 * @startOffset: a #long indicating the start of the desired text range.
161 * @endOffset: a #long indicating the first character past the desired range.
163 * Get a range of text from an #AccessibleText object. The number of bytes
164 * in the returned string may exceed endOffset-startOffset, since
165 * UTF-8 is a variable-width encoding.
167 * Returns: a text string containing characters from @startOffset
168 * to @endOffset-1, inclusive, encoded as UTF-8.
171 AccessibleText_getText (AccessibleText *obj,
172 long int startOffset,
177 cspi_return_val_if_fail (obj != NULL, NULL);
180 Accessibility_Text_getText (CSPI_OBJREF (obj),
185 cspi_return_val_if_ev ("getText", NULL);
191 * AccessibleText_getCaretOffset:
192 * @obj: a pointer to the #AccessibleText object to query.
194 * Get the current offset of the text caret in an #AccessibleText object.
196 * Returns: a long integer indicating the current position of the text caret.
199 AccessibleText_getCaretOffset (AccessibleText *obj)
203 cspi_return_val_if_fail (obj != NULL, -1);
206 Accessibility_Text__get_caretOffset (CSPI_OBJREF (obj), cspi_ev ());
208 cspi_return_val_if_ev ("getCaretOffset", -1);
214 * AccessibleText_getAttributes:
215 * @obj: a pointer to the #AccessibleText object to query.
216 * @offset: a long integer indicating the offset from which the attribute
218 * @startOffset: a #long indicating the start of the desired text range.
219 * @endOffset: a #long indicating the first character past the desired range.
221 * Get the attributes applied to a range of text from an #AccessibleText
222 * object, and the bounds of the range.
223 * The text attributes correspond to CSS attributes where possible,
224 * keys and values are delimited from one another via ":", and
225 * the delimiter between key/value pairs is ";". Thus
226 * "font-size:10;foreground-color:0,0,0" would be a valid
229 * Returns: a text string describing the attributes occurring within the
230 * attribute run containing @offset, encoded as UTF-8.
233 AccessibleText_getAttributes (AccessibleText *obj,
235 long int *startOffset,
238 CORBA_long retStartOffset, retEndOffset;
243 *startOffset = *endOffset = -1;
247 retval = Accessibility_Text_getAttributes (CSPI_OBJREF (obj),
253 if (!cspi_check_ev ("getAttributes"))
255 *startOffset = *endOffset = -1;
260 *startOffset = retStartOffset;
261 *endOffset = retEndOffset;
268 * AccessibleText_setCaretOffset:
269 * @obj: a pointer to the #AccessibleText object on which to operate.
270 * @newOffset: the offset to which the text caret is to be moved.
272 * Set the text caret position for an #AccessibleText object.
274 * Returns: #TRUE if successful, #FALSE otherwise.
277 AccessibleText_setCaretOffset (AccessibleText *obj,
282 cspi_return_val_if_fail (obj != NULL, FALSE);
285 Accessibility_Text_setCaretOffset (CSPI_OBJREF (obj),
286 newOffset, cspi_ev ());
288 cspi_return_val_if_ev ("setCaretOffset", FALSE);
294 * AccessibleText_getTextBeforeOffset:
295 * @obj: a pointer to the #AccessibleText object on which to operate.
296 * @offset: a long integer indicating the offset from which the delimiter
298 * @type: an #AccessibleTextBoundaryType indicating whether the desired
299 * text string is a word, sentence, line, or attribute run.
300 * @startOffset: a pointer to a long integer which is assigned the
301 * starting offset of the returned string, relative to the
302 * original #AccessibleText.
303 * @endOffset: a pointer to a long integer which is assigned the
304 * ending offset of the returned string, relative to the original
307 * Get delimited text from an #AccessibleText object which precedes a given
310 * Returns: a UTF-8 string representing the delimited text, both of whose
311 * delimiting boundaries are before the current offset, or
312 * an empty string if no such text exists.
315 AccessibleText_getTextBeforeOffset (AccessibleText *obj,
317 AccessibleTextBoundaryType type,
318 long int *startOffset,
322 CORBA_long retStartOffset, retEndOffset;
326 *startOffset = *endOffset = -1;
330 retval = Accessibility_Text_getTextBeforeOffset (CSPI_OBJREF (obj),
332 get_accessible_text_boundary_type (type),
333 &retStartOffset, &retEndOffset,
335 if (!cspi_check_ev ("getTextBeforeOffset"))
337 *startOffset = *endOffset = -1;
342 *startOffset = retStartOffset;
343 *endOffset = retEndOffset;
349 * AccessibleText_getTextAtOffset:
350 * @obj: a pointer to the #AccessibleText object on which to operate.
351 * @offset: a long integer indicating the offset from which the delimiter
353 * @type: an #AccessibleTextBoundaryType indicating whether the desired
354 * text string is a word, sentence, line, or attribute run.
355 * @startOffset: a pointer to a long integer which is assigned the
356 * starting offset of the returned string, relative to the
357 * original #AccessibleText.
358 * @endOffset: a pointer to a long integer which is assigned the
359 * ending offset of the returned string, relative to the original
362 * Get delimited text from an #AccessibleText object which includes a given
365 * Returns: a UTF-8 string representing the delimited text, whose
366 * delimiting boundaries bracket the current offset, or
367 * an empty string if no such text exists.
370 AccessibleText_getTextAtOffset (AccessibleText *obj,
372 AccessibleTextBoundaryType type,
373 long int *startOffset, long int *endOffset)
375 CORBA_long corbaStartOffset;
376 CORBA_long corbaEndOffset;
381 *startOffset = *endOffset = -1;
385 retval = Accessibility_Text_getTextAtOffset (CSPI_OBJREF (obj),
387 get_accessible_text_boundary_type (type),
392 if (!cspi_check_ev ("getTextAtOffset"))
394 *startOffset = *endOffset = -1;
399 *startOffset = corbaStartOffset;
400 *endOffset = corbaEndOffset;
406 * AccessibleText_getTextAfterOffset:
407 * @obj: a pointer to the #AccessibleText object on which to operate.
408 * @offset: a long integer indicating the offset from which the delimiter
410 * @type: an #AccessibleTextBoundaryType indicating whether the desired
411 * text string is a word, sentence, line, or attribute run.
412 * @startOffset: a pointer to a long integer which is assigned the
413 * starting offset of the returned string, relative to the
414 * original #AccessibleText.
415 * @endOffset: a pointer to a long integer which is assigned the
416 * ending offset of the returned string, relative to the original
419 * Get delimited text from an #AccessibleText object which follows a given
422 * Returns: a UTF-8 string representing the delimited text, both of whose
423 * delimiting boundaries are after or inclusive of the current
424 * offset, or an empty string if no such text exists.
427 AccessibleText_getTextAfterOffset (AccessibleText *obj,
429 AccessibleTextBoundaryType type,
430 long int *startOffset, long int *endOffset)
433 CORBA_long retStartOffset, retEndOffset;
437 *startOffset = *endOffset = -1;
441 retval = Accessibility_Text_getTextAfterOffset (CSPI_OBJREF (obj),
443 get_accessible_text_boundary_type (type),
444 &retStartOffset, &retEndOffset,
447 if (!cspi_check_ev ("getTextAfterOffset"))
449 *startOffset = *endOffset = -1;
454 *startOffset = retStartOffset;
455 *endOffset = retEndOffset;
461 * AccessibleText_getCharacterAtOffset:
462 * @obj: a pointer to the #AccessibleText object on which to operate.
463 * @offset: a long integer indicating the text offset where the desired
464 * character is located.
466 * Get the character at a given offset for an #AccessibleText object.
468 * Returns: an #unsigned long integer which represents the
469 * UCS-4 unicode code point of the given character, or
470 * 0xFFFFFFFF if the character in question cannot be represented
471 * in the UCS-4 encoding.
474 AccessibleText_getCharacterAtOffset (AccessibleText *obj,
479 cspi_return_val_if_fail (obj != NULL, -1);
482 Accessibility_Text_getCharacterAtOffset (CSPI_OBJREF (obj),
486 cspi_return_val_if_ev ("getCharacterAtOffset", -1);
492 * AccessibleText_getCharacterExtents:
493 * @obj: a pointer to the #AccessibleText object on which to operate.
494 * @offset: an integer indicating the offset of the text character for
495 * whom boundary information is requested.
496 * @x: a pointer to a long integer into which the nominal x coordinate
497 * of the corresponding glyph will be returned.
498 * @y:a pointer to a long integer into which the nominal y coordinate
499 * of the corresponding glyph will be returned.
500 * @width:a pointer to a long integer into which the width
501 * of the corresponding glyph will be returned.
502 * @height: a pointer to a long integer into which the height
503 * of the corresponding glyph will be returned.
504 * @type: an #AccessibleCoordType indicating the coordinate system to use
505 * for the returned values.
507 * Get the bounding box containing the glyph representing
508 * the character at a particular text offset.
511 AccessibleText_getCharacterExtents (AccessibleText *obj,
517 AccessibleCoordType type)
519 CORBA_long retX, retY, retWidth, retHeight;
524 *width = *height = -1;
528 Accessibility_Text_getCharacterExtents (CSPI_OBJREF (obj),
536 if (!cspi_check_ev ("getCharacterExtents"))
539 *width = *height = -1;
551 * AccessibleText_getOffsetAtPoint:
552 * @obj: a pointer to the #AccessibleText object on which to operate.
553 * @x: the x coordinate of the point to be queried.
554 * @y: the y coordinate of the point to be queried.
555 * @type: an #AccessibleCoordType indicating the coordinate system in which
556 * the values should be returned.
558 * Get the bounding box for a glyph at a certain #AccessibleText offset.
560 * Returns: the offset (as a long integer) at the point (@x, @y)
561 * in the specified coordinate system.
565 AccessibleText_getOffsetAtPoint (AccessibleText *obj,
568 AccessibleCoordType type)
572 cspi_return_val_if_fail (obj != NULL, -1);
575 Accessibility_Text_getOffsetAtPoint (CSPI_OBJREF (obj),
580 cspi_return_val_if_ev ("getOffsetAtPoint", -1);
586 * AccessibleText_getRangeExtents:
587 * @obj: a pointer to the #AccessibleText object on which to operate.
588 * @startOffset: an integer indicating the offset of the first text character for
589 * whom boundary information is requested.
590 * @endOffset: an integer indicating the offset of the text character
591 * after the last character for whom boundary information is requested.
592 * @x: a pointer to a long integer into which the nominal x coordinate
593 * of the corresponding bounding box will be returned.
594 * @y:a pointer to a long integer into which the nominal y coordinate
595 * of the corresponding bounding box will be returned.
596 * @width:a pointer to a long integer into which the width
597 * of the corresponding bounding box will be returned.
598 * @height: a pointer to a long integer into which the height
599 * of the corresponding bounding box will be returned.
600 * @type: an #AccessibleCoordType indicating the coordinate system to use
601 * for the returned values.
603 * Get the bounding box for text within a range in an #AccessibleText object.
605 * Returns: the bounding-box extents of the specified text range,
606 * in the specified coordinate system.
610 AccessibleText_getRangeExtents (AccessibleText *obj,
611 long int startOffset,
617 AccessibleCoordType type)
619 CORBA_long retX, retY, retWidth, retHeight;
624 *width = *height = -1;
628 Accessibility_Text_getRangeExtents (CSPI_OBJREF (obj),
637 if (!cspi_check_ev ("getRangeExtents"))
640 *width = *height = -1;
652 * AccessibleText_getBoundedRanges:
653 * @obj: a pointer to the #AccessibleText object on which to operate.
654 * @x: the 'starting' x coordinate of the bounding box.
655 * @y: the 'starting' y coordinate of the bounding box.
656 * @width: the x extent of the bounding box.
657 * @height: the y extent of the bounding box.
658 * @type: an #AccessibleCoordType indicating the coordinate system to use
659 * for the returned values.
660 * @clipTypeX: an #AccessibleTextClipType indicating how to treat characters that
661 * intersect the bounding box's x extents.
662 * @clipTypeY: an #AccessibleTextClipType indicating how to treat characters that
663 * intersect the bounding box's y extents.
665 * Get the ranges of text from an #AccessibleText object which lie within the
666 * bounds defined by (@x, @y) and (@x+@width, @y+@height).
668 * Returns: a null-terminated list of pointers to AccessibleTextRange structs
669 * detailing the bounded text.
671 AccessibleTextRange **
672 AccessibleText_getBoundedRanges (AccessibleText *obj,
677 AccessibleCoordType type,
678 AccessibleTextClipType clipTypeX,
679 AccessibleTextClipType clipTypeY)
681 Accessibility_Text_RangeList *range_seq;
683 cspi_return_val_if_fail (obj != NULL, NULL);
686 Accessibility_Text_getBoundedRanges (CSPI_OBJREF (obj),
689 get_accessible_text_clip_type (clipTypeX),
690 get_accessible_text_clip_type (clipTypeY),
693 cspi_return_val_if_ev ("getBoundedRanges", NULL);
695 return get_accessible_text_ranges_from_range_seq (range_seq);
699 * AccessibleTextRange_freeRanges:
700 * @ranges: a pointer to an array of AccessibleTextRange structs.
702 * Free the memory used by a list of AccessibleTextRange structs.
703 * The argument passed in should be an array of pointers
704 * AccessibleTextRange structs.
707 AccessibleTextRange_freeRanges (AccessibleTextRange **ranges)
709 /* this was a contiguously allocated block, only free the first element */
715 * AccessibleText_getNSelections:
716 * @obj: a pointer to the #AccessibleText object on which to operate.
718 * Get the number of active non-contiguous selections for an
719 * #AccessibleText object.
721 * Returns: a long integer indicating the current
722 * number of non-contiguous text selections active
723 * within an #AccessibleText object.
726 AccessibleText_getNSelections (AccessibleText *obj)
730 cspi_return_val_if_fail (obj != NULL, -1);
733 Accessibility_Text_getNSelections (CSPI_OBJREF (obj), cspi_ev ());
735 cspi_return_val_if_ev ("getNSelections", -1);
741 * AccessibleText_getSelection:
742 * @obj: a pointer to the #AccessibleText object on which to operate.
743 * @selectionNum: an integer indicating which selection to query.
744 * @startOffset: a pointer to a long integer into which the start offset
745 * of the selection will be returned.
746 * @endOffset: a pointer to a long integer into which the start offset
747 * of the selection will be returned.
749 * Get the bounds of the @selectionNum-th active text selection for an
750 * #AccessibleText object.
753 AccessibleText_getSelection (AccessibleText *obj,
754 long int selectionNum,
755 long int *startOffset,
758 CORBA_long retStartOffset, retEndOffset;
762 *endOffset = *startOffset = -1;
766 Accessibility_Text_getSelection (CSPI_OBJREF (obj),
768 &retStartOffset, &retEndOffset,
771 if (!cspi_check_ev ("getSelection"))
773 *startOffset = *endOffset = -1;
777 *startOffset = retStartOffset;
778 *endOffset = retEndOffset;
783 * AccessibleText_addSelection:
784 * @obj: a pointer to the #AccessibleText object on which to operate.
785 * @startOffset: the starting offset of the desired new selection.
786 * @endOffset: the offset of the first character after the new selection.
788 * Select some text (add a text selection) in an #AccessibleText object.
790 * Returns: #TRUE if successful, #FALSE otherwise.
793 AccessibleText_addSelection (AccessibleText *obj,
794 long int startOffset, long int endOffset)
798 cspi_return_val_if_fail (obj != NULL, FALSE);
801 Accessibility_Text_addSelection (
802 CSPI_OBJREF (obj), startOffset,
803 endOffset, cspi_ev ());
805 cspi_return_val_if_ev ("addSelection", FALSE);
811 * AccessibleText_removeSelection:
812 * @obj: a pointer to the #AccessibleText object on which to operate.
813 * @selectionNum: an integer indicating which (possibly of several)
814 * text selection to remove.
816 * De-select a text selection.
818 * Returns: #TRUE if successful, #FALSE otherwise.
821 AccessibleText_removeSelection (AccessibleText *obj,
822 long int selectionNum)
826 cspi_return_val_if_fail (obj != NULL, FALSE);
829 Accessibility_Text_removeSelection (
830 CSPI_OBJREF (obj), selectionNum, cspi_ev ());
832 cspi_return_val_if_ev ("removeSelection", FALSE);
838 * AccessibleText_setSelection:
839 * @obj: a pointer to the #AccessibleText object on which to operate.
840 * @selectionNum: a zero-offset index indicating which text selection to modify.
841 * @startOffset: a long int, the new starting offset for the selection.
842 * @endOffset: a long int, the desired new offset of the first character
843 * after the selection.
845 * Change the bounds of an existing #AccessibleText text selection.
847 * Returns: #TRUE if successful, #FALSE otherwise.
850 AccessibleText_setSelection (AccessibleText *obj,
851 long int selectionNum,
852 long int startOffset,
857 cspi_return_val_if_fail (obj != NULL, FALSE);
859 retval = Accessibility_Text_setSelection (CSPI_OBJREF (obj),
862 endOffset, cspi_ev ());
864 cspi_return_val_if_ev ("setSelection", FALSE);