xref: /trunk/main/sc/qa/complex/calcPreview/ViewForwarder.java (revision 3309286857f19787ae62bd793a98b5af4edd2ad3)
115ab5183SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
315ab5183SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
415ab5183SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
515ab5183SAndrew Rist  * distributed with this work for additional information
615ab5183SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
715ab5183SAndrew Rist  * to you under the Apache License, Version 2.0 (the
815ab5183SAndrew Rist  * "License"); you may not use this file except in compliance
915ab5183SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
1115ab5183SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
1315ab5183SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1415ab5183SAndrew Rist  * software distributed under the License is distributed on an
1515ab5183SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1615ab5183SAndrew Rist  * KIND, either express or implied.  See the License for the
1715ab5183SAndrew Rist  * specific language governing permissions and limitations
1815ab5183SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
2015ab5183SAndrew Rist  *************************************************************/
2115ab5183SAndrew Rist 
2215ab5183SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package complex.calcPreview;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.awt.XWindow;
27cdf0e10cSrcweir import com.sun.star.container.XIndexAccess;
28cdf0e10cSrcweir import com.sun.star.frame.XController;
29cdf0e10cSrcweir import com.sun.star.frame.XDispatch;
30cdf0e10cSrcweir import com.sun.star.frame.XDispatchProvider;
31cdf0e10cSrcweir import com.sun.star.frame.XModel;
32cdf0e10cSrcweir // import com.sun.star.lang.XComponent;
33cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
34cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheet;
35cdf0e10cSrcweir // import com.sun.star.sheet.XSpreadsheetDocument;
36cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheets;
37cdf0e10cSrcweir import com.sun.star.table.XCell;
38cdf0e10cSrcweir // import com.sun.star.uno.Any;
39cdf0e10cSrcweir import com.sun.star.uno.AnyConverter;
40cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
41cdf0e10cSrcweir import com.sun.star.uno.XInterface;
42cdf0e10cSrcweir import com.sun.star.util.URL;
43cdf0e10cSrcweir import com.sun.star.util.XURLTransformer;
44cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleRole;
45cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible;
46cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleText;
47cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleValue;
48cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleComponent;
49cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleContext;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir import util.AccessibilityTools;
52cdf0e10cSrcweir import util.SOfficeFactory;
53cdf0e10cSrcweir import util.utils;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
56cdf0e10cSrcweir // import com.sun.star.beans.XPropertySetInfo;
57cdf0e10cSrcweir import com.sun.star.container.XNameAccess;
58cdf0e10cSrcweir import com.sun.star.lang.XComponent;
59cdf0e10cSrcweir import com.sun.star.sheet.XHeaderFooterContent;
60cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheetDocument;
61cdf0e10cSrcweir import com.sun.star.style.XStyle;
62cdf0e10cSrcweir import com.sun.star.style.XStyleFamiliesSupplier;
63cdf0e10cSrcweir import com.sun.star.text.XText;
64cdf0e10cSrcweir // import com.sun.star.drawing.XDrawPageSupplier;
65cdf0e10cSrcweir // import com.sun.star.drawing.XDrawPage;
66cdf0e10cSrcweir // import com.sun.star.drawing.XShape;
67cdf0e10cSrcweir // import com.sun.star.drawing.XShapes;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 
70cdf0e10cSrcweir // import com.sun.star.beans.Property;
71cdf0e10cSrcweir // import com.sun.star.lang.XServiceInfo;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 
75cdf0e10cSrcweir // import org.junit.After;
76cdf0e10cSrcweir import org.junit.AfterClass;
77cdf0e10cSrcweir import org.junit.Before;
78cdf0e10cSrcweir import org.junit.BeforeClass;
79cdf0e10cSrcweir import org.junit.Test;
80cdf0e10cSrcweir import org.openoffice.test.OfficeConnection;
81cdf0e10cSrcweir import static org.junit.Assert.*;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir /**
84cdf0e10cSrcweir  * A complex test for the preview of Calc documents. This complex test
85cdf0e10cSrcweir  * needs interaction from the user: documents have to be resized and moved.
86cdf0e10cSrcweir  */
87cdf0e10cSrcweir public class ViewForwarder {
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     /** The MultiServiceFactory **/
90cdf0e10cSrcweir     private XMultiServiceFactory mXMSF = null;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     /**
93cdf0e10cSrcweir      * Get a MultiServiceFactory from the Office before the test.
94cdf0e10cSrcweir      */
before()95cdf0e10cSrcweir     @Before public void before()
96cdf0e10cSrcweir     {
97cdf0e10cSrcweir         mXMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
98cdf0e10cSrcweir         // SOfficeFactory SOF = SOfficeFactory.getFactory(mXMSF);
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         // param = new TestParameters();
101cdf0e10cSrcweir         // param.put("ServiceFactory", xMsf);
102cdf0e10cSrcweir         // mXMSF = (XMultiServiceFactory)param.getMSF();
103cdf0e10cSrcweir     }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     /** Create a spreadsheet document, insert some text, header and footer.
107cdf0e10cSrcweir      * Let the user resize the document and check the contents.
108cdf0e10cSrcweir      */
checkPositiveViewForwarder()109cdf0e10cSrcweir     @Test public void checkPositiveViewForwarder() {
110cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory( mXMSF );
111cdf0e10cSrcweir         XSpreadsheetDocument xSpreadsheetDoc = null;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir         try {
114cdf0e10cSrcweir             System.out.println("Creating a spreadsheet document");
115cdf0e10cSrcweir             xSpreadsheetDoc = SOF.createCalcDoc(null);
116cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
117cdf0e10cSrcweir             fail(e.getMessage());
118cdf0e10cSrcweir             return;
119cdf0e10cSrcweir         }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         XInterface oObj = null;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         // inserting some content to have non-empty page preview
124cdf0e10cSrcweir         XCell xCell = null;
125cdf0e10cSrcweir         try {
126cdf0e10cSrcweir             XSpreadsheets oSheets = xSpreadsheetDoc.getSheets() ;
127cdf0e10cSrcweir             XIndexAccess oIndexSheets =
128cdf0e10cSrcweir                 UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
129cdf0e10cSrcweir             Object o = oIndexSheets.getByIndex(0);
130cdf0e10cSrcweir             XSpreadsheet oSheet = (XSpreadsheet)AnyConverter.toObject(
131cdf0e10cSrcweir                             new com.sun.star.uno.Type(XSpreadsheet.class), o);
132cdf0e10cSrcweir             xCell = oSheet.getCellByPosition(0, 0) ;
133cdf0e10cSrcweir             xCell.setFormula("ScAccessiblePageHeader");
134cdf0e10cSrcweir 
135cdf0e10cSrcweir             xCell = oSheet.getCellByPosition(0, 1) ;
136cdf0e10cSrcweir             xCell.setFormula("Cell 1");
137cdf0e10cSrcweir             xCell = oSheet.getCellByPosition(0, 2) ;
138cdf0e10cSrcweir             xCell.setFormula("Cell 2");
139cdf0e10cSrcweir         } catch(com.sun.star.lang.IllegalArgumentException e) {
140*dcaf07f7SJohn Bampton             System.out.println("Exception creating relation :");
141cdf0e10cSrcweir             fail(e.getMessage());
142cdf0e10cSrcweir         } catch(com.sun.star.lang.WrappedTargetException e) {
143*dcaf07f7SJohn Bampton             System.out.println("Exception creating relation :");
144cdf0e10cSrcweir             fail(e.getMessage());
145cdf0e10cSrcweir         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
146*dcaf07f7SJohn Bampton             System.out.println("Exception creating relation :");
147cdf0e10cSrcweir             fail(e.getMessage());
148cdf0e10cSrcweir         }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir         XModel aModel =
151cdf0e10cSrcweir             UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
152cdf0e10cSrcweir 
153cdf0e10cSrcweir         XController xController = aModel.getCurrentController();
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         // get page styles
156cdf0e10cSrcweir         XStyleFamiliesSupplier StyleFam =
157cdf0e10cSrcweir             UnoRuntime.queryInterface(
158cdf0e10cSrcweir                 XStyleFamiliesSupplier.class,
159cdf0e10cSrcweir                 xSpreadsheetDoc );
160cdf0e10cSrcweir         XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
161cdf0e10cSrcweir         XStyle StdStyle = null;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir         try{
164cdf0e10cSrcweir             Object o = StyleFamNames.getByName("PageStyles");
165cdf0e10cSrcweir             XNameAccess PageStyles = (XNameAccess)AnyConverter.toObject(
166cdf0e10cSrcweir                             new com.sun.star.uno.Type(XNameAccess.class), o);
167cdf0e10cSrcweir 
168cdf0e10cSrcweir             o = PageStyles.getByName("Default");
169cdf0e10cSrcweir             StdStyle = (XStyle)AnyConverter.toObject(
170cdf0e10cSrcweir                             new com.sun.star.uno.Type(XStyle.class), o);
171cdf0e10cSrcweir         } catch(com.sun.star.lang.IllegalArgumentException e) {
172cdf0e10cSrcweir             fail(e.getMessage());
173cdf0e10cSrcweir         } catch(com.sun.star.lang.WrappedTargetException e){
174cdf0e10cSrcweir             fail(e.getMessage());
175cdf0e10cSrcweir             return;
176cdf0e10cSrcweir         } catch(com.sun.star.container.NoSuchElementException e){
177cdf0e10cSrcweir             fail(e.getMessage());
178cdf0e10cSrcweir             return;
179cdf0e10cSrcweir         }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir         //get the property-set
182cdf0e10cSrcweir         final XPropertySet PropSet =
183cdf0e10cSrcweir             UnoRuntime.queryInterface(XPropertySet.class, StdStyle);
184cdf0e10cSrcweir 
185cdf0e10cSrcweir         XHeaderFooterContent RPHFC = null;
186cdf0e10cSrcweir 
187cdf0e10cSrcweir         // get the header
188cdf0e10cSrcweir         try {
189cdf0e10cSrcweir             Object o = PropSet.getPropertyValue("RightPageHeaderContent");
190cdf0e10cSrcweir             RPHFC = (XHeaderFooterContent)AnyConverter.toObject(
191cdf0e10cSrcweir                     new com.sun.star.uno.Type(XHeaderFooterContent.class), o);
192cdf0e10cSrcweir 
193cdf0e10cSrcweir         } catch(com.sun.star.lang.IllegalArgumentException e) {
194cdf0e10cSrcweir             fail(e.getMessage());
195cdf0e10cSrcweir         } catch(com.sun.star.lang.WrappedTargetException e){
196cdf0e10cSrcweir             fail(e.getMessage());
197cdf0e10cSrcweir             return;
198cdf0e10cSrcweir         } catch(com.sun.star.beans.UnknownPropertyException e){
199cdf0e10cSrcweir             fail(e.getMessage());
200cdf0e10cSrcweir             return;
201cdf0e10cSrcweir         }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir         // insert text into header
204cdf0e10cSrcweir         XText center = RPHFC.getCenterText();
205cdf0e10cSrcweir         center.setString("First line \n\r Second line \n\r third line ");
206cdf0e10cSrcweir         try {
207cdf0e10cSrcweir             PropSet.setPropertyValue("RightPageHeaderContent",RPHFC);
208cdf0e10cSrcweir         } catch (com.sun.star.beans.UnknownPropertyException e) {
209cdf0e10cSrcweir         } catch (com.sun.star.beans.PropertyVetoException e) {
210cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
211cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {}
212cdf0e10cSrcweir 
213cdf0e10cSrcweir         // get footer
214cdf0e10cSrcweir         RPHFC = null;
215cdf0e10cSrcweir         try {
216cdf0e10cSrcweir             Object o = PropSet.getPropertyValue("RightPageHeaderContent");
217cdf0e10cSrcweir             RPHFC = (XHeaderFooterContent)AnyConverter.toObject(
218cdf0e10cSrcweir                     new com.sun.star.uno.Type(XHeaderFooterContent.class), o);
219cdf0e10cSrcweir         } catch(com.sun.star.lang.IllegalArgumentException e) {
220cdf0e10cSrcweir             fail(e.getMessage());
221cdf0e10cSrcweir         } catch(com.sun.star.lang.WrappedTargetException e){
222cdf0e10cSrcweir             fail(e.getMessage());
223cdf0e10cSrcweir             return;
224cdf0e10cSrcweir         } catch(com.sun.star.beans.UnknownPropertyException e){
225cdf0e10cSrcweir             fail(e.getMessage());
226cdf0e10cSrcweir             return;
227cdf0e10cSrcweir         }
228cdf0e10cSrcweir 
229cdf0e10cSrcweir         // insert text into footer
230cdf0e10cSrcweir         center = RPHFC.getCenterText();
231cdf0e10cSrcweir         center.setString("Third last line\n\r Second last line\n\r last line");
232cdf0e10cSrcweir         try {
233cdf0e10cSrcweir             PropSet.setPropertyValue("RightPageFooterContent",RPHFC);
234cdf0e10cSrcweir         } catch (com.sun.star.beans.UnknownPropertyException e) {
235cdf0e10cSrcweir         } catch (com.sun.star.beans.PropertyVetoException e) {
236cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
237cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {}
238cdf0e10cSrcweir 
239cdf0e10cSrcweir         // switching to 'Page Preview' mode
240cdf0e10cSrcweir         try {
241cdf0e10cSrcweir             XDispatchProvider xDispProv =
242cdf0e10cSrcweir                 UnoRuntime.queryInterface(XDispatchProvider.class, xController);
243cdf0e10cSrcweir             XURLTransformer xParser =
244cdf0e10cSrcweir                 UnoRuntime.queryInterface(XURLTransformer.class,
245cdf0e10cSrcweir             mXMSF.createInstance("com.sun.star.util.URLTransformer"));
246cdf0e10cSrcweir             // Because it's an in/out parameter we must use an
247cdf0e10cSrcweir             // array of URL objects.
248cdf0e10cSrcweir             URL[] aParseURL = new URL[1];
249cdf0e10cSrcweir             aParseURL[0] = new URL();
250cdf0e10cSrcweir             aParseURL[0].Complete = ".uno:PrintPreview";
251cdf0e10cSrcweir             xParser.parseStrict(aParseURL);
252cdf0e10cSrcweir             URL aURL = aParseURL[0];
253cdf0e10cSrcweir             XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
254cdf0e10cSrcweir             if(xDispatcher != null)
255cdf0e10cSrcweir             {
256cdf0e10cSrcweir                 xDispatcher.dispatch( aURL, null );
257cdf0e10cSrcweir             }
258cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
259cdf0e10cSrcweir             fail("Couldn't change mode");
260cdf0e10cSrcweir             return;
261cdf0e10cSrcweir         }
262cdf0e10cSrcweir 
263cdf0e10cSrcweir         try {
264cdf0e10cSrcweir             Thread.sleep(500);
265cdf0e10cSrcweir         } catch (InterruptedException ex) {}
266cdf0e10cSrcweir 
267cdf0e10cSrcweir         System.out.println("Press any key after resizing ");
268cdf0e10cSrcweir         try{
269cdf0e10cSrcweir             byte[]b = new byte[16];
270cdf0e10cSrcweir             System.in.read(b);
271cdf0e10cSrcweir         } catch (Exception e) {
272cdf0e10cSrcweir             e.printStackTrace();
273cdf0e10cSrcweir         }
274cdf0e10cSrcweir 
275cdf0e10cSrcweir         // get the accessible content
276cdf0e10cSrcweir         AccessibilityTools at = new AccessibilityTools();
277cdf0e10cSrcweir 
278cdf0e10cSrcweir         XWindow xWindow = at.getCurrentWindow(mXMSF, aModel);
279cdf0e10cSrcweir         XAccessible xRoot = at.getAccessibleObject(xWindow);
280cdf0e10cSrcweir         XAccessible parent = null;
281cdf0e10cSrcweir 
282cdf0e10cSrcweir         try {
283cdf0e10cSrcweir             parent = at.getAccessibleObjectForRole
284cdf0e10cSrcweir                 (xRoot, AccessibleRole.HEADER, "").getAccessibleChild(0);
285cdf0e10cSrcweir             oObj = parent.getAccessibleContext().getAccessibleChild(0);
286cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
287cdf0e10cSrcweir             fail(iabe.getMessage());
288cdf0e10cSrcweir             return;
289cdf0e10cSrcweir         }
290cdf0e10cSrcweir 
291cdf0e10cSrcweir         System.out.println("ImplementationName " + utils.getImplName(oObj));
292cdf0e10cSrcweir 
293cdf0e10cSrcweir         XAccessibleComponent accPC =
294cdf0e10cSrcweir                 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
295cdf0e10cSrcweir 
296cdf0e10cSrcweir         System.out.println("Parent-BoundsX= "+accPC.getBounds().X);
297cdf0e10cSrcweir         System.out.println("Parent-BoundsY= "+accPC.getBounds().Y);
298cdf0e10cSrcweir         System.out.println("Parent-BoundsWidth= "+accPC.getBounds().Width);
299cdf0e10cSrcweir         System.out.println("Parent-BoundsHeight= "+accPC.getBounds().Height);
300cdf0e10cSrcweir 
301cdf0e10cSrcweir         XAccessibleComponent accPPC =
302cdf0e10cSrcweir                         UnoRuntime.queryInterface(XAccessibleComponent.class,
303cdf0e10cSrcweir                         parent.getAccessibleContext().getAccessibleParent());
304cdf0e10cSrcweir 
305cdf0e10cSrcweir         System.out.println("P-Parent-BoundsX= "+accPPC.getBounds().X);
306cdf0e10cSrcweir         System.out.println("P-Parent-BoundsY= "+accPPC.getBounds().Y);
307cdf0e10cSrcweir         System.out.println("P-Parent-BoundsWidth= "+accPPC.getBounds().Width);
308cdf0e10cSrcweir         System.out.println("P-Parent-BoundsHeight= "+accPPC.getBounds().Height);
309cdf0e10cSrcweir 
310cdf0e10cSrcweir         try {
311cdf0e10cSrcweir             Thread.sleep(500);
312cdf0e10cSrcweir         } catch (InterruptedException ex) {}
313cdf0e10cSrcweir 
314cdf0e10cSrcweir         System.out.println("Press any key when the second line is on top");
315cdf0e10cSrcweir         try{
316cdf0e10cSrcweir             byte[]b = new byte[16];
317cdf0e10cSrcweir             System.in.read(b);
318cdf0e10cSrcweir         } catch (Exception e) {
319cdf0e10cSrcweir             e.printStackTrace();
320cdf0e10cSrcweir         }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir         try {
323cdf0e10cSrcweir             System.out.println("ChildCount: "+
324cdf0e10cSrcweir                     parent.getAccessibleContext().getAccessibleChildCount());
325cdf0e10cSrcweir             System.out.println("Getting child 0 again");
326cdf0e10cSrcweir             oObj = parent.getAccessibleContext().getAccessibleChild(0);
327cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
328cdf0e10cSrcweir             fail(iabe.getMessage());
329cdf0e10cSrcweir             return;
330cdf0e10cSrcweir         }
331cdf0e10cSrcweir 
332cdf0e10cSrcweir         XAccessibleText accT =
333cdf0e10cSrcweir                 UnoRuntime.queryInterface(XAccessibleText.class, oObj);
334cdf0e10cSrcweir         System.out.println("Getting the text: "+accT.getText());
335cdf0e10cSrcweir 
336cdf0e10cSrcweir         XAccessibleComponent accC =
337cdf0e10cSrcweir                 UnoRuntime.queryInterface(XAccessibleComponent.class, oObj);
338cdf0e10cSrcweir         System.out.println("BoundsX= "+accC.getBounds().X);
339cdf0e10cSrcweir         System.out.println("BoundsY= "+accC.getBounds().Y);
340cdf0e10cSrcweir         System.out.println("BoundsWidth= "+accC.getBounds().Width);
341cdf0e10cSrcweir         System.out.println("BoundsHeight= "+accC.getBounds().Height);
342cdf0e10cSrcweir 
343cdf0e10cSrcweir         accPC =
344cdf0e10cSrcweir                 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
345cdf0e10cSrcweir 
346cdf0e10cSrcweir         System.out.println("Parent-BoundsX= "+accPC.getBounds().X);
347cdf0e10cSrcweir         System.out.println("Parent-BoundsY= "+accPC.getBounds().Y);
348cdf0e10cSrcweir         System.out.println("Parent-BoundsWidth= "+accPC.getBounds().Width);
349cdf0e10cSrcweir         System.out.println("Parent-BoundsHeight= "+accPC.getBounds().Height);
350cdf0e10cSrcweir 
351cdf0e10cSrcweir         accPPC =
352cdf0e10cSrcweir         UnoRuntime.queryInterface(XAccessibleComponent.class,
353cdf0e10cSrcweir                         parent.getAccessibleContext().getAccessibleParent());
354cdf0e10cSrcweir 
355cdf0e10cSrcweir         System.out.println("P-Parent-BoundsX= "+accPPC.getBounds().X);
356cdf0e10cSrcweir         System.out.println("P-Parent-BoundsY= "+accPPC.getBounds().Y);
357cdf0e10cSrcweir         System.out.println("P-Parent-BoundsWidth= "+accPPC.getBounds().Width);
358cdf0e10cSrcweir         System.out.println("P-Parent-BoundsHeight= "+accPPC.getBounds().Height);
359cdf0e10cSrcweir 
360cdf0e10cSrcweir 
361cdf0e10cSrcweir 
362cdf0e10cSrcweir         System.out.println("Press any key when the footer is visible.");
363cdf0e10cSrcweir         try{
364cdf0e10cSrcweir             byte[]b = new byte[16];
365cdf0e10cSrcweir             System.in.read(b);
366cdf0e10cSrcweir         } catch (Exception e) {
367cdf0e10cSrcweir             e.printStackTrace();
368cdf0e10cSrcweir         }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir         try {
371cdf0e10cSrcweir             parent = at.getAccessibleObjectForRole
372cdf0e10cSrcweir                 (xRoot, AccessibleRole.FOOTER, "").getAccessibleChild(0);
373cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
374cdf0e10cSrcweir             fail(iabe.getMessage());
375cdf0e10cSrcweir             return;
376cdf0e10cSrcweir         }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir         accPC =
379cdf0e10cSrcweir                 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
380cdf0e10cSrcweir 
381cdf0e10cSrcweir         try {
382cdf0e10cSrcweir             System.out.println("ChildCount: "+
383cdf0e10cSrcweir                     parent.getAccessibleContext().getAccessibleChildCount());
384cdf0e10cSrcweir             System.out.println("Getting child 0 again");
385cdf0e10cSrcweir             oObj = parent.getAccessibleContext().getAccessibleChild(0);
386cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
387cdf0e10cSrcweir             fail(iabe.getMessage());
388cdf0e10cSrcweir             return;
389cdf0e10cSrcweir         }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir         accT =
392cdf0e10cSrcweir                 UnoRuntime.queryInterface(XAccessibleText.class, oObj);
393cdf0e10cSrcweir         System.out.println("Getting the text: "+accT.getText());
394cdf0e10cSrcweir 
395cdf0e10cSrcweir         accC =
396cdf0e10cSrcweir                 UnoRuntime.queryInterface(XAccessibleComponent.class, oObj);
397cdf0e10cSrcweir         System.out.println("BoundsX= "+accC.getBounds().X);
398cdf0e10cSrcweir         System.out.println("BoundsY= "+accC.getBounds().Y);
399cdf0e10cSrcweir         System.out.println("BoundsWidth= "+accC.getBounds().Width);
400cdf0e10cSrcweir         System.out.println("BoundsHeight= "+accC.getBounds().Height);
401cdf0e10cSrcweir 
402cdf0e10cSrcweir         accPC =
403cdf0e10cSrcweir                 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
404cdf0e10cSrcweir 
405cdf0e10cSrcweir         System.out.println("Parent-BoundsX= "+accPC.getBounds().X);
406cdf0e10cSrcweir         System.out.println("Parent-BoundsY= "+accPC.getBounds().Y);
407cdf0e10cSrcweir         System.out.println("Parent-BoundsWidth= "+accPC.getBounds().Width);
408cdf0e10cSrcweir         System.out.println("Parent-BoundsHeight= "+accPC.getBounds().Height);
409cdf0e10cSrcweir 
410cdf0e10cSrcweir         accPPC =
411cdf0e10cSrcweir         UnoRuntime.queryInterface(XAccessibleComponent.class,
412cdf0e10cSrcweir                         parent.getAccessibleContext().getAccessibleParent());
413cdf0e10cSrcweir 
414cdf0e10cSrcweir         System.out.println("P-Parent-BoundsX= "+accPPC.getBounds().X);
415cdf0e10cSrcweir         System.out.println("P-Parent-BoundsY= "+accPPC.getBounds().Y);
416cdf0e10cSrcweir         System.out.println("P-Parent-BoundsWidth= "+accPPC.getBounds().Width);
417cdf0e10cSrcweir         System.out.println("P-Parent-BoundsHeight= "+accPPC.getBounds().Height);
418cdf0e10cSrcweir 
419cdf0e10cSrcweir 
420cdf0e10cSrcweir         System.out.println("Press any key when the page content is on top");
421cdf0e10cSrcweir         try{
422cdf0e10cSrcweir             byte[]b = new byte[16];
423cdf0e10cSrcweir             System.in.read(b);
424cdf0e10cSrcweir         } catch (Exception e) {
425cdf0e10cSrcweir             e.printStackTrace();
426cdf0e10cSrcweir         }
427cdf0e10cSrcweir 
428cdf0e10cSrcweir         try {
429cdf0e10cSrcweir             parent = at.getAccessibleObjectForRole
430cdf0e10cSrcweir                 (xRoot, AccessibleRole.DOCUMENT, "").getAccessibleChild(0);
431cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
432cdf0e10cSrcweir             fail(iabe.getMessage());
433cdf0e10cSrcweir             return;
434cdf0e10cSrcweir         }
435cdf0e10cSrcweir         System.out.println("PARENT: " + parent.getAccessibleContext().getAccessibleName());
436cdf0e10cSrcweir         accPC =
437cdf0e10cSrcweir                 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
438cdf0e10cSrcweir 
439cdf0e10cSrcweir         int cCount = 0;
440cdf0e10cSrcweir         try {
441cdf0e10cSrcweir             cCount =
442cdf0e10cSrcweir                parent.getAccessibleContext().getAccessibleChildCount();
443cdf0e10cSrcweir             System.out.println("ChildCount: "+cCount);
444cdf0e10cSrcweir             System.out.println("Getting child 0 again");
445cdf0e10cSrcweir             oObj = parent.getAccessibleContext().getAccessibleChild(0);
446cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
447cdf0e10cSrcweir             fail(iabe.getMessage());
448cdf0e10cSrcweir             return;
449cdf0e10cSrcweir         }
450cdf0e10cSrcweir 
451cdf0e10cSrcweir         for (int i=0; i<cCount; i++) {
452cdf0e10cSrcweir             try {
453cdf0e10cSrcweir                 XAccessible xA = parent.getAccessibleContext().getAccessibleChild(i);
454cdf0e10cSrcweir                 System.out.println("NAME object " + i + ": " + xA.getAccessibleContext().getAccessibleName());
455cdf0e10cSrcweir             } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
456cdf0e10cSrcweir                 fail(iabe.getMessage());
457cdf0e10cSrcweir                 return;
458cdf0e10cSrcweir             }
459cdf0e10cSrcweir         }
460cdf0e10cSrcweir 
461cdf0e10cSrcweir         System.out.println("SERVICES:");
462cdf0e10cSrcweir         util.dbg.getSuppServices(oObj);
463cdf0e10cSrcweir 
464cdf0e10cSrcweir         XAccessibleValue accV =
465cdf0e10cSrcweir                 UnoRuntime.queryInterface(XAccessibleValue.class, oObj);
466cdf0e10cSrcweir         Object o = accV.getCurrentValue();
467cdf0e10cSrcweir         if (o instanceof String)
468cdf0e10cSrcweir         {
469cdf0e10cSrcweir             System.out.println("Value: " + (String)o);
470cdf0e10cSrcweir         }
471cdf0e10cSrcweir         else
472cdf0e10cSrcweir         {
473cdf0e10cSrcweir             System.out.println("Name of Object: " + o.getClass().getName());
474cdf0e10cSrcweir         }
475cdf0e10cSrcweir         System.out.println("Getting the value: "+accV.getCurrentValue());
476cdf0e10cSrcweir 
477cdf0e10cSrcweir 
478cdf0e10cSrcweir 
479cdf0e10cSrcweir 
480cdf0e10cSrcweir         accC =
481cdf0e10cSrcweir                 UnoRuntime.queryInterface(XAccessibleComponent.class, oObj);
482cdf0e10cSrcweir         System.out.println("BoundsX= "+accC.getBounds().X);
483cdf0e10cSrcweir         System.out.println("BoundsY= "+accC.getBounds().Y);
484cdf0e10cSrcweir         System.out.println("BoundsWidth= "+accC.getBounds().Width);
485cdf0e10cSrcweir         System.out.println("BoundsHeight= "+accC.getBounds().Height);
486cdf0e10cSrcweir 
487cdf0e10cSrcweir         accPC =
488cdf0e10cSrcweir                 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
489cdf0e10cSrcweir 
490cdf0e10cSrcweir         System.out.println("Parent-BoundsX= "+accPC.getBounds().X);
491cdf0e10cSrcweir         System.out.println("Parent-BoundsY= "+accPC.getBounds().Y);
492cdf0e10cSrcweir         System.out.println("Parent-BoundsWidth= "+accPC.getBounds().Width);
493cdf0e10cSrcweir         System.out.println("Parent-BoundsHeight= "+accPC.getBounds().Height);
494cdf0e10cSrcweir 
495cdf0e10cSrcweir         accPPC =
496cdf0e10cSrcweir                 UnoRuntime.queryInterface(XAccessibleComponent.class,
497cdf0e10cSrcweir                         parent.getAccessibleContext().getAccessibleParent());
498cdf0e10cSrcweir 
499cdf0e10cSrcweir         System.out.println("P-Parent-BoundsX= "+accPPC.getBounds().X);
500cdf0e10cSrcweir         System.out.println("P-Parent-BoundsY= "+accPPC.getBounds().Y);
501cdf0e10cSrcweir         System.out.println("P-Parent-BoundsWidth= "+accPPC.getBounds().Width);
502cdf0e10cSrcweir         System.out.println("P-Parent-BoundsHeight= "+accPPC.getBounds().Height);
503cdf0e10cSrcweir 
504cdf0e10cSrcweir         XComponent xComp = UnoRuntime.queryInterface(
505cdf0e10cSrcweir                                     XComponent.class, xSpreadsheetDoc);
506cdf0e10cSrcweir         xComp.dispose();
507cdf0e10cSrcweir     }
508cdf0e10cSrcweir 
509cdf0e10cSrcweir 
510cdf0e10cSrcweir 
511cdf0e10cSrcweir 
512cdf0e10cSrcweir 
513cdf0e10cSrcweir 
514cdf0e10cSrcweir 
515cdf0e10cSrcweir 
516cdf0e10cSrcweir     /**
517cdf0e10cSrcweir      * Create a spreadsheet document, insert some text, header and footer.
518cdf0e10cSrcweir      * Let the user resize the document and check the contents.
519cdf0e10cSrcweir      */
checkNegativeViewForwarder()520cdf0e10cSrcweir     @Test public void checkNegativeViewForwarder() {
521cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory( mXMSF );
522cdf0e10cSrcweir         XSpreadsheetDocument xSpreadsheetDoc = null;
523cdf0e10cSrcweir 
524cdf0e10cSrcweir         try {
525cdf0e10cSrcweir             System.out.println("Creating a spreadsheet document");
526cdf0e10cSrcweir             xSpreadsheetDoc = SOF.createCalcDoc(null);
527cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
528cdf0e10cSrcweir             fail(e.getMessage());
529cdf0e10cSrcweir             return;
530cdf0e10cSrcweir         }
531cdf0e10cSrcweir 
532cdf0e10cSrcweir         XInterface oObj = null;
533cdf0e10cSrcweir 
534cdf0e10cSrcweir         // inserting some content to have non-empty page preview
535cdf0e10cSrcweir         XCell xCell = null;
536cdf0e10cSrcweir         try {
537cdf0e10cSrcweir             XSpreadsheets oSheets = xSpreadsheetDoc.getSheets() ;
538cdf0e10cSrcweir             XIndexAccess oIndexSheets =
539cdf0e10cSrcweir                 UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
540cdf0e10cSrcweir             Object o = oIndexSheets.getByIndex(0);
541cdf0e10cSrcweir             XSpreadsheet oSheet = (XSpreadsheet)AnyConverter.toObject(
542cdf0e10cSrcweir                             new com.sun.star.uno.Type(XSpreadsheet.class), o);
543cdf0e10cSrcweir             xCell = oSheet.getCellByPosition(0, 0) ;
544cdf0e10cSrcweir             xCell.setFormula("ScAccessiblePageHeader");
545cdf0e10cSrcweir 
546cdf0e10cSrcweir             xCell = oSheet.getCellByPosition(0, 1) ;
547cdf0e10cSrcweir             xCell.setFormula("Cell 1");
548cdf0e10cSrcweir             xCell = oSheet.getCellByPosition(0, 2) ;
549cdf0e10cSrcweir             xCell.setFormula("Cell 2");
550cdf0e10cSrcweir         } catch(com.sun.star.lang.IllegalArgumentException e) {
551*dcaf07f7SJohn Bampton             System.out.println("Exception creating relation :");
552cdf0e10cSrcweir             fail(e.getMessage());
553cdf0e10cSrcweir         } catch(com.sun.star.lang.WrappedTargetException e) {
554*dcaf07f7SJohn Bampton             System.out.println("Exception creating relation :");
555cdf0e10cSrcweir             fail(e.getMessage());
556cdf0e10cSrcweir         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
557*dcaf07f7SJohn Bampton             System.out.println("Exception creating relation :");
558cdf0e10cSrcweir             fail(e.getMessage());
559cdf0e10cSrcweir         }
560cdf0e10cSrcweir 
561cdf0e10cSrcweir         XModel aModel =
562cdf0e10cSrcweir             UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
563cdf0e10cSrcweir 
564cdf0e10cSrcweir         XController xController = aModel.getCurrentController();
565cdf0e10cSrcweir 
566cdf0e10cSrcweir         // get page styles
567cdf0e10cSrcweir         XStyleFamiliesSupplier StyleFam =
568cdf0e10cSrcweir             UnoRuntime.queryInterface(
569cdf0e10cSrcweir                 XStyleFamiliesSupplier.class,
570cdf0e10cSrcweir                 xSpreadsheetDoc );
571cdf0e10cSrcweir         XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
572cdf0e10cSrcweir         XStyle StdStyle = null;
573cdf0e10cSrcweir 
574cdf0e10cSrcweir         try{
575cdf0e10cSrcweir             Object o = StyleFamNames.getByName("PageStyles");
576cdf0e10cSrcweir             XNameAccess PageStyles = (XNameAccess)AnyConverter.toObject(
577cdf0e10cSrcweir                             new com.sun.star.uno.Type(XNameAccess.class), o);
578cdf0e10cSrcweir 
579cdf0e10cSrcweir             o = PageStyles.getByName("Default");
580cdf0e10cSrcweir             StdStyle = (XStyle)AnyConverter.toObject(
581cdf0e10cSrcweir                             new com.sun.star.uno.Type(XStyle.class), o);
582cdf0e10cSrcweir         } catch(com.sun.star.lang.IllegalArgumentException e) {
583cdf0e10cSrcweir             fail(e.getMessage());
584cdf0e10cSrcweir         } catch(com.sun.star.lang.WrappedTargetException e){
585cdf0e10cSrcweir             fail(e.getMessage());
586cdf0e10cSrcweir             return;
587cdf0e10cSrcweir         } catch(com.sun.star.container.NoSuchElementException e){
588cdf0e10cSrcweir             fail(e.getMessage());
589cdf0e10cSrcweir             return;
590cdf0e10cSrcweir         }
591cdf0e10cSrcweir 
592cdf0e10cSrcweir         //get the property-set
593cdf0e10cSrcweir         final XPropertySet PropSet =
594cdf0e10cSrcweir             UnoRuntime.queryInterface(XPropertySet.class, StdStyle);
595cdf0e10cSrcweir 
596cdf0e10cSrcweir         XHeaderFooterContent RPHFC = null;
597cdf0e10cSrcweir 
598cdf0e10cSrcweir         // get the header
599cdf0e10cSrcweir         System.out.println( "Creating a test environment" );
600cdf0e10cSrcweir         try {
601cdf0e10cSrcweir             Object o = PropSet.getPropertyValue("RightPageHeaderContent");
602cdf0e10cSrcweir             RPHFC = (XHeaderFooterContent)AnyConverter.toObject(
603cdf0e10cSrcweir                     new com.sun.star.uno.Type(XHeaderFooterContent.class), o);
604cdf0e10cSrcweir         } catch(com.sun.star.lang.IllegalArgumentException e) {
605cdf0e10cSrcweir             fail(e.getMessage());
606cdf0e10cSrcweir         } catch(com.sun.star.lang.WrappedTargetException e){
607cdf0e10cSrcweir             fail(e.getMessage());
608cdf0e10cSrcweir             return;
609cdf0e10cSrcweir         } catch(com.sun.star.beans.UnknownPropertyException e){
610cdf0e10cSrcweir             fail(e.getMessage());
611cdf0e10cSrcweir             return;
612cdf0e10cSrcweir         }
613cdf0e10cSrcweir 
614cdf0e10cSrcweir         // insert text into header
615cdf0e10cSrcweir         XText center = RPHFC.getCenterText();
616cdf0e10cSrcweir         center.setString("First line \n\r Second line \n\r third line ");
617cdf0e10cSrcweir         try {
618cdf0e10cSrcweir             PropSet.setPropertyValue("RightPageHeaderContent",RPHFC);
619cdf0e10cSrcweir         } catch (com.sun.star.beans.UnknownPropertyException e) {
620cdf0e10cSrcweir         } catch (com.sun.star.beans.PropertyVetoException e) {
621cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
622cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {}
623cdf0e10cSrcweir 
624cdf0e10cSrcweir         // get footer
625cdf0e10cSrcweir         RPHFC = null;
626cdf0e10cSrcweir         try {
627cdf0e10cSrcweir             Object o = PropSet.getPropertyValue("RightPageFooterContent");
628cdf0e10cSrcweir             RPHFC = (XHeaderFooterContent)AnyConverter.toObject(
629cdf0e10cSrcweir                     new com.sun.star.uno.Type(XHeaderFooterContent.class), o);
630cdf0e10cSrcweir         } catch(com.sun.star.lang.IllegalArgumentException e) {
631cdf0e10cSrcweir             fail(e.getMessage());
632cdf0e10cSrcweir         } catch(com.sun.star.lang.WrappedTargetException e){
633cdf0e10cSrcweir             fail(e.getMessage());
634cdf0e10cSrcweir             return;
635cdf0e10cSrcweir         } catch(com.sun.star.beans.UnknownPropertyException e){
636cdf0e10cSrcweir             fail(e.getMessage());
637cdf0e10cSrcweir             return;
638cdf0e10cSrcweir         }
639cdf0e10cSrcweir 
640cdf0e10cSrcweir         // insert text into footer
641cdf0e10cSrcweir         center = RPHFC.getCenterText();
642cdf0e10cSrcweir         center.setString("Third last line\n\r Second last line\n\r last line");
643cdf0e10cSrcweir         try {
644cdf0e10cSrcweir             PropSet.setPropertyValue("RightPageFooterContent",RPHFC);
645cdf0e10cSrcweir         } catch (com.sun.star.beans.UnknownPropertyException e) {
646cdf0e10cSrcweir         } catch (com.sun.star.beans.PropertyVetoException e) {
647cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
648cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {}
649cdf0e10cSrcweir 
650cdf0e10cSrcweir         // switching to 'Page Preview' mode
651cdf0e10cSrcweir         try {
652cdf0e10cSrcweir             XDispatchProvider xDispProv =
653cdf0e10cSrcweir                 UnoRuntime.queryInterface(XDispatchProvider.class, xController);
654cdf0e10cSrcweir             XURLTransformer xParser =
655cdf0e10cSrcweir                 UnoRuntime.queryInterface(XURLTransformer.class,
656cdf0e10cSrcweir             mXMSF.createInstance("com.sun.star.util.URLTransformer"));
657cdf0e10cSrcweir             // Because it's an in/out parameter we must use an
658cdf0e10cSrcweir             // array of URL objects.
659cdf0e10cSrcweir             URL[] aParseURL = new URL[1];
660cdf0e10cSrcweir             aParseURL[0] = new URL();
661cdf0e10cSrcweir             aParseURL[0].Complete = ".uno:PrintPreview";
662cdf0e10cSrcweir             xParser.parseStrict(aParseURL);
663cdf0e10cSrcweir             URL aURL = aParseURL[0];
664cdf0e10cSrcweir             XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
665cdf0e10cSrcweir             if(xDispatcher != null)
666cdf0e10cSrcweir             {
667cdf0e10cSrcweir                 xDispatcher.dispatch( aURL, null );
668cdf0e10cSrcweir             }
669cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
670cdf0e10cSrcweir             fail("Couldn't change mode");
671cdf0e10cSrcweir             return;
672cdf0e10cSrcweir         }
673cdf0e10cSrcweir 
674cdf0e10cSrcweir         try {
675cdf0e10cSrcweir             Thread.sleep(500);
676cdf0e10cSrcweir         } catch (InterruptedException ex) {}
677cdf0e10cSrcweir 
678cdf0e10cSrcweir         System.out.println("Press any key after resizing ");
679cdf0e10cSrcweir         try{
680cdf0e10cSrcweir             byte[]b = new byte[16];
681cdf0e10cSrcweir             System.in.read(b);
682cdf0e10cSrcweir         } catch (Exception e) {
683cdf0e10cSrcweir             e.printStackTrace();
684cdf0e10cSrcweir         }
685cdf0e10cSrcweir 
686cdf0e10cSrcweir         // get the accessible content
687cdf0e10cSrcweir         AccessibilityTools at = new AccessibilityTools();
688cdf0e10cSrcweir 
689cdf0e10cSrcweir         XWindow xWindow = at.getCurrentWindow(mXMSF, aModel);
690cdf0e10cSrcweir         XAccessible xRoot = at.getAccessibleObject(xWindow);
691cdf0e10cSrcweir         XAccessible parent = null;
692cdf0e10cSrcweir 
693cdf0e10cSrcweir         try {
694cdf0e10cSrcweir             parent = at.getAccessibleObjectForRole
695cdf0e10cSrcweir                 (xRoot, AccessibleRole.HEADER, "").getAccessibleChild(0);
696cdf0e10cSrcweir             oObj = parent.getAccessibleContext().getAccessibleChild(0);
697cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
698cdf0e10cSrcweir             fail(iabe.getMessage());
699cdf0e10cSrcweir             return;
700cdf0e10cSrcweir         }
701cdf0e10cSrcweir 
702cdf0e10cSrcweir         System.out.println("ImplementationName " + utils.getImplName(oObj));
703cdf0e10cSrcweir 
704cdf0e10cSrcweir         XAccessibleComponent accPC =
705cdf0e10cSrcweir                 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
706cdf0e10cSrcweir 
707cdf0e10cSrcweir         System.out.println("Parent-BoundsX= "+accPC.getBounds().X);
708cdf0e10cSrcweir         System.out.println("Parent-BoundsY= "+accPC.getBounds().Y);
709cdf0e10cSrcweir         System.out.println("Parent-BoundsWidth= "+accPC.getBounds().Width);
710cdf0e10cSrcweir         System.out.println("Parent-BoundsHeight= "+accPC.getBounds().Height);
711cdf0e10cSrcweir 
712cdf0e10cSrcweir         XAccessibleComponent accPPC =
713cdf0e10cSrcweir                         UnoRuntime.queryInterface(XAccessibleComponent.class,
714cdf0e10cSrcweir                         parent.getAccessibleContext().getAccessibleParent());
715cdf0e10cSrcweir 
716cdf0e10cSrcweir         System.out.println("P-Parent-BoundsX= "+accPPC.getBounds().X);
717cdf0e10cSrcweir         System.out.println("P-Parent-BoundsY= "+accPPC.getBounds().Y);
718cdf0e10cSrcweir         System.out.println("P-Parent-BoundsWidth= "+accPPC.getBounds().Width);
719cdf0e10cSrcweir         System.out.println("P-Parent-BoundsHeight= "+accPPC.getBounds().Height);
720cdf0e10cSrcweir 
721cdf0e10cSrcweir         try {
722cdf0e10cSrcweir             Thread.sleep(500);
723cdf0e10cSrcweir         } catch (InterruptedException ex) {}
724cdf0e10cSrcweir 
725cdf0e10cSrcweir         System.out.println("Press any key when the header is not visible.");
726cdf0e10cSrcweir         try{
727cdf0e10cSrcweir             byte[]b = new byte[16];
728cdf0e10cSrcweir             System.in.read(b);
729cdf0e10cSrcweir         } catch (Exception e) {
730cdf0e10cSrcweir             e.printStackTrace();
731cdf0e10cSrcweir         }
732cdf0e10cSrcweir 
733cdf0e10cSrcweir         int childCount = 0;
734cdf0e10cSrcweir         childCount =
735cdf0e10cSrcweir                 parent.getAccessibleContext().getAccessibleChildCount();
736cdf0e10cSrcweir         System.out.println("ChildCount: "+childCount);
737cdf0e10cSrcweir 
738cdf0e10cSrcweir         if (childCount != 0)
739cdf0e10cSrcweir         {
740cdf0e10cSrcweir             fail("Could access header although it was not visible on page.");
741cdf0e10cSrcweir         }
742cdf0e10cSrcweir 
743cdf0e10cSrcweir 
744cdf0e10cSrcweir         try {
745cdf0e10cSrcweir             parent = at.getAccessibleObjectForRole
746cdf0e10cSrcweir                 (xRoot, AccessibleRole.FOOTER, "").getAccessibleChild(0);
747cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
748cdf0e10cSrcweir             fail(iabe.getMessage());
749cdf0e10cSrcweir             return;
750cdf0e10cSrcweir         }
751cdf0e10cSrcweir 
752cdf0e10cSrcweir         accPC =
753cdf0e10cSrcweir                 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
754cdf0e10cSrcweir 
755cdf0e10cSrcweir         System.out.println("Press any key when the footer is not visible.");
756cdf0e10cSrcweir         try{
757cdf0e10cSrcweir             byte[]b = new byte[16];
758cdf0e10cSrcweir             System.in.read(b);
759cdf0e10cSrcweir         } catch (Exception e) {
760cdf0e10cSrcweir             e.printStackTrace();
761cdf0e10cSrcweir         }
762cdf0e10cSrcweir 
763cdf0e10cSrcweir         childCount =
764cdf0e10cSrcweir                 parent.getAccessibleContext().getAccessibleChildCount();
765cdf0e10cSrcweir         System.out.println("ChildCount: "+childCount);
766cdf0e10cSrcweir 
767cdf0e10cSrcweir         if (childCount != 0)
768cdf0e10cSrcweir         {
769cdf0e10cSrcweir             fail("Could access footer although it was not visible on page.");
770cdf0e10cSrcweir         }
771cdf0e10cSrcweir 
772cdf0e10cSrcweir         XComponent xComp =UnoRuntime.queryInterface(
773cdf0e10cSrcweir                                         XComponent.class, xSpreadsheetDoc);
774cdf0e10cSrcweir         xComp.dispose();
775cdf0e10cSrcweir 
776cdf0e10cSrcweir     }
777cdf0e10cSrcweir 
778cdf0e10cSrcweir 
779cdf0e10cSrcweir 
780cdf0e10cSrcweir 
781cdf0e10cSrcweir     /**
782cdf0e10cSrcweir      * Check the preview of header cells
783cdf0e10cSrcweir      */
checkPreviewHeaderCells()784cdf0e10cSrcweir     @Test public void checkPreviewHeaderCells() {
785cdf0e10cSrcweir 
786cdf0e10cSrcweir         XInterface oObj = null;
787cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory( mXMSF);
788cdf0e10cSrcweir         XSpreadsheetDocument xSpreadsheetDoc = null;
789cdf0e10cSrcweir 
790cdf0e10cSrcweir         try {
791cdf0e10cSrcweir             System.out.println("Creating a spreadsheet document");
792cdf0e10cSrcweir             xSpreadsheetDoc = SOF.createCalcDoc(null);
793cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
794cdf0e10cSrcweir             fail(e.getMessage());
795cdf0e10cSrcweir             return;
796cdf0e10cSrcweir         }
797cdf0e10cSrcweir 
798cdf0e10cSrcweir         XModel xModel =
799cdf0e10cSrcweir             UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
800cdf0e10cSrcweir 
801cdf0e10cSrcweir         XController xController = xModel.getCurrentController();
802cdf0e10cSrcweir 
803cdf0e10cSrcweir         //setting value of cell A1
804cdf0e10cSrcweir         XCell xCell = null;
805cdf0e10cSrcweir         try {
806cdf0e10cSrcweir             System.out.println("Getting spreadsheet") ;
807cdf0e10cSrcweir             XSpreadsheets oSheets = xSpreadsheetDoc.getSheets() ;
808cdf0e10cSrcweir             XIndexAccess oIndexSheets =
809cdf0e10cSrcweir             UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
810cdf0e10cSrcweir             Object o = oIndexSheets.getByIndex(0);
811cdf0e10cSrcweir             XSpreadsheet oSheet = (XSpreadsheet)AnyConverter.toObject(
812cdf0e10cSrcweir                             new com.sun.star.uno.Type(XSpreadsheet.class), o);
813cdf0e10cSrcweir 
814cdf0e10cSrcweir             System.out.println("Getting a cell from sheet") ;
815cdf0e10cSrcweir             xCell = oSheet.getCellByPosition(0, 0);
816cdf0e10cSrcweir         } catch(com.sun.star.lang.IllegalArgumentException e) {
817cdf0e10cSrcweir             fail(e.getMessage());
818cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
819cdf0e10cSrcweir             fail(e.getMessage());
820cdf0e10cSrcweir             return;
821cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
822cdf0e10cSrcweir             fail(e.getMessage());
823cdf0e10cSrcweir             return;
824cdf0e10cSrcweir         }
825cdf0e10cSrcweir 
826cdf0e10cSrcweir         xCell.setFormula("Value");
827cdf0e10cSrcweir 
828cdf0e10cSrcweir         //setting property 'PrintHeaders' of the style 'Default'
829cdf0e10cSrcweir         XStyleFamiliesSupplier xSFS =
830cdf0e10cSrcweir             UnoRuntime.queryInterface(XStyleFamiliesSupplier.class,
831cdf0e10cSrcweir                                                             xSpreadsheetDoc);
832cdf0e10cSrcweir         XNameAccess xNA = xSFS.getStyleFamilies();
833cdf0e10cSrcweir         XPropertySet xPropSet = null;
834cdf0e10cSrcweir         try {
835cdf0e10cSrcweir             Object oPageStyles = xNA.getByName("PageStyles");
836cdf0e10cSrcweir             xNA =
837cdf0e10cSrcweir                 UnoRuntime.queryInterface(XNameAccess.class, oPageStyles);
838cdf0e10cSrcweir             Object oDefStyle = xNA.getByName("Default");
839cdf0e10cSrcweir             xPropSet =
840cdf0e10cSrcweir                 UnoRuntime.queryInterface(XPropertySet.class, oDefStyle);
841cdf0e10cSrcweir         } catch(com.sun.star.lang.WrappedTargetException e) {
842cdf0e10cSrcweir             fail(e.getMessage());
843cdf0e10cSrcweir             return;
844cdf0e10cSrcweir         } catch(com.sun.star.container.NoSuchElementException e) {
845cdf0e10cSrcweir             fail(e.getMessage());
846cdf0e10cSrcweir             return;
847cdf0e10cSrcweir         }
848cdf0e10cSrcweir 
849cdf0e10cSrcweir         try {
850cdf0e10cSrcweir             xPropSet.setPropertyValue("PrintHeaders", new Boolean(true));
851cdf0e10cSrcweir         } catch(com.sun.star.lang.WrappedTargetException e) {
852cdf0e10cSrcweir             fail(e.getMessage());
853cdf0e10cSrcweir             return;
854cdf0e10cSrcweir         } catch(com.sun.star.lang.IllegalArgumentException e) {
855cdf0e10cSrcweir             fail(e.getMessage());
856cdf0e10cSrcweir             return;
857cdf0e10cSrcweir         } catch(com.sun.star.beans.PropertyVetoException e) {
858cdf0e10cSrcweir             fail(e.getMessage());
859cdf0e10cSrcweir             return;
860cdf0e10cSrcweir         } catch(com.sun.star.beans.UnknownPropertyException e) {
861cdf0e10cSrcweir             fail(e.getMessage());
862cdf0e10cSrcweir             return;
863cdf0e10cSrcweir         }
864cdf0e10cSrcweir 
865cdf0e10cSrcweir         //switching to 'Print Preview' mode
866cdf0e10cSrcweir         try {
867cdf0e10cSrcweir             XDispatchProvider xDispProv =
868cdf0e10cSrcweir                 UnoRuntime.queryInterface(XDispatchProvider.class, xController);
869cdf0e10cSrcweir             XURLTransformer xParser =
870cdf0e10cSrcweir                 UnoRuntime.queryInterface(XURLTransformer.class,
871cdf0e10cSrcweir             mXMSF.createInstance("com.sun.star.util.URLTransformer"));
872cdf0e10cSrcweir             URL[] aParseURL = new URL[1];
873cdf0e10cSrcweir             aParseURL[0] = new URL();
874cdf0e10cSrcweir             aParseURL[0].Complete = ".uno:PrintPreview";
875cdf0e10cSrcweir             xParser.parseStrict(aParseURL);
876cdf0e10cSrcweir             URL aURL = aParseURL[0];
877cdf0e10cSrcweir             XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
878cdf0e10cSrcweir             if(xDispatcher != null)
879cdf0e10cSrcweir             {
880cdf0e10cSrcweir                 xDispatcher.dispatch( aURL, null );
881cdf0e10cSrcweir             }
882cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
883cdf0e10cSrcweir             fail(e.getMessage());
884cdf0e10cSrcweir             return;
885cdf0e10cSrcweir         }
886cdf0e10cSrcweir 
887cdf0e10cSrcweir         try {
888cdf0e10cSrcweir             Thread.currentThread().sleep(500) ;
889cdf0e10cSrcweir         } catch (InterruptedException e) {
890cdf0e10cSrcweir             System.out.println("While waiting :" + e) ;
891cdf0e10cSrcweir         }
892cdf0e10cSrcweir 
893cdf0e10cSrcweir         AccessibilityTools at = new AccessibilityTools();
894cdf0e10cSrcweir 
895cdf0e10cSrcweir         XWindow xWindow = at.getCurrentWindow(mXMSF, xModel);
896cdf0e10cSrcweir         XAccessible xRoot = at.getAccessibleObject(xWindow);
897cdf0e10cSrcweir 
898cdf0e10cSrcweir //        System.out.println("ImplementationName " + utils.getImplName(oObj));
899cdf0e10cSrcweir 
900cdf0e10cSrcweir         System.out.println("Press any key when the header cell is on top.");
901cdf0e10cSrcweir         try{
902cdf0e10cSrcweir             byte[]b = new byte[16];
903cdf0e10cSrcweir             System.in.read(b);
904cdf0e10cSrcweir         } catch (Exception e) {
905cdf0e10cSrcweir             e.printStackTrace();
906cdf0e10cSrcweir         }
907cdf0e10cSrcweir 
908cdf0e10cSrcweir 
909cdf0e10cSrcweir         XAccessible parent = null;
910cdf0e10cSrcweir 
911cdf0e10cSrcweir         try {
912cdf0e10cSrcweir             System.out.println("Count: " +at.getAccessibleObjectForRole
913cdf0e10cSrcweir                 (xRoot, AccessibleRole.TABLE, "").getAccessibleChildCount());
914cdf0e10cSrcweir //            parent = at.getAccessibleObjectForRole
915cdf0e10cSrcweir //                (xRoot, AccessibleRole.TABLE, "").getAccessibleChild(0);
916cdf0e10cSrcweir //            oObj = parent.getAccessibleContext().getAccessibleChild(1);
917cdf0e10cSrcweir             System.out.println("Getting child 2");
918cdf0e10cSrcweir             oObj = at.getAccessibleObjectForRole
919cdf0e10cSrcweir                 (xRoot, AccessibleRole.TABLE, "").getAccessibleChild(2);
920cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
921cdf0e10cSrcweir             fail(iabe.getMessage());
922cdf0e10cSrcweir             return;
923cdf0e10cSrcweir         }
924cdf0e10cSrcweir 
925cdf0e10cSrcweir         System.out.println("*** DEBUG INFO ***");
926cdf0e10cSrcweir         util.dbg.getSuppServices(oObj);
927cdf0e10cSrcweir         System.out.println("****** IFC ******");
928cdf0e10cSrcweir         util.dbg.printInterfaces(oObj);
929cdf0e10cSrcweir         System.out.println("*****************");
930cdf0e10cSrcweir 
931cdf0e10cSrcweir 
932cdf0e10cSrcweir /*        XAccessibleContext accCtx = (XAccessibleContext)
933cdf0e10cSrcweir                 UnoRuntime.queryInterface(XAccessibleContext.class, oObj);
934cdf0e10cSrcweir         try {
935cdf0e10cSrcweir             System.out.println("Children now: " + accCtx.getAccessibleChild(0).getAccessibleContext().getAccessibleChildCount());
936cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
937cdf0e10cSrcweir             fail(iabe.getMessage());
938cdf0e10cSrcweir             return;
939cdf0e10cSrcweir         }
940cdf0e10cSrcweir */
941cdf0e10cSrcweir 
942cdf0e10cSrcweir         XAccessibleValue accV =
943cdf0e10cSrcweir                 UnoRuntime.queryInterface(XAccessibleValue.class, oObj);
944cdf0e10cSrcweir         Object o = accV.getCurrentValue();
945cdf0e10cSrcweir         System.out.println("Getting the value: "+o + " is void " + util.utils.isVoid(o));
946cdf0e10cSrcweir 
947cdf0e10cSrcweir 
948cdf0e10cSrcweir         XAccessibleComponent accC =
949cdf0e10cSrcweir                 UnoRuntime.queryInterface(XAccessibleComponent.class, oObj);
950cdf0e10cSrcweir 
951cdf0e10cSrcweir         System.out.println("BoundsX= "+accC.getBounds().X);
952cdf0e10cSrcweir         System.out.println("BoundsY= "+accC.getBounds().Y);
953cdf0e10cSrcweir         System.out.println("BoundsWidth= "+accC.getBounds().Width);
954cdf0e10cSrcweir         System.out.println("BoundsHeight= "+accC.getBounds().Height);
955cdf0e10cSrcweir 
956cdf0e10cSrcweir         XComponent xComp = UnoRuntime.queryInterface(
957cdf0e10cSrcweir                                         XComponent.class, xSpreadsheetDoc);
958cdf0e10cSrcweir         xComp.dispose();
959cdf0e10cSrcweir 
960cdf0e10cSrcweir     }
961cdf0e10cSrcweir 
962cdf0e10cSrcweir 
963cdf0e10cSrcweir 
964cdf0e10cSrcweir 
965cdf0e10cSrcweir 
966cdf0e10cSrcweir     /**
967cdf0e10cSrcweir      * Check the preview of Shapes: load a document with shapes and see, if they
968cdf0e10cSrcweir      * are accessible.
969cdf0e10cSrcweir      */
checkPreviewShape()970cdf0e10cSrcweir     @Test public void checkPreviewShape() {
971cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory( mXMSF );
972cdf0e10cSrcweir         XSpreadsheetDocument xSpreadsheetDoc = null;
973cdf0e10cSrcweir         XComponent xComp = null;
974cdf0e10cSrcweir         XInterface oObj = null;
975cdf0e10cSrcweir 
976cdf0e10cSrcweir         try {
977cdf0e10cSrcweir             String docName = "calcshapes.sxc";
978cdf0e10cSrcweir             System.out.println("Loading a spreadsheetdocument.");
979cdf0e10cSrcweir             // String url = utils.getFullURL((String)param.get("TestDocumentPath") + "/" + docName);
980cdf0e10cSrcweir             String url = TestDocument.getUrl(docName);
981cdf0e10cSrcweir             System.out.println("loading document '" + url + "'");
982cdf0e10cSrcweir             xComp = SOF.loadDocument(url);
983cdf0e10cSrcweir             assertNotNull(xComp);
984cdf0e10cSrcweir         }
985cdf0e10cSrcweir         catch (com.sun.star.uno.Exception e) {
986cdf0e10cSrcweir             fail(e.getMessage());
987cdf0e10cSrcweir             return;
988cdf0e10cSrcweir         }
989cdf0e10cSrcweir 
990cdf0e10cSrcweir         try {
991cdf0e10cSrcweir             Thread.currentThread().sleep(500) ;
992cdf0e10cSrcweir         } catch (InterruptedException e) {
993cdf0e10cSrcweir             System.out.println("While waiting :" + e) ;
994cdf0e10cSrcweir         }
995cdf0e10cSrcweir 
996cdf0e10cSrcweir         if (xComp == null) {
997cdf0e10cSrcweir             fail("loading document failed.");
998cdf0e10cSrcweir             return;
999cdf0e10cSrcweir         }
1000cdf0e10cSrcweir 
1001cdf0e10cSrcweir         xSpreadsheetDoc = UnoRuntime.queryInterface(
1002cdf0e10cSrcweir                                             XSpreadsheetDocument.class, xComp);
1003cdf0e10cSrcweir         XModel aModel =
1004cdf0e10cSrcweir             UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
1005cdf0e10cSrcweir 
1006cdf0e10cSrcweir         XController xController = aModel.getCurrentController();
1007cdf0e10cSrcweir 
1008cdf0e10cSrcweir         // switching to 'Page Preview' mode
1009cdf0e10cSrcweir         try {
1010cdf0e10cSrcweir             XDispatchProvider xDispProv =
1011cdf0e10cSrcweir                 UnoRuntime.queryInterface(XDispatchProvider.class, xController);
1012cdf0e10cSrcweir             XURLTransformer xParser =
1013cdf0e10cSrcweir                 UnoRuntime.queryInterface(XURLTransformer.class,
1014cdf0e10cSrcweir             mXMSF.createInstance("com.sun.star.util.URLTransformer"));
1015cdf0e10cSrcweir             // Because it's an in/out parameter we must use an
1016cdf0e10cSrcweir             // array of URL objects.
1017cdf0e10cSrcweir             URL[] aParseURL = new URL[1];
1018cdf0e10cSrcweir             aParseURL[0] = new URL();
1019cdf0e10cSrcweir             aParseURL[0].Complete = ".uno:PrintPreview";
1020cdf0e10cSrcweir             xParser.parseStrict(aParseURL);
1021cdf0e10cSrcweir             URL aURL = aParseURL[0];
1022cdf0e10cSrcweir             XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
1023cdf0e10cSrcweir             if(xDispatcher != null)
1024cdf0e10cSrcweir             {
1025cdf0e10cSrcweir                 xDispatcher.dispatch( aURL, null );
1026cdf0e10cSrcweir             }
1027cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
1028cdf0e10cSrcweir             fail("Couldn't change mode");
1029cdf0e10cSrcweir             return;
1030cdf0e10cSrcweir         }
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir         try {
1033cdf0e10cSrcweir             Thread.currentThread().sleep(500) ;
1034cdf0e10cSrcweir         } catch (InterruptedException e) {
1035cdf0e10cSrcweir             System.out.println("While waiting :" + e) ;
1036cdf0e10cSrcweir         }
1037cdf0e10cSrcweir 
1038cdf0e10cSrcweir 
1039cdf0e10cSrcweir 
1040cdf0e10cSrcweir         System.out.println("Press any key when a shape is on top.");
1041cdf0e10cSrcweir         try{
1042cdf0e10cSrcweir             byte[]b = new byte[16];
1043cdf0e10cSrcweir             System.in.read(b);
1044cdf0e10cSrcweir         } catch (Exception e) {
1045cdf0e10cSrcweir             e.printStackTrace();
1046cdf0e10cSrcweir         }
1047cdf0e10cSrcweir 
1048cdf0e10cSrcweir         // get the accessible content
1049cdf0e10cSrcweir         AccessibilityTools at = new AccessibilityTools();
1050cdf0e10cSrcweir 
1051cdf0e10cSrcweir         XWindow xWindow = at.getCurrentWindow(mXMSF, aModel);
1052cdf0e10cSrcweir         XAccessible xRoot = at.getAccessibleObject(xWindow);
1053cdf0e10cSrcweir         XAccessible parent = null;
1054cdf0e10cSrcweir 
1055cdf0e10cSrcweir         try {
1056cdf0e10cSrcweir             XAccessibleContext con = at.getAccessibleObjectForRole
1057cdf0e10cSrcweir                                 (xRoot, AccessibleRole.SHAPE, "");
1058cdf0e10cSrcweir             System.out.println("Name of AccessibleContext: " + con.getAccessibleName());
1059cdf0e10cSrcweir             oObj = con;
1060cdf0e10cSrcweir         } catch (Exception e) {
1061cdf0e10cSrcweir             fail(e.getMessage());
1062cdf0e10cSrcweir             return;
1063cdf0e10cSrcweir         }
1064cdf0e10cSrcweir 
1065cdf0e10cSrcweir         System.out.println("ImplementationName: " + utils.getImplName(oObj));
1066cdf0e10cSrcweir         util.dbg.printInterfaces(oObj);
1067cdf0e10cSrcweir 
1068cdf0e10cSrcweir         xComp.dispose();
1069cdf0e10cSrcweir     }
1070cdf0e10cSrcweir 
setUpConnection()1071cdf0e10cSrcweir     @BeforeClass public static void setUpConnection() throws Exception {
1072cdf0e10cSrcweir         connection.setUp();
1073cdf0e10cSrcweir     }
1074cdf0e10cSrcweir 
tearDownConnection()1075cdf0e10cSrcweir     @AfterClass public static void tearDownConnection()
1076cdf0e10cSrcweir         throws InterruptedException, com.sun.star.uno.Exception
1077cdf0e10cSrcweir     {
1078cdf0e10cSrcweir         connection.tearDown();
1079cdf0e10cSrcweir     }
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir     private static final OfficeConnection connection = new OfficeConnection();
1082cdf0e10cSrcweir 
1083cdf0e10cSrcweir }
1084