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 <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>
33 #include <vcl/toolkit/button.hxx>
34 #include <vcl/event.hxx>
35 #include <vcl/vclevent.hxx>
36 #include <strings.hxx>
38 using namespace ::com::sun::star
;
39 using namespace ::com::sun::star::uno
;
40 using namespace ::com::sun::star::lang
;
41 using namespace ::com::sun::star::beans
;
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
< 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
,
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::FOCUSABLE
;
102 if ( pVCLXRadioButton
->getState() )
103 rStateSet
|= AccessibleStateType::CHECKED
;
111 OUString
VCLXAccessibleRadioButton::getImplementationName()
113 return "com.sun.star.comp.toolkit.AccessibleRadioButton";
117 Sequence
< OUString
> VCLXAccessibleRadioButton::getSupportedServiceNames()
119 return { "com.sun.star.awt.AccessibleRadioButton" };
126 sal_Int32
VCLXAccessibleRadioButton::getAccessibleActionCount( )
128 OExternalLockGuard
aGuard( this );
134 sal_Bool
VCLXAccessibleRadioButton::doAccessibleAction ( sal_Int32 nIndex
)
136 OExternalLockGuard
aGuard( this );
139 throw IndexOutOfBoundsException();
141 VCLXRadioButton
* pVCLXRadioButton
= static_cast< VCLXRadioButton
* >( GetVCLXWindow() );
142 if ( pVCLXRadioButton
&& !pVCLXRadioButton
->getState() )
143 pVCLXRadioButton
->setState( true );
148 OUString
VCLXAccessibleRadioButton::getAccessibleActionDescription ( sal_Int32 nIndex
)
150 OExternalLockGuard
aGuard( this );
153 throw IndexOutOfBoundsException();
155 return RID_STR_ACC_ACTION_SELECT
;
158 Reference
< XAccessibleKeyBinding
> VCLXAccessibleRadioButton::getAccessibleActionKeyBinding( sal_Int32 nIndex
)
160 OExternalLockGuard
aGuard( this );
163 throw IndexOutOfBoundsException();
165 rtl::Reference
<OAccessibleKeyBindingHelper
> pKeyBindingHelper
= new OAccessibleKeyBindingHelper();
167 VclPtr
<vcl::Window
> pWindow
= GetWindow();
170 KeyEvent aKeyEvent
= pWindow
->GetActivationKey();
171 vcl::KeyCode aKeyCode
= aKeyEvent
.GetKeyCode();
172 if ( aKeyCode
.GetCode() != 0 )
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
);
191 return pKeyBindingHelper
;
198 Any
VCLXAccessibleRadioButton::getCurrentValue( )
200 OExternalLockGuard
aGuard( this );
204 VCLXRadioButton
* pVCLXRadioButton
= static_cast< VCLXRadioButton
* >( GetVCLXWindow() );
205 if ( pVCLXRadioButton
)
206 aValue
<<= static_cast<sal_Int32
>(pVCLXRadioButton
->getState());
212 sal_Bool
VCLXAccessibleRadioButton::setCurrentValue( const Any
& aNumber
)
214 OExternalLockGuard
aGuard( this );
216 bool bReturn
= false;
218 VCLXRadioButton
* pVCLXRadioButton
= static_cast< VCLXRadioButton
* >( GetVCLXWindow() );
219 if ( pVCLXRadioButton
)
221 sal_Int32 nValue
= 0;
222 OSL_VERIFY( aNumber
>>= nValue
);
226 else if ( nValue
> 1 )
229 pVCLXRadioButton
->setState( nValue
== 1 );
237 Any
VCLXAccessibleRadioButton::getMaximumValue( )
239 OExternalLockGuard
aGuard( this );
242 aValue
<<= sal_Int32(1);
248 Any
VCLXAccessibleRadioButton::getMinimumValue( )
250 OExternalLockGuard
aGuard( this );
253 aValue
<<= sal_Int32(0);
258 Any
VCLXAccessibleRadioButton::getMinimumIncrement( )
260 OExternalLockGuard
aGuard( this );
263 aValue
<<= sal_Int32(1);
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */