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