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