1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_slideshow.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir // must be first 32*cdf0e10cSrcweir #include <canvas/debug.hxx> 33*cdf0e10cSrcweir #include <canvas/verbosetrace.hxx> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include "basecontainernode.hxx" 36*cdf0e10cSrcweir #include "tools.hxx" 37*cdf0e10cSrcweir #include "nodetools.hxx" 38*cdf0e10cSrcweir #include "delayevent.hxx" 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include <boost/mem_fn.hpp> 41*cdf0e10cSrcweir #include <algorithm> 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir using namespace com::sun::star; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir namespace slideshow { 46*cdf0e10cSrcweir namespace internal { 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir BaseContainerNode::BaseContainerNode( 49*cdf0e10cSrcweir const uno::Reference< animations::XAnimationNode >& xNode, 50*cdf0e10cSrcweir const BaseContainerNodeSharedPtr& rParent, 51*cdf0e10cSrcweir const NodeContext& rContext ) 52*cdf0e10cSrcweir : BaseNode( xNode, rParent, rContext ), 53*cdf0e10cSrcweir maChildren(), 54*cdf0e10cSrcweir mnFinishedChildren(0), 55*cdf0e10cSrcweir mbDurationIndefinite( isIndefiniteTiming( xNode->getEnd() ) && 56*cdf0e10cSrcweir isIndefiniteTiming( xNode->getDuration() ) ) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir void BaseContainerNode::dispose() 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir forEachChildNode( boost::mem_fn(&Disposable::dispose) ); 63*cdf0e10cSrcweir maChildren.clear(); 64*cdf0e10cSrcweir BaseNode::dispose(); 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir bool BaseContainerNode::init_st() 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir mnFinishedChildren = 0; 70*cdf0e10cSrcweir // initialize all children 71*cdf0e10cSrcweir return (std::count_if( 72*cdf0e10cSrcweir maChildren.begin(), maChildren.end(), 73*cdf0e10cSrcweir boost::mem_fn(&AnimationNode::init) ) == 74*cdf0e10cSrcweir static_cast<VectorOfNodes::difference_type>(maChildren.size())); 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir void BaseContainerNode::deactivate_st( NodeState eDestState ) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir if (eDestState == FROZEN) { 80*cdf0e10cSrcweir // deactivate all children that are not FROZEN or ENDED: 81*cdf0e10cSrcweir forEachChildNode( boost::mem_fn(&AnimationNode::deactivate), 82*cdf0e10cSrcweir ~(FROZEN | ENDED) ); 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir else { 85*cdf0e10cSrcweir // end all children that are not ENDED: 86*cdf0e10cSrcweir forEachChildNode( boost::mem_fn(&AnimationNode::end), ~ENDED ); 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir bool BaseContainerNode::hasPendingAnimation() const 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir // does any of our children returns "true" on 93*cdf0e10cSrcweir // AnimationNode::hasPendingAnimation()? 94*cdf0e10cSrcweir // If yes, we, too, return true 95*cdf0e10cSrcweir VectorOfNodes::const_iterator const iEnd( maChildren.end() ); 96*cdf0e10cSrcweir return (std::find_if( 97*cdf0e10cSrcweir maChildren.begin(), iEnd, 98*cdf0e10cSrcweir boost::mem_fn(&AnimationNode::hasPendingAnimation) ) != iEnd); 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir void BaseContainerNode::appendChildNode( AnimationNodeSharedPtr const& pNode ) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir if (! checkValidNode()) 104*cdf0e10cSrcweir return; 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir // register derived classes as end listeners at all children. 107*cdf0e10cSrcweir // this is necessary to control the children animation 108*cdf0e10cSrcweir // sequence, and to determine our own end event 109*cdf0e10cSrcweir if (pNode->registerDeactivatingListener( getSelf() )) { 110*cdf0e10cSrcweir maChildren.push_back( pNode ); 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir bool BaseContainerNode::isChildNode( AnimationNodeSharedPtr const& pNode ) const 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir // find given notifier in child vector 117*cdf0e10cSrcweir VectorOfNodes::const_iterator const iBegin( maChildren.begin() ); 118*cdf0e10cSrcweir VectorOfNodes::const_iterator const iEnd( maChildren.end() ); 119*cdf0e10cSrcweir VectorOfNodes::const_iterator const iFind( 120*cdf0e10cSrcweir std::find( iBegin, iEnd, pNode ) ); 121*cdf0e10cSrcweir return (iFind != iEnd); 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir bool BaseContainerNode::notifyDeactivatedChild( 125*cdf0e10cSrcweir AnimationNodeSharedPtr const& pChildNode ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir OSL_ASSERT( pChildNode->getState() == FROZEN || 128*cdf0e10cSrcweir pChildNode->getState() == ENDED ); 129*cdf0e10cSrcweir // early exit on invalid nodes 130*cdf0e10cSrcweir OSL_ASSERT( getState() != INVALID ); 131*cdf0e10cSrcweir if( getState() == INVALID ) 132*cdf0e10cSrcweir return false; 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir if (! isChildNode(pChildNode)) { 135*cdf0e10cSrcweir OSL_ENSURE( false, "unknown notifier!" ); 136*cdf0e10cSrcweir return false; 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir std::size_t const nSize = maChildren.size(); 140*cdf0e10cSrcweir OSL_ASSERT( mnFinishedChildren < nSize ); 141*cdf0e10cSrcweir ++mnFinishedChildren; 142*cdf0e10cSrcweir bool const bFinished = (mnFinishedChildren >= nSize); 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir // all children finished, and we've got indefinite duration? 145*cdf0e10cSrcweir // think of ParallelTimeContainer::notifyDeactivating() 146*cdf0e10cSrcweir // if duration given, we will be deactivated by some end event 147*cdf0e10cSrcweir // @see fillCommonParameters() 148*cdf0e10cSrcweir if (bFinished && isDurationIndefinite()) { 149*cdf0e10cSrcweir deactivate(); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir return bFinished; 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir #if defined(VERBOSE) && defined(DBG_UTIL) 156*cdf0e10cSrcweir void BaseContainerNode::showState() const 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir for( std::size_t i=0; i<maChildren.size(); ++i ) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir BaseNodeSharedPtr pNode = 161*cdf0e10cSrcweir boost::shared_dynamic_cast<BaseNode>(maChildren[i]); 162*cdf0e10cSrcweir VERBOSE_TRACE( 163*cdf0e10cSrcweir "Node connection: n0x%X -> n0x%X", 164*cdf0e10cSrcweir (const char*)this+debugGetCurrentOffset(), 165*cdf0e10cSrcweir (const char*)pNode.get()+debugGetCurrentOffset() ); 166*cdf0e10cSrcweir pNode->showState(); 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir BaseNode::showState(); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir #endif 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir } // namespace internal 174*cdf0e10cSrcweir } // namespace slideshow 175*cdf0e10cSrcweir 176