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 package mod._sw; 28 29 import java.io.PrintWriter; 30 31 import lib.StatusException; 32 import lib.TestCase; 33 import lib.TestEnvironment; 34 import lib.TestParameters; 35 import util.AccessibilityTools; 36 import util.SOfficeFactory; 37 import util.WriterTools; 38 import util.utils; 39 40 import com.sun.star.accessibility.AccessibleRole; 41 import com.sun.star.accessibility.XAccessible; 42 import com.sun.star.awt.XWindow; 43 import com.sun.star.beans.XPropertySet; 44 import com.sun.star.frame.XController; 45 import com.sun.star.frame.XModel; 46 import com.sun.star.lang.XMultiServiceFactory; 47 import com.sun.star.text.TextContentAnchorType; 48 import com.sun.star.text.XText; 49 import com.sun.star.text.XTextContent; 50 import com.sun.star.text.XTextCursor; 51 import com.sun.star.text.XTextDocument; 52 import com.sun.star.text.XTextFrame; 53 import com.sun.star.uno.UnoRuntime; 54 import com.sun.star.uno.XInterface; 55 import com.sun.star.view.XViewSettingsSupplier; 56 57 /** 58 * Test of accessible object for the text frame of a text document.<p> 59 * Object implements the following interfaces : 60 * <ul> 61 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li> 62 * </ul> 63 * @see com.sun.star.accessibility.XAccessible 64 */ 65 public class SwAccessibleTextFrameView extends TestCase { 66 67 XTextDocument xTextDoc = null; 68 69 /** 70 * Called to create an instance of <code>TestEnvironment</code> 71 * with an object to test and related objects. 72 * Creates a frame and inserts it into document. 73 * Obtains accessible object for the inserted text frame. 74 * 75 * @param tParam test parameters 76 * @param log writer to log information while testing 77 * 78 * @see TestEnvironment 79 * @see #getTestEnvironment() 80 */ 81 protected TestEnvironment createTestEnvironment( 82 TestParameters Param, PrintWriter log) { 83 84 XInterface oObj = null; 85 XTextFrame oFrame1 = null; 86 XPropertySet oPropSet = null; 87 XText oText = null; 88 XTextCursor oCursor = null; 89 90 // get a soffice factory object 91 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF() ); 92 // creating Frames 93 log.println( "creating Frames" ); 94 try { 95 oFrame1 = SOF.createTextFrame(xTextDoc, 500, 500); 96 oPropSet = (XPropertySet)UnoRuntime.queryInterface( 97 XPropertySet.class, oFrame1 ); 98 oPropSet.setPropertyValue("AnchorType", 99 TextContentAnchorType.AS_CHARACTER); 100 oText = xTextDoc.getText(); 101 oCursor = oText.createTextCursor(); 102 103 log.println( "inserting Frame1" ); 104 XTextContent the_content = (XTextContent) 105 UnoRuntime.queryInterface(XTextContent.class, oFrame1); 106 oText.insertTextContent(oCursor, the_content, true); 107 } catch (Exception e) { 108 e.printStackTrace(log); 109 throw new StatusException("Couldn't insert TextFrame", e); 110 } 111 112 XModel aModel = (XModel) 113 UnoRuntime.queryInterface(XModel.class, xTextDoc); 114 115 AccessibilityTools at = new AccessibilityTools(); 116 117 XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel); 118 XAccessible xRoot = at.getAccessibleObject(xWindow); 119 120 at.getAccessibleObjectForRole(xRoot, AccessibleRole.TEXT_FRAME); 121 122 oObj = at.SearchedContext; 123 124 log.println("ImplementationName " + utils.getImplName(oObj)); 125 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 126 127 TestEnvironment tEnv = new TestEnvironment(oObj); 128 129 XController xController = xTextDoc.getCurrentController(); 130 XViewSettingsSupplier xViewSetSup = (XViewSettingsSupplier) 131 UnoRuntime.queryInterface(XViewSettingsSupplier.class, 132 xController); 133 134 final XPropertySet PropSet = xViewSetSup.getViewSettings(); 135 136 tEnv.addObjRelation("EventProducer", 137 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 138 public void fireEvent() { 139 try { 140 //change zoom value to 15% 141 PropSet.setPropertyValue("ZoomValue", new Short("15")); 142 //and back to 100% 143 PropSet.setPropertyValue("ZoomValue", new Short("100")); 144 } catch ( com.sun.star.lang.WrappedTargetException e ) { 145 146 } catch ( com.sun.star.lang.IllegalArgumentException e ) { 147 148 } catch ( com.sun.star.beans.PropertyVetoException e ) { 149 150 } catch ( com.sun.star.beans.UnknownPropertyException e ) { 151 152 } 153 } 154 }); 155 156 157 return tEnv; 158 159 } 160 161 /** 162 * Called while disposing a <code>TestEnvironment</code>. 163 * Disposes text document. 164 * @param tParam test parameters 165 * @param tEnv the environment to cleanup 166 * @param log writer to log information while testing 167 */ 168 protected void cleanup( TestParameters Param, PrintWriter log) { 169 log.println("dispose text document"); 170 util.DesktopTools.closeDoc(xTextDoc); 171 } 172 173 /** 174 * Called while the <code>TestCase</code> initialization. 175 * Creates a text document. 176 * 177 * @param tParam test parameters 178 * @param log writer to log information while testing 179 * 180 * @see #initializeTestCase() 181 */ 182 protected void initialize(TestParameters Param, PrintWriter log) { 183 log.println( "creating a text document" ); 184 xTextDoc = WriterTools.createTextDoc((XMultiServiceFactory)Param.getMSF()); 185 } 186 } 187 188