Bump version to 6.0-36
[LibreOffice.git] / slideshow / source / engine / animationnodes / sequentialtimecontainer.cxx
blob15e5a7f2763d128411bfa64d9545f4385dd5ed79
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 <delayevent.hxx>
22 #include <eventqueue.hxx>
23 #include <usereventqueue.hxx>
24 #include "sequentialtimecontainer.hxx"
25 #include <tools.hxx>
27 #include <algorithm>
29 namespace slideshow {
30 namespace internal {
32 void SequentialTimeContainer::activate_st()
34 // resolve first possible child, ignore
35 for ( ; mnFinishedChildren < maChildren.size(); ++mnFinishedChildren ) {
36 if (resolveChild( maChildren[mnFinishedChildren] ))
37 break;
38 else {
39 // node still UNRESOLVED, no need to deactivate or end...
40 OSL_FAIL( "### resolving child failed!" );
44 if (isDurationIndefinite() &&
45 (maChildren.empty() || mnFinishedChildren >= maChildren.size()))
47 // deactivate ASAP:
48 auto self(getSelf());
49 scheduleDeactivationEvent(
50 makeEvent( [self] () { self->deactivate(); },
51 "SequentialTimeContainer::deactivate") );
53 else // use default
54 scheduleDeactivationEvent();
57 void SequentialTimeContainer::dispose()
59 BaseContainerNode::dispose();
60 if (mpCurrentSkipEvent) {
61 mpCurrentSkipEvent->dispose();
62 mpCurrentSkipEvent.reset();
64 if (mpCurrentRewindEvent) {
65 mpCurrentRewindEvent->dispose();
66 mpCurrentRewindEvent.reset();
70 void SequentialTimeContainer::skipEffect(
71 AnimationNodeSharedPtr const& pChildNode )
73 if (isChildNode(pChildNode)) {
74 // empty all events ignoring timings => until next effect
75 getContext().mrEventQueue.forceEmpty();
76 getContext().mrEventQueue.addEvent(
77 makeEvent( [pChildNode] () { pChildNode->deactivate(); },
78 "SequentialTimeContainer::deactivate, skipEffect with delay") );
80 else
81 OSL_FAIL( "unknown notifier!" );
84 bool SequentialTimeContainer::resolveChild(
85 AnimationNodeSharedPtr const& pChildNode )
87 bool const bResolved = pChildNode->resolve();
88 if (bResolved && isMainSequenceRootNode()) {
89 // discharge events:
90 if (mpCurrentSkipEvent)
91 mpCurrentSkipEvent->dispose();
92 if (mpCurrentRewindEvent)
93 mpCurrentRewindEvent->dispose();
95 // event that will deactivate the resolved/running child:
96 mpCurrentSkipEvent = makeEvent(
97 std::bind( &SequentialTimeContainer::skipEffect,
98 std::dynamic_pointer_cast<SequentialTimeContainer>( getSelf() ),
99 pChildNode ),
100 "SequentialTimeContainer::skipEffect, resolveChild");
102 // deactivate child node when skip event occurs:
103 getContext().mrUserEventQueue.registerSkipEffectEvent(
104 mpCurrentSkipEvent,
105 mnFinishedChildren+1<maChildren.size());
107 return bResolved;
110 void SequentialTimeContainer::notifyDeactivating(
111 AnimationNodeSharedPtr const& rNotifier )
113 if (notifyDeactivatedChild( rNotifier ))
114 return;
116 OSL_ASSERT( mnFinishedChildren < maChildren.size() );
117 AnimationNodeSharedPtr const& pNextChild = maChildren[mnFinishedChildren];
118 OSL_ASSERT( pNextChild->getState() == UNRESOLVED );
120 if (! resolveChild( pNextChild )) {
121 // could not resolve child - since we risk to
122 // stall the chain of events here, play it safe
123 // and deactivate this node (only if we have
124 // indefinite duration - otherwise, we'll get a
125 // deactivation event, anyways).
126 deactivate();
130 } // namespace internal
131 } // namespace slideshow
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */