1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package mod._toolkit; 24 25 import com.sun.star.awt.XControl; 26 import com.sun.star.awt.XControlModel; 27 import com.sun.star.awt.XDevice; 28 import com.sun.star.awt.XGraphics; 29 import com.sun.star.awt.XTextComponent; 30 import com.sun.star.awt.XToolkit; 31 import com.sun.star.awt.XWindow; 32 import com.sun.star.awt.XWindowPeer; 33 import com.sun.star.beans.XPropertySet; 34 import com.sun.star.drawing.XControlShape; 35 import com.sun.star.drawing.XShape; 36 import com.sun.star.lang.XMultiServiceFactory; 37 import com.sun.star.text.XTextDocument; 38 import com.sun.star.uno.UnoRuntime; 39 import com.sun.star.uno.XInterface; 40 import com.sun.star.view.XControlAccess; 41 42 import java.io.PrintWriter; 43 44 import lib.StatusException; 45 import lib.TestCase; 46 import lib.TestEnvironment; 47 import lib.TestParameters; 48 49 import util.FormTools; 50 import util.SOfficeFactory; 51 import util.WriterTools; 52 import util.utils; 53 54 55 public class UnoControlFormattedField extends TestCase { 56 private static XTextDocument xTextDoc; 57 initialize(TestParameters Param, PrintWriter log)58 protected void initialize(TestParameters Param, PrintWriter log) { 59 SOfficeFactory SOF = SOfficeFactory.getFactory( 60 (XMultiServiceFactory) Param.getMSF()); 61 62 try { 63 log.println("creating a textdocument"); 64 xTextDoc = SOF.createTextDoc(null); 65 } catch (com.sun.star.uno.Exception e) { 66 // Some exception occured.FAILED 67 e.printStackTrace(log); 68 throw new StatusException("Couldn't create document", e); 69 } 70 } 71 cleanup(TestParameters tParam, PrintWriter log)72 protected void cleanup(TestParameters tParam, PrintWriter log) { 73 log.println(" disposing xTextDoc "); 74 75 util.DesktopTools.closeDoc(xTextDoc); 76 } 77 createTestEnvironment(TestParameters Param, PrintWriter log)78 protected TestEnvironment createTestEnvironment(TestParameters Param, 79 PrintWriter log) { 80 XInterface oObj = null; 81 XWindowPeer the_win = null; 82 XToolkit the_kit = null; 83 XDevice aDevice = null; 84 XGraphics aGraphic = null; 85 XControl aControl = null; 86 87 //Insert a ControlShape and get the ControlModel 88 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000, 89 4500, 15000, 90 10000, 91 "DatabaseFormattedField", 92 "UnoControlFormattedField"); 93 94 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape); 95 96 XControlModel the_Model = aShape.getControl(); 97 98 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000, 99 4500, 5000, 10000, 100 "TextField"); 101 102 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2); 103 104 XControlModel the_Model2 = aShape2.getControl(); 105 106 XPropertySet xPS = (XPropertySet) UnoRuntime.queryInterface( 107 XPropertySet.class, the_Model); 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 123 xPS.setPropertyValue("Spin", new Boolean(true)); 124 } catch (com.sun.star.uno.Exception e) { 125 log.println("Couldn't get EditControl"); 126 e.printStackTrace(log); 127 throw new StatusException("Couldn't get EditControl", e); 128 } 129 130 log.println("creating a new environment for UnoControlEdit object"); 131 132 TestEnvironment tEnv = new TestEnvironment(oObj); 133 134 135 //Adding ObjRelation for XView 136 tEnv.addObjRelation("GRAPHICS", aGraphic); 137 138 139 //Adding ObjRelation for XControl 140 tEnv.addObjRelation("CONTEXT", xTextDoc); 141 tEnv.addObjRelation("WINPEER", the_win); 142 tEnv.addObjRelation("TOOLKIT", the_kit); 143 tEnv.addObjRelation("MODEL", the_Model); 144 145 XWindow forObjRel = (XWindow) UnoRuntime.queryInterface(XWindow.class, 146 aControl); 147 148 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel); 149 tEnv.addObjRelation("XWindow.ControlShape", aShape); 150 151 // Adding relation for XTextListener 152 ifc.awt._XTextListener.TestTextListener listener = 153 new ifc.awt._XTextListener.TestTextListener(); 154 XTextComponent textComp = (XTextComponent) UnoRuntime.queryInterface( 155 XTextComponent.class, oObj); 156 textComp.addTextListener(listener); 157 tEnv.addObjRelation("TestTextListener", listener); 158 159 log.println("ImplementationName: " + utils.getImplName(oObj)); 160 161 return tEnv; 162 } // finish method getTestEnvironment 163 } 164