1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "oox/ppt/soundactioncontext.hxx"
29 
30 #include "comphelper/anytostring.hxx"
31 #include "cppuhelper/exc_hlp.hxx"
32 
33 #include "oox/helper/attributelist.hxx"
34 #include "oox/helper/propertymap.hxx"
35 #include "oox/drawingml/embeddedwavaudiofile.hxx"
36 
37 using rtl::OUString;
38 using namespace ::oox::core;
39 using namespace ::com::sun::star::xml::sax;
40 using namespace ::com::sun::star::uno;
41 
42 
43 namespace oox { namespace ppt {
44 
45 
46     SoundActionContext::SoundActionContext( ContextHandler& rParent, PropertyMap & aProperties ) throw()
47     : ContextHandler( rParent )
48 	, maSlideProperties( aProperties )
49 	, mbHasStartSound( false )
50 	, mbLoopSound( false )
51 	, mbStopSound( false )
52 	{
53 	}
54 
55 
56 	SoundActionContext::~SoundActionContext() throw()
57 	{
58 	}
59 
60 
61 	void SoundActionContext::endFastElement( sal_Int32 aElement ) throw (SAXException, RuntimeException)
62 	{
63 		if ( aElement == PPT_TOKEN( sndAc ) )
64 		{
65 			if( mbHasStartSound )
66 			{
67 				OUString url;
68 				// TODO this is very wrong
69 				if ( msSndName.getLength() != 0 )
70 				{
71 					// try the builtIn version
72 					url = msSndName;
73 				}
74 #if 0 // OOo does not support embedded data yet
75 				else if ( msEmbedded.getLength() != 0 )
76 				{
77 					RelationsRef xRel = getHandler()->getRelations();
78 					url =	xRel->getRelationById( msEmbedded )->msTarget;
79 				}
80 				else if ( msLink.getLength() != 0 )
81 				{
82 					url = msLink;
83 				}
84 #endif
85 				if ( url.getLength() != 0 )
86 				{
87                     maSlideProperties[ PROP_Sound ] <<= url;
88                     maSlideProperties[ PROP_SoundOn ] <<= sal_True;
89 				}
90 			}
91 //			else if( mbStopSound )
92 //			{
93 //				maSlideProperties[ CREATE_OUSTRING( "" ) ] = Any( sal_True );
94 //			}
95 		}
96 	}
97 
98 
99 	Reference< XFastContextHandler > SoundActionContext::createFastChildContext( ::sal_Int32 aElement, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
100 	{
101 		Reference< XFastContextHandler > xRet;
102 		AttributeList attribs(xAttribs);
103 
104 		switch( aElement )
105 		{
106 		case PPT_TOKEN( snd ):
107 			if( mbHasStartSound )
108 			{
109 				drawingml::EmbeddedWAVAudioFile aAudio;
110                 drawingml::getEmbeddedWAVAudioFile( getRelations(), xAttribs, aAudio);
111 
112                 msSndName = ( aAudio.mbBuiltIn ? aAudio.msName : aAudio.msEmbed );
113 			}
114 			break;
115 		case PPT_TOKEN( endSnd ):
116 			// CT_Empty
117 			mbStopSound = true;
118 			break;
119 		case PPT_TOKEN( stSnd ):
120 			mbHasStartSound = true;
121 			mbLoopSound = attribs.getBool( XML_loop, false );
122 		default:
123 			break;
124 		}
125 
126 		if( !xRet.is() )
127 			xRet.set( this );
128 
129 		return xRet;
130 	}
131 
132 
133 
134 } }
135