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 "comphelper/anytostring.hxx"
25 #include "cppuhelper/exc_hlp.hxx"
26
27 #include <com/sun/star/beans/XMultiPropertySet.hpp>
28 #include <com/sun/star/container/XNamed.hpp>
29
30 #include "oox/helper/propertyset.hxx"
31 #include "oox/core/xmlfilterbase.hxx"
32 #include "headerfootercontext.hxx"
33 #include "oox/ppt/backgroundproperties.hxx"
34 #include "oox/ppt/slidefragmenthandler.hxx"
35 #include "oox/ppt/slidetimingcontext.hxx"
36 #include "oox/ppt/slidetransitioncontext.hxx"
37 #include "oox/ppt/slidemastertextstylescontext.hxx"
38 #include "oox/ppt/pptshapegroupcontext.hxx"
39 #include "oox/ppt/pptshape.hxx"
40 #include "oox/vml/vmldrawing.hxx"
41 #include "oox/vml/vmldrawingfragment.hxx"
42 #include "oox/drawingml/clrschemecontext.hxx"
43
44
45 using rtl::OUString;
46 using namespace ::com::sun::star;
47 using namespace ::oox::core;
48 using namespace ::oox::drawingml;
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::drawing;
51 using namespace ::com::sun::star::xml::sax;
52 using namespace ::com::sun::star::container;
53
54 namespace oox { namespace ppt {
55
SlideFragmentHandler(XmlFilterBase & rFilter,const OUString & rFragmentPath,SlidePersistPtr pPersistPtr,const ShapeLocation eShapeLocation)56 SlideFragmentHandler::SlideFragmentHandler( XmlFilterBase& rFilter, const OUString& rFragmentPath, SlidePersistPtr pPersistPtr, const ShapeLocation eShapeLocation ) throw()
57 : FragmentHandler( rFilter, rFragmentPath )
58 , mpSlidePersistPtr( pPersistPtr )
59 , meShapeLocation( eShapeLocation )
60 {
61 OUString aVMLDrawingFragmentPath = getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "vmlDrawing" ) );
62 if( aVMLDrawingFragmentPath.getLength() > 0 )
63 getFilter().importFragment( new oox::vml::DrawingFragment(
64 getFilter(), aVMLDrawingFragmentPath, *pPersistPtr->getDrawing() ) );
65 }
66
~SlideFragmentHandler()67 SlideFragmentHandler::~SlideFragmentHandler() throw()
68 {
69 // convert and insert all VML shapes (mostly form controls)
70 mpSlidePersistPtr->getDrawing()->convertAndInsert();
71 }
72
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)73 Reference< XFastContextHandler > SlideFragmentHandler::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
74 {
75 Reference< XFastContextHandler > xRet;
76 AttributeList aAttribs( xAttribs );
77
78 switch( aElementToken )
79 {
80 case PPT_TOKEN( sld ): // CT_Slide
81 {
82 OptValue< bool > aShowMasterSp = aAttribs.getBool( XML_showMasterSp );
83 if( aShowMasterSp.has() && !aShowMasterSp.get() )
84 {
85 PropertyMap aPropMap;
86 aPropMap[ PROP_IsBackgroundObjectsVisible ] = Any( false );
87
88 Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
89 PropertySet aSlideProp( xSlide );
90 aSlideProp.setProperties( aPropMap );
91 }
92 }
93 case PPT_TOKEN( sldMaster ): // CT_SlideMaster
94 case PPT_TOKEN( handoutMaster ): // CT_HandoutMaster
95 {
96 OptValue< bool > aShow = aAttribs.getBool( XML_show );
97 if( aShow.has() && !aShow.get() )
98 {
99 PropertyMap aPropMap;
100 aPropMap[ PROP_Visible ] = Any( false );
101
102 Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
103 PropertySet aSlideProp( xSlide );
104 aSlideProp.setProperties( aPropMap );
105 }
106 break;
107 }
108 case PPT_TOKEN( notes ): // CT_NotesSlide
109 case PPT_TOKEN( notesMaster ): // CT_NotesMaster
110 break;
111 case PPT_TOKEN( cSld ): // CT_CommonSlideData
112 maSlideName = xAttribs->getOptionalValue(XML_name);
113 break;
114
115 case PPT_TOKEN( spTree ): // CT_GroupShape
116 {
117 xRet.set( new PPTShapeGroupContext(
118 *this, mpSlidePersistPtr, meShapeLocation, mpSlidePersistPtr->getShapes(),
119 oox::drawingml::ShapePtr( new PPTShape( meShapeLocation, "com.sun.star.drawing.GroupShape" ) ) ) );
120 }
121 break;
122
123 case PPT_TOKEN( controls ):
124 xRet = getFastContextHandler();
125 break;
126 case PPT_TOKEN( control ):
127 {
128 ::oox::vml::ControlInfo aInfo;
129 aInfo.setShapeId( aAttribs.getInteger( XML_spid, 0 ) );
130 aInfo.maFragmentPath = getFragmentPathFromRelId( aAttribs.getString( R_TOKEN( id ), OUString() ) );
131 aInfo.maName = aAttribs.getXString( XML_name, OUString() );
132 mpSlidePersistPtr->getDrawing()->registerControl( aInfo );
133 }
134 return xRet;
135
136 case PPT_TOKEN( timing ): // CT_SlideTiming
137 xRet.set( new SlideTimingContext( *this, mpSlidePersistPtr->getTimeNodeList() ) );
138 break;
139 case PPT_TOKEN( transition ): // CT_SlideTransition
140 xRet.set( new SlideTransitionContext( *this, xAttribs, maSlideProperties ) );
141 break;
142 case PPT_TOKEN( hf ):
143 xRet.set( new HeaderFooterContext( *this, xAttribs, mpSlidePersistPtr->getHeaderFooter() ) );
144 break;
145
146 // BackgroundGroup
147 case PPT_TOKEN( bgPr ): // CT_BackgroundProperties
148 {
149 FillPropertiesPtr pFillPropertiesPtr( new FillProperties );
150 xRet.set( new BackgroundPropertiesContext( *this, *pFillPropertiesPtr ) );
151 mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
152 }
153 break;
154
155 case PPT_TOKEN( bgRef ): // a:CT_StyleMatrixReference
156 {
157 oox::drawingml::ThemePtr pTheme = mpSlidePersistPtr->getTheme();
158 if (pTheme)
159 {
160 FillPropertiesPtr pFillPropertiesPtr( new FillProperties(
161 *pTheme->getFillStyle( xAttribs->getOptionalValue( XML_idx ).toInt32() ) ) );
162 mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
163 }
164 xRet.set( new ColorContext( *this, mpSlidePersistPtr->getBackgroundColor() ) );
165
166 }
167 break;
168
169 case PPT_TOKEN( clrMap ): // CT_ColorMapping
170 {
171 oox::drawingml::ClrMapPtr pClrMapPtr( new oox::drawingml::ClrMap() );
172 xRet.set( new oox::drawingml::clrMapContext( *this, xAttribs, *pClrMapPtr ) );
173 mpSlidePersistPtr->setClrMap( pClrMapPtr );
174 }
175 break;
176 case PPT_TOKEN( clrMapOvr ): // CT_ColorMappingOverride
177 case PPT_TOKEN( sldLayoutIdLst ): // CT_SlideLayoutIdList
178 break;
179 case PPT_TOKEN( txStyles ): // CT_SlideMasterTextStyles
180 xRet.set( new SlideMasterTextStylesContext( *this, mpSlidePersistPtr ) );
181 break;
182 case PPT_TOKEN( custDataLst ): // CT_CustomerDataList
183 case PPT_TOKEN( tagLst ): // CT_TagList
184 break;
185 }
186
187 if( !xRet.is() )
188 xRet = getFastContextHandler();
189
190 return xRet;
191 }
192
endDocument()193 void SAL_CALL SlideFragmentHandler::endDocument( ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException)
194 {
195 try
196 {
197 Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
198 PropertySet aSlideProp( xSlide );
199 aSlideProp.setProperties( maSlideProperties );
200 if ( maSlideName.getLength() )
201 {
202 Reference< XNamed > xNamed( xSlide, UNO_QUERY );
203 if( xNamed.is() )
204 xNamed->setName( maSlideName );
205 }
206 }
207 catch( uno::Exception& )
208 {
209 OSL_ENSURE( false,
210 (rtl::OString("oox::ppt::SlideFragmentHandler::EndElement(), "
211 "exception caught: ") +
212 rtl::OUStringToOString(
213 comphelper::anyToString( cppu::getCaughtException() ),
214 RTL_TEXTENCODING_UTF8 )).getStr() );
215 }
216 }
217
218 } }
219
220