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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_accessibility.hxx"
26 
27 // includes --------------------------------------------------------------
28 #include <accessibility/standard/vclxaccessiblescrollbar.hxx>
29 
30 #include <toolkit/awt/vclxwindows.hxx>
31 #include <accessibility/helper/accresmgr.hxx>
32 #include <accessibility/helper/accessiblestrings.hrc>
33 
34 #include <unotools/accessiblestatesethelper.hxx>
35 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
36 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
37 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
38 #include <cppuhelper/typeprovider.hxx>
39 #include <comphelper/sequence.hxx>
40 #include <vcl/scrbar.hxx>
41 
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::awt;
45 using namespace ::com::sun::star::lang;
46 using namespace ::com::sun::star::beans;
47 using namespace ::com::sun::star::accessibility;
48 using namespace ::comphelper;
49 
50 
51 // -----------------------------------------------------------------------------
52 // VCLXAccessibleScrollBar
53 // -----------------------------------------------------------------------------
54 
55 VCLXAccessibleScrollBar::VCLXAccessibleScrollBar( VCLXWindow* pVCLWindow )
56 	:VCLXAccessibleComponent( pVCLWindow )
57 {
58 }
59 
60 // -----------------------------------------------------------------------------
61 
62 VCLXAccessibleScrollBar::~VCLXAccessibleScrollBar()
63 {
64 }
65 
66 // -----------------------------------------------------------------------------
67 
68 void VCLXAccessibleScrollBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
69 {
70     switch ( rVclWindowEvent.GetId() )
71     {
72 		case VCLEVENT_SCROLLBAR_SCROLL:
73         {
74             NotifyAccessibleEvent( AccessibleEventId::VALUE_CHANGED, Any(), Any() );
75         }
76         break;
77 		default:
78 			VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
79    }
80 }
81 
82 // -----------------------------------------------------------------------------
83 
84 void VCLXAccessibleScrollBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
85 {
86 	VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
87 
88 	VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
89 	if ( pVCLXScrollBar )
90 	{
91 		// IA2 CWS: scroll bar should not have FOCUSABLE state.
92         // rStateSet.AddState( AccessibleStateType::FOCUSABLE );
93 		if ( pVCLXScrollBar->getOrientation() == ScrollBarOrientation::HORIZONTAL )
94             rStateSet.AddState( AccessibleStateType::HORIZONTAL );
95 		else if ( pVCLXScrollBar->getOrientation() == ScrollBarOrientation::VERTICAL )
96             rStateSet.AddState( AccessibleStateType::VERTICAL );
97 	}
98 }
99 
100 // -----------------------------------------------------------------------------
101 // XInterface
102 // -----------------------------------------------------------------------------
103 
104 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleScrollBar, VCLXAccessibleComponent, VCLXAccessibleScrollBar_BASE )
105 
106 // -----------------------------------------------------------------------------
107 // XTypeProvider
108 // -----------------------------------------------------------------------------
109 
110 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleScrollBar, VCLXAccessibleComponent, VCLXAccessibleScrollBar_BASE )
111 
112 // -----------------------------------------------------------------------------
113 // XServiceInfo
114 // -----------------------------------------------------------------------------
115 
116 ::rtl::OUString VCLXAccessibleScrollBar::getImplementationName() throw (RuntimeException)
117 {
118 	return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleScrollBar" );
119 }
120 
121 // -----------------------------------------------------------------------------
122 
123 Sequence< ::rtl::OUString > VCLXAccessibleScrollBar::getSupportedServiceNames() throw (RuntimeException)
124 {
125 	Sequence< ::rtl::OUString > aNames(1);
126 	aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleScrollBar" );
127 	return aNames;
128 }
129 
130 // -----------------------------------------------------------------------------
131 // XAccessibleAction
132 // -----------------------------------------------------------------------------
133 
134 sal_Int32 VCLXAccessibleScrollBar::getAccessibleActionCount( ) throw (RuntimeException)
135 {
136 	OExternalLockGuard aGuard( this );
137 
138 	return 4;
139 }
140 
141 // -----------------------------------------------------------------------------
142 
143 sal_Bool VCLXAccessibleScrollBar::doAccessibleAction ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
144 {
145 	OExternalLockGuard aGuard( this );
146 
147 	if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
148         throw IndexOutOfBoundsException();
149 
150 	sal_Bool bReturn = sal_False;
151 	ScrollBar* pScrollBar = static_cast< ScrollBar* >( GetWindow() );
152 	if ( pScrollBar )
153 	{
154 		ScrollType eScrollType;
155 		switch ( nIndex )
156 		{
157 			case 0:		eScrollType = SCROLL_LINEUP;	break;
158 			case 1:		eScrollType = SCROLL_LINEDOWN;	break;
159 			case 2:		eScrollType = SCROLL_PAGEUP;	break;
160 			case 3:		eScrollType = SCROLL_PAGEDOWN;	break;
161 			default:	eScrollType = SCROLL_DONTKNOW;	break;
162 		}
163 		if ( pScrollBar->DoScrollAction( eScrollType ) )
164 			bReturn = sal_True;
165 	}
166 
167 	return bReturn;
168 }
169 
170 // -----------------------------------------------------------------------------
171 
172 ::rtl::OUString VCLXAccessibleScrollBar::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
173 {
174 	OExternalLockGuard aGuard( this );
175 
176 	if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
177         throw IndexOutOfBoundsException();
178 
179 	::rtl::OUString sDescription;
180 
181 	switch ( nIndex )
182 	{
183 		case 0:		sDescription = ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_DECLINE ) );		break;
184 		case 1:		sDescription = ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_INCLINE ) );		break;
185 		case 2:		sDescription = ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_DECBLOCK ) );		break;
186 		case 3:		sDescription = ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_INCBLOCK ) );		break;
187 		default:																						break;
188 	}
189 
190 	return sDescription;
191 }
192 
193 // -----------------------------------------------------------------------------
194 
195 Reference< XAccessibleKeyBinding > VCLXAccessibleScrollBar::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
196 {
197 	OExternalLockGuard aGuard( this );
198 
199 	if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
200         throw IndexOutOfBoundsException();
201 
202 	return Reference< XAccessibleKeyBinding >();
203 }
204 
205 // -----------------------------------------------------------------------------
206 // XAccessibleValue
207 // -----------------------------------------------------------------------------
208 
209 Any VCLXAccessibleScrollBar::getCurrentValue(  ) throw (RuntimeException)
210 {
211 	OExternalLockGuard aGuard( this );
212 
213 	Any aValue;
214 
215 	VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
216 	if ( pVCLXScrollBar )
217 		aValue <<= (sal_Int32) pVCLXScrollBar->getValue();
218 
219 	return aValue;
220 }
221 
222 // -----------------------------------------------------------------------------
223 
224 sal_Bool VCLXAccessibleScrollBar::setCurrentValue( const Any& aNumber ) throw (RuntimeException)
225 {
226 	OExternalLockGuard aGuard( this );
227 
228 	sal_Bool bReturn = sal_False;
229 
230 	VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
231 	if ( pVCLXScrollBar )
232 	{
233 		sal_Int32 nValue = 0, nValueMin = 0, nValueMax = 0;
234 		OSL_VERIFY( aNumber >>= nValue );
235 		OSL_VERIFY( getMinimumValue() >>= nValueMin );
236 		OSL_VERIFY( getMaximumValue() >>= nValueMax );
237 
238 		if ( nValue < nValueMin )
239 			nValue = nValueMin;
240 		else if ( nValue > nValueMax )
241 			nValue = nValueMax;
242 
243 		pVCLXScrollBar->setValue( nValue );
244 		bReturn = sal_True;
245 	}
246 
247 	return bReturn;
248 }
249 
250 // -----------------------------------------------------------------------------
251 
252 Any VCLXAccessibleScrollBar::getMaximumValue(  ) throw (RuntimeException)
253 {
254 	OExternalLockGuard aGuard( this );
255 
256 	Any aValue;
257 
258 	VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
259 	if ( pVCLXScrollBar )
260 		aValue <<= (sal_Int32) pVCLXScrollBar->getMaximum();
261 
262 	return aValue;
263 }
264 
265 // -----------------------------------------------------------------------------
266 
267 Any VCLXAccessibleScrollBar::getMinimumValue(  ) throw (RuntimeException)
268 {
269 	OExternalLockGuard aGuard( this );
270 
271 	Any aValue;
272 	aValue <<= (sal_Int32) 0;
273 
274 	return aValue;
275 }
276 
277 // -----------------------------------------------------------------------------
278 
279 // IAccessible2 implementation, 2009
280 ::rtl::OUString VCLXAccessibleScrollBar::getAccessibleName(  ) throw (uno::RuntimeException)
281 {
282 	OExternalLockGuard aGuard( this );
283 
284 	::rtl::OUString aName;
285 	VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
286 	if ( pVCLXScrollBar )
287 	{
288 		if ( pVCLXScrollBar->getOrientation() == ScrollBarOrientation::HORIZONTAL )
289             aName = TK_RES_STRING( RID_STR_ACC_SCROLLBAR_NAME_HORIZONTAL );
290 		else if ( pVCLXScrollBar->getOrientation() == ScrollBarOrientation::VERTICAL )
291             aName = TK_RES_STRING( RID_STR_ACC_SCROLLBAR_NAME_VERTICAL );
292 	}
293 	return aName;
294 }
295 
296