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 <helper/accresmgr.hxx>
23 #include <strings.hrc>
25 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
26 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
27 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
28 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
29 #include <comphelper/accessiblecontexthelper.hxx>
30 #include <vcl/accessibility/strings.hxx>
31 #include <vcl/vclevent.hxx>
33 using namespace ::com::sun::star
;
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::awt
;
36 using namespace ::com::sun::star::lang
;
37 using namespace ::com::sun::star::accessibility
;
38 using namespace ::comphelper
;
41 // VCLXAccessibleScrollBar
44 void VCLXAccessibleScrollBar::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
46 switch ( rVclWindowEvent
.GetId() )
48 case VclEventId::ScrollbarScroll
:
50 NotifyAccessibleEvent( AccessibleEventId::VALUE_CHANGED
, Any(), Any() );
54 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent
);
59 void VCLXAccessibleScrollBar::FillAccessibleStateSet( sal_Int64
& rStateSet
)
61 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet
);
63 // IA2 CWS: scroll bar should not have FOCUSABLE state.
64 // rStateSet.AddState( AccessibleStateType::FOCUSABLE );
65 rStateSet
|= GetOrientationState();
72 OUString
VCLXAccessibleScrollBar::getImplementationName()
74 return u
"com.sun.star.comp.toolkit.AccessibleScrollBar"_ustr
;
78 Sequence
< OUString
> VCLXAccessibleScrollBar::getSupportedServiceNames()
80 return { u
"com.sun.star.awt.AccessibleScrollBar"_ustr
};
86 constexpr sal_Int32 ACCESSIBLE_ACTION_COUNT
=4;
88 sal_Int32
VCLXAccessibleScrollBar::getAccessibleActionCount( )
90 OExternalLockGuard
aGuard( this );
92 return ACCESSIBLE_ACTION_COUNT
;
96 sal_Bool
VCLXAccessibleScrollBar::doAccessibleAction ( sal_Int32 nIndex
)
98 OExternalLockGuard
aGuard( this );
100 if ( nIndex
< 0 || nIndex
>= ACCESSIBLE_ACTION_COUNT
)
101 throw IndexOutOfBoundsException();
103 bool bReturn
= false;
104 VclPtr
< ScrollBar
> pScrollBar
= GetAs
< ScrollBar
>();
107 ScrollType eScrollType
;
110 case 0: eScrollType
= ScrollType::LineUp
; break;
111 case 1: eScrollType
= ScrollType::LineDown
; break;
112 case 2: eScrollType
= ScrollType::PageUp
; break;
113 case 3: eScrollType
= ScrollType::PageDown
; break;
114 default: eScrollType
= ScrollType::DontKnow
; break;
116 if ( pScrollBar
->DoScrollAction( eScrollType
) )
124 OUString
VCLXAccessibleScrollBar::getAccessibleActionDescription ( sal_Int32 nIndex
)
126 OExternalLockGuard
aGuard( this );
128 if ( nIndex
< 0 || nIndex
>= ACCESSIBLE_ACTION_COUNT
)
129 throw IndexOutOfBoundsException();
131 OUString sDescription
;
135 case 0: sDescription
= RID_STR_ACC_ACTION_DECLINE
; break;
136 case 1: sDescription
= RID_STR_ACC_ACTION_INCLINE
; break;
137 case 2: sDescription
= RID_STR_ACC_ACTION_DECBLOCK
; break;
138 case 3: sDescription
= RID_STR_ACC_ACTION_INCBLOCK
; break;
146 Reference
< XAccessibleKeyBinding
> VCLXAccessibleScrollBar::getAccessibleActionKeyBinding( sal_Int32 nIndex
)
148 OExternalLockGuard
aGuard( this );
150 if ( nIndex
< 0 || nIndex
>= ACCESSIBLE_ACTION_COUNT
)
151 throw IndexOutOfBoundsException();
153 return Reference
< XAccessibleKeyBinding
>();
160 Any
VCLXAccessibleScrollBar::getCurrentValue( )
162 OExternalLockGuard
aGuard( this );
166 VclPtr
<ScrollBar
> pScrollBar
= GetAs
<ScrollBar
>();
168 aValue
<<= sal_Int32(pScrollBar
->GetThumbPos());
174 sal_Bool
VCLXAccessibleScrollBar::setCurrentValue( const Any
& aNumber
)
176 OExternalLockGuard
aGuard( this );
178 bool bReturn
= false;
180 VclPtr
<ScrollBar
> pScrollBar
= GetAs
<ScrollBar
>();
183 sal_Int32 nValue
= 0;
184 OSL_VERIFY( aNumber
>>= nValue
);
185 sal_Int32 nValueMax
= pScrollBar
->GetRangeMax();
189 else if ( nValue
> nValueMax
)
192 pScrollBar
->DoScroll(nValue
);
200 Any
VCLXAccessibleScrollBar::getMaximumValue( )
202 OExternalLockGuard
aGuard( this );
206 VclPtr
<ScrollBar
> pScrollBar
= GetAs
<ScrollBar
>();
208 aValue
<<= sal_Int32(pScrollBar
->GetRangeMax());
214 Any
VCLXAccessibleScrollBar::getMinimumValue( )
216 OExternalLockGuard
aGuard( this );
219 aValue
<<= sal_Int32(0);
224 Any
VCLXAccessibleScrollBar::getMinimumIncrement( )
226 OExternalLockGuard
aGuard( this );
232 OUString
VCLXAccessibleScrollBar::getAccessibleName( )
234 OExternalLockGuard
aGuard( this );
236 if (VCLXAccessibleScrollBar::GetOrientationState() == AccessibleStateType::HORIZONTAL
)
237 return AccResId(RID_STR_ACC_SCROLLBAR_NAME_HORIZONTAL
);
239 return AccResId(RID_STR_ACC_SCROLLBAR_NAME_VERTICAL
);
242 sal_Int64
VCLXAccessibleScrollBar::GetOrientationState() const
244 VclPtr
<ScrollBar
> pScrollBar
= GetAs
<ScrollBar
>();
245 if (!pScrollBar
|| pScrollBar
->GetStyle() & WB_HORZ
)
246 return AccessibleStateType::HORIZONTAL
;
248 return AccessibleStateType::VERTICAL
;
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */