1*cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?> 2*cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3*cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="accessibility_XAccessibleComponent" script:language="StarBasic"> 4*cdf0e10cSrcweir 5*cdf0e10cSrcweir 6*cdf0e10cSrcweir'************************************************************************* 7*cdf0e10cSrcweir' 8*cdf0e10cSrcweir' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9*cdf0e10cSrcweir' 10*cdf0e10cSrcweir' Copyright 2000, 2010 Oracle and/or its affiliates. 11*cdf0e10cSrcweir' 12*cdf0e10cSrcweir' OpenOffice.org - a multi-platform office productivity suite 13*cdf0e10cSrcweir' 14*cdf0e10cSrcweir' This file is part of OpenOffice.org. 15*cdf0e10cSrcweir' 16*cdf0e10cSrcweir' OpenOffice.org is free software: you can redistribute it and/or modify 17*cdf0e10cSrcweir' it under the terms of the GNU Lesser General Public License version 3 18*cdf0e10cSrcweir' only, as published by the Free Software Foundation. 19*cdf0e10cSrcweir' 20*cdf0e10cSrcweir' OpenOffice.org is distributed in the hope that it will be useful, 21*cdf0e10cSrcweir' but WITHOUT ANY WARRANTY; without even the implied warranty of 22*cdf0e10cSrcweir' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23*cdf0e10cSrcweir' GNU Lesser General Public License version 3 for more details 24*cdf0e10cSrcweir' (a copy is included in the LICENSE file that accompanied this code). 25*cdf0e10cSrcweir' 26*cdf0e10cSrcweir' You should have received a copy of the GNU Lesser General Public License 27*cdf0e10cSrcweir' version 3 along with OpenOffice.org. If not, see 28*cdf0e10cSrcweir' <http://www.openoffice.org/license.html> 29*cdf0e10cSrcweir' for a copy of the LGPLv3 License. 30*cdf0e10cSrcweir' 31*cdf0e10cSrcweir'************************************************************************* 32*cdf0e10cSrcweir'************************************************************************* 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir' Be sure that all variables are dimensioned: 37*cdf0e10cSrcweiroption explicit 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir 42*cdf0e10cSrcweirSub RunTest() 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir'************************************************************************* 45*cdf0e10cSrcweir' INTERFACE: 46*cdf0e10cSrcweir' com.sun.star.accessibility.XAccessibleComponent 47*cdf0e10cSrcweir'************************************************************************* 48*cdf0e10cSrcweirOn Error Goto ErrHndl 49*cdf0e10cSrcweir Dim bOK As Boolean 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir Test.StartMethod("getBounds()") 52*cdf0e10cSrcweir Dim bounds As new com.sun.star.awt.Rectangle 53*cdf0e10cSrcweir Dim X1,Y1 As Integer 54*cdf0e10cSrcweir bOK = true 55*cdf0e10cSrcweir bounds = oObj.getBounds() 56*cdf0e10cSrcweir X1 = bounds.X+bounds.Width 57*cdf0e10cSrcweir Y1 = bounds.Y+bounds.Height 58*cdf0e10cSrcweir Out.Log("Object's bounding box: ("+bounds.X+","+bounds.Y+","+X1+","+Y1+").") 59*cdf0e10cSrcweir bOK = bOK AND (NOT isNull(bounds)) AND (bounds.X >= 0) AND (bounds.Y >= 0) _ 60*cdf0e10cSrcweir AND (bounds.Width > 0) AND (bounds.Height > 0) 61*cdf0e10cSrcweir Test.MethodTested("getBounds()",bOK) 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir Test.StartMethod("contains()") 64*cdf0e10cSrcweir Dim point1 As new com.sun.star.awt.Point 65*cdf0e10cSrcweir Dim point2 As new com.sun.star.awt.Point 66*cdf0e10cSrcweir bOK = true 67*cdf0e10cSrcweir point1.X = bounds.Width + 1 68*cdf0e10cSrcweir point1.Y = bounds.Height + 1 69*cdf0e10cSrcweir point2.X = 0 70*cdf0e10cSrcweir point2.Y = 0 71*cdf0e10cSrcweir bOK = bOK AND (NOT oObj.contains(point1)) AND oObj.contains(point2) 72*cdf0e10cSrcweir Test.MethodTested("contains()",bOK) 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir Test.StartMethod("getAccessibleAt()") 75*cdf0e10cSrcweir Dim accAt As Object, oChild As Object 76*cdf0e10cSrcweir Dim i As Integer, childCount As Long, mCount As Integer 77*cdf0e10cSrcweir Dim chBounds As new com.sun.star.awt.Rectangle 78*cdf0e10cSrcweir Dim locRes As Boolean 79*cdf0e10cSrcweir Dim ComponentFound As Boolean 80*cdf0e10cSrcweir Dim visibleFound as Boolean 81*cdf0e10cSrcweir Dim XAccessibleSelection as Boolean 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir bOK = true 84*cdf0e10cSrcweir childCount = oObj.getAccessibleChildCount() 85*cdf0e10cSrcweir if (childCount = 0) then 86*cdf0e10cSrcweir Out.Log("There are no children supported by XAccessibleComponent...") 87*cdf0e10cSrcweir else 88*cdf0e10cSrcweir Out.Log("There are "+childCount+" children supported by XAccessibleComponent.") 89*cdf0e10cSrcweir if (childCount > 50) then 90*cdf0e10cSrcweir mCount = 50 91*cdf0e10cSrcweir Out.Log("Checking only first 50 children...") 92*cdf0e10cSrcweir else 93*cdf0e10cSrcweir mCount = childCount 94*cdf0e10cSrcweir End If 95*cdf0e10cSrcweir ComponentFound = false 96*cdf0e10cSrcweir visibleFound = false 97*cdf0e10cSrcweir XAccessibleSelection = hasUNOInterfaces(oObj, "drafts.com.sun.star.accessibility.XAccessibleSelection") 98*cdf0e10cSrcweir for i = 0 to (mCount - 1) 99*cdf0e10cSrcweir oChild = oObj.getAccessibleChild(i) 100*cdf0e10cSrcweir if NOT hasUNOInterfaces(oChild,"drafts.com.sun.star.accessibility.XAccessibleContext") then 101*cdf0e10cSrcweir oChild = oChild.getAccessibleContext() 102*cdf0e10cSrcweir End If 103*cdf0e10cSrcweir if hasUNOInterfaces(oChild,"drafts.com.sun.star.accessibility.XAccessibleComponent") then 104*cdf0e10cSrcweir ComponentFound = TRUE 105*cdf0e10cSrcweir if XAccessibleSelection then 106*cdf0e10cSrcweir if oObj.isAccessibleChildSelected(i) then 107*cdf0e10cSrcweir visibleFound = TRUE 108*cdf0e10cSrcweir End If 109*cdf0e10cSrcweir End If 110*cdf0e10cSrcweir oChild = oChild.getAccessibleContext() 111*cdf0e10cSrcweir chBounds = oChild.getBounds() 112*cdf0e10cSrcweir point1.X = chBounds.X 113*cdf0e10cSrcweir point1.Y = chBounds.Y 114*cdf0e10cSrcweir accAt = oObj.getAccessibleAt(point1) 115*cdf0e10cSrcweir locRes = utils.at_equals(accAt,oChild) 116*cdf0e10cSrcweir Out.log(" getAccessibleAt() with valid points with child " + i + ": " + locRes) 117*cdf0e10cSrcweir bOK = bOK AND locRes 118*cdf0e10cSrcweir point2.X = chBounds.X - 1 119*cdf0e10cSrcweir point2.Y = chBounds.Y - 1 120*cdf0e10cSrcweir accAt = oObj.getAccessibleAt(point2) 121*cdf0e10cSrcweir locRes = NOT utils.at_equals(accAt,oChild) 122*cdf0e10cSrcweir Out.log(" getAccessibleAt() with invalid points with child " + i + ": " + locRes) 123*cdf0e10cSrcweir bOK = bOK AND locRes 124*cdf0e10cSrcweir End If 125*cdf0e10cSrcweir next i 126*cdf0e10cSrcweir if not ComponentFound then 127*cdf0e10cSrcweir Out.Log("Could not find any children which supports XAccessibleComponent!") 128*cdf0e10cSrcweir bOK = TRUE 129*cdf0e10cSrcweir end if 130*cdf0e10cSrcweir if not visibleFound then 131*cdf0e10cSrcweir Out.Log("Could not find any children which is visible!") 132*cdf0e10cSrcweir bOK = TRUE 133*cdf0e10cSrcweir end if 134*cdf0e10cSrcweir End If 135*cdf0e10cSrcweir Test.MethodTested("getAccessibleAt()",bOK) 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir Test.StartMethod("getLocation()") 138*cdf0e10cSrcweir bOK = true 139*cdf0e10cSrcweir point1 = oObj.getLocation() 140*cdf0e10cSrcweir bOK = bOK AND (point1.X = bounds.X) AND (point1.Y = bounds.Y) 141*cdf0e10cSrcweir Test.MethodTested("getLocation()",bOK) 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir Test.StartMethod("getLocationOnScreen()") 144*cdf0e10cSrcweir Dim accParent As Object 145*cdf0e10cSrcweir bOK = true 146*cdf0e10cSrcweir accParent = getParentComponent() 147*cdf0e10cSrcweir point1 = oObj.getLocationOnScreen() 148*cdf0e10cSrcweir if NOT isNull(accParent) then 149*cdf0e10cSrcweir point2 = accParent.getLocationOnScreen() 150*cdf0e10cSrcweir bOK = bOK AND (point2.X + bounds.X = point1.X) 151*cdf0e10cSrcweir bOK = bOK AND (point2.Y + bounds.Y = point1.Y) 152*cdf0e10cSrcweir else 153*cdf0e10cSrcweir Out.Log("Component's parent is null.") 154*cdf0e10cSrcweir End If 155*cdf0e10cSrcweir Test.MethodTested("getLocationOnScreen()",bOK) 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir Test.StartMethod("getSize()") 158*cdf0e10cSrcweir Dim oSize As new com.sun.star.awt.Size 159*cdf0e10cSrcweir bOK = true 160*cdf0e10cSrcweir oSize = oObj.getSize() 161*cdf0e10cSrcweir bOK = bOK AND (oSize.Width = bounds.Width) AND (oSize.Height = bounds.Height) 162*cdf0e10cSrcweir Test.MethodTested("getSize()",bOK) 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir Test.StartMethod("grabFocus()") 165*cdf0e10cSrcweir bOK = true 166*cdf0e10cSrcweir oObj.grabFocus() 167*cdf0e10cSrcweir Test.MethodTested("grabFocus()",bOK) 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir Test.StartMethod("getForeground()") 170*cdf0e10cSrcweir Dim fColor As Long 171*cdf0e10cSrcweir bOK = true 172*cdf0e10cSrcweir fColor = oObj.getForeground() 173*cdf0e10cSrcweir Out.Log("Foreground color is: "+fColor) 174*cdf0e10cSrcweir Test.MethodTested("getForeground()",bOK) 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir Test.StartMethod("getBackground()") 177*cdf0e10cSrcweir Dim bColor As Long 178*cdf0e10cSrcweir bOK = true 179*cdf0e10cSrcweir bColor = oObj.getBackground() 180*cdf0e10cSrcweir Out.Log("Background color is: "+bColor) 181*cdf0e10cSrcweir Test.MethodTested("getBackground()",bOK) 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir 186*cdf0e10cSrcweirExit Sub 187*cdf0e10cSrcweirErrHndl: 188*cdf0e10cSrcweir Test.Exception() 189*cdf0e10cSrcweir bOK = false 190*cdf0e10cSrcweir resume next 191*cdf0e10cSrcweirEnd Sub 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir 194*cdf0e10cSrcweirFunction getAccessibleChildren() As Variant 195*cdf0e10cSrcweir Dim accCount As Integer, i As Integer, j As Integer 196*cdf0e10cSrcweir Dim accChContext As Object, accCh As Object 197*cdf0e10cSrcweir Dim resArray(50) As Variant 198*cdf0e10cSrcweir Dim emptyArray() As Variant 199*cdf0e10cSrcweir j = 0 200*cdf0e10cSrcweir i = 0 201*cdf0e10cSrcweir if NOT hasUNOInterfaces(oObj,"drafts.com.sun.star.accessibility.XAccessible") then 202*cdf0e10cSrcweir Out.Log("An object does not support XAccessible interface!") 203*cdf0e10cSrcweir Exit Function 204*cdf0e10cSrcweir End If 205*cdf0e10cSrcweir accCount = oObj.getAccessibleChildCount() 206*cdf0e10cSrcweir if (accCount > 50) then accCount = 50 207*cdf0e10cSrcweir while (i < accCount) 208*cdf0e10cSrcweir accCh = oObj.getAccessibleChild(i) 209*cdf0e10cSrcweir accChContext = accCh.getAccessibleContext() 210*cdf0e10cSrcweir if hasUNOInterfaces(accChContext,"drafts.com.sun.star.accessibility.XAccessibleComponent") then 211*cdf0e10cSrcweir resArray(j) = accChContext 212*cdf0e10cSrcweir j = j + 1 213*cdf0e10cSrcweir End If 214*cdf0e10cSrcweir i = i + 1 215*cdf0e10cSrcweir wend 216*cdf0e10cSrcweir if (accCount <> 0) then 217*cdf0e10cSrcweir Dim returnArray(j - 1) As Variant 218*cdf0e10cSrcweir For i = 0 to (j - 1) 219*cdf0e10cSrcweir returnArray(i) = resArray(i) 220*cdf0e10cSrcweir next i 221*cdf0e10cSrcweir getAccessibleChildren() = returnArray() 222*cdf0e10cSrcweir else 223*cdf0e10cSrcweir getAccessibleChildren() = emptyArray() 224*cdf0e10cSrcweir End If 225*cdf0e10cSrcweirEnd Function 226*cdf0e10cSrcweir 227*cdf0e10cSrcweirFunction getParentComponent() As Object 228*cdf0e10cSrcweir Dim accParent As Object 229*cdf0e10cSrcweir Dim accParContext As Object 230*cdf0e10cSrcweir if NOT hasUNOInterfaces(oObj,"drafts.com.sun.star.accessibility.XAccessible") then 231*cdf0e10cSrcweir Out.Log("An object does not support XAccessible interface!") 232*cdf0e10cSrcweir Exit Function 233*cdf0e10cSrcweir End If 234*cdf0e10cSrcweir accParent = oObj.getAccessibleParent() 235*cdf0e10cSrcweir if isNull(accParent) then 236*cdf0e10cSrcweir Out.Log("The component has no accessible parent!") 237*cdf0e10cSrcweir Exit Function 238*cdf0e10cSrcweir End If 239*cdf0e10cSrcweir accParContext = accParent.getAccessibleContext() 240*cdf0e10cSrcweir if NOT hasUNOInterfaces(accParContext,"drafts.com.sun.star.accessibility.XAccessibleComponent") then 241*cdf0e10cSrcweir Out.Log("Accessible parent doesn't support XAccessibleComponent!") 242*cdf0e10cSrcweir Exit Function 243*cdf0e10cSrcweir else 244*cdf0e10cSrcweir getParentComponent() = accParContext 245*cdf0e10cSrcweir End If 246*cdf0e10cSrcweirEnd Function 247*cdf0e10cSrcweir</script:module> 248