1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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() );
57 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent
);
62 void VCLXAccessibleScrollBar::FillAccessibleStateSet( sal_Int64
& rStateSet
)
64 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet
);
66 VCLXScrollBar
* pVCLXScrollBar
= static_cast< VCLXScrollBar
* >( GetVCLXWindow() );
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
;
82 OUString
VCLXAccessibleScrollBar::getImplementationName()
84 return "com.sun.star.comp.toolkit.AccessibleScrollBar";
88 Sequence
< OUString
> VCLXAccessibleScrollBar::getSupportedServiceNames()
90 return { "com.sun.star.awt.AccessibleScrollBar" };
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
>();
117 ScrollType eScrollType
;
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
) )
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
;
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;
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
>();
170 Any
VCLXAccessibleScrollBar::getCurrentValue( )
172 OExternalLockGuard
aGuard( this );
176 VCLXScrollBar
* pVCLXScrollBar
= static_cast< VCLXScrollBar
* >( GetVCLXWindow() );
177 if ( pVCLXScrollBar
)
178 aValue
<<= pVCLXScrollBar
->getValue();
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
)
200 else if ( nValue
> nValueMax
)
203 pVCLXScrollBar
->setValue( nValue
);
211 Any
VCLXAccessibleScrollBar::getMaximumValue( )
213 OExternalLockGuard
aGuard( this );
217 VCLXScrollBar
* pVCLXScrollBar
= static_cast< VCLXScrollBar
* >( GetVCLXWindow() );
218 if ( pVCLXScrollBar
)
219 aValue
<<= pVCLXScrollBar
->getMaximum();
225 Any
VCLXAccessibleScrollBar::getMinimumValue( )
227 OExternalLockGuard
aGuard( this );
230 aValue
<<= sal_Int32(0);
235 Any
VCLXAccessibleScrollBar::getMinimumIncrement( )
237 OExternalLockGuard
aGuard( this );
243 OUString
VCLXAccessibleScrollBar::getAccessibleName( )
245 OExternalLockGuard
aGuard( this );
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
);
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */