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