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