1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package mod._svx; 29 30 import java.io.PrintWriter; 31 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.AccessibilityTools; 37 import util.DrawTools; 38 import util.SOfficeFactory; 39 import util.utils; 40 41 import com.sun.star.accessibility.AccessibleRole; 42 import com.sun.star.accessibility.XAccessible; 43 import com.sun.star.awt.XExtendedToolkit; 44 import com.sun.star.awt.XWindow; 45 import com.sun.star.beans.XPropertySet; 46 import com.sun.star.drawing.XShape; 47 import com.sun.star.frame.XController; 48 import com.sun.star.frame.XDispatch; 49 import com.sun.star.frame.XDispatchProvider; 50 import com.sun.star.frame.XModel; 51 import com.sun.star.lang.XComponent; 52 import com.sun.star.lang.XMultiServiceFactory; 53 import com.sun.star.uno.UnoRuntime; 54 import com.sun.star.uno.XInterface; 55 import com.sun.star.util.URL; 56 import com.sun.star.util.XURLTransformer; 57 import com.sun.star.view.XSelectionSupplier; 58 59 60 /** 61 * 62 * @author sw93809 63 * @version 64 */ 65 public class SvxGraphCtrlAccessibleContext extends TestCase{ 66 67 static XComponent xDrawDoc = null; 68 69 /** 70 * Called to create an instance of <code>TestEnvironment</code> 71 * with an object to test and related objects. 72 * Switchs the document to Print Preview mode. 73 * Obtains accissible object for the page view. 74 * 75 * @param tParam test parameters 76 * @param log writer to log information while testing 77 * 78 * @see TestEnvironment 79 * @see #getTestEnvironment() 80 */ 81 82 protected TestEnvironment createTestEnvironment( 83 TestParameters Param, PrintWriter log) { 84 85 XInterface oObj = null; 86 87 88 XModel aModel = (XModel) 89 UnoRuntime.queryInterface(XModel.class, xDrawDoc); 90 91 XController xController = aModel.getCurrentController(); 92 93 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 94 final XShape oShape = SOF.createShape(xDrawDoc, 95 5000,5000,1500,1000,"GraphicObject"); 96 97 98 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape); 99 100 XPropertySet shapeProps = (XPropertySet) 101 UnoRuntime.queryInterface(XPropertySet.class, oShape); 102 103 String url = util.utils.getFullTestURL("space-metal.jpg"); 104 105 log.println("Inserting Graphic: "+url); 106 107 try { 108 shapeProps.setPropertyValue("GraphicURL", url); 109 } catch (com.sun.star.beans.UnknownPropertyException upe) { 110 log.println("Property GraphicURL is unknown"); 111 } catch (com.sun.star.beans.PropertyVetoException pve) { 112 log.println("Property GraphicURL is read only"); 113 } catch (com.sun.star.lang.IllegalArgumentException iae) { 114 log.println("Property GraphicURL tried to set to illegal argument"); 115 } catch (com.sun.star.lang.WrappedTargetException wte) { 116 log.println("Wrapped Target Exception was thrown while setting Property GraphicURL"); 117 } 118 119 120 //Opening ImageMapDialog 121 try { 122 String aSlotID = "slot:10371"; 123 XDispatchProvider xDispProv = (XDispatchProvider) 124 UnoRuntime.queryInterface( XDispatchProvider.class, xController ); 125 XURLTransformer xParser = (com.sun.star.util.XURLTransformer) 126 UnoRuntime.queryInterface(XURLTransformer.class, 127 ((XMultiServiceFactory)Param.getMSF()).createInstance("com.sun.star.util.URLTransformer")); 128 // Because it's an in/out parameter we must use an array of URL objects. 129 URL[] aParseURL = new URL[1]; 130 aParseURL[0] = new URL(); 131 aParseURL[0].Complete = aSlotID; 132 xParser.parseStrict(aParseURL); 133 URL aURL = aParseURL[0]; 134 XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0); 135 if( xDispatcher != null ) 136 xDispatcher.dispatch( aURL, null ); 137 utils.shortWait(Param.getInt(util.PropertyName.SHORT_WAIT)); 138 } catch (com.sun.star.uno.Exception e) { 139 log.println("Couldn't change mode"); 140 } 141 142 143 try { 144 oObj = (XInterface) ((XMultiServiceFactory)Param.getMSF()).createInstance 145 ("com.sun.star.awt.Toolkit") ; 146 } catch (com.sun.star.uno.Exception e) { 147 log.println("Couldn't get toolkit"); 148 e.printStackTrace(log); 149 throw new StatusException("Couldn't get toolkit", e ); 150 } 151 152 XExtendedToolkit tk = (XExtendedToolkit) 153 UnoRuntime.queryInterface(XExtendedToolkit.class,oObj); 154 155 156 AccessibilityTools at = new AccessibilityTools(); 157 158 XWindow xWindow = (XWindow) 159 UnoRuntime.queryInterface(XWindow.class,tk.getActiveTopWindow()); 160 161 XAccessible xRoot = at.getAccessibleObject(xWindow); 162 163 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 164 165 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL); 166 167 log.println("ImplementationName " + utils.getImplName(oObj)); 168 169 TestEnvironment tEnv = new TestEnvironment(oObj); 170 171 //selecting the inserted shape 172 final XSelectionSupplier SelSupp = (XSelectionSupplier) 173 UnoRuntime.queryInterface(XSelectionSupplier.class,xController); 174 175 tEnv.addObjRelation("EventProducer", 176 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 177 public void fireEvent() { 178 try { 179 SelSupp.select(oShape); 180 } catch (com.sun.star.lang.IllegalArgumentException iae) { 181 System.out.println("Couldn't select shape"); 182 } 183 } 184 }); 185 186 return tEnv; 187 188 } 189 190 /** 191 * Called while disposing a <code>TestEnvironment</code>. 192 * Disposes text document. 193 * @param tParam test parameters 194 * @param tEnv the environment to cleanup 195 * @param log writer to log information while testing 196 */ 197 protected void cleanup( TestParameters Param, PrintWriter log) { 198 199 XModel aModel = (XModel) 200 UnoRuntime.queryInterface(XModel.class, xDrawDoc); 201 202 XController xController = aModel.getCurrentController(); 203 204 //Closing ImageMapDialog 205 try { 206 String aSlotID = "slot:10371"; 207 XDispatchProvider xDispProv = (XDispatchProvider) 208 UnoRuntime.queryInterface( XDispatchProvider.class, xController ); 209 XURLTransformer xParser = (com.sun.star.util.XURLTransformer) 210 UnoRuntime.queryInterface(XURLTransformer.class, 211 ((XMultiServiceFactory)Param.getMSF()).createInstance("com.sun.star.util.URLTransformer")); 212 // Because it's an in/out parameter we must use an array of URL objects. 213 URL[] aParseURL = new URL[1]; 214 aParseURL[0] = new URL(); 215 aParseURL[0].Complete = aSlotID; 216 xParser.parseStrict(aParseURL); 217 URL aURL = aParseURL[0]; 218 XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0); 219 if( xDispatcher != null ) 220 xDispatcher.dispatch( aURL, null ); 221 } catch (com.sun.star.uno.Exception e) { 222 log.println("Couldn't change mode"); 223 } 224 log.println( " disposing xDrawDoc " ); 225 util.DesktopTools.closeDoc(xDrawDoc); 226 } 227 228 /** 229 * Called while the <code>TestCase</code> initialization. In the 230 * implementation does nothing. Subclasses can override to initialize 231 * objects shared among all <code>TestEnvironment</code>s. 232 * 233 * @param tParam test parameters 234 * @param log writer to log information while testing 235 * 236 * @see #initializeTestCase() 237 */ 238 protected void initialize(TestParameters Param, PrintWriter log) { 239 // get a soffice factory object 240 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 241 242 try { 243 log.println("creating a draw document"); 244 xDrawDoc = SOF.createDrawDoc(null); 245 } catch (com.sun.star.uno.Exception e) { 246 e.printStackTrace( log ); 247 throw new StatusException( "Couldn't create document ", e ); 248 } 249 } 250 251 } 252