1 /*
2  * This file is part of the LibreOffice project.
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
10  *   Licensed to the Apache Software Foundation (ASF) under one or more
11  *   contributor license agreements. See the NOTICE file distributed
12  *   with this work for additional information regarding copyright
13  *   ownership. The ASF licenses this file to you under the Apache
14  *   License, Version 2.0 (the "License"); you may not use this file
15  *   except in compliance with the License. You may obtain a copy of
16  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
17  */
18 package mod._toolkit;
19 
20 import com.sun.star.awt.XControl;
21 import com.sun.star.awt.XControlModel;
22 import com.sun.star.awt.XDevice;
23 import com.sun.star.awt.XGraphics;
24 import com.sun.star.awt.XToolkit;
25 import com.sun.star.awt.XWindow;
26 import com.sun.star.awt.XWindowPeer;
27 import com.sun.star.beans.XPropertySet;
28 import com.sun.star.drawing.XControlShape;
29 import com.sun.star.text.XTextDocument;
30 import com.sun.star.uno.UnoRuntime;
31 import com.sun.star.uno.XInterface;
32 import com.sun.star.view.XControlAccess;
33 
34 import java.io.PrintWriter;
35 
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.FormTools;
40 import util.SOfficeFactory;
41 import util.WriterTools;
42 import util.utils;
43 
44 
45 public class UnoControlImageControl extends TestCase {
46     private static XTextDocument xTextDoc;
47 
48     @Override
initialize(TestParameters Param, PrintWriter log)49     protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
50         SOfficeFactory SOF = SOfficeFactory.getFactory(
51                                      Param.getMSF());
52 
53         log.println("creating a textdocument");
54         xTextDoc = SOF.createTextDoc(null);
55     }
56 
57     @Override
cleanup(TestParameters tParam, PrintWriter log)58     protected void cleanup(TestParameters tParam, PrintWriter log) {
59         log.println("    disposing xTextDoc ");
60 
61         util.DesktopTools.closeDoc(xTextDoc);
62     }
63 
64     @Override
createTestEnvironment(TestParameters Param, PrintWriter log)65     protected TestEnvironment createTestEnvironment(TestParameters Param,
66                                                     PrintWriter log) throws Exception {
67         XInterface oObj = null;
68         XWindowPeer the_win = null;
69         XToolkit the_kit = null;
70         XDevice aDevice = null;
71         XGraphics aGraphic = null;
72         XControl aControl = null;
73 
74         //Insert a ControlShape and get the ControlModel
75         XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
76                                                                4500, 15000,
77                                                                10000,
78                                                                "DatabaseImageControl",
79                                                                "UnoControlImageControl");
80 
81         WriterTools.getDrawPage(xTextDoc).add(aShape);
82 
83         XControlModel the_Model = aShape.getControl();
84 
85         XPropertySet xPS = UnoRuntime.queryInterface(
86                                    XPropertySet.class, the_Model);
87 
88         XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
89                                                              4500, 5000, 10000,
90                                                              "TextField");
91 
92         WriterTools.getDrawPage(xTextDoc).add(aShape2);
93 
94         XControlModel the_Model2 = aShape2.getControl();
95 
96         //Try to query XControlAccess
97         XControlAccess the_access = UnoRuntime.queryInterface(
98                                             XControlAccess.class,
99                                             xTextDoc.getCurrentController());
100 
101         //get the ImageControlControl for the needed Object relations
102         oObj = the_access.getControl(the_Model);
103         aControl = the_access.getControl(the_Model2);
104         the_win = the_access.getControl(the_Model).getPeer();
105         the_kit = the_win.getToolkit();
106         aDevice = the_kit.createScreenCompatibleDevice(200, 200);
107         aGraphic = aDevice.createGraphics();
108 
109         String imgUrl = util.utils.getFullTestURL("poliball.gif");
110 
111         xPS.setPropertyValue("ImageURL", imgUrl);
112 
113         log.println(
114                 "creating a new environment for UnoControlImageControl object");
115 
116         TestEnvironment tEnv = new TestEnvironment(oObj);
117 
118 
119         //Adding ObjRelation for XView
120         tEnv.addObjRelation("GRAPHICS", aGraphic);
121 
122 
123         //Adding ObjRelation for XControl
124         tEnv.addObjRelation("CONTEXT", xTextDoc);
125         tEnv.addObjRelation("WINPEER", the_win);
126         tEnv.addObjRelation("TOOLKIT", the_kit);
127         tEnv.addObjRelation("MODEL", the_Model);
128 
129         XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class,
130                                                                 aControl);
131 
132         tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
133 
134         System.out.println("ImplementationName: " + utils.getImplName(oObj));
135 
136         return tEnv;
137     } // finish method getTestEnvironment
138 } // finish class UnoControlImageControl
139