1ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5ef39d40dSAndrew Rist * distributed with this work for additional information 6ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10ef39d40dSAndrew Rist * 11ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12ef39d40dSAndrew Rist * 13ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17ef39d40dSAndrew Rist * specific language governing permissions and limitations 18ef39d40dSAndrew Rist * under the License. 19ef39d40dSAndrew Rist * 20ef39d40dSAndrew Rist *************************************************************/ 21ef39d40dSAndrew Rist 22ef39d40dSAndrew Rist 23cdf0e10cSrcweir package mod._toolkit; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.awt.PosSize; 26cdf0e10cSrcweir import com.sun.star.awt.Rectangle; 27cdf0e10cSrcweir import com.sun.star.awt.XControl; 28cdf0e10cSrcweir import com.sun.star.awt.XControlContainer; 29cdf0e10cSrcweir import com.sun.star.awt.XControlModel; 30cdf0e10cSrcweir import com.sun.star.awt.XDevice; 31cdf0e10cSrcweir import com.sun.star.awt.XGraphics; 32cdf0e10cSrcweir import com.sun.star.awt.XToolkit; 33cdf0e10cSrcweir import com.sun.star.awt.XWindow; 34cdf0e10cSrcweir import com.sun.star.awt.XWindowPeer; 35cdf0e10cSrcweir import com.sun.star.drawing.XControlShape; 36cdf0e10cSrcweir import com.sun.star.drawing.XShape; 37cdf0e10cSrcweir import com.sun.star.frame.XController; 38cdf0e10cSrcweir import com.sun.star.frame.XFrame; 39cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 40cdf0e10cSrcweir import com.sun.star.text.XTextDocument; 41cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 42cdf0e10cSrcweir import com.sun.star.uno.XInterface; 43cdf0e10cSrcweir import com.sun.star.view.XControlAccess; 44cdf0e10cSrcweir 45cdf0e10cSrcweir import java.io.PrintWriter; 46cdf0e10cSrcweir 47cdf0e10cSrcweir import lib.StatusException; 48cdf0e10cSrcweir import lib.TestCase; 49cdf0e10cSrcweir import lib.TestEnvironment; 50cdf0e10cSrcweir import lib.TestParameters; 51cdf0e10cSrcweir 52cdf0e10cSrcweir import util.FormTools; 53cdf0e10cSrcweir import util.WriterTools; 54cdf0e10cSrcweir import util.utils; 55cdf0e10cSrcweir 56cdf0e10cSrcweir 57cdf0e10cSrcweir public class UnoControlContainer extends TestCase { 58cdf0e10cSrcweir private static XTextDocument xTextDoc; 59cdf0e10cSrcweir private static XTextDocument xTD2; 60cdf0e10cSrcweir private static XControl xCtrl; 61cdf0e10cSrcweir private static XControl xCtrl1; 62cdf0e10cSrcweir private static XControl xCtrl2; 63cdf0e10cSrcweir initialize(TestParameters param, PrintWriter log)64cdf0e10cSrcweir protected void initialize(TestParameters param, PrintWriter log) { 65cdf0e10cSrcweir try { 66cdf0e10cSrcweir log.println("creating a textdocument"); 67cdf0e10cSrcweir xTD2 = WriterTools.createTextDoc( 68cdf0e10cSrcweir (XMultiServiceFactory) param.getMSF()); 69cdf0e10cSrcweir xTextDoc = WriterTools.createTextDoc( 70cdf0e10cSrcweir (XMultiServiceFactory) param.getMSF()); 71cdf0e10cSrcweir } catch (Exception e) { 72*30acf5e8Spfg // Some exception occured.FAILED 73cdf0e10cSrcweir e.printStackTrace(log); 74cdf0e10cSrcweir throw new StatusException("Couldn't create document", e); 75cdf0e10cSrcweir } 76cdf0e10cSrcweir } 77cdf0e10cSrcweir cleanup(TestParameters tParam, PrintWriter log)78cdf0e10cSrcweir protected void cleanup(TestParameters tParam, PrintWriter log) { 79cdf0e10cSrcweir log.println(" disposing xTextDoc "); 80cdf0e10cSrcweir 81cdf0e10cSrcweir util.DesktopTools.closeDoc(xTextDoc); 82cdf0e10cSrcweir util.DesktopTools.closeDoc(xTD2); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir createTestEnvironment(TestParameters param, PrintWriter log)85cdf0e10cSrcweir public TestEnvironment createTestEnvironment(TestParameters param, 86cdf0e10cSrcweir PrintWriter log) { 87cdf0e10cSrcweir // create Object Relations ------------------------------------------- 88cdf0e10cSrcweir XInterface oObj = null; 89cdf0e10cSrcweir XControlShape shape = null; 90cdf0e10cSrcweir XControlModel model = null; 91cdf0e10cSrcweir XControlAccess access = null; 92cdf0e10cSrcweir XWindow anotherWindow = null; 93cdf0e10cSrcweir 94cdf0e10cSrcweir // for XControl 95cdf0e10cSrcweir XWindowPeer the_win = null; 96cdf0e10cSrcweir XToolkit the_kit = null; 97cdf0e10cSrcweir 98cdf0e10cSrcweir XControlContainer ctrlCont = null; 99cdf0e10cSrcweir 100cdf0e10cSrcweir XGraphics aGraphic = null; 101cdf0e10cSrcweir 102cdf0e10cSrcweir 103cdf0e10cSrcweir // create 3 XControls 104cdf0e10cSrcweir // create first XControl 105cdf0e10cSrcweir shape = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000, 106cdf0e10cSrcweir 10000, "TextField"); 107cdf0e10cSrcweir WriterTools.getDrawPage(xTextDoc).add((XShape) shape); 108cdf0e10cSrcweir model = shape.getControl(); 109cdf0e10cSrcweir access = (XControlAccess) UnoRuntime.queryInterface( 110cdf0e10cSrcweir XControlAccess.class, xTextDoc.getCurrentController()); 111cdf0e10cSrcweir 112cdf0e10cSrcweir try { 113cdf0e10cSrcweir xCtrl = access.getControl(model); 114cdf0e10cSrcweir } catch (Exception e) { 115cdf0e10cSrcweir e.printStackTrace(log); 116cdf0e10cSrcweir throw new StatusException("Couldn't create XControl", e); 117cdf0e10cSrcweir } 118cdf0e10cSrcweir 119cdf0e10cSrcweir 120cdf0e10cSrcweir // create second XControl 121cdf0e10cSrcweir shape = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000, 122cdf0e10cSrcweir 10000, "TextField"); 123cdf0e10cSrcweir WriterTools.getDrawPage(xTextDoc).add((XShape) shape); 124cdf0e10cSrcweir model = shape.getControl(); 125cdf0e10cSrcweir access = (XControlAccess) UnoRuntime.queryInterface( 126cdf0e10cSrcweir XControlAccess.class, xTextDoc.getCurrentController()); 127cdf0e10cSrcweir 128cdf0e10cSrcweir try { 129cdf0e10cSrcweir xCtrl1 = access.getControl(model); 130cdf0e10cSrcweir } catch (Exception e) { 131cdf0e10cSrcweir e.printStackTrace(log); 132cdf0e10cSrcweir throw new StatusException("Couldn't create XControl", e); 133cdf0e10cSrcweir } 134cdf0e10cSrcweir 135cdf0e10cSrcweir 136cdf0e10cSrcweir // create third XControl 137cdf0e10cSrcweir shape = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000, 138cdf0e10cSrcweir 10000, "CommandButton"); 139cdf0e10cSrcweir WriterTools.getDrawPage(xTextDoc).add((XShape) shape); 140cdf0e10cSrcweir model = shape.getControl(); 141cdf0e10cSrcweir access = (XControlAccess) UnoRuntime.queryInterface( 142cdf0e10cSrcweir XControlAccess.class, xTextDoc.getCurrentController()); 143cdf0e10cSrcweir 144cdf0e10cSrcweir try { 145cdf0e10cSrcweir xCtrl2 = access.getControl(model); 146cdf0e10cSrcweir } catch (Exception e) { 147cdf0e10cSrcweir e.printStackTrace(log); 148cdf0e10cSrcweir throw new StatusException("Couldn't create XControl", e); 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151cdf0e10cSrcweir // create XToolkit, XWindowPeer, XDevice 152cdf0e10cSrcweir //Insert a ControlShape and get the ControlModel 153cdf0e10cSrcweir XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000, 154cdf0e10cSrcweir 4500, 15000, 155cdf0e10cSrcweir 10000, 156cdf0e10cSrcweir "CommandButton", 157cdf0e10cSrcweir "UnoControlButton"); 158cdf0e10cSrcweir 159cdf0e10cSrcweir WriterTools.getDrawPage(xTD2).add((XShape) aShape); 160cdf0e10cSrcweir 161cdf0e10cSrcweir XControlModel the_Model = aShape.getControl(); 162cdf0e10cSrcweir 163cdf0e10cSrcweir //Try to query XControlAccess 164cdf0e10cSrcweir XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface( 165cdf0e10cSrcweir XControlAccess.class, 166cdf0e10cSrcweir xTD2.getCurrentController()); 167cdf0e10cSrcweir 168cdf0e10cSrcweir //get the ButtonControl for the needed Object relations 169cdf0e10cSrcweir try { 170cdf0e10cSrcweir the_win = the_access.getControl(the_Model).getPeer(); 171cdf0e10cSrcweir the_kit = the_win.getToolkit(); 172cdf0e10cSrcweir 173cdf0e10cSrcweir XDevice aDevice = the_kit.createScreenCompatibleDevice(200, 200); 174cdf0e10cSrcweir aGraphic = aDevice.createGraphics(); 175cdf0e10cSrcweir } catch (Exception e) { 176cdf0e10cSrcweir log.println("Couldn't get ButtonControl"); 177cdf0e10cSrcweir e.printStackTrace(log); 178cdf0e10cSrcweir throw new StatusException("Couldn't get ButtonControl", e); 179cdf0e10cSrcweir } 180cdf0e10cSrcweir 181cdf0e10cSrcweir try { 182cdf0e10cSrcweir XController aController = xTD2.getCurrentController(); 183cdf0e10cSrcweir XFrame aFrame = aController.getFrame(); 184cdf0e10cSrcweir anotherWindow = aFrame.getComponentWindow(); 185cdf0e10cSrcweir } catch (Exception e) { 186cdf0e10cSrcweir e.printStackTrace(log); 187cdf0e10cSrcweir throw new StatusException("Couldn't create XWindow", e); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir 190cdf0e10cSrcweir // finished create Object Relations ----------------------------------- 191cdf0e10cSrcweir // create the UnoControlContainer 192cdf0e10cSrcweir try { 193cdf0e10cSrcweir oObj = (XInterface) ((XMultiServiceFactory) param.getMSF()).createInstance( 194cdf0e10cSrcweir "com.sun.star.awt.UnoControlContainer"); 195cdf0e10cSrcweir 196cdf0e10cSrcweir XControl xCtrl = (XControl) UnoRuntime.queryInterface( 197cdf0e10cSrcweir XControl.class, oObj); 198cdf0e10cSrcweir xCtrl.setModel(the_Model); 199cdf0e10cSrcweir 200cdf0e10cSrcweir ctrlCont = (XControlContainer) UnoRuntime.queryInterface( 201cdf0e10cSrcweir XControlContainer.class, oObj); 202cdf0e10cSrcweir ctrlCont.addControl("jupp", access.getControl(aShape.getControl())); 203cdf0e10cSrcweir } catch (Exception e) { 204cdf0e10cSrcweir e.printStackTrace(log); 205cdf0e10cSrcweir throw new StatusException("Couldn't create UnoControlContainer", e); 206cdf0e10cSrcweir } 207cdf0e10cSrcweir 208cdf0e10cSrcweir log.println( 209cdf0e10cSrcweir "creating a new environment for UnoControlContainer object"); 210cdf0e10cSrcweir 211cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment(oObj); 212cdf0e10cSrcweir 213cdf0e10cSrcweir XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, oObj); 214cdf0e10cSrcweir Rectangle ps = xWindow.getPosSize(); 215cdf0e10cSrcweir xWindow.setPosSize(ps.X+10, ps.Y+10, ps.Width+10, ps.Height+10, PosSize.POSSIZE); 216cdf0e10cSrcweir 217cdf0e10cSrcweir String objName = "UnoControlContainer"; 218cdf0e10cSrcweir tEnv.addObjRelation("OBJNAME", "toolkit." + objName); 219cdf0e10cSrcweir 220cdf0e10cSrcweir 221cdf0e10cSrcweir // Object relation for XContainer 222cdf0e10cSrcweir tEnv.addObjRelation("XContainer.Container", ctrlCont); 223cdf0e10cSrcweir tEnv.addObjRelation("INSTANCE", xCtrl); 224cdf0e10cSrcweir 225cdf0e10cSrcweir 226cdf0e10cSrcweir //Adding ObjRelation for XView 227cdf0e10cSrcweir tEnv.addObjRelation("GRAPHICS", aGraphic); 228cdf0e10cSrcweir 229cdf0e10cSrcweir 230cdf0e10cSrcweir // Object Relation for XControlContainer 231cdf0e10cSrcweir tEnv.addObjRelation("CONTROL1", xCtrl1); 232cdf0e10cSrcweir tEnv.addObjRelation("CONTROL2", xCtrl2); 233cdf0e10cSrcweir 234cdf0e10cSrcweir 235cdf0e10cSrcweir // Object Relation for XControl 236cdf0e10cSrcweir tEnv.addObjRelation("CONTEXT", xTD2); 237cdf0e10cSrcweir tEnv.addObjRelation("WINPEER", the_win); 238cdf0e10cSrcweir tEnv.addObjRelation("TOOLKIT", the_kit); 239cdf0e10cSrcweir tEnv.addObjRelation("MODEL", the_Model); 240cdf0e10cSrcweir 241cdf0e10cSrcweir 242cdf0e10cSrcweir // Object Relation for XWindow 243cdf0e10cSrcweir tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow); 244cdf0e10cSrcweir System.out.println("ImplementationName: " + utils.getImplName(oObj)); 245cdf0e10cSrcweir 246cdf0e10cSrcweir return tEnv; 247cdf0e10cSrcweir } 248cdf0e10cSrcweir } 249