1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sd.hxx" 30 #include <com/sun/star/presentation/ParagraphTarget.hpp> 31 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 32 #include <com/sun/star/presentation/EffectNodeType.hpp> 33 #include <comphelper/processfactory.hxx> 34 #include <vos/mutex.hxx> 35 #include <editeng/outliner.hxx> 36 #include "CustomAnimationCloner.hxx" 37 #include "drawdoc.hxx" 38 #include "sdpage.hxx" 39 #include <CustomAnimationPreset.hxx> 40 #include <TransitionPreset.hxx> 41 #include "undoanim.hxx" 42 #include "EffectMigration.hxx" 43 44 using namespace ::vos; 45 using ::rtl::OUString; 46 using namespace ::sd; 47 using namespace ::com::sun::star::uno; 48 using namespace ::com::sun::star::animations; 49 using namespace ::com::sun::star::presentation; 50 51 using ::com::sun::star::drawing::XShape; 52 53 /** returns a helper class to manipulate effects inside the main sequence */ 54 sd::MainSequencePtr SdPage::getMainSequence() 55 { 56 if( 0 == mpMainSequence.get() ) 57 mpMainSequence.reset( new sd::MainSequence( getAnimationNode() ) ); 58 59 return mpMainSequence; 60 } 61 62 /** returns the main animation node */ 63 Reference< XAnimationNode > SdPage::getAnimationNode() throw (RuntimeException) 64 { 65 if( !mxAnimationNode.is() ) 66 { 67 mxAnimationNode = Reference< XAnimationNode >::query(::comphelper::getProcessServiceFactory()->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.animations.ParallelTimeContainer")))); 68 if( mxAnimationNode.is() ) 69 { 70 Sequence< ::com::sun::star::beans::NamedValue > aUserData( 1 ); 71 aUserData[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "node-type" ) ); 72 aUserData[0].Value <<= ::com::sun::star::presentation::EffectNodeType::TIMING_ROOT; 73 mxAnimationNode->setUserData( aUserData ); 74 } 75 } 76 77 return mxAnimationNode; 78 } 79 80 void SdPage::setAnimationNode( Reference< XAnimationNode >& xNode ) throw (RuntimeException) 81 { 82 mxAnimationNode = xNode; 83 if( mpMainSequence.get() ) 84 mpMainSequence->reset( xNode ); 85 } 86 87 /** removes all custom animations for the given shape */ 88 void SdPage::removeAnimations( const SdrObject* pObj ) 89 { 90 if( mxAnimationNode.is() ) 91 { 92 getMainSequence(); 93 94 Reference< XShape > xShape( const_cast<SdrObject*>(pObj)->getUnoShape(), UNO_QUERY ); 95 96 if( mpMainSequence->hasEffect( xShape ) ) 97 mpMainSequence->disposeShape( xShape ); 98 } 99 } 100 101 bool SdPage::hasAnimationNode() const 102 { 103 return mxAnimationNode.is(); 104 } 105 106 void SdPage::SetFadeEffect(::com::sun::star::presentation::FadeEffect eNewEffect) 107 { 108 EffectMigration::SetFadeEffect( this, eNewEffect ); 109 } 110 111 FadeEffect SdPage::GetFadeEffect() const 112 { 113 return EffectMigration::GetFadeEffect( this ); 114 } 115 116 /** callback from the sd::View when a new paragraph for one object on this page is created */ 117 void SdPage::onParagraphInserted( ::Outliner* pOutliner, Paragraph* pPara, SdrObject* pObj ) 118 { 119 if( mxAnimationNode.is() ) 120 { 121 ParagraphTarget aTarget; 122 aTarget.Shape = Reference< XShape >( pObj->getUnoShape(), UNO_QUERY ); 123 aTarget.Paragraph = (sal_Int16)pOutliner->GetAbsPos( pPara ); 124 125 getMainSequence()->insertTextRange( makeAny( aTarget ) ); 126 } 127 } 128 129 /** callback from the sd::View when a paragraph from one object on this page is removed */ 130 void SdPage::onParagraphRemoving( ::Outliner* pOutliner, Paragraph* pPara, SdrObject* pObj ) 131 { 132 if( mxAnimationNode.is() ) 133 { 134 ParagraphTarget aTarget; 135 aTarget.Shape = Reference< XShape >( pObj->getUnoShape(), UNO_QUERY ); 136 aTarget.Paragraph = (sal_Int16)pOutliner->GetAbsPos( pPara ); 137 138 getMainSequence()->disposeTextRange( makeAny( aTarget ) ); 139 } 140 } 141 142 /** callback from the sd::View when an object just left text edit mode */ 143 void SdPage::onEndTextEdit( SdrObject* pObj ) 144 { 145 if( pObj && mxAnimationNode.is() ) 146 { 147 Reference< XShape > xObj( pObj->getUnoShape(), UNO_QUERY ); 148 getMainSequence()->onTextChanged( xObj ); 149 } 150 } 151 152 void SdPage::cloneAnimations( SdPage& rTargetPage ) const 153 { 154 if( mxAnimationNode.is() ) 155 { 156 Reference< XAnimationNode > xClonedNode( 157 ::sd::Clone( mxAnimationNode, this, &rTargetPage ) ); 158 159 if( xClonedNode.is() ) 160 rTargetPage.setAnimationNode( xClonedNode ); 161 } 162 } 163 164