1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir package util; 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible; 30*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleComponent; 31*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleContext; 32*cdf0e10cSrcweir import com.sun.star.awt.XWindow; 33*cdf0e10cSrcweir import com.sun.star.frame.XController; 34*cdf0e10cSrcweir import com.sun.star.frame.XFrame; 35*cdf0e10cSrcweir import com.sun.star.frame.XModel; 36*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 37*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 38*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir import java.io.PrintWriter; 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir public class AccessibilityTools { 44*cdf0e10cSrcweir public static XAccessibleContext SearchedContext = null; 45*cdf0e10cSrcweir public static XAccessible SearchedAccessible = null; 46*cdf0e10cSrcweir private static boolean debug = false; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir public AccessibilityTools() { 49*cdf0e10cSrcweir //done = false; 50*cdf0e10cSrcweir SearchedContext = null; 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir public static XAccessible getAccessibleObject(XInterface xObject) { 54*cdf0e10cSrcweir return UnoRuntime.queryInterface(XAccessible.class, xObject); 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir public static XWindow getCurrentContainerWindow(XMultiServiceFactory msf, 58*cdf0e10cSrcweir XModel xModel) { 59*cdf0e10cSrcweir return getWindow(msf, xModel, true); 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir public static XWindow getCurrentWindow(XMultiServiceFactory msf, 63*cdf0e10cSrcweir XModel xModel) { 64*cdf0e10cSrcweir return getWindow(msf, xModel, false); 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir private static XWindow getWindow(XMultiServiceFactory msf, XModel xModel, 68*cdf0e10cSrcweir boolean containerWindow) { 69*cdf0e10cSrcweir XWindow xWindow = null; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir try { 72*cdf0e10cSrcweir if (xModel == null) { 73*cdf0e10cSrcweir System.out.println("invalid model (==null)"); 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir XController xController = xModel.getCurrentController(); 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir if (xController == null) { 79*cdf0e10cSrcweir System.out.println("can't get controller from model"); 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir XFrame xFrame = xController.getFrame(); 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir if (xFrame == null) { 85*cdf0e10cSrcweir System.out.println("can't get frame from controller"); 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir if (containerWindow) 89*cdf0e10cSrcweir xWindow = xFrame.getContainerWindow(); 90*cdf0e10cSrcweir else 91*cdf0e10cSrcweir xWindow = xFrame.getComponentWindow(); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir if (xWindow == null) { 94*cdf0e10cSrcweir System.out.println("can't get window from frame"); 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir } catch (Exception e) { 97*cdf0e10cSrcweir System.out.println("caught exception while getting current window" + e); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir return xWindow; 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir public static XAccessibleContext getAccessibleObjectForRole(XAccessible xacc, 104*cdf0e10cSrcweir short role) { 105*cdf0e10cSrcweir SearchedContext = null; 106*cdf0e10cSrcweir SearchedAccessible = null; 107*cdf0e10cSrcweir getAccessibleObjectForRole_(xacc, role); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir return SearchedContext; 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir public static XAccessibleContext getAccessibleObjectForRole(XAccessible xacc, 113*cdf0e10cSrcweir short role, 114*cdf0e10cSrcweir boolean ignoreShowing) { 115*cdf0e10cSrcweir SearchedContext = null; 116*cdf0e10cSrcweir SearchedAccessible = null; 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir if (ignoreShowing) { 119*cdf0e10cSrcweir getAccessibleObjectForRoleIgnoreShowing_(xacc, role); 120*cdf0e10cSrcweir } else { 121*cdf0e10cSrcweir getAccessibleObjectForRole_(xacc, role); 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir return SearchedContext; 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir public static void getAccessibleObjectForRoleIgnoreShowing_(XAccessible xacc, 128*cdf0e10cSrcweir short role) { 129*cdf0e10cSrcweir XAccessibleContext ac = xacc.getAccessibleContext(); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir if (ac.getAccessibleRole() == role) { 132*cdf0e10cSrcweir SearchedContext = ac; 133*cdf0e10cSrcweir SearchedAccessible = xacc; 134*cdf0e10cSrcweir } else { 135*cdf0e10cSrcweir int k = ac.getAccessibleChildCount(); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir if (ac.getAccessibleChildCount() > 100) { 138*cdf0e10cSrcweir k = 50; 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir for (int i = 0; i < k; i++) { 142*cdf0e10cSrcweir try { 143*cdf0e10cSrcweir getAccessibleObjectForRoleIgnoreShowing_( 144*cdf0e10cSrcweir ac.getAccessibleChild(i), role); 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir if (SearchedContext != null) { 147*cdf0e10cSrcweir return; 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 150*cdf0e10cSrcweir System.out.println("Couldn't get Child"); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir public static void getAccessibleObjectForRole_(XAccessible xacc, 157*cdf0e10cSrcweir short role) { 158*cdf0e10cSrcweir XAccessibleContext ac = xacc.getAccessibleContext(); 159*cdf0e10cSrcweir boolean isShowing = ac.getAccessibleStateSet() 160*cdf0e10cSrcweir .contains(com.sun.star.accessibility.AccessibleStateType.SHOWING); 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir if ((ac.getAccessibleRole() == role) && isShowing) { 163*cdf0e10cSrcweir SearchedContext = ac; 164*cdf0e10cSrcweir SearchedAccessible = xacc; 165*cdf0e10cSrcweir } else { 166*cdf0e10cSrcweir int k = ac.getAccessibleChildCount(); 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir if (ac.getAccessibleChildCount() > 100) { 169*cdf0e10cSrcweir k = 50; 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir for (int i = 0; i < k; i++) { 173*cdf0e10cSrcweir try { 174*cdf0e10cSrcweir getAccessibleObjectForRole_(ac.getAccessibleChild(i), role); 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir if (SearchedContext != null) { 177*cdf0e10cSrcweir return; 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 180*cdf0e10cSrcweir System.out.println("Couldn't get Child"); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir public static XAccessibleContext getAccessibleObjectForRole(XAccessible xacc, 187*cdf0e10cSrcweir short role, 188*cdf0e10cSrcweir String name) { 189*cdf0e10cSrcweir return getAccessibleObjectForRole(xacc, role, name, ""); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir public static XAccessibleContext getAccessibleObjectForRole(XAccessible xacc, 193*cdf0e10cSrcweir short role, 194*cdf0e10cSrcweir String name, 195*cdf0e10cSrcweir boolean ignoreShowing) { 196*cdf0e10cSrcweir if (ignoreShowing) { 197*cdf0e10cSrcweir return getAccessibleObjectForRoleIgnoreShowing(xacc, role, name, 198*cdf0e10cSrcweir ""); 199*cdf0e10cSrcweir } else { 200*cdf0e10cSrcweir return getAccessibleObjectForRole(xacc, role, name, ""); 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir public static XAccessibleContext getAccessibleObjectForRoleIgnoreShowing(XAccessible xacc, 205*cdf0e10cSrcweir short role, 206*cdf0e10cSrcweir String name, 207*cdf0e10cSrcweir String implName) { 208*cdf0e10cSrcweir XAccessibleContext ac = xacc.getAccessibleContext(); 209*cdf0e10cSrcweir if ((ac.getAccessibleRole() == role) && 210*cdf0e10cSrcweir (ac.getAccessibleName().indexOf(name) > -1) && 211*cdf0e10cSrcweir (utils.getImplName(ac).indexOf(implName) > -1)) { 212*cdf0e10cSrcweir SearchedAccessible = xacc; 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir //System.out.println("FOUND the desired component -- "+ ac.getAccessibleName() +isShowing); 215*cdf0e10cSrcweir return ac; 216*cdf0e10cSrcweir } else { 217*cdf0e10cSrcweir int k = ac.getAccessibleChildCount(); 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir if (ac.getAccessibleChildCount() > 100) { 220*cdf0e10cSrcweir k = 50; 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir for (int i = 0; i < k; i++) { 224*cdf0e10cSrcweir try { 225*cdf0e10cSrcweir XAccessibleContext ac1 = getAccessibleObjectForRoleIgnoreShowing( 226*cdf0e10cSrcweir ac.getAccessibleChild(i), 227*cdf0e10cSrcweir role, name, implName); 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir if (ac1 != null) { 230*cdf0e10cSrcweir return ac1; 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 233*cdf0e10cSrcweir System.out.println("Couldn't get Child"); 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir return null; 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir public static XAccessibleContext getAccessibleObjectForRole(XAccessible xacc, 242*cdf0e10cSrcweir short role, 243*cdf0e10cSrcweir String name, 244*cdf0e10cSrcweir String implName) { 245*cdf0e10cSrcweir XAccessibleContext ac = xacc.getAccessibleContext(); 246*cdf0e10cSrcweir boolean isShowing = ac.getAccessibleStateSet() 247*cdf0e10cSrcweir .contains(com.sun.star.accessibility.AccessibleStateType.SHOWING); 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir // hotfix for i91828: 250*cdf0e10cSrcweir // if role to serach is 0 then ignore the role. 251*cdf0e10cSrcweir if ( (role == 0 || ac.getAccessibleRole() == role) && 252*cdf0e10cSrcweir (ac.getAccessibleName().indexOf(name) > -1) && 253*cdf0e10cSrcweir (utils.getImplName(ac).indexOf(implName) > -1) && 254*cdf0e10cSrcweir isShowing) { 255*cdf0e10cSrcweir SearchedAccessible = xacc; 256*cdf0e10cSrcweir //System.out.println("FOUND the desired component -- "+ ac.getAccessibleName() +isShowing); 257*cdf0e10cSrcweir return ac; 258*cdf0e10cSrcweir } else { 259*cdf0e10cSrcweir int k = ac.getAccessibleChildCount(); 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir if (ac.getAccessibleChildCount() > 100) { 262*cdf0e10cSrcweir k = 50; 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir for (int i = 0; i < k; i++) { 266*cdf0e10cSrcweir try { 267*cdf0e10cSrcweir XAccessibleContext ac1 = getAccessibleObjectForRole( 268*cdf0e10cSrcweir ac.getAccessibleChild(i), 269*cdf0e10cSrcweir role, name, implName); 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir if (ac1 != null) { 272*cdf0e10cSrcweir return ac1; 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 275*cdf0e10cSrcweir System.out.println("Couldn't get Child"); 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir return null; 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir /** 284*cdf0e10cSrcweir * This methods retunrs the <CODE>XAccessibleContext</CODE> of a named Sheet-Cell like "G5".<p> 285*cdf0e10cSrcweir * @param xSheetAcc The <CODE>XAccessibleContext</CODE> of a Sheet 286*cdf0e10cSrcweir * @param cellName The name of a cell like "A5" 287*cdf0e10cSrcweir * @return the <CODE>XAccessiblecontext</CODE> of the named cell 288*cdf0e10cSrcweir */ 289*cdf0e10cSrcweir public static XAccessibleContext getSheetCell(XAccessibleContext xSheetAcc, String cellName){ 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir int cellIndex = 0; 292*cdf0e10cSrcweir int column =0; 293*cdf0e10cSrcweir int charMem = 0; 294*cdf0e10cSrcweir for (int n=0; n<cellName.length(); n++){ 295*cdf0e10cSrcweir String cha = cellName.substring(n,n+1); 296*cdf0e10cSrcweir System.out.println("char: " + cha + " "); 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir byte[] bytes = cha.getBytes(); 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir if ((bytes[0] >= 'A') && (bytes[0] <= 'Z')){ 301*cdf0e10cSrcweir charMem = bytes[0]-64; 302*cdf0e10cSrcweir column++; 303*cdf0e10cSrcweir if ( column == 2 ){ 304*cdf0e10cSrcweir cellIndex += charMem * 26; 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir cellIndex= cellIndex+ (bytes[0]-65); 307*cdf0e10cSrcweir } else { 308*cdf0e10cSrcweir String sNumb = cellName.substring(n, cellName.length()); 309*cdf0e10cSrcweir int iNumb = new Integer(0).valueOf(sNumb).intValue(); 310*cdf0e10cSrcweir cellIndex += (iNumb-1) * 256; 311*cdf0e10cSrcweir System.out.println("numb:" + (iNumb-1) * 256); 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir //System.out.println("cellName: " + cellName + " cellIndex: " + cellIndex); 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir try { 319*cdf0e10cSrcweir XAccessibleContext ac = xSheetAcc.getAccessibleChild(cellIndex).getAccessibleContext(); 320*cdf0e10cSrcweir System.out.println(ac.getAccessibleRole() + "," + 321*cdf0e10cSrcweir ac.getAccessibleName() + "(" + 322*cdf0e10cSrcweir ac.getAccessibleDescription() + "):" + 323*cdf0e10cSrcweir utils.getImplName(ac)); 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir return ac; 326*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException ex) { 327*cdf0e10cSrcweir System.out.println("ERROR: could not get child at index " + cellIndex +"': " + ex.toString()); 328*cdf0e10cSrcweir return null; 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir public static void printAccessibleTree(PrintWriter log, XAccessible xacc, boolean debugIsActive) { 333*cdf0e10cSrcweir debug = debugIsActive; 334*cdf0e10cSrcweir if (debug) printAccessibleTree(log, xacc, ""); 335*cdf0e10cSrcweir } 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir public static void printAccessibleTree(PrintWriter log, XAccessible xacc) { 338*cdf0e10cSrcweir printAccessibleTree(log, xacc, ""); 339*cdf0e10cSrcweir } 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir protected static void printAccessibleTree(PrintWriter log, 342*cdf0e10cSrcweir XAccessible xacc, String indent) { 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir XAccessibleContext ac = xacc.getAccessibleContext(); 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir logging(log,indent + ac.getAccessibleRole() + "," + 347*cdf0e10cSrcweir ac.getAccessibleName() + "(" + 348*cdf0e10cSrcweir ac.getAccessibleDescription() + "):" + 349*cdf0e10cSrcweir utils.getImplName(ac)); 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir XAccessibleComponent aComp = (XAccessibleComponent) UnoRuntime.queryInterface( 352*cdf0e10cSrcweir XAccessibleComponent.class, xacc); 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir if (aComp != null) { 355*cdf0e10cSrcweir String bounds = "(" + aComp.getBounds().X + "," + 356*cdf0e10cSrcweir aComp.getBounds().Y + ")" + " (" + 357*cdf0e10cSrcweir aComp.getBounds().Width + "," + 358*cdf0e10cSrcweir aComp.getBounds().Height + ")"; 359*cdf0e10cSrcweir bounds = "The boundary Rectangle is " + bounds; 360*cdf0e10cSrcweir logging(log,indent + indent + bounds); 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir boolean isShowing = ac.getAccessibleStateSet() 364*cdf0e10cSrcweir .contains(com.sun.star.accessibility.AccessibleStateType.SHOWING); 365*cdf0e10cSrcweir logging(log,indent + indent + "StateType contains SHOWING: " + 366*cdf0e10cSrcweir isShowing); 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir int k = ac.getAccessibleChildCount(); 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir if (ac.getAccessibleChildCount() > 100) { 371*cdf0e10cSrcweir k = 50; 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir for (int i = 0; i < k; i++) { 375*cdf0e10cSrcweir try { 376*cdf0e10cSrcweir printAccessibleTree(log, ac.getAccessibleChild(i), 377*cdf0e10cSrcweir indent + " "); 378*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 379*cdf0e10cSrcweir System.out.println("Couldn't get Child"); 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir if (ac.getAccessibleChildCount() > 100) { 384*cdf0e10cSrcweir k = ac.getAccessibleChildCount(); 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir int st = ac.getAccessibleChildCount() - 50; 387*cdf0e10cSrcweir logging(log,indent + " " + " ...... [skipped] ......"); 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir for (int i = st; i < k; i++) { 390*cdf0e10cSrcweir try { 391*cdf0e10cSrcweir printAccessibleTree(log, ac.getAccessibleChild(i), 392*cdf0e10cSrcweir indent + " "); 393*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 394*cdf0e10cSrcweir System.out.println("Couldn't get Child"); 395*cdf0e10cSrcweir } 396*cdf0e10cSrcweir } 397*cdf0e10cSrcweir } 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir 400*cdf0e10cSrcweir public static String accessibleToString(Object AC) { 401*cdf0e10cSrcweir XAccessibleContext xAC = (XAccessibleContext) UnoRuntime.queryInterface( 402*cdf0e10cSrcweir XAccessibleContext.class, AC); 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir if (xAC != null) { 405*cdf0e10cSrcweir return "" + xAC.getAccessibleRole() + "," + 406*cdf0e10cSrcweir xAC.getAccessibleName() + "(" + 407*cdf0e10cSrcweir xAC.getAccessibleDescription() + "):"; 408*cdf0e10cSrcweir } 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir XAccessible xA = (XAccessible) UnoRuntime.queryInterface( 411*cdf0e10cSrcweir XAccessible.class, AC); 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir if (xA == null) { 414*cdf0e10cSrcweir return "(Not supported)"; 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir xAC = xA.getAccessibleContext(); 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir return "" + xAC.getAccessibleRole() + "," + xAC.getAccessibleName() + 420*cdf0e10cSrcweir "(" + xAC.getAccessibleDescription() + ")"; 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir public static boolean equals(XAccessible c1, XAccessible c2) { 424*cdf0e10cSrcweir if ((c1 == null) || (c2 == null)) { 425*cdf0e10cSrcweir return c1 == c2; 426*cdf0e10cSrcweir } 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir return AccessibilityTools.equals(c1.getAccessibleContext(), 429*cdf0e10cSrcweir c2.getAccessibleContext()); 430*cdf0e10cSrcweir } 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir public static boolean equals(XAccessibleContext c1, XAccessibleContext c2) { 433*cdf0e10cSrcweir if ((c1 == null) || (c2 == null)) { 434*cdf0e10cSrcweir return c1 == c2; 435*cdf0e10cSrcweir } 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir if (c1.getAccessibleRole() != c2.getAccessibleRole()) { 438*cdf0e10cSrcweir return false; 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir if (!c1.getAccessibleName().equals(c2.getAccessibleName())) { 442*cdf0e10cSrcweir return false; 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir 445*cdf0e10cSrcweir if (!c1.getAccessibleDescription() 446*cdf0e10cSrcweir .equals(c2.getAccessibleDescription())) { 447*cdf0e10cSrcweir return false; 448*cdf0e10cSrcweir } 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir if (c1.getAccessibleChildCount() != c2.getAccessibleChildCount()) { 451*cdf0e10cSrcweir return false; 452*cdf0e10cSrcweir } 453*cdf0e10cSrcweir 454*cdf0e10cSrcweir return AccessibilityTools.equals(c1.getAccessibleParent(), 455*cdf0e10cSrcweir c2.getAccessibleParent()); 456*cdf0e10cSrcweir } 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir private static void logging(PrintWriter log, String content){ 459*cdf0e10cSrcweir if (debug) log.println(content); 460*cdf0e10cSrcweir } 461*cdf0e10cSrcweir }