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