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/vclxaccessibleradiobutton.hxx>
34 #include <toolkit/awt/vclxwindows.hxx>
35 #include <accessibility/helper/accresmgr.hxx>
36 #include <accessibility/helper/accessiblestrings.hrc>
38 #include <unotools/accessiblerelationsethelper.hxx>
39 #include <unotools/accessiblestatesethelper.hxx>
40 #include <comphelper/accessiblekeybindinghelper.hxx>
41 #include <com/sun/star/awt/KeyModifier.hpp>
42 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
43 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
44 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
45 #include <cppuhelper/typeprovider.hxx>
46 #include <comphelper/sequence.hxx>
47 #include <vcl/window.hxx>
48 #include <vcl/button.hxx>
51 using namespace ::com::sun::star
;
52 using namespace ::com::sun::star::uno
;
53 using namespace ::com::sun::star::lang
;
54 using namespace ::com::sun::star::beans
;
55 using namespace ::com::sun::star::accessibility
;
56 using namespace ::comphelper
;
59 // -----------------------------------------------------------------------------
60 // VCLXAccessibleRadioButton
61 // -----------------------------------------------------------------------------
63 VCLXAccessibleRadioButton::VCLXAccessibleRadioButton( VCLXWindow
* pVCLWindow
)
64 :VCLXAccessibleTextComponent( pVCLWindow
)
68 // -----------------------------------------------------------------------------
70 VCLXAccessibleRadioButton::~VCLXAccessibleRadioButton()
74 // -----------------------------------------------------------------------------
76 void VCLXAccessibleRadioButton::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
78 switch ( rVclWindowEvent
.GetId() )
80 case VCLEVENT_RADIOBUTTON_TOGGLE
:
85 VCLXRadioButton
* pVCLXRadioButton
= static_cast< VCLXRadioButton
* >( GetVCLXWindow() );
86 if ( pVCLXRadioButton
&& pVCLXRadioButton
->getState() )
87 aNewValue
<<= AccessibleStateType::CHECKED
;
89 aOldValue
<<= AccessibleStateType::CHECKED
;
91 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
95 VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent
);
99 // -----------------------------------------------------------------------------
101 void VCLXAccessibleRadioButton::FillAccessibleRelationSet( utl::AccessibleRelationSetHelper
& rRelationSet
)
103 VCLXAccessibleTextComponent::FillAccessibleRelationSet( rRelationSet
);
105 RadioButton
* pRadioButton
= dynamic_cast< RadioButton
* >( GetWindow() );
108 ::std::vector
< RadioButton
* > aGroup
;
109 pRadioButton
->GetRadioButtonGroup( aGroup
, true );
110 if ( !aGroup
.empty() )
113 Sequence
< Reference
< XInterface
> > aSequence( static_cast< sal_Int32
>( aGroup
.size() ) );
114 ::std::vector
< RadioButton
* >::const_iterator aEndItr
= aGroup
.end();
115 for ( ::std::vector
< RadioButton
* >::const_iterator aItr
= aGroup
.begin(); aItr
< aEndItr
; ++aItr
)
117 aSequence
[i
++] = (*aItr
)->GetAccessible();
119 rRelationSet
.AddRelation( AccessibleRelation( AccessibleRelationType::MEMBER_OF
, aSequence
) );
124 // -----------------------------------------------------------------------------
126 void VCLXAccessibleRadioButton::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
128 VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet
);
130 VCLXRadioButton
* pVCLXRadioButton
= static_cast< VCLXRadioButton
* >( GetVCLXWindow() );
131 if ( pVCLXRadioButton
)
133 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
134 if ( pVCLXRadioButton
->getState() )
135 rStateSet
.AddState( AccessibleStateType::CHECKED
);
139 // -----------------------------------------------------------------------------
141 // -----------------------------------------------------------------------------
143 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleRadioButton
, VCLXAccessibleTextComponent
, VCLXAccessibleRadioButton_BASE
)
145 // -----------------------------------------------------------------------------
147 // -----------------------------------------------------------------------------
149 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleRadioButton
, VCLXAccessibleTextComponent
, VCLXAccessibleRadioButton_BASE
)
151 // -----------------------------------------------------------------------------
153 // -----------------------------------------------------------------------------
155 ::rtl::OUString
VCLXAccessibleRadioButton::getImplementationName() throw (RuntimeException
)
157 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleRadioButton" );
160 // -----------------------------------------------------------------------------
162 Sequence
< ::rtl::OUString
> VCLXAccessibleRadioButton::getSupportedServiceNames() throw (RuntimeException
)
164 Sequence
< ::rtl::OUString
> aNames(1);
165 aNames
[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleRadioButton" );
169 // -----------------------------------------------------------------------------
171 // -----------------------------------------------------------------------------
173 sal_Int32
VCLXAccessibleRadioButton::getAccessibleActionCount( ) throw (RuntimeException
)
175 OExternalLockGuard
aGuard( this );
180 // -----------------------------------------------------------------------------
182 sal_Bool
VCLXAccessibleRadioButton::doAccessibleAction ( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
184 OExternalLockGuard
aGuard( this );
186 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
187 throw IndexOutOfBoundsException();
189 VCLXRadioButton
* pVCLXRadioButton
= static_cast< VCLXRadioButton
* >( GetVCLXWindow() );
190 if ( pVCLXRadioButton
&& !pVCLXRadioButton
->getState() )
191 pVCLXRadioButton
->setState( sal_True
);
196 // -----------------------------------------------------------------------------
198 ::rtl::OUString
VCLXAccessibleRadioButton::getAccessibleActionDescription ( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
200 OExternalLockGuard
aGuard( this );
202 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
203 throw IndexOutOfBoundsException();
205 return ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_CLICK
) );
208 // -----------------------------------------------------------------------------
210 Reference
< XAccessibleKeyBinding
> VCLXAccessibleRadioButton::getAccessibleActionKeyBinding( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
212 OExternalLockGuard
aGuard( this );
214 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
215 throw IndexOutOfBoundsException();
217 OAccessibleKeyBindingHelper
* pKeyBindingHelper
= new OAccessibleKeyBindingHelper();
218 Reference
< XAccessibleKeyBinding
> xKeyBinding
= pKeyBindingHelper
;
220 Window
* pWindow
= GetWindow();
223 KeyEvent aKeyEvent
= pWindow
->GetActivationKey();
224 KeyCode aKeyCode
= aKeyEvent
.GetKeyCode();
225 if ( aKeyCode
.GetCode() != 0 )
227 awt::KeyStroke aKeyStroke
;
228 aKeyStroke
.Modifiers
= 0;
229 if ( aKeyCode
.IsShift() )
230 aKeyStroke
.Modifiers
|= awt::KeyModifier::SHIFT
;
231 if ( aKeyCode
.IsMod1() )
232 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD1
;
233 if ( aKeyCode
.IsMod2() )
234 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD2
;
235 if ( aKeyCode
.IsMod3() )
236 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD3
;
237 aKeyStroke
.KeyCode
= aKeyCode
.GetCode();
238 aKeyStroke
.KeyChar
= aKeyEvent
.GetCharCode();
239 aKeyStroke
.KeyFunc
= static_cast< sal_Int16
>( aKeyCode
.GetFunction() );
240 pKeyBindingHelper
->AddKeyBinding( aKeyStroke
);
247 // -----------------------------------------------------------------------------
249 // -----------------------------------------------------------------------------
251 Any
VCLXAccessibleRadioButton::getCurrentValue( ) throw (RuntimeException
)
253 OExternalLockGuard
aGuard( this );
257 VCLXRadioButton
* pVCLXRadioButton
= static_cast< VCLXRadioButton
* >( GetVCLXWindow() );
258 if ( pVCLXRadioButton
)
259 aValue
<<= (sal_Int32
) pVCLXRadioButton
->getState();
264 // -----------------------------------------------------------------------------
266 sal_Bool
VCLXAccessibleRadioButton::setCurrentValue( const Any
& aNumber
) throw (RuntimeException
)
268 OExternalLockGuard
aGuard( this );
270 sal_Bool bReturn
= sal_False
;
272 VCLXRadioButton
* pVCLXRadioButton
= static_cast< VCLXRadioButton
* >( GetVCLXWindow() );
273 if ( pVCLXRadioButton
)
275 sal_Int32 nValue
= 0;
276 OSL_VERIFY( aNumber
>>= nValue
);
280 else if ( nValue
> 1 )
283 pVCLXRadioButton
->setState( (sal_Bool
) nValue
);
290 // -----------------------------------------------------------------------------
292 Any
VCLXAccessibleRadioButton::getMaximumValue( ) throw (RuntimeException
)
294 OExternalLockGuard
aGuard( this );
297 aValue
<<= (sal_Int32
) 1;
302 // -----------------------------------------------------------------------------
304 Any
VCLXAccessibleRadioButton::getMinimumValue( ) throw (RuntimeException
)
306 OExternalLockGuard
aGuard( this );
309 aValue
<<= (sal_Int32
) 0;
314 // -----------------------------------------------------------------------------