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 27cdf0e10cSrcweir // includes -------------------------------------------------------------- 28cdf0e10cSrcweir #include <accessibility/standard/vclxaccessibleedit.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <toolkit/awt/vclxwindows.hxx> 31cdf0e10cSrcweir #include <toolkit/helper/convert.hxx> 32cdf0e10cSrcweir #include <accessibility/helper/accresmgr.hxx> 33cdf0e10cSrcweir #include <accessibility/helper/accessiblestrings.hrc> 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx> 36cdf0e10cSrcweir #include <unotools/accessiblerelationsethelper.hxx> 37cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp> 38cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp> 39cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp> 40cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp> 41cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 42cdf0e10cSrcweir #include <comphelper/sequence.hxx> 43cdf0e10cSrcweir #include <vcl/svapp.hxx> 44cdf0e10cSrcweir #include <vcl/window.hxx> 45cdf0e10cSrcweir #include <vcl/edit.hxx> 46cdf0e10cSrcweir #include <sot/exchange.hxx> 47cdf0e10cSrcweir #include <sot/formats.hxx> 48cdf0e10cSrcweir 49cdf0e10cSrcweir #include <algorithm> 50cdf0e10cSrcweir 51cdf0e10cSrcweir using namespace ::com::sun::star; 52cdf0e10cSrcweir using namespace ::com::sun::star::uno; 53cdf0e10cSrcweir using namespace ::com::sun::star::lang; 54cdf0e10cSrcweir using namespace ::com::sun::star::beans; 55cdf0e10cSrcweir using namespace ::com::sun::star::accessibility; 56cdf0e10cSrcweir using namespace ::comphelper; 57cdf0e10cSrcweir 58cdf0e10cSrcweir 59cdf0e10cSrcweir // ----------------------------------------------------------------------------- 60cdf0e10cSrcweir // VCLXAccessibleEdit 61cdf0e10cSrcweir // ----------------------------------------------------------------------------- 62cdf0e10cSrcweir 63cdf0e10cSrcweir VCLXAccessibleEdit::VCLXAccessibleEdit( VCLXWindow* pVCLWindow ) 64cdf0e10cSrcweir :VCLXAccessibleTextComponent( pVCLWindow ) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir m_nSelectionStart = getSelectionStart(); 67cdf0e10cSrcweir m_nCaretPosition = getCaretPosition(); 68cdf0e10cSrcweir } 69cdf0e10cSrcweir 70cdf0e10cSrcweir // ----------------------------------------------------------------------------- 71cdf0e10cSrcweir 72cdf0e10cSrcweir VCLXAccessibleEdit::~VCLXAccessibleEdit() 73cdf0e10cSrcweir { 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir // ----------------------------------------------------------------------------- 77cdf0e10cSrcweir 78cdf0e10cSrcweir void VCLXAccessibleEdit::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir switch ( rVclWindowEvent.GetId() ) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir case VCLEVENT_EDIT_MODIFY: 83cdf0e10cSrcweir { 84cdf0e10cSrcweir SetText( implGetText() ); 85cdf0e10cSrcweir } 86cdf0e10cSrcweir break; 87cdf0e10cSrcweir case VCLEVENT_EDIT_SELECTIONCHANGED: 88cdf0e10cSrcweir { 89cdf0e10cSrcweir sal_Int32 nOldCaretPosition = m_nCaretPosition; 90cdf0e10cSrcweir sal_Int32 nOldSelectionStart = m_nSelectionStart; 91cdf0e10cSrcweir 92cdf0e10cSrcweir m_nCaretPosition = getCaretPosition(); 93cdf0e10cSrcweir m_nSelectionStart = getSelectionStart(); 94cdf0e10cSrcweir 95cdf0e10cSrcweir Window* pWindow = GetWindow(); 96cdf0e10cSrcweir if ( pWindow && pWindow->HasChildPathFocus() ) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir if ( m_nCaretPosition != nOldCaretPosition ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir Any aOldValue, aNewValue; 101cdf0e10cSrcweir aOldValue <<= (sal_Int32) nOldCaretPosition; 102cdf0e10cSrcweir aNewValue <<= (sal_Int32) m_nCaretPosition; 103cdf0e10cSrcweir NotifyAccessibleEvent( AccessibleEventId::CARET_CHANGED, aOldValue, aNewValue ); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir // #i104470# VCL only has SELECTION_CHANGED, but UAA distinguishes between SELECTION_CHANGED and CARET_CHANGED 107cdf0e10cSrcweir sal_Bool bHasSelection = ( m_nSelectionStart != m_nCaretPosition ); 108cdf0e10cSrcweir sal_Bool bHadSelection = ( nOldSelectionStart != nOldCaretPosition ); 109cdf0e10cSrcweir if ( ( bHasSelection != bHadSelection ) || ( bHasSelection && ( ( m_nCaretPosition != nOldCaretPosition ) || ( m_nSelectionStart != nOldSelectionStart ) ) ) ) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir NotifyAccessibleEvent( AccessibleEventId::TEXT_SELECTION_CHANGED, Any(), Any() ); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir } 115cdf0e10cSrcweir } 116cdf0e10cSrcweir break; 117cdf0e10cSrcweir default: 118cdf0e10cSrcweir VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent ); 119cdf0e10cSrcweir } 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir // ----------------------------------------------------------------------------- 123cdf0e10cSrcweir 124cdf0e10cSrcweir void VCLXAccessibleEdit::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet ) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet ); 127cdf0e10cSrcweir 128cdf0e10cSrcweir VCLXEdit* pVCLXEdit = static_cast< VCLXEdit* >( GetVCLXWindow() ); 129cdf0e10cSrcweir if ( pVCLXEdit ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir rStateSet.AddState( AccessibleStateType::FOCUSABLE ); 132cdf0e10cSrcweir rStateSet.AddState( AccessibleStateType::SINGLE_LINE ); 133cdf0e10cSrcweir if ( pVCLXEdit->isEditable() ) 134cdf0e10cSrcweir rStateSet.AddState( AccessibleStateType::EDITABLE ); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir // ----------------------------------------------------------------------------- 139cdf0e10cSrcweir // OCommonAccessibleText 140cdf0e10cSrcweir // ----------------------------------------------------------------------------- 141cdf0e10cSrcweir 142cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleEdit::implGetText() 143cdf0e10cSrcweir { 144cdf0e10cSrcweir ::rtl::OUString aText; 145cdf0e10cSrcweir 146cdf0e10cSrcweir Edit* pEdit = static_cast< Edit* >( GetWindow() ); 147cdf0e10cSrcweir if ( pEdit ) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir aText = OutputDevice::GetNonMnemonicString( pEdit->GetText() ); 150cdf0e10cSrcweir 151cdf0e10cSrcweir if ( getAccessibleRole() == AccessibleRole::PASSWORD_TEXT ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir xub_Unicode cEchoChar = pEdit->GetEchoChar(); 154cdf0e10cSrcweir if ( !cEchoChar ) 155cdf0e10cSrcweir cEchoChar = '*'; 156cdf0e10cSrcweir XubString sTmp; 157cdf0e10cSrcweir aText = sTmp.Fill( (sal_uInt16)aText.getLength(), cEchoChar ); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir return aText; 162cdf0e10cSrcweir } 163cdf0e10cSrcweir 164cdf0e10cSrcweir // ----------------------------------------------------------------------------- 165cdf0e10cSrcweir 166cdf0e10cSrcweir void VCLXAccessibleEdit::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir awt::Selection aSelection; 169cdf0e10cSrcweir VCLXEdit* pVCLXEdit = static_cast< VCLXEdit* >( GetVCLXWindow() ); 170cdf0e10cSrcweir if ( pVCLXEdit ) 171cdf0e10cSrcweir aSelection = pVCLXEdit->getSelection(); 172cdf0e10cSrcweir 173cdf0e10cSrcweir nStartIndex = aSelection.Min; 174cdf0e10cSrcweir nEndIndex = aSelection.Max; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir // ----------------------------------------------------------------------------- 178cdf0e10cSrcweir // XInterface 179cdf0e10cSrcweir // ----------------------------------------------------------------------------- 180cdf0e10cSrcweir 181cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleEdit, VCLXAccessibleTextComponent, VCLXAccessibleEdit_BASE ) 182cdf0e10cSrcweir 183cdf0e10cSrcweir // ----------------------------------------------------------------------------- 184cdf0e10cSrcweir // XTypeProvider 185cdf0e10cSrcweir // ----------------------------------------------------------------------------- 186cdf0e10cSrcweir 187cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleEdit, VCLXAccessibleTextComponent, VCLXAccessibleEdit_BASE ) 188cdf0e10cSrcweir 189cdf0e10cSrcweir // ----------------------------------------------------------------------------- 190cdf0e10cSrcweir // XServiceInfo 191cdf0e10cSrcweir // ----------------------------------------------------------------------------- 192cdf0e10cSrcweir 193cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleEdit::getImplementationName() throw (RuntimeException) 194cdf0e10cSrcweir { 195cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleEdit" ); 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir // ----------------------------------------------------------------------------- 199cdf0e10cSrcweir 200cdf0e10cSrcweir Sequence< ::rtl::OUString > VCLXAccessibleEdit::getSupportedServiceNames() throw (RuntimeException) 201cdf0e10cSrcweir { 202cdf0e10cSrcweir Sequence< ::rtl::OUString > aNames(1); 203cdf0e10cSrcweir aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleEdit" ); 204cdf0e10cSrcweir return aNames; 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir // ----------------------------------------------------------------------------- 208cdf0e10cSrcweir // XAccessibleContext 209cdf0e10cSrcweir // ----------------------------------------------------------------------------- 210cdf0e10cSrcweir 211cdf0e10cSrcweir sal_Int32 VCLXAccessibleEdit::getAccessibleChildCount() throw (RuntimeException) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 214cdf0e10cSrcweir 215cdf0e10cSrcweir return 0; 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir // ----------------------------------------------------------------------------- 219cdf0e10cSrcweir 220cdf0e10cSrcweir Reference< XAccessible > VCLXAccessibleEdit::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException) 221cdf0e10cSrcweir { 222cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 223cdf0e10cSrcweir 224cdf0e10cSrcweir if ( i < 0 || i >= getAccessibleChildCount() ) 225cdf0e10cSrcweir throw IndexOutOfBoundsException(); 226cdf0e10cSrcweir 227cdf0e10cSrcweir return Reference< XAccessible >(); 228cdf0e10cSrcweir } 229cdf0e10cSrcweir 230cdf0e10cSrcweir // ----------------------------------------------------------------------------- 231cdf0e10cSrcweir 232cdf0e10cSrcweir sal_Int16 VCLXAccessibleEdit::getAccessibleRole( ) throw (RuntimeException) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 235cdf0e10cSrcweir 236cdf0e10cSrcweir sal_Int16 nRole; 237cdf0e10cSrcweir Edit* pEdit = static_cast< Edit* >( GetWindow() ); 238cdf0e10cSrcweir if ( pEdit && ( ( pEdit->GetStyle() & WB_PASSWORD ) || pEdit->GetEchoChar() ) ) 239cdf0e10cSrcweir nRole = AccessibleRole::PASSWORD_TEXT; 240cdf0e10cSrcweir else 241cdf0e10cSrcweir nRole = AccessibleRole::TEXT; 242cdf0e10cSrcweir 243cdf0e10cSrcweir return nRole; 244cdf0e10cSrcweir } 245cdf0e10cSrcweir 246cdf0e10cSrcweir // ----------------------------------------------------------------------------- 247cdf0e10cSrcweir // XAccessibleAction 248cdf0e10cSrcweir // ----------------------------------------------------------------------------- 249cdf0e10cSrcweir 250cdf0e10cSrcweir sal_Int32 VCLXAccessibleEdit::getAccessibleActionCount( ) throw (RuntimeException) 251cdf0e10cSrcweir { 252cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 253cdf0e10cSrcweir 254cdf0e10cSrcweir // There is one action: activate 255cdf0e10cSrcweir return 1; 256cdf0e10cSrcweir } 257cdf0e10cSrcweir 258cdf0e10cSrcweir // ----------------------------------------------------------------------------- 259cdf0e10cSrcweir 260cdf0e10cSrcweir sal_Bool VCLXAccessibleEdit::doAccessibleAction ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 263cdf0e10cSrcweir 264cdf0e10cSrcweir if ( nIndex < 0 || nIndex >= getAccessibleActionCount() ) 265cdf0e10cSrcweir throw IndexOutOfBoundsException(); 266cdf0e10cSrcweir 267cdf0e10cSrcweir sal_Bool bDoAction = sal_False; 268cdf0e10cSrcweir Window* pWindow = GetWindow(); 269cdf0e10cSrcweir if ( pWindow ) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir pWindow->GrabFocus(); 272cdf0e10cSrcweir bDoAction = sal_True; 273cdf0e10cSrcweir } 274cdf0e10cSrcweir 275cdf0e10cSrcweir return bDoAction; 276cdf0e10cSrcweir } 277cdf0e10cSrcweir 278cdf0e10cSrcweir // ----------------------------------------------------------------------------- 279cdf0e10cSrcweir 280cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleEdit::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 281cdf0e10cSrcweir { 282cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 283cdf0e10cSrcweir 284cdf0e10cSrcweir if ( nIndex < 0 || nIndex >= getAccessibleActionCount() ) 285cdf0e10cSrcweir throw IndexOutOfBoundsException(); 286cdf0e10cSrcweir 287cdf0e10cSrcweir static const ::rtl::OUString sAction( RTL_CONSTASCII_USTRINGPARAM( "activate" ) ); 288cdf0e10cSrcweir return sAction; 289cdf0e10cSrcweir } 290cdf0e10cSrcweir 291cdf0e10cSrcweir // ----------------------------------------------------------------------------- 292cdf0e10cSrcweir 293cdf0e10cSrcweir Reference< XAccessibleKeyBinding > VCLXAccessibleEdit::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 296cdf0e10cSrcweir 297cdf0e10cSrcweir if ( nIndex < 0 || nIndex >= getAccessibleActionCount() ) 298cdf0e10cSrcweir throw IndexOutOfBoundsException(); 299cdf0e10cSrcweir 300cdf0e10cSrcweir return Reference< XAccessibleKeyBinding >(); 301cdf0e10cSrcweir } 302cdf0e10cSrcweir 303cdf0e10cSrcweir // ----------------------------------------------------------------------------- 304cdf0e10cSrcweir // XAccessibleText 305cdf0e10cSrcweir // ----------------------------------------------------------------------------- 306cdf0e10cSrcweir 307cdf0e10cSrcweir sal_Int32 VCLXAccessibleEdit::getCaretPosition( ) throw (RuntimeException) 308cdf0e10cSrcweir { 309cdf0e10cSrcweir return getSelectionEnd(); 310cdf0e10cSrcweir } 311cdf0e10cSrcweir 312cdf0e10cSrcweir // ----------------------------------------------------------------------------- 313cdf0e10cSrcweir 314cdf0e10cSrcweir sal_Bool VCLXAccessibleEdit::setCaretPosition( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir return setSelection( nIndex, nIndex ); 317cdf0e10cSrcweir } 318cdf0e10cSrcweir 319cdf0e10cSrcweir // ----------------------------------------------------------------------------- 320cdf0e10cSrcweir 321cdf0e10cSrcweir sal_Unicode VCLXAccessibleEdit::getCharacter( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 322cdf0e10cSrcweir { 323cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 324cdf0e10cSrcweir 325cdf0e10cSrcweir return VCLXAccessibleTextComponent::getCharacter( nIndex ); 326cdf0e10cSrcweir } 327cdf0e10cSrcweir 328cdf0e10cSrcweir // ----------------------------------------------------------------------------- 329cdf0e10cSrcweir 330cdf0e10cSrcweir Sequence< PropertyValue > VCLXAccessibleEdit::getCharacterAttributes( sal_Int32 nIndex, const Sequence< ::rtl::OUString >& aRequestedAttributes ) throw (IndexOutOfBoundsException, RuntimeException) 331cdf0e10cSrcweir { 332cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 333cdf0e10cSrcweir 334cdf0e10cSrcweir return VCLXAccessibleTextComponent::getCharacterAttributes( nIndex, aRequestedAttributes ); 335cdf0e10cSrcweir } 336cdf0e10cSrcweir 337cdf0e10cSrcweir // ----------------------------------------------------------------------------- 338cdf0e10cSrcweir 339cdf0e10cSrcweir awt::Rectangle VCLXAccessibleEdit::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 340cdf0e10cSrcweir { 341cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 342cdf0e10cSrcweir 343cdf0e10cSrcweir awt::Rectangle aBounds( 0, 0, 0, 0 ); 344cdf0e10cSrcweir sal_Int32 nLength = implGetText().getLength(); 345cdf0e10cSrcweir 346cdf0e10cSrcweir if ( !implIsValidRange( nIndex, nIndex, nLength ) ) 347cdf0e10cSrcweir throw IndexOutOfBoundsException(); 348cdf0e10cSrcweir 349cdf0e10cSrcweir Control* pControl = static_cast< Control* >( GetWindow() ); 350cdf0e10cSrcweir if ( pControl ) 351cdf0e10cSrcweir { 352cdf0e10cSrcweir if ( nIndex == nLength ) 353cdf0e10cSrcweir { 354cdf0e10cSrcweir // #108914# calculate virtual bounding rectangle 355cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nLength; ++i ) 356cdf0e10cSrcweir { 357cdf0e10cSrcweir Rectangle aRect = pControl->GetCharacterBounds( i ); 358cdf0e10cSrcweir sal_Int32 nHeight = aRect.GetHeight(); 359cdf0e10cSrcweir if ( aBounds.Height < nHeight ) 360cdf0e10cSrcweir { 361cdf0e10cSrcweir aBounds.Y = aRect.Top(); 362cdf0e10cSrcweir aBounds.Height = nHeight; 363cdf0e10cSrcweir } 364cdf0e10cSrcweir if ( i == nLength - 1 ) 365cdf0e10cSrcweir { 366cdf0e10cSrcweir aBounds.X = aRect.Right() + 1; 367cdf0e10cSrcweir aBounds.Width = 1; 368cdf0e10cSrcweir } 369cdf0e10cSrcweir } 370cdf0e10cSrcweir } 371cdf0e10cSrcweir else 372cdf0e10cSrcweir { 373cdf0e10cSrcweir aBounds = AWTRectangle( pControl->GetCharacterBounds( nIndex ) ); 374cdf0e10cSrcweir } 375cdf0e10cSrcweir } 376cdf0e10cSrcweir 377cdf0e10cSrcweir return aBounds; 378cdf0e10cSrcweir } 379cdf0e10cSrcweir 380cdf0e10cSrcweir // ----------------------------------------------------------------------------- 381cdf0e10cSrcweir 382cdf0e10cSrcweir sal_Int32 VCLXAccessibleEdit::getCharacterCount( ) throw (RuntimeException) 383cdf0e10cSrcweir { 384cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 385cdf0e10cSrcweir 386cdf0e10cSrcweir return VCLXAccessibleTextComponent::getCharacterCount(); 387cdf0e10cSrcweir } 388cdf0e10cSrcweir 389cdf0e10cSrcweir // ----------------------------------------------------------------------------- 390cdf0e10cSrcweir 391cdf0e10cSrcweir sal_Int32 VCLXAccessibleEdit::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException) 392cdf0e10cSrcweir { 393cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 394cdf0e10cSrcweir 395cdf0e10cSrcweir return VCLXAccessibleTextComponent::getIndexAtPoint( aPoint ); 396cdf0e10cSrcweir } 397cdf0e10cSrcweir 398cdf0e10cSrcweir // ----------------------------------------------------------------------------- 399cdf0e10cSrcweir 400cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleEdit::getSelectedText( ) throw (RuntimeException) 401cdf0e10cSrcweir { 402cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 403cdf0e10cSrcweir 404cdf0e10cSrcweir return VCLXAccessibleTextComponent::getSelectedText(); 405cdf0e10cSrcweir } 406cdf0e10cSrcweir 407cdf0e10cSrcweir // ----------------------------------------------------------------------------- 408cdf0e10cSrcweir 409cdf0e10cSrcweir sal_Int32 VCLXAccessibleEdit::getSelectionStart( ) throw (RuntimeException) 410cdf0e10cSrcweir { 411cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 412cdf0e10cSrcweir 413cdf0e10cSrcweir return VCLXAccessibleTextComponent::getSelectionStart(); 414cdf0e10cSrcweir } 415cdf0e10cSrcweir 416cdf0e10cSrcweir // ----------------------------------------------------------------------------- 417cdf0e10cSrcweir 418cdf0e10cSrcweir sal_Int32 VCLXAccessibleEdit::getSelectionEnd( ) throw (RuntimeException) 419cdf0e10cSrcweir { 420cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 421cdf0e10cSrcweir 422cdf0e10cSrcweir return VCLXAccessibleTextComponent::getSelectionEnd(); 423cdf0e10cSrcweir } 424cdf0e10cSrcweir 425cdf0e10cSrcweir // ----------------------------------------------------------------------------- 426cdf0e10cSrcweir 427cdf0e10cSrcweir sal_Bool VCLXAccessibleEdit::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException) 428cdf0e10cSrcweir { 429cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 430cdf0e10cSrcweir 431cdf0e10cSrcweir sal_Bool bReturn = sal_False; 432cdf0e10cSrcweir ::rtl::OUString sText( implGetText() ); 433cdf0e10cSrcweir 434cdf0e10cSrcweir if ( !implIsValidRange( nStartIndex, nEndIndex, sText.getLength() ) ) 435cdf0e10cSrcweir throw IndexOutOfBoundsException(); 436cdf0e10cSrcweir 437cdf0e10cSrcweir VCLXEdit* pVCLXEdit = static_cast< VCLXEdit* >( GetVCLXWindow() ); 438cdf0e10cSrcweir Edit* pEdit = static_cast< Edit* >( GetWindow() ); 439cdf0e10cSrcweir if ( pVCLXEdit && pEdit && pEdit->IsEnabled() ) 440cdf0e10cSrcweir { 441cdf0e10cSrcweir pVCLXEdit->setSelection( awt::Selection( nStartIndex, nEndIndex ) ); 442cdf0e10cSrcweir bReturn = sal_True; 443cdf0e10cSrcweir } 444cdf0e10cSrcweir 445cdf0e10cSrcweir return bReturn; 446cdf0e10cSrcweir } 447cdf0e10cSrcweir 448cdf0e10cSrcweir // ----------------------------------------------------------------------------- 449cdf0e10cSrcweir 450cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleEdit::getText( ) throw (RuntimeException) 451cdf0e10cSrcweir { 452cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 453cdf0e10cSrcweir 454cdf0e10cSrcweir return VCLXAccessibleTextComponent::getText(); 455cdf0e10cSrcweir } 456cdf0e10cSrcweir 457cdf0e10cSrcweir // ----------------------------------------------------------------------------- 458cdf0e10cSrcweir 459cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleEdit::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException) 460cdf0e10cSrcweir { 461cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 462cdf0e10cSrcweir 463cdf0e10cSrcweir return VCLXAccessibleTextComponent::getTextRange( nStartIndex, nEndIndex ); 464cdf0e10cSrcweir } 465cdf0e10cSrcweir 466cdf0e10cSrcweir // ----------------------------------------------------------------------------- 467cdf0e10cSrcweir 468cdf0e10cSrcweir ::com::sun::star::accessibility::TextSegment VCLXAccessibleEdit::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 469cdf0e10cSrcweir { 470cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 471cdf0e10cSrcweir 472cdf0e10cSrcweir return VCLXAccessibleTextComponent::getTextAtIndex( nIndex, aTextType ); 473cdf0e10cSrcweir } 474cdf0e10cSrcweir 475cdf0e10cSrcweir // ----------------------------------------------------------------------------- 476cdf0e10cSrcweir 477cdf0e10cSrcweir ::com::sun::star::accessibility::TextSegment VCLXAccessibleEdit::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 478cdf0e10cSrcweir { 479cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 480cdf0e10cSrcweir 481cdf0e10cSrcweir return VCLXAccessibleTextComponent::getTextBeforeIndex( nIndex, aTextType ); 482cdf0e10cSrcweir } 483cdf0e10cSrcweir 484cdf0e10cSrcweir // ----------------------------------------------------------------------------- 485cdf0e10cSrcweir 486cdf0e10cSrcweir ::com::sun::star::accessibility::TextSegment VCLXAccessibleEdit::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 487cdf0e10cSrcweir { 488cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 489cdf0e10cSrcweir 490cdf0e10cSrcweir return VCLXAccessibleTextComponent::getTextBehindIndex( nIndex, aTextType ); 491cdf0e10cSrcweir } 492cdf0e10cSrcweir 493cdf0e10cSrcweir // ----------------------------------------------------------------------------- 494cdf0e10cSrcweir 495cdf0e10cSrcweir sal_Bool VCLXAccessibleEdit::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException) 496cdf0e10cSrcweir { 497cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 498cdf0e10cSrcweir 499cdf0e10cSrcweir return VCLXAccessibleTextComponent::copyText( nStartIndex, nEndIndex ); 500cdf0e10cSrcweir } 501cdf0e10cSrcweir 502cdf0e10cSrcweir // ----------------------------------------------------------------------------- 503cdf0e10cSrcweir // XAccessibleEditableText 504cdf0e10cSrcweir // ----------------------------------------------------------------------------- 505cdf0e10cSrcweir 506cdf0e10cSrcweir sal_Bool VCLXAccessibleEdit::cutText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException) 507cdf0e10cSrcweir { 508cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 509cdf0e10cSrcweir 510cdf0e10cSrcweir return copyText( nStartIndex, nEndIndex ) && deleteText( nStartIndex, nEndIndex ); 511cdf0e10cSrcweir } 512cdf0e10cSrcweir 513cdf0e10cSrcweir // ----------------------------------------------------------------------------- 514cdf0e10cSrcweir 515cdf0e10cSrcweir sal_Bool VCLXAccessibleEdit::pasteText( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 516cdf0e10cSrcweir { 517cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 518cdf0e10cSrcweir 519cdf0e10cSrcweir sal_Bool bReturn = sal_False; 520cdf0e10cSrcweir 521cdf0e10cSrcweir if ( GetWindow() ) 522cdf0e10cSrcweir { 523cdf0e10cSrcweir Reference< datatransfer::clipboard::XClipboard > xClipboard = GetWindow()->GetClipboard(); 524cdf0e10cSrcweir if ( xClipboard.is() ) 525cdf0e10cSrcweir { 526cdf0e10cSrcweir const sal_uInt32 nRef = Application::ReleaseSolarMutex(); 527cdf0e10cSrcweir Reference< datatransfer::XTransferable > xDataObj = xClipboard->getContents(); 528cdf0e10cSrcweir Application::AcquireSolarMutex( nRef ); 529cdf0e10cSrcweir if ( xDataObj.is() ) 530cdf0e10cSrcweir { 531cdf0e10cSrcweir datatransfer::DataFlavor aFlavor; 532cdf0e10cSrcweir SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aFlavor ); 533cdf0e10cSrcweir if ( xDataObj->isDataFlavorSupported( aFlavor ) ) 534cdf0e10cSrcweir { 535cdf0e10cSrcweir Any aData = xDataObj->getTransferData( aFlavor ); 536cdf0e10cSrcweir ::rtl::OUString sText; 537cdf0e10cSrcweir aData >>= sText; 538cdf0e10cSrcweir bReturn = replaceText( nIndex, nIndex, sText ); 539cdf0e10cSrcweir } 540cdf0e10cSrcweir } 541cdf0e10cSrcweir } 542cdf0e10cSrcweir } 543cdf0e10cSrcweir 544cdf0e10cSrcweir return bReturn; 545cdf0e10cSrcweir } 546cdf0e10cSrcweir 547cdf0e10cSrcweir // ----------------------------------------------------------------------------- 548cdf0e10cSrcweir 549cdf0e10cSrcweir sal_Bool VCLXAccessibleEdit::deleteText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException) 550cdf0e10cSrcweir { 551cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 552cdf0e10cSrcweir 553cdf0e10cSrcweir return replaceText( nStartIndex, nEndIndex, ::rtl::OUString() ); 554cdf0e10cSrcweir } 555cdf0e10cSrcweir 556cdf0e10cSrcweir // ----------------------------------------------------------------------------- 557cdf0e10cSrcweir 558cdf0e10cSrcweir sal_Bool VCLXAccessibleEdit::insertText( const ::rtl::OUString& sText, sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 559cdf0e10cSrcweir { 560cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 561cdf0e10cSrcweir 562cdf0e10cSrcweir return replaceText( nIndex, nIndex, sText ); 563cdf0e10cSrcweir } 564cdf0e10cSrcweir 565cdf0e10cSrcweir // ----------------------------------------------------------------------------- 566cdf0e10cSrcweir 567cdf0e10cSrcweir sal_Bool VCLXAccessibleEdit::replaceText( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const ::rtl::OUString& sReplacement ) throw (IndexOutOfBoundsException, RuntimeException) 568cdf0e10cSrcweir { 569cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 570cdf0e10cSrcweir 571cdf0e10cSrcweir sal_Bool bReturn = sal_False; 572cdf0e10cSrcweir ::rtl::OUString sText( implGetText() ); 573cdf0e10cSrcweir 574cdf0e10cSrcweir if ( !implIsValidRange( nStartIndex, nEndIndex, sText.getLength() ) ) 575cdf0e10cSrcweir throw IndexOutOfBoundsException(); 576cdf0e10cSrcweir 577cdf0e10cSrcweir sal_Int32 nMinIndex = ::std::min( nStartIndex, nEndIndex ); 578cdf0e10cSrcweir sal_Int32 nMaxIndex = ::std::max( nStartIndex, nEndIndex ); 579cdf0e10cSrcweir 580cdf0e10cSrcweir VCLXEdit* pVCLXEdit = static_cast< VCLXEdit* >( GetVCLXWindow() ); 581cdf0e10cSrcweir if ( pVCLXEdit && pVCLXEdit->isEditable() ) 582cdf0e10cSrcweir { 583cdf0e10cSrcweir pVCLXEdit->setText( sText.replaceAt( nMinIndex, nMaxIndex - nMinIndex, sReplacement ) ); 584cdf0e10cSrcweir sal_Int32 nIndex = nMinIndex + sReplacement.getLength(); 585cdf0e10cSrcweir setSelection( nIndex, nIndex ); 586cdf0e10cSrcweir bReturn = sal_True; 587cdf0e10cSrcweir } 588cdf0e10cSrcweir 589cdf0e10cSrcweir return bReturn; 590cdf0e10cSrcweir } 591cdf0e10cSrcweir 592cdf0e10cSrcweir // ----------------------------------------------------------------------------- 593cdf0e10cSrcweir 594cdf0e10cSrcweir sal_Bool VCLXAccessibleEdit::setAttributes( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const Sequence<PropertyValue>& ) throw (IndexOutOfBoundsException, RuntimeException) 595cdf0e10cSrcweir { 596cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 597cdf0e10cSrcweir 598cdf0e10cSrcweir if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) ) 599cdf0e10cSrcweir throw IndexOutOfBoundsException(); 600cdf0e10cSrcweir 601cdf0e10cSrcweir return sal_False; // attributes cannot be set for an edit 602cdf0e10cSrcweir } 603cdf0e10cSrcweir 604cdf0e10cSrcweir // ----------------------------------------------------------------------------- 605cdf0e10cSrcweir 606cdf0e10cSrcweir sal_Bool VCLXAccessibleEdit::setText( const ::rtl::OUString& sText ) throw (RuntimeException) 607cdf0e10cSrcweir { 608cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 609cdf0e10cSrcweir 610cdf0e10cSrcweir sal_Bool bSuccess = sal_False; 611cdf0e10cSrcweir try 612cdf0e10cSrcweir { 613cdf0e10cSrcweir bSuccess = replaceText( 0, implGetText().getLength(), sText ); 614cdf0e10cSrcweir } 615cdf0e10cSrcweir catch( const IndexOutOfBoundsException& ) 616cdf0e10cSrcweir { 617cdf0e10cSrcweir OSL_ENSURE( sal_False, "VCLXAccessibleText::setText: caught an exception!" ); 618cdf0e10cSrcweir } 619cdf0e10cSrcweir return bSuccess; 620cdf0e10cSrcweir } 621cdf0e10cSrcweir 622cdf0e10cSrcweir // ----------------------------------------------------------------------------- 623