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.WriterTools;
49 import util.utils;
50 
51 
52 public class UnoSpinButtonControl extends TestCase {
53     private static XTextDocument xTextDoc;
54 
initialize(TestParameters Param, PrintWriter log)55     protected void initialize(TestParameters Param, PrintWriter log) {
56         log.println("creating a textdocument");
57         xTextDoc = WriterTools.createTextDoc(
58                            (XMultiServiceFactory) Param.getMSF());
59     }
60 
cleanup(TestParameters tParam, PrintWriter log)61     protected void cleanup(TestParameters tParam, PrintWriter log) {
62         log.println("    disposing xTextDoc ");
63 
64         util.DesktopTools.closeDoc(xTextDoc);
65     }
66 
createTestEnvironment(TestParameters Param, PrintWriter log)67     protected TestEnvironment createTestEnvironment(TestParameters Param,
68                                                     PrintWriter log) {
69         XInterface oObj = null;
70         XWindowPeer the_win = null;
71         XToolkit the_kit = null;
72         XDevice aDevice = null;
73         XGraphics aGraphic = null;
74         XControl aControl = null;
75 
76         //Insert a ControlShape and get the ControlModel
77         XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
78                                                                4500, 15000,
79                                                                10000,
80                                                                "SpinButton",
81                                                                "UnoControlSpinButton");
82 
83         WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
84 
85         XControlModel the_Model = aShape.getControl();
86 
87         XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
88                                                              4500, 5000, 10000,
89                                                              "TextField");
90 
91         WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2);
92 
93         XControlModel the_Model2 = aShape2.getControl();
94 
95         //Try to query XControlAccess
96         XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
97                                             XControlAccess.class,
98                                             xTextDoc.getCurrentController());
99 
100         //get the SpinButtonControl for the needed Object relations
101         try {
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         } catch (Exception e) {
109             log.println("Couldn't get SpinButtonControl");
110             e.printStackTrace(log);
111             throw new StatusException("Couldn't get SpinButtonControl", e);
112         }
113 
114         log.println(
115                 "creating a new environment for UnoControlSpinButton object");
116 
117         TestEnvironment tEnv = new TestEnvironment(oObj);
118 
119 
120         //adding Object-Relation for XScrollBar
121         tEnv.addObjRelation("Document", xTextDoc);
122 
123 
124         //Adding ObjRelation for XView
125         tEnv.addObjRelation("GRAPHICS", aGraphic);
126 
127 
128         //Adding ObjRelation for XControl
129         tEnv.addObjRelation("CONTEXT", xTextDoc);
130         tEnv.addObjRelation("WINPEER", the_win);
131         tEnv.addObjRelation("TOOLKIT", the_kit);
132         tEnv.addObjRelation("MODEL", the_Model);
133 
134         XWindow forObjRel = (XWindow) UnoRuntime.queryInterface(XWindow.class,
135                                                                 aControl);
136 
137         tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
138 
139         tEnv.addObjRelation("Document", xTextDoc);
140 
141         System.out.println("ImplementationName: " + utils.getImplName(oObj));
142 
143         return tEnv;
144     } // finish method getTestEnvironment
145 }
146