update emoji autocorrect entries from po-files
[LibreOffice.git] / sd / source / core / CustomAnimationCloner.cxx
blob6bd23086871a7d66b3eb400eb4a42980d7b61a1c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/animations/XAnimationNode.hpp>
21 #include <com/sun/star/animations/Event.hpp>
22 #include <com/sun/star/animations/XAnimateColor.hpp>
23 #include <com/sun/star/animations/XAnimateSet.hpp>
24 #include <com/sun/star/animations/XCommand.hpp>
25 #include <com/sun/star/animations/XAnimateMotion.hpp>
26 #include <com/sun/star/animations/XAnimateTransform.hpp>
27 #include <com/sun/star/animations/XTransitionFilter.hpp>
28 #include <com/sun/star/animations/XIterateContainer.hpp>
29 #include <com/sun/star/animations/XAudio.hpp>
30 #include <com/sun/star/animations/AnimationNodeType.hpp>
31 #include <com/sun/star/animations/ValuePair.hpp>
32 #include <com/sun/star/presentation/EffectNodeType.hpp>
33 #include <com/sun/star/util/XCloneable.hpp>
34 #include <com/sun/star/presentation/ParagraphTarget.hpp>
35 #include <com/sun/star/container/XEnumerationAccess.hpp>
36 #include <com/sun/star/beans/NamedValue.hpp>
38 #include <map>
40 #include "comphelper/anytostring.hxx"
41 #include "cppuhelper/exc_hlp.hxx"
42 #include "rtl/ref.hxx"
43 #include <animations/animationnodehelper.hxx>
45 #include <svx/svditer.hxx>
47 #include "CustomAnimationCloner.hxx"
48 #include "sdpage.hxx"
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::animations;
52 using namespace ::com::sun::star::presentation;
53 using namespace ::com::sun::star::container;
55 using ::com::sun::star::drawing::XShape;
56 using ::com::sun::star::beans::NamedValue;
58 namespace sd
60 class CustomAnimationClonerImpl
62 public:
63 CustomAnimationClonerImpl();
64 Reference< XAnimationNode > Clone( const Reference< XAnimationNode >& xSourceNode, const SdPage* pSource = 0, const SdPage* pTarget = 0 );
66 private:
67 void transformNode( const Reference< XAnimationNode >& xNode );
68 Any transformValue( const Any& rValue );
70 Reference< XShape > getClonedShape( const Reference< XShape >& xSource ) const;
71 Reference< XAnimationNode > getClonedNode( const Reference< XAnimationNode >& xSource ) const;
73 mutable ::std::map< Reference< XShape >, Reference< XShape > > maShapeMap;
74 std::vector< Reference< XAnimationNode > > maSourceNodeVector;
75 std::vector< Reference< XAnimationNode > > maCloneNodeVector;
78 CustomAnimationClonerImpl::CustomAnimationClonerImpl()
82 Reference< XAnimationNode > Clone( const Reference< XAnimationNode >& xSourceNode, const SdPage* pSource, const SdPage* pTarget )
84 CustomAnimationClonerImpl aCloner;
85 return aCloner.Clone( xSourceNode, pSource, pTarget );
88 Reference< XAnimationNode > CustomAnimationClonerImpl::Clone( const Reference< XAnimationNode >& xSourceNode, const SdPage* pSourcePage, const SdPage* pTargetPage )
90 try
92 // clone animation hierarchy
93 Reference< ::com::sun::star::util::XCloneable > xClonable( xSourceNode, UNO_QUERY_THROW );
94 Reference< XAnimationNode > xCloneNode( xClonable->createClone(), UNO_QUERY_THROW );
96 // create a dictionary to map source to cloned shapes
97 if( pSourcePage && pTargetPage )
99 SdrObjListIter aSourceIter( *pSourcePage, IM_DEEPWITHGROUPS );
100 SdrObjListIter aTargetIter( *pTargetPage, IM_DEEPWITHGROUPS );
102 while( aSourceIter.IsMore() && aTargetIter.IsMore() )
104 SdrObject* pSource = aSourceIter.Next();
105 SdrObject* pTarget = aTargetIter.Next();
107 if( pSource && pTarget)
109 Reference< XShape > xSource( pSource->getUnoShape(), UNO_QUERY );
110 Reference< XShape > xTarget( pTarget->getUnoShape(), UNO_QUERY );
111 if( xSource.is() && xTarget.is() )
113 maShapeMap[xSource] = xTarget;
119 // create a dictionary to map source to cloned nodes
120 ::anim::create_deep_vector( xSourceNode, maSourceNodeVector );
121 ::anim::create_deep_vector( xCloneNode, maCloneNodeVector );
123 transformNode( xCloneNode );
125 return xCloneNode;
127 catch( Exception& )
129 OSL_FAIL(
130 OString(OString("sd::CustomAnimationClonerImpl::Clone(), "
131 "exception caught: ") +
132 OUStringToOString(
133 comphelper::anyToString( cppu::getCaughtException() ),
134 RTL_TEXTENCODING_UTF8 )).getStr() );
136 Reference< XAnimationNode > xEmpty;
137 return xEmpty;
141 void CustomAnimationClonerImpl::transformNode( const Reference< XAnimationNode >& xNode )
145 xNode->setBegin( transformValue( xNode->getBegin() ) );
146 xNode->setEnd( transformValue( xNode->getEnd() ) );
148 sal_Int16 nNodeType( xNode->getType() );
149 switch( nNodeType )
151 case AnimationNodeType::ITERATE:
153 Reference< XIterateContainer > xIter( xNode, UNO_QUERY_THROW );
154 xIter->setTarget( transformValue( xIter->getTarget() ) );
156 // its intended that here is no break!
157 case AnimationNodeType::PAR:
158 case AnimationNodeType::SEQ:
160 Reference< XEnumerationAccess > xEnumerationAccess( xNode, UNO_QUERY_THROW );
161 Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
162 while( xEnumeration->hasMoreElements() )
164 Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY_THROW );
165 transformNode( xChildNode );
168 break;
170 case AnimationNodeType::ANIMATE:
171 case AnimationNodeType::SET:
172 case AnimationNodeType::ANIMATEMOTION:
173 case AnimationNodeType::ANIMATECOLOR:
174 case AnimationNodeType::ANIMATETRANSFORM:
175 case AnimationNodeType::TRANSITIONFILTER:
177 Reference< XAnimate > xAnimate( xNode, UNO_QUERY_THROW );
178 xAnimate->setTarget( transformValue( xAnimate->getTarget() ) );
180 break;
182 case AnimationNodeType::COMMAND:
184 Reference< XCommand > xCommand( xNode, UNO_QUERY_THROW );
185 xCommand->setTarget( transformValue( xCommand->getTarget() ) );
187 break;
189 case AnimationNodeType::AUDIO:
191 Reference< XAudio > xAudio( xNode, UNO_QUERY_THROW );
192 xAudio->setSource( transformValue( xAudio->getSource() ) );
194 break;
197 Sequence< NamedValue > aUserData( xNode->getUserData() );
198 if( aUserData.hasElements() )
200 NamedValue* pValue = aUserData.getArray();
201 const sal_Int32 nLength = aUserData.getLength();
202 sal_Int32 nElement;
203 for( nElement = 0; nElement < nLength; nElement++, pValue++ )
205 pValue->Value = transformValue( pValue->Value );
208 xNode->setUserData( aUserData );
211 catch( Exception& )
213 OSL_FAIL(
214 OString(OString("sd::CustomAnimationClonerImpl::transformNode(), "
215 "exception caught: ") +
216 OUStringToOString(
217 comphelper::anyToString( cppu::getCaughtException() ),
218 RTL_TEXTENCODING_UTF8 )).getStr() );
222 Any CustomAnimationClonerImpl::transformValue( const Any& rValue )
224 if( rValue.hasValue() ) try
226 if( rValue.getValueType() == cppu::UnoType<ValuePair>::get() )
228 ValuePair aValuePair;
229 rValue >>= aValuePair;
231 aValuePair.First = transformValue( aValuePair.First );
232 aValuePair.Second = transformValue( aValuePair.Second );
234 return makeAny( aValuePair );
236 else if( rValue.getValueType() == cppu::UnoType< Sequence<Any> >::get() )
238 Sequence<Any> aSequence;
239 rValue >>= aSequence;
241 const sal_Int32 nLength = aSequence.getLength();
242 sal_Int32 nElement;
243 Any* pAny = aSequence.getArray();
245 for( nElement = 0; nElement < nLength; nElement++, pAny++ )
246 *pAny = transformValue( *pAny );
248 return makeAny( aSequence );
250 else if( rValue.getValueTypeClass() == TypeClass_INTERFACE )
252 Reference< XShape > xShape;
253 rValue >>= xShape;
254 if( xShape.is() )
256 return makeAny( getClonedShape( xShape ) );
258 else
260 Reference< XAnimationNode > xNode;
261 rValue >>= xNode;
262 if( xNode.is() )
263 return makeAny( getClonedNode( xNode ) );
266 else if( rValue.getValueType() == cppu::UnoType<ParagraphTarget>::get() )
268 ParagraphTarget aParaTarget;
269 rValue >>= aParaTarget;
271 aParaTarget.Shape = getClonedShape( aParaTarget.Shape );
273 return makeAny( aParaTarget );
275 else if( rValue.getValueType() == cppu::UnoType<Event>::get() )
277 Event aEvent;
278 rValue >>= aEvent;
280 aEvent.Source = transformValue( aEvent.Source );
282 return makeAny( aEvent );
285 catch( Exception& )
287 OSL_FAIL(
288 OString(OString("sd::CustomAnimationClonerImpl::transformValue(), "
289 "exception caught: ") +
290 OUStringToOString(
291 comphelper::anyToString( cppu::getCaughtException() ),
292 RTL_TEXTENCODING_UTF8 )).getStr() );
295 return rValue;
298 Reference< XShape > CustomAnimationClonerImpl::getClonedShape( const Reference< XShape >& xSource ) const
300 if( xSource.is() )
302 if( maShapeMap.find(xSource) != maShapeMap.end() )
304 return maShapeMap[xSource];
307 DBG_ASSERT( maShapeMap.empty(), "sd::CustomAnimationClonerImpl::getClonedShape() failed!" );
309 return xSource;
312 Reference< XAnimationNode > CustomAnimationClonerImpl::getClonedNode( const Reference< XAnimationNode >& xSource ) const
314 sal_Int32 nNode, nNodeCount = maSourceNodeVector.size();
316 for( nNode = 0; nNode < nNodeCount; nNode++ )
318 if( maSourceNodeVector[nNode] == xSource )
319 return maCloneNodeVector[nNode];
322 OSL_FAIL( "sd::CustomAnimationClonerImpl::getClonedNode() failed!" );
323 return xSource;
327 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */