LibreOffice Module oox (master)  1
soundactioncontext.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 #include <config_features.h>
21 
23 
24 #include <com/sun/star/io/XInputStream.hpp>
25 
29 #include <oox/token/namespaces.hxx>
30 #include <oox/token/properties.hxx>
31 #include <oox/token/tokens.hxx>
33 #include <avmedia/mediaitem.hxx>
34 
35 using namespace ::oox::core;
36 using namespace ::com::sun::star::xml::sax;
37 using namespace ::com::sun::star::uno;
38 
39 namespace oox::ppt {
40 
41  SoundActionContext::SoundActionContext( FragmentHandler2 const & rParent, PropertyMap & aProperties ) noexcept
42  : FragmentHandler2( rParent )
43  , maSlideProperties( aProperties )
44  , mbHasStartSound( false )
45  , mbLoopSound( false )
46  , mbStopSound( false )
47  {
48  }
49 
51  {
52  }
53 
55  {
56  if ( !isCurrentElement( PPT_TOKEN( sndAc ) ) )
57  return;
58 
59  if( !mbHasStartSound )
60  return;
61 
62  OUString url;
63 #if HAVE_FEATURE_AVMEDIA
64  if ( !msSndName.isEmpty() )
65  {
66  Reference<css::io::XInputStream>
67  xInputStream = getFilter().openInputStream(msSndName);
68  if (xInputStream.is())
69  {
70  ::avmedia::EmbedMedia(getFilter().getModel(), msSndName, url, xInputStream);
71  xInputStream->closeInput();
72  }
73  }
74 #endif
75  if ( !url.isEmpty() )
76  {
77  maSlideProperties.setProperty( PROP_Sound, url);
78  maSlideProperties.setProperty( PROP_SoundOn, true);
79  }
80  }
81 
83  {
84  switch( aElementToken )
85  {
86  case PPT_TOKEN( snd ):
87  if( mbHasStartSound )
88  {
89  msSndName = drawingml::getEmbeddedWAVAudioFile( getRelations(), rAttribs );
90  }
91  return this;
92  case PPT_TOKEN( endSnd ):
93  // CT_Empty
94  mbStopSound = true;
95  return this;
96  case PPT_TOKEN( stSnd ):
97  mbHasStartSound = true;
98  mbLoopSound = rAttribs.getBool( XML_loop, false );
99  return this;
100  default:
101  break;
102  }
103 
104  return this;
105  }
106 
107 }
108 
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:52
OptValue< bool > getBool(sal_Int32 nAttrToken) const
Returns the boolean value of the specified attribute.
bool isCurrentElement(sal_Int32 nElement) const
Returns true, if nElement contains the identifier of the currently processed element.
virtual ~SoundActionContext() noexcept override
bool setProperty(sal_Int32 nPropId, Type &&rValue)
Sets the specified property to the passed value.
Definition: propertymap.hxx:70
virtual void onEndElement() override
Will be called when the current element is about to be left.
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 aElementToken, const AttributeList &rAttribs) override
Will be called to create a context handler for the passed element.
Provides access to attribute values of an element.
SoundActionContext(::oox::core::FragmentHandler2 const &rParent, PropertyMap &aProperties) noexcept
OUString getEmbeddedWAVAudioFile(const core::Relations &rRelations, const AttributeList &rAttribs)