Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / oox / source / ppt / slidefragmenthandler.cxx
blobc9af6b5306d3b082106a23e4e036c35976bedbfc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "comphelper/anytostring.hxx"
21 #include "cppuhelper/exc_hlp.hxx"
23 #include <com/sun/star/beans/XMultiPropertySet.hpp>
24 #include <com/sun/star/container/XNamed.hpp>
25 #include <osl/diagnose.h>
27 #include <oox/helper/attributelist.hxx>
28 #include "oox/helper/propertyset.hxx"
29 #include "oox/core/xmlfilterbase.hxx"
30 #include "headerfootercontext.hxx"
31 #include "oox/ppt/backgroundproperties.hxx"
32 #include "oox/ppt/slidefragmenthandler.hxx"
33 #include "oox/ppt/slidetimingcontext.hxx"
34 #include "oox/ppt/slidetransitioncontext.hxx"
35 #include "oox/ppt/slidemastertextstylescontext.hxx"
36 #include "oox/ppt/pptshapegroupcontext.hxx"
37 #include "oox/ppt/pptshape.hxx"
38 #include "oox/vml/vmldrawing.hxx"
39 #include "oox/vml/vmldrawingfragment.hxx"
40 #include "drawingml/clrschemecontext.hxx"
41 #include "drawingml/textliststyle.hxx"
42 #include "oox/ppt/pptimport.hxx"
43 #include <oox/token/namespaces.hxx>
44 #include <oox/token/properties.hxx>
45 #include <oox/token/tokens.hxx>
47 using namespace ::com::sun::star;
48 using namespace ::oox::core;
49 using namespace ::oox::drawingml;
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::drawing;
52 using namespace ::com::sun::star::xml::sax;
53 using namespace ::com::sun::star::container;
55 namespace oox { namespace ppt {
57 SlideFragmentHandler::SlideFragmentHandler( XmlFilterBase& rFilter, const OUString& rFragmentPath, SlidePersistPtr pPersistPtr, const ShapeLocation eShapeLocation )
58 : FragmentHandler2( rFilter, rFragmentPath )
59 , mpSlidePersistPtr( pPersistPtr )
60 , meShapeLocation( eShapeLocation )
62 OUString aVMLDrawingFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( "vmlDrawing" );
63 if( !aVMLDrawingFragmentPath.isEmpty() )
64 getFilter().importFragment( new oox::vml::DrawingFragment(
65 getFilter(), aVMLDrawingFragmentPath, *pPersistPtr->getDrawing() ) );
68 SlideFragmentHandler::~SlideFragmentHandler()
70 // convert and insert all VML shapes (mostly form controls)
71 mpSlidePersistPtr->getDrawing()->convertAndInsert();
74 ::oox::core::ContextHandlerRef SlideFragmentHandler::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
76 switch( aElementToken )
78 case PPT_TOKEN( sldMaster ): // CT_SlideMaster
79 case PPT_TOKEN( handoutMaster ): // CT_HandoutMaster
80 case PPT_TOKEN( sld ): // CT_CommonSlideData
82 Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
83 PropertyMap aPropMap;
84 PropertySet aSlideProp( xSlide );
86 aPropMap.setProperty( PROP_Visible, rAttribs.getBool( XML_show, true ));
87 aSlideProp.setProperties( aPropMap );
89 return this;
91 case PPT_TOKEN( notes ): // CT_NotesSlide
93 // Import notesMaster
94 PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() );
95 OUString aNotesFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( "notesMaster" );
97 std::vector< SlidePersistPtr >& rMasterPages( rFilter.getMasterPages() );
98 std::vector< SlidePersistPtr >::iterator aIter( rMasterPages.begin() );
99 while( aIter != rMasterPages.end() )
101 if( (*aIter)->getPath() == aNotesFragmentPath )
103 if( !mpSlidePersistPtr->getMasterPersist() )
104 mpSlidePersistPtr->setMasterPersist( *aIter );
105 break;
107 ++aIter;
109 if( aIter == rMasterPages.end() && !mpSlidePersistPtr->getMasterPersist() )
111 TextListStylePtr pTextListStyle(new TextListStyle);
112 SlidePersistPtr pMasterPersistPtr = std::make_shared<SlidePersist>( rFilter, true, true, mpSlidePersistPtr->getPage(),
113 ShapePtr( new PPTShape( Master, "com.sun.star.drawing.GroupShape" ) ), mpSlidePersistPtr->getNotesTextStyle() );
114 pMasterPersistPtr->setPath( aNotesFragmentPath );
115 rFilter.getMasterPages().push_back( pMasterPersistPtr );
116 FragmentHandlerRef xMasterFragmentHandler( new SlideFragmentHandler( rFilter, aNotesFragmentPath, pMasterPersistPtr, Master ) );
117 rFilter.importFragment( xMasterFragmentHandler );
118 mpSlidePersistPtr->setMasterPersist( pMasterPersistPtr );
120 return this;
122 case PPT_TOKEN( notesMaster ): // CT_NotesMaster
123 return this;
124 case PPT_TOKEN( cSld ): // CT_CommonSlideData
125 maSlideName = rAttribs.getString(XML_name, OUString());
126 return this;
128 case PPT_TOKEN( spTree ): // CT_GroupShape
130 // TODO Convert this to FragmentHandler2
131 return new PPTShapeGroupContext(
132 *this, mpSlidePersistPtr, meShapeLocation, mpSlidePersistPtr->getShapes(),
133 oox::drawingml::ShapePtr( new PPTShape( meShapeLocation, "com.sun.star.drawing.GroupShape" ) ) );
135 break;
137 case PPT_TOKEN( controls ):
138 return this;
139 case PPT_TOKEN( control ):
141 ::oox::vml::ControlInfo aInfo;
142 aInfo.setShapeId( rAttribs.getInteger( XML_spid, 0 ) );
143 aInfo.maFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
144 aInfo.maName = rAttribs.getXString( XML_name, OUString() );
145 mpSlidePersistPtr->getDrawing()->registerControl( aInfo );
147 return this;
149 case PPT_TOKEN( timing ): // CT_SlideTiming
150 return new SlideTimingContext( *this, mpSlidePersistPtr->getTimeNodeList() );
151 case PPT_TOKEN( transition ): // CT_SlideTransition
152 return new SlideTransitionContext( *this, rAttribs, maSlideProperties );
153 case PPT_TOKEN( hf ):
154 return new HeaderFooterContext( *this, rAttribs, mpSlidePersistPtr->getHeaderFooter() );
156 // BackgroundGroup
157 case PPT_TOKEN( bg ):
158 return this;
159 case PPT_TOKEN( bgPr ): // CT_BackgroundProperties
161 FillPropertiesPtr pFillPropertiesPtr( new FillProperties );
162 mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
163 return new BackgroundPropertiesContext( *this, *pFillPropertiesPtr );
165 break;
167 case PPT_TOKEN( bgRef ): // a:CT_StyleMatrixReference
169 const FillProperties *pFillProperties = nullptr;
170 if( mpSlidePersistPtr->getTheme() )
171 pFillProperties = mpSlidePersistPtr->getTheme()->getFillStyle( rAttribs.getInteger( XML_idx, -1 ) );
172 FillPropertiesPtr pFillPropertiesPtr( pFillProperties ? new FillProperties( *pFillProperties ) : new FillProperties );
173 mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
174 ContextHandlerRef ret = new ColorContext( *this, mpSlidePersistPtr->getBackgroundColor() );
175 return ret;
177 break;
179 case A_TOKEN( overrideClrMapping ):
180 case PPT_TOKEN( clrMap ): // CT_ColorMapping
182 oox::drawingml::ClrMapPtr pClrMapPtr( ( aElementToken == PPT_TOKEN( clrMap ) || !mpSlidePersistPtr.get() || !mpSlidePersistPtr->getClrMap().get() ) ? new oox::drawingml::ClrMap : new oox::drawingml::ClrMap( *mpSlidePersistPtr->getClrMap() ) );
183 ContextHandlerRef ret = new oox::drawingml::clrMapContext( *this, rAttribs, *pClrMapPtr );
184 mpSlidePersistPtr->setClrMap( pClrMapPtr );
185 return ret;
187 break;
188 case PPT_TOKEN( clrMapOvr ): // CT_ColorMappingOverride
189 case PPT_TOKEN( sldLayoutIdLst ): // CT_SlideLayoutIdList
190 return this;
191 case PPT_TOKEN( txStyles ): // CT_SlideMasterTextStyles
192 return new SlideMasterTextStylesContext( *this, mpSlidePersistPtr );
193 case PPT_TOKEN( custDataLst ): // CT_CustomerDataList
194 case PPT_TOKEN( tagLst ): // CT_TagList
195 return this;
197 //for Comments
198 case PPT_TOKEN( cmLst ):
199 break;
200 case PPT_TOKEN( cm ):
201 if (!mpSlidePersistPtr->getCommentsList().cmLst.empty() && !getCharVector().empty())
203 // set comment text for earlier comment
204 mpSlidePersistPtr->getCommentsList().cmLst.back().setText( getCharVector().back() );
206 // insert a new comment in vector commentsList
207 mpSlidePersistPtr->getCommentsList().cmLst.push_back(Comment());
208 mpSlidePersistPtr->getCommentsList().cmLst.back().setAuthorId(rAttribs.getString(XML_authorId, OUString()));
209 mpSlidePersistPtr->getCommentsList().cmLst.back().setdt(rAttribs.getString(XML_dt, OUString()));
210 mpSlidePersistPtr->getCommentsList().cmLst.back().setidx(rAttribs.getString(XML_idx, OUString()));
211 break;
213 case PPT_TOKEN( pos ):
214 mpSlidePersistPtr->getCommentsList().cmLst.back().setPoint(
215 rAttribs.getString(XML_x, OUString()),
216 rAttribs.getString(XML_y, OUString()));
217 break;
219 case PPT_TOKEN( cmAuthor ):
220 CommentAuthor _author;
221 _author.clrIdx = rAttribs.getString(XML_clrIdx, OUString());
222 _author.id = rAttribs.getString(XML_id, OUString());
223 _author.initials = rAttribs.getString(XML_initials, OUString());
224 _author.lastIdx = rAttribs.getString(XML_lastIdx, OUString());
225 _author.name = rAttribs.getString(XML_name, OUString());
226 mpSlidePersistPtr->getCommentAuthors().addAuthor(_author);
227 break;
230 return this;
232 void SlideFragmentHandler::onCharacters( const OUString& rChars)
234 maCharVector.push_back(rChars);
236 void SlideFragmentHandler::finalizeImport()
240 Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
241 PropertySet aSlideProp( xSlide );
242 aSlideProp.setProperties( maSlideProperties );
243 if ( !maSlideName.isEmpty() )
245 Reference< XNamed > xNamed( xSlide, UNO_QUERY );
246 if( xNamed.is() )
247 xNamed->setName( maSlideName );
250 catch( uno::Exception& )
252 OSL_FAIL( OString("oox::ppt::SlideFragmentHandler::EndElement(), "
253 "exception caught: " +
254 OUStringToOString(
255 comphelper::anyToString( cppu::getCaughtException() ),
256 RTL_TEXTENCODING_UTF8 )).getStr());
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */