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

Generated by: LCOV version 1.10