xref: /trunk/main/oox/source/ppt/slidefragmenthandler.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ca5ec200SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ca5ec200SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ca5ec200SAndrew Rist  * distributed with this work for additional information
6ca5ec200SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ca5ec200SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ca5ec200SAndrew Rist  * "License"); you may not use this file except in compliance
9ca5ec200SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13ca5ec200SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ca5ec200SAndrew Rist  * software distributed under the License is distributed on an
15ca5ec200SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ca5ec200SAndrew Rist  * KIND, either express or implied.  See the License for the
17ca5ec200SAndrew Rist  * specific language governing permissions and limitations
18ca5ec200SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20ca5ec200SAndrew Rist  *************************************************************/
21ca5ec200SAndrew Rist 
22ca5ec200SAndrew 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 
SlideFragmentHandler(XmlFilterBase & rFilter,const OUString & rFragmentPath,SlidePersistPtr pPersistPtr,const ShapeLocation eShapeLocation)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 
~SlideFragmentHandler()67cdf0e10cSrcweir SlideFragmentHandler::~SlideFragmentHandler() throw()
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     // convert and insert all VML shapes (mostly form controls)
70cdf0e10cSrcweir     mpSlidePersistPtr->getDrawing()->convertAndInsert();
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)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     {
80*c87f51dbSSteve Yin     case PPT_TOKEN( sld ):              // CT_Slide
81cdf0e10cSrcweir     {
82*c87f51dbSSteve Yin         OptValue< bool > aShowMasterSp = aAttribs.getBool( XML_showMasterSp );
83*c87f51dbSSteve Yin         if( aShowMasterSp.has() && !aShowMasterSp.get() )
84*c87f51dbSSteve Yin         {
85*c87f51dbSSteve Yin             PropertyMap aPropMap;
86*c87f51dbSSteve Yin             aPropMap[ PROP_IsBackgroundObjectsVisible ] = Any( false );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir             Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
89cdf0e10cSrcweir             PropertySet aSlideProp( xSlide );
90cdf0e10cSrcweir             aSlideProp.setProperties( aPropMap );
91*c87f51dbSSteve Yin         }
92*c87f51dbSSteve Yin     }
93*c87f51dbSSteve Yin     case PPT_TOKEN( sldMaster ):        // CT_SlideMaster
94*c87f51dbSSteve Yin     case PPT_TOKEN( handoutMaster ):    // CT_HandoutMaster
95*c87f51dbSSteve Yin     {
96*c87f51dbSSteve Yin         OptValue< bool > aShow = aAttribs.getBool( XML_show );
97*c87f51dbSSteve Yin         if( aShow.has() && !aShow.get() )
98*c87f51dbSSteve Yin         {
99*c87f51dbSSteve Yin             PropertyMap aPropMap;
100*c87f51dbSSteve Yin             aPropMap[ PROP_Visible ] = Any( false );
101cdf0e10cSrcweir 
102*c87f51dbSSteve Yin             Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
103*c87f51dbSSteve Yin             PropertySet aSlideProp( xSlide );
104*c87f51dbSSteve Yin             aSlideProp.setProperties( aPropMap );
105*c87f51dbSSteve Yin         }
106cdf0e10cSrcweir         break;
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir     case PPT_TOKEN( notes ):            // CT_NotesSlide
109cdf0e10cSrcweir     case PPT_TOKEN( notesMaster ):      // CT_NotesMaster
110cdf0e10cSrcweir         break;
111cdf0e10cSrcweir     case PPT_TOKEN( cSld ):             // CT_CommonSlideData
112cdf0e10cSrcweir         maSlideName = xAttribs->getOptionalValue(XML_name);
113cdf0e10cSrcweir         break;
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     case PPT_TOKEN( spTree ):           // CT_GroupShape
116cdf0e10cSrcweir         {
117cdf0e10cSrcweir             xRet.set( new PPTShapeGroupContext(
118cdf0e10cSrcweir                 *this, mpSlidePersistPtr, meShapeLocation, mpSlidePersistPtr->getShapes(),
119cdf0e10cSrcweir                 oox::drawingml::ShapePtr( new PPTShape( meShapeLocation, "com.sun.star.drawing.GroupShape" ) ) ) );
120cdf0e10cSrcweir         }
121cdf0e10cSrcweir         break;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     case PPT_TOKEN( controls ):
124cdf0e10cSrcweir         xRet = getFastContextHandler();
125cdf0e10cSrcweir         break;
126cdf0e10cSrcweir     case PPT_TOKEN( control ):
127cdf0e10cSrcweir         {
128cdf0e10cSrcweir             ::oox::vml::ControlInfo aInfo;
129cdf0e10cSrcweir             aInfo.setShapeId( aAttribs.getInteger( XML_spid, 0 ) );
130cdf0e10cSrcweir             aInfo.maFragmentPath = getFragmentPathFromRelId( aAttribs.getString( R_TOKEN( id ), OUString() ) );
131cdf0e10cSrcweir             aInfo.maName = aAttribs.getXString( XML_name, OUString() );
132cdf0e10cSrcweir             mpSlidePersistPtr->getDrawing()->registerControl( aInfo );
133cdf0e10cSrcweir         }
134cdf0e10cSrcweir         return xRet;
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     case PPT_TOKEN( timing ): // CT_SlideTiming
137cdf0e10cSrcweir         xRet.set( new SlideTimingContext( *this, mpSlidePersistPtr->getTimeNodeList() ) );
138cdf0e10cSrcweir         break;
139cdf0e10cSrcweir     case PPT_TOKEN( transition ): // CT_SlideTransition
140cdf0e10cSrcweir         xRet.set( new SlideTransitionContext( *this, xAttribs, maSlideProperties ) );
141cdf0e10cSrcweir         break;
142cdf0e10cSrcweir     case PPT_TOKEN( hf ):
143cdf0e10cSrcweir         xRet.set( new HeaderFooterContext( *this, xAttribs, mpSlidePersistPtr->getHeaderFooter() ) );
144cdf0e10cSrcweir         break;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     // BackgroundGroup
147cdf0e10cSrcweir     case PPT_TOKEN( bgPr ):             // CT_BackgroundProperties
148cdf0e10cSrcweir         {
149cdf0e10cSrcweir             FillPropertiesPtr pFillPropertiesPtr( new FillProperties );
150cdf0e10cSrcweir             xRet.set( new BackgroundPropertiesContext( *this, *pFillPropertiesPtr ) );
151cdf0e10cSrcweir             mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
152cdf0e10cSrcweir         }
153cdf0e10cSrcweir         break;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     case PPT_TOKEN( bgRef ):            // a:CT_StyleMatrixReference
156cdf0e10cSrcweir         {
15799dcb3eeSJürgen Schmidt             oox::drawingml::ThemePtr pTheme = mpSlidePersistPtr->getTheme();
15899dcb3eeSJürgen Schmidt             if (pTheme)
15999dcb3eeSJürgen Schmidt             {
160cdf0e10cSrcweir                 FillPropertiesPtr pFillPropertiesPtr( new FillProperties(
16199dcb3eeSJürgen Schmidt                     *pTheme->getFillStyle( xAttribs->getOptionalValue( XML_idx ).toInt32() ) ) );
162cdf0e10cSrcweir                 mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
163cdf0e10cSrcweir             }
16499dcb3eeSJürgen Schmidt             xRet.set( new ColorContext( *this, mpSlidePersistPtr->getBackgroundColor() ) );
16599dcb3eeSJürgen Schmidt 
16699dcb3eeSJürgen Schmidt         }
167cdf0e10cSrcweir         break;
168cdf0e10cSrcweir 
169cdf0e10cSrcweir     case PPT_TOKEN( clrMap ):           // CT_ColorMapping
170cdf0e10cSrcweir         {
171cdf0e10cSrcweir             oox::drawingml::ClrMapPtr pClrMapPtr( new oox::drawingml::ClrMap() );
172cdf0e10cSrcweir             xRet.set( new oox::drawingml::clrMapContext( *this, xAttribs, *pClrMapPtr ) );
173cdf0e10cSrcweir             mpSlidePersistPtr->setClrMap( pClrMapPtr );
174cdf0e10cSrcweir         }
175cdf0e10cSrcweir         break;
176cdf0e10cSrcweir     case PPT_TOKEN( clrMapOvr ):        // CT_ColorMappingOverride
177cdf0e10cSrcweir     case PPT_TOKEN( sldLayoutIdLst ):   // CT_SlideLayoutIdList
178cdf0e10cSrcweir         break;
179cdf0e10cSrcweir     case PPT_TOKEN( txStyles ):         // CT_SlideMasterTextStyles
180cdf0e10cSrcweir         xRet.set( new SlideMasterTextStylesContext( *this, mpSlidePersistPtr ) );
181cdf0e10cSrcweir         break;
182cdf0e10cSrcweir     case PPT_TOKEN( custDataLst ):      // CT_CustomerDataList
183cdf0e10cSrcweir     case PPT_TOKEN( tagLst ):           // CT_TagList
184cdf0e10cSrcweir         break;
185cdf0e10cSrcweir     }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     if( !xRet.is() )
188cdf0e10cSrcweir         xRet = getFastContextHandler();
189cdf0e10cSrcweir 
190cdf0e10cSrcweir     return xRet;
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
endDocument()193cdf0e10cSrcweir void SAL_CALL SlideFragmentHandler::endDocument(  ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException)
194cdf0e10cSrcweir {
195cdf0e10cSrcweir     try
196cdf0e10cSrcweir     {
197cdf0e10cSrcweir         Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
198cdf0e10cSrcweir         PropertySet aSlideProp( xSlide );
199cdf0e10cSrcweir         aSlideProp.setProperties( maSlideProperties );
200cdf0e10cSrcweir         if ( maSlideName.getLength() )
201cdf0e10cSrcweir         {
202cdf0e10cSrcweir             Reference< XNamed > xNamed( xSlide, UNO_QUERY );
203cdf0e10cSrcweir             if( xNamed.is() )
204cdf0e10cSrcweir                 xNamed->setName( maSlideName );
205cdf0e10cSrcweir         }
206cdf0e10cSrcweir     }
207cdf0e10cSrcweir     catch( uno::Exception& )
208cdf0e10cSrcweir     {
209cdf0e10cSrcweir         OSL_ENSURE( false,
210cdf0e10cSrcweir             (rtl::OString("oox::ppt::SlideFragmentHandler::EndElement(), "
211cdf0e10cSrcweir                     "exception caught: ") +
212cdf0e10cSrcweir             rtl::OUStringToOString(
213cdf0e10cSrcweir                 comphelper::anyToString( cppu::getCaughtException() ),
214cdf0e10cSrcweir                 RTL_TEXTENCODING_UTF8 )).getStr() );
215cdf0e10cSrcweir     }
216cdf0e10cSrcweir }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir } }
219