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 package mod._sw;
24 
25 import java.io.PrintWriter;
26 
27 import lib.StatusException;
28 import lib.TestCase;
29 import lib.TestEnvironment;
30 import lib.TestParameters;
31 import util.AccessibilityTools;
32 import util.SOfficeFactory;
33 import util.WriterTools;
34 import util.utils;
35 
36 import com.sun.star.accessibility.AccessibleRole;
37 import com.sun.star.accessibility.XAccessible;
38 import com.sun.star.awt.XWindow;
39 import com.sun.star.beans.XPropertySet;
40 import com.sun.star.frame.XController;
41 import com.sun.star.frame.XModel;
42 import com.sun.star.lang.XMultiServiceFactory;
43 import com.sun.star.text.TextContentAnchorType;
44 import com.sun.star.text.XText;
45 import com.sun.star.text.XTextContent;
46 import com.sun.star.text.XTextCursor;
47 import com.sun.star.text.XTextDocument;
48 import com.sun.star.text.XTextFrame;
49 import com.sun.star.uno.UnoRuntime;
50 import com.sun.star.uno.XInterface;
51 import com.sun.star.view.XViewSettingsSupplier;
52 
53 /**
54 * Test of accessible object for the text frame of a text document.<p>
55 * Object implements the following interfaces :
56 * <ul>
57 *  <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
58 * </ul>
59 * @see com.sun.star.accessibility.XAccessible
60 */
61 public class SwAccessibleTextFrameView extends TestCase {
62 
63     XTextDocument xTextDoc = null;
64 
65     /**
66     * Called to create an instance of <code>TestEnvironment</code>
67     * with an object to test and related objects.
68     * Creates a frame and inserts it into document.
69     * Obtains accessible object for the inserted text frame.
70     *
71     * @param tParam test parameters
72     * @param log writer to log information while testing
73     *
74     * @see TestEnvironment
75     * @see #getTestEnvironment
76     */
77     protected TestEnvironment createTestEnvironment(
78         TestParameters Param, PrintWriter log) {
79 
80         XInterface oObj = null;
81         XTextFrame oFrame1 = null;
82         XPropertySet oPropSet = null;
83         XText oText = null;
84         XTextCursor oCursor = null;
85 
86         // get a soffice factory object
87         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF() );
88         // creating Frames
89         log.println( "creating Frames" );
90         try {
91             oFrame1 = SOF.createTextFrame(xTextDoc, 500, 500);
92             oPropSet = (XPropertySet)UnoRuntime.queryInterface(
93                 XPropertySet.class, oFrame1 );
94             oPropSet.setPropertyValue("AnchorType",
95                 TextContentAnchorType.AS_CHARACTER);
96             oText = xTextDoc.getText();
97             oCursor = oText.createTextCursor();
98 
99             log.println( "inserting Frame1" );
100             XTextContent the_content = (XTextContent)
101                 UnoRuntime.queryInterface(XTextContent.class, oFrame1);
102             oText.insertTextContent(oCursor, the_content, true);
103         } catch (Exception e) {
104             e.printStackTrace(log);
105             throw new StatusException("Couldn't insert TextFrame", e);
106         }
107 
108         XModel aModel = (XModel)
109             UnoRuntime.queryInterface(XModel.class, xTextDoc);
110 
111         AccessibilityTools at = new AccessibilityTools();
112 
113         XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
114         XAccessible xRoot = at.getAccessibleObject(xWindow);
115 
116         at.getAccessibleObjectForRole(xRoot, AccessibleRole.TEXT_FRAME);
117 
118         oObj = at.SearchedContext;
119 
120         log.println("ImplementationName " + utils.getImplName(oObj));
121         at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
122 
123         TestEnvironment tEnv = new TestEnvironment(oObj);
124 
125         XController xController = xTextDoc.getCurrentController();
126         XViewSettingsSupplier xViewSetSup = (XViewSettingsSupplier)
127                 UnoRuntime.queryInterface(XViewSettingsSupplier.class,
128                 xController);
129 
130         final XPropertySet PropSet = xViewSetSup.getViewSettings();
131 
132         tEnv.addObjRelation("EventProducer",
133             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
134                 public void fireEvent() {
135                     try {
136                         //change zoom value to 15%
137                         PropSet.setPropertyValue("ZoomValue", new Short("15"));
138                         //and back to 100%
139                         PropSet.setPropertyValue("ZoomValue", new Short("100"));
140                     } catch ( com.sun.star.lang.WrappedTargetException e ) {
141 
142                     }  catch ( com.sun.star.lang.IllegalArgumentException e ) {
143 
144                     } catch ( com.sun.star.beans.PropertyVetoException e ) {
145 
146                     } catch ( com.sun.star.beans.UnknownPropertyException e ) {
147 
148                     }
149                 }
150             });
151 
152 
153         return tEnv;
154 
155     }
156 
157     /**
158     * Called while disposing a <code>TestEnvironment</code>.
159     * Disposes text document.
160     * @param tParam test parameters
161     * @param tEnv the environment to cleanup
162     * @param log writer to log information while testing
163     */
164     protected void cleanup( TestParameters Param, PrintWriter log) {
165         log.println("dispose text document");
166         util.DesktopTools.closeDoc(xTextDoc);
167     }
168 
169     /**
170      * Called while the <code>TestCase</code> initialization.
171      * Creates a text document.
172      *
173      * @param tParam test parameters
174      * @param log writer to log information while testing
175      *
176      * @see #initializeTestCase
177      */
178     protected void initialize(TestParameters Param, PrintWriter log) {
179         log.println( "creating a text document" );
180         xTextDoc = WriterTools.createTextDoc((XMultiServiceFactory)Param.getMSF());
181     }
182 }
183 
184