bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlContainer.java
blobfdee3047166fd206f95f5f275469fe26009b70d5
1 /*
2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
18 package mod._toolkit;
20 import com.sun.star.awt.PosSize;
21 import com.sun.star.awt.Rectangle;
22 import com.sun.star.awt.XControl;
23 import com.sun.star.awt.XControlContainer;
24 import com.sun.star.awt.XControlModel;
25 import com.sun.star.awt.XDevice;
26 import com.sun.star.awt.XGraphics;
27 import com.sun.star.awt.XToolkit;
28 import com.sun.star.awt.XWindow;
29 import com.sun.star.awt.XWindowPeer;
30 import com.sun.star.drawing.XControlShape;
31 import com.sun.star.frame.XController;
32 import com.sun.star.frame.XFrame;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.text.XTextDocument;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
37 import com.sun.star.view.XControlAccess;
39 import java.io.PrintWriter;
41 import lib.StatusException;
42 import lib.TestCase;
43 import lib.TestEnvironment;
44 import lib.TestParameters;
46 import util.FormTools;
47 import util.WriterTools;
48 import util.utils;
51 public class UnoControlContainer extends TestCase {
52 private static XTextDocument xTextDoc;
53 private static XTextDocument xTD2;
54 private static XControl xCtrl;
55 private static XControl xCtrl1;
56 private static XControl xCtrl2;
58 protected void initialize(TestParameters param, PrintWriter log) {
59 try {
60 log.println("creating a textdocument");
61 xTD2 = WriterTools.createTextDoc(
62 (XMultiServiceFactory) param.getMSF());
63 xTextDoc = WriterTools.createTextDoc(
64 (XMultiServiceFactory) param.getMSF());
65 } catch (Exception e) {
66 // Some exception occurs.FAILED
67 e.printStackTrace(log);
68 throw new StatusException("Couldn't create document", e);
72 protected void cleanup(TestParameters tParam, PrintWriter log) {
73 log.println(" disposing xTextDoc ");
75 util.DesktopTools.closeDoc(xTextDoc);
76 util.DesktopTools.closeDoc(xTD2);
79 public TestEnvironment createTestEnvironment(TestParameters param,
80 PrintWriter log) {
81 // create Object Relations -------------------------------------------
82 XInterface oObj = null;
83 XControlShape shape = null;
84 XControlModel model = null;
85 XControlAccess access = null;
86 XWindow anotherWindow = null;
88 // for XControl
89 XWindowPeer the_win = null;
90 XToolkit the_kit = null;
92 XControlContainer ctrlCont = null;
94 XGraphics aGraphic = null;
97 // create 3 XControls
98 // create first XControl
99 shape = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000,
100 10000, "TextField");
101 WriterTools.getDrawPage(xTextDoc).add(shape);
102 model = shape.getControl();
103 access = UnoRuntime.queryInterface(
104 XControlAccess.class, xTextDoc.getCurrentController());
106 try {
107 xCtrl = access.getControl(model);
108 } catch (Exception e) {
109 e.printStackTrace(log);
110 throw new StatusException("Couldn't create XControl", e);
114 // create second XControl
115 shape = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000,
116 10000, "TextField");
117 WriterTools.getDrawPage(xTextDoc).add(shape);
118 model = shape.getControl();
119 access = UnoRuntime.queryInterface(
120 XControlAccess.class, xTextDoc.getCurrentController());
122 try {
123 xCtrl1 = access.getControl(model);
124 } catch (Exception e) {
125 e.printStackTrace(log);
126 throw new StatusException("Couldn't create XControl", e);
130 // create third XControl
131 shape = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000,
132 10000, "CommandButton");
133 WriterTools.getDrawPage(xTextDoc).add(shape);
134 model = shape.getControl();
135 access = UnoRuntime.queryInterface(
136 XControlAccess.class, xTextDoc.getCurrentController());
138 try {
139 xCtrl2 = access.getControl(model);
140 } catch (Exception e) {
141 e.printStackTrace(log);
142 throw new StatusException("Couldn't create XControl", e);
145 // create XToolkit, XWindowPeer, XDevice
146 //Insert a ControlShape and get the ControlModel
147 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
148 4500, 15000,
149 10000,
150 "CommandButton",
151 "UnoControlButton");
153 WriterTools.getDrawPage(xTD2).add(aShape);
155 XControlModel the_Model = aShape.getControl();
157 //Try to query XControlAccess
158 XControlAccess the_access = UnoRuntime.queryInterface(
159 XControlAccess.class,
160 xTD2.getCurrentController());
162 //get the ButtonControl for the needed Object relations
163 try {
164 the_win = the_access.getControl(the_Model).getPeer();
165 the_kit = the_win.getToolkit();
167 XDevice aDevice = the_kit.createScreenCompatibleDevice(200, 200);
168 aGraphic = aDevice.createGraphics();
169 } catch (Exception e) {
170 log.println("Couldn't get ButtonControl");
171 e.printStackTrace(log);
172 throw new StatusException("Couldn't get ButtonControl", e);
175 try {
176 XController aController = xTD2.getCurrentController();
177 XFrame aFrame = aController.getFrame();
178 anotherWindow = aFrame.getComponentWindow();
179 } catch (Exception e) {
180 e.printStackTrace(log);
181 throw new StatusException("Couldn't create XWindow", e);
184 // finished create Object Relations -----------------------------------
185 // create the UnoControlContainer
186 try {
187 oObj = (XInterface) ((XMultiServiceFactory) param.getMSF()).createInstance(
188 "com.sun.star.awt.UnoControlContainer");
190 XControl xCtrl = UnoRuntime.queryInterface(
191 XControl.class, oObj);
192 xCtrl.setModel(the_Model);
194 ctrlCont = UnoRuntime.queryInterface(
195 XControlContainer.class, oObj);
196 ctrlCont.addControl("jupp", access.getControl(aShape.getControl()));
197 } catch (Exception e) {
198 e.printStackTrace(log);
199 throw new StatusException("Couldn't create UnoControlContainer", e);
202 log.println(
203 "creating a new environment for UnoControlContainer object");
205 TestEnvironment tEnv = new TestEnvironment(oObj);
207 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, oObj);
208 Rectangle ps = xWindow.getPosSize();
209 xWindow.setPosSize(ps.X+10, ps.Y+10, ps.Width+10, ps.Height+10, PosSize.POSSIZE);
211 String objName = "UnoControlContainer";
212 tEnv.addObjRelation("OBJNAME", "toolkit." + objName);
215 // Object relation for XContainer
216 tEnv.addObjRelation("XContainer.Container", ctrlCont);
217 tEnv.addObjRelation("INSTANCE", xCtrl);
220 //Adding ObjRelation for XView
221 tEnv.addObjRelation("GRAPHICS", aGraphic);
224 // Object Relation for XControlContainer
225 tEnv.addObjRelation("CONTROL1", xCtrl1);
226 tEnv.addObjRelation("CONTROL2", xCtrl2);
229 // Object Relation for XControl
230 tEnv.addObjRelation("CONTEXT", xTD2);
231 tEnv.addObjRelation("WINPEER", the_win);
232 tEnv.addObjRelation("TOOLKIT", the_kit);
233 tEnv.addObjRelation("MODEL", the_Model);
236 // Object Relation for XWindow
237 tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow);
238 System.out.println("ImplementationName: " + utils.getImplName(oObj));
240 return tEnv;