1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 
29 package mod._basctl;
30 
31 import com.sun.star.accessibility.AccessibleRole;
32 import com.sun.star.accessibility.XAccessible;
33 import com.sun.star.awt.PosSize;
34 import com.sun.star.awt.Rectangle;
35 import com.sun.star.awt.XWindow;
36 import com.sun.star.beans.PropertyValue;
37 import com.sun.star.frame.XDesktop;
38 import com.sun.star.frame.XDispatchHelper;
39 import com.sun.star.frame.XDispatchProvider;
40 import com.sun.star.frame.XFrame;
41 import com.sun.star.frame.XModel;
42 import com.sun.star.lang.XMultiServiceFactory;
43 import com.sun.star.text.XTextDocument;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
46 import java.io.PrintWriter;
47 import lib.StatusException;
48 import lib.TestCase;
49 import lib.TestEnvironment;
50 import lib.TestParameters;
51 import util.AccessibilityTools;
52 import util.DesktopTools;
53 import util.WriterTools;
54 import util.utils;
55 
56 public class AccessibleShape extends TestCase {
57 
58     XTextDocument xTextDoc = null;
59     XInterface oObj = null;
60 
61     protected void cleanup(TestParameters Param, PrintWriter log) {
62         log.println("Cleaning up");
63         DesktopTools.closeDoc(xTextDoc);
64         try {
65             XMultiServiceFactory xMSF = (XMultiServiceFactory) Param.getMSF();
66             Object o = xMSF.createInstance("com.sun.star.frame.Desktop");
67             XDesktop xDesk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, o);
68             DesktopTools.closeDoc(xDesk.getCurrentFrame());
69         } catch (Exception e) {
70             log.println("Couldn't close IDE");
71         }
72     }
73 
74     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
75         XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
76         log.println( "creating a test environment" );
77         String aURL=utils.getFullTestURL("basDialog.odt");
78         xTextDoc = WriterTools.loadTextDoc(xMSF,aURL);
79         XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xTextDoc);
80         XFrame xFrame = xModel.getCurrentController().getFrame();
81         XDispatchProvider xDPP = (XDispatchProvider) UnoRuntime.queryInterface(XDispatchProvider.class, xFrame);
82 
83         log.println( "opening the basic dialog editor" );
84         try {
85             Object o = xMSF.createInstance("com.sun.star.frame.DispatchHelper");
86             XDispatchHelper xDPH = (XDispatchHelper) UnoRuntime.queryInterface(XDispatchHelper.class, o);
87             PropertyValue[] aArgs = new PropertyValue[4];
88             aArgs[0] = new PropertyValue();
89             aArgs[0].Name = "Document";
90             aArgs[0].Value = aURL;
91             aArgs[1] = new PropertyValue();
92             aArgs[1].Name = "LibName";
93             aArgs[1].Value = "basctl";
94             aArgs[2] = new PropertyValue();
95             aArgs[2].Name = "Name";
96             aArgs[2].Value = "Dialog1";
97             aArgs[3] = new PropertyValue();
98             aArgs[3].Name = "Type";
99             aArgs[3].Value = "Dialog";
100             xDPH.executeDispatch(xDPP, ".uno:BasicIDEAppear", "", 0, aArgs);
101         } catch (Exception e) {
102             throw new StatusException("Couldn't open Basic Dialog",e);
103         }
104 
105         utils.shortWait(3000);
106 
107         try {
108             oObj = (XInterface) ((XMultiServiceFactory)tParam.getMSF()).createInstance
109                     ("com.sun.star.awt.Toolkit") ;
110         } catch (com.sun.star.uno.Exception e) {
111             log.println("Couldn't get toolkit");
112             e.printStackTrace(log);
113             throw new StatusException("Couldn't get toolkit", e );
114         }
115 
116         AccessibilityTools at = new AccessibilityTools();
117 
118         final XWindow basicIDE = xFrame.getContainerWindow();
119 
120         XAccessible xRoot = at.getAccessibleObject(basicIDE);
121 
122         at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
123 
124         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.SHAPE);
125 
126         // create test environment here
127         TestEnvironment tEnv = new TestEnvironment( oObj );
128 
129         log.println("Implementation Name: " + utils.getImplName(oObj));
130 
131         tEnv.addObjRelation("Destroy", Boolean.TRUE);
132 
133         tEnv.addObjRelation("EventProducer",
134                 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
135             public void fireEvent() {
136                 Rectangle oldPosSize = basicIDE.getPosSize();
137                 Rectangle newPosSize = new Rectangle();
138                 newPosSize.Width = oldPosSize.Width/2;
139                 newPosSize.Height = oldPosSize.Height/2;
140                 newPosSize.X = oldPosSize.X + 20;
141                 newPosSize.Y = oldPosSize.Y + 20;
142                 basicIDE.setPosSize(newPosSize.X, newPosSize.Y, newPosSize.Width,
143                                 newPosSize.Height, PosSize.POSSIZE);
144                 utils.shortWait(1000);
145                 basicIDE.setPosSize(oldPosSize.X, oldPosSize.Y, oldPosSize.Width,
146                                 oldPosSize.Height, PosSize.POSSIZE);
147             }
148         });
149 
150         return tEnv;
151     }
152 
153 
154 
155 }
156