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