CppunitTest_sc_tiledrendering2: move to tiledrendering folder
[LibreOffice.git] / accessibility / source / standard / vclxaccessiblecheckbox.cxx
blob46c3e8749e9230a068e8da609625fe1430529628
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/vclxaccessiblecheckbox.hxx>
22 #include <toolkit/awt/vclxwindows.hxx>
23 #include <helper/accresmgr.hxx>
24 #include <strings.hrc>
26 #include <comphelper/accessiblecontexthelper.hxx>
27 #include <comphelper/accessiblekeybindinghelper.hxx>
28 #include <com/sun/star/awt/KeyModifier.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>
33 #include <vcl/toolkit/button.hxx>
34 #include <vcl/event.hxx>
35 #include <vcl/vclevent.hxx>
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::lang;
40 using namespace ::com::sun::star::accessibility;
41 using namespace ::comphelper;
44 // VCLXAccessibleCheckBox
47 VCLXAccessibleCheckBox::VCLXAccessibleCheckBox( VCLXWindow* pVCLWindow )
48 :ImplInheritanceHelper( pVCLWindow )
50 m_bChecked = IsChecked();
51 m_bIndeterminate = IsIndeterminate();
55 bool VCLXAccessibleCheckBox::IsChecked() const
57 bool bChecked = false;
59 VCLXCheckBox* pVCLXCheckBox = static_cast< VCLXCheckBox* >( GetVCLXWindow() );
60 if ( pVCLXCheckBox && pVCLXCheckBox->getState() == sal_Int16(1) )
61 bChecked = true;
63 return bChecked;
67 bool VCLXAccessibleCheckBox::IsIndeterminate() const
69 bool bIndeterminate = false;
71 VCLXCheckBox* pVCLXCheckBox = static_cast< VCLXCheckBox* >( GetVCLXWindow() );
72 if ( pVCLXCheckBox && pVCLXCheckBox->getState() == sal_Int16(2) )
73 bIndeterminate = true;
75 return bIndeterminate;
79 void VCLXAccessibleCheckBox::SetChecked( bool bChecked )
81 if ( m_bChecked != bChecked )
83 Any aOldValue, aNewValue;
84 if ( m_bChecked )
85 aOldValue <<= AccessibleStateType::CHECKED;
86 else
87 aNewValue <<= AccessibleStateType::CHECKED;
88 m_bChecked = bChecked;
89 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
94 void VCLXAccessibleCheckBox::SetIndeterminate( bool bIndeterminate )
96 if ( m_bIndeterminate != bIndeterminate )
98 Any aOldValue, aNewValue;
99 if ( m_bIndeterminate )
100 aOldValue <<= AccessibleStateType::INDETERMINATE;
101 else
102 aNewValue <<= AccessibleStateType::INDETERMINATE;
103 m_bIndeterminate = bIndeterminate;
104 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
109 void VCLXAccessibleCheckBox::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
111 switch ( rVclWindowEvent.GetId() )
113 case VclEventId::CheckboxToggle:
115 const sal_Int32 nOldValue = m_bIndeterminate ? 2 : (m_bChecked ? 1 : 0);
117 SetChecked( IsChecked() );
118 SetIndeterminate( IsIndeterminate() );
120 const sal_Int32 nNewValue = m_bIndeterminate ? 2 : (m_bChecked ? 1 : 0);
121 if (nOldValue != nNewValue)
122 NotifyAccessibleEvent(AccessibleEventId::VALUE_CHANGED, Any(nOldValue), Any(nNewValue));
124 break;
125 default:
126 VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent );
131 void VCLXAccessibleCheckBox::FillAccessibleStateSet( sal_Int64& rStateSet )
133 VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet );
135 rStateSet |= AccessibleStateType::CHECKABLE;
136 rStateSet |= AccessibleStateType::FOCUSABLE;
138 if ( IsChecked() )
139 rStateSet |= AccessibleStateType::CHECKED;
141 if ( IsIndeterminate() )
142 rStateSet |= AccessibleStateType::INDETERMINATE;
146 // XServiceInfo
149 OUString VCLXAccessibleCheckBox::getImplementationName()
151 return u"com.sun.star.comp.toolkit.AccessibleCheckBox"_ustr;
155 Sequence< OUString > VCLXAccessibleCheckBox::getSupportedServiceNames()
157 return { u"com.sun.star.awt.AccessibleCheckBox"_ustr };
161 // XAccessibleAction
164 sal_Int32 VCLXAccessibleCheckBox::getAccessibleActionCount( )
166 OExternalLockGuard aGuard( this );
168 return 1;
172 sal_Bool VCLXAccessibleCheckBox::doAccessibleAction ( sal_Int32 nIndex )
174 OExternalLockGuard aGuard( this );
176 if ( nIndex != 0 )
177 throw IndexOutOfBoundsException();
179 VclPtr< CheckBox > pCheckBox = GetAs< CheckBox >();
180 VCLXCheckBox* pVCLXCheckBox = static_cast< VCLXCheckBox* >( GetVCLXWindow() );
181 if ( pCheckBox && pVCLXCheckBox )
183 sal_Int32 nValueMax = sal_Int32(1);
185 if ( pCheckBox->IsTriStateEnabled() )
186 nValueMax = sal_Int32(2);
188 sal_Int32 nValue = static_cast<sal_Int32>(pVCLXCheckBox->getState());
190 ++nValue;
192 if ( nValue > nValueMax )
193 nValue = 0;
195 pVCLXCheckBox->setState( static_cast<sal_Int16>(nValue) );
198 return true;
202 OUString VCLXAccessibleCheckBox::getAccessibleActionDescription ( sal_Int32 nIndex )
204 OExternalLockGuard aGuard( this );
206 if ( nIndex != 0 )
207 throw IndexOutOfBoundsException();
209 if(IsChecked())
210 return AccResId( RID_STR_ACC_ACTION_UNCHECK );
211 else
212 return AccResId( RID_STR_ACC_ACTION_CHECK );
216 Reference< XAccessibleKeyBinding > VCLXAccessibleCheckBox::getAccessibleActionKeyBinding( sal_Int32 nIndex )
218 OExternalLockGuard aGuard( this );
220 if ( nIndex != 0 )
221 throw IndexOutOfBoundsException();
223 rtl::Reference<OAccessibleKeyBindingHelper> pKeyBindingHelper = new OAccessibleKeyBindingHelper();
225 VclPtr<vcl::Window> pWindow = GetWindow();
226 if ( pWindow )
228 KeyEvent aKeyEvent = pWindow->GetActivationKey();
229 vcl::KeyCode aKeyCode = aKeyEvent.GetKeyCode();
230 if ( aKeyCode.GetCode() != 0 )
232 awt::KeyStroke aKeyStroke;
233 aKeyStroke.Modifiers = 0;
234 if ( aKeyCode.IsShift() )
235 aKeyStroke.Modifiers |= awt::KeyModifier::SHIFT;
236 if ( aKeyCode.IsMod1() )
237 aKeyStroke.Modifiers |= awt::KeyModifier::MOD1;
238 if ( aKeyCode.IsMod2() )
239 aKeyStroke.Modifiers |= awt::KeyModifier::MOD2;
240 if ( aKeyCode.IsMod3() )
241 aKeyStroke.Modifiers |= awt::KeyModifier::MOD3;
242 aKeyStroke.KeyCode = aKeyCode.GetCode();
243 aKeyStroke.KeyChar = aKeyEvent.GetCharCode();
244 aKeyStroke.KeyFunc = static_cast< sal_Int16 >( aKeyCode.GetFunction() );
245 pKeyBindingHelper->AddKeyBinding( aKeyStroke );
249 return pKeyBindingHelper;
253 // XAccessibleValue
256 Any VCLXAccessibleCheckBox::getCurrentValue( )
258 OExternalLockGuard aGuard( this );
260 Any aValue;
262 VCLXCheckBox* pVCLXCheckBox = static_cast< VCLXCheckBox* >( GetVCLXWindow() );
263 if ( pVCLXCheckBox )
264 aValue <<= static_cast<sal_Int32>(pVCLXCheckBox->getState());
266 return aValue;
270 sal_Bool VCLXAccessibleCheckBox::setCurrentValue( const Any& aNumber )
272 OExternalLockGuard aGuard( this );
274 bool bReturn = false;
276 VCLXCheckBox* pVCLXCheckBox = static_cast< VCLXCheckBox* >( GetVCLXWindow() );
277 if ( pVCLXCheckBox )
279 sal_Int32 nValue = 0, nValueMin = 0, nValueMax = 0;
280 OSL_VERIFY( aNumber >>= nValue );
281 nValueMax=implGetMaximumValue();
283 if ( nValue < nValueMin )
284 nValue = nValueMin;
285 else if ( nValue > nValueMax )
286 nValue = nValueMax;
288 pVCLXCheckBox->setState( static_cast<sal_Int16>(nValue) );
289 bReturn = true;
292 return bReturn;
296 Any VCLXAccessibleCheckBox::getMaximumValue( )
298 OExternalLockGuard aGuard( this );
300 Any aValue;
301 aValue <<= implGetMaximumValue();
303 return aValue;
306 sal_Int32 VCLXAccessibleCheckBox::implGetMaximumValue( )
308 VclPtr< CheckBox > pCheckBox = GetAs< CheckBox >();
309 if ( pCheckBox && pCheckBox->IsTriStateEnabled() )
310 return 2;
312 return 1;
315 Any VCLXAccessibleCheckBox::getMinimumValue( )
317 OExternalLockGuard aGuard( this );
319 Any aValue;
320 aValue <<= sal_Int32(0);
322 return aValue;
325 Any VCLXAccessibleCheckBox::getMinimumIncrement( )
327 OExternalLockGuard aGuard( this );
329 Any aValue;
330 aValue <<= sal_Int32(1);
332 return aValue;
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */