LCOV - code coverage report
Current view: top level - editeng/source/accessibility - AccessibleParaManager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 82 146 56.2 %
Date: 2012-08-25 Functions: 19 32 59.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 61 184 33.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : //------------------------------------------------------------------------
      31                 :            : //
      32                 :            : // Global header
      33                 :            : //
      34                 :            : //------------------------------------------------------------------------
      35                 :            : #include <com/sun/star/uno/Any.hxx>
      36                 :            : #include <com/sun/star/uno/Reference.hxx>
      37                 :            : #include <cppuhelper/weakref.hxx>
      38                 :            : #include <com/sun/star/accessibility/XAccessible.hpp>
      39                 :            : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      40                 :            : 
      41                 :            : //------------------------------------------------------------------------
      42                 :            : //
      43                 :            : // Project-local header
      44                 :            : //
      45                 :            : //------------------------------------------------------------------------
      46                 :            : 
      47                 :            : #include <editeng/unoedhlp.hxx>
      48                 :            : #include <editeng/unopracc.hxx>
      49                 :            : #include <editeng/unoedsrc.hxx>
      50                 :            : #include "editeng/AccessibleParaManager.hxx"
      51                 :            : #include "editeng/AccessibleEditableTextPara.hxx"
      52                 :            : 
      53                 :            : 
      54                 :            : using namespace ::com::sun::star;
      55                 :            : using namespace ::com::sun::star::accessibility;
      56                 :            : 
      57                 :            : 
      58                 :            : 
      59                 :            : namespace accessibility
      60                 :            : {
      61                 :         56 :     AccessibleParaManager::AccessibleParaManager() :
      62                 :            :         maChildren(1),
      63                 :            :         maEEOffset( 0, 0 ),
      64                 :            :         mnFocusedChild( -1 ),
      65         [ +  - ]:         56 :         mbActive( sal_False )
      66                 :            :     {
      67                 :         56 :     }
      68                 :            : 
      69                 :         45 :     AccessibleParaManager::~AccessibleParaManager()
      70                 :            :     {
      71                 :            :         // owner is responsible for possible child defuncs
      72                 :         45 :     }
      73                 :            : 
      74                 :         15 :     void AccessibleParaManager::SetAdditionalChildStates( const VectorOfStates& rChildStates )
      75                 :            :     {
      76                 :         15 :         maChildStates = rChildStates;
      77                 :         15 :     }
      78                 :            : 
      79                 :        116 :     void AccessibleParaManager::SetNum( sal_Int32 nNumParas )
      80                 :            :     {
      81         [ +  + ]:        116 :         if( (size_t)nNumParas < maChildren.size() )
      82                 :         60 :             Release( nNumParas, maChildren.size() );
      83                 :            : 
      84                 :        116 :         maChildren.resize( nNumParas );
      85                 :            : 
      86         [ -  + ]:        116 :         if( mnFocusedChild >= nNumParas )
      87                 :          0 :             mnFocusedChild = -1;
      88                 :        116 :     }
      89                 :            : 
      90                 :         11 :     sal_uInt32 AccessibleParaManager::GetNum() const
      91                 :            :     {
      92                 :         11 :         return maChildren.size();
      93                 :            :     }
      94                 :            : 
      95                 :        157 :     AccessibleParaManager::VectorOfChildren::iterator AccessibleParaManager::begin()
      96                 :            :     {
      97                 :        157 :         return maChildren.begin();
      98                 :            :     }
      99                 :            : 
     100                 :        137 :     AccessibleParaManager::VectorOfChildren::iterator AccessibleParaManager::end()
     101                 :            :     {
     102                 :        137 :         return maChildren.end();
     103                 :            :     }
     104                 :            : 
     105                 :          0 :     AccessibleParaManager::VectorOfChildren::const_iterator AccessibleParaManager::begin() const
     106                 :            :     {
     107                 :          0 :         return maChildren.begin();
     108                 :            :     }
     109                 :            : 
     110                 :          0 :     AccessibleParaManager::VectorOfChildren::const_iterator AccessibleParaManager::end() const
     111                 :            :     {
     112                 :          0 :         return maChildren.end();
     113                 :            :     }
     114                 :            : 
     115                 :          1 :     void AccessibleParaManager::Release( sal_uInt32 nPara )
     116                 :            :     {
     117                 :            :         DBG_ASSERT( maChildren.size() > nPara, "AccessibleParaManager::Release: invalid index" );
     118                 :            : 
     119         [ +  - ]:          1 :         if( maChildren.size() > nPara )
     120                 :            :         {
     121         [ +  - ]:          1 :             ShutdownPara( GetChild( nPara ) );
     122                 :            : 
     123                 :            :             // clear reference and rect
     124         [ +  - ]:          1 :             maChildren[ nPara ] = WeakChild();
     125                 :            :         }
     126                 :          1 :     }
     127                 :            : 
     128                 :          0 :     void AccessibleParaManager::FireEvent( sal_uInt32 nPara,
     129                 :            :                                            const sal_Int16 nEventId,
     130                 :            :                                            const uno::Any& rNewValue,
     131                 :            :                                            const uno::Any& rOldValue ) const
     132                 :            :     {
     133                 :            :         DBG_ASSERT( maChildren.size() > nPara, "AccessibleParaManager::FireEvent: invalid index" );
     134                 :            : 
     135         [ #  # ]:          0 :         if( maChildren.size() > nPara )
     136                 :            :         {
     137 [ #  # ][ #  # ]:          0 :             WeakPara::HardRefType maChild( GetChild( nPara ).first.get() );
                 [ #  # ]
     138         [ #  # ]:          0 :             if( maChild.is() )
     139 [ #  # ][ #  # ]:          0 :                 maChild->FireEvent( nEventId, rNewValue, rOldValue );
     140                 :            :         }
     141                 :          0 :     }
     142                 :            : 
     143                 :        134 :     sal_Bool AccessibleParaManager::IsReferencable( WeakPara::HardRefType aChild )
     144                 :            :     {
     145                 :        134 :         return aChild.is();
     146                 :            :     }
     147                 :            : 
     148                 :         73 :     sal_Bool AccessibleParaManager::IsReferencable( sal_uInt32 nChild ) const
     149                 :            :     {
     150                 :            :         DBG_ASSERT( maChildren.size() > nChild, "AccessibleParaManager::IsReferencable: invalid index" );
     151                 :            : 
     152         [ +  - ]:         73 :         if( maChildren.size() > nChild )
     153                 :            :         {
     154                 :            :             // retrieve hard reference from weak one
     155 [ +  - ][ +  - ]:         73 :             return IsReferencable( GetChild( nChild ).first.get() );
                 [ +  - ]
     156                 :            :         }
     157                 :            :         else
     158                 :            :         {
     159                 :         73 :             return sal_False;
     160                 :            :         }
     161                 :            :     }
     162                 :            : 
     163                 :        258 :     AccessibleParaManager::WeakChild AccessibleParaManager::GetChild( sal_uInt32 nParagraphIndex ) const
     164                 :            :     {
     165                 :            :         DBG_ASSERT( maChildren.size() > nParagraphIndex, "AccessibleParaManager::GetChild: invalid index" );
     166                 :            : 
     167         [ +  - ]:        258 :         if( maChildren.size() > nParagraphIndex )
     168                 :            :         {
     169                 :        258 :             return maChildren[ nParagraphIndex ];
     170                 :            :         }
     171                 :            :         else
     172                 :            :         {
     173                 :        258 :             return WeakChild();
     174                 :            :         }
     175                 :            :     }
     176                 :            : 
     177                 :         60 :     AccessibleParaManager::Child AccessibleParaManager::CreateChild( sal_Int32                              nChild,
     178                 :            :                                                                      const uno::Reference< XAccessible >&   xFrontEnd,
     179                 :            :                                                                      SvxEditSourceAdapter&                  rEditSource,
     180                 :            :                                                                      sal_uInt32                             nParagraphIndex )
     181                 :            :     {
     182                 :            :         DBG_ASSERT( maChildren.size() > nParagraphIndex, "AccessibleParaManager::CreateChild: invalid index" );
     183                 :            : 
     184         [ +  - ]:         60 :         if( maChildren.size() > nParagraphIndex )
     185                 :            :         {
     186                 :            :             // retrieve hard reference from weak one
     187 [ +  - ][ +  - ]:         60 :             WeakPara::HardRefType aChild( GetChild( nParagraphIndex ).first.get() );
                 [ +  - ]
     188                 :            : 
     189 [ +  - ][ +  + ]:         60 :             if( !IsReferencable( nParagraphIndex ) )
     190                 :            :             {
     191                 :            :                 // there is no hard reference available, create object then
     192                 :            :                 // #i27138#
     193         [ +  - ]:         45 :                 AccessibleEditableTextPara* pChild = new AccessibleEditableTextPara( xFrontEnd, this );
     194         [ +  - ]:         45 :                 uno::Reference< XAccessible > xChild( static_cast< ::cppu::OWeakObject* > (pChild), uno::UNO_QUERY );
     195                 :            : 
     196         [ -  + ]:         45 :                 if( !xChild.is() )
     197 [ #  # ][ #  # ]:          0 :                     throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Child creation failed")), xFrontEnd);
     198                 :            : 
     199 [ +  - ][ +  - ]:         45 :                 aChild = WeakPara::HardRefType( xChild, pChild );
         [ +  - ][ +  - ]
                 [ +  - ]
     200                 :            : 
     201         [ +  - ]:         45 :                 InitChild( *aChild, rEditSource, nChild, nParagraphIndex );
     202                 :            : 
     203 [ +  - ][ +  - ]:         45 :                 maChildren[ nParagraphIndex ] = WeakChild( aChild, pChild->getBounds() );
         [ +  - ][ +  - ]
     204                 :            :             }
     205                 :            : 
     206 [ +  - ][ +  - ]:         60 :             return Child( aChild.getRef(), GetChild( nParagraphIndex ).second );
         [ +  - ][ +  - ]
     207                 :            :         }
     208                 :            :         else
     209                 :            :         {
     210                 :         60 :             return Child();
     211                 :            :         }
     212                 :            :     }
     213                 :            : 
     214                 :          0 :     void AccessibleParaManager::SetEEOffset( const Point& rOffset )
     215                 :            :     {
     216                 :          0 :         maEEOffset = rOffset;
     217                 :            : 
     218                 :          0 :         MemFunAdapter< const Point& > aAdapter( &::accessibility::AccessibleEditableTextPara::SetEEOffset, rOffset );
     219 [ #  # ][ #  # ]:          0 :         ::std::for_each( begin(), end(), aAdapter );
                 [ #  # ]
     220                 :          0 :     }
     221                 :            : 
     222                 :          0 :     void AccessibleParaManager::SetActive( sal_Bool bActive )
     223                 :            :     {
     224                 :          0 :         mbActive = bActive;
     225                 :            : 
     226         [ #  # ]:          0 :         if( bActive )
     227                 :            :         {
     228                 :          0 :             SetState( AccessibleStateType::ACTIVE );
     229                 :          0 :             SetState( AccessibleStateType::EDITABLE );
     230                 :            :         }
     231                 :            :         else
     232                 :            :         {
     233                 :          0 :             UnSetState( AccessibleStateType::ACTIVE );
     234                 :          0 :             UnSetState( AccessibleStateType::EDITABLE );
     235                 :            :         }
     236                 :          0 :     }
     237                 :            : 
     238                 :          0 :     void AccessibleParaManager::SetFocus( sal_Int32 nChild )
     239                 :            :     {
     240         [ #  # ]:          0 :         if( mnFocusedChild != -1 )
     241                 :          0 :             UnSetState( mnFocusedChild, AccessibleStateType::FOCUSED );
     242                 :            : 
     243                 :          0 :         mnFocusedChild = nChild;
     244                 :            : 
     245         [ #  # ]:          0 :         if( mnFocusedChild != -1 )
     246                 :          0 :             SetState( mnFocusedChild, AccessibleStateType::FOCUSED );
     247                 :          0 :     }
     248                 :            : 
     249                 :         45 :     void AccessibleParaManager::InitChild( AccessibleEditableTextPara&  rChild,
     250                 :            :                                            SvxEditSourceAdapter&        rEditSource,
     251                 :            :                                            sal_Int32                    nChild,
     252                 :            :                                            sal_uInt32                   nParagraphIndex ) const
     253                 :            :     {
     254                 :         45 :         rChild.SetEditSource( &rEditSource );
     255                 :         45 :         rChild.SetIndexInParent( nChild );
     256                 :         45 :         rChild.SetParagraphIndex( nParagraphIndex );
     257                 :            : 
     258                 :         45 :         rChild.SetEEOffset( maEEOffset );
     259                 :            : 
     260         [ -  + ]:         45 :         if( mbActive )
     261                 :            :         {
     262                 :          0 :             rChild.SetState( AccessibleStateType::ACTIVE );
     263                 :          0 :             rChild.SetState( AccessibleStateType::EDITABLE );
     264                 :            :         }
     265                 :            : 
     266         [ -  + ]:         45 :         if( mnFocusedChild == static_cast<sal_Int32>(nParagraphIndex) )
     267                 :          0 :             rChild.SetState( AccessibleStateType::FOCUSED );
     268                 :            : 
     269                 :            :         // add states passed from outside
     270 [ +  - ][ +  - ]:         58 :         for( VectorOfStates::const_iterator aIt = maChildStates.begin(), aEnd = maChildStates.end(); aIt != aEnd; ++aIt )
                 [ +  + ]
     271 [ +  - ][ +  - ]:         13 :             rChild.SetState( *aIt );
     272                 :         45 :     }
     273                 :            : 
     274                 :          0 :     void AccessibleParaManager::SetState( sal_Int32 nChild, const sal_Int16 nStateId )
     275                 :            :     {
     276                 :            :         MemFunAdapter< const sal_Int16 > aFunc( &AccessibleEditableTextPara::SetState,
     277         [ #  # ]:          0 :                                                 nStateId );
     278 [ #  # ][ #  # ]:          0 :         aFunc( GetChild(nChild) );
                 [ #  # ]
     279                 :          0 :     }
     280                 :            : 
     281                 :          0 :     void AccessibleParaManager::SetState( const sal_Int16 nStateId )
     282                 :            :     {
     283                 :            :         ::std::for_each( begin(), end(),
     284                 :            :                          MemFunAdapter< const sal_Int16 >( &AccessibleEditableTextPara::SetState,
     285 [ #  # ][ #  # ]:          0 :                                                            nStateId ) );
                 [ #  # ]
     286                 :          0 :     }
     287                 :            : 
     288                 :          0 :     void AccessibleParaManager::UnSetState( sal_Int32 nChild, const sal_Int16 nStateId )
     289                 :            :     {
     290                 :            :         MemFunAdapter< const sal_Int16 > aFunc( &AccessibleEditableTextPara::UnSetState,
     291         [ #  # ]:          0 :                                                 nStateId );
     292 [ #  # ][ #  # ]:          0 :         aFunc( GetChild(nChild) );
                 [ #  # ]
     293                 :          0 :     }
     294                 :            : 
     295                 :          0 :     void AccessibleParaManager::UnSetState( const sal_Int16 nStateId )
     296                 :            :     {
     297                 :            :         ::std::for_each( begin(), end(),
     298                 :            :                          MemFunAdapter< const sal_Int16 >( &AccessibleEditableTextPara::UnSetState,
     299 [ #  # ][ #  # ]:          0 :                                                            nStateId ) );
                 [ #  # ]
     300                 :          0 :     }
     301                 :            : 
     302                 :            :     // not generic yet, no arguments...
     303                 :            :     class AccessibleParaManager_DisposeChildren : public ::std::unary_function< ::accessibility::AccessibleEditableTextPara&, void >
     304                 :            :     {
     305                 :            :     public:
     306                 :        117 :         AccessibleParaManager_DisposeChildren() {}
     307                 :         34 :         void operator()( ::accessibility::AccessibleEditableTextPara& rPara )
     308                 :            :         {
     309                 :         34 :             rPara.Dispose();
     310                 :         34 :         }
     311                 :            :     };
     312                 :            : 
     313                 :        117 :     void AccessibleParaManager::Dispose()
     314                 :            :     {
     315                 :        117 :         AccessibleParaManager_DisposeChildren aFunctor;
     316                 :            : 
     317                 :            :         ::std::for_each( begin(), end(),
     318 [ +  - ][ +  - ]:        117 :                          WeakChildAdapter< AccessibleParaManager_DisposeChildren > (aFunctor) );
                 [ +  - ]
     319                 :        117 :     }
     320                 :            : 
     321                 :            :     // not generic yet, too many method arguments...
     322                 :            :     class StateChangeEvent : public ::std::unary_function< ::accessibility::AccessibleEditableTextPara&, void >
     323                 :            :     {
     324                 :            :     public:
     325                 :            :         typedef void return_type;
     326                 :          0 :         StateChangeEvent( const sal_Int16 nEventId,
     327                 :            :                           const uno::Any& rNewValue,
     328                 :            :                           const uno::Any& rOldValue ) :
     329                 :            :             mnEventId( nEventId ),
     330                 :            :             mrNewValue( rNewValue ),
     331                 :          0 :             mrOldValue( rOldValue ) {}
     332                 :          0 :         void operator()( ::accessibility::AccessibleEditableTextPara& rPara )
     333                 :            :         {
     334                 :          0 :             rPara.FireEvent( mnEventId, mrNewValue, mrOldValue );
     335                 :          0 :         }
     336                 :            : 
     337                 :            :     private:
     338                 :            :         const sal_Int16 mnEventId;
     339                 :            :         const uno::Any& mrNewValue;
     340                 :            :         const uno::Any& mrOldValue;
     341                 :            :     };
     342                 :            : 
     343                 :          0 :     void AccessibleParaManager::FireEvent( sal_uInt32 nStartPara,
     344                 :            :                                            sal_uInt32 nEndPara,
     345                 :            :                                            const sal_Int16 nEventId,
     346                 :            :                                            const uno::Any& rNewValue,
     347                 :            :                                            const uno::Any& rOldValue ) const
     348                 :            :     {
     349                 :            :         DBG_ASSERT( maChildren.size() > nStartPara &&
     350                 :            :                     maChildren.size() >= nEndPara , "AccessibleParaManager::FireEvent: invalid index" );
     351                 :            : 
     352   [ #  #  #  # ]:          0 :         if( maChildren.size() > nStartPara &&
                 [ #  # ]
     353                 :          0 :             maChildren.size() >= nEndPara )
     354                 :            :         {
     355                 :          0 :             VectorOfChildren::const_iterator front = maChildren.begin();
     356                 :          0 :             VectorOfChildren::const_iterator back = front;
     357                 :            : 
     358         [ #  # ]:          0 :             ::std::advance( front, nStartPara );
     359         [ #  # ]:          0 :             ::std::advance( back, nEndPara );
     360                 :            : 
     361                 :          0 :             StateChangeEvent aFunctor( nEventId, rNewValue, rOldValue );
     362                 :            : 
     363         [ #  # ]:          0 :             ::std::for_each( front, back, AccessibleParaManager::WeakChildAdapter< StateChangeEvent >( aFunctor ) );
     364                 :            :         }
     365                 :          0 :     }
     366                 :            : 
     367                 :            :     class ReleaseChild : public ::std::unary_function< const AccessibleParaManager::WeakChild&, AccessibleParaManager::WeakChild >
     368                 :            :     {
     369                 :            :     public:
     370                 :         60 :         AccessibleParaManager::WeakChild operator()( const AccessibleParaManager::WeakChild& rPara )
     371                 :            :         {
     372                 :         60 :             AccessibleParaManager::ShutdownPara( rPara );
     373                 :            : 
     374                 :            :             // clear reference
     375                 :         60 :             return AccessibleParaManager::WeakChild();
     376                 :            :         }
     377                 :            :     };
     378                 :            : 
     379                 :         60 :     void AccessibleParaManager::Release( sal_uInt32 nStartPara, sal_uInt32 nEndPara )
     380                 :            :     {
     381                 :            :         DBG_ASSERT( maChildren.size() > nStartPara &&
     382                 :            :                     maChildren.size() >= nEndPara, "AccessibleParaManager::Release: invalid index" );
     383                 :            : 
     384   [ +  -  +  - ]:        120 :         if( maChildren.size() > nStartPara &&
                 [ +  - ]
     385                 :         60 :             maChildren.size() >= nEndPara )
     386                 :            :         {
     387                 :         60 :             VectorOfChildren::iterator front = maChildren.begin();
     388                 :         60 :             VectorOfChildren::iterator back = front;
     389                 :            : 
     390         [ +  - ]:         60 :             ::std::advance( front, nStartPara );
     391         [ +  - ]:         60 :             ::std::advance( back, nEndPara );
     392                 :            : 
     393         [ +  - ]:         60 :             ::std::transform( front, back, front, ReleaseChild() );
     394                 :            :         }
     395                 :         60 :     }
     396                 :            : 
     397                 :         61 :     void AccessibleParaManager::ShutdownPara( const WeakChild& rChild )
     398                 :            :     {
     399         [ +  - ]:         61 :         WeakPara::HardRefType aChild( rChild.first.get() );
     400                 :            : 
     401 [ +  - ][ +  - ]:         61 :         if( IsReferencable( aChild ) )
         [ +  - ][ +  + ]
     402 [ +  - ][ +  - ]:         61 :             aChild->SetEditSource( NULL );
     403                 :         61 :     }
     404                 :            : 
     405                 :            : }
     406                 :            : 
     407                 :            : //------------------------------------------------------------------------
     408                 :            : 
     409                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10