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