Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / core / undoanim.cxx
blobd4a69e62504e8c686ed68bcdd5e85d7251e1910a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <com/sun/star/animations/XAnimationNode.hpp>
23 #include <CustomAnimationCloner.hxx>
25 #include <undoanim.hxx>
26 #include <strings.hrc>
27 #include <sdpage.hxx>
28 #include <sdresid.hxx>
29 #include <CustomAnimationEffect.hxx>
30 #include <drawdoc.hxx>
32 using ::com::sun::star::uno::Reference;
33 using ::com::sun::star::uno::Exception;
34 using namespace ::com::sun::star::animations;
36 namespace sd
39 struct UndoAnimationImpl
41 SdPage* mpPage;
42 Reference< XAnimationNode > mxOldNode;
43 Reference< XAnimationNode > mxNewNode;
44 bool mbNewNodeSet;
47 UndoAnimation::UndoAnimation( SdDrawDocument* pDoc, SdPage* pThePage )
48 : SdrUndoAction( *pDoc ), mpImpl( new UndoAnimationImpl )
50 mpImpl->mpPage = pThePage;
51 mpImpl->mbNewNodeSet = false;
53 try
55 if( pThePage->mxAnimationNode.is() )
56 mpImpl->mxOldNode = ::sd::Clone( pThePage->getAnimationNode() );
58 catch( Exception& )
60 OSL_FAIL("sd::UndoAnimation::UndoAnimation(), exception caught!");
64 UndoAnimation::~UndoAnimation()
68 void UndoAnimation::Undo()
70 try
72 if( !mpImpl->mbNewNodeSet )
74 if( mpImpl->mpPage->mxAnimationNode.is() )
75 mpImpl->mxNewNode.set( ::sd::Clone( mpImpl->mpPage->mxAnimationNode ) );
76 mpImpl->mbNewNodeSet = true;
79 Reference< XAnimationNode > xOldNode;
80 if( mpImpl->mxOldNode.is() )
81 xOldNode = ::sd::Clone( mpImpl->mxOldNode );
83 mpImpl->mpPage->setAnimationNode( xOldNode );
85 catch( Exception& )
87 OSL_FAIL("sd::UndoAnimation::Undo(), exception caught!");
91 void UndoAnimation::Redo()
93 try
95 Reference< XAnimationNode > xNewNode;
96 if( mpImpl->mxNewNode.is() )
97 xNewNode = ::sd::Clone( mpImpl->mxNewNode );
98 mpImpl->mpPage->setAnimationNode( xNewNode );
100 catch( Exception& )
102 OSL_FAIL("sd::UndoAnimation::Redo(), exception caught!");
106 OUString UndoAnimation::GetComment() const
108 return SdResId(STR_UNDO_ANIMATION);
111 struct UndoAnimationPathImpl
113 SdPage* mpPage;
114 sal_Int32 mnEffectOffset;
115 OUString msUndoPath;
116 OUString msRedoPath;
118 UndoAnimationPathImpl( SdPage* pThePage, const css::uno::Reference< css::animations::XAnimationNode >& xNode )
119 : mpPage( pThePage )
120 , mnEffectOffset( -1 )
122 if( mpPage && xNode.is() )
124 std::shared_ptr< sd::MainSequence > pMainSequence( mpPage->getMainSequence() );
125 if( pMainSequence.get() )
127 CustomAnimationEffectPtr pEffect( pMainSequence->findEffect( xNode ) );
128 if( pEffect.get() )
130 mnEffectOffset = pMainSequence->getOffsetFromEffect( pEffect );
131 msUndoPath = pEffect->getPath();
136 UndoAnimationPathImpl(const UndoAnimationPathImpl&) = delete;
137 UndoAnimationPathImpl& operator=(const UndoAnimationPathImpl&) = delete;
139 CustomAnimationEffectPtr getEffect() const
141 CustomAnimationEffectPtr pEffect;
142 if( mpPage && (mnEffectOffset >= 0) )
144 std::shared_ptr< sd::MainSequence > pMainSequence( mpPage->getMainSequence() );
145 if( pMainSequence.get() )
146 pEffect = pMainSequence->getEffectFromOffset( mnEffectOffset );
148 return pEffect;
152 UndoAnimationPath::UndoAnimationPath( SdDrawDocument* pDoc, SdPage* pThePage, const css::uno::Reference< css::animations::XAnimationNode >& xNode )
153 : SdrUndoAction( *pDoc )
154 , mpImpl( new UndoAnimationPathImpl( pThePage, xNode ) )
158 UndoAnimationPath::~UndoAnimationPath()
162 void UndoAnimationPath::Undo()
164 CustomAnimationEffectPtr pEffect = mpImpl->getEffect();
165 if( pEffect.get() )
167 mpImpl->msRedoPath = pEffect->getPath();
168 pEffect->setPath( mpImpl->msUndoPath );
172 void UndoAnimationPath::Redo()
174 CustomAnimationEffectPtr pEffect = mpImpl->getEffect();
175 if( pEffect.get() )
177 pEffect->setPath( mpImpl->msRedoPath );
181 OUString UndoAnimationPath::GetComment() const
183 return SdResId(STR_UNDO_ANIMATION);
186 struct UndoTransitionImpl
188 SdPage* mpPage;
190 sal_Int16 mnNewTransitionType;
191 sal_Int16 mnNewTransitionSubtype;
192 bool mbNewTransitionDirection;
193 sal_Int32 mnNewTransitionFadeColor;
194 double mfNewTransitionDuration;
195 OUString maNewSoundFile;
196 bool mbNewSoundOn;
197 bool mbNewLoopSound;
198 bool mbNewStopSound;
200 sal_Int16 mnOldTransitionType;
201 sal_Int16 mnOldTransitionSubtype;
202 bool mbOldTransitionDirection;
203 sal_Int32 mnOldTransitionFadeColor;
204 double mfOldTransitionDuration;
205 OUString maOldSoundFile;
206 bool mbOldSoundOn;
207 bool mbOldLoopSound;
208 bool mbOldStopSound;
211 UndoTransition::UndoTransition( SdDrawDocument* _pDoc, SdPage* pThePage )
212 : SdUndoAction( _pDoc ), mpImpl( new UndoTransitionImpl )
214 mpImpl->mpPage = pThePage;
216 mpImpl->mnNewTransitionType = -1;
217 mpImpl->mnOldTransitionType = pThePage->mnTransitionType;
218 mpImpl->mnOldTransitionSubtype = pThePage->mnTransitionSubtype;
219 mpImpl->mbOldTransitionDirection = pThePage->mbTransitionDirection;
220 mpImpl->mnOldTransitionFadeColor = pThePage->mnTransitionFadeColor;
221 mpImpl->mfOldTransitionDuration = pThePage->mfTransitionDuration;
222 mpImpl->maOldSoundFile = pThePage->maSoundFile;
223 mpImpl->mbOldSoundOn = pThePage->mbSoundOn;
224 mpImpl->mbOldLoopSound = pThePage->mbLoopSound;
225 mpImpl->mbOldStopSound = pThePage->mbStopSound;
228 UndoTransition::~UndoTransition()
232 void UndoTransition::Undo()
234 if( mpImpl->mnNewTransitionType == -1 )
236 mpImpl->mnNewTransitionType = mpImpl->mpPage->mnTransitionType;
237 mpImpl->mnNewTransitionSubtype = mpImpl->mpPage->mnTransitionSubtype;
238 mpImpl->mbNewTransitionDirection = mpImpl->mpPage->mbTransitionDirection;
239 mpImpl->mnNewTransitionFadeColor = mpImpl->mpPage->mnTransitionFadeColor;
240 mpImpl->mfNewTransitionDuration = mpImpl->mpPage->mfTransitionDuration;
241 mpImpl->maNewSoundFile = mpImpl->mpPage->maSoundFile;
242 mpImpl->mbNewSoundOn = mpImpl->mpPage->mbSoundOn;
243 mpImpl->mbNewLoopSound = mpImpl->mpPage->mbLoopSound;
244 mpImpl->mbNewStopSound = mpImpl->mpPage->mbStopSound;
247 mpImpl->mpPage->mnTransitionType = mpImpl->mnOldTransitionType;
248 mpImpl->mpPage->mnTransitionSubtype = mpImpl->mnOldTransitionSubtype;
249 mpImpl->mpPage->mbTransitionDirection = mpImpl->mbOldTransitionDirection;
250 mpImpl->mpPage->mnTransitionFadeColor = mpImpl->mnOldTransitionFadeColor;
251 mpImpl->mpPage->mfTransitionDuration = mpImpl->mfOldTransitionDuration;
252 mpImpl->mpPage->maSoundFile = mpImpl->maOldSoundFile;
253 mpImpl->mpPage->mbSoundOn = mpImpl->mbOldSoundOn;
254 mpImpl->mpPage->mbLoopSound = mpImpl->mbOldLoopSound;
255 mpImpl->mpPage->mbStopSound = mpImpl->mbOldStopSound;
258 void UndoTransition::Redo()
260 mpImpl->mpPage->mnTransitionType = mpImpl->mnNewTransitionType;
261 mpImpl->mpPage->mnTransitionSubtype = mpImpl->mnNewTransitionSubtype;
262 mpImpl->mpPage->mbTransitionDirection = mpImpl->mbNewTransitionDirection;
263 mpImpl->mpPage->mnTransitionFadeColor = mpImpl->mnNewTransitionFadeColor;
264 mpImpl->mpPage->mfTransitionDuration = mpImpl->mfNewTransitionDuration;
265 mpImpl->mpPage->maSoundFile = mpImpl->maNewSoundFile;
266 mpImpl->mpPage->mbSoundOn = mpImpl->mbNewSoundOn;
267 mpImpl->mpPage->mbLoopSound = mpImpl->mbNewLoopSound;
268 mpImpl->mpPage->mbStopSound = mpImpl->mbNewStopSound;
271 OUString UndoTransition::GetComment() const
273 return SdResId(STR_UNDO_SLIDE_PARAMS);
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */