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.PosSize;
30 import com.sun.star.awt.XControl;
31 import com.sun.star.awt.XControlContainer;
32 import com.sun.star.awt.XControlModel;
33 import com.sun.star.awt.XDevice;
34 import com.sun.star.awt.XGraphics;
35 import com.sun.star.awt.XTabController;
36 import com.sun.star.awt.XToolkit;
37 import com.sun.star.awt.XWindow;
38 import com.sun.star.awt.XWindowPeer;
39 import com.sun.star.lang.XMultiServiceFactory;
40 import com.sun.star.text.XTextDocument;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
43 
44 import java.io.PrintWriter;
45 
46 import lib.StatusException;
47 import lib.TestCase;
48 import lib.TestEnvironment;
49 import lib.TestParameters;
50 
51 import util.SOfficeFactory;
52 
53 
54 /**
55 * Test for object which is represented by service
56 * <code>com.sun.star.awt.UnoControlDialog</code>. <p>
57 * Object implements the following interfaces :
58 * <ul>
59 *  <li> <code>com::sun::star::lang::XComponent</code></li>
60 *  <li> <code>com::sun::star::awt::XWindow</code></li>
61 *  <li> <code>com::sun::star::awt::XDialog</code></li>
62 *  <li> <code>com::sun::star::awt::XControl</code></li>
63 *  <li> <code>com::sun::star::awt::XTopWindow</code></li>
64 *  <li> <code>com::sun::star::awt::XControlContainer</code></li>
65 *  <li> <code>com::sun::star::awt::XView</code></li>
66 * </ul>
67 * This object test <b> is NOT </b> designed to be run in several
68 * threads concurently.
69 * @see com.sun.star.lang.XComponent
70 * @see com.sun.star.awt.XWindow
71 * @see com.sun.star.awt.XDialog
72 * @see com.sun.star.awt.XControl
73 * @see com.sun.star.awt.XTopWindow
74 * @see com.sun.star.awt.XControlContainer
75 * @see com.sun.star.awt.XView
76 * @see ifc.lang._XComponent
77 * @see ifc.awt._XWindow
78 * @see ifc.awt._XDialog
79 * @see ifc.awt._XControl
80 * @see ifc.awt._XTopWindow
81 * @see ifc.awt._XControlContainer
82 * @see ifc.awt._XView
83 */
84 public class UnoControlDialog extends TestCase {
85     private static XWindow xWinDlg = null;
86     private static XTextDocument xTextDoc;
87 
88     /**
89     * Creating a Testenvironment for the interfaces to be tested.
90     * Creates a Dialog Control and Model instance defines Model
91     * for Control, adds to Dialog a button, sets its size and
92     * sets the dialog visible. <p>
93     */
94     public synchronized TestEnvironment createTestEnvironment(TestParameters Param,
95                                                               PrintWriter log) {
96         XInterface oObj = null;
97         XMultiServiceFactory xMSF = (XMultiServiceFactory) Param.getMSF();
98         XControlModel dlgModel = null;
99 
100         XWindowPeer the_win = null;
101         XToolkit the_kit = null;
102         XDevice aDevice = null;
103         XGraphics aGraphic = null;
104 
105         XControl butControl = null;
106         XControl butControl1 = null;
107         XControl butControl2 = null;
108         XTabController tabControl1 = null;
109         XTabController tabControl2 = null;
110 
111         XControlContainer ctrlCont = null;
112 
113         if (xWinDlg != null) {
114             xWinDlg.dispose();
115         }
116 
117         try {
118             dlgModel = (XControlModel) UnoRuntime.queryInterface(
119                                XControlModel.class,
120                                xMSF.createInstance(
121                                        "com.sun.star.awt.UnoControlDialogModel"));
122 
123             XControl dlgControl = (XControl) UnoRuntime.queryInterface(
124                                           XControl.class,
125                                           xMSF.createInstance(
126                                                   "com.sun.star.awt.UnoControlDialog"));
127 
128             dlgControl.setModel(dlgModel);
129 
130             XControlModel butModel = (XControlModel) UnoRuntime.queryInterface(
131                                              XControlModel.class,
132                                              xMSF.createInstance(
133                                                      "com.sun.star.awt.UnoControlButtonModel"));
134 
135             butControl = (XControl) UnoRuntime.queryInterface(XControl.class,
136                                                               xMSF.createInstance(
137                                                                       "com.sun.star.awt.UnoControlButton"));
138 
139             butControl.setModel(butModel);
140 
141 
142             // creating additional controls for XUnoControlContainer
143             tabControl1 = (XTabController) UnoRuntime.queryInterface(
144                                   XTabController.class,
145                                   xMSF.createInstance(
146                                           "com.sun.star.awt.TabController"));
147 
148             tabControl2 = (XTabController) UnoRuntime.queryInterface(
149                                   XTabController.class,
150                                   xMSF.createInstance(
151                                           "com.sun.star.awt.TabController"));
152 
153 
154             // creating additional controls for XControlContainer
155             butModel = (XControlModel) UnoRuntime.queryInterface(
156                                XControlModel.class,
157                                xMSF.createInstance(
158                                        "com.sun.star.awt.UnoControlButtonModel"));
159 
160             butControl1 = (XControl) UnoRuntime.queryInterface(XControl.class,
161                                                                xMSF.createInstance(
162                                                                        "com.sun.star.awt.UnoControlButton"));
163 
164             butControl1.setModel(butModel);
165 
166             butModel = (XControlModel) UnoRuntime.queryInterface(
167                                XControlModel.class,
168                                xMSF.createInstance(
169                                        "com.sun.star.awt.UnoControlButtonModel"));
170 
171             butControl2 = (XControl) UnoRuntime.queryInterface(XControl.class,
172                                                                xMSF.createInstance(
173                                                                        "com.sun.star.awt.UnoControlButton"));
174 
175             butControl2.setModel(butModel);
176 
177             ctrlCont = (XControlContainer) UnoRuntime.queryInterface(
178                                XControlContainer.class, dlgControl);
179 
180             xWinDlg = (XWindow) UnoRuntime.queryInterface(XWindow.class,
181                                                           dlgControl);
182 
183             xWinDlg.setVisible(true);
184 
185             xWinDlg.setPosSize(10, 10, 220, 110, PosSize.SIZE);
186 
187             the_win = dlgControl.getPeer();
188             the_kit = the_win.getToolkit();
189             aDevice = the_kit.createScreenCompatibleDevice(220, 220);
190             aGraphic = aDevice.createGraphics();
191 
192             oObj = dlgControl;
193         } catch (com.sun.star.uno.Exception e) {
194             log.println("Error creating dialog :");
195             e.printStackTrace(log);
196         }
197 
198         log.println("creating a new environment for object");
199 
200         TestEnvironment tEnv = new TestEnvironment(oObj);
201 
202 
203         //Adding ObjRelation for XView
204         tEnv.addObjRelation("GRAPHICS", aGraphic);
205 
206 
207         //Adding ObjRelation for XControl
208         tEnv.addObjRelation("CONTEXT", dlgModel);
209         tEnv.addObjRelation("WINPEER", the_win);
210         tEnv.addObjRelation("TOOLKIT", the_kit);
211         tEnv.addObjRelation("MODEL", dlgModel);
212 
213         tEnv.addObjRelation("INSTANCE", butControl);
214         tEnv.addObjRelation("XContainer.Container", ctrlCont);
215 
216 
217         // adding relations for XUnoControlContainer
218         tEnv.addObjRelation("TABCONTROL1", tabControl1);
219         tEnv.addObjRelation("TABCONTROL2", tabControl2);
220 
221 
222         // adding relations for XControlContainer
223         tEnv.addObjRelation("CONTROL1", butControl1);
224         tEnv.addObjRelation("CONTROL2", butControl2);
225 
226         XWindow forObjRel = xTextDoc.getCurrentController().getFrame()
227                                     .getComponentWindow();
228         tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
229 
230         return tEnv;
231     } // finish method getTestEnvironment
232 
233     protected void cleanup(TestParameters tParam, PrintWriter log) {
234         log.println("Disposing dialog ...");
235         xWinDlg.dispose();
236         log.println("    disposing xTextDoc ");
237 
238         util.DesktopTools.closeDoc(xTextDoc);
239     }
240 
241     protected void initialize(TestParameters tParam, PrintWriter log) {
242         SOfficeFactory SOF = SOfficeFactory.getFactory(
243                                      (XMultiServiceFactory) tParam.getMSF());
244 
245         try {
246             log.println("creating a textdocument");
247             xTextDoc = SOF.createTextDoc(null);
248         } catch (com.sun.star.uno.Exception e) {
249             // Some exception occures.FAILED
250             e.printStackTrace(log);
251             throw new StatusException("Couldn't create document", e);
252         }
253     }
254 }
255