1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir package ifc.accessibility; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import java.util.Vector; 26cdf0e10cSrcweir 27cdf0e10cSrcweir import lib.MultiMethodTest; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible; 30cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleComponent; 31cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleContext; 32cdf0e10cSrcweir import com.sun.star.awt.Point; 33cdf0e10cSrcweir import com.sun.star.awt.Rectangle; 34cdf0e10cSrcweir import com.sun.star.awt.Size; 35cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 36cdf0e10cSrcweir 37cdf0e10cSrcweir 38cdf0e10cSrcweir /** 39cdf0e10cSrcweir * Testing <code>com.sun.star.accessibility.XAccessibleComponent</code> 40cdf0e10cSrcweir * interface methods : 41cdf0e10cSrcweir * <ul> 42cdf0e10cSrcweir * <li><code> containsPoint()</code></li> 43cdf0e10cSrcweir * <li><code> getAccessibleAtPoint()</code></li> 44cdf0e10cSrcweir * <li><code> getBounds()</code></li> 45cdf0e10cSrcweir * <li><code> getLocation()</code></li> 46cdf0e10cSrcweir * <li><code> getLocationOnScreen()</code></li> 47cdf0e10cSrcweir * <li><code> getSize()</code></li> 48cdf0e10cSrcweir * <li><code> grabFocus()</code></li> 49cdf0e10cSrcweir * <li><code> getAccessibleKeyBinding()</code></li> 50cdf0e10cSrcweir * </ul> <p> 51cdf0e10cSrcweir * 52cdf0e10cSrcweir * @see com.sun.star.accessibility.XAccessibleComponent 53cdf0e10cSrcweir */ 54cdf0e10cSrcweir public class _XAccessibleComponent extends MultiMethodTest { 55cdf0e10cSrcweir 56cdf0e10cSrcweir public XAccessibleComponent oObj = null; 57cdf0e10cSrcweir private Rectangle bounds = null; 58cdf0e10cSrcweir private Vector KnownBounds = new Vector(); 59cdf0e10cSrcweir 60cdf0e10cSrcweir 61cdf0e10cSrcweir /** 62cdf0e10cSrcweir * First checks 4 inner bounds (upper, lower, left and right) 63cdf0e10cSrcweir * of component bounding box to contain 64cdf0e10cSrcweir * at least one point of the component. Second 4 outer bounds 65cdf0e10cSrcweir * are checked to not contain any component points.<p> 66cdf0e10cSrcweir * 67cdf0e10cSrcweir * Has <b> OK </b> status if inner bounds contain component points 68cdf0e10cSrcweir * and outer bounds don't contain any component points. <p> 69cdf0e10cSrcweir * 70cdf0e10cSrcweir * The following method tests are to be completed successfully before : 71cdf0e10cSrcweir * <ul> 72cdf0e10cSrcweir * <li> <code> getBounds() </code> : to have size of a component.</li> 73cdf0e10cSrcweir * </ul> 74cdf0e10cSrcweir */ 75cdf0e10cSrcweir public void _containsPoint() { 76cdf0e10cSrcweir requiredMethod("getBounds()"); 77cdf0e10cSrcweir 78cdf0e10cSrcweir boolean result = true; 79cdf0e10cSrcweir 80cdf0e10cSrcweir int curX = 0; 81cdf0e10cSrcweir 82cdf0e10cSrcweir //while (!oObj.containsPoint(new Point(curX, bounds.Y)) && curX < bounds.Width+bounds.X) { 83cdf0e10cSrcweir while (!oObj.containsPoint(new Point(curX, 0)) && 84cdf0e10cSrcweir (curX < bounds.Width)) { 85cdf0e10cSrcweir curX++; 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir ; 89cdf0e10cSrcweir 90cdf0e10cSrcweir //if ((bounds.X <= curX) && (curX < bounds.Width+bounds.X)) { 91cdf0e10cSrcweir if (curX < bounds.Width) { 92cdf0e10cSrcweir log.println("Upper bound of box containsPoint point (" + curX + 93cdf0e10cSrcweir ",0) - OK"); 94cdf0e10cSrcweir } else { 95cdf0e10cSrcweir log.println( 96cdf0e10cSrcweir "Upper bound of box containsPoint no component points - FAILED"); 97cdf0e10cSrcweir result = false; 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir curX = 0; 101cdf0e10cSrcweir 102cdf0e10cSrcweir //while (!oObj.containsPoint(new Point(curX, bounds.Y+bounds.Height - 1)) 103cdf0e10cSrcweir while (!oObj.containsPoint(new Point(curX, bounds.Height - 1)) && 104cdf0e10cSrcweir (curX < bounds.Width)) { 105cdf0e10cSrcweir log.println("containsPoint returns false for (" + curX + "," + 106cdf0e10cSrcweir bounds.Height + ")"); 107cdf0e10cSrcweir curX++; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir 110cdf0e10cSrcweir ; 111cdf0e10cSrcweir 112cdf0e10cSrcweir //if ((bounds.X <= curX) && (curX < bounds.Width+bounds.X)) { 113cdf0e10cSrcweir if (curX < bounds.Width) { 114cdf0e10cSrcweir log.println("Lower bound of box containsPoint point (" + curX + 115cdf0e10cSrcweir "," + (bounds.Height - 1) + ") - OK"); 116cdf0e10cSrcweir } else { 117cdf0e10cSrcweir log.println( 118cdf0e10cSrcweir "Lower bound of box containsPoint no component points - FAILED"); 119cdf0e10cSrcweir result = false; 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir int curY = 0; 123cdf0e10cSrcweir 124cdf0e10cSrcweir //while (!oObj.containsPoint(new Point(bounds.X, curY)) && curY < bounds.Height+bounds.Y) { 125cdf0e10cSrcweir while (!oObj.containsPoint(new Point(0, curY)) && 126cdf0e10cSrcweir (curY < bounds.Height)) { 127cdf0e10cSrcweir curY++; 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir ; 131cdf0e10cSrcweir 132cdf0e10cSrcweir //if ((bounds.Y <= curY) && (curY < bounds.Height+bounds.Y)) { 133cdf0e10cSrcweir if (curY < bounds.Height) { 134cdf0e10cSrcweir log.println("Left bound of box containsPoint point (0," + curY + 135cdf0e10cSrcweir ") - OK"); 136cdf0e10cSrcweir } else { 137cdf0e10cSrcweir log.println( 138cdf0e10cSrcweir "Left bound of box containsPoint no component points - FAILED"); 139cdf0e10cSrcweir result = false; 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir curY = 0; 143cdf0e10cSrcweir 144cdf0e10cSrcweir //while (!oObj.containsPoint(new Point(bounds.X+bounds.Width - 1, curY)) 145cdf0e10cSrcweir // && curY < bounds.Height+bounds.Y) { 146cdf0e10cSrcweir while (!oObj.containsPoint(new Point(bounds.Width - 1, curY)) && 147cdf0e10cSrcweir (curY < bounds.Height)) { 148cdf0e10cSrcweir curY++; 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151cdf0e10cSrcweir ; 152cdf0e10cSrcweir 153cdf0e10cSrcweir //if ((bounds.Y <= curY) && (curY < bounds.Height + bounds.Y)) { 154cdf0e10cSrcweir if (curY < bounds.Height) { 155cdf0e10cSrcweir log.println("Right bound of box containsPoint point (" + 156cdf0e10cSrcweir (bounds.Width - 1) + "," + curY + ") - OK"); 157cdf0e10cSrcweir } else { 158cdf0e10cSrcweir log.println( 159cdf0e10cSrcweir "Right bound of box containsPoint no component points - FAILED"); 160cdf0e10cSrcweir result = false; 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir boolean locRes = true; 164cdf0e10cSrcweir 165cdf0e10cSrcweir for (int x = -1; x <= bounds.Width; x++) { 166cdf0e10cSrcweir if (oObj.containsPoint(new Point(x, -1))) { 167cdf0e10cSrcweir log.println( 168cdf0e10cSrcweir "Outer upper and lower bounds CONTAIN some component point" 169cdf0e10cSrcweir + " (" + x + ", -1) - FAILED"); 170cdf0e10cSrcweir locRes = false; 171cdf0e10cSrcweir break; 172cdf0e10cSrcweir } 173cdf0e10cSrcweir if (oObj.containsPoint(new Point(x, bounds.Height + bounds.Y))) { 174cdf0e10cSrcweir log.println( 175cdf0e10cSrcweir "Outer upper and lower bounds CONTAIN some component point" 176cdf0e10cSrcweir + " (" + x + ", " + bounds.Height + bounds.Y 177cdf0e10cSrcweir + ") - FAILED"); 178cdf0e10cSrcweir locRes = false; 179cdf0e10cSrcweir break; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir if (locRes) { 184cdf0e10cSrcweir log.println("Outer upper and lower bounds contain no component " + 185cdf0e10cSrcweir "points - OK"); 186cdf0e10cSrcweir } else { 187cdf0e10cSrcweir result = false; 188cdf0e10cSrcweir } 189cdf0e10cSrcweir 190cdf0e10cSrcweir locRes = true; 191cdf0e10cSrcweir 192cdf0e10cSrcweir for (int y = -1; y <= bounds.Height; y++) { 193cdf0e10cSrcweir if (oObj.containsPoint(new Point(-1, y))) { 194cdf0e10cSrcweir log.println( 195cdf0e10cSrcweir "Outer left and right bounds CONTAIN some component point" 196cdf0e10cSrcweir + " (-1, " + y + ") - FAILED"); 197cdf0e10cSrcweir locRes = false; 198cdf0e10cSrcweir break; 199cdf0e10cSrcweir } 200cdf0e10cSrcweir if (oObj.containsPoint(new Point(bounds.X + bounds.Width, y))) { 201cdf0e10cSrcweir log.println( 202cdf0e10cSrcweir "Outer left and right bounds CONTAIN some component point" 203cdf0e10cSrcweir + " (" + bounds.X + bounds.Width + ", " + y + ") - FAILED"); 204cdf0e10cSrcweir locRes = false; 205cdf0e10cSrcweir break; 206cdf0e10cSrcweir } 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir if (locRes) { 210cdf0e10cSrcweir log.println("Outer left and right bounds contain no component " + 211cdf0e10cSrcweir "points - OK"); 212cdf0e10cSrcweir } else { 213cdf0e10cSrcweir result = false; 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir tRes.tested("containsPoint()", result); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir /** 220cdf0e10cSrcweir * Iterates through all children which implement 221cdf0e10cSrcweir * <code>XAccessibleComponent</code> (if they exist) determines their 222cdf0e10cSrcweir * boundaries and tries to get each child by <code>getAccessibleAtPoint</code> 223cdf0e10cSrcweir * passing point which belongs to the child. 224cdf0e10cSrcweir * Also the point is checked which doesn't belong to child boundary 225cdf0e10cSrcweir * box. <p> 226cdf0e10cSrcweir * 227cdf0e10cSrcweir * Has <b> OK </b> status if in the first cases the right children 228cdf0e10cSrcweir * are returned, and in the second <code>null</code> or 229cdf0e10cSrcweir * another child is returned. 230cdf0e10cSrcweir */ 231cdf0e10cSrcweir public void _getAccessibleAtPoint() { 232cdf0e10cSrcweir boolean result = true; 233cdf0e10cSrcweir XAccessibleComponent[] children = getChildrenComponents(); 234cdf0e10cSrcweir 235cdf0e10cSrcweir if (children.length > 0) { 236cdf0e10cSrcweir for (int i = 0; i < children.length; i++) { 237cdf0e10cSrcweir Rectangle chBnd = children[i].getBounds(); 238cdf0e10cSrcweir 239cdf0e10cSrcweir if (chBnd.X == -1) { 240cdf0e10cSrcweir continue; 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir log.println("Checking child with bounds " + "(" + chBnd.X + 244cdf0e10cSrcweir "," + chBnd.Y + "),(" + chBnd.Width + "," + 245cdf0e10cSrcweir chBnd.Height + "): " + 246cdf0e10cSrcweir util.AccessibilityTools.accessibleToString( 247cdf0e10cSrcweir children[i])); 248cdf0e10cSrcweir 249cdf0e10cSrcweir XAccessibleContext xAc = (XAccessibleContext) UnoRuntime.queryInterface( 250cdf0e10cSrcweir XAccessibleContext.class, 251cdf0e10cSrcweir children[i]); 252cdf0e10cSrcweir 253cdf0e10cSrcweir boolean MightBeCovered = false; 254cdf0e10cSrcweir boolean isShowing = xAc.getAccessibleStateSet() 255cdf0e10cSrcweir .contains(com.sun.star.accessibility.AccessibleStateType.SHOWING); 256cdf0e10cSrcweir log.println("\tStateType containsPoint SHOWING: " + 257cdf0e10cSrcweir isShowing); 258cdf0e10cSrcweir 259cdf0e10cSrcweir if (!isShowing) { 260cdf0e10cSrcweir log.println("Child is invisible - OK"); 261cdf0e10cSrcweir 262cdf0e10cSrcweir continue; 263cdf0e10cSrcweir } 264cdf0e10cSrcweir 265cdf0e10cSrcweir log.println("finding the point which lies on the component"); 266cdf0e10cSrcweir 267cdf0e10cSrcweir int curX = chBnd.Width / 2; 268cdf0e10cSrcweir int curY = chBnd.Height / 2; 269cdf0e10cSrcweir 270cdf0e10cSrcweir while (!children[i].containsPoint(new Point(curX, curY)) && 271cdf0e10cSrcweir (curX > 0) && (curY > 0)) { 272cdf0e10cSrcweir curX--; 273cdf0e10cSrcweir curY--; 274cdf0e10cSrcweir } 275cdf0e10cSrcweir 276cdf0e10cSrcweir ; 277cdf0e10cSrcweir 278cdf0e10cSrcweir if ((curX == chBnd.Width) && isShowing) { 279cdf0e10cSrcweir log.println("Couldn't find a point with containsPoint"); 280cdf0e10cSrcweir 281cdf0e10cSrcweir continue; 282cdf0e10cSrcweir } 283cdf0e10cSrcweir 284cdf0e10cSrcweir // trying the point laying on child 285cdf0e10cSrcweir XAccessible xAcc = oObj.getAccessibleAtPoint( 286cdf0e10cSrcweir new Point(chBnd.X + curX, 287cdf0e10cSrcweir chBnd.Y + curY)); 288cdf0e10cSrcweir 289cdf0e10cSrcweir 290cdf0e10cSrcweir Point p = new Point(chBnd.X + curX,chBnd.X + curX); 291cdf0e10cSrcweir 292cdf0e10cSrcweir if (isCovered(p) && isShowing) { 293cdf0e10cSrcweir log.println( 294cdf0e10cSrcweir "Child might be covered by another and can't be reached"); 295cdf0e10cSrcweir MightBeCovered = true; 296cdf0e10cSrcweir } 297cdf0e10cSrcweir 298cdf0e10cSrcweir KnownBounds.add(chBnd); 299cdf0e10cSrcweir 300cdf0e10cSrcweir if (xAcc == null) { 301cdf0e10cSrcweir log.println("The child not found at point (" + 302cdf0e10cSrcweir (chBnd.X + curX) + "," + (chBnd.Y + curY) + 303cdf0e10cSrcweir ") - FAILED"); 304cdf0e10cSrcweir 305cdf0e10cSrcweir if (isShowing) { 306cdf0e10cSrcweir result = false; 307cdf0e10cSrcweir } else { 308cdf0e10cSrcweir result &= true; 309cdf0e10cSrcweir } 310cdf0e10cSrcweir } else { 311cdf0e10cSrcweir XAccessible xAccCh = (XAccessible) UnoRuntime.queryInterface( 312cdf0e10cSrcweir XAccessible.class, 313cdf0e10cSrcweir children[i]); 314cdf0e10cSrcweir XAccessibleContext xAccC = (XAccessibleContext) UnoRuntime.queryInterface( 315cdf0e10cSrcweir XAccessibleContext.class, 316cdf0e10cSrcweir children[i]); 317cdf0e10cSrcweir log.println("Child found at point (" + (chBnd.X + curX) + 318cdf0e10cSrcweir "," + (chBnd.Y + curY) + ") - OK"); 319cdf0e10cSrcweir 320cdf0e10cSrcweir boolean res = false; 321cdf0e10cSrcweir int expIndex; 322cdf0e10cSrcweir String expName; 323cdf0e10cSrcweir String expDesc; 324cdf0e10cSrcweir 325cdf0e10cSrcweir if (xAccCh != null) { 326cdf0e10cSrcweir res = util.AccessibilityTools.equals(xAccCh, xAcc); 327cdf0e10cSrcweir expIndex = xAccCh.getAccessibleContext() 328cdf0e10cSrcweir .getAccessibleIndexInParent(); 329cdf0e10cSrcweir expName = xAccCh.getAccessibleContext() 330cdf0e10cSrcweir .getAccessibleName(); 331cdf0e10cSrcweir expDesc = xAccCh.getAccessibleContext() 332cdf0e10cSrcweir .getAccessibleDescription(); 333cdf0e10cSrcweir } else { 334cdf0e10cSrcweir res = xAccC.getAccessibleName() 335cdf0e10cSrcweir .equals(xAcc.getAccessibleContext() 336cdf0e10cSrcweir .getAccessibleName()); 337cdf0e10cSrcweir expIndex = xAccC.getAccessibleIndexInParent(); 338cdf0e10cSrcweir expName = xAccC.getAccessibleName(); 339cdf0e10cSrcweir expDesc = xAccC.getAccessibleDescription(); 340cdf0e10cSrcweir } 341cdf0e10cSrcweir 342cdf0e10cSrcweir if (!res) { 343cdf0e10cSrcweir int gotIndex = xAcc.getAccessibleContext() 344cdf0e10cSrcweir .getAccessibleIndexInParent(); 345cdf0e10cSrcweir 346cdf0e10cSrcweir if (expIndex < gotIndex) { 347cdf0e10cSrcweir log.println("The children found is not the same"); 348cdf0e10cSrcweir log.println("The expected child " + expName); 349cdf0e10cSrcweir log.print("is hidden behind the found Child "); 350cdf0e10cSrcweir log.println(xAcc.getAccessibleContext() 351cdf0e10cSrcweir .getAccessibleName() + " - OK"); 352cdf0e10cSrcweir } else { 353cdf0e10cSrcweir log.println( 354cdf0e10cSrcweir "The children found is not the same"); 355cdf0e10cSrcweir log.println("Expected: " + expName); 356cdf0e10cSrcweir log.println("Description: " + expDesc); 357cdf0e10cSrcweir log.println("Found: " + 358cdf0e10cSrcweir xAcc.getAccessibleContext() 359cdf0e10cSrcweir .getAccessibleName()); 360cdf0e10cSrcweir log.println("Description: " + 361cdf0e10cSrcweir xAcc.getAccessibleContext() 362cdf0e10cSrcweir .getAccessibleDescription()); 363cdf0e10cSrcweir if (MightBeCovered) { 364cdf0e10cSrcweir log.println("... Child is covered by another - OK"); 365cdf0e10cSrcweir } else { 366cdf0e10cSrcweir log.println("... FAILED"); 367cdf0e10cSrcweir result = false; 368cdf0e10cSrcweir } 369cdf0e10cSrcweir 370cdf0e10cSrcweir } 371cdf0e10cSrcweir } 372cdf0e10cSrcweir } 373cdf0e10cSrcweir 374cdf0e10cSrcweir 375cdf0e10cSrcweir // trying the point NOT laying on child 376cdf0e10cSrcweir xAcc = oObj.getAccessibleAtPoint( 377cdf0e10cSrcweir new Point(chBnd.X - 1, chBnd.Y - 1)); 378cdf0e10cSrcweir 379cdf0e10cSrcweir if (xAcc == null) { 380cdf0e10cSrcweir log.println("No children found at point (" + 381cdf0e10cSrcweir (chBnd.X - 1) + "," + (chBnd.Y - 1) + 382cdf0e10cSrcweir ") - OK"); 383cdf0e10cSrcweir result &= true; 384cdf0e10cSrcweir } else { 385cdf0e10cSrcweir XAccessible xAccCh = (XAccessible) UnoRuntime.queryInterface( 386cdf0e10cSrcweir XAccessible.class, 387cdf0e10cSrcweir children[i]); 388cdf0e10cSrcweir boolean res = util.AccessibilityTools.equals(xAccCh, xAcc); 389cdf0e10cSrcweir 390cdf0e10cSrcweir if (res) { 391cdf0e10cSrcweir log.println("The same child found outside " + 392cdf0e10cSrcweir "its bounds at (" + (chBnd.X - 1) + "," + 393cdf0e10cSrcweir (chBnd.Y - 1) + ") - FAILED"); 394cdf0e10cSrcweir result = false; 395cdf0e10cSrcweir } 396cdf0e10cSrcweir } 397cdf0e10cSrcweir } 398cdf0e10cSrcweir } else { 399cdf0e10cSrcweir log.println("There are no children supporting " + 400cdf0e10cSrcweir "XAccessibleComponent"); 401cdf0e10cSrcweir } 402cdf0e10cSrcweir 403cdf0e10cSrcweir tRes.tested("getAccessibleAtPoint()", result); 404cdf0e10cSrcweir } 405cdf0e10cSrcweir 406cdf0e10cSrcweir /** 407cdf0e10cSrcweir * Retrieves the component bounds and stores it. <p> 408cdf0e10cSrcweir * 409cdf0e10cSrcweir * Has <b> OK </b> status if boundary position (x,y) is not negative 410cdf0e10cSrcweir * and size (Width, Height) is greater than 0. 411cdf0e10cSrcweir */ 412cdf0e10cSrcweir public void _getBounds() { 413cdf0e10cSrcweir boolean result = true; 414cdf0e10cSrcweir 415cdf0e10cSrcweir bounds = oObj.getBounds(); 416cdf0e10cSrcweir result &= ((bounds != null) && (bounds.X >= 0) && (bounds.Y >= 0) && (bounds.Width > 0) && (bounds.Height > 0)); 417cdf0e10cSrcweir 418cdf0e10cSrcweir log.println("Bounds = " + 419cdf0e10cSrcweir ((bounds != null) 420cdf0e10cSrcweir ? ("(" + bounds.X + "," + bounds.Y + "),(" + 421cdf0e10cSrcweir bounds.Width + "," + bounds.Height + ")") : "null")); 422cdf0e10cSrcweir 423cdf0e10cSrcweir tRes.tested("getBounds()", result); 424cdf0e10cSrcweir } 425cdf0e10cSrcweir 426cdf0e10cSrcweir /** 427cdf0e10cSrcweir * Gets the location. <p> 428cdf0e10cSrcweir * 429cdf0e10cSrcweir * Has <b> OK </b> status if the location is the same as location 430cdf0e10cSrcweir * of boundary obtained by <code>getBounds()</code> method. 431cdf0e10cSrcweir * 432cdf0e10cSrcweir * The following method tests are to be completed successfully before : 433cdf0e10cSrcweir * <ul> 434cdf0e10cSrcweir * <li> <code> getBounds() </code> : to have bounds </li> 435cdf0e10cSrcweir * </ul> 436cdf0e10cSrcweir */ 437cdf0e10cSrcweir public void _getLocation() { 438cdf0e10cSrcweir requiredMethod("getBounds()"); 439cdf0e10cSrcweir 440cdf0e10cSrcweir boolean result = true; 441cdf0e10cSrcweir Point loc = oObj.getLocation(); 442cdf0e10cSrcweir 443cdf0e10cSrcweir result &= ((loc.X == bounds.X) && (loc.Y == bounds.Y)); 444cdf0e10cSrcweir 445cdf0e10cSrcweir tRes.tested("getLocation()", result); 446cdf0e10cSrcweir } 447cdf0e10cSrcweir 448cdf0e10cSrcweir /** 449cdf0e10cSrcweir * Get the screen location of the component and its parent 450cdf0e10cSrcweir * (if it exists and supports <code>XAccessibleComponent</code>). <p> 451cdf0e10cSrcweir * 452cdf0e10cSrcweir * Has <b> OK </b> status if component screen location equals 453cdf0e10cSrcweir * to screen location of its parent plus location of the component 454cdf0e10cSrcweir * relative to the parent. <p> 455cdf0e10cSrcweir * 456cdf0e10cSrcweir * The following method tests are to be completed successfully before : 457cdf0e10cSrcweir * <ul> 458cdf0e10cSrcweir * <li> <code> getBounds() </code> : to have location of the component 459cdf0e10cSrcweir * relative to its parent</li> 460cdf0e10cSrcweir * </ul> 461cdf0e10cSrcweir */ 462cdf0e10cSrcweir public void _getLocationOnScreen() { 463cdf0e10cSrcweir requiredMethod("getBounds()"); 464cdf0e10cSrcweir 465cdf0e10cSrcweir XAccessibleComponent parent = getParentComponent(); 466cdf0e10cSrcweir 467cdf0e10cSrcweir boolean result = true; 468cdf0e10cSrcweir Point loc = oObj.getLocationOnScreen(); 469cdf0e10cSrcweir log.println("Location is (" + loc.X + "," + loc.Y + ")"); 470cdf0e10cSrcweir 471cdf0e10cSrcweir if (parent != null) { 472cdf0e10cSrcweir Point parLoc = parent.getLocationOnScreen(); 473cdf0e10cSrcweir log.println("Parent location is (" + parLoc.X + "," + parLoc.Y + 474cdf0e10cSrcweir ")"); 475cdf0e10cSrcweir 476cdf0e10cSrcweir result &= ((parLoc.X + bounds.X) == loc.X); 477cdf0e10cSrcweir result &= ((parLoc.Y + bounds.Y) == loc.Y); 478cdf0e10cSrcweir } 479cdf0e10cSrcweir 480cdf0e10cSrcweir tRes.tested("getLocationOnScreen()", result); 481cdf0e10cSrcweir } 482cdf0e10cSrcweir 483cdf0e10cSrcweir /** 484cdf0e10cSrcweir * Obtains the size of the component. <p> 485cdf0e10cSrcweir * 486cdf0e10cSrcweir * Has <b> OK </b> status if the size is the same as in bounds. <p> 487cdf0e10cSrcweir * 488cdf0e10cSrcweir * The following method tests are to be completed successfully before : 489cdf0e10cSrcweir * <ul> 490cdf0e10cSrcweir * <li> <code> getBounds() </code> </li> 491cdf0e10cSrcweir * </ul> 492cdf0e10cSrcweir */ 493cdf0e10cSrcweir public void _getSize() { 494cdf0e10cSrcweir requiredMethod("getBounds()"); 495cdf0e10cSrcweir 496cdf0e10cSrcweir boolean result = true; 497cdf0e10cSrcweir Size size = oObj.getSize(); 498cdf0e10cSrcweir 499cdf0e10cSrcweir result &= (size.Width == bounds.Width); 500cdf0e10cSrcweir result &= (size.Height == bounds.Height); 501cdf0e10cSrcweir 502cdf0e10cSrcweir tRes.tested("getSize()", result); 503cdf0e10cSrcweir } 504cdf0e10cSrcweir 505cdf0e10cSrcweir /** 506cdf0e10cSrcweir * Just calls the method. <p> 507cdf0e10cSrcweir * 508cdf0e10cSrcweir * Has <b> OK </b> status if no runtime exceptions occured. 509cdf0e10cSrcweir */ 510cdf0e10cSrcweir public void _grabFocus() { 511cdf0e10cSrcweir boolean result = true; 512cdf0e10cSrcweir oObj.grabFocus(); 513cdf0e10cSrcweir 514cdf0e10cSrcweir tRes.tested("grabFocus()", result); 515cdf0e10cSrcweir } 516cdf0e10cSrcweir 517cdf0e10cSrcweir /** 518cdf0e10cSrcweir * Retrieves all children (not more than 50) of the current 519cdf0e10cSrcweir * component which support <code>XAccessibleComponent</code>. 520cdf0e10cSrcweir * 521cdf0e10cSrcweir * @return The array of children. Empty array returned if 522cdf0e10cSrcweir * such children were not found or some error occured. 523cdf0e10cSrcweir */ 524cdf0e10cSrcweir private XAccessibleComponent[] getChildrenComponents() { 525cdf0e10cSrcweir XAccessible xAcc = (XAccessible) UnoRuntime.queryInterface( 526cdf0e10cSrcweir XAccessible.class, oObj); 527cdf0e10cSrcweir 528cdf0e10cSrcweir if (xAcc == null) { 529cdf0e10cSrcweir log.println("Component doesn't support XAccessible."); 530cdf0e10cSrcweir 531cdf0e10cSrcweir return new XAccessibleComponent[0]; 532cdf0e10cSrcweir } 533cdf0e10cSrcweir 534cdf0e10cSrcweir XAccessibleContext xAccCon = xAcc.getAccessibleContext(); 535cdf0e10cSrcweir int cnt = xAccCon.getAccessibleChildCount(); 536cdf0e10cSrcweir 537cdf0e10cSrcweir // for cases when too many children exist checking only first 50 538cdf0e10cSrcweir if (cnt > 50) { 539cdf0e10cSrcweir cnt = 50; 540cdf0e10cSrcweir } 541cdf0e10cSrcweir 542cdf0e10cSrcweir Vector childComp = new Vector(); 543cdf0e10cSrcweir 544cdf0e10cSrcweir for (int i = 0; i < cnt; i++) { 545cdf0e10cSrcweir try { 546cdf0e10cSrcweir XAccessible child = xAccCon.getAccessibleChild(i); 547cdf0e10cSrcweir XAccessibleContext xAccConCh = child.getAccessibleContext(); 548cdf0e10cSrcweir XAccessibleComponent xChAccComp = (XAccessibleComponent) UnoRuntime.queryInterface( 549cdf0e10cSrcweir XAccessibleComponent.class, 550cdf0e10cSrcweir xAccConCh); 551cdf0e10cSrcweir 552cdf0e10cSrcweir if (xChAccComp != null) { 553cdf0e10cSrcweir childComp.add(xChAccComp); 554cdf0e10cSrcweir } 555cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 556cdf0e10cSrcweir } 557cdf0e10cSrcweir } 558cdf0e10cSrcweir 559cdf0e10cSrcweir return (XAccessibleComponent[]) childComp.toArray( 560cdf0e10cSrcweir new XAccessibleComponent[childComp.size()]); 561cdf0e10cSrcweir } 562cdf0e10cSrcweir 563cdf0e10cSrcweir /** 564cdf0e10cSrcweir * Gets the parent of the current component which support 565cdf0e10cSrcweir * <code>XAccessibleComponent</code>. 566cdf0e10cSrcweir * 567cdf0e10cSrcweir * @return The parent or <code>null</code> if the component 568cdf0e10cSrcweir * has no parent or some errors occured. 569cdf0e10cSrcweir */ 570cdf0e10cSrcweir private XAccessibleComponent getParentComponent() { 571cdf0e10cSrcweir XAccessible xAcc = (XAccessible) UnoRuntime.queryInterface( 572cdf0e10cSrcweir XAccessible.class, oObj); 573cdf0e10cSrcweir 574cdf0e10cSrcweir if (xAcc == null) { 575cdf0e10cSrcweir log.println("Component doesn't support XAccessible."); 576cdf0e10cSrcweir 577cdf0e10cSrcweir return null; 578cdf0e10cSrcweir } 579cdf0e10cSrcweir 580cdf0e10cSrcweir XAccessibleContext xAccCon = xAcc.getAccessibleContext(); 581cdf0e10cSrcweir XAccessible xAccPar = xAccCon.getAccessibleParent(); 582cdf0e10cSrcweir 583cdf0e10cSrcweir if (xAccPar == null) { 584cdf0e10cSrcweir log.println("Component has no accessible parent."); 585cdf0e10cSrcweir 586cdf0e10cSrcweir return null; 587cdf0e10cSrcweir } 588cdf0e10cSrcweir 589cdf0e10cSrcweir XAccessibleContext xAccConPar = xAccPar.getAccessibleContext(); 590cdf0e10cSrcweir XAccessibleComponent parent = (XAccessibleComponent) UnoRuntime.queryInterface( 591cdf0e10cSrcweir XAccessibleComponent.class, 592cdf0e10cSrcweir xAccConPar); 593cdf0e10cSrcweir 594cdf0e10cSrcweir if (parent == null) { 595cdf0e10cSrcweir log.println( 596cdf0e10cSrcweir "Accessible parent doesn't support XAccessibleComponent"); 597cdf0e10cSrcweir 598cdf0e10cSrcweir return null; 599cdf0e10cSrcweir } 600cdf0e10cSrcweir 601cdf0e10cSrcweir return parent; 602cdf0e10cSrcweir } 603cdf0e10cSrcweir 604cdf0e10cSrcweir /** 605cdf0e10cSrcweir * Just calls the method. 606cdf0e10cSrcweir */ 607cdf0e10cSrcweir public void _getForeground() { 608cdf0e10cSrcweir int forColor = oObj.getForeground(); 609cdf0e10cSrcweir log.println("getForeground(): " + forColor); 610cdf0e10cSrcweir tRes.tested("getForeground()", true); 611cdf0e10cSrcweir } 612cdf0e10cSrcweir 613cdf0e10cSrcweir /** 614cdf0e10cSrcweir * Just calls the method. 615cdf0e10cSrcweir */ 616cdf0e10cSrcweir public void _getBackground() { 617cdf0e10cSrcweir int backColor = oObj.getBackground(); 618cdf0e10cSrcweir log.println("getBackground(): " + backColor); 619cdf0e10cSrcweir tRes.tested("getBackground()", true); 620cdf0e10cSrcweir } 621cdf0e10cSrcweir 622cdf0e10cSrcweir /** 623cdf0e10cSrcweir * Restores initial component text. 624cdf0e10cSrcweir */ 625cdf0e10cSrcweir protected void after() { 626cdf0e10cSrcweir if (tEnv.getObjRelation("Destroy") != null) { 627cdf0e10cSrcweir disposeEnvironment(); 628cdf0e10cSrcweir } 629cdf0e10cSrcweir } 630cdf0e10cSrcweir 631cdf0e10cSrcweir private boolean isCovered(Point p) { 632cdf0e10cSrcweir int elements = KnownBounds.size(); 633cdf0e10cSrcweir boolean Covered = false; 634cdf0e10cSrcweir for (int k=0;k<elements;k++) { 635cdf0e10cSrcweir Rectangle known = (Rectangle) KnownBounds.get(k); 636cdf0e10cSrcweir Covered = (known.X < p.X); 637cdf0e10cSrcweir Covered &= (known.Y < p.Y); 638cdf0e10cSrcweir Covered &= (p.Y < known.Y+known.Height); 639cdf0e10cSrcweir Covered &= (p.X < known.X+known.Width); 640cdf0e10cSrcweir 641cdf0e10cSrcweir if (Covered) { 642cdf0e10cSrcweir break; 643cdf0e10cSrcweir } 644cdf0e10cSrcweir } 645cdf0e10cSrcweir return Covered; 646cdf0e10cSrcweir } 647cdf0e10cSrcweir }