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