Bump version to 6.0-36
[LibreOffice.git] / slideshow / source / engine / animationnodes / animationcommandnode.cxx
blob1b764b1c5a4a30846b8f403bd9d7f2182f5a98bc
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/beans/PropertyValue.hpp>
24 #include "animationcommandnode.hxx"
25 #include <delayevent.hxx>
26 #include <tools.hxx>
27 #include "nodetools.hxx"
30 using namespace com::sun::star;
32 namespace slideshow {
33 namespace internal {
35 namespace EffectCommands = css::presentation::EffectCommands;
37 AnimationCommandNode::AnimationCommandNode( uno::Reference<animations::XAnimationNode> const& xNode,
38 ::std::shared_ptr<BaseContainerNode> const& pParent,
39 NodeContext const& rContext ) :
40 BaseNode( xNode, pParent, rContext ),
41 mbToggled(false),
42 mpShape(),
43 mxCommandNode( xNode, css::uno::UNO_QUERY_THROW )
45 uno::Reference< drawing::XShape > xShape( mxCommandNode->getTarget(),
46 uno::UNO_QUERY );
47 ShapeSharedPtr pShape( getContext().mpSubsettableShapeManager->lookupShape( xShape ) );
48 mpShape = ::std::dynamic_pointer_cast< IExternalMediaShapeBase >( pShape );
51 void AnimationCommandNode::dispose()
53 mxCommandNode.clear();
54 mpShape.reset();
55 BaseNode::dispose();
58 void AnimationCommandNode::activate_st()
60 switch( mxCommandNode->getCommand() ) {
61 // the command is user defined
62 case EffectCommands::CUSTOM: break;
63 // the command is an ole verb.
64 case EffectCommands::VERB: break;
65 // the command starts playing on a media object
66 case EffectCommands::PLAY:
68 double fMediaTime=0.0;
69 beans::PropertyValue aMediaTime;
70 if( (mxCommandNode->getParameter() >>= aMediaTime) && aMediaTime.Name == "MediaTime" )
72 aMediaTime.Value >>= fMediaTime;
74 if( mpShape )
76 mpShape->setMediaTime(fMediaTime/1000.0);
77 mpShape->play();
79 break;
81 // the command toggles the pause status on a media object
82 case EffectCommands::TOGGLEPAUSE:
84 if (mpShape)
86 if( mpShape->isPlaying() )
87 mpShape->pause();
88 else
89 mpShape->play();
90 mbToggled = true;
92 break;
94 // the command stops the animation on a media object
95 case EffectCommands::STOP:
97 if( mpShape )
98 mpShape->stop();
99 break;
101 // the command stops all currently running sound effects
102 case EffectCommands::STOPAUDIO:
103 getContext().mrEventMultiplexer.notifyCommandStopAudio( getSelf() );
104 break;
107 // deactivate ASAP:
108 auto self(getSelf());
109 scheduleDeactivationEvent(
110 makeEvent( [self] () { self->deactivate(); },
111 "AnimationCommandNode::deactivate" ) );
114 void AnimationCommandNode::deactivate_st( NodeState /*eDestState*/ )
116 switch( mxCommandNode->getCommand() ) {
117 // the command toggles the pause status on a media object
118 case EffectCommands::TOGGLEPAUSE:
120 if (mpShape && mbToggled)
122 if( mpShape->isPlaying() )
123 mpShape->pause();
124 else
125 mpShape->play();
126 mbToggled = false;
128 break;
134 bool AnimationCommandNode::hasPendingAnimation() const
136 return mxCommandNode->getCommand() == EffectCommands::STOPAUDIO || mpShape;
139 } // namespace internal
140 } // namespace slideshow
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */