1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package mod._forms;
24 
25 import java.io.PrintWriter;
26 
27 import lib.StatusException;
28 import lib.TestCase;
29 import lib.TestEnvironment;
30 import lib.TestParameters;
31 import util.FormTools;
32 import util.SOfficeFactory;
33 import util.WriterTools;
34 
35 import com.sun.star.awt.XControl;
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.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 util.DesktopTools;
50 
51 public class ONavigationBarControl extends TestCase {
52     XTextDocument xTextDoc;
53 
54     /**
55      * Creates a text document.
56      */
initialize(TestParameters Param, PrintWriter log)57     protected void initialize(TestParameters Param, PrintWriter log) {
58         SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory) Param.getMSF());
59 
60         try {
61             log.println("creating a textdocument");
62             xTextDoc = SOF.createTextDoc(null);
63         } catch (com.sun.star.uno.Exception e) {
64             // Some exception occures.FAILED
65             e.printStackTrace(log);
66             throw new StatusException("Couldn't create document", e);
67         }
68     }
69 
70     /**
71      * Disposes the text document created before
72      */
cleanup(TestParameters tParam, PrintWriter log)73     protected void cleanup(TestParameters tParam, PrintWriter log) {
74         log.println("    disposing xTextDoc ");
75 
76         DesktopTools.closeDoc(xTextDoc);
77     }
78 
79     /**
80      * Creates two components and inserts them to the form of
81      * text document. One component
82      * (<code>com.sun.star.form.component.CommandButton</code>) is created
83      * for testing, another to be passed as relation. Using a controller
84      * of the text document the controller of the first component is
85      * obtained and returned in environment as a test object. <p>
86      *
87      *     Object relations created :
88      * <ul>
89      *  <li> <code>'GRAPHICS'</code> for
90      *      {@link ifc.awt._XView} : a graphics component
91      *      created using screen device of the window peer of
92      *      the controller tested. </li>
93      *  <li> <code>'CONTEXT'</code> for
94      *      {@link ifc.awt._XControl} : the text document
95      *      where the component is inserted. </li>
96      *  <li> <code>'WINPEER'</code> for
97      *      {@link ifc.awt._XControl} : Window peer of the
98      *      controller tested. </li>
99      *  <li> <code>'TOOLKIT'</code> for
100      *      {@link ifc.awt._XControl} : toolkit of the component.</li>
101      *  <li> <code>'MODEL'</code> for
102      *      {@link ifc.awt._XControl} : the model of the controller.</li>
103      *  <li> <code>'XWindow.AnotherWindow'</code> for
104      *      {@link ifc.awt._XWindow} : the controller of another
105      *      component. </li>
106      * </ul>
107      */
createTestEnvironment(TestParameters Param, PrintWriter log)108     protected TestEnvironment createTestEnvironment(TestParameters Param,
109                                                     PrintWriter log) {
110         XInterface oObj = null;
111         XWindowPeer the_win = null;
112         XToolkit the_kit = null;
113         XDevice aDevice = null;
114         XGraphics aGraphic = null;
115         XControl aControl = null;
116 
117         //Insert a ControlShape and get the ControlModel
118         XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
119                                                             4500, 15000, 10000,
120                                                             "NavigationToolBar");
121 
122         WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
123 
124         XControlModel the_Model = aShape.getControl();
125 
126         XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
127                                                              4500, 5000, 10000,
128                                                              "TextField");
129 
130         WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2);
131 
132         XControlModel the_Model2 = aShape2.getControl();
133 
134         //Try to query XControlAccess
135         XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
136                                             XControlAccess.class,
137                                             xTextDoc.getCurrentController());
138 
139         //now get the OButtonControl
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 (com.sun.star.container.NoSuchElementException e) {
148             log.println("Couldn't get ONavigationBarControl");
149             e.printStackTrace(log);
150             throw new StatusException("Couldn't get ONavigationBarControl", e);
151         }
152 
153         log.println("creating a new environment for ONavigationBarControl object");
154 
155         TestEnvironment tEnv = new TestEnvironment(oObj);
156 
157 
158         //Adding ObjRelation for XView
159         tEnv.addObjRelation("GRAPHICS", aGraphic);
160 
161 
162         //Adding ObjRelation for XControl
163         tEnv.addObjRelation("CONTEXT", xTextDoc);
164         tEnv.addObjRelation("WINPEER", the_win);
165         tEnv.addObjRelation("TOOLKIT", the_kit);
166         tEnv.addObjRelation("MODEL", the_Model);
167 
168         XWindow forObjRel = (XWindow) UnoRuntime.queryInterface(XWindow.class,
169                                                                 aControl);
170 
171         tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
172         tEnv.addObjRelation("XWindow.ControlShape", aShape);
173 
174         return tEnv;
175     } // finish method getTestEnvironment
176 } // finish class ONavigationBarControl
177