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.XControl;
26 import com.sun.star.awt.XControlModel;
27 import com.sun.star.awt.XDevice;
28 import com.sun.star.awt.XGraphics;
29 import com.sun.star.awt.XToolkit;
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.lang.XMultiServiceFactory;
35 import com.sun.star.text.XTextDocument;
36 import com.sun.star.uno.UnoRuntime;
37 import com.sun.star.uno.XInterface;
38 import com.sun.star.view.XControlAccess;
39 
40 import java.io.PrintWriter;
41 
42 import lib.StatusException;
43 import lib.TestCase;
44 import lib.TestEnvironment;
45 import lib.TestParameters;
46 
47 import util.FormTools;
48 import util.SOfficeFactory;
49 import util.WriterTools;
50 import util.utils;
51 
52 
53 public class UnoControlGroupBox extends TestCase {
54     private static XTextDocument xTextDoc;
55 
initialize(TestParameters Param, PrintWriter log)56     protected void initialize(TestParameters Param, PrintWriter log) {
57         SOfficeFactory SOF = SOfficeFactory.getFactory(
58                                      (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 occured.FAILED
65             e.printStackTrace(log);
66             throw new StatusException("Couldn't create document", e);
67         }
68     }
69 
cleanup(TestParameters tParam, PrintWriter log)70     protected void cleanup(TestParameters tParam, PrintWriter log) {
71         log.println("    disposing xTextDoc ");
72 
73         util.DesktopTools.closeDoc(xTextDoc);
74     }
75 
createTestEnvironment(TestParameters Param, PrintWriter log)76     protected TestEnvironment createTestEnvironment(TestParameters Param,
77                                                     PrintWriter log) {
78         XInterface oObj = null;
79         XWindowPeer the_win = null;
80         XToolkit the_kit = null;
81         XDevice aDevice = null;
82         XGraphics aGraphic = null;
83         XControl aControl = null;
84 
85         //Insert a ControlShape and get the ControlModel
86         XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
87                                                                4500, 15000,
88                                                                10000,
89                                                                "GroupBox",
90                                                                "UnoControlGroupBox");
91 
92         WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
93 
94         XControlModel the_Model = aShape.getControl();
95 
96         XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
97                                                              4500, 5000, 10000,
98                                                              "TextField");
99 
100         WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2);
101 
102         XControlModel the_Model2 = aShape2.getControl();
103 
104         //Try to query XControlAccess
105         XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
106                                             XControlAccess.class,
107                                             xTextDoc.getCurrentController());
108 
109         //get the GroupBoxControl for the needed Object relations
110         try {
111             oObj = the_access.getControl(the_Model);
112             aControl = the_access.getControl(the_Model2);
113             the_win = the_access.getControl(the_Model).getPeer();
114             the_kit = the_win.getToolkit();
115             aDevice = the_kit.createScreenCompatibleDevice(200, 200);
116             aGraphic = aDevice.createGraphics();
117         } catch (Exception e) {
118             log.println("Couldn't get GroupBoxControl");
119             e.printStackTrace(log);
120             throw new StatusException("Couldn't get GroupBoxControl", e);
121         }
122 
123         log.println("creating a new environment for UnoControlGroupBox object");
124 
125         TestEnvironment tEnv = new TestEnvironment(oObj);
126 
127 
128         //Adding ObjRelation for XView
129         tEnv.addObjRelation("GRAPHICS", aGraphic);
130 
131 
132         //Adding ObjRelation for XControl
133         tEnv.addObjRelation("CONTEXT", xTextDoc);
134         tEnv.addObjRelation("WINPEER", the_win);
135         tEnv.addObjRelation("TOOLKIT", the_kit);
136         tEnv.addObjRelation("MODEL", the_Model);
137 
138         XWindow forObjRel = (XWindow) UnoRuntime.queryInterface(XWindow.class,
139                                                                 aControl);
140 
141         tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
142 
143         System.out.println("ImplementationName: " + utils.getImplName(oObj));
144 
145         return tEnv;
146     } // finish method getTestEnvironment
147 } // finish class UnoControlGroupBox
148