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 AccessibleOLEShape 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.createDrawDoc(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 
88         // creation of testobject here
89         // first we write what we are intend to do to log file
90         log.println( "creating a test environment" );
91 
92         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
93         final XShape oShape = SOF.createShape
94             (xDrawDoc,5000,5000,1500,1000,"OLE2");
95 
96         DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
97 
98         XPropertySet shape_props = (XPropertySet)
99                         UnoRuntime.queryInterface(XPropertySet.class,oShape);
100 
101         log.println("Inserting a Chart");
102 
103         try {
104             shape_props.
105                 setPropertyValue("CLSID","12DCAE26-281F-416F-a234-c3086127382e");
106         } catch (com.sun.star.lang.WrappedTargetException e) {
107             e.printStackTrace(log);
108             throw new StatusException("Couldn't change property", e);
109         } catch (com.sun.star.lang.IllegalArgumentException e) {
110             e.printStackTrace(log);
111             throw new StatusException("Couldn't change property", e);
112         } catch (com.sun.star.beans.PropertyVetoException e) {
113             e.printStackTrace(log);
114             throw new StatusException("Couldn't change property", e);
115         } catch (com.sun.star.beans.UnknownPropertyException e) {
116             e.printStackTrace(log);
117             throw new StatusException("Couldn't change property", e);
118         }
119 
120         AccessibilityTools at = new AccessibilityTools();
121 
122         XWindow xWindow = at.getCurrentWindow ((XMultiServiceFactory)tParam.getMSF(),aModel);
123         XAccessible xRoot = at.getAccessibleObject(xWindow);
124 
125         at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
126 
127 //        oObj = at.getAccessibleObjectForRole
128 //            (xRoot, AccessibleRole.SHAPE, "OLEShape");
129         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.UNKNOWN, "OLEShape");
130 
131         // create test environment here
132         TestEnvironment tEnv = new TestEnvironment( oObj );
133 
134         tEnv.addObjRelation("EventProducer",
135             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
136                 public void fireEvent() {
137                     try {
138                         Size size = oShape.getSize();
139                         size.Width += 100;
140                         oShape.setSize(size);
141                     } catch(com.sun.star.beans.PropertyVetoException e) {}
142                 }
143             });
144 
145         log.println("Implementation Name: " + utils.getImplName(oObj));
146 
147         return tEnv;
148     } // finish method getTestEnvironment
149 
150 }
151 
152