LCOV - code coverage report
Current view: top level - slideshow/source/engine/animationnodes - basecontainernode.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 59 1.7 %
Date: 2015-06-13 12:38:46 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             :     return std::any_of(
      98             :                 maChildren.begin(), maChildren.end(),
      99           0 :                 boost::mem_fn(&AnimationNode::hasPendingAnimation) );
     100             : }
     101             : 
     102           0 : void BaseContainerNode::appendChildNode( AnimationNodeSharedPtr const& pNode )
     103             : {
     104           0 :     if (! checkValidNode())
     105           0 :         return;
     106             : 
     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           0 :     if (pNode->registerDeactivatingListener( getSelf() )) {
     111           0 :         maChildren.push_back( pNode );
     112             :     }
     113             : }
     114             : 
     115           0 : bool BaseContainerNode::isChildNode( AnimationNodeSharedPtr const& pNode ) const
     116             : {
     117             :     // find given notifier in child vector
     118           0 :     VectorOfNodes::const_iterator const iEnd( maChildren.end() );
     119             :     VectorOfNodes::const_iterator const iFind(
     120           0 :         std::find( maChildren.begin(), iEnd, pNode ) );
     121           0 :     return (iFind != iEnd);
     122             : }
     123             : 
     124           0 : bool BaseContainerNode::notifyDeactivatedChild(
     125             :     AnimationNodeSharedPtr const& pChildNode )
     126             : {
     127             :     OSL_ASSERT( pChildNode->getState() == FROZEN ||
     128             :                 pChildNode->getState() == ENDED );
     129             :     // early exit on invalid nodes
     130             :     OSL_ASSERT( getState() != INVALID );
     131           0 :     if( getState() == INVALID )
     132           0 :         return false;
     133             : 
     134           0 :     if (! isChildNode(pChildNode)) {
     135             :         OSL_FAIL( "unknown notifier!" );
     136           0 :         return false;
     137             :     }
     138             : 
     139           0 :     std::size_t const nSize = maChildren.size();
     140             :     OSL_ASSERT( mnFinishedChildren < nSize );
     141           0 :     ++mnFinishedChildren;
     142           0 :     bool bFinished = (mnFinishedChildren >= nSize);
     143             : 
     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           0 :     if (bFinished && isDurationIndefinite()) {
     149           0 :         if( mnLeftIterations >= 1.0 )
     150             :         {
     151           0 :             mnLeftIterations -= 1.0;
     152             :         }
     153           0 :         if( mnLeftIterations >= 1.0 )
     154             :         {
     155           0 :             bFinished = false;
     156             :             EventSharedPtr aRepetitionEvent =
     157           0 :                     makeDelay( boost::bind( &BaseContainerNode::repeat, this ),
     158             :                                0.0,
     159             :                                "BaseContainerNode::repeat");
     160           0 :             getContext().mrEventQueue.addEvent( aRepetitionEvent );
     161             :         }
     162             :         else
     163             :         {
     164           0 :             deactivate();
     165             :         }
     166             :     }
     167             : 
     168           0 :     return bFinished;
     169             : }
     170             : 
     171           0 : bool BaseContainerNode::repeat()
     172             : {
     173           0 :     forEachChildNode( boost::mem_fn(&AnimationNode::end), ~ENDED );
     174           0 :     bool bState = init_children();
     175           0 :     if( bState )
     176           0 :         activate_st();
     177           0 :     return bState;
     178             : }
     179             : 
     180             : #if OSL_DEBUG_LEVEL >= 2 && defined(DBG_UTIL)
     181             : void BaseContainerNode::showState() const
     182             : {
     183             :     for( std::size_t i=0; i<maChildren.size(); ++i )
     184             :     {
     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();
     192             :     }
     193             : 
     194             :     BaseNode::showState();
     195             : }
     196             : #endif
     197             : 
     198             : } // namespace internal
     199           3 : } // namespace slideshow
     200             : 
     201             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11