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 #ifndef INCLUDED_SLIDESHOW_SETACTIVITY_HXX 28 #define INCLUDED_SLIDESHOW_SETACTIVITY_HXX 29 30 // must be first 31 #include <canvas/debug.hxx> 32 #include <tools/diagnose_ex.h> 33 #include <canvas/verbosetrace.hxx> 34 35 #include "animationactivity.hxx" 36 #include "animation.hxx" 37 #include "animatableshape.hxx" 38 #include "shapeattributelayer.hxx" 39 #include "activitiesfactory.hxx" 40 41 namespace slideshow { 42 namespace internal { 43 44 /** Templated setter for animation values 45 46 This template class implements the AnimationActivity 47 interface, but only the perform() and 48 setAttributeLayer() methods are functional. To be used for set animations. 49 50 @see AnimationSetNode. 51 */ 52 template <class AnimationT> 53 class SetActivity : public AnimationActivity 54 { 55 public: 56 typedef ::boost::shared_ptr< AnimationT > AnimationSharedPtrT; 57 typedef typename AnimationT::ValueType ValueT; 58 59 SetActivity( const ActivitiesFactory::CommonParameters& rParms, 60 const AnimationSharedPtrT& rAnimation, 61 const ValueT& rToValue ) 62 : mpAnimation( rAnimation ), 63 mpShape(), 64 mpAttributeLayer(), 65 mpEndEvent( rParms.mpEndEvent ), 66 mrEventQueue( rParms.mrEventQueue ), 67 maToValue( rToValue ), 68 mbIsActive(true) 69 { 70 ENSURE_OR_THROW( mpAnimation, "Invalid animation" ); 71 } 72 73 virtual void dispose() 74 { 75 mbIsActive = false; 76 mpAnimation.reset(); 77 mpShape.reset(); 78 mpAttributeLayer.reset(); 79 // discharge end event: 80 if (mpEndEvent && mpEndEvent->isCharged()) 81 mpEndEvent->dispose(); 82 mpEndEvent.reset(); 83 } 84 85 virtual double calcTimeLag() const 86 { 87 return 0.0; 88 } 89 90 virtual bool perform() 91 { 92 if (! isActive()) 93 return false; 94 // we're going inactive immediately: 95 mbIsActive = false; 96 97 if (mpAnimation && mpAttributeLayer && mpShape) { 98 mpAnimation->start( mpShape, mpAttributeLayer ); 99 (*mpAnimation)(maToValue); 100 mpAnimation->end(); 101 } 102 // fire end event, if any 103 if (mpEndEvent) 104 mrEventQueue.addEvent( mpEndEvent ); 105 106 return false; // don't reinsert 107 } 108 109 virtual bool isActive() const 110 { 111 return mbIsActive; 112 } 113 114 virtual void dequeued() 115 { 116 } 117 118 virtual void end() 119 { 120 perform(); 121 } 122 123 virtual void setTargets( const AnimatableShapeSharedPtr& rShape, 124 const ShapeAttributeLayerSharedPtr& rAttrLayer ) 125 { 126 ENSURE_OR_THROW( rShape, "Invalid shape" ); 127 ENSURE_OR_THROW( rAttrLayer, "Invalid attribute layer" ); 128 129 mpShape = rShape; 130 mpAttributeLayer = rAttrLayer; 131 } 132 133 private: 134 AnimationSharedPtrT mpAnimation; 135 AnimatableShapeSharedPtr mpShape; 136 ShapeAttributeLayerSharedPtr mpAttributeLayer; 137 EventSharedPtr mpEndEvent; 138 EventQueue& mrEventQueue; 139 ValueT maToValue; 140 bool mbIsActive; 141 }; 142 143 template <class AnimationT> AnimationActivitySharedPtr makeSetActivity( 144 const ActivitiesFactory::CommonParameters& rParms, 145 const ::boost::shared_ptr< AnimationT >& rAnimation, 146 const typename AnimationT::ValueType& rToValue ) 147 { 148 return AnimationActivitySharedPtr( 149 new SetActivity<AnimationT>(rParms,rAnimation,rToValue) ); 150 } 151 152 } // namespace internal 153 } // namespace presentation 154 155 #endif /* INCLUDED_SLIDESHOW_SETACTIVITY_HXX */ 156