Debian Codegraph @

vcl/source/accessibility/vclxaccessiblescrollbar.cxx

raw symbols SCIP
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
20 #include <accessibility/vclxaccessiblescrollbar.hxx>
21
22 #include <svdata.hxx>
23 #include <strings.hrc>
24
25 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
26 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
27 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
28 #include <comphelper/accessiblecontexthelper.hxx>
29 #include <vcl/accessibility/strings.hxx>
30 #include <vcl/vclevent.hxx>
31
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::awt;
35 using namespace ::com::sun::star::lang;
36 using namespace ::com::sun::star::accessibility;
37 using namespace ::comphelper;
38
39
40 // VCLXAccessibleScrollBar
41
42
43 void VCLXAccessibleScrollBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
44 {
45 switch ( rVclWindowEvent.GetId() )
46 {
47 case VclEventId::ScrollbarScroll:
48 {
49 NotifyAccessibleEvent( AccessibleEventId::VALUE_CHANGED, Any(), Any() );
50 }
51 break;
52 default:
53 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
54 }
55 }
56
57
58 void VCLXAccessibleScrollBar::FillAccessibleStateSet( sal_Int64& rStateSet )
59 {
60 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
61
62 // IA2 CWS: scroll bar should not have FOCUSABLE state.
63 // rStateSet.AddState( AccessibleStateType::FOCUSABLE );
64 rStateSet |= GetOrientationState();
65 }
66
67
68 // XServiceInfo
69
70
71 OUString VCLXAccessibleScrollBar::getImplementationName()
72 {
73 return u"com.sun.star.comp.toolkit.AccessibleScrollBar"_ustr;
74 }
75
76
77 Sequence< OUString > VCLXAccessibleScrollBar::getSupportedServiceNames()
78 {
79 return { u"com.sun.star.awt.AccessibleScrollBar"_ustr };
80 }
81
82 // XAccessibleAction
83
84 constexpr sal_Int32 ACCESSIBLE_ACTION_COUNT=4;
85
86 sal_Int32 VCLXAccessibleScrollBar::getAccessibleActionCount( )
87 {
88 OExternalLockGuard aGuard( this );
89
90 return ACCESSIBLE_ACTION_COUNT;
91 }
92
93
94 sal_Bool VCLXAccessibleScrollBar::doAccessibleAction ( sal_Int32 nIndex )
95 {
96 OExternalLockGuard aGuard( this );
97
98 if ( nIndex < 0 || nIndex >= ACCESSIBLE_ACTION_COUNT )
99 throw IndexOutOfBoundsException();
100
101 bool bReturn = false;
102 VclPtr< ScrollBar > pScrollBar = GetAs< ScrollBar >();
103 if ( pScrollBar )
104 {
105 ScrollType eScrollType;
106 switch ( nIndex )
107 {
108 case 0: eScrollType = ScrollType::LineUp; break;
109 case 1: eScrollType = ScrollType::LineDown; break;
110 case 2: eScrollType = ScrollType::PageUp; break;
111 case 3: eScrollType = ScrollType::PageDown; break;
112 default: eScrollType = ScrollType::DontKnow; break;
113 }
114 if ( pScrollBar->DoScrollAction( eScrollType ) )
115 bReturn = true;
116 }
117
118 return bReturn;
119 }
120
121
122 OUString VCLXAccessibleScrollBar::getAccessibleActionDescription ( sal_Int32 nIndex )
123 {
124 OExternalLockGuard aGuard( this );
125
126 if ( nIndex < 0 || nIndex >= ACCESSIBLE_ACTION_COUNT )
127 throw IndexOutOfBoundsException();
128
129 OUString sDescription;
130
131 switch ( nIndex )
132 {
133 case 0: sDescription = RID_STR_ACC_ACTION_DECLINE; break;
134 case 1: sDescription = RID_STR_ACC_ACTION_INCLINE; break;
135 case 2: sDescription = RID_STR_ACC_ACTION_DECBLOCK; break;
136 case 3: sDescription = RID_STR_ACC_ACTION_INCBLOCK; break;
137 default: break;
138 }
139
140 return sDescription;
141 }
142
143
144 Reference< XAccessibleKeyBinding > VCLXAccessibleScrollBar::getAccessibleActionKeyBinding( sal_Int32 nIndex )
145 {
146 OExternalLockGuard aGuard( this );
147
148 if ( nIndex < 0 || nIndex >= ACCESSIBLE_ACTION_COUNT )
149 throw IndexOutOfBoundsException();
150
151 return Reference< XAccessibleKeyBinding >();
152 }
153
154
155 // XAccessibleValue
156
157
158 Any VCLXAccessibleScrollBar::getCurrentValue( )
159 {
160 OExternalLockGuard aGuard( this );
161
162 Any aValue;
163
164 VclPtr<ScrollBar> pScrollBar = GetAs<ScrollBar>();
165 if (pScrollBar)
166 aValue <<= sal_Int32(pScrollBar->GetThumbPos());
167
168 return aValue;
169 }
170
171
172 sal_Bool VCLXAccessibleScrollBar::setCurrentValue( const Any& aNumber )
173 {
174 OExternalLockGuard aGuard( this );
175
176 bool bReturn = false;
177
178 VclPtr<ScrollBar> pScrollBar = GetAs<ScrollBar>();
179 if (pScrollBar)
180 {
181 sal_Int32 nValue = 0;
182 OSL_VERIFY( aNumber >>= nValue );
183 sal_Int32 nValueMax = pScrollBar->GetRangeMax();
184
185 if (nValue < 0)
186 nValue = 0;
187 else if ( nValue > nValueMax )
188 nValue = nValueMax;
189
190 pScrollBar->DoScroll(nValue);
191 bReturn = true;
192 }
193
194 return bReturn;
195 }
196
197
198 Any VCLXAccessibleScrollBar::getMaximumValue( )
199 {
200 OExternalLockGuard aGuard( this );
201
202 Any aValue;
203
204 VclPtr<ScrollBar> pScrollBar = GetAs<ScrollBar>();
205 if (pScrollBar)
206 aValue <<= sal_Int32(pScrollBar->GetRangeMax());
207
208 return aValue;
209 }
210
211
212 Any VCLXAccessibleScrollBar::getMinimumValue( )
213 {
214 OExternalLockGuard aGuard( this );
215
216 Any aValue;
217 aValue <<= sal_Int32(0);
218
219 return aValue;
220 }
221
222 Any VCLXAccessibleScrollBar::getMinimumIncrement( )
223 {
224 OExternalLockGuard aGuard( this );
225
226 return Any();
227 }
228
229
230 OUString VCLXAccessibleScrollBar::getAccessibleName( )
231 {
232 OExternalLockGuard aGuard( this );
233
234 if (VCLXAccessibleScrollBar::GetOrientationState() == AccessibleStateType::HORIZONTAL)
235 return VclResId(RID_STR_ACC_SCROLLBAR_NAME_HORIZONTAL);
236
237 return VclResId(RID_STR_ACC_SCROLLBAR_NAME_VERTICAL);
238 }
239
240 sal_Int64 VCLXAccessibleScrollBar::GetOrientationState() const
241 {
242 VclPtr<ScrollBar> pScrollBar = GetAs<ScrollBar>();
243 if (!pScrollBar || pScrollBar->GetStyle() & WB_HORZ)
244 return AccessibleStateType::HORIZONTAL;
245
246 return AccessibleStateType::VERTICAL;
247 }
248
249
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */