1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: slidefragmenthandler.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "comphelper/anytostring.hxx"
32 #include "cppuhelper/exc_hlp.hxx"
34 #include <com/sun/star/beans/XMultiPropertySet.hpp>
35 #include <com/sun/star/container/XNamed.hpp>
38 #include "oox/helper/propertyset.hxx"
39 #include "oox/core/namespaces.hxx"
40 #include "oox/core/xmlfilterbase.hxx"
41 #include "headerfootercontext.hxx"
42 #include "oox/ppt/backgroundproperties.hxx"
43 #include "oox/ppt/slidefragmenthandler.hxx"
44 #include "oox/ppt/slidetimingcontext.hxx"
45 #include "oox/ppt/slidetransitioncontext.hxx"
46 #include "oox/ppt/slidemastertextstylescontext.hxx"
47 #include "oox/ppt/pptshapegroupcontext.hxx"
48 #include "oox/ppt/pptshape.hxx"
49 #include "oox/vml/vmldrawing.hxx"
50 #include "oox/vml/vmldrawingfragment.hxx"
51 #include "oox/drawingml/clrschemecontext.hxx"
55 using namespace ::com::sun::star
;
56 using namespace ::oox::core
;
57 using namespace ::oox::drawingml
;
58 using namespace ::com::sun::star::uno
;
59 using namespace ::com::sun::star::drawing
;
60 using namespace ::com::sun::star::xml::sax
;
61 using namespace ::com::sun::star::container
;
63 namespace oox
{ namespace ppt
{
65 SlideFragmentHandler::SlideFragmentHandler( XmlFilterBase
& rFilter
, const OUString
& rFragmentPath
, SlidePersistPtr pPersistPtr
, const ShapeLocation eShapeLocation
) throw()
66 : FragmentHandler( rFilter
, rFragmentPath
)
67 , mpSlidePersistPtr( pPersistPtr
)
68 , meShapeLocation( eShapeLocation
)
70 OUString aVMLDrawingFragmentPath
= getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATIONSTYPE( "vmlDrawing" ) );
71 if( aVMLDrawingFragmentPath
.getLength() > 0 )
72 getFilter().importFragment( new oox::vml::DrawingFragment(
73 getFilter(), aVMLDrawingFragmentPath
, *pPersistPtr
->getDrawing() ) );
76 SlideFragmentHandler::~SlideFragmentHandler() throw()
78 // convert and insert all VML shapes (mostly form controls)
79 mpSlidePersistPtr
->getDrawing()->convertAndInsert();
82 Reference
< XFastContextHandler
> SlideFragmentHandler::createFastChildContext( sal_Int32 aElementToken
, const Reference
< XFastAttributeList
>& xAttribs
) throw (SAXException
, RuntimeException
)
84 Reference
< XFastContextHandler
> xRet
;
85 AttributeList
aAttribs( xAttribs
);
87 switch( aElementToken
)
89 case NMSP_PPT
|XML_sldMaster
: // CT_SlideMaster
90 case NMSP_PPT
|XML_handoutMaster
: // CT_HandoutMaster
91 case NMSP_PPT
|XML_sld
: // CT_CommonSlideData
92 case NMSP_PPT
|XML_notes
: // CT_NotesSlide
93 case NMSP_PPT
|XML_notesMaster
: // CT_NotesMaster
95 case NMSP_PPT
|XML_cSld
: // CT_CommonSlideData
96 maSlideName
= xAttribs
->getOptionalValue(XML_name
);
99 case NMSP_PPT
|XML_spTree
: // CT_GroupShape
101 xRet
.set( new PPTShapeGroupContext(
102 *this, mpSlidePersistPtr
, meShapeLocation
, mpSlidePersistPtr
->getShapes(),
103 oox::drawingml::ShapePtr( new PPTShape( meShapeLocation
, "com.sun.star.drawing.GroupShape" ) ) ) );
107 case NMSP_PPT
|XML_controls
:
108 xRet
= getFastContextHandler();
110 case NMSP_PPT
|XML_control
:
112 ::oox::vml::ControlInfo aInfo
;
113 aInfo
.setShapeId( aAttribs
.getInteger( XML_spid
, 0 ) );
114 aInfo
.maFragmentPath
= getFragmentPathFromRelId( aAttribs
.getString( R_TOKEN( id
), OUString() ) );
115 aInfo
.maName
= aAttribs
.getXString( XML_name
, OUString() );
116 mpSlidePersistPtr
->getDrawing()->registerControl( aInfo
);
120 case NMSP_PPT
|XML_timing
: // CT_SlideTiming
121 xRet
.set( new SlideTimingContext( *this, mpSlidePersistPtr
->getTimeNodeList() ) );
123 case NMSP_PPT
|XML_transition
: // CT_SlideTransition
124 xRet
.set( new SlideTransitionContext( *this, xAttribs
, maSlideProperties
) );
126 case NMSP_PPT
|XML_hf
:
127 xRet
.set( new HeaderFooterContext( *this, xAttribs
, mpSlidePersistPtr
->getHeaderFooter() ) );
131 case NMSP_PPT
|XML_bgPr
: // CT_BackgroundProperties
133 FillPropertiesPtr
pFillPropertiesPtr( new FillProperties
);
134 xRet
.set( new BackgroundPropertiesContext( *this, *pFillPropertiesPtr
) );
135 mpSlidePersistPtr
->setBackgroundProperties( pFillPropertiesPtr
);
138 case NMSP_PPT
|XML_bgRef
: // a:CT_StyleMatrixReference
141 case NMSP_PPT
|XML_clrMap
: // CT_ColorMapping
143 oox::drawingml::ClrMapPtr
pClrMapPtr( new oox::drawingml::ClrMap() );
144 xRet
.set( new oox::drawingml::clrMapContext( *this, xAttribs
, *pClrMapPtr
) );
145 mpSlidePersistPtr
->setClrMap( pClrMapPtr
);
148 case NMSP_PPT
|XML_clrMapOvr
: // CT_ColorMappingOverride
149 case NMSP_PPT
|XML_sldLayoutIdLst
: // CT_SlideLayoutIdList
151 case NMSP_PPT
|XML_txStyles
: // CT_SlideMasterTextStyles
152 xRet
.set( new SlideMasterTextStylesContext( *this, mpSlidePersistPtr
) );
154 case NMSP_PPT
|XML_custDataLst
: // CT_CustomerDataList
155 case NMSP_PPT
|XML_tagLst
: // CT_TagList
160 xRet
= getFastContextHandler();
165 void SAL_CALL
SlideFragmentHandler::endDocument( ) throw (::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
)
169 Reference
< XDrawPage
> xSlide( mpSlidePersistPtr
->getPage() );
170 PropertySet
aSlideProp( xSlide
);
171 aSlideProp
.setProperties( maSlideProperties
);
172 if ( maSlideName
.getLength() )
174 Reference
< XNamed
> xNamed( xSlide
, UNO_QUERY
);
176 xNamed
->setName( maSlideName
);
179 catch( uno::Exception
& )
182 (rtl::OString("oox::ppt::SlideFragmentHandler::EndElement(), "
183 "exception caught: ") +
184 rtl::OUStringToOString(
185 comphelper::anyToString( cppu::getCaughtException() ),
186 RTL_TEXTENCODING_UTF8
)).getStr() );