X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=cspi%2Fspi_text.c;h=5339a39ba00ff42b1171130cb77752c4d15a595c;hb=dea123f383eb81663ea33463363f5c27f4ac0bcd;hp=fac8de6d4414e8e152a568498ed4d1f38b9d72ee;hpb=f7e228dff4ca3781f686b1fd39e862ed5e5edc79;p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git diff --git a/cspi/spi_text.c b/cspi/spi_text.c index fac8de6..5339a39 100644 --- a/cspi/spi_text.c +++ b/cspi/spi_text.c @@ -2,7 +2,8 @@ * AT-SPI - Assistive Technology Service Provider Interface * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) * - * Copyright 2001 Sun Microsystems Inc. + * 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 @@ -56,7 +57,64 @@ get_accessible_text_boundary_type (AccessibleTextBoundaryType type) /* 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; + } +} + +typedef struct +{ + dbus_int32_t startOffset; + dbus_int32_t endOffset; + char *content; +} Accessibility_Range; + +static AccessibleTextRange ** +get_accessible_text_ranges_from_range_seq (GArray *range_seq) +{ + AccessibleTextRange **ranges = NULL; + AccessibleTextRange *array = NULL; + int i; + if (range_seq && range_seq->len > 0) + { + ranges = g_new0 (AccessibleTextRange *, range_seq->len + 1); + } + array = g_new0 (AccessibleTextRange, range_seq->len); + for (i = 0; i < range_seq->len; i++) + { + Accessibility_Range *r = g_array_index (range_seq, Accessibility_Range *, i); + AccessibleTextRange *range; + range = &array[i]; + range->start = r->startOffset; + range->end = r->endOffset; + range->contents = g_strdup (r->content); + ranges[i] = range; } + ranges[i] = NULL; /* null-terminated list! */ + // TODO: Figure out whether we're leaking strings + g_array_free (range_seq, TRUE); + + return ranges; } @@ -96,11 +154,11 @@ AccessibleText_unref (AccessibleText *obj) long AccessibleText_getCharacterCount (AccessibleText *obj) { - long retval; + dbus_int32_t retval; cspi_return_val_if_fail (obj != NULL, -1); - retval = Accessibility_Text__get_characterCount (CSPI_OBJREF (obj), cspi_ev ()); + cspi_dbus_get_property (obj, spi_interface_text, "characterCount", NULL, "i", &retval); cspi_return_val_if_ev ("getCharacterCount", -1); @@ -126,14 +184,11 @@ AccessibleText_getText (AccessibleText *obj, long int endOffset) { char *retval; + dbus_int32_t d_startOffset = startOffset, d_endOffset = endOffset; cspi_return_val_if_fail (obj != NULL, NULL); - retval = - Accessibility_Text_getText (CSPI_OBJREF (obj), - startOffset, - endOffset, - cspi_ev ()); + cspi_dbus_call (obj, spi_interface_text, "getText", NULL, "ii=>s", startOffset, endOffset, &retval); cspi_return_val_if_ev ("getText", NULL); @@ -151,12 +206,11 @@ AccessibleText_getText (AccessibleText *obj, long AccessibleText_getCaretOffset (AccessibleText *obj) { - long retval; + dbus_int32_t retval; cspi_return_val_if_fail (obj != NULL, -1); - retval = - Accessibility_Text__get_caretOffset (CSPI_OBJREF (obj), cspi_ev ()); + cspi_dbus_get_property (obj, spi_interface_text, "caretOffset", NULL, "i", &retval); cspi_return_val_if_ev ("getCaretOffset", -1); @@ -173,10 +227,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, @@ -184,7 +242,8 @@ AccessibleText_getAttributes (AccessibleText *obj, long int *startOffset, long int *endOffset) { - CORBA_long retStartOffset, retEndOffset; + dbus_int32_t d_offset = offset; + dbus_int32_t retStartOffset, retEndOffset; char *retval; if (obj == NULL) @@ -193,11 +252,7 @@ AccessibleText_getAttributes (AccessibleText *obj, return NULL; } - retval = Accessibility_Text_getAttributes (CSPI_OBJREF (obj), - offset, - &retStartOffset, - &retEndOffset, - cspi_ev ()); + cspi_dbus_call (obj, spi_interface_text, "getAttributes", NULL, "i=>iis", d_offset, &retStartOffset, &retEndOffset, &retval); if (!cspi_check_ev ("getAttributes")) { @@ -214,6 +269,46 @@ AccessibleText_getAttributes (AccessibleText *obj, } /** + * AccessibleText_getDefaultAttributes: + * @obj: a pointer to the #AccessibleText object to query. + * + * Get the default attributes applied to an #AccessibleText + * object. + * 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. The combination of this attribute set and + * the attributes reported by #AccessibleText_getAttributes + * describes the entire set of text attributes over a range. + * + * @Since: AT-SPI 1.4 + * + * Returns: a text string describing the default attributes + * applied to a text object, (exclusive of explicitly-set + * attributes), encoded as UTF-8. + **/ +char * +AccessibleText_getDefaultAttributes (AccessibleText *obj) +{ + char *retval; + + if (obj == NULL) + { + return NULL; + } + + cspi_dbus_call (obj, spi_interface_text, "getAttributes", NULL, "=>s", &retval); + + if (!cspi_check_ev ("getAttributes")) + { + retval = NULL; + } + + return retval; +} + +/** * AccessibleText_setCaretOffset: * @obj: a pointer to the #AccessibleText object on which to operate. * @newOffset: the offset to which the text caret is to be moved. @@ -226,13 +321,12 @@ SPIBoolean AccessibleText_setCaretOffset (AccessibleText *obj, long int newOffset) { - SPIBoolean retval; + dbus_int32_t d_newOffset = newOffset; + dbus_bool_t retval; cspi_return_val_if_fail (obj != NULL, FALSE); - retval = - Accessibility_Text_setCaretOffset (CSPI_OBJREF (obj), - newOffset, cspi_ev ()); + cspi_dbus_call (obj, spi_interface_text, "setCaretOffset", NULL, "i=>b", d_newOffset, &retval); cspi_return_val_if_ev ("setCaretOffset", FALSE); @@ -267,8 +361,10 @@ AccessibleText_getTextBeforeOffset (AccessibleText *obj, long int *startOffset, long int *endOffset) { + dbus_int32_t d_offset = offset; + dbus_uint32_t d_type = type; + dbus_int32_t retStartOffset, retEndOffset; char *retval; - CORBA_long retStartOffset, retEndOffset; if (obj == NULL) { @@ -276,11 +372,7 @@ AccessibleText_getTextBeforeOffset (AccessibleText *obj, return NULL; } - retval = Accessibility_Text_getTextBeforeOffset (CSPI_OBJREF (obj), - offset, - get_accessible_text_boundary_type (type), - &retStartOffset, &retEndOffset, - cspi_ev ()); + cspi_dbus_call (obj, spi_interface_text, "getTextBeforeOffset", NULL, "iu=>iis", d_offset, d_type, &retStartOffset, &retEndOffset, &retval); if (!cspi_check_ev ("getTextBeforeOffset")) { *startOffset = *endOffset = -1; @@ -321,9 +413,10 @@ AccessibleText_getTextAtOffset (AccessibleText *obj, AccessibleTextBoundaryType type, long int *startOffset, long int *endOffset) { - CORBA_long corbaStartOffset; - CORBA_long corbaEndOffset; - char *retval; + dbus_int32_t d_offset = offset; + dbus_uint32_t d_type = type; + dbus_int32_t retStartOffset, retEndOffset; + char *retval; if (obj == NULL) { @@ -331,12 +424,7 @@ AccessibleText_getTextAtOffset (AccessibleText *obj, return NULL; } - retval = Accessibility_Text_getTextAtOffset (CSPI_OBJREF (obj), - offset, - get_accessible_text_boundary_type (type), - &corbaStartOffset, - &corbaEndOffset, - cspi_ev ()); + cspi_dbus_call (obj, spi_interface_text, "getTextAtOffset", NULL, "iu=>iis", d_offset, d_type, &retStartOffset, &retEndOffset, &retval); if (!cspi_check_ev ("getTextAtOffset")) { @@ -345,8 +433,8 @@ AccessibleText_getTextAtOffset (AccessibleText *obj, } else { - *startOffset = corbaStartOffset; - *endOffset = corbaEndOffset; + *startOffset = retStartOffset; + *endOffset = retEndOffset; } return retval; } @@ -378,8 +466,10 @@ AccessibleText_getTextAfterOffset (AccessibleText *obj, AccessibleTextBoundaryType type, long int *startOffset, long int *endOffset) { + dbus_int32_t d_offset = offset; + dbus_uint32_t d_type = type; + dbus_int32_t retStartOffset, retEndOffset; char *retval; - CORBA_long retStartOffset, retEndOffset; if (obj == NULL) { @@ -387,11 +477,7 @@ AccessibleText_getTextAfterOffset (AccessibleText *obj, return NULL; } - retval = Accessibility_Text_getTextAfterOffset (CSPI_OBJREF (obj), - offset, - get_accessible_text_boundary_type (type), - &retStartOffset, &retEndOffset, - cspi_ev ()); + cspi_dbus_call (obj, spi_interface_text, "getTextAfterOffset", NULL, "iu=>iis", d_offset, d_type, &retStartOffset, &retEndOffset, &retval); if (!cspi_check_ev ("getTextAfterOffset")) { @@ -423,14 +509,12 @@ unsigned long AccessibleText_getCharacterAtOffset (AccessibleText *obj, long int offset) { - long retval; + dbus_int32_t d_offset = offset; + dbus_int32_t retval; cspi_return_val_if_fail (obj != NULL, -1); - retval = - Accessibility_Text_getCharacterAtOffset (CSPI_OBJREF (obj), - offset, - cspi_ev ()); + cspi_dbus_call (obj, spi_interface_text, "getCharacterAtOffset", NULL, "i=>i", d_offset, &retval); cspi_return_val_if_ev ("getCharacterAtOffset", -1); @@ -465,7 +549,9 @@ AccessibleText_getCharacterExtents (AccessibleText *obj, long int *height, AccessibleCoordType type) { - CORBA_long retX, retY, retWidth, retHeight; + dbus_int32_t d_offset = offset; + dbus_uint16_t d_type = type; + dbus_int32_t retX, retY, retWidth, retHeight; if (obj == NULL) { @@ -474,13 +560,7 @@ AccessibleText_getCharacterExtents (AccessibleText *obj, return; } - Accessibility_Text_getCharacterExtents (CSPI_OBJREF (obj), - offset, - &retX, - &retY, - &retWidth, - &retHeight, - type, cspi_ev ()); + cspi_dbus_call (obj, spi_interface_text, "getCharacterExtents", NULL, "in=>iiii", d_offset, d_type, &retX, &retY, &retWidth, &retHeight); if (!cspi_check_ev ("getCharacterExtents")) { @@ -516,15 +596,13 @@ AccessibleText_getOffsetAtPoint (AccessibleText *obj, long int y, AccessibleCoordType type) { - long retval; + dbus_int32_t d_x = x, d_y = y; + dbus_uint16_t d_type = type; + dbus_int32_t retval; cspi_return_val_if_fail (obj != NULL, -1); - retval = - Accessibility_Text_getOffsetAtPoint (CSPI_OBJREF (obj), - x, - y, - type, cspi_ev ()); + cspi_dbus_call (obj, spi_interface_text, "getOffsetAtPoint", NULL, "iin=>i", d_x, d_y, d_type, &retval); cspi_return_val_if_ev ("getOffsetAtPoint", -1); @@ -532,6 +610,129 @@ AccessibleText_getOffsetAtPoint (AccessibleText *obj, } /** + * 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. + * + * @Since: AT-SPI 1.2 + **/ +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) +{ + dbus_int32_t d_startOffset = startOffset, d_endOffset = endOffset; + dbus_int16_t d_type = type; + dbus_int32_t retX, retY, retWidth, retHeight; + + if (obj == NULL) + { + *x = *y = -1; + *width = *height = -1; + return; + } + + cspi_dbus_call (obj, spi_interface_text, "getRangeExtents", NULL, "iin=>iiii", d_startOffset, d_endOffset, d_type, &retX, &retY, &retWidth, &retHeight); + + 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). + * + * @Since: AT-SPI 1.2 + * + * 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) +{ + dbus_int32_t d_x = x, d_y = y, d_width = width, d_height = height; + dbus_uint16_t d_type = type; + dbus_uint32_t d_clipTypeX = clipTypeX, d_clipTypeY = clipTypeY; + GArray *range_seq; + + cspi_return_val_if_fail (obj != NULL, NULL); + + cspi_dbus_call (obj, spi_interface_text, "getBoundedRanges", NULL, "iiiinuu=>a(iisv)", d_x, d_y, d_width, d_height, d_type, d_clipTypeX, d_clipTypeY, &range_seq); + + 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. + * + * @Since: AT-SPI 1.2 + **/ +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: * @obj: a pointer to the #AccessibleText object on which to operate. * @@ -545,12 +746,11 @@ AccessibleText_getOffsetAtPoint (AccessibleText *obj, long AccessibleText_getNSelections (AccessibleText *obj) { - long retval; + dbus_int32_t retval; cspi_return_val_if_fail (obj != NULL, -1); - retval = - Accessibility_Text_getNSelections (CSPI_OBJREF (obj), cspi_ev ()); + cspi_dbus_call (obj, spi_interface_text, "getNSelections", NULL, "i", &retval); cspi_return_val_if_ev ("getNSelections", -1); @@ -575,7 +775,8 @@ AccessibleText_getSelection (AccessibleText *obj, long int *startOffset, long int *endOffset) { - CORBA_long retStartOffset, retEndOffset; + dbus_int32_t d_selectionNum = selectionNum; + dbus_int32_t retStartOffset, retEndOffset; if (obj == NULL) { @@ -583,10 +784,7 @@ AccessibleText_getSelection (AccessibleText *obj, return; } - Accessibility_Text_getSelection (CSPI_OBJREF (obj), - selectionNum, - &retStartOffset, &retEndOffset, - cspi_ev ()); + cspi_dbus_call (obj, spi_interface_text, "getSelection", NULL, "i=>ii", d_selectionNum, &retStartOffset, &retEndOffset); if (!cspi_check_ev ("getSelection")) { @@ -613,14 +811,12 @@ SPIBoolean AccessibleText_addSelection (AccessibleText *obj, long int startOffset, long int endOffset) { - SPIBoolean retval; + dbus_int32_t d_startOffset = startOffset, d_endOffset = endOffset; + dbus_bool_t retval; cspi_return_val_if_fail (obj != NULL, FALSE); - retval = - Accessibility_Text_addSelection ( - CSPI_OBJREF (obj), startOffset, - endOffset, cspi_ev ()); + cspi_dbus_call (obj, spi_interface_text, "addSelection", NULL, "ii=>b", d_startOffset, d_endOffset, &retval); cspi_return_val_if_ev ("addSelection", FALSE); @@ -641,13 +837,12 @@ SPIBoolean AccessibleText_removeSelection (AccessibleText *obj, long int selectionNum) { - SPIBoolean retval; + dbus_int32_t d_selectionNum = selectionNum; + dbus_bool_t retval; cspi_return_val_if_fail (obj != NULL, FALSE); - retval = - Accessibility_Text_removeSelection ( - CSPI_OBJREF (obj), selectionNum, cspi_ev ()); + cspi_dbus_call (obj, spi_interface_text, "removeSelection", NULL, "i=>b", d_selectionNum, &retval); cspi_return_val_if_ev ("removeSelection", FALSE); @@ -672,14 +867,12 @@ AccessibleText_setSelection (AccessibleText *obj, long int startOffset, long int endOffset) { - SPIBoolean retval; + dbus_int32_t d_selectionNum = selectionNum, d_startOffset = startOffset, d_endOffset = endOffset; + dbus_bool_t retval; cspi_return_val_if_fail (obj != NULL, FALSE); - retval = Accessibility_Text_setSelection (CSPI_OBJREF (obj), - selectionNum, - startOffset, - endOffset, cspi_ev ()); + cspi_dbus_call (obj, spi_interface_text, "setSelection", NULL, "iii=>b", d_selectionNum, d_startOffset, d_endOffset, &retval); cspi_return_val_if_ev ("setSelection", FALSE); @@ -687,4 +880,88 @@ AccessibleText_setSelection (AccessibleText *obj, } +/** + * AccessibleText_getAttributeRun: + * @obj: a pointer to the #AccessibleText object to query. + * @offset: a long integer indicating the offset from which the attribute + * search is based. + * @startOffset: a #long indicating the start of the desired text range. + * @endOffset: a #long indicating the first character past the desired range. + * @includeDefaults: a #bool if False, the call should only return those + * attributes which are explicitly set on the current attribute + * run, omitting any attributes which are inherited from the + * default values. + * + * @Since: AT-SPI 1.7 + * + * Returns: the AttributeSet defined at offset, optionally including the 'default' attributes. + **/ + +AccessibleAttributeSet * +AccessibleText_getAttributeRun (AccessibleText *obj, + long int offset, + long int *startOffset, + long int *endOffset, + long int includeDefaults){ + + dbus_int32_t d_offset = offset; + dbus_bool_t d_includeDefaults = includeDefaults; + dbus_int32_t retStartOffset, retEndOffset; + AccessibleAttributeSet *retval; + GArray *attributes; + + if (obj == NULL) + { + *startOffset = *endOffset = -1; + return NULL; + } + + cspi_dbus_call (obj, spi_interface_text, "getAttributeRun", NULL, "ib=>iias", d_offset, d_includeDefaults, &retStartOffset, &retEndOffset, &attributes); + + if (!cspi_check_ev ("getAttributeRun")) + { + *startOffset = *endOffset = -1; + retval = NULL; + } + else + { + *startOffset = retStartOffset; + *endOffset = retEndOffset; + retval = _cspi_attribute_set_from_sequence (attributes); + } + + return retval; + +} + +/** + * AccessibleText_getDefaultAttributeSet: + * @obj: a pointer to the #AccessibleText object to query. + * + * + * @Since: AT-SPI 1.7 + * + * Returns: an AttributeSet containing the text attributes + * which apply to all text in the object by virtue of the + * default settings of the document, view, or user agent; e.g. + * those attributes which are implied rather than explicitly + * applied to the text object. For instance, an object whose + * entire text content has been explicitly marked as 'bold' + * will report the 'bold' attribute via getAttributeRun(), + * whereas an object whose text weight is inspecified may + * report the default or implied text weight in the default AttributeSet. + * + **/ + +AccessibleAttributeSet * +AccessibleText_getDefaultAttributeSet (AccessibleText *obj){ + AccessibleAttributeSet *retval; + GArray *attributes; + + cspi_return_val_if_fail (obj != NULL, NULL); + cspi_dbus_call (obj, spi_interface_text, "getDefaultAttributes", NULL, "as", &attributes); + + retval = _cspi_attribute_set_from_sequence (attributes); + return retval; +}