1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="accessibility_XAccessibleEventBroadcaster" script:language="StarBasic"> 4'************************************************************************* 5'* 6' 7' Licensed to the Apache Software Foundation (ASF) under one 8' or more contributor license agreements. See the NOTICE file 9' distributed with this work for additional information 10' regarding copyright ownership. The ASF licenses this file 11' to you under the Apache License, Version 2.0 (the 12' "License"); you may not use this file except in compliance 13' with the License. You may obtain a copy of the License at 14' 15' http://www.apache.org/licenses/LICENSE-2.0 16' 17' Unless required by applicable law or agreed to in writing, 18' software distributed under the License is distributed on an 19' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20' KIND, either express or implied. See the License for the 21' specific language governing permissions and limitations 22' under the License. 23' 24'************************************************************************* 25'************************************************************************* 26 27 28 29' Be sure that all variables are dimensioned: 30option explicit 31 32'************************************************************************* 33' This Interface/Service test depends on the following GLOBAL variables, 34' which must be specified in the object creation: 35 36' fireEvent() precedure 37' located in component test 38 39'************************************************************************* 40 41 42 43 44 45Dim oListener1 As Object 46Dim oListener2 As Object 47Dim bL1called As Boolean 48Dim bL2called As Boolean 49 50 51Sub RunTest() 52 53'************************************************************************* 54' INTERFACE: 55' com.sun.star.accessibility.XAccessibleEventBroadcaster 56'************************************************************************* 57On Error Goto ErrHndl 58 Dim bOK As Boolean 59 Dim isTransient As Boolean 60 Dim stateSet As Variant 61 bOK = true 62 63 'out.log("Creating Listeners...") 64 oListener1 = createUNOListener("EL1_","com.sun.star.accessibility.XAccessibleEventListener") 65 oListener2 = createUNOListener("EL2_","com.sun.star.accessibility.XAccessibleEventListener") 66 bOK = bOK AND NOT isNULL(oListener1) AND NOT isNULL(oListener2) 67 if NOT bOK then out.log( "ERROR: Cannot create listeners...") 68 69 if NOT hasUNOInterfaces(oObj,"com.sun.star.accessibility.XAccessibleContext") then 70 'out.log("Object does not implement XAccessibleContext.") 71 isTransient = false 72 else 73 stateSet = oObj.getAccessibleStateSet() 74 isTransient = stateSet.contains(27) 75 End If 76 77 Test.StartMethod("addEventListener()") 78 bOK = true 79 bL1called = false 80 bL2called = false 81 'out.log("Adding two listeners...") 82 oObj.com_sun_star_accessibility_XAccessibleEventBroadcaster_addEventListener(oListener1) 83 oObj.com_sun_star_accessibility_XAccessibleEventBroadcaster_addEventListener(oListener2) 84 'out.log("fire event") 85 fireEvent() 86 wait(500) 87 out.log("Listener1 called: "+bL1called) 88 out.log("Listener2 called: "+bL2called) 89 if NOT isTransient then 90 bOK = bOK AND bL1called AND bL2called 91 else 92 'out.log("Object is transient, listeners aren't expected to call.") 93 bOK = true 94 End If 95 Test.MethodTested("addEventListener()",bOK) 96 97 98 Test.StartMethod("removeEventListener()") 99 bOK = true 100 bL1called = false 101 bL2called = false 102 'out.log("Removing one listener...") 103 oObj.com_sun_star_accessibility_XAccessibleEventBroadcaster_removeEventListener(oListener1) 104 'out.log("fire event") 105 fireEvent() 106 wait(500) 107 out.log("Listener1 called: "+bL1called) 108 out.log("Listener2 called: "+bL2called) 109 if NOT isTransient then 110 bOK = bOK AND NOT bL1called AND bL2called 111 else 112 'out.log("Object is transient, listeners aren't expected to call.") 113 bOK = true 114 End If 115 Test.MethodTested("removeEventListener()",bOK) 116 117 ' Removing the second listener... 118 oObj.com_sun_star_accessibility_XAccessibleEventBroadcaster_removeEventListener(oListener2) 119 120 121Exit Sub 122ErrHndl: 123 Test.Exception() 124 bOK = false 125 resume next 126End Sub 127 128Sub EL1_notifyEvent(ev As Variant) 129 'out.log("CallBack for Listener1 notifyEvent was called.") 130 bL1called = true 131End Sub 132 133Sub EL1_disposing() 134End Sub 135 136Sub EL2_notifyEvent(ev As Variant) 137 'out.log("CallBack for Listener2 notifyEvent was called.") 138 bL2called = true 139End Sub 140 141Sub EL2_disposing() 142End Sub 143 144</script:module> 145