Line data Source code
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 <com/sun/star/util/XCloneable.hpp>
21 : #include <com/sun/star/animations/XAnimationNode.hpp>
22 : #include "CustomAnimationCloner.hxx"
23 :
24 : #include "undoanim.hxx"
25 : #include "glob.hrc"
26 : #include "sdpage.hxx"
27 : #include "sdresid.hxx"
28 : #include "CustomAnimationEffect.hxx"
29 : #include "drawdoc.hxx"
30 :
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;
36 :
37 :
38 : namespace sd
39 : {
40 :
41 0 : struct UndoAnimationImpl
42 : {
43 : SdPage* mpPage;
44 : Reference< XAnimationNode > mxOldNode;
45 : Reference< XAnimationNode > mxNewNode;
46 : bool mbNewNodeSet;
47 : };
48 :
49 0 : UndoAnimation::UndoAnimation( SdDrawDocument* pDoc, SdPage* pThePage )
50 0 : : SdrUndoAction( *pDoc ), mpImpl( new UndoAnimationImpl )
51 : {
52 0 : mpImpl->mpPage = pThePage;
53 0 : mpImpl->mbNewNodeSet = false;
54 :
55 : try
56 : {
57 0 : if( pThePage->mxAnimationNode.is() )
58 0 : mpImpl->mxOldNode = ::sd::Clone( pThePage->getAnimationNode() );
59 : }
60 0 : catch( Exception& )
61 : {
62 : OSL_FAIL("sd::UndoAnimation::UndoAnimation(), exception caught!");
63 : }
64 0 : }
65 :
66 0 : UndoAnimation::~UndoAnimation()
67 : {
68 0 : delete mpImpl;
69 0 : }
70 :
71 0 : void UndoAnimation::Undo()
72 : {
73 : try
74 : {
75 0 : if( !mpImpl->mbNewNodeSet )
76 : {
77 0 : if( mpImpl->mpPage->mxAnimationNode.is() )
78 0 : mpImpl->mxNewNode.set( ::sd::Clone( mpImpl->mpPage->mxAnimationNode ) );
79 0 : mpImpl->mbNewNodeSet = true;
80 : }
81 :
82 0 : Reference< XAnimationNode > xOldNode;
83 0 : if( mpImpl->mxOldNode.is() )
84 0 : xOldNode = ::sd::Clone( mpImpl->mxOldNode );
85 :
86 0 : mpImpl->mpPage->setAnimationNode( xOldNode );
87 : }
88 0 : catch( Exception& )
89 : {
90 : OSL_FAIL("sd::UndoAnimation::Undo(), exception caught!");
91 : }
92 0 : }
93 :
94 0 : void UndoAnimation::Redo()
95 : {
96 : try
97 : {
98 0 : Reference< XAnimationNode > xNewNode;
99 0 : if( mpImpl->mxNewNode.is() )
100 0 : xNewNode = ::sd::Clone( mpImpl->mxNewNode );
101 0 : mpImpl->mpPage->setAnimationNode( xNewNode );
102 : }
103 0 : catch( Exception& )
104 : {
105 : OSL_FAIL("sd::UndoAnimation::Redo(), exception caught!");
106 : }
107 0 : }
108 :
109 0 : rtl::OUString UndoAnimation::GetComment() const
110 : {
111 0 : return SdResId(STR_UNDO_ANIMATION).toString();
112 : }
113 :
114 : struct UndoAnimationPathImpl
115 : {
116 : SdPage* mpPage;
117 : sal_Int32 mnEffectOffset;
118 : ::rtl::OUString msUndoPath;
119 : ::rtl::OUString msRedoPath;
120 :
121 0 : UndoAnimationPathImpl( SdPage* pThePage, const com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode )
122 : : mpPage( pThePage )
123 0 : , mnEffectOffset( -1 )
124 : {
125 0 : if( mpPage && xNode.is() )
126 : {
127 0 : boost::shared_ptr< sd::MainSequence > pMainSequence( mpPage->getMainSequence() );
128 0 : if( pMainSequence.get() )
129 : {
130 0 : CustomAnimationEffectPtr pEffect( pMainSequence->findEffect( xNode ) );
131 0 : if( pEffect.get() )
132 : {
133 0 : mnEffectOffset = pMainSequence->getOffsetFromEffect( pEffect );
134 0 : msUndoPath = pEffect->getPath();
135 0 : }
136 0 : }
137 : }
138 0 : }
139 :
140 0 : CustomAnimationEffectPtr getEffect() const
141 : {
142 0 : CustomAnimationEffectPtr pEffect;
143 0 : if( mpPage && (mnEffectOffset >= 0) )
144 : {
145 0 : boost::shared_ptr< sd::MainSequence > pMainSequence( mpPage->getMainSequence() );
146 0 : if( pMainSequence.get() )
147 0 : pEffect = pMainSequence->getEffectFromOffset( mnEffectOffset );
148 : }
149 0 : return pEffect;
150 : }
151 :
152 : private:
153 : UndoAnimationPathImpl( const UndoAnimationPathImpl& ); //not implemented
154 : const UndoAnimationPathImpl& operator=( const UndoAnimationPathImpl& ); // not implemented
155 :
156 : };
157 :
158 0 : UndoAnimationPath::UndoAnimationPath( SdDrawDocument* pDoc, SdPage* pThePage, const com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode )
159 : : SdrUndoAction( *pDoc )
160 0 : , mpImpl( new UndoAnimationPathImpl( pThePage, xNode ) )
161 : {
162 0 : }
163 :
164 0 : UndoAnimationPath::~UndoAnimationPath()
165 : {
166 0 : }
167 :
168 0 : void UndoAnimationPath::Undo()
169 : {
170 0 : CustomAnimationEffectPtr pEffect = mpImpl->getEffect();
171 0 : if( pEffect.get() )
172 : {
173 0 : mpImpl->msRedoPath = pEffect->getPath();
174 0 : pEffect->setPath( mpImpl->msUndoPath );
175 0 : }
176 0 : }
177 :
178 0 : void UndoAnimationPath::Redo()
179 : {
180 0 : CustomAnimationEffectPtr pEffect = mpImpl->getEffect();
181 0 : if( pEffect.get() )
182 : {
183 0 : pEffect->setPath( mpImpl->msRedoPath );
184 0 : }
185 0 : }
186 :
187 0 : rtl::OUString UndoAnimationPath::GetComment() const
188 : {
189 0 : return SdResId(STR_UNDO_ANIMATION).toString();
190 : }
191 :
192 0 : struct UndoTransitionImpl
193 : {
194 : SdPage* mpPage;
195 :
196 : sal_Int16 mnNewTransitionType;
197 : sal_Int16 mnNewTransitionSubtype;
198 : sal_Bool mbNewTransitionDirection;
199 : sal_Int32 mnNewTransitionFadeColor;
200 : double mfNewTransitionDuration;
201 : String maNewSoundFile;
202 : bool mbNewSoundOn;
203 : bool mbNewLoopSound;
204 : bool mbNewStopSound;
205 :
206 : sal_Int16 mnOldTransitionType;
207 : sal_Int16 mnOldTransitionSubtype;
208 : sal_Bool mbOldTransitionDirection;
209 : sal_Int32 mnOldTransitionFadeColor;
210 : double mfOldTransitionDuration;
211 : String maOldSoundFile;
212 : bool mbOldSoundOn;
213 : bool mbOldLoopSound;
214 : bool mbOldStopSound;
215 : };
216 :
217 0 : UndoTransition::UndoTransition( SdDrawDocument* _pDoc, SdPage* pThePage )
218 0 : : SdUndoAction( _pDoc ), mpImpl( new UndoTransitionImpl )
219 : {
220 0 : mpImpl->mpPage = pThePage;
221 :
222 0 : mpImpl->mnNewTransitionType = -1;
223 0 : mpImpl->mnOldTransitionType = pThePage->mnTransitionType;
224 0 : mpImpl->mnOldTransitionSubtype = pThePage->mnTransitionSubtype;
225 0 : mpImpl->mbOldTransitionDirection = pThePage->mbTransitionDirection;
226 0 : mpImpl->mnOldTransitionFadeColor = pThePage->mnTransitionFadeColor;
227 0 : mpImpl->mfOldTransitionDuration = pThePage->mfTransitionDuration;
228 0 : mpImpl->maOldSoundFile = pThePage->maSoundFile;
229 0 : mpImpl->mbOldSoundOn = pThePage->mbSoundOn;
230 0 : mpImpl->mbOldLoopSound = pThePage->mbLoopSound;
231 0 : mpImpl->mbOldStopSound = pThePage->mbStopSound;
232 0 : }
233 :
234 0 : UndoTransition::~UndoTransition()
235 : {
236 0 : delete mpImpl;
237 0 : }
238 :
239 0 : void UndoTransition::Undo()
240 : {
241 0 : if( mpImpl->mnNewTransitionType == -1 )
242 : {
243 0 : mpImpl->mnNewTransitionType = mpImpl->mpPage->mnTransitionType;
244 0 : mpImpl->mnNewTransitionSubtype = mpImpl->mpPage->mnTransitionSubtype;
245 0 : mpImpl->mbNewTransitionDirection = mpImpl->mpPage->mbTransitionDirection;
246 0 : mpImpl->mnNewTransitionFadeColor = mpImpl->mpPage->mnTransitionFadeColor;
247 0 : mpImpl->mfNewTransitionDuration = mpImpl->mpPage->mfTransitionDuration;
248 0 : mpImpl->maNewSoundFile = mpImpl->mpPage->maSoundFile;
249 0 : mpImpl->mbNewSoundOn = mpImpl->mpPage->mbSoundOn;
250 0 : mpImpl->mbNewLoopSound = mpImpl->mpPage->mbLoopSound;
251 0 : mpImpl->mbNewStopSound = mpImpl->mpPage->mbStopSound;
252 : }
253 :
254 0 : mpImpl->mpPage->mnTransitionType = mpImpl->mnOldTransitionType;
255 0 : mpImpl->mpPage->mnTransitionSubtype = mpImpl->mnOldTransitionSubtype;
256 0 : mpImpl->mpPage->mbTransitionDirection = mpImpl->mbOldTransitionDirection;
257 0 : mpImpl->mpPage->mnTransitionFadeColor = mpImpl->mnOldTransitionFadeColor;
258 0 : mpImpl->mpPage->mfTransitionDuration = mpImpl->mfOldTransitionDuration;
259 0 : mpImpl->mpPage->maSoundFile = mpImpl->maOldSoundFile;
260 0 : mpImpl->mpPage->mbSoundOn = mpImpl->mbOldSoundOn;
261 0 : mpImpl->mpPage->mbLoopSound = mpImpl->mbOldLoopSound;
262 0 : mpImpl->mpPage->mbStopSound = mpImpl->mbOldStopSound;
263 0 : }
264 :
265 0 : void UndoTransition::Redo()
266 : {
267 0 : mpImpl->mpPage->mnTransitionType = mpImpl->mnNewTransitionType;
268 0 : mpImpl->mpPage->mnTransitionSubtype = mpImpl->mnNewTransitionSubtype;
269 0 : mpImpl->mpPage->mbTransitionDirection = mpImpl->mbNewTransitionDirection;
270 0 : mpImpl->mpPage->mnTransitionFadeColor = mpImpl->mnNewTransitionFadeColor;
271 0 : mpImpl->mpPage->mfTransitionDuration = mpImpl->mfNewTransitionDuration;
272 0 : mpImpl->mpPage->maSoundFile = mpImpl->maNewSoundFile;
273 0 : mpImpl->mpPage->mbSoundOn = mpImpl->mbNewSoundOn;
274 0 : mpImpl->mpPage->mbLoopSound = mpImpl->mbNewLoopSound;
275 0 : mpImpl->mpPage->mbStopSound = mpImpl->mbNewStopSound;
276 0 : }
277 :
278 0 : rtl::OUString UndoTransition::GetComment() const
279 : {
280 0 : return SdResId(STR_UNDO_SLIDE_PARAMS).toString();
281 : }
282 :
283 : }
284 :
285 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|