1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package ifc.awt;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible;
26cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleComponent;
27cdf0e10cSrcweir import com.sun.star.awt.Point;
28cdf0e10cSrcweir import com.sun.star.awt.ScrollBarOrientation;
29cdf0e10cSrcweir import com.sun.star.awt.XScrollBar;
30cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
31cdf0e10cSrcweir import com.sun.star.text.XTextDocument;
32cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir import java.awt.Robot;
35cdf0e10cSrcweir import java.awt.event.InputEvent;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir import lib.MultiMethodTest;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir public class _XScrollBar extends MultiMethodTest {
41cdf0e10cSrcweir     public XScrollBar oObj;
42cdf0e10cSrcweir     public boolean adjusted = false;
43cdf0e10cSrcweir     com.sun.star.awt.XAdjustmentListener listener = new AdjustmentListener();
44cdf0e10cSrcweir 
_addAdjustmentListener()45cdf0e10cSrcweir     public void _addAdjustmentListener() {
46cdf0e10cSrcweir         util.FormTools.switchDesignOf((XMultiServiceFactory) tParam.getMSF(),
47cdf0e10cSrcweir                                  (XTextDocument) tEnv.getObjRelation("Document"));
48cdf0e10cSrcweir         shortWait();
49cdf0e10cSrcweir         oObj.addAdjustmentListener(listener);
50cdf0e10cSrcweir         adjustScrollBar();
51cdf0e10cSrcweir 
52cdf0e10cSrcweir         boolean res = adjusted;
53cdf0e10cSrcweir         oObj.removeAdjustmentListener(listener);
54cdf0e10cSrcweir         adjusted = false;
55cdf0e10cSrcweir         adjustScrollBar();
56cdf0e10cSrcweir         res &= !adjusted;
57cdf0e10cSrcweir         tRes.tested("addAdjustmentListener()", res);
58cdf0e10cSrcweir     }
59cdf0e10cSrcweir 
_removeAdjustmentListener()60cdf0e10cSrcweir     public void _removeAdjustmentListener() {
61cdf0e10cSrcweir         //this method is checked in addAjustmentListener
62cdf0e10cSrcweir         //so that method is requiered here and if it works
63cdf0e10cSrcweir         //this method is given OK too
64cdf0e10cSrcweir         requiredMethod("addAdjustmentListener()");
65cdf0e10cSrcweir         tRes.tested("removeAdjustmentListener()", true);
66cdf0e10cSrcweir     }
67cdf0e10cSrcweir 
_setBlockIncrement()68cdf0e10cSrcweir     public void _setBlockIncrement() {
69cdf0e10cSrcweir         oObj.setBlockIncrement(15);
70cdf0e10cSrcweir         oObj.setBlockIncrement(5);
71cdf0e10cSrcweir         int bi = oObj.getBlockIncrement();
72cdf0e10cSrcweir         tRes.tested("setBlockIncrement()",bi==5);
73cdf0e10cSrcweir     }
74cdf0e10cSrcweir 
_getBlockIncrement()75cdf0e10cSrcweir     public void _getBlockIncrement() {
76cdf0e10cSrcweir         //this method is checked in the corresponding set method
77cdf0e10cSrcweir         //so that method is requiered here and if it works
78cdf0e10cSrcweir         //this method is given OK too
79cdf0e10cSrcweir         requiredMethod("setBlockIncrement()");
80cdf0e10cSrcweir         tRes.tested("getBlockIncrement()", true);
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir 
_setLineIncrement()83cdf0e10cSrcweir     public void _setLineIncrement() {
84cdf0e10cSrcweir         oObj.setLineIncrement(12);
85cdf0e10cSrcweir         oObj.setLineIncrement(2);
86cdf0e10cSrcweir         int li = oObj.getLineIncrement();
87cdf0e10cSrcweir         tRes.tested("setLineIncrement()",li==2);
88cdf0e10cSrcweir     }
89cdf0e10cSrcweir 
_getLineIncrement()90cdf0e10cSrcweir     public void _getLineIncrement() {
91cdf0e10cSrcweir         //this method is checked in the corresponding set method
92cdf0e10cSrcweir         //so that method is requiered here and if it works
93cdf0e10cSrcweir         //this method is given OK too
94cdf0e10cSrcweir         requiredMethod("setLineIncrement()");
95cdf0e10cSrcweir         tRes.tested("getLineIncrement()", true);
96cdf0e10cSrcweir     }
97cdf0e10cSrcweir 
_setMaximum()98cdf0e10cSrcweir     public void _setMaximum() {
99cdf0e10cSrcweir         oObj.setMaximum(490);
100cdf0e10cSrcweir         oObj.setMaximum(480);
101cdf0e10cSrcweir         int max = oObj.getMaximum();
102cdf0e10cSrcweir         tRes.tested("setMaximum()",max==480);
103cdf0e10cSrcweir     }
104cdf0e10cSrcweir 
_getMaximum()105cdf0e10cSrcweir     public void _getMaximum() {
106cdf0e10cSrcweir         //this method is checked in the corresponding set method
107cdf0e10cSrcweir         //so that method is requiered here and if it works
108cdf0e10cSrcweir         //this method is given OK too
109cdf0e10cSrcweir         requiredMethod("setMaximum()");
110cdf0e10cSrcweir         tRes.tested("getMaximum()", true);
111cdf0e10cSrcweir     }
112cdf0e10cSrcweir 
_setOrientation()113cdf0e10cSrcweir     public void _setOrientation() {
114cdf0e10cSrcweir         oObj.setOrientation(ScrollBarOrientation.HORIZONTAL);
115cdf0e10cSrcweir         oObj.setOrientation(ScrollBarOrientation.VERTICAL);
116cdf0e10cSrcweir         int ori = oObj.getOrientation();
117cdf0e10cSrcweir         tRes.tested("setOrientation()",ori==ScrollBarOrientation.VERTICAL);
118cdf0e10cSrcweir     }
119cdf0e10cSrcweir 
_getOrientation()120cdf0e10cSrcweir     public void _getOrientation() {
121cdf0e10cSrcweir         //this method is checked in the corresponding set method
122cdf0e10cSrcweir         //so that method is requiered here and if it works
123cdf0e10cSrcweir         //this method is given OK too
124cdf0e10cSrcweir         requiredMethod("setOrientation()");
125cdf0e10cSrcweir         tRes.tested("getOrientation()", true);
126cdf0e10cSrcweir     }
127cdf0e10cSrcweir 
_setValue()128cdf0e10cSrcweir     public void _setValue() {
129cdf0e10cSrcweir         oObj.setMaximum(600);
130cdf0e10cSrcweir         oObj.setValue(480);
131cdf0e10cSrcweir         oObj.setValue(520);
132cdf0e10cSrcweir         int val = oObj.getValue();
133cdf0e10cSrcweir         tRes.tested("setValue()",val==520);
134cdf0e10cSrcweir     }
135cdf0e10cSrcweir 
_getValue()136cdf0e10cSrcweir     public void _getValue() {
137cdf0e10cSrcweir         //this method is checked in the corresponding set method
138cdf0e10cSrcweir         //so that method is requiered here and if it works
139cdf0e10cSrcweir         //this method is given OK too
140cdf0e10cSrcweir         requiredMethod("setValue()");
141cdf0e10cSrcweir         tRes.tested("getValue()", true);
142cdf0e10cSrcweir     }
143cdf0e10cSrcweir 
_setVisibleSize()144cdf0e10cSrcweir     public void _setVisibleSize() {
145cdf0e10cSrcweir         oObj.setVisibleSize(700);
146cdf0e10cSrcweir         oObj.setVisibleSize(500);
147cdf0e10cSrcweir         int vs = oObj.getVisibleSize();
148cdf0e10cSrcweir         tRes.tested("setVisibleSize()",vs==500);
149cdf0e10cSrcweir     }
150cdf0e10cSrcweir 
_getVisibleSize()151cdf0e10cSrcweir     public void _getVisibleSize() {
152cdf0e10cSrcweir         //this method is checked in the corresponding set method
153cdf0e10cSrcweir         //so that method is requiered here and if it works
154cdf0e10cSrcweir         //this method is given OK too
155cdf0e10cSrcweir         requiredMethod("setVisibleSize()");
156cdf0e10cSrcweir         tRes.tested("getVisibleSize()", true);
157cdf0e10cSrcweir     }
158cdf0e10cSrcweir 
_setValues()159cdf0e10cSrcweir     public void _setValues() {
160cdf0e10cSrcweir         oObj.setValues(80, 200, 300);
161cdf0e10cSrcweir         oObj.setValues(70, 210, 500);
162cdf0e10cSrcweir         int val = oObj.getValue();
163cdf0e10cSrcweir         int vs = oObj.getVisibleSize();
164cdf0e10cSrcweir         int max = oObj.getMaximum();
165cdf0e10cSrcweir         tRes.tested("setValues()",((val==70) && (vs==210) && (max==500)));
166cdf0e10cSrcweir     }
167cdf0e10cSrcweir 
adjustScrollBar()168cdf0e10cSrcweir     private void adjustScrollBar() {
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 
171cdf0e10cSrcweir         XScrollBar sc = (XScrollBar) UnoRuntime.queryInterface(
172cdf0e10cSrcweir                                 XScrollBar.class, tEnv.getTestObject());
173cdf0e10cSrcweir 
174cdf0e10cSrcweir         sc.setValue(500);
175cdf0e10cSrcweir 
176cdf0e10cSrcweir         shortWait();
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         XAccessible acc = (XAccessible) UnoRuntime.queryInterface(
179cdf0e10cSrcweir                                   XAccessible.class, tEnv.getTestObject());
180cdf0e10cSrcweir 
181cdf0e10cSrcweir         XAccessibleComponent aCom = (XAccessibleComponent) UnoRuntime.queryInterface(
182cdf0e10cSrcweir                                             XAccessibleComponent.class,
183cdf0e10cSrcweir                                             acc.getAccessibleContext());
184cdf0e10cSrcweir 
185cdf0e10cSrcweir         Point location = aCom.getLocationOnScreen();
186cdf0e10cSrcweir         //Point location = (Point) tEnv.getObjRelation("Location");
187cdf0e10cSrcweir         //XAccessibleComponent aCom = (XAccessibleComponent) tEnv.getObjRelation("Location");
188cdf0e10cSrcweir         //Point location = aCom.getLocationOnScreen();
189cdf0e10cSrcweir         try {
190cdf0e10cSrcweir             Robot rob = new Robot();
191cdf0e10cSrcweir             rob.mouseMove(location.X + 50, location.Y + 75);
192cdf0e10cSrcweir             rob.mousePress(InputEvent.BUTTON1_MASK);
193cdf0e10cSrcweir             rob.mouseRelease(InputEvent.BUTTON1_MASK);
194cdf0e10cSrcweir         } catch (java.awt.AWTException e) {
195cdf0e10cSrcweir             System.out.println("couldn't adjust scrollbar");
196cdf0e10cSrcweir         }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir         shortWait();
199cdf0e10cSrcweir     }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir     /**
202cdf0e10cSrcweir      * Sleeps for 0.5 sec. to allow Office to react
203cdf0e10cSrcweir      */
shortWait()204cdf0e10cSrcweir     private void shortWait() {
205cdf0e10cSrcweir         try {
206cdf0e10cSrcweir             Thread.sleep(500);
207cdf0e10cSrcweir         } catch (InterruptedException e) {
208cdf0e10cSrcweir             log.println("While waiting :" + e);
209cdf0e10cSrcweir         }
210cdf0e10cSrcweir     }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     public class AdjustmentListener
213cdf0e10cSrcweir         implements com.sun.star.awt.XAdjustmentListener {
adjustmentValueChanged(com.sun.star.awt.AdjustmentEvent adjustmentEvent)214cdf0e10cSrcweir         public void adjustmentValueChanged(com.sun.star.awt.AdjustmentEvent adjustmentEvent) {
215cdf0e10cSrcweir             System.out.println("Adjustment Value changed");
216cdf0e10cSrcweir             System.out.println("AdjustmentEvent: " + adjustmentEvent.Value);
217cdf0e10cSrcweir             adjusted = true;
218cdf0e10cSrcweir         }
219cdf0e10cSrcweir 
disposing(com.sun.star.lang.EventObject eventObject)220cdf0e10cSrcweir         public void disposing(com.sun.star.lang.EventObject eventObject) {
221cdf0e10cSrcweir             System.out.println("Listener disposed");
222cdf0e10cSrcweir         }
223cdf0e10cSrcweir     }
224cdf0e10cSrcweir }
225