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