LCOV - code coverage report
Current view: top level - editeng/source/accessibility - AccessibleParaManager.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 146 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             : 
      21             : 
      22             : 
      23             : // Global header
      24             : 
      25             : 
      26             : #include <com/sun/star/uno/Any.hxx>
      27             : #include <com/sun/star/uno/Reference.hxx>
      28             : #include <cppuhelper/weakref.hxx>
      29             : #include <com/sun/star/accessibility/XAccessible.hpp>
      30             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      31             : 
      32             : 
      33             : 
      34             : // Project-local header
      35             : 
      36             : 
      37             : 
      38             : #include <editeng/unoedhlp.hxx>
      39             : #include <editeng/unopracc.hxx>
      40             : #include <editeng/unoedsrc.hxx>
      41             : #include "editeng/AccessibleParaManager.hxx"
      42             : #include "editeng/AccessibleEditableTextPara.hxx"
      43             : 
      44             : 
      45             : using namespace ::com::sun::star;
      46             : using namespace ::com::sun::star::accessibility;
      47             : 
      48             : 
      49             : 
      50             : namespace accessibility
      51             : {
      52           0 :     AccessibleParaManager::AccessibleParaManager() :
      53             :         maChildren(1),
      54             :         maEEOffset( 0, 0 ),
      55             :         mnFocusedChild( -1 ),
      56           0 :         mbActive( false )
      57             :     {
      58           0 :     }
      59             : 
      60           0 :     AccessibleParaManager::~AccessibleParaManager()
      61             :     {
      62             :         // owner is responsible for possible child defuncs
      63           0 :     }
      64             : 
      65           0 :     void AccessibleParaManager::SetAdditionalChildStates( const VectorOfStates& rChildStates )
      66             :     {
      67           0 :         maChildStates = rChildStates;
      68           0 :     }
      69             : 
      70           0 :     void AccessibleParaManager::SetNum( sal_Int32 nNumParas )
      71             :     {
      72           0 :         if( (size_t)nNumParas < maChildren.size() )
      73           0 :             Release( nNumParas, maChildren.size() );
      74             : 
      75           0 :         maChildren.resize( nNumParas );
      76             : 
      77           0 :         if( mnFocusedChild >= nNumParas )
      78           0 :             mnFocusedChild = -1;
      79           0 :     }
      80             : 
      81           0 :     sal_Int32 AccessibleParaManager::GetNum() const
      82             :     {
      83           0 :         size_t nSize = maChildren.size();
      84           0 :         if (nSize > SAL_MAX_INT32)
      85             :         {
      86             :             SAL_WARN( "editeng", "AccessibleParaManager::GetNum - overflow " << nSize);
      87           0 :             return SAL_MAX_INT32;
      88             :         }
      89           0 :         return static_cast<sal_Int32>(nSize);
      90             :     }
      91             : 
      92           0 :     AccessibleParaManager::VectorOfChildren::iterator AccessibleParaManager::begin()
      93             :     {
      94           0 :         return maChildren.begin();
      95             :     }
      96             : 
      97           0 :     AccessibleParaManager::VectorOfChildren::iterator AccessibleParaManager::end()
      98             :     {
      99           0 :         return maChildren.end();
     100             :     }
     101             : 
     102           0 :     AccessibleParaManager::VectorOfChildren::const_iterator AccessibleParaManager::begin() const
     103             :     {
     104           0 :         return maChildren.begin();
     105             :     }
     106             : 
     107           0 :     AccessibleParaManager::VectorOfChildren::const_iterator AccessibleParaManager::end() const
     108             :     {
     109           0 :         return maChildren.end();
     110             :     }
     111             : 
     112           0 :     void AccessibleParaManager::FireEvent( sal_Int32 nPara,
     113             :                                            const sal_Int16 nEventId,
     114             :                                            const uno::Any& rNewValue,
     115             :                                            const uno::Any& rOldValue ) const
     116             :     {
     117             :         DBG_ASSERT( 0 <= nPara && maChildren.size() > static_cast<size_t>(nPara),
     118             :                 "AccessibleParaManager::FireEvent: invalid index" );
     119             : 
     120           0 :         if( 0 <= nPara && maChildren.size() > static_cast<size_t>(nPara) )
     121             :         {
     122           0 :             WeakPara::HardRefType maChild( GetChild( nPara ).first.get() );
     123           0 :             if( maChild.is() )
     124           0 :                 maChild->FireEvent( nEventId, rNewValue, rOldValue );
     125             :         }
     126           0 :     }
     127             : 
     128           0 :     bool AccessibleParaManager::IsReferencable( WeakPara::HardRefType aChild )
     129             :     {
     130           0 :         return aChild.is();
     131             :     }
     132             : 
     133           0 :     bool AccessibleParaManager::IsReferencable( sal_Int32 nChild ) const
     134             :     {
     135             :         DBG_ASSERT( 0 <= nChild && maChildren.size() > static_cast<size_t>(nChild),
     136             :                 "AccessibleParaManager::IsReferencable: invalid index" );
     137             : 
     138           0 :         if( 0 <= nChild && maChildren.size() > static_cast<size_t>(nChild) )
     139             :         {
     140             :             // retrieve hard reference from weak one
     141           0 :             return IsReferencable( GetChild( nChild ).first.get() );
     142             :         }
     143             :         else
     144             :         {
     145           0 :             return false;
     146             :         }
     147             :     }
     148             : 
     149           0 :     AccessibleParaManager::WeakChild AccessibleParaManager::GetChild( sal_Int32 nParagraphIndex ) const
     150             :     {
     151             :         DBG_ASSERT( 0 <= nParagraphIndex && maChildren.size() > static_cast<size_t>(nParagraphIndex),
     152             :                 "AccessibleParaManager::GetChild: invalid index" );
     153             : 
     154           0 :         if( 0 <= nParagraphIndex && maChildren.size() > static_cast<size_t>(nParagraphIndex) )
     155             :         {
     156           0 :             return maChildren[ nParagraphIndex ];
     157             :         }
     158             :         else
     159             :         {
     160           0 :             return WeakChild();
     161             :         }
     162             :     }
     163             : 
     164           0 :     AccessibleParaManager::Child AccessibleParaManager::CreateChild( sal_Int32                              nChild,
     165             :                                                                      const uno::Reference< XAccessible >&   xFrontEnd,
     166             :                                                                      SvxEditSourceAdapter&                  rEditSource,
     167             :                                                                      sal_Int32                              nParagraphIndex )
     168             :     {
     169             :         DBG_ASSERT( 0 <= nParagraphIndex && maChildren.size() > static_cast<size_t>(nParagraphIndex),
     170             :                 "AccessibleParaManager::CreateChild: invalid index" );
     171             : 
     172           0 :         if( 0 <= nParagraphIndex && maChildren.size() > static_cast<size_t>(nParagraphIndex) )
     173             :         {
     174             :             // retrieve hard reference from weak one
     175           0 :             WeakPara::HardRefType aChild( GetChild( nParagraphIndex ).first.get() );
     176             : 
     177           0 :             if( !IsReferencable( nParagraphIndex ) )
     178             :             {
     179             :                 // there is no hard reference available, create object then
     180             :                 // #i27138#
     181           0 :                 AccessibleEditableTextPara* pChild = new AccessibleEditableTextPara( xFrontEnd, this );
     182           0 :                 uno::Reference< XAccessible > xChild( static_cast< ::cppu::OWeakObject* > (pChild), uno::UNO_QUERY );
     183             : 
     184           0 :                 if( !xChild.is() )
     185           0 :                     throw uno::RuntimeException("Child creation failed", xFrontEnd);
     186             : 
     187           0 :                 aChild = WeakPara::HardRefType( xChild, pChild );
     188             : 
     189           0 :                 InitChild( *aChild, rEditSource, nChild, nParagraphIndex );
     190             : 
     191           0 :                 maChildren[ nParagraphIndex ] = WeakChild( aChild, pChild->getBounds() );
     192             :             }
     193             : 
     194           0 :             return Child( aChild.getRef(), GetChild( nParagraphIndex ).second );
     195             :         }
     196             :         else
     197             :         {
     198           0 :             return Child();
     199             :         }
     200             :     }
     201             : 
     202           0 :     void AccessibleParaManager::SetEEOffset( const Point& rOffset )
     203             :     {
     204           0 :         maEEOffset = rOffset;
     205             : 
     206           0 :         MemFunAdapter< const Point& > aAdapter( &::accessibility::AccessibleEditableTextPara::SetEEOffset, rOffset );
     207           0 :         ::std::for_each( begin(), end(), aAdapter );
     208           0 :     }
     209             : 
     210           0 :     void AccessibleParaManager::SetActive( bool bActive )
     211             :     {
     212           0 :         mbActive = bActive;
     213             : 
     214           0 :         if( bActive )
     215             :         {
     216           0 :             SetState( AccessibleStateType::ACTIVE );
     217           0 :             SetState( AccessibleStateType::EDITABLE );
     218             :         }
     219             :         else
     220             :         {
     221           0 :             UnSetState( AccessibleStateType::ACTIVE );
     222           0 :             UnSetState( AccessibleStateType::EDITABLE );
     223             :         }
     224           0 :     }
     225             : 
     226           0 :     void AccessibleParaManager::SetFocus( sal_Int32 nChild )
     227             :     {
     228           0 :         if( mnFocusedChild != -1 )
     229           0 :             UnSetState( mnFocusedChild, AccessibleStateType::FOCUSED );
     230             : 
     231           0 :         mnFocusedChild = nChild;
     232             : 
     233           0 :         if( mnFocusedChild != -1 )
     234           0 :             SetState( mnFocusedChild, AccessibleStateType::FOCUSED );
     235           0 :     }
     236             : 
     237           0 :     void AccessibleParaManager::InitChild( AccessibleEditableTextPara&  rChild,
     238             :                                            SvxEditSourceAdapter&        rEditSource,
     239             :                                            sal_Int32                    nChild,
     240             :                                            sal_Int32                    nParagraphIndex ) const
     241             :     {
     242           0 :         rChild.SetEditSource( &rEditSource );
     243           0 :         rChild.SetIndexInParent( nChild );
     244           0 :         rChild.SetParagraphIndex( nParagraphIndex );
     245             : 
     246           0 :         rChild.SetEEOffset( maEEOffset );
     247             : 
     248           0 :         if( mbActive )
     249             :         {
     250           0 :             rChild.SetState( AccessibleStateType::ACTIVE );
     251           0 :             rChild.SetState( AccessibleStateType::EDITABLE );
     252             :         }
     253             : 
     254           0 :         if( mnFocusedChild == nParagraphIndex )
     255           0 :             rChild.SetState( AccessibleStateType::FOCUSED );
     256             : 
     257             :         // add states passed from outside
     258           0 :         for( VectorOfStates::const_iterator aIt = maChildStates.begin(), aEnd = maChildStates.end(); aIt != aEnd; ++aIt )
     259           0 :             rChild.SetState( *aIt );
     260           0 :     }
     261             : 
     262           0 :     void AccessibleParaManager::SetState( sal_Int32 nChild, const sal_Int16 nStateId )
     263             :     {
     264             :         MemFunAdapter< const sal_Int16 > aFunc( &AccessibleEditableTextPara::SetState,
     265           0 :                                                 nStateId );
     266           0 :         aFunc( GetChild(nChild) );
     267           0 :     }
     268             : 
     269           0 :     void AccessibleParaManager::SetState( const sal_Int16 nStateId )
     270             :     {
     271             :         ::std::for_each( begin(), end(),
     272             :                          MemFunAdapter< const sal_Int16 >( &AccessibleEditableTextPara::SetState,
     273           0 :                                                            nStateId ) );
     274           0 :     }
     275             : 
     276           0 :     void AccessibleParaManager::UnSetState( sal_Int32 nChild, const sal_Int16 nStateId )
     277             :     {
     278             :         MemFunAdapter< const sal_Int16 > aFunc( &AccessibleEditableTextPara::UnSetState,
     279           0 :                                                 nStateId );
     280           0 :         aFunc( GetChild(nChild) );
     281           0 :     }
     282             : 
     283           0 :     void AccessibleParaManager::UnSetState( const sal_Int16 nStateId )
     284             :     {
     285             :         ::std::for_each( begin(), end(),
     286             :                          MemFunAdapter< const sal_Int16 >( &AccessibleEditableTextPara::UnSetState,
     287           0 :                                                            nStateId ) );
     288           0 :     }
     289             : 
     290             :     // not generic yet, no arguments...
     291             :     class AccessibleParaManager_DisposeChildren : public ::std::unary_function< ::accessibility::AccessibleEditableTextPara&, void >
     292             :     {
     293             :     public:
     294           0 :         AccessibleParaManager_DisposeChildren() {}
     295           0 :         void operator()( ::accessibility::AccessibleEditableTextPara& rPara )
     296             :         {
     297           0 :             rPara.Dispose();
     298           0 :         }
     299             :     };
     300             : 
     301           0 :     void AccessibleParaManager::Dispose()
     302             :     {
     303           0 :         AccessibleParaManager_DisposeChildren aFunctor;
     304             : 
     305             :         ::std::for_each( begin(), end(),
     306           0 :                          WeakChildAdapter< AccessibleParaManager_DisposeChildren > (aFunctor) );
     307           0 :     }
     308             : 
     309             :     // not generic yet, too many method arguments...
     310             :     class StateChangeEvent : public ::std::unary_function< ::accessibility::AccessibleEditableTextPara&, void >
     311             :     {
     312             :     public:
     313             :         typedef void return_type;
     314           0 :         StateChangeEvent( const sal_Int16 nEventId,
     315             :                           const uno::Any& rNewValue,
     316             :                           const uno::Any& rOldValue ) :
     317             :             mnEventId( nEventId ),
     318             :             mrNewValue( rNewValue ),
     319           0 :             mrOldValue( rOldValue ) {}
     320           0 :         void operator()( ::accessibility::AccessibleEditableTextPara& rPara )
     321             :         {
     322           0 :             rPara.FireEvent( mnEventId, mrNewValue, mrOldValue );
     323           0 :         }
     324             : 
     325             :     private:
     326             :         const sal_Int16 mnEventId;
     327             :         const uno::Any& mrNewValue;
     328             :         const uno::Any& mrOldValue;
     329             :     };
     330             : 
     331           0 :     void AccessibleParaManager::FireEvent( sal_Int32 nStartPara,
     332             :                                            sal_Int32 nEndPara,
     333             :                                            const sal_Int16 nEventId,
     334             :                                            const uno::Any& rNewValue,
     335             :                                            const uno::Any& rOldValue ) const
     336             :     {
     337             :         DBG_ASSERT( 0 <= nStartPara && 0 <= nEndPara &&
     338             :                     maChildren.size() > static_cast<size_t>(nStartPara) &&
     339             :                     maChildren.size() >= static_cast<size_t>(nEndPara) &&
     340             :                     nEndPara >= nStartPara, "AccessibleParaManager::FireEvent: invalid index" );
     341             : 
     342             : 
     343             : 
     344           0 :         if( 0 <= nStartPara && 0 <= nEndPara &&
     345           0 :                 maChildren.size() > static_cast<size_t>(nStartPara) &&
     346           0 :                 maChildren.size() >= static_cast<size_t>(nEndPara) &&
     347             :                 nEndPara >= nStartPara )
     348             :         {
     349           0 :             VectorOfChildren::const_iterator front = maChildren.begin();
     350           0 :             VectorOfChildren::const_iterator back = front;
     351             : 
     352           0 :             ::std::advance( front, nStartPara );
     353           0 :             ::std::advance( back, nEndPara );
     354             : 
     355           0 :             StateChangeEvent aFunctor( nEventId, rNewValue, rOldValue );
     356             : 
     357           0 :             ::std::for_each( front, back, AccessibleParaManager::WeakChildAdapter< StateChangeEvent >( aFunctor ) );
     358             :         }
     359           0 :     }
     360             : 
     361             :     class ReleaseChild : public ::std::unary_function< const AccessibleParaManager::WeakChild&, AccessibleParaManager::WeakChild >
     362             :     {
     363             :     public:
     364           0 :         AccessibleParaManager::WeakChild operator()( const AccessibleParaManager::WeakChild& rPara )
     365             :         {
     366           0 :             AccessibleParaManager::ShutdownPara( rPara );
     367             : 
     368             :             // clear reference
     369           0 :             return AccessibleParaManager::WeakChild();
     370             :         }
     371             :     };
     372             : 
     373           0 :     void AccessibleParaManager::Release( sal_Int32 nStartPara, sal_Int32 nEndPara )
     374             :     {
     375             :         DBG_ASSERT( 0 <= nStartPara && 0 <= nEndPara &&
     376             :                     maChildren.size() > static_cast<size_t>(nStartPara) &&
     377             :                     maChildren.size() >= static_cast<size_t>(nEndPara),
     378             :                     "AccessibleParaManager::Release: invalid index" );
     379             : 
     380           0 :         if( 0 <= nStartPara && 0 <= nEndPara &&
     381           0 :                 maChildren.size() > static_cast<size_t>(nStartPara) &&
     382           0 :                 maChildren.size() >= static_cast<size_t>(nEndPara) )
     383             :         {
     384           0 :             VectorOfChildren::iterator front = maChildren.begin();
     385           0 :             VectorOfChildren::iterator back = front;
     386             : 
     387           0 :             ::std::advance( front, nStartPara );
     388           0 :             ::std::advance( back, nEndPara );
     389             : 
     390           0 :             ::std::transform( front, back, front, ReleaseChild() );
     391             :         }
     392           0 :     }
     393             : 
     394           0 :     void AccessibleParaManager::ShutdownPara( const WeakChild& rChild )
     395             :     {
     396           0 :         WeakPara::HardRefType aChild( rChild.first.get() );
     397             : 
     398           0 :         if( IsReferencable( aChild ) )
     399           0 :             aChild->SetEditSource( NULL );
     400           0 :     }
     401             : 
     402             : }
     403             : 
     404             : 
     405             : 
     406             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10