1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: basecontainernode.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_slideshow.hxx"
35 #include <canvas/debug.hxx>
36 #include <canvas/verbosetrace.hxx>
38 #include "basecontainernode.hxx"
40 #include "nodetools.hxx"
41 #include "delayevent.hxx"
43 #include <boost/mem_fn.hpp>
46 using namespace com::sun::star
;
51 BaseContainerNode::BaseContainerNode(
52 const uno::Reference
< animations::XAnimationNode
>& xNode
,
53 const BaseContainerNodeSharedPtr
& rParent
,
54 const NodeContext
& rContext
)
55 : BaseNode( xNode
, rParent
, rContext
),
57 mnFinishedChildren(0),
58 mbDurationIndefinite( isIndefiniteTiming( xNode
->getEnd() ) &&
59 isIndefiniteTiming( xNode
->getDuration() ) )
63 void BaseContainerNode::dispose()
65 forEachChildNode( boost::mem_fn(&Disposable::dispose
) );
70 bool BaseContainerNode::init_st()
72 mnFinishedChildren
= 0;
73 // initialize all children
74 return (std::count_if(
75 maChildren
.begin(), maChildren
.end(),
76 boost::mem_fn(&AnimationNode::init
) ) ==
77 static_cast<VectorOfNodes::difference_type
>(maChildren
.size()));
80 void BaseContainerNode::deactivate_st( NodeState eDestState
)
82 if (eDestState
== FROZEN
) {
83 // deactivate all children that are not FROZEN or ENDED:
84 forEachChildNode( boost::mem_fn(&AnimationNode::deactivate
),
88 // end all children that are not ENDED:
89 forEachChildNode( boost::mem_fn(&AnimationNode::end
), ~ENDED
);
93 bool BaseContainerNode::hasPendingAnimation() const
95 // does any of our children returns "true" on
96 // AnimationNode::hasPendingAnimation()?
97 // If yes, we, too, return true
98 VectorOfNodes::const_iterator
const iEnd( maChildren
.end() );
100 maChildren
.begin(), iEnd
,
101 boost::mem_fn(&AnimationNode::hasPendingAnimation
) ) != iEnd
);
104 void BaseContainerNode::appendChildNode( AnimationNodeSharedPtr
const& pNode
)
106 if (! checkValidNode())
109 // register derived classes as end listeners at all children.
110 // this is necessary to control the children animation
111 // sequence, and to determine our own end event
112 if (pNode
->registerDeactivatingListener( getSelf() )) {
113 maChildren
.push_back( pNode
);
117 bool BaseContainerNode::isChildNode( AnimationNodeSharedPtr
const& pNode
) const
119 // find given notifier in child vector
120 VectorOfNodes::const_iterator
const iBegin( maChildren
.begin() );
121 VectorOfNodes::const_iterator
const iEnd( maChildren
.end() );
122 VectorOfNodes::const_iterator
const iFind(
123 std::find( iBegin
, iEnd
, pNode
) );
124 return (iFind
!= iEnd
);
127 bool BaseContainerNode::notifyDeactivatedChild(
128 AnimationNodeSharedPtr
const& pChildNode
)
130 OSL_ASSERT( pChildNode
->getState() == FROZEN
||
131 pChildNode
->getState() == ENDED
);
132 // early exit on invalid nodes
133 OSL_ASSERT( getState() != INVALID
);
134 if( getState() == INVALID
)
137 if (! isChildNode(pChildNode
)) {
138 OSL_ENSURE( false, "unknown notifier!" );
142 std::size_t const nSize
= maChildren
.size();
143 OSL_ASSERT( mnFinishedChildren
< nSize
);
144 ++mnFinishedChildren
;
145 bool const bFinished
= (mnFinishedChildren
>= nSize
);
147 // all children finished, and we've got indefinite duration?
148 // think of ParallelTimeContainer::notifyDeactivating()
149 // if duration given, we will be deactivated by some end event
150 // @see fillCommonParameters()
151 if (bFinished
&& isDurationIndefinite()) {
158 #if defined(VERBOSE) && defined(DBG_UTIL)
159 void BaseContainerNode::showState() const
161 for( std::size_t i
=0; i
<maChildren
.size(); ++i
)
163 BaseNodeSharedPtr pNode
=
164 boost::shared_dynamic_cast
<BaseNode
>(maChildren
[i
]);
166 "Node connection: n0x%X -> n0x%X",
167 (const char*)this+debugGetCurrentOffset(),
168 (const char*)pNode
.get()+debugGetCurrentOffset() );
172 BaseNode::showState();
176 } // namespace internal
177 } // namespace slideshow