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._toolkit; 28 29 import com.sun.star.awt.XControl; 30 import com.sun.star.awt.XControlModel; 31 import com.sun.star.awt.XDevice; 32 import com.sun.star.awt.XGraphics; 33 import com.sun.star.awt.XTextComponent; 34 import com.sun.star.awt.XToolkit; 35 import com.sun.star.awt.XWindow; 36 import com.sun.star.awt.XWindowPeer; 37 import com.sun.star.beans.XPropertySet; 38 import com.sun.star.drawing.XControlShape; 39 import com.sun.star.drawing.XShape; 40 import com.sun.star.lang.XMultiServiceFactory; 41 import com.sun.star.text.XTextDocument; 42 import com.sun.star.uno.UnoRuntime; 43 import com.sun.star.uno.XInterface; 44 import com.sun.star.view.XControlAccess; 45 46 import java.io.PrintWriter; 47 48 import lib.StatusException; 49 import lib.TestCase; 50 import lib.TestEnvironment; 51 import lib.TestParameters; 52 53 import util.FormTools; 54 import util.SOfficeFactory; 55 import util.WriterTools; 56 import util.utils; 57 58 59 public class UnoControlFormattedField extends TestCase { 60 private static XTextDocument xTextDoc; 61 62 protected void initialize(TestParameters Param, PrintWriter log) { 63 SOfficeFactory SOF = SOfficeFactory.getFactory( 64 (XMultiServiceFactory) Param.getMSF()); 65 66 try { 67 log.println("creating a textdocument"); 68 xTextDoc = SOF.createTextDoc(null); 69 } catch (com.sun.star.uno.Exception e) { 70 // Some exception occures.FAILED 71 e.printStackTrace(log); 72 throw new StatusException("Couldn't create document", e); 73 } 74 } 75 76 protected void cleanup(TestParameters tParam, PrintWriter log) { 77 log.println(" disposing xTextDoc "); 78 79 util.DesktopTools.closeDoc(xTextDoc); 80 } 81 82 protected TestEnvironment createTestEnvironment(TestParameters Param, 83 PrintWriter log) { 84 XInterface oObj = null; 85 XWindowPeer the_win = null; 86 XToolkit the_kit = null; 87 XDevice aDevice = null; 88 XGraphics aGraphic = null; 89 XControl aControl = null; 90 91 //Insert a ControlShape and get the ControlModel 92 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000, 93 4500, 15000, 94 10000, 95 "DatabaseFormattedField", 96 "UnoControlFormattedField"); 97 98 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape); 99 100 XControlModel the_Model = aShape.getControl(); 101 102 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000, 103 4500, 5000, 10000, 104 "TextField"); 105 106 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2); 107 108 XControlModel the_Model2 = aShape2.getControl(); 109 110 XPropertySet xPS = (XPropertySet) UnoRuntime.queryInterface( 111 XPropertySet.class, the_Model); 112 113 //Try to query XControlAccess 114 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface( 115 XControlAccess.class, 116 xTextDoc.getCurrentController()); 117 118 //get the EditControl for the needed Object relations 119 try { 120 oObj = the_access.getControl(the_Model); 121 aControl = the_access.getControl(the_Model2); 122 the_win = the_access.getControl(the_Model).getPeer(); 123 the_kit = the_win.getToolkit(); 124 aDevice = the_kit.createScreenCompatibleDevice(200, 200); 125 aGraphic = aDevice.createGraphics(); 126 127 xPS.setPropertyValue("Spin", new Boolean(true)); 128 } catch (com.sun.star.uno.Exception e) { 129 log.println("Couldn't get EditControl"); 130 e.printStackTrace(log); 131 throw new StatusException("Couldn't get EditControl", e); 132 } 133 134 log.println("creating a new environment for UnoControlEdit object"); 135 136 TestEnvironment tEnv = new TestEnvironment(oObj); 137 138 139 //Adding ObjRelation for XView 140 tEnv.addObjRelation("GRAPHICS", aGraphic); 141 142 143 //Adding ObjRelation for XControl 144 tEnv.addObjRelation("CONTEXT", xTextDoc); 145 tEnv.addObjRelation("WINPEER", the_win); 146 tEnv.addObjRelation("TOOLKIT", the_kit); 147 tEnv.addObjRelation("MODEL", the_Model); 148 149 XWindow forObjRel = (XWindow) UnoRuntime.queryInterface(XWindow.class, 150 aControl); 151 152 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel); 153 tEnv.addObjRelation("XWindow.ControlShape", aShape); 154 155 // Adding relation for XTextListener 156 ifc.awt._XTextListener.TestTextListener listener = 157 new ifc.awt._XTextListener.TestTextListener(); 158 XTextComponent textComp = (XTextComponent) UnoRuntime.queryInterface( 159 XTextComponent.class, oObj); 160 textComp.addTextListener(listener); 161 tEnv.addObjRelation("TestTextListener", listener); 162 163 log.println("ImplementationName: " + utils.getImplName(oObj)); 164 165 return tEnv; 166 } // finish method getTestEnvironment 167 } 168