LCOV - code coverage report
Current view: top level - sd/source/core - undoanim.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 123 0.8 %
Date: 2015-06-13 12:38:46 Functions: 2 27 7.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sal/config.h>
      21             : 
      22             : #include <boost/noncopyable.hpp>
      23             : #include <com/sun/star/util/XCloneable.hpp>
      24             : #include <com/sun/star/animations/XAnimationNode.hpp>
      25             : #include "CustomAnimationCloner.hxx"
      26             : 
      27             : #include "undoanim.hxx"
      28             : #include "glob.hrc"
      29             : #include "sdpage.hxx"
      30             : #include "sdresid.hxx"
      31             : #include "CustomAnimationEffect.hxx"
      32             : #include "drawdoc.hxx"
      33             : 
      34             : using ::com::sun::star::uno::Reference;
      35             : using ::com::sun::star::uno::Exception;
      36             : using ::com::sun::star::uno::UNO_QUERY_THROW;
      37             : using ::com::sun::star::util::XCloneable;
      38             : using namespace ::com::sun::star::animations;
      39             : 
      40             : namespace sd
      41             : {
      42             : 
      43           0 : struct UndoAnimationImpl
      44             : {
      45             :     SdPage*         mpPage;
      46             :     Reference< XAnimationNode > mxOldNode;
      47             :     Reference< XAnimationNode > mxNewNode;
      48             :     bool            mbNewNodeSet;
      49             : };
      50             : 
      51           0 : UndoAnimation::UndoAnimation( SdDrawDocument* pDoc, SdPage* pThePage )
      52           0 : : SdrUndoAction( *pDoc ), mpImpl( new UndoAnimationImpl )
      53             : {
      54           0 :     mpImpl->mpPage = pThePage;
      55           0 :     mpImpl->mbNewNodeSet = false;
      56             : 
      57             :     try
      58             :     {
      59           0 :         if( pThePage->mxAnimationNode.is() )
      60           0 :             mpImpl->mxOldNode = ::sd::Clone( pThePage->getAnimationNode() );
      61             :     }
      62           0 :     catch( Exception& )
      63             :     {
      64             :         OSL_FAIL("sd::UndoAnimation::UndoAnimation(), exception caught!");
      65             :     }
      66           0 : }
      67             : 
      68           0 : UndoAnimation::~UndoAnimation()
      69             : {
      70           0 : }
      71             : 
      72           0 : void UndoAnimation::Undo()
      73             : {
      74             :     try
      75             :     {
      76           0 :         if( !mpImpl->mbNewNodeSet )
      77             :         {
      78           0 :             if( mpImpl->mpPage->mxAnimationNode.is() )
      79           0 :                 mpImpl->mxNewNode.set( ::sd::Clone( mpImpl->mpPage->mxAnimationNode ) );
      80           0 :             mpImpl->mbNewNodeSet = true;
      81             :         }
      82             : 
      83           0 :         Reference< XAnimationNode > xOldNode;
      84           0 :         if( mpImpl->mxOldNode.is() )
      85           0 :             xOldNode = ::sd::Clone( mpImpl->mxOldNode );
      86             : 
      87           0 :         mpImpl->mpPage->setAnimationNode( xOldNode );
      88             :     }
      89           0 :     catch( Exception& )
      90             :     {
      91             :         OSL_FAIL("sd::UndoAnimation::Undo(), exception caught!");
      92             :     }
      93           0 : }
      94             : 
      95           0 : void UndoAnimation::Redo()
      96             : {
      97             :     try
      98             :     {
      99           0 :         Reference< XAnimationNode > xNewNode;
     100           0 :         if( mpImpl->mxNewNode.is() )
     101           0 :             xNewNode = ::sd::Clone( mpImpl->mxNewNode );
     102           0 :         mpImpl->mpPage->setAnimationNode( xNewNode );
     103             :     }
     104           0 :     catch( Exception& )
     105             :     {
     106             :         OSL_FAIL("sd::UndoAnimation::Redo(), exception caught!");
     107             :     }
     108           0 : }
     109             : 
     110           0 : OUString UndoAnimation::GetComment() const
     111             : {
     112           0 :     return SdResId(STR_UNDO_ANIMATION).toString();
     113             : }
     114             : 
     115           0 : struct UndoAnimationPathImpl: private boost::noncopyable
     116             : {
     117             :     SdPage*         mpPage;
     118             :     sal_Int32       mnEffectOffset;
     119             :     OUString msUndoPath;
     120             :     OUString msRedoPath;
     121             : 
     122           0 :     UndoAnimationPathImpl( SdPage* pThePage, const com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode )
     123             :         : mpPage( pThePage )
     124           0 :         , mnEffectOffset( -1 )
     125             :     {
     126           0 :         if( mpPage && xNode.is() )
     127             :         {
     128           0 :             boost::shared_ptr< sd::MainSequence > pMainSequence( mpPage->getMainSequence() );
     129           0 :             if( pMainSequence.get() )
     130             :             {
     131           0 :                 CustomAnimationEffectPtr pEffect( pMainSequence->findEffect( xNode ) );
     132           0 :                 if( pEffect.get() )
     133             :                 {
     134           0 :                     mnEffectOffset = pMainSequence->getOffsetFromEffect( pEffect );
     135           0 :                     msUndoPath = pEffect->getPath();
     136           0 :                 }
     137           0 :             }
     138             :         }
     139           0 :     }
     140             : 
     141           0 :     CustomAnimationEffectPtr getEffect() const
     142             :     {
     143           0 :         CustomAnimationEffectPtr pEffect;
     144           0 :         if( mpPage && (mnEffectOffset >= 0) )
     145             :         {
     146           0 :             boost::shared_ptr< sd::MainSequence > pMainSequence( mpPage->getMainSequence() );
     147           0 :             if( pMainSequence.get() )
     148           0 :                 pEffect = pMainSequence->getEffectFromOffset( mnEffectOffset );
     149             :         }
     150           0 :         return pEffect;
     151             :     }
     152             : };
     153             : 
     154           0 : UndoAnimationPath::UndoAnimationPath( SdDrawDocument* pDoc, SdPage* pThePage, const com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode )
     155             : : SdrUndoAction( *pDoc )
     156           0 : , mpImpl( new UndoAnimationPathImpl( pThePage, xNode ) )
     157             : {
     158           0 : }
     159             : 
     160           0 : UndoAnimationPath::~UndoAnimationPath()
     161             : {
     162           0 : }
     163             : 
     164           0 : void UndoAnimationPath::Undo()
     165             : {
     166           0 :     CustomAnimationEffectPtr pEffect = mpImpl->getEffect();
     167           0 :     if( pEffect.get() )
     168             :     {
     169           0 :         mpImpl->msRedoPath = pEffect->getPath();
     170           0 :         pEffect->setPath( mpImpl->msUndoPath );
     171           0 :     }
     172           0 : }
     173             : 
     174           0 : void UndoAnimationPath::Redo()
     175             : {
     176           0 :     CustomAnimationEffectPtr pEffect = mpImpl->getEffect();
     177           0 :     if( pEffect.get() )
     178             :     {
     179           0 :         pEffect->setPath( mpImpl->msRedoPath );
     180           0 :     }
     181           0 : }
     182             : 
     183           0 : OUString UndoAnimationPath::GetComment() const
     184             : {
     185           0 :     return SdResId(STR_UNDO_ANIMATION).toString();
     186             : }
     187             : 
     188           0 : struct UndoTransitionImpl
     189             : {
     190             :     SdPage*         mpPage;
     191             : 
     192             :     sal_Int16 mnNewTransitionType;
     193             :     sal_Int16 mnNewTransitionSubtype;
     194             :     bool mbNewTransitionDirection;
     195             :     sal_Int32 mnNewTransitionFadeColor;
     196             :     double mfNewTransitionDuration;
     197             :     OUString maNewSoundFile;
     198             :     bool mbNewSoundOn;
     199             :     bool mbNewLoopSound;
     200             :     bool mbNewStopSound;
     201             : 
     202             :     sal_Int16 mnOldTransitionType;
     203             :     sal_Int16 mnOldTransitionSubtype;
     204             :     bool mbOldTransitionDirection;
     205             :     sal_Int32 mnOldTransitionFadeColor;
     206             :     double mfOldTransitionDuration;
     207             :     OUString maOldSoundFile;
     208             :     bool mbOldSoundOn;
     209             :     bool mbOldLoopSound;
     210             :     bool mbOldStopSound;
     211             : };
     212             : 
     213           0 : UndoTransition::UndoTransition( SdDrawDocument* _pDoc, SdPage* pThePage )
     214           0 : : SdUndoAction( _pDoc ), mpImpl( new UndoTransitionImpl )
     215             : {
     216           0 :     mpImpl->mpPage = pThePage;
     217             : 
     218           0 :     mpImpl->mnNewTransitionType = -1;
     219           0 :     mpImpl->mnOldTransitionType = pThePage->mnTransitionType;
     220           0 :     mpImpl->mnOldTransitionSubtype = pThePage->mnTransitionSubtype;
     221           0 :     mpImpl->mbOldTransitionDirection = pThePage->mbTransitionDirection;
     222           0 :     mpImpl->mnOldTransitionFadeColor = pThePage->mnTransitionFadeColor;
     223           0 :     mpImpl->mfOldTransitionDuration = pThePage->mfTransitionDuration;
     224           0 :     mpImpl->maOldSoundFile = pThePage->maSoundFile;
     225           0 :     mpImpl->mbOldSoundOn = pThePage->mbSoundOn;
     226           0 :     mpImpl->mbOldLoopSound = pThePage->mbLoopSound;
     227           0 :     mpImpl->mbOldStopSound = pThePage->mbStopSound;
     228           0 : }
     229             : 
     230           0 : UndoTransition::~UndoTransition()
     231             : {
     232           0 : }
     233             : 
     234           0 : void UndoTransition::Undo()
     235             : {
     236           0 :     if( mpImpl->mnNewTransitionType == -1 )
     237             :     {
     238           0 :         mpImpl->mnNewTransitionType = mpImpl->mpPage->mnTransitionType;
     239           0 :         mpImpl->mnNewTransitionSubtype = mpImpl->mpPage->mnTransitionSubtype;
     240           0 :         mpImpl->mbNewTransitionDirection = mpImpl->mpPage->mbTransitionDirection;
     241           0 :         mpImpl->mnNewTransitionFadeColor = mpImpl->mpPage->mnTransitionFadeColor;
     242           0 :         mpImpl->mfNewTransitionDuration = mpImpl->mpPage->mfTransitionDuration;
     243           0 :         mpImpl->maNewSoundFile = mpImpl->mpPage->maSoundFile;
     244           0 :         mpImpl->mbNewSoundOn = mpImpl->mpPage->mbSoundOn;
     245           0 :         mpImpl->mbNewLoopSound = mpImpl->mpPage->mbLoopSound;
     246           0 :         mpImpl->mbNewStopSound = mpImpl->mpPage->mbStopSound;
     247             :     }
     248             : 
     249           0 :     mpImpl->mpPage->mnTransitionType = mpImpl->mnOldTransitionType;
     250           0 :     mpImpl->mpPage->mnTransitionSubtype = mpImpl->mnOldTransitionSubtype;
     251           0 :     mpImpl->mpPage->mbTransitionDirection = mpImpl->mbOldTransitionDirection;
     252           0 :     mpImpl->mpPage->mnTransitionFadeColor = mpImpl->mnOldTransitionFadeColor;
     253           0 :     mpImpl->mpPage->mfTransitionDuration = mpImpl->mfOldTransitionDuration;
     254           0 :     mpImpl->mpPage->maSoundFile = mpImpl->maOldSoundFile;
     255           0 :     mpImpl->mpPage->mbSoundOn = mpImpl->mbOldSoundOn;
     256           0 :     mpImpl->mpPage->mbLoopSound = mpImpl->mbOldLoopSound;
     257           0 :     mpImpl->mpPage->mbStopSound = mpImpl->mbOldStopSound;
     258           0 : }
     259             : 
     260           0 : void UndoTransition::Redo()
     261             : {
     262           0 :     mpImpl->mpPage->mnTransitionType = mpImpl->mnNewTransitionType;
     263           0 :     mpImpl->mpPage->mnTransitionSubtype = mpImpl->mnNewTransitionSubtype;
     264           0 :     mpImpl->mpPage->mbTransitionDirection = mpImpl->mbNewTransitionDirection;
     265           0 :     mpImpl->mpPage->mnTransitionFadeColor = mpImpl->mnNewTransitionFadeColor;
     266           0 :     mpImpl->mpPage->mfTransitionDuration = mpImpl->mfNewTransitionDuration;
     267           0 :     mpImpl->mpPage->maSoundFile = mpImpl->maNewSoundFile;
     268           0 :     mpImpl->mpPage->mbSoundOn = mpImpl->mbNewSoundOn;
     269           0 :     mpImpl->mpPage->mbLoopSound = mpImpl->mbNewLoopSound;
     270           0 :     mpImpl->mpPage->mbStopSound = mpImpl->mbNewStopSound;
     271           0 : }
     272             : 
     273           0 : OUString UndoTransition::GetComment() const
     274             : {
     275           0 :     return SdResId(STR_UNDO_SLIDE_PARAMS).toString();
     276             : }
     277             : 
     278          66 : }
     279             : 
     280             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11