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