xref: /AOO41X/main/oox/source/ppt/timetargetelementcontext.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 "timetargetelementcontext.hxx"
25 
26 #include "comphelper/anytostring.hxx"
27 #include "cppuhelper/exc_hlp.hxx"
28 #include <osl/diagnose.h>
29 
30 #include <com/sun/star/uno/Any.hxx>
31 
32 #include "oox/helper/attributelist.hxx"
33 #include "oox/drawingml/embeddedwavaudiofile.hxx"
34 
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::xml::sax;
37 using namespace ::oox::core;
38 
39 using ::rtl::OUString;
40 
41 namespace oox { namespace ppt {
42 
43 
44 
45     // CT_TLShapeTargetElement
46     class ShapeTargetElementContext
47         : public ContextHandler
48     {
49     public:
ShapeTargetElementContext(ContextHandler & rParent,ShapeTargetElement & aValue)50         ShapeTargetElementContext( ContextHandler& rParent, ShapeTargetElement & aValue )
51             : ContextHandler( rParent )
52                 , bTargetSet(false)
53                 , maShapeTarget(aValue)
54             {
55             }
createFastChildContext(::sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)56         virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 aElementToken,
57                                                                                                                                                             const Reference< XFastAttributeList >& xAttribs )
58             throw ( SAXException, RuntimeException )
59             {
60                 Reference< XFastContextHandler > xRet;
61 
62                 switch( aElementToken )
63                 {
64                 case PPT_TOKEN( bg ):
65                     bTargetSet = true;
66                     maShapeTarget.mnType = XML_bg;
67                     break;
68                 case PPT_TOKEN( txEl ):
69                     bTargetSet = true;
70                     maShapeTarget.mnType = XML_txEl;
71                     break;
72                 case PPT_TOKEN( subSp ):
73                     bTargetSet = true;
74                     maShapeTarget.mnType = XML_subSp;
75                     maShapeTarget.msSubShapeId = xAttribs->getOptionalValue( XML_spid );
76                     break;
77                 case PPT_TOKEN( graphicEl ):
78                 case PPT_TOKEN( oleChartEl ):
79                     bTargetSet = true;
80                     // TODO
81                     break;
82                 case PPT_TOKEN( charRg ):
83                 case PPT_TOKEN( pRg ):
84                     if( bTargetSet && maShapeTarget.mnType == XML_txEl )
85                     {
86                         maShapeTarget.mnRangeType = getBaseToken( aElementToken );
87                         maShapeTarget.maRange = drawingml::GetIndexRange( xAttribs );
88                     }
89                     break;
90                 default:
91                     break;
92                 }
93                 if( !xRet.is() )
94                     xRet.set( this );
95                 return xRet;
96             }
97 
98     private:
99         bool bTargetSet;
100         ShapeTargetElement & maShapeTarget;
101     };
102 
103 
104 
TimeTargetElementContext(ContextHandler & rParent,const AnimTargetElementPtr & pValue)105     TimeTargetElementContext::TimeTargetElementContext( ContextHandler& rParent, const AnimTargetElementPtr & pValue )
106         : ContextHandler( rParent ),
107             mpTarget( pValue )
108     {
109         OSL_ENSURE( mpTarget, "no valid target passed" );
110     }
111 
112 
~TimeTargetElementContext()113     TimeTargetElementContext::~TimeTargetElementContext( ) throw( )
114     {
115     }
116 
endFastElement(sal_Int32)117     void SAL_CALL TimeTargetElementContext::endFastElement( sal_Int32 /*aElement*/ ) throw ( SAXException, RuntimeException)
118     {
119     }
120 
createFastChildContext(::sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)121     Reference< XFastContextHandler > SAL_CALL TimeTargetElementContext::createFastChildContext( ::sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw ( SAXException, RuntimeException )
122     {
123         Reference< XFastContextHandler > xRet;
124 
125         switch( aElementToken )
126         {
127         case PPT_TOKEN( inkTgt ):
128         {
129             mpTarget->mnType = XML_inkTgt;
130             OUString aId = xAttribs->getOptionalValue( XML_spid );
131             if( aId.getLength() )
132             {
133                 mpTarget->msValue = aId;
134             }
135             break;
136         }
137         case PPT_TOKEN( sldTgt ):
138             mpTarget->mnType = XML_sldTgt;
139             break;
140         case PPT_TOKEN( sndTgt ):
141         {
142             mpTarget->mnType = XML_sndTgt;
143             drawingml::EmbeddedWAVAudioFile aAudio;
144             drawingml::getEmbeddedWAVAudioFile( getRelations(), xAttribs, aAudio);
145 
146             OUString sSndName = ( aAudio.mbBuiltIn ? aAudio.msName : aAudio.msEmbed );
147             mpTarget->msValue = sSndName;
148             break;
149         }
150         case PPT_TOKEN( spTgt ):
151         {
152             mpTarget->mnType = XML_spTgt;
153             OUString aId = xAttribs->getOptionalValue( XML_spid );
154             mpTarget->msValue = aId;
155             xRet.set( new ShapeTargetElementContext( *this, mpTarget->maShapeTarget ) );
156             break;
157         }
158         default:
159             OSL_TRACE( "OOX: unhandled tag %ld in TL_TimeTargetElement.", getBaseToken( aElementToken ) );
160             break;
161         }
162 
163         if( !xRet.is() )
164             xRet.set( this );
165 
166         return xRet;
167     }
168 
169 
170 } }
171