2010-10-12 15:51:52 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-07-11 09:51:50 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2005-01-21 16:04:55 +00:00
|
|
|
|
2006-09-17 07:35:24 +00:00
|
|
|
|
2005-10-11 07:42:36 +00:00
|
|
|
#include "basecontainernode.hxx"
|
2012-06-19 18:53:14 +02:00
|
|
|
#include "eventqueue.hxx"
|
2005-10-11 07:42:36 +00:00
|
|
|
#include "tools.hxx"
|
|
|
|
#include "nodetools.hxx"
|
|
|
|
#include "delayevent.hxx"
|
2007-07-17 13:48:37 +00:00
|
|
|
|
2016-05-11 12:41:19 +02:00
|
|
|
#include <functional>
|
2005-01-21 16:04:55 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2006-07-26 06:34:02 +00:00
|
|
|
using namespace com::sun::star;
|
2005-01-21 16:04:55 +00:00
|
|
|
|
2006-12-13 14:32:16 +00:00
|
|
|
namespace slideshow {
|
2005-10-11 07:42:36 +00:00
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
BaseContainerNode::BaseContainerNode(
|
|
|
|
const uno::Reference< animations::XAnimationNode >& xNode,
|
|
|
|
const BaseContainerNodeSharedPtr& rParent,
|
|
|
|
const NodeContext& rContext )
|
|
|
|
: BaseNode( xNode, rParent, rContext ),
|
|
|
|
maChildren(),
|
|
|
|
mnFinishedChildren(0),
|
2014-02-19 16:26:30 +00:00
|
|
|
mnLeftIterations(0),
|
2007-07-17 13:48:37 +00:00
|
|
|
mbDurationIndefinite( isIndefiniteTiming( xNode->getEnd() ) &&
|
2005-10-11 07:42:36 +00:00
|
|
|
isIndefiniteTiming( xNode->getDuration() ) )
|
2005-01-21 16:04:55 +00:00
|
|
|
{
|
2005-10-11 07:42:36 +00:00
|
|
|
}
|
2005-01-21 16:04:55 +00:00
|
|
|
|
2005-10-11 07:42:36 +00:00
|
|
|
void BaseContainerNode::dispose()
|
|
|
|
{
|
2016-07-29 10:40:50 +02:00
|
|
|
forEachChildNode( std::mem_fn(&Disposable::dispose), -1 );
|
2005-10-11 07:42:36 +00:00
|
|
|
maChildren.clear();
|
|
|
|
BaseNode::dispose();
|
|
|
|
}
|
2005-01-21 16:04:55 +00:00
|
|
|
|
2006-07-26 06:34:02 +00:00
|
|
|
bool BaseContainerNode::init_st()
|
2012-06-19 18:53:14 +02:00
|
|
|
{
|
|
|
|
if( !(getXAnimationNode()->getRepeatCount() >>= mnLeftIterations) )
|
|
|
|
mnLeftIterations = 1.0;
|
|
|
|
return init_children();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BaseContainerNode::init_children()
|
2005-10-11 07:42:36 +00:00
|
|
|
{
|
|
|
|
mnFinishedChildren = 0;
|
2012-06-19 18:53:14 +02:00
|
|
|
|
2005-10-11 07:42:36 +00:00
|
|
|
// initialize all children
|
2006-07-26 06:34:02 +00:00
|
|
|
return (std::count_if(
|
|
|
|
maChildren.begin(), maChildren.end(),
|
2016-05-11 12:41:19 +02:00
|
|
|
std::mem_fn(&AnimationNode::init) ) ==
|
2006-07-26 06:34:02 +00:00
|
|
|
static_cast<VectorOfNodes::difference_type>(maChildren.size()));
|
2005-10-11 07:42:36 +00:00
|
|
|
}
|
2005-01-21 16:04:55 +00:00
|
|
|
|
2006-07-26 06:34:02 +00:00
|
|
|
void BaseContainerNode::deactivate_st( NodeState eDestState )
|
2005-10-11 07:42:36 +00:00
|
|
|
{
|
2012-06-26 22:08:02 +02:00
|
|
|
mnLeftIterations = 0; // in order to make skip effect work correctly
|
2006-07-26 06:34:02 +00:00
|
|
|
if (eDestState == FROZEN) {
|
|
|
|
// deactivate all children that are not FROZEN or ENDED:
|
2016-05-11 12:41:19 +02:00
|
|
|
forEachChildNode( std::mem_fn(&AnimationNode::deactivate),
|
2006-07-26 06:34:02 +00:00
|
|
|
~(FROZEN | ENDED) );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// end all children that are not ENDED:
|
2016-05-11 12:41:19 +02:00
|
|
|
forEachChildNode( std::mem_fn(&AnimationNode::end), ~ENDED );
|
2006-07-26 06:34:02 +00:00
|
|
|
}
|
2005-10-11 07:42:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BaseContainerNode::hasPendingAnimation() const
|
|
|
|
{
|
|
|
|
// does any of our children returns "true" on
|
|
|
|
// AnimationNode::hasPendingAnimation()?
|
|
|
|
// If yes, we, too, return true
|
2015-05-12 19:54:36 +09:00
|
|
|
return std::any_of(
|
|
|
|
maChildren.begin(), maChildren.end(),
|
2016-05-11 12:41:19 +02:00
|
|
|
std::mem_fn(&AnimationNode::hasPendingAnimation) );
|
2005-10-11 07:42:36 +00:00
|
|
|
}
|
|
|
|
|
2006-07-26 06:34:02 +00:00
|
|
|
void BaseContainerNode::appendChildNode( AnimationNodeSharedPtr const& pNode )
|
2005-10-11 07:42:36 +00:00
|
|
|
{
|
2006-07-26 06:34:02 +00:00
|
|
|
if (! checkValidNode())
|
2005-10-11 07:42:36 +00:00
|
|
|
return;
|
|
|
|
|
2006-07-26 06:34:02 +00:00
|
|
|
// register derived classes as end listeners at all children.
|
2005-10-11 07:42:36 +00:00
|
|
|
// this is necessary to control the children animation
|
|
|
|
// sequence, and to determine our own end event
|
2006-07-26 06:34:02 +00:00
|
|
|
if (pNode->registerDeactivatingListener( getSelf() )) {
|
|
|
|
maChildren.push_back( pNode );
|
2005-10-11 07:42:36 +00:00
|
|
|
}
|
|
|
|
}
|
2005-01-21 16:04:55 +00:00
|
|
|
|
2006-07-26 06:34:02 +00:00
|
|
|
bool BaseContainerNode::isChildNode( AnimationNodeSharedPtr const& pNode ) const
|
2005-10-11 07:42:36 +00:00
|
|
|
{
|
2006-07-26 06:34:02 +00:00
|
|
|
// find given notifier in child vector
|
|
|
|
VectorOfNodes::const_iterator const iEnd( maChildren.end() );
|
|
|
|
VectorOfNodes::const_iterator const iFind(
|
2012-01-09 18:04:58 +01:00
|
|
|
std::find( maChildren.begin(), iEnd, pNode ) );
|
2006-07-26 06:34:02 +00:00
|
|
|
return (iFind != iEnd);
|
2005-10-11 07:42:36 +00:00
|
|
|
}
|
2005-01-21 16:04:55 +00:00
|
|
|
|
2006-07-26 06:34:02 +00:00
|
|
|
bool BaseContainerNode::notifyDeactivatedChild(
|
|
|
|
AnimationNodeSharedPtr const& pChildNode )
|
2005-10-11 07:42:36 +00:00
|
|
|
{
|
2017-05-07 17:03:35 +10:00
|
|
|
OSL_ASSERT( pChildNode->getState() == FROZEN ||
|
2006-07-26 06:34:02 +00:00
|
|
|
pChildNode->getState() == ENDED );
|
2005-10-11 07:42:36 +00:00
|
|
|
// early exit on invalid nodes
|
2017-05-07 17:03:35 +10:00
|
|
|
OSL_ASSERT( getState() != INVALID );
|
2005-10-11 07:42:36 +00:00
|
|
|
if( getState() == INVALID )
|
2006-07-26 06:34:02 +00:00
|
|
|
return false;
|
2005-10-11 07:42:36 +00:00
|
|
|
|
2006-07-26 06:34:02 +00:00
|
|
|
if (! isChildNode(pChildNode)) {
|
2011-03-12 11:41:23 +01:00
|
|
|
OSL_FAIL( "unknown notifier!" );
|
2006-07-26 06:34:02 +00:00
|
|
|
return false;
|
2005-10-11 07:42:36 +00:00
|
|
|
}
|
2006-07-26 06:34:02 +00:00
|
|
|
|
|
|
|
std::size_t const nSize = maChildren.size();
|
2017-05-07 17:03:35 +10:00
|
|
|
OSL_ASSERT( mnFinishedChildren < nSize );
|
2006-07-26 06:34:02 +00:00
|
|
|
++mnFinishedChildren;
|
2012-06-19 18:53:14 +02:00
|
|
|
bool bFinished = (mnFinishedChildren >= nSize);
|
2006-07-26 06:34:02 +00:00
|
|
|
|
|
|
|
// all children finished, and we've got indefinite duration?
|
|
|
|
// think of ParallelTimeContainer::notifyDeactivating()
|
|
|
|
// if duration given, we will be deactivated by some end event
|
|
|
|
// @see fillCommonParameters()
|
|
|
|
if (bFinished && isDurationIndefinite()) {
|
2012-06-19 18:53:14 +02:00
|
|
|
if( mnLeftIterations >= 1.0 )
|
|
|
|
{
|
|
|
|
mnLeftIterations -= 1.0;
|
|
|
|
}
|
|
|
|
if( mnLeftIterations >= 1.0 )
|
|
|
|
{
|
|
|
|
bFinished = false;
|
|
|
|
EventSharedPtr aRepetitionEvent =
|
2015-08-03 17:20:26 +02:00
|
|
|
makeDelay( [this] () { this->repeat(); },
|
2012-06-19 18:53:14 +02:00
|
|
|
0.0,
|
|
|
|
"BaseContainerNode::repeat");
|
|
|
|
getContext().mrEventQueue.addEvent( aRepetitionEvent );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
deactivate();
|
|
|
|
}
|
2005-10-11 07:42:36 +00:00
|
|
|
}
|
2005-01-21 16:04:55 +00:00
|
|
|
|
2006-07-26 06:34:02 +00:00
|
|
|
return bFinished;
|
|
|
|
}
|
2005-01-21 16:04:55 +00:00
|
|
|
|
2016-01-14 11:45:01 +02:00
|
|
|
void BaseContainerNode::repeat()
|
2012-06-19 18:53:14 +02:00
|
|
|
{
|
2016-05-11 12:41:19 +02:00
|
|
|
forEachChildNode( std::mem_fn(&AnimationNode::end), ~ENDED );
|
2014-04-24 11:37:39 +02:00
|
|
|
bool bState = init_children();
|
2012-06-19 18:53:14 +02:00
|
|
|
if( bState )
|
|
|
|
activate_st();
|
|
|
|
}
|
|
|
|
|
2015-08-10 14:04:31 -05:00
|
|
|
#if defined(DBG_UTIL)
|
2005-10-11 07:42:36 +00:00
|
|
|
void BaseContainerNode::showState() const
|
|
|
|
{
|
2016-05-10 14:39:07 +02:00
|
|
|
for(const auto & i : maChildren)
|
2005-10-11 07:42:36 +00:00
|
|
|
{
|
2006-07-26 06:34:02 +00:00
|
|
|
BaseNodeSharedPtr pNode =
|
2016-05-10 14:39:07 +02:00
|
|
|
std::dynamic_pointer_cast<BaseNode>(i);
|
2015-08-10 14:01:33 -05:00
|
|
|
SAL_INFO("slideshow.verbose",
|
|
|
|
"Node connection: n" <<
|
2016-02-09 13:41:27 +00:00
|
|
|
debugGetNodeName(this) <<
|
2015-08-10 14:01:33 -05:00
|
|
|
" -> n" <<
|
2016-02-09 13:41:27 +00:00
|
|
|
debugGetNodeName(pNode.get()));
|
2006-07-26 06:34:02 +00:00
|
|
|
pNode->showState();
|
2005-10-11 07:42:36 +00:00
|
|
|
}
|
2005-01-21 16:04:55 +00:00
|
|
|
|
2005-10-11 07:42:36 +00:00
|
|
|
BaseNode::showState();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} // namespace internal
|
2006-12-13 14:32:16 +00:00
|
|
|
} // namespace slideshow
|
2005-10-11 07:42:36 +00:00
|
|
|
|
2010-10-12 15:51:52 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|