update dev300-m58
[ooovba.git] / accessibility / source / standard / vclxaccessibleradiobutton.cxx
blob78f060959f0a41f297dc4e38be1c44446e5b0778
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclxaccessibleradiobutton.cxx,v $
10 * $Revision: 1.4 $
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:
85 Any aOldValue;
86 Any aNewValue;
88 VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() );
89 if ( pVCLXRadioButton && pVCLXRadioButton->getState() )
90 aNewValue <<= AccessibleStateType::CHECKED;
91 else
92 aOldValue <<= AccessibleStateType::CHECKED;
94 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
96 break;
97 default:
98 VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent );
102 // -----------------------------------------------------------------------------
104 void VCLXAccessibleRadioButton::FillAccessibleRelationSet( utl::AccessibleRelationSetHelper& rRelationSet )
106 VCLXAccessibleTextComponent::FillAccessibleRelationSet( rRelationSet );
108 RadioButton* pRadioButton = dynamic_cast< RadioButton* >( GetWindow() );
109 if ( pRadioButton )
111 ::std::vector< RadioButton* > aGroup;
112 pRadioButton->GetRadioButtonGroup( aGroup, true );
113 if ( !aGroup.empty() )
115 sal_Int32 i = 0;
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 // -----------------------------------------------------------------------------
143 // XInterface
144 // -----------------------------------------------------------------------------
146 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleRadioButton, VCLXAccessibleTextComponent, VCLXAccessibleRadioButton_BASE )
148 // -----------------------------------------------------------------------------
149 // XTypeProvider
150 // -----------------------------------------------------------------------------
152 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleRadioButton, VCLXAccessibleTextComponent, VCLXAccessibleRadioButton_BASE )
154 // -----------------------------------------------------------------------------
155 // XServiceInfo
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" );
169 return aNames;
172 // -----------------------------------------------------------------------------
173 // XAccessibleAction
174 // -----------------------------------------------------------------------------
176 sal_Int32 VCLXAccessibleRadioButton::getAccessibleActionCount( ) throw (RuntimeException)
178 OExternalLockGuard aGuard( this );
180 return 1;
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 );
196 return 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();
224 if ( pWindow )
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 );
247 return xKeyBinding;
250 // -----------------------------------------------------------------------------
251 // XAccessibleValue
252 // -----------------------------------------------------------------------------
254 Any VCLXAccessibleRadioButton::getCurrentValue( ) throw (RuntimeException)
256 OExternalLockGuard aGuard( this );
258 Any aValue;
260 VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() );
261 if ( pVCLXRadioButton )
262 aValue <<= (sal_Int32) pVCLXRadioButton->getState();
264 return aValue;
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 );
281 if ( nValue < 0 )
282 nValue = 0;
283 else if ( nValue > 1 )
284 nValue = 1;
286 pVCLXRadioButton->setState( (sal_Bool) nValue );
287 bReturn = sal_True;
290 return bReturn;
293 // -----------------------------------------------------------------------------
295 Any VCLXAccessibleRadioButton::getMaximumValue( ) throw (RuntimeException)
297 OExternalLockGuard aGuard( this );
299 Any aValue;
300 aValue <<= (sal_Int32) 1;
302 return aValue;
305 // -----------------------------------------------------------------------------
307 Any VCLXAccessibleRadioButton::getMinimumValue( ) throw (RuntimeException)
309 OExternalLockGuard aGuard( this );
311 Any aValue;
312 aValue <<= (sal_Int32) 0;
314 return aValue;
317 // -----------------------------------------------------------------------------