merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _toolkit / UnoScrollBarControl.java
blob7003884af0b78d41ba52658989a251e9713b0368
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: UnoScrollBarControl.java,v $
10 * $Revision: 1.7 $
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._toolkit;
32 import com.sun.star.awt.Rectangle;
33 import com.sun.star.awt.XControl;
34 import com.sun.star.awt.XControlModel;
35 import com.sun.star.awt.XDevice;
36 import com.sun.star.awt.XGraphics;
37 import com.sun.star.awt.XToolkit;
38 import com.sun.star.awt.XWindow;
39 import com.sun.star.awt.XWindowPeer;
40 import com.sun.star.drawing.XControlShape;
41 import com.sun.star.drawing.XShape;
42 import com.sun.star.frame.XFrame;
43 import com.sun.star.frame.XModel;
44 import com.sun.star.lang.XMultiServiceFactory;
45 import com.sun.star.text.XTextDocument;
46 import com.sun.star.uno.UnoRuntime;
47 import com.sun.star.uno.XInterface;
48 import com.sun.star.view.XControlAccess;
49 import java.awt.Dimension;
50 import java.awt.Toolkit;
52 import java.io.PrintWriter;
54 import lib.StatusException;
55 import lib.TestCase;
56 import lib.TestEnvironment;
57 import lib.TestParameters;
59 import util.FormTools;
60 import util.SOfficeFactory;
61 import util.WriterTools;
62 import util.utils;
65 public class UnoScrollBarControl extends TestCase {
66 private static XTextDocument xTextDoc;
68 protected void initialize(TestParameters Param, PrintWriter log) {
69 SOfficeFactory SOF = SOfficeFactory.getFactory(
70 (XMultiServiceFactory) Param.getMSF());
72 try {
73 log.println("creating a textdocument");
74 xTextDoc = SOF.createTextDoc(null);
76 log.println("maximize the window size");
77 XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xTextDoc);
78 XFrame xFrame = xModel.getCurrentController().getFrame();
79 XWindow xWin = xFrame.getContainerWindow();
81 Toolkit tk = Toolkit.getDefaultToolkit();
82 Dimension dim = tk.getScreenSize();
84 Rectangle newPosSize = xWin.getPosSize();
85 newPosSize.Width = new Double(dim.getWidth()).intValue();
86 newPosSize.Height = new Double(dim.getHeight()).intValue();
87 newPosSize.X = 0;
88 newPosSize.Y = 0;
90 xWin.setPosSize(newPosSize.X, newPosSize.Y, newPosSize.Width,
91 newPosSize.Height, com.sun.star.awt.PosSize.POSSIZE);
93 } catch (com.sun.star.uno.Exception e) {
94 // Some exception occures.FAILED
95 e.printStackTrace(log);
96 throw new StatusException("Couldn't create document", e);
100 protected void cleanup(TestParameters tParam, PrintWriter log) {
101 log.println(" disposing xTextDoc ");
103 util.DesktopTools.closeDoc(xTextDoc);
106 protected TestEnvironment createTestEnvironment(TestParameters Param,
107 PrintWriter log) {
108 XInterface oObj = null;
109 XWindowPeer the_win = null;
110 XToolkit the_kit = null;
111 XDevice aDevice = null;
112 XGraphics aGraphic = null;
113 XControl aControl = null;
115 //Insert a ControlShape and get the ControlModel
116 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
117 4500, 15000,
118 10000,
119 "ScrollBar",
120 "UnoControlScrollBar");
122 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
124 XControlModel the_Model = aShape.getControl();
126 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
127 4500, 5000, 10000,
128 "TextField");
130 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2);
132 XControlModel the_Model2 = aShape2.getControl();
134 //Try to query XControlAccess
135 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
136 XControlAccess.class,
137 xTextDoc.getCurrentController());
139 //get the ScrollBarControl for the needed Object relations
140 try {
141 oObj = the_access.getControl(the_Model);
142 aControl = the_access.getControl(the_Model2);
143 the_win = the_access.getControl(the_Model).getPeer();
144 the_kit = the_win.getToolkit();
145 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
146 aGraphic = aDevice.createGraphics();
147 } catch (Exception e) {
148 log.println("Couldn't get ScrollBarControl");
149 e.printStackTrace(log);
150 throw new StatusException("Couldn't get ScrollBarControl", e);
153 log.println(
154 "creating a new environment for UnoControlScrollBar object");
156 TestEnvironment tEnv = new TestEnvironment(oObj);
159 //adding Object-Relation for XScrollBar
160 tEnv.addObjRelation("Document", xTextDoc);
163 //Adding ObjRelation for XView
164 tEnv.addObjRelation("GRAPHICS", aGraphic);
167 //Adding ObjRelation for XControl
168 tEnv.addObjRelation("CONTEXT", xTextDoc);
169 tEnv.addObjRelation("WINPEER", the_win);
170 tEnv.addObjRelation("TOOLKIT", the_kit);
171 tEnv.addObjRelation("MODEL", the_Model);
173 XWindow forObjRel = (XWindow) UnoRuntime.queryInterface(XWindow.class,
174 aControl);
176 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
178 System.out.println("ImplementationName: " + utils.getImplName(oObj));
180 return tEnv;
181 } // finish method getTestEnvironment