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