Update ooo320-m1
[ooovba.git] / slideshow / source / engine / animationnodes / setactivity.hxx
blob813ed79f5f1b142115e17101ab8fadd2b2d159ad
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: setactivity.hxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef INCLUDED_SLIDESHOW_SETACTIVITY_HXX
31 #define INCLUDED_SLIDESHOW_SETACTIVITY_HXX
33 // must be first
34 #include <canvas/debug.hxx>
35 #include <tools/diagnose_ex.h>
36 #include <canvas/verbosetrace.hxx>
38 #include "animationactivity.hxx"
39 #include "animation.hxx"
40 #include "animatableshape.hxx"
41 #include "shapeattributelayer.hxx"
42 #include "activitiesfactory.hxx"
44 namespace slideshow {
45 namespace internal {
47 /** Templated setter for animation values
49 This template class implements the AnimationActivity
50 interface, but only the perform() and
51 setAttributeLayer() methods are functional. To be used for set animations.
53 @see AnimationSetNode.
55 template <class AnimationT>
56 class SetActivity : public AnimationActivity
58 public:
59 typedef ::boost::shared_ptr< AnimationT > AnimationSharedPtrT;
60 typedef typename AnimationT::ValueType ValueT;
62 SetActivity( const ActivitiesFactory::CommonParameters& rParms,
63 const AnimationSharedPtrT& rAnimation,
64 const ValueT& rToValue )
65 : mpAnimation( rAnimation ),
66 mpShape(),
67 mpAttributeLayer(),
68 mpEndEvent( rParms.mpEndEvent ),
69 mrEventQueue( rParms.mrEventQueue ),
70 maToValue( rToValue ),
71 mbIsActive(true)
73 ENSURE_OR_THROW( mpAnimation, "Invalid animation" );
76 virtual void dispose()
78 mbIsActive = false;
79 mpAnimation.reset();
80 mpShape.reset();
81 mpAttributeLayer.reset();
82 // discharge end event:
83 if (mpEndEvent && mpEndEvent->isCharged())
84 mpEndEvent->dispose();
85 mpEndEvent.reset();
88 virtual double calcTimeLag() const
90 return 0.0;
93 virtual bool perform()
95 if (! isActive())
96 return false;
97 // we're going inactive immediately:
98 mbIsActive = false;
100 if (mpAnimation && mpAttributeLayer && mpShape) {
101 mpAnimation->start( mpShape, mpAttributeLayer );
102 (*mpAnimation)(maToValue);
103 mpAnimation->end();
105 // fire end event, if any
106 if (mpEndEvent)
107 mrEventQueue.addEvent( mpEndEvent );
109 return false; // don't reinsert
112 virtual bool isActive() const
114 return mbIsActive;
117 virtual void dequeued()
121 virtual void end()
123 perform();
126 virtual void setTargets( const AnimatableShapeSharedPtr& rShape,
127 const ShapeAttributeLayerSharedPtr& rAttrLayer )
129 ENSURE_OR_THROW( rShape, "Invalid shape" );
130 ENSURE_OR_THROW( rAttrLayer, "Invalid attribute layer" );
132 mpShape = rShape;
133 mpAttributeLayer = rAttrLayer;
136 private:
137 AnimationSharedPtrT mpAnimation;
138 AnimatableShapeSharedPtr mpShape;
139 ShapeAttributeLayerSharedPtr mpAttributeLayer;
140 EventSharedPtr mpEndEvent;
141 EventQueue& mrEventQueue;
142 ValueT maToValue;
143 bool mbIsActive;
146 template <class AnimationT> AnimationActivitySharedPtr makeSetActivity(
147 const ActivitiesFactory::CommonParameters& rParms,
148 const ::boost::shared_ptr< AnimationT >& rAnimation,
149 const typename AnimationT::ValueType& rToValue )
151 return AnimationActivitySharedPtr(
152 new SetActivity<AnimationT>(rParms,rAnimation,rToValue) );
155 } // namespace internal
156 } // namespace presentation
158 #endif /* INCLUDED_SLIDESHOW_SETACTIVITY_HXX */