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._forms; 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.FormTools; 36 import util.SOfficeFactory; 37 import util.WriterTools; 38 39 import com.sun.star.awt.XControl; 40 import com.sun.star.awt.XControlModel; 41 import com.sun.star.awt.XDevice; 42 import com.sun.star.awt.XGraphics; 43 import com.sun.star.awt.XTextComponent; 44 import com.sun.star.awt.XToolkit; 45 import com.sun.star.awt.XWindow; 46 import com.sun.star.awt.XWindowPeer; 47 import com.sun.star.drawing.XControlShape; 48 import com.sun.star.drawing.XShape; 49 import com.sun.star.lang.XMultiServiceFactory; 50 import com.sun.star.text.XTextDocument; 51 import com.sun.star.uno.UnoRuntime; 52 import com.sun.star.uno.XInterface; 53 import com.sun.star.util.XCloseable; 54 import com.sun.star.view.XControlAccess; 55 56 57 /** 58 * Test for object which is represented by default controller 59 * of the <code>com.sun.star.form.component.TextField</code> 60 * component. <p> 61 * 62 * Object implements the following interfaces : 63 * <ul> 64 * <li> <code>com::sun::star::awt::XView</code></li> 65 * <li> <code>com::sun::star::form::XBoundControl</code></li> 66 * <li> <code>com::sun::star::awt::XControl</code></li> 67 * <li> <code>com::sun::star::awt::XTextComponent</code></li> 68 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li> 69 * <li> <code>com::sun::star::awt::XTextListener</code></li> 70 * <li> <code>com::sun::star::form::XChangeBroadcaster</code></li> 71 * <li> <code>com::sun::star::awt::XWindow</code></li> 72 * <li> <code>com::sun::star::lang::XComponent</code></li> 73 * <li> <code>com::sun::star::awt::XTextLayoutConstrains</code></li> 74 * <li> <code>com::sun::star::lang::XEventListener</code></li> 75 * </ul> <p> 76 * This object test <b> is NOT </b> designed to be run in several 77 * threads concurently. 78 * 79 * @see com.sun.star.awt.XView 80 * @see com.sun.star.form.XBoundControl 81 * @see com.sun.star.awt.XControl 82 * @see com.sun.star.awt.XTextComponent 83 * @see com.sun.star.awt.XLayoutConstrains 84 * @see com.sun.star.awt.XTextListener 85 * @see com.sun.star.form.XChangeBroadcaster 86 * @see com.sun.star.awt.XWindow 87 * @see com.sun.star.lang.XComponent 88 * @see com.sun.star.awt.XTextLayoutConstrains 89 * @see com.sun.star.lang.XEventListener 90 * @see ifc.awt._XView 91 * @see ifc.form._XBoundControl 92 * @see ifc.awt._XControl 93 * @see ifc.awt._XTextComponent 94 * @see ifc.awt._XLayoutConstrains 95 * @see ifc.awt._XTextListener 96 * @see ifc.form._XChangeBroadcaster 97 * @see ifc.awt._XWindow 98 * @see ifc.lang._XComponent 99 * @see ifc.awt._XTextLayoutConstrains 100 * @see ifc.lang._XEventListener 101 */ 102 public class OEditControl extends TestCase { 103 XTextDocument xTextDoc; 104 105 /** 106 * Creates a new text document. 107 */ 108 protected void initialize(TestParameters Param, PrintWriter log) { 109 SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) Param.getMSF())); 110 111 try { 112 log.println("creating a textdocument"); 113 xTextDoc = SOF.createTextDoc(null); 114 } catch (com.sun.star.uno.Exception e) { 115 // Some exception occures.FAILED 116 e.printStackTrace(log); 117 throw new StatusException("Couldn't create document", e); 118 } 119 } 120 121 /** 122 * Disposes the text document created before 123 */ 124 protected void cleanup(TestParameters tParam, PrintWriter log) { 125 log.println(" disposing xTextDoc "); 126 127 try { 128 XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 129 XCloseable.class, xTextDoc); 130 closer.close(true); 131 } catch (com.sun.star.util.CloseVetoException e) { 132 log.println("couldn't close document"); 133 } catch (com.sun.star.lang.DisposedException e) { 134 log.println("couldn't close document"); 135 } 136 } 137 138 /** 139 * Creates two components and inserts them to the form of 140 * text document. One component 141 * (<code>com.sun.star.form.component.TextField</code>) is created 142 * for testing, another to be passed as relation. Using a controller 143 * of the text document the controller of the first component is 144 * obtained and returned in environment as a test object. <p> 145 * 146 * Object relations created : 147 * <ul> 148 * <li> <code>'GRAPHICS'</code> for 149 * {@link ifc.awt._XView} : a graphics component 150 * created using screen device of the window peer of 151 * the controller tested. </li> 152 * <li> <code>'CONTEXT'</code> for 153 * {@link ifc.awt._XControl} : the text document 154 * where the component is inserted. </li> 155 * <li> <code>'WINPEER'</code> for 156 * {@link ifc.awt._XControl} : Window peer of the 157 * controller tested. </li> 158 * <li> <code>'TOOLKIT'</code> for 159 * {@link ifc.awt._XControl} : toolkit of the component.</li> 160 * <li> <code>'MODEL'</code> for 161 * {@link ifc.awt._XControl} : the model of the controller.</li> 162 * <li> <code>'XWindow.AnotherWindow'</code> for 163 * {@link ifc.awt._XWindow} : the controller of another 164 * component. </li> 165 * <li> <code>'Win1'</code> for 166 * {@link ifc.form.XChangeBroadcaster} : the window (controller) 167 * of the tested component. </li> 168 * <li> <code>'Win2'</code> for 169 * {@link ifc.form.XChangeBroadcaster} : the window (controller) 170 * of another component. </li> 171 * <li> <code>'CONTROL'</code> for 172 * {@link ifc.form.XChangeBroadcaster} : the controller 173 * of another component. </li> 174 * </ul> 175 */ 176 protected TestEnvironment createTestEnvironment(TestParameters Param, 177 PrintWriter log) { 178 XInterface oObj = null; 179 XControl aControl = null; 180 XWindowPeer the_win = null; 181 XToolkit the_kit = null; 182 XDevice aDevice = null; 183 XGraphics aGraphic = null; 184 185 //Insert a ControlShape and get the ControlModel 186 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000, 187 4500, 15000, 10000, 188 "TextField"); 189 190 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape); 191 192 XControlModel the_Model = aShape.getControl(); 193 194 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000, 195 4500, 5000, 10000, 196 "TextField"); 197 198 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2); 199 200 XControlModel the_Model2 = aShape2.getControl(); 201 202 //Try to query XControlAccess 203 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface( 204 XControlAccess.class, 205 xTextDoc.getCurrentController()); 206 207 //now get the OEditControl 208 try { 209 oObj = the_access.getControl(the_Model); 210 aControl = the_access.getControl(the_Model2); 211 the_win = the_access.getControl(the_Model).getPeer(); 212 the_kit = the_win.getToolkit(); 213 aDevice = the_kit.createScreenCompatibleDevice(200, 200); 214 aGraphic = aDevice.createGraphics(); 215 } catch (com.sun.star.container.NoSuchElementException e) { 216 log.println("Couldn't get OEditControl"); 217 e.printStackTrace(log); 218 throw new StatusException("Couldn't get OEditControl", e); 219 } 220 221 log.println("creating a new environment for OEditControl object"); 222 223 TestEnvironment tEnv = new TestEnvironment(oObj); 224 225 226 //Adding ObjRelation for XView 227 tEnv.addObjRelation("GRAPHICS", aGraphic); 228 229 230 //Adding ObjRelation for XControl 231 tEnv.addObjRelation("CONTEXT", xTextDoc); 232 tEnv.addObjRelation("WINPEER", the_win); 233 tEnv.addObjRelation("TOOLKIT", the_kit); 234 tEnv.addObjRelation("MODEL", the_Model); 235 236 // relations for XChangeBroadcaster 237 XWindow forObjRel = (XWindow) UnoRuntime.queryInterface(XWindow.class, 238 aControl); 239 240 tEnv.addObjRelation("Win1", 241 (XWindow) UnoRuntime.queryInterface(XWindow.class, 242 oObj)); 243 tEnv.addObjRelation("Win2", forObjRel); 244 tEnv.addObjRelation("CONTROL", aControl); 245 246 247 // relation for XWindow 248 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel); 249 tEnv.addObjRelation("XWindow.ControlShape", aShape); 250 251 // Adding relation for XTextListener 252 ifc.awt._XTextListener.TestTextListener listener = 253 new ifc.awt._XTextListener.TestTextListener(); 254 XTextComponent textComp = (XTextComponent) UnoRuntime.queryInterface( 255 XTextComponent.class, oObj); 256 textComp.addTextListener(listener); 257 tEnv.addObjRelation("TestTextListener", listener); 258 259 return tEnv; 260 } // finish method getTestEnvironment 261 } // finish class OEditControl 262