LCOV - code coverage report
Current view: top level - accessibility/source/standard - vclxaccessibletextcomponent.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 87 125 69.6 %
Date: 2012-08-25 Functions: 23 31 74.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 105 256 41.0 %

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

Generated by: LCOV version 1.10