fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / slideshow / source / engine / animationnodes / basecontainernode.cxx
bloba3c73e8e2c23daa030d0a8824726d087601b8892
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 // must be first
22 #include <canvas/debug.hxx>
23 #include <canvas/verbosetrace.hxx>
25 #include "basecontainernode.hxx"
26 #include "eventqueue.hxx"
27 #include "tools.hxx"
28 #include "nodetools.hxx"
29 #include "delayevent.hxx"
31 #include <boost/bind.hpp>
32 #include <boost/mem_fn.hpp>
33 #include <algorithm>
35 using namespace com::sun::star;
37 namespace slideshow {
38 namespace internal {
40 BaseContainerNode::BaseContainerNode(
41 const uno::Reference< animations::XAnimationNode >& xNode,
42 const BaseContainerNodeSharedPtr& rParent,
43 const NodeContext& rContext )
44 : BaseNode( xNode, rParent, rContext ),
45 maChildren(),
46 mnFinishedChildren(0),
47 mnLeftIterations(0),
48 mbDurationIndefinite( isIndefiniteTiming( xNode->getEnd() ) &&
49 isIndefiniteTiming( xNode->getDuration() ) )
53 void BaseContainerNode::dispose()
55 forEachChildNode( boost::mem_fn(&Disposable::dispose) );
56 maChildren.clear();
57 BaseNode::dispose();
60 bool BaseContainerNode::init_st()
62 if( !(getXAnimationNode()->getRepeatCount() >>= mnLeftIterations) )
63 mnLeftIterations = 1.0;
64 return init_children();
67 bool BaseContainerNode::init_children()
69 mnFinishedChildren = 0;
71 // initialize all children
72 return (std::count_if(
73 maChildren.begin(), maChildren.end(),
74 boost::mem_fn(&AnimationNode::init) ) ==
75 static_cast<VectorOfNodes::difference_type>(maChildren.size()));
78 void BaseContainerNode::deactivate_st( NodeState eDestState )
80 mnLeftIterations = 0; // in order to make skip effect work correctly
81 if (eDestState == FROZEN) {
82 // deactivate all children that are not FROZEN or ENDED:
83 forEachChildNode( boost::mem_fn(&AnimationNode::deactivate),
84 ~(FROZEN | ENDED) );
86 else {
87 // end all children that are not ENDED:
88 forEachChildNode( boost::mem_fn(&AnimationNode::end), ~ENDED );
92 bool BaseContainerNode::hasPendingAnimation() const
94 // does any of our children returns "true" on
95 // AnimationNode::hasPendingAnimation()?
96 // If yes, we, too, return true
97 return std::any_of(
98 maChildren.begin(), maChildren.end(),
99 boost::mem_fn(&AnimationNode::hasPendingAnimation) );
102 void BaseContainerNode::appendChildNode( AnimationNodeSharedPtr const& pNode )
104 if (! checkValidNode())
105 return;
107 // register derived classes as end listeners at all children.
108 // this is necessary to control the children animation
109 // sequence, and to determine our own end event
110 if (pNode->registerDeactivatingListener( getSelf() )) {
111 maChildren.push_back( pNode );
115 bool BaseContainerNode::isChildNode( AnimationNodeSharedPtr const& pNode ) const
117 // find given notifier in child vector
118 VectorOfNodes::const_iterator const iEnd( maChildren.end() );
119 VectorOfNodes::const_iterator const iFind(
120 std::find( maChildren.begin(), iEnd, pNode ) );
121 return (iFind != iEnd);
124 bool BaseContainerNode::notifyDeactivatedChild(
125 AnimationNodeSharedPtr const& pChildNode )
127 OSL_ASSERT( pChildNode->getState() == FROZEN ||
128 pChildNode->getState() == ENDED );
129 // early exit on invalid nodes
130 OSL_ASSERT( getState() != INVALID );
131 if( getState() == INVALID )
132 return false;
134 if (! isChildNode(pChildNode)) {
135 OSL_FAIL( "unknown notifier!" );
136 return false;
139 std::size_t const nSize = maChildren.size();
140 OSL_ASSERT( mnFinishedChildren < nSize );
141 ++mnFinishedChildren;
142 bool bFinished = (mnFinishedChildren >= nSize);
144 // all children finished, and we've got indefinite duration?
145 // think of ParallelTimeContainer::notifyDeactivating()
146 // if duration given, we will be deactivated by some end event
147 // @see fillCommonParameters()
148 if (bFinished && isDurationIndefinite()) {
149 if( mnLeftIterations >= 1.0 )
151 mnLeftIterations -= 1.0;
153 if( mnLeftIterations >= 1.0 )
155 bFinished = false;
156 EventSharedPtr aRepetitionEvent =
157 makeDelay( boost::bind( &BaseContainerNode::repeat, this ),
158 0.0,
159 "BaseContainerNode::repeat");
160 getContext().mrEventQueue.addEvent( aRepetitionEvent );
162 else
164 deactivate();
168 return bFinished;
171 bool BaseContainerNode::repeat()
173 forEachChildNode( boost::mem_fn(&AnimationNode::end), ~ENDED );
174 bool bState = init_children();
175 if( bState )
176 activate_st();
177 return bState;
180 #if OSL_DEBUG_LEVEL >= 2 && defined(DBG_UTIL)
181 void BaseContainerNode::showState() const
183 for( std::size_t i=0; i<maChildren.size(); ++i )
185 BaseNodeSharedPtr pNode =
186 boost::dynamic_pointer_cast<BaseNode>(maChildren[i]);
187 VERBOSE_TRACE(
188 "Node connection: n%p -> n%p",
189 (const char*)this+debugGetCurrentOffset(),
190 (const char*)pNode.get()+debugGetCurrentOffset() );
191 pNode->showState();
194 BaseNode::showState();
196 #endif
198 } // namespace internal
199 } // namespace slideshow
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */