1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package mod._toolkit;
28 
29 import com.sun.star.awt.Rectangle;
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.XToolkit;
35 import com.sun.star.awt.XWindow;
36 import com.sun.star.awt.XWindowPeer;
37 import com.sun.star.drawing.XControlShape;
38 import com.sun.star.drawing.XShape;
39 import com.sun.star.frame.XFrame;
40 import com.sun.star.frame.XModel;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.text.XTextDocument;
43 import com.sun.star.uno.UnoRuntime;
44 import com.sun.star.uno.XInterface;
45 import com.sun.star.view.XControlAccess;
46 import java.awt.Dimension;
47 import java.awt.Toolkit;
48 
49 import java.io.PrintWriter;
50 
51 import lib.StatusException;
52 import lib.TestCase;
53 import lib.TestEnvironment;
54 import lib.TestParameters;
55 
56 import util.FormTools;
57 import util.SOfficeFactory;
58 import util.WriterTools;
59 import util.utils;
60 
61 
62 public class UnoScrollBarControl extends TestCase {
63     private static XTextDocument xTextDoc;
64 
65     protected void initialize(TestParameters Param, PrintWriter log) {
66         SOfficeFactory SOF = SOfficeFactory.getFactory(
67                                      (XMultiServiceFactory) Param.getMSF());
68 
69         try {
70             log.println("creating a textdocument");
71             xTextDoc = SOF.createTextDoc(null);
72 
73             log.println("maximize the window size");
74             XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xTextDoc);
75             XFrame xFrame = xModel.getCurrentController().getFrame();
76             XWindow xWin = xFrame.getContainerWindow();
77 
78             Toolkit tk = Toolkit.getDefaultToolkit();
79             Dimension dim = tk.getScreenSize();
80 
81             Rectangle newPosSize = xWin.getPosSize();
82             newPosSize.Width = new Double(dim.getWidth()).intValue();
83             newPosSize.Height = new Double(dim.getHeight()).intValue();
84             newPosSize.X = 0;
85             newPosSize.Y = 0;
86 
87             xWin.setPosSize(newPosSize.X, newPosSize.Y, newPosSize.Width,
88                             newPosSize.Height, com.sun.star.awt.PosSize.POSSIZE);
89 
90         } catch (com.sun.star.uno.Exception e) {
91             // Some exception occures.FAILED
92             e.printStackTrace(log);
93             throw new StatusException("Couldn't create document", e);
94         }
95     }
96 
97     protected void cleanup(TestParameters tParam, PrintWriter log) {
98         log.println("    disposing xTextDoc ");
99 
100         util.DesktopTools.closeDoc(xTextDoc);
101     }
102 
103     protected TestEnvironment createTestEnvironment(TestParameters Param,
104                                                     PrintWriter log) {
105         XInterface oObj = null;
106         XWindowPeer the_win = null;
107         XToolkit the_kit = null;
108         XDevice aDevice = null;
109         XGraphics aGraphic = null;
110         XControl aControl = null;
111 
112         //Insert a ControlShape and get the ControlModel
113         XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
114                                                                4500, 15000,
115                                                                10000,
116                                                                "ScrollBar",
117                                                                "UnoControlScrollBar");
118 
119         WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
120 
121         XControlModel the_Model = aShape.getControl();
122 
123         XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
124                                                              4500, 5000, 10000,
125                                                              "TextField");
126 
127         WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2);
128 
129         XControlModel the_Model2 = aShape2.getControl();
130 
131         //Try to query XControlAccess
132         XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
133                                             XControlAccess.class,
134                                             xTextDoc.getCurrentController());
135 
136         //get the ScrollBarControl for the needed Object relations
137         try {
138             oObj = the_access.getControl(the_Model);
139             aControl = the_access.getControl(the_Model2);
140             the_win = the_access.getControl(the_Model).getPeer();
141             the_kit = the_win.getToolkit();
142             aDevice = the_kit.createScreenCompatibleDevice(200, 200);
143             aGraphic = aDevice.createGraphics();
144         } catch (Exception e) {
145             log.println("Couldn't get ScrollBarControl");
146             e.printStackTrace(log);
147             throw new StatusException("Couldn't get ScrollBarControl", e);
148         }
149 
150         log.println(
151                 "creating a new environment for UnoControlScrollBar object");
152 
153         TestEnvironment tEnv = new TestEnvironment(oObj);
154 
155 
156         //adding Object-Relation for XScrollBar
157         tEnv.addObjRelation("Document", xTextDoc);
158 
159 
160         //Adding ObjRelation for XView
161         tEnv.addObjRelation("GRAPHICS", aGraphic);
162 
163 
164         //Adding ObjRelation for XControl
165         tEnv.addObjRelation("CONTEXT", xTextDoc);
166         tEnv.addObjRelation("WINPEER", the_win);
167         tEnv.addObjRelation("TOOLKIT", the_kit);
168         tEnv.addObjRelation("MODEL", the_Model);
169 
170         XWindow forObjRel = (XWindow) UnoRuntime.queryInterface(XWindow.class,
171                                                                 aControl);
172 
173         tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
174 
175         System.out.println("ImplementationName: " + utils.getImplName(oObj));
176 
177         return tEnv;
178     } // finish method getTestEnvironment
179 }
180