20#include <com/sun/star/animations/XAnimate.hpp>
21#include <com/sun/star/animations/XAnimationNode.hpp>
22#include <com/sun/star/animations/Event.hpp>
23#include <com/sun/star/animations/XCommand.hpp>
24#include <com/sun/star/animations/XIterateContainer.hpp>
25#include <com/sun/star/animations/XAudio.hpp>
26#include <com/sun/star/animations/AnimationNodeType.hpp>
27#include <com/sun/star/animations/ValuePair.hpp>
28#include <com/sun/star/util/XCloneable.hpp>
29#include <com/sun/star/presentation/ParagraphTarget.hpp>
30#include <com/sun/star/container/XEnumerationAccess.hpp>
31#include <com/sun/star/beans/NamedValue.hpp>
49using ::com::sun::star::drawing::XShape;
50using ::com::sun::star::beans::NamedValue;
56 class CustomAnimationClonerImpl
59 CustomAnimationClonerImpl();
60 Reference< XAnimationNode >
Clone(
const Reference< XAnimationNode >& xSourceNode,
const SdPage* pSource,
const SdPage* pTarget );
63 void transformNode(
const Reference< XAnimationNode >& xNode );
64 Any transformValue(
const Any& rValue );
66 Reference< XShape > getClonedShape(
const Reference< XShape >& xSource )
const;
67 Reference< XAnimationNode > getClonedNode(
const Reference< XAnimationNode >& xSource )
const;
69 mutable ::std::map< Reference< XShape >, Reference< XShape > > maShapeMap;
70 std::vector< Reference< XAnimationNode > > maSourceNodeVector;
71 std::vector< Reference< XAnimationNode > > maCloneNodeVector;
76 CustomAnimationClonerImpl::CustomAnimationClonerImpl()
80 Reference< XAnimationNode >
Clone(
const Reference< XAnimationNode >& xSourceNode,
const SdPage* pSource,
const SdPage* pTarget )
82 CustomAnimationClonerImpl aCloner;
83 return aCloner.Clone( xSourceNode, pSource, pTarget );
91 Reference< css::util::XCloneable > xClonable( xSourceNode, UNO_QUERY_THROW );
92 Reference< XAnimationNode > xCloneNode( xClonable->createClone(), UNO_QUERY_THROW );
95 if( pSourcePage && pTargetPage )
97 SdrObjListIter aSourceIter( pSourcePage, SdrIterMode::DeepWithGroups );
98 SdrObjListIter aTargetIter( pTargetPage, SdrIterMode::DeepWithGroups );
100 while( aSourceIter.IsMore() && aTargetIter.IsMore() )
105 if( pSource && pTarget)
107 Reference< XShape > xSource( pSource->
getUnoShape(), UNO_QUERY );
109 if( xSource.is() &&
xTarget.is() )
118 ::anim::create_deep_vector( xSourceNode, maSourceNodeVector );
119 ::anim::create_deep_vector( xCloneNode, maCloneNodeVector );
121 transformNode( xCloneNode );
128 Reference< XAnimationNode > xEmpty;
133 void CustomAnimationClonerImpl::transformNode(
const Reference< XAnimationNode >& xNode )
137 xNode->setBegin( transformValue( xNode->getBegin() ) );
138 xNode->setEnd( transformValue( xNode->getEnd() ) );
140 sal_Int16 nNodeType( xNode->getType() );
143 case AnimationNodeType::ITERATE:
145 Reference< XIterateContainer > xIter( xNode, UNO_QUERY_THROW );
146 xIter->setTarget( transformValue( xIter->getTarget() ) );
149 case AnimationNodeType::PAR:
150 case AnimationNodeType::SEQ:
152 Reference< XEnumerationAccess > xEnumerationAccess( xNode, UNO_QUERY_THROW );
153 Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_SET_THROW );
154 while( xEnumeration->hasMoreElements() )
156 Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY_THROW );
157 transformNode( xChildNode );
162 case AnimationNodeType::ANIMATE:
163 case AnimationNodeType::SET:
164 case AnimationNodeType::ANIMATEMOTION:
165 case AnimationNodeType::ANIMATEPHYSICS:
166 case AnimationNodeType::ANIMATECOLOR:
167 case AnimationNodeType::ANIMATETRANSFORM:
168 case AnimationNodeType::TRANSITIONFILTER:
170 Reference< XAnimate > xAnimate( xNode, UNO_QUERY_THROW );
171 xAnimate->setTarget( transformValue( xAnimate->getTarget() ) );
175 case AnimationNodeType::COMMAND:
177 Reference< XCommand > xCommand( xNode, UNO_QUERY_THROW );
178 xCommand->setTarget( transformValue( xCommand->getTarget() ) );
182 case AnimationNodeType::AUDIO:
184 Reference< XAudio > xAudio( xNode, UNO_QUERY_THROW );
185 xAudio->setSource( transformValue( xAudio->getSource() ) );
190 Sequence< NamedValue > aUserData( xNode->getUserData() );
191 if( aUserData.hasElements() )
193 for( NamedValue & namedValue : asNonConstRange(aUserData) )
195 namedValue.Value = transformValue( namedValue.Value );
198 xNode->setUserData( aUserData );
207 Any CustomAnimationClonerImpl::transformValue(
const Any& rValue )
209 if( rValue.hasValue() )
try
213 ValuePair aValuePair;
214 rValue >>= aValuePair;
216 aValuePair.First = transformValue( aValuePair.First );
217 aValuePair.Second = transformValue( aValuePair.Second );
219 return Any( aValuePair );
221 else if( rValue.getValueType() ==
cppu::UnoType< Sequence<Any> >::get() )
223 Sequence<Any> aSequence;
224 rValue >>= aSequence;
226 for( Any& rAny : asNonConstRange(aSequence) )
227 rAny = transformValue( rAny );
229 return Any( aSequence );
231 else if( rValue.getValueTypeClass() == TypeClass_INTERFACE )
233 Reference< XShape > xShape;
237 return Any( getClonedShape( xShape ) );
241 Reference< XAnimationNode > xNode;
244 return Any( getClonedNode( xNode ) );
249 ParagraphTarget aParaTarget;
250 rValue >>= aParaTarget;
252 aParaTarget.Shape = getClonedShape( aParaTarget.Shape );
254 return Any( aParaTarget );
263 return Any( aEvent );
274 Reference< XShape > CustomAnimationClonerImpl::getClonedShape(
const Reference< XShape >& xSource )
const
278 if( maShapeMap.find(xSource) != maShapeMap.end() )
280 return maShapeMap[xSource];
283 DBG_ASSERT( maShapeMap.empty(),
"sd::CustomAnimationClonerImpl::getClonedShape() failed!" );
288 Reference< XAnimationNode > CustomAnimationClonerImpl::getClonedNode(
const Reference< XAnimationNode >& xSource )
const
290 std::size_t nNodeCount = maSourceNodeVector.size();
291 std::size_t nCloneNodeCount = maCloneNodeVector.size();
293 if (nNodeCount != nCloneNodeCount)
294 SAL_WARN(
"sd.core",
"Sizes of maSourceNodeVector and maCloneNodeVector mismatch!");
296 for( std::size_t nNode = 0; nNode < nNodeCount && nNode < nCloneNodeCount; ++nNode )
298 if( maSourceNodeVector[nNode] == xSource )
299 return maCloneNodeVector[nNode];
302 OSL_FAIL(
"sd::CustomAnimationClonerImpl::getClonedNode() failed!" );
virtual css::uno::Reference< css::drawing::XShape > getUnoShape()
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XInterface > xTarget
#define SAL_WARN(area, stream)
Reference< XAnimationNode > Clone(const Reference< XAnimationNode > &xSourceNode, const SdPage *pSource, const SdPage *pTarget)