LCOV - code coverage report
Current view: top level - slideshow/source/engine/animationnodes - basecontainernode.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 60 1.7 %
Date: 2014-11-03 Functions: 2 12 16.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      21             : // must be first
      22             : #include <canvas/debug.hxx>
      23             : #include <canvas/verbosetrace.hxx>
      24             : 
      25             : #include "basecontainernode.hxx"
      26             : #include "eventqueue.hxx"
      27             : #include "tools.hxx"
      28             : #include "nodetools.hxx"
      29             : #include "delayevent.hxx"
      30             : 
      31             : #include <boost/bind.hpp>
      32             : #include <boost/mem_fn.hpp>
      33             : #include <algorithm>
      34             : 
      35             : using namespace com::sun::star;
      36             : 
      37             : namespace slideshow {
      38             : namespace internal {
      39             : 
      40           0 : 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           0 :       mbDurationIndefinite( isIndefiniteTiming( xNode->getEnd() ) &&
      49           0 :                             isIndefiniteTiming( xNode->getDuration() ) )
      50             : {
      51           0 : }
      52             : 
      53           0 : void BaseContainerNode::dispose()
      54             : {
      55           0 :     forEachChildNode( boost::mem_fn(&Disposable::dispose) );
      56           0 :     maChildren.clear();
      57           0 :     BaseNode::dispose();
      58           0 : }
      59             : 
      60           0 : bool BaseContainerNode::init_st()
      61             : {
      62           0 :    if( !(getXAnimationNode()->getRepeatCount() >>= mnLeftIterations) )
      63           0 :         mnLeftIterations = 1.0;
      64           0 :    return init_children();
      65             : }
      66             : 
      67           0 : bool BaseContainerNode::init_children()
      68             : {
      69           0 :     mnFinishedChildren = 0;
      70             : 
      71             :     // initialize all children
      72             :     return (std::count_if(
      73             :                 maChildren.begin(), maChildren.end(),
      74           0 :                 boost::mem_fn(&AnimationNode::init) ) ==
      75           0 :             static_cast<VectorOfNodes::difference_type>(maChildren.size()));
      76             : }
      77             : 
      78           0 : void BaseContainerNode::deactivate_st( NodeState eDestState )
      79             : {
      80           0 :     mnLeftIterations = 0; // in order to make skip effect work correctly
      81           0 :     if (eDestState == FROZEN) {
      82             :         // deactivate all children that are not FROZEN or ENDED:
      83           0 :         forEachChildNode( boost::mem_fn(&AnimationNode::deactivate),
      84           0 :                           ~(FROZEN | ENDED) );
      85             :     }
      86             :     else {
      87             :         // end all children that are not ENDED:
      88           0 :         forEachChildNode( boost::mem_fn(&AnimationNode::end), ~ENDED );
      89             :     }
      90           0 : }
      91             : 
      92           0 : bool BaseContainerNode::hasPendingAnimation() const
      93             : {
      94             :     // does any of our children returns "true" on
      95             :     // AnimationNode::hasPendingAnimation()?
      96             :     // If yes, we, too, return true
      97           0 :     VectorOfNodes::const_iterator const iEnd( maChildren.end() );
      98             :     return (std::find_if(
      99             :                 maChildren.begin(), iEnd,
     100           0 :                 boost::mem_fn(&AnimationNode::hasPendingAnimation) ) != iEnd);
     101             : }
     102             : 
     103           0 : void BaseContainerNode::appendChildNode( AnimationNodeSharedPtr const& pNode )
     104             : {
     105           0 :     if (! checkValidNode())
     106           0 :         return;
     107             : 
     108             :     // register derived classes as end listeners at all children.
     109             :     // this is necessary to control the children animation
     110             :     // sequence, and to determine our own end event
     111           0 :     if (pNode->registerDeactivatingListener( getSelf() )) {
     112           0 :         maChildren.push_back( pNode );
     113             :     }
     114             : }
     115             : 
     116           0 : bool BaseContainerNode::isChildNode( AnimationNodeSharedPtr const& pNode ) const
     117             : {
     118             :     // find given notifier in child vector
     119           0 :     VectorOfNodes::const_iterator const iEnd( maChildren.end() );
     120             :     VectorOfNodes::const_iterator const iFind(
     121           0 :         std::find( maChildren.begin(), iEnd, pNode ) );
     122           0 :     return (iFind != iEnd);
     123             : }
     124             : 
     125           0 : bool BaseContainerNode::notifyDeactivatedChild(
     126             :     AnimationNodeSharedPtr const& pChildNode )
     127             : {
     128             :     OSL_ASSERT( pChildNode->getState() == FROZEN ||
     129             :                 pChildNode->getState() == ENDED );
     130             :     // early exit on invalid nodes
     131             :     OSL_ASSERT( getState() != INVALID );
     132           0 :     if( getState() == INVALID )
     133           0 :         return false;
     134             : 
     135           0 :     if (! isChildNode(pChildNode)) {
     136             :         OSL_FAIL( "unknown notifier!" );
     137           0 :         return false;
     138             :     }
     139             : 
     140           0 :     std::size_t const nSize = maChildren.size();
     141             :     OSL_ASSERT( mnFinishedChildren < nSize );
     142           0 :     ++mnFinishedChildren;
     143           0 :     bool bFinished = (mnFinishedChildren >= nSize);
     144             : 
     145             :     // all children finished, and we've got indefinite duration?
     146             :     // think of ParallelTimeContainer::notifyDeactivating()
     147             :     // if duration given, we will be deactivated by some end event
     148             :     // @see fillCommonParameters()
     149           0 :     if (bFinished && isDurationIndefinite()) {
     150           0 :         if( mnLeftIterations >= 1.0 )
     151             :         {
     152           0 :             mnLeftIterations -= 1.0;
     153             :         }
     154           0 :         if( mnLeftIterations >= 1.0 )
     155             :         {
     156           0 :             bFinished = false;
     157             :             EventSharedPtr aRepetitionEvent =
     158           0 :                     makeDelay( boost::bind( &BaseContainerNode::repeat, this ),
     159             :                                0.0,
     160             :                                "BaseContainerNode::repeat");
     161           0 :             getContext().mrEventQueue.addEvent( aRepetitionEvent );
     162             :         }
     163             :         else
     164             :         {
     165           0 :             deactivate();
     166             :         }
     167             :     }
     168             : 
     169           0 :     return bFinished;
     170             : }
     171             : 
     172           0 : bool BaseContainerNode::repeat()
     173             : {
     174           0 :     forEachChildNode( boost::mem_fn(&AnimationNode::end), ~ENDED );
     175           0 :     bool bState = init_children();
     176           0 :     if( bState )
     177           0 :         activate_st();
     178           0 :     return bState;
     179             : }
     180             : 
     181             : #if OSL_DEBUG_LEVEL >= 2 && defined(DBG_UTIL)
     182             : void BaseContainerNode::showState() const
     183             : {
     184             :     for( std::size_t i=0; i<maChildren.size(); ++i )
     185             :     {
     186             :         BaseNodeSharedPtr pNode =
     187             :             boost::dynamic_pointer_cast<BaseNode>(maChildren[i]);
     188             :         VERBOSE_TRACE(
     189             :             "Node connection: n0x%X -> n0x%X",
     190             :             (const char*)this+debugGetCurrentOffset(),
     191             :             (const char*)pNode.get()+debugGetCurrentOffset() );
     192             :         pNode->showState();
     193             :     }
     194             : 
     195             :     BaseNode::showState();
     196             : }
     197             : #endif
     198             : 
     199             : } // namespace internal
     200           6 : } // namespace slideshow
     201             : 
     202             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10