1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <standard/vclxaccessibleradiobutton.hxx>
22 #include <toolkit/awt/vclxwindows.hxx>
24 #include <unotools/accessiblerelationsethelper.hxx>
25 #include <comphelper/accessiblecontexthelper.hxx>
26 #include <comphelper/accessiblekeybindinghelper.hxx>
27 #include <comphelper/sequence.hxx>
28 #include <com/sun/star/awt/KeyModifier.hpp>
29 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
30 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
31 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
32 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
33 #include <vcl/window.hxx>
34 #include <vcl/toolkit/button.hxx>
35 #include <vcl/event.hxx>
36 #include <vcl/vclevent.hxx>
37 #include <strings.hxx>
39 using namespace ::com::sun::star
;
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::lang
;
42 using namespace ::com::sun::star::accessibility
;
43 using namespace ::comphelper
;
46 // VCLXAccessibleRadioButton
49 void VCLXAccessibleRadioButton::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
51 switch ( rVclWindowEvent
.GetId() )
53 case VclEventId::RadiobuttonToggle
:
58 VCLXRadioButton
* pVCLXRadioButton
= static_cast< VCLXRadioButton
* >( GetVCLXWindow() );
59 if ( pVCLXRadioButton
&& pVCLXRadioButton
->getState() )
60 aNewValue
<<= AccessibleStateType::CHECKED
;
62 aOldValue
<<= AccessibleStateType::CHECKED
;
64 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
68 VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent
);
73 void VCLXAccessibleRadioButton::FillAccessibleRelationSet( utl::AccessibleRelationSetHelper
& rRelationSet
)
75 VCLXAccessibleTextComponent::FillAccessibleRelationSet( rRelationSet
);
77 VclPtr
< RadioButton
> pRadioButton
= GetAsDynamic
< RadioButton
>();
81 std::vector
< VclPtr
<RadioButton
> > aGroup(pRadioButton
->GetRadioButtonGroup());
84 std::vector
<Reference
<css::accessibility::XAccessible
>> 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
,
89 comphelper::containerToSequence(aVec
)));
94 void VCLXAccessibleRadioButton::FillAccessibleStateSet( sal_Int64
& rStateSet
)
96 VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet
);
98 VCLXRadioButton
* pVCLXRadioButton
= static_cast< VCLXRadioButton
* >( GetVCLXWindow() );
99 if ( pVCLXRadioButton
)
101 rStateSet
|= AccessibleStateType::CHECKABLE
;
102 rStateSet
|= AccessibleStateType::FOCUSABLE
;
103 if ( pVCLXRadioButton
->getState() )
104 rStateSet
|= AccessibleStateType::CHECKED
;
112 OUString
VCLXAccessibleRadioButton::getImplementationName()
114 return u
"com.sun.star.comp.toolkit.AccessibleRadioButton"_ustr
;
118 Sequence
< OUString
> VCLXAccessibleRadioButton::getSupportedServiceNames()
120 return { u
"com.sun.star.awt.AccessibleRadioButton"_ustr
};
127 sal_Int32
VCLXAccessibleRadioButton::getAccessibleActionCount( )
129 OExternalLockGuard
aGuard( this );
135 sal_Bool
VCLXAccessibleRadioButton::doAccessibleAction ( sal_Int32 nIndex
)
137 OExternalLockGuard
aGuard( this );
140 throw IndexOutOfBoundsException();
142 VCLXRadioButton
* pVCLXRadioButton
= static_cast< VCLXRadioButton
* >( GetVCLXWindow() );
143 if ( pVCLXRadioButton
&& !pVCLXRadioButton
->getState() )
144 pVCLXRadioButton
->setState( true );
149 OUString
VCLXAccessibleRadioButton::getAccessibleActionDescription ( sal_Int32 nIndex
)
151 OExternalLockGuard
aGuard( this );
154 throw IndexOutOfBoundsException();
156 return RID_STR_ACC_ACTION_SELECT
;
159 Reference
< XAccessibleKeyBinding
> VCLXAccessibleRadioButton::getAccessibleActionKeyBinding( sal_Int32 nIndex
)
161 OExternalLockGuard
aGuard( this );
164 throw IndexOutOfBoundsException();
166 rtl::Reference
<OAccessibleKeyBindingHelper
> pKeyBindingHelper
= new OAccessibleKeyBindingHelper();
168 VclPtr
<vcl::Window
> pWindow
= GetWindow();
171 KeyEvent aKeyEvent
= pWindow
->GetActivationKey();
172 vcl::KeyCode aKeyCode
= aKeyEvent
.GetKeyCode();
173 if ( aKeyCode
.GetCode() != 0 )
175 awt::KeyStroke aKeyStroke
;
176 aKeyStroke
.Modifiers
= 0;
177 if ( aKeyCode
.IsShift() )
178 aKeyStroke
.Modifiers
|= awt::KeyModifier::SHIFT
;
179 if ( aKeyCode
.IsMod1() )
180 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD1
;
181 if ( aKeyCode
.IsMod2() )
182 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD2
;
183 if ( aKeyCode
.IsMod3() )
184 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD3
;
185 aKeyStroke
.KeyCode
= aKeyCode
.GetCode();
186 aKeyStroke
.KeyChar
= aKeyEvent
.GetCharCode();
187 aKeyStroke
.KeyFunc
= static_cast< sal_Int16
>( aKeyCode
.GetFunction() );
188 pKeyBindingHelper
->AddKeyBinding( aKeyStroke
);
192 return pKeyBindingHelper
;
199 Any
VCLXAccessibleRadioButton::getCurrentValue( )
201 OExternalLockGuard
aGuard( this );
205 VCLXRadioButton
* pVCLXRadioButton
= static_cast< VCLXRadioButton
* >( GetVCLXWindow() );
206 if ( pVCLXRadioButton
)
207 aValue
<<= static_cast<sal_Int32
>(pVCLXRadioButton
->getState());
213 sal_Bool
VCLXAccessibleRadioButton::setCurrentValue( const Any
& aNumber
)
215 OExternalLockGuard
aGuard( this );
217 bool bReturn
= false;
219 VCLXRadioButton
* pVCLXRadioButton
= static_cast< VCLXRadioButton
* >( GetVCLXWindow() );
220 if ( pVCLXRadioButton
)
222 sal_Int32 nValue
= 0;
223 OSL_VERIFY( aNumber
>>= nValue
);
227 else if ( nValue
> 1 )
230 pVCLXRadioButton
->setState( nValue
== 1 );
238 Any
VCLXAccessibleRadioButton::getMaximumValue( )
240 OExternalLockGuard
aGuard( this );
243 aValue
<<= sal_Int32(1);
249 Any
VCLXAccessibleRadioButton::getMinimumValue( )
251 OExternalLockGuard
aGuard( this );
254 aValue
<<= sal_Int32(0);
259 Any
VCLXAccessibleRadioButton::getMinimumIncrement( )
261 OExternalLockGuard
aGuard( this );
264 aValue
<<= sal_Int32(1);
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */