Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / accessibility / source / standard / vclxaccessiblescrollbar.cxx
blob4ea6f788bb3ce29fea33fcbf788cc7d3f96f476b
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 <standard/vclxaccessiblescrollbar.hxx>
22 #include <toolkit/awt/vclxwindows.hxx>
23 #include <helper/accresmgr.hxx>
24 #include <strings.hrc>
26 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
27 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
28 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
29 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
30 #include <comphelper/accessiblecontexthelper.hxx>
31 #include <vcl/toolkit/scrbar.hxx>
32 #include <vcl/vclevent.hxx>
33 #include <strings.hxx>
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::awt;
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::accessibility;
41 using namespace ::comphelper;
44 // VCLXAccessibleScrollBar
47 void VCLXAccessibleScrollBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
49 switch ( rVclWindowEvent.GetId() )
51 case VclEventId::ScrollbarScroll:
53 NotifyAccessibleEvent( AccessibleEventId::VALUE_CHANGED, Any(), Any() );
55 break;
56 default:
57 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
62 void VCLXAccessibleScrollBar::FillAccessibleStateSet( sal_Int64& rStateSet )
64 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
66 VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
67 if ( pVCLXScrollBar )
69 // IA2 CWS: scroll bar should not have FOCUSABLE state.
70 // rStateSet.AddState( AccessibleStateType::FOCUSABLE );
71 if ( pVCLXScrollBar->getOrientation() == ScrollBarOrientation::HORIZONTAL )
72 rStateSet |= AccessibleStateType::HORIZONTAL;
73 else if ( pVCLXScrollBar->getOrientation() == ScrollBarOrientation::VERTICAL )
74 rStateSet |= AccessibleStateType::VERTICAL;
79 // XServiceInfo
82 OUString VCLXAccessibleScrollBar::getImplementationName()
84 return "com.sun.star.comp.toolkit.AccessibleScrollBar";
88 Sequence< OUString > VCLXAccessibleScrollBar::getSupportedServiceNames()
90 return { "com.sun.star.awt.AccessibleScrollBar" };
94 // XAccessibleAction
96 constexpr sal_Int32 ACCESSIBLE_ACTION_COUNT=4;
98 sal_Int32 VCLXAccessibleScrollBar::getAccessibleActionCount( )
100 OExternalLockGuard aGuard( this );
102 return ACCESSIBLE_ACTION_COUNT;
106 sal_Bool VCLXAccessibleScrollBar::doAccessibleAction ( sal_Int32 nIndex )
108 OExternalLockGuard aGuard( this );
110 if ( nIndex < 0 || nIndex >= ACCESSIBLE_ACTION_COUNT )
111 throw IndexOutOfBoundsException();
113 bool bReturn = false;
114 VclPtr< ScrollBar > pScrollBar = GetAs< ScrollBar >();
115 if ( pScrollBar )
117 ScrollType eScrollType;
118 switch ( nIndex )
120 case 0: eScrollType = ScrollType::LineUp; break;
121 case 1: eScrollType = ScrollType::LineDown; break;
122 case 2: eScrollType = ScrollType::PageUp; break;
123 case 3: eScrollType = ScrollType::PageDown; break;
124 default: eScrollType = ScrollType::DontKnow; break;
126 if ( pScrollBar->DoScrollAction( eScrollType ) )
127 bReturn = true;
130 return bReturn;
134 OUString VCLXAccessibleScrollBar::getAccessibleActionDescription ( sal_Int32 nIndex )
136 OExternalLockGuard aGuard( this );
138 if ( nIndex < 0 || nIndex >= ACCESSIBLE_ACTION_COUNT )
139 throw IndexOutOfBoundsException();
141 OUString sDescription;
143 switch ( nIndex )
145 case 0: sDescription = OUString(RID_STR_ACC_ACTION_DECLINE); break;
146 case 1: sDescription = OUString(RID_STR_ACC_ACTION_INCLINE); break;
147 case 2: sDescription = OUString(RID_STR_ACC_ACTION_DECBLOCK); break;
148 case 3: sDescription = OUString(RID_STR_ACC_ACTION_INCBLOCK); break;
149 default: break;
152 return sDescription;
156 Reference< XAccessibleKeyBinding > VCLXAccessibleScrollBar::getAccessibleActionKeyBinding( sal_Int32 nIndex )
158 OExternalLockGuard aGuard( this );
160 if ( nIndex < 0 || nIndex >= ACCESSIBLE_ACTION_COUNT )
161 throw IndexOutOfBoundsException();
163 return Reference< XAccessibleKeyBinding >();
167 // XAccessibleValue
170 Any VCLXAccessibleScrollBar::getCurrentValue( )
172 OExternalLockGuard aGuard( this );
174 Any aValue;
176 VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
177 if ( pVCLXScrollBar )
178 aValue <<= pVCLXScrollBar->getValue();
180 return aValue;
184 sal_Bool VCLXAccessibleScrollBar::setCurrentValue( const Any& aNumber )
186 OExternalLockGuard aGuard( this );
188 bool bReturn = false;
190 VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
191 if ( pVCLXScrollBar )
193 sal_Int32 nValue = 0, nValueMin = 0, nValueMax = 0;
194 OSL_VERIFY( aNumber >>= nValue );
195 OSL_VERIFY( getMinimumValue() >>= nValueMin );
196 OSL_VERIFY( getMaximumValue() >>= nValueMax );
198 if ( nValue < nValueMin )
199 nValue = nValueMin;
200 else if ( nValue > nValueMax )
201 nValue = nValueMax;
203 pVCLXScrollBar->setValue( nValue );
204 bReturn = true;
207 return bReturn;
211 Any VCLXAccessibleScrollBar::getMaximumValue( )
213 OExternalLockGuard aGuard( this );
215 Any aValue;
217 VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
218 if ( pVCLXScrollBar )
219 aValue <<= pVCLXScrollBar->getMaximum();
221 return aValue;
225 Any VCLXAccessibleScrollBar::getMinimumValue( )
227 OExternalLockGuard aGuard( this );
229 Any aValue;
230 aValue <<= sal_Int32(0);
232 return aValue;
235 Any VCLXAccessibleScrollBar::getMinimumIncrement( )
237 OExternalLockGuard aGuard( this );
239 return Any();
243 OUString VCLXAccessibleScrollBar::getAccessibleName( )
245 OExternalLockGuard aGuard( this );
247 OUString aName;
248 VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
249 if ( pVCLXScrollBar )
251 if ( pVCLXScrollBar->getOrientation() == ScrollBarOrientation::HORIZONTAL )
252 aName = AccResId( RID_STR_ACC_SCROLLBAR_NAME_HORIZONTAL );
253 else if ( pVCLXScrollBar->getOrientation() == ScrollBarOrientation::VERTICAL )
254 aName = AccResId( RID_STR_ACC_SCROLLBAR_NAME_VERTICAL );
256 return aName;
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */