LibreOffice Module accessibility (master) 1
vclxaccessiblescrollbar.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21
22#include <toolkit/awt/vclxwindows.hxx>
23#include <helper/accresmgr.hxx>
24#include <strings.hrc>
25
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>
32#include <vcl/vclevent.hxx>
33#include <strings.hxx>
34
35using namespace ::com::sun::star;
36using namespace ::com::sun::star::uno;
37using namespace ::com::sun::star::awt;
38using namespace ::com::sun::star::lang;
39using namespace ::com::sun::star::beans;
40using namespace ::com::sun::star::accessibility;
41using namespace ::comphelper;
42
43
44// VCLXAccessibleScrollBar
45
46
48{
49 switch ( rVclWindowEvent.GetId() )
50 {
51 case VclEventId::ScrollbarScroll:
52 {
53 NotifyAccessibleEvent( AccessibleEventId::VALUE_CHANGED, Any(), Any() );
54 }
55 break;
56 default:
57 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
58 }
59}
60
61
63{
64 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
65
66 VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
67 if ( pVCLXScrollBar )
68 {
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;
75 }
76}
77
78
79// XServiceInfo
80
81
83{
84 return "com.sun.star.comp.toolkit.AccessibleScrollBar";
85}
86
87
89{
90 return { "com.sun.star.awt.AccessibleScrollBar" };
91}
92
93
94// XAccessibleAction
95
96constexpr sal_Int32 ACCESSIBLE_ACTION_COUNT=4;
97
99{
100 OExternalLockGuard aGuard( this );
101
103}
104
105
107{
108 OExternalLockGuard aGuard( this );
109
110 if ( nIndex < 0 || nIndex >= ACCESSIBLE_ACTION_COUNT )
111 throw IndexOutOfBoundsException();
112
113 bool bReturn = false;
114 VclPtr< ScrollBar > pScrollBar = GetAs< ScrollBar >();
115 if ( pScrollBar )
116 {
117 ScrollType eScrollType;
118 switch ( nIndex )
119 {
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;
125 }
126 if ( pScrollBar->DoScrollAction( eScrollType ) )
127 bReturn = true;
128 }
129
130 return bReturn;
131}
132
133
135{
136 OExternalLockGuard aGuard( this );
137
138 if ( nIndex < 0 || nIndex >= ACCESSIBLE_ACTION_COUNT )
139 throw IndexOutOfBoundsException();
140
141 OUString sDescription;
142
143 switch ( nIndex )
144 {
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;
150 }
151
152 return sDescription;
153}
154
155
156Reference< XAccessibleKeyBinding > VCLXAccessibleScrollBar::getAccessibleActionKeyBinding( sal_Int32 nIndex )
157{
158 OExternalLockGuard aGuard( this );
159
160 if ( nIndex < 0 || nIndex >= ACCESSIBLE_ACTION_COUNT )
161 throw IndexOutOfBoundsException();
162
163 return Reference< XAccessibleKeyBinding >();
164}
165
166
167// XAccessibleValue
168
169
171{
172 OExternalLockGuard aGuard( this );
173
174 Any aValue;
175
176 VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
177 if ( pVCLXScrollBar )
178 aValue <<= pVCLXScrollBar->getValue();
179
180 return aValue;
181}
182
183
185{
186 OExternalLockGuard aGuard( this );
187
188 bool bReturn = false;
189
190 VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
191 if ( pVCLXScrollBar )
192 {
193 sal_Int32 nValue = 0, nValueMin = 0, nValueMax = 0;
194 OSL_VERIFY( aNumber >>= nValue );
195 OSL_VERIFY( getMinimumValue() >>= nValueMin );
196 OSL_VERIFY( getMaximumValue() >>= nValueMax );
197
198 if ( nValue < nValueMin )
199 nValue = nValueMin;
200 else if ( nValue > nValueMax )
201 nValue = nValueMax;
202
203 pVCLXScrollBar->setValue( nValue );
204 bReturn = true;
205 }
206
207 return bReturn;
208}
209
210
212{
213 OExternalLockGuard aGuard( this );
214
215 Any aValue;
216
217 VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
218 if ( pVCLXScrollBar )
219 aValue <<= pVCLXScrollBar->getMaximum();
220
221 return aValue;
222}
223
224
226{
227 OExternalLockGuard aGuard( this );
228
229 Any aValue;
230 aValue <<= sal_Int32(0);
231
232 return aValue;
233}
234
236{
237 OExternalLockGuard aGuard( this );
238
239 return Any();
240}
241
242
244{
245 OExternalLockGuard aGuard( this );
246
247 OUString aName;
248 VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
249 if ( pVCLXScrollBar )
250 {
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 );
255 }
256 return aName;
257}
258
259
260/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString AccResId(TranslateId aId)
Definition: accresmgr.cxx:22
virtual sal_Bool SAL_CALL setCurrentValue(const css::uno::Any &aNumber) override
virtual OUString SAL_CALL getAccessibleActionDescription(sal_Int32 nIndex) override
virtual void FillAccessibleStateSet(sal_Int64 &rStateSet) override
virtual void ProcessWindowEvent(const VclWindowEvent &rVclWindowEvent) override
virtual css::uno::Any SAL_CALL getMinimumIncrement() override
virtual css::uno::Any SAL_CALL getMaximumValue() override
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Reference< css::accessibility::XAccessibleKeyBinding > SAL_CALL getAccessibleActionKeyBinding(sal_Int32 nIndex) override
OUString SAL_CALL getAccessibleName() override
virtual sal_Int32 SAL_CALL getAccessibleActionCount() override
virtual css::uno::Any SAL_CALL getCurrentValue() override
virtual sal_Bool SAL_CALL doAccessibleAction(sal_Int32 nIndex) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Any SAL_CALL getMinimumValue() override
sal_Int32 SAL_CALL getOrientation() override
sal_Int32 SAL_CALL getMaximum() override
sal_Int32 SAL_CALL getValue() override
void SAL_CALL setValue(sal_Int32 n) override
VclEventId GetId() const
sal_Int16 nValue
sal_Int32 nIndex
OUString aName
constexpr OUStringLiteral RID_STR_ACC_ACTION_INCBLOCK
Definition: strings.hxx:19
constexpr OUStringLiteral RID_STR_ACC_ACTION_DECLINE
Definition: strings.hxx:18
constexpr OUStringLiteral RID_STR_ACC_ACTION_INCLINE
Definition: strings.hxx:17
constexpr OUStringLiteral RID_STR_ACC_ACTION_DECBLOCK
Definition: strings.hxx:20
unsigned char sal_Bool
ScrollType
constexpr sal_Int32 ACCESSIBLE_ACTION_COUNT