summaryrefslogtreecommitdiff
path: root/accessibility
diff options
context:
space:
mode:
authorRĂ¼diger Timm <rt@openoffice.org>2003-06-12 06:58:27 +0000
committerRĂ¼diger Timm <rt@openoffice.org>2003-06-12 06:58:27 +0000
commit6f04fcdafcdfdae29fcccc2bc174914b70773022 (patch)
tree590fac91c8c31a770d61985bbca2d69e3a6fba78 /accessibility
parentc8f73a90abf00412293575eae5c4ef735f21eda9 (diff)
INTEGRATION: CWS uaa04 (1.10.2); FILE MERGED
2003/06/04 08:54:10 obr 1.10.2.2: #i13956# container now support AccessibleText 2003/05/28 14:45:47 obr 1.10.2.1: #i14100# changed the private text change protocol with the JABG
Diffstat (limited to 'accessibility')
-rw-r--r--accessibility/bridge/org/openoffice/java/accessibility/AccessibleTextImpl.java428
1 files changed, 228 insertions, 200 deletions
diff --git a/accessibility/bridge/org/openoffice/java/accessibility/AccessibleTextImpl.java b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleTextImpl.java
index 821da8c1bbd7..12420fc8d073 100644
--- a/accessibility/bridge/org/openoffice/java/accessibility/AccessibleTextImpl.java
+++ b/accessibility/bridge/org/openoffice/java/accessibility/AccessibleTextImpl.java
@@ -54,87 +54,150 @@
*
*
************************************************************************/
-
package org.openoffice.java.accessibility;
+import com.sun.star.accessibility.*;
import com.sun.star.awt.*;
import com.sun.star.style.*;
import com.sun.star.uno.*;
-import com.sun.star.accessibility.*;
+import org.openoffice.java.accessibility.logging.*;
+
+import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleText;
+
import javax.swing.text.StyleConstants;
+
/** The GenericAccessibleEditableText mapps the calls to the java AccessibleEditableText
* interface to the corresponding methods of the UNO XAccessibleEditableText interface.
*/
public class AccessibleTextImpl implements javax.accessibility.AccessibleText {
+ final static double toPointFactor = 1 / ((7 / 10) + 34.5);
+ static String[] attributeList = {
+ "ParaAdjust", "CharBackColor", "CharWeight", "ParaFirstLineIndent",
+ "CharFontPitch", "CharHeight", "CharColor", "CharPosture",
+ "ParaLeftMargin", "ParaLineSpacing", "ParaTopMargin", "ParaBottomMargin",
+ "CharStrikeout", "CharEscapement", "ParaTabStops", "CharUnderline"
+ };
XAccessibleText unoObject;
-
- final static double toPointFactor = 1 / (7/10 + 34.5);
-
private javax.swing.text.TabSet tabSet = null;
private javax.swing.text.TabStop[] tabStops = null;
+ private static Type TextSegmentType = new Type(TextSegment.class);
/** Creates new GenericAccessibleEditableText object */
public AccessibleTextImpl(XAccessibleText xAccessibleText) {
- unoObject = xAccessibleText;
+
+ if (Build.PRODUCT) {
+ unoObject = xAccessibleText;
+ } else {
+ String property = System.getProperty("AccessBridgeLogging");
+ if ((property != null) && (property.indexOf("text") != -1)) {
+ unoObject = new XAccessibleTextLog(xAccessibleText);
+ } else {
+ unoObject = xAccessibleText;
+ }
+ }
+ }
+
+ public static javax.accessibility.AccessibleText get(com.sun.star.uno.XInterface unoObject) {
+ try {
+ XAccessibleText unoAccessibleText = (XAccessibleText)
+ UnoRuntime.queryInterface(XAccessibleText.class, unoObject);
+ if (unoAccessibleText != null) {
+ return new AccessibleTextImpl(unoAccessibleText);
+ }
+ } catch (com.sun.star.uno.RuntimeException e) {
+ }
+ return null;
}
protected static short toTextType(int part) {
short type = 0;
+
switch (part) {
case AccessibleText.CHARACTER:
type = AccessibleTextType.CHARACTER;
+
break;
+
case AccessibleText.WORD:
type = AccessibleTextType.WORD;
+
break;
+
case AccessibleText.SENTENCE:
type = AccessibleTextType.SENTENCE;
+
break;
+
case 4:
type = AccessibleTextType.LINE;
+
break;
+
case 5:
type = AccessibleTextType.ATTRIBUTE_RUN;
+
break;
+
default:
break;
}
+
return type;
}
+ protected static Object convertTextSegment(Object any) {
+ try {
+ if (AnyConverter.isObject(any)) {
+ TextSegment ts = (TextSegment)
+ AnyConverter.toObject(TextSegmentType, any);
+ if (ts != null) {
+ // Since there is nothing like a "range" object in the JAA yet,
+ // the Object[3] is a private negotiation with the JABG
+ Object[] array = { new Integer(ts.SegmentStart),
+ new Integer(ts.SegmentEnd), ts.SegmentText };
+ return array;
+ }
+ }
+ } catch (com.sun.star.lang.IllegalArgumentException e) {
+ }
+
+ return null;
+ }
+
/** Returns the string after a given index */
public String getAfterIndex(int part, int index) {
short type = toTextType(part);
- if (type > 0) {
- try {
- // the office returns an empty string when asking for the word at
- // the position of a blank
- TextSegment ts = unoObject.getTextBehindIndex(index, type);
- if ((part == AccessibleText.WORD) && (ts.SegmentText.length() == 0)) {
-// int max = getCharCount();
-// for (int i=index; i < max; i++) {
-// if (! unoObject.getTextBehindIndex(i, AccessibleTextType.CHARACTER).equals(" "))
-// break;
-// s += " ";
-// }
- ts.SegmentText = " ";
- }
- return ts.SegmentText;
- } catch (com.sun.star.uno.Exception e) {
+
+ try {
+ TextSegment ts = unoObject.getTextBehindIndex(index, type);
+
+ // the office returns an empty string when asking for the word at
+ // the position of a blank
+ if ((part == AccessibleText.WORD) &&
+ (ts.SegmentText.length() == 0)) {
+ // FIXME: should potentially return more than one blank, but
+ // since this will be fixed in the office at some time ..
+ return " ";
}
+
+ return ts.SegmentText;
+ } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
+ // Workaround for #104847#
+ if ((type == AccessibleTextType.LINE) && (index > 0) && (getCharCount() == index)) {
+ return getAfterIndex(part, index - 1);
+ }
+ } catch (com.sun.star.lang.IllegalArgumentException e) {
}
+
return null;
}
/** Returns the zero-based offset of the caret */
public int getCaretPosition() {
try {
-// if (Build.DEBUG) {
-// System.err.println(this + "getCaretPosition() returns " + unoObject.getCaretPosition());
-// }
return unoObject.getCaretPosition();
} catch (com.sun.star.uno.RuntimeException e) {
return -1;
@@ -145,134 +208,157 @@ public class AccessibleTextImpl implements javax.accessibility.AccessibleText {
public int getSelectionStart() {
try {
int index = unoObject.getSelectionStart();
+
if (index == -1) {
index = getCaretPosition();
}
+
return index;
} catch (com.sun.star.uno.RuntimeException e) {
return -1;
}
}
- protected void setAttribute(javax.swing.text.MutableAttributeSet as, com.sun.star.beans.PropertyValue property) {
+ protected void setAttribute(javax.swing.text.MutableAttributeSet as,
+ com.sun.star.beans.PropertyValue property) {
try {
// Map alignment attribute
if (property.Name.equals("ParaAdjust")) {
ParagraphAdjust adjust = null;
+
if (property.Value instanceof ParagraphAdjust) {
adjust = (ParagraphAdjust) property.Value;
} else if (property.Value instanceof Any) {
- adjust = (ParagraphAdjust) AnyConverter.toObject(new Type(ParagraphAdjust.class), property.Value);
+ adjust = (ParagraphAdjust) AnyConverter.toObject(new Type(
+ ParagraphAdjust.class), property.Value);
} else {
- adjust = ParagraphAdjust.fromInt(AnyConverter.toInt(property.Value));
+ adjust = ParagraphAdjust.fromInt(AnyConverter.toInt(
+ property.Value));
}
+
if (adjust != null) {
if (adjust.equals(ParagraphAdjust.LEFT)) {
- StyleConstants.setAlignment(as, StyleConstants.ALIGN_LEFT);
+ StyleConstants.setAlignment(as,
+ StyleConstants.ALIGN_LEFT);
} else if (adjust.equals(ParagraphAdjust.RIGHT)) {
- StyleConstants.setAlignment(as, StyleConstants.ALIGN_RIGHT);
+ StyleConstants.setAlignment(as,
+ StyleConstants.ALIGN_RIGHT);
} else if (adjust.equals(ParagraphAdjust.CENTER)) {
- StyleConstants.setAlignment(as, StyleConstants.ALIGN_CENTER);
- } else if (adjust.equals(ParagraphAdjust.BLOCK) || adjust.equals(ParagraphAdjust.STRETCH)) {
- StyleConstants.setAlignment(as, StyleConstants.ALIGN_JUSTIFIED);
+ StyleConstants.setAlignment(as,
+ StyleConstants.ALIGN_CENTER);
+ } else if (adjust.equals(ParagraphAdjust.BLOCK) ||
+ adjust.equals(ParagraphAdjust.STRETCH)) {
+ StyleConstants.setAlignment(as,
+ StyleConstants.ALIGN_JUSTIFIED);
}
} else if (Build.DEBUG) {
- System.err.println("Invalid property value for key ParaAdjust: " + property.Value.getClass().getName());
+ System.err.println(
+ "Invalid property value for key ParaAdjust: " +
+ property.Value.getClass().getName());
}
- // Map background color
+ // Map background color
} else if (property.Name.equals("CharBackColor")) {
- StyleConstants.setBackground(as, new java.awt.Color(AnyConverter.toInt(property.Value)));
-
- // FIXME: BidiLevel
+ StyleConstants.setBackground(as,
+ new java.awt.Color(AnyConverter.toInt(property.Value)));
- // Set bold attribute
+ // FIXME: BidiLevel
+ // Set bold attribute
} else if (property.Name.equals("CharWeight")) {
boolean isBold = AnyConverter.toFloat(property.Value) > 125;
StyleConstants.setBold(as, isBold);
- // FIXME: Java 1.4 ComponentAttribute, ComponentElementName, ComposedTextAttribute
-
- // Set FirstLineIndent attribute
+ // FIXME: Java 1.4 ComponentAttribute, ComponentElementName, ComposedTextAttribute
+ // Set FirstLineIndent attribute
} else if (property.Name.equals("ParaFirstLineIndent")) {
- StyleConstants.setFirstLineIndent(as, (float) (toPointFactor * AnyConverter.toInt(property.Value)));
+ StyleConstants.setFirstLineIndent(as,
+ (float) (toPointFactor * AnyConverter.toInt(property.Value)));
- // Set font family attribute
+ // Set font family attribute
} else if (property.Name.equals("CharFontPitch")) {
- if (AnyConverter.toShort (property.Value) == 2) {
+ if (AnyConverter.toShort(property.Value) == 2) {
StyleConstants.setFontFamily(as, "Proportional");
}
- // Set font size attribute
+ // Set font size attribute
} else if (property.Name.equals("CharHeight")) {
- StyleConstants.setFontSize(as, (int) AnyConverter.toFloat(property.Value));
+ StyleConstants.setFontSize(as,
+ (int) AnyConverter.toFloat(property.Value));
- // Map foreground color
+ // Map foreground color
} else if (property.Name.equals("CharColor")) {
- StyleConstants.setForeground(as, new java.awt.Color(AnyConverter.toInt(property.Value)));
+ StyleConstants.setForeground(as,
+ new java.awt.Color(AnyConverter.toInt(property.Value)));
- // FIXME: IconAttribute, IconElementName
-
- // Set italic attribute
+ // FIXME: IconAttribute, IconElementName
+ // Set italic attribute
} else if (property.Name.equals("CharPosture")) {
FontSlant fs = null;
+
if (property.Value instanceof FontSlant) {
fs = (FontSlant) property.Value;
} else if (property.Value instanceof Any) {
- fs = (FontSlant) AnyConverter.toObject(new Type(FontSlant.class), property.Value);
+ fs = (FontSlant) AnyConverter.toObject(new Type(
+ FontSlant.class), property.Value);
}
+
if (fs != null) {
StyleConstants.setItalic(as, FontSlant.ITALIC.equals(fs));
}
- // Set left indent attribute
+ // Set left indent attribute
} else if (property.Name.equals("ParaLeftMargin")) {
- StyleConstants.setLeftIndent(as, (float) (toPointFactor * AnyConverter.toInt(property.Value)));
+ StyleConstants.setLeftIndent(as,
+ (float) (toPointFactor * AnyConverter.toInt(property.Value)));
- // Set right indent attribute
+ // Set right indent attribute
} else if (property.Name.equals("ParaRightMargin")) {
- StyleConstants.setRightIndent(as, (float) (toPointFactor * AnyConverter.toInt(property.Value)));
+ StyleConstants.setRightIndent(as,
+ (float) (toPointFactor * AnyConverter.toInt(property.Value)));
}
-
// Set line spacing attribute
else if (property.Name.equals("ParaLineSpacing")) {
LineSpacing ls = null;
+
if (property.Value instanceof LineSpacing) {
ls = (LineSpacing) property.Value;
} else if (property.Value instanceof Any) {
- ls = (LineSpacing) AnyConverter.toObject(new Type(LineSpacing.class), property.Value);
+ ls = (LineSpacing) AnyConverter.toObject(new Type(
+ LineSpacing.class), property.Value);
}
+
if (ls != null) {
- StyleConstants.setLineSpacing(as, (float) (toPointFactor * ls.Height));
+ StyleConstants.setLineSpacing(as,
+ (float) (toPointFactor * ls.Height));
}
}
-
// FIXME: Java 1.4 NameAttribute, Orientation, ResolveAttribute
-
// Set space above attribute
else if (property.Name.equals("ParaTopMargin")) {
- StyleConstants.setSpaceAbove(as, (float) (toPointFactor * AnyConverter.toInt(property.Value)));
+ StyleConstants.setSpaceAbove(as,
+ (float) (toPointFactor * AnyConverter.toInt(property.Value)));
}
-
// Set space below attribute
else if (property.Name.equals("ParaBottomMargin")) {
- StyleConstants.setSpaceBelow(as, (float) (toPointFactor * AnyConverter.toInt(property.Value)));
+ StyleConstants.setSpaceBelow(as,
+ (float) (toPointFactor * AnyConverter.toInt(property.Value)));
- // Set strike through attribute
+ // Set strike through attribute
} else if (property.Name.equals("CharStrikeout")) {
boolean isStrikeThrough = (FontStrikeout.NONE != AnyConverter.toShort(property.Value));
StyleConstants.setStrikeThrough(as, isStrikeThrough);
- // Set sub-/superscript attribute
+ // Set sub-/superscript attribute
} else if (property.Name.equals("CharEscapement")) {
short value = AnyConverter.toShort(property.Value);
+
if (value > 0) {
StyleConstants.setSuperscript(as, true);
} else if (value < 0) {
StyleConstants.setSubscript(as, true);
}
- // Set tabset attribute
+ // Set tabset attribute
} else if (property.Name.equals("ParaTabStops")) {
TabStop[] unoTabStops = (TabStop[]) AnyConverter.toArray(property.Value);
javax.swing.text.TabStop[] tabStops = new javax.swing.text.TabStop[unoTabStops.length];
@@ -282,83 +368,70 @@ public class AccessibleTextImpl implements javax.accessibility.AccessibleText {
if (unoTabStops[index2].Alignment.equals(TabAlign.LEFT)) {
tabStops[index2] = new javax.swing.text.TabStop(pos,
- javax.swing.text.TabStop.ALIGN_LEFT,
- javax.swing.text.TabStop.LEAD_NONE);
- }
- else if (unoTabStops[index2].Alignment.equals(TabAlign.CENTER)) {
+ javax.swing.text.TabStop.ALIGN_LEFT,
+ javax.swing.text.TabStop.LEAD_NONE);
+ } else if (unoTabStops[index2].Alignment.equals(
+ TabAlign.CENTER)) {
tabStops[index2] = new javax.swing.text.TabStop(pos,
- javax.swing.text.TabStop.ALIGN_CENTER,
- javax.swing.text.TabStop.LEAD_NONE);
- }
- else if (unoTabStops[index2].Alignment.equals(TabAlign.RIGHT)) {
+ javax.swing.text.TabStop.ALIGN_CENTER,
+ javax.swing.text.TabStop.LEAD_NONE);
+ } else if (unoTabStops[index2].Alignment.equals(
+ TabAlign.RIGHT)) {
tabStops[index2] = new javax.swing.text.TabStop(pos,
- javax.swing.text.TabStop.ALIGN_RIGHT,
- javax.swing.text.TabStop.LEAD_NONE);
- }
- else if (unoTabStops[index2].Alignment.equals(TabAlign.DECIMAL)) {
+ javax.swing.text.TabStop.ALIGN_RIGHT,
+ javax.swing.text.TabStop.LEAD_NONE);
+ } else if (unoTabStops[index2].Alignment.equals(
+ TabAlign.DECIMAL)) {
tabStops[index2] = new javax.swing.text.TabStop(pos,
- javax.swing.text.TabStop.ALIGN_DECIMAL,
- javax.swing.text.TabStop.LEAD_NONE);
- }
- else {
+ javax.swing.text.TabStop.ALIGN_DECIMAL,
+ javax.swing.text.TabStop.LEAD_NONE);
+ } else {
tabStops[index2] = new javax.swing.text.TabStop(pos);
}
}
// Re-use tabSet object if possible to make AttributeSet.equals work
- if ((this.tabSet == null) || !java.util.Arrays.equals(tabStops, this.tabStops)) {
+ if ((this.tabSet == null) ||
+ !java.util.Arrays.equals(tabStops, this.tabStops)) {
this.tabStops = tabStops;
this.tabSet = new javax.swing.text.TabSet(tabStops);
}
- StyleConstants.setTabSet(as, this.tabSet);
+ StyleConstants.setTabSet(as, this.tabSet);
- // Set underline attribute
+ // Set underline attribute
} else if (property.Name.equals("CharUnderline")) {
boolean isUnderline = (FontUnderline.NONE != AnyConverter.toShort(property.Value));
StyleConstants.setUnderline(as, isUnderline);
}
} catch (com.sun.star.lang.IllegalArgumentException e) {
if (Build.DEBUG) {
- System.err.println("*** ERROR *** " + e .getClass().getName() + " caught for property " + property.Name + ": " + e.getMessage());
- System.err.println(" value is of type " + property.Value.getClass().getName());
+ System.err.println("*** ERROR *** " + e.getClass().getName() +
+ " caught for property " + property.Name + ": " +
+ e.getMessage());
+ System.err.println(" value is of type " +
+ property.Value.getClass().getName());
}
}
}
- static String [] attributeList = {
- "ParaAdjust",
- "CharBackColor",
- "CharWeight",
- "ParaFirstLineIndent",
- "CharFontPitch",
- "CharHeight",
- "CharColor",
- "CharPosture",
- "ParaLeftMargin",
- "ParaLineSpacing",
- "ParaTopMargin",
- "ParaBottomMargin",
- "CharStrikeout",
- "CharEscapement",
- "ParaTabStops",
- "CharUnderline"
- };
-
/** Returns the AttributSet for a given character at a given index */
public javax.swing.text.AttributeSet getCharacterAttribute(int index) {
try {
- com.sun.star.beans.PropertyValue[] propertyValues = unoObject.getCharacterAttributes(index, attributeList);
+ com.sun.star.beans.PropertyValue[] propertyValues = unoObject.getCharacterAttributes(index,
+ attributeList);
javax.swing.text.SimpleAttributeSet attributeSet = new javax.swing.text.SimpleAttributeSet();
+
if (null != propertyValues) {
for (int i = 0; i < propertyValues.length; i++) {
setAttribute(attributeSet, propertyValues[i]);
}
}
+
return attributeSet;
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
- if (Build.DEBUG) {
- System.err.println(e.getClass().getName() + " caught at index " + index + ": " + e.getMessage());
+ if ((index > 0) && (getCharCount() == index)) {
+ return getCharacterAttribute(index - 1);
}
return null;
}
@@ -367,16 +440,8 @@ public class AccessibleTextImpl implements javax.accessibility.AccessibleText {
/** Given a point in local coordinates, return the zero-based index of the character under that point */
public int getIndexAtPoint(java.awt.Point point) {
try {
-// if (Build.DEBUG) {
-// System.err.println(this + "getIndexAtPoint(" + point.x + ", " + point.y + ") returns " +
-// unoObject.getIndexAtPoint(new Point(point.x, point.y)));
-// }
return unoObject.getIndexAtPoint(new Point(point.x, point.y));
} catch (com.sun.star.uno.RuntimeException e) {
- if (Build.DEBUG) {
- System.err.println(this + "RuntimeException caught for getIndexAtPoint(" + point.x + ", " + point.y + ")");
- System.err.println(e.getMessage());
- }
return -1;
}
}
@@ -385,9 +450,11 @@ public class AccessibleTextImpl implements javax.accessibility.AccessibleText {
public int getSelectionEnd() {
try {
int index = unoObject.getSelectionEnd();
+
if (index == -1) {
index = getCaretPosition();
}
+
return index;
} catch (com.sun.star.uno.RuntimeException e) {
return -1;
@@ -397,75 +464,56 @@ public class AccessibleTextImpl implements javax.accessibility.AccessibleText {
/** Returns the string before a given index */
public java.lang.String getBeforeIndex(int part, int index) {
short type = toTextType(part);
- if (type > 0) {
- try {
- // the office returns an empty string when asking for the word at
- // the position of a blank
- TextSegment ts = unoObject.getTextBeforeIndex(index, type);
- if ((part == AccessibleText.WORD) && (ts.SegmentText.length() == 0)) {
-// int max = getCharCount();
-// for (int i=index; i < max; i++) {
-// if (! unoObject.getTextBeforeIndex(i, AccessibleTextType.CHARACTER).equals(" "))
-// break;
-// s += " ";
-// }
- ts.SegmentText = " ";
- }
- return ts.SegmentText;
- } catch (com.sun.star.uno.Exception e) {
- if (Build.DEBUG) {
- System.err.println(this + e .getClass().getName() + " caught in getBeforeIndex(" + part + ", " + index + "): ");
- System.err.println(e.getMessage());
- }
+
+ try {
+ // the office returns an empty string when asking for the word at
+ // the position of a blank
+ TextSegment ts = unoObject.getTextBeforeIndex(index, type);
+
+ if ((part == AccessibleText.WORD) &&
+ (ts.SegmentText.length() == 0)) {
+ // FIXME: should potentially return more than one blank, but
+ // since this will be fixed in the office at some time ..
+ return " ";
}
+
+ return ts.SegmentText;
+ } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
+ // Workaround for #104847#
+ if ((type == AccessibleTextType.LINE) && (index > 0) && (getCharCount() == index)) {
+ return getBeforeIndex(part, index - 1);
+ }
+ } catch (com.sun.star.lang.IllegalArgumentException e) {
}
+
return null;
}
/** Returns the string at a given index */
public java.lang.String getAtIndex(int part, int index) {
short type = toTextType(part);
- if (type > 0) {
- try {
- // the office returns an empty string when asking for the word at
- // the position of a blank
- TextSegment ts = unoObject.getTextAtIndex(index, type);
- if ((part == AccessibleText.WORD) && (ts.SegmentText.length() == 0)) {
-// int max = getCharCount();
-// for (int i=index; i < max; i++) {
-// if (! unoObject.getTextAtIndex(i, AccessibleTextType.CHARACTER).equals(" "))
-// break;
-// s += " ";
-// }
- ts.SegmentText = " ";
-
- // Workaround for #104847#
- } else if ((type == AccessibleTextType.LINE) && (ts.SegmentText.length() == 0)) {
- if (index == getCharCount()) {
- ts = unoObject.getTextAtIndex(index - 1, type);
- }
- }
-// if (Build.DEBUG) {
-// System.err.println(this + " getAtIndex(" + part + "," + index + ") returns " + s + " (length: " + s.length() + ")");
-// }
- return ts.SegmentText;
- } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
- if (Build.DEBUG) {
- System.err.println(this + "IndexOutOfBoundsException caught for getAtIndex(" + part + "," + index + ")");
- System.err.println(e.getMessage());
- }
- // Workaround for #104847#
- if (type == AccessibleTextType.LINE) {
+ try {
+ // the office returns an empty string when asking for the word at
+ // the position of a blank
+ TextSegment ts = unoObject.getTextAtIndex(index, type);
+
+ if ((part == AccessibleText.WORD) &&
+ (ts.SegmentText.length() == 0)) {
+ // FIXME: should potentially return more than one blank, but
+ // since this will be fixed in the office at some time ..
+ return " ";
+ }
- try {
- return unoObject.getTextAtIndex(index - 1, type).SegmentText;
- } catch (com.sun.star.uno.Exception e2) {
- }
- }
- } catch (com.sun.star.uno.Exception e) {
+ return ts.SegmentText;
+ } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
+ // Workaround for #104847#
+ if ((type == AccessibleTextType.LINE) && (index > 0) && (getCharCount() == index)) {
+ return getAtIndex(part, index - 1);
}
+ } catch (com.sun.star.lang.IllegalArgumentException e) {
}
+
return null;
}
@@ -475,6 +523,7 @@ public class AccessibleTextImpl implements javax.accessibility.AccessibleText {
return unoObject.getCharacterCount();
} catch (com.sun.star.uno.RuntimeException e) {
}
+
return 0;
}
@@ -484,6 +533,7 @@ public class AccessibleTextImpl implements javax.accessibility.AccessibleText {
return unoObject.getSelectedText();
} catch (com.sun.star.uno.RuntimeException e) {
}
+
return null;
}
@@ -493,34 +543,12 @@ public class AccessibleTextImpl implements javax.accessibility.AccessibleText {
Rectangle unoRect = unoObject.getCharacterBounds(index);
return new java.awt.Rectangle(unoRect.X, unoRect.Y, unoRect.Width, unoRect.Height);
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
-// if (Build.DEBUG) {
-// System.err.println(this + "IndexOutOfBoundsException caught for getCharacterBounds(" + index + ")");
-// System.err.println(e.getMessage());
-// }
- if (index > 0) {
+ if ((index > 0) && (getCharCount() == index)) {
return getCharacterBounds(index - 1);
}
} catch (com.sun.star.uno.RuntimeException e) {
- if (Build.DEBUG) {
- System.err.println(this + "RuntimeException caught for getCharacterBounds(" + index + ")");
- System.err.println(e.getMessage());
- }
}
- return new java.awt.Rectangle();
- }
- public String toString() {
- try {
- XAccessibleContext unoAccessibleContext = (XAccessibleContext)
- UnoRuntime.queryInterface(XAccessibleContext.class, unoObject);
- if (unoAccessibleContext != null) {
- return "[" + AccessibleRoleAdapter.getAccessibleRole(unoAccessibleContext.getAccessibleRole()) + "] " +
- unoAccessibleContext.getAccessibleName() + ": ";
- } else {
- return super.toString();
- }
- } catch (com.sun.star.uno.RuntimeException e) {
- return super.toString();
- }
+ return new java.awt.Rectangle();
}
}