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