1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
27 #include <sdresid.hxx>
28 #include <CustomAnimationEffect.hxx>
29 #include <drawdoc.hxx>
30 #include <comphelper/diagnose_ex.hxx>
32 namespace com::sun::star::animations
{ class XAnimationNode
; }
34 using ::com::sun::star::uno::Reference
;
35 using ::com::sun::star::uno::Exception
;
36 using namespace ::com::sun::star::animations
;
41 struct UndoAnimationImpl
44 Reference
< XAnimationNode
> mxOldNode
;
45 Reference
< XAnimationNode
> mxNewNode
;
49 UndoAnimation::UndoAnimation( SdDrawDocument
* pDoc
, SdPage
* pThePage
)
50 : SdrUndoAction( *pDoc
), mpImpl( new UndoAnimationImpl
)
52 mpImpl
->mpPage
= pThePage
;
53 mpImpl
->mbNewNodeSet
= false;
57 if( pThePage
->mxAnimationNode
.is() )
58 mpImpl
->mxOldNode
= ::sd::Clone( pThePage
->getAnimationNode() );
62 TOOLS_WARN_EXCEPTION( "sd", "sd::UndoAnimation::UndoAnimation()");
66 UndoAnimation::~UndoAnimation()
70 void UndoAnimation::Undo()
74 if( !mpImpl
->mbNewNodeSet
)
76 if( mpImpl
->mpPage
->mxAnimationNode
.is() )
77 mpImpl
->mxNewNode
.set( ::sd::Clone( mpImpl
->mpPage
->mxAnimationNode
) );
78 mpImpl
->mbNewNodeSet
= true;
81 Reference
< XAnimationNode
> xOldNode
;
82 if( mpImpl
->mxOldNode
.is() )
83 xOldNode
= ::sd::Clone( mpImpl
->mxOldNode
);
85 mpImpl
->mpPage
->setAnimationNode( xOldNode
);
89 TOOLS_WARN_EXCEPTION( "sd", "sd::UndoAnimation::Undo()");
93 void UndoAnimation::Redo()
97 Reference
< XAnimationNode
> xNewNode
;
98 if( mpImpl
->mxNewNode
.is() )
99 xNewNode
= ::sd::Clone( mpImpl
->mxNewNode
);
100 mpImpl
->mpPage
->setAnimationNode( xNewNode
);
104 TOOLS_WARN_EXCEPTION( "sd", "sd::UndoAnimation::Redo()");
108 OUString
UndoAnimation::GetComment() const
110 return SdResId(STR_UNDO_ANIMATION
);
113 struct UndoAnimationPathImpl
116 sal_Int32 mnEffectOffset
;
120 UndoAnimationPathImpl( SdPage
* pThePage
, const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
)
122 , mnEffectOffset( -1 )
124 if( !(mpPage
&& xNode
.is()) )
127 std::shared_ptr
< sd::MainSequence
> pMainSequence( mpPage
->getMainSequence() );
130 CustomAnimationEffectPtr
pEffect( pMainSequence
->findEffect( xNode
) );
133 mnEffectOffset
= pMainSequence
->getOffsetFromEffect( pEffect
);
134 msUndoPath
= pEffect
->getPath();
138 UndoAnimationPathImpl(const UndoAnimationPathImpl
&) = delete;
139 UndoAnimationPathImpl
& operator=(const UndoAnimationPathImpl
&) = delete;
141 CustomAnimationEffectPtr
getEffect() const
143 CustomAnimationEffectPtr pEffect
;
144 if( mpPage
&& (mnEffectOffset
>= 0) )
146 std::shared_ptr
< sd::MainSequence
> pMainSequence( mpPage
->getMainSequence() );
148 pEffect
= pMainSequence
->getEffectFromOffset( mnEffectOffset
);
154 UndoAnimationPath::UndoAnimationPath( SdDrawDocument
* pDoc
, SdPage
* pThePage
, const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
)
155 : SdrUndoAction( *pDoc
)
156 , mpImpl( new UndoAnimationPathImpl( pThePage
, xNode
) )
160 UndoAnimationPath::~UndoAnimationPath()
164 void UndoAnimationPath::Undo()
166 CustomAnimationEffectPtr pEffect
= mpImpl
->getEffect();
169 mpImpl
->msRedoPath
= pEffect
->getPath();
170 pEffect
->setPath( mpImpl
->msUndoPath
);
174 void UndoAnimationPath::Redo()
176 CustomAnimationEffectPtr pEffect
= mpImpl
->getEffect();
179 pEffect
->setPath( mpImpl
->msRedoPath
);
183 OUString
UndoAnimationPath::GetComment() const
185 return SdResId(STR_UNDO_ANIMATION
);
188 struct UndoTransitionImpl
192 sal_Int16 mnNewTransitionType
;
193 sal_Int16 mnNewTransitionSubtype
;
194 bool mbNewTransitionDirection
;
195 sal_Int32 mnNewTransitionFadeColor
;
196 double mfNewTransitionDuration
;
197 OUString maNewSoundFile
;
202 sal_Int16 mnOldTransitionType
;
203 sal_Int16 mnOldTransitionSubtype
;
204 bool mbOldTransitionDirection
;
205 sal_Int32 mnOldTransitionFadeColor
;
206 double mfOldTransitionDuration
;
207 OUString maOldSoundFile
;
213 UndoTransition::UndoTransition( SdDrawDocument
* _pDoc
, SdPage
* pThePage
)
214 : SdUndoAction( _pDoc
), mpImpl( new UndoTransitionImpl
)
216 mpImpl
->mpPage
= pThePage
;
218 mpImpl
->mnNewTransitionType
= -1;
219 mpImpl
->mnOldTransitionType
= pThePage
->mnTransitionType
;
220 mpImpl
->mnOldTransitionSubtype
= pThePage
->mnTransitionSubtype
;
221 mpImpl
->mbOldTransitionDirection
= pThePage
->mbTransitionDirection
;
222 mpImpl
->mnOldTransitionFadeColor
= pThePage
->mnTransitionFadeColor
;
223 mpImpl
->mfOldTransitionDuration
= pThePage
->mfTransitionDuration
;
224 mpImpl
->maOldSoundFile
= pThePage
->maSoundFile
;
225 mpImpl
->mbOldSoundOn
= pThePage
->mbSoundOn
;
226 mpImpl
->mbOldLoopSound
= pThePage
->mbLoopSound
;
227 mpImpl
->mbOldStopSound
= pThePage
->mbStopSound
;
230 UndoTransition::~UndoTransition()
234 void UndoTransition::Undo()
236 if( mpImpl
->mnNewTransitionType
== -1 )
238 mpImpl
->mnNewTransitionType
= mpImpl
->mpPage
->mnTransitionType
;
239 mpImpl
->mnNewTransitionSubtype
= mpImpl
->mpPage
->mnTransitionSubtype
;
240 mpImpl
->mbNewTransitionDirection
= mpImpl
->mpPage
->mbTransitionDirection
;
241 mpImpl
->mnNewTransitionFadeColor
= mpImpl
->mpPage
->mnTransitionFadeColor
;
242 mpImpl
->mfNewTransitionDuration
= mpImpl
->mpPage
->mfTransitionDuration
;
243 mpImpl
->maNewSoundFile
= mpImpl
->mpPage
->maSoundFile
;
244 mpImpl
->mbNewSoundOn
= mpImpl
->mpPage
->mbSoundOn
;
245 mpImpl
->mbNewLoopSound
= mpImpl
->mpPage
->mbLoopSound
;
246 mpImpl
->mbNewStopSound
= mpImpl
->mpPage
->mbStopSound
;
249 mpImpl
->mpPage
->mnTransitionType
= mpImpl
->mnOldTransitionType
;
250 mpImpl
->mpPage
->mnTransitionSubtype
= mpImpl
->mnOldTransitionSubtype
;
251 mpImpl
->mpPage
->mbTransitionDirection
= mpImpl
->mbOldTransitionDirection
;
252 mpImpl
->mpPage
->mnTransitionFadeColor
= mpImpl
->mnOldTransitionFadeColor
;
253 mpImpl
->mpPage
->mfTransitionDuration
= mpImpl
->mfOldTransitionDuration
;
254 mpImpl
->mpPage
->maSoundFile
= mpImpl
->maOldSoundFile
;
255 mpImpl
->mpPage
->mbSoundOn
= mpImpl
->mbOldSoundOn
;
256 mpImpl
->mpPage
->mbLoopSound
= mpImpl
->mbOldLoopSound
;
257 mpImpl
->mpPage
->mbStopSound
= mpImpl
->mbOldStopSound
;
260 void UndoTransition::Redo()
262 mpImpl
->mpPage
->mnTransitionType
= mpImpl
->mnNewTransitionType
;
263 mpImpl
->mpPage
->mnTransitionSubtype
= mpImpl
->mnNewTransitionSubtype
;
264 mpImpl
->mpPage
->mbTransitionDirection
= mpImpl
->mbNewTransitionDirection
;
265 mpImpl
->mpPage
->mnTransitionFadeColor
= mpImpl
->mnNewTransitionFadeColor
;
266 mpImpl
->mpPage
->mfTransitionDuration
= mpImpl
->mfNewTransitionDuration
;
267 mpImpl
->mpPage
->maSoundFile
= mpImpl
->maNewSoundFile
;
268 mpImpl
->mpPage
->mbSoundOn
= mpImpl
->mbNewSoundOn
;
269 mpImpl
->mpPage
->mbLoopSound
= mpImpl
->mbNewLoopSound
;
270 mpImpl
->mpPage
->mbStopSound
= mpImpl
->mbNewStopSound
;
273 OUString
UndoTransition::GetComment() const
275 return SdResId(STR_UNDO_SLIDE_PARAMS
);
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */