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.view.XControlAccess; 41 import util.DesktopTools; 42 43 public class ONavigationBarControl extends TestCase { 44 XTextDocument xTextDoc; 45 46 /** 47 * Creates a text document. 48 */ 49 @Override initialize(TestParameters Param, PrintWriter log)50 protected void initialize(TestParameters Param, PrintWriter log) throws Exception { 51 SOfficeFactory SOF = SOfficeFactory.getFactory(Param.getMSF()); 52 53 log.println("creating a textdocument"); 54 xTextDoc = SOF.createTextDoc(null); 55 } 56 57 /** 58 * Disposes the text document created before 59 */ 60 @Override cleanup(TestParameters tParam, PrintWriter log)61 protected void cleanup(TestParameters tParam, PrintWriter log) { 62 log.println(" disposing xTextDoc "); 63 64 DesktopTools.closeDoc(xTextDoc); 65 } 66 67 /** 68 * Creates two components and inserts them to the form of 69 * text document. One component 70 * (<code>com.sun.star.form.component.CommandButton</code>) is created 71 * for testing, another to be passed as relation. Using a controller 72 * of the text document the controller of the first component is 73 * obtained and returned in environment as a test object. <p> 74 * 75 * Object relations created : 76 * <ul> 77 * <li> <code>'GRAPHICS'</code> for 78 * {@link ifc.awt._XView} : a graphics component 79 * created using screen device of the window peer of 80 * the controller tested. </li> 81 * <li> <code>'CONTEXT'</code> for 82 * {@link ifc.awt._XControl} : the text document 83 * where the component is inserted. </li> 84 * <li> <code>'WINPEER'</code> for 85 * {@link ifc.awt._XControl} : Window peer of the 86 * controller tested. </li> 87 * <li> <code>'TOOLKIT'</code> for 88 * {@link ifc.awt._XControl} : toolkit of the component.</li> 89 * <li> <code>'MODEL'</code> for 90 * {@link ifc.awt._XControl} : the model of the controller.</li> 91 * <li> <code>'XWindow.AnotherWindow'</code> for 92 * {@link ifc.awt._XWindow} : the controller of another 93 * component. </li> 94 * </ul> 95 */ 96 @Override createTestEnvironment(TestParameters Param, PrintWriter log)97 protected TestEnvironment createTestEnvironment(TestParameters Param, 98 PrintWriter log) throws Exception { 99 XInterface oObj = null; 100 XWindowPeer the_win = null; 101 XToolkit the_kit = null; 102 XDevice aDevice = null; 103 XGraphics aGraphic = null; 104 XControl aControl = null; 105 106 //Insert a ControlShape and get the ControlModel 107 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000, 108 4500, 15000, 10000, 109 "NavigationToolBar"); 110 111 WriterTools.getDrawPage(xTextDoc).add(aShape); 112 113 XControlModel the_Model = aShape.getControl(); 114 115 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000, 116 4500, 5000, 10000, 117 "TextField"); 118 119 WriterTools.getDrawPage(xTextDoc).add(aShape2); 120 121 XControlModel the_Model2 = aShape2.getControl(); 122 123 //Try to query XControlAccess 124 XControlAccess the_access = UnoRuntime.queryInterface( 125 XControlAccess.class, 126 xTextDoc.getCurrentController()); 127 128 //now get the OButtonControl 129 oObj = the_access.getControl(the_Model); 130 aControl = the_access.getControl(the_Model2); 131 the_win = the_access.getControl(the_Model).getPeer(); 132 the_kit = the_win.getToolkit(); 133 aDevice = the_kit.createScreenCompatibleDevice(200, 200); 134 aGraphic = aDevice.createGraphics(); 135 136 log.println("creating a new environment for ONavigationBarControl object"); 137 138 TestEnvironment tEnv = new TestEnvironment(oObj); 139 140 141 //Adding ObjRelation for XView 142 tEnv.addObjRelation("GRAPHICS", aGraphic); 143 144 145 //Adding ObjRelation for XControl 146 tEnv.addObjRelation("CONTEXT", xTextDoc); 147 tEnv.addObjRelation("WINPEER", the_win); 148 tEnv.addObjRelation("TOOLKIT", the_kit); 149 tEnv.addObjRelation("MODEL", the_Model); 150 151 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class, 152 aControl); 153 154 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel); 155 tEnv.addObjRelation("XWindow.ControlShape", aShape); 156 157 return tEnv; 158 } // finish method getTestEnvironment 159 } // finish class ONavigationBarControl 160