1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ViewForwarder.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package complex
.calcPreview
;
33 import complexlib
.ComplexTestCase
;
35 import com
.sun
.star
.awt
.XWindow
;
36 import com
.sun
.star
.container
.XIndexAccess
;
37 import com
.sun
.star
.frame
.XController
;
38 import com
.sun
.star
.frame
.XDispatch
;
39 import com
.sun
.star
.frame
.XDispatchProvider
;
40 import com
.sun
.star
.frame
.XModel
;
41 import com
.sun
.star
.lang
.XComponent
;
42 import com
.sun
.star
.lang
.XMultiServiceFactory
;
43 import com
.sun
.star
.sheet
.XSpreadsheet
;
44 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
45 import com
.sun
.star
.sheet
.XSpreadsheets
;
46 import com
.sun
.star
.table
.XCell
;
47 import com
.sun
.star
.uno
.Any
;
48 import com
.sun
.star
.uno
.AnyConverter
;
49 import com
.sun
.star
.uno
.UnoRuntime
;
50 import com
.sun
.star
.uno
.XInterface
;
51 import com
.sun
.star
.util
.URL
;
52 import com
.sun
.star
.util
.XURLTransformer
;
53 import com
.sun
.star
.accessibility
.AccessibleRole
;
54 import com
.sun
.star
.accessibility
.XAccessible
;
55 import com
.sun
.star
.accessibility
.XAccessibleText
;
56 import com
.sun
.star
.accessibility
.XAccessibleValue
;
57 import com
.sun
.star
.accessibility
.XAccessibleComponent
;
58 import com
.sun
.star
.accessibility
.XAccessibleContext
;
60 import util
.AccessibilityTools
;
61 import util
.SOfficeFactory
;
64 import com
.sun
.star
.beans
.XPropertySet
;
65 import com
.sun
.star
.beans
.XPropertySetInfo
;
66 import com
.sun
.star
.container
.XNameAccess
;
67 import com
.sun
.star
.lang
.XComponent
;
68 import com
.sun
.star
.sheet
.XHeaderFooterContent
;
69 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
70 import com
.sun
.star
.style
.XStyle
;
71 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
72 import com
.sun
.star
.text
.XText
;
73 import com
.sun
.star
.drawing
.XDrawPageSupplier
;
74 import com
.sun
.star
.drawing
.XDrawPage
;
75 import com
.sun
.star
.drawing
.XShape
;
76 import com
.sun
.star
.drawing
.XShapes
;
79 import com
.sun
.star
.beans
.Property
;
80 import com
.sun
.star
.lang
.XServiceInfo
;
83 * A complex test for the preview of Calc documents. This complex test
84 * needs interaction from the user: documents have to be resized and moved.
86 public class ViewForwarder
extends ComplexTestCase
{
88 /** The MultiServiceFactory **/
89 private XMultiServiceFactory mXMSF
= null;
91 /** Get all test methods.
92 * @return The test methods.
94 public String
[] getTestMethodNames() {
95 return new String
[]{"checkPositiveViewForwarder",
96 "checkNegativeViewForwarder",
97 "checkPreviewHeaderCells",
103 * Get a MultiServiceFactory from the Office before the test.
105 public void before() {
106 mXMSF
= (XMultiServiceFactory
)param
.getMSF();
110 /** Create a spreadsheet document, insert some text, header and footer.
111 * Let the user resize the document and check the contents.
113 public void checkPositiveViewForwarder() {
114 SOfficeFactory SOF
= SOfficeFactory
.getFactory( mXMSF
);
115 XSpreadsheetDocument xSpreadsheetDoc
= null;
118 log
.println("Creating a spreadsheet document");
119 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
120 } catch (com
.sun
.star
.uno
.Exception e
) {
121 failed(e
.getMessage());
125 XInterface oObj
= null;
127 // inserting some content to have non-empty page preview
130 XSpreadsheets oSheets
= xSpreadsheetDoc
.getSheets() ;
131 XIndexAccess oIndexSheets
= (XIndexAccess
)
132 UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
133 Object o
= oIndexSheets
.getByIndex(0);
134 XSpreadsheet oSheet
= (XSpreadsheet
)AnyConverter
.toObject(
135 new com
.sun
.star
.uno
.Type(XSpreadsheet
.class), o
);
136 xCell
= oSheet
.getCellByPosition(0, 0) ;
137 xCell
.setFormula("ScAccessiblePageHeader");
139 xCell
= oSheet
.getCellByPosition(0, 1) ;
140 xCell
.setFormula("Cell 1");
141 xCell
= oSheet
.getCellByPosition(0, 2) ;
142 xCell
.setFormula("Cell 2");
143 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
144 log
.println("Exception ceating relation :");
145 failed(e
.getMessage());
146 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
147 log
.println("Exception ceating relation :");
148 failed(e
.getMessage());
149 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
150 log
.println("Exception ceating relation :");
151 failed(e
.getMessage());
154 XModel aModel
= (XModel
)
155 UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc
);
157 XController xController
= aModel
.getCurrentController();
160 XStyleFamiliesSupplier StyleFam
= (XStyleFamiliesSupplier
)
161 UnoRuntime
.queryInterface(
162 XStyleFamiliesSupplier
.class,
164 XNameAccess StyleFamNames
= StyleFam
.getStyleFamilies();
165 XStyle StdStyle
= null;
168 Object o
= StyleFamNames
.getByName("PageStyles");
169 XNameAccess PageStyles
= (XNameAccess
)AnyConverter
.toObject(
170 new com
.sun
.star
.uno
.Type(XNameAccess
.class), o
);
172 o
= PageStyles
.getByName("Default");
173 StdStyle
= (XStyle
)AnyConverter
.toObject(
174 new com
.sun
.star
.uno
.Type(XStyle
.class), o
);
175 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
176 failed(e
.getMessage());
177 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
178 failed(e
.getMessage());
180 } catch(com
.sun
.star
.container
.NoSuchElementException e
){
181 failed(e
.getMessage());
185 //get the property-set
186 final XPropertySet PropSet
= (XPropertySet
)
187 UnoRuntime
.queryInterface(XPropertySet
.class, StdStyle
);
189 XHeaderFooterContent RPHFC
= null;
193 Object o
= PropSet
.getPropertyValue("RightPageHeaderContent");
194 RPHFC
= (XHeaderFooterContent
)AnyConverter
.toObject(
195 new com
.sun
.star
.uno
.Type(XHeaderFooterContent
.class), o
);
197 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
198 failed(e
.getMessage());
199 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
200 failed(e
.getMessage());
202 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
203 failed(e
.getMessage());
207 // insert text into header
208 XText center
= RPHFC
.getCenterText();
209 center
.setString("First line \n\r Second line \n\r third line ");
211 PropSet
.setPropertyValue("RightPageHeaderContent",RPHFC
);
212 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
213 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
214 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
215 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {}
220 Object o
= PropSet
.getPropertyValue("RightPageHeaderContent");
221 RPHFC
= (XHeaderFooterContent
)AnyConverter
.toObject(
222 new com
.sun
.star
.uno
.Type(XHeaderFooterContent
.class), o
);
223 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
224 failed(e
.getMessage());
225 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
226 failed(e
.getMessage());
228 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
229 failed(e
.getMessage());
233 // insert text into footer
234 center
= RPHFC
.getCenterText();
235 center
.setString("Third last line\n\r Second last line\n\r last line");
237 PropSet
.setPropertyValue("RightPageFooterContent",RPHFC
);
238 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
239 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
240 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
241 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {}
243 // switching to 'Page Preview' mode
245 XDispatchProvider xDispProv
= (XDispatchProvider
)
246 UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
247 XURLTransformer xParser
= (com
.sun
.star
.util
.XURLTransformer
)
248 UnoRuntime
.queryInterface(XURLTransformer
.class,
249 mXMSF
.createInstance("com.sun.star.util.URLTransformer"));
250 // Because it's an in/out parameter we must use an
251 // array of URL objects.
252 URL
[] aParseURL
= new URL
[1];
253 aParseURL
[0] = new URL();
254 aParseURL
[0].Complete
= ".uno:PrintPreview";
255 xParser
.parseStrict(aParseURL
);
256 URL aURL
= aParseURL
[0];
257 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
258 if(xDispatcher
!= null)
259 xDispatcher
.dispatch( aURL
, null );
260 } catch (com
.sun
.star
.uno
.Exception e
) {
261 failed("Couldn't change mode");
267 } catch (InterruptedException ex
) {}
269 log
.println("Press any key after resizing ");
271 byte[]b
= new byte[16];
273 } catch (Exception e
) {
277 // get the accessible content
278 AccessibilityTools at
= new AccessibilityTools();
280 XWindow xWindow
= at
.getCurrentWindow(mXMSF
, aModel
);
281 XAccessible xRoot
= at
.getAccessibleObject(xWindow
);
282 XAccessible parent
= null;
285 parent
= at
.getAccessibleObjectForRole
286 (xRoot
, AccessibleRole
.HEADER
, "").getAccessibleChild(0);
287 oObj
= parent
.getAccessibleContext().getAccessibleChild(0);
288 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
289 failed(iabe
.getMessage());
293 log
.println("ImplementationName " + utils
.getImplName(oObj
));
295 XAccessibleComponent accPC
= (XAccessibleComponent
)
296 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
298 log
.println("Parent-BoundsX= "+accPC
.getBounds().X
);
299 log
.println("Parent-BoundsY= "+accPC
.getBounds().Y
);
300 log
.println("Parent-BoundsWidth= "+accPC
.getBounds().Width
);
301 log
.println("Parent-BoundsHeight= "+accPC
.getBounds().Height
);
303 XAccessibleComponent accPPC
= (XAccessibleComponent
)
304 UnoRuntime
.queryInterface(XAccessibleComponent
.class,
305 parent
.getAccessibleContext().getAccessibleParent());
307 log
.println("P-Parent-BoundsX= "+accPPC
.getBounds().X
);
308 log
.println("P-Parent-BoundsY= "+accPPC
.getBounds().Y
);
309 log
.println("P-Parent-BoundsWidth= "+accPPC
.getBounds().Width
);
310 log
.println("P-Parent-BoundsHeight= "+accPPC
.getBounds().Height
);
314 } catch (InterruptedException ex
) {}
316 log
.println("Press any key when the second line is on top");
318 byte[]b
= new byte[16];
320 } catch (Exception e
) {
325 log
.println("ChildCount: "+
326 parent
.getAccessibleContext().getAccessibleChildCount());
327 log
.println("Getting child 0 again");
328 oObj
= parent
.getAccessibleContext().getAccessibleChild(0);
329 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
330 failed(iabe
.getMessage());
334 XAccessibleText accT
= (XAccessibleText
)
335 UnoRuntime
.queryInterface(XAccessibleText
.class, oObj
);
336 log
.println("Getting the text: "+accT
.getText());
338 XAccessibleComponent accC
= (XAccessibleComponent
)
339 UnoRuntime
.queryInterface(XAccessibleComponent
.class, oObj
);
340 log
.println("BoundsX= "+accC
.getBounds().X
);
341 log
.println("BoundsY= "+accC
.getBounds().Y
);
342 log
.println("BoundsWidth= "+accC
.getBounds().Width
);
343 log
.println("BoundsHeight= "+accC
.getBounds().Height
);
345 accPC
= (XAccessibleComponent
)
346 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
348 log
.println("Parent-BoundsX= "+accPC
.getBounds().X
);
349 log
.println("Parent-BoundsY= "+accPC
.getBounds().Y
);
350 log
.println("Parent-BoundsWidth= "+accPC
.getBounds().Width
);
351 log
.println("Parent-BoundsHeight= "+accPC
.getBounds().Height
);
353 accPPC
= (XAccessibleComponent
)
354 UnoRuntime
.queryInterface(XAccessibleComponent
.class,
355 parent
.getAccessibleContext().getAccessibleParent());
357 log
.println("P-Parent-BoundsX= "+accPPC
.getBounds().X
);
358 log
.println("P-Parent-BoundsY= "+accPPC
.getBounds().Y
);
359 log
.println("P-Parent-BoundsWidth= "+accPPC
.getBounds().Width
);
360 log
.println("P-Parent-BoundsHeight= "+accPPC
.getBounds().Height
);
364 log
.println("Press any key when the footer is visible.");
366 byte[]b
= new byte[16];
368 } catch (Exception e
) {
373 parent
= at
.getAccessibleObjectForRole
374 (xRoot
, AccessibleRole
.FOOTER
, "").getAccessibleChild(0);
375 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
376 failed(iabe
.getMessage());
380 accPC
= (XAccessibleComponent
)
381 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
384 log
.println("ChildCount: "+
385 parent
.getAccessibleContext().getAccessibleChildCount());
386 log
.println("Getting child 0 again");
387 oObj
= parent
.getAccessibleContext().getAccessibleChild(0);
388 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
389 failed(iabe
.getMessage());
393 accT
= (XAccessibleText
)
394 UnoRuntime
.queryInterface(XAccessibleText
.class, oObj
);
395 log
.println("Getting the text: "+accT
.getText());
397 accC
= (XAccessibleComponent
)
398 UnoRuntime
.queryInterface(XAccessibleComponent
.class, oObj
);
399 log
.println("BoundsX= "+accC
.getBounds().X
);
400 log
.println("BoundsY= "+accC
.getBounds().Y
);
401 log
.println("BoundsWidth= "+accC
.getBounds().Width
);
402 log
.println("BoundsHeight= "+accC
.getBounds().Height
);
404 accPC
= (XAccessibleComponent
)
405 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
407 log
.println("Parent-BoundsX= "+accPC
.getBounds().X
);
408 log
.println("Parent-BoundsY= "+accPC
.getBounds().Y
);
409 log
.println("Parent-BoundsWidth= "+accPC
.getBounds().Width
);
410 log
.println("Parent-BoundsHeight= "+accPC
.getBounds().Height
);
412 accPPC
= (XAccessibleComponent
)
413 UnoRuntime
.queryInterface(XAccessibleComponent
.class,
414 parent
.getAccessibleContext().getAccessibleParent());
416 log
.println("P-Parent-BoundsX= "+accPPC
.getBounds().X
);
417 log
.println("P-Parent-BoundsY= "+accPPC
.getBounds().Y
);
418 log
.println("P-Parent-BoundsWidth= "+accPPC
.getBounds().Width
);
419 log
.println("P-Parent-BoundsHeight= "+accPPC
.getBounds().Height
);
422 log
.println("Press any key when the page content is on top");
424 byte[]b
= new byte[16];
426 } catch (Exception e
) {
431 parent
= at
.getAccessibleObjectForRole
432 (xRoot
, AccessibleRole
.DOCUMENT
, "").getAccessibleChild(0);
433 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
434 failed(iabe
.getMessage());
437 System
.out
.println("PARENT: " + parent
.getAccessibleContext().getAccessibleName());
438 accPC
= (XAccessibleComponent
)
439 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
444 parent
.getAccessibleContext().getAccessibleChildCount();
445 log
.println("ChildCount: "+cCount
);
446 log
.println("Getting child 0 again");
447 oObj
= parent
.getAccessibleContext().getAccessibleChild(0);
448 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
449 failed(iabe
.getMessage());
453 for (int i
=0; i
<cCount
; i
++) {
455 XAccessible xA
= parent
.getAccessibleContext().getAccessibleChild(i
);
456 System
.out
.println("NAME object " + i
+ ": " + xA
.getAccessibleContext().getAccessibleName());
457 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
458 failed(iabe
.getMessage());
463 System
.out
.println("SERVICES:");
464 util
.dbg
.getSuppServices(oObj
);
466 XAccessibleValue accV
= (XAccessibleValue
)
467 UnoRuntime
.queryInterface(XAccessibleValue
.class, oObj
);
468 Object o
= accV
.getCurrentValue();
469 if (o
instanceof String
)
470 System
.out
.println("Value: " + (String
)o
);
472 System
.out
.println("Name of Object: " + o
.getClass().getName());
473 log
.println("Getting the value: "+accV
.getCurrentValue());
478 accC
= (XAccessibleComponent
)
479 UnoRuntime
.queryInterface(XAccessibleComponent
.class, oObj
);
480 log
.println("BoundsX= "+accC
.getBounds().X
);
481 log
.println("BoundsY= "+accC
.getBounds().Y
);
482 log
.println("BoundsWidth= "+accC
.getBounds().Width
);
483 log
.println("BoundsHeight= "+accC
.getBounds().Height
);
485 accPC
= (XAccessibleComponent
)
486 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
488 log
.println("Parent-BoundsX= "+accPC
.getBounds().X
);
489 log
.println("Parent-BoundsY= "+accPC
.getBounds().Y
);
490 log
.println("Parent-BoundsWidth= "+accPC
.getBounds().Width
);
491 log
.println("Parent-BoundsHeight= "+accPC
.getBounds().Height
);
493 accPPC
= (XAccessibleComponent
)
494 UnoRuntime
.queryInterface(XAccessibleComponent
.class,
495 parent
.getAccessibleContext().getAccessibleParent());
497 log
.println("P-Parent-BoundsX= "+accPPC
.getBounds().X
);
498 log
.println("P-Parent-BoundsY= "+accPPC
.getBounds().Y
);
499 log
.println("P-Parent-BoundsWidth= "+accPPC
.getBounds().Width
);
500 log
.println("P-Parent-BoundsHeight= "+accPPC
.getBounds().Height
);
502 XComponent xComp
= (XComponent
)UnoRuntime
.queryInterface(
503 XComponent
.class, xSpreadsheetDoc
);
515 * Create a spreadsheet document, insert some text, header and footer.
516 * Let the user resize the document and check the contents.
518 public void checkNegativeViewForwarder() {
519 SOfficeFactory SOF
= SOfficeFactory
.getFactory( mXMSF
);
520 XSpreadsheetDocument xSpreadsheetDoc
= null;
523 log
.println("Creating a spreadsheet document");
524 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
525 } catch (com
.sun
.star
.uno
.Exception e
) {
526 failed(e
.getMessage());
530 XInterface oObj
= null;
532 // inserting some content to have non-empty page preview
535 XSpreadsheets oSheets
= xSpreadsheetDoc
.getSheets() ;
536 XIndexAccess oIndexSheets
= (XIndexAccess
)
537 UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
538 Object o
= oIndexSheets
.getByIndex(0);
539 XSpreadsheet oSheet
= (XSpreadsheet
)AnyConverter
.toObject(
540 new com
.sun
.star
.uno
.Type(XSpreadsheet
.class), o
);
541 xCell
= oSheet
.getCellByPosition(0, 0) ;
542 xCell
.setFormula("ScAccessiblePageHeader");
544 xCell
= oSheet
.getCellByPosition(0, 1) ;
545 xCell
.setFormula("Cell 1");
546 xCell
= oSheet
.getCellByPosition(0, 2) ;
547 xCell
.setFormula("Cell 2");
548 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
549 log
.println("Exception ceating relation :");
550 failed(e
.getMessage());
551 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
552 log
.println("Exception ceating relation :");
553 failed(e
.getMessage());
554 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
555 log
.println("Exception ceating relation :");
556 failed(e
.getMessage());
559 XModel aModel
= (XModel
)
560 UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc
);
562 XController xController
= aModel
.getCurrentController();
565 XStyleFamiliesSupplier StyleFam
= (XStyleFamiliesSupplier
)
566 UnoRuntime
.queryInterface(
567 XStyleFamiliesSupplier
.class,
569 XNameAccess StyleFamNames
= StyleFam
.getStyleFamilies();
570 XStyle StdStyle
= null;
573 Object o
= StyleFamNames
.getByName("PageStyles");
574 XNameAccess PageStyles
= (XNameAccess
)AnyConverter
.toObject(
575 new com
.sun
.star
.uno
.Type(XNameAccess
.class), o
);
577 o
= PageStyles
.getByName("Default");
578 StdStyle
= (XStyle
)AnyConverter
.toObject(
579 new com
.sun
.star
.uno
.Type(XStyle
.class), o
);
580 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
581 failed(e
.getMessage());
582 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
583 failed(e
.getMessage());
585 } catch(com
.sun
.star
.container
.NoSuchElementException e
){
586 failed(e
.getMessage());
590 //get the property-set
591 final XPropertySet PropSet
= (XPropertySet
)
592 UnoRuntime
.queryInterface(XPropertySet
.class, StdStyle
);
594 XHeaderFooterContent RPHFC
= null;
597 log
.println( "Creating a test environment" );
599 Object o
= PropSet
.getPropertyValue("RightPageHeaderContent");
600 RPHFC
= (XHeaderFooterContent
)AnyConverter
.toObject(
601 new com
.sun
.star
.uno
.Type(XHeaderFooterContent
.class), o
);
602 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
603 failed(e
.getMessage());
604 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
605 failed(e
.getMessage());
607 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
608 failed(e
.getMessage());
612 // insert text into header
613 XText center
= RPHFC
.getCenterText();
614 center
.setString("First line \n\r Second line \n\r third line ");
616 PropSet
.setPropertyValue("RightPageHeaderContent",RPHFC
);
617 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
618 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
619 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
620 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {}
625 Object o
= PropSet
.getPropertyValue("RightPageFooterContent");
626 RPHFC
= (XHeaderFooterContent
)AnyConverter
.toObject(
627 new com
.sun
.star
.uno
.Type(XHeaderFooterContent
.class), o
);
628 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
629 failed(e
.getMessage());
630 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
631 failed(e
.getMessage());
633 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
634 failed(e
.getMessage());
638 // insert text into footer
639 center
= RPHFC
.getCenterText();
640 center
.setString("Third last line\n\r Second last line\n\r last line");
642 PropSet
.setPropertyValue("RightPageFooterContent",RPHFC
);
643 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
644 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
645 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
646 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {}
648 // switching to 'Page Preview' mode
650 XDispatchProvider xDispProv
= (XDispatchProvider
)
651 UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
652 XURLTransformer xParser
= (com
.sun
.star
.util
.XURLTransformer
)
653 UnoRuntime
.queryInterface(XURLTransformer
.class,
654 mXMSF
.createInstance("com.sun.star.util.URLTransformer"));
655 // Because it's an in/out parameter we must use an
656 // array of URL objects.
657 URL
[] aParseURL
= new URL
[1];
658 aParseURL
[0] = new URL();
659 aParseURL
[0].Complete
= ".uno:PrintPreview";
660 xParser
.parseStrict(aParseURL
);
661 URL aURL
= aParseURL
[0];
662 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
663 if(xDispatcher
!= null)
664 xDispatcher
.dispatch( aURL
, null );
665 } catch (com
.sun
.star
.uno
.Exception e
) {
666 failed("Couldn't change mode");
672 } catch (InterruptedException ex
) {}
674 log
.println("Press any key after resizing ");
676 byte[]b
= new byte[16];
678 } catch (Exception e
) {
682 // get the accessible content
683 AccessibilityTools at
= new AccessibilityTools();
685 XWindow xWindow
= at
.getCurrentWindow(mXMSF
, aModel
);
686 XAccessible xRoot
= at
.getAccessibleObject(xWindow
);
687 XAccessible parent
= null;
690 parent
= at
.getAccessibleObjectForRole
691 (xRoot
, AccessibleRole
.HEADER
, "").getAccessibleChild(0);
692 oObj
= parent
.getAccessibleContext().getAccessibleChild(0);
693 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
694 failed(iabe
.getMessage());
698 log
.println("ImplementationName " + utils
.getImplName(oObj
));
700 XAccessibleComponent accPC
= (XAccessibleComponent
)
701 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
703 log
.println("Parent-BoundsX= "+accPC
.getBounds().X
);
704 log
.println("Parent-BoundsY= "+accPC
.getBounds().Y
);
705 log
.println("Parent-BoundsWidth= "+accPC
.getBounds().Width
);
706 log
.println("Parent-BoundsHeight= "+accPC
.getBounds().Height
);
708 XAccessibleComponent accPPC
= (XAccessibleComponent
)
709 UnoRuntime
.queryInterface(XAccessibleComponent
.class,
710 parent
.getAccessibleContext().getAccessibleParent());
712 log
.println("P-Parent-BoundsX= "+accPPC
.getBounds().X
);
713 log
.println("P-Parent-BoundsY= "+accPPC
.getBounds().Y
);
714 log
.println("P-Parent-BoundsWidth= "+accPPC
.getBounds().Width
);
715 log
.println("P-Parent-BoundsHeight= "+accPPC
.getBounds().Height
);
719 } catch (InterruptedException ex
) {}
721 log
.println("Press any key when the header is not visible.");
723 byte[]b
= new byte[16];
725 } catch (Exception e
) {
731 parent
.getAccessibleContext().getAccessibleChildCount();
732 log
.println("ChildCount: "+childCount
);
735 failed("Could access header although it was not visible on page.");
739 parent
= at
.getAccessibleObjectForRole
740 (xRoot
, AccessibleRole
.FOOTER
, "").getAccessibleChild(0);
741 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
742 failed(iabe
.getMessage());
746 accPC
= (XAccessibleComponent
)
747 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
749 log
.println("Press any key when the footer is not visible.");
751 byte[]b
= new byte[16];
753 } catch (Exception e
) {
758 parent
.getAccessibleContext().getAccessibleChildCount();
759 log
.println("ChildCount: "+childCount
);
762 failed("Could access footer although it was not visible on page.");
764 XComponent xComp
= (XComponent
)UnoRuntime
.queryInterface(
765 XComponent
.class, xSpreadsheetDoc
);
774 * Check the preview of header cells
776 public void checkPreviewHeaderCells() {
778 XInterface oObj
= null;
779 SOfficeFactory SOF
= SOfficeFactory
.getFactory( mXMSF
);
780 XSpreadsheetDocument xSpreadsheetDoc
= null;
783 log
.println("Creating a spreadsheet document");
784 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
785 } catch (com
.sun
.star
.uno
.Exception e
) {
786 failed(e
.getMessage());
790 XModel xModel
= (XModel
)
791 UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc
);
793 XController xController
= xModel
.getCurrentController();
795 //setting value of cell A1
798 log
.println("Getting spreadsheet") ;
799 XSpreadsheets oSheets
= xSpreadsheetDoc
.getSheets() ;
800 XIndexAccess oIndexSheets
= (XIndexAccess
)
801 UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
802 Object o
= oIndexSheets
.getByIndex(0);
803 XSpreadsheet oSheet
= (XSpreadsheet
)AnyConverter
.toObject(
804 new com
.sun
.star
.uno
.Type(XSpreadsheet
.class), o
);
806 log
.println("Getting a cell from sheet") ;
807 xCell
= oSheet
.getCellByPosition(0, 0);
808 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
809 failed(e
.getMessage());
810 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
811 failed(e
.getMessage());
813 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
814 failed(e
.getMessage());
818 xCell
.setFormula("Value");
820 //setting property 'PrintHeaders' of the style 'Default'
821 XStyleFamiliesSupplier xSFS
= (XStyleFamiliesSupplier
)
822 UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class,
824 XNameAccess xNA
= xSFS
.getStyleFamilies();
825 XPropertySet xPropSet
= null;
827 Object oPageStyles
= xNA
.getByName("PageStyles");
829 UnoRuntime
.queryInterface(XNameAccess
.class, oPageStyles
);
830 Object oDefStyle
= xNA
.getByName("Default");
831 xPropSet
= (XPropertySet
)
832 UnoRuntime
.queryInterface(XPropertySet
.class, oDefStyle
);
833 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
834 failed(e
.getMessage());
836 } catch(com
.sun
.star
.container
.NoSuchElementException e
) {
837 failed(e
.getMessage());
842 xPropSet
.setPropertyValue("PrintHeaders", new Boolean(true));
843 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
844 failed(e
.getMessage());
846 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
847 failed(e
.getMessage());
849 } catch(com
.sun
.star
.beans
.PropertyVetoException e
) {
850 failed(e
.getMessage());
852 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
853 failed(e
.getMessage());
857 //switching to 'Print Preview' mode
859 XDispatchProvider xDispProv
= (XDispatchProvider
)
860 UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
861 XURLTransformer xParser
= (com
.sun
.star
.util
.XURLTransformer
)
862 UnoRuntime
.queryInterface(XURLTransformer
.class,
863 mXMSF
.createInstance("com.sun.star.util.URLTransformer"));
864 URL
[] aParseURL
= new URL
[1];
865 aParseURL
[0] = new URL();
866 aParseURL
[0].Complete
= ".uno:PrintPreview";
867 xParser
.parseStrict(aParseURL
);
868 URL aURL
= aParseURL
[0];
869 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
870 if(xDispatcher
!= null)
871 xDispatcher
.dispatch( aURL
, null );
872 } catch (com
.sun
.star
.uno
.Exception e
) {
873 failed(e
.getMessage());
878 Thread
.currentThread().sleep(500) ;
879 } catch (InterruptedException e
) {
880 System
.out
.println("While waiting :" + e
) ;
883 AccessibilityTools at
= new AccessibilityTools();
885 XWindow xWindow
= at
.getCurrentWindow(mXMSF
, xModel
);
886 XAccessible xRoot
= at
.getAccessibleObject(xWindow
);
888 // log.println("ImplementationName " + utils.getImplName(oObj));
890 log
.println("Press any key when the header cell is on top.");
892 byte[]b
= new byte[16];
894 } catch (Exception e
) {
899 XAccessible parent
= null;
902 System
.out
.println("Count: " +at
.getAccessibleObjectForRole
903 (xRoot
, AccessibleRole
.TABLE
, "").getAccessibleChildCount());
904 // parent = at.getAccessibleObjectForRole
905 // (xRoot, AccessibleRole.TABLE, "").getAccessibleChild(0);
906 // oObj = parent.getAccessibleContext().getAccessibleChild(1);
907 System
.out
.println("Getting child 2");
908 oObj
= at
.getAccessibleObjectForRole
909 (xRoot
, AccessibleRole
.TABLE
, "").getAccessibleChild(2);
910 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
911 failed(iabe
.getMessage());
915 System
.out
.println("*** DEBUG INFO ***");
916 util
.dbg
.getSuppServices(oObj
);
917 System
.out
.println("****** IFC ******");
918 util
.dbg
.printInterfaces(oObj
);
919 System
.out
.println("*****************");
922 /* XAccessibleContext accCtx = (XAccessibleContext)
923 UnoRuntime.queryInterface(XAccessibleContext.class, oObj);
925 System.out.println("Children now: " + accCtx.getAccessibleChild(0).getAccessibleContext().getAccessibleChildCount());
926 } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
927 failed(iabe.getMessage());
932 XAccessibleValue accV
= (XAccessibleValue
)
933 UnoRuntime
.queryInterface(XAccessibleValue
.class, oObj
);
934 Object o
= accV
.getCurrentValue();
935 log
.println("Getting the value: "+o
+ " is void " + util
.utils
.isVoid(o
));
938 XAccessibleComponent accC
= (XAccessibleComponent
)
939 UnoRuntime
.queryInterface(XAccessibleComponent
.class, oObj
);
941 log
.println("BoundsX= "+accC
.getBounds().X
);
942 log
.println("BoundsY= "+accC
.getBounds().Y
);
943 log
.println("BoundsWidth= "+accC
.getBounds().Width
);
944 log
.println("BoundsHeight= "+accC
.getBounds().Height
);
946 XComponent xComp
= (XComponent
)UnoRuntime
.queryInterface(
947 XComponent
.class, xSpreadsheetDoc
);
957 * Check the preview of Shapes: load a document with shapes and see, if they
960 public void checkPreviewShape() {
961 SOfficeFactory SOF
= SOfficeFactory
.getFactory( mXMSF
);
962 XSpreadsheetDocument xSpreadsheetDoc
= null;
963 XComponent xComp
= null;
964 XInterface oObj
= null;
967 String docName
= "calcshapes.sxc";
968 log
.println("Loading a spreadsheetdocument.");
969 String url
= utils
.getFullURL(
970 (String
)param
.get("TestDocumentPath") + "/" + docName
);
971 log
.println("loading document '" + url
+ "'");
972 xComp
= SOF
.loadDocument(url
);
974 } catch (com
.sun
.star
.uno
.Exception e
) {
975 failed(e
.getMessage());
980 Thread
.currentThread().sleep(500) ;
981 } catch (InterruptedException e
) {
982 System
.out
.println("While waiting :" + e
) ;
986 failed("loading document failed.");
990 xSpreadsheetDoc
= (XSpreadsheetDocument
)UnoRuntime
.queryInterface(
991 XSpreadsheetDocument
.class, xComp
);
992 XModel aModel
= (XModel
)
993 UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc
);
995 XController xController
= aModel
.getCurrentController();
997 // switching to 'Page Preview' mode
999 XDispatchProvider xDispProv
= (XDispatchProvider
)
1000 UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
1001 XURLTransformer xParser
= (com
.sun
.star
.util
.XURLTransformer
)
1002 UnoRuntime
.queryInterface(XURLTransformer
.class,
1003 mXMSF
.createInstance("com.sun.star.util.URLTransformer"));
1004 // Because it's an in/out parameter we must use an
1005 // array of URL objects.
1006 URL
[] aParseURL
= new URL
[1];
1007 aParseURL
[0] = new URL();
1008 aParseURL
[0].Complete
= ".uno:PrintPreview";
1009 xParser
.parseStrict(aParseURL
);
1010 URL aURL
= aParseURL
[0];
1011 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
1012 if(xDispatcher
!= null)
1013 xDispatcher
.dispatch( aURL
, null );
1014 } catch (com
.sun
.star
.uno
.Exception e
) {
1015 failed("Couldn't change mode");
1020 Thread
.currentThread().sleep(500) ;
1021 } catch (InterruptedException e
) {
1022 System
.out
.println("While waiting :" + e
) ;
1027 log
.println("Press any key when a shape is on top.");
1029 byte[]b
= new byte[16];
1031 } catch (Exception e
) {
1032 e
.printStackTrace();
1035 // get the accessible content
1036 AccessibilityTools at
= new AccessibilityTools();
1038 XWindow xWindow
= at
.getCurrentWindow(mXMSF
, aModel
);
1039 XAccessible xRoot
= at
.getAccessibleObject(xWindow
);
1040 XAccessible parent
= null;
1043 XAccessibleContext con
= at
.getAccessibleObjectForRole
1044 (xRoot
, AccessibleRole
.SHAPE
, "");
1045 log
.println("Name of AccessibleContext: " + con
.getAccessibleName());
1047 } catch (Exception e
) {
1048 failed(e
.getMessage());
1052 log
.println("ImplementationName: " + utils
.getImplName(oObj
));
1053 util
.dbg
.printInterfaces(oObj
);