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