1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "comphelper/anytostring.hxx"
29 #include "cppuhelper/exc_hlp.hxx"
30 
31 #include <com/sun/star/beans/XMultiPropertySet.hpp>
32 #include <com/sun/star/container/XNamed.hpp>
33 
34 #include "oox/helper/propertyset.hxx"
35 #include "oox/core/xmlfilterbase.hxx"
36 #include "headerfootercontext.hxx"
37 #include "oox/ppt/backgroundproperties.hxx"
38 #include "oox/ppt/slidefragmenthandler.hxx"
39 #include "oox/ppt/slidetimingcontext.hxx"
40 #include "oox/ppt/slidetransitioncontext.hxx"
41 #include "oox/ppt/slidemastertextstylescontext.hxx"
42 #include "oox/ppt/pptshapegroupcontext.hxx"
43 #include "oox/ppt/pptshape.hxx"
44 #include "oox/vml/vmldrawing.hxx"
45 #include "oox/vml/vmldrawingfragment.hxx"
46 #include "oox/drawingml/clrschemecontext.hxx"
47 
48 
49 using rtl::OUString;
50 using namespace ::com::sun::star;
51 using namespace ::oox::core;
52 using namespace ::oox::drawingml;
53 using namespace ::com::sun::star::uno;
54 using namespace ::com::sun::star::drawing;
55 using namespace ::com::sun::star::xml::sax;
56 using namespace ::com::sun::star::container;
57 
58 namespace oox { namespace ppt {
59 
60 SlideFragmentHandler::SlideFragmentHandler( XmlFilterBase& rFilter, const OUString& rFragmentPath, SlidePersistPtr pPersistPtr, const ShapeLocation eShapeLocation ) throw()
61 : FragmentHandler( rFilter, rFragmentPath )
62 , mpSlidePersistPtr( pPersistPtr )
63 , meShapeLocation( eShapeLocation )
64 {
65     OUString aVMLDrawingFragmentPath = getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "vmlDrawing" ) );
66     if( aVMLDrawingFragmentPath.getLength() > 0 )
67         getFilter().importFragment( new oox::vml::DrawingFragment(
68             getFilter(), aVMLDrawingFragmentPath, *pPersistPtr->getDrawing() ) );
69 }
70 
71 SlideFragmentHandler::~SlideFragmentHandler() throw()
72 {
73     // convert and insert all VML shapes (mostly form controls)
74     mpSlidePersistPtr->getDrawing()->convertAndInsert();
75 }
76 
77 Reference< XFastContextHandler > SlideFragmentHandler::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
78 {
79 	Reference< XFastContextHandler > xRet;
80     AttributeList aAttribs( xAttribs );
81 
82 	switch( aElementToken )
83 	{
84 	case PPT_TOKEN( sldMaster ):		// CT_SlideMaster
85 	case PPT_TOKEN( handoutMaster ):	// CT_HandoutMaster
86 	case PPT_TOKEN( sld ):				// CT_CommonSlideData
87 	{
88 	    AttributeList attribs( xAttribs );
89 
90 	    Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
91 	    PropertyMap aPropMap;
92 	    PropertySet aSlideProp( xSlide );
93 
94 	    aPropMap[ PROP_Visible ] = Any( attribs.getBool( XML_show, sal_True ) );
95 	    aSlideProp.setProperties( aPropMap );
96 
97 	    break;
98 	}
99 	case PPT_TOKEN( notes ):			// CT_NotesSlide
100 	case PPT_TOKEN( notesMaster ):		// CT_NotesMaster
101 		break;
102 	case PPT_TOKEN( cSld ):				// CT_CommonSlideData
103 		maSlideName = xAttribs->getOptionalValue(XML_name);
104 		break;
105 
106 	case PPT_TOKEN( spTree ):			// CT_GroupShape
107 		{
108             xRet.set( new PPTShapeGroupContext(
109                 *this, mpSlidePersistPtr, meShapeLocation, mpSlidePersistPtr->getShapes(),
110                 oox::drawingml::ShapePtr( new PPTShape( meShapeLocation, "com.sun.star.drawing.GroupShape" ) ) ) );
111 		}
112 		break;
113 
114     case PPT_TOKEN( controls ):
115         xRet = getFastContextHandler();
116         break;
117     case PPT_TOKEN( control ):
118         {
119             ::oox::vml::ControlInfo aInfo;
120             aInfo.setShapeId( aAttribs.getInteger( XML_spid, 0 ) );
121             aInfo.maFragmentPath = getFragmentPathFromRelId( aAttribs.getString( R_TOKEN( id ), OUString() ) );
122             aInfo.maName = aAttribs.getXString( XML_name, OUString() );
123             mpSlidePersistPtr->getDrawing()->registerControl( aInfo );
124         }
125         return xRet;
126 
127 	case PPT_TOKEN( timing ): // CT_SlideTiming
128         xRet.set( new SlideTimingContext( *this, mpSlidePersistPtr->getTimeNodeList() ) );
129 		break;
130 	case PPT_TOKEN( transition ): // CT_SlideTransition
131         xRet.set( new SlideTransitionContext( *this, xAttribs, maSlideProperties ) );
132 		break;
133 	case PPT_TOKEN( hf ):
134 		xRet.set( new HeaderFooterContext( *this, xAttribs, mpSlidePersistPtr->getHeaderFooter() ) );
135 		break;
136 
137 	// BackgroundGroup
138 	case PPT_TOKEN( bgPr ):				// CT_BackgroundProperties
139 		{
140             FillPropertiesPtr pFillPropertiesPtr( new FillProperties );
141             xRet.set( new BackgroundPropertiesContext( *this, *pFillPropertiesPtr ) );
142 			mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
143 		}
144 		break;
145 
146 	case PPT_TOKEN( bgRef ):			// a:CT_StyleMatrixReference
147 		{
148 			FillPropertiesPtr pFillPropertiesPtr( new FillProperties(
149 				*mpSlidePersistPtr->getTheme()->getFillStyle( xAttribs->getOptionalValue( XML_idx ).toInt32() ) ) );
150 			xRet.set( new ColorContext( *this, mpSlidePersistPtr->getBackgroundColor() ) );
151 			mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
152 		}
153 		break;
154 
155 	case PPT_TOKEN( clrMap ):			// CT_ColorMapping
156 		{
157 			oox::drawingml::ClrMapPtr pClrMapPtr( new oox::drawingml::ClrMap() );
158             xRet.set( new oox::drawingml::clrMapContext( *this, xAttribs, *pClrMapPtr ) );
159 			mpSlidePersistPtr->setClrMap( pClrMapPtr );
160 		}
161 		break;
162 	case PPT_TOKEN( clrMapOvr ):		// CT_ColorMappingOverride
163 	case PPT_TOKEN( sldLayoutIdLst ):	// CT_SlideLayoutIdList
164 		break;
165 	case PPT_TOKEN( txStyles ):			// CT_SlideMasterTextStyles
166         xRet.set( new SlideMasterTextStylesContext( *this, mpSlidePersistPtr ) );
167 		break;
168 	case PPT_TOKEN( custDataLst ):		// CT_CustomerDataList
169 	case PPT_TOKEN( tagLst ):			// CT_TagList
170 		break;
171 	}
172 
173 	if( !xRet.is() )
174         xRet = getFastContextHandler();
175 
176 	return xRet;
177 }
178 
179 void SAL_CALL SlideFragmentHandler::endDocument(  ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException)
180 {
181 	try
182 	{
183 		Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
184         PropertySet aSlideProp( xSlide );
185         aSlideProp.setProperties( maSlideProperties );
186 		if ( maSlideName.getLength() )
187 		{
188 			Reference< XNamed > xNamed( xSlide, UNO_QUERY );
189 			if( xNamed.is() )
190 				xNamed->setName( maSlideName );
191 		}
192 	}
193 	catch( uno::Exception& )
194 	{
195         OSL_ENSURE( false,
196 			(rtl::OString("oox::ppt::SlideFragmentHandler::EndElement(), "
197 					"exception caught: ") +
198 			rtl::OUStringToOString(
199 				comphelper::anyToString( cppu::getCaughtException() ),
200 				RTL_TEXTENCODING_UTF8 )).getStr() );
201 	}
202 }
203 
204 } }
205 
206