1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_slideshow.hxx"
26 
27 // must be first
28 #include <canvas/debug.hxx>
29 #include <tools/diagnose_ex.h>
30 #include <tools/diagnose_ex.h>
31 
32 #include <comphelper/anytostring.hxx>
33 #include <cppuhelper/exc_hlp.hxx>
34 
35 #include "slideanimations.hxx"
36 #include "animationnodefactory.hxx"
37 
38 using namespace ::com::sun::star;
39 
40 namespace slideshow
41 {
42     namespace internal
43     {
44         SlideAnimations::SlideAnimations( const SlideShowContext&     rContext,
45                                           const ::basegfx::B2DVector& rSlideSize ) :
46             maContext( rContext ),
47             maSlideSize( rSlideSize ),
48             mpRootNode()
49         {
50             ENSURE_OR_THROW( maContext.mpSubsettableShapeManager,
51                               "SlideAnimations::SlideAnimations(): Invalid SlideShowContext" );
52         }
53 
54         SlideAnimations::~SlideAnimations()
55         {
56             if( mpRootNode )
57             {
58                 SHOW_NODE_TREE( mpRootNode );
59 
60                 try
61                 {
62                     mpRootNode->dispose();
63                 }
64                 catch (uno::Exception &)
65                 {
66                     OSL_ENSURE( false, rtl::OUStringToOString(
67                                     comphelper::anyToString(
68                                         cppu::getCaughtException() ),
69                                     RTL_TEXTENCODING_UTF8 ).getStr() );
70                 }
71             }
72         }
73 
74         bool SlideAnimations::importAnimations( const uno::Reference< animations::XAnimationNode >& xRootAnimationNode )
75         {
76             mpRootNode = AnimationNodeFactory::createAnimationNode(
77                 xRootAnimationNode,
78                 maSlideSize,
79                 maContext );
80 
81             SHOW_NODE_TREE( mpRootNode );
82 
83             return mpRootNode;
84         }
85 
86         bool SlideAnimations::isAnimated() const
87         {
88             if( !mpRootNode )
89                 return false; // no animations there
90 
91             // query root node about pending animations
92             return mpRootNode->hasPendingAnimation();
93         }
94 
95         bool SlideAnimations::start()
96         {
97             if( !mpRootNode )
98                 return false; // no animations there
99 
100             // init all nodes
101             if( !mpRootNode->init() )
102                 return false;
103 
104             // resolve root node
105             if( !mpRootNode->resolve() )
106                 return false;
107 
108             return true;
109         }
110 
111         void SlideAnimations::end()
112         {
113             if( !mpRootNode )
114                 return; // no animations there
115 
116             // end root node
117             mpRootNode->deactivate();
118             mpRootNode->end();
119         }
120 
121         void SlideAnimations::dispose()
122         {
123             mpRootNode.reset();
124             maContext.dispose();
125         }
126 	}
127 }
128