1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5b190011SAndrew Rist  * distributed with this work for additional information
6*5b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist  * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5b190011SAndrew Rist  *
11*5b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5b190011SAndrew Rist  *
13*5b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist  * software distributed under the License is distributed on an
15*5b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5b190011SAndrew Rist  * specific language governing permissions and limitations
18*5b190011SAndrew Rist  * under the License.
19*5b190011SAndrew Rist  *
20*5b190011SAndrew Rist  *************************************************************/
21*5b190011SAndrew Rist 
22*5b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir #include <com/sun/star/presentation/ParagraphTarget.hpp>
27cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28cdf0e10cSrcweir #include <com/sun/star/presentation/EffectNodeType.hpp>
29cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
30cdf0e10cSrcweir #include <vos/mutex.hxx>
31cdf0e10cSrcweir #include <editeng/outliner.hxx>
32cdf0e10cSrcweir #include "CustomAnimationCloner.hxx"
33cdf0e10cSrcweir #include "drawdoc.hxx"
34cdf0e10cSrcweir #include "sdpage.hxx"
35cdf0e10cSrcweir #include <CustomAnimationPreset.hxx>
36cdf0e10cSrcweir #include <TransitionPreset.hxx>
37cdf0e10cSrcweir #include "undoanim.hxx"
38cdf0e10cSrcweir #include "EffectMigration.hxx"
39cdf0e10cSrcweir 
40cdf0e10cSrcweir using namespace ::vos;
41cdf0e10cSrcweir using ::rtl::OUString;
42cdf0e10cSrcweir using namespace ::sd;
43cdf0e10cSrcweir using namespace ::com::sun::star::uno;
44cdf0e10cSrcweir using namespace ::com::sun::star::animations;
45cdf0e10cSrcweir using namespace ::com::sun::star::presentation;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir using ::com::sun::star::drawing::XShape;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir /** returns a helper class to manipulate effects inside the main sequence */
getMainSequence()50cdf0e10cSrcweir sd::MainSequencePtr SdPage::getMainSequence()
51cdf0e10cSrcweir {
52cdf0e10cSrcweir 	if( 0 == mpMainSequence.get() )
53cdf0e10cSrcweir 		mpMainSequence.reset( new sd::MainSequence( getAnimationNode() ) );
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 	return mpMainSequence;
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
58cdf0e10cSrcweir /** returns the main animation node */
getAnimationNode()59cdf0e10cSrcweir Reference< XAnimationNode > SdPage::getAnimationNode() throw (RuntimeException)
60cdf0e10cSrcweir {
61cdf0e10cSrcweir 	if( !mxAnimationNode.is() )
62cdf0e10cSrcweir 	{
63cdf0e10cSrcweir 		mxAnimationNode = Reference< XAnimationNode >::query(::comphelper::getProcessServiceFactory()->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.animations.ParallelTimeContainer"))));
64cdf0e10cSrcweir 		if( mxAnimationNode.is() )
65cdf0e10cSrcweir 		{
66cdf0e10cSrcweir 			Sequence< ::com::sun::star::beans::NamedValue > aUserData( 1 );
67cdf0e10cSrcweir 			aUserData[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "node-type" ) );
68cdf0e10cSrcweir 			aUserData[0].Value <<= ::com::sun::star::presentation::EffectNodeType::TIMING_ROOT;
69cdf0e10cSrcweir 			mxAnimationNode->setUserData( aUserData );
70cdf0e10cSrcweir 		}
71cdf0e10cSrcweir 	}
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	return mxAnimationNode;
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
setAnimationNode(Reference<XAnimationNode> & xNode)76cdf0e10cSrcweir void SdPage::setAnimationNode( Reference< XAnimationNode >& xNode ) throw (RuntimeException)
77cdf0e10cSrcweir {
78cdf0e10cSrcweir 	mxAnimationNode = xNode;
79cdf0e10cSrcweir 	if( mpMainSequence.get() )
80cdf0e10cSrcweir 		mpMainSequence->reset( xNode );
81cdf0e10cSrcweir }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir /** removes all custom animations for the given shape */
removeAnimations(const SdrObject * pObj)84cdf0e10cSrcweir void SdPage::removeAnimations( const SdrObject* pObj )
85cdf0e10cSrcweir {
86cdf0e10cSrcweir 	if( mxAnimationNode.is() )
87cdf0e10cSrcweir 	{
88cdf0e10cSrcweir 		getMainSequence();
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 		Reference< XShape > xShape( const_cast<SdrObject*>(pObj)->getUnoShape(), UNO_QUERY );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 		if( mpMainSequence->hasEffect( xShape ) )
93cdf0e10cSrcweir 			mpMainSequence->disposeShape( xShape );
94cdf0e10cSrcweir 	}
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
hasAnimationNode() const97cdf0e10cSrcweir bool SdPage::hasAnimationNode() const
98cdf0e10cSrcweir {
99cdf0e10cSrcweir 	return mxAnimationNode.is();
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
SetFadeEffect(::com::sun::star::presentation::FadeEffect eNewEffect)102cdf0e10cSrcweir void SdPage::SetFadeEffect(::com::sun::star::presentation::FadeEffect eNewEffect)
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 	EffectMigration::SetFadeEffect( this, eNewEffect );
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
GetFadeEffect() const107cdf0e10cSrcweir FadeEffect SdPage::GetFadeEffect() const
108cdf0e10cSrcweir {
109cdf0e10cSrcweir 	return EffectMigration::GetFadeEffect( this );
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir /** callback from the sd::View when a new paragraph for one object on this page is created */
onParagraphInserted(::Outliner * pOutliner,Paragraph * pPara,SdrObject * pObj)113cdf0e10cSrcweir void SdPage::onParagraphInserted( ::Outliner* pOutliner, Paragraph* pPara, SdrObject* pObj )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir 	if( mxAnimationNode.is() )
116cdf0e10cSrcweir 	{
117cdf0e10cSrcweir 		ParagraphTarget aTarget;
118cdf0e10cSrcweir 		aTarget.Shape = Reference< XShape >( pObj->getUnoShape(), UNO_QUERY );
119cdf0e10cSrcweir 		aTarget.Paragraph = (sal_Int16)pOutliner->GetAbsPos( pPara );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 		getMainSequence()->insertTextRange( makeAny( aTarget ) );
122cdf0e10cSrcweir 	}
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir /** callback from the sd::View when a paragraph from one object on this page is removed */
onParagraphRemoving(::Outliner * pOutliner,Paragraph * pPara,SdrObject * pObj)126cdf0e10cSrcweir void SdPage::onParagraphRemoving( ::Outliner* pOutliner, Paragraph* pPara, SdrObject* pObj )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir 	if( mxAnimationNode.is() )
129cdf0e10cSrcweir 	{
130cdf0e10cSrcweir 		ParagraphTarget aTarget;
131cdf0e10cSrcweir 		aTarget.Shape = Reference< XShape >( pObj->getUnoShape(), UNO_QUERY );
132cdf0e10cSrcweir 		aTarget.Paragraph = (sal_Int16)pOutliner->GetAbsPos( pPara );
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 		getMainSequence()->disposeTextRange( makeAny( aTarget ) );
135cdf0e10cSrcweir 	}
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir /** callback from the sd::View when an object just left text edit mode */
onEndTextEdit(SdrObject * pObj)139cdf0e10cSrcweir void SdPage::onEndTextEdit( SdrObject* pObj )
140cdf0e10cSrcweir {
141cdf0e10cSrcweir 	if( pObj && mxAnimationNode.is() )
142cdf0e10cSrcweir 	{
143cdf0e10cSrcweir 		Reference< XShape > xObj( pObj->getUnoShape(), UNO_QUERY );
144cdf0e10cSrcweir 		getMainSequence()->onTextChanged( xObj );
145cdf0e10cSrcweir 	}
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
cloneAnimations(SdPage & rTargetPage) const148cdf0e10cSrcweir void SdPage::cloneAnimations( SdPage& rTargetPage ) const
149cdf0e10cSrcweir {
150cdf0e10cSrcweir 	if( mxAnimationNode.is() )
151cdf0e10cSrcweir 	{
152cdf0e10cSrcweir 		Reference< XAnimationNode > xClonedNode(
153cdf0e10cSrcweir 			::sd::Clone( mxAnimationNode, this, &rTargetPage ) );
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 		if( xClonedNode.is() )
156cdf0e10cSrcweir 			rTargetPage.setAnimationNode( xClonedNode );
157cdf0e10cSrcweir 	}
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
160