LCOV - code coverage report
Current view: top level - accessibility/source/standard - vclxaccessibletextcomponent.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 87 124 70.2 %
Date: 2015-06-13 12:38:46 Functions: 23 31 74.2 %
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/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             : #include <vcl/settings.hxx>
      35             : 
      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          34 : VCLXAccessibleTextComponent::VCLXAccessibleTextComponent( VCLXWindow* pVCLXWindow )
      51          34 :     :VCLXAccessibleComponent( pVCLXWindow )
      52             : {
      53          34 :     if ( GetWindow() )
      54          34 :         m_sText = OutputDevice::GetNonMnemonicString( GetWindow()->GetText() );
      55          34 : }
      56             : 
      57             : 
      58             : 
      59          29 : VCLXAccessibleTextComponent::~VCLXAccessibleTextComponent()
      60             : {
      61          29 : }
      62             : 
      63             : 
      64             : 
      65           0 : void VCLXAccessibleTextComponent::SetText( const 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          70 : void VCLXAccessibleTextComponent::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
      78             : {
      79          70 :     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          70 :             VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
      89             :    }
      90          70 : }
      91             : 
      92             : 
      93             : // OCommonAccessibleText
      94             : 
      95             : 
      96          72 : OUString VCLXAccessibleTextComponent::implGetText()
      97             : {
      98          72 :     OUString aText;
      99          72 :     if ( GetWindow() )
     100          72 :         aText = OutputDevice::GetNonMnemonicString( GetWindow()->GetText() );
     101             : 
     102          72 :     return aText;
     103             : }
     104             : 
     105             : 
     106             : 
     107           2 : lang::Locale VCLXAccessibleTextComponent::implGetLocale()
     108             : {
     109           2 :     return Application::GetSettings().GetLanguageTag().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          29 : void VCLXAccessibleTextComponent::disposing()
     125             : {
     126          29 :     VCLXAccessibleComponent::disposing();
     127             : 
     128          29 :     m_sText.clear();
     129          29 : }
     130             : 
     131             : 
     132             : // XInterface
     133             : 
     134             : 
     135        1772 : 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, std::exception)
     148             : {
     149           0 :     OExternalLockGuard aGuard( this );
     150             : 
     151           0 :     return -1;
     152             : }
     153             : 
     154             : 
     155             : 
     156           3 : sal_Bool VCLXAccessibleTextComponent::setCaretPosition( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     157             : {
     158           3 :     OExternalLockGuard aGuard( this );
     159             : 
     160           3 :     return setSelection( nIndex, nIndex );
     161             : }
     162             : 
     163             : 
     164             : 
     165          10 : sal_Unicode VCLXAccessibleTextComponent::getCharacter( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     166             : {
     167          10 :     OExternalLockGuard aGuard( this );
     168             : 
     169          10 :     return OCommonAccessibleText::getCharacter( nIndex );
     170             : }
     171             : 
     172             : 
     173             : 
     174           3 : Sequence< PropertyValue > VCLXAccessibleTextComponent::getCharacterAttributes( sal_Int32 nIndex, const Sequence< OUString >& aRequestedAttributes ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     175             : {
     176           3 :     OExternalLockGuard aGuard( this );
     177             : 
     178           3 :     Sequence< PropertyValue > aValues;
     179           6 :     OUString sText( implGetText() );
     180             : 
     181           3 :     if ( !implIsValidIndex( nIndex, sText.getLength() ) )
     182           2 :         throw IndexOutOfBoundsException();
     183             : 
     184           1 :     if ( GetWindow() )
     185             :     {
     186           1 :         vcl::Font aFont = GetWindow()->GetControlFont();
     187             : 
     188           1 :         sal_Int32 nBackColor = GetWindow()->GetControlBackground().GetColor();
     189           1 :         sal_Int32 nColor = GetWindow()->GetControlForeground().GetColor();
     190             : 
     191             :         // MT: Code with default font was introduced with the IA2 CWS, but I am not convinced that this is the correct font...
     192             :         // Decide what to do when we have a concrete issue.
     193             :         /*
     194             :         Font aDefaultVCLFont;
     195             :         OutputDevice* pDev = Application::GetDefaultDevice();
     196             :         if ( pDev )
     197             :         {
     198             :             aDefaultVCLFont = pDev->GetSettings().GetStyleSettings().GetAppFont();
     199             :             if ( !aFont.GetName().Len() )
     200             :             {
     201             :                 String aDefaultName = aDefaultVCLFont.GetName();
     202             :                 aFont.SetName( aDefaultName );
     203             :             }
     204             :             if ( !aFont.GetHeight() )
     205             :             {
     206             :                 aFont.SetHeight( aDefaultVCLFont.GetHeight() );
     207             :             }
     208             :             if ( aFont.GetWeight() == WEIGHT_DONTKNOW )
     209             :             {
     210             :                 aFont.SetWeight( aDefaultVCLFont.GetWeight() );
     211             :             }
     212             : 
     213             :             //if nColor is -1, it may indicate that the default color black is using.
     214             :             if ( nColor == -1)
     215             :             {
     216             :                 nColor = aDefaultVCLFont.GetColor().GetColor();
     217             :             }
     218             :         }
     219             :         */
     220             : 
     221             :         // MT: Adjustment stuff was introduced with the IA2 CWS, but adjustment is not a character attribute...
     222             :         // In case we reintroduce it, use adjustment as extra parameter for the CharacterAttributesHelper...
     223             :         /*
     224             :         WinBits aBits = GetWindow()->GetStyle();
     225             :         sal_Int16 nAdjust = -1;
     226             :         if ( aBits & WB_LEFT )
     227             :         {
     228             :             nAdjust = style::ParagraphAdjust_LEFT;
     229             :         }
     230             :         else if ( aBits & WB_RIGHT )
     231             :         {
     232             :             nAdjust = style::ParagraphAdjust_RIGHT;
     233             :         }
     234             :         else if ( aBits & WB_CENTER )
     235             :         {
     236             :             nAdjust = style::ParagraphAdjust_CENTER;
     237             :         }
     238             :         */
     239             : 
     240           2 :         aValues = CharacterAttributesHelper( aFont, nBackColor, nColor )
     241           2 :             .GetCharacterAttributes( aRequestedAttributes );
     242             :     }
     243             : 
     244           4 :     return aValues;
     245             : }
     246             : 
     247             : 
     248             : 
     249          16 : awt::Rectangle VCLXAccessibleTextComponent::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     250             : {
     251          16 :     OExternalLockGuard aGuard( this );
     252             : 
     253          16 :     if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
     254           2 :         throw IndexOutOfBoundsException();
     255             : 
     256          14 :     awt::Rectangle aRect;
     257          28 :     VclPtr< Control > pControl = GetAs< Control >();
     258          14 :     if ( pControl )
     259          14 :         aRect = AWTRectangle( pControl->GetCharacterBounds( nIndex ) );
     260             : 
     261          30 :     return aRect;
     262             : }
     263             : 
     264             : 
     265             : 
     266           1 : sal_Int32 VCLXAccessibleTextComponent::getCharacterCount() throw (RuntimeException, std::exception)
     267             : {
     268           1 :     OExternalLockGuard aGuard( this );
     269             : 
     270           1 :     return OCommonAccessibleText::getCharacterCount();
     271             : }
     272             : 
     273             : 
     274             : 
     275          15 : sal_Int32 VCLXAccessibleTextComponent::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException, std::exception)
     276             : {
     277          15 :     OExternalLockGuard aGuard( this );
     278             : 
     279          15 :     sal_Int32 nIndex = -1;
     280          30 :     VclPtr< Control > pControl = GetAs< Control >();
     281          15 :     if ( pControl )
     282          15 :         nIndex = pControl->GetIndexForPoint( VCLPoint( aPoint ) );
     283             : 
     284          30 :     return nIndex;
     285             : }
     286             : 
     287             : 
     288             : 
     289           0 : OUString VCLXAccessibleTextComponent::getSelectedText() throw (RuntimeException, std::exception)
     290             : {
     291           0 :     OExternalLockGuard aGuard( this );
     292             : 
     293           0 :     return OCommonAccessibleText::getSelectedText();
     294             : }
     295             : 
     296             : 
     297             : 
     298           9 : sal_Int32 VCLXAccessibleTextComponent::getSelectionStart() throw (RuntimeException, std::exception)
     299             : {
     300           9 :     OExternalLockGuard aGuard( this );
     301             : 
     302           9 :     return OCommonAccessibleText::getSelectionStart();
     303             : }
     304             : 
     305             : 
     306             : 
     307           9 : sal_Int32 VCLXAccessibleTextComponent::getSelectionEnd() throw (RuntimeException, std::exception)
     308             : {
     309           9 :     OExternalLockGuard aGuard( this );
     310             : 
     311           9 :     return OCommonAccessibleText::getSelectionEnd();
     312             : }
     313             : 
     314             : 
     315             : 
     316           3 : sal_Bool VCLXAccessibleTextComponent::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     317             : {
     318           3 :     OExternalLockGuard aGuard( this );
     319             : 
     320           3 :     if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
     321           2 :         throw IndexOutOfBoundsException();
     322             : 
     323           3 :     return false;
     324             : }
     325             : 
     326             : 
     327             : 
     328           2 : OUString VCLXAccessibleTextComponent::getText() throw (RuntimeException, std::exception)
     329             : {
     330           2 :     OExternalLockGuard aGuard( this );
     331             : 
     332           2 :     return OCommonAccessibleText::getText();
     333             : }
     334             : 
     335             : 
     336             : 
     337           7 : OUString VCLXAccessibleTextComponent::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     338             : {
     339           7 :     OExternalLockGuard aGuard( this );
     340             : 
     341           7 :     return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex );
     342             : }
     343             : 
     344             : 
     345             : 
     346          11 : ::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, std::exception)
     347             : {
     348          11 :     OExternalLockGuard aGuard( this );
     349             : 
     350          11 :     return OCommonAccessibleText::getTextAtIndex( nIndex, aTextType );
     351             : }
     352             : 
     353             : 
     354             : 
     355           6 : ::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, std::exception)
     356             : {
     357           6 :     OExternalLockGuard aGuard( this );
     358             : 
     359           6 :     return OCommonAccessibleText::getTextBeforeIndex( nIndex, aTextType );
     360             : }
     361             : 
     362             : 
     363             : 
     364           6 : ::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, std::exception)
     365             : {
     366           6 :     OExternalLockGuard aGuard( this );
     367             : 
     368           6 :     return OCommonAccessibleText::getTextBehindIndex( nIndex, aTextType );
     369             : }
     370             : 
     371             : 
     372             : 
     373           0 : sal_Bool VCLXAccessibleTextComponent::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     374             : {
     375           0 :     OExternalLockGuard aGuard( this );
     376             : 
     377           0 :     bool bReturn = false;
     378             : 
     379           0 :     if ( GetWindow() )
     380             :     {
     381           0 :         Reference< datatransfer::clipboard::XClipboard > xClipboard = GetWindow()->GetClipboard();
     382           0 :         if ( xClipboard.is() )
     383             :         {
     384           0 :             OUString sText( getTextRange( nStartIndex, nEndIndex ) );
     385             : 
     386           0 :             vcl::unohelper::TextDataObject* pDataObj = new vcl::unohelper::TextDataObject( sText );
     387             : 
     388           0 :             SolarMutexReleaser aReleaser;
     389           0 :             xClipboard->setContents( pDataObj, NULL );
     390             : 
     391           0 :             Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
     392           0 :             if( xFlushableClipboard.is() )
     393           0 :                 xFlushableClipboard->flushClipboard();
     394             : 
     395           0 :             bReturn = true;
     396           0 :         }
     397             :     }
     398             : 
     399           0 :     return bReturn;
     400             : }
     401             : 
     402             : 
     403             : 
     404             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11