1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <sal/config.h>
21
22 #include <CustomAnimationCloner.hxx>
23
24 #include <undoanim.hxx>
25 #include <strings.hrc>
26 #include <sdpage.hxx>
27 #include <sdresid.hxx>
28 #include <CustomAnimationEffect.hxx>
29 #include <drawdoc.hxx>
30 #include <tools/diagnose_ex.h>
31
32 namespace com::sun::star::animations { class XAnimationNode; }
33
34 using ::com::sun::star::uno::Reference;
35 using ::com::sun::star::uno::Exception;
36 using namespace ::com::sun::star::animations;
37
38 namespace sd
39 {
40
41 struct UndoAnimationImpl
42 {
43 SdPage* mpPage;
44 Reference< XAnimationNode > mxOldNode;
45 Reference< XAnimationNode > mxNewNode;
46 bool mbNewNodeSet;
47 };
48
UndoAnimation(SdDrawDocument * pDoc,SdPage * pThePage)49 UndoAnimation::UndoAnimation( SdDrawDocument* pDoc, SdPage* pThePage )
50 : SdrUndoAction( *pDoc ), mpImpl( new UndoAnimationImpl )
51 {
52 mpImpl->mpPage = pThePage;
53 mpImpl->mbNewNodeSet = false;
54
55 try
56 {
57 if( pThePage->mxAnimationNode.is() )
58 mpImpl->mxOldNode = ::sd::Clone( pThePage->getAnimationNode() );
59 }
60 catch( Exception& )
61 {
62 TOOLS_WARN_EXCEPTION( "sd", "sd::UndoAnimation::UndoAnimation()");
63 }
64 }
65
~UndoAnimation()66 UndoAnimation::~UndoAnimation()
67 {
68 }
69
Undo()70 void UndoAnimation::Undo()
71 {
72 try
73 {
74 if( !mpImpl->mbNewNodeSet )
75 {
76 if( mpImpl->mpPage->mxAnimationNode.is() )
77 mpImpl->mxNewNode.set( ::sd::Clone( mpImpl->mpPage->mxAnimationNode ) );
78 mpImpl->mbNewNodeSet = true;
79 }
80
81 Reference< XAnimationNode > xOldNode;
82 if( mpImpl->mxOldNode.is() )
83 xOldNode = ::sd::Clone( mpImpl->mxOldNode );
84
85 mpImpl->mpPage->setAnimationNode( xOldNode );
86 }
87 catch( Exception& )
88 {
89 TOOLS_WARN_EXCEPTION( "sd", "sd::UndoAnimation::Undo()");
90 }
91 }
92
Redo()93 void UndoAnimation::Redo()
94 {
95 try
96 {
97 Reference< XAnimationNode > xNewNode;
98 if( mpImpl->mxNewNode.is() )
99 xNewNode = ::sd::Clone( mpImpl->mxNewNode );
100 mpImpl->mpPage->setAnimationNode( xNewNode );
101 }
102 catch( Exception& )
103 {
104 TOOLS_WARN_EXCEPTION( "sd", "sd::UndoAnimation::Redo()");
105 }
106 }
107
GetComment() const108 OUString UndoAnimation::GetComment() const
109 {
110 return SdResId(STR_UNDO_ANIMATION);
111 }
112
113 struct UndoAnimationPathImpl
114 {
115 SdPage* mpPage;
116 sal_Int32 mnEffectOffset;
117 OUString msUndoPath;
118 OUString msRedoPath;
119
UndoAnimationPathImplsd::UndoAnimationPathImpl120 UndoAnimationPathImpl( SdPage* pThePage, const css::uno::Reference< css::animations::XAnimationNode >& xNode )
121 : mpPage( pThePage )
122 , mnEffectOffset( -1 )
123 {
124 if( !(mpPage && xNode.is()) )
125 return;
126
127 std::shared_ptr< sd::MainSequence > pMainSequence( mpPage->getMainSequence() );
128 if( pMainSequence )
129 {
130 CustomAnimationEffectPtr pEffect( pMainSequence->findEffect( xNode ) );
131 if( pEffect )
132 {
133 mnEffectOffset = pMainSequence->getOffsetFromEffect( pEffect );
134 msUndoPath = pEffect->getPath();
135 }
136 }
137 }
138 UndoAnimationPathImpl(const UndoAnimationPathImpl&) = delete;
139 UndoAnimationPathImpl& operator=(const UndoAnimationPathImpl&) = delete;
140
getEffectsd::UndoAnimationPathImpl141 CustomAnimationEffectPtr getEffect() const
142 {
143 CustomAnimationEffectPtr pEffect;
144 if( mpPage && (mnEffectOffset >= 0) )
145 {
146 std::shared_ptr< sd::MainSequence > pMainSequence( mpPage->getMainSequence() );
147 if( pMainSequence )
148 pEffect = pMainSequence->getEffectFromOffset( mnEffectOffset );
149 }
150 return pEffect;
151 }
152 };
153
UndoAnimationPath(SdDrawDocument * pDoc,SdPage * pThePage,const css::uno::Reference<css::animations::XAnimationNode> & xNode)154 UndoAnimationPath::UndoAnimationPath( SdDrawDocument* pDoc, SdPage* pThePage, const css::uno::Reference< css::animations::XAnimationNode >& xNode )
155 : SdrUndoAction( *pDoc )
156 , mpImpl( new UndoAnimationPathImpl( pThePage, xNode ) )
157 {
158 }
159
~UndoAnimationPath()160 UndoAnimationPath::~UndoAnimationPath()
161 {
162 }
163
Undo()164 void UndoAnimationPath::Undo()
165 {
166 CustomAnimationEffectPtr pEffect = mpImpl->getEffect();
167 if( pEffect )
168 {
169 mpImpl->msRedoPath = pEffect->getPath();
170 pEffect->setPath( mpImpl->msUndoPath );
171 }
172 }
173
Redo()174 void UndoAnimationPath::Redo()
175 {
176 CustomAnimationEffectPtr pEffect = mpImpl->getEffect();
177 if( pEffect )
178 {
179 pEffect->setPath( mpImpl->msRedoPath );
180 }
181 }
182
GetComment() const183 OUString UndoAnimationPath::GetComment() const
184 {
185 return SdResId(STR_UNDO_ANIMATION);
186 }
187
188 struct UndoTransitionImpl
189 {
190 SdPage* mpPage;
191
192 sal_Int16 mnNewTransitionType;
193 sal_Int16 mnNewTransitionSubtype;
194 bool mbNewTransitionDirection;
195 sal_Int32 mnNewTransitionFadeColor;
196 double mfNewTransitionDuration;
197 OUString maNewSoundFile;
198 bool mbNewSoundOn;
199 bool mbNewLoopSound;
200 bool mbNewStopSound;
201
202 sal_Int16 mnOldTransitionType;
203 sal_Int16 mnOldTransitionSubtype;
204 bool mbOldTransitionDirection;
205 sal_Int32 mnOldTransitionFadeColor;
206 double mfOldTransitionDuration;
207 OUString maOldSoundFile;
208 bool mbOldSoundOn;
209 bool mbOldLoopSound;
210 bool mbOldStopSound;
211 };
212
UndoTransition(SdDrawDocument * _pDoc,SdPage * pThePage)213 UndoTransition::UndoTransition( SdDrawDocument* _pDoc, SdPage* pThePage )
214 : SdUndoAction( _pDoc ), mpImpl( new UndoTransitionImpl )
215 {
216 mpImpl->mpPage = pThePage;
217
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;
228 }
229
~UndoTransition()230 UndoTransition::~UndoTransition()
231 {
232 }
233
Undo()234 void UndoTransition::Undo()
235 {
236 if( mpImpl->mnNewTransitionType == -1 )
237 {
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;
247 }
248
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;
258 }
259
Redo()260 void UndoTransition::Redo()
261 {
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;
271 }
272
GetComment() const273 OUString UndoTransition::GetComment() const
274 {
275 return SdResId(STR_UNDO_SLIDE_PARAMS);
276 }
277
278 }
279
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
281