merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _forms / ONavigationBarControl.java
blobbc0476f6df1538bda9859610186c26aef4fff493
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ONavigationBarControl.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package mod._forms;
32 import java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
38 import util.FormTools;
39 import util.SOfficeFactory;
40 import util.WriterTools;
42 import com.sun.star.awt.XControl;
43 import com.sun.star.awt.XControlModel;
44 import com.sun.star.awt.XDevice;
45 import com.sun.star.awt.XGraphics;
46 import com.sun.star.awt.XToolkit;
47 import com.sun.star.awt.XWindow;
48 import com.sun.star.awt.XWindowPeer;
49 import com.sun.star.drawing.XControlShape;
50 import com.sun.star.drawing.XShape;
51 import com.sun.star.lang.XMultiServiceFactory;
52 import com.sun.star.text.XTextDocument;
53 import com.sun.star.uno.UnoRuntime;
54 import com.sun.star.uno.XInterface;
55 import com.sun.star.view.XControlAccess;
56 import util.DesktopTools;
58 public class ONavigationBarControl extends TestCase {
59 XTextDocument xTextDoc;
61 /**
62 * Creates a text document.
64 protected void initialize(TestParameters Param, PrintWriter log) {
65 SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory) Param.getMSF());
67 try {
68 log.println("creating a textdocument");
69 xTextDoc = SOF.createTextDoc(null);
70 } catch (com.sun.star.uno.Exception e) {
71 // Some exception occures.FAILED
72 e.printStackTrace(log);
73 throw new StatusException("Couldn't create document", e);
77 /**
78 * Disposes the text document created before
80 protected void cleanup(TestParameters tParam, PrintWriter log) {
81 log.println(" disposing xTextDoc ");
83 DesktopTools.closeDoc(xTextDoc);
86 /**
87 * Creates two components and inserts them to the form of
88 * text document. One component
89 * (<code>com.sun.star.form.component.CommandButton</code>) is created
90 * for testing, another to be passed as relation. Using a controller
91 * of the text document the controller of the first component is
92 * obtained and returned in environment as a test object. <p>
94 * Object relations created :
95 * <ul>
96 * <li> <code>'GRAPHICS'</code> for
97 * {@link ifc.awt._XView} : a graphics component
98 * created using screen device of the window peer of
99 * the controller tested. </li>
100 * <li> <code>'CONTEXT'</code> for
101 * {@link ifc.awt._XControl} : the text document
102 * where the component is inserted. </li>
103 * <li> <code>'WINPEER'</code> for
104 * {@link ifc.awt._XControl} : Window peer of the
105 * controller tested. </li>
106 * <li> <code>'TOOLKIT'</code> for
107 * {@link ifc.awt._XControl} : toolkit of the component.</li>
108 * <li> <code>'MODEL'</code> for
109 * {@link ifc.awt._XControl} : the model of the controller.</li>
110 * <li> <code>'XWindow.AnotherWindow'</code> for
111 * {@link ifc.awt._XWindow} : the controller of another
112 * component. </li>
113 * </ul>
115 protected TestEnvironment createTestEnvironment(TestParameters Param,
116 PrintWriter log) {
117 XInterface oObj = null;
118 XWindowPeer the_win = null;
119 XToolkit the_kit = null;
120 XDevice aDevice = null;
121 XGraphics aGraphic = null;
122 XControl aControl = null;
124 //Insert a ControlShape and get the ControlModel
125 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
126 4500, 15000, 10000,
127 "NavigationToolBar");
129 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
131 XControlModel the_Model = aShape.getControl();
133 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
134 4500, 5000, 10000,
135 "TextField");
137 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2);
139 XControlModel the_Model2 = aShape2.getControl();
141 //Try to query XControlAccess
142 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
143 XControlAccess.class,
144 xTextDoc.getCurrentController());
146 //now get the OButtonControl
147 try {
148 oObj = the_access.getControl(the_Model);
149 aControl = the_access.getControl(the_Model2);
150 the_win = the_access.getControl(the_Model).getPeer();
151 the_kit = the_win.getToolkit();
152 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
153 aGraphic = aDevice.createGraphics();
154 } catch (com.sun.star.container.NoSuchElementException e) {
155 log.println("Couldn't get ONavigationBarControl");
156 e.printStackTrace(log);
157 throw new StatusException("Couldn't get ONavigationBarControl", e);
160 log.println("creating a new environment for ONavigationBarControl object");
162 TestEnvironment tEnv = new TestEnvironment(oObj);
165 //Adding ObjRelation for XView
166 tEnv.addObjRelation("GRAPHICS", aGraphic);
169 //Adding ObjRelation for XControl
170 tEnv.addObjRelation("CONTEXT", xTextDoc);
171 tEnv.addObjRelation("WINPEER", the_win);
172 tEnv.addObjRelation("TOOLKIT", the_kit);
173 tEnv.addObjRelation("MODEL", the_Model);
175 XWindow forObjRel = (XWindow) UnoRuntime.queryInterface(XWindow.class,
176 aControl);
178 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
179 tEnv.addObjRelation("XWindow.ControlShape", aShape);
181 return tEnv;
182 } // finish method getTestEnvironment
183 } // finish class ONavigationBarControl