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 <unotools/accessiblerelationsethelper.hxx>
23 #include <comphelper/accessiblecontexthelper.hxx>
24 #include <comphelper/accessiblekeybindinghelper.hxx>
25 #include <comphelper/sequence.hxx>
26 #include <com/sun/star/awt/KeyModifier.hpp>
27 #include <com/sun/star/accessibility/AccessibleRelationType.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 #include <vcl/accessibility/strings.hxx>
32 #include <vcl/window.hxx>
33 #include <vcl/event.hxx>
34 #include <vcl/vclevent.hxx>
36 using namespace ::com::sun::star
;
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::lang
;
39 using namespace ::com::sun::star::accessibility
;
40 using namespace ::comphelper
;
43 // VCLXAccessibleRadioButton
46 void VCLXAccessibleRadioButton::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
48 switch ( rVclWindowEvent
.GetId() )
50 case VclEventId::RadiobuttonToggle
:
55 VclPtr
<RadioButton
> pRadioButton
= GetAs
<RadioButton
>();
56 if (pRadioButton
&& pRadioButton
->IsChecked())
57 aNewValue
<<= AccessibleStateType::CHECKED
;
59 aOldValue
<<= AccessibleStateType::CHECKED
;
61 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
65 VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent
);
70 void VCLXAccessibleRadioButton::FillAccessibleRelationSet( utl::AccessibleRelationSetHelper
& rRelationSet
)
72 VCLXAccessibleTextComponent::FillAccessibleRelationSet( rRelationSet
);
74 VclPtr
<RadioButton
> pRadioButton
= GetAs
<RadioButton
>();
78 std::vector
< VclPtr
<RadioButton
> > aGroup(pRadioButton
->GetRadioButtonGroup());
81 std::vector
<Reference
<css::accessibility::XAccessible
>> aVec
;
82 aVec
.reserve(aGroup
.size());
83 std::transform(aGroup
.begin(), aGroup
.end(), std::back_inserter(aVec
),
84 [](const VclPtr
<RadioButton
>& rxItem
) { return rxItem
->GetAccessible(); });
85 rRelationSet
.AddRelation(AccessibleRelation(AccessibleRelationType_MEMBER_OF
,
86 comphelper::containerToSequence(aVec
)));
91 void VCLXAccessibleRadioButton::FillAccessibleStateSet( sal_Int64
& rStateSet
)
93 VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet
);
95 VclPtr
<RadioButton
> pRadioButton
= GetAs
<RadioButton
>();
98 rStateSet
|= AccessibleStateType::CHECKABLE
;
99 rStateSet
|= AccessibleStateType::FOCUSABLE
;
100 if (pRadioButton
->IsChecked())
101 rStateSet
|= AccessibleStateType::CHECKED
;
109 OUString
VCLXAccessibleRadioButton::getImplementationName()
111 return u
"com.sun.star.comp.toolkit.AccessibleRadioButton"_ustr
;
115 Sequence
< OUString
> VCLXAccessibleRadioButton::getSupportedServiceNames()
117 return { u
"com.sun.star.awt.AccessibleRadioButton"_ustr
};
124 sal_Int32
VCLXAccessibleRadioButton::getAccessibleActionCount( )
126 OExternalLockGuard
aGuard( this );
132 sal_Bool
VCLXAccessibleRadioButton::doAccessibleAction ( sal_Int32 nIndex
)
134 OExternalLockGuard
aGuard( this );
137 throw IndexOutOfBoundsException();
139 VclPtr
<RadioButton
> pRadioButton
= GetAs
<RadioButton
>();
140 if (pRadioButton
&& !pRadioButton
->IsChecked())
141 pRadioButton
->Check(true);
146 OUString
VCLXAccessibleRadioButton::getAccessibleActionDescription ( sal_Int32 nIndex
)
148 OExternalLockGuard
aGuard( this );
151 throw IndexOutOfBoundsException();
153 return RID_STR_ACC_ACTION_SELECT
;
156 Reference
< XAccessibleKeyBinding
> VCLXAccessibleRadioButton::getAccessibleActionKeyBinding( sal_Int32 nIndex
)
158 OExternalLockGuard
aGuard( this );
161 throw IndexOutOfBoundsException();
163 rtl::Reference
<OAccessibleKeyBindingHelper
> pKeyBindingHelper
= new OAccessibleKeyBindingHelper();
165 VclPtr
<vcl::Window
> pWindow
= GetWindow();
168 KeyEvent aKeyEvent
= pWindow
->GetActivationKey();
169 vcl::KeyCode aKeyCode
= aKeyEvent
.GetKeyCode();
170 if ( aKeyCode
.GetCode() != 0 )
172 awt::KeyStroke aKeyStroke
;
173 aKeyStroke
.Modifiers
= 0;
174 if ( aKeyCode
.IsShift() )
175 aKeyStroke
.Modifiers
|= awt::KeyModifier::SHIFT
;
176 if ( aKeyCode
.IsMod1() )
177 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD1
;
178 if ( aKeyCode
.IsMod2() )
179 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD2
;
180 if ( aKeyCode
.IsMod3() )
181 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD3
;
182 aKeyStroke
.KeyCode
= aKeyCode
.GetCode();
183 aKeyStroke
.KeyChar
= aKeyEvent
.GetCharCode();
184 aKeyStroke
.KeyFunc
= static_cast< sal_Int16
>( aKeyCode
.GetFunction() );
185 pKeyBindingHelper
->AddKeyBinding( aKeyStroke
);
189 return pKeyBindingHelper
;
196 Any
VCLXAccessibleRadioButton::getCurrentValue( )
198 OExternalLockGuard
aGuard( this );
202 VclPtr
<RadioButton
> pRadioButton
= GetAs
<RadioButton
>();
204 aValue
<<= static_cast<sal_Int32
>(pRadioButton
->IsChecked() ? 1 : 0);
210 sal_Bool
VCLXAccessibleRadioButton::setCurrentValue( const Any
& aNumber
)
212 OExternalLockGuard
aGuard( this );
214 bool bReturn
= false;
216 VclPtr
<RadioButton
> pRadioButton
= GetAs
<RadioButton
>();
219 sal_Int32 nValue
= 0;
220 OSL_VERIFY( aNumber
>>= nValue
);
224 else if ( nValue
> 1 )
227 pRadioButton
->Check(nValue
== 1);
235 Any
VCLXAccessibleRadioButton::getMaximumValue( )
237 OExternalLockGuard
aGuard( this );
240 aValue
<<= sal_Int32(1);
246 Any
VCLXAccessibleRadioButton::getMinimumValue( )
248 OExternalLockGuard
aGuard( this );
251 aValue
<<= sal_Int32(0);
256 Any
VCLXAccessibleRadioButton::getMinimumIncrement( )
258 OExternalLockGuard
aGuard( this );
261 aValue
<<= sal_Int32(1);
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */