merge the formfield patch from ooo-build
[ooovba.git] / sd / source / core / undoanim.cxx
blob0b0477b4b44e85fc06a7951c00f39cc8d7be1e53
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: undoanim.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
33 #include <com/sun/star/util/XCloneable.hpp>
34 #include <com/sun/star/animations/XAnimationNode.hpp>
35 #include "CustomAnimationCloner.hxx"
37 #include "undoanim.hxx"
38 #include "glob.hrc"
39 #include "sdpage.hxx"
40 #include "sdresid.hxx"
41 #include "CustomAnimationEffect.hxx"
42 #include "drawdoc.hxx"
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::uno::Exception;
46 using ::com::sun::star::uno::UNO_QUERY_THROW;
47 using ::com::sun::star::util::XCloneable;
48 using namespace ::com::sun::star::animations;
51 namespace sd
54 struct UndoAnimationImpl
56 SdPage* mpPage;
57 Reference< XAnimationNode > mxOldNode;
58 Reference< XAnimationNode > mxNewNode;
59 bool mbNewNodeSet;
62 UndoAnimation::UndoAnimation( SdDrawDocument* pDoc, SdPage* pThePage )
63 : SdrUndoAction( *pDoc ), mpImpl( new UndoAnimationImpl )
65 mpImpl->mpPage = pThePage;
66 mpImpl->mbNewNodeSet = false;
68 try
70 if( pThePage->mxAnimationNode.is() )
71 mpImpl->mxOldNode = ::sd::Clone( pThePage->getAnimationNode() );
73 catch( Exception& e )
75 (void)e;
76 DBG_ERROR("sd::UndoAnimation::UndoAnimation(), exception caught!");
80 UndoAnimation::~UndoAnimation()
82 delete mpImpl;
85 void UndoAnimation::Undo()
87 try
89 if( !mpImpl->mbNewNodeSet )
91 if( mpImpl->mpPage->mxAnimationNode.is() )
92 mpImpl->mxNewNode.set( ::sd::Clone( mpImpl->mpPage->mxAnimationNode ) );
93 mpImpl->mbNewNodeSet = true;
96 Reference< XAnimationNode > xOldNode;
97 if( mpImpl->mxOldNode.is() )
98 xOldNode = ::sd::Clone( mpImpl->mxOldNode );
100 mpImpl->mpPage->setAnimationNode( xOldNode );
102 catch( Exception& e )
104 (void)e;
105 DBG_ERROR("sd::UndoAnimation::Undo(), exception caught!");
109 void UndoAnimation::Redo()
113 Reference< XAnimationNode > xNewNode;
114 if( mpImpl->mxNewNode.is() )
115 xNewNode = ::sd::Clone( mpImpl->mxNewNode );
116 mpImpl->mpPage->setAnimationNode( xNewNode );
118 catch( Exception& e )
120 (void)e;
121 DBG_ERROR("sd::UndoAnimation::Redo(), exception caught!");
125 String UndoAnimation::GetComment() const
127 return String(SdResId(STR_UNDO_ANIMATION));
130 struct UndoAnimationPathImpl
132 SdPage* mpPage;
133 sal_Int32 mnEffectOffset;
134 ::rtl::OUString msUndoPath;
135 ::rtl::OUString msRedoPath;
137 UndoAnimationPathImpl( SdPage* pThePage, const com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode )
138 : mpPage( pThePage )
139 , mnEffectOffset( -1 )
141 if( mpPage && xNode.is() )
143 boost::shared_ptr< sd::MainSequence > pMainSequence( mpPage->getMainSequence() );
144 if( pMainSequence.get() )
146 CustomAnimationEffectPtr pEffect( pMainSequence->findEffect( xNode ) );
147 if( pEffect.get() )
149 mnEffectOffset = pMainSequence->getOffsetFromEffect( pEffect );
150 msUndoPath = pEffect->getPath();
156 CustomAnimationEffectPtr getEffect() const
158 CustomAnimationEffectPtr pEffect;
159 if( mpPage && (mnEffectOffset >= 0) )
161 boost::shared_ptr< sd::MainSequence > pMainSequence( mpPage->getMainSequence() );
162 if( pMainSequence.get() )
163 pEffect = pMainSequence->getEffectFromOffset( mnEffectOffset );
165 return pEffect;
168 private:
169 UndoAnimationPathImpl( const UndoAnimationPathImpl& ); //not implemented
170 const UndoAnimationPathImpl& operator=( const UndoAnimationPathImpl& ); // not implemented
174 UndoAnimationPath::UndoAnimationPath( SdDrawDocument* pDoc, SdPage* pThePage, const com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode )
175 : SdrUndoAction( *pDoc )
176 , mpImpl( new UndoAnimationPathImpl( pThePage, xNode ) )
180 UndoAnimationPath::~UndoAnimationPath()
184 void UndoAnimationPath::Undo()
186 CustomAnimationEffectPtr pEffect = mpImpl->getEffect();
187 if( pEffect.get() )
189 mpImpl->msRedoPath = pEffect->getPath();
190 pEffect->setPath( mpImpl->msUndoPath );
194 void UndoAnimationPath::Redo()
196 CustomAnimationEffectPtr pEffect = mpImpl->getEffect();
197 if( pEffect.get() )
199 pEffect->setPath( mpImpl->msRedoPath );
203 String UndoAnimationPath::GetComment() const
205 return String(SdResId(STR_UNDO_ANIMATION));
208 struct UndoTransitionImpl
210 SdPage* mpPage;
212 sal_Int16 mnNewTransitionType;
213 sal_Int16 mnNewTransitionSubtype;
214 sal_Bool mbNewTransitionDirection;
215 sal_Int32 mnNewTransitionFadeColor;
216 double mfNewTransitionDuration;
217 String maNewSoundFile;
218 bool mbNewSoundOn;
219 bool mbNewLoopSound;
220 bool mbNewStopSound;
222 sal_Int16 mnOldTransitionType;
223 sal_Int16 mnOldTransitionSubtype;
224 sal_Bool mbOldTransitionDirection;
225 sal_Int32 mnOldTransitionFadeColor;
226 double mfOldTransitionDuration;
227 String maOldSoundFile;
228 bool mbOldSoundOn;
229 bool mbOldLoopSound;
230 bool mbOldStopSound;
233 UndoTransition::UndoTransition( SdDrawDocument* _pDoc, SdPage* pThePage )
234 : SdUndoAction( _pDoc ), mpImpl( new UndoTransitionImpl )
236 mpImpl->mpPage = pThePage;
238 mpImpl->mnNewTransitionType = -1;
239 mpImpl->mnOldTransitionType = pThePage->mnTransitionType;
240 mpImpl->mnOldTransitionSubtype = pThePage->mnTransitionSubtype;
241 mpImpl->mbOldTransitionDirection = pThePage->mbTransitionDirection;
242 mpImpl->mnOldTransitionFadeColor = pThePage->mnTransitionFadeColor;
243 mpImpl->mfOldTransitionDuration = pThePage->mfTransitionDuration;
244 mpImpl->maOldSoundFile = pThePage->maSoundFile;
245 mpImpl->mbOldSoundOn = pThePage->mbSoundOn;
246 mpImpl->mbOldLoopSound = pThePage->mbLoopSound;
247 mpImpl->mbOldStopSound = pThePage->mbStopSound;
250 UndoTransition::~UndoTransition()
252 delete mpImpl;
255 void UndoTransition::Undo()
257 if( mpImpl->mnNewTransitionType == -1 )
259 mpImpl->mnNewTransitionType = mpImpl->mpPage->mnTransitionType;
260 mpImpl->mnNewTransitionSubtype = mpImpl->mpPage->mnTransitionSubtype;
261 mpImpl->mbNewTransitionDirection = mpImpl->mpPage->mbTransitionDirection;
262 mpImpl->mnNewTransitionFadeColor = mpImpl->mpPage->mnTransitionFadeColor;
263 mpImpl->mfNewTransitionDuration = mpImpl->mpPage->mfTransitionDuration;
264 mpImpl->maNewSoundFile = mpImpl->mpPage->maSoundFile;
265 mpImpl->mbNewSoundOn = mpImpl->mpPage->mbSoundOn;
266 mpImpl->mbNewLoopSound = mpImpl->mpPage->mbLoopSound;
267 mpImpl->mbNewStopSound = mpImpl->mpPage->mbStopSound;
270 mpImpl->mpPage->mnTransitionType = mpImpl->mnOldTransitionType;
271 mpImpl->mpPage->mnTransitionSubtype = mpImpl->mnOldTransitionSubtype;
272 mpImpl->mpPage->mbTransitionDirection = mpImpl->mbOldTransitionDirection;
273 mpImpl->mpPage->mnTransitionFadeColor = mpImpl->mnOldTransitionFadeColor;
274 mpImpl->mpPage->mfTransitionDuration = mpImpl->mfOldTransitionDuration;
275 mpImpl->mpPage->maSoundFile = mpImpl->maOldSoundFile;
276 mpImpl->mpPage->mbSoundOn = mpImpl->mbOldSoundOn;
277 mpImpl->mpPage->mbLoopSound = mpImpl->mbOldLoopSound;
278 mpImpl->mpPage->mbStopSound = mpImpl->mbOldStopSound;
281 void UndoTransition::Redo()
283 mpImpl->mpPage->mnTransitionType = mpImpl->mnNewTransitionType;
284 mpImpl->mpPage->mnTransitionSubtype = mpImpl->mnNewTransitionSubtype;
285 mpImpl->mpPage->mbTransitionDirection = mpImpl->mbNewTransitionDirection;
286 mpImpl->mpPage->mnTransitionFadeColor = mpImpl->mnNewTransitionFadeColor;
287 mpImpl->mpPage->mfTransitionDuration = mpImpl->mfNewTransitionDuration;
288 mpImpl->mpPage->maSoundFile = mpImpl->maNewSoundFile;
289 mpImpl->mpPage->mbSoundOn = mpImpl->mbNewSoundOn;
290 mpImpl->mpPage->mbLoopSound = mpImpl->mbNewLoopSound;
291 mpImpl->mpPage->mbStopSound = mpImpl->mbNewStopSound;
294 String UndoTransition::GetComment() const
296 return String(SdResId(STR_UNDO_SLIDE_PARAMS));