Branch libreoffice-5-0-4
[LibreOffice.git] / accessibility / source / standard / vclxaccessiblescrollbar.cxx
blob76e58a67537da87002c8a304a68555a9879d48b0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <accessibility/standard/vclxaccessiblescrollbar.hxx>
22 #include <toolkit/awt/vclxwindows.hxx>
23 #include <accessibility/helper/accresmgr.hxx>
24 #include <accessibility/helper/accessiblestrings.hrc>
26 #include <unotools/accessiblestatesethelper.hxx>
27 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
28 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
29 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
30 #include <cppuhelper/typeprovider.hxx>
31 #include <comphelper/sequence.hxx>
32 #include <vcl/scrbar.hxx>
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::awt;
37 using namespace ::com::sun::star::lang;
38 using namespace ::com::sun::star::beans;
39 using namespace ::com::sun::star::accessibility;
40 using namespace ::comphelper;
43 // VCLXAccessibleScrollBar
46 VCLXAccessibleScrollBar::VCLXAccessibleScrollBar( VCLXWindow* pVCLWindow )
47 :VCLXAccessibleComponent( pVCLWindow )
53 VCLXAccessibleScrollBar::~VCLXAccessibleScrollBar()
59 void VCLXAccessibleScrollBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
61 switch ( rVclWindowEvent.GetId() )
63 case VCLEVENT_SCROLLBAR_SCROLL:
65 NotifyAccessibleEvent( AccessibleEventId::VALUE_CHANGED, Any(), Any() );
67 break;
68 default:
69 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
75 void VCLXAccessibleScrollBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
77 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
79 VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
80 if ( pVCLXScrollBar )
82 // IA2 CWS: scroll bar should not have FOCUSABLE state.
83 // rStateSet.AddState( AccessibleStateType::FOCUSABLE );
84 if ( pVCLXScrollBar->getOrientation() == ScrollBarOrientation::HORIZONTAL )
85 rStateSet.AddState( AccessibleStateType::HORIZONTAL );
86 else if ( pVCLXScrollBar->getOrientation() == ScrollBarOrientation::VERTICAL )
87 rStateSet.AddState( AccessibleStateType::VERTICAL );
92 // XInterface
95 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleScrollBar, VCLXAccessibleComponent, VCLXAccessibleScrollBar_BASE )
98 // XTypeProvider
101 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleScrollBar, VCLXAccessibleComponent, VCLXAccessibleScrollBar_BASE )
104 // XServiceInfo
107 OUString VCLXAccessibleScrollBar::getImplementationName() throw (RuntimeException, std::exception)
109 return OUString( "com.sun.star.comp.toolkit.AccessibleScrollBar" );
114 Sequence< OUString > VCLXAccessibleScrollBar::getSupportedServiceNames() throw (RuntimeException, std::exception)
116 Sequence< OUString > aNames(1);
117 aNames[0] = "com.sun.star.awt.AccessibleScrollBar";
118 return aNames;
122 // XAccessibleAction
125 sal_Int32 VCLXAccessibleScrollBar::getAccessibleActionCount( ) throw (RuntimeException, std::exception)
127 OExternalLockGuard aGuard( this );
129 return 4;
134 sal_Bool VCLXAccessibleScrollBar::doAccessibleAction ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
136 OExternalLockGuard aGuard( this );
138 if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
139 throw IndexOutOfBoundsException();
141 bool bReturn = false;
142 VclPtr< ScrollBar > pScrollBar = GetAs< ScrollBar >();
143 if ( pScrollBar )
145 ScrollType eScrollType;
146 switch ( nIndex )
148 case 0: eScrollType = SCROLL_LINEUP; break;
149 case 1: eScrollType = SCROLL_LINEDOWN; break;
150 case 2: eScrollType = SCROLL_PAGEUP; break;
151 case 3: eScrollType = SCROLL_PAGEDOWN; break;
152 default: eScrollType = SCROLL_DONTKNOW; break;
154 if ( pScrollBar->DoScrollAction( eScrollType ) )
155 bReturn = true;
158 return bReturn;
163 OUString VCLXAccessibleScrollBar::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
165 OExternalLockGuard aGuard( this );
167 if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
168 throw IndexOutOfBoundsException();
170 OUString sDescription;
172 switch ( nIndex )
174 case 0: sDescription = OUString( TK_RES_STRING( RID_STR_ACC_ACTION_DECLINE ) ); break;
175 case 1: sDescription = OUString( TK_RES_STRING( RID_STR_ACC_ACTION_INCLINE ) ); break;
176 case 2: sDescription = OUString( TK_RES_STRING( RID_STR_ACC_ACTION_DECBLOCK ) ); break;
177 case 3: sDescription = OUString( TK_RES_STRING( RID_STR_ACC_ACTION_INCBLOCK ) ); break;
178 default: break;
181 return sDescription;
186 Reference< XAccessibleKeyBinding > VCLXAccessibleScrollBar::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
188 OExternalLockGuard aGuard( this );
190 if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
191 throw IndexOutOfBoundsException();
193 return Reference< XAccessibleKeyBinding >();
197 // XAccessibleValue
200 Any VCLXAccessibleScrollBar::getCurrentValue( ) throw (RuntimeException, std::exception)
202 OExternalLockGuard aGuard( this );
204 Any aValue;
206 VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
207 if ( pVCLXScrollBar )
208 aValue <<= (sal_Int32) pVCLXScrollBar->getValue();
210 return aValue;
215 sal_Bool VCLXAccessibleScrollBar::setCurrentValue( const Any& aNumber ) throw (RuntimeException, std::exception)
217 OExternalLockGuard aGuard( this );
219 bool bReturn = false;
221 VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
222 if ( pVCLXScrollBar )
224 sal_Int32 nValue = 0, nValueMin = 0, nValueMax = 0;
225 OSL_VERIFY( aNumber >>= nValue );
226 OSL_VERIFY( getMinimumValue() >>= nValueMin );
227 OSL_VERIFY( getMaximumValue() >>= nValueMax );
229 if ( nValue < nValueMin )
230 nValue = nValueMin;
231 else if ( nValue > nValueMax )
232 nValue = nValueMax;
234 pVCLXScrollBar->setValue( nValue );
235 bReturn = true;
238 return bReturn;
243 Any VCLXAccessibleScrollBar::getMaximumValue( ) throw (RuntimeException, std::exception)
245 OExternalLockGuard aGuard( this );
247 Any aValue;
249 VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
250 if ( pVCLXScrollBar )
251 aValue <<= (sal_Int32) pVCLXScrollBar->getMaximum();
253 return aValue;
258 Any VCLXAccessibleScrollBar::getMinimumValue( ) throw (RuntimeException, std::exception)
260 OExternalLockGuard aGuard( this );
262 Any aValue;
263 aValue <<= (sal_Int32) 0;
265 return aValue;
270 OUString VCLXAccessibleScrollBar::getAccessibleName( ) throw (uno::RuntimeException, std::exception)
272 OExternalLockGuard aGuard( this );
274 OUString aName;
275 VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
276 if ( pVCLXScrollBar )
278 if ( pVCLXScrollBar->getOrientation() == ScrollBarOrientation::HORIZONTAL )
279 aName = TK_RES_STRING( RID_STR_ACC_SCROLLBAR_NAME_HORIZONTAL );
280 else if ( pVCLXScrollBar->getOrientation() == ScrollBarOrientation::VERTICAL )
281 aName = TK_RES_STRING( RID_STR_ACC_SCROLLBAR_NAME_VERTICAL );
283 return aName;
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */