1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <com/sun/star/beans/XPropertySet.hpp>
21 #include <com/sun/star/container/XNamed.hpp>
22 #include <com/sun/star/drawing/XDrawPage.hpp>
23 #include <comphelper/diagnose_ex.hxx>
25 #include <oox/helper/attributelist.hxx>
26 #include <oox/helper/propertyset.hxx>
27 #include <oox/core/xmlfilterbase.hxx>
28 #include "headerfootercontext.hxx"
29 #include <oox/ppt/backgroundproperties.hxx>
30 #include <oox/ppt/slidefragmenthandler.hxx>
31 #include <oox/ppt/slidetimingcontext.hxx>
32 #include <oox/ppt/slidetransitioncontext.hxx>
33 #include <oox/ppt/slidemastertextstylescontext.hxx>
34 #include <oox/ppt/pptshapegroupcontext.hxx>
35 #include <oox/ppt/pptshape.hxx>
36 #include <oox/vml/vmldrawing.hxx>
37 #include <oox/vml/vmldrawingfragment.hxx>
38 #include <drawingml/clrschemecontext.hxx>
39 #include <drawingml/fillproperties.hxx>
40 #include <oox/ppt/pptimport.hxx>
41 #include <oox/token/namespaces.hxx>
42 #include <oox/token/properties.hxx>
43 #include <oox/token/tokens.hxx>
45 using namespace ::com::sun::star
;
46 using namespace ::oox::core
;
47 using namespace ::oox::drawingml
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::drawing
;
50 using namespace ::com::sun::star::xml::sax
;
51 using namespace ::com::sun::star::container
;
55 SlideFragmentHandler::SlideFragmentHandler( XmlFilterBase
& rFilter
, const OUString
& rFragmentPath
, const SlidePersistPtr
& pPersistPtr
, const ShapeLocation eShapeLocation
)
56 : FragmentHandler2( rFilter
, rFragmentPath
)
57 , mpSlidePersistPtr( pPersistPtr
)
58 , meShapeLocation( eShapeLocation
)
60 OUString aVMLDrawingFragmentPath
= getFragmentPathFromFirstTypeFromOfficeDoc( u
"vmlDrawing" );
61 if( !aVMLDrawingFragmentPath
.isEmpty() )
62 getFilter().importFragment( new oox::vml::DrawingFragment(
63 getFilter(), aVMLDrawingFragmentPath
, *pPersistPtr
->getDrawing() ) );
66 SlideFragmentHandler::~SlideFragmentHandler()
68 // convert and insert all VML shapes (mostly form controls)
69 mpSlidePersistPtr
->getDrawing()->convertAndInsert();
72 ::oox::core::ContextHandlerRef
SlideFragmentHandler::onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
)
74 switch( aElementToken
)
76 case PPT_TOKEN( sldMaster
): // CT_SlideMaster
77 case PPT_TOKEN( handoutMaster
): // CT_HandoutMaster
78 case PPT_TOKEN( sld
): // CT_CommonSlideData
80 Reference
< XDrawPage
> xSlide( mpSlidePersistPtr
->getPage() );
81 Reference
< css::beans::XPropertySet
> xSet(xSlide
, UNO_QUERY
);
83 PropertySet
aSlideProp( xSlide
);
85 std::optional
<bool> aShowMasterShapes
= rAttribs
.getBool(XML_showMasterSp
);
86 if (aShowMasterShapes
.has_value() && !aShowMasterShapes
.value())
87 xSet
->setPropertyValue(u
"IsBackgroundObjectsVisible"_ustr
, Any(false));
89 aPropMap
.setProperty( PROP_Visible
, rAttribs
.getBool( XML_show
, true ));
90 aSlideProp
.setProperties( aPropMap
);
94 case PPT_TOKEN( notes
): // CT_NotesSlide
97 PowerPointImport
& rFilter
= dynamic_cast< PowerPointImport
& >( getFilter() );
98 OUString aNotesFragmentPath
= getFragmentPathFromFirstTypeFromOfficeDoc( u
"notesMaster" );
100 std::vector
< SlidePersistPtr
>& rMasterPages( rFilter
.getMasterPages() );
101 bool bNotesFragmentPathFound
= false;
102 for (auto const& masterPage
: rMasterPages
)
104 if( masterPage
->getPath() == aNotesFragmentPath
)
106 if( !mpSlidePersistPtr
->getMasterPersist() )
107 mpSlidePersistPtr
->setMasterPersist(masterPage
);
108 bNotesFragmentPathFound
=true;
112 if( !bNotesFragmentPathFound
&& !mpSlidePersistPtr
->getMasterPersist() )
114 SlidePersistPtr pMasterPersistPtr
= std::make_shared
<SlidePersist
>( rFilter
, true, true, mpSlidePersistPtr
->getPage(),
115 std::make_shared
<PPTShape
>( Master
, u
"com.sun.star.drawing.GroupShape"_ustr
), 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
);
124 case PPT_TOKEN( notesMaster
): // CT_NotesMaster
126 case PPT_TOKEN( cSld
): // CT_CommonSlideData
127 maSlideName
= rAttribs
.getStringDefaulted(XML_name
);
130 case PPT_TOKEN( spTree
): // CT_GroupShape
132 return new PPTShapeGroupContext(
133 *this, mpSlidePersistPtr
, meShapeLocation
, mpSlidePersistPtr
->getShapes(),
134 std::make_shared
<PPTShape
>( meShapeLocation
, u
"com.sun.star.drawing.GroupShape"_ustr
) );
138 case PPT_TOKEN( controls
):
140 case PPT_TOKEN( control
):
142 ::oox::vml::ControlInfo aInfo
;
143 aInfo
.setShapeId( rAttribs
.getInteger( XML_spid
, 0 ) );
144 aInfo
.maFragmentPath
= getFragmentPathFromRelId( rAttribs
.getStringDefaulted( R_TOKEN( id
)) );
145 aInfo
.maName
= rAttribs
.getXString( XML_name
, OUString() );
146 mpSlidePersistPtr
->getDrawing()->registerControl( aInfo
);
150 case PPT_TOKEN( timing
): // CT_SlideTiming
151 return new SlideTimingContext( *this, mpSlidePersistPtr
->getTimeNodeList() );
152 case PPT_TOKEN( transition
): // CT_SlideTransition
153 return new SlideTransitionContext( *this, rAttribs
, maSlideProperties
);
154 case PPT_TOKEN( hf
):
155 return new HeaderFooterContext( *this, rAttribs
, mpSlidePersistPtr
->getHeaderFooter() );
158 case PPT_TOKEN( bg
):
160 case PPT_TOKEN( bgPr
): // CT_BackgroundProperties
162 FillPropertiesPtr pFillPropertiesPtr
=std::make_shared
<FillProperties
>();
163 mpSlidePersistPtr
->setBackgroundProperties( pFillPropertiesPtr
);
164 return new BackgroundPropertiesContext( *this, *pFillPropertiesPtr
);
168 case PPT_TOKEN( bgRef
): // a:CT_StyleMatrixReference
170 const FillProperties
*pFillProperties
= nullptr;
171 if( mpSlidePersistPtr
->getTheme() )
172 pFillProperties
= mpSlidePersistPtr
->getTheme()->getFillStyle( rAttribs
.getInteger( XML_idx
, -1 ) );
173 FillPropertiesPtr pFillPropertiesPtr
=
175 ? std::make_shared
<FillProperties
>( *pFillProperties
)
176 : std::make_shared
<FillProperties
>();
177 mpSlidePersistPtr
->setBackgroundProperties( pFillPropertiesPtr
);
178 ContextHandlerRef ret
= new ColorContext( *this, mpSlidePersistPtr
->getBackgroundColor() );
183 case A_TOKEN( overrideClrMapping
):
184 case PPT_TOKEN( clrMap
): // CT_ColorMapping
186 oox::drawingml::ClrMapPtr pClrMapPtr
=
187 ( aElementToken
== PPT_TOKEN( clrMap
) || !mpSlidePersistPtr
|| !mpSlidePersistPtr
->getClrMap() )
188 ? std::make_shared
<oox::drawingml::ClrMap
>()
189 : std::make_shared
<oox::drawingml::ClrMap
>( *mpSlidePersistPtr
->getClrMap() );
190 ContextHandlerRef ret
= new oox::drawingml::clrMapContext( *this, rAttribs
, *pClrMapPtr
);
191 mpSlidePersistPtr
->setClrMap( pClrMapPtr
);
195 case PPT_TOKEN( clrMapOvr
): // CT_ColorMappingOverride
196 case PPT_TOKEN( sldLayoutIdLst
): // CT_SlideLayoutIdList
198 case PPT_TOKEN( txStyles
): // CT_SlideMasterTextStyles
199 return new SlideMasterTextStylesContext( *this, mpSlidePersistPtr
);
200 case PPT_TOKEN( custDataLst
): // CT_CustomerDataList
201 case PPT_TOKEN( tagLst
): // CT_TagList
205 case PPT_TOKEN( cmLst
):
207 case PPT_TOKEN( cm
):
208 if (!mpSlidePersistPtr
->getCommentsList().cmLst
.empty() && !getCharVector().empty())
210 // set comment text for earlier comment
211 mpSlidePersistPtr
->getCommentsList().cmLst
.back().setText( getCharVector().back() );
213 // insert a new comment in vector commentsList
214 mpSlidePersistPtr
->getCommentsList().cmLst
.emplace_back();
215 mpSlidePersistPtr
->getCommentsList().cmLst
.back().setAuthorId(rAttribs
.getStringDefaulted(XML_authorId
));
216 mpSlidePersistPtr
->getCommentsList().cmLst
.back().setdt(rAttribs
.getStringDefaulted(XML_dt
));
217 mpSlidePersistPtr
->getCommentsList().cmLst
.back().setidx(rAttribs
.getStringDefaulted(XML_idx
));
220 case PPT_TOKEN( pos
):
221 mpSlidePersistPtr
->getCommentsList().cmLst
.back().setPoint(
222 rAttribs
.getStringDefaulted(XML_x
),
223 rAttribs
.getStringDefaulted(XML_y
));
226 case PPT_TOKEN( cmAuthor
):
227 CommentAuthor _author
;
228 _author
.clrIdx
= rAttribs
.getStringDefaulted(XML_clrIdx
);
229 _author
.id
= rAttribs
.getStringDefaulted(XML_id
);
230 _author
.initials
= rAttribs
.getStringDefaulted(XML_initials
);
231 _author
.lastIdx
= rAttribs
.getStringDefaulted(XML_lastIdx
);
232 _author
.name
= rAttribs
.getStringDefaulted(XML_name
);
233 mpSlidePersistPtr
->getCommentAuthors().addAuthor(_author
);
239 void SlideFragmentHandler::onCharacters( const OUString
& rChars
)
241 maCharVector
.push_back(rChars
);
243 void SlideFragmentHandler::finalizeImport()
247 Reference
< XDrawPage
> xSlide( mpSlidePersistPtr
->getPage() );
248 PropertySet
aSlideProp( xSlide
);
249 aSlideProp
.setProperties( maSlideProperties
);
250 if ( !maSlideName
.isEmpty() )
252 Reference
< XNamed
> xNamed( xSlide
, UNO_QUERY
);
254 xNamed
->setName( maSlideName
);
257 catch( uno::Exception
& )
259 TOOLS_WARN_EXCEPTION( "oox", "oox::ppt::SlideFragmentHandler::EndElement()" );
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */