Bump version to 6.0-36
[LibreOffice.git] / slideshow / source / engine / animationnodes / basecontainernode.cxx
blobc19165f72cbf7d071966e375df86cc2116588879
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 <basecontainernode.hxx>
22 #include <eventqueue.hxx>
23 #include <tools.hxx>
24 #include "nodetools.hxx"
25 #include <delayevent.hxx>
27 #include <functional>
28 #include <algorithm>
30 using namespace com::sun::star;
32 namespace slideshow {
33 namespace internal {
35 BaseContainerNode::BaseContainerNode(
36 const uno::Reference< animations::XAnimationNode >& xNode,
37 const BaseContainerNodeSharedPtr& rParent,
38 const NodeContext& rContext )
39 : BaseNode( xNode, rParent, rContext ),
40 maChildren(),
41 mnFinishedChildren(0),
42 mnLeftIterations(0),
43 mbDurationIndefinite( isIndefiniteTiming( xNode->getEnd() ) &&
44 isIndefiniteTiming( xNode->getDuration() ) )
48 void BaseContainerNode::dispose()
50 forEachChildNode( std::mem_fn(&Disposable::dispose), -1 );
51 maChildren.clear();
52 BaseNode::dispose();
55 bool BaseContainerNode::init_st()
57 if( !(getXAnimationNode()->getRepeatCount() >>= mnLeftIterations) )
58 mnLeftIterations = 1.0;
59 return init_children();
62 bool BaseContainerNode::init_children()
64 mnFinishedChildren = 0;
66 // initialize all children
67 return (std::count_if(
68 maChildren.begin(), maChildren.end(),
69 std::mem_fn(&AnimationNode::init) ) ==
70 static_cast<VectorOfNodes::difference_type>(maChildren.size()));
73 void BaseContainerNode::deactivate_st( NodeState eDestState )
75 mnLeftIterations = 0; // in order to make skip effect work correctly
76 if (eDestState == FROZEN) {
77 // deactivate all children that are not FROZEN or ENDED:
78 forEachChildNode( std::mem_fn(&AnimationNode::deactivate),
79 ~(FROZEN | ENDED) );
81 else {
82 // end all children that are not ENDED:
83 forEachChildNode( std::mem_fn(&AnimationNode::end), ~ENDED );
87 bool BaseContainerNode::hasPendingAnimation() const
89 // does any of our children returns "true" on
90 // AnimationNode::hasPendingAnimation()?
91 // If yes, we, too, return true
92 return std::any_of(
93 maChildren.begin(), maChildren.end(),
94 std::mem_fn(&AnimationNode::hasPendingAnimation) );
97 void BaseContainerNode::appendChildNode( AnimationNodeSharedPtr const& pNode )
99 if (! checkValidNode())
100 return;
102 // register derived classes as end listeners at all children.
103 // this is necessary to control the children animation
104 // sequence, and to determine our own end event
105 if (pNode->registerDeactivatingListener( getSelf() )) {
106 maChildren.push_back( pNode );
110 bool BaseContainerNode::isChildNode( AnimationNodeSharedPtr const& pNode ) const
112 // find given notifier in child vector
113 VectorOfNodes::const_iterator const iEnd( maChildren.end() );
114 VectorOfNodes::const_iterator const iFind(
115 std::find( maChildren.begin(), iEnd, pNode ) );
116 return (iFind != iEnd);
119 bool BaseContainerNode::notifyDeactivatedChild(
120 AnimationNodeSharedPtr const& pChildNode )
122 OSL_ASSERT( pChildNode->getState() == FROZEN ||
123 pChildNode->getState() == ENDED );
124 // early exit on invalid nodes
125 OSL_ASSERT( getState() != INVALID );
126 if( getState() == INVALID )
127 return false;
129 if (! isChildNode(pChildNode)) {
130 OSL_FAIL( "unknown notifier!" );
131 return false;
134 std::size_t const nSize = maChildren.size();
135 OSL_ASSERT( mnFinishedChildren < nSize );
136 ++mnFinishedChildren;
137 bool bFinished = (mnFinishedChildren >= nSize);
139 // all children finished, and we've got indefinite duration?
140 // think of ParallelTimeContainer::notifyDeactivating()
141 // if duration given, we will be deactivated by some end event
142 // @see fillCommonParameters()
143 if (bFinished && isDurationIndefinite()) {
144 if( mnLeftIterations >= 1.0 )
146 mnLeftIterations -= 1.0;
148 if( mnLeftIterations >= 1.0 )
150 bFinished = false;
151 EventSharedPtr aRepetitionEvent =
152 makeDelay( [this] () { this->repeat(); },
153 0.0,
154 "BaseContainerNode::repeat");
155 getContext().mrEventQueue.addEvent( aRepetitionEvent );
157 else
159 deactivate();
163 return bFinished;
166 void BaseContainerNode::repeat()
168 forEachChildNode( std::mem_fn(&AnimationNode::end), ~ENDED );
169 bool bState = init_children();
170 if( bState )
171 activate_st();
174 #if defined(DBG_UTIL)
175 void BaseContainerNode::showState() const
177 for(const auto & i : maChildren)
179 BaseNodeSharedPtr pNode =
180 std::dynamic_pointer_cast<BaseNode>(i);
181 SAL_INFO("slideshow.verbose",
182 "Node connection: n" <<
183 debugGetNodeName(this) <<
184 " -> n" <<
185 debugGetNodeName(pNode.get()));
186 pNode->showState();
189 BaseNode::showState();
191 #endif
193 } // namespace internal
194 } // namespace slideshow
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */