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