1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdpage_animations.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
33 #include <com/sun/star/presentation/ParagraphTarget.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/presentation/EffectNodeType.hpp>
36 #include <comphelper/processfactory.hxx>
37 #include <vos/mutex.hxx>
38 #include <svx/outliner.hxx>
39 #include "CustomAnimationCloner.hxx"
40 #include "drawdoc.hxx"
42 #include <CustomAnimationPreset.hxx>
43 #include <TransitionPreset.hxx>
44 #include "undoanim.hxx"
45 #include "EffectMigration.hxx"
47 using namespace ::vos
;
48 using ::rtl::OUString
;
50 using namespace ::com::sun::star::uno
;
51 using namespace ::com::sun::star::animations
;
52 using namespace ::com::sun::star::presentation
;
54 using ::com::sun::star::drawing::XShape
;
56 /** returns a helper class to manipulate effects inside the main sequence */
57 sd::MainSequencePtr
SdPage::getMainSequence()
59 if( 0 == mpMainSequence
.get() )
60 mpMainSequence
.reset( new sd::MainSequence( getAnimationNode() ) );
62 return mpMainSequence
;
65 /** returns the main animation node */
66 Reference
< XAnimationNode
> SdPage::getAnimationNode() throw (RuntimeException
)
68 if( !mxAnimationNode
.is() )
70 mxAnimationNode
= Reference
< XAnimationNode
>::query(::comphelper::getProcessServiceFactory()->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.animations.ParallelTimeContainer"))));
71 if( mxAnimationNode
.is() )
73 Sequence
< ::com::sun::star::beans::NamedValue
> aUserData( 1 );
74 aUserData
[0].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "node-type" ) );
75 aUserData
[0].Value
<<= ::com::sun::star::presentation::EffectNodeType::TIMING_ROOT
;
76 mxAnimationNode
->setUserData( aUserData
);
80 return mxAnimationNode
;
83 void SdPage::setAnimationNode( Reference
< XAnimationNode
>& xNode
) throw (RuntimeException
)
85 mxAnimationNode
= xNode
;
86 if( mpMainSequence
.get() )
87 mpMainSequence
->reset( xNode
);
90 /** removes all custom animations for the given shape */
91 void SdPage::removeAnimations( const SdrObject
* pObj
)
93 if( mxAnimationNode
.is() )
97 Reference
< XShape
> xShape( const_cast<SdrObject
*>(pObj
)->getUnoShape(), UNO_QUERY
);
99 if( mpMainSequence
->hasEffect( xShape
) )
100 mpMainSequence
->disposeShape( xShape
);
104 bool SdPage::hasAnimationNode() const
106 return mxAnimationNode
.is();
109 void SdPage::SetFadeEffect(::com::sun::star::presentation::FadeEffect eNewEffect
)
111 EffectMigration::SetFadeEffect( this, eNewEffect
);
114 FadeEffect
SdPage::GetFadeEffect() const
116 return EffectMigration::GetFadeEffect( this );
119 /** callback from the sd::View when a new paragraph for one object on this page is created */
120 void SdPage::onParagraphInserted( ::Outliner
* pOutliner
, Paragraph
* pPara
, SdrObject
* pObj
)
122 if( mxAnimationNode
.is() )
124 ParagraphTarget aTarget
;
125 aTarget
.Shape
= Reference
< XShape
>( pObj
->getUnoShape(), UNO_QUERY
);
126 aTarget
.Paragraph
= (sal_Int16
)pOutliner
->GetAbsPos( pPara
);
128 getMainSequence()->insertTextRange( makeAny( aTarget
) );
132 /** callback from the sd::View when a paragraph from one object on this page is removed */
133 void SdPage::onParagraphRemoving( ::Outliner
* pOutliner
, Paragraph
* pPara
, SdrObject
* pObj
)
135 if( mxAnimationNode
.is() )
137 ParagraphTarget aTarget
;
138 aTarget
.Shape
= Reference
< XShape
>( pObj
->getUnoShape(), UNO_QUERY
);
139 aTarget
.Paragraph
= (sal_Int16
)pOutliner
->GetAbsPos( pPara
);
141 getMainSequence()->disposeTextRange( makeAny( aTarget
) );
145 /** callback from the sd::View when an object just left text edit mode */
146 void SdPage::onEndTextEdit( SdrObject
* pObj
)
148 if( pObj
&& mxAnimationNode
.is() )
150 Reference
< XShape
> xObj( pObj
->getUnoShape(), UNO_QUERY
);
151 getMainSequence()->onTextChanged( xObj
);
155 void SdPage::cloneAnimations( SdPage
& rTargetPage
) const
157 if( mxAnimationNode
.is() )
159 Reference
< XAnimationNode
> xClonedNode(
160 ::sd::Clone( mxAnimationNode
, this, &rTargetPage
) );
162 if( xClonedNode
.is() )
163 rTargetPage
.setAnimationNode( xClonedNode
);