X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=cspi%2Fspi_text.c;h=ab13b045e2a657e379f84cf1df105abbd75a4001;hb=b1419354d8c2b37d43601cd2f7ad4579ec10a5fa;hp=974c850de82f6c31e3dc2274a49c216cb983d677;hpb=2b8f4365c549962de1f20418ca00dd503d6e28bc;p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git diff --git a/cspi/spi_text.c b/cspi/spi_text.c index 974c850..ab13b04 100644 --- a/cspi/spi_text.c +++ b/cspi/spi_text.c @@ -1,40 +1,138 @@ +/* + * AT-SPI - Assistive Technology Service Provider Interface + * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) + * + * Copyright 2001, 2002 Sun Microsystems Inc., + * Copyright 2001, 2002 Ximian, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + #include +static Accessibility_TEXT_BOUNDARY_TYPE +get_accessible_text_boundary_type (AccessibleTextBoundaryType type) +{ + switch (type) + { + case SPI_TEXT_BOUNDARY_CHAR: + return Accessibility_TEXT_BOUNDARY_CHAR; + break; + case SPI_TEXT_BOUNDARY_CURSOR_POS: + /* FixME */ + return Accessibility_TEXT_BOUNDARY_CHAR; + break; + case SPI_TEXT_BOUNDARY_WORD_START: + return Accessibility_TEXT_BOUNDARY_WORD_START; + break; + case SPI_TEXT_BOUNDARY_WORD_END: + return Accessibility_TEXT_BOUNDARY_WORD_END; + break; + case SPI_TEXT_BOUNDARY_SENTENCE_START: + return Accessibility_TEXT_BOUNDARY_SENTENCE_START; + break; + case SPI_TEXT_BOUNDARY_SENTENCE_END: + return Accessibility_TEXT_BOUNDARY_SENTENCE_END; + break; + case SPI_TEXT_BOUNDARY_LINE_START: + return Accessibility_TEXT_BOUNDARY_LINE_START; + break; + case SPI_TEXT_BOUNDARY_LINE_END: + return Accessibility_TEXT_BOUNDARY_LINE_END; + break; + case SPI_TEXT_BOUNDARY_ATTRIBUTE_RANGE: + /* Fixme */ + return Accessibility_TEXT_BOUNDARY_CHAR; + break; + default: + /* FIXME */ + return Accessibility_TEXT_BOUNDARY_CHAR; + } +} + +static Accessibility_TEXT_CLIP_TYPE +get_accessible_text_clip_type (AccessibleTextClipType type) +{ + switch (type) + { + case SPI_TEXT_CLIP_NONE: + return Accessibility_TEXT_CLIP_NONE; + break; + case SPI_TEXT_CLIP_MIN: + return Accessibility_TEXT_CLIP_MIN; + break; + case SPI_TEXT_CLIP_MAX: + return Accessibility_TEXT_CLIP_MAX; + break; + default: + return Accessibility_TEXT_CLIP_BOTH; + } +} + +static AccessibleTextRange ** +get_accessible_text_ranges_from_range_seq (Accessibility_Text_RangeList *range_seq) +{ + AccessibleTextRange **ranges = NULL; + AccessibleTextRange *array = NULL; + int i; + if (range_seq && range_seq->_length > 0) + { + ranges = g_new0 (AccessibleTextRange *, range_seq->_length + 1); + } + array = g_new0 (AccessibleTextRange, range_seq->_length); + for (i = 0; i < range_seq->_length; i++) + { + AccessibleTextRange *range; + range = &array[i]; + range->start = range_seq->_buffer[i].startOffset; + range->end = range_seq->_buffer[i].endOffset; + range->contents = CORBA_string_dup (range_seq->_buffer[i].content); + ranges[i] = range; + } + ranges[i] = NULL; /* null-terminated list! */ + CORBA_free (range_seq); + + return ranges; +} + + /** * AccessibleText_ref: * @obj: a pointer to the #AccessibleText object on which to operate. * * Increment the reference count for an #AccessibleText object. - * - * Returns: (no return code implemented yet). - * **/ -int +void AccessibleText_ref (AccessibleText *obj) { cspi_object_ref (obj); - return 0; } - - /** * AccessibleText_unref: * @obj: a pointer to the #Accessible object on which to operate. * * Decrement the reference count for an #AccessibleText object. - * - * Returns: (no return code implemented yet). - * **/ -int +void AccessibleText_unref (AccessibleText *obj) { cspi_object_unref (obj); - return 0; } - /** * AccessibleText_getCharacterCount: * @obj: a pointer to the #AccessibleText object to query. @@ -43,24 +141,21 @@ AccessibleText_unref (AccessibleText *obj) * * Returns: a long integer indicating the total number of * characters in the #AccessibleText object. - * **/ long AccessibleText_getCharacterCount (AccessibleText *obj) { long retval; - CORBA_exception_init (cspi_ev ()); - retval = (long) - Accessibility_Text__get_characterCount (CSPI_OBJREF (obj), cspi_ev ()); + cspi_return_val_if_fail (obj != NULL, -1); - cspi_check_ev (cspi_ev (), "SpiAccessibleText_getCharacterCount"); + retval = Accessibility_Text__get_characterCount (CSPI_OBJREF (obj), cspi_ev ()); + + cspi_return_val_if_ev ("getCharacterCount", -1); return retval; } - - /** * AccessibleText_getText: * @obj: a pointer to the #AccessibleText object to query. @@ -73,16 +168,25 @@ AccessibleText_getCharacterCount (AccessibleText *obj) * * Returns: a text string containing characters from @startOffset * to @endOffset-1, inclusive, encoded as UTF-8. - * **/ char * AccessibleText_getText (AccessibleText *obj, long int startOffset, long int endOffset) { - return (char *) + char *retval; + + cspi_return_val_if_fail (obj != NULL, NULL); + + retval = Accessibility_Text_getText (CSPI_OBJREF (obj), - (CORBA_long) startOffset, (CORBA_long) endOffset, cspi_ev ()); + startOffset, + endOffset, + cspi_ev ()); + + cspi_return_val_if_ev ("getText", NULL); + + return retval; } /** @@ -92,15 +196,21 @@ AccessibleText_getText (AccessibleText *obj, * Get the current offset of the text caret in an #AccessibleText object. * * Returns: a long integer indicating the current position of the text caret. - * **/ long AccessibleText_getCaretOffset (AccessibleText *obj) { - return (long) + long retval; + + cspi_return_val_if_fail (obj != NULL, -1); + + retval = Accessibility_Text__get_caretOffset (CSPI_OBJREF (obj), cspi_ev ()); -} + cspi_return_val_if_ev ("getCaretOffset", -1); + + return retval; +} /** * AccessibleText_getAttributes: @@ -112,11 +222,14 @@ AccessibleText_getCaretOffset (AccessibleText *obj) * * Get the attributes applied to a range of text from an #AccessibleText * object, and the bounds of the range. + * The text attributes correspond to CSS attributes where possible, + * keys and values are delimited from one another via ":", and + * the delimiter between key/value pairs is ";". Thus + * "font-size:10;foreground-color:0,0,0" would be a valid + * return string. * * Returns: a text string describing the attributes occurring within the - * attribute run containing @offset, encoded as UTF-8 and - * delimited by ':' - * + * attribute run containing @offset, encoded as UTF-8. **/ char * AccessibleText_getAttributes (AccessibleText *obj, @@ -126,18 +239,32 @@ AccessibleText_getAttributes (AccessibleText *obj, { CORBA_long retStartOffset, retEndOffset; char *retval; - retval = (char *) - Accessibility_Text_getAttributes (CSPI_OBJREF (obj), - (CORBA_long) offset, + + if (obj == NULL) + { + *startOffset = *endOffset = -1; + return NULL; + } + + retval = Accessibility_Text_getAttributes (CSPI_OBJREF (obj), + offset, &retStartOffset, &retEndOffset, cspi_ev ()); - *startOffset = (long) retStartOffset; - *endOffset = (long) retEndOffset; - return retval; -} + if (!cspi_check_ev ("getAttributes")) + { + *startOffset = *endOffset = -1; + retval = NULL; + } + else + { + *startOffset = retStartOffset; + *endOffset = retEndOffset; + } + return retval; +} /** * AccessibleText_setCaretOffset: @@ -147,15 +274,22 @@ AccessibleText_getAttributes (AccessibleText *obj, * Set the text caret position for an #AccessibleText object. * * Returns: #TRUE if successful, #FALSE otherwise. - * **/ SPIBoolean AccessibleText_setCaretOffset (AccessibleText *obj, long int newOffset) { - return (SPIBoolean) + SPIBoolean retval; + + cspi_return_val_if_fail (obj != NULL, FALSE); + + retval = Accessibility_Text_setCaretOffset (CSPI_OBJREF (obj), - (CORBA_long) newOffset, cspi_ev ()); + newOffset, cspi_ev ()); + + cspi_return_val_if_ev ("setCaretOffset", FALSE); + + return retval; } /** @@ -178,7 +312,6 @@ AccessibleText_setCaretOffset (AccessibleText *obj, * Returns: a UTF-8 string representing the delimited text, both of whose * delimiting boundaries are before the current offset, or * an empty string if no such text exists. - * **/ char * AccessibleText_getTextBeforeOffset (AccessibleText *obj, @@ -189,13 +322,28 @@ AccessibleText_getTextBeforeOffset (AccessibleText *obj, { char *retval; CORBA_long retStartOffset, retEndOffset; - retval = (char *) - Accessibility_Text_getTextBeforeOffset (CSPI_OBJREF (obj), - (CORBA_long) offset, (Accessibility_TEXT_BOUNDARY_TYPE) type, + + if (obj == NULL) + { + *startOffset = *endOffset = -1; + return NULL; + } + + retval = Accessibility_Text_getTextBeforeOffset (CSPI_OBJREF (obj), + offset, + get_accessible_text_boundary_type (type), &retStartOffset, &retEndOffset, cspi_ev ()); - *startOffset = (long) retStartOffset; - *endOffset = (long) retEndOffset; + if (!cspi_check_ev ("getTextBeforeOffset")) + { + *startOffset = *endOffset = -1; + retval = NULL; + } + else + { + *startOffset = retStartOffset; + *endOffset = retEndOffset; + } return retval; } @@ -219,7 +367,6 @@ AccessibleText_getTextBeforeOffset (AccessibleText *obj, * Returns: a UTF-8 string representing the delimited text, whose * delimiting boundaries bracket the current offset, or * an empty string if no such text exists. - * **/ char * AccessibleText_getTextAtOffset (AccessibleText *obj, @@ -229,22 +376,34 @@ AccessibleText_getTextAtOffset (AccessibleText *obj, { CORBA_long corbaStartOffset; CORBA_long corbaEndOffset; - char *retval = ""; + char *retval; + + if (obj == NULL) + { + *startOffset = *endOffset = -1; + return NULL; + } + retval = Accessibility_Text_getTextAtOffset (CSPI_OBJREF (obj), - (CORBA_long) offset, - (Accessibility_TEXT_BOUNDARY_TYPE) type, + offset, + get_accessible_text_boundary_type (type), &corbaStartOffset, &corbaEndOffset, cspi_ev ()); - *startOffset = (long) corbaStartOffset; - *endOffset = (long) corbaEndOffset; -#ifdef CSPI_DEBUG - fprintf (stderr, "text offsets %ld to %ld\n", *startOffset, *endOffset); -#endif + + if (!cspi_check_ev ("getTextAtOffset")) + { + *startOffset = *endOffset = -1; + retval = NULL; + } + else + { + *startOffset = corbaStartOffset; + *endOffset = corbaEndOffset; + } return retval; } - /** * AccessibleText_getTextAfterOffset: * @obj: a pointer to the #AccessibleText object on which to operate. @@ -265,7 +424,6 @@ AccessibleText_getTextAtOffset (AccessibleText *obj, * Returns: a UTF-8 string representing the delimited text, both of whose * delimiting boundaries are after or inclusive of the current * offset, or an empty string if no such text exists. - * **/ char * AccessibleText_getTextAfterOffset (AccessibleText *obj, @@ -275,18 +433,32 @@ AccessibleText_getTextAfterOffset (AccessibleText *obj, { char *retval; CORBA_long retStartOffset, retEndOffset; - retval = (char *) - Accessibility_Text_getTextAfterOffset (CSPI_OBJREF (obj), - (CORBA_long) offset, (Accessibility_TEXT_BOUNDARY_TYPE) type, + + if (obj == NULL) + { + *startOffset = *endOffset = -1; + return NULL; + } + + retval = Accessibility_Text_getTextAfterOffset (CSPI_OBJREF (obj), + offset, + get_accessible_text_boundary_type (type), &retStartOffset, &retEndOffset, cspi_ev ()); - *startOffset = (long) retStartOffset; - *endOffset = (long) retEndOffset; + + if (!cspi_check_ev ("getTextAfterOffset")) + { + *startOffset = *endOffset = -1; + retval = NULL; + } + else + { + *startOffset = retStartOffset; + *endOffset = retEndOffset; + } return retval; } - - /** * AccessibleText_getCharacterAtOffset: * @obj: a pointer to the #AccessibleText object on which to operate. @@ -299,15 +471,23 @@ AccessibleText_getTextAfterOffset (AccessibleText *obj, * UCS-4 unicode code point of the given character, or * 0xFFFFFFFF if the character in question cannot be represented * in the UCS-4 encoding. - * **/ unsigned long AccessibleText_getCharacterAtOffset (AccessibleText *obj, long int offset) { - return (unsigned long) + long retval; + + cspi_return_val_if_fail (obj != NULL, -1); + + retval = Accessibility_Text_getCharacterAtOffset (CSPI_OBJREF (obj), - (CORBA_long) offset, cspi_ev ()); + offset, + cspi_ev ()); + + cspi_return_val_if_ev ("getCharacterAtOffset", -1); + + return retval; } /** @@ -328,7 +508,6 @@ AccessibleText_getCharacterAtOffset (AccessibleText *obj, * * Get the bounding box containing the glyph representing * the character at a particular text offset. - * **/ void AccessibleText_getCharacterExtents (AccessibleText *obj, @@ -340,20 +519,36 @@ AccessibleText_getCharacterExtents (AccessibleText *obj, AccessibleCoordType type) { CORBA_long retX, retY, retWidth, retHeight; + + if (obj == NULL) + { + *x = *y = -1; + *width = *height = -1; + return; + } + Accessibility_Text_getCharacterExtents (CSPI_OBJREF (obj), - (CORBA_long) offset, + offset, &retX, &retY, &retWidth, &retHeight, - (CORBA_short) type, cspi_ev ()); - *x = (long) retX; - *y = (long) retY; - *width = (long) retWidth; - *height = (long) retHeight; + type, cspi_ev ()); + + if (!cspi_check_ev ("getCharacterExtents")) + { + *x = *y = -1; + *width = *height = -1; + } + else + { + *x = retX; + *y = retY; + *width = retWidth; + *height = retHeight; + } } - /** * AccessibleText_getOffsetAtPoint: * @obj: a pointer to the #AccessibleText object on which to operate. @@ -374,11 +569,149 @@ AccessibleText_getOffsetAtPoint (AccessibleText *obj, long int y, AccessibleCoordType type) { - return (long) + long retval; + + cspi_return_val_if_fail (obj != NULL, -1); + + retval = Accessibility_Text_getOffsetAtPoint (CSPI_OBJREF (obj), - (CORBA_long) x, (CORBA_long) y, (CORBA_short) type, cspi_ev ()); + x, + y, + type, cspi_ev ()); + + cspi_return_val_if_ev ("getOffsetAtPoint", -1); + + return retval; +} + +/** + * AccessibleText_getRangeExtents: + * @obj: a pointer to the #AccessibleText object on which to operate. + * @startOffset: an integer indicating the offset of the first text character for + * whom boundary information is requested. + * @endOffset: an integer indicating the offset of the text character + * after the last character for whom boundary information is requested. + * @x: a pointer to a long integer into which the nominal x coordinate + * of the corresponding bounding box will be returned. + * @y:a pointer to a long integer into which the nominal y coordinate + * of the corresponding bounding box will be returned. + * @width:a pointer to a long integer into which the width + * of the corresponding bounding box will be returned. + * @height: a pointer to a long integer into which the height + * of the corresponding bounding box will be returned. + * @type: an #AccessibleCoordType indicating the coordinate system to use + * for the returned values. + * + * Get the bounding box for text within a range in an #AccessibleText object. + * + * Returns: the bounding-box extents of the specified text range, + * in the specified coordinate system. + * + **/ +void +AccessibleText_getRangeExtents (AccessibleText *obj, + long int startOffset, + long int endOffset, + long int *x, + long int *y, + long int *width, + long int *height, + AccessibleCoordType type) +{ + CORBA_long retX, retY, retWidth, retHeight; + + if (obj == NULL) + { + *x = *y = -1; + *width = *height = -1; + return; + } + + Accessibility_Text_getRangeExtents (CSPI_OBJREF (obj), + startOffset, + endOffset, + &retX, + &retY, + &retWidth, + &retHeight, + type, cspi_ev ()); + + if (!cspi_check_ev ("getRangeExtents")) + { + *x = *y = -1; + *width = *height = -1; + } + else + { + *x = retX; + *y = retY; + *width = retWidth; + *height = retHeight; + } +} + +/** + * AccessibleText_getBoundedRanges: + * @obj: a pointer to the #AccessibleText object on which to operate. + * @x: the 'starting' x coordinate of the bounding box. + * @y: the 'starting' y coordinate of the bounding box. + * @width: the x extent of the bounding box. + * @height: the y extent of the bounding box. + * @type: an #AccessibleCoordType indicating the coordinate system to use + * for the returned values. + * @clipTypeX: an #AccessibleTextClipType indicating how to treat characters that + * intersect the bounding box's x extents. + * @clipTypeY: an #AccessibleTextClipType indicating how to treat characters that + * intersect the bounding box's y extents. + * + * Get the ranges of text from an #AccessibleText object which lie within the + * bounds defined by (@x, @y) and (@x+@width, @y+@height). + * + * Returns: a null-terminated list of pointers to AccessibleTextRange structs + * detailing the bounded text. + **/ +AccessibleTextRange ** +AccessibleText_getBoundedRanges (AccessibleText *obj, + long int x, + long int y, + long int width, + long int height, + AccessibleCoordType type, + AccessibleTextClipType clipTypeX, + AccessibleTextClipType clipTypeY) +{ + Accessibility_Text_RangeList *range_seq; + + cspi_return_val_if_fail (obj != NULL, NULL); + + range_seq = + Accessibility_Text_getBoundedRanges (CSPI_OBJREF (obj), + x, y, width, height, + type, + get_accessible_text_clip_type (clipTypeX), + get_accessible_text_clip_type (clipTypeY), + cspi_ev ()); + + cspi_return_val_if_ev ("getBoundedRanges", NULL); + + return get_accessible_text_ranges_from_range_seq (range_seq); } +/** + * AccessibleTextRange_freeRanges: + * @ranges: a pointer to an array of AccessibleTextRange structs. + * + * Free the memory used by a list of AccessibleTextRange structs. + * The argument passed in should be an array of pointers + * AccessibleTextRange structs. + **/ +void +AccessibleTextRange_freeRanges (AccessibleTextRange **ranges) +{ + /* this was a contiguously allocated block, only free the first element */ + g_free (ranges[0]); + g_free (ranges); +} /** * AccessibleText_getNSelections: @@ -390,16 +723,21 @@ AccessibleText_getOffsetAtPoint (AccessibleText *obj, * Returns: a long integer indicating the current * number of non-contiguous text selections active * within an #AccessibleText object. - * **/ long AccessibleText_getNSelections (AccessibleText *obj) { - return (long) + long retval; + + cspi_return_val_if_fail (obj != NULL, -1); + + retval = Accessibility_Text_getNSelections (CSPI_OBJREF (obj), cspi_ev ()); -} + cspi_return_val_if_ev ("getNSelections", -1); + return retval; +} /** * AccessibleText_getSelection: @@ -412,7 +750,6 @@ AccessibleText_getNSelections (AccessibleText *obj) * * Get the bounds of the @selectionNum-th active text selection for an * #AccessibleText object. - * **/ void AccessibleText_getSelection (AccessibleText *obj, @@ -421,15 +758,28 @@ AccessibleText_getSelection (AccessibleText *obj, long int *endOffset) { CORBA_long retStartOffset, retEndOffset; - Accessibility_Text_getSelection (CSPI_OBJREF (obj), - (CORBA_long) selectionNum, - &retStartOffset, &retEndOffset, cspi_ev ()); - - *startOffset = (long) retStartOffset; - *endOffset = (long) retEndOffset; -} + if (obj == NULL) + { + *endOffset = *startOffset = -1; + return; + } + Accessibility_Text_getSelection (CSPI_OBJREF (obj), + selectionNum, + &retStartOffset, &retEndOffset, + cspi_ev ()); + + if (!cspi_check_ev ("getSelection")) + { + *startOffset = *endOffset = -1; + } + else + { + *startOffset = retStartOffset; + *endOffset = retEndOffset; + } +} /** * AccessibleText_addSelection: @@ -440,18 +790,24 @@ AccessibleText_getSelection (AccessibleText *obj, * Select some text (add a text selection) in an #AccessibleText object. * * Returns: #TRUE if successful, #FALSE otherwise. - * **/ SPIBoolean AccessibleText_addSelection (AccessibleText *obj, long int startOffset, long int endOffset) { - return (SPIBoolean) - Accessibility_Text_addSelection (CSPI_OBJREF (obj), - (CORBA_long) startOffset, (CORBA_long) endOffset, - cspi_ev ()); -} + SPIBoolean retval; + + cspi_return_val_if_fail (obj != NULL, FALSE); + + retval = + Accessibility_Text_addSelection ( + CSPI_OBJREF (obj), startOffset, + endOffset, cspi_ev ()); + + cspi_return_val_if_ev ("addSelection", FALSE); + return retval; +} /** * AccessibleText_removeSelection: @@ -462,15 +818,22 @@ AccessibleText_addSelection (AccessibleText *obj, * De-select a text selection. * * Returns: #TRUE if successful, #FALSE otherwise. - * **/ SPIBoolean AccessibleText_removeSelection (AccessibleText *obj, long int selectionNum) { - return (SPIBoolean) - Accessibility_Text_removeSelection (CSPI_OBJREF (obj), - (CORBA_long) selectionNum, cspi_ev ()); + SPIBoolean retval; + + cspi_return_val_if_fail (obj != NULL, FALSE); + + retval = + Accessibility_Text_removeSelection ( + CSPI_OBJREF (obj), selectionNum, cspi_ev ()); + + cspi_return_val_if_ev ("removeSelection", FALSE); + + return retval; } /** @@ -484,7 +847,6 @@ AccessibleText_removeSelection (AccessibleText *obj, * Change the bounds of an existing #AccessibleText text selection. * * Returns: #TRUE if successful, #FALSE otherwise. - * **/ SPIBoolean AccessibleText_setSelection (AccessibleText *obj, @@ -492,11 +854,18 @@ AccessibleText_setSelection (AccessibleText *obj, long int startOffset, long int endOffset) { - return (SPIBoolean) - Accessibility_Text_setSelection (CSPI_OBJREF (obj), - (CORBA_long) selectionNum, - (CORBA_long) startOffset, - (CORBA_long) endOffset, cspi_ev ()); + SPIBoolean retval; + + cspi_return_val_if_fail (obj != NULL, FALSE); + + retval = Accessibility_Text_setSelection (CSPI_OBJREF (obj), + selectionNum, + startOffset, + endOffset, cspi_ev ()); + + cspi_return_val_if_ev ("setSelection", FALSE); + + return retval; }