nss: upgrade to release 3.73
[LibreOffice.git] / sd / source / core / undoanim.cxx
blob707d14bf885b0f234ccac1f56c62d6cd8e5e5737
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 <CustomAnimationCloner.hxx>
24 #include <undoanim.hxx>
25 #include <strings.hrc>
26 #include <sdpage.hxx>
27 #include <sdresid.hxx>
28 #include <CustomAnimationEffect.hxx>
29 #include <drawdoc.hxx>
31 namespace com::sun::star::animations { class XAnimationNode; }
33 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::uno::Exception;
35 using namespace ::com::sun::star::animations;
37 namespace sd
40 struct UndoAnimationImpl
42 SdPage* mpPage;
43 Reference< XAnimationNode > mxOldNode;
44 Reference< XAnimationNode > mxNewNode;
45 bool mbNewNodeSet;
48 UndoAnimation::UndoAnimation( SdDrawDocument* pDoc, SdPage* pThePage )
49 : SdrUndoAction( *pDoc ), mpImpl( new UndoAnimationImpl )
51 mpImpl->mpPage = pThePage;
52 mpImpl->mbNewNodeSet = false;
54 try
56 if( pThePage->mxAnimationNode.is() )
57 mpImpl->mxOldNode = ::sd::Clone( pThePage->getAnimationNode() );
59 catch( Exception& )
61 OSL_FAIL("sd::UndoAnimation::UndoAnimation(), exception caught!");
65 UndoAnimation::~UndoAnimation()
69 void UndoAnimation::Undo()
71 try
73 if( !mpImpl->mbNewNodeSet )
75 if( mpImpl->mpPage->mxAnimationNode.is() )
76 mpImpl->mxNewNode.set( ::sd::Clone( mpImpl->mpPage->mxAnimationNode ) );
77 mpImpl->mbNewNodeSet = true;
80 Reference< XAnimationNode > xOldNode;
81 if( mpImpl->mxOldNode.is() )
82 xOldNode = ::sd::Clone( mpImpl->mxOldNode );
84 mpImpl->mpPage->setAnimationNode( xOldNode );
86 catch( Exception& )
88 OSL_FAIL("sd::UndoAnimation::Undo(), exception caught!");
92 void UndoAnimation::Redo()
94 try
96 Reference< XAnimationNode > xNewNode;
97 if( mpImpl->mxNewNode.is() )
98 xNewNode = ::sd::Clone( mpImpl->mxNewNode );
99 mpImpl->mpPage->setAnimationNode( xNewNode );
101 catch( Exception& )
103 OSL_FAIL("sd::UndoAnimation::Redo(), exception caught!");
107 OUString UndoAnimation::GetComment() const
109 return SdResId(STR_UNDO_ANIMATION);
112 struct UndoAnimationPathImpl
114 SdPage* mpPage;
115 sal_Int32 mnEffectOffset;
116 OUString msUndoPath;
117 OUString msRedoPath;
119 UndoAnimationPathImpl( SdPage* pThePage, const css::uno::Reference< css::animations::XAnimationNode >& xNode )
120 : mpPage( pThePage )
121 , mnEffectOffset( -1 )
123 if( !(mpPage && xNode.is()) )
124 return;
126 std::shared_ptr< sd::MainSequence > pMainSequence( mpPage->getMainSequence() );
127 if( pMainSequence )
129 CustomAnimationEffectPtr pEffect( pMainSequence->findEffect( xNode ) );
130 if( pEffect )
132 mnEffectOffset = pMainSequence->getOffsetFromEffect( pEffect );
133 msUndoPath = pEffect->getPath();
137 UndoAnimationPathImpl(const UndoAnimationPathImpl&) = delete;
138 UndoAnimationPathImpl& operator=(const UndoAnimationPathImpl&) = delete;
140 CustomAnimationEffectPtr getEffect() const
142 CustomAnimationEffectPtr pEffect;
143 if( mpPage && (mnEffectOffset >= 0) )
145 std::shared_ptr< sd::MainSequence > pMainSequence( mpPage->getMainSequence() );
146 if( pMainSequence )
147 pEffect = pMainSequence->getEffectFromOffset( mnEffectOffset );
149 return pEffect;
153 UndoAnimationPath::UndoAnimationPath( SdDrawDocument* pDoc, SdPage* pThePage, const css::uno::Reference< css::animations::XAnimationNode >& xNode )
154 : SdrUndoAction( *pDoc )
155 , mpImpl( new UndoAnimationPathImpl( pThePage, xNode ) )
159 UndoAnimationPath::~UndoAnimationPath()
163 void UndoAnimationPath::Undo()
165 CustomAnimationEffectPtr pEffect = mpImpl->getEffect();
166 if( pEffect )
168 mpImpl->msRedoPath = pEffect->getPath();
169 pEffect->setPath( mpImpl->msUndoPath );
173 void UndoAnimationPath::Redo()
175 CustomAnimationEffectPtr pEffect = mpImpl->getEffect();
176 if( pEffect )
178 pEffect->setPath( mpImpl->msRedoPath );
182 OUString UndoAnimationPath::GetComment() const
184 return SdResId(STR_UNDO_ANIMATION);
187 struct UndoTransitionImpl
189 SdPage* mpPage;
191 sal_Int16 mnNewTransitionType;
192 sal_Int16 mnNewTransitionSubtype;
193 bool mbNewTransitionDirection;
194 sal_Int32 mnNewTransitionFadeColor;
195 double mfNewTransitionDuration;
196 OUString maNewSoundFile;
197 bool mbNewSoundOn;
198 bool mbNewLoopSound;
199 bool mbNewStopSound;
201 sal_Int16 mnOldTransitionType;
202 sal_Int16 mnOldTransitionSubtype;
203 bool mbOldTransitionDirection;
204 sal_Int32 mnOldTransitionFadeColor;
205 double mfOldTransitionDuration;
206 OUString maOldSoundFile;
207 bool mbOldSoundOn;
208 bool mbOldLoopSound;
209 bool mbOldStopSound;
212 UndoTransition::UndoTransition( SdDrawDocument* _pDoc, SdPage* pThePage )
213 : SdUndoAction( _pDoc ), mpImpl( new UndoTransitionImpl )
215 mpImpl->mpPage = pThePage;
217 mpImpl->mnNewTransitionType = -1;
218 mpImpl->mnOldTransitionType = pThePage->mnTransitionType;
219 mpImpl->mnOldTransitionSubtype = pThePage->mnTransitionSubtype;
220 mpImpl->mbOldTransitionDirection = pThePage->mbTransitionDirection;
221 mpImpl->mnOldTransitionFadeColor = pThePage->mnTransitionFadeColor;
222 mpImpl->mfOldTransitionDuration = pThePage->mfTransitionDuration;
223 mpImpl->maOldSoundFile = pThePage->maSoundFile;
224 mpImpl->mbOldSoundOn = pThePage->mbSoundOn;
225 mpImpl->mbOldLoopSound = pThePage->mbLoopSound;
226 mpImpl->mbOldStopSound = pThePage->mbStopSound;
229 UndoTransition::~UndoTransition()
233 void UndoTransition::Undo()
235 if( mpImpl->mnNewTransitionType == -1 )
237 mpImpl->mnNewTransitionType = mpImpl->mpPage->mnTransitionType;
238 mpImpl->mnNewTransitionSubtype = mpImpl->mpPage->mnTransitionSubtype;
239 mpImpl->mbNewTransitionDirection = mpImpl->mpPage->mbTransitionDirection;
240 mpImpl->mnNewTransitionFadeColor = mpImpl->mpPage->mnTransitionFadeColor;
241 mpImpl->mfNewTransitionDuration = mpImpl->mpPage->mfTransitionDuration;
242 mpImpl->maNewSoundFile = mpImpl->mpPage->maSoundFile;
243 mpImpl->mbNewSoundOn = mpImpl->mpPage->mbSoundOn;
244 mpImpl->mbNewLoopSound = mpImpl->mpPage->mbLoopSound;
245 mpImpl->mbNewStopSound = mpImpl->mpPage->mbStopSound;
248 mpImpl->mpPage->mnTransitionType = mpImpl->mnOldTransitionType;
249 mpImpl->mpPage->mnTransitionSubtype = mpImpl->mnOldTransitionSubtype;
250 mpImpl->mpPage->mbTransitionDirection = mpImpl->mbOldTransitionDirection;
251 mpImpl->mpPage->mnTransitionFadeColor = mpImpl->mnOldTransitionFadeColor;
252 mpImpl->mpPage->mfTransitionDuration = mpImpl->mfOldTransitionDuration;
253 mpImpl->mpPage->maSoundFile = mpImpl->maOldSoundFile;
254 mpImpl->mpPage->mbSoundOn = mpImpl->mbOldSoundOn;
255 mpImpl->mpPage->mbLoopSound = mpImpl->mbOldLoopSound;
256 mpImpl->mpPage->mbStopSound = mpImpl->mbOldStopSound;
259 void UndoTransition::Redo()
261 mpImpl->mpPage->mnTransitionType = mpImpl->mnNewTransitionType;
262 mpImpl->mpPage->mnTransitionSubtype = mpImpl->mnNewTransitionSubtype;
263 mpImpl->mpPage->mbTransitionDirection = mpImpl->mbNewTransitionDirection;
264 mpImpl->mpPage->mnTransitionFadeColor = mpImpl->mnNewTransitionFadeColor;
265 mpImpl->mpPage->mfTransitionDuration = mpImpl->mfNewTransitionDuration;
266 mpImpl->mpPage->maSoundFile = mpImpl->maNewSoundFile;
267 mpImpl->mpPage->mbSoundOn = mpImpl->mbNewSoundOn;
268 mpImpl->mpPage->mbLoopSound = mpImpl->mbNewLoopSound;
269 mpImpl->mpPage->mbStopSound = mpImpl->mbNewStopSound;
272 OUString UndoTransition::GetComment() const
274 return SdResId(STR_UNDO_SLIDE_PARAMS);
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */