1*0841af79SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*0841af79SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*0841af79SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*0841af79SAndrew Rist * distributed with this work for additional information 6*0841af79SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*0841af79SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*0841af79SAndrew Rist * "License"); you may not use this file except in compliance 9*0841af79SAndrew Rist * with the License. You may obtain a copy of the License at 10*0841af79SAndrew Rist * 11*0841af79SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*0841af79SAndrew Rist * 13*0841af79SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*0841af79SAndrew Rist * software distributed under the License is distributed on an 15*0841af79SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*0841af79SAndrew Rist * KIND, either express or implied. See the License for the 17*0841af79SAndrew Rist * specific language governing permissions and limitations 18*0841af79SAndrew Rist * under the License. 19*0841af79SAndrew Rist * 20*0841af79SAndrew Rist *************************************************************/ 21*0841af79SAndrew Rist 22*0841af79SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_accessibility.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir // includes -------------------------------------------------------------- 28cdf0e10cSrcweir #include <accessibility/standard/vclxaccessibleradiobutton.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <toolkit/awt/vclxwindows.hxx> 31cdf0e10cSrcweir #include <accessibility/helper/accresmgr.hxx> 32cdf0e10cSrcweir #include <accessibility/helper/accessiblestrings.hrc> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include <unotools/accessiblerelationsethelper.hxx> 35cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx> 36cdf0e10cSrcweir #include <comphelper/accessiblekeybindinghelper.hxx> 37cdf0e10cSrcweir #include <com/sun/star/awt/KeyModifier.hpp> 38cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRelationType.hpp> 39cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp> 40cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp> 41cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 42cdf0e10cSrcweir #include <comphelper/sequence.hxx> 43cdf0e10cSrcweir #include <vcl/window.hxx> 44cdf0e10cSrcweir #include <vcl/button.hxx> 45cdf0e10cSrcweir 46cdf0e10cSrcweir 47cdf0e10cSrcweir using namespace ::com::sun::star; 48cdf0e10cSrcweir using namespace ::com::sun::star::uno; 49cdf0e10cSrcweir using namespace ::com::sun::star::lang; 50cdf0e10cSrcweir using namespace ::com::sun::star::beans; 51cdf0e10cSrcweir using namespace ::com::sun::star::accessibility; 52cdf0e10cSrcweir using namespace ::comphelper; 53cdf0e10cSrcweir 54cdf0e10cSrcweir 55cdf0e10cSrcweir // ----------------------------------------------------------------------------- 56cdf0e10cSrcweir // VCLXAccessibleRadioButton 57cdf0e10cSrcweir // ----------------------------------------------------------------------------- 58cdf0e10cSrcweir 59cdf0e10cSrcweir VCLXAccessibleRadioButton::VCLXAccessibleRadioButton( VCLXWindow* pVCLWindow ) 60cdf0e10cSrcweir :VCLXAccessibleTextComponent( pVCLWindow ) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir } 63cdf0e10cSrcweir 64cdf0e10cSrcweir // ----------------------------------------------------------------------------- 65cdf0e10cSrcweir 66cdf0e10cSrcweir VCLXAccessibleRadioButton::~VCLXAccessibleRadioButton() 67cdf0e10cSrcweir { 68cdf0e10cSrcweir } 69cdf0e10cSrcweir 70cdf0e10cSrcweir // ----------------------------------------------------------------------------- 71cdf0e10cSrcweir 72cdf0e10cSrcweir void VCLXAccessibleRadioButton::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) 73cdf0e10cSrcweir { 74cdf0e10cSrcweir switch ( rVclWindowEvent.GetId() ) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir case VCLEVENT_RADIOBUTTON_TOGGLE: 77cdf0e10cSrcweir { 78cdf0e10cSrcweir Any aOldValue; 79cdf0e10cSrcweir Any aNewValue; 80cdf0e10cSrcweir 81cdf0e10cSrcweir VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() ); 82cdf0e10cSrcweir if ( pVCLXRadioButton && pVCLXRadioButton->getState() ) 83cdf0e10cSrcweir aNewValue <<= AccessibleStateType::CHECKED; 84cdf0e10cSrcweir else 85cdf0e10cSrcweir aOldValue <<= AccessibleStateType::CHECKED; 86cdf0e10cSrcweir 87cdf0e10cSrcweir NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir break; 90cdf0e10cSrcweir default: 91cdf0e10cSrcweir VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent ); 92cdf0e10cSrcweir } 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir // ----------------------------------------------------------------------------- 96cdf0e10cSrcweir 97cdf0e10cSrcweir void VCLXAccessibleRadioButton::FillAccessibleRelationSet( utl::AccessibleRelationSetHelper& rRelationSet ) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir VCLXAccessibleTextComponent::FillAccessibleRelationSet( rRelationSet ); 100cdf0e10cSrcweir 101cdf0e10cSrcweir RadioButton* pRadioButton = dynamic_cast< RadioButton* >( GetWindow() ); 102cdf0e10cSrcweir if ( pRadioButton ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir ::std::vector< RadioButton* > aGroup; 105cdf0e10cSrcweir pRadioButton->GetRadioButtonGroup( aGroup, true ); 106cdf0e10cSrcweir if ( !aGroup.empty() ) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir sal_Int32 i = 0; 109cdf0e10cSrcweir Sequence< Reference< XInterface > > aSequence( static_cast< sal_Int32 >( aGroup.size() ) ); 110cdf0e10cSrcweir ::std::vector< RadioButton* >::const_iterator aEndItr = aGroup.end(); 111cdf0e10cSrcweir for ( ::std::vector< RadioButton* >::const_iterator aItr = aGroup.begin(); aItr < aEndItr; ++aItr ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir aSequence[i++] = (*aItr)->GetAccessible(); 114cdf0e10cSrcweir } 115cdf0e10cSrcweir rRelationSet.AddRelation( AccessibleRelation( AccessibleRelationType::MEMBER_OF, aSequence ) ); 116cdf0e10cSrcweir } 117cdf0e10cSrcweir } 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir // ----------------------------------------------------------------------------- 121cdf0e10cSrcweir 122cdf0e10cSrcweir void VCLXAccessibleRadioButton::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet ); 125cdf0e10cSrcweir 126cdf0e10cSrcweir VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() ); 127cdf0e10cSrcweir if ( pVCLXRadioButton ) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir rStateSet.AddState( AccessibleStateType::FOCUSABLE ); 130cdf0e10cSrcweir if ( pVCLXRadioButton->getState() ) 131cdf0e10cSrcweir rStateSet.AddState( AccessibleStateType::CHECKED ); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir } 134cdf0e10cSrcweir 135cdf0e10cSrcweir // ----------------------------------------------------------------------------- 136cdf0e10cSrcweir // XInterface 137cdf0e10cSrcweir // ----------------------------------------------------------------------------- 138cdf0e10cSrcweir 139cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleRadioButton, VCLXAccessibleTextComponent, VCLXAccessibleRadioButton_BASE ) 140cdf0e10cSrcweir 141cdf0e10cSrcweir // ----------------------------------------------------------------------------- 142cdf0e10cSrcweir // XTypeProvider 143cdf0e10cSrcweir // ----------------------------------------------------------------------------- 144cdf0e10cSrcweir 145cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleRadioButton, VCLXAccessibleTextComponent, VCLXAccessibleRadioButton_BASE ) 146cdf0e10cSrcweir 147cdf0e10cSrcweir // ----------------------------------------------------------------------------- 148cdf0e10cSrcweir // XServiceInfo 149cdf0e10cSrcweir // ----------------------------------------------------------------------------- 150cdf0e10cSrcweir 151cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleRadioButton::getImplementationName() throw (RuntimeException) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleRadioButton" ); 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir // ----------------------------------------------------------------------------- 157cdf0e10cSrcweir 158cdf0e10cSrcweir Sequence< ::rtl::OUString > VCLXAccessibleRadioButton::getSupportedServiceNames() throw (RuntimeException) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir Sequence< ::rtl::OUString > aNames(1); 161cdf0e10cSrcweir aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleRadioButton" ); 162cdf0e10cSrcweir return aNames; 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir // ----------------------------------------------------------------------------- 166cdf0e10cSrcweir // XAccessibleAction 167cdf0e10cSrcweir // ----------------------------------------------------------------------------- 168cdf0e10cSrcweir 169cdf0e10cSrcweir sal_Int32 VCLXAccessibleRadioButton::getAccessibleActionCount( ) throw (RuntimeException) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 172cdf0e10cSrcweir 173cdf0e10cSrcweir return 1; 174cdf0e10cSrcweir } 175cdf0e10cSrcweir 176cdf0e10cSrcweir // ----------------------------------------------------------------------------- 177cdf0e10cSrcweir 178cdf0e10cSrcweir sal_Bool VCLXAccessibleRadioButton::doAccessibleAction ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 181cdf0e10cSrcweir 182cdf0e10cSrcweir if ( nIndex < 0 || nIndex >= getAccessibleActionCount() ) 183cdf0e10cSrcweir throw IndexOutOfBoundsException(); 184cdf0e10cSrcweir 185cdf0e10cSrcweir VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() ); 186cdf0e10cSrcweir if ( pVCLXRadioButton && !pVCLXRadioButton->getState() ) 187cdf0e10cSrcweir pVCLXRadioButton->setState( sal_True ); 188cdf0e10cSrcweir 189cdf0e10cSrcweir return sal_True; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir // ----------------------------------------------------------------------------- 193cdf0e10cSrcweir 194cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleRadioButton::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 195cdf0e10cSrcweir { 196cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 197cdf0e10cSrcweir 198cdf0e10cSrcweir if ( nIndex < 0 || nIndex >= getAccessibleActionCount() ) 199cdf0e10cSrcweir throw IndexOutOfBoundsException(); 200cdf0e10cSrcweir 201cdf0e10cSrcweir return ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_CLICK ) ); 202cdf0e10cSrcweir } 203cdf0e10cSrcweir 204cdf0e10cSrcweir // ----------------------------------------------------------------------------- 205cdf0e10cSrcweir 206cdf0e10cSrcweir Reference< XAccessibleKeyBinding > VCLXAccessibleRadioButton::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 207cdf0e10cSrcweir { 208cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 209cdf0e10cSrcweir 210cdf0e10cSrcweir if ( nIndex < 0 || nIndex >= getAccessibleActionCount() ) 211cdf0e10cSrcweir throw IndexOutOfBoundsException(); 212cdf0e10cSrcweir 213cdf0e10cSrcweir OAccessibleKeyBindingHelper* pKeyBindingHelper = new OAccessibleKeyBindingHelper(); 214cdf0e10cSrcweir Reference< XAccessibleKeyBinding > xKeyBinding = pKeyBindingHelper; 215cdf0e10cSrcweir 216cdf0e10cSrcweir Window* pWindow = GetWindow(); 217cdf0e10cSrcweir if ( pWindow ) 218cdf0e10cSrcweir { 219cdf0e10cSrcweir KeyEvent aKeyEvent = pWindow->GetActivationKey(); 220cdf0e10cSrcweir KeyCode aKeyCode = aKeyEvent.GetKeyCode(); 221cdf0e10cSrcweir if ( aKeyCode.GetCode() != 0 ) 222cdf0e10cSrcweir { 223cdf0e10cSrcweir awt::KeyStroke aKeyStroke; 224cdf0e10cSrcweir aKeyStroke.Modifiers = 0; 225cdf0e10cSrcweir if ( aKeyCode.IsShift() ) 226cdf0e10cSrcweir aKeyStroke.Modifiers |= awt::KeyModifier::SHIFT; 227cdf0e10cSrcweir if ( aKeyCode.IsMod1() ) 228cdf0e10cSrcweir aKeyStroke.Modifiers |= awt::KeyModifier::MOD1; 229cdf0e10cSrcweir if ( aKeyCode.IsMod2() ) 230cdf0e10cSrcweir aKeyStroke.Modifiers |= awt::KeyModifier::MOD2; 231cdf0e10cSrcweir if ( aKeyCode.IsMod3() ) 232cdf0e10cSrcweir aKeyStroke.Modifiers |= awt::KeyModifier::MOD3; 233cdf0e10cSrcweir aKeyStroke.KeyCode = aKeyCode.GetCode(); 234cdf0e10cSrcweir aKeyStroke.KeyChar = aKeyEvent.GetCharCode(); 235cdf0e10cSrcweir aKeyStroke.KeyFunc = static_cast< sal_Int16 >( aKeyCode.GetFunction() ); 236cdf0e10cSrcweir pKeyBindingHelper->AddKeyBinding( aKeyStroke ); 237cdf0e10cSrcweir } 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240cdf0e10cSrcweir return xKeyBinding; 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir // ----------------------------------------------------------------------------- 244cdf0e10cSrcweir // XAccessibleValue 245cdf0e10cSrcweir // ----------------------------------------------------------------------------- 246cdf0e10cSrcweir 247cdf0e10cSrcweir Any VCLXAccessibleRadioButton::getCurrentValue( ) throw (RuntimeException) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 250cdf0e10cSrcweir 251cdf0e10cSrcweir Any aValue; 252cdf0e10cSrcweir 253cdf0e10cSrcweir VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() ); 254cdf0e10cSrcweir if ( pVCLXRadioButton ) 255cdf0e10cSrcweir aValue <<= (sal_Int32) pVCLXRadioButton->getState(); 256cdf0e10cSrcweir 257cdf0e10cSrcweir return aValue; 258cdf0e10cSrcweir } 259cdf0e10cSrcweir 260cdf0e10cSrcweir // ----------------------------------------------------------------------------- 261cdf0e10cSrcweir 262cdf0e10cSrcweir sal_Bool VCLXAccessibleRadioButton::setCurrentValue( const Any& aNumber ) throw (RuntimeException) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 265cdf0e10cSrcweir 266cdf0e10cSrcweir sal_Bool bReturn = sal_False; 267cdf0e10cSrcweir 268cdf0e10cSrcweir VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() ); 269cdf0e10cSrcweir if ( pVCLXRadioButton ) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir sal_Int32 nValue = 0; 272cdf0e10cSrcweir OSL_VERIFY( aNumber >>= nValue ); 273cdf0e10cSrcweir 274cdf0e10cSrcweir if ( nValue < 0 ) 275cdf0e10cSrcweir nValue = 0; 276cdf0e10cSrcweir else if ( nValue > 1 ) 277cdf0e10cSrcweir nValue = 1; 278cdf0e10cSrcweir 279cdf0e10cSrcweir pVCLXRadioButton->setState( (sal_Bool) nValue ); 280cdf0e10cSrcweir bReturn = sal_True; 281cdf0e10cSrcweir } 282cdf0e10cSrcweir 283cdf0e10cSrcweir return bReturn; 284cdf0e10cSrcweir } 285cdf0e10cSrcweir 286cdf0e10cSrcweir // ----------------------------------------------------------------------------- 287cdf0e10cSrcweir 288cdf0e10cSrcweir Any VCLXAccessibleRadioButton::getMaximumValue( ) throw (RuntimeException) 289cdf0e10cSrcweir { 290cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 291cdf0e10cSrcweir 292cdf0e10cSrcweir Any aValue; 293cdf0e10cSrcweir aValue <<= (sal_Int32) 1; 294cdf0e10cSrcweir 295cdf0e10cSrcweir return aValue; 296cdf0e10cSrcweir } 297cdf0e10cSrcweir 298cdf0e10cSrcweir // ----------------------------------------------------------------------------- 299cdf0e10cSrcweir 300cdf0e10cSrcweir Any VCLXAccessibleRadioButton::getMinimumValue( ) throw (RuntimeException) 301cdf0e10cSrcweir { 302cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 303cdf0e10cSrcweir 304cdf0e10cSrcweir Any aValue; 305cdf0e10cSrcweir aValue <<= (sal_Int32) 0; 306cdf0e10cSrcweir 307cdf0e10cSrcweir return aValue; 308cdf0e10cSrcweir } 309cdf0e10cSrcweir 310cdf0e10cSrcweir // ----------------------------------------------------------------------------- 311