tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlNumericField.java
blob073b637563d5629331f94bbbd77a529f3f3b0c05
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 java.io.PrintWriter;
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 import util.utils;
30 import com.sun.star.awt.XControl;
31 import com.sun.star.awt.XControlModel;
32 import com.sun.star.awt.XDevice;
33 import com.sun.star.awt.XGraphics;
34 import com.sun.star.awt.XTextComponent;
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;
46 public class UnoControlNumericField extends TestCase {
47 private static XTextDocument xTextDoc;
49 @Override
50 protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
51 SOfficeFactory SOF = SOfficeFactory.getFactory( Param.getMSF());
53 log.println("creating a textdocument");
54 xTextDoc = SOF.createTextDoc(null);
57 @Override
58 protected void cleanup(TestParameters tParam, PrintWriter log) {
59 log.println(" disposing xTextDoc ");
61 try {
62 XCloseable closer = UnoRuntime.queryInterface(
63 XCloseable.class, xTextDoc);
64 closer.close(true);
65 } catch (com.sun.star.util.CloseVetoException e) {
66 log.println("couldn't close document");
67 } catch (com.sun.star.lang.DisposedException e) {
68 log.println("couldn't close document");
72 @Override
73 protected TestEnvironment createTestEnvironment(TestParameters Param,
74 PrintWriter log) throws Exception {
75 XInterface oObj = null;
76 XWindowPeer the_win = null;
77 XToolkit the_kit = null;
78 XDevice aDevice = null;
79 XGraphics aGraphic = null;
80 XControl aControl = null;
82 //Insert a ControlShape and get the ControlModel
83 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
84 4500, 15000,
85 10000,
86 "NumericField",
87 "UnoControlNumericField");
89 WriterTools.getDrawPage(xTextDoc).add(aShape);
91 XControlModel the_Model = aShape.getControl();
93 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
94 4500, 5000, 10000,
95 "TextField");
97 WriterTools.getDrawPage(xTextDoc).add(aShape2);
99 XControlModel the_Model2 = aShape2.getControl();
101 //Try to query XControlAccess
102 XControlAccess the_access = UnoRuntime.queryInterface(
103 XControlAccess.class,
104 xTextDoc.getCurrentController());
106 //get the NumericFieldControl for the needed Object relations
107 oObj = the_access.getControl(the_Model);
108 aControl = the_access.getControl(the_Model2);
109 the_win = the_access.getControl(the_Model).getPeer();
110 the_kit = the_win.getToolkit();
111 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
112 aGraphic = aDevice.createGraphics();
114 log.println(
115 "creating a new environment for UnoControlNumericField object");
117 TestEnvironment tEnv = new TestEnvironment(oObj);
120 //Adding ObjRelation for XView
121 tEnv.addObjRelation("GRAPHICS", aGraphic);
124 //Adding ObjRelation for XControl
125 tEnv.addObjRelation("CONTEXT", xTextDoc);
126 tEnv.addObjRelation("WINPEER", the_win);
127 tEnv.addObjRelation("TOOLKIT", the_kit);
128 tEnv.addObjRelation("MODEL", the_Model);
130 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class,
131 aControl);
133 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
134 tEnv.addObjRelation("XWindow.ControlShape", aShape);
136 // Adding relation for XTextListener
137 ifc.awt._XTextListener.TestTextListener listener =
138 new ifc.awt._XTextListener.TestTextListener();
139 XTextComponent textComp = UnoRuntime.queryInterface(
140 XTextComponent.class, oObj);
141 textComp.addTextListener(listener);
142 tEnv.addObjRelation("TestTextListener", listener);
144 tEnv.addObjRelation("XTextComponent.onlyNumbers", "");
146 log.println("ImplementationName: " + utils.getImplName(oObj));
148 return tEnv;
149 } // finish method getTestEnvironment
150 } // finish class UnoControlNumericField