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
10ca5ec200SAndrew Rist  *
11ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ca5ec200SAndrew Rist  *
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.
19ca5ec200SAndrew Rist  *
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 	{
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 		{
144*deebd566SJürgen Schmidt             oox::drawingml::ThemePtr pTheme = mpSlidePersistPtr->getTheme();
145*deebd566SJürgen Schmidt             if (pTheme)
146*deebd566SJürgen Schmidt             {
147*deebd566SJürgen Schmidt                 FillPropertiesPtr pFillPropertiesPtr( new FillProperties(
148*deebd566SJürgen Schmidt 				    *pTheme->getFillStyle( xAttribs->getOptionalValue( XML_idx ).toInt32() ) ) );
149*deebd566SJürgen Schmidt                 mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
150*deebd566SJürgen Schmidt             }
151*deebd566SJürgen Schmidt             xRet.set( new ColorContext( *this, mpSlidePersistPtr->getBackgroundColor() ) );
152*deebd566SJürgen Schmidt 
153cdf0e10cSrcweir 		}
154cdf0e10cSrcweir 		break;
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 	case PPT_TOKEN( clrMap ):			// CT_ColorMapping
157cdf0e10cSrcweir 		{
158cdf0e10cSrcweir 			oox::drawingml::ClrMapPtr pClrMapPtr( new oox::drawingml::ClrMap() );
159cdf0e10cSrcweir             xRet.set( new oox::drawingml::clrMapContext( *this, xAttribs, *pClrMapPtr ) );
160cdf0e10cSrcweir 			mpSlidePersistPtr->setClrMap( pClrMapPtr );
161cdf0e10cSrcweir 		}
162cdf0e10cSrcweir 		break;
163cdf0e10cSrcweir 	case PPT_TOKEN( clrMapOvr ):		// CT_ColorMappingOverride
164cdf0e10cSrcweir 	case PPT_TOKEN( sldLayoutIdLst ):	// CT_SlideLayoutIdList
165cdf0e10cSrcweir 		break;
166cdf0e10cSrcweir 	case PPT_TOKEN( txStyles ):			// CT_SlideMasterTextStyles
167cdf0e10cSrcweir         xRet.set( new SlideMasterTextStylesContext( *this, mpSlidePersistPtr ) );
168cdf0e10cSrcweir 		break;
169cdf0e10cSrcweir 	case PPT_TOKEN( custDataLst ):		// CT_CustomerDataList
170cdf0e10cSrcweir 	case PPT_TOKEN( tagLst ):			// CT_TagList
171cdf0e10cSrcweir 		break;
172cdf0e10cSrcweir 	}
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 	if( !xRet.is() )
175cdf0e10cSrcweir         xRet = getFastContextHandler();
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 	return xRet;
178cdf0e10cSrcweir }
179cdf0e10cSrcweir 
endDocument()180cdf0e10cSrcweir void SAL_CALL SlideFragmentHandler::endDocument(  ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException)
181cdf0e10cSrcweir {
182cdf0e10cSrcweir 	try
183cdf0e10cSrcweir 	{
184cdf0e10cSrcweir 		Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
185cdf0e10cSrcweir         PropertySet aSlideProp( xSlide );
186cdf0e10cSrcweir         aSlideProp.setProperties( maSlideProperties );
187cdf0e10cSrcweir 		if ( maSlideName.getLength() )
188cdf0e10cSrcweir 		{
189cdf0e10cSrcweir 			Reference< XNamed > xNamed( xSlide, UNO_QUERY );
190cdf0e10cSrcweir 			if( xNamed.is() )
191cdf0e10cSrcweir 				xNamed->setName( maSlideName );
192cdf0e10cSrcweir 		}
193cdf0e10cSrcweir 	}
194cdf0e10cSrcweir 	catch( uno::Exception& )
195cdf0e10cSrcweir 	{
196cdf0e10cSrcweir         OSL_ENSURE( false,
197cdf0e10cSrcweir 			(rtl::OString("oox::ppt::SlideFragmentHandler::EndElement(), "
198cdf0e10cSrcweir 					"exception caught: ") +
199cdf0e10cSrcweir 			rtl::OUStringToOString(
200cdf0e10cSrcweir 				comphelper::anyToString( cppu::getCaughtException() ),
201cdf0e10cSrcweir 				RTL_TEXTENCODING_UTF8 )).getStr() );
202cdf0e10cSrcweir 	}
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir } }
206cdf0e10cSrcweir 
207