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