LibreOffice Module oox (master) 1
presentationfragmenthandler.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
23#include <o3tl/string_view.hxx>
24#include <sal/log.hxx>
25#include <tools/multisel.hxx>
27
28#include <com/sun/star/container/XNamed.hpp>
29#include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
30#include <com/sun/star/drawing/XDrawPages.hpp>
31#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
32#include <com/sun/star/drawing/XMasterPageTarget.hpp>
33#include <com/sun/star/frame/XModel.hpp>
34#include <com/sun/star/io/XInputStream.hpp>
35#include <com/sun/star/text/XTextField.hpp>
36#include <com/sun/star/xml/dom/XDocument.hpp>
37#include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
38#include <com/sun/star/presentation/XPresentationPage.hpp>
39#include <com/sun/star/task/XStatusIndicator.hpp>
40#include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
41#include <com/sun/star/container/XIndexContainer.hpp>
42#include <com/sun/star/lang/XMultiServiceFactory.hpp>
43#include <com/sun/star/lang/XSingleServiceFactory.hpp>
44#include <com/sun/star/container/XNameContainer.hpp>
45
53#include <oox/ppt/pptshape.hxx>
57#include <oox/ppt/pptimport.hxx>
58#include <oox/token/namespaces.hxx>
59#include <oox/token/tokens.hxx>
60
61#include <com/sun/star/office/XAnnotation.hpp>
62#include <com/sun/star/office/XAnnotationAccess.hpp>
63#include <ooxresid.hxx>
64#include <strings.hrc>
65
66using namespace ::com::sun::star;
67using namespace ::oox::core;
68using namespace ::oox::drawingml;
69using namespace ::com::sun::star::uno;
70using namespace ::com::sun::star::beans;
71using namespace ::com::sun::star::drawing;
72using namespace ::com::sun::star::presentation;
73using namespace ::com::sun::star::xml::sax;
74
75namespace oox::ppt {
76
77static std::map<PredefinedClrSchemeId, sal_Int32> PredefinedClrTokens =
78{
79 //{ dk1, XML_dk1 },
80 //{ lt1, XML_lt1 },
81 { dk2, XML_dk2 },
82 { lt2, XML_lt2 },
83 { accent1, XML_accent1 },
84 { accent2, XML_accent2 },
85 { accent3, XML_accent3 },
86 { accent4, XML_accent4 },
87 { accent5, XML_accent5 },
88 { accent6, XML_accent6 },
89 { hlink, XML_hlink },
90 { folHlink, XML_folHlink }
91};
92
93PresentationFragmentHandler::PresentationFragmentHandler(XmlFilterBase& rFilter, const OUString& rFragmentPath)
94 : FragmentHandler2( rFilter, rFragmentPath )
95 , mpTextListStyle( std::make_shared<TextListStyle>() )
96 , mbCommentAuthorsRead(false)
97{
98 TextParagraphPropertiesArray& rParagraphDefaultsVector( mpTextListStyle->getListStyle() );
99 for (auto & elem : rParagraphDefaultsVector)
100 {
101 // ppt is having zero bottom margin per default, whereas OOo is 0,5cm,
102 // so this attribute needs to be set always
103 elem.getParaBottomMargin() = TextSpacing( 0 );
104 }
105}
106
108{
109}
110
111void PresentationFragmentHandler::importSlideNames(XmlFilterBase& rFilter, const std::vector<SlidePersistPtr>& rSlidePersist)
112{
113 sal_Int32 nMaxPages = rSlidePersist.size();
114 for (sal_Int32 nPage = 0; nPage < nMaxPages; nPage++)
115 {
116 auto aShapeMap = rSlidePersist[nPage]->getShapeMap();
117 auto aIter = std::find_if(aShapeMap.begin(), aShapeMap.end(),
118 [](const std::pair<OUString, ShapePtr>& element) {
119 auto pShapePtr = element.second;
120 return (pShapePtr
121 && (pShapePtr->getSubType() == XML_title
122 || pShapePtr->getSubType() == XML_ctrTitle));
123 });
124 if (aIter != aShapeMap.end())
125 {
126 OUString aTitleText;
127 Reference<text::XTextRange> xText(aIter->second->getXShape(), UNO_QUERY_THROW);
128 aTitleText = xText->getString();
129 // just a magic value but we don't want to drop out slide names which are too long
130 if (aTitleText.getLength() > 63)
131 aTitleText = aTitleText.copy(0, 63);
132 bool bUseTitleAsSlideName = !aTitleText.isEmpty();
133 // check duplicated title name
134 if (bUseTitleAsSlideName)
135 {
136 sal_Int32 nCount = 1;
137 Reference<XDrawPagesSupplier> xDPS(rFilter.getModel(), UNO_QUERY_THROW);
138 Reference<XDrawPages> xDrawPages(xDPS->getDrawPages(), UNO_SET_THROW);
139 for (sal_Int32 i = 0; i < nPage; ++i)
140 {
141 Reference<XDrawPage> xDrawPage(xDrawPages->getByIndex(i), UNO_QUERY);
142 Reference<container::XNamed> xNamed(xDrawPage, UNO_QUERY_THROW);
143 OUString sRest;
144 if (xNamed->getName().startsWith(aTitleText, &sRest)
145 && (sRest.isEmpty()
146 || (sRest.startsWith(" (") && sRest.endsWith(")")
147 && o3tl::toInt32(sRest.subView(2, sRest.getLength() - 3)) > 0)))
148 nCount++;
149 }
150 Reference<container::XNamed> xName(rSlidePersist[nPage]->getPage(), UNO_QUERY_THROW);
151 xName->setName(
152 aTitleText
153 + (nCount == 1 ? OUString("") : " (" + OUString::number(nCount) + ")"));
154 }
155 }
156 }
157}
158
159void PresentationFragmentHandler::importCustomSlideShow(std::vector<CustomShow>& rCustomShowList)
160{
161 PowerPointImport& rFilter = dynamic_cast<PowerPointImport&>(getFilter());
162 Reference<frame::XModel> xModel(rFilter.getModel());
163 Reference<XDrawPagesSupplier> xDrawPagesSupplier(xModel, UNO_QUERY_THROW);
164 Reference<XDrawPages> xDrawPages(xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW);
165
166 Reference<css::lang::XSingleServiceFactory> mxShowFactory;
167 Reference<css::container::XNameContainer> mxShows;
168 Reference<XCustomPresentationSupplier> xShowsSupplier(xModel, UNO_QUERY);
169 if (xShowsSupplier.is())
170 {
171 mxShows = xShowsSupplier->getCustomPresentations();
172 mxShowFactory.set(mxShows, UNO_QUERY);
173 }
174
175 for (size_t i = 0; i < rCustomShowList.size(); ++i)
176 {
177 Reference<com::sun::star::container::XIndexContainer> xShow(mxShowFactory->createInstance(),
178 UNO_QUERY);
179 if (xShow.is())
180 {
181 static const OUStringLiteral sSlide = u"slides/slide";
182 for (size_t j = 0; j < rCustomShowList[i].maSldLst.size(); ++j)
183 {
184 OUString sCustomSlide = rCustomShowList[i].maSldLst[j];
185 sal_Int32 nPageNumber = 0;
186 if (sCustomSlide.match(sSlide))
187 nPageNumber = o3tl::toInt32(sCustomSlide.subView(sSlide.getLength()));
188
189 Reference<XDrawPage> xPage;
190 xDrawPages->getByIndex(nPageNumber - 1) >>= xPage;
191 if (xPage.is())
192 xShow->insertByIndex(xShow->getCount(), Any(xPage));
193 }
194
195 Any aAny;
196 aAny <<= xShow;
197 mxShows->insertByName(rCustomShowList[i].maCustomShowName, aAny);
198 }
199 }
200}
201
203 sal_Int32 nThemeIdx)
204{
205 if (!pThemePtr)
206 return;
207
208 try
209 {
210 uno::Reference<beans::XPropertySet> xDocProps(getFilter().getModel(), uno::UNO_QUERY);
211 if (xDocProps.is())
212 {
213 uno::Reference<beans::XPropertySetInfo> xPropsInfo = xDocProps->getPropertySetInfo();
214
215 static const OUStringLiteral aGrabBagPropName = u"InteropGrabBag";
216 if (xPropsInfo.is() && xPropsInfo->hasPropertyByName(aGrabBagPropName))
217 {
218 // get existing grab bag
219 comphelper::SequenceAsHashMap aGrabBag(xDocProps->getPropertyValue(aGrabBagPropName));
220
221 comphelper::SequenceAsHashMap aThemesHashMap;
222
223 // create current theme
224 uno::Sequence<beans::PropertyValue> aCurrentTheme(PredefinedClrSchemeId::Count);
225 auto pCurrentTheme = aCurrentTheme.getArray();
226
227 ClrScheme rClrScheme = pThemePtr->getClrScheme();
229 {
230 sal_uInt32 nToken = PredefinedClrTokens[static_cast<PredefinedClrSchemeId>(nId)];
231 const OUString& sName = PredefinedClrNames[static_cast<PredefinedClrSchemeId>(nId)];
232 ::Color nColor;
233
234 rClrScheme.getColor(nToken, nColor);
235 const uno::Any& rColor = uno::Any(nColor);
236
237 pCurrentTheme[nId].Name = sName;
238 pCurrentTheme[nId].Value = rColor;
239 }
240
241
242 uno::Sequence<beans::PropertyValue> aTheme{
243 // add new theme to the sequence
244 // Export code uses the master slide's index to find the right theme
245 // so use the same index in the grabbag.
247 "ppt/theme/theme" + OUString::number(nThemeIdx) + ".xml", aCurrentTheme),
248 // store DOM fragment for SmartArt re-generation
249 comphelper::makePropertyValue("OOXTheme", pThemePtr->getFragment())
250 };
251
252 aThemesHashMap << aTheme;
253
254 // put the new items
255 aGrabBag.update(aThemesHashMap);
256
257 // put it back to the document
258 xDocProps->setPropertyValue(aGrabBagPropName, uno::Any(aGrabBag.getAsConstPropertyValueList()));
259 }
260 }
261 }
262 catch (const uno::Exception&)
263 {
264 SAL_WARN("oox", "oox::ppt::PresentationFragmentHandler::saveThemeToGrabBag, Failed to save grab bag");
265 }
266}
267
268void PresentationFragmentHandler::importSlide(sal_uInt32 nSlide, bool bFirstPage, bool bImportNotesPage)
269{
270 PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() );
271
272 Reference< frame::XModel > xModel( rFilter.getModel() );
273 Reference< drawing::XDrawPage > xSlide;
274
275 // importing slide pages and its corresponding notes page
276 Reference< drawing::XDrawPagesSupplier > xDPS( xModel, uno::UNO_QUERY_THROW );
277 Reference< drawing::XDrawPages > xDrawPages( xDPS->getDrawPages(), uno::UNO_SET_THROW );
278
279 try {
280
281 if( bFirstPage )
282 xDrawPages->getByIndex( 0 ) >>= xSlide;
283 else
284 xSlide = xDrawPages->insertNewByIndex( xDrawPages->getCount() );
285
286 OUString aSlideFragmentPath = getFragmentPathFromRelId( maSlidesVector[ nSlide ] );
287 if( !aSlideFragmentPath.isEmpty() )
288 {
289 SlidePersistPtr pMasterPersistPtr;
290 SlidePersistPtr pSlidePersistPtr = std::make_shared<SlidePersist>( rFilter, false, false, xSlide,
291 std::make_shared<PPTShape>( Slide, "com.sun.star.drawing.GroupShape" ), mpTextListStyle );
292
293 FragmentHandlerRef xSlideFragmentHandler( new SlideFragmentHandler( rFilter, aSlideFragmentPath, pSlidePersistPtr, Slide ) );
294
295 // importing the corresponding masterpage/layout
296 OUString aLayoutFragmentPath = xSlideFragmentHandler->getFragmentPathFromFirstTypeFromOfficeDoc( u"slideLayout" );
297 OUString aCommentFragmentPath = xSlideFragmentHandler->getFragmentPathFromFirstTypeFromOfficeDoc( u"comments" );
298 if ( !aLayoutFragmentPath.isEmpty() )
299 {
300 // importing layout
301 RelationsRef xLayoutRelations = rFilter.importRelations( aLayoutFragmentPath );
302 OUString aMasterFragmentPath = xLayoutRelations->getFragmentPathFromFirstTypeFromOfficeDoc( u"slideMaster" );
303 if( !aMasterFragmentPath.isEmpty() )
304 {
305 // check if the corresponding masterpage+layout has already been imported
306 std::vector< SlidePersistPtr >& rMasterPages( rFilter.getMasterPages() );
307 for (auto const& masterPage : rMasterPages)
308 {
309 if ( ( masterPage->getPath() == aMasterFragmentPath ) && ( masterPage->getLayoutPath() == aLayoutFragmentPath ) )
310 {
311 pMasterPersistPtr = masterPage;
312 break;
313 }
314 }
315
316 if ( !pMasterPersistPtr )
317 { // masterpersist not found, we have to load it
318 Reference< drawing::XDrawPage > xMasterPage;
319 Reference< drawing::XMasterPagesSupplier > xMPS( xModel, uno::UNO_QUERY_THROW );
320 Reference< drawing::XDrawPages > xMasterPages( xMPS->getMasterPages(), uno::UNO_SET_THROW );
321
322 sal_Int32 nIndex;
323 if( rFilter.getMasterPages().empty() )
324 {
325 nIndex = 0;
326 xMasterPages->getByIndex( nIndex ) >>= xMasterPage;
327 }
328 else
329 {
330 nIndex = xMasterPages->getCount();
331 xMasterPage = xMasterPages->insertNewByIndex( nIndex );
332 }
333
334 pMasterPersistPtr = std::make_shared<SlidePersist>( rFilter, true, false, xMasterPage,
335 std::make_shared<PPTShape>( Master, "com.sun.star.drawing.GroupShape" ), mpTextListStyle );
336 pMasterPersistPtr->setLayoutPath( aLayoutFragmentPath );
337 rFilter.getMasterPages().push_back( pMasterPersistPtr );
338 rFilter.setActualSlidePersist( pMasterPersistPtr );
339 FragmentHandlerRef xMasterFragmentHandler( new SlideFragmentHandler( rFilter, aMasterFragmentPath, pMasterPersistPtr, Master ) );
340
341 // set the correct theme
342 OUString aThemeFragmentPath = xMasterFragmentHandler->getFragmentPathFromFirstTypeFromOfficeDoc( u"theme" );
343 if( !aThemeFragmentPath.isEmpty() )
344 {
345 std::map< OUString, oox::drawingml::ThemePtr >& rThemes( rFilter.getThemes() );
346 std::map< OUString, oox::drawingml::ThemePtr >::iterator aIter2( rThemes.find( aThemeFragmentPath ) );
347 if( aIter2 == rThemes.end() )
348 {
349 oox::drawingml::ThemePtr pThemePtr = std::make_shared<oox::drawingml::Theme>();
350 pMasterPersistPtr->setTheme( pThemePtr );
351 Reference<xml::dom::XDocument> xDoc=
352 rFilter.importFragment(aThemeFragmentPath);
353
354 rFilter.importFragment(
355 new ThemeFragmentHandler(
356 rFilter, aThemeFragmentPath, *pThemePtr ),
357 Reference<xml::sax::XFastSAXSerializable>(
358 xDoc,
359 UNO_QUERY_THROW));
360 rThemes[ aThemeFragmentPath ] = pThemePtr;
361 pThemePtr->setFragment(xDoc);
362 saveThemeToGrabBag(pThemePtr, nIndex + 1);
363 }
364 else
365 {
366 pMasterPersistPtr->setTheme( (*aIter2).second );
367 }
368 }
369 importSlide( xMasterFragmentHandler, pMasterPersistPtr );
370 rFilter.importFragment( new LayoutFragmentHandler( rFilter, aLayoutFragmentPath, pMasterPersistPtr ) );
371 pMasterPersistPtr->createBackground( rFilter );
372 pMasterPersistPtr->createXShapes( rFilter );
373
374 oox::drawingml::ThemePtr pTheme = pMasterPersistPtr->getTheme();
375 if (pTheme)
376 {
377 pTheme->addTheme(pMasterPersistPtr->getPage());
378 }
379 }
380 }
381 }
382
383 // importing slide page
384 if (pMasterPersistPtr) {
385 pSlidePersistPtr->setMasterPersist( pMasterPersistPtr );
386 pSlidePersistPtr->setTheme( pMasterPersistPtr->getTheme() );
387 Reference< drawing::XMasterPageTarget > xMasterPageTarget( pSlidePersistPtr->getPage(), UNO_QUERY );
388 if( xMasterPageTarget.is() )
389 xMasterPageTarget->setMasterPage( pMasterPersistPtr->getPage() );
390 }
391 rFilter.getDrawPages().push_back( pSlidePersistPtr );
392 rFilter.setActualSlidePersist( pSlidePersistPtr );
393 importSlide( xSlideFragmentHandler, pSlidePersistPtr );
394 pSlidePersistPtr->createBackground( rFilter );
395 pSlidePersistPtr->createXShapes( rFilter );
396
397 if(bImportNotesPage) {
398
399 // now importing the notes page
400 OUString aNotesFragmentPath = xSlideFragmentHandler->getFragmentPathFromFirstTypeFromOfficeDoc( u"notesSlide" );
401 if( !aNotesFragmentPath.isEmpty() )
402 {
403 Reference< XPresentationPage > xPresentationPage( xSlide, UNO_QUERY );
404 if ( xPresentationPage.is() )
405 {
406 Reference< XDrawPage > xNotesPage( xPresentationPage->getNotesPage() );
407 if ( xNotesPage.is() )
408 {
409 SlidePersistPtr pNotesPersistPtr = std::make_shared<SlidePersist>( rFilter, false, true, xNotesPage,
410 std::make_shared<PPTShape>( Slide, "com.sun.star.drawing.GroupShape" ), mpTextListStyle );
411 FragmentHandlerRef xNotesFragmentHandler( new SlideFragmentHandler( getFilter(), aNotesFragmentPath, pNotesPersistPtr, Slide ) );
412 rFilter.getNotesPages().push_back( pNotesPersistPtr );
413 rFilter.setActualSlidePersist( pNotesPersistPtr );
414 importSlide( xNotesFragmentHandler, pNotesPersistPtr );
415 pNotesPersistPtr->createBackground( rFilter );
416 pNotesPersistPtr->createXShapes( rFilter );
417 }
418 }
419 }
420 }
421
422 if( !mbCommentAuthorsRead && !aCommentFragmentPath.isEmpty() )
423 {
424 // Comments are present and commentAuthors.xml has still not been read
426 Reference< XPresentationPage > xPresentationPage( xSlide, UNO_QUERY );
427 Reference< XDrawPage > xCommentAuthorsPage( xPresentationPage->getNotesPage() );
428 SlidePersistPtr pCommentAuthorsPersistPtr =
429 std::make_shared<SlidePersist>( rFilter, false, true, xCommentAuthorsPage,
430 std::make_shared<PPTShape>(
431 Slide, "com.sun.star.drawing.GroupShape" ),
433 FragmentHandlerRef xCommentAuthorsFragmentHandler(
434 new SlideFragmentHandler( getFilter(),
435 "ppt/commentAuthors.xml",
436 pCommentAuthorsPersistPtr,
437 Slide ) );
438
439 getFilter().importFragment( xCommentAuthorsFragmentHandler );
440 maAuthorList.setValues( pCommentAuthorsPersistPtr->getCommentAuthors() );
441 }
442 if( !aCommentFragmentPath.isEmpty() )
443 {
444 Reference< XPresentationPage > xPresentationPage( xSlide, UNO_QUERY );
445 Reference< XDrawPage > xCommentsPage( xPresentationPage->getNotesPage() );
446 SlidePersistPtr pCommentsPersistPtr =
447 std::make_shared<SlidePersist>(
448 rFilter, false, true, xCommentsPage,
449 std::make_shared<PPTShape>(
450 Slide, "com.sun.star.drawing.GroupShape" ),
452
453 FragmentHandlerRef xCommentsFragmentHandler(
455 getFilter(),
456 aCommentFragmentPath,
457 pCommentsPersistPtr,
458 Slide ) );
459 pCommentsPersistPtr->getCommentsList().cmLst.clear();
460 getFilter().importFragment( xCommentsFragmentHandler );
461
462 if (!pCommentsPersistPtr->getCommentsList().cmLst.empty())
463 {
464 //set comment chars for last comment on slide
465 SlideFragmentHandler* comment_handler =
466 dynamic_cast<SlideFragmentHandler*>(xCommentsFragmentHandler.get());
467 assert(comment_handler);
468 // some comments have no text -> set empty string as text to avoid
469 // crash (back() on empty vector is undefined) and losing other
470 // comment data that might be there (author, position, timestamp etc.)
471 pCommentsPersistPtr->getCommentsList().cmLst.back().setText(
472 comment_handler->getCharVector().empty() ? "" :
473 comment_handler->getCharVector().back() );
474 }
475 pCommentsPersistPtr->getCommentAuthors().setValues(maAuthorList);
476
477 //insert all comments from commentsList
478 for(int i=0; i<pCommentsPersistPtr->getCommentsList().getSize(); i++)
479 {
480 try {
481 Comment aComment = pCommentsPersistPtr->getCommentsList().getCommentAtIndex(i);
482 uno::Reference< office::XAnnotationAccess > xAnnotationAccess( xSlide, UNO_QUERY_THROW );
483 uno::Reference< office::XAnnotation > xAnnotation( xAnnotationAccess->createAndInsertAnnotation() );
484 int nPosX = aComment.getIntX();
485 int nPosY = aComment.getIntY();
486 xAnnotation->setPosition(
487 geometry::RealPoint2D(
488 ::oox::drawingml::convertEmuToHmm( nPosX ) * 15.87,
489 ::oox::drawingml::convertEmuToHmm( nPosY ) * 15.87 ) );
490 xAnnotation->setAuthor( aComment.getAuthor(maAuthorList) );
491 xAnnotation->setDateTime( aComment.getDateTime() );
492 uno::Reference< text::XText > xText( xAnnotation->getTextRange() );
493 xText->setString( aComment.get_text());
494 } catch( css::lang::IllegalArgumentException& ) {}
495 }
496 }
497 }
498 }
499 catch( uno::Exception& )
500 {
501 TOOLS_WARN_EXCEPTION( "oox", "oox::ppt::PresentationFragmentHandler::EndDocument()" );
502 }
503}
504
506{
507 PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() );
508
509 sal_Int32 nPageCount = maSlidesVector.size();
510
511 // we will take the FilterData property "PageRange" if available, otherwise full range is used
512 comphelper::SequenceAsHashMap& rFilterData = rFilter.getFilterData();
513
514 // writing back the original PageCount of this document, it can be accessed from the XModel
515 // via getArgs after the import.
516 rFilterData["OriginalPageCount"] <<= nPageCount;
517 bool bImportNotesPages = rFilterData.getUnpackedValueOrDefault("ImportNotesPages", true);
518 OUString aPageRange = rFilterData.getUnpackedValueOrDefault("PageRange", OUString());
519
520 if( !aPageRange.getLength() )
521 {
522 aPageRange = "1-" + OUString::number( nPageCount );
523 }
524
525 StringRangeEnumerator aRangeEnumerator( aPageRange, 0, nPageCount - 1 );
526 if (aRangeEnumerator.size())
527 {
528 // todo: localized progress bar text
529 const Reference< task::XStatusIndicator >& rxStatusIndicator( getFilter().getStatusIndicator() );
530 if ( rxStatusIndicator.is() )
531 rxStatusIndicator->start( OUString(), 10000 );
532
533 try
534 {
535 int nPagesImported = 0;
536 for (sal_Int32 elem : aRangeEnumerator)
537 {
538 if ( rxStatusIndicator.is() )
539 rxStatusIndicator->setValue((nPagesImported * 10000) / aRangeEnumerator.size());
540
541 importSlide(elem, !nPagesImported, bImportNotesPages);
542 nPagesImported++;
543 }
544 importSlideNames( rFilter, rFilter.getDrawPages());
545 if (!maCustomShowList.empty())
547 }
548 catch( uno::Exception& )
549 {
550 TOOLS_WARN_EXCEPTION( "oox", "oox::ppt::PresentationFragmentHandler::finalizeImport()" );
551 }
552 // todo error handling;
553 if ( rxStatusIndicator.is() )
554 rxStatusIndicator->end();
555 }
556
557 // open the VBA project storage
558 OUString aVbaFragmentPath = getFragmentPathFromFirstType(CREATE_MSOFFICE_RELATION_TYPE("vbaProject"));
559 if (!aVbaFragmentPath.isEmpty())
560 {
561 uno::Reference<io::XInputStream> xInStrm = getFilter().openInputStream(aVbaFragmentPath);
562 if (xInStrm.is())
563 {
564 StorageRef xPrjStrg = std::make_shared<oox::ole::OleStorage>(getFilter().getComponentContext(), xInStrm, false);
565 getFilter().getVbaProject().importVbaProject(*xPrjStrg);
566 }
567 }
568}
569
570// CT_Presentation
572{
573 switch( aElementToken )
574 {
575 case PPT_TOKEN( presentation ):
576 case PPT_TOKEN( sldMasterIdLst ):
577 case PPT_TOKEN( notesMasterIdLst ):
578 case PPT_TOKEN( sldIdLst ):
579 return this;
580 case PPT_TOKEN( sldMasterId ):
581 maSlideMasterVector.push_back( rAttribs.getStringDefaulted( R_TOKEN( id )) );
582 return this;
583 case PPT_TOKEN( sldId ):
584 maSlidesVector.push_back( rAttribs.getStringDefaulted( R_TOKEN( id )) );
585 return this;
586 case PPT_TOKEN( notesMasterId ):
587 maNotesMasterVector.push_back( rAttribs.getStringDefaulted( R_TOKEN( id )) );
588 return this;
589 case PPT_TOKEN( sldSz ):
591 return this;
592 case PPT_TOKEN( notesSz ):
594 return this;
595 case PPT_TOKEN( custShowLst ):
596 return new CustomShowListContext( *this, maCustomShowList );
597 case PPT_TOKEN( defaultTextStyle ):
598 return new TextListStyleContext( *this, *mpTextListStyle );
599 case PPT_TOKEN( modifyVerifier ):
600 OUString sAlgorithmClass = rAttribs.getStringDefaulted(XML_cryptAlgorithmClass);
601 OUString sAlgorithmType = rAttribs.getStringDefaulted(XML_cryptAlgorithmType);
602 sal_Int32 nAlgorithmSid = rAttribs.getInteger(XML_cryptAlgorithmSid, 0);
603 sal_Int32 nSpinCount = rAttribs.getInteger(XML_spinCount, 0);
604 OUString sSalt = rAttribs.getStringDefaulted(XML_saltData);
605 OUString sHash = rAttribs.getStringDefaulted(XML_hashData);
606 if (sAlgorithmClass == "hash" && sAlgorithmType == "typeAny" && nAlgorithmSid != 0
607 && !sSalt.isEmpty() && !sHash.isEmpty())
608 {
609 OUString sAlgorithmName;
610 switch (nAlgorithmSid)
611 {
612 case 1:
613 sAlgorithmName = "MD2";
614 break;
615 case 2:
616 sAlgorithmName = "MD4";
617 break;
618 case 3:
619 sAlgorithmName = "MD5";
620 break;
621 case 4:
622 sAlgorithmName = "SHA-1";
623 break;
624 case 5:
625 sAlgorithmName = "MAC";
626 break;
627 case 6:
628 sAlgorithmName = "RIPEMD";
629 break;
630 case 7:
631 sAlgorithmName = "RIPEMD-160";
632 break;
633 case 9:
634 sAlgorithmName = "HMAC";
635 break;
636 case 12:
637 sAlgorithmName = "SHA-256";
638 break;
639 case 13:
640 sAlgorithmName = "SHA-384";
641 break;
642 case 14:
643 sAlgorithmName = "SHA-512";
644 break;
645 default:; // 8, 10, 11, any other value: Undefined.
646 }
647
648 if (!sAlgorithmName.isEmpty())
649 {
650 uno::Sequence<beans::PropertyValue> aResult{
651 comphelper::makePropertyValue("algorithm-name", sAlgorithmName),
652 comphelper::makePropertyValue("salt", sSalt),
653 comphelper::makePropertyValue("iteration-count", nSpinCount),
655 };
656 try
657 {
658 uno::Reference<beans::XPropertySet> xDocSettings(
659 getFilter().getModelFactory()->createInstance(
660 "com.sun.star.document.Settings"),
661 uno::UNO_QUERY);
662 xDocSettings->setPropertyValue("ModifyPasswordInfo", uno::Any(aResult));
663 }
664 catch (const uno::Exception&)
665 {
666 }
667 }
668 }
669 return this;
670 }
671 return this;
672}
673
674void PresentationFragmentHandler::importSlide( const FragmentHandlerRef& rxSlideFragmentHandler,
675 const SlidePersistPtr& rSlidePersistPtr )
676{
677 Reference< drawing::XDrawPage > xSlide( rSlidePersistPtr->getPage() );
678 SlidePersistPtr pMasterPersistPtr( rSlidePersistPtr->getMasterPersist() );
679 if ( pMasterPersistPtr )
680 {
681 // Setting "Layout" property adds extra title and outliner preset shapes to the master slide
682 Reference< drawing::XDrawPage > xMasterSlide(pMasterPersistPtr->getPage());
683 const int nCount = xMasterSlide->getCount();
684
685 uno::Reference< beans::XPropertySet > xSet( xSlide, uno::UNO_QUERY_THROW );
686 xSet->setPropertyValue( "Layout", Any( pMasterPersistPtr->getLayoutFromValueToken() ) );
687
688 while( nCount < xMasterSlide->getCount())
689 {
690 Reference< drawing::XShape > xShape;
691 xMasterSlide->getByIndex(xMasterSlide->getCount()-1) >>= xShape;
692 xMasterSlide->remove(xShape);
693 }
694 }
695 while( xSlide->getCount() )
696 {
697 Reference< drawing::XShape > xShape;
698 xSlide->getByIndex(0) >>= xShape;
699 xSlide->remove( xShape );
700 }
701
702 Reference< XPropertySet > xPropertySet( xSlide, UNO_QUERY );
703 if ( xPropertySet.is() )
704 {
705 awt::Size& rPageSize( rSlidePersistPtr->isNotesPage() ? maNotesSize : maSlideSize );
706 xPropertySet->setPropertyValue( "Width", Any( rPageSize.Width ) );
707 xPropertySet->setPropertyValue( "Height", Any( rPageSize.Height ) );
708
709 oox::ppt::HeaderFooter aHeaderFooter( rSlidePersistPtr->getHeaderFooter() );
710 if ( !rSlidePersistPtr->isMasterPage() )
711 aHeaderFooter.mbSlideNumber = aHeaderFooter.mbHeader = aHeaderFooter.mbFooter = aHeaderFooter.mbDateTime = false;
712 try
713 {
714 if ( rSlidePersistPtr->isNotesPage() )
715 xPropertySet->setPropertyValue( "IsHeaderVisible", Any( aHeaderFooter.mbHeader ) );
716 xPropertySet->setPropertyValue( "IsFooterVisible", Any( aHeaderFooter.mbFooter ) );
717 xPropertySet->setPropertyValue( "IsDateTimeVisible", Any( aHeaderFooter.mbDateTime ) );
718 xPropertySet->setPropertyValue( "IsPageNumberVisible", Any( aHeaderFooter.mbSlideNumber ) );
719 }
720 catch( uno::Exception& )
721 {
722 }
723 }
724 rSlidePersistPtr->setPath( rxSlideFragmentHandler->getFragmentPath() );
725 getFilter().importFragment( rxSlideFragmentHandler );
726}
727
728}
729
730/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
sal_Int32 size() const
TValueType getUnpackedValueOrDefault(const OUString &sKey, const TValueType &aDefault) const
css::uno::Sequence< css::beans::PropertyValue > getAsConstPropertyValueList() const
void update(const SequenceAsHashMap &rSource)
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< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (decimal).
const css::uno::Reference< css::xml::sax::XFastAttributeList > & getFastAttributeList() const
Returns the wrapped com.sun.star.xml.sax.XFastAttributeList object.
::comphelper::SequenceAsHashMap & getFilterData() const
Returns the FilterData.
Definition: filterbase.cxx:245
const css::uno::Reference< css::frame::XModel > & getModel() const
Returns the document model (always existing).
Definition: filterbase.cxx:220
RelationsRef importRelations(const OUString &rFragmentPath)
Imports the relations fragment associated with the specified fragment.
bool importFragment(const rtl::Reference< FragmentHandler > &rxHandler)
Imports a fragment using the passed fragment handler, which contains the full path to the fragment st...
void setValues(const CommentAuthorList &list)
Definition: comments.cxx:19
const OUString & get_text() const
Definition: comments.hxx:83
OUString getAuthor(const CommentAuthorList &list)
Definition: comments.cxx:69
const css::util::DateTime & getDateTime() const
Definition: comments.hxx:87
sal_Int32 getIntX() const
Definition: comments.hxx:91
sal_Int32 getIntY() const
Definition: comments.hxx:95
std::vector< SlidePersistPtr > & getNotesPages()
Definition: pptimport.hxx:73
std::vector< SlidePersistPtr > & getMasterPages()
Definition: pptimport.hxx:72
std::vector< SlidePersistPtr > & getDrawPages()
Definition: pptimport.hxx:71
void setActualSlidePersist(SlidePersistPtr pActualSlidePersist)
Definition: pptimport.hxx:69
std::map< OUString, oox::drawingml::ThemePtr > & getThemes()
Definition: pptimport.hxx:70
static void importSlideNames(::oox::core::XmlFilterBase &rFilter, const std::vector< SlidePersistPtr > &rSlidePersist)
void importSlide(const ::oox::core::FragmentHandlerRef &rSlideFragmentHandler, const oox::ppt::SlidePersistPtr &rPersist)
virtual ~PresentationFragmentHandler() noexcept override
PresentationFragmentHandler(::oox::core::XmlFilterBase &rFilter, const OUString &rFragmentPath)
::oox::drawingml::TextListStylePtr mpTextListStyle
void importCustomSlideShow(std::vector< CustomShow > &rCustomShowList)
void saveThemeToGrabBag(const oox::drawingml::ThemePtr &pThemePtr, sal_Int32 nThemeIdx)
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 aElementToken, const AttributeList &rAttribs) override
Will be called to create a context handler for the passed element.
const ::std::vector< OUString > & getCharVector() const
int nCount
#define TOOLS_WARN_EXCEPTION(area, stream)
OString sName
Definition: drawingml.cxx:4066
float u
char const sHash[]
sal_Int32 nIndex
#define SAL_WARN(area, stream)
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
std::shared_ptr< T > make_shared(Args &&... args)
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
std::shared_ptr< Relations > RelationsRef
Definition: relations.hxx:63
::rtl::Reference< FragmentHandler > FragmentHandlerRef
sal_Int32 convertEmuToHmm(sal_Int64 nValue)
Converts the passed 64-bit integer value from EMUs to 1/100 mm.
awt::Size GetSize2D(const Reference< XFastAttributeList > &xAttribs)
converts the attributes from a CT_Size2D into an awt Size with 1/100thmm
std::shared_ptr< Theme > ThemePtr
std::array< TextParagraphProperties, NUM_TEXT_LIST_STYLE_ENTRIES > TextParagraphPropertiesArray
static std::map< PredefinedClrSchemeId, OUString > PredefinedClrNames
Definition: clrscheme.hxx:52
std::shared_ptr< SlidePersist > SlidePersistPtr
static std::map< PredefinedClrSchemeId, sal_Int32 > PredefinedClrTokens
std::shared_ptr< StorageBase > StorageRef
Definition: storagebase.hxx:42
sal_Int16 nId
Definition: olehelper.cxx:98
DefTokenId nToken
#define CREATE_MSOFFICE_RELATION_TYPE(ascii)
Expands to an OUString containing an MS Office specific relation type created from the passed literal...
Definition: relations.hxx:46
Reference< XModel > xModel