tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / slideshow / source / engine / animationnodes / animationcommandnode.cxx
blobe73f68490f9d493d75c19e125638701b7099d1a0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <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>
28 #include <comphelper/sequenceashashmap.hxx>
30 #include "animationcommandnode.hxx"
31 #include <eventmultiplexer.hxx>
32 #include <delayevent.hxx>
35 using namespace com::sun::star;
37 namespace
39 /// Determines if this is the root of the timing node tree.
40 bool IsTimingRootNode(const uno::Reference<animations::XAnimationNode>& xNode)
42 uno::Sequence<beans::NamedValue> aUserData = xNode->getUserData();
43 comphelper::SequenceAsHashMap aMap(aUserData);
44 auto it = aMap.find(u"node-type"_ustr);
45 if (it == aMap.end())
47 return false;
50 sal_Int16 nNodeType{};
51 if (!(it->second >>= nNodeType))
53 return false;
56 return nNodeType == css::presentation::EffectNodeType::TIMING_ROOT;
59 /// Walks the parent chain of xNode and stops at the timing root.
60 uno::Reference<animations::XAnimationNode>
61 GetTimingRoot(const uno::Reference<animations::XAnimationNode>& xNode)
63 uno::Reference<animations::XAnimationNode> xParent(xNode->getParent(), uno::UNO_QUERY);
64 while (true)
66 if (!xParent.is())
68 break;
71 if (IsTimingRootNode(xParent))
73 return xParent;
76 xParent.set(xParent->getParent(), uno::UNO_QUERY);
79 return {};
83 namespace slideshow::internal {
85 namespace EffectCommands = css::presentation::EffectCommands;
87 AnimationCommandNode::AnimationCommandNode( uno::Reference<animations::XAnimationNode> const& xNode,
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 )
94 uno::Reference< drawing::XShape > xShape( mxCommandNode->getTarget(),
95 uno::UNO_QUERY );
96 ShapeSharedPtr pShape( getContext().mpSubsettableShapeManager->lookupShape( xShape ) );
97 mpShape = ::std::dynamic_pointer_cast< IExternalMediaShapeBase >( pShape );
98 mxShape = std::move(xShape);
101 void AnimationCommandNode::dispose()
103 mxCommandNode.clear();
104 mpShape.reset();
105 BaseNode::dispose();
108 bool AnimationCommandNode::GetLoopingFromAnimation(
109 const uno::Reference<animations::XCommand>& xCommandNode,
110 const uno::Reference<drawing::XShape>& xShape)
112 uno::Reference<animations::XAnimationNode> xTimingRoot = GetTimingRoot(xCommandNode);
113 uno::Reference<container::XEnumerationAccess> xEnumAccess(xTimingRoot, uno::UNO_QUERY);
114 if (!xEnumAccess.is())
116 return false;
119 uno::Reference<container::XEnumeration> xNodes = xEnumAccess->createEnumeration();
120 while (xNodes->hasMoreElements())
122 uno::Reference<animations::XAnimationNode> xNode(xNodes->nextElement(), uno::UNO_QUERY);
123 if (xNode->getType() != animations::AnimationNodeType::AUDIO)
125 continue;
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)
132 continue;
135 animations::Timing eTiming{};
136 if ((xAudio->getRepeatCount() >>= eTiming) && eTiming == animations::Timing_INDEFINITE)
138 return true;
141 return false;
144 void AnimationCommandNode::activate_st()
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:
154 double fMediaTime=0.0;
155 beans::PropertyValue aMediaTime;
156 if( (mxCommandNode->getParameter() >>= aMediaTime) && aMediaTime.Name == "MediaTime" )
158 aMediaTime.Value >>= fMediaTime;
160 if( mpShape )
162 mpShape->setMediaTime(fMediaTime/1000.0);
164 if (AnimationCommandNode::GetLoopingFromAnimation(mxCommandNode, mxShape))
166 // If looping is requested from the animation, then that has priority over the
167 // looping from the shape itself.
168 mpShape->setLooping(true);
171 mpShape->play();
173 break;
175 // the command toggles the pause status on a media object
176 case EffectCommands::TOGGLEPAUSE:
178 if (mpShape)
180 if( mpShape->isPlaying() )
181 mpShape->pause();
182 else
183 mpShape->play();
185 break;
187 // the command stops the animation on a media object
188 case EffectCommands::STOP:
190 if( mpShape )
191 mpShape->stop();
192 break;
194 // the command stops all currently running sound effects
195 case EffectCommands::STOPAUDIO:
196 getContext().mrEventMultiplexer.notifyCommandStopAudio( getSelf() );
197 break;
200 // deactivate ASAP:
201 std::shared_ptr<BaseNode> self(getSelf());
202 scheduleDeactivationEvent(
203 makeEvent( [self=std::move(self)] () { self->deactivate(); },
204 u"AnimationCommandNode::deactivate"_ustr ) );
207 bool AnimationCommandNode::hasPendingAnimation() const
209 return mxCommandNode->getCommand() == EffectCommands::STOPAUDIO || mpShape;
212 } // namespace slideshow::internal
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */