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