1 /* 2 * This file is part of the LibreOffice project. 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 10 * Licensed to the Apache Software Foundation (ASF) under one or more 11 * contributor license agreements. See the NOTICE file distributed 12 * with this work for additional information regarding copyright 13 * ownership. The ASF licenses this file to you under the Apache 14 * License, Version 2.0 (the "License"); you may not use this file 15 * except in compliance with the License. You may obtain a copy of 16 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 17 */ 18 package mod._forms; 19 20 import java.io.PrintWriter; 21 22 import lib.TestCase; 23 import lib.TestEnvironment; 24 import lib.TestParameters; 25 import util.FormTools; 26 import util.SOfficeFactory; 27 import util.WriterTools; 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.XToolkit; 34 import com.sun.star.awt.XWindow; 35 import com.sun.star.awt.XWindowPeer; 36 import com.sun.star.drawing.XControlShape; 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.util.XCloseable; 41 import com.sun.star.view.XControlAccess; 42 43 44 /** 45 * Test for object which is represented by default controller 46 * of the <code>com.sun.star.form.component.CommandButton</code> 47 * component. <p> 48 * 49 * Object implements the following interfaces : 50 * <ul> 51 * <li> <code>com::sun::star::lang::XComponent</code></li> 52 * <li> <code>com::sun::star::awt::XWindow</code></li> 53 * <li> <code>com::sun::star::form::XApproveActionBroadcaster</code></li> 54 * <li> <code>com::sun::star::awt::XControl</code></li> 55 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li> 56 * <li> <code>com::sun::star::awt::XButton</code></li> 57 * <li> <code>com::sun::star::awt::XView</code></li> 58 * </ul> <p> 59 * 60 * This object test <b> is NOT </b> designed to be run in several 61 * threads concurrently. 62 * 63 * @see com.sun.star.lang.XComponent 64 * @see com.sun.star.awt.XWindow 65 * @see com.sun.star.form.XApproveActionBroadcaster 66 * @see com.sun.star.awt.XControl 67 * @see com.sun.star.awt.XLayoutConstrains 68 * @see com.sun.star.awt.XButton 69 * @see com.sun.star.awt.XView 70 * @see ifc.lang._XComponent 71 * @see ifc.awt._XWindow 72 * @see ifc.form._XApproveActionBroadcaster 73 * @see ifc.awt._XControl 74 * @see ifc.awt._XLayoutConstrains 75 * @see ifc.awt._XButton 76 * @see ifc.awt._XView 77 */ 78 public class OButtonControl extends TestCase { 79 XTextDocument xTextDoc; 80 81 /** 82 * Creates a text document. 83 */ 84 @Override initialize(TestParameters Param, PrintWriter log)85 protected void initialize(TestParameters Param, PrintWriter log) throws Exception { 86 SOfficeFactory SOF = SOfficeFactory.getFactory(Param.getMSF()); 87 88 log.println("creating a textdocument"); 89 xTextDoc = SOF.createTextDoc(null); 90 } 91 92 /** 93 * Disposes the text document created before 94 */ 95 @Override cleanup(TestParameters tParam, PrintWriter log)96 protected void cleanup(TestParameters tParam, PrintWriter log) { 97 log.println(" disposing xTextDoc "); 98 99 try { 100 XCloseable closer = UnoRuntime.queryInterface( 101 XCloseable.class, xTextDoc); 102 closer.close(true); 103 } catch (com.sun.star.util.CloseVetoException e) { 104 log.println("couldn't close document"); 105 } catch (com.sun.star.lang.DisposedException e) { 106 log.println("couldn't close document"); 107 } 108 } 109 110 /** 111 * Creates two components and inserts them to the form of 112 * text document. One component 113 * (<code>com.sun.star.form.component.CommandButton</code>) is created 114 * for testing, another to be passed as relation. Using a controller 115 * of the text document the controller of the first component is 116 * obtained and returned in environment as a test object. <p> 117 * 118 * Object relations created : 119 * <ul> 120 * <li> <code>'GRAPHICS'</code> for 121 * {@link ifc.awt._XView} : a graphics component 122 * created using screen device of the window peer of 123 * the controller tested. </li> 124 * <li> <code>'CONTEXT'</code> for 125 * {@link ifc.awt._XControl} : the text document 126 * where the component is inserted. </li> 127 * <li> <code>'WINPEER'</code> for 128 * {@link ifc.awt._XControl} : Window peer of the 129 * controller tested. </li> 130 * <li> <code>'TOOLKIT'</code> for 131 * {@link ifc.awt._XControl} : toolkit of the component.</li> 132 * <li> <code>'MODEL'</code> for 133 * {@link ifc.awt._XControl} : the model of the controller.</li> 134 * <li> <code>'XWindow.AnotherWindow'</code> for 135 * {@link ifc.awt._XWindow} : the controller of another 136 * component. </li> 137 * </ul> 138 */ 139 @Override createTestEnvironment(TestParameters Param, PrintWriter log)140 protected TestEnvironment createTestEnvironment(TestParameters Param, 141 PrintWriter log) throws Exception { 142 XInterface oObj = null; 143 XWindowPeer the_win = null; 144 XToolkit the_kit = null; 145 XDevice aDevice = null; 146 XGraphics aGraphic = null; 147 XControl aControl = null; 148 149 //Insert a ControlShape and get the ControlModel 150 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000, 151 4500, 15000, 10000, 152 "CommandButton"); 153 154 WriterTools.getDrawPage(xTextDoc).add(aShape); 155 156 XControlModel the_Model = aShape.getControl(); 157 158 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000, 159 4500, 5000, 10000, 160 "TextField"); 161 162 WriterTools.getDrawPage(xTextDoc).add(aShape2); 163 164 XControlModel the_Model2 = aShape2.getControl(); 165 166 //Try to query XControlAccess 167 XControlAccess the_access = UnoRuntime.queryInterface( 168 XControlAccess.class, 169 xTextDoc.getCurrentController()); 170 171 //now get the OButtonControl 172 oObj = the_access.getControl(the_Model); 173 aControl = the_access.getControl(the_Model2); 174 the_win = the_access.getControl(the_Model).getPeer(); 175 the_kit = the_win.getToolkit(); 176 aDevice = the_kit.createScreenCompatibleDevice(200, 200); 177 aGraphic = aDevice.createGraphics(); 178 179 log.println("creating a new environment for OButtonControl object"); 180 181 TestEnvironment tEnv = new TestEnvironment(oObj); 182 183 184 //Adding ObjRelation for XView 185 tEnv.addObjRelation("GRAPHICS", aGraphic); 186 187 188 //Adding ObjRelation for XControl 189 tEnv.addObjRelation("CONTEXT", xTextDoc); 190 tEnv.addObjRelation("WINPEER", the_win); 191 tEnv.addObjRelation("TOOLKIT", the_kit); 192 tEnv.addObjRelation("MODEL", the_Model); 193 194 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class, 195 aControl); 196 197 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel); 198 tEnv.addObjRelation("XWindow.ControlShape", aShape); 199 200 return tEnv; 201 } // finish method getTestEnvironment 202 } // finish class OButtonControl 203