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