xref: /trunk/main/sd/source/core/undoanim.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 #include <com/sun/star/util/XCloneable.hpp>
31 #include <com/sun/star/animations/XAnimationNode.hpp>
32 #include "CustomAnimationCloner.hxx"
33 
34 #include "undoanim.hxx"
35 #include "glob.hrc"
36 #include "sdpage.hxx"
37 #include "sdresid.hxx"
38 #include "CustomAnimationEffect.hxx"
39 #include "drawdoc.hxx"
40 
41 using ::com::sun::star::uno::Reference;
42 using ::com::sun::star::uno::Exception;
43 using ::com::sun::star::uno::UNO_QUERY_THROW;
44 using ::com::sun::star::util::XCloneable;
45 using namespace ::com::sun::star::animations;
46 
47 
48 namespace sd
49 {
50 
51 struct UndoAnimationImpl
52 {
53     SdPage*         mpPage;
54     Reference< XAnimationNode > mxOldNode;
55     Reference< XAnimationNode > mxNewNode;
56     bool            mbNewNodeSet;
57 };
58 
59 UndoAnimation::UndoAnimation( SdDrawDocument* pDoc, SdPage* pThePage )
60 : SdrUndoAction( *pDoc ), mpImpl( new UndoAnimationImpl )
61 {
62     mpImpl->mpPage = pThePage;
63     mpImpl->mbNewNodeSet = false;
64 
65     try
66     {
67         if( pThePage->mxAnimationNode.is() )
68             mpImpl->mxOldNode = ::sd::Clone( pThePage->getAnimationNode() );
69     }
70     catch( Exception& e )
71     {
72         (void)e;
73         DBG_ERROR("sd::UndoAnimation::UndoAnimation(), exception caught!");
74     }
75 }
76 
77 UndoAnimation::~UndoAnimation()
78 {
79     delete mpImpl;
80 }
81 
82 void UndoAnimation::Undo()
83 {
84     try
85     {
86         if( !mpImpl->mbNewNodeSet )
87         {
88             if( mpImpl->mpPage->mxAnimationNode.is() )
89                 mpImpl->mxNewNode.set( ::sd::Clone( mpImpl->mpPage->mxAnimationNode ) );
90             mpImpl->mbNewNodeSet = true;
91         }
92 
93         Reference< XAnimationNode > xOldNode;
94         if( mpImpl->mxOldNode.is() )
95             xOldNode = ::sd::Clone( mpImpl->mxOldNode );
96 
97         mpImpl->mpPage->setAnimationNode( xOldNode );
98     }
99     catch( Exception& e )
100     {
101         (void)e;
102         DBG_ERROR("sd::UndoAnimation::Undo(), exception caught!");
103     }
104 }
105 
106 void UndoAnimation::Redo()
107 {
108     try
109     {
110         Reference< XAnimationNode > xNewNode;
111         if( mpImpl->mxNewNode.is() )
112             xNewNode = ::sd::Clone( mpImpl->mxNewNode );
113         mpImpl->mpPage->setAnimationNode( xNewNode );
114     }
115     catch( Exception& e )
116     {
117         (void)e;
118         DBG_ERROR("sd::UndoAnimation::Redo(), exception caught!");
119     }
120 }
121 
122 String UndoAnimation::GetComment() const
123 {
124     return String(SdResId(STR_UNDO_ANIMATION));
125 }
126 
127 struct UndoAnimationPathImpl
128 {
129     SdPage*         mpPage;
130     sal_Int32       mnEffectOffset;
131     ::rtl::OUString msUndoPath;
132     ::rtl::OUString msRedoPath;
133 
134     UndoAnimationPathImpl( SdPage* pThePage, const com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode )
135         : mpPage( pThePage )
136         , mnEffectOffset( -1 )
137     {
138         if( mpPage && xNode.is() )
139         {
140             boost::shared_ptr< sd::MainSequence > pMainSequence( mpPage->getMainSequence() );
141             if( pMainSequence.get() )
142             {
143                 CustomAnimationEffectPtr pEffect( pMainSequence->findEffect( xNode ) );
144                 if( pEffect.get() )
145                 {
146                     mnEffectOffset = pMainSequence->getOffsetFromEffect( pEffect );
147                     msUndoPath = pEffect->getPath();
148                 }
149             }
150         }
151     }
152 
153     CustomAnimationEffectPtr getEffect() const
154     {
155         CustomAnimationEffectPtr pEffect;
156         if( mpPage && (mnEffectOffset >= 0) )
157         {
158             boost::shared_ptr< sd::MainSequence > pMainSequence( mpPage->getMainSequence() );
159             if( pMainSequence.get() )
160                 pEffect = pMainSequence->getEffectFromOffset( mnEffectOffset );
161         }
162         return pEffect;
163     }
164 
165     private:
166         UndoAnimationPathImpl( const UndoAnimationPathImpl& ); //not implemented
167         const UndoAnimationPathImpl& operator=( const UndoAnimationPathImpl& ); // not implemented
168 
169 };
170 
171 UndoAnimationPath::UndoAnimationPath( SdDrawDocument* pDoc, SdPage* pThePage, const com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode )
172 : SdrUndoAction( *pDoc )
173 , mpImpl( new UndoAnimationPathImpl( pThePage, xNode ) )
174 {
175 }
176 
177 UndoAnimationPath::~UndoAnimationPath()
178 {
179 }
180 
181 void UndoAnimationPath::Undo()
182 {
183     CustomAnimationEffectPtr pEffect = mpImpl->getEffect();
184     if( pEffect.get() )
185     {
186         mpImpl->msRedoPath = pEffect->getPath();
187         pEffect->setPath( mpImpl->msUndoPath );
188     }
189 }
190 
191 void UndoAnimationPath::Redo()
192 {
193     CustomAnimationEffectPtr pEffect = mpImpl->getEffect();
194     if( pEffect.get() )
195     {
196         pEffect->setPath( mpImpl->msRedoPath );
197     }
198 }
199 
200 String UndoAnimationPath::GetComment() const
201 {
202     return String(SdResId(STR_UNDO_ANIMATION));
203 }
204 
205 struct UndoTransitionImpl
206 {
207     SdPage*         mpPage;
208 
209     sal_Int16 mnNewTransitionType;
210     sal_Int16 mnNewTransitionSubtype;
211     sal_Bool mbNewTransitionDirection;
212     sal_Int32 mnNewTransitionFadeColor;
213     double mfNewTransitionDuration;
214     String maNewSoundFile;
215     bool mbNewSoundOn;
216     bool mbNewLoopSound;
217     bool mbNewStopSound;
218 
219     sal_Int16 mnOldTransitionType;
220     sal_Int16 mnOldTransitionSubtype;
221     sal_Bool mbOldTransitionDirection;
222     sal_Int32 mnOldTransitionFadeColor;
223     double mfOldTransitionDuration;
224     String maOldSoundFile;
225     bool mbOldSoundOn;
226     bool mbOldLoopSound;
227     bool mbOldStopSound;
228 };
229 
230 UndoTransition::UndoTransition( SdDrawDocument* _pDoc, SdPage* pThePage )
231 : SdUndoAction( _pDoc ), mpImpl( new UndoTransitionImpl )
232 {
233     mpImpl->mpPage = pThePage;
234 
235     mpImpl->mnNewTransitionType = -1;
236     mpImpl->mnOldTransitionType = pThePage->mnTransitionType;
237     mpImpl->mnOldTransitionSubtype = pThePage->mnTransitionSubtype;
238     mpImpl->mbOldTransitionDirection = pThePage->mbTransitionDirection;
239     mpImpl->mnOldTransitionFadeColor = pThePage->mnTransitionFadeColor;
240     mpImpl->mfOldTransitionDuration = pThePage->mfTransitionDuration;
241     mpImpl->maOldSoundFile = pThePage->maSoundFile;
242     mpImpl->mbOldSoundOn = pThePage->mbSoundOn;
243     mpImpl->mbOldLoopSound = pThePage->mbLoopSound;
244     mpImpl->mbOldStopSound = pThePage->mbStopSound;
245 }
246 
247 UndoTransition::~UndoTransition()
248 {
249     delete mpImpl;
250 }
251 
252 void UndoTransition::Undo()
253 {
254     if( mpImpl->mnNewTransitionType == -1 )
255     {
256         mpImpl->mnNewTransitionType = mpImpl->mpPage->mnTransitionType;
257         mpImpl->mnNewTransitionSubtype = mpImpl->mpPage->mnTransitionSubtype;
258         mpImpl->mbNewTransitionDirection = mpImpl->mpPage->mbTransitionDirection;
259         mpImpl->mnNewTransitionFadeColor = mpImpl->mpPage->mnTransitionFadeColor;
260         mpImpl->mfNewTransitionDuration = mpImpl->mpPage->mfTransitionDuration;
261         mpImpl->maNewSoundFile = mpImpl->mpPage->maSoundFile;
262         mpImpl->mbNewSoundOn = mpImpl->mpPage->mbSoundOn;
263         mpImpl->mbNewLoopSound = mpImpl->mpPage->mbLoopSound;
264         mpImpl->mbNewStopSound = mpImpl->mpPage->mbStopSound;
265     }
266 
267     mpImpl->mpPage->mnTransitionType = mpImpl->mnOldTransitionType;
268     mpImpl->mpPage->mnTransitionSubtype = mpImpl->mnOldTransitionSubtype;
269     mpImpl->mpPage->mbTransitionDirection = mpImpl->mbOldTransitionDirection;
270     mpImpl->mpPage->mnTransitionFadeColor = mpImpl->mnOldTransitionFadeColor;
271     mpImpl->mpPage->mfTransitionDuration = mpImpl->mfOldTransitionDuration;
272     mpImpl->mpPage->maSoundFile = mpImpl->maOldSoundFile;
273     mpImpl->mpPage->mbSoundOn = mpImpl->mbOldSoundOn;
274     mpImpl->mpPage->mbLoopSound = mpImpl->mbOldLoopSound;
275     mpImpl->mpPage->mbStopSound = mpImpl->mbOldStopSound;
276 }
277 
278 void UndoTransition::Redo()
279 {
280     mpImpl->mpPage->mnTransitionType = mpImpl->mnNewTransitionType;
281     mpImpl->mpPage->mnTransitionSubtype = mpImpl->mnNewTransitionSubtype;
282     mpImpl->mpPage->mbTransitionDirection = mpImpl->mbNewTransitionDirection;
283     mpImpl->mpPage->mnTransitionFadeColor = mpImpl->mnNewTransitionFadeColor;
284     mpImpl->mpPage->mfTransitionDuration = mpImpl->mfNewTransitionDuration;
285     mpImpl->mpPage->maSoundFile = mpImpl->maNewSoundFile;
286     mpImpl->mpPage->mbSoundOn = mpImpl->mbNewSoundOn;
287     mpImpl->mpPage->mbLoopSound = mpImpl->mbNewLoopSound;
288     mpImpl->mpPage->mbStopSound = mpImpl->mbNewStopSound;
289 }
290 
291 String UndoTransition::GetComment() const
292 {
293     return String(SdResId(STR_UNDO_SLIDE_PARAMS));
294 }
295 
296 }
297