1 /*
2  * This file is part of the LibreOffice project.
3  *
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/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
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 .
17  */
18 package ifc.awt;
19 
20 import com.sun.star.accessibility.XAccessible;
21 import com.sun.star.accessibility.XAccessibleComponent;
22 import com.sun.star.awt.Point;
23 import com.sun.star.awt.ScrollBarOrientation;
24 import com.sun.star.awt.XScrollBar;
25 import com.sun.star.text.XTextDocument;
26 import com.sun.star.uno.UnoRuntime;
27 
28 import java.awt.Robot;
29 import java.awt.event.InputEvent;
30 
31 import lib.MultiMethodTest;
32 
33 
34 public class _XScrollBar extends MultiMethodTest {
35     public XScrollBar oObj;
36     public boolean adjusted = false;
37     com.sun.star.awt.XAdjustmentListener listener = new AdjustmentListener();
38 
_addAdjustmentListener()39     public void _addAdjustmentListener() throws Exception {
40         util.FormTools.switchDesignOf(tParam.getMSF(),
41                                  (XTextDocument) tEnv.getObjRelation("Document"));
42         oObj.addAdjustmentListener(listener);
43         adjustScrollBar();
44 
45         boolean res = adjusted;
46         oObj.removeAdjustmentListener(listener);
47         adjusted = false;
48         adjustScrollBar();
49         res &= !adjusted;
50         tRes.tested("addAdjustmentListener()", res);
51     }
52 
_removeAdjustmentListener()53     public void _removeAdjustmentListener() {
54         //this method is checked in addAjustmentListener
55         //so that method is required here and if it works
56         //this method is given OK too
57         requiredMethod("addAdjustmentListener()");
58         tRes.tested("removeAdjustmentListener()", true);
59     }
60 
_setBlockIncrement()61     public void _setBlockIncrement() {
62         oObj.setBlockIncrement(15);
63         oObj.setBlockIncrement(5);
64         int bi = oObj.getBlockIncrement();
65         tRes.tested("setBlockIncrement()",bi==5);
66     }
67 
_getBlockIncrement()68     public void _getBlockIncrement() {
69         //this method is checked in the corresponding set method
70         //so that method is required here and if it works
71         //this method is given OK too
72         requiredMethod("setBlockIncrement()");
73         tRes.tested("getBlockIncrement()", true);
74     }
75 
_setLineIncrement()76     public void _setLineIncrement() {
77         oObj.setLineIncrement(12);
78         oObj.setLineIncrement(2);
79         int li = oObj.getLineIncrement();
80         tRes.tested("setLineIncrement()",li==2);
81     }
82 
_getLineIncrement()83     public void _getLineIncrement() {
84         //this method is checked in the corresponding set method
85         //so that method is required here and if it works
86         //this method is given OK too
87         requiredMethod("setLineIncrement()");
88         tRes.tested("getLineIncrement()", true);
89     }
90 
_setMaximum()91     public void _setMaximum() {
92         oObj.setMaximum(490);
93         oObj.setMaximum(480);
94         int max = oObj.getMaximum();
95         tRes.tested("setMaximum()",max==480);
96     }
97 
_getMaximum()98     public void _getMaximum() {
99         //this method is checked in the corresponding set method
100         //so that method is required here and if it works
101         //this method is given OK too
102         requiredMethod("setMaximum()");
103         tRes.tested("getMaximum()", true);
104     }
105 
_setOrientation()106     public void _setOrientation() {
107         oObj.setOrientation(ScrollBarOrientation.HORIZONTAL);
108         oObj.setOrientation(ScrollBarOrientation.VERTICAL);
109         int ori = oObj.getOrientation();
110         tRes.tested("setOrientation()",ori==ScrollBarOrientation.VERTICAL);
111     }
112 
_getOrientation()113     public void _getOrientation() {
114         //this method is checked in the corresponding set method
115         //so that method is required here and if it works
116         //this method is given OK too
117         requiredMethod("setOrientation()");
118         tRes.tested("getOrientation()", true);
119     }
120 
_setValue()121     public void _setValue() {
122         oObj.setMaximum(600);
123         oObj.setValue(480);
124         oObj.setValue(520);
125         int val = oObj.getValue();
126         tRes.tested("setValue()",val==520);
127     }
128 
_getValue()129     public void _getValue() {
130         //this method is checked in the corresponding set method
131         //so that method is required here and if it works
132         //this method is given OK too
133         requiredMethod("setValue()");
134         tRes.tested("getValue()", true);
135     }
136 
_setVisibleSize()137     public void _setVisibleSize() {
138         oObj.setVisibleSize(700);
139         oObj.setVisibleSize(500);
140         int vs = oObj.getVisibleSize();
141         tRes.tested("setVisibleSize()",vs==500);
142     }
143 
_getVisibleSize()144     public void _getVisibleSize() {
145         //this method is checked in the corresponding set method
146         //so that method is required here and if it works
147         //this method is given OK too
148         requiredMethod("setVisibleSize()");
149         tRes.tested("getVisibleSize()", true);
150     }
151 
_setValues()152     public void _setValues() {
153         oObj.setValues(80, 200, 300);
154         oObj.setValues(70, 210, 500);
155         int val = oObj.getValue();
156         int vs = oObj.getVisibleSize();
157         int max = oObj.getMaximum();
158         tRes.tested("setValues()",((val==70) && (vs==210) && (max==500)));
159     }
160 
adjustScrollBar()161     private void adjustScrollBar() {
162 
163 
164         XScrollBar sc = UnoRuntime.queryInterface(
165                                 XScrollBar.class, tEnv.getTestObject());
166 
167         sc.setValue(500);
168 
169         waitForEventIdle();
170 
171         XAccessible acc = UnoRuntime.queryInterface(
172                                   XAccessible.class, tEnv.getTestObject());
173 
174         XAccessibleComponent aCom = UnoRuntime.queryInterface(
175                                             XAccessibleComponent.class,
176                                             acc.getAccessibleContext());
177 
178         Point location = aCom.getLocationOnScreen();
179         try {
180             Robot rob = new Robot();
181             rob.mouseMove(location.X + 50, location.Y + 75);
182             rob.mousePress(InputEvent.BUTTON1_MASK);
183             rob.mouseRelease(InputEvent.BUTTON1_MASK);
184         } catch (java.awt.AWTException e) {
185             System.out.println("couldn't adjust scrollbar");
186         }
187 
188         waitForEventIdle();
189     }
190 
191     public class AdjustmentListener
192         implements com.sun.star.awt.XAdjustmentListener {
adjustmentValueChanged(com.sun.star.awt.AdjustmentEvent adjustmentEvent)193         public void adjustmentValueChanged(com.sun.star.awt.AdjustmentEvent adjustmentEvent) {
194             System.out.println("Adjustment Value changed");
195             System.out.println("AdjustmentEvent: " + adjustmentEvent.Value);
196             adjusted = true;
197         }
198 
disposing(com.sun.star.lang.EventObject eventObject)199         public void disposing(com.sun.star.lang.EventObject eventObject) {
200             System.out.println("Listener disposed");
201         }
202     }
203 }
204