tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / accessibility / source / standard / vclxaccessibleradiobutton.cxx
blob104be051a3ea1f3e68832c69a224f0bf9aca0610
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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:
52 Any aOldValue;
53 Any aNewValue;
55 VclPtr<RadioButton> pRadioButton = GetAs<RadioButton>();
56 if (pRadioButton && pRadioButton->IsChecked())
57 aNewValue <<= AccessibleStateType::CHECKED;
58 else
59 aOldValue <<= AccessibleStateType::CHECKED;
61 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
63 break;
64 default:
65 VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent );
70 void VCLXAccessibleRadioButton::FillAccessibleRelationSet( utl::AccessibleRelationSetHelper& rRelationSet )
72 VCLXAccessibleTextComponent::FillAccessibleRelationSet( rRelationSet );
74 VclPtr<RadioButton> pRadioButton = GetAs<RadioButton>();
75 if ( !pRadioButton )
76 return;
78 std::vector< VclPtr<RadioButton> > aGroup(pRadioButton->GetRadioButtonGroup());
79 if (!aGroup.empty())
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>();
96 if (pRadioButton)
98 rStateSet |= AccessibleStateType::CHECKABLE;
99 rStateSet |= AccessibleStateType::FOCUSABLE;
100 if (pRadioButton->IsChecked())
101 rStateSet |= AccessibleStateType::CHECKED;
106 // XServiceInfo
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 };
121 // XAccessibleAction
124 sal_Int32 VCLXAccessibleRadioButton::getAccessibleActionCount( )
126 OExternalLockGuard aGuard( this );
128 return 1;
132 sal_Bool VCLXAccessibleRadioButton::doAccessibleAction ( sal_Int32 nIndex )
134 OExternalLockGuard aGuard( this );
136 if ( nIndex != 0 )
137 throw IndexOutOfBoundsException();
139 VclPtr<RadioButton> pRadioButton = GetAs<RadioButton>();
140 if (pRadioButton && !pRadioButton->IsChecked())
141 pRadioButton->Check(true);
143 return true;
146 OUString VCLXAccessibleRadioButton::getAccessibleActionDescription ( sal_Int32 nIndex )
148 OExternalLockGuard aGuard( this );
150 if ( nIndex != 0 )
151 throw IndexOutOfBoundsException();
153 return RID_STR_ACC_ACTION_SELECT;
156 Reference< XAccessibleKeyBinding > VCLXAccessibleRadioButton::getAccessibleActionKeyBinding( sal_Int32 nIndex )
158 OExternalLockGuard aGuard( this );
160 if ( nIndex != 0 )
161 throw IndexOutOfBoundsException();
163 rtl::Reference<OAccessibleKeyBindingHelper> pKeyBindingHelper = new OAccessibleKeyBindingHelper();
165 VclPtr<vcl::Window> pWindow = GetWindow();
166 if ( pWindow )
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;
193 // XAccessibleValue
196 Any VCLXAccessibleRadioButton::getCurrentValue( )
198 OExternalLockGuard aGuard( this );
200 Any aValue;
202 VclPtr<RadioButton> pRadioButton = GetAs<RadioButton>();
203 if (pRadioButton)
204 aValue <<= static_cast<sal_Int32>(pRadioButton->IsChecked() ? 1 : 0);
206 return aValue;
210 sal_Bool VCLXAccessibleRadioButton::setCurrentValue( const Any& aNumber )
212 OExternalLockGuard aGuard( this );
214 bool bReturn = false;
216 VclPtr<RadioButton> pRadioButton = GetAs<RadioButton>();
217 if (pRadioButton)
219 sal_Int32 nValue = 0;
220 OSL_VERIFY( aNumber >>= nValue );
222 if ( nValue < 0 )
223 nValue = 0;
224 else if ( nValue > 1 )
225 nValue = 1;
227 pRadioButton->Check(nValue == 1);
228 bReturn = true;
231 return bReturn;
235 Any VCLXAccessibleRadioButton::getMaximumValue( )
237 OExternalLockGuard aGuard( this );
239 Any aValue;
240 aValue <<= sal_Int32(1);
242 return aValue;
246 Any VCLXAccessibleRadioButton::getMinimumValue( )
248 OExternalLockGuard aGuard( this );
250 Any aValue;
251 aValue <<= sal_Int32(0);
253 return aValue;
256 Any VCLXAccessibleRadioButton::getMinimumIncrement( )
258 OExternalLockGuard aGuard( this );
260 Any aValue;
261 aValue <<= sal_Int32(1);
263 return aValue;
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */