1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_accessibility.hxx"
31 // includes --------------------------------------------------------------
32 #include <accessibility/standard/vclxaccessiblecheckbox.hxx>
34 #include <toolkit/awt/vclxwindows.hxx>
35 #include <accessibility/helper/accresmgr.hxx>
36 #include <accessibility/helper/accessiblestrings.hrc>
38 #include <unotools/accessiblestatesethelper.hxx>
39 #include <comphelper/accessiblekeybindinghelper.hxx>
40 #include <com/sun/star/awt/KeyModifier.hpp>
41 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
42 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
43 #include <cppuhelper/typeprovider.hxx>
44 #include <comphelper/sequence.hxx>
46 #include <vcl/button.hxx>
48 using namespace ::com::sun::star
;
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::lang
;
51 using namespace ::com::sun::star::beans
;
52 using namespace ::com::sun::star::accessibility
;
53 using namespace ::comphelper
;
56 // -----------------------------------------------------------------------------
57 // VCLXAccessibleCheckBox
58 // -----------------------------------------------------------------------------
60 VCLXAccessibleCheckBox::VCLXAccessibleCheckBox( VCLXWindow
* pVCLWindow
)
61 :VCLXAccessibleTextComponent( pVCLWindow
)
63 m_bChecked
= IsChecked();
64 m_bIndeterminate
= IsIndeterminate();
67 // -----------------------------------------------------------------------------
69 VCLXAccessibleCheckBox::~VCLXAccessibleCheckBox()
73 // -----------------------------------------------------------------------------
75 bool VCLXAccessibleCheckBox::IsChecked()
77 bool bChecked
= false;
79 VCLXCheckBox
* pVCLXCheckBox
= static_cast< VCLXCheckBox
* >( GetVCLXWindow() );
80 if ( pVCLXCheckBox
&& pVCLXCheckBox
->getState() == (sal_Int16
) 1 )
86 // -----------------------------------------------------------------------------
88 bool VCLXAccessibleCheckBox::IsIndeterminate()
90 bool bIndeterminate
= false;
92 VCLXCheckBox
* pVCLXCheckBox
= static_cast< VCLXCheckBox
* >( GetVCLXWindow() );
93 if ( pVCLXCheckBox
&& pVCLXCheckBox
->getState() == (sal_Int16
) 2 )
94 bIndeterminate
= true;
96 return bIndeterminate
;
99 // -----------------------------------------------------------------------------
101 void VCLXAccessibleCheckBox::SetChecked( bool bChecked
)
103 if ( m_bChecked
!= bChecked
)
105 Any aOldValue
, aNewValue
;
107 aOldValue
<<= AccessibleStateType::CHECKED
;
109 aNewValue
<<= AccessibleStateType::CHECKED
;
110 m_bChecked
= bChecked
;
111 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
115 // -----------------------------------------------------------------------------
117 void VCLXAccessibleCheckBox::SetIndeterminate( bool bIndeterminate
)
119 if ( m_bIndeterminate
!= bIndeterminate
)
121 Any aOldValue
, aNewValue
;
122 if ( m_bIndeterminate
)
123 aOldValue
<<= AccessibleStateType::INDETERMINATE
;
125 aNewValue
<<= AccessibleStateType::INDETERMINATE
;
126 m_bIndeterminate
= bIndeterminate
;
127 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
131 // -----------------------------------------------------------------------------
133 void VCLXAccessibleCheckBox::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
135 switch ( rVclWindowEvent
.GetId() )
137 case VCLEVENT_CHECKBOX_TOGGLE
:
139 SetChecked( IsChecked() );
140 SetIndeterminate( IsIndeterminate() );
144 VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent
);
148 // -----------------------------------------------------------------------------
150 void VCLXAccessibleCheckBox::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
152 VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet
);
154 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
157 rStateSet
.AddState( AccessibleStateType::CHECKED
);
159 if ( IsIndeterminate() )
160 rStateSet
.AddState( AccessibleStateType::INDETERMINATE
);
163 // -----------------------------------------------------------------------------
165 // -----------------------------------------------------------------------------
167 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleCheckBox
, VCLXAccessibleTextComponent
, VCLXAccessibleCheckBox_BASE
)
169 // -----------------------------------------------------------------------------
171 // -----------------------------------------------------------------------------
173 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleCheckBox
, VCLXAccessibleTextComponent
, VCLXAccessibleCheckBox_BASE
)
175 // -----------------------------------------------------------------------------
177 // -----------------------------------------------------------------------------
179 ::rtl::OUString
VCLXAccessibleCheckBox::getImplementationName() throw (RuntimeException
)
181 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleCheckBox" );
184 // -----------------------------------------------------------------------------
186 Sequence
< ::rtl::OUString
> VCLXAccessibleCheckBox::getSupportedServiceNames() throw (RuntimeException
)
188 Sequence
< ::rtl::OUString
> aNames(1);
189 aNames
[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleCheckBox" );
193 // -----------------------------------------------------------------------------
195 // -----------------------------------------------------------------------------
197 sal_Int32
VCLXAccessibleCheckBox::getAccessibleActionCount( ) throw (RuntimeException
)
199 OExternalLockGuard
aGuard( this );
204 // -----------------------------------------------------------------------------
206 sal_Bool
VCLXAccessibleCheckBox::doAccessibleAction ( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
208 OExternalLockGuard
aGuard( this );
210 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
211 throw IndexOutOfBoundsException();
213 CheckBox
* pCheckBox
= (CheckBox
*) GetWindow();
214 VCLXCheckBox
* pVCLXCheckBox
= static_cast< VCLXCheckBox
* >( GetVCLXWindow() );
215 if ( pCheckBox
&& pVCLXCheckBox
)
217 sal_Int32 nValueMin
= (sal_Int32
) 0;
218 sal_Int32 nValueMax
= (sal_Int32
) 1;
220 if ( pCheckBox
->IsTriStateEnabled() )
221 nValueMax
= (sal_Int32
) 2;
223 sal_Int32 nValue
= (sal_Int32
) pVCLXCheckBox
->getState();
227 if ( nValue
> nValueMax
)
230 pVCLXCheckBox
->setState( (sal_Int16
) nValue
);
236 // -----------------------------------------------------------------------------
238 ::rtl::OUString
VCLXAccessibleCheckBox::getAccessibleActionDescription ( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
240 OExternalLockGuard
aGuard( this );
242 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
243 throw IndexOutOfBoundsException();
245 return ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_CLICK
) );
248 // -----------------------------------------------------------------------------
250 Reference
< XAccessibleKeyBinding
> VCLXAccessibleCheckBox::getAccessibleActionKeyBinding( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
252 OExternalLockGuard
aGuard( this );
254 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
255 throw IndexOutOfBoundsException();
257 OAccessibleKeyBindingHelper
* pKeyBindingHelper
= new OAccessibleKeyBindingHelper();
258 Reference
< XAccessibleKeyBinding
> xKeyBinding
= pKeyBindingHelper
;
260 Window
* pWindow
= GetWindow();
263 KeyEvent aKeyEvent
= pWindow
->GetActivationKey();
264 KeyCode aKeyCode
= aKeyEvent
.GetKeyCode();
265 if ( aKeyCode
.GetCode() != 0 )
267 awt::KeyStroke aKeyStroke
;
268 aKeyStroke
.Modifiers
= 0;
269 if ( aKeyCode
.IsShift() )
270 aKeyStroke
.Modifiers
|= awt::KeyModifier::SHIFT
;
271 if ( aKeyCode
.IsMod1() )
272 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD1
;
273 if ( aKeyCode
.IsMod2() )
274 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD2
;
275 if ( aKeyCode
.IsMod3() )
276 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD3
;
277 aKeyStroke
.KeyCode
= aKeyCode
.GetCode();
278 aKeyStroke
.KeyChar
= aKeyEvent
.GetCharCode();
279 aKeyStroke
.KeyFunc
= static_cast< sal_Int16
>( aKeyCode
.GetFunction() );
280 pKeyBindingHelper
->AddKeyBinding( aKeyStroke
);
287 // -----------------------------------------------------------------------------
289 // -----------------------------------------------------------------------------
291 Any
VCLXAccessibleCheckBox::getCurrentValue( ) throw (RuntimeException
)
293 OExternalLockGuard
aGuard( this );
297 VCLXCheckBox
* pVCLXCheckBox
= static_cast< VCLXCheckBox
* >( GetVCLXWindow() );
299 aValue
<<= (sal_Int32
) pVCLXCheckBox
->getState();
304 // -----------------------------------------------------------------------------
306 sal_Bool
VCLXAccessibleCheckBox::setCurrentValue( const Any
& aNumber
) throw (RuntimeException
)
308 OExternalLockGuard
aGuard( this );
310 sal_Bool bReturn
= sal_False
;
312 VCLXCheckBox
* pVCLXCheckBox
= static_cast< VCLXCheckBox
* >( GetVCLXWindow() );
315 sal_Int32 nValue
= 0, nValueMin
= 0, nValueMax
= 0;
316 OSL_VERIFY( aNumber
>>= nValue
);
317 OSL_VERIFY( getMinimumValue() >>= nValueMin
);
318 OSL_VERIFY( getMaximumValue() >>= nValueMax
);
320 if ( nValue
< nValueMin
)
322 else if ( nValue
> nValueMax
)
325 pVCLXCheckBox
->setState( (sal_Int16
) nValue
);
332 // -----------------------------------------------------------------------------
334 Any
VCLXAccessibleCheckBox::getMaximumValue( ) throw (RuntimeException
)
336 OExternalLockGuard
aGuard( this );
340 CheckBox
* pCheckBox
= (CheckBox
*) GetWindow();
341 if ( pCheckBox
&& pCheckBox
->IsTriStateEnabled() )
342 aValue
<<= (sal_Int32
) 2;
344 aValue
<<= (sal_Int32
) 1;
349 // -----------------------------------------------------------------------------
351 Any
VCLXAccessibleCheckBox::getMinimumValue( ) throw (RuntimeException
)
353 OExternalLockGuard
aGuard( this );
356 aValue
<<= (sal_Int32
) 0;
361 // -----------------------------------------------------------------------------