LCOV - code coverage report
Current view: top level - libreoffice/accessibility/source/standard - vclxaccessibleedit.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 236 0.0 %
Date: 2012-12-27 Functions: 0 45 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10