tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / accessibility / source / standard / vclxaccessiblescrollbar.cxx
blob7dfb2a145e441bd24a1d9308498aeccc9b1c7e86
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 <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() );
52 break;
53 default:
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();
69 // XServiceInfo
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 };
84 // XAccessibleAction
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 >();
105 if ( pScrollBar )
107 ScrollType eScrollType;
108 switch ( nIndex )
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 ) )
117 bReturn = true;
120 return bReturn;
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;
133 switch ( nIndex )
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;
139 default: break;
142 return sDescription;
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 >();
157 // XAccessibleValue
160 Any VCLXAccessibleScrollBar::getCurrentValue( )
162 OExternalLockGuard aGuard( this );
164 Any aValue;
166 VclPtr<ScrollBar> pScrollBar = GetAs<ScrollBar>();
167 if (pScrollBar)
168 aValue <<= sal_Int32(pScrollBar->GetThumbPos());
170 return aValue;
174 sal_Bool VCLXAccessibleScrollBar::setCurrentValue( const Any& aNumber )
176 OExternalLockGuard aGuard( this );
178 bool bReturn = false;
180 VclPtr<ScrollBar> pScrollBar = GetAs<ScrollBar>();
181 if (pScrollBar)
183 sal_Int32 nValue = 0;
184 OSL_VERIFY( aNumber >>= nValue );
185 sal_Int32 nValueMax = pScrollBar->GetRangeMax();
187 if (nValue < 0)
188 nValue = 0;
189 else if ( nValue > nValueMax )
190 nValue = nValueMax;
192 pScrollBar->DoScroll(nValue);
193 bReturn = true;
196 return bReturn;
200 Any VCLXAccessibleScrollBar::getMaximumValue( )
202 OExternalLockGuard aGuard( this );
204 Any aValue;
206 VclPtr<ScrollBar> pScrollBar = GetAs<ScrollBar>();
207 if (pScrollBar)
208 aValue <<= sal_Int32(pScrollBar->GetRangeMax());
210 return aValue;
214 Any VCLXAccessibleScrollBar::getMinimumValue( )
216 OExternalLockGuard aGuard( this );
218 Any aValue;
219 aValue <<= sal_Int32(0);
221 return aValue;
224 Any VCLXAccessibleScrollBar::getMinimumIncrement( )
226 OExternalLockGuard aGuard( this );
228 return Any();
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: */