bump product version to 5.0.4.1
[LibreOffice.git] / slideshow / source / engine / animationnodes / sequentialtimecontainer.cxx
blob1972e31ce68767194bcbbb833d2cbee1c4d33b4b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <canvas/debug.hxx>
22 #include <canvas/verbosetrace.hxx>
24 #include "delayevent.hxx"
25 #include "eventqueue.hxx"
26 #include "usereventqueue.hxx"
27 #include "sequentialtimecontainer.hxx"
28 #include "tools.hxx"
30 #include <boost/bind.hpp>
31 #include <algorithm>
33 namespace slideshow {
34 namespace internal {
36 void SequentialTimeContainer::activate_st()
38 // resolve first possible child, ignore
39 for ( ; mnFinishedChildren < maChildren.size(); ++mnFinishedChildren ) {
40 if (resolveChild( maChildren[mnFinishedChildren] ))
41 break;
42 else {
43 // node still UNRESOLVED, no need to deactivate or end...
44 OSL_FAIL( "### resolving child failed!" );
48 if (isDurationIndefinite() &&
49 (maChildren.empty() || mnFinishedChildren >= maChildren.size()))
51 // deactivate ASAP:
52 scheduleDeactivationEvent(
53 makeEvent(
54 boost::bind< void >( boost::mem_fn( &AnimationNode::deactivate ), getSelf() ),
55 "SequentialTimeContainer::deactivate") );
57 else // use default
58 scheduleDeactivationEvent();
61 void SequentialTimeContainer::dispose()
63 BaseContainerNode::dispose();
64 if (mpCurrentSkipEvent) {
65 mpCurrentSkipEvent->dispose();
66 mpCurrentSkipEvent.reset();
68 if (mpCurrentRewindEvent) {
69 mpCurrentRewindEvent->dispose();
70 mpCurrentRewindEvent.reset();
74 void SequentialTimeContainer::skipEffect(
75 AnimationNodeSharedPtr const& pChildNode )
77 if (isChildNode(pChildNode)) {
78 // empty all events ignoring timings => until next effect
79 getContext().mrEventQueue.forceEmpty();
80 getContext().mrEventQueue.addEvent(
81 makeEvent(
82 boost::bind<void>( boost::mem_fn( &AnimationNode::deactivate ), pChildNode ),
83 "SequentialTimeContainer::deactivate, skipEffect with delay") );
85 else
86 OSL_FAIL( "unknown notifier!" );
89 bool SequentialTimeContainer::resolveChild(
90 AnimationNodeSharedPtr const& pChildNode )
92 bool const bResolved = pChildNode->resolve();
93 if (bResolved && isMainSequenceRootNode()) {
94 // discharge events:
95 if (mpCurrentSkipEvent)
96 mpCurrentSkipEvent->dispose();
97 if (mpCurrentRewindEvent)
98 mpCurrentRewindEvent->dispose();
100 // event that will deactivate the resolved/running child:
101 mpCurrentSkipEvent = makeEvent(
102 boost::bind( &SequentialTimeContainer::skipEffect,
103 boost::dynamic_pointer_cast<SequentialTimeContainer>( getSelf() ),
104 pChildNode ),
105 "SequentialTimeContainer::skipEffect, resolveChild");
107 // deactivate child node when skip event occurs:
108 getContext().mrUserEventQueue.registerSkipEffectEvent(
109 mpCurrentSkipEvent,
110 mnFinishedChildren+1<maChildren.size());
112 return bResolved;
115 void SequentialTimeContainer::notifyDeactivating(
116 AnimationNodeSharedPtr const& rNotifier )
118 if (notifyDeactivatedChild( rNotifier ))
119 return;
121 OSL_ASSERT( mnFinishedChildren < maChildren.size() );
122 AnimationNodeSharedPtr const& pNextChild = maChildren[mnFinishedChildren];
123 OSL_ASSERT( pNextChild->getState() == UNRESOLVED );
125 if (! resolveChild( pNextChild )) {
126 // could not resolve child - since we risk to
127 // stall the chain of events here, play it safe
128 // and deactivate this node (only if we have
129 // indefinite duration - otherwise, we'll get a
130 // deactivation event, anyways).
131 deactivate();
135 } // namespace internal
136 } // namespace slideshow
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */