LibreOffice Module oox (master) 1
slidefragmenthandler.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <com/sun/star/beans/XPropertySet.hpp>
21#include <com/sun/star/container/XNamed.hpp>
22#include <com/sun/star/drawing/XDrawPage.hpp>
24
35#include <oox/ppt/pptshape.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>
44
45using namespace ::com::sun::star;
46using namespace ::oox::core;
47using namespace ::oox::drawingml;
48using namespace ::com::sun::star::uno;
49using namespace ::com::sun::star::drawing;
50using namespace ::com::sun::star::xml::sax;
51using namespace ::com::sun::star::container;
52
53namespace oox::ppt {
54
55SlideFragmentHandler::SlideFragmentHandler( XmlFilterBase& rFilter, const OUString& rFragmentPath, const SlidePersistPtr& pPersistPtr, const ShapeLocation eShapeLocation )
56: FragmentHandler2( rFilter, rFragmentPath )
57, mpSlidePersistPtr( pPersistPtr )
58, meShapeLocation( eShapeLocation )
59{
60 OUString aVMLDrawingFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( u"vmlDrawing" );
61 if( !aVMLDrawingFragmentPath.isEmpty() )
62 getFilter().importFragment( new oox::vml::DrawingFragment(
63 getFilter(), aVMLDrawingFragmentPath, *pPersistPtr->getDrawing() ) );
64}
65
67{
68 // convert and insert all VML shapes (mostly form controls)
69 mpSlidePersistPtr->getDrawing()->convertAndInsert();
70}
71
73{
74 switch( aElementToken )
75 {
76 case PPT_TOKEN( sldMaster ): // CT_SlideMaster
77 case PPT_TOKEN( handoutMaster ): // CT_HandoutMaster
78 case PPT_TOKEN( sld ): // CT_CommonSlideData
79 {
80 Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
81 Reference< css::beans::XPropertySet > xSet(xSlide, UNO_QUERY);
82 PropertyMap aPropMap;
83 PropertySet aSlideProp( xSlide );
84
85 std::optional<bool> aShowMasterShapes = rAttribs.getBool(XML_showMasterSp);
86 if (aShowMasterShapes.has_value() && !aShowMasterShapes.value())
87 xSet->setPropertyValue("IsBackgroundObjectsVisible", Any(false));
88
89 aPropMap.setProperty( PROP_Visible, rAttribs.getBool( XML_show, true ));
90 aSlideProp.setProperties( aPropMap );
91
92 return this;
93 }
94 case PPT_TOKEN( notes ): // CT_NotesSlide
95 {
96 // Import notesMaster
97 PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() );
98 OUString aNotesFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( u"notesMaster" );
99
100 std::vector< SlidePersistPtr >& rMasterPages( rFilter.getMasterPages() );
101 bool bNotesFragmentPathFound = false;
102 for (auto const& masterPage : rMasterPages)
103 {
104 if( masterPage->getPath() == aNotesFragmentPath )
105 {
106 if( !mpSlidePersistPtr->getMasterPersist() )
107 mpSlidePersistPtr->setMasterPersist(masterPage);
108 bNotesFragmentPathFound=true;
109 break;
110 }
111 }
112 if( !bNotesFragmentPathFound && !mpSlidePersistPtr->getMasterPersist() )
113 {
114 SlidePersistPtr pMasterPersistPtr = std::make_shared<SlidePersist>( rFilter, true, true, mpSlidePersistPtr->getPage(),
115 std::make_shared<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 );
121 }
122 return this;
123 }
124 case PPT_TOKEN( notesMaster ): // CT_NotesMaster
125 return this;
126 case PPT_TOKEN( cSld ): // CT_CommonSlideData
127 maSlideName = rAttribs.getStringDefaulted(XML_name);
128 return this;
129
130 case PPT_TOKEN( spTree ): // CT_GroupShape
131 {
132 return new PPTShapeGroupContext(
134 std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.GroupShape" ) );
135 }
136 break;
137
138 case PPT_TOKEN( controls ):
139 return this;
140 case PPT_TOKEN( control ):
141 {
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 );
147 }
148 return this;
149
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() );
156
157 // BackgroundGroup
158 case PPT_TOKEN( bg ):
159 return this;
160 case PPT_TOKEN( bgPr ): // CT_BackgroundProperties
161 {
162 FillPropertiesPtr pFillPropertiesPtr =std::make_shared<FillProperties>();
163 mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
164 return new BackgroundPropertiesContext( *this, *pFillPropertiesPtr );
165 }
166 break;
167
168 case PPT_TOKEN( bgRef ): // a:CT_StyleMatrixReference
169 {
170 const FillProperties *pFillProperties = nullptr;
171 if( mpSlidePersistPtr->getTheme() )
172 pFillProperties = mpSlidePersistPtr->getTheme()->getFillStyle( rAttribs.getInteger( XML_idx, -1 ) );
173 FillPropertiesPtr pFillPropertiesPtr =
174 pFillProperties
175 ? std::make_shared<FillProperties>( *pFillProperties )
176 : std::make_shared<FillProperties>();
177 mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
178 ContextHandlerRef ret = new ColorContext( *this, mpSlidePersistPtr->getBackgroundColor() );
179 return ret;
180 }
181 break;
182
183 case A_TOKEN( overrideClrMapping ):
184 case PPT_TOKEN( clrMap ): // CT_ColorMapping
185 {
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 );
192 return ret;
193 }
194 break;
195 case PPT_TOKEN( clrMapOvr ): // CT_ColorMappingOverride
196 case PPT_TOKEN( sldLayoutIdLst ): // CT_SlideLayoutIdList
197 return this;
198 case PPT_TOKEN( txStyles ): // CT_SlideMasterTextStyles
200 case PPT_TOKEN( custDataLst ): // CT_CustomerDataList
201 case PPT_TOKEN( tagLst ): // CT_TagList
202 return this;
203
204 //for Comments
205 case PPT_TOKEN( cmLst ):
206 break;
207 case PPT_TOKEN( cm ):
208 if (!mpSlidePersistPtr->getCommentsList().cmLst.empty() && !getCharVector().empty())
209 {
210 // set comment text for earlier comment
211 mpSlidePersistPtr->getCommentsList().cmLst.back().setText( getCharVector().back() );
212 }
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));
218 break;
219
220 case PPT_TOKEN( pos ):
221 mpSlidePersistPtr->getCommentsList().cmLst.back().setPoint(
222 rAttribs.getStringDefaulted(XML_x),
223 rAttribs.getStringDefaulted(XML_y));
224 break;
225
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);
234 break;
235 }
236
237 return this;
238}
239void SlideFragmentHandler::onCharacters( const OUString& rChars)
240{
241 maCharVector.push_back(rChars);
242}
244{
245 try
246 {
247 Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
248 PropertySet aSlideProp( xSlide );
249 aSlideProp.setProperties( maSlideProperties );
250 if ( !maSlideName.isEmpty() )
251 {
252 Reference< XNamed > xNamed( xSlide, UNO_QUERY );
253 if( xNamed.is() )
254 xNamed->setName( maSlideName );
255 }
256 }
257 catch( uno::Exception& )
258 {
259 TOOLS_WARN_EXCEPTION( "oox", "oox::ppt::SlideFragmentHandler::EndElement()" );
260 }
261}
262
263}
264
265/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Provides access to attribute values of an element.
OUString getStringDefaulted(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute, returns an empty string if attribute not present...
std::optional< OUString > getXString(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute.
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (decimal).
std::optional< bool > getBool(sal_Int32 nAttrToken) const
Returns the boolean value of the specified attribute.
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:52
bool setProperty(sal_Int32 nPropId, Type &&rValue)
Sets the specified property to the passed value.
Definition: propertymap.hxx:72
A wrapper for a UNO property set.
Definition: propertyset.hxx:58
void setProperties(const css::uno::Sequence< OUString > &rPropNames, const css::uno::Sequence< css::uno::Any > &rValues)
Puts the passed properties into the property set.
bool importFragment(const rtl::Reference< FragmentHandler > &rxHandler)
Imports a fragment using the passed fragment handler, which contains the full path to the fragment st...
std::vector< SlidePersistPtr > & getMasterPages()
Definition: pptimport.hxx:72
const ::std::vector< OUString > & getCharVector() const
SlideFragmentHandler(::oox::core::XmlFilterBase &rFilter, const OUString &rFragmentPath, const SlidePersistPtr &pPersistPtr, const ShapeLocation eShapeLocation)
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 aElementToken, const AttributeList &rAttribs) override
::std::vector< OUString > maCharVector
virtual void onCharacters(const OUString &rChars) override
virtual void finalizeImport() override
#define TOOLS_WARN_EXCEPTION(area, stream)
float u
::rtl::Reference< ContextHandler > ContextHandlerRef
::rtl::Reference< FragmentHandler > FragmentHandlerRef
std::shared_ptr< ClrMap > ClrMapPtr
Definition: clrscheme.hxx:64
std::shared_ptr< FillProperties > FillPropertiesPtr
std::shared_ptr< SlidePersist > SlidePersistPtr
const snew_slide_value_info_layout notes[]
Contains information about a form control embedded in a draw page.
Definition: vmldrawing.hxx:79
OUString maName
Programmatical name of the form control.
Definition: vmldrawing.hxx:82
void setShapeId(sal_Int32 nShapeId)
Sets the string representation of the passed numeric shape identifier.
Definition: vmldrawing.cxx:90
OUString maFragmentPath
Path to the fragment describing the form control properties.
Definition: vmldrawing.hxx:81
size_t pos
constexpr OUStringLiteral PROP_Visible