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