LCOV - code coverage report
Current view: top level - accessibility/source/standard - vclxaccessibletextcomponent.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 125 0.0 %
Date: 2014-04-14 Functions: 0 31 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/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           0 : VCLXAccessibleTextComponent::VCLXAccessibleTextComponent( VCLXWindow* pVCLXWindow )
      51           0 :     :VCLXAccessibleComponent( pVCLXWindow )
      52             : {
      53           0 :     if ( GetWindow() )
      54           0 :         m_sText = OutputDevice::GetNonMnemonicString( GetWindow()->GetText() );
      55           0 : }
      56             : 
      57             : 
      58             : 
      59           0 : VCLXAccessibleTextComponent::~VCLXAccessibleTextComponent()
      60             : {
      61           0 : }
      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           0 : void VCLXAccessibleTextComponent::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
      78             : {
      79           0 :     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           0 :             VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
      89             :    }
      90           0 : }
      91             : 
      92             : 
      93             : // OCommonAccessibleText
      94             : 
      95             : 
      96           0 : OUString VCLXAccessibleTextComponent::implGetText()
      97             : {
      98           0 :     OUString aText;
      99           0 :     if ( GetWindow() )
     100           0 :         aText = OutputDevice::GetNonMnemonicString( GetWindow()->GetText() );
     101             : 
     102           0 :     return aText;
     103             : }
     104             : 
     105             : 
     106             : 
     107           0 : lang::Locale VCLXAccessibleTextComponent::implGetLocale()
     108             : {
     109           0 :     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           0 : void VCLXAccessibleTextComponent::disposing()
     125             : {
     126           0 :     VCLXAccessibleComponent::disposing();
     127             : 
     128           0 :     m_sText = OUString();
     129           0 : }
     130             : 
     131             : 
     132             : // XInterface
     133             : 
     134             : 
     135           0 : 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           0 : sal_Bool VCLXAccessibleTextComponent::setCaretPosition( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     157             : {
     158           0 :     OExternalLockGuard aGuard( this );
     159             : 
     160           0 :     return setSelection( nIndex, nIndex );
     161             : }
     162             : 
     163             : 
     164             : 
     165           0 : sal_Unicode VCLXAccessibleTextComponent::getCharacter( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     166             : {
     167           0 :     OExternalLockGuard aGuard( this );
     168             : 
     169           0 :     return OCommonAccessibleText::getCharacter( nIndex );
     170             : }
     171             : 
     172             : 
     173             : 
     174           0 : Sequence< PropertyValue > VCLXAccessibleTextComponent::getCharacterAttributes( sal_Int32 nIndex, const Sequence< OUString >& aRequestedAttributes ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     175             : {
     176           0 :     OExternalLockGuard aGuard( this );
     177             : 
     178           0 :     Sequence< PropertyValue > aValues;
     179           0 :     OUString sText( implGetText() );
     180             : 
     181           0 :     if ( !implIsValidIndex( nIndex, sText.getLength() ) )
     182           0 :         throw IndexOutOfBoundsException();
     183             : 
     184           0 :     if ( GetWindow() )
     185             :     {
     186           0 :         Font aFont = GetWindow()->GetControlFont();
     187             : 
     188           0 :         sal_Int32 nBackColor = GetWindow()->GetControlBackground().GetColor();
     189           0 :         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           0 :         aValues = CharacterAttributesHelper( aFont, nBackColor, nColor )
     241           0 :             .GetCharacterAttributes( aRequestedAttributes );
     242             :     }
     243             : 
     244           0 :     return aValues;
     245             : }
     246             : 
     247             : 
     248             : 
     249           0 : awt::Rectangle VCLXAccessibleTextComponent::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     250             : {
     251           0 :     OExternalLockGuard aGuard( this );
     252             : 
     253           0 :     if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
     254           0 :         throw IndexOutOfBoundsException();
     255             : 
     256           0 :     awt::Rectangle aRect;
     257           0 :     Control* pControl = static_cast< Control* >( GetWindow() );
     258           0 :     if ( pControl )
     259           0 :         aRect = AWTRectangle( pControl->GetCharacterBounds( nIndex ) );
     260             : 
     261           0 :     return aRect;
     262             : }
     263             : 
     264             : 
     265             : 
     266           0 : sal_Int32 VCLXAccessibleTextComponent::getCharacterCount() throw (RuntimeException, std::exception)
     267             : {
     268           0 :     OExternalLockGuard aGuard( this );
     269             : 
     270           0 :     return OCommonAccessibleText::getCharacterCount();
     271             : }
     272             : 
     273             : 
     274             : 
     275           0 : sal_Int32 VCLXAccessibleTextComponent::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException, std::exception)
     276             : {
     277           0 :     OExternalLockGuard aGuard( this );
     278             : 
     279           0 :     sal_Int32 nIndex = -1;
     280           0 :     Control* pControl = static_cast< Control* >( GetWindow() );
     281           0 :     if ( pControl )
     282           0 :         nIndex = pControl->GetIndexForPoint( VCLPoint( aPoint ) );
     283             : 
     284           0 :     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           0 : sal_Int32 VCLXAccessibleTextComponent::getSelectionStart() throw (RuntimeException, std::exception)
     299             : {
     300           0 :     OExternalLockGuard aGuard( this );
     301             : 
     302           0 :     return OCommonAccessibleText::getSelectionStart();
     303             : }
     304             : 
     305             : 
     306             : 
     307           0 : sal_Int32 VCLXAccessibleTextComponent::getSelectionEnd() throw (RuntimeException, std::exception)
     308             : {
     309           0 :     OExternalLockGuard aGuard( this );
     310             : 
     311           0 :     return OCommonAccessibleText::getSelectionEnd();
     312             : }
     313             : 
     314             : 
     315             : 
     316           0 : sal_Bool VCLXAccessibleTextComponent::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     317             : {
     318           0 :     OExternalLockGuard aGuard( this );
     319             : 
     320           0 :     if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
     321           0 :         throw IndexOutOfBoundsException();
     322             : 
     323           0 :     return sal_False;
     324             : }
     325             : 
     326             : 
     327             : 
     328           0 : OUString VCLXAccessibleTextComponent::getText() throw (RuntimeException, std::exception)
     329             : {
     330           0 :     OExternalLockGuard aGuard( this );
     331             : 
     332           0 :     return OCommonAccessibleText::getText();
     333             : }
     334             : 
     335             : 
     336             : 
     337           0 : OUString VCLXAccessibleTextComponent::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     338             : {
     339           0 :     OExternalLockGuard aGuard( this );
     340             : 
     341           0 :     return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex );
     342             : }
     343             : 
     344             : 
     345             : 
     346           0 : ::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           0 :     OExternalLockGuard aGuard( this );
     349             : 
     350           0 :     return OCommonAccessibleText::getTextAtIndex( nIndex, aTextType );
     351             : }
     352             : 
     353             : 
     354             : 
     355           0 : ::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           0 :     OExternalLockGuard aGuard( this );
     358             : 
     359           0 :     return OCommonAccessibleText::getTextBeforeIndex( nIndex, aTextType );
     360             : }
     361             : 
     362             : 
     363             : 
     364           0 : ::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           0 :     OExternalLockGuard aGuard( this );
     367             : 
     368           0 :     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 :     sal_Bool bReturn = sal_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 = sal_True;
     397           0 :         }
     398             :     }
     399             : 
     400           0 :     return bReturn;
     401             : }
     402             : 
     403             : 
     404             : 
     405             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10