1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <basecontainernode.hxx>
22 #include <com/sun/star/animations/AnimationRestart.hpp>
23 #include <com/sun/star/animations/AnimationFill.hpp>
24 #include <eventqueue.hxx>
25 #include "nodetools.hxx"
26 #include <delayevent.hxx>
27 #include <sal/log.hxx>
32 using namespace com::sun::star
;
34 namespace slideshow::internal
{
36 bool isRepeatIndefinite(const uno::Reference
<animations::XAnimationNode
>& xNode
)
38 return xNode
->getRepeatCount().hasValue() && isIndefiniteTiming(xNode
->getRepeatCount());
41 bool isRestart(const uno::Reference
<animations::XAnimationNode
>& xNode
)
43 sal_Int16 nRestart
= xNode
->getRestart();
44 return nRestart
== animations::AnimationRestart::WHEN_NOT_ACTIVE
||
45 nRestart
== animations::AnimationRestart::ALWAYS
;
49 BaseContainerNode::BaseContainerNode(
50 const uno::Reference
< animations::XAnimationNode
>& xNode
,
51 const BaseContainerNodeSharedPtr
& rParent
,
52 const NodeContext
& rContext
)
53 : BaseNode( xNode
, rParent
, rContext
),
55 mnFinishedChildren(0),
57 mbRepeatIndefinite(isRepeatIndefinite(xNode
)),
58 mbRestart(isRestart(xNode
)),
59 mbDurationIndefinite( isIndefiniteTiming( xNode
->getEnd() ) &&
60 isIndefiniteTiming( xNode
->getDuration() ) )
64 void BaseContainerNode::dispose()
66 forEachChildNode( std::mem_fn(&Disposable::dispose
), -1 );
71 bool BaseContainerNode::init_st()
73 if( !(getXAnimationNode()->getRepeatCount() >>= mnLeftIterations
) )
74 mnLeftIterations
= 1.0;
75 return init_children();
78 bool BaseContainerNode::init_children()
80 mnFinishedChildren
= 0;
82 // initialize all children
83 return (std::count_if(
84 maChildren
.begin(), maChildren
.end(),
85 std::mem_fn(&AnimationNode::init
) ) ==
86 static_cast<VectorOfNodes::difference_type
>(maChildren
.size()));
89 void BaseContainerNode::deactivate_st( NodeState eDestState
)
91 mnLeftIterations
= 0; // in order to make skip effect work correctly
92 if (eDestState
== FROZEN
) {
93 // deactivate all children that are not FROZEN or ENDED:
94 forEachChildNode( std::mem_fn(&AnimationNode::deactivate
),
98 // end all children that are not ENDED:
99 forEachChildNode( std::mem_fn(&AnimationNode::end
), ~ENDED
);
103 bool BaseContainerNode::hasPendingAnimation() const
105 // does any of our children returns "true" on
106 // AnimationNode::hasPendingAnimation()?
107 // If yes, we, too, return true
109 maChildren
.begin(), maChildren
.end(),
110 std::mem_fn(&AnimationNode::hasPendingAnimation
) );
113 void BaseContainerNode::appendChildNode( AnimationNodeSharedPtr
const& pNode
)
115 if (! checkValidNode())
118 // register derived classes as end listeners at all children.
119 // this is necessary to control the children animation
120 // sequence, and to determine our own end event
121 if (pNode
->registerDeactivatingListener( getSelf() )) {
122 maChildren
.push_back( pNode
);
126 bool BaseContainerNode::isChildNode( AnimationNodeSharedPtr
const& pNode
) const
128 // find given notifier in child vector
129 VectorOfNodes::const_iterator
const iEnd( maChildren
.end() );
130 VectorOfNodes::const_iterator
const iFind(
131 std::find( maChildren
.begin(), iEnd
, pNode
) );
132 return (iFind
!= iEnd
);
135 bool BaseContainerNode::notifyDeactivatedChild(
136 AnimationNodeSharedPtr
const& pChildNode
)
138 OSL_ASSERT( pChildNode
->getState() == FROZEN
||
139 pChildNode
->getState() == ENDED
);
140 // early exit on invalid nodes
141 OSL_ASSERT( getState() != INVALID
);
142 if( getState() == INVALID
)
145 if (! isChildNode(pChildNode
)) {
146 OSL_FAIL( "unknown notifier!" );
150 std::size_t const nSize
= maChildren
.size();
151 OSL_ASSERT( mnFinishedChildren
< nSize
);
152 ++mnFinishedChildren
;
153 bool bFinished
= (mnFinishedChildren
>= nSize
);
155 // Handle repetition here.
157 if(!mbRepeatIndefinite
&& mnLeftIterations
>= 1.0)
159 mnLeftIterations
-= 1.0;
161 if(mnLeftIterations
>= 1.0 || mbRestart
)
163 // SMIL spec said that "Accumulate" controls whether or not the animation
164 // is cumulative, but XTimeContainer do not have this attribute, so always
165 // remove the effect before next repeat.
166 forEachChildNode(std::mem_fn(&AnimationNode::removeEffect
), -1);
168 if (mnLeftIterations
>= 1.0)
171 EventSharedPtr aRepetitionEvent
=
172 makeDelay( [this] () { this->repeat(); },
174 "BaseContainerNode::repeat");
175 getContext().mrEventQueue
.addEvent( aRepetitionEvent
);
177 else if (isDurationIndefinite())
179 if (getFillMode() == animations::AnimationFill::REMOVE
)
180 forEachChildNode(std::mem_fn(&AnimationNode::removeEffect
), -1);
188 void BaseContainerNode::repeat()
190 // Prevent repeat event scheduled before deactivation.
191 if (getState() == FROZEN
|| getState() == ENDED
)
194 forEachChildNode( std::mem_fn(&AnimationNode::end
), ~ENDED
);
195 bool bState
= init_children();
200 #if defined(DBG_UTIL)
201 void BaseContainerNode::showState() const
203 for(const auto & i
: maChildren
)
205 BaseNodeSharedPtr pNode
=
206 std::dynamic_pointer_cast
<BaseNode
>(i
);
207 SAL_INFO("slideshow.verbose",
208 "Node connection: n" <<
209 debugGetNodeName(this) <<
211 debugGetNodeName(pNode
.get()));
215 BaseNode::showState();
219 } // namespace slideshow::internal
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */