1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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 <CustomAnimationEffect.hxx>
27 #include <sdpage.hxx>
28 #include <EffectMigration.hxx>
29
30 using namespace ::sd;
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::animations;
33 using namespace ::com::sun::star::presentation;
34
35 using ::com::sun::star::drawing::XShape;
36
37 /** returns a helper class to manipulate effects inside the main sequence */
getMainSequence()38 std::shared_ptr< sd::MainSequence > const & SdPage::getMainSequence()
39 {
40 if (nullptr == mpMainSequence)
41 mpMainSequence = std::make_shared<sd::MainSequence>( getAnimationNode() );
42
43 return mpMainSequence;
44 }
45
46 /** returns the main animation node */
getAnimationNode()47 Reference< XAnimationNode > const & SdPage::getAnimationNode()
48 {
49 if( !mxAnimationNode.is() )
50 {
51 mxAnimationNode.set( ParallelTimeContainer::create( ::comphelper::getProcessComponentContext() ), UNO_QUERY_THROW );
52 Sequence< css::beans::NamedValue > aUserData
53 { { "node-type", css::uno::makeAny(css::presentation::EffectNodeType::TIMING_ROOT) } };
54 mxAnimationNode->setUserData( aUserData );
55 }
56
57 return mxAnimationNode;
58 }
59
setAnimationNode(Reference<XAnimationNode> const & xNode)60 void SdPage::setAnimationNode( Reference< XAnimationNode > const & xNode )
61 {
62 mxAnimationNode = xNode;
63 if( mpMainSequence )
64 mpMainSequence->reset( xNode );
65 }
66
67 /** removes all custom animations for the given shape */
removeAnimations(const SdrObject * pObj)68 void SdPage::removeAnimations( const SdrObject* pObj )
69 {
70 if( mxAnimationNode.is() )
71 {
72 getMainSequence();
73
74 Reference< XShape > xShape( const_cast<SdrObject*>(pObj)->getUnoShape(), UNO_QUERY );
75
76 if( mpMainSequence->hasEffect( xShape ) )
77 mpMainSequence->disposeShape( xShape );
78 }
79 }
80
81 /** Notify that the object has been renamed and the animation effect has to update. */
notifyObjectRenamed(const SdrObject * pObj)82 void SdPage::notifyObjectRenamed(const SdrObject* pObj)
83 {
84 if (pObj && hasAnimationNode())
85 {
86 Reference<XShape> xShape(const_cast<SdrObject*>(pObj)->getUnoShape(), UNO_QUERY);
87
88 if (xShape.is() && getMainSequence()->hasEffect(xShape))
89 getMainSequence()->notify_change();
90 }
91 }
92
hasAnimationNode() const93 bool SdPage::hasAnimationNode() const
94 {
95 return mxAnimationNode.is();
96 }
97
SetFadeEffect(css::presentation::FadeEffect eNewEffect)98 void SdPage::SetFadeEffect(css::presentation::FadeEffect eNewEffect)
99 {
100 EffectMigration::SetFadeEffect( this, eNewEffect );
101 }
102
GetFadeEffect() const103 FadeEffect SdPage::GetFadeEffect() const
104 {
105 return EffectMigration::GetFadeEffect( this );
106 }
107
108 /** callback from the sd::View when a new paragraph for one object on this page is created */
onParagraphInserted(::Outliner * pOutliner,Paragraph const * pPara,SdrObject * pObj)109 void SdPage::onParagraphInserted( ::Outliner* pOutliner, Paragraph const * pPara, SdrObject* pObj )
110 {
111 if( mxAnimationNode.is() )
112 {
113 ParagraphTarget aTarget;
114 aTarget.Shape.set( pObj->getUnoShape(), UNO_QUERY );
115 /* FIXME: Paragraph should be sal_Int32, though more than 64k
116 * paragraphs at a shape are unlikely... */
117 aTarget.Paragraph = static_cast<sal_Int16>(pOutliner->GetAbsPos( pPara ));
118
119 getMainSequence()->insertTextRange( makeAny( aTarget ) );
120 }
121 }
122
123 /** callback from the sd::View when a paragraph from one object on this page is removed */
onParagraphRemoving(::Outliner * pOutliner,Paragraph const * pPara,SdrObject * pObj)124 void SdPage::onParagraphRemoving( ::Outliner* pOutliner, Paragraph const * pPara, SdrObject* pObj )
125 {
126 if( mxAnimationNode.is() )
127 {
128 ParagraphTarget aTarget;
129 aTarget.Shape.set( pObj->getUnoShape(), UNO_QUERY );
130 /* FIXME: Paragraph should be sal_Int32, though more than 64k
131 * paragraphs at a shape are unlikely... */
132 aTarget.Paragraph = static_cast<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 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
161