LibreOffice Module accessibility (master) 1
vclxaccessiblebutton.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#include <helper/accresmgr.hxx>
22#include <strings.hrc>
23
26#include <com/sun/star/awt/KeyModifier.hpp>
27#include <com/sun/star/accessibility/AccessibleStateType.hpp>
28#include <com/sun/star/accessibility/AccessibleEventId.hpp>
29#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
30#include <strings.hxx>
31
33#include <vcl/event.hxx>
34#include <vcl/vclevent.hxx>
35
36using namespace ::com::sun::star;
37using namespace ::com::sun::star::uno;
38using namespace ::com::sun::star::lang;
39using namespace ::com::sun::star::beans;
40using namespace ::com::sun::star::accessibility;
41using namespace ::comphelper;
42
43
44// VCLXAccessibleButton
45
46
48{
49 switch ( rVclWindowEvent.GetId() )
50 {
51 case VclEventId::PushbuttonToggle:
52 {
53 Any aOldValue;
54 Any aNewValue;
55
56 VclPtr< PushButton > pButton = GetAs< PushButton >();
57 if ( pButton && pButton->GetState() == TRISTATE_TRUE )
58 aNewValue <<= AccessibleStateType::CHECKED;
59 else
60 aOldValue <<= AccessibleStateType::CHECKED;
61
62 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
63 }
64 break;
65 default:
67 }
68}
69
70
72{
73 VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet );
74
75 VclPtr< PushButton > pButton = GetAs< PushButton >();
76 if ( !pButton )
77 return;
78
79 rStateSet |= AccessibleStateType::FOCUSABLE;
80
81 if ( pButton->GetState() == TRISTATE_TRUE )
82 rStateSet |= AccessibleStateType::CHECKED;
83
84 if ( pButton->IsPressed() )
85 rStateSet |= AccessibleStateType::PRESSED;
86
87 // IA2 CWS: if the button has a popup menu, it should has the state EXPANDABLE
88 if( pButton->GetType() == WindowType::MENUBUTTON )
89 {
90 rStateSet |= AccessibleStateType::EXPANDABLE;
91 }
92 if( pButton->GetStyle() & WB_DEFBUTTON )
93 {
94 rStateSet |= AccessibleStateType::DEFAULT;
95 }
96}
97
98
99// XServiceInfo
100
101
103{
104 return "com.sun.star.comp.toolkit.AccessibleButton";
105}
106
107
109{
110 return { "com.sun.star.awt.AccessibleButton" };
111}
112
113
114// XAccessibleContext
115
116
118{
119 OUString aName( VCLXAccessibleTextComponent::getAccessibleName() );
120 sal_Int32 nLength = aName.getLength();
121
122 if ( nLength >= 3 && aName.match( "...", nLength - 3 ) )
123 {
124 if ( nLength == 3 )
125 {
126 // it's a browse button
127 aName = AccResId( RID_STR_ACC_NAME_BROWSEBUTTON );
128 }
129 else
130 {
131 // remove the three trailing dots
132 aName = aName.copy( 0, nLength - 3 );
133 }
134 }
135 else if ( nLength >= 3 && aName.match( "<< ", 0 ) )
136 {
137 // remove the leading symbols
138 aName = aName.copy( 3, nLength - 3 );
139 }
140 else if ( nLength >= 3 && aName.match( " >>", nLength - 3 ) )
141 {
142 // remove the trailing symbols
143 aName = aName.copy( 0, nLength - 3 );
144 }
145
146 return aName;
147}
148
149
150// XAccessibleAction
151
152
154{
155 OExternalLockGuard aGuard( this );
156
157 return 1;
158}
159
160
162{
163 OExternalLockGuard aGuard( this );
164
165 if ( nIndex != 0 )
166 throw IndexOutOfBoundsException();
167
168 VclPtr< PushButton > pButton = GetAs< PushButton >();
169 if ( pButton )
170 pButton->Click();
171
172 return true;
173}
174
175
177{
178 OExternalLockGuard aGuard( this );
179
180 if ( nIndex != 0 )
181 throw IndexOutOfBoundsException();
182
184}
185
186
187Reference< XAccessibleKeyBinding > VCLXAccessibleButton::getAccessibleActionKeyBinding( sal_Int32 nIndex )
188{
189 OExternalLockGuard aGuard( this );
190
191 if ( nIndex != 0 )
192 throw IndexOutOfBoundsException();
193
194 rtl::Reference<OAccessibleKeyBindingHelper> pKeyBindingHelper = new OAccessibleKeyBindingHelper();
195
196 VclPtr<vcl::Window> pWindow = GetWindow();
197 if ( pWindow )
198 {
199 KeyEvent aKeyEvent = pWindow->GetActivationKey();
200 vcl::KeyCode aKeyCode = aKeyEvent.GetKeyCode();
201 if ( aKeyCode.GetCode() != 0 )
202 {
203 awt::KeyStroke aKeyStroke;
204 aKeyStroke.Modifiers = 0;
205 if ( aKeyCode.IsShift() )
206 aKeyStroke.Modifiers |= awt::KeyModifier::SHIFT;
207 if ( aKeyCode.IsMod1() )
208 aKeyStroke.Modifiers |= awt::KeyModifier::MOD1;
209 if ( aKeyCode.IsMod2() )
210 aKeyStroke.Modifiers |= awt::KeyModifier::MOD2;
211 if ( aKeyCode.IsMod3() )
212 aKeyStroke.Modifiers |= awt::KeyModifier::MOD3;
213 aKeyStroke.KeyCode = aKeyCode.GetCode();
214 aKeyStroke.KeyChar = aKeyEvent.GetCharCode();
215 aKeyStroke.KeyFunc = static_cast< sal_Int16 >( aKeyCode.GetFunction() );
216 pKeyBindingHelper->AddKeyBinding( aKeyStroke );
217 }
218 }
219
220 return pKeyBindingHelper;
221}
222
223
224// XAccessibleValue
225
226
228{
229 OExternalLockGuard aGuard( this );
230
231 Any aValue;
232
233 VclPtr< PushButton > pButton = GetAs< PushButton >();
234 if ( pButton )
235 aValue <<= static_cast<sal_Int32>(pButton->IsPressed());
236
237 return aValue;
238}
239
240
242{
243 OExternalLockGuard aGuard( this );
244
245 bool bReturn = false;
246
247 VclPtr< PushButton > pButton = GetAs< PushButton >();
248 if ( pButton )
249 {
250 sal_Int32 nValue = 0;
251 OSL_VERIFY( aNumber >>= nValue );
252
253 if ( nValue < 0 )
254 nValue = 0;
255 else if ( nValue > 1 )
256 nValue = 1;
257
258 pButton->SetPressed( nValue == 1 );
259 bReturn = true;
260 }
261
262 return bReturn;
263}
264
265
267{
268 OExternalLockGuard aGuard( this );
269
270 Any aValue;
271 aValue <<= sal_Int32(1);
272
273 return aValue;
274}
275
276
278{
279 OExternalLockGuard aGuard( this );
280
281 Any aValue;
282 aValue <<= sal_Int32(0);
283
284 return aValue;
285}
286
288{
289 OExternalLockGuard aGuard( this );
290
291 Any aValue;
292 aValue <<= sal_Int32(1);
293
294 return aValue;
295}
296
297
298/* 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 css::uno::Any SAL_CALL getMinimumIncrement() override
virtual css::uno::Any SAL_CALL getMaximumValue() override
virtual OUString SAL_CALL getAccessibleName() override
virtual void ProcessWindowEvent(const VclWindowEvent &rVclWindowEvent) override
virtual css::uno::Any SAL_CALL getMinimumValue() override
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL doAccessibleAction(sal_Int32 nIndex) override
virtual OUString SAL_CALL getAccessibleActionDescription(sal_Int32 nIndex) override
virtual sal_Int32 SAL_CALL getAccessibleActionCount() override
virtual sal_Bool SAL_CALL setCurrentValue(const css::uno::Any &aNumber) override
virtual css::uno::Any SAL_CALL getCurrentValue() override
virtual css::uno::Reference< css::accessibility::XAccessibleKeyBinding > SAL_CALL getAccessibleActionKeyBinding(sal_Int32 nIndex) override
virtual void FillAccessibleStateSet(sal_Int64 &rStateSet) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void ProcessWindowEvent(const VclWindowEvent &rVclWindowEvent) 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
TRISTATE_TRUE
sal_Int32 nIndex
OUString aName
constexpr OUStringLiteral RID_STR_ACC_ACTION_CLICK
Definition: strings.hxx:14
unsigned char sal_Bool
WinBits const WB_DEFBUTTON
sal_Int32 nLength