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.XControlModel; 26 import com.sun.star.awt.XWindow; 27 import com.sun.star.awt.XWindowPeer; 28 import com.sun.star.drawing.XControlShape; 29 import com.sun.star.drawing.XShape; 30 import com.sun.star.frame.XController; 31 import com.sun.star.frame.XModel; 32 import com.sun.star.lang.XMultiServiceFactory; 33 import com.sun.star.text.XTextDocument; 34 import com.sun.star.uno.UnoRuntime; 35 import com.sun.star.uno.XInterface; 36 import com.sun.star.view.XControlAccess; 37 38 import java.io.PrintWriter; 39 40 import lib.StatusException; 41 import lib.TestCase; 42 import lib.TestEnvironment; 43 import lib.TestParameters; 44 45 import util.FormTools; 46 import util.SOfficeFactory; 47 import util.WriterTools; 48 import util.utils; 49 50 51 /** 52 * Test for <code>com.sun.star.awt.Toolkit</code> service. 53 */ 54 public class Toolkit 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 occured.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 util.DesktopTools.closeDoc(xTextDoc); 74 } 75 76 /** 77 * Creating a Testenvironment for the interfaces to be tested. 78 * Creates <code>com.sun.star.awt.Toolkit</code> service. 79 */ createTestEnvironment(TestParameters Param, PrintWriter log)80 public TestEnvironment createTestEnvironment(TestParameters Param, 81 PrintWriter log) 82 throws StatusException { 83 XInterface oObj = null; 84 XWindowPeer the_win = null; 85 XWindow win = null; 86 87 //Insert a ControlShape and get the ControlModel 88 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000, 89 4500, 15000, 10000, 90 "CommandButton"); 91 92 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape); 93 94 XControlModel the_Model = aShape.getControl(); 95 96 //Try to query XControlAccess 97 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface( 98 XControlAccess.class, 99 xTextDoc.getCurrentController()); 100 XController cntrlr = (XController) UnoRuntime.queryInterface( 101 XController.class, 102 xTextDoc.getCurrentController()); 103 104 //now get the toolkit 105 try { 106 win = cntrlr.getFrame().getContainerWindow(); 107 108 109 //win = (XWindow) UnoRuntime.queryInterface(XWindow.class, ctrl) ; 110 the_win = the_access.getControl(the_Model).getPeer(); 111 oObj = (XInterface) ((XMultiServiceFactory) Param.getMSF()).createInstance( 112 "com.sun.star.awt.Toolkit"); 113 } catch (com.sun.star.uno.Exception e) { 114 log.println("Couldn't get toolkit"); 115 e.printStackTrace(log); 116 throw new StatusException("Couldn't get toolkit", e); 117 } 118 119 XModel xModel = (XModel)UnoRuntime.queryInterface(XModel.class, xTextDoc); 120 121 log.println(" creating a new environment for toolkit object"); 122 123 TestEnvironment tEnv = new TestEnvironment(oObj); 124 125 log.println("Implementation Name: " + utils.getImplName(oObj)); 126 127 tEnv.addObjRelation("WINPEER", the_win); 128 129 tEnv.addObjRelation("XModel", xModel); 130 131 132 // adding relation for XDataTransferProviderAccess 133 tEnv.addObjRelation("XDataTransferProviderAccess.XWindow", win); 134 135 return tEnv; 136 } // finish method getTestEnvironment 137 } // finish class Toolkit 138