1*ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ca5ec200SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ca5ec200SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ca5ec200SAndrew Rist  * distributed with this work for additional information
6*ca5ec200SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ca5ec200SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ca5ec200SAndrew Rist  * "License"); you may not use this file except in compliance
9*ca5ec200SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ca5ec200SAndrew Rist  *
11*ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ca5ec200SAndrew Rist  *
13*ca5ec200SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ca5ec200SAndrew Rist  * software distributed under the License is distributed on an
15*ca5ec200SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ca5ec200SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ca5ec200SAndrew Rist  * specific language governing permissions and limitations
18*ca5ec200SAndrew Rist  * under the License.
19*ca5ec200SAndrew Rist  *
20*ca5ec200SAndrew Rist  *************************************************************/
21*ca5ec200SAndrew Rist 
22*ca5ec200SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "timetargetelementcontext.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "comphelper/anytostring.hxx"
27cdf0e10cSrcweir #include "cppuhelper/exc_hlp.hxx"
28cdf0e10cSrcweir #include <osl/diagnose.h>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include "oox/helper/attributelist.hxx"
33cdf0e10cSrcweir #include "oox/drawingml/embeddedwavaudiofile.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace ::com::sun::star::uno;
36cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
37cdf0e10cSrcweir using namespace ::oox::core;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir using ::rtl::OUString;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace oox { namespace ppt {
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 	// CT_TLShapeTargetElement
46cdf0e10cSrcweir 	class ShapeTargetElementContext
47cdf0e10cSrcweir         : public ContextHandler
48cdf0e10cSrcweir 	{
49cdf0e10cSrcweir 	public:
ShapeTargetElementContext(ContextHandler & rParent,ShapeTargetElement & aValue)50cdf0e10cSrcweir         ShapeTargetElementContext( ContextHandler& rParent, ShapeTargetElement & aValue )
51cdf0e10cSrcweir             : ContextHandler( rParent )
52cdf0e10cSrcweir 				, bTargetSet(false)
53cdf0e10cSrcweir 				, maShapeTarget(aValue)
54cdf0e10cSrcweir 			{
55cdf0e10cSrcweir 			}
createFastChildContext(::sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)56cdf0e10cSrcweir 		virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 aElementToken,
57cdf0e10cSrcweir 																																							const Reference< XFastAttributeList >& xAttribs )
58cdf0e10cSrcweir 			throw ( SAXException, RuntimeException )
59cdf0e10cSrcweir 			{
60cdf0e10cSrcweir 				Reference< XFastContextHandler > xRet;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 				switch( aElementToken )
63cdf0e10cSrcweir 				{
64cdf0e10cSrcweir 				case PPT_TOKEN( bg ):
65cdf0e10cSrcweir 					bTargetSet = true;
66cdf0e10cSrcweir 					maShapeTarget.mnType = XML_bg;
67cdf0e10cSrcweir 					break;
68cdf0e10cSrcweir 				case PPT_TOKEN( txEl ):
69cdf0e10cSrcweir 					bTargetSet = true;
70cdf0e10cSrcweir 					maShapeTarget.mnType = XML_txEl;
71cdf0e10cSrcweir 					break;
72cdf0e10cSrcweir 				case PPT_TOKEN( subSp ):
73cdf0e10cSrcweir 					bTargetSet = true;
74cdf0e10cSrcweir 					maShapeTarget.mnType = XML_subSp;
75cdf0e10cSrcweir 					maShapeTarget.msSubShapeId = xAttribs->getOptionalValue( XML_spid );
76cdf0e10cSrcweir 					break;
77cdf0e10cSrcweir 				case PPT_TOKEN( graphicEl ):
78cdf0e10cSrcweir 				case PPT_TOKEN( oleChartEl ):
79cdf0e10cSrcweir 					bTargetSet = true;
80cdf0e10cSrcweir 					// TODO
81cdf0e10cSrcweir 					break;
82cdf0e10cSrcweir 				case PPT_TOKEN( charRg ):
83cdf0e10cSrcweir 				case PPT_TOKEN( pRg ):
84cdf0e10cSrcweir 					if( bTargetSet && maShapeTarget.mnType == XML_txEl )
85cdf0e10cSrcweir 					{
86cdf0e10cSrcweir                         maShapeTarget.mnRangeType = getBaseToken( aElementToken );
87cdf0e10cSrcweir 						maShapeTarget.maRange = drawingml::GetIndexRange( xAttribs );
88cdf0e10cSrcweir 					}
89cdf0e10cSrcweir 					break;
90cdf0e10cSrcweir 				default:
91cdf0e10cSrcweir 					break;
92cdf0e10cSrcweir 				}
93cdf0e10cSrcweir 				if( !xRet.is() )
94cdf0e10cSrcweir 					xRet.set( this );
95cdf0e10cSrcweir 				return xRet;
96cdf0e10cSrcweir 			}
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	private:
99cdf0e10cSrcweir 		bool bTargetSet;
100cdf0e10cSrcweir 		ShapeTargetElement & maShapeTarget;
101cdf0e10cSrcweir 	};
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 
TimeTargetElementContext(ContextHandler & rParent,const AnimTargetElementPtr & pValue)105cdf0e10cSrcweir     TimeTargetElementContext::TimeTargetElementContext( ContextHandler& rParent, const AnimTargetElementPtr & pValue )
106cdf0e10cSrcweir         : ContextHandler( rParent ),
107cdf0e10cSrcweir 			mpTarget( pValue )
108cdf0e10cSrcweir 	{
109cdf0e10cSrcweir 		OSL_ENSURE( mpTarget, "no valid target passed" );
110cdf0e10cSrcweir 	}
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 
~TimeTargetElementContext()113cdf0e10cSrcweir 	TimeTargetElementContext::~TimeTargetElementContext( ) throw( )
114cdf0e10cSrcweir 	{
115cdf0e10cSrcweir 	}
116cdf0e10cSrcweir 
endFastElement(sal_Int32)117cdf0e10cSrcweir 	void SAL_CALL TimeTargetElementContext::endFastElement( sal_Int32 /*aElement*/ ) throw ( SAXException, RuntimeException)
118cdf0e10cSrcweir 	{
119cdf0e10cSrcweir 	}
120cdf0e10cSrcweir 
createFastChildContext(::sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)121cdf0e10cSrcweir 	Reference< XFastContextHandler > SAL_CALL TimeTargetElementContext::createFastChildContext( ::sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw ( SAXException, RuntimeException )
122cdf0e10cSrcweir 	{
123cdf0e10cSrcweir 		Reference< XFastContextHandler > xRet;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 		switch( aElementToken )
126cdf0e10cSrcweir 		{
127cdf0e10cSrcweir 		case PPT_TOKEN( inkTgt ):
128cdf0e10cSrcweir 		{
129cdf0e10cSrcweir 			mpTarget->mnType = XML_inkTgt;
130cdf0e10cSrcweir 			OUString aId = xAttribs->getOptionalValue( XML_spid );
131cdf0e10cSrcweir 			if( aId.getLength() )
132cdf0e10cSrcweir 			{
133cdf0e10cSrcweir 				mpTarget->msValue = aId;
134cdf0e10cSrcweir 			}
135cdf0e10cSrcweir 			break;
136cdf0e10cSrcweir 		}
137cdf0e10cSrcweir 		case PPT_TOKEN( sldTgt ):
138cdf0e10cSrcweir 			mpTarget->mnType = XML_sldTgt;
139cdf0e10cSrcweir 			break;
140cdf0e10cSrcweir 		case PPT_TOKEN( sndTgt ):
141cdf0e10cSrcweir 		{
142cdf0e10cSrcweir 			mpTarget->mnType = XML_sndTgt;
143cdf0e10cSrcweir 			drawingml::EmbeddedWAVAudioFile aAudio;
144cdf0e10cSrcweir             drawingml::getEmbeddedWAVAudioFile( getRelations(), xAttribs, aAudio);
145cdf0e10cSrcweir 
146cdf0e10cSrcweir             OUString sSndName = ( aAudio.mbBuiltIn ? aAudio.msName : aAudio.msEmbed );
147cdf0e10cSrcweir 			mpTarget->msValue = sSndName;
148cdf0e10cSrcweir 			break;
149cdf0e10cSrcweir 		}
150cdf0e10cSrcweir 		case PPT_TOKEN( spTgt ):
151cdf0e10cSrcweir 		{
152cdf0e10cSrcweir 			mpTarget->mnType = XML_spTgt;
153cdf0e10cSrcweir 			OUString aId = xAttribs->getOptionalValue( XML_spid );
154cdf0e10cSrcweir 			mpTarget->msValue = aId;
155cdf0e10cSrcweir 			xRet.set( new ShapeTargetElementContext( *this, mpTarget->maShapeTarget ) );
156cdf0e10cSrcweir 			break;
157cdf0e10cSrcweir 		}
158cdf0e10cSrcweir 		default:
159cdf0e10cSrcweir             OSL_TRACE( "OOX: unhandled tag %ld in TL_TimeTargetElement.", getBaseToken( aElementToken ) );
160cdf0e10cSrcweir 			break;
161cdf0e10cSrcweir 		}
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 		if( !xRet.is() )
164cdf0e10cSrcweir 			xRet.set( this );
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 		return xRet;
167cdf0e10cSrcweir 	}
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 
170cdf0e10cSrcweir } }
171