1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_slideshow.hxx"
30 
31 // must be first
32 #include <canvas/debug.hxx>
33 #include <tools/diagnose_ex.h>
34 #include <tools/diagnose_ex.h>
35 
36 #include <comphelper/anytostring.hxx>
37 #include <cppuhelper/exc_hlp.hxx>
38 
39 #include "slideanimations.hxx"
40 #include "animationnodefactory.hxx"
41 
42 using namespace ::com::sun::star;
43 
44 namespace slideshow
45 {
46     namespace internal
47     {
48         SlideAnimations::SlideAnimations( const SlideShowContext&     rContext,
49                                           const ::basegfx::B2DVector& rSlideSize ) :
50             maContext( rContext ),
51             maSlideSize( rSlideSize ),
52             mpRootNode()
53         {
54             ENSURE_OR_THROW( maContext.mpSubsettableShapeManager,
55                               "SlideAnimations::SlideAnimations(): Invalid SlideShowContext" );
56         }
57 
58         SlideAnimations::~SlideAnimations()
59         {
60             if( mpRootNode )
61             {
62                 SHOW_NODE_TREE( mpRootNode );
63 
64                 try
65                 {
66                     mpRootNode->dispose();
67                 }
68                 catch (uno::Exception &)
69                 {
70                     OSL_ENSURE( false, rtl::OUStringToOString(
71                                     comphelper::anyToString(
72                                         cppu::getCaughtException() ),
73                                     RTL_TEXTENCODING_UTF8 ).getStr() );
74                 }
75             }
76         }
77 
78         bool SlideAnimations::importAnimations( const uno::Reference< animations::XAnimationNode >& xRootAnimationNode )
79         {
80             mpRootNode = AnimationNodeFactory::createAnimationNode(
81                 xRootAnimationNode,
82                 maSlideSize,
83                 maContext );
84 
85             SHOW_NODE_TREE( mpRootNode );
86 
87             return mpRootNode;
88         }
89 
90         bool SlideAnimations::isAnimated() const
91         {
92             if( !mpRootNode )
93                 return false; // no animations there
94 
95             // query root node about pending animations
96             return mpRootNode->hasPendingAnimation();
97         }
98 
99         bool SlideAnimations::start()
100         {
101             if( !mpRootNode )
102                 return false; // no animations there
103 
104             // init all nodes
105             if( !mpRootNode->init() )
106                 return false;
107 
108             // resolve root node
109             if( !mpRootNode->resolve() )
110                 return false;
111 
112             return true;
113         }
114 
115         void SlideAnimations::end()
116         {
117             if( !mpRootNode )
118                 return; // no animations there
119 
120             // end root node
121             mpRootNode->deactivate();
122             mpRootNode->end();
123         }
124 
125         void SlideAnimations::dispose()
126         {
127             mpRootNode.reset();
128             maContext.dispose();
129         }
130 	}
131 }
132