xref: /AOO41X/main/sd/source/core/CustomAnimationEffect.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 <tools/debug.hxx>
31*cdf0e10cSrcweir #include <com/sun/star/util/XCloneable.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/animations/AnimationFill.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/container/XEnumerationAccess.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/presentation/EffectNodeType.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/presentation/EffectCommands.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/presentation/EffectPresetClass.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/presentation/ParagraphTarget.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/presentation/ShapeAnimationSubType.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/animations/AnimationNodeType.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/animations/XCommand.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/animations/AnimationTransformType.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/animations/XIterateContainer.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/animations/XAnimateTransform.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/animations/Event.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/animations/EventTrigger.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/animations/Timing.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPage.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/text/XText.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/animations/XAnimate.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/util/XChangesNotifier.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/animations/XAnimateMotion.hpp>
55*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
56*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
57*cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/i18n/XBreakIterator.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/i18n/CharacterIteratorMode.hpp>
60*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_TEXT_WORDTYPE_HPP_
61*cdf0e10cSrcweir #include <com/sun/star/i18n/WordType.hpp>
62*cdf0e10cSrcweir #endif
63*cdf0e10cSrcweir #include <com/sun/star/presentation/TextAnimationType.hpp>
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx>
66*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
67*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
68*cdf0e10cSrcweir #include <basegfx/range/b2drange.hxx>
69*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx>
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir #include <algorithm>
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir #include <drawinglayer/geometry/viewinformation2d.hxx>
76*cdf0e10cSrcweir #include <svx/sdr/contact/viewcontact.hxx>
77*cdf0e10cSrcweir #include <svx/svdopath.hxx>
78*cdf0e10cSrcweir #include <svx/svdpage.hxx>
79*cdf0e10cSrcweir #include <svx/unoapi.hxx>
80*cdf0e10cSrcweir #include "CustomAnimationEffect.hxx"
81*cdf0e10cSrcweir #include <CustomAnimationPreset.hxx>
82*cdf0e10cSrcweir #include "animations.hxx"
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir using namespace ::com::sun::star;
85*cdf0e10cSrcweir using namespace ::com::sun::star::presentation;
86*cdf0e10cSrcweir using namespace ::com::sun::star::animations;
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir using ::rtl::OUString;
89*cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
90*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
91*cdf0e10cSrcweir using ::com::sun::star::uno::XInterface;
92*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY;
93*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW;
94*cdf0e10cSrcweir using ::com::sun::star::uno::Any;
95*cdf0e10cSrcweir using ::com::sun::star::uno::makeAny;
96*cdf0e10cSrcweir using ::com::sun::star::uno::Exception;
97*cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException;
98*cdf0e10cSrcweir using ::com::sun::star::container::XEnumerationAccess;
99*cdf0e10cSrcweir using ::com::sun::star::container::XEnumeration;
100*cdf0e10cSrcweir using ::com::sun::star::beans::NamedValue;
101*cdf0e10cSrcweir using ::com::sun::star::container::XChild;
102*cdf0e10cSrcweir using ::com::sun::star::container::XElementAccess;
103*cdf0e10cSrcweir using ::com::sun::star::drawing::XShape;
104*cdf0e10cSrcweir using ::com::sun::star::lang::XInitialization;
105*cdf0e10cSrcweir using ::com::sun::star::drawing::XShapes;
106*cdf0e10cSrcweir using ::com::sun::star::drawing::XDrawPage;
107*cdf0e10cSrcweir using ::com::sun::star::text::XText;
108*cdf0e10cSrcweir using ::com::sun::star::text::XTextRange;
109*cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet;
110*cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory;
111*cdf0e10cSrcweir using ::com::sun::star::util::XCloneable;
112*cdf0e10cSrcweir using ::com::sun::star::lang::Locale;
113*cdf0e10cSrcweir using ::com::sun::star::util::XChangesNotifier;
114*cdf0e10cSrcweir using ::com::sun::star::util::XChangesListener;
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir namespace sd
117*cdf0e10cSrcweir {
118*cdf0e10cSrcweir class MainSequenceChangeGuard
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir public:
121*cdf0e10cSrcweir 	MainSequenceChangeGuard( EffectSequenceHelper* pSequence )
122*cdf0e10cSrcweir 	{
123*cdf0e10cSrcweir 		mpMainSequence = dynamic_cast< MainSequence* >( pSequence );
124*cdf0e10cSrcweir 		if( mpMainSequence == 0 )
125*cdf0e10cSrcweir 		{
126*cdf0e10cSrcweir 			InteractiveSequence* pI = dynamic_cast< InteractiveSequence* >( pSequence );
127*cdf0e10cSrcweir 			if( pI )
128*cdf0e10cSrcweir 				mpMainSequence = pI->mpMainSequence;
129*cdf0e10cSrcweir 		}
130*cdf0e10cSrcweir 		DBG_ASSERT( mpMainSequence, "sd::MainSequenceChangeGuard::MainSequenceChangeGuard(), no main sequence to guard!" );
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 		if( mpMainSequence )
133*cdf0e10cSrcweir 			mpMainSequence->mbIgnoreChanges++;
134*cdf0e10cSrcweir 	}
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir 	~MainSequenceChangeGuard()
137*cdf0e10cSrcweir 	{
138*cdf0e10cSrcweir 		if( mpMainSequence )
139*cdf0e10cSrcweir 			mpMainSequence->mbIgnoreChanges++;
140*cdf0e10cSrcweir 	}
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir private:
143*cdf0e10cSrcweir 	MainSequence* mpMainSequence;
144*cdf0e10cSrcweir };
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir CustomAnimationEffect::CustomAnimationEffect( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode )
147*cdf0e10cSrcweir :	mnNodeType(-1),
148*cdf0e10cSrcweir 	mnPresetClass(-1),
149*cdf0e10cSrcweir 	mfBegin(-1.0),
150*cdf0e10cSrcweir 	mfDuration(-1.0),
151*cdf0e10cSrcweir 	mfAbsoluteDuration(-1.0),
152*cdf0e10cSrcweir 	mnGroupId(-1),
153*cdf0e10cSrcweir 	mnIterateType(0),
154*cdf0e10cSrcweir 	mfIterateInterval(0.0),
155*cdf0e10cSrcweir 	mnParaDepth( -1 ),
156*cdf0e10cSrcweir 	mbHasText(sal_False),
157*cdf0e10cSrcweir 	mfAcceleration( 1.0 ),
158*cdf0e10cSrcweir 	mfDecelerate( 1.0 ),
159*cdf0e10cSrcweir 	mbAutoReverse(false),
160*cdf0e10cSrcweir 	mnTargetSubItem(0),
161*cdf0e10cSrcweir 	mnCommand(0),
162*cdf0e10cSrcweir 	mpEffectSequence( 0 ),
163*cdf0e10cSrcweir 	mbHasAfterEffect(false),
164*cdf0e10cSrcweir 	mbAfterEffectOnNextEffect(false)
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir 	setNode( xNode );
167*cdf0e10cSrcweir }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir // --------------------------------------------------------------------
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir void CustomAnimationEffect::setNode( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode )
172*cdf0e10cSrcweir {
173*cdf0e10cSrcweir 	mxNode = xNode;
174*cdf0e10cSrcweir 	mxAudio.clear();
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 	Sequence< NamedValue > aUserData( mxNode->getUserData() );
177*cdf0e10cSrcweir 	sal_Int32 nLength = aUserData.getLength();
178*cdf0e10cSrcweir 	const NamedValue* p = aUserData.getConstArray();
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir 	while( nLength-- )
181*cdf0e10cSrcweir 	{
182*cdf0e10cSrcweir         if( p->Name.equalsAscii( "node-type" ) )
183*cdf0e10cSrcweir 		{
184*cdf0e10cSrcweir 			p->Value >>= mnNodeType;
185*cdf0e10cSrcweir 		}
186*cdf0e10cSrcweir 		else if( p->Name.equalsAscii( "preset-id" ) )
187*cdf0e10cSrcweir 		{
188*cdf0e10cSrcweir 			p->Value >>= maPresetId;
189*cdf0e10cSrcweir 		}
190*cdf0e10cSrcweir 		else if( p->Name.equalsAscii( "preset-sub-type" ) )
191*cdf0e10cSrcweir 		{
192*cdf0e10cSrcweir 			p->Value >>= maPresetSubType;
193*cdf0e10cSrcweir 		}
194*cdf0e10cSrcweir 		else if( p->Name.equalsAscii( "preset-class" ) )
195*cdf0e10cSrcweir 		{
196*cdf0e10cSrcweir 			p->Value >>= mnPresetClass;
197*cdf0e10cSrcweir 		}
198*cdf0e10cSrcweir 		else if( p->Name.equalsAscii( "preset-property" ) )
199*cdf0e10cSrcweir 		{
200*cdf0e10cSrcweir 			p->Value >>= maProperty;
201*cdf0e10cSrcweir 		}
202*cdf0e10cSrcweir 		else if( p->Name.equalsAscii( "group-id" ) )
203*cdf0e10cSrcweir 		{
204*cdf0e10cSrcweir 			p->Value >>= mnGroupId;
205*cdf0e10cSrcweir 		}
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir 		p++;
208*cdf0e10cSrcweir 	}
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir 	// get effect start time
211*cdf0e10cSrcweir 	mxNode->getBegin() >>= mfBegin;
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir 	mfAcceleration = mxNode->getAcceleration();
214*cdf0e10cSrcweir 	mfDecelerate = mxNode->getDecelerate();
215*cdf0e10cSrcweir 	mbAutoReverse = mxNode->getAutoReverse();
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 	// get iteration data
218*cdf0e10cSrcweir 	Reference< XIterateContainer > xIter( mxNode, UNO_QUERY );
219*cdf0e10cSrcweir 	if( xIter.is() )
220*cdf0e10cSrcweir 	{
221*cdf0e10cSrcweir 		mfIterateInterval = xIter->getIterateInterval();
222*cdf0e10cSrcweir 		mnIterateType = xIter->getIterateType();
223*cdf0e10cSrcweir 		maTarget = xIter->getTarget();
224*cdf0e10cSrcweir 		mnTargetSubItem = xIter->getSubItem();
225*cdf0e10cSrcweir 	}
226*cdf0e10cSrcweir 	else
227*cdf0e10cSrcweir 	{
228*cdf0e10cSrcweir 		mfIterateInterval = 0.0f;
229*cdf0e10cSrcweir 		mnIterateType = 0;
230*cdf0e10cSrcweir 	}
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 	// calculate effect duration and get target shape
233*cdf0e10cSrcweir 	Reference< XEnumerationAccess > xEnumerationAccess( mxNode, UNO_QUERY );
234*cdf0e10cSrcweir 	if( xEnumerationAccess.is() )
235*cdf0e10cSrcweir 	{
236*cdf0e10cSrcweir 		Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY );
237*cdf0e10cSrcweir 		if( xEnumeration.is() )
238*cdf0e10cSrcweir 		{
239*cdf0e10cSrcweir 			while( xEnumeration->hasMoreElements() )
240*cdf0e10cSrcweir 			{
241*cdf0e10cSrcweir 				Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY );
242*cdf0e10cSrcweir 				if( !xChildNode.is() )
243*cdf0e10cSrcweir 					continue;
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir 				if( xChildNode->getType() == AnimationNodeType::AUDIO )
246*cdf0e10cSrcweir 				{
247*cdf0e10cSrcweir 					mxAudio.set( xChildNode, UNO_QUERY );
248*cdf0e10cSrcweir 				}
249*cdf0e10cSrcweir 				else if( xChildNode->getType() == AnimationNodeType::COMMAND )
250*cdf0e10cSrcweir 				{
251*cdf0e10cSrcweir 					Reference< XCommand > xCommand( xChildNode, UNO_QUERY );
252*cdf0e10cSrcweir 					if( xCommand.is() )
253*cdf0e10cSrcweir 					{
254*cdf0e10cSrcweir 						mnCommand = xCommand->getCommand();
255*cdf0e10cSrcweir 						if( !maTarget.hasValue() )
256*cdf0e10cSrcweir 							maTarget = xCommand->getTarget();
257*cdf0e10cSrcweir 					}
258*cdf0e10cSrcweir 				}
259*cdf0e10cSrcweir 				else
260*cdf0e10cSrcweir 				{
261*cdf0e10cSrcweir 					double fBegin = 0.0;
262*cdf0e10cSrcweir 					double fDuration = 0.0;
263*cdf0e10cSrcweir 					xChildNode->getBegin() >>= fBegin;
264*cdf0e10cSrcweir 					xChildNode->getDuration() >>= fDuration;
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir 					fDuration += fBegin;
267*cdf0e10cSrcweir 					if( fDuration > mfDuration )
268*cdf0e10cSrcweir 						mfDuration = fDuration;
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir 					// no target shape yet?
271*cdf0e10cSrcweir 					if( !maTarget.hasValue() )
272*cdf0e10cSrcweir 					{
273*cdf0e10cSrcweir 						// go get it boys!
274*cdf0e10cSrcweir 						Reference< XAnimate > xAnimate( xChildNode, UNO_QUERY );
275*cdf0e10cSrcweir 						if( xAnimate.is() )
276*cdf0e10cSrcweir 						{
277*cdf0e10cSrcweir 							maTarget = xAnimate->getTarget();
278*cdf0e10cSrcweir 							mnTargetSubItem = xAnimate->getSubItem();
279*cdf0e10cSrcweir 						}
280*cdf0e10cSrcweir 					}
281*cdf0e10cSrcweir 				}
282*cdf0e10cSrcweir 			}
283*cdf0e10cSrcweir 		}
284*cdf0e10cSrcweir 	}
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir 	mfAbsoluteDuration = mfDuration;
287*cdf0e10cSrcweir 	checkForText();
288*cdf0e10cSrcweir }
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir // --------------------------------------------------------------------
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir sal_Int32 CustomAnimationEffect::getNumberOfSubitems( const Any& aTarget, sal_Int16 nIterateType )
293*cdf0e10cSrcweir {
294*cdf0e10cSrcweir 	sal_Int32 nSubItems = 0;
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 	try
297*cdf0e10cSrcweir 	{
298*cdf0e10cSrcweir 		// first get target text
299*cdf0e10cSrcweir 		sal_Int32 nOnlyPara = -1;
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir 		Reference< XText > xShape;
302*cdf0e10cSrcweir 		aTarget >>= xShape;
303*cdf0e10cSrcweir 		if( !xShape.is() )
304*cdf0e10cSrcweir 		{
305*cdf0e10cSrcweir 			ParagraphTarget aParaTarget;
306*cdf0e10cSrcweir 			if( aTarget >>= aParaTarget )
307*cdf0e10cSrcweir 			{
308*cdf0e10cSrcweir 				xShape.set( aParaTarget.Shape, UNO_QUERY );
309*cdf0e10cSrcweir 				nOnlyPara = aParaTarget.Paragraph;
310*cdf0e10cSrcweir 			}
311*cdf0e10cSrcweir 		}
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir 		// now use the break iterator to iterate over the given text
314*cdf0e10cSrcweir 		// and count the sub items
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir 		if( xShape.is() )
317*cdf0e10cSrcweir 		{
318*cdf0e10cSrcweir 			// TODO/LATER: Optimize this, don't create a break iterator each time
319*cdf0e10cSrcweir 			Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() );
320*cdf0e10cSrcweir 			Reference < i18n::XBreakIterator > xBI( xMSF->createInstance( OUString::createFromAscii( "com.sun.star.i18n.BreakIterator" ) ), UNO_QUERY );
321*cdf0e10cSrcweir 			DBG_ASSERT( xBI.is(), "sd::CustomAnimationEffect::getNumberOfSubitems(), could not create a 'com.sun.star.i18n.BreakIterator'!" );
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir 			if( xBI.is() )
324*cdf0e10cSrcweir 			{
325*cdf0e10cSrcweir 				Reference< XEnumerationAccess > xEA( xShape, UNO_QUERY_THROW );
326*cdf0e10cSrcweir 				Reference< XEnumeration > xEnumeration( xEA->createEnumeration(), UNO_QUERY_THROW );
327*cdf0e10cSrcweir 				Locale aLocale;
328*cdf0e10cSrcweir 				const OUString aStrLocaleName( RTL_CONSTASCII_USTRINGPARAM("CharLocale") );
329*cdf0e10cSrcweir 				Reference< XTextRange > xParagraph;
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 				sal_Int32 nPara = 0;
332*cdf0e10cSrcweir 				while( xEnumeration->hasMoreElements() )
333*cdf0e10cSrcweir 				{
334*cdf0e10cSrcweir 					xEnumeration->nextElement() >>= xParagraph;
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir 					// skip this if its not the only paragraph we want to count
337*cdf0e10cSrcweir 					if( (nOnlyPara != -1) && (nOnlyPara != nPara ) )
338*cdf0e10cSrcweir 						continue;
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir 					if( nIterateType == TextAnimationType::BY_PARAGRAPH )
341*cdf0e10cSrcweir 					{
342*cdf0e10cSrcweir 						nSubItems++;
343*cdf0e10cSrcweir 					}
344*cdf0e10cSrcweir 					else
345*cdf0e10cSrcweir 					{
346*cdf0e10cSrcweir 						const OUString aText( xParagraph->getString() );
347*cdf0e10cSrcweir 						Reference< XPropertySet > xSet( xParagraph, UNO_QUERY_THROW );
348*cdf0e10cSrcweir 						xSet->getPropertyValue( aStrLocaleName ) >>= aLocale;
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir 						sal_Int32 nPos;
351*cdf0e10cSrcweir 						const sal_Int32 nEndPos = aText.getLength();
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir 						if( nIterateType == TextAnimationType::BY_WORD )
354*cdf0e10cSrcweir 						{
355*cdf0e10cSrcweir 							for( nPos = 0; nPos < nEndPos; nPos++ )
356*cdf0e10cSrcweir 							{
357*cdf0e10cSrcweir 								nPos = xBI->getWordBoundary(aText, nPos, aLocale, i18n::WordType::ANY_WORD, sal_True).endPos;
358*cdf0e10cSrcweir 								nSubItems++;
359*cdf0e10cSrcweir 							}
360*cdf0e10cSrcweir 							break;
361*cdf0e10cSrcweir 						}
362*cdf0e10cSrcweir 						else
363*cdf0e10cSrcweir 						{
364*cdf0e10cSrcweir 							sal_Int32 nDone;
365*cdf0e10cSrcweir 							for( nPos = 0; nPos < nEndPos; nPos++ )
366*cdf0e10cSrcweir 							{
367*cdf0e10cSrcweir 								nPos = xBI->nextCharacters(aText, nPos, aLocale, i18n::CharacterIteratorMode::SKIPCELL, 0, nDone);
368*cdf0e10cSrcweir 								nSubItems++;
369*cdf0e10cSrcweir 							}
370*cdf0e10cSrcweir 						}
371*cdf0e10cSrcweir 					}
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir 					if( nPara == nOnlyPara )
374*cdf0e10cSrcweir 						break;
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir 					nPara++;
377*cdf0e10cSrcweir 				}
378*cdf0e10cSrcweir 			}
379*cdf0e10cSrcweir 		}
380*cdf0e10cSrcweir 	}
381*cdf0e10cSrcweir 	catch( Exception& e )
382*cdf0e10cSrcweir 	{
383*cdf0e10cSrcweir 		(void)e;
384*cdf0e10cSrcweir 		nSubItems = 0;
385*cdf0e10cSrcweir 		DBG_ERROR( "sd::CustomAnimationEffect::getNumberOfSubitems(), exception cought!" );
386*cdf0e10cSrcweir 	}
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir 	return nSubItems;
389*cdf0e10cSrcweir }
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir // --------------------------------------------------------------------
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir CustomAnimationEffect::~CustomAnimationEffect()
394*cdf0e10cSrcweir {
395*cdf0e10cSrcweir }
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir // --------------------------------------------------------------------
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir CustomAnimationEffectPtr CustomAnimationEffect::clone() const
400*cdf0e10cSrcweir {
401*cdf0e10cSrcweir 	Reference< XCloneable > xCloneable( mxNode, UNO_QUERY_THROW );
402*cdf0e10cSrcweir 	Reference< XAnimationNode > xNode( xCloneable->createClone(), UNO_QUERY_THROW );
403*cdf0e10cSrcweir 	CustomAnimationEffectPtr pEffect( new CustomAnimationEffect( xNode ) );
404*cdf0e10cSrcweir 	pEffect->setEffectSequence( getEffectSequence() );
405*cdf0e10cSrcweir 	return pEffect;
406*cdf0e10cSrcweir }
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir // --------------------------------------------------------------------
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir sal_Int32 CustomAnimationEffect::get_node_type( const Reference< XAnimationNode >& xNode )
411*cdf0e10cSrcweir {
412*cdf0e10cSrcweir 	sal_Int16 nNodeType = -1;
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir 	if( xNode.is() )
415*cdf0e10cSrcweir 	{
416*cdf0e10cSrcweir 		Sequence< NamedValue > aUserData( xNode->getUserData() );
417*cdf0e10cSrcweir 		sal_Int32 nLength = aUserData.getLength();
418*cdf0e10cSrcweir 		if( nLength )
419*cdf0e10cSrcweir 		{
420*cdf0e10cSrcweir 			const NamedValue* p = aUserData.getConstArray();
421*cdf0e10cSrcweir 			while( nLength-- )
422*cdf0e10cSrcweir 			{
423*cdf0e10cSrcweir 				if( p->Name.equalsAscii( "node-type" ) )
424*cdf0e10cSrcweir 				{
425*cdf0e10cSrcweir 					p->Value >>= nNodeType;
426*cdf0e10cSrcweir 					break;
427*cdf0e10cSrcweir 				}
428*cdf0e10cSrcweir 				p++;
429*cdf0e10cSrcweir 			}
430*cdf0e10cSrcweir 		}
431*cdf0e10cSrcweir 	}
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir 	return nNodeType;
434*cdf0e10cSrcweir }
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir // --------------------------------------------------------------------
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir void CustomAnimationEffect::setPresetClass( sal_Int16 nPresetClass )
439*cdf0e10cSrcweir {
440*cdf0e10cSrcweir 	if( mnPresetClass != nPresetClass )
441*cdf0e10cSrcweir 	{
442*cdf0e10cSrcweir 		mnPresetClass = nPresetClass;
443*cdf0e10cSrcweir 		if( mxNode.is() )
444*cdf0e10cSrcweir 		{
445*cdf0e10cSrcweir 			// first try to find a "preset-class" entry in the user data
446*cdf0e10cSrcweir 			// and change it
447*cdf0e10cSrcweir 			Sequence< NamedValue > aUserData( mxNode->getUserData() );
448*cdf0e10cSrcweir 			sal_Int32 nLength = aUserData.getLength();
449*cdf0e10cSrcweir 			bool bFound = false;
450*cdf0e10cSrcweir 			if( nLength )
451*cdf0e10cSrcweir 			{
452*cdf0e10cSrcweir 				NamedValue* p = aUserData.getArray();
453*cdf0e10cSrcweir 				while( nLength-- )
454*cdf0e10cSrcweir 				{
455*cdf0e10cSrcweir 					if( p->Name.equalsAscii( "preset-class" ) )
456*cdf0e10cSrcweir 					{
457*cdf0e10cSrcweir 						p->Value <<= mnPresetClass;
458*cdf0e10cSrcweir 						bFound = true;
459*cdf0e10cSrcweir 						break;
460*cdf0e10cSrcweir 					}
461*cdf0e10cSrcweir 					p++;
462*cdf0e10cSrcweir 				}
463*cdf0e10cSrcweir 			}
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir 			// no "node-type" entry inside user data, so add it
466*cdf0e10cSrcweir 			if( !bFound )
467*cdf0e10cSrcweir 			{
468*cdf0e10cSrcweir 				nLength = aUserData.getLength();
469*cdf0e10cSrcweir 				aUserData.realloc( nLength + 1);
470*cdf0e10cSrcweir 				aUserData[nLength].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "preset-class" ) );
471*cdf0e10cSrcweir 				aUserData[nLength].Value <<= mnPresetClass;
472*cdf0e10cSrcweir 			}
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir 			mxNode->setUserData( aUserData );
475*cdf0e10cSrcweir 		}
476*cdf0e10cSrcweir 	}
477*cdf0e10cSrcweir }
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir void CustomAnimationEffect::setNodeType( sal_Int16 nNodeType )
480*cdf0e10cSrcweir {
481*cdf0e10cSrcweir 	if( mnNodeType != nNodeType )
482*cdf0e10cSrcweir 	{
483*cdf0e10cSrcweir 		mnNodeType = nNodeType;
484*cdf0e10cSrcweir 		if( mxNode.is() )
485*cdf0e10cSrcweir 		{
486*cdf0e10cSrcweir 			// first try to find a "node-type" entry in the user data
487*cdf0e10cSrcweir 			// and change it
488*cdf0e10cSrcweir 			Sequence< NamedValue > aUserData( mxNode->getUserData() );
489*cdf0e10cSrcweir 			sal_Int32 nLength = aUserData.getLength();
490*cdf0e10cSrcweir 			bool bFound = false;
491*cdf0e10cSrcweir 			if( nLength )
492*cdf0e10cSrcweir 			{
493*cdf0e10cSrcweir 				NamedValue* p = aUserData.getArray();
494*cdf0e10cSrcweir 				while( nLength-- )
495*cdf0e10cSrcweir 				{
496*cdf0e10cSrcweir 					if( p->Name.equalsAscii( "node-type" ) )
497*cdf0e10cSrcweir 					{
498*cdf0e10cSrcweir 						p->Value <<= mnNodeType;
499*cdf0e10cSrcweir 						bFound = true;
500*cdf0e10cSrcweir 						break;
501*cdf0e10cSrcweir 					}
502*cdf0e10cSrcweir 					p++;
503*cdf0e10cSrcweir 				}
504*cdf0e10cSrcweir 			}
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir 			// no "node-type" entry inside user data, so add it
507*cdf0e10cSrcweir 			if( !bFound )
508*cdf0e10cSrcweir 			{
509*cdf0e10cSrcweir 				nLength = aUserData.getLength();
510*cdf0e10cSrcweir 				aUserData.realloc( nLength + 1);
511*cdf0e10cSrcweir 				aUserData[nLength].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "node-type" ) );
512*cdf0e10cSrcweir 				aUserData[nLength].Value <<= mnNodeType;
513*cdf0e10cSrcweir 			}
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir 			mxNode->setUserData( aUserData );
516*cdf0e10cSrcweir 		}
517*cdf0e10cSrcweir 	}
518*cdf0e10cSrcweir }
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir // --------------------------------------------------------------------
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir void CustomAnimationEffect::setGroupId( sal_Int32 nGroupId )
523*cdf0e10cSrcweir {
524*cdf0e10cSrcweir 	mnGroupId = nGroupId;
525*cdf0e10cSrcweir 	if( mxNode.is() )
526*cdf0e10cSrcweir 	{
527*cdf0e10cSrcweir 		// first try to find a "group-id" entry in the user data
528*cdf0e10cSrcweir 		// and change it
529*cdf0e10cSrcweir 		Sequence< NamedValue > aUserData( mxNode->getUserData() );
530*cdf0e10cSrcweir 		sal_Int32 nLength = aUserData.getLength();
531*cdf0e10cSrcweir 		bool bFound = false;
532*cdf0e10cSrcweir 		if( nLength )
533*cdf0e10cSrcweir 		{
534*cdf0e10cSrcweir 			NamedValue* p = aUserData.getArray();
535*cdf0e10cSrcweir 			while( nLength-- )
536*cdf0e10cSrcweir 			{
537*cdf0e10cSrcweir 				if( p->Name.equalsAscii( "group-id" ) )
538*cdf0e10cSrcweir 				{
539*cdf0e10cSrcweir 					p->Value <<= mnGroupId;
540*cdf0e10cSrcweir 					bFound = true;
541*cdf0e10cSrcweir 					break;
542*cdf0e10cSrcweir 				}
543*cdf0e10cSrcweir 				p++;
544*cdf0e10cSrcweir 			}
545*cdf0e10cSrcweir 		}
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir 		// no "node-type" entry inside user data, so add it
548*cdf0e10cSrcweir 		if( !bFound )
549*cdf0e10cSrcweir 		{
550*cdf0e10cSrcweir 			nLength = aUserData.getLength();
551*cdf0e10cSrcweir 			aUserData.realloc( nLength + 1);
552*cdf0e10cSrcweir 			aUserData[nLength].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "group-id" ) );
553*cdf0e10cSrcweir 			aUserData[nLength].Value <<= mnGroupId;
554*cdf0e10cSrcweir 		}
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir 		mxNode->setUserData( aUserData );
557*cdf0e10cSrcweir 	}
558*cdf0e10cSrcweir }
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir // --------------------------------------------------------------------
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir /** checks if the text for this effect has changed and updates internal flags.
563*cdf0e10cSrcweir 	returns true if something changed.
564*cdf0e10cSrcweir */
565*cdf0e10cSrcweir bool CustomAnimationEffect::checkForText()
566*cdf0e10cSrcweir {
567*cdf0e10cSrcweir 	bool bChange = false;
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir 	Reference< XText > xText;
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir 	if( maTarget.getValueType() == ::getCppuType((const ParagraphTarget*)0) )
572*cdf0e10cSrcweir 	{
573*cdf0e10cSrcweir 		// calc para depth
574*cdf0e10cSrcweir 		ParagraphTarget aParaTarget;
575*cdf0e10cSrcweir 		maTarget >>= aParaTarget;
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir 		xText = Reference< XText >::query( aParaTarget.Shape );
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir 		// get paragraph
580*cdf0e10cSrcweir 		if( xText.is() )
581*cdf0e10cSrcweir 		{
582*cdf0e10cSrcweir 			Reference< XEnumerationAccess > xEA( xText, UNO_QUERY );
583*cdf0e10cSrcweir 			if( xEA.is() )
584*cdf0e10cSrcweir 			{
585*cdf0e10cSrcweir 				Reference< XEnumeration > xEnumeration( xEA->createEnumeration(), UNO_QUERY );
586*cdf0e10cSrcweir 				if( xEnumeration.is() )
587*cdf0e10cSrcweir 				{
588*cdf0e10cSrcweir 					sal_Bool bHasText = xEnumeration->hasMoreElements();
589*cdf0e10cSrcweir 					bChange |= bHasText != mbHasText;
590*cdf0e10cSrcweir 					mbHasText = bHasText;
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir 					sal_Int32 nPara = aParaTarget.Paragraph;
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir 					while( xEnumeration->hasMoreElements() && nPara-- )
595*cdf0e10cSrcweir 						xEnumeration->nextElement();
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir 					if( xEnumeration->hasMoreElements() )
598*cdf0e10cSrcweir 					{
599*cdf0e10cSrcweir 						Reference< XPropertySet > xParaSet;
600*cdf0e10cSrcweir 						xEnumeration->nextElement() >>= xParaSet;
601*cdf0e10cSrcweir 						if( xParaSet.is() )
602*cdf0e10cSrcweir 						{
603*cdf0e10cSrcweir 							sal_Int32 nParaDepth = 0;
604*cdf0e10cSrcweir 							const OUString strNumberingLevel( RTL_CONSTASCII_USTRINGPARAM("NumberingLevel") );
605*cdf0e10cSrcweir 							xParaSet->getPropertyValue( strNumberingLevel ) >>= nParaDepth;
606*cdf0e10cSrcweir 							bChange |= nParaDepth != mnParaDepth;
607*cdf0e10cSrcweir 							mnParaDepth = nParaDepth;
608*cdf0e10cSrcweir 						}
609*cdf0e10cSrcweir 					}
610*cdf0e10cSrcweir 				}
611*cdf0e10cSrcweir 			}
612*cdf0e10cSrcweir 		}
613*cdf0e10cSrcweir 	}
614*cdf0e10cSrcweir 	else
615*cdf0e10cSrcweir 	{
616*cdf0e10cSrcweir 		maTarget >>= xText;
617*cdf0e10cSrcweir 		sal_Bool bHasText = xText.is() && xText->getString().getLength();
618*cdf0e10cSrcweir 		bChange |= bHasText != mbHasText;
619*cdf0e10cSrcweir 		mbHasText = bHasText;
620*cdf0e10cSrcweir 	}
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir 	bChange |= calculateIterateDuration();
623*cdf0e10cSrcweir 	return bChange;
624*cdf0e10cSrcweir }
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir bool CustomAnimationEffect::calculateIterateDuration()
627*cdf0e10cSrcweir {
628*cdf0e10cSrcweir 	bool bChange = false;
629*cdf0e10cSrcweir 
630*cdf0e10cSrcweir 	// if we have an iteration, we must also calculate the
631*cdf0e10cSrcweir 	// 'true' container duration, that is
632*cdf0e10cSrcweir 	// ( ( is form animated ) ? [contained effects duration] : 0 ) +
633*cdf0e10cSrcweir 	// ( [number of animated children] - 1 ) * [interval-delay] + [contained effects duration]
634*cdf0e10cSrcweir 	Reference< XIterateContainer > xIter( mxNode, UNO_QUERY );
635*cdf0e10cSrcweir 	if( xIter.is() )
636*cdf0e10cSrcweir 	{
637*cdf0e10cSrcweir 		double fDuration = mfDuration;
638*cdf0e10cSrcweir 		const double fSubEffectDuration = mfDuration;
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir 		if( mnTargetSubItem != ShapeAnimationSubType::ONLY_BACKGROUND ) // does not make sense for iterate container but better check
641*cdf0e10cSrcweir 		{
642*cdf0e10cSrcweir 			const sal_Int32 nSubItems = getNumberOfSubitems( maTarget, mnIterateType );
643*cdf0e10cSrcweir 			if( nSubItems )
644*cdf0e10cSrcweir 			{
645*cdf0e10cSrcweir 				const double f = (nSubItems-1) * mfIterateInterval;
646*cdf0e10cSrcweir 				fDuration += f;
647*cdf0e10cSrcweir 			}
648*cdf0e10cSrcweir 		}
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir 		// if we also animate the form first, we have to add the
651*cdf0e10cSrcweir 		// sub effect duration to the whole effect duration
652*cdf0e10cSrcweir 		if( mnTargetSubItem == ShapeAnimationSubType::AS_WHOLE )
653*cdf0e10cSrcweir 			fDuration += fSubEffectDuration;
654*cdf0e10cSrcweir 
655*cdf0e10cSrcweir 		bChange |= fDuration != mfAbsoluteDuration;
656*cdf0e10cSrcweir 		mfAbsoluteDuration = fDuration;
657*cdf0e10cSrcweir 	}
658*cdf0e10cSrcweir 
659*cdf0e10cSrcweir 	return bChange;
660*cdf0e10cSrcweir }
661*cdf0e10cSrcweir 
662*cdf0e10cSrcweir // --------------------------------------------------------------------
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir void CustomAnimationEffect::setTarget( const ::com::sun::star::uno::Any& rTarget )
665*cdf0e10cSrcweir {
666*cdf0e10cSrcweir 	try
667*cdf0e10cSrcweir 	{
668*cdf0e10cSrcweir 		maTarget = rTarget;
669*cdf0e10cSrcweir 
670*cdf0e10cSrcweir 		// first, check special case for random node
671*cdf0e10cSrcweir 		Reference< XInitialization > xInit( mxNode, UNO_QUERY );
672*cdf0e10cSrcweir 		if( xInit.is() )
673*cdf0e10cSrcweir 		{
674*cdf0e10cSrcweir 			const Sequence< Any > aArgs( &maTarget, 1 );
675*cdf0e10cSrcweir 			xInit->initialize( aArgs );
676*cdf0e10cSrcweir 		}
677*cdf0e10cSrcweir 		else
678*cdf0e10cSrcweir 		{
679*cdf0e10cSrcweir 			Reference< XIterateContainer > xIter( mxNode, UNO_QUERY );
680*cdf0e10cSrcweir 			if( xIter.is() )
681*cdf0e10cSrcweir 			{
682*cdf0e10cSrcweir 				xIter->setTarget(maTarget);
683*cdf0e10cSrcweir 			}
684*cdf0e10cSrcweir 			else
685*cdf0e10cSrcweir 			{
686*cdf0e10cSrcweir 				Reference< XEnumerationAccess > xEnumerationAccess( mxNode, UNO_QUERY );
687*cdf0e10cSrcweir 				if( xEnumerationAccess.is() )
688*cdf0e10cSrcweir 				{
689*cdf0e10cSrcweir 					Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY );
690*cdf0e10cSrcweir 					if( xEnumeration.is() )
691*cdf0e10cSrcweir 					{
692*cdf0e10cSrcweir 						while( xEnumeration->hasMoreElements() )
693*cdf0e10cSrcweir 						{
694*cdf0e10cSrcweir 							const Any aElem( xEnumeration->nextElement() );
695*cdf0e10cSrcweir 							Reference< XAnimate > xAnimate( aElem, UNO_QUERY );
696*cdf0e10cSrcweir 							if( xAnimate.is() )
697*cdf0e10cSrcweir 								xAnimate->setTarget( rTarget );
698*cdf0e10cSrcweir                             else
699*cdf0e10cSrcweir                             {
700*cdf0e10cSrcweir                                 Reference< XCommand > xCommand( aElem, UNO_QUERY );
701*cdf0e10cSrcweir                                 if( xCommand.is() )
702*cdf0e10cSrcweir                                     xCommand->setTarget( rTarget );
703*cdf0e10cSrcweir                             }
704*cdf0e10cSrcweir 						}
705*cdf0e10cSrcweir 					}
706*cdf0e10cSrcweir 				}
707*cdf0e10cSrcweir 			}
708*cdf0e10cSrcweir 		}
709*cdf0e10cSrcweir 		checkForText();
710*cdf0e10cSrcweir 	}
711*cdf0e10cSrcweir 	catch( Exception& )
712*cdf0e10cSrcweir 	{
713*cdf0e10cSrcweir 		DBG_ERROR( "sd::CustomAnimationEffect::setTarget(), exception cought!" );
714*cdf0e10cSrcweir 	}
715*cdf0e10cSrcweir }
716*cdf0e10cSrcweir 
717*cdf0e10cSrcweir // --------------------------------------------------------------------
718*cdf0e10cSrcweir 
719*cdf0e10cSrcweir void CustomAnimationEffect::setTargetSubItem( sal_Int16 nSubItem )
720*cdf0e10cSrcweir {
721*cdf0e10cSrcweir 	try
722*cdf0e10cSrcweir 	{
723*cdf0e10cSrcweir 		mnTargetSubItem = nSubItem;
724*cdf0e10cSrcweir 
725*cdf0e10cSrcweir 		Reference< XIterateContainer > xIter( mxNode, UNO_QUERY );
726*cdf0e10cSrcweir 		if( xIter.is() )
727*cdf0e10cSrcweir 		{
728*cdf0e10cSrcweir 			xIter->setSubItem(mnTargetSubItem);
729*cdf0e10cSrcweir 		}
730*cdf0e10cSrcweir 		else
731*cdf0e10cSrcweir 		{
732*cdf0e10cSrcweir 			Reference< XEnumerationAccess > xEnumerationAccess( mxNode, UNO_QUERY );
733*cdf0e10cSrcweir 			if( xEnumerationAccess.is() )
734*cdf0e10cSrcweir 			{
735*cdf0e10cSrcweir 				Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY );
736*cdf0e10cSrcweir 				if( xEnumeration.is() )
737*cdf0e10cSrcweir 				{
738*cdf0e10cSrcweir 					while( xEnumeration->hasMoreElements() )
739*cdf0e10cSrcweir 					{
740*cdf0e10cSrcweir 						Reference< XAnimate > xAnimate( xEnumeration->nextElement(), UNO_QUERY );
741*cdf0e10cSrcweir 						if( xAnimate.is() )
742*cdf0e10cSrcweir 							xAnimate->setSubItem( mnTargetSubItem );
743*cdf0e10cSrcweir 					}
744*cdf0e10cSrcweir 				}
745*cdf0e10cSrcweir 			}
746*cdf0e10cSrcweir 		}
747*cdf0e10cSrcweir 	}
748*cdf0e10cSrcweir 	catch( Exception& )
749*cdf0e10cSrcweir 	{
750*cdf0e10cSrcweir 		DBG_ERROR( "sd::CustomAnimationEffect::setTargetSubItem(), exception cought!" );
751*cdf0e10cSrcweir 	}
752*cdf0e10cSrcweir }
753*cdf0e10cSrcweir 
754*cdf0e10cSrcweir // --------------------------------------------------------------------
755*cdf0e10cSrcweir 
756*cdf0e10cSrcweir void CustomAnimationEffect::setDuration( double fDuration )
757*cdf0e10cSrcweir {
758*cdf0e10cSrcweir 	if( (mfDuration != -1.0) && (mfDuration != fDuration) ) try
759*cdf0e10cSrcweir 	{
760*cdf0e10cSrcweir 		double fScale = fDuration / mfDuration;
761*cdf0e10cSrcweir 		mfDuration = fDuration;
762*cdf0e10cSrcweir 		mfAbsoluteDuration = mfDuration;
763*cdf0e10cSrcweir 
764*cdf0e10cSrcweir 		// calculate effect duration and get target shape
765*cdf0e10cSrcweir 		Reference< XEnumerationAccess > xEnumerationAccess( mxNode, UNO_QUERY );
766*cdf0e10cSrcweir 		if( xEnumerationAccess.is() )
767*cdf0e10cSrcweir 		{
768*cdf0e10cSrcweir 			Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY );
769*cdf0e10cSrcweir 			if( xEnumeration.is() )
770*cdf0e10cSrcweir 			{
771*cdf0e10cSrcweir 				while( xEnumeration->hasMoreElements() )
772*cdf0e10cSrcweir 				{
773*cdf0e10cSrcweir 					Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY );
774*cdf0e10cSrcweir 					if( !xChildNode.is() )
775*cdf0e10cSrcweir 						continue;
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir 
778*cdf0e10cSrcweir 					double fChildBegin = 0.0;
779*cdf0e10cSrcweir 					xChildNode->getBegin() >>= fChildBegin;
780*cdf0e10cSrcweir 					if(  fChildBegin != 0.0 )
781*cdf0e10cSrcweir 					{
782*cdf0e10cSrcweir 						fChildBegin *= fScale;
783*cdf0e10cSrcweir 						xChildNode->setBegin( makeAny( fChildBegin ) );
784*cdf0e10cSrcweir 					}
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir 					double fChildDuration = 0.0;
787*cdf0e10cSrcweir 					xChildNode->getDuration() >>= fChildDuration;
788*cdf0e10cSrcweir 					if( fChildDuration != 0.0 )
789*cdf0e10cSrcweir 					{
790*cdf0e10cSrcweir 						fChildDuration *= fScale;
791*cdf0e10cSrcweir 						xChildNode->setDuration( makeAny( fChildDuration ) );
792*cdf0e10cSrcweir 					}
793*cdf0e10cSrcweir 				}
794*cdf0e10cSrcweir 			}
795*cdf0e10cSrcweir 		}
796*cdf0e10cSrcweir 		calculateIterateDuration();
797*cdf0e10cSrcweir 	}
798*cdf0e10cSrcweir 	catch( Exception& )
799*cdf0e10cSrcweir 	{
800*cdf0e10cSrcweir 		DBG_ERROR( "sd::CustomAnimationEffect::setDuration(), exception cought!" );
801*cdf0e10cSrcweir 	}
802*cdf0e10cSrcweir }
803*cdf0e10cSrcweir 
804*cdf0e10cSrcweir // --------------------------------------------------------------------
805*cdf0e10cSrcweir 
806*cdf0e10cSrcweir void CustomAnimationEffect::setBegin( double fBegin )
807*cdf0e10cSrcweir {
808*cdf0e10cSrcweir 	if( mxNode.is() ) try
809*cdf0e10cSrcweir 	{
810*cdf0e10cSrcweir 		mfBegin = fBegin;
811*cdf0e10cSrcweir 		mxNode->setBegin( makeAny( fBegin ) );
812*cdf0e10cSrcweir 	}
813*cdf0e10cSrcweir 	catch( Exception& )
814*cdf0e10cSrcweir 	{
815*cdf0e10cSrcweir 		DBG_ERROR( "sd::CustomAnimationEffect::setBegin(), exception cought!" );
816*cdf0e10cSrcweir 	}
817*cdf0e10cSrcweir }
818*cdf0e10cSrcweir 
819*cdf0e10cSrcweir // --------------------------------------------------------------------
820*cdf0e10cSrcweir 
821*cdf0e10cSrcweir void CustomAnimationEffect::setAcceleration( double fAcceleration )
822*cdf0e10cSrcweir {
823*cdf0e10cSrcweir 	if( mxNode.is() ) try
824*cdf0e10cSrcweir 	{
825*cdf0e10cSrcweir 		mfAcceleration = fAcceleration;
826*cdf0e10cSrcweir 		mxNode->setAcceleration( fAcceleration );
827*cdf0e10cSrcweir 	}
828*cdf0e10cSrcweir 	catch( Exception& )
829*cdf0e10cSrcweir 	{
830*cdf0e10cSrcweir 		DBG_ERROR( "sd::CustomAnimationEffect::setAcceleration(), exception cought!" );
831*cdf0e10cSrcweir 	}
832*cdf0e10cSrcweir }
833*cdf0e10cSrcweir // --------------------------------------------------------------------
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir void CustomAnimationEffect::setDecelerate( double fDecelerate )
836*cdf0e10cSrcweir {
837*cdf0e10cSrcweir 	if( mxNode.is() ) try
838*cdf0e10cSrcweir 	{
839*cdf0e10cSrcweir 		mfDecelerate = fDecelerate;
840*cdf0e10cSrcweir 		mxNode->setDecelerate( fDecelerate );
841*cdf0e10cSrcweir 	}
842*cdf0e10cSrcweir 	catch( Exception& )
843*cdf0e10cSrcweir 	{
844*cdf0e10cSrcweir 		DBG_ERROR( "sd::CustomAnimationEffect::setDecelerate(), exception cought!" );
845*cdf0e10cSrcweir 	}
846*cdf0e10cSrcweir }
847*cdf0e10cSrcweir 
848*cdf0e10cSrcweir // --------------------------------------------------------------------
849*cdf0e10cSrcweir 
850*cdf0e10cSrcweir void CustomAnimationEffect::setAutoReverse( sal_Bool bAutoReverse )
851*cdf0e10cSrcweir {
852*cdf0e10cSrcweir 	if( mxNode.is() ) try
853*cdf0e10cSrcweir 	{
854*cdf0e10cSrcweir 		mbAutoReverse = bAutoReverse;
855*cdf0e10cSrcweir 		mxNode->setAutoReverse( bAutoReverse );
856*cdf0e10cSrcweir 	}
857*cdf0e10cSrcweir 	catch( Exception& )
858*cdf0e10cSrcweir 	{
859*cdf0e10cSrcweir 		DBG_ERROR( "sd::CustomAnimationEffect::setAutoReverse(), exception cought!" );
860*cdf0e10cSrcweir 	}
861*cdf0e10cSrcweir }
862*cdf0e10cSrcweir 
863*cdf0e10cSrcweir // --------------------------------------------------------------------
864*cdf0e10cSrcweir 
865*cdf0e10cSrcweir void CustomAnimationEffect::replaceNode( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode )
866*cdf0e10cSrcweir {
867*cdf0e10cSrcweir 	sal_Int16 nNodeType = mnNodeType;
868*cdf0e10cSrcweir 	Any aTarget = maTarget;
869*cdf0e10cSrcweir 
870*cdf0e10cSrcweir 	double fBegin = mfBegin;
871*cdf0e10cSrcweir 	double fDuration = mfDuration;
872*cdf0e10cSrcweir 	double fAcceleration = mfAcceleration;
873*cdf0e10cSrcweir 	double fDecelerate = mfDecelerate ;
874*cdf0e10cSrcweir 	sal_Bool bAutoReverse = mbAutoReverse;
875*cdf0e10cSrcweir 	Reference< XAudio > xAudio( mxAudio );
876*cdf0e10cSrcweir 	sal_Int16 nIterateType = mnIterateType;
877*cdf0e10cSrcweir 	double fIterateInterval = mfIterateInterval;
878*cdf0e10cSrcweir 	sal_Int16 nSubItem = mnTargetSubItem;
879*cdf0e10cSrcweir 
880*cdf0e10cSrcweir 	setNode( xNode );
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir 	setAudio( xAudio );
883*cdf0e10cSrcweir 	setNodeType( nNodeType );
884*cdf0e10cSrcweir 	setTarget( aTarget );
885*cdf0e10cSrcweir 	setTargetSubItem( nSubItem );
886*cdf0e10cSrcweir 	setDuration( fDuration );
887*cdf0e10cSrcweir 	setBegin( fBegin );
888*cdf0e10cSrcweir 
889*cdf0e10cSrcweir 	setAcceleration( fAcceleration );
890*cdf0e10cSrcweir 	setDecelerate( fDecelerate );
891*cdf0e10cSrcweir 	setAutoReverse( bAutoReverse );
892*cdf0e10cSrcweir 
893*cdf0e10cSrcweir 	if( nIterateType != mnIterateType )
894*cdf0e10cSrcweir 		setIterateType( nIterateType );
895*cdf0e10cSrcweir 
896*cdf0e10cSrcweir 	if( mnIterateType && ( fIterateInterval != mfIterateInterval ) )
897*cdf0e10cSrcweir 		setIterateInterval( fIterateInterval );
898*cdf0e10cSrcweir }
899*cdf0e10cSrcweir 
900*cdf0e10cSrcweir // --------------------------------------------------------------------
901*cdf0e10cSrcweir 
902*cdf0e10cSrcweir Reference< XShape > CustomAnimationEffect::getTargetShape() const
903*cdf0e10cSrcweir {
904*cdf0e10cSrcweir 	Reference< XShape > xShape;
905*cdf0e10cSrcweir 	maTarget >>= xShape;
906*cdf0e10cSrcweir 	if( !xShape.is() )
907*cdf0e10cSrcweir 	{
908*cdf0e10cSrcweir 		ParagraphTarget aParaTarget;
909*cdf0e10cSrcweir 		if( maTarget >>= aParaTarget )
910*cdf0e10cSrcweir 			xShape = aParaTarget.Shape;
911*cdf0e10cSrcweir 	}
912*cdf0e10cSrcweir 
913*cdf0e10cSrcweir 	return xShape;
914*cdf0e10cSrcweir }
915*cdf0e10cSrcweir 
916*cdf0e10cSrcweir // --------------------------------------------------------------------
917*cdf0e10cSrcweir 
918*cdf0e10cSrcweir Any	CustomAnimationEffect::getRepeatCount() const
919*cdf0e10cSrcweir {
920*cdf0e10cSrcweir 	if( mxNode.is() )
921*cdf0e10cSrcweir 	{
922*cdf0e10cSrcweir 		return mxNode->getRepeatCount();
923*cdf0e10cSrcweir 	}
924*cdf0e10cSrcweir 	else
925*cdf0e10cSrcweir 	{
926*cdf0e10cSrcweir 		Any aAny;
927*cdf0e10cSrcweir 		return aAny;
928*cdf0e10cSrcweir 	}
929*cdf0e10cSrcweir }
930*cdf0e10cSrcweir 
931*cdf0e10cSrcweir // --------------------------------------------------------------------
932*cdf0e10cSrcweir 
933*cdf0e10cSrcweir Any	CustomAnimationEffect::getEnd() const
934*cdf0e10cSrcweir {
935*cdf0e10cSrcweir 	if( mxNode.is() )
936*cdf0e10cSrcweir 	{
937*cdf0e10cSrcweir 		return mxNode->getEnd();
938*cdf0e10cSrcweir 	}
939*cdf0e10cSrcweir 	else
940*cdf0e10cSrcweir 	{
941*cdf0e10cSrcweir 		Any aAny;
942*cdf0e10cSrcweir 		return aAny;
943*cdf0e10cSrcweir 	}
944*cdf0e10cSrcweir }
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir // --------------------------------------------------------------------
947*cdf0e10cSrcweir 
948*cdf0e10cSrcweir sal_Int16 CustomAnimationEffect::getFill() const
949*cdf0e10cSrcweir {
950*cdf0e10cSrcweir 	if( mxNode.is() )
951*cdf0e10cSrcweir 		return mxNode->getFill();
952*cdf0e10cSrcweir 	else
953*cdf0e10cSrcweir 		return 0;
954*cdf0e10cSrcweir }
955*cdf0e10cSrcweir 
956*cdf0e10cSrcweir // --------------------------------------------------------------------
957*cdf0e10cSrcweir 
958*cdf0e10cSrcweir void CustomAnimationEffect::setRepeatCount( const Any& rRepeatCount )
959*cdf0e10cSrcweir {
960*cdf0e10cSrcweir 	if( mxNode.is() )
961*cdf0e10cSrcweir 		mxNode->setRepeatCount( rRepeatCount );
962*cdf0e10cSrcweir }
963*cdf0e10cSrcweir 
964*cdf0e10cSrcweir // --------------------------------------------------------------------
965*cdf0e10cSrcweir 
966*cdf0e10cSrcweir void CustomAnimationEffect::setEnd( const Any& rEnd )
967*cdf0e10cSrcweir {
968*cdf0e10cSrcweir 	if( mxNode.is() )
969*cdf0e10cSrcweir 		mxNode->setEnd( rEnd );
970*cdf0e10cSrcweir }
971*cdf0e10cSrcweir 
972*cdf0e10cSrcweir // --------------------------------------------------------------------
973*cdf0e10cSrcweir 
974*cdf0e10cSrcweir void CustomAnimationEffect::setFill( sal_Int16 nFill )
975*cdf0e10cSrcweir {
976*cdf0e10cSrcweir 	if( mxNode.is() )
977*cdf0e10cSrcweir 		mxNode->setFill( nFill );
978*cdf0e10cSrcweir }
979*cdf0e10cSrcweir 
980*cdf0e10cSrcweir // --------------------------------------------------------------------
981*cdf0e10cSrcweir 
982*cdf0e10cSrcweir Reference< XAnimationNode > CustomAnimationEffect::createAfterEffectNode() const throw (Exception)
983*cdf0e10cSrcweir {
984*cdf0e10cSrcweir 	DBG_ASSERT( mbHasAfterEffect, "sd::CustomAnimationEffect::createAfterEffectNode(), this node has no after effect!" );
985*cdf0e10cSrcweir 
986*cdf0e10cSrcweir 	Reference< XMultiServiceFactory > xMsf( ::comphelper::getProcessServiceFactory() );
987*cdf0e10cSrcweir 
988*cdf0e10cSrcweir 	const char* pServiceName = maDimColor.hasValue() ?
989*cdf0e10cSrcweir 		"com.sun.star.animations.AnimateColor" : "com.sun.star.animations.AnimateSet";
990*cdf0e10cSrcweir 
991*cdf0e10cSrcweir 	Reference< XAnimate > xAnimate( xMsf->createInstance(OUString::createFromAscii(pServiceName) ), UNO_QUERY_THROW );
992*cdf0e10cSrcweir 
993*cdf0e10cSrcweir 	Any aTo;
994*cdf0e10cSrcweir 	OUString aAttributeName;
995*cdf0e10cSrcweir 
996*cdf0e10cSrcweir 	if( maDimColor.hasValue() )
997*cdf0e10cSrcweir 	{
998*cdf0e10cSrcweir 		aTo = maDimColor;
999*cdf0e10cSrcweir 		aAttributeName = OUString( RTL_CONSTASCII_USTRINGPARAM( "DimColor" ) );
1000*cdf0e10cSrcweir 	}
1001*cdf0e10cSrcweir 	else
1002*cdf0e10cSrcweir 	{
1003*cdf0e10cSrcweir 		aTo = makeAny( (sal_Bool)sal_False );
1004*cdf0e10cSrcweir 		aAttributeName = OUString( RTL_CONSTASCII_USTRINGPARAM( "Visibility" ) );
1005*cdf0e10cSrcweir 	}
1006*cdf0e10cSrcweir 
1007*cdf0e10cSrcweir 	Any aBegin;
1008*cdf0e10cSrcweir 	if( !mbAfterEffectOnNextEffect ) // sameClick
1009*cdf0e10cSrcweir 	{
1010*cdf0e10cSrcweir 		Event aEvent;
1011*cdf0e10cSrcweir 
1012*cdf0e10cSrcweir 		aEvent.Source <<= getNode();
1013*cdf0e10cSrcweir 		aEvent.Trigger = EventTrigger::END_EVENT;
1014*cdf0e10cSrcweir 		aEvent.Repeat = 0;
1015*cdf0e10cSrcweir 
1016*cdf0e10cSrcweir 		aBegin <<= aEvent;
1017*cdf0e10cSrcweir 	}
1018*cdf0e10cSrcweir 	else
1019*cdf0e10cSrcweir 	{
1020*cdf0e10cSrcweir 		aBegin <<= (double)0.0;
1021*cdf0e10cSrcweir 	}
1022*cdf0e10cSrcweir 
1023*cdf0e10cSrcweir 	xAnimate->setBegin( aBegin );
1024*cdf0e10cSrcweir 	xAnimate->setTo( aTo );
1025*cdf0e10cSrcweir 	xAnimate->setAttributeName( aAttributeName );
1026*cdf0e10cSrcweir 
1027*cdf0e10cSrcweir 	xAnimate->setDuration( makeAny( (double)0.001 ) );
1028*cdf0e10cSrcweir 	xAnimate->setFill( AnimationFill::HOLD );
1029*cdf0e10cSrcweir 	xAnimate->setTarget( maTarget );
1030*cdf0e10cSrcweir 
1031*cdf0e10cSrcweir 	return Reference< XAnimationNode >( xAnimate, UNO_QUERY_THROW );
1032*cdf0e10cSrcweir }
1033*cdf0e10cSrcweir 
1034*cdf0e10cSrcweir // --------------------------------------------------------------------
1035*cdf0e10cSrcweir 
1036*cdf0e10cSrcweir void CustomAnimationEffect::setIterateType( sal_Int16 nIterateType )
1037*cdf0e10cSrcweir {
1038*cdf0e10cSrcweir 	if( mnIterateType != nIterateType ) try
1039*cdf0e10cSrcweir 	{
1040*cdf0e10cSrcweir 		// do we need to exchange the container node?
1041*cdf0e10cSrcweir 		if( (mnIterateType == 0) || (nIterateType == 0) )
1042*cdf0e10cSrcweir 		{
1043*cdf0e10cSrcweir 			sal_Int16 nTargetSubItem = mnTargetSubItem;
1044*cdf0e10cSrcweir 
1045*cdf0e10cSrcweir 			Reference< XMultiServiceFactory > xMsf( ::comphelper::getProcessServiceFactory() );
1046*cdf0e10cSrcweir 			const char * pServiceName =
1047*cdf0e10cSrcweir 				nIterateType ? "com.sun.star.animations.IterateContainer" : "com.sun.star.animations.ParallelTimeContainer";
1048*cdf0e10cSrcweir 			Reference< XTimeContainer > xNewContainer(
1049*cdf0e10cSrcweir 				xMsf->createInstance( OUString::createFromAscii(pServiceName) ), UNO_QUERY_THROW );
1050*cdf0e10cSrcweir 
1051*cdf0e10cSrcweir 			Reference< XTimeContainer > xOldContainer( mxNode, UNO_QUERY_THROW );
1052*cdf0e10cSrcweir 			Reference< XEnumerationAccess > xEnumerationAccess( mxNode, UNO_QUERY_THROW );
1053*cdf0e10cSrcweir 			Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
1054*cdf0e10cSrcweir 			while( xEnumeration->hasMoreElements() )
1055*cdf0e10cSrcweir 			{
1056*cdf0e10cSrcweir 				Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY_THROW );
1057*cdf0e10cSrcweir 				xOldContainer->removeChild( xChildNode );
1058*cdf0e10cSrcweir 				xNewContainer->appendChild( xChildNode );
1059*cdf0e10cSrcweir 			}
1060*cdf0e10cSrcweir 
1061*cdf0e10cSrcweir 			Reference< XAnimationNode > xNewNode( xNewContainer, UNO_QUERY_THROW );
1062*cdf0e10cSrcweir 
1063*cdf0e10cSrcweir 			xNewNode->setBegin( mxNode->getBegin() );
1064*cdf0e10cSrcweir 			xNewNode->setDuration( mxNode->getDuration() );
1065*cdf0e10cSrcweir 			xNewNode->setEnd( mxNode->getEnd() );
1066*cdf0e10cSrcweir 			xNewNode->setEndSync( mxNode->getEndSync() );
1067*cdf0e10cSrcweir 			xNewNode->setRepeatCount( mxNode->getRepeatCount() );
1068*cdf0e10cSrcweir 			xNewNode->setFill( mxNode->getFill() );
1069*cdf0e10cSrcweir 			xNewNode->setFillDefault( mxNode->getFillDefault() );
1070*cdf0e10cSrcweir 			xNewNode->setRestart( mxNode->getRestart() );
1071*cdf0e10cSrcweir 			xNewNode->setRestartDefault( mxNode->getRestartDefault() );
1072*cdf0e10cSrcweir 			xNewNode->setAcceleration( mxNode->getAcceleration() );
1073*cdf0e10cSrcweir 			xNewNode->setDecelerate( mxNode->getDecelerate() );
1074*cdf0e10cSrcweir 			xNewNode->setAutoReverse( mxNode->getAutoReverse() );
1075*cdf0e10cSrcweir 			xNewNode->setRepeatDuration( mxNode->getRepeatDuration() );
1076*cdf0e10cSrcweir 			xNewNode->setEndSync( mxNode->getEndSync() );
1077*cdf0e10cSrcweir 			xNewNode->setRepeatCount( mxNode->getRepeatCount() );
1078*cdf0e10cSrcweir 			xNewNode->setUserData( mxNode->getUserData() );
1079*cdf0e10cSrcweir 
1080*cdf0e10cSrcweir 			mxNode = xNewNode;
1081*cdf0e10cSrcweir 
1082*cdf0e10cSrcweir 			Any aTarget;
1083*cdf0e10cSrcweir 			if( nIterateType )
1084*cdf0e10cSrcweir 			{
1085*cdf0e10cSrcweir 				Reference< XIterateContainer > xIter( mxNode, UNO_QUERY_THROW );
1086*cdf0e10cSrcweir 				xIter->setTarget(maTarget);
1087*cdf0e10cSrcweir 				xIter->setSubItem( nTargetSubItem );
1088*cdf0e10cSrcweir 			}
1089*cdf0e10cSrcweir 			else
1090*cdf0e10cSrcweir 			{
1091*cdf0e10cSrcweir 				aTarget = maTarget;
1092*cdf0e10cSrcweir 			}
1093*cdf0e10cSrcweir 
1094*cdf0e10cSrcweir 			Reference< XEnumerationAccess > xEA( mxNode, UNO_QUERY_THROW );
1095*cdf0e10cSrcweir 			Reference< XEnumeration > xE( xEA->createEnumeration(), UNO_QUERY_THROW );
1096*cdf0e10cSrcweir 			while( xE->hasMoreElements() )
1097*cdf0e10cSrcweir 			{
1098*cdf0e10cSrcweir 				Reference< XAnimate > xAnimate( xE->nextElement(), UNO_QUERY );
1099*cdf0e10cSrcweir 				if( xAnimate.is() )
1100*cdf0e10cSrcweir 				{
1101*cdf0e10cSrcweir 					xAnimate->setTarget( aTarget );
1102*cdf0e10cSrcweir 					xAnimate->setSubItem( nTargetSubItem );
1103*cdf0e10cSrcweir 				}
1104*cdf0e10cSrcweir 			}
1105*cdf0e10cSrcweir 		}
1106*cdf0e10cSrcweir 
1107*cdf0e10cSrcweir 		mnIterateType = nIterateType;
1108*cdf0e10cSrcweir 
1109*cdf0e10cSrcweir 		// if we have an iteration container, we must set its type
1110*cdf0e10cSrcweir 		if( mnIterateType )
1111*cdf0e10cSrcweir 		{
1112*cdf0e10cSrcweir 			Reference< XIterateContainer > xIter( mxNode, UNO_QUERY_THROW );
1113*cdf0e10cSrcweir 			xIter->setIterateType( nIterateType );
1114*cdf0e10cSrcweir 		}
1115*cdf0e10cSrcweir 
1116*cdf0e10cSrcweir 		checkForText();
1117*cdf0e10cSrcweir 	}
1118*cdf0e10cSrcweir 	catch( Exception& e )
1119*cdf0e10cSrcweir 	{
1120*cdf0e10cSrcweir 		(void)e;
1121*cdf0e10cSrcweir 		DBG_ERROR( "sd::CustomAnimationEffect::setIterateType(), Exception cought!" );
1122*cdf0e10cSrcweir 	}
1123*cdf0e10cSrcweir }
1124*cdf0e10cSrcweir 
1125*cdf0e10cSrcweir // --------------------------------------------------------------------
1126*cdf0e10cSrcweir 
1127*cdf0e10cSrcweir void CustomAnimationEffect::setIterateInterval( double fIterateInterval )
1128*cdf0e10cSrcweir {
1129*cdf0e10cSrcweir 	if( mfIterateInterval != fIterateInterval )
1130*cdf0e10cSrcweir 	{
1131*cdf0e10cSrcweir 		Reference< XIterateContainer > xIter( mxNode, UNO_QUERY );
1132*cdf0e10cSrcweir 
1133*cdf0e10cSrcweir 		DBG_ASSERT( xIter.is(), "sd::CustomAnimationEffect::setIterateInterval(), not an iteration node" );
1134*cdf0e10cSrcweir 		if( xIter.is() )
1135*cdf0e10cSrcweir 		{
1136*cdf0e10cSrcweir 			mfIterateInterval = fIterateInterval;
1137*cdf0e10cSrcweir 			xIter->setIterateInterval( fIterateInterval );
1138*cdf0e10cSrcweir 		}
1139*cdf0e10cSrcweir 
1140*cdf0e10cSrcweir 		calculateIterateDuration();
1141*cdf0e10cSrcweir 	}
1142*cdf0e10cSrcweir }
1143*cdf0e10cSrcweir 
1144*cdf0e10cSrcweir // --------------------------------------------------------------------
1145*cdf0e10cSrcweir 
1146*cdf0e10cSrcweir ::rtl::OUString	CustomAnimationEffect::getPath() const
1147*cdf0e10cSrcweir {
1148*cdf0e10cSrcweir 	::rtl::OUString aPath;
1149*cdf0e10cSrcweir 
1150*cdf0e10cSrcweir 	if( mxNode.is() ) try
1151*cdf0e10cSrcweir 	{
1152*cdf0e10cSrcweir 		Reference< XEnumerationAccess > xEnumerationAccess( mxNode, UNO_QUERY_THROW );
1153*cdf0e10cSrcweir 		Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
1154*cdf0e10cSrcweir 		while( xEnumeration->hasMoreElements() )
1155*cdf0e10cSrcweir 		{
1156*cdf0e10cSrcweir 			Reference< XAnimateMotion > xMotion( xEnumeration->nextElement(), UNO_QUERY );
1157*cdf0e10cSrcweir 			if( xMotion.is() )
1158*cdf0e10cSrcweir 			{
1159*cdf0e10cSrcweir 				xMotion->getPath() >>= aPath;
1160*cdf0e10cSrcweir 				break;
1161*cdf0e10cSrcweir 			}
1162*cdf0e10cSrcweir 		}
1163*cdf0e10cSrcweir 	}
1164*cdf0e10cSrcweir 	catch( Exception& e )
1165*cdf0e10cSrcweir 	{
1166*cdf0e10cSrcweir 		(void)e;
1167*cdf0e10cSrcweir 		DBG_ERROR("sd::CustomAnimationEffect::getPath(), exception cought!" );
1168*cdf0e10cSrcweir 	}
1169*cdf0e10cSrcweir 
1170*cdf0e10cSrcweir 	return aPath;
1171*cdf0e10cSrcweir }
1172*cdf0e10cSrcweir 
1173*cdf0e10cSrcweir // --------------------------------------------------------------------
1174*cdf0e10cSrcweir 
1175*cdf0e10cSrcweir void CustomAnimationEffect::setPath( const ::rtl::OUString& rPath )
1176*cdf0e10cSrcweir {
1177*cdf0e10cSrcweir 	if( mxNode.is() ) try
1178*cdf0e10cSrcweir 	{
1179*cdf0e10cSrcweir 		Reference< XEnumerationAccess > xEnumerationAccess( mxNode, UNO_QUERY_THROW );
1180*cdf0e10cSrcweir 		Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
1181*cdf0e10cSrcweir 		while( xEnumeration->hasMoreElements() )
1182*cdf0e10cSrcweir 		{
1183*cdf0e10cSrcweir 			Reference< XAnimateMotion > xMotion( xEnumeration->nextElement(), UNO_QUERY );
1184*cdf0e10cSrcweir 			if( xMotion.is() )
1185*cdf0e10cSrcweir 			{
1186*cdf0e10cSrcweir 
1187*cdf0e10cSrcweir 				MainSequenceChangeGuard aGuard( mpEffectSequence );
1188*cdf0e10cSrcweir 				xMotion->setPath( Any( rPath ) );
1189*cdf0e10cSrcweir 				break;
1190*cdf0e10cSrcweir 			}
1191*cdf0e10cSrcweir 		}
1192*cdf0e10cSrcweir 	}
1193*cdf0e10cSrcweir 	catch( Exception& e )
1194*cdf0e10cSrcweir 	{
1195*cdf0e10cSrcweir 		(void)e;
1196*cdf0e10cSrcweir 		DBG_ERROR("sd::CustomAnimationEffect::setPath(), exception cought!" );
1197*cdf0e10cSrcweir 	}
1198*cdf0e10cSrcweir }
1199*cdf0e10cSrcweir 
1200*cdf0e10cSrcweir // --------------------------------------------------------------------
1201*cdf0e10cSrcweir 
1202*cdf0e10cSrcweir Any CustomAnimationEffect::getProperty( sal_Int32 nNodeType, const OUString& rAttributeName, EValue eValue )
1203*cdf0e10cSrcweir {
1204*cdf0e10cSrcweir 	Any aProperty;
1205*cdf0e10cSrcweir 	if( mxNode.is() ) try
1206*cdf0e10cSrcweir 	{
1207*cdf0e10cSrcweir 		Reference< XEnumerationAccess > xEnumerationAccess( mxNode, UNO_QUERY );
1208*cdf0e10cSrcweir 		if( xEnumerationAccess.is() )
1209*cdf0e10cSrcweir 		{
1210*cdf0e10cSrcweir 			Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY );
1211*cdf0e10cSrcweir 			if( xEnumeration.is() )
1212*cdf0e10cSrcweir 			{
1213*cdf0e10cSrcweir 				while( xEnumeration->hasMoreElements() && !aProperty.hasValue() )
1214*cdf0e10cSrcweir 				{
1215*cdf0e10cSrcweir 					Reference< XAnimate > xAnimate( xEnumeration->nextElement(), UNO_QUERY );
1216*cdf0e10cSrcweir 					if( !xAnimate.is() )
1217*cdf0e10cSrcweir 						continue;
1218*cdf0e10cSrcweir 
1219*cdf0e10cSrcweir 					if( xAnimate->getType() == nNodeType )
1220*cdf0e10cSrcweir 					{
1221*cdf0e10cSrcweir 						if( xAnimate->getAttributeName() == rAttributeName )
1222*cdf0e10cSrcweir 						{
1223*cdf0e10cSrcweir 							switch( eValue )
1224*cdf0e10cSrcweir 							{
1225*cdf0e10cSrcweir 							case VALUE_FROM: aProperty = xAnimate->getFrom(); break;
1226*cdf0e10cSrcweir 							case VALUE_TO:   aProperty = xAnimate->getTo(); break;
1227*cdf0e10cSrcweir 							case VALUE_BY:   aProperty = xAnimate->getBy(); break;
1228*cdf0e10cSrcweir 							case VALUE_FIRST:
1229*cdf0e10cSrcweir 							case VALUE_LAST:
1230*cdf0e10cSrcweir 								{
1231*cdf0e10cSrcweir 									Sequence<Any> aValues( xAnimate->getValues() );
1232*cdf0e10cSrcweir 									if( aValues.hasElements() )
1233*cdf0e10cSrcweir 										aProperty =  aValues[ eValue == VALUE_FIRST ? 0 : aValues.getLength() - 1 ];
1234*cdf0e10cSrcweir 								}
1235*cdf0e10cSrcweir 								break;
1236*cdf0e10cSrcweir 							}
1237*cdf0e10cSrcweir 						}
1238*cdf0e10cSrcweir 					}
1239*cdf0e10cSrcweir 				}
1240*cdf0e10cSrcweir 			}
1241*cdf0e10cSrcweir 		}
1242*cdf0e10cSrcweir 	}
1243*cdf0e10cSrcweir 	catch( Exception& e )
1244*cdf0e10cSrcweir 	{
1245*cdf0e10cSrcweir 		(void)e;
1246*cdf0e10cSrcweir 		DBG_ERROR("sd::CustomAnimationEffect::getProperty(), exception cought!" );
1247*cdf0e10cSrcweir 	}
1248*cdf0e10cSrcweir 
1249*cdf0e10cSrcweir 	return aProperty;
1250*cdf0e10cSrcweir }
1251*cdf0e10cSrcweir 
1252*cdf0e10cSrcweir // --------------------------------------------------------------------
1253*cdf0e10cSrcweir 
1254*cdf0e10cSrcweir bool CustomAnimationEffect::setProperty( sal_Int32 nNodeType, const OUString& rAttributeName, EValue eValue, const Any& rValue )
1255*cdf0e10cSrcweir {
1256*cdf0e10cSrcweir 	bool bChanged = false;
1257*cdf0e10cSrcweir 	if( mxNode.is() ) try
1258*cdf0e10cSrcweir 	{
1259*cdf0e10cSrcweir 		Reference< XEnumerationAccess > xEnumerationAccess( mxNode, UNO_QUERY );
1260*cdf0e10cSrcweir 		if( xEnumerationAccess.is() )
1261*cdf0e10cSrcweir 		{
1262*cdf0e10cSrcweir 			Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY );
1263*cdf0e10cSrcweir 			if( xEnumeration.is() )
1264*cdf0e10cSrcweir 			{
1265*cdf0e10cSrcweir 				while( xEnumeration->hasMoreElements() )
1266*cdf0e10cSrcweir 				{
1267*cdf0e10cSrcweir 					Reference< XAnimate > xAnimate( xEnumeration->nextElement(), UNO_QUERY );
1268*cdf0e10cSrcweir 					if( !xAnimate.is() )
1269*cdf0e10cSrcweir 						continue;
1270*cdf0e10cSrcweir 
1271*cdf0e10cSrcweir 					if( xAnimate->getType() == nNodeType )
1272*cdf0e10cSrcweir 					{
1273*cdf0e10cSrcweir 						if( xAnimate->getAttributeName() == rAttributeName )
1274*cdf0e10cSrcweir 						{
1275*cdf0e10cSrcweir 							switch( eValue )
1276*cdf0e10cSrcweir 							{
1277*cdf0e10cSrcweir 							case VALUE_FROM:
1278*cdf0e10cSrcweir 								if( xAnimate->getFrom() != rValue )
1279*cdf0e10cSrcweir 								{
1280*cdf0e10cSrcweir 									xAnimate->setFrom( rValue );
1281*cdf0e10cSrcweir 									bChanged = true;
1282*cdf0e10cSrcweir 								}
1283*cdf0e10cSrcweir 								break;
1284*cdf0e10cSrcweir 							case VALUE_TO:
1285*cdf0e10cSrcweir 								if( xAnimate->getTo() != rValue )
1286*cdf0e10cSrcweir 								{
1287*cdf0e10cSrcweir 									xAnimate->setTo( rValue );
1288*cdf0e10cSrcweir 									bChanged = true;
1289*cdf0e10cSrcweir 								}
1290*cdf0e10cSrcweir 								break;
1291*cdf0e10cSrcweir 							case VALUE_BY:
1292*cdf0e10cSrcweir 								if( xAnimate->getTo() != rValue )
1293*cdf0e10cSrcweir 								{
1294*cdf0e10cSrcweir 									xAnimate->setBy( rValue );
1295*cdf0e10cSrcweir 									bChanged = true;
1296*cdf0e10cSrcweir 								}
1297*cdf0e10cSrcweir 								break;
1298*cdf0e10cSrcweir 							case VALUE_FIRST:
1299*cdf0e10cSrcweir 							case VALUE_LAST:
1300*cdf0e10cSrcweir 								{
1301*cdf0e10cSrcweir 									Sequence<Any> aValues( xAnimate->getValues() );
1302*cdf0e10cSrcweir 									if( !aValues.hasElements() )
1303*cdf0e10cSrcweir 										aValues.realloc(1);
1304*cdf0e10cSrcweir 
1305*cdf0e10cSrcweir 									sal_Int32 nIndex = eValue == VALUE_FIRST ? 0 : aValues.getLength() - 1;
1306*cdf0e10cSrcweir 
1307*cdf0e10cSrcweir 									if( aValues[ nIndex ] != rValue )
1308*cdf0e10cSrcweir 									{
1309*cdf0e10cSrcweir 										aValues[ nIndex ] = rValue;
1310*cdf0e10cSrcweir 										xAnimate->setValues( aValues );
1311*cdf0e10cSrcweir 										bChanged = true;
1312*cdf0e10cSrcweir 									}
1313*cdf0e10cSrcweir 								}
1314*cdf0e10cSrcweir 							}
1315*cdf0e10cSrcweir 						}
1316*cdf0e10cSrcweir 					}
1317*cdf0e10cSrcweir 				}
1318*cdf0e10cSrcweir 			}
1319*cdf0e10cSrcweir 		}
1320*cdf0e10cSrcweir 	}
1321*cdf0e10cSrcweir 	catch( Exception& e )
1322*cdf0e10cSrcweir 	{
1323*cdf0e10cSrcweir 		(void)e;
1324*cdf0e10cSrcweir 		DBG_ERROR("sd::CustomAnimationEffect::setProperty(), exception cought!" );
1325*cdf0e10cSrcweir 	}
1326*cdf0e10cSrcweir 
1327*cdf0e10cSrcweir 	return bChanged;
1328*cdf0e10cSrcweir }
1329*cdf0e10cSrcweir 
1330*cdf0e10cSrcweir // --------------------------------------------------------------------
1331*cdf0e10cSrcweir 
1332*cdf0e10cSrcweir static bool implIsColorAttribute( const OUString& rAttributeName )
1333*cdf0e10cSrcweir {
1334*cdf0e10cSrcweir 	return rAttributeName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("FillColor") ) ||
1335*cdf0e10cSrcweir 		   rAttributeName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("LineColor") ) ||
1336*cdf0e10cSrcweir 		   rAttributeName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("CharColor") );
1337*cdf0e10cSrcweir }
1338*cdf0e10cSrcweir 
1339*cdf0e10cSrcweir // --------------------------------------------------------------------
1340*cdf0e10cSrcweir 
1341*cdf0e10cSrcweir Any CustomAnimationEffect::getColor( sal_Int32 nIndex )
1342*cdf0e10cSrcweir {
1343*cdf0e10cSrcweir 	Any aColor;
1344*cdf0e10cSrcweir 	if( mxNode.is() ) try
1345*cdf0e10cSrcweir 	{
1346*cdf0e10cSrcweir 		Reference< XEnumerationAccess > xEnumerationAccess( mxNode, UNO_QUERY );
1347*cdf0e10cSrcweir 		if( xEnumerationAccess.is() )
1348*cdf0e10cSrcweir 		{
1349*cdf0e10cSrcweir 			Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY );
1350*cdf0e10cSrcweir 			if( xEnumeration.is() )
1351*cdf0e10cSrcweir 			{
1352*cdf0e10cSrcweir 				while( xEnumeration->hasMoreElements() && !aColor.hasValue() )
1353*cdf0e10cSrcweir 				{
1354*cdf0e10cSrcweir 					Reference< XAnimate > xAnimate( xEnumeration->nextElement(), UNO_QUERY );
1355*cdf0e10cSrcweir 					if( !xAnimate.is() )
1356*cdf0e10cSrcweir 						continue;
1357*cdf0e10cSrcweir 
1358*cdf0e10cSrcweir 					switch( xAnimate->getType() )
1359*cdf0e10cSrcweir 					{
1360*cdf0e10cSrcweir 					case AnimationNodeType::SET:
1361*cdf0e10cSrcweir 					case AnimationNodeType::ANIMATE:
1362*cdf0e10cSrcweir 						if( !implIsColorAttribute( xAnimate->getAttributeName() ) )
1363*cdf0e10cSrcweir 							break;
1364*cdf0e10cSrcweir 					case AnimationNodeType::ANIMATECOLOR:
1365*cdf0e10cSrcweir 						Sequence<Any> aValues( xAnimate->getValues() );
1366*cdf0e10cSrcweir 						if( aValues.hasElements() )
1367*cdf0e10cSrcweir 						{
1368*cdf0e10cSrcweir 							if( aValues.getLength() > nIndex )
1369*cdf0e10cSrcweir 								aColor = aValues[nIndex];
1370*cdf0e10cSrcweir 						}
1371*cdf0e10cSrcweir 						else if( nIndex == 0 )
1372*cdf0e10cSrcweir 							aColor = xAnimate->getFrom();
1373*cdf0e10cSrcweir 						else
1374*cdf0e10cSrcweir 							aColor = xAnimate->getTo();
1375*cdf0e10cSrcweir 					}
1376*cdf0e10cSrcweir 				}
1377*cdf0e10cSrcweir 			}
1378*cdf0e10cSrcweir 		}
1379*cdf0e10cSrcweir 	}
1380*cdf0e10cSrcweir 	catch( Exception& e )
1381*cdf0e10cSrcweir 	{
1382*cdf0e10cSrcweir 		(void)e;
1383*cdf0e10cSrcweir 		DBG_ERROR("sd::CustomAnimationEffect::getColor(), exception cought!" );
1384*cdf0e10cSrcweir 	}
1385*cdf0e10cSrcweir 
1386*cdf0e10cSrcweir 	return aColor;
1387*cdf0e10cSrcweir }
1388*cdf0e10cSrcweir 
1389*cdf0e10cSrcweir // --------------------------------------------------------------------
1390*cdf0e10cSrcweir 
1391*cdf0e10cSrcweir void CustomAnimationEffect::setColor( sal_Int32 nIndex, const Any& rColor )
1392*cdf0e10cSrcweir {
1393*cdf0e10cSrcweir 	if( mxNode.is() ) try
1394*cdf0e10cSrcweir 	{
1395*cdf0e10cSrcweir 		Reference< XEnumerationAccess > xEnumerationAccess( mxNode, UNO_QUERY );
1396*cdf0e10cSrcweir 		if( xEnumerationAccess.is() )
1397*cdf0e10cSrcweir 		{
1398*cdf0e10cSrcweir 			Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY );
1399*cdf0e10cSrcweir 			if( xEnumeration.is() )
1400*cdf0e10cSrcweir 			{
1401*cdf0e10cSrcweir 				while( xEnumeration->hasMoreElements() )
1402*cdf0e10cSrcweir 				{
1403*cdf0e10cSrcweir 					Reference< XAnimate > xAnimate( xEnumeration->nextElement(), UNO_QUERY );
1404*cdf0e10cSrcweir 					if( !xAnimate.is() )
1405*cdf0e10cSrcweir 						continue;
1406*cdf0e10cSrcweir 
1407*cdf0e10cSrcweir 					switch( xAnimate->getType() )
1408*cdf0e10cSrcweir 					{
1409*cdf0e10cSrcweir 					case AnimationNodeType::SET:
1410*cdf0e10cSrcweir 					case AnimationNodeType::ANIMATE:
1411*cdf0e10cSrcweir 						if( !implIsColorAttribute( xAnimate->getAttributeName() ) )
1412*cdf0e10cSrcweir 							break;
1413*cdf0e10cSrcweir 					case AnimationNodeType::ANIMATECOLOR:
1414*cdf0e10cSrcweir 					{
1415*cdf0e10cSrcweir 						Sequence<Any> aValues( xAnimate->getValues() );
1416*cdf0e10cSrcweir 						if( aValues.hasElements() )
1417*cdf0e10cSrcweir 						{
1418*cdf0e10cSrcweir 							if( aValues.getLength() > nIndex )
1419*cdf0e10cSrcweir 							{
1420*cdf0e10cSrcweir 								aValues[nIndex] = rColor;
1421*cdf0e10cSrcweir 								xAnimate->setValues( aValues );
1422*cdf0e10cSrcweir 							}
1423*cdf0e10cSrcweir 						}
1424*cdf0e10cSrcweir 						else if( (nIndex == 0) && xAnimate->getFrom().hasValue() )
1425*cdf0e10cSrcweir 							xAnimate->setFrom(rColor);
1426*cdf0e10cSrcweir 						else if( (nIndex == 1) && xAnimate->getTo().hasValue() )
1427*cdf0e10cSrcweir 							xAnimate->setTo(rColor);
1428*cdf0e10cSrcweir 					}
1429*cdf0e10cSrcweir 					break;
1430*cdf0e10cSrcweir 
1431*cdf0e10cSrcweir 					}
1432*cdf0e10cSrcweir 				}
1433*cdf0e10cSrcweir 			}
1434*cdf0e10cSrcweir 		}
1435*cdf0e10cSrcweir 	}
1436*cdf0e10cSrcweir 	catch( Exception& e )
1437*cdf0e10cSrcweir 	{
1438*cdf0e10cSrcweir 		(void)e;
1439*cdf0e10cSrcweir 		DBG_ERROR("sd::CustomAnimationEffect::setColor(), exception cought!" );
1440*cdf0e10cSrcweir 	}
1441*cdf0e10cSrcweir }
1442*cdf0e10cSrcweir 
1443*cdf0e10cSrcweir // --------------------------------------------------------------------
1444*cdf0e10cSrcweir 
1445*cdf0e10cSrcweir Any CustomAnimationEffect::getTransformationProperty( sal_Int32 nTransformType, EValue eValue )
1446*cdf0e10cSrcweir {
1447*cdf0e10cSrcweir 	Any aProperty;
1448*cdf0e10cSrcweir 	if( mxNode.is() ) try
1449*cdf0e10cSrcweir 	{
1450*cdf0e10cSrcweir 		Reference< XEnumerationAccess > xEnumerationAccess( mxNode, UNO_QUERY );
1451*cdf0e10cSrcweir 		if( xEnumerationAccess.is() )
1452*cdf0e10cSrcweir 		{
1453*cdf0e10cSrcweir 			Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY );
1454*cdf0e10cSrcweir 			if( xEnumeration.is() )
1455*cdf0e10cSrcweir 			{
1456*cdf0e10cSrcweir 				while( xEnumeration->hasMoreElements() && !aProperty.hasValue() )
1457*cdf0e10cSrcweir 				{
1458*cdf0e10cSrcweir 					Reference< XAnimateTransform > xTransform( xEnumeration->nextElement(), UNO_QUERY );
1459*cdf0e10cSrcweir 					if( !xTransform.is() )
1460*cdf0e10cSrcweir 						continue;
1461*cdf0e10cSrcweir 
1462*cdf0e10cSrcweir 					if( xTransform->getTransformType() == nTransformType )
1463*cdf0e10cSrcweir 					{
1464*cdf0e10cSrcweir 						switch( eValue )
1465*cdf0e10cSrcweir 						{
1466*cdf0e10cSrcweir 						case VALUE_FROM: aProperty = xTransform->getFrom(); break;
1467*cdf0e10cSrcweir 						case VALUE_TO:   aProperty = xTransform->getTo(); break;
1468*cdf0e10cSrcweir 						case VALUE_BY:   aProperty = xTransform->getBy(); break;
1469*cdf0e10cSrcweir 						case VALUE_FIRST:
1470*cdf0e10cSrcweir 						case VALUE_LAST:
1471*cdf0e10cSrcweir 							{
1472*cdf0e10cSrcweir 								Sequence<Any> aValues( xTransform->getValues() );
1473*cdf0e10cSrcweir 								if( aValues.hasElements() )
1474*cdf0e10cSrcweir 									aProperty =  aValues[ eValue == VALUE_FIRST ? 0 : aValues.getLength() - 1 ];
1475*cdf0e10cSrcweir 							}
1476*cdf0e10cSrcweir 							break;
1477*cdf0e10cSrcweir 						}
1478*cdf0e10cSrcweir 					}
1479*cdf0e10cSrcweir 				}
1480*cdf0e10cSrcweir 			}
1481*cdf0e10cSrcweir 		}
1482*cdf0e10cSrcweir 	}
1483*cdf0e10cSrcweir 	catch( Exception& e )
1484*cdf0e10cSrcweir 	{
1485*cdf0e10cSrcweir 		(void)e;
1486*cdf0e10cSrcweir 		DBG_ERROR("sd::CustomAnimationEffect::getTransformationProperty(), exception cought!" );
1487*cdf0e10cSrcweir 	}
1488*cdf0e10cSrcweir 
1489*cdf0e10cSrcweir 	return aProperty;
1490*cdf0e10cSrcweir }
1491*cdf0e10cSrcweir 
1492*cdf0e10cSrcweir // --------------------------------------------------------------------
1493*cdf0e10cSrcweir 
1494*cdf0e10cSrcweir bool CustomAnimationEffect::setTransformationProperty( sal_Int32 nTransformType, EValue eValue, const Any& rValue )
1495*cdf0e10cSrcweir {
1496*cdf0e10cSrcweir 	bool bChanged = false;
1497*cdf0e10cSrcweir 	if( mxNode.is() ) try
1498*cdf0e10cSrcweir 	{
1499*cdf0e10cSrcweir 		Reference< XEnumerationAccess > xEnumerationAccess( mxNode, UNO_QUERY );
1500*cdf0e10cSrcweir 		if( xEnumerationAccess.is() )
1501*cdf0e10cSrcweir 		{
1502*cdf0e10cSrcweir 			Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY );
1503*cdf0e10cSrcweir 			if( xEnumeration.is() )
1504*cdf0e10cSrcweir 			{
1505*cdf0e10cSrcweir 				while( xEnumeration->hasMoreElements() )
1506*cdf0e10cSrcweir 				{
1507*cdf0e10cSrcweir 					Reference< XAnimateTransform > xTransform( xEnumeration->nextElement(), UNO_QUERY );
1508*cdf0e10cSrcweir 					if( !xTransform.is() )
1509*cdf0e10cSrcweir 						continue;
1510*cdf0e10cSrcweir 
1511*cdf0e10cSrcweir 					if( xTransform->getTransformType() == nTransformType )
1512*cdf0e10cSrcweir 					{
1513*cdf0e10cSrcweir 						switch( eValue )
1514*cdf0e10cSrcweir 						{
1515*cdf0e10cSrcweir 						case VALUE_FROM:
1516*cdf0e10cSrcweir 							if( xTransform->getFrom() != rValue )
1517*cdf0e10cSrcweir 							{
1518*cdf0e10cSrcweir 								xTransform->setFrom( rValue );
1519*cdf0e10cSrcweir 								bChanged = true;
1520*cdf0e10cSrcweir 							}
1521*cdf0e10cSrcweir 							break;
1522*cdf0e10cSrcweir 						case VALUE_TO:
1523*cdf0e10cSrcweir 							if( xTransform->getTo() != rValue )
1524*cdf0e10cSrcweir 							{
1525*cdf0e10cSrcweir 								xTransform->setTo( rValue );
1526*cdf0e10cSrcweir 								bChanged = true;
1527*cdf0e10cSrcweir 							}
1528*cdf0e10cSrcweir 							break;
1529*cdf0e10cSrcweir 						case VALUE_BY:
1530*cdf0e10cSrcweir 							if( xTransform->getBy() != rValue )
1531*cdf0e10cSrcweir 							{
1532*cdf0e10cSrcweir 								xTransform->setBy( rValue );
1533*cdf0e10cSrcweir 								bChanged = true;
1534*cdf0e10cSrcweir 							}
1535*cdf0e10cSrcweir 							break;
1536*cdf0e10cSrcweir 						case VALUE_FIRST:
1537*cdf0e10cSrcweir 						case VALUE_LAST:
1538*cdf0e10cSrcweir 							{
1539*cdf0e10cSrcweir 								Sequence<Any> aValues( xTransform->getValues() );
1540*cdf0e10cSrcweir 								if( !aValues.hasElements() )
1541*cdf0e10cSrcweir 									aValues.realloc(1);
1542*cdf0e10cSrcweir 
1543*cdf0e10cSrcweir 								sal_Int32 nIndex = eValue == VALUE_FIRST ? 0 : aValues.getLength() - 1;
1544*cdf0e10cSrcweir 								if( aValues[nIndex] != rValue )
1545*cdf0e10cSrcweir 								{
1546*cdf0e10cSrcweir 									aValues[nIndex] = rValue;
1547*cdf0e10cSrcweir 									xTransform->setValues( aValues );
1548*cdf0e10cSrcweir 									bChanged = true;
1549*cdf0e10cSrcweir 								}
1550*cdf0e10cSrcweir 							}
1551*cdf0e10cSrcweir 						}
1552*cdf0e10cSrcweir 					}
1553*cdf0e10cSrcweir 				}
1554*cdf0e10cSrcweir 			}
1555*cdf0e10cSrcweir 		}
1556*cdf0e10cSrcweir 	}
1557*cdf0e10cSrcweir 	catch( Exception& e )
1558*cdf0e10cSrcweir 	{
1559*cdf0e10cSrcweir 		(void)e;
1560*cdf0e10cSrcweir 		DBG_ERROR("sd::CustomAnimationEffect::setTransformationProperty(), exception cought!" );
1561*cdf0e10cSrcweir 	}
1562*cdf0e10cSrcweir 
1563*cdf0e10cSrcweir 	return bChanged;
1564*cdf0e10cSrcweir }
1565*cdf0e10cSrcweir 
1566*cdf0e10cSrcweir // --------------------------------------------------------------------
1567*cdf0e10cSrcweir 
1568*cdf0e10cSrcweir void CustomAnimationEffect::createAudio( const ::com::sun::star::uno::Any& rSource, double fVolume /* = 1.0 */ )
1569*cdf0e10cSrcweir {
1570*cdf0e10cSrcweir 	DBG_ASSERT( !mxAudio.is(), "sd::CustomAnimationEffect::createAudio(), node already has an audio!" );
1571*cdf0e10cSrcweir 
1572*cdf0e10cSrcweir 	if( !mxAudio.is() ) try
1573*cdf0e10cSrcweir 	{
1574*cdf0e10cSrcweir 		Reference< XMultiServiceFactory > xMsf( ::comphelper::getProcessServiceFactory() );
1575*cdf0e10cSrcweir 		Reference< XAudio > xAudio( xMsf->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.animations.Audio") ) ), UNO_QUERY_THROW );
1576*cdf0e10cSrcweir 		xAudio->setSource( rSource );
1577*cdf0e10cSrcweir 		xAudio->setVolume( fVolume );
1578*cdf0e10cSrcweir 		setAudio( xAudio );
1579*cdf0e10cSrcweir 	}
1580*cdf0e10cSrcweir 	catch( Exception& e )
1581*cdf0e10cSrcweir 	{
1582*cdf0e10cSrcweir 		(void)e;
1583*cdf0e10cSrcweir 		DBG_ERROR("sd::CustomAnimationEffect::createAudio(), exception cought!" );
1584*cdf0e10cSrcweir 	}
1585*cdf0e10cSrcweir }
1586*cdf0e10cSrcweir 
1587*cdf0e10cSrcweir // --------------------------------------------------------------------
1588*cdf0e10cSrcweir 
1589*cdf0e10cSrcweir static Reference< XCommand > findCommandNode( const Reference< XAnimationNode >& xRootNode )
1590*cdf0e10cSrcweir {
1591*cdf0e10cSrcweir 	Reference< XCommand > xCommand;
1592*cdf0e10cSrcweir 
1593*cdf0e10cSrcweir 	if( xRootNode.is() ) try
1594*cdf0e10cSrcweir 	{
1595*cdf0e10cSrcweir 		Reference< XEnumerationAccess > xEnumerationAccess( xRootNode, UNO_QUERY_THROW );
1596*cdf0e10cSrcweir 		Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
1597*cdf0e10cSrcweir 		while( !xCommand.is() && xEnumeration->hasMoreElements() )
1598*cdf0e10cSrcweir 		{
1599*cdf0e10cSrcweir 			Reference< XAnimationNode > xNode( xEnumeration->nextElement(), UNO_QUERY );
1600*cdf0e10cSrcweir 			if( xNode.is() && (xNode->getType() == AnimationNodeType::COMMAND) )
1601*cdf0e10cSrcweir 				xCommand.set( xNode, UNO_QUERY_THROW );
1602*cdf0e10cSrcweir 		}
1603*cdf0e10cSrcweir 	}
1604*cdf0e10cSrcweir 	catch( Exception& e )
1605*cdf0e10cSrcweir 	{
1606*cdf0e10cSrcweir 		(void)e;
1607*cdf0e10cSrcweir 		DBG_ERROR("sd::findCommandNode(), exception caught!" );
1608*cdf0e10cSrcweir 	}
1609*cdf0e10cSrcweir 
1610*cdf0e10cSrcweir 	return xCommand;
1611*cdf0e10cSrcweir }
1612*cdf0e10cSrcweir 
1613*cdf0e10cSrcweir void CustomAnimationEffect::removeAudio()
1614*cdf0e10cSrcweir {
1615*cdf0e10cSrcweir 	try
1616*cdf0e10cSrcweir 	{
1617*cdf0e10cSrcweir 		Reference< XAnimationNode > xChild;
1618*cdf0e10cSrcweir 
1619*cdf0e10cSrcweir 		if( mxAudio.is() )
1620*cdf0e10cSrcweir 		{
1621*cdf0e10cSrcweir 			xChild.set( mxAudio, UNO_QUERY );
1622*cdf0e10cSrcweir 			mxAudio.clear();
1623*cdf0e10cSrcweir 		}
1624*cdf0e10cSrcweir 		else if( mnCommand == EffectCommands::STOPAUDIO )
1625*cdf0e10cSrcweir 		{
1626*cdf0e10cSrcweir 			xChild.set( findCommandNode( mxNode ), UNO_QUERY );
1627*cdf0e10cSrcweir 			mnCommand = 0;
1628*cdf0e10cSrcweir 		}
1629*cdf0e10cSrcweir 
1630*cdf0e10cSrcweir 		if( xChild.is() )
1631*cdf0e10cSrcweir 		{
1632*cdf0e10cSrcweir 			Reference< XTimeContainer > xContainer( mxNode, UNO_QUERY );
1633*cdf0e10cSrcweir 			if( xContainer.is() )
1634*cdf0e10cSrcweir 				xContainer->removeChild( xChild );
1635*cdf0e10cSrcweir 		}
1636*cdf0e10cSrcweir 	}
1637*cdf0e10cSrcweir 	catch( Exception& e )
1638*cdf0e10cSrcweir 	{
1639*cdf0e10cSrcweir 		(void)e;
1640*cdf0e10cSrcweir 		DBG_ERROR("sd::CustomAnimationEffect::removeAudio(), exception caught!" );
1641*cdf0e10cSrcweir 	}
1642*cdf0e10cSrcweir 
1643*cdf0e10cSrcweir }
1644*cdf0e10cSrcweir 
1645*cdf0e10cSrcweir // --------------------------------------------------------------------
1646*cdf0e10cSrcweir 
1647*cdf0e10cSrcweir void CustomAnimationEffect::setAudio( const Reference< ::com::sun::star::animations::XAudio >& xAudio )
1648*cdf0e10cSrcweir {
1649*cdf0e10cSrcweir 	if( mxAudio != xAudio ) try
1650*cdf0e10cSrcweir 	{
1651*cdf0e10cSrcweir 		removeAudio();
1652*cdf0e10cSrcweir 		mxAudio = xAudio;
1653*cdf0e10cSrcweir 		Reference< XTimeContainer > xContainer( mxNode, UNO_QUERY );
1654*cdf0e10cSrcweir 		Reference< XAnimationNode > xChild( mxAudio, UNO_QUERY );
1655*cdf0e10cSrcweir 		if( xContainer.is() && xChild.is() )
1656*cdf0e10cSrcweir 			xContainer->appendChild( xChild );
1657*cdf0e10cSrcweir 	}
1658*cdf0e10cSrcweir 	catch( Exception& e )
1659*cdf0e10cSrcweir 	{
1660*cdf0e10cSrcweir 		(void)e;
1661*cdf0e10cSrcweir 		DBG_ERROR("sd::CustomAnimationEffect::setAudio(), exception caught!" );
1662*cdf0e10cSrcweir 	}
1663*cdf0e10cSrcweir }
1664*cdf0e10cSrcweir 
1665*cdf0e10cSrcweir // --------------------------------------------------------------------
1666*cdf0e10cSrcweir 
1667*cdf0e10cSrcweir void CustomAnimationEffect::setStopAudio()
1668*cdf0e10cSrcweir {
1669*cdf0e10cSrcweir 	if( mnCommand != EffectCommands::STOPAUDIO ) try
1670*cdf0e10cSrcweir 	{
1671*cdf0e10cSrcweir 		if( mxAudio.is() )
1672*cdf0e10cSrcweir 			removeAudio();
1673*cdf0e10cSrcweir 
1674*cdf0e10cSrcweir 		Reference< XMultiServiceFactory > xMsf( ::comphelper::getProcessServiceFactory() );
1675*cdf0e10cSrcweir 		Reference< XCommand > xCommand( xMsf->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.animations.Command") ) ), UNO_QUERY_THROW );
1676*cdf0e10cSrcweir 
1677*cdf0e10cSrcweir 		xCommand->setCommand( EffectCommands::STOPAUDIO );
1678*cdf0e10cSrcweir 
1679*cdf0e10cSrcweir 		Reference< XTimeContainer > xContainer( mxNode, UNO_QUERY_THROW );
1680*cdf0e10cSrcweir 		Reference< XAnimationNode > xChild( xCommand, UNO_QUERY_THROW );
1681*cdf0e10cSrcweir 		xContainer->appendChild( xChild );
1682*cdf0e10cSrcweir 
1683*cdf0e10cSrcweir 		mnCommand = EffectCommands::STOPAUDIO;
1684*cdf0e10cSrcweir 	}
1685*cdf0e10cSrcweir 	catch( Exception& e )
1686*cdf0e10cSrcweir 	{
1687*cdf0e10cSrcweir 		(void)e;
1688*cdf0e10cSrcweir 		DBG_ERROR("sd::CustomAnimationEffect::setStopAudio(), exception caught!" );
1689*cdf0e10cSrcweir 	}
1690*cdf0e10cSrcweir }
1691*cdf0e10cSrcweir 
1692*cdf0e10cSrcweir // --------------------------------------------------------------------
1693*cdf0e10cSrcweir 
1694*cdf0e10cSrcweir bool CustomAnimationEffect::getStopAudio() const
1695*cdf0e10cSrcweir {
1696*cdf0e10cSrcweir 	return mnCommand == EffectCommands::STOPAUDIO;
1697*cdf0e10cSrcweir }
1698*cdf0e10cSrcweir 
1699*cdf0e10cSrcweir // --------------------------------------------------------------------
1700*cdf0e10cSrcweir 
1701*cdf0e10cSrcweir SdrPathObj* CustomAnimationEffect::createSdrPathObjFromPath()
1702*cdf0e10cSrcweir {
1703*cdf0e10cSrcweir 	SdrPathObj * pPathObj = new SdrPathObj( OBJ_PATHLINE );
1704*cdf0e10cSrcweir 	updateSdrPathObjFromPath( *pPathObj );
1705*cdf0e10cSrcweir 	return pPathObj;
1706*cdf0e10cSrcweir }
1707*cdf0e10cSrcweir 
1708*cdf0e10cSrcweir // --------------------------------------------------------------------
1709*cdf0e10cSrcweir 
1710*cdf0e10cSrcweir void CustomAnimationEffect::updateSdrPathObjFromPath( SdrPathObj& rPathObj )
1711*cdf0e10cSrcweir {
1712*cdf0e10cSrcweir 	::basegfx::B2DPolyPolygon xPolyPoly;
1713*cdf0e10cSrcweir 	if( ::basegfx::tools::importFromSvgD( xPolyPoly, getPath() ) )
1714*cdf0e10cSrcweir 	{
1715*cdf0e10cSrcweir 		SdrObject* pObj = GetSdrObjectFromXShape( getTargetShape() );
1716*cdf0e10cSrcweir 		if( pObj )
1717*cdf0e10cSrcweir 		{
1718*cdf0e10cSrcweir 			SdrPage* pPage = pObj->GetPage();
1719*cdf0e10cSrcweir 			if( pPage )
1720*cdf0e10cSrcweir 			{
1721*cdf0e10cSrcweir 				const Size aPageSize( pPage->GetSize() );
1722*cdf0e10cSrcweir                 xPolyPoly.transform(basegfx::tools::createScaleB2DHomMatrix((double)aPageSize.Width(), (double)aPageSize.Height()));
1723*cdf0e10cSrcweir 			}
1724*cdf0e10cSrcweir 
1725*cdf0e10cSrcweir 			const Rectangle aBoundRect( pObj->GetCurrentBoundRect() );
1726*cdf0e10cSrcweir 			const Point aCenter( aBoundRect.Center() );
1727*cdf0e10cSrcweir             xPolyPoly.transform(basegfx::tools::createTranslateB2DHomMatrix(aCenter.X(), aCenter.Y()));
1728*cdf0e10cSrcweir 		}
1729*cdf0e10cSrcweir 	}
1730*cdf0e10cSrcweir 
1731*cdf0e10cSrcweir 	rPathObj.SetPathPoly( xPolyPoly );
1732*cdf0e10cSrcweir }
1733*cdf0e10cSrcweir 
1734*cdf0e10cSrcweir // --------------------------------------------------------------------
1735*cdf0e10cSrcweir 
1736*cdf0e10cSrcweir void CustomAnimationEffect::updatePathFromSdrPathObj( const SdrPathObj& rPathObj )
1737*cdf0e10cSrcweir {
1738*cdf0e10cSrcweir 	::basegfx::B2DPolyPolygon xPolyPoly( rPathObj.GetPathPoly() );
1739*cdf0e10cSrcweir 
1740*cdf0e10cSrcweir 	SdrObject* pObj = GetSdrObjectFromXShape( getTargetShape() );
1741*cdf0e10cSrcweir 	if( pObj )
1742*cdf0e10cSrcweir 	{
1743*cdf0e10cSrcweir 		Rectangle aBoundRect(0,0,0,0);
1744*cdf0e10cSrcweir 
1745*cdf0e10cSrcweir     	const drawinglayer::primitive2d::Primitive2DSequence xPrimitives(pObj->GetViewContact().getViewIndependentPrimitive2DSequence());
1746*cdf0e10cSrcweir 	    const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
1747*cdf0e10cSrcweir    		const basegfx::B2DRange aRange(drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(xPrimitives, aViewInformation2D));
1748*cdf0e10cSrcweir 
1749*cdf0e10cSrcweir 		if(!aRange.isEmpty())
1750*cdf0e10cSrcweir 		{
1751*cdf0e10cSrcweir 			aBoundRect = Rectangle(
1752*cdf0e10cSrcweir 					(sal_Int32)floor(aRange.getMinX()), (sal_Int32)floor(aRange.getMinY()),
1753*cdf0e10cSrcweir 					(sal_Int32)ceil(aRange.getMaxX()), (sal_Int32)ceil(aRange.getMaxY()));
1754*cdf0e10cSrcweir 		}
1755*cdf0e10cSrcweir 
1756*cdf0e10cSrcweir 		const Point aCenter( aBoundRect.Center() );
1757*cdf0e10cSrcweir 
1758*cdf0e10cSrcweir         xPolyPoly.transform(basegfx::tools::createTranslateB2DHomMatrix(-aCenter.X(), -aCenter.Y()));
1759*cdf0e10cSrcweir 
1760*cdf0e10cSrcweir 		SdrPage* pPage = pObj->GetPage();
1761*cdf0e10cSrcweir 		if( pPage )
1762*cdf0e10cSrcweir 		{
1763*cdf0e10cSrcweir 			const Size aPageSize( pPage->GetSize() );
1764*cdf0e10cSrcweir             xPolyPoly.transform(basegfx::tools::createScaleB2DHomMatrix(
1765*cdf0e10cSrcweir                 1.0 / (double)aPageSize.Width(), 1.0 / (double)aPageSize.Height()));
1766*cdf0e10cSrcweir 		}
1767*cdf0e10cSrcweir 	}
1768*cdf0e10cSrcweir 
1769*cdf0e10cSrcweir 	setPath( ::basegfx::tools::exportToSvgD( xPolyPoly ) );
1770*cdf0e10cSrcweir }
1771*cdf0e10cSrcweir 
1772*cdf0e10cSrcweir // ====================================================================
1773*cdf0e10cSrcweir 
1774*cdf0e10cSrcweir EffectSequenceHelper::EffectSequenceHelper()
1775*cdf0e10cSrcweir : mnSequenceType( EffectNodeType::DEFAULT )
1776*cdf0e10cSrcweir {
1777*cdf0e10cSrcweir }
1778*cdf0e10cSrcweir 
1779*cdf0e10cSrcweir // --------------------------------------------------------------------
1780*cdf0e10cSrcweir 
1781*cdf0e10cSrcweir EffectSequenceHelper::EffectSequenceHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XTimeContainer >& xSequenceRoot )
1782*cdf0e10cSrcweir : mxSequenceRoot( xSequenceRoot ), mnSequenceType( EffectNodeType::DEFAULT )
1783*cdf0e10cSrcweir {
1784*cdf0e10cSrcweir 	Reference< XAnimationNode > xNode( mxSequenceRoot, UNO_QUERY_THROW );
1785*cdf0e10cSrcweir 	create( xNode );
1786*cdf0e10cSrcweir }
1787*cdf0e10cSrcweir 
1788*cdf0e10cSrcweir // --------------------------------------------------------------------
1789*cdf0e10cSrcweir 
1790*cdf0e10cSrcweir EffectSequenceHelper::~EffectSequenceHelper()
1791*cdf0e10cSrcweir {
1792*cdf0e10cSrcweir 	reset();
1793*cdf0e10cSrcweir }
1794*cdf0e10cSrcweir 
1795*cdf0e10cSrcweir // --------------------------------------------------------------------
1796*cdf0e10cSrcweir 
1797*cdf0e10cSrcweir void EffectSequenceHelper::reset()
1798*cdf0e10cSrcweir {
1799*cdf0e10cSrcweir 	EffectSequence::iterator aIter( maEffects.begin() );
1800*cdf0e10cSrcweir 	EffectSequence::iterator aEnd( maEffects.end() );
1801*cdf0e10cSrcweir 	if( aIter != aEnd )
1802*cdf0e10cSrcweir 	{
1803*cdf0e10cSrcweir 		CustomAnimationEffectPtr pEffect = (*aIter++);
1804*cdf0e10cSrcweir 		pEffect->setEffectSequence(0);
1805*cdf0e10cSrcweir 	}
1806*cdf0e10cSrcweir 	maEffects.clear();
1807*cdf0e10cSrcweir }
1808*cdf0e10cSrcweir 
1809*cdf0e10cSrcweir Reference< XAnimationNode > EffectSequenceHelper::getRootNode()
1810*cdf0e10cSrcweir {
1811*cdf0e10cSrcweir 	Reference< XAnimationNode > xRoot( mxSequenceRoot, UNO_QUERY );
1812*cdf0e10cSrcweir 	return xRoot;
1813*cdf0e10cSrcweir }
1814*cdf0e10cSrcweir 
1815*cdf0e10cSrcweir // --------------------------------------------------------------------
1816*cdf0e10cSrcweir 
1817*cdf0e10cSrcweir void EffectSequenceHelper::append( const CustomAnimationEffectPtr& pEffect )
1818*cdf0e10cSrcweir {
1819*cdf0e10cSrcweir 	pEffect->setEffectSequence( this );
1820*cdf0e10cSrcweir 	maEffects.push_back(pEffect);
1821*cdf0e10cSrcweir 	rebuild();
1822*cdf0e10cSrcweir }
1823*cdf0e10cSrcweir 
1824*cdf0e10cSrcweir // --------------------------------------------------------------------
1825*cdf0e10cSrcweir 
1826*cdf0e10cSrcweir CustomAnimationEffectPtr EffectSequenceHelper::append( const CustomAnimationPresetPtr& pPreset, const Any& rTarget, double fDuration /* = -1.0 */ )
1827*cdf0e10cSrcweir {
1828*cdf0e10cSrcweir 	CustomAnimationEffectPtr pEffect;
1829*cdf0e10cSrcweir 
1830*cdf0e10cSrcweir 	if( pPreset.get() )
1831*cdf0e10cSrcweir 	{
1832*cdf0e10cSrcweir 		OUString strEmpty;
1833*cdf0e10cSrcweir 		Reference< XAnimationNode > xNode( pPreset->create( strEmpty ) );
1834*cdf0e10cSrcweir 		if( xNode.is() )
1835*cdf0e10cSrcweir 		{
1836*cdf0e10cSrcweir 			// first, filter all only ui relevant user data
1837*cdf0e10cSrcweir 			std::vector< NamedValue > aNewUserData;
1838*cdf0e10cSrcweir 			Sequence< NamedValue > aUserData( xNode->getUserData() );
1839*cdf0e10cSrcweir 			sal_Int32 nLength = aUserData.getLength();
1840*cdf0e10cSrcweir 			const NamedValue* p = aUserData.getConstArray();
1841*cdf0e10cSrcweir 			bool bFilter = false;
1842*cdf0e10cSrcweir 
1843*cdf0e10cSrcweir 			while( nLength-- )
1844*cdf0e10cSrcweir 			{
1845*cdf0e10cSrcweir 				if( !p->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "text-only" ) ) &&
1846*cdf0e10cSrcweir 					!p->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "preset-property" ) ) )
1847*cdf0e10cSrcweir 				{
1848*cdf0e10cSrcweir 					aNewUserData.push_back( *p );
1849*cdf0e10cSrcweir 					bFilter = true;
1850*cdf0e10cSrcweir 				}
1851*cdf0e10cSrcweir 				p++;
1852*cdf0e10cSrcweir 			}
1853*cdf0e10cSrcweir 
1854*cdf0e10cSrcweir 			if( bFilter )
1855*cdf0e10cSrcweir 			{
1856*cdf0e10cSrcweir 				aUserData = ::comphelper::containerToSequence< NamedValue, std::vector< NamedValue > >( aNewUserData );
1857*cdf0e10cSrcweir 				xNode->setUserData( aUserData );
1858*cdf0e10cSrcweir 			}
1859*cdf0e10cSrcweir 
1860*cdf0e10cSrcweir 			// check target, maybe we need to force it to text
1861*cdf0e10cSrcweir 			Any aTarget( rTarget );
1862*cdf0e10cSrcweir 			sal_Int16 nSubItem = ShapeAnimationSubType::AS_WHOLE;
1863*cdf0e10cSrcweir 
1864*cdf0e10cSrcweir 			if(	aTarget.getValueType() == ::getCppuType((const ParagraphTarget*)0) )
1865*cdf0e10cSrcweir 			{
1866*cdf0e10cSrcweir 				nSubItem = ShapeAnimationSubType::ONLY_TEXT;
1867*cdf0e10cSrcweir 			}
1868*cdf0e10cSrcweir 			else if( pPreset->isTextOnly() )
1869*cdf0e10cSrcweir 			{
1870*cdf0e10cSrcweir 				Reference< XShape > xShape;
1871*cdf0e10cSrcweir 				aTarget >>= xShape;
1872*cdf0e10cSrcweir 				if( xShape.is() )
1873*cdf0e10cSrcweir 				{
1874*cdf0e10cSrcweir 					// thats bad, we target a shape here but the effect is only for text
1875*cdf0e10cSrcweir 					// so change subitem
1876*cdf0e10cSrcweir 					nSubItem = ShapeAnimationSubType::ONLY_TEXT;
1877*cdf0e10cSrcweir 				}
1878*cdf0e10cSrcweir 			}
1879*cdf0e10cSrcweir 
1880*cdf0e10cSrcweir 			// now create effect from preset
1881*cdf0e10cSrcweir 			pEffect.reset( new CustomAnimationEffect( xNode ) );
1882*cdf0e10cSrcweir 			pEffect->setEffectSequence( this );
1883*cdf0e10cSrcweir 			pEffect->setTarget( aTarget );
1884*cdf0e10cSrcweir 			pEffect->setTargetSubItem( nSubItem );
1885*cdf0e10cSrcweir 			if( fDuration != -1.0 )
1886*cdf0e10cSrcweir 				pEffect->setDuration( fDuration );
1887*cdf0e10cSrcweir 
1888*cdf0e10cSrcweir 			maEffects.push_back(pEffect);
1889*cdf0e10cSrcweir 
1890*cdf0e10cSrcweir 			rebuild();
1891*cdf0e10cSrcweir 		}
1892*cdf0e10cSrcweir 	}
1893*cdf0e10cSrcweir 
1894*cdf0e10cSrcweir 	DBG_ASSERT( pEffect.get(), "sd::EffectSequenceHelper::append(), failed!" );
1895*cdf0e10cSrcweir 	return pEffect;
1896*cdf0e10cSrcweir }
1897*cdf0e10cSrcweir 
1898*cdf0e10cSrcweir // --------------------------------------------------------------------
1899*cdf0e10cSrcweir 
1900*cdf0e10cSrcweir CustomAnimationEffectPtr EffectSequenceHelper::append( const SdrPathObj& rPathObj, const Any& rTarget, double fDuration /* = -1.0 */ )
1901*cdf0e10cSrcweir {
1902*cdf0e10cSrcweir 	CustomAnimationEffectPtr pEffect;
1903*cdf0e10cSrcweir 
1904*cdf0e10cSrcweir 	if( fDuration <= 0.0 )
1905*cdf0e10cSrcweir 		fDuration = 2.0;
1906*cdf0e10cSrcweir 
1907*cdf0e10cSrcweir 	try
1908*cdf0e10cSrcweir 	{
1909*cdf0e10cSrcweir 		Reference< XTimeContainer > xEffectContainer( createParallelTimeContainer() );
1910*cdf0e10cSrcweir 		const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.animations.AnimateMotion" ) );
1911*cdf0e10cSrcweir 		Reference< XAnimationNode > xAnimateMotion( ::comphelper::getProcessServiceFactory()->createInstance(aServiceName), UNO_QUERY_THROW );
1912*cdf0e10cSrcweir 
1913*cdf0e10cSrcweir 		xAnimateMotion->setDuration( Any( fDuration ) );
1914*cdf0e10cSrcweir 		xAnimateMotion->setFill( AnimationFill::HOLD );
1915*cdf0e10cSrcweir 		xEffectContainer->appendChild( xAnimateMotion );
1916*cdf0e10cSrcweir 
1917*cdf0e10cSrcweir 		sal_Int16 nSubItem = ShapeAnimationSubType::AS_WHOLE;
1918*cdf0e10cSrcweir 
1919*cdf0e10cSrcweir 		if(	rTarget.getValueType() == ::getCppuType((const ParagraphTarget*)0) )
1920*cdf0e10cSrcweir 			nSubItem = ShapeAnimationSubType::ONLY_TEXT;
1921*cdf0e10cSrcweir 
1922*cdf0e10cSrcweir 		Reference< XAnimationNode > xEffectNode( xEffectContainer, UNO_QUERY_THROW );
1923*cdf0e10cSrcweir 		pEffect.reset( new CustomAnimationEffect( xEffectNode ) );
1924*cdf0e10cSrcweir 		pEffect->setEffectSequence( this );
1925*cdf0e10cSrcweir 		pEffect->setTarget( rTarget );
1926*cdf0e10cSrcweir 		pEffect->setTargetSubItem( nSubItem );
1927*cdf0e10cSrcweir 		pEffect->setNodeType( ::com::sun::star::presentation::EffectNodeType::ON_CLICK );
1928*cdf0e10cSrcweir 		pEffect->setPresetClass( ::com::sun::star::presentation::EffectPresetClass::MOTIONPATH );
1929*cdf0e10cSrcweir 		pEffect->setAcceleration( 0.5 );
1930*cdf0e10cSrcweir 		pEffect->setDecelerate( 0.5 );
1931*cdf0e10cSrcweir 		pEffect->setFill( AnimationFill::HOLD );
1932*cdf0e10cSrcweir 		pEffect->setBegin( 0.0 );
1933*cdf0e10cSrcweir 		pEffect->updatePathFromSdrPathObj( rPathObj );
1934*cdf0e10cSrcweir 		if( fDuration != -1.0 )
1935*cdf0e10cSrcweir 			pEffect->setDuration( fDuration );
1936*cdf0e10cSrcweir 
1937*cdf0e10cSrcweir 		maEffects.push_back(pEffect);
1938*cdf0e10cSrcweir 
1939*cdf0e10cSrcweir 		rebuild();
1940*cdf0e10cSrcweir 	}
1941*cdf0e10cSrcweir 	catch( Exception& )
1942*cdf0e10cSrcweir 	{
1943*cdf0e10cSrcweir 		DBG_ERROR( "sd::EffectSequenceHelper::append(), exception cought!" );
1944*cdf0e10cSrcweir 	}
1945*cdf0e10cSrcweir 
1946*cdf0e10cSrcweir 	return pEffect;
1947*cdf0e10cSrcweir }
1948*cdf0e10cSrcweir 
1949*cdf0e10cSrcweir // --------------------------------------------------------------------
1950*cdf0e10cSrcweir 
1951*cdf0e10cSrcweir void EffectSequenceHelper::replace( const CustomAnimationEffectPtr& pEffect, const CustomAnimationPresetPtr& pPreset, const OUString& rPresetSubType, double fDuration /* = -1.0 */ )
1952*cdf0e10cSrcweir {
1953*cdf0e10cSrcweir 	if( pEffect.get() && pPreset.get() ) try
1954*cdf0e10cSrcweir 	{
1955*cdf0e10cSrcweir 		Reference< XAnimationNode > xNewNode( pPreset->create( rPresetSubType ) );
1956*cdf0e10cSrcweir 		if( xNewNode.is() )
1957*cdf0e10cSrcweir 		{
1958*cdf0e10cSrcweir 			pEffect->replaceNode( xNewNode );
1959*cdf0e10cSrcweir 			if( fDuration != -1.0 )
1960*cdf0e10cSrcweir 				pEffect->setDuration( fDuration );
1961*cdf0e10cSrcweir 		}
1962*cdf0e10cSrcweir 
1963*cdf0e10cSrcweir 		rebuild();
1964*cdf0e10cSrcweir 	}
1965*cdf0e10cSrcweir 	catch( Exception& e )
1966*cdf0e10cSrcweir 	{
1967*cdf0e10cSrcweir 		(void)e;
1968*cdf0e10cSrcweir 		DBG_ERROR( "sd::EffectSequenceHelper::replace(), exception cought!" );
1969*cdf0e10cSrcweir 	}
1970*cdf0e10cSrcweir }
1971*cdf0e10cSrcweir 
1972*cdf0e10cSrcweir // --------------------------------------------------------------------
1973*cdf0e10cSrcweir 
1974*cdf0e10cSrcweir void EffectSequenceHelper::replace( const CustomAnimationEffectPtr& pEffect, const CustomAnimationPresetPtr& pPreset, double fDuration /* = -1.0 */ )
1975*cdf0e10cSrcweir {
1976*cdf0e10cSrcweir 	OUString strEmpty;
1977*cdf0e10cSrcweir 	replace( pEffect, pPreset, strEmpty, fDuration );
1978*cdf0e10cSrcweir }
1979*cdf0e10cSrcweir 
1980*cdf0e10cSrcweir // --------------------------------------------------------------------
1981*cdf0e10cSrcweir 
1982*cdf0e10cSrcweir void EffectSequenceHelper::remove( const CustomAnimationEffectPtr& pEffect )
1983*cdf0e10cSrcweir {
1984*cdf0e10cSrcweir 	if( pEffect.get() )
1985*cdf0e10cSrcweir 	{
1986*cdf0e10cSrcweir 		pEffect->setEffectSequence( 0 );
1987*cdf0e10cSrcweir 		maEffects.remove( pEffect );
1988*cdf0e10cSrcweir 	}
1989*cdf0e10cSrcweir 
1990*cdf0e10cSrcweir 	rebuild();
1991*cdf0e10cSrcweir }
1992*cdf0e10cSrcweir 
1993*cdf0e10cSrcweir // --------------------------------------------------------------------
1994*cdf0e10cSrcweir 
1995*cdf0e10cSrcweir void EffectSequenceHelper::rebuild()
1996*cdf0e10cSrcweir {
1997*cdf0e10cSrcweir 	implRebuild();
1998*cdf0e10cSrcweir }
1999*cdf0e10cSrcweir 
2000*cdf0e10cSrcweir // --------------------------------------------------------------------
2001*cdf0e10cSrcweir 
2002*cdf0e10cSrcweir void EffectSequenceHelper::implRebuild()
2003*cdf0e10cSrcweir {
2004*cdf0e10cSrcweir 	try
2005*cdf0e10cSrcweir 	{
2006*cdf0e10cSrcweir 		// first we delete all time containers on the first two levels
2007*cdf0e10cSrcweir 		Reference< XEnumerationAccess > xEnumerationAccess( mxSequenceRoot, UNO_QUERY_THROW );
2008*cdf0e10cSrcweir 		Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
2009*cdf0e10cSrcweir 		while( xEnumeration->hasMoreElements() )
2010*cdf0e10cSrcweir 		{
2011*cdf0e10cSrcweir 			Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY_THROW );
2012*cdf0e10cSrcweir 			Reference< XTimeContainer > xChildContainer( xChildNode, UNO_QUERY_THROW );
2013*cdf0e10cSrcweir 
2014*cdf0e10cSrcweir 			Reference< XEnumerationAccess > xChildEnumerationAccess( xChildNode, UNO_QUERY_THROW );
2015*cdf0e10cSrcweir 			Reference< XEnumeration > xChildEnumeration( xChildEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
2016*cdf0e10cSrcweir 			while( xChildEnumeration->hasMoreElements() )
2017*cdf0e10cSrcweir 			{
2018*cdf0e10cSrcweir 				Reference< XAnimationNode > xNode( xChildEnumeration->nextElement(), UNO_QUERY_THROW );
2019*cdf0e10cSrcweir 				xChildContainer->removeChild( xNode );
2020*cdf0e10cSrcweir 			}
2021*cdf0e10cSrcweir 
2022*cdf0e10cSrcweir 			mxSequenceRoot->removeChild( xChildNode );
2023*cdf0e10cSrcweir 		}
2024*cdf0e10cSrcweir 
2025*cdf0e10cSrcweir 		// second, rebuild main sequence
2026*cdf0e10cSrcweir 		EffectSequence::iterator aIter( maEffects.begin() );
2027*cdf0e10cSrcweir 		EffectSequence::iterator aEnd( maEffects.end() );
2028*cdf0e10cSrcweir 		if( aIter != aEnd )
2029*cdf0e10cSrcweir 		{
2030*cdf0e10cSrcweir 			AfterEffectNodeList aAfterEffects;
2031*cdf0e10cSrcweir 
2032*cdf0e10cSrcweir 			CustomAnimationEffectPtr pEffect = (*aIter++);
2033*cdf0e10cSrcweir 
2034*cdf0e10cSrcweir 			bool bFirst = true;
2035*cdf0e10cSrcweir 			do
2036*cdf0e10cSrcweir 			{
2037*cdf0e10cSrcweir 				// create a par container for the next click node and all following with and after effects
2038*cdf0e10cSrcweir 				Reference< XTimeContainer > xOnClickContainer( createParallelTimeContainer() );
2039*cdf0e10cSrcweir 
2040*cdf0e10cSrcweir 				Event aEvent;
2041*cdf0e10cSrcweir 				if( mxEventSource.is() )
2042*cdf0e10cSrcweir                 {
2043*cdf0e10cSrcweir 					aEvent.Source <<= mxEventSource;
2044*cdf0e10cSrcweir                     aEvent.Trigger = EventTrigger::ON_CLICK;
2045*cdf0e10cSrcweir                 }
2046*cdf0e10cSrcweir                 else
2047*cdf0e10cSrcweir                 {
2048*cdf0e10cSrcweir                     aEvent.Trigger = EventTrigger::ON_NEXT;
2049*cdf0e10cSrcweir                 }
2050*cdf0e10cSrcweir                 aEvent.Repeat = 0;
2051*cdf0e10cSrcweir 
2052*cdf0e10cSrcweir 				Any aBegin( makeAny( aEvent ) );
2053*cdf0e10cSrcweir 				if( bFirst )
2054*cdf0e10cSrcweir 				{
2055*cdf0e10cSrcweir 					// if the first node is not a click action, this click container
2056*cdf0e10cSrcweir 					// must not have INDEFINITE begin but start at 0s
2057*cdf0e10cSrcweir 					bFirst = false;
2058*cdf0e10cSrcweir 					if( pEffect->getNodeType() != EffectNodeType::ON_CLICK )
2059*cdf0e10cSrcweir 						aBegin <<= (double)0.0;
2060*cdf0e10cSrcweir 				}
2061*cdf0e10cSrcweir 
2062*cdf0e10cSrcweir 				xOnClickContainer->setBegin( aBegin );
2063*cdf0e10cSrcweir 
2064*cdf0e10cSrcweir 				Reference< XAnimationNode > xOnClickContainerNode( xOnClickContainer, UNO_QUERY_THROW );
2065*cdf0e10cSrcweir 				mxSequenceRoot->appendChild( xOnClickContainerNode );
2066*cdf0e10cSrcweir 
2067*cdf0e10cSrcweir 				double fBegin = 0.0;
2068*cdf0e10cSrcweir 
2069*cdf0e10cSrcweir 				do
2070*cdf0e10cSrcweir 				{
2071*cdf0e10cSrcweir 					// create a par container for the current click or after effect node and all following with effects
2072*cdf0e10cSrcweir 					Reference< XTimeContainer > xWithContainer( createParallelTimeContainer() );
2073*cdf0e10cSrcweir 					Reference< XAnimationNode > xWithContainerNode( xWithContainer, UNO_QUERY_THROW );
2074*cdf0e10cSrcweir 					xWithContainer->setBegin( makeAny( fBegin ) );
2075*cdf0e10cSrcweir 					xOnClickContainer->appendChild( xWithContainerNode );
2076*cdf0e10cSrcweir 
2077*cdf0e10cSrcweir 					double fDuration = 0.0;
2078*cdf0e10cSrcweir 					do
2079*cdf0e10cSrcweir 					{
2080*cdf0e10cSrcweir 						Reference< XAnimationNode > xEffectNode( pEffect->getNode() );
2081*cdf0e10cSrcweir 						xWithContainer->appendChild( xEffectNode );
2082*cdf0e10cSrcweir 
2083*cdf0e10cSrcweir 						if( pEffect->hasAfterEffect() )
2084*cdf0e10cSrcweir 						{
2085*cdf0e10cSrcweir 							Reference< XAnimationNode > xAfterEffect( pEffect->createAfterEffectNode() );
2086*cdf0e10cSrcweir 							AfterEffectNode a( xAfterEffect, xEffectNode, pEffect->IsAfterEffectOnNext() );
2087*cdf0e10cSrcweir 							aAfterEffects.push_back( a );
2088*cdf0e10cSrcweir 						}
2089*cdf0e10cSrcweir 
2090*cdf0e10cSrcweir 						double fTemp = pEffect->getBegin() + pEffect->getAbsoluteDuration();
2091*cdf0e10cSrcweir 						if( fTemp > fDuration )
2092*cdf0e10cSrcweir 							fDuration = fTemp;
2093*cdf0e10cSrcweir 
2094*cdf0e10cSrcweir 						if( aIter != aEnd )
2095*cdf0e10cSrcweir 							pEffect = (*aIter++);
2096*cdf0e10cSrcweir 						else
2097*cdf0e10cSrcweir 							pEffect.reset();
2098*cdf0e10cSrcweir 					}
2099*cdf0e10cSrcweir 					while( pEffect.get() && (pEffect->getNodeType() == EffectNodeType::WITH_PREVIOUS) );
2100*cdf0e10cSrcweir 
2101*cdf0e10cSrcweir 					fBegin += fDuration;
2102*cdf0e10cSrcweir 				}
2103*cdf0e10cSrcweir 				while( pEffect.get() && (pEffect->getNodeType() != EffectNodeType::ON_CLICK) );
2104*cdf0e10cSrcweir 			}
2105*cdf0e10cSrcweir 			while( pEffect.get() );
2106*cdf0e10cSrcweir 
2107*cdf0e10cSrcweir 			// process after effect nodes
2108*cdf0e10cSrcweir 			std::for_each( aAfterEffects.begin(), aAfterEffects.end(), stl_process_after_effect_node_func );
2109*cdf0e10cSrcweir 
2110*cdf0e10cSrcweir 			updateTextGroups();
2111*cdf0e10cSrcweir 
2112*cdf0e10cSrcweir             // reset duration, might have been altered (see below)
2113*cdf0e10cSrcweir             mxSequenceRoot->setDuration( Any() );
2114*cdf0e10cSrcweir 		}
2115*cdf0e10cSrcweir         else
2116*cdf0e10cSrcweir         {
2117*cdf0e10cSrcweir             // empty sequence, set duration to 0.0 explicitely
2118*cdf0e10cSrcweir             // (otherwise, this sequence will never end)
2119*cdf0e10cSrcweir             mxSequenceRoot->setDuration( makeAny((double)0.0) );
2120*cdf0e10cSrcweir         }
2121*cdf0e10cSrcweir 	}
2122*cdf0e10cSrcweir 	catch( Exception& e )
2123*cdf0e10cSrcweir 	{
2124*cdf0e10cSrcweir 		(void)e;
2125*cdf0e10cSrcweir 		DBG_ERROR( "sd::EffectSequenceHelper::rebuild(), exception cought!" );
2126*cdf0e10cSrcweir 	}
2127*cdf0e10cSrcweir }
2128*cdf0e10cSrcweir 
2129*cdf0e10cSrcweir // --------------------------------------------------------------------
2130*cdf0e10cSrcweir 
2131*cdf0e10cSrcweir Reference< XTimeContainer > EffectSequenceHelper::createParallelTimeContainer() const
2132*cdf0e10cSrcweir {
2133*cdf0e10cSrcweir 	const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.animations.ParallelTimeContainer" ) );
2134*cdf0e10cSrcweir 	return Reference< XTimeContainer >( ::comphelper::getProcessServiceFactory()->createInstance(aServiceName), UNO_QUERY );
2135*cdf0e10cSrcweir }
2136*cdf0e10cSrcweir 
2137*cdf0e10cSrcweir // --------------------------------------------------------------------
2138*cdf0e10cSrcweir 
2139*cdf0e10cSrcweir stl_CustomAnimationEffect_search_node_predict::stl_CustomAnimationEffect_search_node_predict( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xSearchNode )
2140*cdf0e10cSrcweir : mxSearchNode( xSearchNode )
2141*cdf0e10cSrcweir {
2142*cdf0e10cSrcweir }
2143*cdf0e10cSrcweir 
2144*cdf0e10cSrcweir // --------------------------------------------------------------------
2145*cdf0e10cSrcweir 
2146*cdf0e10cSrcweir bool stl_CustomAnimationEffect_search_node_predict::operator()( CustomAnimationEffectPtr pEffect ) const
2147*cdf0e10cSrcweir {
2148*cdf0e10cSrcweir 	return pEffect->getNode() == mxSearchNode;
2149*cdf0e10cSrcweir }
2150*cdf0e10cSrcweir 
2151*cdf0e10cSrcweir // --------------------------------------------------------------------
2152*cdf0e10cSrcweir 
2153*cdf0e10cSrcweir static bool implFindNextContainer( Reference< XTimeContainer >& xParent, Reference< XTimeContainer >& xCurrent, Reference< XTimeContainer >& xNext )
2154*cdf0e10cSrcweir  throw(Exception)
2155*cdf0e10cSrcweir {
2156*cdf0e10cSrcweir 	Reference< XEnumerationAccess > xEnumerationAccess( xParent, UNO_QUERY_THROW );
2157*cdf0e10cSrcweir 	Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration() );
2158*cdf0e10cSrcweir 	if( xEnumeration.is() )
2159*cdf0e10cSrcweir 	{
2160*cdf0e10cSrcweir 		Reference< XInterface > x;
2161*cdf0e10cSrcweir 		while( xEnumeration->hasMoreElements() && !xNext.is() )
2162*cdf0e10cSrcweir 		{
2163*cdf0e10cSrcweir 			if( (xEnumeration->nextElement() >>= x) && (x == xCurrent) )
2164*cdf0e10cSrcweir 			{
2165*cdf0e10cSrcweir 				if( xEnumeration->hasMoreElements() )
2166*cdf0e10cSrcweir 					xEnumeration->nextElement() >>= xNext;
2167*cdf0e10cSrcweir 			}
2168*cdf0e10cSrcweir 		}
2169*cdf0e10cSrcweir 	}
2170*cdf0e10cSrcweir 	return xNext.is();
2171*cdf0e10cSrcweir }
2172*cdf0e10cSrcweir 
2173*cdf0e10cSrcweir // --------------------------------------------------------------------
2174*cdf0e10cSrcweir 
2175*cdf0e10cSrcweir void stl_process_after_effect_node_func(AfterEffectNode& rNode)
2176*cdf0e10cSrcweir {
2177*cdf0e10cSrcweir 	try
2178*cdf0e10cSrcweir 	{
2179*cdf0e10cSrcweir 		if( rNode.mxNode.is() && rNode.mxMaster.is() )
2180*cdf0e10cSrcweir 		{
2181*cdf0e10cSrcweir 			// set master node
2182*cdf0e10cSrcweir 			Reference< XAnimationNode > xMasterNode( rNode.mxMaster, UNO_QUERY_THROW );
2183*cdf0e10cSrcweir 			Sequence< NamedValue > aUserData( rNode.mxNode->getUserData() );
2184*cdf0e10cSrcweir 			sal_Int32 nSize = aUserData.getLength();
2185*cdf0e10cSrcweir 			aUserData.realloc(nSize+1);
2186*cdf0e10cSrcweir 			aUserData[nSize].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "master-element" ) );
2187*cdf0e10cSrcweir 			aUserData[nSize].Value <<= xMasterNode;
2188*cdf0e10cSrcweir 			rNode.mxNode->setUserData( aUserData );
2189*cdf0e10cSrcweir 
2190*cdf0e10cSrcweir 			// insert after effect node into timeline
2191*cdf0e10cSrcweir 			Reference< XTimeContainer > xContainer( rNode.mxMaster->getParent(), UNO_QUERY_THROW );
2192*cdf0e10cSrcweir 
2193*cdf0e10cSrcweir 			if( !rNode.mbOnNextEffect ) // sameClick
2194*cdf0e10cSrcweir 			{
2195*cdf0e10cSrcweir 				// insert the aftereffect after its effect is animated
2196*cdf0e10cSrcweir 				xContainer->insertAfter( rNode.mxNode, rNode.mxMaster );
2197*cdf0e10cSrcweir 			}
2198*cdf0e10cSrcweir 			else // nextClick
2199*cdf0e10cSrcweir 			{
2200*cdf0e10cSrcweir 				Reference< XMultiServiceFactory > xMsf( ::comphelper::getProcessServiceFactory() );
2201*cdf0e10cSrcweir 				// insert the aftereffect in the next group
2202*cdf0e10cSrcweir 
2203*cdf0e10cSrcweir 				Reference< XTimeContainer > xClickContainer( xContainer->getParent(), UNO_QUERY_THROW );
2204*cdf0e10cSrcweir 				Reference< XTimeContainer > xSequenceContainer( xClickContainer->getParent(), UNO_QUERY_THROW );
2205*cdf0e10cSrcweir 
2206*cdf0e10cSrcweir 				Reference< XTimeContainer > xNextContainer;
2207*cdf0e10cSrcweir 
2208*cdf0e10cSrcweir 				// first try if we have an after effect container
2209*cdf0e10cSrcweir 				if( !implFindNextContainer( xClickContainer, xContainer, xNextContainer ) )
2210*cdf0e10cSrcweir 				{
2211*cdf0e10cSrcweir 					Reference< XTimeContainer > xNextClickContainer;
2212*cdf0e10cSrcweir 					// if not, try to find the next click effect container
2213*cdf0e10cSrcweir 					if( implFindNextContainer( xSequenceContainer, xClickContainer, xNextClickContainer ) )
2214*cdf0e10cSrcweir 					{
2215*cdf0e10cSrcweir 						Reference< XEnumerationAccess > xEnumerationAccess( xNextClickContainer, UNO_QUERY_THROW );
2216*cdf0e10cSrcweir 						Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
2217*cdf0e10cSrcweir 						if( xEnumeration->hasMoreElements() )
2218*cdf0e10cSrcweir 						{
2219*cdf0e10cSrcweir 							// the next container is the first child container
2220*cdf0e10cSrcweir 							xEnumeration->nextElement() >>= xNextContainer;
2221*cdf0e10cSrcweir 						}
2222*cdf0e10cSrcweir 						else
2223*cdf0e10cSrcweir 						{
2224*cdf0e10cSrcweir 							// this does not yet have a child container, create one
2225*cdf0e10cSrcweir 							const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.animations.ParallelTimeContainer") );
2226*cdf0e10cSrcweir 							xNextContainer = Reference< XTimeContainer >::query( xMsf->createInstance(aServiceName) );
2227*cdf0e10cSrcweir 
2228*cdf0e10cSrcweir 							if( xNextContainer.is() )
2229*cdf0e10cSrcweir 							{
2230*cdf0e10cSrcweir 								Reference< XAnimationNode > xNode( xNextContainer, UNO_QUERY_THROW );
2231*cdf0e10cSrcweir 								xNode->setBegin( makeAny( (double)0.0 ) );
2232*cdf0e10cSrcweir //								xNode->setFill( AnimationFill::HOLD );
2233*cdf0e10cSrcweir 								xNextClickContainer->appendChild( xNode );
2234*cdf0e10cSrcweir 							}
2235*cdf0e10cSrcweir 						}
2236*cdf0e10cSrcweir 						DBG_ASSERT( xNextContainer.is(), "ppt::stl_process_after_effect_node_func::operator(), could not find/create container!" );
2237*cdf0e10cSrcweir 					}
2238*cdf0e10cSrcweir 				}
2239*cdf0e10cSrcweir 
2240*cdf0e10cSrcweir 				// if we don't have a next container, we add one to the sequence container
2241*cdf0e10cSrcweir 				if( !xNextContainer.is() )
2242*cdf0e10cSrcweir 				{
2243*cdf0e10cSrcweir 					const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.animations.ParallelTimeContainer") );
2244*cdf0e10cSrcweir 					Reference< XTimeContainer > xNewClickContainer( xMsf->createInstance(aServiceName), UNO_QUERY_THROW );
2245*cdf0e10cSrcweir 
2246*cdf0e10cSrcweir 					Reference< XAnimationNode > xNewClickNode( xNewClickContainer, UNO_QUERY_THROW );
2247*cdf0e10cSrcweir 
2248*cdf0e10cSrcweir                     Event aEvent;
2249*cdf0e10cSrcweir                     aEvent.Trigger = EventTrigger::ON_NEXT;
2250*cdf0e10cSrcweir                     aEvent.Repeat = 0;
2251*cdf0e10cSrcweir 					xNewClickNode->setBegin( makeAny( aEvent ) );
2252*cdf0e10cSrcweir 
2253*cdf0e10cSrcweir 					Reference< XAnimationNode > xRefNode( xClickContainer, UNO_QUERY_THROW );
2254*cdf0e10cSrcweir 					xSequenceContainer->insertAfter( xNewClickNode, xRefNode );
2255*cdf0e10cSrcweir 
2256*cdf0e10cSrcweir 					xNextContainer = Reference< XTimeContainer >::query( xMsf->createInstance(aServiceName) );
2257*cdf0e10cSrcweir 
2258*cdf0e10cSrcweir 					DBG_ASSERT( xNextContainer.is(), "ppt::stl_process_after_effect_node_func::operator(), could not create container!" );
2259*cdf0e10cSrcweir 					if( xNextContainer.is() )
2260*cdf0e10cSrcweir 					{
2261*cdf0e10cSrcweir 						Reference< XAnimationNode > xNode( xNextContainer, UNO_QUERY_THROW );
2262*cdf0e10cSrcweir 						xNode->setBegin( makeAny( (double)0.0 ) );
2263*cdf0e10cSrcweir //						xNode->setFill( AnimationFill::HOLD );
2264*cdf0e10cSrcweir 						xNewClickContainer->appendChild( xNode );
2265*cdf0e10cSrcweir 					}
2266*cdf0e10cSrcweir 				}
2267*cdf0e10cSrcweir 
2268*cdf0e10cSrcweir 				if( xNextContainer.is() )
2269*cdf0e10cSrcweir 				{
2270*cdf0e10cSrcweir 					// find begin time of first element
2271*cdf0e10cSrcweir 					Reference< XEnumerationAccess > xEnumerationAccess( xNextContainer, UNO_QUERY_THROW );
2272*cdf0e10cSrcweir 					Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
2273*cdf0e10cSrcweir 					if( xEnumeration->hasMoreElements() )
2274*cdf0e10cSrcweir 					{
2275*cdf0e10cSrcweir 						Reference< XAnimationNode > xChild;
2276*cdf0e10cSrcweir 						// the next container is the first child container
2277*cdf0e10cSrcweir 						xEnumeration->nextElement() >>= xChild;
2278*cdf0e10cSrcweir 						if( xChild.is() )
2279*cdf0e10cSrcweir 						{
2280*cdf0e10cSrcweir 							Any aBegin( xChild->getBegin() );
2281*cdf0e10cSrcweir 							double fBegin = 0.0;
2282*cdf0e10cSrcweir 							if( (aBegin >>= fBegin) && (fBegin >= 0.0))
2283*cdf0e10cSrcweir 								rNode.mxNode->setBegin( aBegin );
2284*cdf0e10cSrcweir 						}
2285*cdf0e10cSrcweir 					}
2286*cdf0e10cSrcweir 
2287*cdf0e10cSrcweir 					xNextContainer->appendChild( rNode.mxNode );
2288*cdf0e10cSrcweir 				}
2289*cdf0e10cSrcweir 			}
2290*cdf0e10cSrcweir 		}
2291*cdf0e10cSrcweir 	}
2292*cdf0e10cSrcweir 	catch( Exception& e )
2293*cdf0e10cSrcweir 	{
2294*cdf0e10cSrcweir 		(void)e;
2295*cdf0e10cSrcweir 		DBG_ERROR( "ppt::stl_process_after_effect_node_func::operator(), exception cought!" );
2296*cdf0e10cSrcweir 	}
2297*cdf0e10cSrcweir }
2298*cdf0e10cSrcweir 
2299*cdf0e10cSrcweir // --------------------------------------------------------------------
2300*cdf0e10cSrcweir 
2301*cdf0e10cSrcweir EffectSequence::iterator EffectSequenceHelper::find( const CustomAnimationEffectPtr& pEffect )
2302*cdf0e10cSrcweir {
2303*cdf0e10cSrcweir 	return std::find( maEffects.begin(), maEffects.end(), pEffect );
2304*cdf0e10cSrcweir }
2305*cdf0e10cSrcweir 
2306*cdf0e10cSrcweir // --------------------------------------------------------------------
2307*cdf0e10cSrcweir 
2308*cdf0e10cSrcweir CustomAnimationEffectPtr EffectSequenceHelper::findEffect( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode ) const
2309*cdf0e10cSrcweir {
2310*cdf0e10cSrcweir 	CustomAnimationEffectPtr pEffect;
2311*cdf0e10cSrcweir 
2312*cdf0e10cSrcweir 	EffectSequence::const_iterator aIter( maEffects.begin() );
2313*cdf0e10cSrcweir 	for( ; aIter != maEffects.end(); aIter++ )
2314*cdf0e10cSrcweir 	{
2315*cdf0e10cSrcweir 		if( (*aIter)->getNode() == xNode )
2316*cdf0e10cSrcweir 		{
2317*cdf0e10cSrcweir 			pEffect = (*aIter);
2318*cdf0e10cSrcweir 			break;
2319*cdf0e10cSrcweir 		}
2320*cdf0e10cSrcweir 	}
2321*cdf0e10cSrcweir 
2322*cdf0e10cSrcweir 	return pEffect;
2323*cdf0e10cSrcweir }
2324*cdf0e10cSrcweir 
2325*cdf0e10cSrcweir // --------------------------------------------------------------------
2326*cdf0e10cSrcweir 
2327*cdf0e10cSrcweir sal_Int32 EffectSequenceHelper::getOffsetFromEffect( const CustomAnimationEffectPtr& xEffect ) const
2328*cdf0e10cSrcweir {
2329*cdf0e10cSrcweir 	sal_Int32 nOffset = 0;
2330*cdf0e10cSrcweir 
2331*cdf0e10cSrcweir 	EffectSequence::const_iterator aIter( maEffects.begin() );
2332*cdf0e10cSrcweir 	for( ; aIter != maEffects.end(); aIter++, nOffset++ )
2333*cdf0e10cSrcweir 	{
2334*cdf0e10cSrcweir 		if( (*aIter) == xEffect )
2335*cdf0e10cSrcweir 			return nOffset;
2336*cdf0e10cSrcweir 	}
2337*cdf0e10cSrcweir 
2338*cdf0e10cSrcweir 	return -1;
2339*cdf0e10cSrcweir }
2340*cdf0e10cSrcweir 
2341*cdf0e10cSrcweir // --------------------------------------------------------------------
2342*cdf0e10cSrcweir 
2343*cdf0e10cSrcweir CustomAnimationEffectPtr EffectSequenceHelper::getEffectFromOffset( sal_Int32 nOffset ) const
2344*cdf0e10cSrcweir {
2345*cdf0e10cSrcweir 	EffectSequence::const_iterator aIter( maEffects.begin() );
2346*cdf0e10cSrcweir 	while( nOffset-- && aIter != maEffects.end() )
2347*cdf0e10cSrcweir 		aIter++;
2348*cdf0e10cSrcweir 
2349*cdf0e10cSrcweir 	CustomAnimationEffectPtr pEffect;
2350*cdf0e10cSrcweir 	if( aIter != maEffects.end() )
2351*cdf0e10cSrcweir 		pEffect = (*aIter);
2352*cdf0e10cSrcweir 
2353*cdf0e10cSrcweir 	return pEffect;
2354*cdf0e10cSrcweir }
2355*cdf0e10cSrcweir 
2356*cdf0e10cSrcweir // --------------------------------------------------------------------
2357*cdf0e10cSrcweir 
2358*cdf0e10cSrcweir bool EffectSequenceHelper::disposeShape( const Reference< XShape >& xShape )
2359*cdf0e10cSrcweir {
2360*cdf0e10cSrcweir 	bool bChanges = false;
2361*cdf0e10cSrcweir 
2362*cdf0e10cSrcweir 	EffectSequence::iterator aIter( maEffects.begin() );
2363*cdf0e10cSrcweir 	while( aIter != maEffects.end() )
2364*cdf0e10cSrcweir 	{
2365*cdf0e10cSrcweir 		if( (*aIter)->getTargetShape() == xShape )
2366*cdf0e10cSrcweir 		{
2367*cdf0e10cSrcweir 			(*aIter)->setEffectSequence( 0 );
2368*cdf0e10cSrcweir 			bChanges = true;
2369*cdf0e10cSrcweir 			aIter = maEffects.erase( aIter );
2370*cdf0e10cSrcweir 		}
2371*cdf0e10cSrcweir 		else
2372*cdf0e10cSrcweir 		{
2373*cdf0e10cSrcweir 			aIter++;
2374*cdf0e10cSrcweir 		}
2375*cdf0e10cSrcweir 	}
2376*cdf0e10cSrcweir 
2377*cdf0e10cSrcweir 	return bChanges;
2378*cdf0e10cSrcweir }
2379*cdf0e10cSrcweir 
2380*cdf0e10cSrcweir // --------------------------------------------------------------------
2381*cdf0e10cSrcweir 
2382*cdf0e10cSrcweir bool EffectSequenceHelper::hasEffect( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape )
2383*cdf0e10cSrcweir {
2384*cdf0e10cSrcweir 	EffectSequence::iterator aIter( maEffects.begin() );
2385*cdf0e10cSrcweir 	while( aIter != maEffects.end() )
2386*cdf0e10cSrcweir 	{
2387*cdf0e10cSrcweir 		if( (*aIter)->getTargetShape() == xShape )
2388*cdf0e10cSrcweir 			return true;
2389*cdf0e10cSrcweir 		aIter++;
2390*cdf0e10cSrcweir 	}
2391*cdf0e10cSrcweir 
2392*cdf0e10cSrcweir 	return false;
2393*cdf0e10cSrcweir }
2394*cdf0e10cSrcweir 
2395*cdf0e10cSrcweir // --------------------------------------------------------------------
2396*cdf0e10cSrcweir 
2397*cdf0e10cSrcweir void EffectSequenceHelper::insertTextRange( const com::sun::star::uno::Any& aTarget )
2398*cdf0e10cSrcweir {
2399*cdf0e10cSrcweir 	bool bChanges = false;
2400*cdf0e10cSrcweir 
2401*cdf0e10cSrcweir 	ParagraphTarget aParaTarget;
2402*cdf0e10cSrcweir 	if( !(aTarget >>= aParaTarget ) )
2403*cdf0e10cSrcweir 		return;
2404*cdf0e10cSrcweir 
2405*cdf0e10cSrcweir 	EffectSequence::iterator aIter( maEffects.begin() );
2406*cdf0e10cSrcweir 	while( aIter != maEffects.end() )
2407*cdf0e10cSrcweir 	{
2408*cdf0e10cSrcweir 		if( (*aIter)->getTargetShape() == aParaTarget.Shape )
2409*cdf0e10cSrcweir 			bChanges |= (*aIter)->checkForText();
2410*cdf0e10cSrcweir 		aIter++;
2411*cdf0e10cSrcweir 	}
2412*cdf0e10cSrcweir 
2413*cdf0e10cSrcweir 	if( bChanges )
2414*cdf0e10cSrcweir 		rebuild();
2415*cdf0e10cSrcweir }
2416*cdf0e10cSrcweir 
2417*cdf0e10cSrcweir // --------------------------------------------------------------------
2418*cdf0e10cSrcweir 
2419*cdf0e10cSrcweir void EffectSequenceHelper::disposeTextRange( const com::sun::star::uno::Any& aTarget )
2420*cdf0e10cSrcweir {
2421*cdf0e10cSrcweir 	ParagraphTarget aParaTarget;
2422*cdf0e10cSrcweir 	if( !(aTarget >>= aParaTarget ) )
2423*cdf0e10cSrcweir 		return;
2424*cdf0e10cSrcweir 
2425*cdf0e10cSrcweir 	bool bChanges = false;
2426*cdf0e10cSrcweir 	bool bErased = false;
2427*cdf0e10cSrcweir 
2428*cdf0e10cSrcweir 	EffectSequence::iterator aIter( maEffects.begin() );
2429*cdf0e10cSrcweir 	while( aIter != maEffects.end() )
2430*cdf0e10cSrcweir 	{
2431*cdf0e10cSrcweir 		Any aIterTarget( (*aIter)->getTarget() );
2432*cdf0e10cSrcweir 		if( aIterTarget.getValueType() == ::getCppuType((const ParagraphTarget*)0) )
2433*cdf0e10cSrcweir 		{
2434*cdf0e10cSrcweir 			ParagraphTarget aIterParaTarget;
2435*cdf0e10cSrcweir 			if( (aIterTarget >>= aIterParaTarget) && (aIterParaTarget.Shape == aParaTarget.Shape) )
2436*cdf0e10cSrcweir 			{
2437*cdf0e10cSrcweir 				if( aIterParaTarget.Paragraph == aParaTarget.Paragraph )
2438*cdf0e10cSrcweir 				{
2439*cdf0e10cSrcweir 					// delete this effect if it targets the disposed paragraph directly
2440*cdf0e10cSrcweir 					(*aIter)->setEffectSequence( 0 );
2441*cdf0e10cSrcweir 					aIter = maEffects.erase( aIter );
2442*cdf0e10cSrcweir 					bChanges = true;
2443*cdf0e10cSrcweir 					bErased = true;
2444*cdf0e10cSrcweir 				}
2445*cdf0e10cSrcweir 				else
2446*cdf0e10cSrcweir 				{
2447*cdf0e10cSrcweir 					if( aIterParaTarget.Paragraph > aParaTarget.Paragraph )
2448*cdf0e10cSrcweir 					{
2449*cdf0e10cSrcweir 						// shift all paragraphs after disposed paragraph
2450*cdf0e10cSrcweir 						aIterParaTarget.Paragraph--;
2451*cdf0e10cSrcweir 						(*aIter)->setTarget( makeAny( aIterParaTarget ) );
2452*cdf0e10cSrcweir 					}
2453*cdf0e10cSrcweir 				}
2454*cdf0e10cSrcweir 			}
2455*cdf0e10cSrcweir 		}
2456*cdf0e10cSrcweir 		else if( (*aIter)->getTargetShape() == aParaTarget.Shape )
2457*cdf0e10cSrcweir 		{
2458*cdf0e10cSrcweir 			bChanges |= (*aIter)->checkForText();
2459*cdf0e10cSrcweir 		}
2460*cdf0e10cSrcweir 
2461*cdf0e10cSrcweir 		if( bErased )
2462*cdf0e10cSrcweir 			bErased = false;
2463*cdf0e10cSrcweir 		else
2464*cdf0e10cSrcweir 			aIter++;
2465*cdf0e10cSrcweir 	}
2466*cdf0e10cSrcweir 
2467*cdf0e10cSrcweir 	if( bChanges )
2468*cdf0e10cSrcweir 		rebuild();
2469*cdf0e10cSrcweir }
2470*cdf0e10cSrcweir 
2471*cdf0e10cSrcweir // --------------------------------------------------------------------
2472*cdf0e10cSrcweir 
2473*cdf0e10cSrcweir CustomAnimationTextGroup::CustomAnimationTextGroup( const Reference< XShape >& rTarget, sal_Int32 nGroupId )
2474*cdf0e10cSrcweir :	maTarget( rTarget ),
2475*cdf0e10cSrcweir 	mnGroupId( nGroupId )
2476*cdf0e10cSrcweir {
2477*cdf0e10cSrcweir 	reset();
2478*cdf0e10cSrcweir }
2479*cdf0e10cSrcweir 
2480*cdf0e10cSrcweir // --------------------------------------------------------------------
2481*cdf0e10cSrcweir 
2482*cdf0e10cSrcweir void CustomAnimationTextGroup::reset()
2483*cdf0e10cSrcweir {
2484*cdf0e10cSrcweir 	mnTextGrouping = -1;
2485*cdf0e10cSrcweir 	mbAnimateForm = false;
2486*cdf0e10cSrcweir 	mbTextReverse = false;
2487*cdf0e10cSrcweir 	mfGroupingAuto = -1.0;
2488*cdf0e10cSrcweir 	mnLastPara = -1; // used to check for TextReverse
2489*cdf0e10cSrcweir 
2490*cdf0e10cSrcweir 	int i = 5;
2491*cdf0e10cSrcweir 	while( i-- ) mnDepthFlags[i] = 0;
2492*cdf0e10cSrcweir 
2493*cdf0e10cSrcweir 	maEffects.clear();
2494*cdf0e10cSrcweir }
2495*cdf0e10cSrcweir 
2496*cdf0e10cSrcweir // --------------------------------------------------------------------
2497*cdf0e10cSrcweir 
2498*cdf0e10cSrcweir void CustomAnimationTextGroup::addEffect( CustomAnimationEffectPtr& pEffect )
2499*cdf0e10cSrcweir {
2500*cdf0e10cSrcweir 	maEffects.push_back( pEffect );
2501*cdf0e10cSrcweir 
2502*cdf0e10cSrcweir 	Any aTarget( pEffect->getTarget() );
2503*cdf0e10cSrcweir 	if( aTarget.getValueType() == ::getCppuType((const ParagraphTarget*)0) )
2504*cdf0e10cSrcweir 	{
2505*cdf0e10cSrcweir 		// now look at the paragraph
2506*cdf0e10cSrcweir 		ParagraphTarget aParaTarget;
2507*cdf0e10cSrcweir 		aTarget >>= aParaTarget;
2508*cdf0e10cSrcweir 
2509*cdf0e10cSrcweir 		if( mnLastPara != -1 )
2510*cdf0e10cSrcweir 			mbTextReverse = mnLastPara > aParaTarget.Paragraph;
2511*cdf0e10cSrcweir 
2512*cdf0e10cSrcweir 		mnLastPara = aParaTarget.Paragraph;
2513*cdf0e10cSrcweir 
2514*cdf0e10cSrcweir 		const sal_Int32 nParaDepth = pEffect->getParaDepth();
2515*cdf0e10cSrcweir 
2516*cdf0e10cSrcweir 		// only look at the first 5 levels
2517*cdf0e10cSrcweir 		if( nParaDepth < 5 )
2518*cdf0e10cSrcweir 		{
2519*cdf0e10cSrcweir 			// our first paragraph with this level?
2520*cdf0e10cSrcweir 			if( mnDepthFlags[nParaDepth] == 0 )
2521*cdf0e10cSrcweir 			{
2522*cdf0e10cSrcweir 				// so set it to the first found
2523*cdf0e10cSrcweir 				mnDepthFlags[nParaDepth] = (sal_Int8)pEffect->getNodeType();
2524*cdf0e10cSrcweir 			}
2525*cdf0e10cSrcweir 			else if( mnDepthFlags[nParaDepth] != pEffect->getNodeType() )
2526*cdf0e10cSrcweir 			{
2527*cdf0e10cSrcweir 				mnDepthFlags[nParaDepth] = -1;
2528*cdf0e10cSrcweir 			}
2529*cdf0e10cSrcweir 
2530*cdf0e10cSrcweir 			if( pEffect->getNodeType() == EffectNodeType::AFTER_PREVIOUS )
2531*cdf0e10cSrcweir 				mfGroupingAuto = pEffect->getBegin();
2532*cdf0e10cSrcweir 
2533*cdf0e10cSrcweir 			mnTextGrouping = 0;
2534*cdf0e10cSrcweir 			while( (mnTextGrouping < 5) && (mnDepthFlags[mnTextGrouping] > 0) )
2535*cdf0e10cSrcweir 				mnTextGrouping++;
2536*cdf0e10cSrcweir 		}
2537*cdf0e10cSrcweir 	}
2538*cdf0e10cSrcweir 	else
2539*cdf0e10cSrcweir 	{
2540*cdf0e10cSrcweir 		// if we have an effect with the shape as a target, we animate the background
2541*cdf0e10cSrcweir 		mbAnimateForm = pEffect->getTargetSubItem() != ShapeAnimationSubType::ONLY_TEXT;
2542*cdf0e10cSrcweir 	}
2543*cdf0e10cSrcweir }
2544*cdf0e10cSrcweir 
2545*cdf0e10cSrcweir // --------------------------------------------------------------------
2546*cdf0e10cSrcweir 
2547*cdf0e10cSrcweir class TextGroupMapImpl : public std::map< sal_Int32, CustomAnimationTextGroup* >
2548*cdf0e10cSrcweir {
2549*cdf0e10cSrcweir public:
2550*cdf0e10cSrcweir 	CustomAnimationTextGroup* findGroup( sal_Int32 nGroupId );
2551*cdf0e10cSrcweir };
2552*cdf0e10cSrcweir 
2553*cdf0e10cSrcweir // --------------------------------------------------------------------
2554*cdf0e10cSrcweir 
2555*cdf0e10cSrcweir CustomAnimationTextGroupPtr EffectSequenceHelper::findGroup( sal_Int32 nGroupId )
2556*cdf0e10cSrcweir {
2557*cdf0e10cSrcweir 	CustomAnimationTextGroupPtr aPtr;
2558*cdf0e10cSrcweir 
2559*cdf0e10cSrcweir 	CustomAnimationTextGroupMap::iterator aIter( maGroupMap.find( nGroupId ) );
2560*cdf0e10cSrcweir 	if( aIter != maGroupMap.end() )
2561*cdf0e10cSrcweir 		aPtr = (*aIter).second;
2562*cdf0e10cSrcweir 
2563*cdf0e10cSrcweir 	return aPtr;
2564*cdf0e10cSrcweir }
2565*cdf0e10cSrcweir 
2566*cdf0e10cSrcweir // --------------------------------------------------------------------
2567*cdf0e10cSrcweir 
2568*cdf0e10cSrcweir void EffectSequenceHelper::updateTextGroups()
2569*cdf0e10cSrcweir {
2570*cdf0e10cSrcweir 	maGroupMap.clear();
2571*cdf0e10cSrcweir 
2572*cdf0e10cSrcweir 	// first create all the groups
2573*cdf0e10cSrcweir 	EffectSequence::iterator aIter( maEffects.begin() );
2574*cdf0e10cSrcweir 	const EffectSequence::iterator aEnd( maEffects.end() );
2575*cdf0e10cSrcweir 	while( aIter != aEnd )
2576*cdf0e10cSrcweir 	{
2577*cdf0e10cSrcweir 		CustomAnimationEffectPtr pEffect( (*aIter++) );
2578*cdf0e10cSrcweir 
2579*cdf0e10cSrcweir 		const sal_Int32 nGroupId = pEffect->getGroupId();
2580*cdf0e10cSrcweir 
2581*cdf0e10cSrcweir 		if( nGroupId == -1 )
2582*cdf0e10cSrcweir 			continue; // trivial case, no group
2583*cdf0e10cSrcweir 
2584*cdf0e10cSrcweir 		CustomAnimationTextGroupPtr pGroup = findGroup( nGroupId );
2585*cdf0e10cSrcweir 		if( !pGroup.get() )
2586*cdf0e10cSrcweir 		{
2587*cdf0e10cSrcweir 			pGroup.reset( new CustomAnimationTextGroup( pEffect->getTargetShape(), nGroupId ) );
2588*cdf0e10cSrcweir 			maGroupMap[nGroupId] = pGroup;
2589*cdf0e10cSrcweir 		}
2590*cdf0e10cSrcweir 
2591*cdf0e10cSrcweir 		pGroup->addEffect( pEffect );
2592*cdf0e10cSrcweir 	}
2593*cdf0e10cSrcweir }
2594*cdf0e10cSrcweir 
2595*cdf0e10cSrcweir // --------------------------------------------------------------------
2596*cdf0e10cSrcweir 
2597*cdf0e10cSrcweir CustomAnimationTextGroupPtr	EffectSequenceHelper::createTextGroup( CustomAnimationEffectPtr pEffect, sal_Int32 nTextGrouping, double fTextGroupingAuto, sal_Bool bAnimateForm, sal_Bool bTextReverse )
2598*cdf0e10cSrcweir {
2599*cdf0e10cSrcweir 	// first finde a free group-id
2600*cdf0e10cSrcweir 	sal_Int32 nGroupId = 0;
2601*cdf0e10cSrcweir 
2602*cdf0e10cSrcweir 	CustomAnimationTextGroupMap::iterator aIter( maGroupMap.begin() );
2603*cdf0e10cSrcweir 	const CustomAnimationTextGroupMap::iterator aEnd( maGroupMap.end() );
2604*cdf0e10cSrcweir 	while( aIter != aEnd )
2605*cdf0e10cSrcweir 	{
2606*cdf0e10cSrcweir 		if( (*aIter).first == nGroupId )
2607*cdf0e10cSrcweir 		{
2608*cdf0e10cSrcweir 			nGroupId++;
2609*cdf0e10cSrcweir 			aIter = maGroupMap.begin();
2610*cdf0e10cSrcweir 		}
2611*cdf0e10cSrcweir 		else
2612*cdf0e10cSrcweir 		{
2613*cdf0e10cSrcweir 			aIter++;
2614*cdf0e10cSrcweir 		}
2615*cdf0e10cSrcweir 	}
2616*cdf0e10cSrcweir 
2617*cdf0e10cSrcweir 	Reference< XShape > xTarget( pEffect->getTargetShape() );
2618*cdf0e10cSrcweir 
2619*cdf0e10cSrcweir 	CustomAnimationTextGroupPtr	pTextGroup( new CustomAnimationTextGroup( xTarget, nGroupId ) );
2620*cdf0e10cSrcweir 	maGroupMap[nGroupId] = pTextGroup;
2621*cdf0e10cSrcweir 
2622*cdf0e10cSrcweir 	bool bUsed = false;
2623*cdf0e10cSrcweir 
2624*cdf0e10cSrcweir 	// do we need to target the shape?
2625*cdf0e10cSrcweir 	if( (nTextGrouping == 0) || bAnimateForm )
2626*cdf0e10cSrcweir 	{
2627*cdf0e10cSrcweir 		sal_Int16 nSubItem;
2628*cdf0e10cSrcweir 		if( nTextGrouping == 0)
2629*cdf0e10cSrcweir 			nSubItem = bAnimateForm ? ShapeAnimationSubType::AS_WHOLE : ShapeAnimationSubType::ONLY_TEXT;
2630*cdf0e10cSrcweir 		else
2631*cdf0e10cSrcweir 			nSubItem = ShapeAnimationSubType::ONLY_BACKGROUND;
2632*cdf0e10cSrcweir 
2633*cdf0e10cSrcweir 		pEffect->setTarget( makeAny( xTarget ) );
2634*cdf0e10cSrcweir 		pEffect->setTargetSubItem( nSubItem );
2635*cdf0e10cSrcweir 		pEffect->setEffectSequence( this );
2636*cdf0e10cSrcweir 		pEffect->setGroupId( nGroupId );
2637*cdf0e10cSrcweir 
2638*cdf0e10cSrcweir 		pTextGroup->addEffect( pEffect );
2639*cdf0e10cSrcweir 		bUsed = true;
2640*cdf0e10cSrcweir 	}
2641*cdf0e10cSrcweir 
2642*cdf0e10cSrcweir 	pTextGroup->mnTextGrouping = nTextGrouping;
2643*cdf0e10cSrcweir 	pTextGroup->mfGroupingAuto = fTextGroupingAuto;
2644*cdf0e10cSrcweir 	pTextGroup->mbTextReverse = bTextReverse;
2645*cdf0e10cSrcweir 
2646*cdf0e10cSrcweir 	// now add an effect for each paragraph
2647*cdf0e10cSrcweir 	createTextGroupParagraphEffects( pTextGroup, pEffect, bUsed );
2648*cdf0e10cSrcweir 
2649*cdf0e10cSrcweir 	notify_listeners();
2650*cdf0e10cSrcweir 
2651*cdf0e10cSrcweir 	return pTextGroup;
2652*cdf0e10cSrcweir }
2653*cdf0e10cSrcweir 
2654*cdf0e10cSrcweir // --------------------------------------------------------------------
2655*cdf0e10cSrcweir 
2656*cdf0e10cSrcweir void EffectSequenceHelper::createTextGroupParagraphEffects( CustomAnimationTextGroupPtr pTextGroup, CustomAnimationEffectPtr pEffect, bool bUsed )
2657*cdf0e10cSrcweir {
2658*cdf0e10cSrcweir 	Reference< XShape > xTarget( pTextGroup->maTarget );
2659*cdf0e10cSrcweir 
2660*cdf0e10cSrcweir 	sal_Int32 nTextGrouping = pTextGroup->mnTextGrouping;
2661*cdf0e10cSrcweir 	double fTextGroupingAuto = pTextGroup->mfGroupingAuto;
2662*cdf0e10cSrcweir 	sal_Bool bTextReverse = pTextGroup->mbTextReverse;
2663*cdf0e10cSrcweir 
2664*cdf0e10cSrcweir 	// now add an effect for each paragraph
2665*cdf0e10cSrcweir 	if( nTextGrouping >= 0 ) try
2666*cdf0e10cSrcweir 	{
2667*cdf0e10cSrcweir 		EffectSequence::iterator aInsertIter( find( pEffect ) );
2668*cdf0e10cSrcweir 
2669*cdf0e10cSrcweir 		const OUString strNumberingLevel( RTL_CONSTASCII_USTRINGPARAM("NumberingLevel") );
2670*cdf0e10cSrcweir 		Reference< XEnumerationAccess > xText( xTarget, UNO_QUERY_THROW );
2671*cdf0e10cSrcweir 		Reference< XEnumeration > xEnumeration( xText->createEnumeration(), UNO_QUERY_THROW );
2672*cdf0e10cSrcweir 
2673*cdf0e10cSrcweir 		std::list< sal_Int16 > aParaList;
2674*cdf0e10cSrcweir 		sal_Int16 nPara;
2675*cdf0e10cSrcweir 
2676*cdf0e10cSrcweir 		// fill the list with all valid paragraphs
2677*cdf0e10cSrcweir 		for( nPara = 0; xEnumeration->hasMoreElements(); nPara++ )
2678*cdf0e10cSrcweir 		{
2679*cdf0e10cSrcweir 			Reference< XTextRange > xRange( xEnumeration->nextElement(), UNO_QUERY );
2680*cdf0e10cSrcweir 			if( xRange.is() && xRange->getString().getLength() )
2681*cdf0e10cSrcweir 			{
2682*cdf0e10cSrcweir 				if( bTextReverse ) // sort them
2683*cdf0e10cSrcweir 					aParaList.push_front( nPara );
2684*cdf0e10cSrcweir 				else
2685*cdf0e10cSrcweir 					aParaList.push_back( nPara );
2686*cdf0e10cSrcweir 			}
2687*cdf0e10cSrcweir 		}
2688*cdf0e10cSrcweir 
2689*cdf0e10cSrcweir 		ParagraphTarget aTarget;
2690*cdf0e10cSrcweir 		aTarget.Shape = xTarget;
2691*cdf0e10cSrcweir 
2692*cdf0e10cSrcweir 		std::list< sal_Int16 >::iterator aIter( aParaList.begin() );
2693*cdf0e10cSrcweir 		std::list< sal_Int16 >::iterator aEnd( aParaList.end() );
2694*cdf0e10cSrcweir 		while( aIter != aEnd )
2695*cdf0e10cSrcweir 		{
2696*cdf0e10cSrcweir 			aTarget.Paragraph = (*aIter++);
2697*cdf0e10cSrcweir 
2698*cdf0e10cSrcweir 			CustomAnimationEffectPtr pNewEffect;
2699*cdf0e10cSrcweir 			if( bUsed )
2700*cdf0e10cSrcweir 			{
2701*cdf0e10cSrcweir 				// clone a new effect from first effect
2702*cdf0e10cSrcweir 				pNewEffect = pEffect->clone();
2703*cdf0e10cSrcweir 				++aInsertIter;
2704*cdf0e10cSrcweir 				aInsertIter = maEffects.insert( aInsertIter, pNewEffect );
2705*cdf0e10cSrcweir 			}
2706*cdf0e10cSrcweir 			else
2707*cdf0e10cSrcweir 			{
2708*cdf0e10cSrcweir 				// reuse first effect if its not yet used
2709*cdf0e10cSrcweir 				pNewEffect = pEffect;
2710*cdf0e10cSrcweir 				bUsed = true;
2711*cdf0e10cSrcweir 				aInsertIter = find( pNewEffect );
2712*cdf0e10cSrcweir 			}
2713*cdf0e10cSrcweir 
2714*cdf0e10cSrcweir 			// set target and group-id
2715*cdf0e10cSrcweir 			pNewEffect->setTarget( makeAny( aTarget ) );
2716*cdf0e10cSrcweir 			pNewEffect->setTargetSubItem( ShapeAnimationSubType::ONLY_TEXT );
2717*cdf0e10cSrcweir 			pNewEffect->setGroupId( pTextGroup->mnGroupId );
2718*cdf0e10cSrcweir 			pNewEffect->setEffectSequence( this );
2719*cdf0e10cSrcweir 
2720*cdf0e10cSrcweir 			// set correct node type
2721*cdf0e10cSrcweir 			if( pNewEffect->getParaDepth() < nTextGrouping )
2722*cdf0e10cSrcweir 			{
2723*cdf0e10cSrcweir 				if( fTextGroupingAuto == -1.0 )
2724*cdf0e10cSrcweir 				{
2725*cdf0e10cSrcweir 					pNewEffect->setNodeType( EffectNodeType::ON_CLICK );
2726*cdf0e10cSrcweir 					pNewEffect->setBegin( 0.0 );
2727*cdf0e10cSrcweir 				}
2728*cdf0e10cSrcweir 				else
2729*cdf0e10cSrcweir 				{
2730*cdf0e10cSrcweir 					pNewEffect->setNodeType( EffectNodeType::AFTER_PREVIOUS );
2731*cdf0e10cSrcweir 					pNewEffect->setBegin( fTextGroupingAuto );
2732*cdf0e10cSrcweir 				}
2733*cdf0e10cSrcweir 			}
2734*cdf0e10cSrcweir 			else
2735*cdf0e10cSrcweir 			{
2736*cdf0e10cSrcweir 				pNewEffect->setNodeType( EffectNodeType::WITH_PREVIOUS );
2737*cdf0e10cSrcweir 				pNewEffect->setBegin( 0.0 );
2738*cdf0e10cSrcweir 			}
2739*cdf0e10cSrcweir 
2740*cdf0e10cSrcweir 			pTextGroup->addEffect( pNewEffect );
2741*cdf0e10cSrcweir 		}
2742*cdf0e10cSrcweir 		notify_listeners();
2743*cdf0e10cSrcweir 	}
2744*cdf0e10cSrcweir 	catch( Exception& e )
2745*cdf0e10cSrcweir 	{
2746*cdf0e10cSrcweir 		(void)e;
2747*cdf0e10cSrcweir 		DBG_ERROR("sd::EffectSequenceHelper::createTextGroup(), exception cought!" );
2748*cdf0e10cSrcweir 	}
2749*cdf0e10cSrcweir }
2750*cdf0e10cSrcweir 
2751*cdf0e10cSrcweir // --------------------------------------------------------------------
2752*cdf0e10cSrcweir 
2753*cdf0e10cSrcweir void EffectSequenceHelper::setTextGrouping( CustomAnimationTextGroupPtr pTextGroup, sal_Int32 nTextGrouping )
2754*cdf0e10cSrcweir {
2755*cdf0e10cSrcweir 	if( pTextGroup->mnTextGrouping == nTextGrouping )
2756*cdf0e10cSrcweir 	{
2757*cdf0e10cSrcweir 		// first case, trivial case, do nothing
2758*cdf0e10cSrcweir 	}
2759*cdf0e10cSrcweir 	else if( (pTextGroup->mnTextGrouping == -1) && (nTextGrouping >= 0) )
2760*cdf0e10cSrcweir 	{
2761*cdf0e10cSrcweir 		// second case, we need to add new effects for each paragraph
2762*cdf0e10cSrcweir 
2763*cdf0e10cSrcweir 		CustomAnimationEffectPtr pEffect( pTextGroup->maEffects.front() );
2764*cdf0e10cSrcweir 
2765*cdf0e10cSrcweir 		pTextGroup->mnTextGrouping = nTextGrouping;
2766*cdf0e10cSrcweir 		createTextGroupParagraphEffects( pTextGroup, pEffect, true );
2767*cdf0e10cSrcweir 		notify_listeners();
2768*cdf0e10cSrcweir 	}
2769*cdf0e10cSrcweir 	else if( (pTextGroup->mnTextGrouping >= 0) && (nTextGrouping == -1 ) )
2770*cdf0e10cSrcweir 	{
2771*cdf0e10cSrcweir 		// third case, we need to remove effects for each paragraph
2772*cdf0e10cSrcweir 
2773*cdf0e10cSrcweir 		EffectSequence aEffects( pTextGroup->maEffects );
2774*cdf0e10cSrcweir 		pTextGroup->reset();
2775*cdf0e10cSrcweir 
2776*cdf0e10cSrcweir 		EffectSequence::iterator aIter( aEffects.begin() );
2777*cdf0e10cSrcweir 		const EffectSequence::iterator aEnd( aEffects.end() );
2778*cdf0e10cSrcweir 		while( aIter != aEnd )
2779*cdf0e10cSrcweir 		{
2780*cdf0e10cSrcweir 			CustomAnimationEffectPtr pEffect( (*aIter++) );
2781*cdf0e10cSrcweir 
2782*cdf0e10cSrcweir 			if( pEffect->getTarget().getValueType() == ::getCppuType((const ParagraphTarget*)0) )
2783*cdf0e10cSrcweir 				remove( pEffect );
2784*cdf0e10cSrcweir 			else
2785*cdf0e10cSrcweir 				pTextGroup->addEffect( pEffect );
2786*cdf0e10cSrcweir 		}
2787*cdf0e10cSrcweir 		notify_listeners();
2788*cdf0e10cSrcweir 	}
2789*cdf0e10cSrcweir 	else
2790*cdf0e10cSrcweir 	{
2791*cdf0e10cSrcweir 		// fourth case, we need to change the node types for the text nodes
2792*cdf0e10cSrcweir 		double fTextGroupingAuto = pTextGroup->mfGroupingAuto;
2793*cdf0e10cSrcweir 
2794*cdf0e10cSrcweir 		EffectSequence aEffects( pTextGroup->maEffects );
2795*cdf0e10cSrcweir 		pTextGroup->reset();
2796*cdf0e10cSrcweir 
2797*cdf0e10cSrcweir 		EffectSequence::iterator aIter( aEffects.begin() );
2798*cdf0e10cSrcweir 		const EffectSequence::iterator aEnd( aEffects.end() );
2799*cdf0e10cSrcweir 		while( aIter != aEnd )
2800*cdf0e10cSrcweir 		{
2801*cdf0e10cSrcweir 			CustomAnimationEffectPtr pEffect( (*aIter++) );
2802*cdf0e10cSrcweir 
2803*cdf0e10cSrcweir 			if( pEffect->getTarget().getValueType() == ::getCppuType((const ParagraphTarget*)0) )
2804*cdf0e10cSrcweir 			{
2805*cdf0e10cSrcweir 				// set correct node type
2806*cdf0e10cSrcweir 				if( pEffect->getParaDepth() < nTextGrouping )
2807*cdf0e10cSrcweir 				{
2808*cdf0e10cSrcweir 					if( fTextGroupingAuto == -1.0 )
2809*cdf0e10cSrcweir 					{
2810*cdf0e10cSrcweir 						pEffect->setNodeType( EffectNodeType::ON_CLICK );
2811*cdf0e10cSrcweir 						pEffect->setBegin( 0.0 );
2812*cdf0e10cSrcweir 					}
2813*cdf0e10cSrcweir 					else
2814*cdf0e10cSrcweir 					{
2815*cdf0e10cSrcweir 						pEffect->setNodeType( EffectNodeType::AFTER_PREVIOUS );
2816*cdf0e10cSrcweir 						pEffect->setBegin( fTextGroupingAuto );
2817*cdf0e10cSrcweir 					}
2818*cdf0e10cSrcweir 				}
2819*cdf0e10cSrcweir 				else
2820*cdf0e10cSrcweir 				{
2821*cdf0e10cSrcweir 					pEffect->setNodeType( EffectNodeType::WITH_PREVIOUS );
2822*cdf0e10cSrcweir 					pEffect->setBegin( 0.0 );
2823*cdf0e10cSrcweir 				}
2824*cdf0e10cSrcweir 			}
2825*cdf0e10cSrcweir 
2826*cdf0e10cSrcweir 			pTextGroup->addEffect( pEffect );
2827*cdf0e10cSrcweir 
2828*cdf0e10cSrcweir 		}
2829*cdf0e10cSrcweir 		notify_listeners();
2830*cdf0e10cSrcweir 	}
2831*cdf0e10cSrcweir }
2832*cdf0e10cSrcweir 
2833*cdf0e10cSrcweir // --------------------------------------------------------------------
2834*cdf0e10cSrcweir 
2835*cdf0e10cSrcweir void EffectSequenceHelper::setAnimateForm( CustomAnimationTextGroupPtr pTextGroup, sal_Bool bAnimateForm )
2836*cdf0e10cSrcweir {
2837*cdf0e10cSrcweir 	if( pTextGroup->mbAnimateForm == bAnimateForm )
2838*cdf0e10cSrcweir 	{
2839*cdf0e10cSrcweir 		// trivial case, do nothing
2840*cdf0e10cSrcweir 	}
2841*cdf0e10cSrcweir 	else
2842*cdf0e10cSrcweir 	{
2843*cdf0e10cSrcweir 		EffectSequence aEffects( pTextGroup->maEffects );
2844*cdf0e10cSrcweir 		pTextGroup->reset();
2845*cdf0e10cSrcweir 
2846*cdf0e10cSrcweir 		EffectSequence::iterator aIter( aEffects.begin() );
2847*cdf0e10cSrcweir 		const EffectSequence::iterator aEnd( aEffects.end() );
2848*cdf0e10cSrcweir 
2849*cdf0e10cSrcweir 		// first insert if we have to
2850*cdf0e10cSrcweir 		if( bAnimateForm )
2851*cdf0e10cSrcweir 		{
2852*cdf0e10cSrcweir 			EffectSequence::iterator aInsertIter( find( (*aIter) ) );
2853*cdf0e10cSrcweir 
2854*cdf0e10cSrcweir 			CustomAnimationEffectPtr pEffect;
2855*cdf0e10cSrcweir 			if( (aEffects.size() == 1) && ((*aIter)->getTarget().getValueType() != ::getCppuType((const ParagraphTarget*)0) ) )
2856*cdf0e10cSrcweir 			{
2857*cdf0e10cSrcweir 				// special case, only one effect and that targets whole text,
2858*cdf0e10cSrcweir 				// convert this to target whole shape
2859*cdf0e10cSrcweir 				pEffect = (*aIter++);
2860*cdf0e10cSrcweir 				pEffect->setTargetSubItem( ShapeAnimationSubType::AS_WHOLE );
2861*cdf0e10cSrcweir 			}
2862*cdf0e10cSrcweir 			else
2863*cdf0e10cSrcweir 			{
2864*cdf0e10cSrcweir 				pEffect = (*aIter)->clone();
2865*cdf0e10cSrcweir 				pEffect->setTarget( makeAny( (*aIter)->getTargetShape() ) );
2866*cdf0e10cSrcweir 				pEffect->setTargetSubItem( ShapeAnimationSubType::ONLY_BACKGROUND );
2867*cdf0e10cSrcweir 				maEffects.insert( aInsertIter, pEffect );
2868*cdf0e10cSrcweir 			}
2869*cdf0e10cSrcweir 
2870*cdf0e10cSrcweir 			pTextGroup->addEffect( pEffect );
2871*cdf0e10cSrcweir 		}
2872*cdf0e10cSrcweir 
2873*cdf0e10cSrcweir 		if( !bAnimateForm && (aEffects.size() == 1) )
2874*cdf0e10cSrcweir 		{
2875*cdf0e10cSrcweir 			CustomAnimationEffectPtr pEffect( (*aIter) );
2876*cdf0e10cSrcweir 			pEffect->setTarget( makeAny( (*aIter)->getTargetShape() ) );
2877*cdf0e10cSrcweir 			pEffect->setTargetSubItem( ShapeAnimationSubType::ONLY_TEXT );
2878*cdf0e10cSrcweir 			pTextGroup->addEffect( pEffect );
2879*cdf0e10cSrcweir 		}
2880*cdf0e10cSrcweir 		else
2881*cdf0e10cSrcweir 		{
2882*cdf0e10cSrcweir 			// readd the rest to the group again
2883*cdf0e10cSrcweir 			while( aIter != aEnd )
2884*cdf0e10cSrcweir 			{
2885*cdf0e10cSrcweir 				CustomAnimationEffectPtr pEffect( (*aIter++) );
2886*cdf0e10cSrcweir 
2887*cdf0e10cSrcweir 				if( pEffect->getTarget().getValueType() == ::getCppuType((const ParagraphTarget*)0) )
2888*cdf0e10cSrcweir 				{
2889*cdf0e10cSrcweir 					pTextGroup->addEffect( pEffect );
2890*cdf0e10cSrcweir 				}
2891*cdf0e10cSrcweir 				else
2892*cdf0e10cSrcweir 				{
2893*cdf0e10cSrcweir 					DBG_ASSERT( !bAnimateForm, "sd::EffectSequenceHelper::setAnimateForm(), something is wrong here!" );
2894*cdf0e10cSrcweir 					remove( pEffect );
2895*cdf0e10cSrcweir 				}
2896*cdf0e10cSrcweir 			}
2897*cdf0e10cSrcweir 		}
2898*cdf0e10cSrcweir 		notify_listeners();
2899*cdf0e10cSrcweir 	}
2900*cdf0e10cSrcweir }
2901*cdf0e10cSrcweir 
2902*cdf0e10cSrcweir // --------------------------------------------------------------------
2903*cdf0e10cSrcweir 
2904*cdf0e10cSrcweir void EffectSequenceHelper::setTextGroupingAuto( CustomAnimationTextGroupPtr pTextGroup, double fTextGroupingAuto )
2905*cdf0e10cSrcweir {
2906*cdf0e10cSrcweir 	sal_Int32 nTextGrouping = pTextGroup->mnTextGrouping;
2907*cdf0e10cSrcweir 
2908*cdf0e10cSrcweir 	EffectSequence aEffects( pTextGroup->maEffects );
2909*cdf0e10cSrcweir 	pTextGroup->reset();
2910*cdf0e10cSrcweir 
2911*cdf0e10cSrcweir 	EffectSequence::iterator aIter( aEffects.begin() );
2912*cdf0e10cSrcweir 	const EffectSequence::iterator aEnd( aEffects.end() );
2913*cdf0e10cSrcweir 	while( aIter != aEnd )
2914*cdf0e10cSrcweir 	{
2915*cdf0e10cSrcweir 		CustomAnimationEffectPtr pEffect( (*aIter++) );
2916*cdf0e10cSrcweir 
2917*cdf0e10cSrcweir 		if( pEffect->getTarget().getValueType() == ::getCppuType((const ParagraphTarget*)0) )
2918*cdf0e10cSrcweir 		{
2919*cdf0e10cSrcweir 			// set correct node type
2920*cdf0e10cSrcweir 			if( pEffect->getParaDepth() < nTextGrouping )
2921*cdf0e10cSrcweir 			{
2922*cdf0e10cSrcweir 				if( fTextGroupingAuto == -1.0 )
2923*cdf0e10cSrcweir 				{
2924*cdf0e10cSrcweir 					pEffect->setNodeType( EffectNodeType::ON_CLICK );
2925*cdf0e10cSrcweir 					pEffect->setBegin( 0.0 );
2926*cdf0e10cSrcweir 				}
2927*cdf0e10cSrcweir 				else
2928*cdf0e10cSrcweir 				{
2929*cdf0e10cSrcweir 					pEffect->setNodeType( EffectNodeType::AFTER_PREVIOUS );
2930*cdf0e10cSrcweir 					pEffect->setBegin( fTextGroupingAuto );
2931*cdf0e10cSrcweir 				}
2932*cdf0e10cSrcweir 			}
2933*cdf0e10cSrcweir 			else
2934*cdf0e10cSrcweir 			{
2935*cdf0e10cSrcweir 				pEffect->setNodeType( EffectNodeType::WITH_PREVIOUS );
2936*cdf0e10cSrcweir 				pEffect->setBegin( 0.0 );
2937*cdf0e10cSrcweir 			}
2938*cdf0e10cSrcweir 		}
2939*cdf0e10cSrcweir 
2940*cdf0e10cSrcweir 		pTextGroup->addEffect( pEffect );
2941*cdf0e10cSrcweir 
2942*cdf0e10cSrcweir 	}
2943*cdf0e10cSrcweir 	notify_listeners();
2944*cdf0e10cSrcweir }
2945*cdf0e10cSrcweir 
2946*cdf0e10cSrcweir // --------------------------------------------------------------------
2947*cdf0e10cSrcweir 
2948*cdf0e10cSrcweir struct ImplStlTextGroupSortHelper
2949*cdf0e10cSrcweir {
2950*cdf0e10cSrcweir 	ImplStlTextGroupSortHelper( bool bReverse ) : mbReverse( bReverse ) {};
2951*cdf0e10cSrcweir 	bool operator()( const CustomAnimationEffectPtr& p1, const CustomAnimationEffectPtr& p2 );
2952*cdf0e10cSrcweir 	bool mbReverse;
2953*cdf0e10cSrcweir 	sal_Int32 getTargetParagraph( const CustomAnimationEffectPtr& p1 );
2954*cdf0e10cSrcweir };
2955*cdf0e10cSrcweir 
2956*cdf0e10cSrcweir // --------------------------------------------------------------------
2957*cdf0e10cSrcweir 
2958*cdf0e10cSrcweir sal_Int32 ImplStlTextGroupSortHelper::getTargetParagraph( const CustomAnimationEffectPtr& p1 )
2959*cdf0e10cSrcweir {
2960*cdf0e10cSrcweir 	const Any aTarget(p1->getTarget());
2961*cdf0e10cSrcweir 	if( aTarget.hasValue() && aTarget.getValueType() == ::getCppuType((const ParagraphTarget*)0) )
2962*cdf0e10cSrcweir 	{
2963*cdf0e10cSrcweir 		ParagraphTarget aParaTarget;
2964*cdf0e10cSrcweir 		aTarget >>= aParaTarget;
2965*cdf0e10cSrcweir 		return aParaTarget.Paragraph;
2966*cdf0e10cSrcweir 	}
2967*cdf0e10cSrcweir 	else
2968*cdf0e10cSrcweir 	{
2969*cdf0e10cSrcweir 		return mbReverse ? 0x7fffffff : -1;
2970*cdf0e10cSrcweir 	}
2971*cdf0e10cSrcweir }
2972*cdf0e10cSrcweir 
2973*cdf0e10cSrcweir // --------------------------------------------------------------------
2974*cdf0e10cSrcweir 
2975*cdf0e10cSrcweir bool ImplStlTextGroupSortHelper::operator()( const CustomAnimationEffectPtr& p1, const CustomAnimationEffectPtr& p2 )
2976*cdf0e10cSrcweir {
2977*cdf0e10cSrcweir 	if( mbReverse )
2978*cdf0e10cSrcweir 	{
2979*cdf0e10cSrcweir 		return getTargetParagraph( p2 ) < getTargetParagraph( p1 );
2980*cdf0e10cSrcweir 	}
2981*cdf0e10cSrcweir 	else
2982*cdf0e10cSrcweir 	{
2983*cdf0e10cSrcweir 		return getTargetParagraph( p1 ) < getTargetParagraph( p2 );
2984*cdf0e10cSrcweir 	}
2985*cdf0e10cSrcweir }
2986*cdf0e10cSrcweir 
2987*cdf0e10cSrcweir // --------------------------------------------------------------------
2988*cdf0e10cSrcweir 
2989*cdf0e10cSrcweir void EffectSequenceHelper::setTextReverse( CustomAnimationTextGroupPtr pTextGroup, sal_Bool bTextReverse )
2990*cdf0e10cSrcweir {
2991*cdf0e10cSrcweir 	if( pTextGroup->mbTextReverse == bTextReverse )
2992*cdf0e10cSrcweir 	{
2993*cdf0e10cSrcweir 		// do nothing
2994*cdf0e10cSrcweir 	}
2995*cdf0e10cSrcweir 	else
2996*cdf0e10cSrcweir 	{
2997*cdf0e10cSrcweir 		std::vector< CustomAnimationEffectPtr > aSortedVector(pTextGroup->maEffects.size());
2998*cdf0e10cSrcweir 		std::copy( pTextGroup->maEffects.begin(), pTextGroup->maEffects.end(), aSortedVector.begin() );
2999*cdf0e10cSrcweir 		ImplStlTextGroupSortHelper aSortHelper( bTextReverse );
3000*cdf0e10cSrcweir 		std::sort( aSortedVector.begin(), aSortedVector.end(), aSortHelper );
3001*cdf0e10cSrcweir 
3002*cdf0e10cSrcweir 		pTextGroup->reset();
3003*cdf0e10cSrcweir 
3004*cdf0e10cSrcweir 		std::vector< CustomAnimationEffectPtr >::iterator aIter( aSortedVector.begin() );
3005*cdf0e10cSrcweir 		const std::vector< CustomAnimationEffectPtr >::iterator aEnd( aSortedVector.end() );
3006*cdf0e10cSrcweir 
3007*cdf0e10cSrcweir 		if( aIter != aEnd )
3008*cdf0e10cSrcweir 		{
3009*cdf0e10cSrcweir 			pTextGroup->addEffect( (*aIter ) );
3010*cdf0e10cSrcweir 			EffectSequence::iterator aInsertIter( find( (*aIter++) ) );
3011*cdf0e10cSrcweir 			while( aIter != aEnd )
3012*cdf0e10cSrcweir 			{
3013*cdf0e10cSrcweir 				CustomAnimationEffectPtr pEffect( (*aIter++) );
3014*cdf0e10cSrcweir 				maEffects.erase( find( pEffect ) );
3015*cdf0e10cSrcweir 				aInsertIter = maEffects.insert( ++aInsertIter, pEffect );
3016*cdf0e10cSrcweir 				pTextGroup->addEffect( pEffect );
3017*cdf0e10cSrcweir 			}
3018*cdf0e10cSrcweir 		}
3019*cdf0e10cSrcweir 		notify_listeners();
3020*cdf0e10cSrcweir 	}
3021*cdf0e10cSrcweir }
3022*cdf0e10cSrcweir 
3023*cdf0e10cSrcweir // --------------------------------------------------------------------
3024*cdf0e10cSrcweir 
3025*cdf0e10cSrcweir void EffectSequenceHelper::addListener( ISequenceListener* pListener )
3026*cdf0e10cSrcweir {
3027*cdf0e10cSrcweir 	if( std::find( maListeners.begin(), maListeners.end(), pListener ) == maListeners.end() )
3028*cdf0e10cSrcweir 		maListeners.push_back( pListener );
3029*cdf0e10cSrcweir }
3030*cdf0e10cSrcweir 
3031*cdf0e10cSrcweir // --------------------------------------------------------------------
3032*cdf0e10cSrcweir 
3033*cdf0e10cSrcweir void EffectSequenceHelper::removeListener( ISequenceListener* pListener )
3034*cdf0e10cSrcweir {
3035*cdf0e10cSrcweir 	maListeners.remove( pListener );
3036*cdf0e10cSrcweir }
3037*cdf0e10cSrcweir 
3038*cdf0e10cSrcweir // --------------------------------------------------------------------
3039*cdf0e10cSrcweir 
3040*cdf0e10cSrcweir struct stl_notify_listeners_func : public std::unary_function<ISequenceListener*, void>
3041*cdf0e10cSrcweir {
3042*cdf0e10cSrcweir 	stl_notify_listeners_func() {}
3043*cdf0e10cSrcweir 	void operator()(ISequenceListener* pListener) { pListener->notify_change(); }
3044*cdf0e10cSrcweir };
3045*cdf0e10cSrcweir 
3046*cdf0e10cSrcweir // --------------------------------------------------------------------
3047*cdf0e10cSrcweir 
3048*cdf0e10cSrcweir void EffectSequenceHelper::notify_listeners()
3049*cdf0e10cSrcweir {
3050*cdf0e10cSrcweir 	stl_notify_listeners_func aFunc;
3051*cdf0e10cSrcweir 	std::for_each( maListeners.begin(), maListeners.end(), aFunc );
3052*cdf0e10cSrcweir }
3053*cdf0e10cSrcweir 
3054*cdf0e10cSrcweir // --------------------------------------------------------------------
3055*cdf0e10cSrcweir 
3056*cdf0e10cSrcweir void EffectSequenceHelper::create( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode )
3057*cdf0e10cSrcweir {
3058*cdf0e10cSrcweir 	DBG_ASSERT( xNode.is(), "sd::EffectSequenceHelper::create(), illegal argument" );
3059*cdf0e10cSrcweir 
3060*cdf0e10cSrcweir 	if( xNode.is() ) try
3061*cdf0e10cSrcweir 	{
3062*cdf0e10cSrcweir 		Reference< XEnumerationAccess > xEnumerationAccess( xNode, UNO_QUERY_THROW );
3063*cdf0e10cSrcweir 		Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
3064*cdf0e10cSrcweir 		while( xEnumeration->hasMoreElements() )
3065*cdf0e10cSrcweir 		{
3066*cdf0e10cSrcweir 			Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY_THROW );
3067*cdf0e10cSrcweir 			createEffectsequence( xChildNode );
3068*cdf0e10cSrcweir 		}
3069*cdf0e10cSrcweir 	}
3070*cdf0e10cSrcweir 	catch( Exception& )
3071*cdf0e10cSrcweir 	{
3072*cdf0e10cSrcweir 		DBG_ERROR( "sd::EffectSequenceHelper::create(), exception cought!" );
3073*cdf0e10cSrcweir 	}
3074*cdf0e10cSrcweir }
3075*cdf0e10cSrcweir 
3076*cdf0e10cSrcweir // --------------------------------------------------------------------
3077*cdf0e10cSrcweir 
3078*cdf0e10cSrcweir void EffectSequenceHelper::createEffectsequence( const Reference< XAnimationNode >& xNode )
3079*cdf0e10cSrcweir {
3080*cdf0e10cSrcweir 	DBG_ASSERT( xNode.is(), "sd::EffectSequenceHelper::createEffectsequence(), illegal argument" );
3081*cdf0e10cSrcweir 
3082*cdf0e10cSrcweir 	if( xNode.is() ) try
3083*cdf0e10cSrcweir 	{
3084*cdf0e10cSrcweir 		Reference< XEnumerationAccess > xEnumerationAccess( xNode, UNO_QUERY_THROW );
3085*cdf0e10cSrcweir 		Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
3086*cdf0e10cSrcweir 		while( xEnumeration->hasMoreElements() )
3087*cdf0e10cSrcweir 		{
3088*cdf0e10cSrcweir 			Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY_THROW );
3089*cdf0e10cSrcweir 
3090*cdf0e10cSrcweir 			createEffects( xChildNode );
3091*cdf0e10cSrcweir 		}
3092*cdf0e10cSrcweir 	}
3093*cdf0e10cSrcweir 	catch( Exception& )
3094*cdf0e10cSrcweir 	{
3095*cdf0e10cSrcweir 		DBG_ERROR( "sd::EffectSequenceHelper::createEffectsequence(), exception cought!" );
3096*cdf0e10cSrcweir 	}
3097*cdf0e10cSrcweir }
3098*cdf0e10cSrcweir 
3099*cdf0e10cSrcweir // --------------------------------------------------------------------
3100*cdf0e10cSrcweir 
3101*cdf0e10cSrcweir void EffectSequenceHelper::createEffects( const Reference< XAnimationNode >& xNode )
3102*cdf0e10cSrcweir {
3103*cdf0e10cSrcweir 	DBG_ASSERT( xNode.is(), "sd::EffectSequenceHelper::createEffects(), illegal argument" );
3104*cdf0e10cSrcweir 
3105*cdf0e10cSrcweir 	if( xNode.is() ) try
3106*cdf0e10cSrcweir 	{
3107*cdf0e10cSrcweir 		Reference< XEnumerationAccess > xEnumerationAccess( xNode, UNO_QUERY_THROW );
3108*cdf0e10cSrcweir 		Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
3109*cdf0e10cSrcweir 		while( xEnumeration->hasMoreElements() )
3110*cdf0e10cSrcweir 		{
3111*cdf0e10cSrcweir 			Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY_THROW );
3112*cdf0e10cSrcweir 
3113*cdf0e10cSrcweir 			switch( xChildNode->getType() )
3114*cdf0e10cSrcweir 			{
3115*cdf0e10cSrcweir 			// found an effect
3116*cdf0e10cSrcweir 			case AnimationNodeType::PAR:
3117*cdf0e10cSrcweir 			case AnimationNodeType::ITERATE:
3118*cdf0e10cSrcweir 				{
3119*cdf0e10cSrcweir 					CustomAnimationEffectPtr pEffect( new CustomAnimationEffect( xChildNode ) );
3120*cdf0e10cSrcweir 
3121*cdf0e10cSrcweir 					if( pEffect->mnNodeType != -1 )
3122*cdf0e10cSrcweir 					{
3123*cdf0e10cSrcweir 						pEffect->setEffectSequence( this );
3124*cdf0e10cSrcweir 						maEffects.push_back(pEffect);
3125*cdf0e10cSrcweir 					}
3126*cdf0e10cSrcweir 				}
3127*cdf0e10cSrcweir 				break;
3128*cdf0e10cSrcweir 
3129*cdf0e10cSrcweir 			// found an after effect
3130*cdf0e10cSrcweir 			case AnimationNodeType::SET:
3131*cdf0e10cSrcweir 			case AnimationNodeType::ANIMATECOLOR:
3132*cdf0e10cSrcweir 				{
3133*cdf0e10cSrcweir 					processAfterEffect( xChildNode );
3134*cdf0e10cSrcweir 				}
3135*cdf0e10cSrcweir 				break;
3136*cdf0e10cSrcweir 			}
3137*cdf0e10cSrcweir 		}
3138*cdf0e10cSrcweir 	}
3139*cdf0e10cSrcweir 	catch( Exception& e )
3140*cdf0e10cSrcweir 	{
3141*cdf0e10cSrcweir 		(void)e;
3142*cdf0e10cSrcweir 		DBG_ERROR( "sd::EffectSequenceHelper::createEffects(), exception cought!" );
3143*cdf0e10cSrcweir 	}
3144*cdf0e10cSrcweir }
3145*cdf0e10cSrcweir 
3146*cdf0e10cSrcweir // --------------------------------------------------------------------
3147*cdf0e10cSrcweir 
3148*cdf0e10cSrcweir void EffectSequenceHelper::processAfterEffect( const Reference< XAnimationNode >& xNode )
3149*cdf0e10cSrcweir {
3150*cdf0e10cSrcweir 	try
3151*cdf0e10cSrcweir 	{
3152*cdf0e10cSrcweir 		Reference< XAnimationNode > xMaster;
3153*cdf0e10cSrcweir 
3154*cdf0e10cSrcweir 		Sequence< NamedValue > aUserData( xNode->getUserData() );
3155*cdf0e10cSrcweir 		sal_Int32 nLength = aUserData.getLength();
3156*cdf0e10cSrcweir 		const NamedValue* p = aUserData.getConstArray();
3157*cdf0e10cSrcweir 
3158*cdf0e10cSrcweir 		while( nLength-- )
3159*cdf0e10cSrcweir 		{
3160*cdf0e10cSrcweir 			if( p->Name.equalsAscii( "master-element" ) )
3161*cdf0e10cSrcweir 			{
3162*cdf0e10cSrcweir 				p->Value >>= xMaster;
3163*cdf0e10cSrcweir 				break;
3164*cdf0e10cSrcweir 			}
3165*cdf0e10cSrcweir 			p++;
3166*cdf0e10cSrcweir 		}
3167*cdf0e10cSrcweir 
3168*cdf0e10cSrcweir 		// only process if this is a valid after effect
3169*cdf0e10cSrcweir 		if( xMaster.is() )
3170*cdf0e10cSrcweir 		{
3171*cdf0e10cSrcweir 			CustomAnimationEffectPtr pMasterEffect;
3172*cdf0e10cSrcweir 
3173*cdf0e10cSrcweir 			// find the master effect
3174*cdf0e10cSrcweir 			stl_CustomAnimationEffect_search_node_predict aSearchPredict( xMaster );
3175*cdf0e10cSrcweir 			EffectSequence::iterator aIter( std::find_if( maEffects.begin(), maEffects.end(), aSearchPredict ) );
3176*cdf0e10cSrcweir 			if( aIter != maEffects.end() )
3177*cdf0e10cSrcweir 				pMasterEffect = (*aIter );
3178*cdf0e10cSrcweir 
3179*cdf0e10cSrcweir 			if( pMasterEffect.get() )
3180*cdf0e10cSrcweir 			{
3181*cdf0e10cSrcweir 				pMasterEffect->setHasAfterEffect( true );
3182*cdf0e10cSrcweir 
3183*cdf0e10cSrcweir 				// find out what kind of after effect this is
3184*cdf0e10cSrcweir 				if( xNode->getType() == AnimationNodeType::ANIMATECOLOR )
3185*cdf0e10cSrcweir 				{
3186*cdf0e10cSrcweir 					// its a dim
3187*cdf0e10cSrcweir 					Reference< XAnimate > xAnimate( xNode, UNO_QUERY_THROW );
3188*cdf0e10cSrcweir 					pMasterEffect->setDimColor( xAnimate->getTo() );
3189*cdf0e10cSrcweir 					pMasterEffect->setAfterEffectOnNext( true );
3190*cdf0e10cSrcweir 				}
3191*cdf0e10cSrcweir 				else
3192*cdf0e10cSrcweir 				{
3193*cdf0e10cSrcweir 					// its a hide
3194*cdf0e10cSrcweir 					Reference< XChild > xNodeChild( xNode, UNO_QUERY_THROW );
3195*cdf0e10cSrcweir 					Reference< XChild > xMasterChild( xMaster, UNO_QUERY_THROW );
3196*cdf0e10cSrcweir 					pMasterEffect->setAfterEffectOnNext( xNodeChild->getParent() != xMasterChild->getParent() );
3197*cdf0e10cSrcweir 				}
3198*cdf0e10cSrcweir 			}
3199*cdf0e10cSrcweir 		}
3200*cdf0e10cSrcweir 	}
3201*cdf0e10cSrcweir 	catch( Exception& e )
3202*cdf0e10cSrcweir 	{
3203*cdf0e10cSrcweir 		(void)e;
3204*cdf0e10cSrcweir 		DBG_ERROR( "sd::EffectSequenceHelper::processAfterEffect(), exception cought!" );
3205*cdf0e10cSrcweir 	}
3206*cdf0e10cSrcweir }
3207*cdf0e10cSrcweir 
3208*cdf0e10cSrcweir /*
3209*cdf0e10cSrcweir double EffectSequenceHelper::calculateIterateNodeDuration(
3210*cdf0e10cSrcweir {
3211*cdf0e10cSrcweir     Reference< i18n::XBreakIterator > xBI( ImplGetBreakIterator() );
3212*cdf0e10cSrcweir 
3213*cdf0e10cSrcweir     sal_Int32 nDone;
3214*cdf0e10cSrcweir     sal_Int32 nNextCellBreak( xBI->nextCharacters(rTxt, nIdx, rLocale, i18n::CharacterIteratorMode::SKIPCELL, 0, nDone) );
3215*cdf0e10cSrcweir     i18n::Boundary nNextWordBoundary( xBI->getWordBoundary(rTxt, nIdx, rLocale, i18n::WordType::ANY_WORD, sal_True) );
3216*cdf0e10cSrcweir     sal_Int32 nNextSentenceBreak( xBI->endOfSentence(rTxt, nIdx, rLocale) );
3217*cdf0e10cSrcweir 
3218*cdf0e10cSrcweir     const sal_Int32 nEndPos( nIdx + nLen );
3219*cdf0e10cSrcweir     sal_Int32 i, currOffset(0);
3220*cdf0e10cSrcweir     for( i=nIdx; i<nEndPos; ++i )
3221*cdf0e10cSrcweir     {
3222*cdf0e10cSrcweir         // TODO: Check whether position update is valid for CTL/BiDi
3223*cdf0e10cSrcweir         rOutDev.DrawText( rPos + Point(currOffset,0), rTxt, i, 1 );
3224*cdf0e10cSrcweir         currOffset = *pDXArray++;
3225*cdf0e10cSrcweir 
3226*cdf0e10cSrcweir         // issue the comments at the respective break positions
3227*cdf0e10cSrcweir         if( i == nNextCellBreak )
3228*cdf0e10cSrcweir         {
3229*cdf0e10cSrcweir             rMtf.AddAction( new MetaCommentAction( "XTEXT_EOC" ) );
3230*cdf0e10cSrcweir             nNextCellBreak = xBI->nextCharacters(rTxt, i, rLocale, i18n::CharacterIteratorMode::SKIPCELL, 1, nDone);
3231*cdf0e10cSrcweir         }
3232*cdf0e10cSrcweir         if( i == nNextWordBoundary.endPos )
3233*cdf0e10cSrcweir         {
3234*cdf0e10cSrcweir             rMtf.AddAction( new MetaCommentAction( "XTEXT_EOW" ) );
3235*cdf0e10cSrcweir             nNextWordBoundary = xBI->getWordBoundary(rTxt, i+1, rLocale, i18n::WordType::ANY_WORD, sal_True);
3236*cdf0e10cSrcweir         }
3237*cdf0e10cSrcweir         if( i == nNextSentenceBreak )
3238*cdf0e10cSrcweir         {
3239*cdf0e10cSrcweir             rMtf.AddAction( new MetaCommentAction( "XTEXT_EOS" ) );
3240*cdf0e10cSrcweir             nNextSentenceBreak = xBI->endOfSentence(rTxt, i+1, rLocale);
3241*cdf0e10cSrcweir         }
3242*cdf0e10cSrcweir     }
3243*cdf0e10cSrcweir }
3244*cdf0e10cSrcweir 
3245*cdf0e10cSrcweir */
3246*cdf0e10cSrcweir // ====================================================================
3247*cdf0e10cSrcweir 
3248*cdf0e10cSrcweir class AnimationChangeListener : public cppu::WeakImplHelper1< XChangesListener >
3249*cdf0e10cSrcweir {
3250*cdf0e10cSrcweir public:
3251*cdf0e10cSrcweir 	AnimationChangeListener( MainSequence* pMainSequence ) : mpMainSequence( pMainSequence ) {}
3252*cdf0e10cSrcweir 
3253*cdf0e10cSrcweir     virtual void SAL_CALL changesOccurred( const ::com::sun::star::util::ChangesEvent& Event ) throw (RuntimeException);
3254*cdf0e10cSrcweir     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (RuntimeException);
3255*cdf0e10cSrcweir private:
3256*cdf0e10cSrcweir 	MainSequence* mpMainSequence;
3257*cdf0e10cSrcweir };
3258*cdf0e10cSrcweir 
3259*cdf0e10cSrcweir void SAL_CALL AnimationChangeListener::changesOccurred( const ::com::sun::star::util::ChangesEvent& ) throw (RuntimeException)
3260*cdf0e10cSrcweir {
3261*cdf0e10cSrcweir 	if( mpMainSequence )
3262*cdf0e10cSrcweir 		mpMainSequence->startRecreateTimer();
3263*cdf0e10cSrcweir }
3264*cdf0e10cSrcweir 
3265*cdf0e10cSrcweir void SAL_CALL AnimationChangeListener::disposing( const ::com::sun::star::lang::EventObject& ) throw (RuntimeException)
3266*cdf0e10cSrcweir {
3267*cdf0e10cSrcweir }
3268*cdf0e10cSrcweir 
3269*cdf0e10cSrcweir // ====================================================================
3270*cdf0e10cSrcweir 
3271*cdf0e10cSrcweir MainSequence::MainSequence()
3272*cdf0e10cSrcweir : mxTimingRootNode( ::comphelper::getProcessServiceFactory()->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.animations.SequenceTimeContainer"))), UNO_QUERY )
3273*cdf0e10cSrcweir , mbRebuilding( false )
3274*cdf0e10cSrcweir , mnRebuildLockGuard( 0 )
3275*cdf0e10cSrcweir , mbPendingRebuildRequest( false )
3276*cdf0e10cSrcweir {
3277*cdf0e10cSrcweir 	if( mxTimingRootNode.is() )
3278*cdf0e10cSrcweir 	{
3279*cdf0e10cSrcweir 		Sequence< ::com::sun::star::beans::NamedValue > aUserData( 1 );
3280*cdf0e10cSrcweir 		aUserData[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "node-type" ) );
3281*cdf0e10cSrcweir 		aUserData[0].Value <<= ::com::sun::star::presentation::EffectNodeType::MAIN_SEQUENCE;
3282*cdf0e10cSrcweir 		mxTimingRootNode->setUserData( aUserData );
3283*cdf0e10cSrcweir 	}
3284*cdf0e10cSrcweir 	init();
3285*cdf0e10cSrcweir }
3286*cdf0e10cSrcweir 
3287*cdf0e10cSrcweir // --------------------------------------------------------------------
3288*cdf0e10cSrcweir 
3289*cdf0e10cSrcweir MainSequence::MainSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode )
3290*cdf0e10cSrcweir : mxTimingRootNode( xNode, UNO_QUERY )
3291*cdf0e10cSrcweir , mbRebuilding( false )
3292*cdf0e10cSrcweir , mnRebuildLockGuard( 0 )
3293*cdf0e10cSrcweir , mbPendingRebuildRequest( false )
3294*cdf0e10cSrcweir , mbIgnoreChanges( 0 )
3295*cdf0e10cSrcweir {
3296*cdf0e10cSrcweir 	init();
3297*cdf0e10cSrcweir }
3298*cdf0e10cSrcweir 
3299*cdf0e10cSrcweir // --------------------------------------------------------------------
3300*cdf0e10cSrcweir 
3301*cdf0e10cSrcweir MainSequence::~MainSequence()
3302*cdf0e10cSrcweir {
3303*cdf0e10cSrcweir 	reset();
3304*cdf0e10cSrcweir }
3305*cdf0e10cSrcweir 
3306*cdf0e10cSrcweir // --------------------------------------------------------------------
3307*cdf0e10cSrcweir 
3308*cdf0e10cSrcweir void MainSequence::init()
3309*cdf0e10cSrcweir {
3310*cdf0e10cSrcweir 	mnSequenceType = EffectNodeType::MAIN_SEQUENCE;
3311*cdf0e10cSrcweir 
3312*cdf0e10cSrcweir 	maTimer.SetTimeoutHdl( LINK(this, MainSequence, onTimerHdl) );
3313*cdf0e10cSrcweir 	maTimer.SetTimeout(500);
3314*cdf0e10cSrcweir 
3315*cdf0e10cSrcweir 	mxChangesListener.set( new AnimationChangeListener( this ) );
3316*cdf0e10cSrcweir 
3317*cdf0e10cSrcweir 	createMainSequence();
3318*cdf0e10cSrcweir }
3319*cdf0e10cSrcweir 
3320*cdf0e10cSrcweir // --------------------------------------------------------------------
3321*cdf0e10cSrcweir 
3322*cdf0e10cSrcweir void MainSequence::reset( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xTimingRootNode )
3323*cdf0e10cSrcweir {
3324*cdf0e10cSrcweir 	reset();
3325*cdf0e10cSrcweir 
3326*cdf0e10cSrcweir 	mxTimingRootNode.set( xTimingRootNode, UNO_QUERY );
3327*cdf0e10cSrcweir 
3328*cdf0e10cSrcweir 	createMainSequence();
3329*cdf0e10cSrcweir }
3330*cdf0e10cSrcweir 
3331*cdf0e10cSrcweir // --------------------------------------------------------------------
3332*cdf0e10cSrcweir 
3333*cdf0e10cSrcweir Reference< ::com::sun::star::animations::XAnimationNode > MainSequence::getRootNode()
3334*cdf0e10cSrcweir {
3335*cdf0e10cSrcweir 	DBG_ASSERT( mnRebuildLockGuard == 0, "MainSequence::getRootNode(), rebuild is locked, ist this really what you want?" );
3336*cdf0e10cSrcweir 
3337*cdf0e10cSrcweir 	if( maTimer.IsActive() && mbTimerMode )
3338*cdf0e10cSrcweir 	{
3339*cdf0e10cSrcweir 		// force a rebuild NOW if one is pending
3340*cdf0e10cSrcweir 		maTimer.Stop();
3341*cdf0e10cSrcweir 		implRebuild();
3342*cdf0e10cSrcweir 	}
3343*cdf0e10cSrcweir 
3344*cdf0e10cSrcweir 	return EffectSequenceHelper::getRootNode();
3345*cdf0e10cSrcweir }
3346*cdf0e10cSrcweir 
3347*cdf0e10cSrcweir // --------------------------------------------------------------------
3348*cdf0e10cSrcweir 
3349*cdf0e10cSrcweir void MainSequence::createMainSequence()
3350*cdf0e10cSrcweir {
3351*cdf0e10cSrcweir 	if( mxTimingRootNode.is() ) try
3352*cdf0e10cSrcweir 	{
3353*cdf0e10cSrcweir 		Reference< XEnumerationAccess > xEnumerationAccess( mxTimingRootNode, UNO_QUERY_THROW );
3354*cdf0e10cSrcweir 		Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
3355*cdf0e10cSrcweir 		while( xEnumeration->hasMoreElements() )
3356*cdf0e10cSrcweir 		{
3357*cdf0e10cSrcweir 			Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY_THROW );
3358*cdf0e10cSrcweir 			sal_Int32 nNodeType = CustomAnimationEffect::get_node_type( xChildNode );
3359*cdf0e10cSrcweir 			if( nNodeType == EffectNodeType::MAIN_SEQUENCE )
3360*cdf0e10cSrcweir 			{
3361*cdf0e10cSrcweir 				mxSequenceRoot.set( xChildNode, UNO_QUERY );
3362*cdf0e10cSrcweir 				EffectSequenceHelper::create( xChildNode );
3363*cdf0e10cSrcweir 			}
3364*cdf0e10cSrcweir 			else if( nNodeType == EffectNodeType::INTERACTIVE_SEQUENCE )
3365*cdf0e10cSrcweir 			{
3366*cdf0e10cSrcweir 				Reference< XTimeContainer > xInteractiveRoot( xChildNode, UNO_QUERY_THROW );
3367*cdf0e10cSrcweir 				InteractiveSequencePtr pIS( new InteractiveSequence( xInteractiveRoot, this ) );
3368*cdf0e10cSrcweir 				pIS->addListener( this );
3369*cdf0e10cSrcweir 				maInteractiveSequenceList.push_back( pIS );
3370*cdf0e10cSrcweir 			}
3371*cdf0e10cSrcweir 		}
3372*cdf0e10cSrcweir 
3373*cdf0e10cSrcweir 		// see if we have a mainsequence at all. if not, create one...
3374*cdf0e10cSrcweir 		if( !mxSequenceRoot.is() )
3375*cdf0e10cSrcweir 		{
3376*cdf0e10cSrcweir 			mxSequenceRoot = Reference< XTimeContainer >::query(::comphelper::getProcessServiceFactory()->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.animations.SequenceTimeContainer"))));
3377*cdf0e10cSrcweir 			if( mxSequenceRoot.is() )
3378*cdf0e10cSrcweir 			{
3379*cdf0e10cSrcweir 				uno::Sequence< ::com::sun::star::beans::NamedValue > aUserData( 1 );
3380*cdf0e10cSrcweir 				aUserData[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "node-type" ) );
3381*cdf0e10cSrcweir 				aUserData[0].Value <<= ::com::sun::star::presentation::EffectNodeType::MAIN_SEQUENCE;
3382*cdf0e10cSrcweir 				mxSequenceRoot->setUserData( aUserData );
3383*cdf0e10cSrcweir 
3384*cdf0e10cSrcweir                 // empty sequence until now, set duration to 0.0
3385*cdf0e10cSrcweir                 // explicitely (otherwise, this sequence will never
3386*cdf0e10cSrcweir                 // end)
3387*cdf0e10cSrcweir                 mxSequenceRoot->setDuration( makeAny((double)0.0) );
3388*cdf0e10cSrcweir 
3389*cdf0e10cSrcweir 				Reference< XAnimationNode > xMainSequenceNode( mxSequenceRoot, UNO_QUERY_THROW );
3390*cdf0e10cSrcweir 				mxTimingRootNode->appendChild( xMainSequenceNode );
3391*cdf0e10cSrcweir 			}
3392*cdf0e10cSrcweir 		}
3393*cdf0e10cSrcweir 
3394*cdf0e10cSrcweir 		updateTextGroups();
3395*cdf0e10cSrcweir 
3396*cdf0e10cSrcweir 		notify_listeners();
3397*cdf0e10cSrcweir 
3398*cdf0e10cSrcweir 		Reference< XChangesNotifier > xNotifier( mxTimingRootNode, UNO_QUERY );
3399*cdf0e10cSrcweir 		if( xNotifier.is() )
3400*cdf0e10cSrcweir 			xNotifier->addChangesListener( mxChangesListener );
3401*cdf0e10cSrcweir 	}
3402*cdf0e10cSrcweir 	catch( Exception& e )
3403*cdf0e10cSrcweir 	{
3404*cdf0e10cSrcweir 		(void)e;
3405*cdf0e10cSrcweir 		DBG_ERROR( "sd::MainSequence::create(), exception cought!" );
3406*cdf0e10cSrcweir 		return;
3407*cdf0e10cSrcweir 	}
3408*cdf0e10cSrcweir 
3409*cdf0e10cSrcweir 	DBG_ASSERT( mxSequenceRoot.is(), "sd::MainSequence::create(), found no main sequence!" );
3410*cdf0e10cSrcweir }
3411*cdf0e10cSrcweir 
3412*cdf0e10cSrcweir // --------------------------------------------------------------------
3413*cdf0e10cSrcweir 
3414*cdf0e10cSrcweir void MainSequence::reset()
3415*cdf0e10cSrcweir {
3416*cdf0e10cSrcweir 	EffectSequenceHelper::reset();
3417*cdf0e10cSrcweir 
3418*cdf0e10cSrcweir 	InteractiveSequenceList::iterator aIter;
3419*cdf0e10cSrcweir 	for( aIter = maInteractiveSequenceList.begin(); aIter != maInteractiveSequenceList.end(); aIter++ )
3420*cdf0e10cSrcweir 		(*aIter)->reset();
3421*cdf0e10cSrcweir 	maInteractiveSequenceList.clear();
3422*cdf0e10cSrcweir 
3423*cdf0e10cSrcweir 	try
3424*cdf0e10cSrcweir 	{
3425*cdf0e10cSrcweir 		Reference< XChangesNotifier > xNotifier( mxTimingRootNode, UNO_QUERY );
3426*cdf0e10cSrcweir 		if( xNotifier.is() )
3427*cdf0e10cSrcweir 			xNotifier->removeChangesListener( mxChangesListener );
3428*cdf0e10cSrcweir 	}
3429*cdf0e10cSrcweir 	catch( Exception& )
3430*cdf0e10cSrcweir 	{
3431*cdf0e10cSrcweir 		// ...
3432*cdf0e10cSrcweir 	}
3433*cdf0e10cSrcweir }
3434*cdf0e10cSrcweir 
3435*cdf0e10cSrcweir // --------------------------------------------------------------------
3436*cdf0e10cSrcweir 
3437*cdf0e10cSrcweir InteractiveSequencePtr MainSequence::createInteractiveSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xShape )
3438*cdf0e10cSrcweir {
3439*cdf0e10cSrcweir 	InteractiveSequencePtr pIS;
3440*cdf0e10cSrcweir 
3441*cdf0e10cSrcweir 	// create a new interactive sequence container
3442*cdf0e10cSrcweir 	Reference< XTimeContainer > xISRoot( ::comphelper::getProcessServiceFactory()->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.animations.SequenceTimeContainer"))), UNO_QUERY );
3443*cdf0e10cSrcweir 	DBG_ASSERT( xISRoot.is(), "sd::MainSequence::createInteractiveSequence(), could not create \"com.sun.star.animations.SequenceTimeContainer\"!");
3444*cdf0e10cSrcweir 	if( xISRoot.is() )
3445*cdf0e10cSrcweir 	{
3446*cdf0e10cSrcweir 		uno::Sequence< ::com::sun::star::beans::NamedValue > aUserData( 1 );
3447*cdf0e10cSrcweir 		aUserData[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "node-type" ) );
3448*cdf0e10cSrcweir 		aUserData[0].Value <<= ::com::sun::star::presentation::EffectNodeType::INTERACTIVE_SEQUENCE ;
3449*cdf0e10cSrcweir 		xISRoot->setUserData( aUserData );
3450*cdf0e10cSrcweir 
3451*cdf0e10cSrcweir 		Reference< XChild > xChild( mxSequenceRoot, UNO_QUERY_THROW );
3452*cdf0e10cSrcweir 		Reference< XAnimationNode > xISNode( xISRoot, UNO_QUERY_THROW );
3453*cdf0e10cSrcweir 		Reference< XTimeContainer > xParent( xChild->getParent(), UNO_QUERY_THROW );
3454*cdf0e10cSrcweir 		xParent->appendChild( xISNode );
3455*cdf0e10cSrcweir 	}
3456*cdf0e10cSrcweir 	pIS.reset( new InteractiveSequence( xISRoot, this) );
3457*cdf0e10cSrcweir     pIS->setTriggerShape( xShape );
3458*cdf0e10cSrcweir 	pIS->addListener( this );
3459*cdf0e10cSrcweir 	maInteractiveSequenceList.push_back( pIS );
3460*cdf0e10cSrcweir 	return pIS;
3461*cdf0e10cSrcweir }
3462*cdf0e10cSrcweir 
3463*cdf0e10cSrcweir // --------------------------------------------------------------------
3464*cdf0e10cSrcweir 
3465*cdf0e10cSrcweir CustomAnimationEffectPtr MainSequence::findEffect( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode ) const
3466*cdf0e10cSrcweir {
3467*cdf0e10cSrcweir 	CustomAnimationEffectPtr pEffect = EffectSequenceHelper::findEffect( xNode );
3468*cdf0e10cSrcweir 
3469*cdf0e10cSrcweir 	if( pEffect.get() == 0 )
3470*cdf0e10cSrcweir 	{
3471*cdf0e10cSrcweir 		InteractiveSequenceList::const_iterator aIter;
3472*cdf0e10cSrcweir 		for( aIter = maInteractiveSequenceList.begin(); (aIter != maInteractiveSequenceList.end()) && (pEffect.get() == 0); aIter++ )
3473*cdf0e10cSrcweir 		{
3474*cdf0e10cSrcweir 			pEffect = (*aIter)->findEffect( xNode );
3475*cdf0e10cSrcweir 		}
3476*cdf0e10cSrcweir 	}
3477*cdf0e10cSrcweir 	return pEffect;
3478*cdf0e10cSrcweir }
3479*cdf0e10cSrcweir 
3480*cdf0e10cSrcweir // --------------------------------------------------------------------
3481*cdf0e10cSrcweir 
3482*cdf0e10cSrcweir sal_Int32 MainSequence::getOffsetFromEffect( const CustomAnimationEffectPtr& pEffect ) const
3483*cdf0e10cSrcweir {
3484*cdf0e10cSrcweir 	sal_Int32 nOffset = EffectSequenceHelper::getOffsetFromEffect( pEffect );
3485*cdf0e10cSrcweir 
3486*cdf0e10cSrcweir 	if( nOffset != -1 )
3487*cdf0e10cSrcweir 		return nOffset;
3488*cdf0e10cSrcweir 
3489*cdf0e10cSrcweir 	nOffset = EffectSequenceHelper::getCount();
3490*cdf0e10cSrcweir 
3491*cdf0e10cSrcweir 	InteractiveSequenceList::const_iterator aIter;
3492*cdf0e10cSrcweir 	for( aIter = maInteractiveSequenceList.begin(); aIter != maInteractiveSequenceList.end(); aIter++ )
3493*cdf0e10cSrcweir 	{
3494*cdf0e10cSrcweir 		sal_Int32 nTemp = (*aIter)->getOffsetFromEffect( pEffect );
3495*cdf0e10cSrcweir 		if( nTemp != -1 )
3496*cdf0e10cSrcweir 			return nOffset + nTemp;
3497*cdf0e10cSrcweir 
3498*cdf0e10cSrcweir 		nOffset += (*aIter)->getCount();
3499*cdf0e10cSrcweir 	}
3500*cdf0e10cSrcweir 
3501*cdf0e10cSrcweir 	return -1;
3502*cdf0e10cSrcweir }
3503*cdf0e10cSrcweir 
3504*cdf0e10cSrcweir // --------------------------------------------------------------------
3505*cdf0e10cSrcweir 
3506*cdf0e10cSrcweir CustomAnimationEffectPtr MainSequence::getEffectFromOffset( sal_Int32 nOffset ) const
3507*cdf0e10cSrcweir {
3508*cdf0e10cSrcweir 	if( nOffset >= 0 )
3509*cdf0e10cSrcweir 	{
3510*cdf0e10cSrcweir 		if( nOffset < getCount() )
3511*cdf0e10cSrcweir 			return EffectSequenceHelper::getEffectFromOffset( nOffset );
3512*cdf0e10cSrcweir 
3513*cdf0e10cSrcweir 		nOffset -= getCount();
3514*cdf0e10cSrcweir 
3515*cdf0e10cSrcweir 		InteractiveSequenceList::const_iterator aIter( maInteractiveSequenceList.begin() );
3516*cdf0e10cSrcweir 
3517*cdf0e10cSrcweir 		while( (aIter != maInteractiveSequenceList.end()) && (nOffset > (*aIter)->getCount()) )
3518*cdf0e10cSrcweir 			nOffset -= (*aIter++)->getCount();
3519*cdf0e10cSrcweir 
3520*cdf0e10cSrcweir 		if( (aIter != maInteractiveSequenceList.end()) && (nOffset >= 0) )
3521*cdf0e10cSrcweir 			return (*aIter)->getEffectFromOffset( nOffset );
3522*cdf0e10cSrcweir 	}
3523*cdf0e10cSrcweir 
3524*cdf0e10cSrcweir 	CustomAnimationEffectPtr pEffect;
3525*cdf0e10cSrcweir 	return pEffect;
3526*cdf0e10cSrcweir }
3527*cdf0e10cSrcweir 
3528*cdf0e10cSrcweir // --------------------------------------------------------------------
3529*cdf0e10cSrcweir 
3530*cdf0e10cSrcweir bool MainSequence::disposeShape( const Reference< XShape >& xShape )
3531*cdf0e10cSrcweir {
3532*cdf0e10cSrcweir 	bool bChanges = EffectSequenceHelper::disposeShape( xShape );
3533*cdf0e10cSrcweir 
3534*cdf0e10cSrcweir 	InteractiveSequenceList::iterator aIter;
3535*cdf0e10cSrcweir 	for( aIter = maInteractiveSequenceList.begin(); aIter != maInteractiveSequenceList.end();  )
3536*cdf0e10cSrcweir 	{
3537*cdf0e10cSrcweir 		if( (*aIter)->getTriggerShape() == xShape )
3538*cdf0e10cSrcweir 		{
3539*cdf0e10cSrcweir 			aIter = maInteractiveSequenceList.erase( aIter );
3540*cdf0e10cSrcweir 			bChanges = true;
3541*cdf0e10cSrcweir 		}
3542*cdf0e10cSrcweir 		else
3543*cdf0e10cSrcweir 		{
3544*cdf0e10cSrcweir 			bChanges |= (*aIter++)->disposeShape( xShape );
3545*cdf0e10cSrcweir 		}
3546*cdf0e10cSrcweir 	}
3547*cdf0e10cSrcweir 
3548*cdf0e10cSrcweir 	if( bChanges )
3549*cdf0e10cSrcweir 		startRebuildTimer();
3550*cdf0e10cSrcweir 
3551*cdf0e10cSrcweir 	return bChanges;
3552*cdf0e10cSrcweir }
3553*cdf0e10cSrcweir 
3554*cdf0e10cSrcweir // --------------------------------------------------------------------
3555*cdf0e10cSrcweir 
3556*cdf0e10cSrcweir bool MainSequence::hasEffect( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape )
3557*cdf0e10cSrcweir {
3558*cdf0e10cSrcweir 	if( EffectSequenceHelper::hasEffect( xShape ) )
3559*cdf0e10cSrcweir 		return true;
3560*cdf0e10cSrcweir 
3561*cdf0e10cSrcweir 	InteractiveSequenceList::iterator aIter;
3562*cdf0e10cSrcweir 	for( aIter = maInteractiveSequenceList.begin(); aIter != maInteractiveSequenceList.end();  )
3563*cdf0e10cSrcweir 	{
3564*cdf0e10cSrcweir 		if( (*aIter)->getTriggerShape() == xShape )
3565*cdf0e10cSrcweir 			return true;
3566*cdf0e10cSrcweir 
3567*cdf0e10cSrcweir 		if( (*aIter++)->hasEffect( xShape ) )
3568*cdf0e10cSrcweir 			return true;
3569*cdf0e10cSrcweir 	}
3570*cdf0e10cSrcweir 
3571*cdf0e10cSrcweir 	return false;
3572*cdf0e10cSrcweir }
3573*cdf0e10cSrcweir 
3574*cdf0e10cSrcweir // --------------------------------------------------------------------
3575*cdf0e10cSrcweir 
3576*cdf0e10cSrcweir void MainSequence::insertTextRange( const com::sun::star::uno::Any& aTarget )
3577*cdf0e10cSrcweir {
3578*cdf0e10cSrcweir 	EffectSequenceHelper::insertTextRange( aTarget );
3579*cdf0e10cSrcweir 
3580*cdf0e10cSrcweir 	InteractiveSequenceList::iterator aIter;
3581*cdf0e10cSrcweir 	for( aIter = maInteractiveSequenceList.begin(); aIter != maInteractiveSequenceList.end(); aIter++ )
3582*cdf0e10cSrcweir 	{
3583*cdf0e10cSrcweir 		(*aIter)->insertTextRange( aTarget );
3584*cdf0e10cSrcweir 	}
3585*cdf0e10cSrcweir }
3586*cdf0e10cSrcweir // --------------------------------------------------------------------
3587*cdf0e10cSrcweir 
3588*cdf0e10cSrcweir void MainSequence::disposeTextRange( const com::sun::star::uno::Any& aTarget )
3589*cdf0e10cSrcweir {
3590*cdf0e10cSrcweir 	EffectSequenceHelper::disposeTextRange( aTarget );
3591*cdf0e10cSrcweir 
3592*cdf0e10cSrcweir 	InteractiveSequenceList::iterator aIter;
3593*cdf0e10cSrcweir 	for( aIter = maInteractiveSequenceList.begin(); aIter != maInteractiveSequenceList.end(); aIter++ )
3594*cdf0e10cSrcweir 	{
3595*cdf0e10cSrcweir 		(*aIter)->disposeTextRange( aTarget );
3596*cdf0e10cSrcweir 	}
3597*cdf0e10cSrcweir }
3598*cdf0e10cSrcweir 
3599*cdf0e10cSrcweir // --------------------------------------------------------------------
3600*cdf0e10cSrcweir 
3601*cdf0e10cSrcweir /** callback from the sd::View when an object just left text edit mode */
3602*cdf0e10cSrcweir void MainSequence::onTextChanged( const Reference< XShape >& xShape )
3603*cdf0e10cSrcweir {
3604*cdf0e10cSrcweir 	EffectSequenceHelper::onTextChanged( xShape );
3605*cdf0e10cSrcweir 
3606*cdf0e10cSrcweir 	InteractiveSequenceList::iterator aIter;
3607*cdf0e10cSrcweir 	for( aIter = maInteractiveSequenceList.begin(); aIter != maInteractiveSequenceList.end(); aIter++ )
3608*cdf0e10cSrcweir 	{
3609*cdf0e10cSrcweir 		(*aIter)->onTextChanged( xShape );
3610*cdf0e10cSrcweir 	}
3611*cdf0e10cSrcweir }
3612*cdf0e10cSrcweir 
3613*cdf0e10cSrcweir // --------------------------------------------------------------------
3614*cdf0e10cSrcweir 
3615*cdf0e10cSrcweir void EffectSequenceHelper::onTextChanged( const Reference< XShape >& xShape )
3616*cdf0e10cSrcweir {
3617*cdf0e10cSrcweir 	bool bChanges = false;
3618*cdf0e10cSrcweir 
3619*cdf0e10cSrcweir 	EffectSequence::iterator aIter;
3620*cdf0e10cSrcweir 	for( aIter = maEffects.begin(); aIter != maEffects.end(); aIter++ )
3621*cdf0e10cSrcweir 	{
3622*cdf0e10cSrcweir 		if( (*aIter)->getTargetShape() == xShape )
3623*cdf0e10cSrcweir 			bChanges |= (*aIter)->checkForText();
3624*cdf0e10cSrcweir 	}
3625*cdf0e10cSrcweir 
3626*cdf0e10cSrcweir 	if( bChanges )
3627*cdf0e10cSrcweir 		EffectSequenceHelper::implRebuild();
3628*cdf0e10cSrcweir }
3629*cdf0e10cSrcweir 
3630*cdf0e10cSrcweir // --------------------------------------------------------------------
3631*cdf0e10cSrcweir 
3632*cdf0e10cSrcweir void MainSequence::rebuild()
3633*cdf0e10cSrcweir {
3634*cdf0e10cSrcweir 	startRebuildTimer();
3635*cdf0e10cSrcweir }
3636*cdf0e10cSrcweir 
3637*cdf0e10cSrcweir // --------------------------------------------------------------------
3638*cdf0e10cSrcweir 
3639*cdf0e10cSrcweir void MainSequence::lockRebuilds()
3640*cdf0e10cSrcweir {
3641*cdf0e10cSrcweir 	mnRebuildLockGuard++;
3642*cdf0e10cSrcweir }
3643*cdf0e10cSrcweir 
3644*cdf0e10cSrcweir // --------------------------------------------------------------------
3645*cdf0e10cSrcweir 
3646*cdf0e10cSrcweir void MainSequence::unlockRebuilds()
3647*cdf0e10cSrcweir {
3648*cdf0e10cSrcweir 	DBG_ASSERT( mnRebuildLockGuard, "sd::MainSequence::unlockRebuilds(), no corresponding lockRebuilds() call!" );
3649*cdf0e10cSrcweir 	if( mnRebuildLockGuard )
3650*cdf0e10cSrcweir 		mnRebuildLockGuard--;
3651*cdf0e10cSrcweir 
3652*cdf0e10cSrcweir 	if( (mnRebuildLockGuard == 0) && mbPendingRebuildRequest )
3653*cdf0e10cSrcweir 	{
3654*cdf0e10cSrcweir 		mbPendingRebuildRequest = false;
3655*cdf0e10cSrcweir 		startRebuildTimer();
3656*cdf0e10cSrcweir 	}
3657*cdf0e10cSrcweir }
3658*cdf0e10cSrcweir 
3659*cdf0e10cSrcweir // --------------------------------------------------------------------
3660*cdf0e10cSrcweir 
3661*cdf0e10cSrcweir void MainSequence::implRebuild()
3662*cdf0e10cSrcweir {
3663*cdf0e10cSrcweir 	if( mnRebuildLockGuard )
3664*cdf0e10cSrcweir 	{
3665*cdf0e10cSrcweir 		mbPendingRebuildRequest = true;
3666*cdf0e10cSrcweir 		return;
3667*cdf0e10cSrcweir 	}
3668*cdf0e10cSrcweir 
3669*cdf0e10cSrcweir 	mbRebuilding = true;
3670*cdf0e10cSrcweir 
3671*cdf0e10cSrcweir 	EffectSequenceHelper::implRebuild();
3672*cdf0e10cSrcweir 
3673*cdf0e10cSrcweir 	InteractiveSequenceList::iterator aIter( maInteractiveSequenceList.begin() );
3674*cdf0e10cSrcweir 	const InteractiveSequenceList::iterator aEnd( maInteractiveSequenceList.end() );
3675*cdf0e10cSrcweir 	while( aIter != aEnd )
3676*cdf0e10cSrcweir 	{
3677*cdf0e10cSrcweir 		InteractiveSequencePtr pIS( (*aIter) );
3678*cdf0e10cSrcweir 		if( pIS->maEffects.empty() )
3679*cdf0e10cSrcweir 		{
3680*cdf0e10cSrcweir 			// remove empty interactive sequences
3681*cdf0e10cSrcweir 			aIter = maInteractiveSequenceList.erase( aIter );
3682*cdf0e10cSrcweir 
3683*cdf0e10cSrcweir 			Reference< XChild > xChild( mxSequenceRoot, UNO_QUERY_THROW );
3684*cdf0e10cSrcweir 			Reference< XTimeContainer > xParent( xChild->getParent(), UNO_QUERY_THROW );
3685*cdf0e10cSrcweir 			Reference< XAnimationNode > xISNode( pIS->mxSequenceRoot, UNO_QUERY_THROW );
3686*cdf0e10cSrcweir 			xParent->removeChild( xISNode );
3687*cdf0e10cSrcweir 		}
3688*cdf0e10cSrcweir 		else
3689*cdf0e10cSrcweir 		{
3690*cdf0e10cSrcweir 			pIS->implRebuild();
3691*cdf0e10cSrcweir 			aIter++;
3692*cdf0e10cSrcweir 		}
3693*cdf0e10cSrcweir 	}
3694*cdf0e10cSrcweir 
3695*cdf0e10cSrcweir 	notify_listeners();
3696*cdf0e10cSrcweir 	mbRebuilding = false;
3697*cdf0e10cSrcweir }
3698*cdf0e10cSrcweir 
3699*cdf0e10cSrcweir // --------------------------------------------------------------------
3700*cdf0e10cSrcweir 
3701*cdf0e10cSrcweir void MainSequence::notify_change()
3702*cdf0e10cSrcweir {
3703*cdf0e10cSrcweir 	notify_listeners();
3704*cdf0e10cSrcweir }
3705*cdf0e10cSrcweir 
3706*cdf0e10cSrcweir // --------------------------------------------------------------------
3707*cdf0e10cSrcweir 
3708*cdf0e10cSrcweir bool MainSequence::setTrigger( const CustomAnimationEffectPtr& pEffect, const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xTriggerShape )
3709*cdf0e10cSrcweir {
3710*cdf0e10cSrcweir 	EffectSequenceHelper* pOldSequence = pEffect->getEffectSequence();
3711*cdf0e10cSrcweir 
3712*cdf0e10cSrcweir 	EffectSequenceHelper* pNewSequence = 0;
3713*cdf0e10cSrcweir 	if( xTriggerShape.is() )
3714*cdf0e10cSrcweir 	{
3715*cdf0e10cSrcweir 		InteractiveSequenceList::iterator aIter( maInteractiveSequenceList.begin() );
3716*cdf0e10cSrcweir 		const InteractiveSequenceList::iterator aEnd( maInteractiveSequenceList.end() );
3717*cdf0e10cSrcweir 		while( aIter != aEnd )
3718*cdf0e10cSrcweir 		{
3719*cdf0e10cSrcweir 			InteractiveSequencePtr pIS( (*aIter++) );
3720*cdf0e10cSrcweir 			if( pIS->getTriggerShape() == xTriggerShape )
3721*cdf0e10cSrcweir 			{
3722*cdf0e10cSrcweir 				pNewSequence = pIS.get();
3723*cdf0e10cSrcweir 				break;
3724*cdf0e10cSrcweir 			}
3725*cdf0e10cSrcweir 		}
3726*cdf0e10cSrcweir 
3727*cdf0e10cSrcweir 		if( !pNewSequence )
3728*cdf0e10cSrcweir 			pNewSequence = createInteractiveSequence( xTriggerShape ).get();
3729*cdf0e10cSrcweir 	}
3730*cdf0e10cSrcweir 	else
3731*cdf0e10cSrcweir 	{
3732*cdf0e10cSrcweir 		pNewSequence = this;
3733*cdf0e10cSrcweir 	}
3734*cdf0e10cSrcweir 
3735*cdf0e10cSrcweir 	if( pOldSequence != pNewSequence )
3736*cdf0e10cSrcweir 	{
3737*cdf0e10cSrcweir 		if( pOldSequence )
3738*cdf0e10cSrcweir 			pOldSequence->maEffects.remove( pEffect );
3739*cdf0e10cSrcweir 		if( pNewSequence )
3740*cdf0e10cSrcweir 			pNewSequence->maEffects.push_back( pEffect );
3741*cdf0e10cSrcweir 		pEffect->setEffectSequence( pNewSequence );
3742*cdf0e10cSrcweir 		return true;
3743*cdf0e10cSrcweir 	}
3744*cdf0e10cSrcweir 	else
3745*cdf0e10cSrcweir 	{
3746*cdf0e10cSrcweir 		return false;
3747*cdf0e10cSrcweir 	}
3748*cdf0e10cSrcweir 
3749*cdf0e10cSrcweir }
3750*cdf0e10cSrcweir 
3751*cdf0e10cSrcweir // --------------------------------------------------------------------
3752*cdf0e10cSrcweir 
3753*cdf0e10cSrcweir IMPL_LINK( MainSequence, onTimerHdl, Timer *, EMPTYARG )
3754*cdf0e10cSrcweir {
3755*cdf0e10cSrcweir 	if( mbTimerMode )
3756*cdf0e10cSrcweir 	{
3757*cdf0e10cSrcweir 		implRebuild();
3758*cdf0e10cSrcweir 	}
3759*cdf0e10cSrcweir 	else
3760*cdf0e10cSrcweir 	{
3761*cdf0e10cSrcweir 		reset();
3762*cdf0e10cSrcweir 		createMainSequence();
3763*cdf0e10cSrcweir 	}
3764*cdf0e10cSrcweir 
3765*cdf0e10cSrcweir 	return 0;
3766*cdf0e10cSrcweir }
3767*cdf0e10cSrcweir 
3768*cdf0e10cSrcweir // --------------------------------------------------------------------
3769*cdf0e10cSrcweir 
3770*cdf0e10cSrcweir /** starts a timer that recreates the internal structure from the API core after 1 second */
3771*cdf0e10cSrcweir void MainSequence::startRecreateTimer()
3772*cdf0e10cSrcweir {
3773*cdf0e10cSrcweir 	if( !mbRebuilding && (mbIgnoreChanges == 0) )
3774*cdf0e10cSrcweir 	{
3775*cdf0e10cSrcweir 		mbTimerMode = false;
3776*cdf0e10cSrcweir 		maTimer.Start();
3777*cdf0e10cSrcweir 	}
3778*cdf0e10cSrcweir }
3779*cdf0e10cSrcweir 
3780*cdf0e10cSrcweir // --------------------------------------------------------------------
3781*cdf0e10cSrcweir 
3782*cdf0e10cSrcweir /** starts a timer that rebuilds the API core from the internal structure after 1 second */
3783*cdf0e10cSrcweir void MainSequence::startRebuildTimer()
3784*cdf0e10cSrcweir {
3785*cdf0e10cSrcweir 	mbTimerMode = true;
3786*cdf0e10cSrcweir 	maTimer.Start();
3787*cdf0e10cSrcweir }
3788*cdf0e10cSrcweir 
3789*cdf0e10cSrcweir // ====================================================================
3790*cdf0e10cSrcweir 
3791*cdf0e10cSrcweir InteractiveSequence::InteractiveSequence( const Reference< XTimeContainer >& xSequenceRoot, MainSequence* pMainSequence )
3792*cdf0e10cSrcweir : EffectSequenceHelper( xSequenceRoot ), mpMainSequence( pMainSequence )
3793*cdf0e10cSrcweir {
3794*cdf0e10cSrcweir 	mnSequenceType = EffectNodeType::INTERACTIVE_SEQUENCE;
3795*cdf0e10cSrcweir 
3796*cdf0e10cSrcweir 	try
3797*cdf0e10cSrcweir 	{
3798*cdf0e10cSrcweir 		if( mxSequenceRoot.is() )
3799*cdf0e10cSrcweir 		{
3800*cdf0e10cSrcweir 			Reference< XEnumerationAccess > xEnumerationAccess( mxSequenceRoot, UNO_QUERY_THROW );
3801*cdf0e10cSrcweir 			Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
3802*cdf0e10cSrcweir 			while( !mxEventSource.is() && xEnumeration->hasMoreElements() )
3803*cdf0e10cSrcweir 			{
3804*cdf0e10cSrcweir 				Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY_THROW );
3805*cdf0e10cSrcweir 
3806*cdf0e10cSrcweir 				Event aEvent;
3807*cdf0e10cSrcweir 				if( (xChildNode->getBegin() >>= aEvent) && (aEvent.Trigger == EventTrigger::ON_CLICK) )
3808*cdf0e10cSrcweir 					aEvent.Source >>= mxEventSource;
3809*cdf0e10cSrcweir 			}
3810*cdf0e10cSrcweir 		}
3811*cdf0e10cSrcweir 	}
3812*cdf0e10cSrcweir 	catch( Exception& e )
3813*cdf0e10cSrcweir 	{
3814*cdf0e10cSrcweir 		(void)e;
3815*cdf0e10cSrcweir 		DBG_ERROR( "sd::InteractiveSequence::InteractiveSequence(), exception cought!" );
3816*cdf0e10cSrcweir 		return;
3817*cdf0e10cSrcweir 	}
3818*cdf0e10cSrcweir }
3819*cdf0e10cSrcweir 
3820*cdf0e10cSrcweir // --------------------------------------------------------------------
3821*cdf0e10cSrcweir 
3822*cdf0e10cSrcweir void InteractiveSequence::rebuild()
3823*cdf0e10cSrcweir {
3824*cdf0e10cSrcweir 	mpMainSequence->rebuild();
3825*cdf0e10cSrcweir }
3826*cdf0e10cSrcweir 
3827*cdf0e10cSrcweir void InteractiveSequence::implRebuild()
3828*cdf0e10cSrcweir {
3829*cdf0e10cSrcweir 	EffectSequenceHelper::implRebuild();
3830*cdf0e10cSrcweir }
3831*cdf0e10cSrcweir 
3832*cdf0e10cSrcweir // --------------------------------------------------------------------
3833*cdf0e10cSrcweir 
3834*cdf0e10cSrcweir MainSequenceRebuildGuard::MainSequenceRebuildGuard( const MainSequencePtr& pMainSequence )
3835*cdf0e10cSrcweir : mpMainSequence( pMainSequence )
3836*cdf0e10cSrcweir {
3837*cdf0e10cSrcweir 	if( mpMainSequence.get() )
3838*cdf0e10cSrcweir 		mpMainSequence->lockRebuilds();
3839*cdf0e10cSrcweir }
3840*cdf0e10cSrcweir 
3841*cdf0e10cSrcweir MainSequenceRebuildGuard::~MainSequenceRebuildGuard()
3842*cdf0e10cSrcweir {
3843*cdf0e10cSrcweir 	if( mpMainSequence.get() )
3844*cdf0e10cSrcweir 		mpMainSequence->unlockRebuilds();
3845*cdf0e10cSrcweir }
3846*cdf0e10cSrcweir 
3847*cdf0e10cSrcweir 
3848*cdf0e10cSrcweir }
3849