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/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::beans
;
41 using namespace ::com::sun::star::accessibility
;
42 using namespace ::comphelper
;
45 // VCLXAccessibleCheckBox
48 VCLXAccessibleCheckBox::VCLXAccessibleCheckBox( VCLXWindow
* pVCLWindow
)
49 :ImplInheritanceHelper( pVCLWindow
)
51 m_bChecked
= IsChecked();
52 m_bIndeterminate
= IsIndeterminate();
56 bool VCLXAccessibleCheckBox::IsChecked() const
58 bool bChecked
= false;
60 VCLXCheckBox
* pVCLXCheckBox
= static_cast< VCLXCheckBox
* >( GetVCLXWindow() );
61 if ( pVCLXCheckBox
&& pVCLXCheckBox
->getState() == sal_Int16(1) )
68 bool VCLXAccessibleCheckBox::IsIndeterminate() const
70 bool bIndeterminate
= false;
72 VCLXCheckBox
* pVCLXCheckBox
= static_cast< VCLXCheckBox
* >( GetVCLXWindow() );
73 if ( pVCLXCheckBox
&& pVCLXCheckBox
->getState() == sal_Int16(2) )
74 bIndeterminate
= true;
76 return bIndeterminate
;
80 void VCLXAccessibleCheckBox::SetChecked( bool bChecked
)
82 if ( m_bChecked
!= bChecked
)
84 Any aOldValue
, aNewValue
;
86 aOldValue
<<= AccessibleStateType::CHECKED
;
88 aNewValue
<<= AccessibleStateType::CHECKED
;
89 m_bChecked
= bChecked
;
90 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
95 void VCLXAccessibleCheckBox::SetIndeterminate( bool bIndeterminate
)
97 if ( m_bIndeterminate
!= bIndeterminate
)
99 Any aOldValue
, aNewValue
;
100 if ( m_bIndeterminate
)
101 aOldValue
<<= AccessibleStateType::INDETERMINATE
;
103 aNewValue
<<= AccessibleStateType::INDETERMINATE
;
104 m_bIndeterminate
= bIndeterminate
;
105 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
110 void VCLXAccessibleCheckBox::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
112 switch ( rVclWindowEvent
.GetId() )
114 case VclEventId::CheckboxToggle
:
116 SetChecked( IsChecked() );
117 SetIndeterminate( IsIndeterminate() );
121 VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent
);
126 void VCLXAccessibleCheckBox::FillAccessibleStateSet( sal_Int64
& rStateSet
)
128 VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet
);
130 rStateSet
|= AccessibleStateType::FOCUSABLE
;
133 rStateSet
|= AccessibleStateType::CHECKED
;
135 if ( IsIndeterminate() )
136 rStateSet
|= AccessibleStateType::INDETERMINATE
;
143 OUString
VCLXAccessibleCheckBox::getImplementationName()
145 return "com.sun.star.comp.toolkit.AccessibleCheckBox";
149 Sequence
< OUString
> VCLXAccessibleCheckBox::getSupportedServiceNames()
151 return { "com.sun.star.awt.AccessibleCheckBox" };
158 sal_Int32
VCLXAccessibleCheckBox::getAccessibleActionCount( )
160 OExternalLockGuard
aGuard( this );
166 sal_Bool
VCLXAccessibleCheckBox::doAccessibleAction ( sal_Int32 nIndex
)
168 OExternalLockGuard
aGuard( this );
171 throw IndexOutOfBoundsException();
173 VclPtr
< CheckBox
> pCheckBox
= GetAs
< CheckBox
>();
174 VCLXCheckBox
* pVCLXCheckBox
= static_cast< VCLXCheckBox
* >( GetVCLXWindow() );
175 if ( pCheckBox
&& pVCLXCheckBox
)
177 sal_Int32 nValueMax
= sal_Int32(1);
179 if ( pCheckBox
->IsTriStateEnabled() )
180 nValueMax
= sal_Int32(2);
182 sal_Int32 nValue
= static_cast<sal_Int32
>(pVCLXCheckBox
->getState());
186 if ( nValue
> nValueMax
)
189 pVCLXCheckBox
->setState( static_cast<sal_Int16
>(nValue
) );
196 OUString
VCLXAccessibleCheckBox::getAccessibleActionDescription ( sal_Int32 nIndex
)
198 OExternalLockGuard
aGuard( this );
201 throw IndexOutOfBoundsException();
204 return AccResId( RID_STR_ACC_ACTION_UNCHECK
);
206 return AccResId( RID_STR_ACC_ACTION_CHECK
);
210 Reference
< XAccessibleKeyBinding
> VCLXAccessibleCheckBox::getAccessibleActionKeyBinding( sal_Int32 nIndex
)
212 OExternalLockGuard
aGuard( this );
215 throw IndexOutOfBoundsException();
217 rtl::Reference
<OAccessibleKeyBindingHelper
> pKeyBindingHelper
= new OAccessibleKeyBindingHelper();
219 VclPtr
<vcl::Window
> pWindow
= GetWindow();
222 KeyEvent aKeyEvent
= pWindow
->GetActivationKey();
223 vcl::KeyCode aKeyCode
= aKeyEvent
.GetKeyCode();
224 if ( aKeyCode
.GetCode() != 0 )
226 awt::KeyStroke aKeyStroke
;
227 aKeyStroke
.Modifiers
= 0;
228 if ( aKeyCode
.IsShift() )
229 aKeyStroke
.Modifiers
|= awt::KeyModifier::SHIFT
;
230 if ( aKeyCode
.IsMod1() )
231 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD1
;
232 if ( aKeyCode
.IsMod2() )
233 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD2
;
234 if ( aKeyCode
.IsMod3() )
235 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD3
;
236 aKeyStroke
.KeyCode
= aKeyCode
.GetCode();
237 aKeyStroke
.KeyChar
= aKeyEvent
.GetCharCode();
238 aKeyStroke
.KeyFunc
= static_cast< sal_Int16
>( aKeyCode
.GetFunction() );
239 pKeyBindingHelper
->AddKeyBinding( aKeyStroke
);
243 return pKeyBindingHelper
;
250 Any
VCLXAccessibleCheckBox::getCurrentValue( )
252 OExternalLockGuard
aGuard( this );
256 VCLXCheckBox
* pVCLXCheckBox
= static_cast< VCLXCheckBox
* >( GetVCLXWindow() );
258 aValue
<<= static_cast<sal_Int32
>(pVCLXCheckBox
->getState());
264 sal_Bool
VCLXAccessibleCheckBox::setCurrentValue( const Any
& aNumber
)
266 OExternalLockGuard
aGuard( this );
268 bool bReturn
= false;
270 VCLXCheckBox
* pVCLXCheckBox
= static_cast< VCLXCheckBox
* >( GetVCLXWindow() );
273 sal_Int32 nValue
= 0, nValueMin
= 0, nValueMax
= 0;
274 OSL_VERIFY( aNumber
>>= nValue
);
275 nValueMax
=implGetMaximumValue();
277 if ( nValue
< nValueMin
)
279 else if ( nValue
> nValueMax
)
282 pVCLXCheckBox
->setState( static_cast<sal_Int16
>(nValue
) );
290 Any
VCLXAccessibleCheckBox::getMaximumValue( )
292 OExternalLockGuard
aGuard( this );
295 aValue
<<= implGetMaximumValue();
300 sal_Int32
VCLXAccessibleCheckBox::implGetMaximumValue( )
302 VclPtr
< CheckBox
> pCheckBox
= GetAs
< CheckBox
>();
303 if ( pCheckBox
&& pCheckBox
->IsTriStateEnabled() )
309 Any
VCLXAccessibleCheckBox::getMinimumValue( )
311 OExternalLockGuard
aGuard( this );
314 aValue
<<= sal_Int32(0);
319 Any
VCLXAccessibleCheckBox::getMinimumIncrement( )
321 OExternalLockGuard
aGuard( this );
324 aValue
<<= sal_Int32(1);
330 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */