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' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7' 8' Copyright 2000, 2010 Oracle and/or its affiliates. 9' 10' OpenOffice.org - a multi-platform office productivity suite 11' 12' This file is part of OpenOffice.org. 13' 14' OpenOffice.org is free software: you can redistribute it and/or modify 15' it under the terms of the GNU Lesser General Public License version 3 16' only, as published by the Free Software Foundation. 17' 18' OpenOffice.org is distributed in the hope that it will be useful, 19' but WITHOUT ANY WARRANTY; without even the implied warranty of 20' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21' GNU Lesser General Public License version 3 for more details 22' (a copy is included in the LICENSE file that accompanied this code). 23' 24' You should have received a copy of the GNU Lesser General Public License 25' version 3 along with OpenOffice.org. If not, see 26' <http://www.openoffice.org/license.html> 27' for a copy of the LGPLv3 License. 28' 29'************************************************************************* 30'************************************************************************* 31 32 33 34' Be sure that all variables are dimensioned: 35option explicit 36 37'************************************************************************* 38' This Interface/Service test depends on the following GLOBAL variables, 39' which must be specified in the object creation: 40 41' fireEvent() precedure 42' located in component test 43 44'************************************************************************* 45 46 47 48 49 50Dim oListener1 As Object 51Dim oListener2 As Object 52Dim bL1called As Boolean 53Dim bL2called As Boolean 54 55 56Sub RunTest() 57 58'************************************************************************* 59' INTERFACE: 60' com.sun.star.accessibility.XAccessibleEventBroadcaster 61'************************************************************************* 62On Error Goto ErrHndl 63 Dim bOK As Boolean 64 Dim isTransient As Boolean 65 Dim stateSet As Variant 66 bOK = true 67 68 'out.log("Creating Listeners...") 69 oListener1 = createUNOListener("EL1_","com.sun.star.accessibility.XAccessibleEventListener") 70 oListener2 = createUNOListener("EL2_","com.sun.star.accessibility.XAccessibleEventListener") 71 bOK = bOK AND NOT isNULL(oListener1) AND NOT isNULL(oListener2) 72 if NOT bOK then out.log( "ERROR: Cannot create listeners...") 73 74 if NOT hasUNOInterfaces(oObj,"com.sun.star.accessibility.XAccessibleContext") then 75 'out.log("Object does not implement XAccessibleContext.") 76 isTransient = false 77 else 78 stateSet = oObj.getAccessibleStateSet() 79 isTransient = stateSet.contains(27) 80 End If 81 82 Test.StartMethod("addEventListener()") 83 bOK = true 84 bL1called = false 85 bL2called = false 86 'out.log("Adding two listeners...") 87 oObj.com_sun_star_accessibility_XAccessibleEventBroadcaster_addEventListener(oListener1) 88 oObj.com_sun_star_accessibility_XAccessibleEventBroadcaster_addEventListener(oListener2) 89 'out.log("fire event") 90 fireEvent() 91 wait(500) 92 out.log("Listener1 called: "+bL1called) 93 out.log("Listener2 called: "+bL2called) 94 if NOT isTransient then 95 bOK = bOK AND bL1called AND bL2called 96 else 97 'out.log("Object is transient, listeners aren't expected to call.") 98 bOK = true 99 End If 100 Test.MethodTested("addEventListener()",bOK) 101 102 103 Test.StartMethod("removeEventListener()") 104 bOK = true 105 bL1called = false 106 bL2called = false 107 'out.log("Removing one listener...") 108 oObj.com_sun_star_accessibility_XAccessibleEventBroadcaster_removeEventListener(oListener1) 109 'out.log("fire event") 110 fireEvent() 111 wait(500) 112 out.log("Listener1 called: "+bL1called) 113 out.log("Listener2 called: "+bL2called) 114 if NOT isTransient then 115 bOK = bOK AND NOT bL1called AND bL2called 116 else 117 'out.log("Object is transient, listeners aren't expected to call.") 118 bOK = true 119 End If 120 Test.MethodTested("removeEventListener()",bOK) 121 122 ' Removing the second listener... 123 oObj.com_sun_star_accessibility_XAccessibleEventBroadcaster_removeEventListener(oListener2) 124 125 126Exit Sub 127ErrHndl: 128 Test.Exception() 129 bOK = false 130 resume next 131End Sub 132 133Sub EL1_notifyEvent(ev As Variant) 134 'out.log("CallBack for Listener1 notifyEvent was called.") 135 bL1called = true 136End Sub 137 138Sub EL1_disposing() 139End Sub 140 141Sub EL2_notifyEvent(ev As Variant) 142 'out.log("CallBack for Listener2 notifyEvent was called.") 143 bL2called = true 144End Sub 145 146Sub EL2_disposing() 147End Sub 148 149</script:module>