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