LCOV - code coverage report
Current view: top level - sd/source/core - CustomAnimationCloner.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 111 0.0 %
Date: 2012-08-25 Functions: 0 8 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 276 0.0 %

           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                 :            : #include <com/sun/star/animations/XAnimationNode.hpp>
      30                 :            : #include <com/sun/star/animations/Event.hpp>
      31                 :            : #include <com/sun/star/animations/XAnimateColor.hpp>
      32                 :            : #include <com/sun/star/animations/XAnimateSet.hpp>
      33                 :            : #include <com/sun/star/animations/XCommand.hpp>
      34                 :            : #include <com/sun/star/animations/XAnimateMotion.hpp>
      35                 :            : #include <com/sun/star/animations/XAnimateTransform.hpp>
      36                 :            : #include <com/sun/star/animations/XTransitionFilter.hpp>
      37                 :            : #include <com/sun/star/animations/XIterateContainer.hpp>
      38                 :            : #include <com/sun/star/animations/XAudio.hpp>
      39                 :            : #include <com/sun/star/animations/AnimationNodeType.hpp>
      40                 :            : #include <com/sun/star/animations/ValuePair.hpp>
      41                 :            : #include <com/sun/star/presentation/EffectNodeType.hpp>
      42                 :            : #include <com/sun/star/util/XCloneable.hpp>
      43                 :            : #include <com/sun/star/presentation/ParagraphTarget.hpp>
      44                 :            : #include <com/sun/star/container/XEnumerationAccess.hpp>
      45                 :            : #include <com/sun/star/beans/NamedValue.hpp>
      46                 :            : 
      47                 :            : #include <map>
      48                 :            : 
      49                 :            : #include "comphelper/anytostring.hxx"
      50                 :            : #include "cppuhelper/exc_hlp.hxx"
      51                 :            : #include "rtl/ref.hxx"
      52                 :            : #include <animations/animationnodehelper.hxx>
      53                 :            : 
      54                 :            : // header for class SdrObjListIter
      55                 :            : #include <svx/svditer.hxx>
      56                 :            : 
      57                 :            : #include "sdpage.hxx"
      58                 :            : 
      59                 :            : using namespace ::com::sun::star::uno;
      60                 :            : using namespace ::com::sun::star::animations;
      61                 :            : using namespace ::com::sun::star::presentation;
      62                 :            : using namespace ::com::sun::star::container;
      63                 :            : 
      64                 :            : using ::rtl::OUString;
      65                 :            : using ::rtl::OString;
      66                 :            : using ::com::sun::star::drawing::XShape;
      67                 :            : using ::com::sun::star::beans::NamedValue;
      68                 :            : 
      69                 :            : namespace sd
      70                 :            : {
      71                 :          0 :     class CustomAnimationClonerImpl
      72                 :            :     {
      73                 :            :     public:
      74                 :            :         CustomAnimationClonerImpl();
      75                 :            :         Reference< XAnimationNode > Clone( const Reference< XAnimationNode >& xSourceNode, const SdPage* pSource = 0, const SdPage* pTarget = 0 );
      76                 :            : 
      77                 :            :     private:
      78                 :            :         void transformNode( const Reference< XAnimationNode >& xNode );
      79                 :            :         Any transformValue( const Any& rValue );
      80                 :            : 
      81                 :            :         Reference< XShape > getClonedShape( const Reference< XShape >& xSource ) const;
      82                 :            :         Reference< XAnimationNode > getClonedNode( const Reference< XAnimationNode >& xSource ) const;
      83                 :            : 
      84                 :            :         mutable ::std::map< Reference< XShape >, Reference< XShape > > maShapeMap;
      85                 :            :         std::vector< Reference< XAnimationNode > > maSourceNodeVector;
      86                 :            :         std::vector< Reference< XAnimationNode > > maCloneNodeVector;
      87                 :            :     };
      88                 :            : 
      89 [ #  # ][ #  # ]:          0 :     CustomAnimationClonerImpl::CustomAnimationClonerImpl()
      90                 :            :     {
      91                 :          0 :     }
      92                 :            : 
      93                 :          0 :     Reference< XAnimationNode > Clone( const Reference< XAnimationNode >& xSourceNode, const SdPage* pSource, const SdPage* pTarget )
      94                 :            :     {
      95         [ #  # ]:          0 :         CustomAnimationClonerImpl aCloner;
      96         [ #  # ]:          0 :         return aCloner.Clone( xSourceNode, pSource, pTarget );
      97                 :            :     }
      98                 :            : 
      99                 :          0 :     Reference< XAnimationNode > CustomAnimationClonerImpl::Clone( const Reference< XAnimationNode >& xSourceNode, const SdPage* pSourcePage, const SdPage* pTargetPage )
     100                 :            :     {
     101                 :            :         try
     102                 :            :         {
     103                 :            :             // clone animation hierarchie
     104         [ #  # ]:          0 :             Reference< ::com::sun::star::util::XCloneable > xClonable( xSourceNode, UNO_QUERY_THROW );
     105 [ #  # ][ #  # ]:          0 :             Reference< XAnimationNode > xCloneNode( xClonable->createClone(), UNO_QUERY_THROW );
                 [ #  # ]
     106                 :            : 
     107                 :            :             // create a dictionary to map source to cloned shapes
     108 [ #  # ][ #  # ]:          0 :             if( pSourcePage && pTargetPage )
     109                 :            :             {
     110         [ #  # ]:          0 :                 SdrObjListIter aSourceIter( *pSourcePage, IM_DEEPWITHGROUPS );
     111         [ #  # ]:          0 :                 SdrObjListIter aTargetIter( *pTargetPage, IM_DEEPWITHGROUPS );
     112                 :            : 
     113 [ #  # ][ #  # ]:          0 :                 while( aSourceIter.IsMore() && aTargetIter.IsMore() )
                 [ #  # ]
     114                 :            :                 {
     115         [ #  # ]:          0 :                     SdrObject* pSource = aSourceIter.Next();
     116         [ #  # ]:          0 :                     SdrObject* pTarget = aTargetIter.Next();
     117                 :            : 
     118 [ #  # ][ #  # ]:          0 :                     if( pSource && pTarget)
     119                 :            :                     {
     120 [ #  # ][ #  # ]:          0 :                         Reference< XShape > xSource( pSource->getUnoShape(), UNO_QUERY );
     121 [ #  # ][ #  # ]:          0 :                         Reference< XShape > xTarget( pTarget->getUnoShape(), UNO_QUERY );
     122 [ #  # ][ #  # ]:          0 :                         if( xSource.is() && xTarget.is() )
                 [ #  # ]
     123                 :            :                         {
     124 [ #  # ][ #  # ]:          0 :                             maShapeMap[xSource] = xTarget;
     125                 :          0 :                         }
     126                 :            :                     }
     127                 :          0 :                 }
     128                 :            :             }
     129                 :            : 
     130                 :            :             // create a dictionary to map source to cloned nodes
     131         [ #  # ]:          0 :             ::anim::create_deep_vector( xSourceNode, maSourceNodeVector );
     132         [ #  # ]:          0 :             ::anim::create_deep_vector( xCloneNode, maCloneNodeVector );
     133                 :            : 
     134         [ #  # ]:          0 :             transformNode( xCloneNode );
     135                 :            : 
     136         [ #  # ]:          0 :             return xCloneNode;
     137                 :            :         }
     138                 :          0 :         catch( Exception& )
     139                 :            :         {
     140                 :            :             OSL_FAIL(
     141                 :            :                 (OString("sd::CustomAnimationClonerImpl::Clone(), "
     142                 :            :                         "exception caught: ") +
     143                 :            :                 rtl::OUStringToOString(
     144                 :            :                     comphelper::anyToString( cppu::getCaughtException() ),
     145                 :            :                     RTL_TEXTENCODING_UTF8 )).getStr() );
     146                 :            : 
     147                 :          0 :             Reference< XAnimationNode > xEmpty;
     148                 :          0 :             return xEmpty;
     149                 :            :         }
     150                 :            :     }
     151                 :            : 
     152                 :          0 :     void CustomAnimationClonerImpl::transformNode( const Reference< XAnimationNode >& xNode )
     153                 :            :     {
     154                 :            :         try
     155                 :            :         {
     156 [ #  # ][ #  # ]:          0 :             xNode->setBegin( transformValue( xNode->getBegin() ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     157 [ #  # ][ #  # ]:          0 :             xNode->setEnd( transformValue( xNode->getEnd() ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     158                 :            : 
     159 [ #  # ][ #  # ]:          0 :             sal_Int16 nNodeType( xNode->getType() );
     160   [ #  #  #  #  :          0 :             switch( nNodeType )
                   #  # ]
     161                 :            :             {
     162                 :            :             case AnimationNodeType::ITERATE:
     163                 :            :             {
     164         [ #  # ]:          0 :                 Reference< XIterateContainer > xIter( xNode, UNO_QUERY_THROW );
     165 [ #  # ][ #  # ]:          0 :                 xIter->setTarget( transformValue( xIter->getTarget() ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     166                 :            :             }
     167                 :            :             // its intended that here is no break!
     168                 :            :             case AnimationNodeType::PAR:
     169                 :            :             case AnimationNodeType::SEQ:
     170                 :            :             {
     171         [ #  # ]:          0 :                 Reference< XEnumerationAccess > xEnumerationAccess( xNode, UNO_QUERY_THROW );
     172 [ #  # ][ #  # ]:          0 :                 Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
                 [ #  # ]
     173 [ #  # ][ #  # ]:          0 :                 while( xEnumeration->hasMoreElements() )
                 [ #  # ]
     174                 :            :                 {
     175 [ #  # ][ #  # ]:          0 :                     Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY_THROW );
                 [ #  # ]
     176         [ #  # ]:          0 :                     transformNode( xChildNode );
     177                 :          0 :                 }
     178                 :            :             }
     179                 :          0 :             break;
     180                 :            : 
     181                 :            :             case AnimationNodeType::ANIMATE:
     182                 :            :             case AnimationNodeType::SET:
     183                 :            :             case AnimationNodeType::ANIMATEMOTION:
     184                 :            :             case AnimationNodeType::ANIMATECOLOR:
     185                 :            :             case AnimationNodeType::ANIMATETRANSFORM:
     186                 :            :             case AnimationNodeType::TRANSITIONFILTER:
     187                 :            :             {
     188         [ #  # ]:          0 :                 Reference< XAnimate > xAnimate( xNode, UNO_QUERY_THROW );
     189 [ #  # ][ #  # ]:          0 :                 xAnimate->setTarget( transformValue( xAnimate->getTarget() ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     190                 :            :             }
     191                 :          0 :             break;
     192                 :            : 
     193                 :            :             case AnimationNodeType::COMMAND:
     194                 :            :             {
     195         [ #  # ]:          0 :                 Reference< XCommand > xCommand( xNode, UNO_QUERY_THROW );
     196 [ #  # ][ #  # ]:          0 :                 xCommand->setTarget( transformValue( xCommand->getTarget() ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     197                 :            :             }
     198                 :          0 :             break;
     199                 :            : 
     200                 :            :             case AnimationNodeType::AUDIO:
     201                 :            :             {
     202         [ #  # ]:          0 :                 Reference< XAudio > xAudio( xNode, UNO_QUERY_THROW );
     203 [ #  # ][ #  # ]:          0 :                 xAudio->setSource( transformValue( xAudio->getSource() ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     204                 :            :             }
     205                 :          0 :             break;
     206                 :            :             }
     207                 :            : 
     208 [ #  # ][ #  # ]:          0 :             Sequence< NamedValue > aUserData( xNode->getUserData() );
     209         [ #  # ]:          0 :             if( aUserData.hasElements() )
     210                 :            :             {
     211         [ #  # ]:          0 :                 NamedValue* pValue = aUserData.getArray();
     212                 :          0 :                 const sal_Int32 nLength = aUserData.getLength();
     213                 :            :                 sal_Int32 nElement;
     214         [ #  # ]:          0 :                 for( nElement = 0; nElement < nLength; nElement++, pValue++ )
     215                 :            :                 {
     216         [ #  # ]:          0 :                     pValue->Value = transformValue( pValue->Value );
     217                 :            :                 }
     218                 :            : 
     219 [ #  # ][ #  # ]:          0 :                 xNode->setUserData( aUserData );
     220 [ #  # ][ #  # ]:          0 :             }
     221                 :            :         }
     222                 :          0 :         catch( Exception& )
     223                 :            :         {
     224                 :            :             OSL_FAIL(
     225                 :            :                 (OString("sd::CustomAnimationClonerImpl::transformNode(), "
     226                 :            :                         "exception caught: ") +
     227                 :            :                 rtl::OUStringToOString(
     228                 :            :                     comphelper::anyToString( cppu::getCaughtException() ),
     229                 :            :                     RTL_TEXTENCODING_UTF8 )).getStr() );
     230                 :            :         }
     231                 :          0 :     }
     232                 :            : 
     233                 :          0 :     Any CustomAnimationClonerImpl::transformValue( const Any& rValue )
     234                 :            :     {
     235         [ #  # ]:          0 :         if( rValue.hasValue() ) try
     236                 :            :         {
     237 [ #  # ][ #  # ]:          0 :             if( rValue.getValueType() == ::getCppuType((const ValuePair*)0) )
     238                 :            :             {
     239                 :          0 :                 ValuePair aValuePair;
     240         [ #  # ]:          0 :                 rValue >>= aValuePair;
     241                 :            : 
     242         [ #  # ]:          0 :                 aValuePair.First = transformValue( aValuePair.First );
     243         [ #  # ]:          0 :                 aValuePair.Second = transformValue( aValuePair.Second );
     244                 :            : 
     245         [ #  # ]:          0 :                 return makeAny( aValuePair );
     246                 :            :             }
     247 [ #  # ][ #  # ]:          0 :             else if( rValue.getValueType() == ::getCppuType((Sequence<Any>*)0) )
     248                 :            :             {
     249         [ #  # ]:          0 :                 Sequence<Any> aSequence;
     250         [ #  # ]:          0 :                 rValue >>= aSequence;
     251                 :            : 
     252                 :          0 :                 const sal_Int32 nLength = aSequence.getLength();
     253                 :            :                 sal_Int32 nElement;
     254         [ #  # ]:          0 :                 Any* pAny = aSequence.getArray();
     255                 :            : 
     256         [ #  # ]:          0 :                 for( nElement = 0; nElement < nLength; nElement++, pAny++ )
     257         [ #  # ]:          0 :                     *pAny = transformValue( *pAny );
     258                 :            : 
     259 [ #  # ][ #  # ]:          0 :                 return makeAny( aSequence );
     260                 :            :             }
     261         [ #  # ]:          0 :             else if( rValue.getValueTypeClass() == TypeClass_INTERFACE )
     262                 :            :             {
     263                 :          0 :                 Reference< XShape > xShape;
     264         [ #  # ]:          0 :                 rValue >>= xShape;
     265         [ #  # ]:          0 :                 if( xShape.is() )
     266                 :            :                 {
     267 [ #  # ][ #  # ]:          0 :                     return makeAny( getClonedShape( xShape ) );
     268                 :            :                 }
     269                 :            :                 else
     270                 :            :                 {
     271                 :          0 :                     Reference< XAnimationNode > xNode;
     272         [ #  # ]:          0 :                     rValue >>= xNode;
     273         [ #  # ]:          0 :                     if( xNode.is() )
     274 [ #  # ][ #  # ]:          0 :                         return makeAny( getClonedNode( xNode ) );
                 [ #  # ]
     275         [ #  # ]:          0 :                 }
     276                 :            :             }
     277 [ #  # ][ #  # ]:          0 :             else if( rValue.getValueType() == ::getCppuType((const ParagraphTarget*)0) )
     278                 :            :             {
     279         [ #  # ]:          0 :                 ParagraphTarget aParaTarget;
     280         [ #  # ]:          0 :                 rValue >>= aParaTarget;
     281                 :            : 
     282 [ #  # ][ #  # ]:          0 :                 aParaTarget.Shape = getClonedShape( aParaTarget.Shape );
     283                 :            : 
     284 [ #  # ][ #  # ]:          0 :                 return makeAny( aParaTarget );
     285                 :            :             }
     286 [ #  # ][ #  # ]:          0 :             else if( rValue.getValueType() == ::getCppuType((const Event*)0) )
     287                 :            :             {
     288                 :          0 :                 Event aEvent;
     289         [ #  # ]:          0 :                 rValue >>= aEvent;
     290                 :            : 
     291         [ #  # ]:          0 :                 aEvent.Source = transformValue( aEvent.Source );
     292                 :            : 
     293 [ #  # ][ #  # ]:          0 :                 return makeAny( aEvent );
     294                 :            :             }
     295                 :            :         }
     296                 :          0 :         catch( Exception& )
     297                 :            :         {
     298                 :            :             OSL_FAIL(
     299                 :            :                 (OString("sd::CustomAnimationClonerImpl::transformValue(), "
     300                 :            :                         "exception caught: ") +
     301                 :            :                 rtl::OUStringToOString(
     302                 :            :                     comphelper::anyToString( cppu::getCaughtException() ),
     303                 :            :                     RTL_TEXTENCODING_UTF8 )).getStr() );
     304                 :            :         }
     305                 :            : 
     306                 :          0 :         return rValue;
     307                 :            :     }
     308                 :            : 
     309                 :          0 :     Reference< XShape > CustomAnimationClonerImpl::getClonedShape( const Reference< XShape >& xSource ) const
     310                 :            :     {
     311         [ #  # ]:          0 :         if( xSource.is() )
     312                 :            :         {
     313 [ #  # ][ #  # ]:          0 :             if( maShapeMap.find(xSource) != maShapeMap.end() )
     314                 :            :             {
     315                 :          0 :                 return maShapeMap[xSource];
     316                 :            :             }
     317                 :            : 
     318                 :            :             DBG_ASSERT( maShapeMap.empty(), "sd::CustomAnimationClonerImpl::getClonedShape() failed!" );
     319                 :            :         }
     320                 :          0 :         return xSource;
     321                 :            :     }
     322                 :            : 
     323                 :          0 :     Reference< XAnimationNode > CustomAnimationClonerImpl::getClonedNode( const Reference< XAnimationNode >& xSource ) const
     324                 :            :     {
     325                 :          0 :         sal_Int32 nNode, nNodeCount = maSourceNodeVector.size();
     326                 :            : 
     327         [ #  # ]:          0 :         for( nNode = 0; nNode < nNodeCount; nNode++ )
     328                 :            :         {
     329         [ #  # ]:          0 :             if( maSourceNodeVector[nNode] == xSource )
     330                 :          0 :                 return maCloneNodeVector[nNode];
     331                 :            :         }
     332                 :            : 
     333                 :            :         OSL_FAIL( "sd::CustomAnimationClonerImpl::getClonedNode() failed!" );
     334                 :          0 :         return xSource;
     335                 :            :     }
     336                 :            : }
     337                 :            : 
     338                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10