INTEGRATION: CWS qadev29 (1.10.36); FILE MERGED
2007/04/24 10:08:42 cn 1.10.36.2: #i74690#:new method "getSheetCell()" 2007/04/23 13:23:24 cn 1.10.36.1: #i74190# new method getSheetCell()
This commit is contained in:
parent
42c656fa8c
commit
347fc35a51
1 changed files with 108 additions and 62 deletions
|
@ -4,9 +4,9 @@
|
|||
*
|
||||
* $RCSfile: AccessibilityTools.java,v $
|
||||
*
|
||||
* $Revision: 1.10 $
|
||||
* $Revision: 1.11 $
|
||||
*
|
||||
* last change: $Author: rt $ $Date: 2005-09-08 17:31:05 $
|
||||
* last change: $Author: ihi $ $Date: 2007-06-04 13:31:30 $
|
||||
*
|
||||
* The Contents of this file are made available subject to
|
||||
* the terms of GNU Lesser General Public License Version 2.1.
|
||||
|
@ -37,11 +37,8 @@ package util;
|
|||
import com.sun.star.accessibility.XAccessible;
|
||||
import com.sun.star.accessibility.XAccessibleComponent;
|
||||
import com.sun.star.accessibility.XAccessibleContext;
|
||||
import com.sun.star.accessibility.XAccessibleRelationSet;
|
||||
import com.sun.star.accessibility.XAccessibleStateSet;
|
||||
import com.sun.star.awt.XWindow;
|
||||
import com.sun.star.frame.XController;
|
||||
import com.sun.star.frame.XDesktop;
|
||||
import com.sun.star.frame.XFrame;
|
||||
import com.sun.star.frame.XModel;
|
||||
import com.sun.star.lang.XMultiServiceFactory;
|
||||
|
@ -66,10 +63,10 @@ public class AccessibilityTools {
|
|||
|
||||
try {
|
||||
xAccessible = (XAccessible) UnoRuntime.queryInterface(
|
||||
XAccessible.class, xObject);
|
||||
XAccessible.class, xObject);
|
||||
} catch (Exception e) {
|
||||
System.out.println(
|
||||
"caught exception while getting accessible object" + e);
|
||||
"caught exception while getting accessible object" + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
@ -77,17 +74,17 @@ public class AccessibilityTools {
|
|||
}
|
||||
|
||||
public static XWindow getCurrentContainerWindow(XMultiServiceFactory msf,
|
||||
XModel xModel) {
|
||||
XModel xModel) {
|
||||
return getWindow(msf, xModel, true);
|
||||
}
|
||||
|
||||
public static XWindow getCurrentWindow(XMultiServiceFactory msf,
|
||||
XModel xModel) {
|
||||
XModel xModel) {
|
||||
return getWindow(msf, xModel, false);
|
||||
}
|
||||
|
||||
private static XWindow getWindow(XMultiServiceFactory msf, XModel xModel,
|
||||
boolean containerWindow) {
|
||||
boolean containerWindow) {
|
||||
XWindow xWindow = null;
|
||||
|
||||
try {
|
||||
|
@ -123,7 +120,7 @@ public class AccessibilityTools {
|
|||
}
|
||||
|
||||
public static XAccessibleContext getAccessibleObjectForRole(XAccessible xacc,
|
||||
short role) {
|
||||
short role) {
|
||||
SearchedContext = null;
|
||||
SearchedAccessible = null;
|
||||
getAccessibleObjectForRole_(xacc, role);
|
||||
|
@ -132,8 +129,8 @@ public class AccessibilityTools {
|
|||
}
|
||||
|
||||
public static XAccessibleContext getAccessibleObjectForRole(XAccessible xacc,
|
||||
short role,
|
||||
boolean ignoreShowing) {
|
||||
short role,
|
||||
boolean ignoreShowing) {
|
||||
SearchedContext = null;
|
||||
SearchedAccessible = null;
|
||||
|
||||
|
@ -147,7 +144,7 @@ public class AccessibilityTools {
|
|||
}
|
||||
|
||||
public static void getAccessibleObjectForRoleIgnoreShowing_(XAccessible xacc,
|
||||
short role) {
|
||||
short role) {
|
||||
XAccessibleContext ac = xacc.getAccessibleContext();
|
||||
|
||||
if (ac.getAccessibleRole() == role) {
|
||||
|
@ -163,7 +160,7 @@ public class AccessibilityTools {
|
|||
for (int i = 0; i < k; i++) {
|
||||
try {
|
||||
getAccessibleObjectForRoleIgnoreShowing_(
|
||||
ac.getAccessibleChild(i), role);
|
||||
ac.getAccessibleChild(i), role);
|
||||
|
||||
if (SearchedContext != null) {
|
||||
return;
|
||||
|
@ -176,10 +173,10 @@ public class AccessibilityTools {
|
|||
}
|
||||
|
||||
public static void getAccessibleObjectForRole_(XAccessible xacc,
|
||||
short role) {
|
||||
short role) {
|
||||
XAccessibleContext ac = xacc.getAccessibleContext();
|
||||
boolean isShowing = ac.getAccessibleStateSet()
|
||||
.contains(com.sun.star.accessibility.AccessibleStateType.SHOWING);
|
||||
.contains(com.sun.star.accessibility.AccessibleStateType.SHOWING);
|
||||
|
||||
if ((ac.getAccessibleRole() == role) && isShowing) {
|
||||
SearchedContext = ac;
|
||||
|
@ -206,31 +203,31 @@ public class AccessibilityTools {
|
|||
}
|
||||
|
||||
public static XAccessibleContext getAccessibleObjectForRole(XAccessible xacc,
|
||||
short role,
|
||||
String name) {
|
||||
short role,
|
||||
String name) {
|
||||
return getAccessibleObjectForRole(xacc, role, name, "");
|
||||
}
|
||||
|
||||
public static XAccessibleContext getAccessibleObjectForRole(XAccessible xacc,
|
||||
short role,
|
||||
String name,
|
||||
boolean ignoreShowing) {
|
||||
short role,
|
||||
String name,
|
||||
boolean ignoreShowing) {
|
||||
if (ignoreShowing) {
|
||||
return getAccessibleObjectForRoleIgnoreShowing(xacc, role, name,
|
||||
"");
|
||||
"");
|
||||
} else {
|
||||
return getAccessibleObjectForRole(xacc, role, name, "");
|
||||
}
|
||||
}
|
||||
|
||||
public static XAccessibleContext getAccessibleObjectForRoleIgnoreShowing(XAccessible xacc,
|
||||
short role,
|
||||
String name,
|
||||
String implName) {
|
||||
short role,
|
||||
String name,
|
||||
String implName) {
|
||||
XAccessibleContext ac = xacc.getAccessibleContext();
|
||||
if ((ac.getAccessibleRole() == role) &&
|
||||
(ac.getAccessibleName().indexOf(name) > -1) &&
|
||||
(utils.getImplName(ac).indexOf(implName) > -1)) {
|
||||
(ac.getAccessibleName().indexOf(name) > -1) &&
|
||||
(utils.getImplName(ac).indexOf(implName) > -1)) {
|
||||
SearchedAccessible = xacc;
|
||||
|
||||
//System.out.println("FOUND the desired component -- "+ ac.getAccessibleName() +isShowing);
|
||||
|
@ -245,8 +242,8 @@ public class AccessibilityTools {
|
|||
for (int i = 0; i < k; i++) {
|
||||
try {
|
||||
XAccessibleContext ac1 = getAccessibleObjectForRoleIgnoreShowing(
|
||||
ac.getAccessibleChild(i),
|
||||
role, name, implName);
|
||||
ac.getAccessibleChild(i),
|
||||
role, name, implName);
|
||||
|
||||
if (ac1 != null) {
|
||||
return ac1;
|
||||
|
@ -261,16 +258,16 @@ public class AccessibilityTools {
|
|||
}
|
||||
|
||||
public static XAccessibleContext getAccessibleObjectForRole(XAccessible xacc,
|
||||
short role,
|
||||
String name,
|
||||
String implName) {
|
||||
short role,
|
||||
String name,
|
||||
String implName) {
|
||||
XAccessibleContext ac = xacc.getAccessibleContext();
|
||||
boolean isShowing = ac.getAccessibleStateSet()
|
||||
.contains(com.sun.star.accessibility.AccessibleStateType.SHOWING);
|
||||
.contains(com.sun.star.accessibility.AccessibleStateType.SHOWING);
|
||||
if ((ac.getAccessibleRole() == role) &&
|
||||
(ac.getAccessibleName().indexOf(name) > -1) &&
|
||||
(utils.getImplName(ac).indexOf(implName) > -1) &&
|
||||
isShowing) {
|
||||
(ac.getAccessibleName().indexOf(name) > -1) &&
|
||||
(utils.getImplName(ac).indexOf(implName) > -1) &&
|
||||
isShowing) {
|
||||
SearchedAccessible = xacc;
|
||||
|
||||
//System.out.println("FOUND the desired component -- "+ ac.getAccessibleName() +isShowing);
|
||||
|
@ -285,8 +282,8 @@ public class AccessibilityTools {
|
|||
for (int i = 0; i < k; i++) {
|
||||
try {
|
||||
XAccessibleContext ac1 = getAccessibleObjectForRole(
|
||||
ac.getAccessibleChild(i),
|
||||
role, name, implName);
|
||||
ac.getAccessibleChild(i),
|
||||
role, name, implName);
|
||||
|
||||
if (ac1 != null) {
|
||||
return ac1;
|
||||
|
@ -300,6 +297,55 @@ public class AccessibilityTools {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This methods retunrs the <CODE>XAccessibleContext</CODE> of a named Sheet-Cell like "G5".<p>
|
||||
* @param xSheetAcc The <CODE>XAccessibleContext</CODE> of a Sheet
|
||||
* @param cellName The name of a cell like "A5"
|
||||
* @return the <CODE>XAccessiblecontext</CODE> of the named cell
|
||||
*/
|
||||
public static XAccessibleContext getSheetCell(XAccessibleContext xSheetAcc, String cellName){
|
||||
|
||||
int cellIndex = 0;
|
||||
int column =0;
|
||||
int charMem = 0;
|
||||
for (int n=0; n<cellName.length(); n++){
|
||||
String cha = cellName.substring(n,n+1);
|
||||
System.out.println("char: " + cha + " ");
|
||||
|
||||
byte[] bytes = cha.getBytes();
|
||||
|
||||
if ((bytes[0] >= 'A') && (bytes[0] <= 'Z')){
|
||||
charMem = bytes[0]-64;
|
||||
column++;
|
||||
if ( column == 2 ){
|
||||
cellIndex += charMem * 26;
|
||||
}
|
||||
cellIndex= cellIndex+ (bytes[0]-65);
|
||||
} else {
|
||||
String sNumb = cellName.substring(n, cellName.length());
|
||||
int iNumb = new Integer(0).valueOf(sNumb).intValue();
|
||||
cellIndex += (iNumb-1) * 256;
|
||||
System.out.println("numb:" + (iNumb-1) * 256);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//System.out.println("cellName: " + cellName + " cellIndex: " + cellIndex);
|
||||
|
||||
try {
|
||||
XAccessibleContext ac = xSheetAcc.getAccessibleChild(cellIndex).getAccessibleContext();
|
||||
System.out.println(ac.getAccessibleRole() + "," +
|
||||
ac.getAccessibleName() + "(" +
|
||||
ac.getAccessibleDescription() + "):" +
|
||||
utils.getImplName(ac));
|
||||
|
||||
return ac;
|
||||
} catch (com.sun.star.lang.IndexOutOfBoundsException ex) {
|
||||
System.out.println("ERROR: could not get child at index " + cellIndex +"': " + ex.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void printAccessibleTree(PrintWriter log, XAccessible xacc, boolean debugIsActive) {
|
||||
debug = debugIsActive;
|
||||
if (debug) printAccessibleTree(log, xacc, "");
|
||||
|
@ -310,31 +356,31 @@ public class AccessibilityTools {
|
|||
}
|
||||
|
||||
protected static void printAccessibleTree(PrintWriter log,
|
||||
XAccessible xacc, String indent) {
|
||||
XAccessible xacc, String indent) {
|
||||
|
||||
XAccessibleContext ac = xacc.getAccessibleContext();
|
||||
|
||||
logging(log,indent + ac.getAccessibleRole() + "," +
|
||||
ac.getAccessibleName() + "(" +
|
||||
ac.getAccessibleDescription() + "):" +
|
||||
utils.getImplName(ac));
|
||||
ac.getAccessibleName() + "(" +
|
||||
ac.getAccessibleDescription() + "):" +
|
||||
utils.getImplName(ac));
|
||||
|
||||
XAccessibleComponent aComp = (XAccessibleComponent) UnoRuntime.queryInterface(
|
||||
XAccessibleComponent.class, xacc);
|
||||
XAccessibleComponent.class, xacc);
|
||||
|
||||
if (aComp != null) {
|
||||
String bounds = "(" + aComp.getBounds().X + "," +
|
||||
aComp.getBounds().Y + ")" + " (" +
|
||||
aComp.getBounds().Width + "," +
|
||||
aComp.getBounds().Height + ")";
|
||||
aComp.getBounds().Y + ")" + " (" +
|
||||
aComp.getBounds().Width + "," +
|
||||
aComp.getBounds().Height + ")";
|
||||
bounds = "The boundary Rectangle is " + bounds;
|
||||
logging(log,indent + indent + bounds);
|
||||
}
|
||||
|
||||
boolean isShowing = ac.getAccessibleStateSet()
|
||||
.contains(com.sun.star.accessibility.AccessibleStateType.SHOWING);
|
||||
.contains(com.sun.star.accessibility.AccessibleStateType.SHOWING);
|
||||
logging(log,indent + indent + "StateType contains SHOWING: " +
|
||||
isShowing);
|
||||
isShowing);
|
||||
|
||||
int k = ac.getAccessibleChildCount();
|
||||
|
||||
|
@ -345,7 +391,7 @@ public class AccessibilityTools {
|
|||
for (int i = 0; i < k; i++) {
|
||||
try {
|
||||
printAccessibleTree(log, ac.getAccessibleChild(i),
|
||||
indent + " ");
|
||||
indent + " ");
|
||||
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
|
||||
System.out.println("Couldn't get Child");
|
||||
}
|
||||
|
@ -360,7 +406,7 @@ public class AccessibilityTools {
|
|||
for (int i = st; i < k; i++) {
|
||||
try {
|
||||
printAccessibleTree(log, ac.getAccessibleChild(i),
|
||||
indent + " ");
|
||||
indent + " ");
|
||||
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
|
||||
System.out.println("Couldn't get Child");
|
||||
}
|
||||
|
@ -370,16 +416,16 @@ public class AccessibilityTools {
|
|||
|
||||
public static String accessibleToString(Object AC) {
|
||||
XAccessibleContext xAC = (XAccessibleContext) UnoRuntime.queryInterface(
|
||||
XAccessibleContext.class, AC);
|
||||
XAccessibleContext.class, AC);
|
||||
|
||||
if (xAC != null) {
|
||||
return "" + xAC.getAccessibleRole() + "," +
|
||||
xAC.getAccessibleName() + "(" +
|
||||
xAC.getAccessibleDescription() + "):";
|
||||
xAC.getAccessibleName() + "(" +
|
||||
xAC.getAccessibleDescription() + "):";
|
||||
}
|
||||
|
||||
XAccessible xA = (XAccessible) UnoRuntime.queryInterface(
|
||||
XAccessible.class, AC);
|
||||
XAccessible.class, AC);
|
||||
|
||||
if (xA == null) {
|
||||
return "(Not supported)";
|
||||
|
@ -388,7 +434,7 @@ public class AccessibilityTools {
|
|||
xAC = xA.getAccessibleContext();
|
||||
|
||||
return "" + xAC.getAccessibleRole() + "," + xAC.getAccessibleName() +
|
||||
"(" + xAC.getAccessibleDescription() + ")";
|
||||
"(" + xAC.getAccessibleDescription() + ")";
|
||||
}
|
||||
|
||||
public static boolean equals(XAccessible c1, XAccessible c2) {
|
||||
|
@ -397,7 +443,7 @@ public class AccessibilityTools {
|
|||
}
|
||||
|
||||
return AccessibilityTools.equals(c1.getAccessibleContext(),
|
||||
c2.getAccessibleContext());
|
||||
c2.getAccessibleContext());
|
||||
}
|
||||
|
||||
public static boolean equals(XAccessibleContext c1, XAccessibleContext c2) {
|
||||
|
@ -414,7 +460,7 @@ public class AccessibilityTools {
|
|||
}
|
||||
|
||||
if (!c1.getAccessibleDescription()
|
||||
.equals(c2.getAccessibleDescription())) {
|
||||
.equals(c2.getAccessibleDescription())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -423,10 +469,10 @@ public class AccessibilityTools {
|
|||
}
|
||||
|
||||
return AccessibilityTools.equals(c1.getAccessibleParent(),
|
||||
c2.getAccessibleParent());
|
||||
c2.getAccessibleParent());
|
||||
}
|
||||
|
||||
private static void logging(PrintWriter log, String content){
|
||||
if (debug) log.println(content);
|
||||
}
|
||||
private static void logging(PrintWriter log, String content){
|
||||
if (debug) log.println(content);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue