2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import java
.io
.PrintWriter
;
23 import lib
.TestEnvironment
;
24 import lib
.TestParameters
;
25 import util
.AccessibilityTools
;
26 import util
.WriterTools
;
29 import com
.sun
.star
.accessibility
.AccessibleRole
;
30 import com
.sun
.star
.accessibility
.XAccessible
;
31 import com
.sun
.star
.accessibility
.XAccessibleContext
;
32 import com
.sun
.star
.accessibility
.XAccessibleValue
;
33 import com
.sun
.star
.awt
.XWindow
;
34 import com
.sun
.star
.beans
.XPropertySet
;
35 import com
.sun
.star
.container
.XEnumeration
;
36 import com
.sun
.star
.container
.XEnumerationAccess
;
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
.text
.ControlCharacter
;
42 import com
.sun
.star
.text
.XText
;
43 import com
.sun
.star
.text
.XTextCursor
;
44 import com
.sun
.star
.text
.XTextDocument
;
45 import com
.sun
.star
.uno
.AnyConverter
;
46 import com
.sun
.star
.uno
.Type
;
47 import com
.sun
.star
.uno
.UnoRuntime
;
48 import com
.sun
.star
.uno
.XInterface
;
49 import com
.sun
.star
.util
.URL
;
50 import com
.sun
.star
.util
.XURLTransformer
;
52 public class SwAccessiblePageView
extends TestCase
{
54 XTextDocument xTextDoc
= null;
57 * Called to create an instance of <code>TestEnvironment</code>
58 * with an object to test and related objects.
59 * Switches the document to Print Preview mode.
60 * Obtains accessible object for the page view.
62 * @param Param test parameters
63 * @param log writer to log information while testing
65 * @see TestEnvironment
66 * @see #getTestEnvironment
69 protected TestEnvironment
createTestEnvironment(
70 TestParameters Param
, PrintWriter log
) throws Exception
{
72 XInterface oObj
= null;
73 XInterface port
= null;
74 XInterface para
= null;
75 XPropertySet paraP
= null;
76 XText oText
= xTextDoc
.getText();
77 XTextCursor oCursor
= oText
.createTextCursor();
79 log
.println( "inserting some lines" );
80 for (int i
=0; i
<2; i
++){
81 oText
.insertString( oCursor
,"Paragraph Number: " + i
, false);
82 oText
.insertString( oCursor
,
83 " The quick brown fox jumps over the lazy Dog: SwXParagraph",
85 oText
.insertControlCharacter(
86 oCursor
, ControlCharacter
.PARAGRAPH_BREAK
, false );
87 oText
.insertString( oCursor
,
88 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
90 oText
.insertControlCharacter(oCursor
,
91 ControlCharacter
.PARAGRAPH_BREAK
, false );
92 oText
.insertControlCharacter(
93 oCursor
, ControlCharacter
.LINE_BREAK
, false );
97 XEnumerationAccess oEnumA
= UnoRuntime
.queryInterface(XEnumerationAccess
.class, oText
);
98 XEnumeration oEnum
= oEnumA
.createEnumeration();
100 para
= (XInterface
) AnyConverter
.toObject(
101 new Type(XInterface
.class),oEnum
.nextElement());
102 XEnumerationAccess oEnumB
= UnoRuntime
.queryInterface( XEnumerationAccess
.class, para
);
103 XEnumeration oEnum2
= oEnumB
.createEnumeration();
104 port
= (XInterface
) AnyConverter
.toObject(
105 new Type(XInterface
.class),oEnum2
.nextElement());
107 UnoRuntime
.queryInterface(XPropertySet
.class, port
);
108 paraP
= UnoRuntime
.queryInterface(XPropertySet
.class, para
);
109 paraP
.setPropertyValue("BreakType",com
.sun
.star
.style
.BreakType
.PAGE_AFTER
);
111 util
.utils
.waitForEventIdle(Param
.getMSF());
113 XController xController
= xTextDoc
.getCurrentController();
115 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xTextDoc
);
117 //switch to 'Print Preview' mode
118 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
119 XURLTransformer xParser
= UnoRuntime
.queryInterface(XURLTransformer
.class,
120 Param
.getMSF().createInstance("com.sun.star.util.URLTransformer"));
121 // Because it's an in/out parameter we must use an array of URL objects.
122 URL
[] aParseURL
= new URL
[1];
123 aParseURL
[0] = new URL();
124 aParseURL
[0].Complete
= ".uno:PrintPreview";
125 xParser
.parseStrict(aParseURL
);
126 URL aURL
= aParseURL
[0];
127 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
128 if(xDispatcher
!= null)
129 xDispatcher
.dispatch( aURL
, null );
131 util
.utils
.waitForEventIdle(Param
.getMSF());
133 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(aModel
);
134 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
136 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
138 System
.out
.println("Panel: "+AccessibleRole
.PANEL
);
139 System
.out
.println("ScrollPane: "+AccessibleRole
.SCROLL_PANE
);
140 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PANEL
,"Page");
142 log
.println("ImplementationName " + utils
.getImplName(oObj
));
145 TestEnvironment tEnv
= new TestEnvironment(oObj
);
147 getAccessibleObjectForRole(xRoot
, AccessibleRole
.SCROLL_BAR
);
148 final XAccessibleValue xAccVal
= UnoRuntime
.queryInterface
149 (XAccessibleValue
.class, SearchedContext
) ;
151 tEnv
.addObjRelation("EventProducer",
152 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
153 public void fireEvent() {
154 Integer old
= (Integer
) xAccVal
.getCurrentValue();
155 Integer newValue
= Integer
.valueOf(old
.intValue()+10);
156 xAccVal
.setCurrentValue(newValue
);
157 xAccVal
.setCurrentValue(old
);
165 public static boolean first
= false;
166 public static XAccessibleContext SearchedContext
= null;
168 public static void getAccessibleObjectForRole(XAccessible xacc
,short role
) {
169 XAccessibleContext ac
= xacc
.getAccessibleContext();
170 if (ac
.getAccessibleRole()==role
) {
171 if (first
) SearchedContext
= ac
;
174 long k
= ac
.getAccessibleChildCount();
175 for (long i
= 0; i
< k
; i
++) {
177 getAccessibleObjectForRole(ac
.getAccessibleChild(i
),role
);
178 if (SearchedContext
!= null) return ;
179 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
180 System
.out
.println("Couldn't get Child");
188 * Called while disposing a <code>TestEnvironment</code>.
189 * Disposes text document.
190 * @param Param test parameters
191 * @param log writer to log information while testing
194 protected void cleanup( TestParameters Param
, PrintWriter log
) {
195 log
.println("dispose text document");
196 util
.DesktopTools
.closeDoc(xTextDoc
);
200 * Called while the <code>TestCase</code> initialization. In the
201 * implementation does nothing. Subclasses can override to initialize
202 * objects shared among all <code>TestEnvironment</code>s.
204 * @param Param test parameters
205 * @param log writer to log information while testing
207 * @see #initializeTestCase
210 protected void initialize(TestParameters Param
, PrintWriter log
) throws Exception
{
211 log
.println( "creating a text document" );
212 xTextDoc
= WriterTools
.createTextDoc(Param
.getMSF());