1*70f497fbSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*70f497fbSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*70f497fbSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*70f497fbSAndrew Rist  * distributed with this work for additional information
6*70f497fbSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*70f497fbSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*70f497fbSAndrew Rist  * "License"); you may not use this file except in compliance
9*70f497fbSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*70f497fbSAndrew Rist  *
11*70f497fbSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*70f497fbSAndrew Rist  *
13*70f497fbSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*70f497fbSAndrew Rist  * software distributed under the License is distributed on an
15*70f497fbSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*70f497fbSAndrew Rist  * KIND, either express or implied.  See the License for the
17*70f497fbSAndrew Rist  * specific language governing permissions and limitations
18*70f497fbSAndrew Rist  * under the License.
19*70f497fbSAndrew Rist  *
20*70f497fbSAndrew Rist  *************************************************************/
21*70f497fbSAndrew Rist 
22*70f497fbSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_slideshow.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // must be first
28cdf0e10cSrcweir #include <canvas/debug.hxx>
29cdf0e10cSrcweir #include <canvas/verbosetrace.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "basecontainernode.hxx"
32cdf0e10cSrcweir #include "tools.hxx"
33cdf0e10cSrcweir #include "nodetools.hxx"
34cdf0e10cSrcweir #include "delayevent.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <boost/mem_fn.hpp>
37cdf0e10cSrcweir #include <algorithm>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir using namespace com::sun::star;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace slideshow {
42cdf0e10cSrcweir namespace internal {
43cdf0e10cSrcweir 
44cdf0e10cSrcweir BaseContainerNode::BaseContainerNode(
45cdf0e10cSrcweir     const uno::Reference< animations::XAnimationNode >&     xNode,
46cdf0e10cSrcweir     const BaseContainerNodeSharedPtr&                       rParent,
47cdf0e10cSrcweir     const NodeContext&                                      rContext )
48cdf0e10cSrcweir     : BaseNode( xNode, rParent, rContext ),
49cdf0e10cSrcweir       maChildren(),
50cdf0e10cSrcweir       mnFinishedChildren(0),
51cdf0e10cSrcweir       mbDurationIndefinite( isIndefiniteTiming( xNode->getEnd() ) &&
52cdf0e10cSrcweir                             isIndefiniteTiming( xNode->getDuration() ) )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir void BaseContainerNode::dispose()
57cdf0e10cSrcweir {
58cdf0e10cSrcweir     forEachChildNode( boost::mem_fn(&Disposable::dispose) );
59cdf0e10cSrcweir     maChildren.clear();
60cdf0e10cSrcweir     BaseNode::dispose();
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir bool BaseContainerNode::init_st()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir     mnFinishedChildren = 0;
66cdf0e10cSrcweir     // initialize all children
67cdf0e10cSrcweir     return (std::count_if(
68cdf0e10cSrcweir                 maChildren.begin(), maChildren.end(),
69cdf0e10cSrcweir                 boost::mem_fn(&AnimationNode::init) ) ==
70cdf0e10cSrcweir             static_cast<VectorOfNodes::difference_type>(maChildren.size()));
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir void BaseContainerNode::deactivate_st( NodeState eDestState )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     if (eDestState == FROZEN) {
76cdf0e10cSrcweir         // deactivate all children that are not FROZEN or ENDED:
77cdf0e10cSrcweir         forEachChildNode( boost::mem_fn(&AnimationNode::deactivate),
78cdf0e10cSrcweir                           ~(FROZEN | ENDED) );
79cdf0e10cSrcweir     }
80cdf0e10cSrcweir     else {
81cdf0e10cSrcweir         // end all children that are not ENDED:
82cdf0e10cSrcweir         forEachChildNode( boost::mem_fn(&AnimationNode::end), ~ENDED );
83cdf0e10cSrcweir     }
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir bool BaseContainerNode::hasPendingAnimation() const
87cdf0e10cSrcweir {
88cdf0e10cSrcweir     // does any of our children returns "true" on
89cdf0e10cSrcweir     // AnimationNode::hasPendingAnimation()?
90cdf0e10cSrcweir     // If yes, we, too, return true
91cdf0e10cSrcweir     VectorOfNodes::const_iterator const iEnd( maChildren.end() );
92cdf0e10cSrcweir     return (std::find_if(
93cdf0e10cSrcweir                 maChildren.begin(), iEnd,
94cdf0e10cSrcweir                 boost::mem_fn(&AnimationNode::hasPendingAnimation) ) != iEnd);
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir void BaseContainerNode::appendChildNode( AnimationNodeSharedPtr const& pNode )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir     if (! checkValidNode())
100cdf0e10cSrcweir         return;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     // register derived classes as end listeners at all children.
103cdf0e10cSrcweir     // this is necessary to control the children animation
104cdf0e10cSrcweir     // sequence, and to determine our own end event
105cdf0e10cSrcweir     if (pNode->registerDeactivatingListener( getSelf() )) {
106cdf0e10cSrcweir         maChildren.push_back( pNode );
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir bool BaseContainerNode::isChildNode( AnimationNodeSharedPtr const& pNode ) const
111cdf0e10cSrcweir {
112cdf0e10cSrcweir     // find given notifier in child vector
113cdf0e10cSrcweir     VectorOfNodes::const_iterator const iBegin( maChildren.begin() );
114cdf0e10cSrcweir     VectorOfNodes::const_iterator const iEnd( maChildren.end() );
115cdf0e10cSrcweir     VectorOfNodes::const_iterator const iFind(
116cdf0e10cSrcweir         std::find( iBegin, iEnd, pNode ) );
117cdf0e10cSrcweir     return (iFind != iEnd);
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir bool BaseContainerNode::notifyDeactivatedChild(
121cdf0e10cSrcweir     AnimationNodeSharedPtr const& pChildNode )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir     OSL_ASSERT( pChildNode->getState() == FROZEN ||
124cdf0e10cSrcweir                 pChildNode->getState() == ENDED );
125cdf0e10cSrcweir     // early exit on invalid nodes
126cdf0e10cSrcweir     OSL_ASSERT( getState() != INVALID );
127cdf0e10cSrcweir     if( getState() == INVALID )
128cdf0e10cSrcweir         return false;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     if (! isChildNode(pChildNode)) {
131cdf0e10cSrcweir         OSL_ENSURE( false, "unknown notifier!" );
132cdf0e10cSrcweir         return false;
133cdf0e10cSrcweir     }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir     std::size_t const nSize = maChildren.size();
136cdf0e10cSrcweir     OSL_ASSERT( mnFinishedChildren < nSize );
137cdf0e10cSrcweir     ++mnFinishedChildren;
138cdf0e10cSrcweir     bool const bFinished = (mnFinishedChildren >= nSize);
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     // all children finished, and we've got indefinite duration?
141cdf0e10cSrcweir     // think of ParallelTimeContainer::notifyDeactivating()
142cdf0e10cSrcweir     // if duration given, we will be deactivated by some end event
143cdf0e10cSrcweir     // @see fillCommonParameters()
144cdf0e10cSrcweir     if (bFinished && isDurationIndefinite()) {
145cdf0e10cSrcweir         deactivate();
146cdf0e10cSrcweir     }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     return bFinished;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir #if defined(VERBOSE) && defined(DBG_UTIL)
152cdf0e10cSrcweir void BaseContainerNode::showState() const
153cdf0e10cSrcweir {
154cdf0e10cSrcweir     for( std::size_t i=0; i<maChildren.size(); ++i )
155cdf0e10cSrcweir     {
156cdf0e10cSrcweir         BaseNodeSharedPtr pNode =
157cdf0e10cSrcweir             boost::shared_dynamic_cast<BaseNode>(maChildren[i]);
158cdf0e10cSrcweir         VERBOSE_TRACE(
159cdf0e10cSrcweir             "Node connection: n0x%X -> n0x%X",
160cdf0e10cSrcweir             (const char*)this+debugGetCurrentOffset(),
161cdf0e10cSrcweir             (const char*)pNode.get()+debugGetCurrentOffset() );
162cdf0e10cSrcweir         pNode->showState();
163cdf0e10cSrcweir     }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     BaseNode::showState();
166cdf0e10cSrcweir }
167cdf0e10cSrcweir #endif
168cdf0e10cSrcweir 
169cdf0e10cSrcweir } // namespace internal
170cdf0e10cSrcweir } // namespace slideshow
171cdf0e10cSrcweir 
172