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