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 10cdf0e10cSrcweir * 11*0841af79SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 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 #include <accessibility/standard/vclxaccessibletextcomponent.hxx> 27cdf0e10cSrcweir #include <toolkit/helper/macros.hxx> 28cdf0e10cSrcweir #include <toolkit/helper/convert.hxx> 29cdf0e10cSrcweir #include <accessibility/helper/characterattributeshelper.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp> 32cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp> 33cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp> 34cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 35cdf0e10cSrcweir #include <comphelper/sequence.hxx> 36cdf0e10cSrcweir #include <vcl/window.hxx> 37cdf0e10cSrcweir #include <vcl/svapp.hxx> 38cdf0e10cSrcweir #include <vcl/unohelp2.hxx> 39cdf0e10cSrcweir #include <vcl/ctrl.hxx> 40cdf0e10cSrcweir 41cdf0e10cSrcweir #include <memory> 42cdf0e10cSrcweir #include <vector> 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 // class VCLXAccessibleTextComponent 54cdf0e10cSrcweir // ---------------------------------------------------- 55cdf0e10cSrcweir 56cdf0e10cSrcweir VCLXAccessibleTextComponent::VCLXAccessibleTextComponent( VCLXWindow* pVCLXWindow ) 57cdf0e10cSrcweir :VCLXAccessibleComponent( pVCLXWindow ) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir if ( GetWindow() ) 60cdf0e10cSrcweir m_sText = OutputDevice::GetNonMnemonicString( GetWindow()->GetText() ); 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir // ----------------------------------------------------------------------------- 64cdf0e10cSrcweir 65cdf0e10cSrcweir VCLXAccessibleTextComponent::~VCLXAccessibleTextComponent() 66cdf0e10cSrcweir { 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir // ----------------------------------------------------------------------------- 70cdf0e10cSrcweir 71cdf0e10cSrcweir void VCLXAccessibleTextComponent::SetText( const ::rtl::OUString& sText ) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir Any aOldValue, aNewValue; 74cdf0e10cSrcweir if ( implInitTextChangedEvent( m_sText, sText, aOldValue, aNewValue ) ) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir m_sText = sText; 77cdf0e10cSrcweir NotifyAccessibleEvent( AccessibleEventId::TEXT_CHANGED, aOldValue, aNewValue ); 78cdf0e10cSrcweir } 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir // ----------------------------------------------------------------------------- 82cdf0e10cSrcweir 83cdf0e10cSrcweir void VCLXAccessibleTextComponent::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir switch ( rVclWindowEvent.GetId() ) 86cdf0e10cSrcweir { 87cdf0e10cSrcweir case VCLEVENT_WINDOW_FRAMETITLECHANGED: 88cdf0e10cSrcweir { 89cdf0e10cSrcweir VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent ); 90cdf0e10cSrcweir SetText( implGetText() ); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir break; 93cdf0e10cSrcweir default: 94cdf0e10cSrcweir VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent ); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir // ----------------------------------------------------------------------------- 99cdf0e10cSrcweir // OCommonAccessibleText 100cdf0e10cSrcweir // ----------------------------------------------------------------------------- 101cdf0e10cSrcweir 102cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleTextComponent::implGetText() 103cdf0e10cSrcweir { 104cdf0e10cSrcweir ::rtl::OUString aText; 105cdf0e10cSrcweir if ( GetWindow() ) 106cdf0e10cSrcweir aText = OutputDevice::GetNonMnemonicString( GetWindow()->GetText() ); 107cdf0e10cSrcweir 108cdf0e10cSrcweir return aText; 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir // ----------------------------------------------------------------------------- 112cdf0e10cSrcweir 113cdf0e10cSrcweir lang::Locale VCLXAccessibleTextComponent::implGetLocale() 114cdf0e10cSrcweir { 115cdf0e10cSrcweir return Application::GetSettings().GetLocale(); 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir // ----------------------------------------------------------------------------- 119cdf0e10cSrcweir 120cdf0e10cSrcweir void VCLXAccessibleTextComponent::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir nStartIndex = 0; 123cdf0e10cSrcweir nEndIndex = 0; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir // ----------------------------------------------------------------------------- 127cdf0e10cSrcweir // XComponent 128cdf0e10cSrcweir // ----------------------------------------------------------------------------- 129cdf0e10cSrcweir 130cdf0e10cSrcweir void VCLXAccessibleTextComponent::disposing() 131cdf0e10cSrcweir { 132cdf0e10cSrcweir VCLXAccessibleComponent::disposing(); 133cdf0e10cSrcweir 134cdf0e10cSrcweir m_sText = ::rtl::OUString(); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir // ----------------------------------------------------------------------------- 138cdf0e10cSrcweir // XInterface 139cdf0e10cSrcweir // ----------------------------------------------------------------------------- 140cdf0e10cSrcweir 141cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleTextComponent, VCLXAccessibleComponent, VCLXAccessibleTextComponent_BASE ) 142cdf0e10cSrcweir 143cdf0e10cSrcweir // ----------------------------------------------------------------------------- 144cdf0e10cSrcweir // XTypeProvider 145cdf0e10cSrcweir // ----------------------------------------------------------------------------- 146cdf0e10cSrcweir 147cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleTextComponent, VCLXAccessibleComponent, VCLXAccessibleTextComponent_BASE ) 148cdf0e10cSrcweir 149cdf0e10cSrcweir // ----------------------------------------------------------------------------- 150cdf0e10cSrcweir // XAccessibleText 151cdf0e10cSrcweir // ----------------------------------------------------------------------------- 152cdf0e10cSrcweir 153cdf0e10cSrcweir sal_Int32 VCLXAccessibleTextComponent::getCaretPosition() throw (RuntimeException) 154cdf0e10cSrcweir { 155cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 156cdf0e10cSrcweir 157cdf0e10cSrcweir return -1; 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir // ----------------------------------------------------------------------------- 161cdf0e10cSrcweir 162cdf0e10cSrcweir sal_Bool VCLXAccessibleTextComponent::setCaretPosition( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 165cdf0e10cSrcweir 166cdf0e10cSrcweir return setSelection( nIndex, nIndex ); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir // ----------------------------------------------------------------------------- 170cdf0e10cSrcweir 171cdf0e10cSrcweir sal_Unicode VCLXAccessibleTextComponent::getCharacter( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 174cdf0e10cSrcweir 175cdf0e10cSrcweir return OCommonAccessibleText::getCharacter( nIndex ); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir // ----------------------------------------------------------------------------- 179cdf0e10cSrcweir 180cdf0e10cSrcweir Sequence< PropertyValue > VCLXAccessibleTextComponent::getCharacterAttributes( sal_Int32 nIndex, const Sequence< ::rtl::OUString >& aRequestedAttributes ) throw (IndexOutOfBoundsException, RuntimeException) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 183cdf0e10cSrcweir 184cdf0e10cSrcweir Sequence< PropertyValue > aValues; 185cdf0e10cSrcweir ::rtl::OUString sText( implGetText() ); 186cdf0e10cSrcweir 187cdf0e10cSrcweir if ( !implIsValidIndex( nIndex, sText.getLength() ) ) 188cdf0e10cSrcweir throw IndexOutOfBoundsException(); 189cdf0e10cSrcweir 190cdf0e10cSrcweir if ( GetWindow() ) 191cdf0e10cSrcweir { 192cdf0e10cSrcweir Font aFont = GetWindow()->GetControlFont(); 193cdf0e10cSrcweir sal_Int32 nBackColor = GetWindow()->GetControlBackground().GetColor(); 194cdf0e10cSrcweir sal_Int32 nColor = GetWindow()->GetControlForeground().GetColor(); 195cdf0e10cSrcweir ::std::auto_ptr< CharacterAttributesHelper > pHelper( new CharacterAttributesHelper( aFont, nBackColor, nColor ) ); 196cdf0e10cSrcweir aValues = pHelper->GetCharacterAttributes( aRequestedAttributes ); 197cdf0e10cSrcweir } 198cdf0e10cSrcweir 199cdf0e10cSrcweir return aValues; 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir // ----------------------------------------------------------------------------- 203cdf0e10cSrcweir 204cdf0e10cSrcweir awt::Rectangle VCLXAccessibleTextComponent::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 205cdf0e10cSrcweir { 206cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 207cdf0e10cSrcweir 208cdf0e10cSrcweir if ( !implIsValidIndex( nIndex, implGetText().getLength() ) ) 209cdf0e10cSrcweir throw IndexOutOfBoundsException(); 210cdf0e10cSrcweir 211cdf0e10cSrcweir awt::Rectangle aRect; 212cdf0e10cSrcweir Control* pControl = static_cast< Control* >( GetWindow() ); 213cdf0e10cSrcweir if ( pControl ) 214cdf0e10cSrcweir aRect = AWTRectangle( pControl->GetCharacterBounds( nIndex ) ); 215cdf0e10cSrcweir 216cdf0e10cSrcweir return aRect; 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir // ----------------------------------------------------------------------------- 220cdf0e10cSrcweir 221cdf0e10cSrcweir sal_Int32 VCLXAccessibleTextComponent::getCharacterCount() throw (RuntimeException) 222cdf0e10cSrcweir { 223cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 224cdf0e10cSrcweir 225cdf0e10cSrcweir return OCommonAccessibleText::getCharacterCount(); 226cdf0e10cSrcweir } 227cdf0e10cSrcweir 228cdf0e10cSrcweir // ----------------------------------------------------------------------------- 229cdf0e10cSrcweir 230cdf0e10cSrcweir sal_Int32 VCLXAccessibleTextComponent::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException) 231cdf0e10cSrcweir { 232cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 233cdf0e10cSrcweir 234cdf0e10cSrcweir sal_Int32 nIndex = -1; 235cdf0e10cSrcweir Control* pControl = static_cast< Control* >( GetWindow() ); 236cdf0e10cSrcweir if ( pControl ) 237cdf0e10cSrcweir nIndex = pControl->GetIndexForPoint( VCLPoint( aPoint ) ); 238cdf0e10cSrcweir 239cdf0e10cSrcweir return nIndex; 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242cdf0e10cSrcweir // ----------------------------------------------------------------------------- 243cdf0e10cSrcweir 244cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleTextComponent::getSelectedText() throw (RuntimeException) 245cdf0e10cSrcweir { 246cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 247cdf0e10cSrcweir 248cdf0e10cSrcweir return OCommonAccessibleText::getSelectedText(); 249cdf0e10cSrcweir } 250cdf0e10cSrcweir 251cdf0e10cSrcweir // ----------------------------------------------------------------------------- 252cdf0e10cSrcweir 253cdf0e10cSrcweir sal_Int32 VCLXAccessibleTextComponent::getSelectionStart() throw (RuntimeException) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 256cdf0e10cSrcweir 257cdf0e10cSrcweir return OCommonAccessibleText::getSelectionStart(); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir 260cdf0e10cSrcweir // ----------------------------------------------------------------------------- 261cdf0e10cSrcweir 262cdf0e10cSrcweir sal_Int32 VCLXAccessibleTextComponent::getSelectionEnd() throw (RuntimeException) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 265cdf0e10cSrcweir 266cdf0e10cSrcweir return OCommonAccessibleText::getSelectionEnd(); 267cdf0e10cSrcweir } 268cdf0e10cSrcweir 269cdf0e10cSrcweir // ----------------------------------------------------------------------------- 270cdf0e10cSrcweir 271cdf0e10cSrcweir sal_Bool VCLXAccessibleTextComponent::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException) 272cdf0e10cSrcweir { 273cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 274cdf0e10cSrcweir 275cdf0e10cSrcweir if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) ) 276cdf0e10cSrcweir throw IndexOutOfBoundsException(); 277cdf0e10cSrcweir 278cdf0e10cSrcweir return sal_False; 279cdf0e10cSrcweir } 280cdf0e10cSrcweir 281cdf0e10cSrcweir // ----------------------------------------------------------------------------- 282cdf0e10cSrcweir 283cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleTextComponent::getText() throw (RuntimeException) 284cdf0e10cSrcweir { 285cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 286cdf0e10cSrcweir 287cdf0e10cSrcweir return OCommonAccessibleText::getText(); 288cdf0e10cSrcweir } 289cdf0e10cSrcweir 290cdf0e10cSrcweir // ----------------------------------------------------------------------------- 291cdf0e10cSrcweir 292cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleTextComponent::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException) 293cdf0e10cSrcweir { 294cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 295cdf0e10cSrcweir 296cdf0e10cSrcweir return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex ); 297cdf0e10cSrcweir } 298cdf0e10cSrcweir 299cdf0e10cSrcweir // ----------------------------------------------------------------------------- 300cdf0e10cSrcweir 301cdf0e10cSrcweir ::com::sun::star::accessibility::TextSegment VCLXAccessibleTextComponent::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 302cdf0e10cSrcweir { 303cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 304cdf0e10cSrcweir 305cdf0e10cSrcweir return OCommonAccessibleText::getTextAtIndex( nIndex, aTextType ); 306cdf0e10cSrcweir } 307cdf0e10cSrcweir 308cdf0e10cSrcweir // ----------------------------------------------------------------------------- 309cdf0e10cSrcweir 310cdf0e10cSrcweir ::com::sun::star::accessibility::TextSegment VCLXAccessibleTextComponent::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 311cdf0e10cSrcweir { 312cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 313cdf0e10cSrcweir 314cdf0e10cSrcweir return OCommonAccessibleText::getTextBeforeIndex( nIndex, aTextType ); 315cdf0e10cSrcweir } 316cdf0e10cSrcweir 317cdf0e10cSrcweir // ----------------------------------------------------------------------------- 318cdf0e10cSrcweir 319cdf0e10cSrcweir ::com::sun::star::accessibility::TextSegment VCLXAccessibleTextComponent::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 320cdf0e10cSrcweir { 321cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 322cdf0e10cSrcweir 323cdf0e10cSrcweir return OCommonAccessibleText::getTextBehindIndex( nIndex, aTextType ); 324cdf0e10cSrcweir } 325cdf0e10cSrcweir 326cdf0e10cSrcweir // ----------------------------------------------------------------------------- 327cdf0e10cSrcweir 328cdf0e10cSrcweir sal_Bool VCLXAccessibleTextComponent::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException) 329cdf0e10cSrcweir { 330cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 331cdf0e10cSrcweir 332cdf0e10cSrcweir sal_Bool bReturn = sal_False; 333cdf0e10cSrcweir 334cdf0e10cSrcweir if ( GetWindow() ) 335cdf0e10cSrcweir { 336cdf0e10cSrcweir Reference< datatransfer::clipboard::XClipboard > xClipboard = GetWindow()->GetClipboard(); 337cdf0e10cSrcweir if ( xClipboard.is() ) 338cdf0e10cSrcweir { 339cdf0e10cSrcweir ::rtl::OUString sText( getTextRange( nStartIndex, nEndIndex ) ); 340cdf0e10cSrcweir 341cdf0e10cSrcweir ::vcl::unohelper::TextDataObject* pDataObj = new ::vcl::unohelper::TextDataObject( sText ); 342cdf0e10cSrcweir const sal_uInt32 nRef = Application::ReleaseSolarMutex(); 343cdf0e10cSrcweir xClipboard->setContents( pDataObj, NULL ); 344cdf0e10cSrcweir 345cdf0e10cSrcweir Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY ); 346cdf0e10cSrcweir if( xFlushableClipboard.is() ) 347cdf0e10cSrcweir xFlushableClipboard->flushClipboard(); 348cdf0e10cSrcweir 349cdf0e10cSrcweir Application::AcquireSolarMutex( nRef ); 350cdf0e10cSrcweir 351cdf0e10cSrcweir bReturn = sal_True; 352cdf0e10cSrcweir } 353cdf0e10cSrcweir } 354cdf0e10cSrcweir 355cdf0e10cSrcweir return bReturn; 356cdf0e10cSrcweir } 357cdf0e10cSrcweir 358cdf0e10cSrcweir // ----------------------------------------------------------------------------- 359