LCOV - code coverage report
Current view: top level - libreoffice/slideshow/source/engine/animationnodes - basecontainernode.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 60 0.0 %
Date: 2012-12-27 Functions: 0 12 0.0 %
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           0 :       mbDurationIndefinite( isIndefiniteTiming( xNode->getEnd() ) &&
      48           0 :                             isIndefiniteTiming( xNode->getDuration() ) )
      49             : {
      50           0 : }
      51             : 
      52           0 : void BaseContainerNode::dispose()
      53             : {
      54           0 :     forEachChildNode( boost::mem_fn(&Disposable::dispose) );
      55           0 :     maChildren.clear();
      56           0 :     BaseNode::dispose();
      57           0 : }
      58             : 
      59           0 : bool BaseContainerNode::init_st()
      60             : {
      61           0 :    if( !(getXAnimationNode()->getRepeatCount() >>= mnLeftIterations) )
      62           0 :         mnLeftIterations = 1.0;
      63           0 :    return init_children();
      64             : }
      65             : 
      66           0 : bool BaseContainerNode::init_children()
      67             : {
      68           0 :     mnFinishedChildren = 0;
      69             : 
      70             :     // initialize all children
      71             :     return (std::count_if(
      72             :                 maChildren.begin(), maChildren.end(),
      73           0 :                 boost::mem_fn(&AnimationNode::init) ) ==
      74           0 :             static_cast<VectorOfNodes::difference_type>(maChildren.size()));
      75             : }
      76             : 
      77           0 : void BaseContainerNode::deactivate_st( NodeState eDestState )
      78             : {
      79           0 :     mnLeftIterations = 0; // in order to make skip effect work correctly
      80           0 :     if (eDestState == FROZEN) {
      81             :         // deactivate all children that are not FROZEN or ENDED:
      82           0 :         forEachChildNode( boost::mem_fn(&AnimationNode::deactivate),
      83           0 :                           ~(FROZEN | ENDED) );
      84             :     }
      85             :     else {
      86             :         // end all children that are not ENDED:
      87           0 :         forEachChildNode( boost::mem_fn(&AnimationNode::end), ~ENDED );
      88             :     }
      89           0 : }
      90             : 
      91           0 : bool BaseContainerNode::hasPendingAnimation() const
      92             : {
      93             :     // does any of our children returns "true" on
      94             :     // AnimationNode::hasPendingAnimation()?
      95             :     // If yes, we, too, return true
      96           0 :     VectorOfNodes::const_iterator const iEnd( maChildren.end() );
      97             :     return (std::find_if(
      98             :                 maChildren.begin(), iEnd,
      99           0 :                 boost::mem_fn(&AnimationNode::hasPendingAnimation) ) != iEnd);
     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 :     sal_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::shared_dynamic_cast<BaseNode>(maChildren[i]);
     187             :         VERBOSE_TRACE(
     188             :             "Node connection: n0x%X -> n0x%X",
     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           0 : } // namespace slideshow
     200             : 
     201             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10