tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlContainer.java
blob7c872dfaa1b2cd0fc770631473390cb63a7adffd
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.text.XTextDocument;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XInterface;
36 import com.sun.star.view.XControlAccess;
38 import java.io.PrintWriter;
40 import lib.TestCase;
41 import lib.TestEnvironment;
42 import lib.TestParameters;
43 import util.FormTools;
44 import util.WriterTools;
45 import util.utils;
48 public class UnoControlContainer extends TestCase {
49 private static XTextDocument xTextDoc;
50 private static XTextDocument xTD2;
51 private static XControl xCtrl1;
52 private static XControl xCtrl2;
54 @Override
55 protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
56 log.println("creating a textdocument");
57 xTD2 = WriterTools.createTextDoc(
58 Param.getMSF());
59 xTextDoc = WriterTools.createTextDoc(
60 Param.getMSF());
63 @Override
64 protected void cleanup(TestParameters tParam, PrintWriter log) {
65 log.println(" disposing xTextDoc ");
67 util.DesktopTools.closeDoc(xTextDoc);
68 util.DesktopTools.closeDoc(xTD2);
71 @Override
72 public TestEnvironment createTestEnvironment(TestParameters param,
73 PrintWriter log) throws Exception {
74 // create Object Relations -------------------------------------------
75 XInterface oObj = null;
76 XControlShape shape = null;
77 XControlModel model = null;
78 XControlAccess access = null;
79 XWindow anotherWindow = null;
81 // for XControl
82 XWindowPeer the_win = null;
83 XToolkit the_kit = null;
85 XControlContainer ctrlCont = null;
87 XGraphics aGraphic = null;
90 // create 3 XControls
91 // create first XControl
92 shape = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000,
93 10000, "TextField");
94 WriterTools.getDrawPage(xTextDoc).add(shape);
95 model = shape.getControl();
96 access = UnoRuntime.queryInterface(
97 XControlAccess.class, xTextDoc.getCurrentController());
99 access.getControl(model);
102 // create second XControl
103 shape = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000,
104 10000, "TextField");
105 WriterTools.getDrawPage(xTextDoc).add(shape);
106 model = shape.getControl();
107 access = UnoRuntime.queryInterface(
108 XControlAccess.class, xTextDoc.getCurrentController());
110 xCtrl1 = access.getControl(model);
113 // create third XControl
114 shape = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000,
115 10000, "CommandButton");
116 WriterTools.getDrawPage(xTextDoc).add(shape);
117 model = shape.getControl();
118 access = UnoRuntime.queryInterface(
119 XControlAccess.class, xTextDoc.getCurrentController());
121 xCtrl2 = access.getControl(model);
123 // create XToolkit, XWindowPeer, XDevice
124 //Insert a ControlShape and get the ControlModel
125 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
126 4500, 15000,
127 10000,
128 "CommandButton",
129 "UnoControlButton");
131 WriterTools.getDrawPage(xTD2).add(aShape);
133 XControlModel the_Model = aShape.getControl();
135 //Try to query XControlAccess
136 XControlAccess the_access = UnoRuntime.queryInterface(
137 XControlAccess.class,
138 xTD2.getCurrentController());
140 //get the ButtonControl for the needed Object relations
141 the_win = the_access.getControl(the_Model).getPeer();
142 the_kit = the_win.getToolkit();
144 XDevice aDevice = the_kit.createScreenCompatibleDevice(200, 200);
145 aGraphic = aDevice.createGraphics();
147 XController aController = xTD2.getCurrentController();
148 XFrame aFrame = aController.getFrame();
149 anotherWindow = aFrame.getComponentWindow();
151 // finished create Object Relations -----------------------------------
152 // create the UnoControlContainer
153 oObj = (XInterface) param.getMSF().createInstance(
154 "com.sun.star.awt.UnoControlContainer");
156 XControl xCtrl = UnoRuntime.queryInterface(
157 XControl.class, oObj);
158 xCtrl.setModel(the_Model);
160 ctrlCont = UnoRuntime.queryInterface(
161 XControlContainer.class, oObj);
162 ctrlCont.addControl("jupp", access.getControl(aShape.getControl()));
164 log.println(
165 "creating a new environment for UnoControlContainer object");
167 TestEnvironment tEnv = new TestEnvironment(oObj);
169 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, oObj);
170 Rectangle ps = xWindow.getPosSize();
171 xWindow.setPosSize(ps.X+10, ps.Y+10, ps.Width+10, ps.Height+10, PosSize.POSSIZE);
173 String objName = "UnoControlContainer";
174 tEnv.addObjRelation("OBJNAME", "toolkit." + objName);
177 // Object relation for XContainer
178 tEnv.addObjRelation("XContainer.Container", ctrlCont);
179 tEnv.addObjRelation("INSTANCE", xCtrl);
182 //Adding ObjRelation for XView
183 tEnv.addObjRelation("GRAPHICS", aGraphic);
186 // Object Relation for XControlContainer
187 tEnv.addObjRelation("CONTROL1", xCtrl1);
188 tEnv.addObjRelation("CONTROL2", xCtrl2);
191 // Object Relation for XControl
192 tEnv.addObjRelation("CONTEXT", xTD2);
193 tEnv.addObjRelation("WINPEER", the_win);
194 tEnv.addObjRelation("TOOLKIT", the_kit);
195 tEnv.addObjRelation("MODEL", the_Model);
198 // Object Relation for XWindow
199 tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow);
200 System.out.println("ImplementationName: " + utils.getImplName(oObj));
202 return tEnv;