LibreOffice Module accessibility (master) 1
vclxaccessibleradiobutton.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
27#include <com/sun/star/awt/KeyModifier.hpp>
28#include <com/sun/star/accessibility/AccessibleRelationType.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#include <vcl/window.hxx>
34#include <vcl/event.hxx>
35#include <vcl/vclevent.hxx>
36#include <strings.hxx>
37
38using namespace ::com::sun::star;
39using namespace ::com::sun::star::uno;
40using namespace ::com::sun::star::lang;
41using namespace ::com::sun::star::beans;
42using namespace ::com::sun::star::accessibility;
43using namespace ::comphelper;
44
45
46// VCLXAccessibleRadioButton
47
48
50{
51 switch ( rVclWindowEvent.GetId() )
52 {
53 case VclEventId::RadiobuttonToggle:
54 {
55 Any aOldValue;
56 Any aNewValue;
57
58 VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() );
59 if ( pVCLXRadioButton && pVCLXRadioButton->getState() )
60 aNewValue <<= AccessibleStateType::CHECKED;
61 else
62 aOldValue <<= AccessibleStateType::CHECKED;
63
64 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
65 }
66 break;
67 default:
69 }
70}
71
72
74{
75 VCLXAccessibleTextComponent::FillAccessibleRelationSet( rRelationSet );
76
77 VclPtr< RadioButton > pRadioButton = GetAsDynamic< RadioButton >();
78 if ( !pRadioButton )
79 return;
80
81 std::vector< VclPtr<RadioButton> > aGroup(pRadioButton->GetRadioButtonGroup());
82 if (!aGroup.empty())
83 {
84 std::vector< Reference< XInterface > > aVec;
85 aVec.reserve(aGroup.size());
86 std::transform(aGroup.begin(), aGroup.end(), std::back_inserter(aVec),
87 [](const VclPtr<RadioButton>& rxItem) { return rxItem->GetAccessible(); });
88 rRelationSet.AddRelation( AccessibleRelation( AccessibleRelationType::MEMBER_OF,
90 }
91}
92
93
95{
96 VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet );
97
98 VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() );
99 if ( pVCLXRadioButton )
100 {
101 rStateSet |= AccessibleStateType::FOCUSABLE;
102 if ( pVCLXRadioButton->getState() )
103 rStateSet |= AccessibleStateType::CHECKED;
104 }
105}
106
107
108// XServiceInfo
109
110
112{
113 return "com.sun.star.comp.toolkit.AccessibleRadioButton";
114}
115
116
118{
119 return { "com.sun.star.awt.AccessibleRadioButton" };
120}
121
122
123// XAccessibleAction
124
125
127{
128 OExternalLockGuard aGuard( this );
129
130 return 1;
131}
132
133
135{
136 OExternalLockGuard aGuard( this );
137
138 if ( nIndex != 0 )
139 throw IndexOutOfBoundsException();
140
141 VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() );
142 if ( pVCLXRadioButton && !pVCLXRadioButton->getState() )
143 pVCLXRadioButton->setState( true );
144
145 return true;
146}
147
149{
150 OExternalLockGuard aGuard( this );
151
152 if ( nIndex != 0 )
153 throw IndexOutOfBoundsException();
154
156}
157
158Reference< XAccessibleKeyBinding > VCLXAccessibleRadioButton::getAccessibleActionKeyBinding( sal_Int32 nIndex )
159{
160 OExternalLockGuard aGuard( this );
161
162 if ( nIndex != 0 )
163 throw IndexOutOfBoundsException();
164
165 rtl::Reference<OAccessibleKeyBindingHelper> pKeyBindingHelper = new OAccessibleKeyBindingHelper();
166
167 VclPtr<vcl::Window> pWindow = GetWindow();
168 if ( pWindow )
169 {
170 KeyEvent aKeyEvent = pWindow->GetActivationKey();
171 vcl::KeyCode aKeyCode = aKeyEvent.GetKeyCode();
172 if ( aKeyCode.GetCode() != 0 )
173 {
174 awt::KeyStroke aKeyStroke;
175 aKeyStroke.Modifiers = 0;
176 if ( aKeyCode.IsShift() )
177 aKeyStroke.Modifiers |= awt::KeyModifier::SHIFT;
178 if ( aKeyCode.IsMod1() )
179 aKeyStroke.Modifiers |= awt::KeyModifier::MOD1;
180 if ( aKeyCode.IsMod2() )
181 aKeyStroke.Modifiers |= awt::KeyModifier::MOD2;
182 if ( aKeyCode.IsMod3() )
183 aKeyStroke.Modifiers |= awt::KeyModifier::MOD3;
184 aKeyStroke.KeyCode = aKeyCode.GetCode();
185 aKeyStroke.KeyChar = aKeyEvent.GetCharCode();
186 aKeyStroke.KeyFunc = static_cast< sal_Int16 >( aKeyCode.GetFunction() );
187 pKeyBindingHelper->AddKeyBinding( aKeyStroke );
188 }
189 }
190
191 return pKeyBindingHelper;
192}
193
194
195// XAccessibleValue
196
197
199{
200 OExternalLockGuard aGuard( this );
201
202 Any aValue;
203
204 VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() );
205 if ( pVCLXRadioButton )
206 aValue <<= static_cast<sal_Int32>(pVCLXRadioButton->getState());
207
208 return aValue;
209}
210
211
213{
214 OExternalLockGuard aGuard( this );
215
216 bool bReturn = false;
217
218 VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() );
219 if ( pVCLXRadioButton )
220 {
221 sal_Int32 nValue = 0;
222 OSL_VERIFY( aNumber >>= nValue );
223
224 if ( nValue < 0 )
225 nValue = 0;
226 else if ( nValue > 1 )
227 nValue = 1;
228
229 pVCLXRadioButton->setState( nValue == 1 );
230 bReturn = true;
231 }
232
233 return bReturn;
234}
235
236
238{
239 OExternalLockGuard aGuard( this );
240
241 Any aValue;
242 aValue <<= sal_Int32(1);
243
244 return aValue;
245}
246
247
249{
250 OExternalLockGuard aGuard( this );
251
252 Any aValue;
253 aValue <<= sal_Int32(0);
254
255 return aValue;
256}
257
259{
260 OExternalLockGuard aGuard( this );
261
262 Any aValue;
263 aValue <<= sal_Int32(1);
264
265 return aValue;
266}
267
268
269/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Unicode GetCharCode() const
const vcl::KeyCode & GetKeyCode() const
virtual OUString SAL_CALL getAccessibleActionDescription(sal_Int32 nIndex) override
virtual css::uno::Any SAL_CALL getMaximumValue() override
virtual void ProcessWindowEvent(const VclWindowEvent &rVclWindowEvent) override
virtual void FillAccessibleStateSet(sal_Int64 &rStateSet) override
virtual css::uno::Any SAL_CALL getCurrentValue() override
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL setCurrentValue(const css::uno::Any &aNumber) override
virtual css::uno::Any SAL_CALL getMinimumIncrement() override
virtual sal_Int32 SAL_CALL getAccessibleActionCount() override
virtual sal_Bool SAL_CALL doAccessibleAction(sal_Int32 nIndex) override
virtual css::uno::Reference< css::accessibility::XAccessibleKeyBinding > SAL_CALL getAccessibleActionKeyBinding(sal_Int32 nIndex) override
virtual css::uno::Any SAL_CALL getMinimumValue() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void FillAccessibleRelationSet(utl::AccessibleRelationSetHelper &rRelationSet) override
virtual void ProcessWindowEvent(const VclWindowEvent &rVclWindowEvent) override
void SAL_CALL setState(sal_Bool b) override
sal_Bool SAL_CALL getState() override
VclEventId GetId() const
void AddRelation(const css::accessibility::AccessibleRelation &rRelation)
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
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
constexpr OUStringLiteral RID_STR_ACC_ACTION_SELECT
Definition: strings.hxx:16
unsigned char sal_Bool