1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: UnoControlContainer.java,v $
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 ************************************************************************/
32 import com
.sun
.star
.awt
.PosSize
;
33 import com
.sun
.star
.awt
.Rectangle
;
34 import com
.sun
.star
.awt
.XControl
;
35 import com
.sun
.star
.awt
.XControlContainer
;
36 import com
.sun
.star
.awt
.XControlModel
;
37 import com
.sun
.star
.awt
.XDevice
;
38 import com
.sun
.star
.awt
.XGraphics
;
39 import com
.sun
.star
.awt
.XToolkit
;
40 import com
.sun
.star
.awt
.XWindow
;
41 import com
.sun
.star
.awt
.XWindowPeer
;
42 import com
.sun
.star
.drawing
.XControlShape
;
43 import com
.sun
.star
.drawing
.XShape
;
44 import com
.sun
.star
.frame
.XController
;
45 import com
.sun
.star
.frame
.XFrame
;
46 import com
.sun
.star
.lang
.XMultiServiceFactory
;
47 import com
.sun
.star
.text
.XTextDocument
;
48 import com
.sun
.star
.uno
.UnoRuntime
;
49 import com
.sun
.star
.uno
.XInterface
;
50 import com
.sun
.star
.view
.XControlAccess
;
52 import java
.io
.PrintWriter
;
54 import lib
.StatusException
;
56 import lib
.TestEnvironment
;
57 import lib
.TestParameters
;
59 import util
.FormTools
;
60 import util
.WriterTools
;
64 public class UnoControlContainer
extends TestCase
{
65 private static XTextDocument xTextDoc
;
66 private static XTextDocument xTD2
;
67 private static XControl xCtrl
;
68 private static XControl xCtrl1
;
69 private static XControl xCtrl2
;
71 protected void initialize(TestParameters param
, PrintWriter log
) {
73 log
.println("creating a textdocument");
74 xTD2
= WriterTools
.createTextDoc(
75 (XMultiServiceFactory
) param
.getMSF());
76 xTextDoc
= WriterTools
.createTextDoc(
77 (XMultiServiceFactory
) param
.getMSF());
78 } catch (Exception e
) {
79 // Some exception occures.FAILED
80 e
.printStackTrace(log
);
81 throw new StatusException("Couldn't create document", e
);
85 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
86 log
.println(" disposing xTextDoc ");
88 util
.DesktopTools
.closeDoc(xTextDoc
);
89 util
.DesktopTools
.closeDoc(xTD2
);
92 public TestEnvironment
createTestEnvironment(TestParameters param
,
94 // create Object Relations -------------------------------------------
95 XInterface oObj
= null;
96 XControlShape shape
= null;
97 XControlModel model
= null;
98 XControlAccess access
= null;
99 XWindow anotherWindow
= null;
102 XWindowPeer the_win
= null;
103 XToolkit the_kit
= null;
105 XControlContainer ctrlCont
= null;
107 XGraphics aGraphic
= null;
110 // create 3 XControls
111 // create first XControl
112 shape
= FormTools
.createControlShape(xTextDoc
, 3000, 4500, 15000,
114 WriterTools
.getDrawPage(xTextDoc
).add((XShape
) shape
);
115 model
= shape
.getControl();
116 access
= (XControlAccess
) UnoRuntime
.queryInterface(
117 XControlAccess
.class, xTextDoc
.getCurrentController());
120 xCtrl
= access
.getControl(model
);
121 } catch (Exception e
) {
122 e
.printStackTrace(log
);
123 throw new StatusException("Couldn't create XControl", e
);
127 // create second XControl
128 shape
= FormTools
.createControlShape(xTextDoc
, 3000, 4500, 15000,
130 WriterTools
.getDrawPage(xTextDoc
).add((XShape
) shape
);
131 model
= shape
.getControl();
132 access
= (XControlAccess
) UnoRuntime
.queryInterface(
133 XControlAccess
.class, xTextDoc
.getCurrentController());
136 xCtrl1
= access
.getControl(model
);
137 } catch (Exception e
) {
138 e
.printStackTrace(log
);
139 throw new StatusException("Couldn't create XControl", e
);
143 // create third XControl
144 shape
= FormTools
.createControlShape(xTextDoc
, 3000, 4500, 15000,
145 10000, "CommandButton");
146 WriterTools
.getDrawPage(xTextDoc
).add((XShape
) shape
);
147 model
= shape
.getControl();
148 access
= (XControlAccess
) UnoRuntime
.queryInterface(
149 XControlAccess
.class, xTextDoc
.getCurrentController());
152 xCtrl2
= access
.getControl(model
);
153 } catch (Exception e
) {
154 e
.printStackTrace(log
);
155 throw new StatusException("Couldn't create XControl", e
);
158 // create XToolkit, XWindowPeer, XDevice
159 //Insert a ControlShape and get the ControlModel
160 XControlShape aShape
= FormTools
.createUnoControlShape(xTextDoc
, 3000,
166 WriterTools
.getDrawPage(xTD2
).add((XShape
) aShape
);
168 XControlModel the_Model
= aShape
.getControl();
170 //Try to query XControlAccess
171 XControlAccess the_access
= (XControlAccess
) UnoRuntime
.queryInterface(
172 XControlAccess
.class,
173 xTD2
.getCurrentController());
175 //get the ButtonControl for the needed Object relations
177 the_win
= the_access
.getControl(the_Model
).getPeer();
178 the_kit
= the_win
.getToolkit();
180 XDevice aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
181 aGraphic
= aDevice
.createGraphics();
182 } catch (Exception e
) {
183 log
.println("Couldn't get ButtonControl");
184 e
.printStackTrace(log
);
185 throw new StatusException("Couldn't get ButtonControl", e
);
189 XController aController
= xTD2
.getCurrentController();
190 XFrame aFrame
= aController
.getFrame();
191 anotherWindow
= aFrame
.getComponentWindow();
192 } catch (Exception e
) {
193 e
.printStackTrace(log
);
194 throw new StatusException("Couldn't create XWindow", e
);
197 // finished create Object Relations -----------------------------------
198 // create the UnoControlContainer
200 oObj
= (XInterface
) ((XMultiServiceFactory
) param
.getMSF()).createInstance(
201 "com.sun.star.awt.UnoControlContainer");
203 XControl xCtrl
= (XControl
) UnoRuntime
.queryInterface(
204 XControl
.class, oObj
);
205 xCtrl
.setModel(the_Model
);
207 ctrlCont
= (XControlContainer
) UnoRuntime
.queryInterface(
208 XControlContainer
.class, oObj
);
209 ctrlCont
.addControl("jupp", access
.getControl(aShape
.getControl()));
210 } catch (Exception e
) {
211 e
.printStackTrace(log
);
212 throw new StatusException("Couldn't create UnoControlContainer", e
);
216 "creating a new environment for UnoControlContainer object");
218 TestEnvironment tEnv
= new TestEnvironment(oObj
);
220 XWindow xWindow
= (XWindow
) UnoRuntime
.queryInterface(XWindow
.class, oObj
);
221 Rectangle ps
= xWindow
.getPosSize();
222 xWindow
.setPosSize(ps
.X
+10, ps
.Y
+10, ps
.Width
+10, ps
.Height
+10, PosSize
.POSSIZE
);
224 String objName
= "UnoControlContainer";
225 tEnv
.addObjRelation("OBJNAME", "toolkit." + objName
);
228 // Object relation for XContainer
229 tEnv
.addObjRelation("XContainer.Container", ctrlCont
);
230 tEnv
.addObjRelation("INSTANCE", xCtrl
);
233 //Adding ObjRelation for XView
234 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
237 // Object Relation for XControlContainer
238 tEnv
.addObjRelation("CONTROL1", xCtrl1
);
239 tEnv
.addObjRelation("CONTROL2", xCtrl2
);
242 // Object Relation for XControl
243 tEnv
.addObjRelation("CONTEXT", xTD2
);
244 tEnv
.addObjRelation("WINPEER", the_win
);
245 tEnv
.addObjRelation("TOOLKIT", the_kit
);
246 tEnv
.addObjRelation("MODEL", the_Model
);
249 // Object Relation for XWindow
250 tEnv
.addObjRelation("XWindow.AnotherWindow", anotherWindow
);
251 System
.out
.println("ImplementationName: " + utils
.getImplName(oObj
));