1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclxaccessibleradiobutton.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_accessibility.hxx"
34 // includes --------------------------------------------------------------
35 #include <accessibility/standard/vclxaccessibleradiobutton.hxx>
37 #include <toolkit/awt/vclxwindows.hxx>
38 #include <accessibility/helper/accresmgr.hxx>
39 #include <accessibility/helper/accessiblestrings.hrc>
41 #include <unotools/accessiblerelationsethelper.hxx>
42 #include <unotools/accessiblestatesethelper.hxx>
43 #include <comphelper/accessiblekeybindinghelper.hxx>
44 #include <com/sun/star/awt/KeyModifier.hpp>
45 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
46 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
47 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
48 #include <cppuhelper/typeprovider.hxx>
49 #include <comphelper/sequence.hxx>
50 #include <vcl/window.hxx>
51 #include <vcl/button.hxx>
54 using namespace ::com::sun::star
;
55 using namespace ::com::sun::star::uno
;
56 using namespace ::com::sun::star::lang
;
57 using namespace ::com::sun::star::beans
;
58 using namespace ::com::sun::star::accessibility
;
59 using namespace ::comphelper
;
62 // -----------------------------------------------------------------------------
63 // VCLXAccessibleRadioButton
64 // -----------------------------------------------------------------------------
66 VCLXAccessibleRadioButton::VCLXAccessibleRadioButton( VCLXWindow
* pVCLWindow
)
67 :VCLXAccessibleTextComponent( pVCLWindow
)
71 // -----------------------------------------------------------------------------
73 VCLXAccessibleRadioButton::~VCLXAccessibleRadioButton()
77 // -----------------------------------------------------------------------------
79 void VCLXAccessibleRadioButton::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
81 switch ( rVclWindowEvent
.GetId() )
83 case VCLEVENT_RADIOBUTTON_TOGGLE
:
88 VCLXRadioButton
* pVCLXRadioButton
= static_cast< VCLXRadioButton
* >( GetVCLXWindow() );
89 if ( pVCLXRadioButton
&& pVCLXRadioButton
->getState() )
90 aNewValue
<<= AccessibleStateType::CHECKED
;
92 aOldValue
<<= AccessibleStateType::CHECKED
;
94 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
98 VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent
);
102 // -----------------------------------------------------------------------------
104 void VCLXAccessibleRadioButton::FillAccessibleRelationSet( utl::AccessibleRelationSetHelper
& rRelationSet
)
106 VCLXAccessibleTextComponent::FillAccessibleRelationSet( rRelationSet
);
108 RadioButton
* pRadioButton
= dynamic_cast< RadioButton
* >( GetWindow() );
111 ::std::vector
< RadioButton
* > aGroup
;
112 pRadioButton
->GetRadioButtonGroup( aGroup
, true );
113 if ( !aGroup
.empty() )
116 Sequence
< Reference
< XInterface
> > aSequence( static_cast< sal_Int32
>( aGroup
.size() ) );
117 ::std::vector
< RadioButton
* >::const_iterator aEndItr
= aGroup
.end();
118 for ( ::std::vector
< RadioButton
* >::const_iterator aItr
= aGroup
.begin(); aItr
< aEndItr
; ++aItr
)
120 aSequence
[i
++] = (*aItr
)->GetAccessible();
122 rRelationSet
.AddRelation( AccessibleRelation( AccessibleRelationType::MEMBER_OF
, aSequence
) );
127 // -----------------------------------------------------------------------------
129 void VCLXAccessibleRadioButton::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
131 VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet
);
133 VCLXRadioButton
* pVCLXRadioButton
= static_cast< VCLXRadioButton
* >( GetVCLXWindow() );
134 if ( pVCLXRadioButton
)
136 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
137 if ( pVCLXRadioButton
->getState() )
138 rStateSet
.AddState( AccessibleStateType::CHECKED
);
142 // -----------------------------------------------------------------------------
144 // -----------------------------------------------------------------------------
146 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleRadioButton
, VCLXAccessibleTextComponent
, VCLXAccessibleRadioButton_BASE
)
148 // -----------------------------------------------------------------------------
150 // -----------------------------------------------------------------------------
152 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleRadioButton
, VCLXAccessibleTextComponent
, VCLXAccessibleRadioButton_BASE
)
154 // -----------------------------------------------------------------------------
156 // -----------------------------------------------------------------------------
158 ::rtl::OUString
VCLXAccessibleRadioButton::getImplementationName() throw (RuntimeException
)
160 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleRadioButton" );
163 // -----------------------------------------------------------------------------
165 Sequence
< ::rtl::OUString
> VCLXAccessibleRadioButton::getSupportedServiceNames() throw (RuntimeException
)
167 Sequence
< ::rtl::OUString
> aNames(1);
168 aNames
[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleRadioButton" );
172 // -----------------------------------------------------------------------------
174 // -----------------------------------------------------------------------------
176 sal_Int32
VCLXAccessibleRadioButton::getAccessibleActionCount( ) throw (RuntimeException
)
178 OExternalLockGuard
aGuard( this );
183 // -----------------------------------------------------------------------------
185 sal_Bool
VCLXAccessibleRadioButton::doAccessibleAction ( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
187 OExternalLockGuard
aGuard( this );
189 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
190 throw IndexOutOfBoundsException();
192 VCLXRadioButton
* pVCLXRadioButton
= static_cast< VCLXRadioButton
* >( GetVCLXWindow() );
193 if ( pVCLXRadioButton
&& !pVCLXRadioButton
->getState() )
194 pVCLXRadioButton
->setState( sal_True
);
199 // -----------------------------------------------------------------------------
201 ::rtl::OUString
VCLXAccessibleRadioButton::getAccessibleActionDescription ( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
203 OExternalLockGuard
aGuard( this );
205 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
206 throw IndexOutOfBoundsException();
208 return ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_CLICK
) );
211 // -----------------------------------------------------------------------------
213 Reference
< XAccessibleKeyBinding
> VCLXAccessibleRadioButton::getAccessibleActionKeyBinding( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
215 OExternalLockGuard
aGuard( this );
217 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
218 throw IndexOutOfBoundsException();
220 OAccessibleKeyBindingHelper
* pKeyBindingHelper
= new OAccessibleKeyBindingHelper();
221 Reference
< XAccessibleKeyBinding
> xKeyBinding
= pKeyBindingHelper
;
223 Window
* pWindow
= GetWindow();
226 KeyEvent aKeyEvent
= pWindow
->GetActivationKey();
227 KeyCode aKeyCode
= aKeyEvent
.GetKeyCode();
228 if ( aKeyCode
.GetCode() != 0 )
230 awt::KeyStroke aKeyStroke
;
231 aKeyStroke
.Modifiers
= 0;
232 if ( aKeyCode
.IsShift() )
233 aKeyStroke
.Modifiers
|= awt::KeyModifier::SHIFT
;
234 if ( aKeyCode
.IsMod1() )
235 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD1
;
236 if ( aKeyCode
.IsMod2() )
237 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD2
;
238 if ( aKeyCode
.IsMod3() )
239 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD3
;
240 aKeyStroke
.KeyCode
= aKeyCode
.GetCode();
241 aKeyStroke
.KeyChar
= aKeyEvent
.GetCharCode();
242 aKeyStroke
.KeyFunc
= static_cast< sal_Int16
>( aKeyCode
.GetFunction() );
243 pKeyBindingHelper
->AddKeyBinding( aKeyStroke
);
250 // -----------------------------------------------------------------------------
252 // -----------------------------------------------------------------------------
254 Any
VCLXAccessibleRadioButton::getCurrentValue( ) throw (RuntimeException
)
256 OExternalLockGuard
aGuard( this );
260 VCLXRadioButton
* pVCLXRadioButton
= static_cast< VCLXRadioButton
* >( GetVCLXWindow() );
261 if ( pVCLXRadioButton
)
262 aValue
<<= (sal_Int32
) pVCLXRadioButton
->getState();
267 // -----------------------------------------------------------------------------
269 sal_Bool
VCLXAccessibleRadioButton::setCurrentValue( const Any
& aNumber
) throw (RuntimeException
)
271 OExternalLockGuard
aGuard( this );
273 sal_Bool bReturn
= sal_False
;
275 VCLXRadioButton
* pVCLXRadioButton
= static_cast< VCLXRadioButton
* >( GetVCLXWindow() );
276 if ( pVCLXRadioButton
)
278 sal_Int32 nValue
= 0;
279 OSL_VERIFY( aNumber
>>= nValue
);
283 else if ( nValue
> 1 )
286 pVCLXRadioButton
->setState( (sal_Bool
) nValue
);
293 // -----------------------------------------------------------------------------
295 Any
VCLXAccessibleRadioButton::getMaximumValue( ) throw (RuntimeException
)
297 OExternalLockGuard
aGuard( this );
300 aValue
<<= (sal_Int32
) 1;
305 // -----------------------------------------------------------------------------
307 Any
VCLXAccessibleRadioButton::getMinimumValue( ) throw (RuntimeException
)
309 OExternalLockGuard
aGuard( this );
312 aValue
<<= (sal_Int32
) 0;
317 // -----------------------------------------------------------------------------