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.XCheckBox;
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.frame.XController;
35 import com.sun.star.frame.XFrame;
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 public class UnoControlCheckBox extends TestCase {
56     private static XTextDocument xTextDoc;
57     private static XTextDocument xTD2;
58 
initialize(TestParameters Param, PrintWriter log)59     protected void initialize(TestParameters Param, PrintWriter log) {
60         SOfficeFactory SOF = SOfficeFactory.getFactory(
61                                      (XMultiServiceFactory) Param.getMSF());
62 
63         try {
64             log.println("creating a textdocument");
65             xTextDoc = SOF.createTextDoc(null);
66             xTD2 = WriterTools.createTextDoc(
67                            (XMultiServiceFactory) Param.getMSF());
68         } catch (com.sun.star.uno.Exception e) {
69             // Some exception occured.FAILED
70             e.printStackTrace(log);
71             throw new StatusException("Couldn't create document", e);
72         }
73     }
74 
cleanup(TestParameters tParam, PrintWriter log)75     protected void cleanup(TestParameters tParam, PrintWriter log) {
76         log.println("    disposing xTextDoc ");
77 
78         util.DesktopTools.closeDoc(xTextDoc);
79         util.DesktopTools.closeDoc(xTD2);
80     }
81 
createTestEnvironment(TestParameters Param, PrintWriter log)82     protected TestEnvironment createTestEnvironment(TestParameters Param,
83                                                     PrintWriter log) {
84         XInterface oObj = null;
85         XWindowPeer the_win = null;
86         XToolkit the_kit = null;
87         XDevice aDevice = null;
88         XGraphics aGraphic = null;
89         XWindow anotherWindow = null;
90 
91         //Insert a ControlShape and get the ControlModel
92         XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
93                                                                4500, 15000,
94                                                                10000,
95                                                                "CheckBox",
96                                                                "UnoControlCheckBox");
97 
98         WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
99 
100         XControlModel the_Model = aShape.getControl();
101 
102         //Try to query XControlAccess
103         XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
104                                             XControlAccess.class,
105                                             xTextDoc.getCurrentController());
106 
107         //get the CheckBoxControl for the needed Object relations
108         try {
109             oObj = the_access.getControl(the_Model);
110             the_win = the_access.getControl(the_Model).getPeer();
111             the_kit = the_win.getToolkit();
112             aDevice = the_kit.createScreenCompatibleDevice(200, 200);
113             aGraphic = aDevice.createGraphics();
114         } catch (Exception e) {
115             log.println("Couldn't get CheckBoxControl");
116             e.printStackTrace(log);
117             throw new StatusException("Couldn't get CheckBoxControl", e);
118         }
119 
120         log.println("creating a new environment for UnoControlCheckBox object");
121 
122         TestEnvironment tEnv = new TestEnvironment(oObj);
123 
124 
125         //Adding ObjRelation for XView
126         tEnv.addObjRelation("GRAPHICS", aGraphic);
127 
128 
129         //Adding ObjRelation for XControl
130         tEnv.addObjRelation("CONTEXT", xTextDoc);
131         tEnv.addObjRelation("WINPEER", the_win);
132         tEnv.addObjRelation("TOOLKIT", the_kit);
133         tEnv.addObjRelation("MODEL", the_Model);
134 
135         // adding object relation for XItemListener
136         ifc.awt._XItemListener.TestItemListener listener =
137                 new ifc.awt._XItemListener.TestItemListener();
138         XCheckBox check = (XCheckBox) UnoRuntime.queryInterface(
139                                   XCheckBox.class, oObj);
140         check.addItemListener(listener);
141         tEnv.addObjRelation("TestItemListener", listener);
142 
143         System.out.println("ImplementationName: " + utils.getImplName(oObj));
144 
145         try {
146             XController aController = xTD2.getCurrentController();
147             XFrame aFrame = aController.getFrame();
148             anotherWindow = aFrame.getComponentWindow();
149         } catch (Exception e) {
150             e.printStackTrace(log);
151             throw new StatusException("Couldn't create XWindow", e);
152         }
153 
154 
155         // Object Relation for XWindow
156         tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow);
157 
158         return tEnv;
159     } // finish method getTestEnvironment
160 } // finish class UnoControlCheckBox
161