1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sd.hxx" 30*cdf0e10cSrcweir #include <com/sun/star/animations/XAnimationNode.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/animations/Event.hpp> 32*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ANIMATIONS_XAnimateColor_HPP_ 33*cdf0e10cSrcweir #include <com/sun/star/animations/XAnimateColor.hpp> 34*cdf0e10cSrcweir #endif 35*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ANIMATIONS_XAnimateSet_HPP_ 36*cdf0e10cSrcweir #include <com/sun/star/animations/XAnimateSet.hpp> 37*cdf0e10cSrcweir #endif 38*cdf0e10cSrcweir #include <com/sun/star/animations/XCommand.hpp> 39*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ANIMATIONS_XAnimateMotion_HPP_ 40*cdf0e10cSrcweir #include <com/sun/star/animations/XAnimateMotion.hpp> 41*cdf0e10cSrcweir #endif 42*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ANIMATIONS_XAnimateTransform_HPP_ 43*cdf0e10cSrcweir #include <com/sun/star/animations/XAnimateTransform.hpp> 44*cdf0e10cSrcweir #endif 45*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ANIMATIONS_XTransitionFilter_HPP_ 46*cdf0e10cSrcweir #include <com/sun/star/animations/XTransitionFilter.hpp> 47*cdf0e10cSrcweir #endif 48*cdf0e10cSrcweir #include <com/sun/star/animations/XIterateContainer.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/animations/XAudio.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/animations/AnimationNodeType.hpp> 51*cdf0e10cSrcweir #include <com/sun/star/animations/ValuePair.hpp> 52*cdf0e10cSrcweir #include <com/sun/star/presentation/EffectNodeType.hpp> 53*cdf0e10cSrcweir #include <com/sun/star/util/XCloneable.hpp> 54*cdf0e10cSrcweir #include <com/sun/star/presentation/ParagraphTarget.hpp> 55*cdf0e10cSrcweir #include <com/sun/star/container/XEnumerationAccess.hpp> 56*cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp> 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir #include <map> 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir #include "comphelper/anytostring.hxx" 61*cdf0e10cSrcweir #include "cppuhelper/exc_hlp.hxx" 62*cdf0e10cSrcweir #include "rtl/ref.hxx" 63*cdf0e10cSrcweir #include <animations/animationnodehelper.hxx> 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir // header for class SdrObjListIter 66*cdf0e10cSrcweir #include <svx/svditer.hxx> 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir #include "sdpage.hxx" 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 71*cdf0e10cSrcweir using namespace ::com::sun::star::animations; 72*cdf0e10cSrcweir using namespace ::com::sun::star::presentation; 73*cdf0e10cSrcweir using namespace ::com::sun::star::container; 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir using ::rtl::OUString; 76*cdf0e10cSrcweir using ::rtl::OString; 77*cdf0e10cSrcweir using ::com::sun::star::drawing::XShape; 78*cdf0e10cSrcweir using ::com::sun::star::beans::NamedValue; 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir namespace sd 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir class CustomAnimationClonerImpl 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir public: 85*cdf0e10cSrcweir CustomAnimationClonerImpl(); 86*cdf0e10cSrcweir Reference< XAnimationNode > Clone( const Reference< XAnimationNode >& xSourceNode, const SdPage* pSource = 0, const SdPage* pTarget = 0 ); 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir private: 89*cdf0e10cSrcweir void transformNode( const Reference< XAnimationNode >& xNode ); 90*cdf0e10cSrcweir Any transformValue( const Any& rValue ); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir Reference< XShape > getClonedShape( const Reference< XShape >& xSource ) const; 93*cdf0e10cSrcweir Reference< XAnimationNode > getClonedNode( const Reference< XAnimationNode >& xSource ) const; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir mutable ::std::map< Reference< XShape >, Reference< XShape > > maShapeMap; 96*cdf0e10cSrcweir std::vector< Reference< XAnimationNode > > maSourceNodeVector; 97*cdf0e10cSrcweir std::vector< Reference< XAnimationNode > > maCloneNodeVector; 98*cdf0e10cSrcweir }; 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir CustomAnimationClonerImpl::CustomAnimationClonerImpl() 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir Reference< XAnimationNode > Clone( const Reference< XAnimationNode >& xSourceNode, const SdPage* pSource, const SdPage* pTarget ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir CustomAnimationClonerImpl aCloner; 107*cdf0e10cSrcweir return aCloner.Clone( xSourceNode, pSource, pTarget ); 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir Reference< XAnimationNode > CustomAnimationClonerImpl::Clone( const Reference< XAnimationNode >& xSourceNode, const SdPage* pSourcePage, const SdPage* pTargetPage ) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir try 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir // clone animation hierarchie 115*cdf0e10cSrcweir Reference< ::com::sun::star::util::XCloneable > xClonable( xSourceNode, UNO_QUERY_THROW ); 116*cdf0e10cSrcweir Reference< XAnimationNode > xCloneNode( xClonable->createClone(), UNO_QUERY_THROW ); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir // create a dictionary to map source to cloned shapes 119*cdf0e10cSrcweir if( pSourcePage && pTargetPage ) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir SdrObjListIter aSourceIter( *pSourcePage, IM_DEEPWITHGROUPS ); 122*cdf0e10cSrcweir SdrObjListIter aTargetIter( *pTargetPage, IM_DEEPWITHGROUPS ); 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir while( aSourceIter.IsMore() && aTargetIter.IsMore() ) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir SdrObject* pSource = aSourceIter.Next(); 127*cdf0e10cSrcweir SdrObject* pTarget = aTargetIter.Next(); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir if( pSource && pTarget) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir Reference< XShape > xSource( pSource->getUnoShape(), UNO_QUERY ); 132*cdf0e10cSrcweir Reference< XShape > xTarget( pTarget->getUnoShape(), UNO_QUERY ); 133*cdf0e10cSrcweir if( xSource.is() && xTarget.is() ) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir maShapeMap[xSource] = xTarget; 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir // create a dictionary to map source to cloned nodes 142*cdf0e10cSrcweir ::anim::create_deep_vector( xSourceNode, maSourceNodeVector ); 143*cdf0e10cSrcweir ::anim::create_deep_vector( xCloneNode, maCloneNodeVector ); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir transformNode( xCloneNode ); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir return xCloneNode; 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir catch( Exception& e ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir (void)e; 152*cdf0e10cSrcweir DBG_ERROR( 153*cdf0e10cSrcweir (OString("sd::CustomAnimationClonerImpl::Clone(), " 154*cdf0e10cSrcweir "exception caught: ") + 155*cdf0e10cSrcweir rtl::OUStringToOString( 156*cdf0e10cSrcweir comphelper::anyToString( cppu::getCaughtException() ), 157*cdf0e10cSrcweir RTL_TEXTENCODING_UTF8 )).getStr() ); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir Reference< XAnimationNode > xEmpty; 160*cdf0e10cSrcweir return xEmpty; 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir void CustomAnimationClonerImpl::transformNode( const Reference< XAnimationNode >& xNode ) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir try 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir xNode->setBegin( transformValue( xNode->getBegin() ) ); 169*cdf0e10cSrcweir xNode->setEnd( transformValue( xNode->getEnd() ) ); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir sal_Int16 nNodeType( xNode->getType() ); 172*cdf0e10cSrcweir switch( nNodeType ) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir case AnimationNodeType::ITERATE: 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir Reference< XIterateContainer > xIter( xNode, UNO_QUERY_THROW ); 177*cdf0e10cSrcweir xIter->setTarget( transformValue( xIter->getTarget() ) ); 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir // its intended that here is no break! 180*cdf0e10cSrcweir case AnimationNodeType::PAR: 181*cdf0e10cSrcweir case AnimationNodeType::SEQ: 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir Reference< XEnumerationAccess > xEnumerationAccess( xNode, UNO_QUERY_THROW ); 184*cdf0e10cSrcweir Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW ); 185*cdf0e10cSrcweir while( xEnumeration->hasMoreElements() ) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY_THROW ); 188*cdf0e10cSrcweir transformNode( xChildNode ); 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir break; 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir case AnimationNodeType::ANIMATE: 194*cdf0e10cSrcweir case AnimationNodeType::SET: 195*cdf0e10cSrcweir case AnimationNodeType::ANIMATEMOTION: 196*cdf0e10cSrcweir case AnimationNodeType::ANIMATECOLOR: 197*cdf0e10cSrcweir case AnimationNodeType::ANIMATETRANSFORM: 198*cdf0e10cSrcweir case AnimationNodeType::TRANSITIONFILTER: 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir Reference< XAnimate > xAnimate( xNode, UNO_QUERY_THROW ); 201*cdf0e10cSrcweir xAnimate->setTarget( transformValue( xAnimate->getTarget() ) ); 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir break; 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir case AnimationNodeType::COMMAND: 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir Reference< XCommand > xCommand( xNode, UNO_QUERY_THROW ); 208*cdf0e10cSrcweir xCommand->setTarget( transformValue( xCommand->getTarget() ) ); 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir break; 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir case AnimationNodeType::AUDIO: 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir Reference< XAudio > xAudio( xNode, UNO_QUERY_THROW ); 215*cdf0e10cSrcweir xAudio->setSource( transformValue( xAudio->getSource() ) ); 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir break; 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir Sequence< NamedValue > aUserData( xNode->getUserData() ); 221*cdf0e10cSrcweir if( aUserData.hasElements() ) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir NamedValue* pValue = aUserData.getArray(); 224*cdf0e10cSrcweir const sal_Int32 nLength = aUserData.getLength(); 225*cdf0e10cSrcweir sal_Int32 nElement; 226*cdf0e10cSrcweir for( nElement = 0; nElement < nLength; nElement++, pValue++ ) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir pValue->Value = transformValue( pValue->Value ); 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir xNode->setUserData( aUserData ); 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir catch( Exception& e ) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir (void)e; 237*cdf0e10cSrcweir DBG_ERROR( 238*cdf0e10cSrcweir (OString("sd::CustomAnimationClonerImpl::transformNode(), " 239*cdf0e10cSrcweir "exception caught: ") + 240*cdf0e10cSrcweir rtl::OUStringToOString( 241*cdf0e10cSrcweir comphelper::anyToString( cppu::getCaughtException() ), 242*cdf0e10cSrcweir RTL_TEXTENCODING_UTF8 )).getStr() ); 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir Any CustomAnimationClonerImpl::transformValue( const Any& rValue ) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir if( rValue.hasValue() ) try 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir if( rValue.getValueType() == ::getCppuType((const ValuePair*)0) ) 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir ValuePair aValuePair; 253*cdf0e10cSrcweir rValue >>= aValuePair; 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir aValuePair.First = transformValue( aValuePair.First ); 256*cdf0e10cSrcweir aValuePair.Second = transformValue( aValuePair.Second ); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir return makeAny( aValuePair ); 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir else if( rValue.getValueType() == ::getCppuType((Sequence<Any>*)0) ) 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir Sequence<Any> aSequence; 263*cdf0e10cSrcweir rValue >>= aSequence; 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir const sal_Int32 nLength = aSequence.getLength(); 266*cdf0e10cSrcweir sal_Int32 nElement; 267*cdf0e10cSrcweir Any* pAny = aSequence.getArray(); 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir for( nElement = 0; nElement < nLength; nElement++, pAny++ ) 270*cdf0e10cSrcweir *pAny = transformValue( *pAny ); 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir return makeAny( aSequence ); 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir else if( rValue.getValueTypeClass() == TypeClass_INTERFACE ) 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir Reference< XShape > xShape; 277*cdf0e10cSrcweir rValue >>= xShape; 278*cdf0e10cSrcweir if( xShape.is() ) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir return makeAny( getClonedShape( xShape ) ); 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir else 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir Reference< XAnimationNode > xNode; 285*cdf0e10cSrcweir rValue >>= xNode; 286*cdf0e10cSrcweir if( xNode.is() ) 287*cdf0e10cSrcweir return makeAny( getClonedNode( xNode ) ); 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir else if( rValue.getValueType() == ::getCppuType((const ParagraphTarget*)0) ) 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir ParagraphTarget aParaTarget; 293*cdf0e10cSrcweir rValue >>= aParaTarget; 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir aParaTarget.Shape = getClonedShape( aParaTarget.Shape ); 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir return makeAny( aParaTarget ); 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir else if( rValue.getValueType() == ::getCppuType((const Event*)0) ) 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir Event aEvent; 302*cdf0e10cSrcweir rValue >>= aEvent; 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir aEvent.Source = transformValue( aEvent.Source ); 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir return makeAny( aEvent ); 307*cdf0e10cSrcweir } 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir catch( Exception& e ) 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir (void)e; 312*cdf0e10cSrcweir DBG_ERROR( 313*cdf0e10cSrcweir (OString("sd::CustomAnimationClonerImpl::transformValue(), " 314*cdf0e10cSrcweir "exception caught: ") + 315*cdf0e10cSrcweir rtl::OUStringToOString( 316*cdf0e10cSrcweir comphelper::anyToString( cppu::getCaughtException() ), 317*cdf0e10cSrcweir RTL_TEXTENCODING_UTF8 )).getStr() ); 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir return rValue; 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir Reference< XShape > CustomAnimationClonerImpl::getClonedShape( const Reference< XShape >& xSource ) const 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir if( xSource.is() ) 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir if( maShapeMap.find(xSource) != maShapeMap.end() ) 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir return maShapeMap[xSource]; 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir DBG_ASSERT( maShapeMap.empty(), "sd::CustomAnimationClonerImpl::getClonedShape() failed!" ); 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir return xSource; 335*cdf0e10cSrcweir } 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir Reference< XAnimationNode > CustomAnimationClonerImpl::getClonedNode( const Reference< XAnimationNode >& xSource ) const 338*cdf0e10cSrcweir { 339*cdf0e10cSrcweir sal_Int32 nNode, nNodeCount = maSourceNodeVector.size(); 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir for( nNode = 0; nNode < nNodeCount; nNode++ ) 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir if( maSourceNodeVector[nNode] == xSource ) 344*cdf0e10cSrcweir return maCloneNodeVector[nNode]; 345*cdf0e10cSrcweir } 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir DBG_ERROR( "sd::CustomAnimationClonerImpl::getClonedNode() failed!" ); 348*cdf0e10cSrcweir return xSource; 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir } 351