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 19 package mod._forms; 20 21 import java.io.PrintWriter; 22 23 import lib.TestCase; 24 import lib.TestEnvironment; 25 import lib.TestParameters; 26 import util.FormTools; 27 import util.SOfficeFactory; 28 import util.WriterTools; 29 30 import com.sun.star.awt.XCheckBox; 31 import com.sun.star.awt.XControl; 32 import com.sun.star.awt.XControlModel; 33 import com.sun.star.awt.XDevice; 34 import com.sun.star.awt.XGraphics; 35 import com.sun.star.awt.XToolkit; 36 import com.sun.star.awt.XWindow; 37 import com.sun.star.awt.XWindowPeer; 38 import com.sun.star.drawing.XControlShape; 39 import com.sun.star.text.XTextDocument; 40 import com.sun.star.uno.UnoRuntime; 41 import com.sun.star.uno.XInterface; 42 import com.sun.star.util.XCloseable; 43 import com.sun.star.view.XControlAccess; 44 45 46 /** 47 * Test for object which is represented by default controller 48 * of the <code>com.sun.star.form.component.CheckBox</code> 49 * component. <p> 50 * 51 * Object implements the following interfaces : 52 * <ul> 53 * <li> <code>com::sun::star::awt::XView</code></li> 54 * <li> <code>com::sun::star::form::XBoundControl</code></li> 55 * <li> <code>com::sun::star::awt::XControl</code></li> 56 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li> 57 * <li> <code>com::sun::star::awt::XItemListener</code></li> 58 * <li> <code>com::sun::star::awt::XWindow</code></li> 59 * <li> <code>com::sun::star::awt::XCheckBox</code></li> 60 * <li> <code>com::sun::star::lang::XComponent</code></li> 61 * <li> <code>com::sun::star::lang::XEventListener</code></li> 62 * </ul> <p> 63 * This object test <b> is NOT </b> designed to be run in several 64 * threads concurrently. 65 * 66 * @see com.sun.star.awt.XView 67 * @see com.sun.star.form.XBoundControl 68 * @see com.sun.star.awt.XControl 69 * @see com.sun.star.awt.XLayoutConstrains 70 * @see com.sun.star.awt.XItemListener 71 * @see com.sun.star.awt.XWindow 72 * @see com.sun.star.awt.XCheckBox 73 * @see com.sun.star.lang.XComponent 74 * @see com.sun.star.lang.XEventListener 75 * @see ifc.awt._XView 76 * @see ifc.form._XBoundControl 77 * @see ifc.awt._XControl 78 * @see ifc.awt._XLayoutConstrains 79 * @see ifc.awt._XItemListener 80 * @see ifc.awt._XWindow 81 * @see ifc.awt._XCheckBox 82 * @see ifc.lang._XComponent 83 * @see ifc.lang._XEventListener 84 */ 85 public class OCheckBoxControl extends TestCase { 86 87 XTextDocument xTextDoc; 88 89 /** 90 * Creates a new text document. 91 */ 92 @Override initialize( TestParameters Param, PrintWriter log)93 protected void initialize ( TestParameters Param, PrintWriter log) throws Exception { 94 SOfficeFactory SOF = SOfficeFactory.getFactory( Param.getMSF() ); 95 log.println( "creating a textdocument" ); 96 xTextDoc = SOF.createTextDoc( null ); 97 } 98 99 /** 100 * Disposes the text document created before 101 */ 102 @Override cleanup(TestParameters tParam, PrintWriter log)103 protected void cleanup(TestParameters tParam, PrintWriter log) { 104 log.println(" disposing xTextDoc "); 105 106 try { 107 XCloseable closer = UnoRuntime.queryInterface( 108 XCloseable.class, xTextDoc); 109 closer.close(true); 110 } catch (com.sun.star.util.CloseVetoException e) { 111 log.println("couldn't close document"); 112 } catch (com.sun.star.lang.DisposedException e) { 113 log.println("couldn't close document"); 114 } 115 } 116 117 /** 118 * Creates two components and inserts them to the form of 119 * text document. One component 120 * (<code>com.sun.star.form.component.CheckBox</code>) is created 121 * for testing, another to be passed as relation. Using a controller 122 * of the text document the controller of the first component is 123 * obtained and returned in environment as a test object. <p> 124 * 125 * Object relations created : 126 * <ul> 127 * <li> <code>'GRAPHICS'</code> for 128 * {@link ifc.awt._XView} : a graphics component 129 * created using screen device of the window peer of 130 * the controller tested. </li> 131 * <li> <code>'CONTEXT'</code> for 132 * {@link ifc.awt._XControl} : the text document 133 * where the component is inserted. </li> 134 * <li> <code>'WINPEER'</code> for 135 * {@link ifc.awt._XControl} : Window peer of the 136 * controller tested. </li> 137 * <li> <code>'TOOLKIT'</code> for 138 * {@link ifc.awt._XControl} : toolkit of the component.</li> 139 * <li> <code>'MODEL'</code> for 140 * {@link ifc.awt._XControl} : the model of the controller.</li> 141 * <li> <code>'XWindow.AnotherWindow'</code> for 142 * {@link ifc.awt._XWindow} : the controller of another 143 * component. </li> 144 * <li> <code>'TestItemListener'</code> for 145 * {@link ifc.awt._XItemListener} : listener implementation is 146 * registered here and passed as relation. </li> 147 * </ul> 148 */ 149 @Override createTestEnvironment(TestParameters Param, PrintWriter log)150 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) throws Exception { 151 XInterface oObj = null; 152 XWindowPeer the_win = null; 153 XToolkit the_kit = null; 154 XDevice aDevice = null; 155 XGraphics aGraphic = null; 156 XControl aControl = null; 157 //Insert a ControlShape and get the ControlModel 158 XControlShape aShape = FormTools.createControlShape( 159 xTextDoc,3000,4500,15000,10000,"CheckBox"); 160 161 WriterTools.getDrawPage(xTextDoc).add(aShape); 162 163 XControlModel the_Model = aShape.getControl(); 164 165 XControlShape aShape2 = FormTools.createControlShape( 166 xTextDoc,3000,4500,5000,10000,"TextField"); 167 168 WriterTools.getDrawPage(xTextDoc).add(aShape2); 169 170 XControlModel the_Model2 = aShape2.getControl(); 171 172 //Try to query XControlAccess 173 XControlAccess the_access = UnoRuntime.queryInterface( 174 XControlAccess.class,xTextDoc.getCurrentController()); 175 176 //now get the OButtonControl 177 oObj = the_access.getControl(the_Model); 178 aControl = the_access.getControl(the_Model2); 179 the_win = the_access.getControl(the_Model).getPeer(); 180 the_kit = the_win.getToolkit(); 181 aDevice = the_kit.createScreenCompatibleDevice(200,200); 182 aGraphic = aDevice.createGraphics(); 183 184 log.println( "creating a new environment for OCheckBoxControl object" ); 185 TestEnvironment tEnv = new TestEnvironment( oObj ); 186 187 //Adding ObjRelation for XView 188 tEnv.addObjRelation("GRAPHICS",aGraphic); 189 190 //Adding ObjRelation for XControl 191 tEnv.addObjRelation("CONTEXT",xTextDoc); 192 tEnv.addObjRelation("WINPEER",the_win); 193 tEnv.addObjRelation("TOOLKIT",the_kit); 194 tEnv.addObjRelation("MODEL",the_Model); 195 196 // Adding relation for XItemListener 197 ifc.awt._XItemListener.TestItemListener listener = 198 new ifc.awt._XItemListener.TestItemListener() ; 199 XCheckBox box = UnoRuntime.queryInterface 200 (XCheckBox.class, oObj) ; 201 box.addItemListener(listener) ; 202 tEnv.addObjRelation("TestItemListener", listener) ; 203 204 // Adding relation for XWindow 205 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class,aControl); 206 207 tEnv.addObjRelation("XWindow.AnotherWindow",forObjRel); 208 209 return tEnv; 210 } // finish method getTestEnvironment 211 212 } // finish class OButtonControl 213 214 215