xref: /AOO41X/main/oox/source/ppt/soundactioncontext.cxx (revision ca5ec2004b000a7d9aaa8381be8ac2853e3b1dc7)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "oox/ppt/soundactioncontext.hxx"
25 
26 #include "comphelper/anytostring.hxx"
27 #include "cppuhelper/exc_hlp.hxx"
28 
29 #include "oox/helper/attributelist.hxx"
30 #include "oox/helper/propertymap.hxx"
31 #include "oox/drawingml/embeddedwavaudiofile.hxx"
32 
33 using rtl::OUString;
34 using namespace ::oox::core;
35 using namespace ::com::sun::star::xml::sax;
36 using namespace ::com::sun::star::uno;
37 
38 
39 namespace oox { namespace ppt {
40 
41 
SoundActionContext(ContextHandler & rParent,PropertyMap & aProperties)42     SoundActionContext::SoundActionContext( ContextHandler& rParent, PropertyMap & aProperties ) throw()
43     : ContextHandler( rParent )
44     , maSlideProperties( aProperties )
45     , mbHasStartSound( false )
46     , mbLoopSound( false )
47     , mbStopSound( false )
48     {
49     }
50 
51 
~SoundActionContext()52     SoundActionContext::~SoundActionContext() throw()
53     {
54     }
55 
56 
endFastElement(sal_Int32 aElement)57     void SoundActionContext::endFastElement( sal_Int32 aElement ) throw (SAXException, RuntimeException)
58     {
59         if ( aElement == PPT_TOKEN( sndAc ) )
60         {
61             if( mbHasStartSound )
62             {
63                 OUString url;
64                 // TODO this is very wrong
65                 if ( msSndName.getLength() != 0 )
66                 {
67                     // try the builtIn version
68                     url = msSndName;
69                 }
70 #if 0 // OOo does not support embedded data yet
71                 else if ( msEmbedded.getLength() != 0 )
72                 {
73                     RelationsRef xRel = getHandler()->getRelations();
74                     url =   xRel->getRelationById( msEmbedded )->msTarget;
75                 }
76                 else if ( msLink.getLength() != 0 )
77                 {
78                     url = msLink;
79                 }
80 #endif
81                 if ( url.getLength() != 0 )
82                 {
83                     maSlideProperties[ PROP_Sound ] <<= url;
84                     maSlideProperties[ PROP_SoundOn ] <<= sal_True;
85                 }
86             }
87 //          else if( mbStopSound )
88 //          {
89 //              maSlideProperties[ CREATE_OUSTRING( "" ) ] = Any( sal_True );
90 //          }
91         }
92     }
93 
94 
createFastChildContext(::sal_Int32 aElement,const Reference<XFastAttributeList> & xAttribs)95     Reference< XFastContextHandler > SoundActionContext::createFastChildContext( ::sal_Int32 aElement, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
96     {
97         Reference< XFastContextHandler > xRet;
98         AttributeList attribs(xAttribs);
99 
100         switch( aElement )
101         {
102         case PPT_TOKEN( snd ):
103             if( mbHasStartSound )
104             {
105                 drawingml::EmbeddedWAVAudioFile aAudio;
106                 drawingml::getEmbeddedWAVAudioFile( getRelations(), xAttribs, aAudio);
107 
108                 msSndName = ( aAudio.mbBuiltIn ? aAudio.msName : aAudio.msEmbed );
109             }
110             break;
111         case PPT_TOKEN( endSnd ):
112             // CT_Empty
113             mbStopSound = true;
114             break;
115         case PPT_TOKEN( stSnd ):
116             mbHasStartSound = true;
117             mbLoopSound = attribs.getBool( XML_loop, false );
118         default:
119             break;
120         }
121 
122         if( !xRet.is() )
123             xRet.set( this );
124 
125         return xRet;
126     }
127 
128 
129 
130 } }
131