xref: /AOO41X/main/qadevOOo/tests/java/mod/_svx/AccessiblePresentationShape.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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.DrawTools;
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.beans.XPropertySet;
46 import com.sun.star.drawing.XShape;
47 import com.sun.star.frame.XModel;
48 import com.sun.star.lang.XComponent;
49 import com.sun.star.lang.XMultiServiceFactory;
50 import com.sun.star.uno.UnoRuntime;
51 import com.sun.star.uno.XInterface;
52 
53 public class AccessiblePresentationShape extends TestCase {
54 
55     static XComponent xDrawDoc;
56     static XModel aModel;
57 
58     protected void initialize( TestParameters tParam, PrintWriter log ) {
59 
60         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
61 
62         try {
63             log.println( "creating a drawdoc" );
64             xDrawDoc = SOF.createImpressDoc(null);
65             aModel = (XModel)
66                 UnoRuntime.queryInterface(XModel.class, xDrawDoc);
67 
68         } catch ( com.sun.star.uno.Exception e ) {
69             // Some exception occures.FAILED
70             e.printStackTrace( log );
71             throw new StatusException( "Couldn't create document", e );
72         }
73     }
74 
75     /**
76      * Disposes the Draw document loaded before.
77      */
78     protected void cleanup( TestParameters tParam, PrintWriter log ) {
79         log.println( "    disposing xDrawDoc " );
80         util.DesktopTools.closeDoc(xDrawDoc);
81     }
82 
83     protected TestEnvironment createTestEnvironment
84             (TestParameters tParam, PrintWriter log) {
85 
86         XInterface oObj = null;
87         XShape oShape = null;
88 
89         // creation of testobject here
90         // first we write what we are intend to do to log file
91         log.println( "creating a test environment" );
92 
93         XMultiServiceFactory docMSF = (XMultiServiceFactory)
94             UnoRuntime.queryInterface(XMultiServiceFactory.class, xDrawDoc);
95         try {
96             oShape = (XShape) UnoRuntime.queryInterface(XShape.class,
97                 docMSF.createInstance
98                 ("com.sun.star.presentation.HandoutShape"));
99         } catch (com.sun.star.uno.Exception e) {
100             throw new StatusException("couldn't create component", e);
101         }
102 
103 
104         DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
105 
106         XPropertySet shapeProps = (XPropertySet)
107                         UnoRuntime.queryInterface(XPropertySet.class, oShape);
108 
109         try {
110             shapeProps.setPropertyValue(
111                                 "IsEmptyPresentationObject", new Boolean(false));
112         } catch (Exception e) {}
113 
114         AccessibilityTools at = new AccessibilityTools();
115 
116         XWindow xWindow = at.getCurrentWindow ((XMultiServiceFactory)tParam.getMSF(),aModel);
117         XAccessible xRoot = at.getAccessibleObject(xWindow);
118 
119         at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
120 //        oObj = at.getAccessibleObjectForRole
121 //            (xRoot, AccessibleRole.SHAPE, "ImpressHandout");
122         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.UNKNOWN, "ImpressHandout");
123 
124         log.println("Implementation Name: "+utils.getImplName(oObj));
125 
126         // create test environment here
127         TestEnvironment tEnv = new TestEnvironment( oObj );
128 
129         final XShape fShape = oShape ;
130         tEnv.addObjRelation("EventProducer",
131             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
132                 public void fireEvent() {
133                     try {
134                         Size size = fShape.getSize();
135                         size.Width += 100;
136                         fShape.setSize(size);
137                     } catch(com.sun.star.beans.PropertyVetoException e) {}
138                 }
139             });
140 
141         log.println("Implementation Name: " + utils.getImplName(oObj));
142 
143         return tEnv;
144     } // finish method getTestEnvironment
145 
146 }
147 
148