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