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 std::u16string_view sRest;
144 if (o3tl::starts_with(xNamed->getName(), aTitleText, &sRest)
145 && (sRest.empty()
146 || (o3tl::starts_with(sRest, u" (") && o3tl::ends_with(sRest, u")")
147 && o3tl::toInt32(sRest.substr(2, sRest.size() - 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 auto pTheme = std::make_shared<model::Theme>();
355 pThemePtr->setTheme(pTheme);
356
357 rFilter.importFragment(
358 new ThemeFragmentHandler(rFilter, aThemeFragmentPath, *pThemePtr, *pTheme),
359 Reference<xml::sax::XFastSAXSerializable>(
360 xDoc,
361 UNO_QUERY_THROW));
362 rThemes[ aThemeFragmentPath ] = pThemePtr;
363 pThemePtr->setFragment(xDoc);
364 saveThemeToGrabBag(pThemePtr, nIndex + 1);
365 }
366 else
367 {
368 pMasterPersistPtr->setTheme( (*aIter2).second );
369 }
370 }
371 importSlide( xMasterFragmentHandler, pMasterPersistPtr );
372 rFilter.importFragment( new LayoutFragmentHandler( rFilter, aLayoutFragmentPath, pMasterPersistPtr ) );
373 pMasterPersistPtr->createBackground( rFilter );
374 pMasterPersistPtr->createXShapes( rFilter );
375
376 oox::drawingml::ThemePtr pTheme = pMasterPersistPtr->getTheme();
377 if (pTheme)
378 {
379 pTheme->addTheme(pMasterPersistPtr->getPage());
380 }
381 }
382 }
383 }
384
385 // importing slide page
386 if (pMasterPersistPtr) {
387 pSlidePersistPtr->setMasterPersist( pMasterPersistPtr );
388 pSlidePersistPtr->setTheme( pMasterPersistPtr->getTheme() );
389 Reference< drawing::XMasterPageTarget > xMasterPageTarget( pSlidePersistPtr->getPage(), UNO_QUERY );
390 if( xMasterPageTarget.is() )
391 xMasterPageTarget->setMasterPage( pMasterPersistPtr->getPage() );
392 }
393 rFilter.getDrawPages().push_back( pSlidePersistPtr );
394 rFilter.setActualSlidePersist( pSlidePersistPtr );
395 importSlide( xSlideFragmentHandler, pSlidePersistPtr );
396 pSlidePersistPtr->createBackground( rFilter );
397 pSlidePersistPtr->createXShapes( rFilter );
398
399 if(bImportNotesPage) {
400
401 // now importing the notes page
402 OUString aNotesFragmentPath = xSlideFragmentHandler->getFragmentPathFromFirstTypeFromOfficeDoc( u"notesSlide" );
403 if( !aNotesFragmentPath.isEmpty() )
404 {
405 Reference< XPresentationPage > xPresentationPage( xSlide, UNO_QUERY );
406 if ( xPresentationPage.is() )
407 {
408 Reference< XDrawPage > xNotesPage( xPresentationPage->getNotesPage() );
409 if ( xNotesPage.is() )
410 {
411 SlidePersistPtr pNotesPersistPtr = std::make_shared<SlidePersist>( rFilter, false, true, xNotesPage,
412 std::make_shared<PPTShape>( Slide, "com.sun.star.drawing.GroupShape" ), mpTextListStyle );
413 FragmentHandlerRef xNotesFragmentHandler( new SlideFragmentHandler( getFilter(), aNotesFragmentPath, pNotesPersistPtr, Slide ) );
414 rFilter.getNotesPages().push_back( pNotesPersistPtr );
415 rFilter.setActualSlidePersist( pNotesPersistPtr );
416 importSlide( xNotesFragmentHandler, pNotesPersistPtr );
417 pNotesPersistPtr->createBackground( rFilter );
418 pNotesPersistPtr->createXShapes( rFilter );
419 }
420 }
421 }
422 }
423
424 if( !mbCommentAuthorsRead && !aCommentFragmentPath.isEmpty() )
425 {
426 // Comments are present and commentAuthors.xml has still not been read
428 Reference< XPresentationPage > xPresentationPage( xSlide, UNO_QUERY );
429 Reference< XDrawPage > xCommentAuthorsPage( xPresentationPage->getNotesPage() );
430 SlidePersistPtr pCommentAuthorsPersistPtr =
431 std::make_shared<SlidePersist>( rFilter, false, true, xCommentAuthorsPage,
432 std::make_shared<PPTShape>(
433 Slide, "com.sun.star.drawing.GroupShape" ),
435 FragmentHandlerRef xCommentAuthorsFragmentHandler(
436 new SlideFragmentHandler( getFilter(),
437 "ppt/commentAuthors.xml",
438 pCommentAuthorsPersistPtr,
439 Slide ) );
440
441 getFilter().importFragment( xCommentAuthorsFragmentHandler );
442 maAuthorList.setValues( pCommentAuthorsPersistPtr->getCommentAuthors() );
443 }
444 if( !aCommentFragmentPath.isEmpty() )
445 {
446 Reference< XPresentationPage > xPresentationPage( xSlide, UNO_QUERY );
447 Reference< XDrawPage > xCommentsPage( xPresentationPage->getNotesPage() );
448 SlidePersistPtr pCommentsPersistPtr =
449 std::make_shared<SlidePersist>(
450 rFilter, false, true, xCommentsPage,
451 std::make_shared<PPTShape>(
452 Slide, "com.sun.star.drawing.GroupShape" ),
454
455 FragmentHandlerRef xCommentsFragmentHandler(
457 getFilter(),
458 aCommentFragmentPath,
459 pCommentsPersistPtr,
460 Slide ) );
461 pCommentsPersistPtr->getCommentsList().cmLst.clear();
462 getFilter().importFragment( xCommentsFragmentHandler );
463
464 if (!pCommentsPersistPtr->getCommentsList().cmLst.empty())
465 {
466 //set comment chars for last comment on slide
467 SlideFragmentHandler* comment_handler =
468 dynamic_cast<SlideFragmentHandler*>(xCommentsFragmentHandler.get());
469 assert(comment_handler);
470 // some comments have no text -> set empty string as text to avoid
471 // crash (back() on empty vector is undefined) and losing other
472 // comment data that might be there (author, position, timestamp etc.)
473 pCommentsPersistPtr->getCommentsList().cmLst.back().setText(
474 comment_handler->getCharVector().empty() ? "" :
475 comment_handler->getCharVector().back() );
476 }
477 pCommentsPersistPtr->getCommentAuthors().setValues(maAuthorList);
478
479 //insert all comments from commentsList
480 for(int i=0; i<pCommentsPersistPtr->getCommentsList().getSize(); i++)
481 {
482 try {
483 Comment aComment = pCommentsPersistPtr->getCommentsList().getCommentAtIndex(i);
484 uno::Reference< office::XAnnotationAccess > xAnnotationAccess( xSlide, UNO_QUERY_THROW );
485 uno::Reference< office::XAnnotation > xAnnotation( xAnnotationAccess->createAndInsertAnnotation() );
486 int nPosX = aComment.getIntX();
487 int nPosY = aComment.getIntY();
488 xAnnotation->setPosition(
489 geometry::RealPoint2D(
490 ::oox::drawingml::convertEmuToHmm( nPosX ) * 15.87,
491 ::oox::drawingml::convertEmuToHmm( nPosY ) * 15.87 ) );
492 xAnnotation->setAuthor( aComment.getAuthor(maAuthorList) );
493 xAnnotation->setDateTime( aComment.getDateTime() );
494 uno::Reference< text::XText > xText( xAnnotation->getTextRange() );
495 xText->setString( aComment.get_text());
496 } catch( css::lang::IllegalArgumentException& ) {}
497 }
498 }
499 }
500 }
501 catch( uno::Exception& )
502 {
503 TOOLS_WARN_EXCEPTION( "oox", "oox::ppt::PresentationFragmentHandler::EndDocument()" );
504 }
505}
506
508{
509 PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() );
510
511 sal_Int32 nPageCount = maSlidesVector.size();
512
513 // we will take the FilterData property "PageRange" if available, otherwise full range is used
514 comphelper::SequenceAsHashMap& rFilterData = rFilter.getFilterData();
515
516 // writing back the original PageCount of this document, it can be accessed from the XModel
517 // via getArgs after the import.
518 rFilterData["OriginalPageCount"] <<= nPageCount;
519 bool bImportNotesPages = rFilterData.getUnpackedValueOrDefault("ImportNotesPages", true);
520 OUString aPageRange = rFilterData.getUnpackedValueOrDefault("PageRange", OUString());
521
522 if( !aPageRange.getLength() )
523 {
524 aPageRange = "1-" + OUString::number( nPageCount );
525 }
526
527 StringRangeEnumerator aRangeEnumerator( aPageRange, 0, nPageCount - 1 );
528 if (aRangeEnumerator.size())
529 {
530 // todo: localized progress bar text
531 const Reference< task::XStatusIndicator >& rxStatusIndicator( getFilter().getStatusIndicator() );
532 if ( rxStatusIndicator.is() )
533 rxStatusIndicator->start( OUString(), 10000 );
534
535 try
536 {
537 int nPagesImported = 0;
538 for (sal_Int32 elem : aRangeEnumerator)
539 {
540 if ( rxStatusIndicator.is() )
541 rxStatusIndicator->setValue((nPagesImported * 10000) / aRangeEnumerator.size());
542
543 importSlide(elem, !nPagesImported, bImportNotesPages);
544 nPagesImported++;
545 }
546 importSlideNames( rFilter, rFilter.getDrawPages());
547 if (!maCustomShowList.empty())
549 }
550 catch( uno::Exception& )
551 {
552 TOOLS_WARN_EXCEPTION( "oox", "oox::ppt::PresentationFragmentHandler::finalizeImport()" );
553 }
554 // todo error handling;
555 if ( rxStatusIndicator.is() )
556 rxStatusIndicator->end();
557 }
558
559 // open the VBA project storage
560 OUString aVbaFragmentPath = getFragmentPathFromFirstType(CREATE_MSOFFICE_RELATION_TYPE("vbaProject"));
561 if (!aVbaFragmentPath.isEmpty())
562 {
563 uno::Reference<io::XInputStream> xInStrm = getFilter().openInputStream(aVbaFragmentPath);
564 if (xInStrm.is())
565 {
566 StorageRef xPrjStrg = std::make_shared<oox::ole::OleStorage>(getFilter().getComponentContext(), xInStrm, false);
567 getFilter().getVbaProject().importVbaProject(*xPrjStrg);
568 }
569 }
570}
571
572// CT_Presentation
574{
575 switch( aElementToken )
576 {
577 case PPT_TOKEN( presentation ):
578 case PPT_TOKEN( sldMasterIdLst ):
579 case PPT_TOKEN( notesMasterIdLst ):
580 case PPT_TOKEN( sldIdLst ):
581 return this;
582 case PPT_TOKEN( sldMasterId ):
583 maSlideMasterVector.push_back( rAttribs.getStringDefaulted( R_TOKEN( id )) );
584 return this;
585 case PPT_TOKEN( sldId ):
586 maSlidesVector.push_back( rAttribs.getStringDefaulted( R_TOKEN( id )) );
587 return this;
588 case PPT_TOKEN( notesMasterId ):
589 maNotesMasterVector.push_back( rAttribs.getStringDefaulted( R_TOKEN( id )) );
590 return this;
591 case PPT_TOKEN( sldSz ):
593 return this;
594 case PPT_TOKEN( notesSz ):
596 return this;
597 case PPT_TOKEN( custShowLst ):
598 return new CustomShowListContext( *this, maCustomShowList );
599 case PPT_TOKEN( defaultTextStyle ):
600 return new TextListStyleContext( *this, *mpTextListStyle );
601 case PPT_TOKEN( modifyVerifier ):
602 OUString sAlgorithmClass = rAttribs.getStringDefaulted(XML_cryptAlgorithmClass);
603 OUString sAlgorithmType = rAttribs.getStringDefaulted(XML_cryptAlgorithmType);
604 sal_Int32 nAlgorithmSid = rAttribs.getInteger(XML_cryptAlgorithmSid, 0);
605 sal_Int32 nSpinCount = rAttribs.getInteger(XML_spinCount, 0);
606 OUString sSalt = rAttribs.getStringDefaulted(XML_saltData);
607 OUString sHash = rAttribs.getStringDefaulted(XML_hashData);
608 if (sAlgorithmClass == "hash" && sAlgorithmType == "typeAny" && nAlgorithmSid != 0
609 && !sSalt.isEmpty() && !sHash.isEmpty())
610 {
611 OUString sAlgorithmName;
612 switch (nAlgorithmSid)
613 {
614 case 1:
615 sAlgorithmName = "MD2";
616 break;
617 case 2:
618 sAlgorithmName = "MD4";
619 break;
620 case 3:
621 sAlgorithmName = "MD5";
622 break;
623 case 4:
624 sAlgorithmName = "SHA-1";
625 break;
626 case 5:
627 sAlgorithmName = "MAC";
628 break;
629 case 6:
630 sAlgorithmName = "RIPEMD";
631 break;
632 case 7:
633 sAlgorithmName = "RIPEMD-160";
634 break;
635 case 9:
636 sAlgorithmName = "HMAC";
637 break;
638 case 12:
639 sAlgorithmName = "SHA-256";
640 break;
641 case 13:
642 sAlgorithmName = "SHA-384";
643 break;
644 case 14:
645 sAlgorithmName = "SHA-512";
646 break;
647 default:; // 8, 10, 11, any other value: Undefined.
648 }
649
650 if (!sAlgorithmName.isEmpty())
651 {
652 uno::Sequence<beans::PropertyValue> aResult{
653 comphelper::makePropertyValue("algorithm-name", sAlgorithmName),
654 comphelper::makePropertyValue("salt", sSalt),
655 comphelper::makePropertyValue("iteration-count", nSpinCount),
657 };
658 try
659 {
660 uno::Reference<beans::XPropertySet> xDocSettings(
661 getFilter().getModelFactory()->createInstance(
662 "com.sun.star.document.Settings"),
663 uno::UNO_QUERY);
664 xDocSettings->setPropertyValue("ModifyPasswordInfo", uno::Any(aResult));
665 }
666 catch (const uno::Exception&)
667 {
668 }
669 }
670 }
671 return this;
672 }
673 return this;
674}
675
676void PresentationFragmentHandler::importSlide( const FragmentHandlerRef& rxSlideFragmentHandler,
677 const SlidePersistPtr& rSlidePersistPtr )
678{
679 Reference< drawing::XDrawPage > xSlide( rSlidePersistPtr->getPage() );
680 SlidePersistPtr pMasterPersistPtr( rSlidePersistPtr->getMasterPersist() );
681 if ( pMasterPersistPtr )
682 {
683 // Setting "Layout" property adds extra title and outliner preset shapes to the master slide
684 Reference< drawing::XDrawPage > xMasterSlide(pMasterPersistPtr->getPage());
685 const int nCount = xMasterSlide->getCount();
686
687 uno::Reference< beans::XPropertySet > xSet( xSlide, uno::UNO_QUERY_THROW );
688 xSet->setPropertyValue( "Layout", Any( pMasterPersistPtr->getLayoutFromValueToken() ) );
689
690 while( nCount < xMasterSlide->getCount())
691 {
692 Reference< drawing::XShape > xShape;
693 xMasterSlide->getByIndex(xMasterSlide->getCount()-1) >>= xShape;
694 xMasterSlide->remove(xShape);
695 }
696 }
697 while( xSlide->getCount() )
698 {
699 Reference< drawing::XShape > xShape;
700 xSlide->getByIndex(0) >>= xShape;
701 xSlide->remove( xShape );
702 }
703
704 Reference< XPropertySet > xPropertySet( xSlide, UNO_QUERY );
705 if ( xPropertySet.is() )
706 {
707 awt::Size& rPageSize( rSlidePersistPtr->isNotesPage() ? maNotesSize : maSlideSize );
708 xPropertySet->setPropertyValue( "Width", Any( rPageSize.Width ) );
709 xPropertySet->setPropertyValue( "Height", Any( rPageSize.Height ) );
710
711 oox::ppt::HeaderFooter aHeaderFooter( rSlidePersistPtr->getHeaderFooter() );
712 if ( !rSlidePersistPtr->isMasterPage() )
713 aHeaderFooter.mbSlideNumber = aHeaderFooter.mbHeader = aHeaderFooter.mbFooter = aHeaderFooter.mbDateTime = false;
714 try
715 {
716 if ( rSlidePersistPtr->isNotesPage() )
717 xPropertySet->setPropertyValue( "IsHeaderVisible", Any( aHeaderFooter.mbHeader ) );
718 xPropertySet->setPropertyValue( "IsFooterVisible", Any( aHeaderFooter.mbFooter ) );
719 xPropertySet->setPropertyValue( "IsDateTimeVisible", Any( aHeaderFooter.mbDateTime ) );
720 xPropertySet->setPropertyValue( "IsPageNumberVisible", Any( aHeaderFooter.mbSlideNumber ) );
721 }
722 catch( uno::Exception& )
723 {
724 }
725 }
726 rSlidePersistPtr->setPath( rxSlideFragmentHandler->getFragmentPath() );
727 getFilter().importFragment( rxSlideFragmentHandler );
728}
729
730}
731
732/* 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
const ::std::vector< OUString > & getCharVector() const
int nCount
#define TOOLS_WARN_EXCEPTION(area, stream)
OString sName
Definition: drawingml.cxx:4478
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)
constexpr bool ends_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
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:53
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