Files
libreoffice/slideshow/source/engine/animationnodes/basecontainernode.cxx
Oliver Bolte 2c914ed7a4 INTEGRATION: CWS presfixes08 (1.3.16); FILE MERGED
2005/07/21 16:13:44 dbo 1.3.16.4: #i45197# some cleanup
Issue number:
Submitted by:
Reviewed by:
2005/07/20 16:05:59 dbo 1.3.16.3: #i45197#
Issue number:
Submitted by:
Reviewed by:
2005/07/15 13:11:01 dbo 1.3.16.2: #i45197# skipping animations, cleanup
Issue number:
Submitted by:
Reviewed by:
2005/06/13 08:55:19 dbo 1.3.16.1: #i45197# skip effect event
Issue number:
Submitted by:
Reviewed by:
2005-10-11 07:42:36 +00:00

257 lines
7.5 KiB
C++

/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: basecontainernode.cxx,v $
*
* $Revision: 1.5 $
*
* last change: $Author: obo $ $Date: 2005-10-11 08:42:36 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
************************************************************************/
// must be first
#include "canvas/debug.hxx"
#include "canvas/verbosetrace.hxx"
#include "basecontainernode.hxx"
#include "tools.hxx"
#include "nodetools.hxx"
#include "delayevent.hxx"
#include "boost/bind.hpp"
#include "boost/mem_fn.hpp"
#include <vector>
#include <algorithm>
#include <iterator>
using namespace ::com::sun::star;
namespace presentation {
namespace internal {
BaseContainerNode::BaseContainerNode(
const uno::Reference< animations::XAnimationNode >& xNode,
const BaseContainerNodeSharedPtr& rParent,
const NodeContext& rContext )
: BaseNode( xNode, rParent, rContext ),
maChildren(),
maFinishedStates(),
mnFinishedChildren(0),
mbOverrideIndefiniteBegin( false ),
mbDurationIndefinite( isIndefiniteTiming( xNode->getEnd() ) ||
isIndefiniteTiming( xNode->getDuration() ) )
{
}
bool BaseContainerNode::activate()
{
if( getState() == ACTIVE )
return true; // avoid duplicate event generation
if( !BaseNode::activate() )
return false;
if( isDurationInfinite() &&
maChildren.empty() )
{
// schedule deactivation:
getContext().mrEventQueue.addEvent(
makeEvent( boost::bind( &BaseNode::deactivate, getSelf() ) ) );
}
return true;
}
void BaseContainerNode::deactivate()
{
// deactivate all children:
VectorOfNodes::iterator iPos( maChildren.begin() );
VectorOfNodes::iterator const iEnd( maChildren.end() );
for ( ; iPos != iEnd; ++iPos ) {
BaseNodeSharedPtr const& pNode = *iPos;
NodeState const eState = pNode->getState();
if (eState != FROZEN || eState != ENDED)
pNode->deactivate();
}
BaseNode::deactivate();
}
void BaseContainerNode::dispose()
{
std::for_each( maChildren.begin(), maChildren.end(),
boost::mem_fn(&BaseNode::dispose) );
maChildren.clear();
maFinishedStates.clear();
BaseNode::dispose();
}
bool BaseContainerNode::init()
{
if( !BaseNode::init() )
return false;
// init local state
std::fill( maFinishedStates.begin(), maFinishedStates.end(), false );
mnFinishedChildren = 0;
mbOverrideIndefiniteBegin = false;
// initialize all children
if( std::count_if( maChildren.begin(), maChildren.end(),
boost::mem_fn(&AnimationNode::init) )
!= static_cast<VectorOfNodes::difference_type>(maChildren.size()) )
{
return false; // not all children have been correctly initialized
}
return true;
}
void BaseContainerNode::end()
{
BaseNode::end();
// end all children
std::for_each( maChildren.begin(), maChildren.end(),
boost::mem_fn(&AnimationNode::end) );
}
bool BaseContainerNode::hasPendingAnimation() const
{
const VectorOfNodes::const_iterator aEnd( maChildren.end() );
// does any of our children returns "true" on
// AnimationNode::hasPendingAnimation()?
// If yes, we, too, return true
return std::find_if( maChildren.begin(), aEnd,
boost::mem_fn(&AnimationNode::hasPendingAnimation) )
!= aEnd;
}
void BaseContainerNode::appendChildNode( const BaseNodeSharedPtr& rNode )
{
ENSURE_AND_THROW(
getSelf().get(), "BaseContainerNode::appendChildNode(): no self set" );
// early exit on invalid nodes
if( getState() == INVALID )
return;
// register ourself as end listeners at all children.
// this is necessary to control the children animation
// sequence, and to determine our own end event
if( rNode->registerDeactivatingListener( getSelf() ) ) {
maChildren.push_back( rNode );
maFinishedStates.push_back( false );
}
}
void BaseContainerNode::scheduleActivationEvent()
{
// buffer value for check below
const bool bOverrideIndefiniteBegin( mbOverrideIndefiniteBegin );
// request will be fulfilled, but normalize state early
// (prevent callback errors)
mbOverrideIndefiniteBegin = false;
// for indefinite start event - our begin event
// becomes definite, if a child has issued a
// requestResolveOnChildren(). Otherwise, we'll never
// become active.
if( bOverrideIndefiniteBegin &&
isIndefiniteTiming( getXNode()->getBegin() ) )
{
// become active immediately.
if( !activate() ) {
OSL_ENSURE( false, "BaseContainerNode::scheduleActivationEvent(): "
"Could not activate ourselves" );
}
}
else {
// no override necessary - use normal BaseNode method
BaseNode::scheduleActivationEvent();
}
}
void BaseContainerNode::requestResolveOnChildren()
{
// early exit on invalid nodes
if( getState() == INVALID )
return;
// coerce our resolve() to override indefinite begins.
// After all, we now _have_ defined begin time, which is
// _now_.
mbOverrideIndefiniteBegin = true;
if( getState() == UNRESOLVED ) {
ENSURE_AND_THROW( getParentNode().get(),
"BaseContainerNode::requestResolveOnChildren(): "
"No parent, and still unresolved" );
// if we ourselves are unresolved, request parent
// to resolve us
getParentNode()->requestResolveOnChildren();
}
else {
// otherwise, try to (re)start ourselves.
if( !activate() ) {
OSL_ENSURE( false,
"BaseContainerNode::requestResolveOnChildren(): "
"Could not (re)start" );
}
}
}
// Debug
//=========================================================================
#if defined(VERBOSE) && defined(DBG_UTIL)
void BaseContainerNode::showState() const
{
for( std::size_t i=0; i<maChildren.size(); ++i )
{
VERBOSE_TRACE(
"Node connection: n0x%X -> n0x%X",
(const char*)this+debugGetCurrentOffset(),
(const char*)maChildren[i].get()+debugGetCurrentOffset() );
maChildren[i]->showState();
}
BaseNode::showState();
}
const char* BaseContainerNode::getDescription() const
{
return "BaseNode";
}
#endif
} // namespace internal
} // namespace presentation