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._toolkit;
24 
25 import com.sun.star.awt.XControlModel;
26 import com.sun.star.awt.XWindow;
27 import com.sun.star.awt.XWindowPeer;
28 import com.sun.star.drawing.XControlShape;
29 import com.sun.star.drawing.XShape;
30 import com.sun.star.frame.XController;
31 import com.sun.star.frame.XModel;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.text.XTextDocument;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XInterface;
36 import com.sun.star.view.XControlAccess;
37 
38 import java.io.PrintWriter;
39 
40 import lib.StatusException;
41 import lib.TestCase;
42 import lib.TestEnvironment;
43 import lib.TestParameters;
44 
45 import util.FormTools;
46 import util.SOfficeFactory;
47 import util.WriterTools;
48 import util.utils;
49 
50 
51 /**
52 * Test for <code>com.sun.star.awt.Toolkit</code> service.
53 */
54 public class Toolkit extends TestCase {
55     private static XTextDocument xTextDoc;
56 
57     protected void initialize(TestParameters Param, PrintWriter log) {
58         SOfficeFactory SOF = SOfficeFactory.getFactory(
59                                      (XMultiServiceFactory) Param.getMSF());
60 
61         try {
62             log.println("creating a textdocument");
63             xTextDoc = SOF.createTextDoc(null);
64         } catch (com.sun.star.uno.Exception e) {
65             // Some exception occures.FAILED
66             e.printStackTrace(log);
67             throw new StatusException("Couldn't create document", e);
68         }
69     }
70 
71     protected void cleanup(TestParameters tParam, PrintWriter log) {
72         log.println("    disposing xTextDoc ");
73         util.DesktopTools.closeDoc(xTextDoc);
74         ;
75     }
76 
77     /**
78     * Creating a Testenvironment for the interfaces to be tested.
79     * Creates <code>com.sun.star.awt.Toolkit</code> service.
80     */
81     public TestEnvironment createTestEnvironment(TestParameters Param,
82                                                  PrintWriter log)
83                                           throws StatusException {
84         XInterface oObj = null;
85         XWindowPeer the_win = null;
86         XWindow win = null;
87 
88         //Insert a ControlShape and get the ControlModel
89         XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
90                                                             4500, 15000, 10000,
91                                                             "CommandButton");
92 
93         WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
94 
95         XControlModel the_Model = aShape.getControl();
96 
97         //Try to query XControlAccess
98         XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
99                                             XControlAccess.class,
100                                             xTextDoc.getCurrentController());
101         XController cntrlr = (XController) UnoRuntime.queryInterface(
102                                      XController.class,
103                                      xTextDoc.getCurrentController());
104 
105         //now get the toolkit
106         try {
107             win = cntrlr.getFrame().getContainerWindow();
108 
109 
110             //win = (XWindow) UnoRuntime.queryInterface(XWindow.class, ctrl) ;
111             the_win = the_access.getControl(the_Model).getPeer();
112             oObj = (XInterface) ((XMultiServiceFactory) Param.getMSF()).createInstance(
113                            "com.sun.star.awt.Toolkit");
114         } catch (com.sun.star.uno.Exception e) {
115             log.println("Couldn't get toolkit");
116             e.printStackTrace(log);
117             throw new StatusException("Couldn't get toolkit", e);
118         }
119 
120         XModel xModel = (XModel)UnoRuntime.queryInterface(XModel.class, xTextDoc);
121 
122         log.println("    creating a new environment for toolkit object");
123 
124         TestEnvironment tEnv = new TestEnvironment(oObj);
125 
126         log.println("Implementation Name: " + utils.getImplName(oObj));
127 
128         tEnv.addObjRelation("WINPEER", the_win);
129 
130         tEnv.addObjRelation("XModel", xModel);
131 
132 
133         // adding relation for XDataTransferProviderAccess
134         tEnv.addObjRelation("XDataTransferProviderAccess.XWindow", win);
135 
136         return tEnv;
137     } // finish method getTestEnvironment
138 } // finish class Toolkit
139