xref: /AOO41X/main/slideshow/source/engine/animationnodes/animationnodefactory.cxx (revision 70f497fb4451dd853e622598505702a3cb5381a8)
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
10cdf0e10cSrcweir  *
11*70f497fbSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
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 <com/sun/star/drawing/XShape.hpp>
32cdf0e10cSrcweir #include <com/sun/star/animations/XAnimate.hpp>
33cdf0e10cSrcweir #include <com/sun/star/animations/AnimationNodeType.hpp>
34cdf0e10cSrcweir #include <com/sun/star/presentation/EffectNodeType.hpp>
35cdf0e10cSrcweir #include <com/sun/star/presentation/TextAnimationType.hpp>
36cdf0e10cSrcweir #include <com/sun/star/animations/XAnimateSet.hpp>
37cdf0e10cSrcweir #include <com/sun/star/animations/XIterateContainer.hpp>
38cdf0e10cSrcweir #include <com/sun/star/presentation/ShapeAnimationSubType.hpp>
39cdf0e10cSrcweir #include <com/sun/star/animations/XAnimateMotion.hpp>
40cdf0e10cSrcweir #include <com/sun/star/animations/XAnimateColor.hpp>
41cdf0e10cSrcweir #include <com/sun/star/animations/XAnimateTransform.hpp>
42cdf0e10cSrcweir #include <com/sun/star/animations/AnimationTransformType.hpp>
43cdf0e10cSrcweir #include <com/sun/star/animations/XTransitionFilter.hpp>
44cdf0e10cSrcweir #include <com/sun/star/animations/XAudio.hpp>
45cdf0e10cSrcweir #include <com/sun/star/presentation/ParagraphTarget.hpp>
46cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
47cdf0e10cSrcweir #include <animations/animationnodehelper.hxx>
48cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #include "animationnodefactory.hxx"
51cdf0e10cSrcweir #include "paralleltimecontainer.hxx"
52cdf0e10cSrcweir #include "sequentialtimecontainer.hxx"
53cdf0e10cSrcweir #include "propertyanimationnode.hxx"
54cdf0e10cSrcweir #include "animationsetnode.hxx"
55cdf0e10cSrcweir #include "animationpathmotionnode.hxx"
56cdf0e10cSrcweir #include "animationcolornode.hxx"
57cdf0e10cSrcweir #include "animationtransformnode.hxx"
58cdf0e10cSrcweir #include "animationtransitionfilternode.hxx"
59cdf0e10cSrcweir #include "animationaudionode.hxx"
60cdf0e10cSrcweir #include "animationcommandnode.hxx"
61cdf0e10cSrcweir #include "nodetools.hxx"
62cdf0e10cSrcweir #include "tools.hxx"
63cdf0e10cSrcweir 
64cdf0e10cSrcweir #include <boost/bind.hpp>
65cdf0e10cSrcweir 
66cdf0e10cSrcweir using namespace ::com::sun::star;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir namespace slideshow {
69cdf0e10cSrcweir namespace internal {
70cdf0e10cSrcweir 
71cdf0e10cSrcweir namespace {
72cdf0e10cSrcweir 
73cdf0e10cSrcweir // forward declaration needed by NodeCreator
74cdf0e10cSrcweir BaseNodeSharedPtr implCreateAnimationNode(
75cdf0e10cSrcweir     const uno::Reference< animations::XAnimationNode >&  xNode,
76cdf0e10cSrcweir     const BaseContainerNodeSharedPtr&                    rParent,
77cdf0e10cSrcweir     const NodeContext&                                   rContext );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir class NodeCreator
80cdf0e10cSrcweir {
81cdf0e10cSrcweir public:
NodeCreator(BaseContainerNodeSharedPtr & rParent,const NodeContext & rContext)82cdf0e10cSrcweir     NodeCreator( BaseContainerNodeSharedPtr&    rParent,
83cdf0e10cSrcweir                  const NodeContext&             rContext )
84cdf0e10cSrcweir         : mrParent( rParent ), mrContext( rContext ) {}
85cdf0e10cSrcweir 
operator ()(const uno::Reference<animations::XAnimationNode> & xChildNode) const86cdf0e10cSrcweir     void operator()(
87cdf0e10cSrcweir         const uno::Reference< animations::XAnimationNode >& xChildNode ) const
88cdf0e10cSrcweir     {
89cdf0e10cSrcweir         createChild( xChildNode, mrContext );
90cdf0e10cSrcweir     }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir protected:
createChild(const uno::Reference<animations::XAnimationNode> & xChildNode,const NodeContext & rContext) const93cdf0e10cSrcweir     void createChild(
94cdf0e10cSrcweir         const uno::Reference< animations::XAnimationNode >&   xChildNode,
95cdf0e10cSrcweir         const NodeContext&                                    rContext ) const
96cdf0e10cSrcweir     {
97cdf0e10cSrcweir         BaseNodeSharedPtr pChild( implCreateAnimationNode( xChildNode,
98cdf0e10cSrcweir                                                            mrParent,
99cdf0e10cSrcweir                                                            rContext ) );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir         OSL_ENSURE( pChild,
102cdf0e10cSrcweir                     "NodeCreator::operator(): child creation failed" );
103cdf0e10cSrcweir 
104cdf0e10cSrcweir         // TODO(Q1): This yields circular references, which, it seems, is
105cdf0e10cSrcweir         // unavoidable here
106cdf0e10cSrcweir         if( pChild )
107cdf0e10cSrcweir             mrParent->appendChildNode( pChild );
108cdf0e10cSrcweir     }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     BaseContainerNodeSharedPtr&     mrParent;
111cdf0e10cSrcweir     const NodeContext&              mrContext;
112cdf0e10cSrcweir };
113cdf0e10cSrcweir 
114cdf0e10cSrcweir /** Same as NodeCreator, only that NodeContext's
115cdf0e10cSrcweir     SubsetShape is cloned for every child node.
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     This is used for iterated animation node generation
118cdf0e10cSrcweir */
119cdf0e10cSrcweir class CloningNodeCreator : private NodeCreator
120cdf0e10cSrcweir {
121cdf0e10cSrcweir public:
CloningNodeCreator(BaseContainerNodeSharedPtr & rParent,const NodeContext & rContext)122cdf0e10cSrcweir     CloningNodeCreator( BaseContainerNodeSharedPtr& rParent,
123cdf0e10cSrcweir                         const NodeContext&          rContext )
124cdf0e10cSrcweir         : NodeCreator( rParent, rContext ) {}
125cdf0e10cSrcweir 
operator ()(const uno::Reference<animations::XAnimationNode> & xChildNode) const126cdf0e10cSrcweir     void operator()(
127cdf0e10cSrcweir         const uno::Reference< animations::XAnimationNode >& xChildNode ) const
128cdf0e10cSrcweir     {
129cdf0e10cSrcweir         NodeContext aContext( mrContext );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         // TODO(Q1): There's a catch here. If you clone a
132cdf0e10cSrcweir         // subset whose actual subsetting has already been
133cdf0e10cSrcweir         // realized (i.e. if enableSubsetShape() has been
134cdf0e10cSrcweir         // called already), and the original of your clone
135cdf0e10cSrcweir         // goes out of scope, then your subset will be
136cdf0e10cSrcweir         // gone (SubsettableShapeManager::revokeSubset() be
137cdf0e10cSrcweir         // called). As of now, this behaviour is not
138cdf0e10cSrcweir         // triggered here (we either clone, XOR we enable
139cdf0e10cSrcweir         // subset initially), but one might consider
140cdf0e10cSrcweir         // reworking DrawShape/ShapeSubset to avoid this.
141cdf0e10cSrcweir 
142cdf0e10cSrcweir         // clone ShapeSubset, since each node needs their
143cdf0e10cSrcweir         // own version of the ShapeSubset (otherwise,
144cdf0e10cSrcweir         // e.g. activity counting does not work - subset
145cdf0e10cSrcweir         // would be removed after first animation node
146cdf0e10cSrcweir         // disables it).
147cdf0e10cSrcweir         //
148cdf0e10cSrcweir         // NOTE: this is only a problem for animation
149cdf0e10cSrcweir         // nodes that explicitely call
150cdf0e10cSrcweir         // disableSubsetShape(). Independent shape subsets
151cdf0e10cSrcweir         // (like those created for ParagraphTargets)
152cdf0e10cSrcweir         // solely rely on the ShapeSubset destructor to
153cdf0e10cSrcweir         // normalize things, which does the right thing
154cdf0e10cSrcweir         // here: the subset is only removed after _the
155cdf0e10cSrcweir         // last_ animation node releases the shared ptr.
156cdf0e10cSrcweir         aContext.mpMasterShapeSubset.reset(
157cdf0e10cSrcweir             new ShapeSubset( *aContext.mpMasterShapeSubset ) );
158cdf0e10cSrcweir 
159cdf0e10cSrcweir         createChild( xChildNode, aContext );
160cdf0e10cSrcweir     }
161cdf0e10cSrcweir };
162cdf0e10cSrcweir 
163cdf0e10cSrcweir /** Create animation nodes for text iterations
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     This method clones the animation nodes below xIterNode
166cdf0e10cSrcweir     for every iterated shape entity.
167cdf0e10cSrcweir */
implCreateIteratedNodes(const uno::Reference<animations::XIterateContainer> & xIterNode,BaseContainerNodeSharedPtr & rParent,const NodeContext & rContext)168cdf0e10cSrcweir bool implCreateIteratedNodes(
169cdf0e10cSrcweir     const uno::Reference< animations::XIterateContainer >&    xIterNode,
170cdf0e10cSrcweir     BaseContainerNodeSharedPtr&                               rParent,
171cdf0e10cSrcweir     const NodeContext&                                        rContext )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir     ENSURE_OR_THROW( xIterNode.is(),
174cdf0e10cSrcweir                       "implCreateIteratedNodes(): Invalid node" );
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     const double nIntervalTimeout( xIterNode->getIterateInterval() );
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     // valid iterate interval? We're ruling out monstrous
179cdf0e10cSrcweir     // values here, to avoid pseudo 'hangs' in the
180cdf0e10cSrcweir     // presentation
181cdf0e10cSrcweir     if( nIntervalTimeout < 0.0 ||
182cdf0e10cSrcweir         nIntervalTimeout > 1000.0 )
183cdf0e10cSrcweir     {
184cdf0e10cSrcweir         return false; // not an active iteration
185cdf0e10cSrcweir     }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     if( ::basegfx::fTools::equalZero( nIntervalTimeout ) )
188cdf0e10cSrcweir         OSL_TRACE( "implCreateIteratedNodes(): "
189cdf0e10cSrcweir                    "iterate interval close to zero, there's "
190cdf0e10cSrcweir                    "no point in defining such an effect "
191cdf0e10cSrcweir                    "(visually equivalent to whole-shape effect)" );
192cdf0e10cSrcweir 
193cdf0e10cSrcweir     // Determine target shape (or subset)
194cdf0e10cSrcweir     // ==================================
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     // TODO(E1): I'm not too sure what to expect here...
197cdf0e10cSrcweir     ENSURE_OR_RETURN_FALSE(
198cdf0e10cSrcweir         xIterNode->getTarget().hasValue(),
199cdf0e10cSrcweir         "implCreateIteratedNodes(): no target on ITERATE node" );
200cdf0e10cSrcweir 
201cdf0e10cSrcweir     uno::Reference< drawing::XShape > xTargetShape( xIterNode->getTarget(),
202cdf0e10cSrcweir                                                     uno::UNO_QUERY );
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     presentation::ParagraphTarget aTarget;
205cdf0e10cSrcweir     sal_Int16                     nSubItem( xIterNode->getSubItem() );
206cdf0e10cSrcweir     bool                          bParagraphTarget( false );
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     if( !xTargetShape.is() )
209cdf0e10cSrcweir     {
210cdf0e10cSrcweir         // no shape provided. Maybe a ParagraphTarget?
211cdf0e10cSrcweir         if( !(xIterNode->getTarget() >>= aTarget) )
212cdf0e10cSrcweir             ENSURE_OR_RETURN_FALSE(
213cdf0e10cSrcweir                 false,
214cdf0e10cSrcweir                 "implCreateIteratedNodes(): could not extract any "
215cdf0e10cSrcweir                 "target information" );
216cdf0e10cSrcweir 
217cdf0e10cSrcweir         xTargetShape = aTarget.Shape;
218cdf0e10cSrcweir 
219cdf0e10cSrcweir         ENSURE_OR_RETURN_FALSE(
220cdf0e10cSrcweir             xTargetShape.is(),
221cdf0e10cSrcweir             "implCreateIteratedNodes(): invalid shape in ParagraphTarget" );
222cdf0e10cSrcweir 
223cdf0e10cSrcweir         // we've a paragraph target to iterate over, thus,
224cdf0e10cSrcweir         // the whole animation container refers only to
225cdf0e10cSrcweir         // the text
226cdf0e10cSrcweir         nSubItem = presentation::ShapeAnimationSubType::ONLY_TEXT;
227cdf0e10cSrcweir 
228cdf0e10cSrcweir         bParagraphTarget = true;
229cdf0e10cSrcweir     }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     // Lookup shape, and fill NodeContext
232cdf0e10cSrcweir     // ==================================
233cdf0e10cSrcweir 
234cdf0e10cSrcweir     AttributableShapeSharedPtr  pTargetShape(
235cdf0e10cSrcweir         lookupAttributableShape( rContext.maContext.mpSubsettableShapeManager,
236cdf0e10cSrcweir                                  xTargetShape ) );
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     const DocTreeNodeSupplier& rTreeNodeSupplier(
239cdf0e10cSrcweir         pTargetShape->getTreeNodeSupplier() );
240cdf0e10cSrcweir 
241cdf0e10cSrcweir     ShapeSubsetSharedPtr pTargetSubset;
242cdf0e10cSrcweir 
243cdf0e10cSrcweir     NodeContext aContext( rContext );
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     // paragraph targets already need a subset as the
246cdf0e10cSrcweir     // master shape (they're representing only a single
247cdf0e10cSrcweir     // paragraph)
248cdf0e10cSrcweir     if( bParagraphTarget )
249cdf0e10cSrcweir     {
250cdf0e10cSrcweir         ENSURE_OR_RETURN_FALSE(
251cdf0e10cSrcweir             aTarget.Paragraph >= 0 &&
252cdf0e10cSrcweir             rTreeNodeSupplier.getNumberOfTreeNodes(
253cdf0e10cSrcweir                 DocTreeNode::NODETYPE_LOGICAL_PARAGRAPH ) > aTarget.Paragraph,
254cdf0e10cSrcweir             "implCreateIteratedNodes(): paragraph index out of range" );
255cdf0e10cSrcweir 
256cdf0e10cSrcweir         pTargetSubset.reset(
257cdf0e10cSrcweir             new ShapeSubset(
258cdf0e10cSrcweir                 pTargetShape,
259cdf0e10cSrcweir                 // retrieve index aTarget.Paragraph of
260cdf0e10cSrcweir                 // type PARAGRAPH from this shape
261cdf0e10cSrcweir                 rTreeNodeSupplier.getTreeNode(
262cdf0e10cSrcweir                     aTarget.Paragraph,
263cdf0e10cSrcweir                     DocTreeNode::NODETYPE_LOGICAL_PARAGRAPH ),
264cdf0e10cSrcweir                 rContext.maContext.mpSubsettableShapeManager ) );
265cdf0e10cSrcweir 
266cdf0e10cSrcweir         // iterate target is not the whole shape, but only
267cdf0e10cSrcweir         // the selected paragraph - subset _must_ be
268cdf0e10cSrcweir         // independent, to be able to affect visibility
269cdf0e10cSrcweir         // independent of master shape
270cdf0e10cSrcweir         aContext.mbIsIndependentSubset = true;
271cdf0e10cSrcweir 
272cdf0e10cSrcweir         // already enable parent subset right here, to
273cdf0e10cSrcweir         // make potentially generated subsets subtract
274cdf0e10cSrcweir         // their content from the parent subset (and not
275cdf0e10cSrcweir         // the original shape). Otherwise, already
276cdf0e10cSrcweir         // subsetted parents (e.g. paragraphs) would not
277cdf0e10cSrcweir         // have their characters removed, when the child
278cdf0e10cSrcweir         // iterations start.
279cdf0e10cSrcweir         // Furthermore, the setup of initial shape
280cdf0e10cSrcweir         // attributes of course needs the subset shape
281cdf0e10cSrcweir         // generated, to apply e.g. visibility changes.
282cdf0e10cSrcweir         pTargetSubset->enableSubsetShape();
283cdf0e10cSrcweir     }
284cdf0e10cSrcweir     else
285cdf0e10cSrcweir     {
286cdf0e10cSrcweir         pTargetSubset.reset(
287cdf0e10cSrcweir             new ShapeSubset( pTargetShape,
288cdf0e10cSrcweir                              rContext.maContext.mpSubsettableShapeManager ));
289cdf0e10cSrcweir     }
290cdf0e10cSrcweir 
291cdf0e10cSrcweir     aContext.mpMasterShapeSubset = pTargetSubset;
292cdf0e10cSrcweir     uno::Reference< animations::XAnimationNode > xNode( xIterNode,
293cdf0e10cSrcweir                                                         uno::UNO_QUERY_THROW );
294cdf0e10cSrcweir 
295cdf0e10cSrcweir     // Generate subsets
296cdf0e10cSrcweir     // ================
297cdf0e10cSrcweir 
298cdf0e10cSrcweir     if( bParagraphTarget ||
299cdf0e10cSrcweir         nSubItem != presentation::ShapeAnimationSubType::ONLY_TEXT )
300cdf0e10cSrcweir     {
301cdf0e10cSrcweir         // prepend with animations for
302cdf0e10cSrcweir         // full Shape (will be subtracted
303cdf0e10cSrcweir         // from the subset parts within
304cdf0e10cSrcweir         // the Shape::createSubset()
305cdf0e10cSrcweir         // method). For ONLY_TEXT effects,
306cdf0e10cSrcweir         // we skip this part, to animate
307cdf0e10cSrcweir         // only the text.
308cdf0e10cSrcweir         //
309cdf0e10cSrcweir         // OR
310cdf0e10cSrcweir         //
311cdf0e10cSrcweir         // prepend with subset animation for full
312cdf0e10cSrcweir         // _paragraph_, from which the individual
313cdf0e10cSrcweir         // paragraph subsets are subtracted. Note that the
314cdf0e10cSrcweir         // subitem is superfluous here, we always assume
315cdf0e10cSrcweir         // ONLY_TEXT, if a paragraph is referenced as the
316cdf0e10cSrcweir         // master of an iteration effect.
317cdf0e10cSrcweir         NodeCreator aCreator( rParent, aContext );
318cdf0e10cSrcweir         if( !::anim::for_each_childNode( xNode,
319cdf0e10cSrcweir                                          aCreator ) )
320cdf0e10cSrcweir         {
321cdf0e10cSrcweir             ENSURE_OR_RETURN_FALSE(
322cdf0e10cSrcweir                 false,
323cdf0e10cSrcweir                 "implCreateIteratedNodes(): iterated child node creation failed" );
324cdf0e10cSrcweir         }
325cdf0e10cSrcweir     }
326cdf0e10cSrcweir 
327cdf0e10cSrcweir     // TODO(F2): This does not do the correct
328cdf0e10cSrcweir     // thing. Having nSubItem be set to ONLY_BACKGROUND
329cdf0e10cSrcweir     // should result in the text staying unanimated in the
330cdf0e10cSrcweir     // foreground, while the shape moves in the background
331cdf0e10cSrcweir     // (this behaviour is perfectly possible with the
332cdf0e10cSrcweir     // slideshow engine, only that the text won't be
333cdf0e10cSrcweir     // currently visible, because animations are always in
334cdf0e10cSrcweir     // the foreground)
335cdf0e10cSrcweir     if( nSubItem != presentation::ShapeAnimationSubType::ONLY_BACKGROUND )
336cdf0e10cSrcweir     {
337cdf0e10cSrcweir         // determine type of subitem iteration (logical
338cdf0e10cSrcweir         // text unit to animate)
339cdf0e10cSrcweir         DocTreeNode::NodeType eIterateNodeType(
340cdf0e10cSrcweir             DocTreeNode::NODETYPE_LOGICAL_CHARACTER_CELL );
341cdf0e10cSrcweir 
342cdf0e10cSrcweir         switch( xIterNode->getIterateType() )
343cdf0e10cSrcweir         {
344cdf0e10cSrcweir         case presentation::TextAnimationType::BY_PARAGRAPH:
345cdf0e10cSrcweir             eIterateNodeType = DocTreeNode::NODETYPE_LOGICAL_PARAGRAPH;
346cdf0e10cSrcweir             break;
347cdf0e10cSrcweir 
348cdf0e10cSrcweir         case presentation::TextAnimationType::BY_WORD:
349cdf0e10cSrcweir             eIterateNodeType = DocTreeNode::NODETYPE_LOGICAL_WORD;
350cdf0e10cSrcweir             break;
351cdf0e10cSrcweir 
352cdf0e10cSrcweir         case presentation::TextAnimationType::BY_LETTER:
353cdf0e10cSrcweir             eIterateNodeType = DocTreeNode::NODETYPE_LOGICAL_CHARACTER_CELL;
354cdf0e10cSrcweir             break;
355cdf0e10cSrcweir 
356cdf0e10cSrcweir         default:
357cdf0e10cSrcweir             ENSURE_OR_THROW(
358cdf0e10cSrcweir                 false, "implCreateIteratedNodes(): "
359cdf0e10cSrcweir                 "Unexpected IterateType on XIterateContainer");
360cdf0e10cSrcweir             break;
361cdf0e10cSrcweir         }
362cdf0e10cSrcweir 
363cdf0e10cSrcweir         if( bParagraphTarget &&
364cdf0e10cSrcweir             eIterateNodeType != DocTreeNode::NODETYPE_LOGICAL_WORD &&
365cdf0e10cSrcweir             eIterateNodeType != DocTreeNode::NODETYPE_LOGICAL_CHARACTER_CELL )
366cdf0e10cSrcweir         {
367cdf0e10cSrcweir             // will not animate the whole paragraph, when
368cdf0e10cSrcweir             // only the paragraph is animated at all.
369cdf0e10cSrcweir             OSL_ENSURE( false,
370cdf0e10cSrcweir                         "implCreateIteratedNodes(): Ignoring paragraph iteration for paragraph master" );
371cdf0e10cSrcweir         }
372cdf0e10cSrcweir         else
373cdf0e10cSrcweir         {
374cdf0e10cSrcweir             // setup iteration parameters
375cdf0e10cSrcweir             // --------------------------
376cdf0e10cSrcweir 
377cdf0e10cSrcweir             // iterate target is the whole shape (or the
378cdf0e10cSrcweir             // whole parent subshape), thus, can save
379cdf0e10cSrcweir             // loads of subset shapes by generating them
380cdf0e10cSrcweir             // only when the effects become active -
381cdf0e10cSrcweir             // before and after the effect active
382cdf0e10cSrcweir             // duration, all attributes are shared by
383cdf0e10cSrcweir             // master shape and subset (since the iterated
384cdf0e10cSrcweir             // effects are all the same).
385cdf0e10cSrcweir             aContext.mbIsIndependentSubset = false;
386cdf0e10cSrcweir 
387cdf0e10cSrcweir             // determine number of nodes for given subitem
388cdf0e10cSrcweir             // type
389cdf0e10cSrcweir             sal_Int32 nTreeNodes( 0 );
390cdf0e10cSrcweir             if( bParagraphTarget )
391cdf0e10cSrcweir             {
392cdf0e10cSrcweir                 // create the iterated subset _relative_ to
393cdf0e10cSrcweir                 // the given paragraph index (i.e. animate the
394cdf0e10cSrcweir                 // given subset type, but only when it's part
395cdf0e10cSrcweir                 // of the given paragraph)
396cdf0e10cSrcweir                 nTreeNodes = rTreeNodeSupplier.getNumberOfSubsetTreeNodes(
397cdf0e10cSrcweir                     pTargetSubset->getSubset(),
398cdf0e10cSrcweir                     eIterateNodeType );
399cdf0e10cSrcweir             }
400cdf0e10cSrcweir             else
401cdf0e10cSrcweir             {
402cdf0e10cSrcweir                 // generate normal subset
403cdf0e10cSrcweir                 nTreeNodes = rTreeNodeSupplier.getNumberOfTreeNodes(
404cdf0e10cSrcweir                     eIterateNodeType );
405cdf0e10cSrcweir             }
406cdf0e10cSrcweir 
407cdf0e10cSrcweir 
408cdf0e10cSrcweir             // iterate node, generate copies of the children for each subset
409cdf0e10cSrcweir             // -------------------------------------------------------------
410cdf0e10cSrcweir 
411cdf0e10cSrcweir             // NodeContext::mnStartDelay contains additional node delay.
412cdf0e10cSrcweir             // This will make the duplicated nodes for each iteration start
413cdf0e10cSrcweir             // increasingly later.
414cdf0e10cSrcweir             aContext.mnStartDelay = nIntervalTimeout;
415cdf0e10cSrcweir 
416cdf0e10cSrcweir             for( sal_Int32 i=0; i<nTreeNodes; ++i )
417cdf0e10cSrcweir             {
418cdf0e10cSrcweir                 // create subset with the corresponding tree nodes
419cdf0e10cSrcweir                 if( bParagraphTarget )
420cdf0e10cSrcweir                 {
421cdf0e10cSrcweir                     // create subsets relative to paragraph subset
422cdf0e10cSrcweir                     aContext.mpMasterShapeSubset.reset(
423cdf0e10cSrcweir                         new ShapeSubset(
424cdf0e10cSrcweir                             pTargetSubset,
425cdf0e10cSrcweir                             rTreeNodeSupplier.getSubsetTreeNode(
426cdf0e10cSrcweir                                 pTargetSubset->getSubset(),
427cdf0e10cSrcweir                                 i,
428cdf0e10cSrcweir                                 eIterateNodeType ) ) );
429cdf0e10cSrcweir                 }
430cdf0e10cSrcweir                 else
431cdf0e10cSrcweir                 {
432cdf0e10cSrcweir                     // create subsets from main shape
433cdf0e10cSrcweir                     aContext.mpMasterShapeSubset.reset(
434cdf0e10cSrcweir                         new ShapeSubset( pTargetSubset,
435cdf0e10cSrcweir                                          rTreeNodeSupplier.getTreeNode(
436cdf0e10cSrcweir                                              i,
437cdf0e10cSrcweir                                              eIterateNodeType ) ) );
438cdf0e10cSrcweir                 }
439cdf0e10cSrcweir 
440cdf0e10cSrcweir                 CloningNodeCreator aCreator( rParent, aContext );
441cdf0e10cSrcweir                 if( !::anim::for_each_childNode( xNode,
442cdf0e10cSrcweir                                                  aCreator ) )
443cdf0e10cSrcweir                 {
444cdf0e10cSrcweir                     ENSURE_OR_RETURN_FALSE(
445cdf0e10cSrcweir                         false, "implCreateIteratedNodes(): "
446cdf0e10cSrcweir                         "iterated child node creation failed" );
447cdf0e10cSrcweir                 }
448cdf0e10cSrcweir 
449cdf0e10cSrcweir                 aContext.mnStartDelay += nIntervalTimeout;
450cdf0e10cSrcweir             }
451cdf0e10cSrcweir         }
452cdf0e10cSrcweir     }
453cdf0e10cSrcweir 
454cdf0e10cSrcweir     // done with iterate child generation
455cdf0e10cSrcweir     return true;
456cdf0e10cSrcweir }
457cdf0e10cSrcweir 
implCreateAnimationNode(const uno::Reference<animations::XAnimationNode> & xNode,const BaseContainerNodeSharedPtr & rParent,const NodeContext & rContext)458cdf0e10cSrcweir BaseNodeSharedPtr implCreateAnimationNode(
459cdf0e10cSrcweir     const uno::Reference< animations::XAnimationNode >&  xNode,
460cdf0e10cSrcweir     const BaseContainerNodeSharedPtr&                    rParent,
461cdf0e10cSrcweir     const NodeContext&                                   rContext )
462cdf0e10cSrcweir {
463cdf0e10cSrcweir     ENSURE_OR_THROW( xNode.is(),
464cdf0e10cSrcweir                       "implCreateAnimationNode(): invalid XAnimationNode" );
465cdf0e10cSrcweir 
466cdf0e10cSrcweir     BaseNodeSharedPtr           pCreatedNode;
467cdf0e10cSrcweir     BaseContainerNodeSharedPtr  pCreatedContainer;
468cdf0e10cSrcweir 
469cdf0e10cSrcweir     // create the internal node, corresponding to xNode
470cdf0e10cSrcweir     switch( xNode->getType() )
471cdf0e10cSrcweir     {
472cdf0e10cSrcweir     case animations::AnimationNodeType::CUSTOM:
473cdf0e10cSrcweir         OSL_ENSURE( false, "implCreateAnimationNode(): "
474cdf0e10cSrcweir                     "CUSTOM not yet implemented" );
475cdf0e10cSrcweir         return pCreatedNode;
476cdf0e10cSrcweir 
477cdf0e10cSrcweir     case animations::AnimationNodeType::PAR:
478cdf0e10cSrcweir         pCreatedNode = pCreatedContainer = BaseContainerNodeSharedPtr(
479cdf0e10cSrcweir             new ParallelTimeContainer( xNode, rParent, rContext ) );
480cdf0e10cSrcweir         break;
481cdf0e10cSrcweir 
482cdf0e10cSrcweir     case animations::AnimationNodeType::ITERATE:
483cdf0e10cSrcweir         // map iterate container to ParallelTimeContainer.
484cdf0e10cSrcweir         // the iterating functionality is to be found
485cdf0e10cSrcweir         // below, (see method implCreateIteratedNodes)
486cdf0e10cSrcweir         pCreatedNode = pCreatedContainer = BaseContainerNodeSharedPtr(
487cdf0e10cSrcweir             new ParallelTimeContainer( xNode, rParent, rContext ) );
488cdf0e10cSrcweir         break;
489cdf0e10cSrcweir 
490cdf0e10cSrcweir     case animations::AnimationNodeType::SEQ:
491cdf0e10cSrcweir         pCreatedNode = pCreatedContainer = BaseContainerNodeSharedPtr(
492cdf0e10cSrcweir             new SequentialTimeContainer( xNode, rParent, rContext ) );
493cdf0e10cSrcweir         break;
494cdf0e10cSrcweir 
495cdf0e10cSrcweir     case animations::AnimationNodeType::ANIMATE:
496cdf0e10cSrcweir         pCreatedNode.reset( new PropertyAnimationNode(
497cdf0e10cSrcweir                                 xNode, rParent, rContext ) );
498cdf0e10cSrcweir         break;
499cdf0e10cSrcweir 
500cdf0e10cSrcweir     case animations::AnimationNodeType::SET:
501cdf0e10cSrcweir         pCreatedNode.reset( new AnimationSetNode(
502cdf0e10cSrcweir                                 xNode, rParent, rContext ) );
503cdf0e10cSrcweir         break;
504cdf0e10cSrcweir 
505cdf0e10cSrcweir     case animations::AnimationNodeType::ANIMATEMOTION:
506cdf0e10cSrcweir         pCreatedNode.reset( new AnimationPathMotionNode(
507cdf0e10cSrcweir                                 xNode, rParent, rContext ) );
508cdf0e10cSrcweir         break;
509cdf0e10cSrcweir 
510cdf0e10cSrcweir     case animations::AnimationNodeType::ANIMATECOLOR:
511cdf0e10cSrcweir         pCreatedNode.reset( new AnimationColorNode(
512cdf0e10cSrcweir                                 xNode, rParent, rContext ) );
513cdf0e10cSrcweir         break;
514cdf0e10cSrcweir 
515cdf0e10cSrcweir     case animations::AnimationNodeType::ANIMATETRANSFORM:
516cdf0e10cSrcweir         pCreatedNode.reset( new AnimationTransformNode(
517cdf0e10cSrcweir                                 xNode, rParent, rContext ) );
518cdf0e10cSrcweir         break;
519cdf0e10cSrcweir 
520cdf0e10cSrcweir     case animations::AnimationNodeType::TRANSITIONFILTER:
521cdf0e10cSrcweir         pCreatedNode.reset( new AnimationTransitionFilterNode(
522cdf0e10cSrcweir                                 xNode, rParent, rContext ) );
523cdf0e10cSrcweir         break;
524cdf0e10cSrcweir 
525cdf0e10cSrcweir     case animations::AnimationNodeType::AUDIO:
526cdf0e10cSrcweir         pCreatedNode.reset( new AnimationAudioNode(
527cdf0e10cSrcweir                                 xNode, rParent, rContext ) );
528cdf0e10cSrcweir         break;
529cdf0e10cSrcweir 
530cdf0e10cSrcweir     case animations::AnimationNodeType::COMMAND:
531cdf0e10cSrcweir         pCreatedNode.reset( new AnimationCommandNode(
532cdf0e10cSrcweir                                 xNode, rParent, rContext ) );
533cdf0e10cSrcweir         break;
534cdf0e10cSrcweir 
535cdf0e10cSrcweir     default:
536cdf0e10cSrcweir         OSL_ENSURE( false, "implCreateAnimationNode(): "
537cdf0e10cSrcweir                     "invalid AnimationNodeType" );
538cdf0e10cSrcweir         return pCreatedNode;
539cdf0e10cSrcweir     }
540cdf0e10cSrcweir 
541cdf0e10cSrcweir     // TODO(Q1): This yields circular references, which, it seems, is
542cdf0e10cSrcweir     // unavoidable here
543cdf0e10cSrcweir 
544cdf0e10cSrcweir     // HACK: node objects need shared_ptr to themselves,
545cdf0e10cSrcweir     // which we pass them here.
546cdf0e10cSrcweir     pCreatedNode->setSelf( pCreatedNode );
547cdf0e10cSrcweir 
548cdf0e10cSrcweir     // if we've got a container node object, recursively add
549cdf0e10cSrcweir     // its children
550cdf0e10cSrcweir     if( pCreatedContainer )
551cdf0e10cSrcweir     {
552cdf0e10cSrcweir         uno::Reference< animations::XIterateContainer > xIterNode(
553cdf0e10cSrcweir             xNode, uno::UNO_QUERY );
554cdf0e10cSrcweir 
555cdf0e10cSrcweir         // when this node is an XIterateContainer with
556cdf0e10cSrcweir         // active iterations, this method will generate
557cdf0e10cSrcweir         // the appropriate children
558cdf0e10cSrcweir         if( xIterNode.is() )
559cdf0e10cSrcweir         {
560cdf0e10cSrcweir             // note that implCreateIteratedNodes() might
561cdf0e10cSrcweir             // choose not to generate any child nodes
562cdf0e10cSrcweir             // (e.g. when the iterate timeout is outside
563cdf0e10cSrcweir             // sensible limits). Then, no child nodes are
564cdf0e10cSrcweir             // generated at all, since typically, child
565cdf0e10cSrcweir             // node attribute are incomplete for iteration
566cdf0e10cSrcweir             // children.
567cdf0e10cSrcweir             implCreateIteratedNodes( xIterNode,
568cdf0e10cSrcweir                                      pCreatedContainer,
569cdf0e10cSrcweir                                      rContext );
570cdf0e10cSrcweir         }
571cdf0e10cSrcweir         else
572cdf0e10cSrcweir         {
573cdf0e10cSrcweir             // no iterate subset node, just plain child generation now
574cdf0e10cSrcweir             NodeCreator aCreator( pCreatedContainer, rContext );
575cdf0e10cSrcweir             if( !::anim::for_each_childNode( xNode, aCreator ) )
576cdf0e10cSrcweir             {
577cdf0e10cSrcweir                 OSL_ENSURE( false, "implCreateAnimationNode(): "
578cdf0e10cSrcweir                             "child node creation failed" );
579cdf0e10cSrcweir                 return BaseNodeSharedPtr();
580cdf0e10cSrcweir             }
581cdf0e10cSrcweir         }
582cdf0e10cSrcweir     }
583cdf0e10cSrcweir 
584cdf0e10cSrcweir     return pCreatedNode;
585cdf0e10cSrcweir }
586cdf0e10cSrcweir 
587cdf0e10cSrcweir } // anon namespace
588cdf0e10cSrcweir 
createAnimationNode(const uno::Reference<animations::XAnimationNode> & xNode,const::basegfx::B2DVector & rSlideSize,const SlideShowContext & rContext)589cdf0e10cSrcweir AnimationNodeSharedPtr AnimationNodeFactory::createAnimationNode(
590cdf0e10cSrcweir     const uno::Reference< animations::XAnimationNode >&   xNode,
591cdf0e10cSrcweir     const ::basegfx::B2DVector&                           rSlideSize,
592cdf0e10cSrcweir     const SlideShowContext&                               rContext )
593cdf0e10cSrcweir {
594cdf0e10cSrcweir     ENSURE_OR_THROW(
595cdf0e10cSrcweir         xNode.is(),
596cdf0e10cSrcweir         "AnimationNodeFactory::createAnimationNode(): invalid XAnimationNode" );
597cdf0e10cSrcweir 
598cdf0e10cSrcweir     return BaseNodeSharedPtr( implCreateAnimationNode(
599cdf0e10cSrcweir                                   xNode,
600cdf0e10cSrcweir                                   BaseContainerNodeSharedPtr(), // no parent
601cdf0e10cSrcweir                                   NodeContext( rContext,
602cdf0e10cSrcweir                                                rSlideSize )));
603cdf0e10cSrcweir }
604cdf0e10cSrcweir 
605cdf0e10cSrcweir #if defined(VERBOSE) && defined(DBG_UTIL)
showTree(AnimationNodeSharedPtr & pRootNode)606cdf0e10cSrcweir void AnimationNodeFactory::showTree( AnimationNodeSharedPtr& pRootNode )
607cdf0e10cSrcweir {
608cdf0e10cSrcweir     if( pRootNode )
609cdf0e10cSrcweir         DEBUG_NODES_SHOWTREE( boost::dynamic_pointer_cast<BaseContainerNode>(
610cdf0e10cSrcweir                                   pRootNode).get() );
611cdf0e10cSrcweir }
612cdf0e10cSrcweir #endif
613cdf0e10cSrcweir 
614cdf0e10cSrcweir } // namespace internal
615cdf0e10cSrcweir } // namespace slideshow
616cdf0e10cSrcweir 
617