Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / oox / source / ppt / slidefragmenthandler.cxx
blob615665d8ae3c64da06c9ecf577a1f7f610f43133
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>
26 #include <sal/log.hxx>
27 #include <tools/diagnose_ex.h>
29 #include <oox/helper/attributelist.hxx>
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 <drawingml/clrschemecontext.hxx>
43 #include <drawingml/textliststyle.hxx>
44 #include <oox/ppt/pptimport.hxx>
45 #include <oox/token/namespaces.hxx>
46 #include <oox/token/properties.hxx>
47 #include <oox/token/tokens.hxx>
49 using namespace ::com::sun::star;
50 using namespace ::oox::core;
51 using namespace ::oox::drawingml;
52 using namespace ::com::sun::star::uno;
53 using namespace ::com::sun::star::drawing;
54 using namespace ::com::sun::star::xml::sax;
55 using namespace ::com::sun::star::container;
57 namespace oox { namespace ppt {
59 SlideFragmentHandler::SlideFragmentHandler( XmlFilterBase& rFilter, const OUString& rFragmentPath, const SlidePersistPtr& pPersistPtr, const ShapeLocation eShapeLocation )
60 : FragmentHandler2( rFilter, rFragmentPath )
61 , mpSlidePersistPtr( pPersistPtr )
62 , meShapeLocation( eShapeLocation )
64 OUString aVMLDrawingFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( "vmlDrawing" );
65 if( !aVMLDrawingFragmentPath.isEmpty() )
66 getFilter().importFragment( new oox::vml::DrawingFragment(
67 getFilter(), aVMLDrawingFragmentPath, *pPersistPtr->getDrawing() ) );
70 SlideFragmentHandler::~SlideFragmentHandler()
72 // convert and insert all VML shapes (mostly form controls)
73 mpSlidePersistPtr->getDrawing()->convertAndInsert();
76 ::oox::core::ContextHandlerRef SlideFragmentHandler::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
78 switch( aElementToken )
80 case PPT_TOKEN( sldMaster ): // CT_SlideMaster
81 case PPT_TOKEN( handoutMaster ): // CT_HandoutMaster
82 case PPT_TOKEN( sld ): // CT_CommonSlideData
84 Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
85 PropertyMap aPropMap;
86 PropertySet aSlideProp( xSlide );
88 aPropMap.setProperty( PROP_Visible, rAttribs.getBool( XML_show, true ));
89 aSlideProp.setProperties( aPropMap );
91 return this;
93 case PPT_TOKEN( notes ): // CT_NotesSlide
95 // Import notesMaster
96 PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() );
97 OUString aNotesFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( "notesMaster" );
99 std::vector< SlidePersistPtr >& rMasterPages( rFilter.getMasterPages() );
100 bool bNotesFragmentPathFound = false;
101 for (auto const& masterPage : rMasterPages)
103 if( masterPage->getPath() == aNotesFragmentPath )
105 if( !mpSlidePersistPtr->getMasterPersist() )
106 mpSlidePersistPtr->setMasterPersist(masterPage);
107 bNotesFragmentPathFound=true;
108 break;
111 if( !bNotesFragmentPathFound && !mpSlidePersistPtr->getMasterPersist() )
113 TextListStylePtr pTextListStyle(new TextListStyle);
114 SlidePersistPtr pMasterPersistPtr = std::make_shared<SlidePersist>( rFilter, true, true, mpSlidePersistPtr->getPage(),
115 ShapePtr( new PPTShape( Master, "com.sun.star.drawing.GroupShape" ) ), mpSlidePersistPtr->getNotesTextStyle() );
116 pMasterPersistPtr->setPath( aNotesFragmentPath );
117 rFilter.getMasterPages().push_back( pMasterPersistPtr );
118 FragmentHandlerRef xMasterFragmentHandler( new SlideFragmentHandler( rFilter, aNotesFragmentPath, pMasterPersistPtr, Master ) );
119 rFilter.importFragment( xMasterFragmentHandler );
120 mpSlidePersistPtr->setMasterPersist( pMasterPersistPtr );
122 return this;
124 case PPT_TOKEN( notesMaster ): // CT_NotesMaster
125 return this;
126 case PPT_TOKEN( cSld ): // CT_CommonSlideData
127 maSlideName = rAttribs.getString(XML_name, OUString());
128 return this;
130 case PPT_TOKEN( spTree ): // CT_GroupShape
132 // TODO Convert this to FragmentHandler2
133 return new PPTShapeGroupContext(
134 *this, mpSlidePersistPtr, meShapeLocation, mpSlidePersistPtr->getShapes(),
135 oox::drawingml::ShapePtr( new PPTShape( meShapeLocation, "com.sun.star.drawing.GroupShape" ) ) );
137 break;
139 case PPT_TOKEN( controls ):
140 return this;
141 case PPT_TOKEN( control ):
143 ::oox::vml::ControlInfo aInfo;
144 aInfo.setShapeId( rAttribs.getInteger( XML_spid, 0 ) );
145 aInfo.maFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
146 aInfo.maName = rAttribs.getXString( XML_name, OUString() );
147 mpSlidePersistPtr->getDrawing()->registerControl( aInfo );
149 return this;
151 case PPT_TOKEN( timing ): // CT_SlideTiming
152 return new SlideTimingContext( *this, mpSlidePersistPtr->getTimeNodeList() );
153 case PPT_TOKEN( transition ): // CT_SlideTransition
154 return new SlideTransitionContext( *this, rAttribs, maSlideProperties );
155 case PPT_TOKEN( hf ):
156 return new HeaderFooterContext( *this, rAttribs, mpSlidePersistPtr->getHeaderFooter() );
158 // BackgroundGroup
159 case PPT_TOKEN( bg ):
160 return this;
161 case PPT_TOKEN( bgPr ): // CT_BackgroundProperties
163 FillPropertiesPtr pFillPropertiesPtr( new FillProperties );
164 mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
165 return new BackgroundPropertiesContext( *this, *pFillPropertiesPtr );
167 break;
169 case PPT_TOKEN( bgRef ): // a:CT_StyleMatrixReference
171 const FillProperties *pFillProperties = nullptr;
172 if( mpSlidePersistPtr->getTheme() )
173 pFillProperties = mpSlidePersistPtr->getTheme()->getFillStyle( rAttribs.getInteger( XML_idx, -1 ) );
174 FillPropertiesPtr pFillPropertiesPtr( pFillProperties ? new FillProperties( *pFillProperties ) : new FillProperties );
175 mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
176 ContextHandlerRef ret = new ColorContext( *this, mpSlidePersistPtr->getBackgroundColor() );
177 return ret;
179 break;
181 case A_TOKEN( overrideClrMapping ):
182 case PPT_TOKEN( clrMap ): // CT_ColorMapping
184 oox::drawingml::ClrMapPtr pClrMapPtr( ( aElementToken == PPT_TOKEN( clrMap ) || !mpSlidePersistPtr.get() || !mpSlidePersistPtr->getClrMap().get() ) ? new oox::drawingml::ClrMap : new oox::drawingml::ClrMap( *mpSlidePersistPtr->getClrMap() ) );
185 ContextHandlerRef ret = new oox::drawingml::clrMapContext( *this, rAttribs, *pClrMapPtr );
186 mpSlidePersistPtr->setClrMap( pClrMapPtr );
187 return ret;
189 break;
190 case PPT_TOKEN( clrMapOvr ): // CT_ColorMappingOverride
191 case PPT_TOKEN( sldLayoutIdLst ): // CT_SlideLayoutIdList
192 return this;
193 case PPT_TOKEN( txStyles ): // CT_SlideMasterTextStyles
194 return new SlideMasterTextStylesContext( *this, mpSlidePersistPtr );
195 case PPT_TOKEN( custDataLst ): // CT_CustomerDataList
196 case PPT_TOKEN( tagLst ): // CT_TagList
197 return this;
199 //for Comments
200 case PPT_TOKEN( cmLst ):
201 break;
202 case PPT_TOKEN( cm ):
203 if (!mpSlidePersistPtr->getCommentsList().cmLst.empty() && !getCharVector().empty())
205 // set comment text for earlier comment
206 mpSlidePersistPtr->getCommentsList().cmLst.back().setText( getCharVector().back() );
208 // insert a new comment in vector commentsList
209 mpSlidePersistPtr->getCommentsList().cmLst.emplace_back();
210 mpSlidePersistPtr->getCommentsList().cmLst.back().setAuthorId(rAttribs.getString(XML_authorId, OUString()));
211 mpSlidePersistPtr->getCommentsList().cmLst.back().setdt(rAttribs.getString(XML_dt, OUString()));
212 mpSlidePersistPtr->getCommentsList().cmLst.back().setidx(rAttribs.getString(XML_idx, OUString()));
213 break;
215 case PPT_TOKEN( pos ):
216 mpSlidePersistPtr->getCommentsList().cmLst.back().setPoint(
217 rAttribs.getString(XML_x, OUString()),
218 rAttribs.getString(XML_y, OUString()));
219 break;
221 case PPT_TOKEN( cmAuthor ):
222 CommentAuthor _author;
223 _author.clrIdx = rAttribs.getString(XML_clrIdx, OUString());
224 _author.id = rAttribs.getString(XML_id, OUString());
225 _author.initials = rAttribs.getString(XML_initials, OUString());
226 _author.lastIdx = rAttribs.getString(XML_lastIdx, OUString());
227 _author.name = rAttribs.getString(XML_name, OUString());
228 mpSlidePersistPtr->getCommentAuthors().addAuthor(_author);
229 break;
232 return this;
234 void SlideFragmentHandler::onCharacters( const OUString& rChars)
236 maCharVector.push_back(rChars);
238 void SlideFragmentHandler::finalizeImport()
242 Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
243 PropertySet aSlideProp( xSlide );
244 aSlideProp.setProperties( maSlideProperties );
245 if ( !maSlideName.isEmpty() )
247 Reference< XNamed > xNamed( xSlide, UNO_QUERY );
248 if( xNamed.is() )
249 xNamed->setName( maSlideName );
252 catch( uno::Exception& )
254 TOOLS_WARN_EXCEPTION( "oox", "oox::ppt::SlideFragmentHandler::EndElement()" );
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */