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_XAccessibleSelection" 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' This Interface/Service test depends on the following GLOBAL variables, 36*b1cdbd2cSJim Jagielski' which must be specified in the object creation: 37*b1cdbd2cSJim Jagielski 38*b1cdbd2cSJim Jagielski' Global multiSelection As Boolean 39*b1cdbd2cSJim Jagielski 40*b1cdbd2cSJim Jagielski'************************************************************************* 41*b1cdbd2cSJim Jagielski 42*b1cdbd2cSJim Jagielski 43*b1cdbd2cSJim Jagielski 44*b1cdbd2cSJim Jagielski 45*b1cdbd2cSJim Jagielski 46*b1cdbd2cSJim Jagielski 47*b1cdbd2cSJim JagielskiSub RunTest() 48*b1cdbd2cSJim Jagielski 49*b1cdbd2cSJim Jagielski'************************************************************************* 50*b1cdbd2cSJim Jagielski' INTERFACE: 51*b1cdbd2cSJim Jagielski' com.sun.star.accessibility.XAccessibleSelection 52*b1cdbd2cSJim Jagielski'************************************************************************* 53*b1cdbd2cSJim JagielskiOn Error Goto ErrHndl 54*b1cdbd2cSJim Jagielski Dim bOK As Boolean, locRes As Boolean 55*b1cdbd2cSJim Jagielski Dim chCount As Long, selCount As Long 56*b1cdbd2cSJim Jagielski Dim i As Long, mCount As Integer 57*b1cdbd2cSJim Jagielski 58*b1cdbd2cSJim Jagielski if multiSelection then 59*b1cdbd2cSJim Jagielski Out.Log("Object allows multiple selection!") 60*b1cdbd2cSJim Jagielski else 61*b1cdbd2cSJim Jagielski Out.Log("Object does not allow multiple selection!") 62*b1cdbd2cSJim Jagielski End If 63*b1cdbd2cSJim Jagielski 64*b1cdbd2cSJim Jagielski chCount = oObj.getAccessibleChildCount() 65*b1cdbd2cSJim Jagielski selCount = oObj.getSelectedAccessibleChildCount() 66*b1cdbd2cSJim Jagielski Out.Log("Object has "+chCount+" child(ren), "+selCount+" of them selected.") 67*b1cdbd2cSJim Jagielski If (chCount > 50) then 68*b1cdbd2cSJim Jagielski mCount = 50 69*b1cdbd2cSJim Jagielski Out.Log("Object has too many children. Testing only first 50.") 70*b1cdbd2cSJim Jagielski else 71*b1cdbd2cSJim Jagielski mCount = chCount 72*b1cdbd2cSJim Jagielski End If 73*b1cdbd2cSJim Jagielski 74*b1cdbd2cSJim Jagielski clearSelection() 75*b1cdbd2cSJim Jagielski 76*b1cdbd2cSJim Jagielski Test.StartMethod("selectAccessibleChild()") 77*b1cdbd2cSJim Jagielski bOK = true 78*b1cdbd2cSJim Jagielski if (mCount > 0) then 79*b1cdbd2cSJim Jagielski i = mCount - 1 80*b1cdbd2cSJim Jagielski while (oObj.isAccessibleChildSelected(i) OR itemDisabled(oObj.getAccessibleChild(i))) AND (i > 0) 81*b1cdbd2cSJim Jagielski i = i - 1 82*b1cdbd2cSJim Jagielski wend 83*b1cdbd2cSJim Jagielski if (i >= 0) then 84*b1cdbd2cSJim Jagielski Out.Log("Selecting child #"+i+"...") 85*b1cdbd2cSJim Jagielski oObj.selectAccessibleChild(i) 86*b1cdbd2cSJim Jagielski wait(500) 87*b1cdbd2cSJim Jagielski locRes = oObj.isAccessibleChildSelected(i) 88*b1cdbd2cSJim Jagielski Out.Log("Child #"+i+" selected: "+locRes) 89*b1cdbd2cSJim Jagielski bOK = bOK AND locRes 90*b1cdbd2cSJim Jagielski End If 91*b1cdbd2cSJim Jagielski End If 92*b1cdbd2cSJim Jagielski clearSelection() 93*b1cdbd2cSJim Jagielski Test.MethodTested("selectAccessibleChild()",bOK) 94*b1cdbd2cSJim Jagielski 95*b1cdbd2cSJim Jagielski Test.StartMethod("isAccessibleChildSelected()") 96*b1cdbd2cSJim Jagielski bOK = true 97*b1cdbd2cSJim Jagielski if (mCount > 0) then 98*b1cdbd2cSJim Jagielski i = mCount - 1 99*b1cdbd2cSJim Jagielski while (oObj.isAccessibleChildSelected(i) OR itemDisabled(oObj.getAccessibleChild(i))) AND (i > 0) 100*b1cdbd2cSJim Jagielski i = i - 1 101*b1cdbd2cSJim Jagielski wend 102*b1cdbd2cSJim Jagielski if (i >= 0) then 103*b1cdbd2cSJim Jagielski Out.Log("Selecting child #"+i+"...") 104*b1cdbd2cSJim Jagielski oObj.selectAccessibleChild(i) 105*b1cdbd2cSJim Jagielski wait(500) 106*b1cdbd2cSJim Jagielski locRes = oObj.isAccessibleChildSelected(i) 107*b1cdbd2cSJim Jagielski Out.Log("Child #"+i+" selected: "+locRes) 108*b1cdbd2cSJim Jagielski bOK = bOK AND locRes 109*b1cdbd2cSJim Jagielski End If 110*b1cdbd2cSJim Jagielski End If 111*b1cdbd2cSJim Jagielski clearSelection() 112*b1cdbd2cSJim Jagielski Test.MethodTested("isAccessibleChildSelected()",bOK) 113*b1cdbd2cSJim Jagielski 114*b1cdbd2cSJim Jagielski Test.StartMethod("clearAccessibleSelection()") 115*b1cdbd2cSJim Jagielski bOK = true 116*b1cdbd2cSJim Jagielski if (mCount > 0) AND (multiSelection) then 117*b1cdbd2cSJim Jagielski oObj.selectAccessibleChild(chCount - 1) 118*b1cdbd2cSJim Jagielski wait(500) 119*b1cdbd2cSJim Jagielski oObj.clearAccessibleSelection() 120*b1cdbd2cSJim Jagielski wait(500) 121*b1cdbd2cSJim Jagielski bOK = bOK AND NOT oObj.isAccessibleChildSelected(mCount - 1) 122*b1cdbd2cSJim Jagielski else 123*b1cdbd2cSJim Jagielski Out.Log("Cannot clear all selection for this object!") 124*b1cdbd2cSJim Jagielski End If 125*b1cdbd2cSJim Jagielski Test.MethodTested("clearAccessibleSelection()",bOK) 126*b1cdbd2cSJim Jagielski 127*b1cdbd2cSJim Jagielski' ### The following property was not found in correspond IDL file! ### 128*b1cdbd2cSJim Jagielski Test.StartMethod("selectAllAccessibleChildren()") 129*b1cdbd2cSJim Jagielski bOK = true 130*b1cdbd2cSJim Jagielski i = 0 131*b1cdbd2cSJim Jagielski if ((mCount > 0) AND multiSelection) then 132*b1cdbd2cSJim Jagielski' ### The following property was not found in correspond IDL file! ### 133*b1cdbd2cSJim Jagielski oObj.selectAllAccessibleChildren() 134*b1cdbd2cSJim Jagielski wait(500) 135*b1cdbd2cSJim Jagielski while (i < mCount) 136*b1cdbd2cSJim Jagielski bOK = bOK AND oObj.isAccessibleChildSelected(i) 137*b1cdbd2cSJim Jagielski i = i + 1 138*b1cdbd2cSJim Jagielski wend 139*b1cdbd2cSJim Jagielski else 140*b1cdbd2cSJim Jagielski Out.Log("Cannot select all children for this object!") 141*b1cdbd2cSJim Jagielski End If 142*b1cdbd2cSJim Jagielski clearSelection() 143*b1cdbd2cSJim Jagielski Test.MethodTested("selectAllAccessibleChildren()",bOK) 144*b1cdbd2cSJim Jagielski 145*b1cdbd2cSJim Jagielski Test.StartMethod("getSelectedAccessibleChildCount()") 146*b1cdbd2cSJim Jagielski bOK = true 147*b1cdbd2cSJim Jagielski Out.Log("Selecting all...") 148*b1cdbd2cSJim Jagielski oObj.selectAllAccessibleChildren() 149*b1cdbd2cSJim Jagielski wait(500) 150*b1cdbd2cSJim Jagielski selCount = oObj.getSelectedAccessibleChildCount() 151*b1cdbd2cSJim Jagielski Out.Log("Selected "+selCount+" child(ren).") 152*b1cdbd2cSJim Jagielski If (multiSelection) then 153*b1cdbd2cSJim Jagielski bOK = bOK AND (selCount = chCount) 154*b1cdbd2cSJim Jagielski else 155*b1cdbd2cSJim Jagielski bOK = bOK AND (selCount = 1) 156*b1cdbd2cSJim Jagielski End If 157*b1cdbd2cSJim Jagielski clearSelection() 158*b1cdbd2cSJim Jagielski selCount = oObj.getSelectedAccessibleChildCount() 159*b1cdbd2cSJim Jagielski if (multiSelection) then 160*b1cdbd2cSJim Jagielski bOK = bOK AND (selCount = 0) 161*b1cdbd2cSJim Jagielski else 162*b1cdbd2cSJim Jagielski bOK = bOK AND (selCount = 1) 163*b1cdbd2cSJim Jagielski End If 164*b1cdbd2cSJim Jagielski Test.MethodTested("getSelectedAccessibleChildCount()",bOK) 165*b1cdbd2cSJim Jagielski 166*b1cdbd2cSJim Jagielski Test.StartMethod("getSelectedAccessibleChild()") 167*b1cdbd2cSJim Jagielski Dim selAccChild As Object, accChild As Object 168*b1cdbd2cSJim Jagielski bOK = true 169*b1cdbd2cSJim Jagielski if (mCount > 0) then 170*b1cdbd2cSJim Jagielski i = mCount - 1 171*b1cdbd2cSJim Jagielski while (oObj.isAccessibleChildSelected(i) OR itemDisabled(oObj.getAccessibleChild(i))) AND (i > 0) 172*b1cdbd2cSJim Jagielski i = i - 1 173*b1cdbd2cSJim Jagielski wend 174*b1cdbd2cSJim Jagielski if (i >= 0) then 175*b1cdbd2cSJim Jagielski Out.Log("Selecting child #"+i+"...") 176*b1cdbd2cSJim Jagielski oObj.selectAccessibleChild(i) 177*b1cdbd2cSJim Jagielski wait(500) 178*b1cdbd2cSJim Jagielski Out.Log("Child #"+i+" selected: "+oObj.isAccessibleChildSelected(i)) 179*b1cdbd2cSJim Jagielski Out.Log("Now "+oObj.getSelectedAccessibleChildCount()+" child(ren) selected.") 180*b1cdbd2cSJim Jagielski selCount = oObj.getSelectedAccessibleChildCount() 181*b1cdbd2cSJim Jagielski if (selCount > 0) then 182*b1cdbd2cSJim Jagielski selAccChild = oObj.getSelectedAccessibleChild(selCount-1) 183*b1cdbd2cSJim Jagielski accChild = oObj.getAccessibleChild(i) 184*b1cdbd2cSJim Jagielski bOK = bOK AND utils.at_equals(accChild,selAccChild) 185*b1cdbd2cSJim Jagielski else 186*b1cdbd2cSJim Jagielski Out.Log("There are no selected children. Test fails.") 187*b1cdbd2cSJim Jagielski bOK = false 188*b1cdbd2cSJim Jagielski End If 189*b1cdbd2cSJim Jagielski End If 190*b1cdbd2cSJim Jagielski End If 191*b1cdbd2cSJim Jagielski Test.MethodTested("getSelectedAccessibleChild()",bOK) 192*b1cdbd2cSJim Jagielski 193*b1cdbd2cSJim Jagielski Test.StartMethod("deselectAccessibleChild()") 194*b1cdbd2cSJim Jagielski Dim newSelCount As Long 195*b1cdbd2cSJim Jagielski Dim isSelected as Boolean 196*b1cdbd2cSJim Jagielski bOK = true 197*b1cdbd2cSJim Jagielski oObj.selectAllAccessibleChildren() 198*b1cdbd2cSJim Jagielski wait(500) 199*b1cdbd2cSJim Jagielski selCount = oObj.getSelectedAccessibleChildCount() 200*b1cdbd2cSJim Jagielski Out.Log("There was "+selCount+" selected child(ren)") 201*b1cdbd2cSJim Jagielski Out.Log("Deselecting child...") 202*b1cdbd2cSJim Jagielski for i = 0 to mCount - 1 203*b1cdbd2cSJim Jagielski if oObj.isAccessibleChildSelected(i) then 204*b1cdbd2cSJim Jagielski isSelected = true 205*b1cdbd2cSJim Jagielski end if 206*b1cdbd2cSJim Jagielski oObj.deselectAccessibleChild(i) 207*b1cdbd2cSJim Jagielski wait(500) 208*b1cdbd2cSJim Jagielski newSelCount = oObj.getSelectedAccessibleChildCount() 209*b1cdbd2cSJim Jagielski Out.Log("selCount = " + selCount + " newSelCount = " + newSelCount) 210*b1cdbd2cSJim Jagielski if (multiSelection) then 211*b1cdbd2cSJim Jagielski if isSelected then 212*b1cdbd2cSJim Jagielski Out.Log("isSelected") 213*b1cdbd2cSJim Jagielski bOK = bOK AND (selCount - 1 = newSelCount) 214*b1cdbd2cSJim Jagielski else 215*b1cdbd2cSJim Jagielski bOK = bOK AND (selCount = newSelCount) 216*b1cdbd2cSJim Jagielski end if 217*b1cdbd2cSJim Jagielski else 218*b1cdbd2cSJim Jagielski Out.Log("is not multi") 219*b1cdbd2cSJim Jagielski bOK = bOK AND (newSelCount <= 1) 220*b1cdbd2cSJim Jagielski End If 221*b1cdbd2cSJim Jagielski selCount = newSelCount 222*b1cdbd2cSJim Jagielski next 223*b1cdbd2cSJim Jagielski Test.MethodTested("deselectAccessibleChild()",bOK) 224*b1cdbd2cSJim Jagielski 225*b1cdbd2cSJim JagielskiExit Sub 226*b1cdbd2cSJim JagielskiErrHndl: 227*b1cdbd2cSJim Jagielski Test.Exception() 228*b1cdbd2cSJim Jagielski bOK = false 229*b1cdbd2cSJim Jagielski resume next 230*b1cdbd2cSJim JagielskiEnd Sub 231*b1cdbd2cSJim Jagielski 232*b1cdbd2cSJim JagielskiSub clearSelection() 233*b1cdbd2cSJim Jagielski if NOT multiSelection then Exit Sub 234*b1cdbd2cSJim Jagielski Dim selCount As Long 235*b1cdbd2cSJim Jagielski selCount = oObj.getSelectedAccessibleChildCount() 236*b1cdbd2cSJim Jagielski if (selCount = 0) then Exit Sub 237*b1cdbd2cSJim Jagielski oObj.clearAccessibleSelection() 238*b1cdbd2cSJim Jagielski wait(500) 239*b1cdbd2cSJim Jagielski selCount = oObj.getSelectedAccessibleChildCount() 240*b1cdbd2cSJim Jagielski if selCount = 0 then 241*b1cdbd2cSJim Jagielski Out.Log("Deselect all: success") 242*b1cdbd2cSJim Jagielski else 243*b1cdbd2cSJim Jagielski Out.Log("Deselect all: error!. "+selCount+" child(ren) remains selected.") 244*b1cdbd2cSJim Jagielski End If 245*b1cdbd2cSJim JagielskiEnd Sub 246*b1cdbd2cSJim Jagielski 247*b1cdbd2cSJim JagielskiFunction itemDisabled(oChild As Object) As Boolean 248*b1cdbd2cSJim Jagielski if NOT hasUNOInterfaces(oChild,"com.sun.star.accessibility.XAccessibleContext") then 249*b1cdbd2cSJim Jagielski oChild = oChild.getAccessibleContext() 250*b1cdbd2cSJim Jagielski End If 251*b1cdbd2cSJim Jagielski itemDisabled = NOT oChild.getAccessibleStateSet().contains(21) 252*b1cdbd2cSJim JagielskiEnd Function 253*b1cdbd2cSJim Jagielski 254*b1cdbd2cSJim Jagielski</script:module> 255