1*70f497fbSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*70f497fbSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*70f497fbSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*70f497fbSAndrew Rist  * distributed with this work for additional information
6*70f497fbSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*70f497fbSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*70f497fbSAndrew Rist  * "License"); you may not use this file except in compliance
9*70f497fbSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*70f497fbSAndrew Rist  *
11*70f497fbSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*70f497fbSAndrew Rist  *
13*70f497fbSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*70f497fbSAndrew Rist  * software distributed under the License is distributed on an
15*70f497fbSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*70f497fbSAndrew Rist  * KIND, either express or implied.  See the License for the
17*70f497fbSAndrew Rist  * specific language governing permissions and limitations
18*70f497fbSAndrew Rist  * under the License.
19*70f497fbSAndrew Rist  *
20*70f497fbSAndrew Rist  *************************************************************/
21*70f497fbSAndrew Rist 
22*70f497fbSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_slideshow.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <canvas/debug.hxx>
28cdf0e10cSrcweir #include <canvas/verbosetrace.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include "delayevent.hxx"
31cdf0e10cSrcweir #include "eventqueue.hxx"
32cdf0e10cSrcweir #include "usereventqueue.hxx"
33cdf0e10cSrcweir #include "sequentialtimecontainer.hxx"
34cdf0e10cSrcweir #include "tools.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <boost/bind.hpp>
37cdf0e10cSrcweir #include <algorithm>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace slideshow {
40cdf0e10cSrcweir namespace internal {
41cdf0e10cSrcweir 
activate_st()42cdf0e10cSrcweir void SequentialTimeContainer::activate_st()
43cdf0e10cSrcweir {
44cdf0e10cSrcweir     // resolve first possible child, ignore
45cdf0e10cSrcweir     for ( ; mnFinishedChildren < maChildren.size(); ++mnFinishedChildren ) {
46cdf0e10cSrcweir         if (resolveChild( maChildren[mnFinishedChildren] ))
47cdf0e10cSrcweir             break;
48cdf0e10cSrcweir         else {
49cdf0e10cSrcweir             // node still UNRESOLVED, no need to deactivate or end...
50cdf0e10cSrcweir             OSL_ENSURE( false, "### resolving child failed!" );
51cdf0e10cSrcweir         }
52cdf0e10cSrcweir     }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir     if (isDurationIndefinite() &&
55cdf0e10cSrcweir         (maChildren.empty() || mnFinishedChildren >= maChildren.size()))
56cdf0e10cSrcweir     {
57cdf0e10cSrcweir         // deactivate ASAP:
58cdf0e10cSrcweir         scheduleDeactivationEvent(
59cdf0e10cSrcweir             makeEvent(
60cdf0e10cSrcweir                  boost::bind< void >( boost::mem_fn( &AnimationNode::deactivate ), getSelf() ),
61cdf0e10cSrcweir                  "SequentialTimeContainer::deactivate") );
62cdf0e10cSrcweir     }
63cdf0e10cSrcweir     else // use default
64cdf0e10cSrcweir         scheduleDeactivationEvent();
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
dispose()67cdf0e10cSrcweir void SequentialTimeContainer::dispose()
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     BaseContainerNode::dispose();
70cdf0e10cSrcweir     if (mpCurrentSkipEvent) {
71cdf0e10cSrcweir         mpCurrentSkipEvent->dispose();
72cdf0e10cSrcweir         mpCurrentSkipEvent.reset();
73cdf0e10cSrcweir     }
74cdf0e10cSrcweir     if (mpCurrentRewindEvent) {
75cdf0e10cSrcweir         mpCurrentRewindEvent->dispose();
76cdf0e10cSrcweir         mpCurrentRewindEvent.reset();
77cdf0e10cSrcweir     }
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
skipEffect(AnimationNodeSharedPtr const & pChildNode)80cdf0e10cSrcweir void SequentialTimeContainer::skipEffect(
81cdf0e10cSrcweir     AnimationNodeSharedPtr const& pChildNode )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir     if (isChildNode(pChildNode)) {
84cdf0e10cSrcweir         // empty all events ignoring timings => until next effect
85cdf0e10cSrcweir         getContext().mrEventQueue.forceEmpty();
86cdf0e10cSrcweir         getContext().mrEventQueue.addEvent(
87cdf0e10cSrcweir             makeEvent(
88cdf0e10cSrcweir                 boost::bind<void>( boost::mem_fn( &AnimationNode::deactivate ), pChildNode ),
89cdf0e10cSrcweir                 "SequentialTimeContainer::deactivate, skipEffect with delay") );
90cdf0e10cSrcweir     }
91cdf0e10cSrcweir     else
92cdf0e10cSrcweir         OSL_ENSURE( false, "unknown notifier!" );
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
rewindEffect(AnimationNodeSharedPtr const &)95cdf0e10cSrcweir void SequentialTimeContainer::rewindEffect(
96cdf0e10cSrcweir     AnimationNodeSharedPtr const& /*pChildNode*/ )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir     // xxx todo: ...
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
resolveChild(AnimationNodeSharedPtr const & pChildNode)101cdf0e10cSrcweir bool SequentialTimeContainer::resolveChild(
102cdf0e10cSrcweir     AnimationNodeSharedPtr const& pChildNode )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     bool const bResolved = pChildNode->resolve();
105cdf0e10cSrcweir     if (bResolved && isMainSequenceRootNode()) {
106cdf0e10cSrcweir         // discharge events:
107cdf0e10cSrcweir         if (mpCurrentSkipEvent)
108cdf0e10cSrcweir             mpCurrentSkipEvent->dispose();
109cdf0e10cSrcweir         if (mpCurrentRewindEvent)
110cdf0e10cSrcweir             mpCurrentRewindEvent->dispose();
111cdf0e10cSrcweir 
112cdf0e10cSrcweir         // event that will deactivate the resolved/running child:
113cdf0e10cSrcweir         mpCurrentSkipEvent = makeEvent(
114cdf0e10cSrcweir             boost::bind( &SequentialTimeContainer::skipEffect,
115cdf0e10cSrcweir                          boost::dynamic_pointer_cast<SequentialTimeContainer>( getSelf() ),
116cdf0e10cSrcweir                          pChildNode ),
117cdf0e10cSrcweir             "SequentialTimeContainer::skipEffect, resolveChild");
118cdf0e10cSrcweir         // event that will reresolve the resolved/activated child:
119cdf0e10cSrcweir         mpCurrentRewindEvent = makeEvent(
120cdf0e10cSrcweir             boost::bind( &SequentialTimeContainer::rewindEffect,
121cdf0e10cSrcweir                          boost::dynamic_pointer_cast<SequentialTimeContainer>( getSelf() ),
122cdf0e10cSrcweir                          pChildNode ),
123cdf0e10cSrcweir             "SequentialTimeContainer::rewindEffect, resolveChild");
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         // deactivate child node when skip event occurs:
126cdf0e10cSrcweir         getContext().mrUserEventQueue.registerSkipEffectEvent(
127cdf0e10cSrcweir             mpCurrentSkipEvent,
128cdf0e10cSrcweir             mnFinishedChildren+1<maChildren.size());
129cdf0e10cSrcweir         // rewind to previous child:
130cdf0e10cSrcweir         getContext().mrUserEventQueue.registerRewindEffectEvent(
131cdf0e10cSrcweir             mpCurrentRewindEvent );
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir     return bResolved;
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
notifyDeactivating(AnimationNodeSharedPtr const & rNotifier)136cdf0e10cSrcweir void SequentialTimeContainer::notifyDeactivating(
137cdf0e10cSrcweir     AnimationNodeSharedPtr const& rNotifier )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir     if (notifyDeactivatedChild( rNotifier ))
140cdf0e10cSrcweir         return;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     OSL_ASSERT( mnFinishedChildren < maChildren.size() );
143cdf0e10cSrcweir     AnimationNodeSharedPtr const& pNextChild = maChildren[mnFinishedChildren];
144cdf0e10cSrcweir     OSL_ASSERT( pNextChild->getState() == UNRESOLVED );
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     if (! resolveChild( pNextChild )) {
147cdf0e10cSrcweir         // could not resolve child - since we risk to
148cdf0e10cSrcweir         // stall the chain of events here, play it safe
149cdf0e10cSrcweir         // and deactivate this node (only if we have
150cdf0e10cSrcweir         // indefinite duration - otherwise, we'll get a
151cdf0e10cSrcweir         // deactivation event, anyways).
152cdf0e10cSrcweir         deactivate();
153cdf0e10cSrcweir     }
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir } // namespace internal
157cdf0e10cSrcweir } // namespace slideshow
158cdf0e10cSrcweir 
159