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