1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/animations/ParallelTimeContainer.hpp>
21 #include <com/sun/star/presentation/EffectNodeType.hpp>
22 #include <com/sun/star/presentation/ParagraphTarget.hpp>
23 #include <comphelper/processfactory.hxx>
24 #include <editeng/outliner.hxx>
25 #include <CustomAnimationCloner.hxx>
26 #include <drawdoc.hxx>
28 #include <CustomAnimationPreset.hxx>
29 #include <TransitionPreset.hxx>
30 #include <undoanim.hxx>
31 #include <EffectMigration.hxx>
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::animations
;
36 using namespace ::com::sun::star::presentation
;
38 using ::com::sun::star::drawing::XShape
;
40 /** returns a helper class to manipulate effects inside the main sequence */
41 sd::MainSequencePtr
const & SdPage::getMainSequence()
43 if( nullptr == mpMainSequence
.get() )
44 mpMainSequence
.reset( new sd::MainSequence( getAnimationNode() ) );
46 return mpMainSequence
;
49 /** returns the main animation node */
50 Reference
< XAnimationNode
> const & SdPage::getAnimationNode()
52 if( !mxAnimationNode
.is() )
54 mxAnimationNode
.set( ParallelTimeContainer::create( ::comphelper::getProcessComponentContext() ), UNO_QUERY_THROW
);
55 Sequence
< css::beans::NamedValue
> aUserData
56 { { "node-type", css::uno::makeAny(css::presentation::EffectNodeType::TIMING_ROOT
) } };
57 mxAnimationNode
->setUserData( aUserData
);
60 return mxAnimationNode
;
63 void SdPage::setAnimationNode( Reference
< XAnimationNode
> const & xNode
)
65 mxAnimationNode
= xNode
;
66 if( mpMainSequence
.get() )
67 mpMainSequence
->reset( xNode
);
70 /** removes all custom animations for the given shape */
71 void SdPage::removeAnimations( const SdrObject
* pObj
)
73 if( mxAnimationNode
.is() )
77 Reference
< XShape
> xShape( const_cast<SdrObject
*>(pObj
)->getUnoShape(), UNO_QUERY
);
79 if( mpMainSequence
->hasEffect( xShape
) )
80 mpMainSequence
->disposeShape( xShape
);
84 bool SdPage::hasAnimationNode() const
86 return mxAnimationNode
.is();
89 void SdPage::SetFadeEffect(css::presentation::FadeEffect eNewEffect
)
91 EffectMigration::SetFadeEffect( this, eNewEffect
);
94 FadeEffect
SdPage::GetFadeEffect() const
96 return EffectMigration::GetFadeEffect( this );
99 /** callback from the sd::View when a new paragraph for one object on this page is created */
100 void SdPage::onParagraphInserted( ::Outliner
* pOutliner
, Paragraph
const * pPara
, SdrObject
* pObj
)
102 if( mxAnimationNode
.is() )
104 ParagraphTarget aTarget
;
105 aTarget
.Shape
.set( pObj
->getUnoShape(), UNO_QUERY
);
106 /* FIXME: Paragraph should be sal_Int32, though more than 64k
107 * paragrapsh at a shape are unlikely.. */
108 aTarget
.Paragraph
= static_cast<sal_Int16
>(pOutliner
->GetAbsPos( pPara
));
110 getMainSequence()->insertTextRange( makeAny( aTarget
) );
114 /** callback from the sd::View when a paragraph from one object on this page is removed */
115 void SdPage::onParagraphRemoving( ::Outliner
* pOutliner
, Paragraph
const * pPara
, SdrObject
* pObj
)
117 if( mxAnimationNode
.is() )
119 ParagraphTarget aTarget
;
120 aTarget
.Shape
.set( pObj
->getUnoShape(), UNO_QUERY
);
121 /* FIXME: Paragraph should be sal_Int32, though more than 64k
122 * paragrapsh at a shape are unlikely.. */
123 aTarget
.Paragraph
= static_cast<sal_Int16
>(pOutliner
->GetAbsPos( pPara
));
125 getMainSequence()->disposeTextRange( makeAny( aTarget
) );
129 /** callback from the sd::View when an object just left text edit mode */
130 void SdPage::onEndTextEdit( SdrObject
* pObj
)
132 if( pObj
&& mxAnimationNode
.is() )
134 Reference
< XShape
> xObj( pObj
->getUnoShape(), UNO_QUERY
);
135 getMainSequence()->onTextChanged( xObj
);
139 void SdPage::cloneAnimations( SdPage
& rTargetPage
) const
141 if( mxAnimationNode
.is() )
143 Reference
< XAnimationNode
> xClonedNode(
144 ::sd::Clone( mxAnimationNode
, this, &rTargetPage
) );
146 if( xClonedNode
.is() )
147 rTargetPage
.setAnimationNode( xClonedNode
);
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */