1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir package ifc.awt;
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible;
30*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleComponent;
31*cdf0e10cSrcweir import com.sun.star.awt.Point;
32*cdf0e10cSrcweir import com.sun.star.awt.ScrollBarOrientation;
33*cdf0e10cSrcweir import com.sun.star.awt.XScrollBar;
34*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
35*cdf0e10cSrcweir import com.sun.star.text.XTextDocument;
36*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir import java.awt.Robot;
39*cdf0e10cSrcweir import java.awt.event.InputEvent;
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir import lib.MultiMethodTest;
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir public class _XScrollBar extends MultiMethodTest {
45*cdf0e10cSrcweir     public XScrollBar oObj;
46*cdf0e10cSrcweir     public boolean adjusted = false;
47*cdf0e10cSrcweir     com.sun.star.awt.XAdjustmentListener listener = new AdjustmentListener();
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir     public void _addAdjustmentListener() {
50*cdf0e10cSrcweir         util.FormTools.switchDesignOf((XMultiServiceFactory) tParam.getMSF(),
51*cdf0e10cSrcweir                                  (XTextDocument) tEnv.getObjRelation("Document"));
52*cdf0e10cSrcweir         shortWait();
53*cdf0e10cSrcweir         oObj.addAdjustmentListener(listener);
54*cdf0e10cSrcweir         adjustScrollBar();
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir         boolean res = adjusted;
57*cdf0e10cSrcweir         oObj.removeAdjustmentListener(listener);
58*cdf0e10cSrcweir         adjusted = false;
59*cdf0e10cSrcweir         adjustScrollBar();
60*cdf0e10cSrcweir         res &= !adjusted;
61*cdf0e10cSrcweir         tRes.tested("addAdjustmentListener()", res);
62*cdf0e10cSrcweir     }
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir     public void _removeAdjustmentListener() {
65*cdf0e10cSrcweir         //this method is checked in addAjustmentListener
66*cdf0e10cSrcweir         //so that method is requiered here and if it works
67*cdf0e10cSrcweir         //this method is given OK too
68*cdf0e10cSrcweir         requiredMethod("addAdjustmentListener()");
69*cdf0e10cSrcweir         tRes.tested("removeAdjustmentListener()", true);
70*cdf0e10cSrcweir     }
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir     public void _setBlockIncrement() {
73*cdf0e10cSrcweir         oObj.setBlockIncrement(15);
74*cdf0e10cSrcweir         oObj.setBlockIncrement(5);
75*cdf0e10cSrcweir         int bi = oObj.getBlockIncrement();
76*cdf0e10cSrcweir         tRes.tested("setBlockIncrement()",bi==5);
77*cdf0e10cSrcweir     }
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir     public void _getBlockIncrement() {
80*cdf0e10cSrcweir         //this method is checked in the corresponding set method
81*cdf0e10cSrcweir         //so that method is requiered here and if it works
82*cdf0e10cSrcweir         //this method is given OK too
83*cdf0e10cSrcweir         requiredMethod("setBlockIncrement()");
84*cdf0e10cSrcweir         tRes.tested("getBlockIncrement()", true);
85*cdf0e10cSrcweir     }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir     public void _setLineIncrement() {
88*cdf0e10cSrcweir         oObj.setLineIncrement(12);
89*cdf0e10cSrcweir         oObj.setLineIncrement(2);
90*cdf0e10cSrcweir         int li = oObj.getLineIncrement();
91*cdf0e10cSrcweir         tRes.tested("setLineIncrement()",li==2);
92*cdf0e10cSrcweir     }
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir     public void _getLineIncrement() {
95*cdf0e10cSrcweir         //this method is checked in the corresponding set method
96*cdf0e10cSrcweir         //so that method is requiered here and if it works
97*cdf0e10cSrcweir         //this method is given OK too
98*cdf0e10cSrcweir         requiredMethod("setLineIncrement()");
99*cdf0e10cSrcweir         tRes.tested("getLineIncrement()", true);
100*cdf0e10cSrcweir     }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir     public void _setMaximum() {
103*cdf0e10cSrcweir         oObj.setMaximum(490);
104*cdf0e10cSrcweir         oObj.setMaximum(480);
105*cdf0e10cSrcweir         int max = oObj.getMaximum();
106*cdf0e10cSrcweir         tRes.tested("setMaximum()",max==480);
107*cdf0e10cSrcweir     }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir     public void _getMaximum() {
110*cdf0e10cSrcweir         //this method is checked in the corresponding set method
111*cdf0e10cSrcweir         //so that method is requiered here and if it works
112*cdf0e10cSrcweir         //this method is given OK too
113*cdf0e10cSrcweir         requiredMethod("setMaximum()");
114*cdf0e10cSrcweir         tRes.tested("getMaximum()", true);
115*cdf0e10cSrcweir     }
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir     public void _setOrientation() {
118*cdf0e10cSrcweir         oObj.setOrientation(ScrollBarOrientation.HORIZONTAL);
119*cdf0e10cSrcweir         oObj.setOrientation(ScrollBarOrientation.VERTICAL);
120*cdf0e10cSrcweir         int ori = oObj.getOrientation();
121*cdf0e10cSrcweir         tRes.tested("setOrientation()",ori==ScrollBarOrientation.VERTICAL);
122*cdf0e10cSrcweir     }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir     public void _getOrientation() {
125*cdf0e10cSrcweir         //this method is checked in the corresponding set method
126*cdf0e10cSrcweir         //so that method is requiered here and if it works
127*cdf0e10cSrcweir         //this method is given OK too
128*cdf0e10cSrcweir         requiredMethod("setOrientation()");
129*cdf0e10cSrcweir         tRes.tested("getOrientation()", true);
130*cdf0e10cSrcweir     }
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir     public void _setValue() {
133*cdf0e10cSrcweir         oObj.setMaximum(600);
134*cdf0e10cSrcweir         oObj.setValue(480);
135*cdf0e10cSrcweir         oObj.setValue(520);
136*cdf0e10cSrcweir         int val = oObj.getValue();
137*cdf0e10cSrcweir         tRes.tested("setValue()",val==520);
138*cdf0e10cSrcweir     }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir     public void _getValue() {
141*cdf0e10cSrcweir         //this method is checked in the corresponding set method
142*cdf0e10cSrcweir         //so that method is requiered here and if it works
143*cdf0e10cSrcweir         //this method is given OK too
144*cdf0e10cSrcweir         requiredMethod("setValue()");
145*cdf0e10cSrcweir         tRes.tested("getValue()", true);
146*cdf0e10cSrcweir     }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir     public void _setVisibleSize() {
149*cdf0e10cSrcweir         oObj.setVisibleSize(700);
150*cdf0e10cSrcweir         oObj.setVisibleSize(500);
151*cdf0e10cSrcweir         int vs = oObj.getVisibleSize();
152*cdf0e10cSrcweir         tRes.tested("setVisibleSize()",vs==500);
153*cdf0e10cSrcweir     }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir     public void _getVisibleSize() {
156*cdf0e10cSrcweir         //this method is checked in the corresponding set method
157*cdf0e10cSrcweir         //so that method is requiered here and if it works
158*cdf0e10cSrcweir         //this method is given OK too
159*cdf0e10cSrcweir         requiredMethod("setVisibleSize()");
160*cdf0e10cSrcweir         tRes.tested("getVisibleSize()", true);
161*cdf0e10cSrcweir     }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir     public void _setValues() {
164*cdf0e10cSrcweir         oObj.setValues(80, 200, 300);
165*cdf0e10cSrcweir         oObj.setValues(70, 210, 500);
166*cdf0e10cSrcweir         int val = oObj.getValue();
167*cdf0e10cSrcweir         int vs = oObj.getVisibleSize();
168*cdf0e10cSrcweir         int max = oObj.getMaximum();
169*cdf0e10cSrcweir         tRes.tested("setValues()",((val==70) && (vs==210) && (max==500)));
170*cdf0e10cSrcweir     }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     private void adjustScrollBar() {
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir         XScrollBar sc = (XScrollBar) UnoRuntime.queryInterface(
176*cdf0e10cSrcweir                                 XScrollBar.class, tEnv.getTestObject());
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir         sc.setValue(500);
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir         shortWait();
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir         XAccessible acc = (XAccessible) UnoRuntime.queryInterface(
183*cdf0e10cSrcweir                                   XAccessible.class, tEnv.getTestObject());
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir         XAccessibleComponent aCom = (XAccessibleComponent) UnoRuntime.queryInterface(
186*cdf0e10cSrcweir                                             XAccessibleComponent.class,
187*cdf0e10cSrcweir                                             acc.getAccessibleContext());
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir         Point location = aCom.getLocationOnScreen();
190*cdf0e10cSrcweir         //Point location = (Point) tEnv.getObjRelation("Location");
191*cdf0e10cSrcweir         //XAccessibleComponent aCom = (XAccessibleComponent) tEnv.getObjRelation("Location");
192*cdf0e10cSrcweir         //Point location = aCom.getLocationOnScreen();
193*cdf0e10cSrcweir         try {
194*cdf0e10cSrcweir             Robot rob = new Robot();
195*cdf0e10cSrcweir             rob.mouseMove(location.X + 50, location.Y + 75);
196*cdf0e10cSrcweir             rob.mousePress(InputEvent.BUTTON1_MASK);
197*cdf0e10cSrcweir             rob.mouseRelease(InputEvent.BUTTON1_MASK);
198*cdf0e10cSrcweir         } catch (java.awt.AWTException e) {
199*cdf0e10cSrcweir             System.out.println("couldn't adjust scrollbar");
200*cdf0e10cSrcweir         }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir         shortWait();
203*cdf0e10cSrcweir     }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir     /**
206*cdf0e10cSrcweir      * Sleeps for 0.5 sec. to allow Office to react
207*cdf0e10cSrcweir      */
208*cdf0e10cSrcweir     private void shortWait() {
209*cdf0e10cSrcweir         try {
210*cdf0e10cSrcweir             Thread.sleep(500);
211*cdf0e10cSrcweir         } catch (InterruptedException e) {
212*cdf0e10cSrcweir             log.println("While waiting :" + e);
213*cdf0e10cSrcweir         }
214*cdf0e10cSrcweir     }
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir     public class AdjustmentListener
217*cdf0e10cSrcweir         implements com.sun.star.awt.XAdjustmentListener {
218*cdf0e10cSrcweir         public void adjustmentValueChanged(com.sun.star.awt.AdjustmentEvent adjustmentEvent) {
219*cdf0e10cSrcweir             System.out.println("Adjustment Value changed");
220*cdf0e10cSrcweir             System.out.println("AdjustmentEvent: " + adjustmentEvent.Value);
221*cdf0e10cSrcweir             adjusted = true;
222*cdf0e10cSrcweir         }
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir         public void disposing(com.sun.star.lang.EventObject eventObject) {
225*cdf0e10cSrcweir             System.out.println("Listener disposed");
226*cdf0e10cSrcweir         }
227*cdf0e10cSrcweir     }
228*cdf0e10cSrcweir }
229