LCOV - code coverage report
Current view: top level - accessibility/source/standard - vclxaccessibletextcomponent.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 88 126 69.8 %
Date: 2014-11-03 Functions: 25 33 75.8 %
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          80 : VCLXAccessibleTextComponent::VCLXAccessibleTextComponent( VCLXWindow* pVCLXWindow )
      51          80 :     :VCLXAccessibleComponent( pVCLXWindow )
      52             : {
      53          80 :     if ( GetWindow() )
      54          80 :         m_sText = OutputDevice::GetNonMnemonicString( GetWindow()->GetText() );
      55          80 : }
      56             : 
      57             : 
      58             : 
      59          70 : VCLXAccessibleTextComponent::~VCLXAccessibleTextComponent()
      60             : {
      61          70 : }
      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         189 : void VCLXAccessibleTextComponent::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
      78             : {
      79         189 :     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         189 :             VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
      89             :    }
      90         189 : }
      91             : 
      92             : 
      93             : // OCommonAccessibleText
      94             : 
      95             : 
      96         144 : OUString VCLXAccessibleTextComponent::implGetText()
      97             : {
      98         144 :     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().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          70 : void VCLXAccessibleTextComponent::disposing()
     125             : {
     126          70 :     VCLXAccessibleComponent::disposing();
     127             : 
     128          70 :     m_sText = OUString();
     129          70 : }
     130             : 
     131             : 
     132             : // XInterface
     133             : 
     134             : 
     135        4002 : 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           6 : sal_Bool VCLXAccessibleTextComponent::setCaretPosition( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     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, std::exception)
     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< OUString >& aRequestedAttributes ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     175             : {
     176           6 :     OExternalLockGuard aGuard( this );
     177             : 
     178           6 :     Sequence< PropertyValue > aValues;
     179          12 :     OUString sText( implGetText() );
     180             : 
     181           6 :     if ( !implIsValidIndex( nIndex, sText.getLength() ) )
     182           4 :         throw IndexOutOfBoundsException();
     183             : 
     184           2 :     if ( GetWindow() )
     185             :     {
     186           2 :         vcl::Font aFont = GetWindow()->GetControlFont();
     187             : 
     188           2 :         sal_Int32 nBackColor = GetWindow()->GetControlBackground().GetColor();
     189           2 :         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           4 :         aValues = CharacterAttributesHelper( aFont, nBackColor, nColor )
     241           4 :             .GetCharacterAttributes( aRequestedAttributes );
     242             :     }
     243             : 
     244           8 :     return aValues;
     245             : }
     246             : 
     247             : 
     248             : 
     249          32 : awt::Rectangle VCLXAccessibleTextComponent::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     250             : {
     251          32 :     OExternalLockGuard aGuard( this );
     252             : 
     253          32 :     if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
     254           4 :         throw IndexOutOfBoundsException();
     255             : 
     256          28 :     awt::Rectangle aRect;
     257          28 :     Control* pControl = static_cast< Control* >( GetWindow() );
     258          28 :     if ( pControl )
     259          28 :         aRect = AWTRectangle( pControl->GetCharacterBounds( nIndex ) );
     260             : 
     261          32 :     return aRect;
     262             : }
     263             : 
     264             : 
     265             : 
     266           2 : sal_Int32 VCLXAccessibleTextComponent::getCharacterCount() throw (RuntimeException, std::exception)
     267             : {
     268           2 :     OExternalLockGuard aGuard( this );
     269             : 
     270           2 :     return OCommonAccessibleText::getCharacterCount();
     271             : }
     272             : 
     273             : 
     274             : 
     275          30 : sal_Int32 VCLXAccessibleTextComponent::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException, std::exception)
     276             : {
     277          30 :     OExternalLockGuard aGuard( this );
     278             : 
     279          30 :     sal_Int32 nIndex = -1;
     280          30 :     Control* pControl = static_cast< Control* >( GetWindow() );
     281          30 :     if ( pControl )
     282          30 :         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          32 : sal_Int32 VCLXAccessibleTextComponent::getSelectionStart() throw (RuntimeException, std::exception)
     299             : {
     300          32 :     OExternalLockGuard aGuard( this );
     301             : 
     302          32 :     return OCommonAccessibleText::getSelectionStart();
     303             : }
     304             : 
     305             : 
     306             : 
     307          32 : sal_Int32 VCLXAccessibleTextComponent::getSelectionEnd() throw (RuntimeException, std::exception)
     308             : {
     309          32 :     OExternalLockGuard aGuard( this );
     310             : 
     311          32 :     return OCommonAccessibleText::getSelectionEnd();
     312             : }
     313             : 
     314             : 
     315             : 
     316           6 : sal_Bool VCLXAccessibleTextComponent::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     317             : {
     318           6 :     OExternalLockGuard aGuard( this );
     319             : 
     320           6 :     if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
     321           4 :         throw IndexOutOfBoundsException();
     322             : 
     323           6 :     return false;
     324             : }
     325             : 
     326             : 
     327             : 
     328           4 : OUString VCLXAccessibleTextComponent::getText() throw (RuntimeException, std::exception)
     329             : {
     330           4 :     OExternalLockGuard aGuard( this );
     331             : 
     332           4 :     return OCommonAccessibleText::getText();
     333             : }
     334             : 
     335             : 
     336             : 
     337          14 : OUString VCLXAccessibleTextComponent::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     338             : {
     339          14 :     OExternalLockGuard aGuard( this );
     340             : 
     341          14 :     return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex );
     342             : }
     343             : 
     344             : 
     345             : 
     346          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, std::exception)
     347             : {
     348          22 :     OExternalLockGuard aGuard( this );
     349             : 
     350          22 :     return OCommonAccessibleText::getTextAtIndex( nIndex, aTextType );
     351             : }
     352             : 
     353             : 
     354             : 
     355          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, std::exception)
     356             : {
     357          12 :     OExternalLockGuard aGuard( this );
     358             : 
     359          12 :     return OCommonAccessibleText::getTextBeforeIndex( nIndex, aTextType );
     360             : }
     361             : 
     362             : 
     363             : 
     364          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, std::exception)
     365             : {
     366          12 :     OExternalLockGuard aGuard( this );
     367             : 
     368          12 :     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           0 :             const sal_uInt32 nRef = Application::ReleaseSolarMutex();
     388           0 :             xClipboard->setContents( pDataObj, NULL );
     389             : 
     390           0 :             Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
     391           0 :             if( xFlushableClipboard.is() )
     392           0 :                 xFlushableClipboard->flushClipboard();
     393             : 
     394           0 :             Application::AcquireSolarMutex( nRef );
     395             : 
     396           0 :             bReturn = true;
     397           0 :         }
     398             :     }
     399             : 
     400           0 :     return bReturn;
     401          60 : }
     402             : 
     403             : 
     404             : 
     405             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10