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 java.io.PrintWriter;
26 
27 import lib.StatusException;
28 import lib.TestCase;
29 import lib.TestEnvironment;
30 import lib.TestParameters;
31 import util.FormTools;
32 import util.SOfficeFactory;
33 import util.WriterTools;
34 import util.utils;
35 
36 import com.sun.star.awt.XControl;
37 import com.sun.star.awt.XControlModel;
38 import com.sun.star.awt.XDevice;
39 import com.sun.star.awt.XGraphics;
40 import com.sun.star.awt.XTextComponent;
41 import com.sun.star.awt.XToolkit;
42 import com.sun.star.awt.XWindow;
43 import com.sun.star.awt.XWindowPeer;
44 import com.sun.star.drawing.XControlShape;
45 import com.sun.star.drawing.XShape;
46 import com.sun.star.lang.XMultiServiceFactory;
47 import com.sun.star.text.XTextDocument;
48 import com.sun.star.uno.UnoRuntime;
49 import com.sun.star.uno.XInterface;
50 import com.sun.star.util.XCloseable;
51 import com.sun.star.view.XControlAccess;
52 
53 
54 public class UnoControlComboBox extends TestCase {
55     private static XTextDocument xTextDoc;
56 
initialize(TestParameters Param, PrintWriter log)57     protected void initialize(TestParameters Param, PrintWriter log) {
58         SOfficeFactory SOF = SOfficeFactory.getFactory( (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 occures.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                                                                "ComboBox",
90                                                                "UnoControlComboBox");
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 ComboBoxControl 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 ComboBoxControl");
119             e.printStackTrace(log);
120             throw new StatusException("Couldn't get ComboBoxControl", e);
121         }
122 
123         log.println("creating a new environment for UnoControlComboBox 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         tEnv.addObjRelation("XWindow.ControlShape", aShape);
143 
144         // Adding relation for XTextListener
145         ifc.awt._XTextListener.TestTextListener listener =
146                 new ifc.awt._XTextListener.TestTextListener();
147         XTextComponent textComp = (XTextComponent) UnoRuntime.queryInterface(
148                                           XTextComponent.class, oObj);
149         textComp.addTextListener(listener);
150         tEnv.addObjRelation("TestTextListener", listener);
151 
152         log.println("ImplementationName: " + utils.getImplName(oObj));
153 
154         return tEnv;
155     } // finish method getTestEnvironment
156 } // finish class UnoControlComboBox
157