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 
24 
25 package mod._basctl;
26 
27 import com.sun.star.accessibility.AccessibleRole;
28 import com.sun.star.accessibility.XAccessible;
29 import com.sun.star.awt.PosSize;
30 import com.sun.star.awt.Rectangle;
31 import com.sun.star.awt.XWindow;
32 import com.sun.star.beans.PropertyValue;
33 import com.sun.star.frame.XDesktop;
34 import com.sun.star.frame.XDispatchHelper;
35 import com.sun.star.frame.XDispatchProvider;
36 import com.sun.star.frame.XFrame;
37 import com.sun.star.frame.XModel;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.text.XTextDocument;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
42 import java.io.PrintWriter;
43 import lib.StatusException;
44 import lib.TestCase;
45 import lib.TestEnvironment;
46 import lib.TestParameters;
47 import util.AccessibilityTools;
48 import util.DesktopTools;
49 import util.WriterTools;
50 import util.utils;
51 
52 public class AccessibleShape extends TestCase {
53 
54     XTextDocument xTextDoc = null;
55     XInterface oObj = null;
56 
cleanup(TestParameters Param, PrintWriter log)57     protected void cleanup(TestParameters Param, PrintWriter log) {
58         log.println("Cleaning up");
59         DesktopTools.closeDoc(xTextDoc);
60         try {
61             XMultiServiceFactory xMSF = (XMultiServiceFactory) Param.getMSF();
62             Object o = xMSF.createInstance("com.sun.star.frame.Desktop");
63             XDesktop xDesk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, o);
64             DesktopTools.closeDoc(xDesk.getCurrentFrame());
65         } catch (Exception e) {
66             log.println("Couldn't close IDE");
67         }
68     }
69 
createTestEnvironment(TestParameters tParam, PrintWriter log)70     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
71         XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
72         log.println( "creating a test environment" );
73         String aURL=utils.getFullTestURL("basDialog.odt");
74         xTextDoc = WriterTools.loadTextDoc(xMSF,aURL);
75         XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xTextDoc);
76         XFrame xFrame = xModel.getCurrentController().getFrame();
77         XDispatchProvider xDPP = (XDispatchProvider) UnoRuntime.queryInterface(XDispatchProvider.class, xFrame);
78 
79         log.println( "opening the basic dialog editor" );
80         try {
81             Object o = xMSF.createInstance("com.sun.star.frame.DispatchHelper");
82             XDispatchHelper xDPH = (XDispatchHelper) UnoRuntime.queryInterface(XDispatchHelper.class, o);
83             PropertyValue[] aArgs = new PropertyValue[4];
84             aArgs[0] = new PropertyValue();
85             aArgs[0].Name = "Document";
86             aArgs[0].Value = aURL;
87             aArgs[1] = new PropertyValue();
88             aArgs[1].Name = "LibName";
89             aArgs[1].Value = "basctl";
90             aArgs[2] = new PropertyValue();
91             aArgs[2].Name = "Name";
92             aArgs[2].Value = "Dialog1";
93             aArgs[3] = new PropertyValue();
94             aArgs[3].Name = "Type";
95             aArgs[3].Value = "Dialog";
96             xDPH.executeDispatch(xDPP, ".uno:BasicIDEAppear", "", 0, aArgs);
97         } catch (Exception e) {
98             throw new StatusException("Couldn't open Basic Dialog",e);
99         }
100 
101         utils.shortWait(3000);
102 
103         try {
104             oObj = (XInterface) ((XMultiServiceFactory)tParam.getMSF()).createInstance
105                     ("com.sun.star.awt.Toolkit") ;
106         } catch (com.sun.star.uno.Exception e) {
107             log.println("Couldn't get toolkit");
108             e.printStackTrace(log);
109             throw new StatusException("Couldn't get toolkit", e );
110         }
111 
112         AccessibilityTools at = new AccessibilityTools();
113 
114         final XWindow basicIDE = xFrame.getContainerWindow();
115 
116         XAccessible xRoot = at.getAccessibleObject(basicIDE);
117 
118         at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
119 
120         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.SHAPE);
121 
122         // create test environment here
123         TestEnvironment tEnv = new TestEnvironment( oObj );
124 
125         log.println("Implementation Name: " + utils.getImplName(oObj));
126 
127         tEnv.addObjRelation("Destroy", Boolean.TRUE);
128 
129         tEnv.addObjRelation("EventProducer",
130                 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
131             public void fireEvent() {
132                 Rectangle oldPosSize = basicIDE.getPosSize();
133                 Rectangle newPosSize = new Rectangle();
134                 newPosSize.Width = oldPosSize.Width/2;
135                 newPosSize.Height = oldPosSize.Height/2;
136                 newPosSize.X = oldPosSize.X + 20;
137                 newPosSize.Y = oldPosSize.Y + 20;
138                 basicIDE.setPosSize(newPosSize.X, newPosSize.Y, newPosSize.Width,
139                                 newPosSize.Height, PosSize.POSSIZE);
140                 utils.shortWait(1000);
141                 basicIDE.setPosSize(oldPosSize.X, oldPosSize.Y, oldPosSize.Width,
142                                 oldPosSize.Height, PosSize.POSSIZE);
143             }
144         });
145 
146         return tEnv;
147     }
148 
149 
150 
151 }
152