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