1*aaef562fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*aaef562fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*aaef562fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*aaef562fSAndrew Rist * distributed with this work for additional information 6*aaef562fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*aaef562fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*aaef562fSAndrew Rist * "License"); you may not use this file except in compliance 9*aaef562fSAndrew Rist * with the License. You may obtain a copy of the License at 10*aaef562fSAndrew Rist * 11*aaef562fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*aaef562fSAndrew Rist * 13*aaef562fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*aaef562fSAndrew Rist * software distributed under the License is distributed on an 15*aaef562fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*aaef562fSAndrew Rist * KIND, either express or implied. See the License for the 17*aaef562fSAndrew Rist * specific language governing permissions and limitations 18*aaef562fSAndrew Rist * under the License. 19*aaef562fSAndrew Rist * 20*aaef562fSAndrew Rist *************************************************************/ 21*aaef562fSAndrew Rist 22*aaef562fSAndrew Rist 23cdf0e10cSrcweir #ifndef INCLUDED_SLIDESHOW_BASENODE_HXX 24cdf0e10cSrcweir #define INCLUDED_SLIDESHOW_BASENODE_HXX 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <canvas/debug.hxx> 27cdf0e10cSrcweir #include <tools/diagnose_ex.h> 28cdf0e10cSrcweir #include <osl/diagnose.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include "event.hxx" 31cdf0e10cSrcweir #include "animationnode.hxx" 32cdf0e10cSrcweir #include "slideshowcontext.hxx" 33cdf0e10cSrcweir #include "shapesubset.hxx" 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include <boost/noncopyable.hpp> 36cdf0e10cSrcweir #include <vector> 37cdf0e10cSrcweir 38cdf0e10cSrcweir namespace slideshow { 39cdf0e10cSrcweir namespace internal { 40cdf0e10cSrcweir 41cdf0e10cSrcweir /** Context for every node. 42cdf0e10cSrcweir 43cdf0e10cSrcweir Besides the global AnimationNodeFactory::Context data, 44cdf0e10cSrcweir this struct also contains the current DocTree subset 45cdf0e10cSrcweir for this node. If start and end index of the 46cdf0e10cSrcweir DocTreeNode are equal, the node should use the 47cdf0e10cSrcweir complete shape. 48cdf0e10cSrcweir */ 49cdf0e10cSrcweir struct NodeContext 50cdf0e10cSrcweir { 51cdf0e10cSrcweir NodeContext( const SlideShowContext& rContext, 52cdf0e10cSrcweir const ::basegfx::B2DVector& rSlideSize ) 53cdf0e10cSrcweir : maContext( rContext ), 54cdf0e10cSrcweir maSlideSize( rSlideSize ), 55cdf0e10cSrcweir mpMasterShapeSubset(), 56cdf0e10cSrcweir mnStartDelay(0.0), 57cdf0e10cSrcweir mbIsIndependentSubset( true ) 58cdf0e10cSrcweir {} 59cdf0e10cSrcweir 60cdf0e10cSrcweir void dispose() 61cdf0e10cSrcweir { 62cdf0e10cSrcweir maContext.dispose(); 63cdf0e10cSrcweir mpMasterShapeSubset.reset(); 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir /// Context as passed to createAnimationNode() 67cdf0e10cSrcweir SlideShowContext maContext; 68cdf0e10cSrcweir 69cdf0e10cSrcweir /// Size in user coordinate space of the corresponding slide 70cdf0e10cSrcweir ::basegfx::B2DVector maSlideSize; 71cdf0e10cSrcweir 72cdf0e10cSrcweir /// Shape to be used (provided by parent, e.g. for iterations) 73cdf0e10cSrcweir ShapeSubsetSharedPtr mpMasterShapeSubset; 74cdf0e10cSrcweir 75cdf0e10cSrcweir /// Additional delay to node begin (to offset iterate effects) 76cdf0e10cSrcweir double mnStartDelay; 77cdf0e10cSrcweir 78cdf0e10cSrcweir /// When true, subset must be created during slide initialization 79cdf0e10cSrcweir bool mbIsIndependentSubset; 80cdf0e10cSrcweir }; 81cdf0e10cSrcweir 82cdf0e10cSrcweir class BaseContainerNode; 83cdf0e10cSrcweir 84cdf0e10cSrcweir /** This interface extends AnimationNode with some 85cdf0e10cSrcweir file-private accessor methods. 86cdf0e10cSrcweir */ 87cdf0e10cSrcweir class BaseNode : public AnimationNode, 88cdf0e10cSrcweir public ::osl::DebugBase<BaseNode>, 89cdf0e10cSrcweir private ::boost::noncopyable 90cdf0e10cSrcweir { 91cdf0e10cSrcweir public: 92cdf0e10cSrcweir BaseNode( ::com::sun::star::uno::Reference< 93cdf0e10cSrcweir ::com::sun::star::animations::XAnimationNode> const& xNode, 94cdf0e10cSrcweir ::boost::shared_ptr<BaseContainerNode> const& pParent, 95cdf0e10cSrcweir NodeContext const& rContext ); 96cdf0e10cSrcweir 97cdf0e10cSrcweir /** Provide the node with a shared_ptr to itself. 98cdf0e10cSrcweir 99cdf0e10cSrcweir Since implementation has to create objects which need 100cdf0e10cSrcweir a shared_ptr to this node, and a pointee cannot 101cdf0e10cSrcweir retrieve a shared_ptr to itself internally, have to 102cdf0e10cSrcweir set that from the outside. 103cdf0e10cSrcweir */ 104cdf0e10cSrcweir void setSelf( const ::boost::shared_ptr< BaseNode >& rSelf ); 105cdf0e10cSrcweir 106cdf0e10cSrcweir 107cdf0e10cSrcweir #if defined(VERBOSE) && defined(DBG_UTIL) 108cdf0e10cSrcweir virtual void showState() const; 109cdf0e10cSrcweir virtual const char* getDescription() const; 110cdf0e10cSrcweir void showTreeFromWithin() const; 111cdf0e10cSrcweir #endif 112cdf0e10cSrcweir 113cdf0e10cSrcweir const ::boost::shared_ptr< BaseContainerNode >& getParentNode() const 114cdf0e10cSrcweir { return mpParent; } 115cdf0e10cSrcweir 116cdf0e10cSrcweir // Disposable: 117cdf0e10cSrcweir virtual void dispose(); 118cdf0e10cSrcweir 119cdf0e10cSrcweir // AnimationNode: 120cdf0e10cSrcweir virtual bool init(); 121cdf0e10cSrcweir virtual bool resolve(); 122cdf0e10cSrcweir virtual bool activate(); 123cdf0e10cSrcweir virtual void deactivate(); 124cdf0e10cSrcweir virtual void end(); 125cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< 126cdf0e10cSrcweir ::com::sun::star::animations::XAnimationNode> getXAnimationNode() const; 127cdf0e10cSrcweir virtual NodeState getState() const; 128cdf0e10cSrcweir virtual bool registerDeactivatingListener( 129cdf0e10cSrcweir const AnimationNodeSharedPtr& rNotifee ); 130cdf0e10cSrcweir // nop: 131cdf0e10cSrcweir virtual void notifyDeactivating( const AnimationNodeSharedPtr& rNotifier ); 132cdf0e10cSrcweir 133cdf0e10cSrcweir bool isMainSequenceRootNode() const { return mbIsMainSequenceRootNode; } 134cdf0e10cSrcweir 135cdf0e10cSrcweir protected: 136cdf0e10cSrcweir void scheduleDeactivationEvent( EventSharedPtr const& pEvent = 137cdf0e10cSrcweir EventSharedPtr() ); 138cdf0e10cSrcweir 139cdf0e10cSrcweir SlideShowContext const& getContext() const { return maContext; } 140cdf0e10cSrcweir ::boost::shared_ptr<BaseNode> const& getSelf() const { return mpSelf; } 141cdf0e10cSrcweir 142cdf0e10cSrcweir bool checkValidNode() const { 143cdf0e10cSrcweir ENSURE_OR_THROW( mpSelf, "no self ptr set!" ); 144cdf0e10cSrcweir bool const bRet = (meCurrState != INVALID); 145cdf0e10cSrcweir OSL_ENSURE( bRet, "### INVALID node!" ); 146cdf0e10cSrcweir return bRet; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir private: 150cdf0e10cSrcweir // all state affecting methods have "_st" counterparts being called at 151cdf0e10cSrcweir // derived classes when in state transistion: no-ops here at BaseNode... 152cdf0e10cSrcweir virtual bool init_st(); 153cdf0e10cSrcweir virtual bool resolve_st(); 154cdf0e10cSrcweir virtual void activate_st(); 155cdf0e10cSrcweir virtual void deactivate_st( NodeState eDestState ); 156cdf0e10cSrcweir 157cdf0e10cSrcweir private: 158cdf0e10cSrcweir /// notifies 159cdf0e10cSrcweir /// - all registered deactivation listeners 160cdf0e10cSrcweir /// - single animation end (every node) 161cdf0e10cSrcweir /// - slide animations (if main sequence root node) 162cdf0e10cSrcweir void notifyEndListeners() const; 163cdf0e10cSrcweir 164cdf0e10cSrcweir /// Get the node's restart mode 165cdf0e10cSrcweir sal_Int16 getRestartMode(); 166cdf0e10cSrcweir 167cdf0e10cSrcweir /** Get the default restart mode 168cdf0e10cSrcweir 169cdf0e10cSrcweir If this node's default mode is 170cdf0e10cSrcweir AnimationRestart::DEFAULT, this method recursively 171cdf0e10cSrcweir calls the parent node. 172cdf0e10cSrcweir */ 173cdf0e10cSrcweir sal_Int16 getRestartDefaultMode() const; 174cdf0e10cSrcweir 175cdf0e10cSrcweir /// Get the node's fill mode 176cdf0e10cSrcweir sal_Int16 getFillMode(); 177cdf0e10cSrcweir 178cdf0e10cSrcweir /** Get the default fill mode. 179cdf0e10cSrcweir 180cdf0e10cSrcweir If this node's default mode is AnimationFill::DEFAULT, 181cdf0e10cSrcweir this method recursively calls the parent node. 182cdf0e10cSrcweir */ 183cdf0e10cSrcweir sal_Int16 getFillDefaultMode() const; 184cdf0e10cSrcweir 185cdf0e10cSrcweir bool isTransition( NodeState eFromState, NodeState eToState, 186cdf0e10cSrcweir bool debugAssert = true ) const { 187cdf0e10cSrcweir (void) debugAssert; // avoid warning 188cdf0e10cSrcweir bool const bRet =((mpStateTransitionTable[eFromState] & eToState) != 0); 189cdf0e10cSrcweir OSL_ENSURE( !debugAssert || bRet, "### state unreachable!" ); 190cdf0e10cSrcweir return bRet; 191cdf0e10cSrcweir } 192cdf0e10cSrcweir 193cdf0e10cSrcweir bool inStateOrTransition( int mask ) const { 194cdf0e10cSrcweir return ((meCurrState & mask) != 0 || 195cdf0e10cSrcweir (meCurrentStateTransition & mask) != 0); 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir class StateTransition; 199cdf0e10cSrcweir friend class StateTransition; 200cdf0e10cSrcweir 201cdf0e10cSrcweir private: 202cdf0e10cSrcweir SlideShowContext maContext; 203cdf0e10cSrcweir 204cdf0e10cSrcweir typedef ::std::vector< AnimationNodeSharedPtr > ListenerVector; 205cdf0e10cSrcweir 206cdf0e10cSrcweir ListenerVector maDeactivatingListeners; 207cdf0e10cSrcweir ::com::sun::star::uno::Reference< 208cdf0e10cSrcweir ::com::sun::star::animations::XAnimationNode > mxAnimationNode; 209cdf0e10cSrcweir ::boost::shared_ptr< BaseContainerNode > mpParent; 210cdf0e10cSrcweir ::boost::shared_ptr< BaseNode > mpSelf; 211cdf0e10cSrcweir const int* mpStateTransitionTable; 212cdf0e10cSrcweir const double mnStartDelay; 213cdf0e10cSrcweir NodeState meCurrState; 214cdf0e10cSrcweir int meCurrentStateTransition; 215cdf0e10cSrcweir EventSharedPtr mpCurrentEvent; 216cdf0e10cSrcweir const bool mbIsMainSequenceRootNode; 217cdf0e10cSrcweir }; 218cdf0e10cSrcweir 219cdf0e10cSrcweir typedef ::boost::shared_ptr< BaseNode > BaseNodeSharedPtr; 220cdf0e10cSrcweir 221cdf0e10cSrcweir } // namespace internal 222cdf0e10cSrcweir } // namespace slideshow 223cdf0e10cSrcweir 224cdf0e10cSrcweir #endif /* INCLUDED_SLIDESHOW_BASENODE_HXX */ 225cdf0e10cSrcweir 226