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 <com/sun/star/util/XCloneable.hpp>
21 #include <com/sun/star/animations/XAnimationNode.hpp>
22 #include "CustomAnimationCloner.hxx"
24 #include "undoanim.hxx"
27 #include "sdresid.hxx"
28 #include "CustomAnimationEffect.hxx"
29 #include "drawdoc.hxx"
31 using ::com::sun::star::uno::Reference
;
32 using ::com::sun::star::uno::Exception
;
33 using ::com::sun::star::uno::UNO_QUERY_THROW
;
34 using ::com::sun::star::util::XCloneable
;
35 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 OSL_FAIL("sd::UndoAnimation::UndoAnimation(), exception caught!");
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 OSL_FAIL("sd::UndoAnimation::Undo(), exception caught!");
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 OSL_FAIL("sd::UndoAnimation::Redo(), exception caught!");
108 OUString
UndoAnimation::GetComment() const
110 return SdResId(STR_UNDO_ANIMATION
).toString();
113 struct UndoAnimationPathImpl
116 sal_Int32 mnEffectOffset
;
120 UndoAnimationPathImpl( SdPage
* pThePage
, const com::sun::star::uno::Reference
< ::com::sun::star::animations::XAnimationNode
>& xNode
)
122 , mnEffectOffset( -1 )
124 if( mpPage
&& xNode
.is() )
126 boost::shared_ptr
< sd::MainSequence
> pMainSequence( mpPage
->getMainSequence() );
127 if( pMainSequence
.get() )
129 CustomAnimationEffectPtr
pEffect( pMainSequence
->findEffect( xNode
) );
132 mnEffectOffset
= pMainSequence
->getOffsetFromEffect( pEffect
);
133 msUndoPath
= pEffect
->getPath();
139 CustomAnimationEffectPtr
getEffect() const
141 CustomAnimationEffectPtr pEffect
;
142 if( mpPage
&& (mnEffectOffset
>= 0) )
144 boost::shared_ptr
< sd::MainSequence
> pMainSequence( mpPage
->getMainSequence() );
145 if( pMainSequence
.get() )
146 pEffect
= pMainSequence
->getEffectFromOffset( mnEffectOffset
);
152 UndoAnimationPathImpl( const UndoAnimationPathImpl
& ); //not implemented
153 const UndoAnimationPathImpl
& operator=( const UndoAnimationPathImpl
& ); // not implemented
157 UndoAnimationPath::UndoAnimationPath( SdDrawDocument
* pDoc
, SdPage
* pThePage
, const com::sun::star::uno::Reference
< ::com::sun::star::animations::XAnimationNode
>& xNode
)
158 : SdrUndoAction( *pDoc
)
159 , mpImpl( new UndoAnimationPathImpl( pThePage
, xNode
) )
163 UndoAnimationPath::~UndoAnimationPath()
167 void UndoAnimationPath::Undo()
169 CustomAnimationEffectPtr pEffect
= mpImpl
->getEffect();
172 mpImpl
->msRedoPath
= pEffect
->getPath();
173 pEffect
->setPath( mpImpl
->msUndoPath
);
177 void UndoAnimationPath::Redo()
179 CustomAnimationEffectPtr pEffect
= mpImpl
->getEffect();
182 pEffect
->setPath( mpImpl
->msRedoPath
);
186 OUString
UndoAnimationPath::GetComment() const
188 return SdResId(STR_UNDO_ANIMATION
).toString();
191 struct UndoTransitionImpl
195 sal_Int16 mnNewTransitionType
;
196 sal_Int16 mnNewTransitionSubtype
;
197 sal_Bool mbNewTransitionDirection
;
198 sal_Int32 mnNewTransitionFadeColor
;
199 double mfNewTransitionDuration
;
200 String maNewSoundFile
;
205 sal_Int16 mnOldTransitionType
;
206 sal_Int16 mnOldTransitionSubtype
;
207 sal_Bool mbOldTransitionDirection
;
208 sal_Int32 mnOldTransitionFadeColor
;
209 double mfOldTransitionDuration
;
210 String maOldSoundFile
;
216 UndoTransition::UndoTransition( SdDrawDocument
* _pDoc
, SdPage
* pThePage
)
217 : SdUndoAction( _pDoc
), mpImpl( new UndoTransitionImpl
)
219 mpImpl
->mpPage
= pThePage
;
221 mpImpl
->mnNewTransitionType
= -1;
222 mpImpl
->mnOldTransitionType
= pThePage
->mnTransitionType
;
223 mpImpl
->mnOldTransitionSubtype
= pThePage
->mnTransitionSubtype
;
224 mpImpl
->mbOldTransitionDirection
= pThePage
->mbTransitionDirection
;
225 mpImpl
->mnOldTransitionFadeColor
= pThePage
->mnTransitionFadeColor
;
226 mpImpl
->mfOldTransitionDuration
= pThePage
->mfTransitionDuration
;
227 mpImpl
->maOldSoundFile
= pThePage
->maSoundFile
;
228 mpImpl
->mbOldSoundOn
= pThePage
->mbSoundOn
;
229 mpImpl
->mbOldLoopSound
= pThePage
->mbLoopSound
;
230 mpImpl
->mbOldStopSound
= pThePage
->mbStopSound
;
233 UndoTransition::~UndoTransition()
237 void UndoTransition::Undo()
239 if( mpImpl
->mnNewTransitionType
== -1 )
241 mpImpl
->mnNewTransitionType
= mpImpl
->mpPage
->mnTransitionType
;
242 mpImpl
->mnNewTransitionSubtype
= mpImpl
->mpPage
->mnTransitionSubtype
;
243 mpImpl
->mbNewTransitionDirection
= mpImpl
->mpPage
->mbTransitionDirection
;
244 mpImpl
->mnNewTransitionFadeColor
= mpImpl
->mpPage
->mnTransitionFadeColor
;
245 mpImpl
->mfNewTransitionDuration
= mpImpl
->mpPage
->mfTransitionDuration
;
246 mpImpl
->maNewSoundFile
= mpImpl
->mpPage
->maSoundFile
;
247 mpImpl
->mbNewSoundOn
= mpImpl
->mpPage
->mbSoundOn
;
248 mpImpl
->mbNewLoopSound
= mpImpl
->mpPage
->mbLoopSound
;
249 mpImpl
->mbNewStopSound
= mpImpl
->mpPage
->mbStopSound
;
252 mpImpl
->mpPage
->mnTransitionType
= mpImpl
->mnOldTransitionType
;
253 mpImpl
->mpPage
->mnTransitionSubtype
= mpImpl
->mnOldTransitionSubtype
;
254 mpImpl
->mpPage
->mbTransitionDirection
= mpImpl
->mbOldTransitionDirection
;
255 mpImpl
->mpPage
->mnTransitionFadeColor
= mpImpl
->mnOldTransitionFadeColor
;
256 mpImpl
->mpPage
->mfTransitionDuration
= mpImpl
->mfOldTransitionDuration
;
257 mpImpl
->mpPage
->maSoundFile
= mpImpl
->maOldSoundFile
;
258 mpImpl
->mpPage
->mbSoundOn
= mpImpl
->mbOldSoundOn
;
259 mpImpl
->mpPage
->mbLoopSound
= mpImpl
->mbOldLoopSound
;
260 mpImpl
->mpPage
->mbStopSound
= mpImpl
->mbOldStopSound
;
263 void UndoTransition::Redo()
265 mpImpl
->mpPage
->mnTransitionType
= mpImpl
->mnNewTransitionType
;
266 mpImpl
->mpPage
->mnTransitionSubtype
= mpImpl
->mnNewTransitionSubtype
;
267 mpImpl
->mpPage
->mbTransitionDirection
= mpImpl
->mbNewTransitionDirection
;
268 mpImpl
->mpPage
->mnTransitionFadeColor
= mpImpl
->mnNewTransitionFadeColor
;
269 mpImpl
->mpPage
->mfTransitionDuration
= mpImpl
->mfNewTransitionDuration
;
270 mpImpl
->mpPage
->maSoundFile
= mpImpl
->maNewSoundFile
;
271 mpImpl
->mpPage
->mbSoundOn
= mpImpl
->mbNewSoundOn
;
272 mpImpl
->mpPage
->mbLoopSound
= mpImpl
->mbNewLoopSound
;
273 mpImpl
->mpPage
->mbStopSound
= mpImpl
->mbNewStopSound
;
276 OUString
UndoTransition::GetComment() const
278 return SdResId(STR_UNDO_SLIDE_PARAMS
).toString();
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */