/src/libreoffice/vcl/source/accessibility/vclxaccessiblecheckbox.cxx
Line | Count | Source |
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/vclxaccessiblecheckbox.hxx> |
21 | | |
22 | | #include <svdata.hxx> |
23 | | #include <strings.hrc> |
24 | | |
25 | | #include <comphelper/accessiblecontexthelper.hxx> |
26 | | #include <comphelper/accessiblekeybindinghelper.hxx> |
27 | | #include <com/sun/star/awt/KeyModifier.hpp> |
28 | | #include <com/sun/star/accessibility/AccessibleStateType.hpp> |
29 | | #include <com/sun/star/accessibility/AccessibleEventId.hpp> |
30 | | #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> |
31 | | |
32 | | #include <vcl/event.hxx> |
33 | | #include <vcl/vclevent.hxx> |
34 | | |
35 | | using namespace ::com::sun::star; |
36 | | using namespace ::com::sun::star::uno; |
37 | | using namespace ::com::sun::star::lang; |
38 | | using namespace ::com::sun::star::accessibility; |
39 | | using namespace ::comphelper; |
40 | | |
41 | | |
42 | | // VCLXAccessibleCheckBox |
43 | | |
44 | | |
45 | | VCLXAccessibleCheckBox::VCLXAccessibleCheckBox(CheckBox* pCheckBox) |
46 | 0 | :ImplInheritanceHelper(pCheckBox) |
47 | 0 | { |
48 | 0 | m_bChecked = IsChecked(); |
49 | 0 | m_bIndeterminate = IsIndeterminate(); |
50 | 0 | } |
51 | | |
52 | | |
53 | | bool VCLXAccessibleCheckBox::IsChecked() const |
54 | 0 | { |
55 | 0 | VclPtr<CheckBox> pCheckBox = GetAs<CheckBox>(); |
56 | 0 | return pCheckBox && pCheckBox->IsChecked(); |
57 | 0 | } |
58 | | |
59 | | |
60 | | bool VCLXAccessibleCheckBox::IsIndeterminate() const |
61 | 0 | { |
62 | 0 | VclPtr<CheckBox> pCheckBox = GetAs<CheckBox>(); |
63 | 0 | return pCheckBox && pCheckBox->GetState() == TRISTATE_INDET; |
64 | 0 | } |
65 | | |
66 | | |
67 | | void VCLXAccessibleCheckBox::SetChecked( bool bChecked ) |
68 | 0 | { |
69 | 0 | if ( m_bChecked != bChecked ) |
70 | 0 | { |
71 | 0 | Any aOldValue, aNewValue; |
72 | 0 | if ( m_bChecked ) |
73 | 0 | aOldValue <<= AccessibleStateType::CHECKED; |
74 | 0 | else |
75 | 0 | aNewValue <<= AccessibleStateType::CHECKED; |
76 | 0 | m_bChecked = bChecked; |
77 | 0 | NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); |
78 | 0 | } |
79 | 0 | } |
80 | | |
81 | | |
82 | | void VCLXAccessibleCheckBox::SetIndeterminate( bool bIndeterminate ) |
83 | 0 | { |
84 | 0 | if ( m_bIndeterminate != bIndeterminate ) |
85 | 0 | { |
86 | 0 | Any aOldValue, aNewValue; |
87 | 0 | if ( m_bIndeterminate ) |
88 | 0 | aOldValue <<= AccessibleStateType::INDETERMINATE; |
89 | 0 | else |
90 | 0 | aNewValue <<= AccessibleStateType::INDETERMINATE; |
91 | 0 | m_bIndeterminate = bIndeterminate; |
92 | 0 | NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); |
93 | 0 | } |
94 | 0 | } |
95 | | |
96 | | |
97 | | void VCLXAccessibleCheckBox::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) |
98 | 0 | { |
99 | 0 | switch ( rVclWindowEvent.GetId() ) |
100 | 0 | { |
101 | 0 | case VclEventId::CheckboxToggle: |
102 | 0 | { |
103 | 0 | const sal_Int32 nOldValue = m_bIndeterminate ? 2 : (m_bChecked ? 1 : 0); |
104 | |
|
105 | 0 | SetChecked( IsChecked() ); |
106 | 0 | SetIndeterminate( IsIndeterminate() ); |
107 | |
|
108 | 0 | const sal_Int32 nNewValue = m_bIndeterminate ? 2 : (m_bChecked ? 1 : 0); |
109 | 0 | if (nOldValue != nNewValue) |
110 | 0 | NotifyAccessibleEvent(AccessibleEventId::VALUE_CHANGED, Any(nOldValue), Any(nNewValue)); |
111 | 0 | } |
112 | 0 | break; |
113 | 0 | default: |
114 | 0 | VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent ); |
115 | 0 | } |
116 | 0 | } |
117 | | |
118 | | |
119 | | void VCLXAccessibleCheckBox::FillAccessibleStateSet( sal_Int64& rStateSet ) |
120 | 0 | { |
121 | 0 | VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet ); |
122 | |
|
123 | 0 | rStateSet |= AccessibleStateType::CHECKABLE; |
124 | 0 | rStateSet |= AccessibleStateType::FOCUSABLE; |
125 | |
|
126 | 0 | if ( IsChecked() ) |
127 | 0 | rStateSet |= AccessibleStateType::CHECKED; |
128 | |
|
129 | 0 | if ( IsIndeterminate() ) |
130 | 0 | rStateSet |= AccessibleStateType::INDETERMINATE; |
131 | 0 | } |
132 | | |
133 | | |
134 | | // XServiceInfo |
135 | | |
136 | | |
137 | | OUString VCLXAccessibleCheckBox::getImplementationName() |
138 | 0 | { |
139 | 0 | return u"com.sun.star.comp.toolkit.AccessibleCheckBox"_ustr; |
140 | 0 | } |
141 | | |
142 | | |
143 | | Sequence< OUString > VCLXAccessibleCheckBox::getSupportedServiceNames() |
144 | 0 | { |
145 | 0 | return { u"com.sun.star.awt.AccessibleCheckBox"_ustr }; |
146 | 0 | } |
147 | | |
148 | | // XAccessibleAction |
149 | | |
150 | | |
151 | | sal_Int32 VCLXAccessibleCheckBox::getAccessibleActionCount( ) |
152 | 0 | { |
153 | 0 | OExternalLockGuard aGuard( this ); |
154 | |
|
155 | 0 | return 1; |
156 | 0 | } |
157 | | |
158 | | |
159 | | sal_Bool VCLXAccessibleCheckBox::doAccessibleAction ( sal_Int32 nIndex ) |
160 | 0 | { |
161 | 0 | OExternalLockGuard aGuard( this ); |
162 | |
|
163 | 0 | if ( nIndex != 0 ) |
164 | 0 | throw IndexOutOfBoundsException(); |
165 | | |
166 | 0 | VclPtr<CheckBox> pCheckBox = GetAs<CheckBox>(); |
167 | 0 | if (pCheckBox) |
168 | 0 | { |
169 | 0 | sal_Int32 nValueMax = sal_Int32(1); |
170 | |
|
171 | 0 | if ( pCheckBox->IsTriStateEnabled() ) |
172 | 0 | nValueMax = sal_Int32(2); |
173 | |
|
174 | 0 | sal_Int32 nValue = static_cast<sal_Int32>(pCheckBox->GetState()); |
175 | |
|
176 | 0 | ++nValue; |
177 | |
|
178 | 0 | if ( nValue > nValueMax ) |
179 | 0 | nValue = 0; |
180 | |
|
181 | 0 | pCheckBox->SetState(static_cast<TriState>(nValue)); |
182 | 0 | } |
183 | |
|
184 | 0 | return true; |
185 | 0 | } |
186 | | |
187 | | |
188 | | OUString VCLXAccessibleCheckBox::getAccessibleActionDescription ( sal_Int32 nIndex ) |
189 | 0 | { |
190 | 0 | OExternalLockGuard aGuard( this ); |
191 | |
|
192 | 0 | if ( nIndex != 0 ) |
193 | 0 | throw IndexOutOfBoundsException(); |
194 | | |
195 | 0 | if(IsChecked()) |
196 | 0 | return VclResId( RID_STR_ACC_ACTION_UNCHECK ); |
197 | 0 | else |
198 | 0 | return VclResId( RID_STR_ACC_ACTION_CHECK ); |
199 | 0 | } |
200 | | |
201 | | |
202 | | Reference< XAccessibleKeyBinding > VCLXAccessibleCheckBox::getAccessibleActionKeyBinding( sal_Int32 nIndex ) |
203 | 0 | { |
204 | 0 | OExternalLockGuard aGuard( this ); |
205 | |
|
206 | 0 | if ( nIndex != 0 ) |
207 | 0 | throw IndexOutOfBoundsException(); |
208 | | |
209 | 0 | rtl::Reference<OAccessibleKeyBindingHelper> pKeyBindingHelper = new OAccessibleKeyBindingHelper(); |
210 | |
|
211 | 0 | VclPtr<vcl::Window> pWindow = GetWindow(); |
212 | 0 | if ( pWindow ) |
213 | 0 | { |
214 | 0 | KeyEvent aKeyEvent = pWindow->GetActivationKey(); |
215 | 0 | vcl::KeyCode aKeyCode = aKeyEvent.GetKeyCode(); |
216 | 0 | if ( aKeyCode.GetCode() != 0 ) |
217 | 0 | { |
218 | 0 | awt::KeyStroke aKeyStroke; |
219 | 0 | aKeyStroke.Modifiers = 0; |
220 | 0 | if ( aKeyCode.IsShift() ) |
221 | 0 | aKeyStroke.Modifiers |= awt::KeyModifier::SHIFT; |
222 | 0 | if ( aKeyCode.IsMod1() ) |
223 | 0 | aKeyStroke.Modifiers |= awt::KeyModifier::MOD1; |
224 | 0 | if ( aKeyCode.IsMod2() ) |
225 | 0 | aKeyStroke.Modifiers |= awt::KeyModifier::MOD2; |
226 | 0 | if ( aKeyCode.IsMod3() ) |
227 | 0 | aKeyStroke.Modifiers |= awt::KeyModifier::MOD3; |
228 | 0 | aKeyStroke.KeyCode = aKeyCode.GetCode(); |
229 | 0 | aKeyStroke.KeyChar = aKeyEvent.GetCharCode(); |
230 | 0 | aKeyStroke.KeyFunc = static_cast< sal_Int16 >( aKeyCode.GetFunction() ); |
231 | 0 | pKeyBindingHelper->AddKeyBinding( aKeyStroke ); |
232 | 0 | } |
233 | 0 | } |
234 | |
|
235 | 0 | return pKeyBindingHelper; |
236 | 0 | } |
237 | | |
238 | | |
239 | | // XAccessibleValue |
240 | | |
241 | | |
242 | | Any VCLXAccessibleCheckBox::getCurrentValue( ) |
243 | 0 | { |
244 | 0 | OExternalLockGuard aGuard( this ); |
245 | |
|
246 | 0 | Any aValue; |
247 | |
|
248 | 0 | VclPtr<CheckBox> pCheckBox = GetAs<CheckBox>(); |
249 | 0 | if (pCheckBox) |
250 | 0 | aValue <<= static_cast<sal_Int32>(pCheckBox->GetState()); |
251 | |
|
252 | 0 | return aValue; |
253 | 0 | } |
254 | | |
255 | | |
256 | | sal_Bool VCLXAccessibleCheckBox::setCurrentValue( const Any& aNumber ) |
257 | 0 | { |
258 | 0 | OExternalLockGuard aGuard( this ); |
259 | |
|
260 | 0 | bool bReturn = false; |
261 | |
|
262 | 0 | VclPtr<CheckBox> pCheckBox = GetAs<CheckBox>(); |
263 | 0 | if (pCheckBox) |
264 | 0 | { |
265 | 0 | sal_Int32 nValue = 0, nValueMin = 0, nValueMax = 0; |
266 | 0 | OSL_VERIFY( aNumber >>= nValue ); |
267 | 0 | nValueMax=implGetMaximumValue(); |
268 | |
|
269 | 0 | if ( nValue < nValueMin ) |
270 | 0 | nValue = nValueMin; |
271 | 0 | else if ( nValue > nValueMax ) |
272 | 0 | nValue = nValueMax; |
273 | |
|
274 | 0 | pCheckBox->SetState(static_cast<TriState>(nValue)); |
275 | 0 | bReturn = true; |
276 | 0 | } |
277 | |
|
278 | 0 | return bReturn; |
279 | 0 | } |
280 | | |
281 | | |
282 | | Any VCLXAccessibleCheckBox::getMaximumValue( ) |
283 | 0 | { |
284 | 0 | OExternalLockGuard aGuard( this ); |
285 | |
|
286 | 0 | Any aValue; |
287 | 0 | aValue <<= implGetMaximumValue(); |
288 | |
|
289 | 0 | return aValue; |
290 | 0 | } |
291 | | |
292 | | sal_Int32 VCLXAccessibleCheckBox::implGetMaximumValue( ) |
293 | 0 | { |
294 | 0 | VclPtr< CheckBox > pCheckBox = GetAs< CheckBox >(); |
295 | 0 | if ( pCheckBox && pCheckBox->IsTriStateEnabled() ) |
296 | 0 | return 2; |
297 | | |
298 | 0 | return 1; |
299 | 0 | } |
300 | | |
301 | | Any VCLXAccessibleCheckBox::getMinimumValue( ) |
302 | 0 | { |
303 | 0 | OExternalLockGuard aGuard( this ); |
304 | |
|
305 | 0 | Any aValue; |
306 | 0 | aValue <<= sal_Int32(0); |
307 | |
|
308 | 0 | return aValue; |
309 | 0 | } |
310 | | |
311 | | Any VCLXAccessibleCheckBox::getMinimumIncrement( ) |
312 | 0 | { |
313 | 0 | OExternalLockGuard aGuard( this ); |
314 | |
|
315 | 0 | Any aValue; |
316 | 0 | aValue <<= sal_Int32(1); |
317 | |
|
318 | 0 | return aValue; |
319 | 0 | } |
320 | | |
321 | | |
322 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |