LibreOffice Module slideshow (master) 1
animationcommandnode.cxx
Go to the documentation of this file.
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#include <com/sun/star/presentation/EffectCommands.hpp>
22#include <com/sun/star/presentation/EffectNodeType.hpp>
23#include <com/sun/star/animations/AnimationNodeType.hpp>
24#include <com/sun/star/animations/XAudio.hpp>
25#include <com/sun/star/animations/Timing.hpp>
26#include <com/sun/star/beans/PropertyValue.hpp>
27
29
31#include <eventmultiplexer.hxx>
32#include <delayevent.hxx>
33
34
35using namespace com::sun::star;
36
37namespace
38{
40bool IsTimingRootNode(const uno::Reference<animations::XAnimationNode>& xNode)
41{
42 uno::Sequence<beans::NamedValue> aUserData = xNode->getUserData();
44 auto it = aMap.find("node-type");
45 if (it == aMap.end())
46 {
47 return false;
48 }
49
50 sal_Int16 nNodeType{};
51 if (!(it->second >>= nNodeType))
52 {
53 return false;
54 }
55
56 return nNodeType == css::presentation::EffectNodeType::TIMING_ROOT;
57}
58
60uno::Reference<animations::XAnimationNode>
61GetTimingRoot(const uno::Reference<animations::XAnimationNode>& xNode)
62{
63 uno::Reference<animations::XAnimationNode> xParent(xNode->getParent(), uno::UNO_QUERY);
64 while (true)
65 {
66 if (!xParent.is())
67 {
68 break;
69 }
70
71 if (IsTimingRootNode(xParent))
72 {
73 return xParent;
74 }
75
76 xParent.set(xParent->getParent(), uno::UNO_QUERY);
77 }
78
79 return {};
80}
81}
82
83namespace slideshow::internal {
84
85namespace EffectCommands = css::presentation::EffectCommands;
86
88 ::std::shared_ptr<BaseContainerNode> const& pParent,
89 NodeContext const& rContext ) :
90 BaseNode( xNode, pParent, rContext ),
91 mpShape(),
92 mxCommandNode( xNode, css::uno::UNO_QUERY_THROW )
93{
95 uno::UNO_QUERY );
96 ShapeSharedPtr pShape( getContext().mpSubsettableShapeManager->lookupShape( xShape ) );
97 mpShape = ::std::dynamic_pointer_cast< IExternalMediaShapeBase >( pShape );
98 mxShape = xShape;
99}
100
102{
103 mxCommandNode.clear();
104 mpShape.reset();
106}
107
109 const uno::Reference<animations::XCommand>& xCommandNode,
111{
112 uno::Reference<animations::XAnimationNode> xTimingRoot = GetTimingRoot(xCommandNode);
113 uno::Reference<container::XEnumerationAccess> xEnumAccess(xTimingRoot, uno::UNO_QUERY);
114 if (!xEnumAccess.is())
115 {
116 return false;
117 }
118
119 uno::Reference<container::XEnumeration> xNodes = xEnumAccess->createEnumeration();
120 while (xNodes->hasMoreElements())
121 {
122 uno::Reference<animations::XAnimationNode> xNode(xNodes->nextElement(), uno::UNO_QUERY);
123 if (xNode->getType() != animations::AnimationNodeType::AUDIO)
124 {
125 continue;
126 }
127
128 uno::Reference<animations::XAudio> xAudio(xNode, uno::UNO_QUERY);
129 uno::Reference<drawing::XShape> xSource(xAudio->getSource(), uno::UNO_QUERY);
130 if (xSource != xShape)
131 {
132 continue;
133 }
134
135 animations::Timing eTiming{};
136 if ((xAudio->getRepeatCount() >>= eTiming) && eTiming == animations::Timing_INDEFINITE)
137 {
138 return true;
139 }
140 }
141 return false;
142}
143
145{
146 switch( mxCommandNode->getCommand() ) {
147 // the command is user defined
148 case EffectCommands::CUSTOM: break;
149 // the command is an ole verb.
150 case EffectCommands::VERB: break;
151 // the command starts playing on a media object
152 case EffectCommands::PLAY:
153 {
154 double fMediaTime=0.0;
155 beans::PropertyValue aMediaTime;
156 if( (mxCommandNode->getParameter() >>= aMediaTime) && aMediaTime.Name == "MediaTime" )
157 {
158 aMediaTime.Value >>= fMediaTime;
159 }
160 if( mpShape )
161 {
162 mpShape->setMediaTime(fMediaTime/1000.0);
163
165 {
166 // If looping is requested from the animation, then that has priority over the
167 // looping from the shape itself.
168 mpShape->setLooping(true);
169 }
170
171 mpShape->play();
172 }
173 break;
174 }
175 // the command toggles the pause status on a media object
176 case EffectCommands::TOGGLEPAUSE:
177 {
178 if (mpShape)
179 {
180 if( mpShape->isPlaying() )
181 mpShape->pause();
182 else
183 mpShape->play();
184 }
185 break;
186 }
187 // the command stops the animation on a media object
188 case EffectCommands::STOP:
189 {
190 if( mpShape )
191 mpShape->stop();
192 break;
193 }
194 // the command stops all currently running sound effects
195 case EffectCommands::STOPAUDIO:
197 break;
198 }
199
200 // deactivate ASAP:
201 auto self(getSelf());
203 makeEvent( [self] () { self->deactivate(); },
204 "AnimationCommandNode::deactivate" ) );
205}
206
208{
209 return mxCommandNode->getCommand() == EffectCommands::STOPAUDIO || mpShape;
210}
211
212} // namespace slideshow::internal
213
214/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnimatableShapeSharedPtr mpShape
static bool GetLoopingFromAnimation(const css::uno::Reference< css::animations::XCommand > &xCommandNode, const css::uno::Reference< css::drawing::XShape > &xShape)
Assuming that xCommandNode is a play command, determines if an audio node wants looping when xShape p...
AnimationCommandNode(css::uno::Reference< css::animations::XAnimationNode > const &xNode, ::std::shared_ptr< BaseContainerNode > const &pParent, NodeContext const &rContext)
virtual void dispose() override
Dispose all object references.
css::uno::Reference< css::animations::XCommand > mxCommandNode
css::uno::Reference< css::drawing::XShape > mxShape
IExternalMediaShapeBaseSharedPtr mpShape
virtual bool hasPendingAnimation() const override
Query node whether it has an animation pending.
This interface extends AnimationNode with some file-private accessor methods.
Definition: basenode.hxx:83
SlideShowContext const & getContext() const
Definition: basenode.hxx:135
::std::shared_ptr< BaseNode > const & getSelf() const
Definition: basenode.hxx:136
virtual void dispose() override
Dispose all object references.
Definition: basenode.cxx:339
void scheduleDeactivationEvent(EventSharedPtr const &pEvent=EventSharedPtr())
Definition: basenode.cxx:519
bool notifyCommandStopAudio(const AnimationNodeSharedPtr &rNode)
Notify that all audio has to be stopped.
#define makeEvent(f, d)
Definition: delayevent.hxx:131
::std::shared_ptr< Shape > ShapeSharedPtr
HashMap_OWString_Interface aMap
std::shared_ptr< SubsettableShapeManager > mpSubsettableShapeManager
Definition: slideimpl.cxx:199
Context for every node.
Definition: basenode.hxx:45