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 package mod._svx;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.AccessibilityTools;
37 import util.FormTools;
38 import util.SOfficeFactory;
39 import util.utils;
40 
41 import com.sun.star.accessibility.AccessibleRole;
42 import com.sun.star.accessibility.XAccessible;
43 import com.sun.star.awt.Size;
44 import com.sun.star.awt.XWindow;
45 import com.sun.star.drawing.XShape;
46 import com.sun.star.frame.XModel;
47 import com.sun.star.lang.XComponent;
48 import com.sun.star.lang.XMultiServiceFactory;
49 import com.sun.star.uno.UnoRuntime;
50 import com.sun.star.uno.XInterface;
51 
52 public class AccessibleControlShape extends TestCase {
53 
54     static XComponent xDrawDoc;
55     static XModel aModel;
56 
57     protected void initialize( TestParameters tParam, PrintWriter log ) {
58 
59         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
60 
61         try {
62             log.println( "creating a drawdoc" );
63             xDrawDoc = SOF.createDrawDoc(null);
64             aModel = (XModel)
65                 UnoRuntime.queryInterface(XModel.class, xDrawDoc);
66 
67         } catch ( com.sun.star.uno.Exception e ) {
68             // Some exception occures.FAILED
69             e.printStackTrace( log );
70             throw new StatusException( "Couldn't create document", e );
71         }
72     }
73 
74     /**
75      * Disposes the Draw document loaded before.
76      */
77     protected void cleanup( TestParameters tParam, PrintWriter log ) {
78         log.println( "    disposing xDrawDoc " );
79         util.DesktopTools.closeDoc(xDrawDoc);
80     }
81 
82     protected TestEnvironment createTestEnvironment
83             (TestParameters tParam, PrintWriter log) {
84 
85         XInterface oObj = null;
86 
87         log.println( "creating a test environment" );
88 
89         final XShape oShape = FormTools.insertControlShape
90             (xDrawDoc,3000,4500,15000,1000,"CommandButton");
91 
92         AccessibilityTools at = new AccessibilityTools();
93         utils.shortWait(5000);
94         XWindow xWindow = at.getCurrentWindow ((XMultiServiceFactory)tParam.getMSF(),aModel);
95         XAccessible xRoot = at.getAccessibleObject(xWindow);
96 
97         at.getAccessibleObjectForRole(xRoot, AccessibleRole.SHAPE);
98 
99         at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
100 
101 //        oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.SHAPE,
102 //            "Button");
103         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.UNKNOWN, "Button");
104 
105         // create test environment here
106         TestEnvironment tEnv = new TestEnvironment( oObj );
107 
108         tEnv.addObjRelation("EventProducer",
109             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
110                 public void fireEvent() {
111                     try {
112                         Size size = oShape.getSize();
113                         size.Width += 100;
114                         oShape.setSize(size);
115                     } catch(com.sun.star.beans.PropertyVetoException e) {}
116                 }
117             });
118 
119         log.println("Implementation Name: " + utils.getImplName(oObj));
120 
121         return tEnv;
122     } // finish method getTestEnvironment
123 
124 }
125 
126