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 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_slideshow.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <canvas/debug.hxx>
32*cdf0e10cSrcweir #include <canvas/verbosetrace.hxx>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include "delayevent.hxx"
35*cdf0e10cSrcweir #include "eventqueue.hxx"
36*cdf0e10cSrcweir #include "usereventqueue.hxx"
37*cdf0e10cSrcweir #include "sequentialtimecontainer.hxx"
38*cdf0e10cSrcweir #include "tools.hxx"
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <boost/bind.hpp>
41*cdf0e10cSrcweir #include <algorithm>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir namespace slideshow {
44*cdf0e10cSrcweir namespace internal {
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir void SequentialTimeContainer::activate_st()
47*cdf0e10cSrcweir {
48*cdf0e10cSrcweir     // resolve first possible child, ignore
49*cdf0e10cSrcweir     for ( ; mnFinishedChildren < maChildren.size(); ++mnFinishedChildren ) {
50*cdf0e10cSrcweir         if (resolveChild( maChildren[mnFinishedChildren] ))
51*cdf0e10cSrcweir             break;
52*cdf0e10cSrcweir         else {
53*cdf0e10cSrcweir             // node still UNRESOLVED, no need to deactivate or end...
54*cdf0e10cSrcweir             OSL_ENSURE( false, "### resolving child failed!" );
55*cdf0e10cSrcweir         }
56*cdf0e10cSrcweir     }
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir     if (isDurationIndefinite() &&
59*cdf0e10cSrcweir         (maChildren.empty() || mnFinishedChildren >= maChildren.size()))
60*cdf0e10cSrcweir     {
61*cdf0e10cSrcweir         // deactivate ASAP:
62*cdf0e10cSrcweir         scheduleDeactivationEvent(
63*cdf0e10cSrcweir             makeEvent(
64*cdf0e10cSrcweir                  boost::bind< void >( boost::mem_fn( &AnimationNode::deactivate ), getSelf() ),
65*cdf0e10cSrcweir                  "SequentialTimeContainer::deactivate") );
66*cdf0e10cSrcweir     }
67*cdf0e10cSrcweir     else // use default
68*cdf0e10cSrcweir         scheduleDeactivationEvent();
69*cdf0e10cSrcweir }
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir void SequentialTimeContainer::dispose()
72*cdf0e10cSrcweir {
73*cdf0e10cSrcweir     BaseContainerNode::dispose();
74*cdf0e10cSrcweir     if (mpCurrentSkipEvent) {
75*cdf0e10cSrcweir         mpCurrentSkipEvent->dispose();
76*cdf0e10cSrcweir         mpCurrentSkipEvent.reset();
77*cdf0e10cSrcweir     }
78*cdf0e10cSrcweir     if (mpCurrentRewindEvent) {
79*cdf0e10cSrcweir         mpCurrentRewindEvent->dispose();
80*cdf0e10cSrcweir         mpCurrentRewindEvent.reset();
81*cdf0e10cSrcweir     }
82*cdf0e10cSrcweir }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir void SequentialTimeContainer::skipEffect(
85*cdf0e10cSrcweir     AnimationNodeSharedPtr const& pChildNode )
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir     if (isChildNode(pChildNode)) {
88*cdf0e10cSrcweir         // empty all events ignoring timings => until next effect
89*cdf0e10cSrcweir         getContext().mrEventQueue.forceEmpty();
90*cdf0e10cSrcweir         getContext().mrEventQueue.addEvent(
91*cdf0e10cSrcweir             makeEvent(
92*cdf0e10cSrcweir                 boost::bind<void>( boost::mem_fn( &AnimationNode::deactivate ), pChildNode ),
93*cdf0e10cSrcweir                 "SequentialTimeContainer::deactivate, skipEffect with delay") );
94*cdf0e10cSrcweir     }
95*cdf0e10cSrcweir     else
96*cdf0e10cSrcweir         OSL_ENSURE( false, "unknown notifier!" );
97*cdf0e10cSrcweir }
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir void SequentialTimeContainer::rewindEffect(
100*cdf0e10cSrcweir     AnimationNodeSharedPtr const& /*pChildNode*/ )
101*cdf0e10cSrcweir {
102*cdf0e10cSrcweir     // xxx todo: ...
103*cdf0e10cSrcweir }
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir bool SequentialTimeContainer::resolveChild(
106*cdf0e10cSrcweir     AnimationNodeSharedPtr const& pChildNode )
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir     bool const bResolved = pChildNode->resolve();
109*cdf0e10cSrcweir     if (bResolved && isMainSequenceRootNode()) {
110*cdf0e10cSrcweir         // discharge events:
111*cdf0e10cSrcweir         if (mpCurrentSkipEvent)
112*cdf0e10cSrcweir             mpCurrentSkipEvent->dispose();
113*cdf0e10cSrcweir         if (mpCurrentRewindEvent)
114*cdf0e10cSrcweir             mpCurrentRewindEvent->dispose();
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir         // event that will deactivate the resolved/running child:
117*cdf0e10cSrcweir         mpCurrentSkipEvent = makeEvent(
118*cdf0e10cSrcweir             boost::bind( &SequentialTimeContainer::skipEffect,
119*cdf0e10cSrcweir                          boost::dynamic_pointer_cast<SequentialTimeContainer>( getSelf() ),
120*cdf0e10cSrcweir                          pChildNode ),
121*cdf0e10cSrcweir             "SequentialTimeContainer::skipEffect, resolveChild");
122*cdf0e10cSrcweir         // event that will reresolve the resolved/activated child:
123*cdf0e10cSrcweir         mpCurrentRewindEvent = makeEvent(
124*cdf0e10cSrcweir             boost::bind( &SequentialTimeContainer::rewindEffect,
125*cdf0e10cSrcweir                          boost::dynamic_pointer_cast<SequentialTimeContainer>( getSelf() ),
126*cdf0e10cSrcweir                          pChildNode ),
127*cdf0e10cSrcweir             "SequentialTimeContainer::rewindEffect, resolveChild");
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir         // deactivate child node when skip event occurs:
130*cdf0e10cSrcweir         getContext().mrUserEventQueue.registerSkipEffectEvent(
131*cdf0e10cSrcweir             mpCurrentSkipEvent,
132*cdf0e10cSrcweir             mnFinishedChildren+1<maChildren.size());
133*cdf0e10cSrcweir         // rewind to previous child:
134*cdf0e10cSrcweir         getContext().mrUserEventQueue.registerRewindEffectEvent(
135*cdf0e10cSrcweir             mpCurrentRewindEvent );
136*cdf0e10cSrcweir     }
137*cdf0e10cSrcweir     return bResolved;
138*cdf0e10cSrcweir }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir void SequentialTimeContainer::notifyDeactivating(
141*cdf0e10cSrcweir     AnimationNodeSharedPtr const& rNotifier )
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir     if (notifyDeactivatedChild( rNotifier ))
144*cdf0e10cSrcweir         return;
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir     OSL_ASSERT( mnFinishedChildren < maChildren.size() );
147*cdf0e10cSrcweir     AnimationNodeSharedPtr const& pNextChild = maChildren[mnFinishedChildren];
148*cdf0e10cSrcweir     OSL_ASSERT( pNextChild->getState() == UNRESOLVED );
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir     if (! resolveChild( pNextChild )) {
151*cdf0e10cSrcweir         // could not resolve child - since we risk to
152*cdf0e10cSrcweir         // stall the chain of events here, play it safe
153*cdf0e10cSrcweir         // and deactivate this node (only if we have
154*cdf0e10cSrcweir         // indefinite duration - otherwise, we'll get a
155*cdf0e10cSrcweir         // deactivation event, anyways).
156*cdf0e10cSrcweir         deactivate();
157*cdf0e10cSrcweir     }
158*cdf0e10cSrcweir }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir } // namespace internal
161*cdf0e10cSrcweir } // namespace slideshow
162*cdf0e10cSrcweir 
163