10841af79SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 30841af79SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 40841af79SAndrew Rist * or more contributor license agreements. See the NOTICE file 50841af79SAndrew Rist * distributed with this work for additional information 60841af79SAndrew Rist * regarding copyright ownership. The ASF licenses this file 70841af79SAndrew Rist * to you under the Apache License, Version 2.0 (the 80841af79SAndrew Rist * "License"); you may not use this file except in compliance 90841af79SAndrew Rist * with the License. You may obtain a copy of the License at 100841af79SAndrew Rist * 110841af79SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 120841af79SAndrew Rist * 130841af79SAndrew Rist * Unless required by applicable law or agreed to in writing, 140841af79SAndrew Rist * software distributed under the License is distributed on an 150841af79SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 160841af79SAndrew Rist * KIND, either express or implied. See the License for the 170841af79SAndrew Rist * specific language governing permissions and limitations 180841af79SAndrew Rist * under the License. 190841af79SAndrew Rist * 200841af79SAndrew Rist *************************************************************/ 210841af79SAndrew Rist 220841af79SAndrew 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/vclxaccessiblecheckbox.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <toolkit/awt/vclxwindows.hxx> 31cdf0e10cSrcweir #include <accessibility/helper/accresmgr.hxx> 32cdf0e10cSrcweir #include <accessibility/helper/accessiblestrings.hrc> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx> 35cdf0e10cSrcweir #include <comphelper/accessiblekeybindinghelper.hxx> 36cdf0e10cSrcweir #include <com/sun/star/awt/KeyModifier.hpp> 37cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp> 38cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp> 39cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 40cdf0e10cSrcweir #include <comphelper/sequence.hxx> 41cdf0e10cSrcweir 42cdf0e10cSrcweir #include <vcl/button.hxx> 43cdf0e10cSrcweir 44cdf0e10cSrcweir using namespace ::com::sun::star; 45cdf0e10cSrcweir using namespace ::com::sun::star::uno; 46cdf0e10cSrcweir using namespace ::com::sun::star::lang; 47cdf0e10cSrcweir using namespace ::com::sun::star::beans; 48cdf0e10cSrcweir using namespace ::com::sun::star::accessibility; 49cdf0e10cSrcweir using namespace ::comphelper; 50cdf0e10cSrcweir 51cdf0e10cSrcweir 52cdf0e10cSrcweir // ----------------------------------------------------------------------------- 53cdf0e10cSrcweir // VCLXAccessibleCheckBox 54cdf0e10cSrcweir // ----------------------------------------------------------------------------- 55cdf0e10cSrcweir 56cdf0e10cSrcweir VCLXAccessibleCheckBox::VCLXAccessibleCheckBox( VCLXWindow* pVCLWindow ) 57cdf0e10cSrcweir :VCLXAccessibleTextComponent( pVCLWindow ) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir m_bChecked = IsChecked(); 60cdf0e10cSrcweir m_bIndeterminate = IsIndeterminate(); 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir // ----------------------------------------------------------------------------- 64cdf0e10cSrcweir 65cdf0e10cSrcweir VCLXAccessibleCheckBox::~VCLXAccessibleCheckBox() 66cdf0e10cSrcweir { 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir // ----------------------------------------------------------------------------- 70cdf0e10cSrcweir 71cdf0e10cSrcweir bool VCLXAccessibleCheckBox::IsChecked() 72cdf0e10cSrcweir { 73cdf0e10cSrcweir bool bChecked = false; 74cdf0e10cSrcweir 75cdf0e10cSrcweir VCLXCheckBox* pVCLXCheckBox = static_cast< VCLXCheckBox* >( GetVCLXWindow() ); 76cdf0e10cSrcweir if ( pVCLXCheckBox && pVCLXCheckBox->getState() == (sal_Int16) 1 ) 77cdf0e10cSrcweir bChecked = true; 78cdf0e10cSrcweir 79cdf0e10cSrcweir return bChecked; 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir // ----------------------------------------------------------------------------- 83cdf0e10cSrcweir 84cdf0e10cSrcweir bool VCLXAccessibleCheckBox::IsIndeterminate() 85cdf0e10cSrcweir { 86cdf0e10cSrcweir bool bIndeterminate = false; 87cdf0e10cSrcweir 88cdf0e10cSrcweir VCLXCheckBox* pVCLXCheckBox = static_cast< VCLXCheckBox* >( GetVCLXWindow() ); 89cdf0e10cSrcweir if ( pVCLXCheckBox && pVCLXCheckBox->getState() == (sal_Int16) 2 ) 90cdf0e10cSrcweir bIndeterminate = true; 91cdf0e10cSrcweir 92cdf0e10cSrcweir return bIndeterminate; 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir // ----------------------------------------------------------------------------- 96cdf0e10cSrcweir 97cdf0e10cSrcweir void VCLXAccessibleCheckBox::SetChecked( bool bChecked ) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir if ( m_bChecked != bChecked ) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir Any aOldValue, aNewValue; 102cdf0e10cSrcweir if ( m_bChecked ) 103cdf0e10cSrcweir aOldValue <<= AccessibleStateType::CHECKED; 104cdf0e10cSrcweir else 105cdf0e10cSrcweir aNewValue <<= AccessibleStateType::CHECKED; 106cdf0e10cSrcweir m_bChecked = bChecked; 107cdf0e10cSrcweir NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); 108cdf0e10cSrcweir } 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir // ----------------------------------------------------------------------------- 112cdf0e10cSrcweir 113cdf0e10cSrcweir void VCLXAccessibleCheckBox::SetIndeterminate( bool bIndeterminate ) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir if ( m_bIndeterminate != bIndeterminate ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir Any aOldValue, aNewValue; 118cdf0e10cSrcweir if ( m_bIndeterminate ) 119cdf0e10cSrcweir aOldValue <<= AccessibleStateType::INDETERMINATE; 120cdf0e10cSrcweir else 121cdf0e10cSrcweir aNewValue <<= AccessibleStateType::INDETERMINATE; 122cdf0e10cSrcweir m_bIndeterminate = bIndeterminate; 123cdf0e10cSrcweir NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir // ----------------------------------------------------------------------------- 128cdf0e10cSrcweir 129cdf0e10cSrcweir void VCLXAccessibleCheckBox::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir switch ( rVclWindowEvent.GetId() ) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir case VCLEVENT_CHECKBOX_TOGGLE: 134cdf0e10cSrcweir { 135cdf0e10cSrcweir SetChecked( IsChecked() ); 136cdf0e10cSrcweir SetIndeterminate( IsIndeterminate() ); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir break; 139cdf0e10cSrcweir default: 140cdf0e10cSrcweir VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent ); 141cdf0e10cSrcweir } 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir // ----------------------------------------------------------------------------- 145cdf0e10cSrcweir 146cdf0e10cSrcweir void VCLXAccessibleCheckBox::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet ) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet ); 149cdf0e10cSrcweir 150cdf0e10cSrcweir rStateSet.AddState( AccessibleStateType::FOCUSABLE ); 151cdf0e10cSrcweir 152cdf0e10cSrcweir if ( IsChecked() ) 153cdf0e10cSrcweir rStateSet.AddState( AccessibleStateType::CHECKED ); 154cdf0e10cSrcweir 155cdf0e10cSrcweir if ( IsIndeterminate() ) 156cdf0e10cSrcweir rStateSet.AddState( AccessibleStateType::INDETERMINATE ); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir // ----------------------------------------------------------------------------- 160cdf0e10cSrcweir // XInterface 161cdf0e10cSrcweir // ----------------------------------------------------------------------------- 162cdf0e10cSrcweir 163cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleCheckBox, VCLXAccessibleTextComponent, VCLXAccessibleCheckBox_BASE ) 164cdf0e10cSrcweir 165cdf0e10cSrcweir // ----------------------------------------------------------------------------- 166cdf0e10cSrcweir // XTypeProvider 167cdf0e10cSrcweir // ----------------------------------------------------------------------------- 168cdf0e10cSrcweir 169cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleCheckBox, VCLXAccessibleTextComponent, VCLXAccessibleCheckBox_BASE ) 170cdf0e10cSrcweir 171cdf0e10cSrcweir // ----------------------------------------------------------------------------- 172cdf0e10cSrcweir // XServiceInfo 173cdf0e10cSrcweir // ----------------------------------------------------------------------------- 174cdf0e10cSrcweir 175cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleCheckBox::getImplementationName() throw (RuntimeException) 176cdf0e10cSrcweir { 177cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleCheckBox" ); 178cdf0e10cSrcweir } 179cdf0e10cSrcweir 180cdf0e10cSrcweir // ----------------------------------------------------------------------------- 181cdf0e10cSrcweir 182cdf0e10cSrcweir Sequence< ::rtl::OUString > VCLXAccessibleCheckBox::getSupportedServiceNames() throw (RuntimeException) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir Sequence< ::rtl::OUString > aNames(1); 185cdf0e10cSrcweir aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleCheckBox" ); 186cdf0e10cSrcweir return aNames; 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir // ----------------------------------------------------------------------------- 190cdf0e10cSrcweir // XAccessibleAction 191cdf0e10cSrcweir // ----------------------------------------------------------------------------- 192cdf0e10cSrcweir 193cdf0e10cSrcweir sal_Int32 VCLXAccessibleCheckBox::getAccessibleActionCount( ) throw (RuntimeException) 194cdf0e10cSrcweir { 195cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 196cdf0e10cSrcweir 197cdf0e10cSrcweir return 1; 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir // ----------------------------------------------------------------------------- 201cdf0e10cSrcweir 202cdf0e10cSrcweir sal_Bool VCLXAccessibleCheckBox::doAccessibleAction ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 205cdf0e10cSrcweir 206cdf0e10cSrcweir if ( nIndex < 0 || nIndex >= getAccessibleActionCount() ) 207cdf0e10cSrcweir throw IndexOutOfBoundsException(); 208cdf0e10cSrcweir 209cdf0e10cSrcweir CheckBox* pCheckBox = (CheckBox*) GetWindow(); 210cdf0e10cSrcweir VCLXCheckBox* pVCLXCheckBox = static_cast< VCLXCheckBox* >( GetVCLXWindow() ); 211cdf0e10cSrcweir if ( pCheckBox && pVCLXCheckBox ) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir sal_Int32 nValueMin = (sal_Int32) 0; 214cdf0e10cSrcweir sal_Int32 nValueMax = (sal_Int32) 1; 215cdf0e10cSrcweir 216cdf0e10cSrcweir if ( pCheckBox->IsTriStateEnabled() ) 217cdf0e10cSrcweir nValueMax = (sal_Int32) 2; 218cdf0e10cSrcweir 219cdf0e10cSrcweir sal_Int32 nValue = (sal_Int32) pVCLXCheckBox->getState(); 220cdf0e10cSrcweir 221cdf0e10cSrcweir ++nValue; 222cdf0e10cSrcweir 223cdf0e10cSrcweir if ( nValue > nValueMax ) 224cdf0e10cSrcweir nValue = nValueMin; 225cdf0e10cSrcweir 226cdf0e10cSrcweir pVCLXCheckBox->setState( (sal_Int16) nValue ); 227cdf0e10cSrcweir } 228cdf0e10cSrcweir 229cdf0e10cSrcweir return sal_True; 230cdf0e10cSrcweir } 231cdf0e10cSrcweir 232cdf0e10cSrcweir // ----------------------------------------------------------------------------- 233cdf0e10cSrcweir 234cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleCheckBox::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 235cdf0e10cSrcweir { 236cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 237cdf0e10cSrcweir 238cdf0e10cSrcweir if ( nIndex < 0 || nIndex >= getAccessibleActionCount() ) 239cdf0e10cSrcweir throw IndexOutOfBoundsException(); 240cdf0e10cSrcweir 241*21075d77SSteve Yin //IAccessibility2 Implementation 2009----- 242*21075d77SSteve Yin // return ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_CLICK ) ); 243*21075d77SSteve Yin //-----IAccessibility2 Implementation 2009 244*21075d77SSteve Yin if(IsChecked()) 245*21075d77SSteve Yin return ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_UNCHECK ) ); 246*21075d77SSteve Yin else 247*21075d77SSteve Yin return ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_CHECK ) ); 248cdf0e10cSrcweir } 249cdf0e10cSrcweir 250cdf0e10cSrcweir // ----------------------------------------------------------------------------- 251cdf0e10cSrcweir 252cdf0e10cSrcweir Reference< XAccessibleKeyBinding > VCLXAccessibleCheckBox::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 253cdf0e10cSrcweir { 254cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 255cdf0e10cSrcweir 256cdf0e10cSrcweir if ( nIndex < 0 || nIndex >= getAccessibleActionCount() ) 257cdf0e10cSrcweir throw IndexOutOfBoundsException(); 258cdf0e10cSrcweir 259cdf0e10cSrcweir OAccessibleKeyBindingHelper* pKeyBindingHelper = new OAccessibleKeyBindingHelper(); 260cdf0e10cSrcweir Reference< XAccessibleKeyBinding > xKeyBinding = pKeyBindingHelper; 261cdf0e10cSrcweir 262cdf0e10cSrcweir Window* pWindow = GetWindow(); 263cdf0e10cSrcweir if ( pWindow ) 264cdf0e10cSrcweir { 265cdf0e10cSrcweir KeyEvent aKeyEvent = pWindow->GetActivationKey(); 266cdf0e10cSrcweir KeyCode aKeyCode = aKeyEvent.GetKeyCode(); 267cdf0e10cSrcweir if ( aKeyCode.GetCode() != 0 ) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir awt::KeyStroke aKeyStroke; 270cdf0e10cSrcweir aKeyStroke.Modifiers = 0; 271cdf0e10cSrcweir if ( aKeyCode.IsShift() ) 272cdf0e10cSrcweir aKeyStroke.Modifiers |= awt::KeyModifier::SHIFT; 273cdf0e10cSrcweir if ( aKeyCode.IsMod1() ) 274cdf0e10cSrcweir aKeyStroke.Modifiers |= awt::KeyModifier::MOD1; 275cdf0e10cSrcweir if ( aKeyCode.IsMod2() ) 276cdf0e10cSrcweir aKeyStroke.Modifiers |= awt::KeyModifier::MOD2; 277cdf0e10cSrcweir if ( aKeyCode.IsMod3() ) 278cdf0e10cSrcweir aKeyStroke.Modifiers |= awt::KeyModifier::MOD3; 279cdf0e10cSrcweir aKeyStroke.KeyCode = aKeyCode.GetCode(); 280cdf0e10cSrcweir aKeyStroke.KeyChar = aKeyEvent.GetCharCode(); 281cdf0e10cSrcweir aKeyStroke.KeyFunc = static_cast< sal_Int16 >( aKeyCode.GetFunction() ); 282cdf0e10cSrcweir pKeyBindingHelper->AddKeyBinding( aKeyStroke ); 283cdf0e10cSrcweir } 284cdf0e10cSrcweir } 285cdf0e10cSrcweir 286cdf0e10cSrcweir return xKeyBinding; 287cdf0e10cSrcweir } 288cdf0e10cSrcweir 289cdf0e10cSrcweir // ----------------------------------------------------------------------------- 290cdf0e10cSrcweir // XAccessibleValue 291cdf0e10cSrcweir // ----------------------------------------------------------------------------- 292cdf0e10cSrcweir 293cdf0e10cSrcweir Any VCLXAccessibleCheckBox::getCurrentValue( ) throw (RuntimeException) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 296cdf0e10cSrcweir 297cdf0e10cSrcweir Any aValue; 298cdf0e10cSrcweir 299cdf0e10cSrcweir VCLXCheckBox* pVCLXCheckBox = static_cast< VCLXCheckBox* >( GetVCLXWindow() ); 300cdf0e10cSrcweir if ( pVCLXCheckBox ) 301cdf0e10cSrcweir aValue <<= (sal_Int32) pVCLXCheckBox->getState(); 302cdf0e10cSrcweir 303cdf0e10cSrcweir return aValue; 304cdf0e10cSrcweir } 305cdf0e10cSrcweir 306cdf0e10cSrcweir // ----------------------------------------------------------------------------- 307cdf0e10cSrcweir 308cdf0e10cSrcweir sal_Bool VCLXAccessibleCheckBox::setCurrentValue( const Any& aNumber ) throw (RuntimeException) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 311cdf0e10cSrcweir 312cdf0e10cSrcweir sal_Bool bReturn = sal_False; 313cdf0e10cSrcweir 314cdf0e10cSrcweir VCLXCheckBox* pVCLXCheckBox = static_cast< VCLXCheckBox* >( GetVCLXWindow() ); 315cdf0e10cSrcweir if ( pVCLXCheckBox ) 316cdf0e10cSrcweir { 317cdf0e10cSrcweir sal_Int32 nValue = 0, nValueMin = 0, nValueMax = 0; 318cdf0e10cSrcweir OSL_VERIFY( aNumber >>= nValue ); 319cdf0e10cSrcweir OSL_VERIFY( getMinimumValue() >>= nValueMin ); 320cdf0e10cSrcweir OSL_VERIFY( getMaximumValue() >>= nValueMax ); 321cdf0e10cSrcweir 322cdf0e10cSrcweir if ( nValue < nValueMin ) 323cdf0e10cSrcweir nValue = nValueMin; 324cdf0e10cSrcweir else if ( nValue > nValueMax ) 325cdf0e10cSrcweir nValue = nValueMax; 326cdf0e10cSrcweir 327cdf0e10cSrcweir pVCLXCheckBox->setState( (sal_Int16) nValue ); 328cdf0e10cSrcweir bReturn = sal_True; 329cdf0e10cSrcweir } 330cdf0e10cSrcweir 331cdf0e10cSrcweir return bReturn; 332cdf0e10cSrcweir } 333cdf0e10cSrcweir 334cdf0e10cSrcweir // ----------------------------------------------------------------------------- 335cdf0e10cSrcweir 336cdf0e10cSrcweir Any VCLXAccessibleCheckBox::getMaximumValue( ) throw (RuntimeException) 337cdf0e10cSrcweir { 338cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 339cdf0e10cSrcweir 340cdf0e10cSrcweir Any aValue; 341cdf0e10cSrcweir 342cdf0e10cSrcweir CheckBox* pCheckBox = (CheckBox*) GetWindow(); 343cdf0e10cSrcweir if ( pCheckBox && pCheckBox->IsTriStateEnabled() ) 344cdf0e10cSrcweir aValue <<= (sal_Int32) 2; 345cdf0e10cSrcweir else 346cdf0e10cSrcweir aValue <<= (sal_Int32) 1; 347cdf0e10cSrcweir 348cdf0e10cSrcweir return aValue; 349cdf0e10cSrcweir } 350cdf0e10cSrcweir 351cdf0e10cSrcweir // ----------------------------------------------------------------------------- 352cdf0e10cSrcweir 353cdf0e10cSrcweir Any VCLXAccessibleCheckBox::getMinimumValue( ) throw (RuntimeException) 354cdf0e10cSrcweir { 355cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 356cdf0e10cSrcweir 357cdf0e10cSrcweir Any aValue; 358cdf0e10cSrcweir aValue <<= (sal_Int32) 0; 359cdf0e10cSrcweir 360cdf0e10cSrcweir return aValue; 361cdf0e10cSrcweir } 362cdf0e10cSrcweir 363cdf0e10cSrcweir // ----------------------------------------------------------------------------- 364