1c82f2877SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3c82f2877SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4c82f2877SAndrew Rist * or more contributor license agreements. See the NOTICE file 5c82f2877SAndrew Rist * distributed with this work for additional information 6c82f2877SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7c82f2877SAndrew Rist * to you under the Apache License, Version 2.0 (the 8c82f2877SAndrew Rist * "License"); you may not use this file except in compliance 9c82f2877SAndrew Rist * with the License. You may obtain a copy of the License at 10c82f2877SAndrew Rist * 11c82f2877SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12c82f2877SAndrew Rist * 13c82f2877SAndrew Rist * Unless required by applicable law or agreed to in writing, 14c82f2877SAndrew Rist * software distributed under the License is distributed on an 15c82f2877SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16c82f2877SAndrew Rist * KIND, either express or implied. See the License for the 17c82f2877SAndrew Rist * specific language governing permissions and limitations 18c82f2877SAndrew Rist * under the License. 19c82f2877SAndrew Rist * 20c82f2877SAndrew Rist *************************************************************/ 21c82f2877SAndrew Rist 22c82f2877SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_accessibility.hxx" 26cdf0e10cSrcweir #include <accessibility/standard/vclxaccessiblemenuitem.hxx> 27cdf0e10cSrcweir #include <accessibility/helper/accresmgr.hxx> 28cdf0e10cSrcweir #include <accessibility/helper/accessiblestrings.hrc> 29cdf0e10cSrcweir #include <toolkit/helper/convert.hxx> 30cdf0e10cSrcweir #include <accessibility/helper/characterattributeshelper.hxx> 31cdf0e10cSrcweir #include <comphelper/accessiblekeybindinghelper.hxx> 32cdf0e10cSrcweir #include <com/sun/star/awt/KeyModifier.hpp> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp> 35cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp> 36cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp> 37cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp> 38cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx> 39cdf0e10cSrcweir #include <comphelper/sequence.hxx> 40cdf0e10cSrcweir #include <vcl/svapp.hxx> 41cdf0e10cSrcweir #include <vcl/window.hxx> 42cdf0e10cSrcweir #include <vcl/menu.hxx> 43cdf0e10cSrcweir #include <vcl/unohelp2.hxx> 44cdf0e10cSrcweir 45cdf0e10cSrcweir #include <memory> 46cdf0e10cSrcweir 47cdf0e10cSrcweir 48cdf0e10cSrcweir using namespace ::com::sun::star::accessibility; 49cdf0e10cSrcweir using namespace ::com::sun::star::uno; 50cdf0e10cSrcweir using namespace ::com::sun::star::beans; 51cdf0e10cSrcweir using namespace ::com::sun::star::lang; 52cdf0e10cSrcweir using namespace ::com::sun::star; 53cdf0e10cSrcweir using namespace ::comphelper; 54cdf0e10cSrcweir 55cdf0e10cSrcweir 56cdf0e10cSrcweir // ----------------------------------------------------------------------------- 57cdf0e10cSrcweir // class VCLXAccessibleMenuItem 58cdf0e10cSrcweir // ----------------------------------------------------------------------------- 59cdf0e10cSrcweir 60cdf0e10cSrcweir VCLXAccessibleMenuItem::VCLXAccessibleMenuItem( Menu* pParent, sal_uInt16 nItemPos, Menu* pMenu ) 61cdf0e10cSrcweir :OAccessibleMenuItemComponent( pParent, nItemPos, pMenu ) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir // ----------------------------------------------------------------------------- 66cdf0e10cSrcweir 67cdf0e10cSrcweir VCLXAccessibleMenuItem::~VCLXAccessibleMenuItem() 68cdf0e10cSrcweir { 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir // ----------------------------------------------------------------------------- 72cdf0e10cSrcweir 73cdf0e10cSrcweir sal_Bool VCLXAccessibleMenuItem::IsFocused() 74cdf0e10cSrcweir { 75cdf0e10cSrcweir return IsHighlighted(); 76cdf0e10cSrcweir } 77cdf0e10cSrcweir 78cdf0e10cSrcweir // ----------------------------------------------------------------------------- 79cdf0e10cSrcweir 80cdf0e10cSrcweir sal_Bool VCLXAccessibleMenuItem::IsSelected() 81cdf0e10cSrcweir { 82cdf0e10cSrcweir return IsHighlighted(); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir // ----------------------------------------------------------------------------- 86cdf0e10cSrcweir 87cdf0e10cSrcweir sal_Bool VCLXAccessibleMenuItem::IsChecked() 88cdf0e10cSrcweir { 89cdf0e10cSrcweir sal_Bool bChecked = sal_False; 90cdf0e10cSrcweir 91cdf0e10cSrcweir if ( m_pParent ) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir sal_uInt16 nItemId = m_pParent->GetItemId( m_nItemPos ); 94cdf0e10cSrcweir if ( m_pParent->IsItemChecked( nItemId ) ) 95cdf0e10cSrcweir bChecked = sal_True; 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir return bChecked; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir // ----------------------------------------------------------------------------- 102cdf0e10cSrcweir 103cdf0e10cSrcweir sal_Bool VCLXAccessibleMenuItem::IsHighlighted() 104cdf0e10cSrcweir { 105cdf0e10cSrcweir sal_Bool bHighlighted = sal_False; 106cdf0e10cSrcweir 107cdf0e10cSrcweir if ( m_pParent && m_pParent->IsHighlighted( m_nItemPos ) ) 108cdf0e10cSrcweir bHighlighted = sal_True; 109cdf0e10cSrcweir 110cdf0e10cSrcweir return bHighlighted; 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir // ----------------------------------------------------------------------------- 114cdf0e10cSrcweir 115cdf0e10cSrcweir void VCLXAccessibleMenuItem::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir OAccessibleMenuItemComponent::FillAccessibleStateSet( rStateSet ); 118cdf0e10cSrcweir 119cdf0e10cSrcweir rStateSet.AddState( AccessibleStateType::FOCUSABLE ); 120cdf0e10cSrcweir 121cdf0e10cSrcweir if ( IsFocused() ) 122cdf0e10cSrcweir rStateSet.AddState( AccessibleStateType::FOCUSED ); 123cdf0e10cSrcweir 124cdf0e10cSrcweir rStateSet.AddState( AccessibleStateType::SELECTABLE ); 125cdf0e10cSrcweir 126cdf0e10cSrcweir if ( IsSelected() ) 127cdf0e10cSrcweir rStateSet.AddState( AccessibleStateType::SELECTED ); 128cdf0e10cSrcweir 129cdf0e10cSrcweir if ( IsChecked() ) 130cdf0e10cSrcweir rStateSet.AddState( AccessibleStateType::CHECKED ); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir // ----------------------------------------------------------------------------- 134cdf0e10cSrcweir // OCommonAccessibleText 135cdf0e10cSrcweir // ----------------------------------------------------------------------------- 136cdf0e10cSrcweir 137cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleMenuItem::implGetText() 138cdf0e10cSrcweir { 139cdf0e10cSrcweir return m_sItemText; 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir // ----------------------------------------------------------------------------- 143cdf0e10cSrcweir 144cdf0e10cSrcweir Locale VCLXAccessibleMenuItem::implGetLocale() 145cdf0e10cSrcweir { 146cdf0e10cSrcweir return Application::GetSettings().GetLocale(); 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir // ----------------------------------------------------------------------------- 150cdf0e10cSrcweir 151cdf0e10cSrcweir void VCLXAccessibleMenuItem::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir nStartIndex = 0; 154cdf0e10cSrcweir nEndIndex = 0; 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir // ----------------------------------------------------------------------------- 158cdf0e10cSrcweir // XInterface 159cdf0e10cSrcweir // ----------------------------------------------------------------------------- 160cdf0e10cSrcweir 161cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleMenuItem, OAccessibleMenuItemComponent, VCLXAccessibleMenuItem_BASE ) 162cdf0e10cSrcweir 163cdf0e10cSrcweir // ----------------------------------------------------------------------------- 164cdf0e10cSrcweir // XTypeProvider 165cdf0e10cSrcweir // ----------------------------------------------------------------------------- 166cdf0e10cSrcweir 167cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleMenuItem, OAccessibleMenuItemComponent, VCLXAccessibleMenuItem_BASE ) 168cdf0e10cSrcweir 169cdf0e10cSrcweir // ----------------------------------------------------------------------------- 170cdf0e10cSrcweir // XServiceInfo 171cdf0e10cSrcweir // ----------------------------------------------------------------------------- 172cdf0e10cSrcweir 173cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleMenuItem::getImplementationName() throw (RuntimeException) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleMenuItem" ); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir // ----------------------------------------------------------------------------- 179cdf0e10cSrcweir 180cdf0e10cSrcweir Sequence< ::rtl::OUString > VCLXAccessibleMenuItem::getSupportedServiceNames() throw (RuntimeException) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir Sequence< ::rtl::OUString > aNames(1); 183cdf0e10cSrcweir aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleMenuItem" ); 184cdf0e10cSrcweir return aNames; 185cdf0e10cSrcweir } 186cdf0e10cSrcweir 187cdf0e10cSrcweir // ----------------------------------------------------------------------------- 188cdf0e10cSrcweir // XAccessibleContext 189cdf0e10cSrcweir // ----------------------------------------------------------------------------- 190cdf0e10cSrcweir 191cdf0e10cSrcweir sal_Int16 VCLXAccessibleMenuItem::getAccessibleRole( ) throw (RuntimeException) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 194*21075d77SSteve Yin // IA2 CWS. MT: We had the aditional roles in UAA for ever, but never used them anywhere. 195*21075d77SSteve Yin // Looks reasonable, but need to verify in Orca and VoiceOver. 196*21075d77SSteve Yin sal_Int16 nRole = AccessibleRole::MENU_ITEM; 197*21075d77SSteve Yin if ( m_pParent ) 198*21075d77SSteve Yin { 199*21075d77SSteve Yin sal_uInt16 nItemId = m_pParent->GetItemId( m_nItemPos ); 200*21075d77SSteve Yin MenuItemBits nItemBits = m_pParent->GetItemBits(nItemId); 201*21075d77SSteve Yin if( nItemBits & MIB_RADIOCHECK) 202*21075d77SSteve Yin nRole = AccessibleRole::RADIO_MENU_ITEM; 203*21075d77SSteve Yin else if( nItemBits & MIB_CHECKABLE) 204*21075d77SSteve Yin nRole = AccessibleRole::CHECK_MENU_ITEM; 205*21075d77SSteve Yin } 206*21075d77SSteve Yin return nRole; 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir // ----------------------------------------------------------------------------- 210cdf0e10cSrcweir // XAccessibleText 211cdf0e10cSrcweir // ----------------------------------------------------------------------------- 212cdf0e10cSrcweir 213cdf0e10cSrcweir sal_Int32 VCLXAccessibleMenuItem::getCaretPosition() throw (RuntimeException) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 216cdf0e10cSrcweir 217cdf0e10cSrcweir return -1; 218cdf0e10cSrcweir } 219cdf0e10cSrcweir 220cdf0e10cSrcweir // ----------------------------------------------------------------------------- 221cdf0e10cSrcweir 222cdf0e10cSrcweir sal_Bool VCLXAccessibleMenuItem::setCaretPosition( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 223cdf0e10cSrcweir { 224cdf0e10cSrcweir 225cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 226cdf0e10cSrcweir 227cdf0e10cSrcweir if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) ) 228cdf0e10cSrcweir throw IndexOutOfBoundsException(); 229cdf0e10cSrcweir 230cdf0e10cSrcweir return sal_False; 231cdf0e10cSrcweir } 232cdf0e10cSrcweir 233cdf0e10cSrcweir // ----------------------------------------------------------------------------- 234cdf0e10cSrcweir 235cdf0e10cSrcweir sal_Unicode VCLXAccessibleMenuItem::getCharacter( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 238cdf0e10cSrcweir 239cdf0e10cSrcweir return OCommonAccessibleText::getCharacter( nIndex ); 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242cdf0e10cSrcweir // ----------------------------------------------------------------------------- 243cdf0e10cSrcweir 244cdf0e10cSrcweir Sequence< PropertyValue > VCLXAccessibleMenuItem::getCharacterAttributes( sal_Int32 nIndex, const Sequence< ::rtl::OUString >& aRequestedAttributes ) throw (IndexOutOfBoundsException, RuntimeException) 245cdf0e10cSrcweir { 246cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 247cdf0e10cSrcweir 248cdf0e10cSrcweir Sequence< PropertyValue > aValues; 249cdf0e10cSrcweir ::rtl::OUString sText( implGetText() ); 250cdf0e10cSrcweir 251cdf0e10cSrcweir if ( !implIsValidIndex( nIndex, sText.getLength() ) ) 252cdf0e10cSrcweir throw IndexOutOfBoundsException(); 253cdf0e10cSrcweir 254cdf0e10cSrcweir Font aFont = Application::GetSettings().GetStyleSettings().GetMenuFont(); 255cdf0e10cSrcweir sal_Int32 nBackColor = getBackground(); 256cdf0e10cSrcweir sal_Int32 nColor = getForeground(); 257cdf0e10cSrcweir ::std::auto_ptr< CharacterAttributesHelper > pHelper( new CharacterAttributesHelper( aFont, nBackColor, nColor ) ); 258cdf0e10cSrcweir aValues = pHelper->GetCharacterAttributes( aRequestedAttributes ); 259cdf0e10cSrcweir 260cdf0e10cSrcweir return aValues; 261cdf0e10cSrcweir } 262cdf0e10cSrcweir 263cdf0e10cSrcweir // ----------------------------------------------------------------------------- 264cdf0e10cSrcweir 265cdf0e10cSrcweir awt::Rectangle VCLXAccessibleMenuItem::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 266cdf0e10cSrcweir { 267cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 268cdf0e10cSrcweir 269cdf0e10cSrcweir if ( !implIsValidIndex( nIndex, implGetText().getLength() ) ) 270cdf0e10cSrcweir throw IndexOutOfBoundsException(); 271cdf0e10cSrcweir 272cdf0e10cSrcweir awt::Rectangle aBounds( 0, 0, 0, 0 ); 273cdf0e10cSrcweir if ( m_pParent ) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir sal_uInt16 nItemId = m_pParent->GetItemId( m_nItemPos ); 276cdf0e10cSrcweir Rectangle aItemRect = m_pParent->GetBoundingRectangle( m_nItemPos ); 277cdf0e10cSrcweir Rectangle aCharRect = m_pParent->GetCharacterBounds( nItemId, nIndex ); 278cdf0e10cSrcweir aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() ); 279cdf0e10cSrcweir aBounds = AWTRectangle( aCharRect ); 280cdf0e10cSrcweir } 281cdf0e10cSrcweir 282cdf0e10cSrcweir return aBounds; 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir // ----------------------------------------------------------------------------- 286cdf0e10cSrcweir 287cdf0e10cSrcweir sal_Int32 VCLXAccessibleMenuItem::getCharacterCount() throw (RuntimeException) 288cdf0e10cSrcweir { 289cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 290cdf0e10cSrcweir 291cdf0e10cSrcweir return OCommonAccessibleText::getCharacterCount(); 292cdf0e10cSrcweir } 293cdf0e10cSrcweir 294cdf0e10cSrcweir // ----------------------------------------------------------------------------- 295cdf0e10cSrcweir 296cdf0e10cSrcweir sal_Int32 VCLXAccessibleMenuItem::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 299cdf0e10cSrcweir 300cdf0e10cSrcweir sal_Int32 nIndex = -1; 301cdf0e10cSrcweir if ( m_pParent ) 302cdf0e10cSrcweir { 303cdf0e10cSrcweir sal_uInt16 nItemId = 0; 304cdf0e10cSrcweir Rectangle aItemRect = m_pParent->GetBoundingRectangle( m_nItemPos ); 305cdf0e10cSrcweir Point aPnt( VCLPoint( aPoint ) ); 306cdf0e10cSrcweir aPnt += aItemRect.TopLeft(); 307cdf0e10cSrcweir sal_Int32 nI = m_pParent->GetIndexForPoint( aPnt, nItemId ); 308cdf0e10cSrcweir if ( nI != -1 && m_pParent->GetItemId( m_nItemPos ) == nItemId ) 309cdf0e10cSrcweir nIndex = nI; 310cdf0e10cSrcweir } 311cdf0e10cSrcweir 312cdf0e10cSrcweir return nIndex; 313cdf0e10cSrcweir } 314cdf0e10cSrcweir 315cdf0e10cSrcweir // ----------------------------------------------------------------------------- 316cdf0e10cSrcweir 317cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleMenuItem::getSelectedText() throw (RuntimeException) 318cdf0e10cSrcweir { 319cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 320cdf0e10cSrcweir 321cdf0e10cSrcweir return OCommonAccessibleText::getSelectedText(); 322cdf0e10cSrcweir } 323cdf0e10cSrcweir 324cdf0e10cSrcweir // ----------------------------------------------------------------------------- 325cdf0e10cSrcweir 326cdf0e10cSrcweir sal_Int32 VCLXAccessibleMenuItem::getSelectionStart() throw (RuntimeException) 327cdf0e10cSrcweir { 328cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 329cdf0e10cSrcweir 330cdf0e10cSrcweir return OCommonAccessibleText::getSelectionStart(); 331cdf0e10cSrcweir } 332cdf0e10cSrcweir 333cdf0e10cSrcweir // ----------------------------------------------------------------------------- 334cdf0e10cSrcweir 335cdf0e10cSrcweir sal_Int32 VCLXAccessibleMenuItem::getSelectionEnd() throw (RuntimeException) 336cdf0e10cSrcweir { 337cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 338cdf0e10cSrcweir 339cdf0e10cSrcweir return OCommonAccessibleText::getSelectionEnd(); 340cdf0e10cSrcweir } 341cdf0e10cSrcweir 342cdf0e10cSrcweir // ----------------------------------------------------------------------------- 343cdf0e10cSrcweir 344cdf0e10cSrcweir sal_Bool VCLXAccessibleMenuItem::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException) 345cdf0e10cSrcweir { 346cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 347cdf0e10cSrcweir 348cdf0e10cSrcweir if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) ) 349cdf0e10cSrcweir throw IndexOutOfBoundsException(); 350cdf0e10cSrcweir 351cdf0e10cSrcweir return sal_False; 352cdf0e10cSrcweir } 353cdf0e10cSrcweir 354cdf0e10cSrcweir // ----------------------------------------------------------------------------- 355cdf0e10cSrcweir 356cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleMenuItem::getText() throw (RuntimeException) 357cdf0e10cSrcweir { 358cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 359cdf0e10cSrcweir 360cdf0e10cSrcweir return OCommonAccessibleText::getText(); 361cdf0e10cSrcweir } 362cdf0e10cSrcweir 363cdf0e10cSrcweir // ----------------------------------------------------------------------------- 364cdf0e10cSrcweir 365cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleMenuItem::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException) 366cdf0e10cSrcweir { 367cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 368cdf0e10cSrcweir 369cdf0e10cSrcweir return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex ); 370cdf0e10cSrcweir } 371cdf0e10cSrcweir 372cdf0e10cSrcweir // ----------------------------------------------------------------------------- 373cdf0e10cSrcweir 374cdf0e10cSrcweir ::com::sun::star::accessibility::TextSegment VCLXAccessibleMenuItem::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 375cdf0e10cSrcweir { 376cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 377cdf0e10cSrcweir 378cdf0e10cSrcweir return OCommonAccessibleText::getTextAtIndex( nIndex, aTextType ); 379cdf0e10cSrcweir } 380cdf0e10cSrcweir 381cdf0e10cSrcweir // ----------------------------------------------------------------------------- 382cdf0e10cSrcweir 383cdf0e10cSrcweir ::com::sun::star::accessibility::TextSegment VCLXAccessibleMenuItem::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 384cdf0e10cSrcweir { 385cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 386cdf0e10cSrcweir 387cdf0e10cSrcweir return OCommonAccessibleText::getTextBeforeIndex( nIndex, aTextType ); 388cdf0e10cSrcweir } 389cdf0e10cSrcweir 390cdf0e10cSrcweir // ----------------------------------------------------------------------------- 391cdf0e10cSrcweir 392cdf0e10cSrcweir ::com::sun::star::accessibility::TextSegment VCLXAccessibleMenuItem::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 393cdf0e10cSrcweir { 394cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 395cdf0e10cSrcweir 396cdf0e10cSrcweir return OCommonAccessibleText::getTextBehindIndex( nIndex, aTextType ); 397cdf0e10cSrcweir } 398cdf0e10cSrcweir 399cdf0e10cSrcweir // ----------------------------------------------------------------------------- 400cdf0e10cSrcweir 401cdf0e10cSrcweir sal_Bool VCLXAccessibleMenuItem::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException) 402cdf0e10cSrcweir { 403cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 404cdf0e10cSrcweir 405cdf0e10cSrcweir sal_Bool bReturn = sal_False; 406cdf0e10cSrcweir 407cdf0e10cSrcweir if ( m_pParent ) 408cdf0e10cSrcweir { 409cdf0e10cSrcweir Window* pWindow = m_pParent->GetWindow(); 410cdf0e10cSrcweir if ( pWindow ) 411cdf0e10cSrcweir { 412cdf0e10cSrcweir Reference< datatransfer::clipboard::XClipboard > xClipboard = pWindow->GetClipboard(); 413cdf0e10cSrcweir if ( xClipboard.is() ) 414cdf0e10cSrcweir { 415cdf0e10cSrcweir ::rtl::OUString sText( getTextRange( nStartIndex, nEndIndex ) ); 416cdf0e10cSrcweir 417cdf0e10cSrcweir ::vcl::unohelper::TextDataObject* pDataObj = new ::vcl::unohelper::TextDataObject( sText ); 418cdf0e10cSrcweir const sal_uInt32 nRef = Application::ReleaseSolarMutex(); 419cdf0e10cSrcweir xClipboard->setContents( pDataObj, NULL ); 420cdf0e10cSrcweir 421cdf0e10cSrcweir Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY ); 422cdf0e10cSrcweir if( xFlushableClipboard.is() ) 423cdf0e10cSrcweir xFlushableClipboard->flushClipboard(); 424cdf0e10cSrcweir 425cdf0e10cSrcweir Application::AcquireSolarMutex( nRef ); 426cdf0e10cSrcweir 427cdf0e10cSrcweir bReturn = sal_True; 428cdf0e10cSrcweir } 429cdf0e10cSrcweir } 430cdf0e10cSrcweir } 431cdf0e10cSrcweir 432cdf0e10cSrcweir return bReturn; 433cdf0e10cSrcweir } 434cdf0e10cSrcweir 435cdf0e10cSrcweir // ----------------------------------------------------------------------------- 436cdf0e10cSrcweir // XAccessibleAction 437cdf0e10cSrcweir // ----------------------------------------------------------------------------- 438cdf0e10cSrcweir 439cdf0e10cSrcweir sal_Int32 VCLXAccessibleMenuItem::getAccessibleActionCount( ) throw (RuntimeException) 440cdf0e10cSrcweir { 441cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 442cdf0e10cSrcweir 443cdf0e10cSrcweir return 1; 444cdf0e10cSrcweir } 445cdf0e10cSrcweir 446cdf0e10cSrcweir // ----------------------------------------------------------------------------- 447cdf0e10cSrcweir 448cdf0e10cSrcweir sal_Bool VCLXAccessibleMenuItem::doAccessibleAction ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 449cdf0e10cSrcweir { 450cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 451cdf0e10cSrcweir 452cdf0e10cSrcweir if ( nIndex < 0 || nIndex >= getAccessibleActionCount() ) 453cdf0e10cSrcweir throw IndexOutOfBoundsException(); 454cdf0e10cSrcweir 455cdf0e10cSrcweir Click(); 456cdf0e10cSrcweir 457cdf0e10cSrcweir return sal_True; 458cdf0e10cSrcweir } 459cdf0e10cSrcweir 460cdf0e10cSrcweir // ----------------------------------------------------------------------------- 461cdf0e10cSrcweir 462cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleMenuItem::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 463cdf0e10cSrcweir { 464cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 465cdf0e10cSrcweir 466cdf0e10cSrcweir if ( nIndex < 0 || nIndex >= getAccessibleActionCount() ) 467cdf0e10cSrcweir throw IndexOutOfBoundsException(); 468*21075d77SSteve Yin //IAccessibility2 Impplementaton 2009----- 469*21075d77SSteve Yin return ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_SELECT ) ); 470*21075d77SSteve Yin //-----IAccessibility2 Impplementaton 2009 471cdf0e10cSrcweir } 472cdf0e10cSrcweir 473cdf0e10cSrcweir // ----------------------------------------------------------------------------- 474cdf0e10cSrcweir 475cdf0e10cSrcweir Reference< XAccessibleKeyBinding > VCLXAccessibleMenuItem::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 476cdf0e10cSrcweir { 477cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 478cdf0e10cSrcweir 479cdf0e10cSrcweir if ( nIndex < 0 || nIndex >= getAccessibleActionCount() ) 480cdf0e10cSrcweir throw IndexOutOfBoundsException(); 481cdf0e10cSrcweir 482cdf0e10cSrcweir OAccessibleKeyBindingHelper* pKeyBindingHelper = new OAccessibleKeyBindingHelper(); 483cdf0e10cSrcweir Reference< XAccessibleKeyBinding > xKeyBinding = pKeyBindingHelper; 484cdf0e10cSrcweir 485cdf0e10cSrcweir if ( m_pParent ) 486cdf0e10cSrcweir { 487cdf0e10cSrcweir // create auto mnemonics 488cdf0e10cSrcweir if ( Application::GetSettings().GetStyleSettings().GetAutoMnemonic() && !( m_pParent->GetMenuFlags() & MENU_FLAG_NOAUTOMNEMONICS ) ) 489cdf0e10cSrcweir m_pParent->CreateAutoMnemonics(); 490cdf0e10cSrcweir 491cdf0e10cSrcweir // activation key 492cdf0e10cSrcweir KeyEvent aKeyEvent = m_pParent->GetActivationKey( m_pParent->GetItemId( m_nItemPos ) ); 493cdf0e10cSrcweir KeyCode aKeyCode = aKeyEvent.GetKeyCode(); 494cdf0e10cSrcweir Sequence< awt::KeyStroke > aSeq1(1); 495cdf0e10cSrcweir aSeq1[0].Modifiers = 0; 496cdf0e10cSrcweir Reference< XAccessible > xParent( getAccessibleParent() ); 497cdf0e10cSrcweir if ( xParent.is() ) 498cdf0e10cSrcweir { 499cdf0e10cSrcweir Reference< XAccessibleContext > xParentContext( xParent->getAccessibleContext() ); 500cdf0e10cSrcweir if ( xParentContext.is() && xParentContext->getAccessibleRole() == AccessibleRole::MENU_BAR ) 501cdf0e10cSrcweir aSeq1[0].Modifiers |= awt::KeyModifier::MOD2; 502cdf0e10cSrcweir } 503cdf0e10cSrcweir aSeq1[0].KeyCode = aKeyCode.GetCode(); 504cdf0e10cSrcweir aSeq1[0].KeyChar = aKeyEvent.GetCharCode(); 505cdf0e10cSrcweir aSeq1[0].KeyFunc = static_cast< sal_Int16 >( aKeyCode.GetFunction() ); 506cdf0e10cSrcweir pKeyBindingHelper->AddKeyBinding( aSeq1 ); 507cdf0e10cSrcweir 508cdf0e10cSrcweir // complete menu activation key sequence 509cdf0e10cSrcweir Sequence< awt::KeyStroke > aSeq; 510cdf0e10cSrcweir if ( xParent.is() ) 511cdf0e10cSrcweir { 512cdf0e10cSrcweir Reference< XAccessibleContext > xParentContext( xParent->getAccessibleContext() ); 513cdf0e10cSrcweir if ( xParentContext.is() && xParentContext->getAccessibleRole() == AccessibleRole::MENU ) 514cdf0e10cSrcweir { 515cdf0e10cSrcweir Reference< XAccessibleAction > xAction( xParentContext, UNO_QUERY ); 516cdf0e10cSrcweir if ( xAction.is() && xAction->getAccessibleActionCount() > 0 ) 517cdf0e10cSrcweir { 518cdf0e10cSrcweir Reference< XAccessibleKeyBinding > xKeyB( xAction->getAccessibleActionKeyBinding( 0 ) ); 519cdf0e10cSrcweir if ( xKeyB.is() && xKeyB->getAccessibleKeyBindingCount() > 1 ) 520cdf0e10cSrcweir aSeq = xKeyB->getAccessibleKeyBinding( 1 ); 521cdf0e10cSrcweir } 522cdf0e10cSrcweir } 523cdf0e10cSrcweir } 524cdf0e10cSrcweir Sequence< awt::KeyStroke > aSeq2 = ::comphelper::concatSequences( aSeq, aSeq1 ); 525cdf0e10cSrcweir pKeyBindingHelper->AddKeyBinding( aSeq2 ); 526cdf0e10cSrcweir 527cdf0e10cSrcweir // accelerator key 528cdf0e10cSrcweir KeyCode aAccelKeyCode = m_pParent->GetAccelKey( m_pParent->GetItemId( m_nItemPos ) ); 529cdf0e10cSrcweir if ( aAccelKeyCode.GetCode() != 0 ) 530cdf0e10cSrcweir { 531cdf0e10cSrcweir Sequence< awt::KeyStroke > aSeq3(1); 532cdf0e10cSrcweir aSeq3[0].Modifiers = 0; 533cdf0e10cSrcweir if ( aAccelKeyCode.IsShift() ) 534cdf0e10cSrcweir aSeq3[0].Modifiers |= awt::KeyModifier::SHIFT; 535cdf0e10cSrcweir if ( aAccelKeyCode.IsMod1() ) 536cdf0e10cSrcweir aSeq3[0].Modifiers |= awt::KeyModifier::MOD1; 537cdf0e10cSrcweir if ( aAccelKeyCode.IsMod2() ) 538cdf0e10cSrcweir aSeq3[0].Modifiers |= awt::KeyModifier::MOD2; 539cdf0e10cSrcweir if ( aAccelKeyCode.IsMod3() ) 540cdf0e10cSrcweir aSeq3[0].Modifiers |= awt::KeyModifier::MOD3; 541cdf0e10cSrcweir aSeq3[0].KeyCode = aAccelKeyCode.GetCode(); 542cdf0e10cSrcweir aSeq3[0].KeyFunc = static_cast< sal_Int16 >( aAccelKeyCode.GetFunction() ); 543cdf0e10cSrcweir pKeyBindingHelper->AddKeyBinding( aSeq3 ); 544cdf0e10cSrcweir } 545cdf0e10cSrcweir } 546cdf0e10cSrcweir 547cdf0e10cSrcweir return xKeyBinding; 548cdf0e10cSrcweir } 549cdf0e10cSrcweir 550cdf0e10cSrcweir // ----------------------------------------------------------------------------- 551cdf0e10cSrcweir // XAccessibleValue 552cdf0e10cSrcweir // ----------------------------------------------------------------------------- 553cdf0e10cSrcweir 554cdf0e10cSrcweir Any VCLXAccessibleMenuItem::getCurrentValue( ) throw (RuntimeException) 555cdf0e10cSrcweir { 556cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 557cdf0e10cSrcweir 558cdf0e10cSrcweir Any aValue; 559cdf0e10cSrcweir if ( IsSelected() ) 560cdf0e10cSrcweir aValue <<= (sal_Int32) 1; 561cdf0e10cSrcweir else 562cdf0e10cSrcweir aValue <<= (sal_Int32) 0; 563cdf0e10cSrcweir 564cdf0e10cSrcweir return aValue; 565cdf0e10cSrcweir } 566cdf0e10cSrcweir 567cdf0e10cSrcweir // ----------------------------------------------------------------------------- 568cdf0e10cSrcweir 569cdf0e10cSrcweir sal_Bool VCLXAccessibleMenuItem::setCurrentValue( const Any& aNumber ) throw (RuntimeException) 570cdf0e10cSrcweir { 571cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 572cdf0e10cSrcweir 573cdf0e10cSrcweir sal_Bool bReturn = sal_False; 574cdf0e10cSrcweir sal_Int32 nValue = 0; 575cdf0e10cSrcweir OSL_VERIFY( aNumber >>= nValue ); 576cdf0e10cSrcweir 577cdf0e10cSrcweir if ( nValue <= 0 ) 578cdf0e10cSrcweir { 579cdf0e10cSrcweir DeSelect(); 580cdf0e10cSrcweir bReturn = sal_True; 581cdf0e10cSrcweir } 582cdf0e10cSrcweir else if ( nValue >= 1 ) 583cdf0e10cSrcweir { 584cdf0e10cSrcweir Select(); 585cdf0e10cSrcweir bReturn = sal_True; 586cdf0e10cSrcweir } 587cdf0e10cSrcweir 588cdf0e10cSrcweir return bReturn; 589cdf0e10cSrcweir } 590cdf0e10cSrcweir 591cdf0e10cSrcweir // ----------------------------------------------------------------------------- 592cdf0e10cSrcweir 593cdf0e10cSrcweir Any VCLXAccessibleMenuItem::getMaximumValue( ) throw (RuntimeException) 594cdf0e10cSrcweir { 595cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 596cdf0e10cSrcweir 597cdf0e10cSrcweir Any aValue; 598cdf0e10cSrcweir aValue <<= (sal_Int32) 1; 599cdf0e10cSrcweir 600cdf0e10cSrcweir return aValue; 601cdf0e10cSrcweir } 602cdf0e10cSrcweir 603cdf0e10cSrcweir // ----------------------------------------------------------------------------- 604cdf0e10cSrcweir 605cdf0e10cSrcweir Any VCLXAccessibleMenuItem::getMinimumValue( ) throw (RuntimeException) 606cdf0e10cSrcweir { 607cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 608cdf0e10cSrcweir 609cdf0e10cSrcweir Any aValue; 610cdf0e10cSrcweir aValue <<= (sal_Int32) 0; 611cdf0e10cSrcweir 612cdf0e10cSrcweir return aValue; 613cdf0e10cSrcweir } 614cdf0e10cSrcweir 615cdf0e10cSrcweir // ----------------------------------------------------------------------------- 616