Line data Source code
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/lang/XMultiServiceFactory.hpp>
22 : #include <com/sun/star/presentation/EffectNodeType.hpp>
23 : #include <com/sun/star/presentation/ParagraphTarget.hpp>
24 : #include <comphelper/processfactory.hxx>
25 : #include <osl/mutex.hxx>
26 : #include <editeng/outliner.hxx>
27 : #include "CustomAnimationCloner.hxx"
28 : #include "drawdoc.hxx"
29 : #include "sdpage.hxx"
30 : #include <CustomAnimationPreset.hxx>
31 : #include <TransitionPreset.hxx>
32 : #include "undoanim.hxx"
33 : #include "EffectMigration.hxx"
34 :
35 : using namespace ::sd;
36 : using namespace ::com::sun::star::uno;
37 : using namespace ::com::sun::star::animations;
38 : using namespace ::com::sun::star::presentation;
39 :
40 : using ::com::sun::star::drawing::XShape;
41 :
42 : /** returns a helper class to manipulate effects inside the main sequence */
43 392 : sd::MainSequencePtr SdPage::getMainSequence()
44 : {
45 392 : if( 0 == mpMainSequence.get() )
46 93 : mpMainSequence.reset( new sd::MainSequence( getAnimationNode() ) );
47 :
48 392 : return mpMainSequence;
49 : }
50 :
51 : /** returns the main animation node */
52 372 : Reference< XAnimationNode > SdPage::getAnimationNode() throw (RuntimeException)
53 : {
54 372 : if( !mxAnimationNode.is() )
55 : {
56 262 : mxAnimationNode.set( ParallelTimeContainer::create( ::comphelper::getProcessComponentContext() ), UNO_QUERY_THROW );
57 262 : Sequence< ::com::sun::star::beans::NamedValue > aUserData( 1 );
58 262 : aUserData[0].Name = "node-type";
59 262 : aUserData[0].Value <<= ::com::sun::star::presentation::EffectNodeType::TIMING_ROOT;
60 262 : mxAnimationNode->setUserData( aUserData );
61 : }
62 :
63 372 : return mxAnimationNode;
64 : }
65 :
66 0 : void SdPage::setAnimationNode( Reference< XAnimationNode >& xNode ) throw (RuntimeException)
67 : {
68 0 : mxAnimationNode = xNode;
69 0 : if( mpMainSequence.get() )
70 0 : mpMainSequence->reset( xNode );
71 0 : }
72 :
73 : /** removes all custom animations for the given shape */
74 2431 : void SdPage::removeAnimations( const SdrObject* pObj )
75 : {
76 2431 : if( mxAnimationNode.is() )
77 : {
78 85 : getMainSequence();
79 :
80 85 : Reference< XShape > xShape( const_cast<SdrObject*>(pObj)->getUnoShape(), UNO_QUERY );
81 :
82 85 : if( mpMainSequence->hasEffect( xShape ) )
83 0 : mpMainSequence->disposeShape( xShape );
84 : }
85 2431 : }
86 :
87 1239 : bool SdPage::hasAnimationNode() const
88 : {
89 1239 : return mxAnimationNode.is();
90 : }
91 :
92 0 : void SdPage::SetFadeEffect(::com::sun::star::presentation::FadeEffect eNewEffect)
93 : {
94 0 : EffectMigration::SetFadeEffect( this, eNewEffect );
95 0 : }
96 :
97 42 : FadeEffect SdPage::GetFadeEffect() const
98 : {
99 42 : return EffectMigration::GetFadeEffect( this );
100 : }
101 :
102 : /** callback from the sd::View when a new paragraph for one object on this page is created */
103 0 : void SdPage::onParagraphInserted( ::Outliner* pOutliner, Paragraph* pPara, SdrObject* pObj )
104 : {
105 0 : if( mxAnimationNode.is() )
106 : {
107 0 : ParagraphTarget aTarget;
108 0 : aTarget.Shape = Reference< XShape >( pObj->getUnoShape(), UNO_QUERY );
109 : /* FIXME: Paragraph should be sal_Int32, though more than 64k
110 : * paragrapsh at a shape are unlikely.. */
111 0 : aTarget.Paragraph = (sal_Int16)pOutliner->GetAbsPos( pPara );
112 :
113 0 : getMainSequence()->insertTextRange( makeAny( aTarget ) );
114 : }
115 0 : }
116 :
117 : /** callback from the sd::View when a paragraph from one object on this page is removed */
118 0 : void SdPage::onParagraphRemoving( ::Outliner* pOutliner, Paragraph* pPara, SdrObject* pObj )
119 : {
120 0 : if( mxAnimationNode.is() )
121 : {
122 0 : ParagraphTarget aTarget;
123 0 : aTarget.Shape = Reference< XShape >( pObj->getUnoShape(), UNO_QUERY );
124 : /* FIXME: Paragraph should be sal_Int32, though more than 64k
125 : * paragrapsh at a shape are unlikely.. */
126 0 : aTarget.Paragraph = (sal_Int16)pOutliner->GetAbsPos( pPara );
127 :
128 0 : getMainSequence()->disposeTextRange( makeAny( aTarget ) );
129 : }
130 0 : }
131 :
132 : /** callback from the sd::View when an object just left text edit mode */
133 7 : void SdPage::onEndTextEdit( SdrObject* pObj )
134 : {
135 7 : if( pObj && mxAnimationNode.is() )
136 : {
137 0 : Reference< XShape > xObj( pObj->getUnoShape(), UNO_QUERY );
138 0 : getMainSequence()->onTextChanged( xObj );
139 : }
140 7 : }
141 :
142 1 : void SdPage::cloneAnimations( SdPage& rTargetPage ) const
143 : {
144 1 : if( mxAnimationNode.is() )
145 : {
146 : Reference< XAnimationNode > xClonedNode(
147 0 : ::sd::Clone( mxAnimationNode, this, &rTargetPage ) );
148 :
149 0 : if( xClonedNode.is() )
150 0 : rTargetPage.setAnimationNode( xClonedNode );
151 : }
152 67 : }
153 :
154 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|