LibreOffice Module sd (master) 1
drawdoc3.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
21#include <memory>
22#include <string_view>
23
24#include <sfx2/docfile.hxx>
25#include <sfx2/docfilt.hxx>
26#include <sfx2/app.hxx>
27#include <svl/itemset.hxx>
28#include <tools/debug.hxx>
30
31#include <sfx2/fcontnr.hxx>
32#include <svl/style.hxx>
33#include <svx/svdpagv.hxx>
34#include <svx/svdundo.hxx>
35#include <vcl/stdtext.hxx>
36#include <vcl/svapp.hxx>
37#include <vcl/weld.hxx>
38#include <xmloff/autolayout.hxx>
39
40#include <strings.hrc>
41#include <drawdoc.hxx>
42#include <sdmod.hxx>
43#include <sdpage.hxx>
44#include <stlpool.hxx>
45#include <sdresid.hxx>
46#include <customshowlist.hxx>
47#include <sdxfer.hxx>
48
49#include <unmovss.hxx>
50#include <unchss.hxx>
51#include <unprlout.hxx>
52#include <DrawDocShell.hxx>
53#include <GraphicDocShell.hxx>
54#include <ViewShell.hxx>
55#include <View.hxx>
56#include <ViewShellBase.hxx>
57#include <strings.hxx>
58
59using namespace ::com::sun::star;
60
65namespace {
66
67class InsertBookmarkAsPage_FindDuplicateLayouts
68{
69public:
70 explicit InsertBookmarkAsPage_FindDuplicateLayouts( std::vector<OUString> &rLayoutsToTransfer )
71 : mrLayoutsToTransfer(rLayoutsToTransfer) {}
72 void operator()( SdDrawDocument&, SdPage const *, bool, SdDrawDocument* );
73private:
74 std::vector<OUString> &mrLayoutsToTransfer;
75};
76
77}
78
79void InsertBookmarkAsPage_FindDuplicateLayouts::operator()( SdDrawDocument& rDoc, SdPage const * pBMMPage, bool bRenameDuplicates, SdDrawDocument* pBookmarkDoc )
80{
81 // now check for duplicate masterpage and layout names
82
83 OUString aLayout( pBMMPage->GetLayoutName() );
84 sal_Int32 nIndex = aLayout.indexOf( SD_LT_SEPARATOR );
85 if( nIndex != -1 )
86 aLayout = aLayout.copy(0, nIndex);
87
88 std::vector<OUString>::const_iterator pIter =
89 find(mrLayoutsToTransfer.begin(),mrLayoutsToTransfer.end(),aLayout);
90
91 bool bFound = pIter != mrLayoutsToTransfer.end();
92
93 const sal_uInt16 nMPageCount = rDoc.GetMasterPageCount();
94 for (sal_uInt16 nMPage = 0; nMPage < nMPageCount && !bFound; nMPage++)
95 {
96 // Do the layouts already exist within the document?
97 SdPage* pTestPage = static_cast<SdPage*>( rDoc.GetMasterPage(nMPage) );
98 OUString aTest(pTestPage->GetLayoutName());
99 sal_Int32 nIndex2 = aTest.indexOf( SD_LT_SEPARATOR );
100 if( nIndex2 != -1 )
101 aTest = aTest.copy(0, nIndex2);
102
103 if (aTest == aLayout && pBMMPage->GetPageKind() == pTestPage->GetPageKind())
104 {
105 // Ignore Layouts with "Default" these seem to be special - in the sense that there are lot of assumption all over Impress
106 // about this
107 if( bRenameDuplicates && aTest != SdResId( STR_LAYOUT_DEFAULT_NAME ) && !(pTestPage->Equals(*pBMMPage)) )
108 {
109 pBookmarkDoc->RenameLayoutTemplate(
110 pBMMPage->GetLayoutName(), pBMMPage->GetName() + "_");
111 aLayout = pBMMPage->GetName();
112
113 break;
114 }
115 else
116 bFound = true;
117 }
118 }
119
120 if (!bFound)
121 mrLayoutsToTransfer.push_back(aLayout);
122}
123
124// Inserts a bookmark as a page
126 const std::vector<OUString> &rBookmarkList, sal_uInt16 nBMSdPageCount,
127 InsertBookmarkAsPage_FindDuplicateLayouts& rPageIterator, bool bRenameDuplicates )
128{
129
130 // Refactored copy'n'pasted layout name collection from InsertBookmarkAsPage
131
132 int nPos, nEndPos;
133
134 if( rBookmarkList.empty() )
135 {
136 // no list? whole source document
137 nEndPos = nBMSdPageCount;
138 }
139 else
140 {
141 // bookmark list? number of entries
142 nEndPos = rBookmarkList.size();
143 }
144
145 SdPage* pBMPage;
146
147 // iterate over number of pages to insert
148 for (nPos = 0; nPos < nEndPos; ++nPos)
149 {
150 // the master page associated to the nPos'th page to insert
151 SdPage* pBMMPage = nullptr;
152
153 if( rBookmarkList.empty() )
154 {
155 // simply take master page of nPos'th page in source document
156 pBMMPage = static_cast<SdPage*>(&(pBookmarkDoc->GetSdPage(static_cast<sal_uInt16>(nPos), PageKind::Standard)->TRG_GetMasterPage()));
157 }
158 else
159 {
160 // fetch nPos'th entry from bookmark list, and determine master page
161 OUString aBMPgName(rBookmarkList[nPos]);
162 bool bIsMasterPage;
163
164 sal_uInt16 nBMPage = pBookmarkDoc->GetPageByName( aBMPgName, bIsMasterPage );
165
166 if (nBMPage != SDRPAGE_NOTFOUND)
167 {
168 pBMPage = static_cast<SdPage*>( pBookmarkDoc->GetPage(nBMPage) );
169 }
170 else
171 {
172 pBMPage = nullptr;
173 }
174
175 // enforce that bookmarked page is a standard page and not already a master page
176 if (pBMPage && pBMPage->GetPageKind()==PageKind::Standard && !pBMPage->IsMasterPage())
177 {
178 const sal_uInt16 nBMSdPage = (nBMPage - 1) / 2;
179 pBMMPage = static_cast<SdPage*> (&(pBookmarkDoc->GetSdPage(nBMSdPage, PageKind::Standard)->TRG_GetMasterPage()));
180 }
181 }
182
183 // successfully determined valid (bookmarked) page?
184 if( pBMMPage )
185 {
186 // yes, call functor
187 rPageIterator( rDoc, pBMMPage, bRenameDuplicates, pBookmarkDoc );
188 }
189 }
190}
191
192// Opens a bookmark document
194{
195 bool bOK = true;
196 SdDrawDocument* pBookmarkDoc = nullptr;
197 OUString aBookmarkName = pMedium->GetName();
198 std::shared_ptr<const SfxFilter> pFilter = pMedium->GetFilter();
199 if ( !pFilter )
200 {
201 pMedium->UseInteractionHandler( true );
202 SfxGetpApp()->GetFilterMatcher().GuessFilter(*pMedium, pFilter);
203 }
204
205 if ( !pFilter )
206 {
207 bOK = false;
208 }
209 else if ( !aBookmarkName.isEmpty() && maBookmarkFile != aBookmarkName )
210 {
211 bool bCreateGraphicShell = pFilter->GetServiceName() == "com.sun.star.drawing.DrawingDocument";
212 bool bCreateImpressShell = pFilter->GetServiceName() == "com.sun.star.presentation.PresentationDocument";
213 if ( bCreateGraphicShell || bCreateImpressShell )
214 {
216
217 // Create a DocShell, as OLE objects might be contained in the
218 // document. (Persist)
219 // If that wasn't the case, we could load the model directly.
220 if ( bCreateGraphicShell )
221 // Draw
222 mxBookmarkDocShRef = new ::sd::GraphicDocShell(SfxObjectCreateMode::STANDARD);
223 else
224 // Impress
225 mxBookmarkDocShRef = new ::sd::DrawDocShell(SfxObjectCreateMode::STANDARD, true, DocumentType::Impress);
226
227 bOK = mxBookmarkDocShRef->DoLoad(pMedium);
228 if( bOK )
229 {
230 maBookmarkFile = aBookmarkName;
231 pBookmarkDoc = mxBookmarkDocShRef->GetDoc();
232 }
233 }
234 }
235
236 DBG_ASSERT(!aBookmarkName.isEmpty(), "Empty document name!");
237
238 if (!bOK)
239 {
240 std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(nullptr,
241 VclMessageType::Warning, VclButtonsType::Ok, SdResId(STR_READ_DATA_ERROR)));
242 xErrorBox->run();
243
245 pBookmarkDoc = nullptr;
246 }
247 else if (mxBookmarkDocShRef.is())
248 {
249 pBookmarkDoc = mxBookmarkDocShRef->GetDoc();
250 }
251
252 return pBookmarkDoc;
253}
254
255// Opens a bookmark document
256SdDrawDocument* SdDrawDocument::OpenBookmarkDoc(const OUString& rBookmarkFile)
257{
258 SdDrawDocument* pBookmarkDoc = nullptr;
259
260 if (!rBookmarkFile.isEmpty() && maBookmarkFile != rBookmarkFile)
261 {
262 std::unique_ptr<SfxMedium> xMedium(new SfxMedium(rBookmarkFile, StreamMode::READ));
263 pBookmarkDoc = OpenBookmarkDoc(xMedium.release());
264 }
265 else if (mxBookmarkDocShRef.is())
266 {
267 pBookmarkDoc = mxBookmarkDocShRef->GetDoc();
268 }
269
270 return pBookmarkDoc;
271}
272
273// Inserts a bookmark (page or object)
275 const std::vector<OUString> &rBookmarkList, // List of names of the bookmarks to be inserted
276 std::vector<OUString> &rExchangeList, // List of the names to be used
277 bool bLink, // Insert bookmarks as links?
278 sal_uInt16 nInsertPos, // Insertion position of pages
279 ::sd::DrawDocShell* pBookmarkDocSh, // If set, this is the source document
280 Point const * pObjPos) // Insertion position of objects
281{
282 bool bOK = true;
283 bool bInsertPages = false;
284
285 if (rBookmarkList.empty())
286 {
287 // Insert all pages
288 bInsertPages = true;
289 }
290 else
291 {
292 SdDrawDocument* pBookmarkDoc = nullptr;
293
294 if (pBookmarkDocSh)
295 {
296 pBookmarkDoc = pBookmarkDocSh->GetDoc();
297 }
298 else if ( mxBookmarkDocShRef.is() )
299 {
300 pBookmarkDoc = mxBookmarkDocShRef->GetDoc();
301 }
302 else
303 bOK = false;
304
305 bInsertPages = bOK && std::any_of(rBookmarkList.begin(), rBookmarkList.end(),
306 [&pBookmarkDoc](const OUString& rBookmark) {
307 // Is there a page name in the bookmark list?
308 bool bIsMasterPage;
309 return pBookmarkDoc->GetPageByName(rBookmark, bIsMasterPage) != SDRPAGE_NOTFOUND;
310 });
311 }
312
313 bool bCalcObjCount = !rExchangeList.empty();
314
315 if ( bOK && bInsertPages )
316 {
317 // Insert all page bookmarks
318 bOK = InsertBookmarkAsPage(rBookmarkList, &rExchangeList, bLink, false/*bReplace*/,
319 nInsertPos, false/*bNoDialogs*/, pBookmarkDocSh, true/*bCopy*/, true, false);
320 }
321
322 if ( bOK && !rBookmarkList.empty() )
323 {
324 // Insert all object bookmarks
325 InsertBookmarkAsObject(rBookmarkList, rExchangeList,
326 pBookmarkDocSh, pObjPos, bCalcObjCount);
327 }
328}
329
330namespace
331{
332
333void
334lcl_removeUnusedStyles(SfxStyleSheetBasePool* const pStyleSheetPool, StyleSheetCopyResultVector& rStyles)
335{
336 StyleSheetCopyResultVector aUsedStyles;
337 aUsedStyles.reserve(rStyles.size());
338 for (const auto& a : rStyles)
339 {
340 if (a.m_xStyleSheet->IsUsed())
341 aUsedStyles.push_back(a);
342 else
343 pStyleSheetPool->Remove(a.m_xStyleSheet.get());
344 }
345 rStyles = aUsedStyles;
346}
347
348void
349lcl_removeUnusedTableStyles(SdStyleSheetPool* const pStyleSheetPool, XStyleVector const & rStyles)
350{
351 css::uno::Reference<css::container::XNameContainer> xTableFamily(
352 pStyleSheetPool->getByName("table"), css::uno::UNO_QUERY);
353 if (!xTableFamily)
354 return;
355
356 for (const auto& a : rStyles)
357 {
358 if (!a->isInUse())
359 xTableFamily->removeByName(a->getName());
360 }
361}
362
363SfxStyleSheet *lcl_findStyle(StyleSheetCopyResultVector& rStyles, std::u16string_view aStyleName)
364{
365 for (const auto& a : rStyles)
366 {
367 if (a.m_xStyleSheet->GetName().startsWith(aStyleName))
368 return a.m_xStyleSheet.get();
369 }
370 return nullptr;
371}
372
373}
374
376 const std::vector<OUString> &rBookmarkList,
377 std::vector<OUString> *pExchangeList, // List of names to be used
378 bool bLink,
379 bool bReplace,
380 sal_uInt16 nInsertPos,
381 bool bNoDialogs,
382 ::sd::DrawDocShell* pBookmarkDocSh,
383 bool bCopy,
384 bool bMergeMasterPages,
385 bool bPreservePageNames)
386{
387 bool bContinue = true;
388 bool bScaleObjects = false;
389 sal_uInt16 nReplacedStandardPages = 0;
390
391 SdDrawDocument* pBookmarkDoc = nullptr;
392 OUString aBookmarkName;
393
394 if (pBookmarkDocSh)
395 {
396 pBookmarkDoc = pBookmarkDocSh->GetDoc();
397
398 if (pBookmarkDocSh->GetMedium())
399 {
400 aBookmarkName = pBookmarkDocSh->GetMedium()->GetName();
401 }
402 }
403 else if ( mxBookmarkDocShRef.is() )
404 {
405 pBookmarkDoc = mxBookmarkDocShRef->GetDoc();
406 aBookmarkName = maBookmarkFile;
407 }
408 else
409 {
410 return false;
411 }
412
413 const sal_uInt16 nSdPageCount = GetSdPageCount(PageKind::Standard);
414 const sal_uInt16 nBMSdPageCount = pBookmarkDoc->GetSdPageCount(PageKind::Standard);
415 const sal_uInt16 nMPageCount = GetMasterPageCount();
416
417 if (nSdPageCount==0 || nBMSdPageCount==0 || nMPageCount==0)
418 {
419 return false;
420 }
421
422 // Store the size and some other properties of the first page and notes
423 // page so that inserted pages can be properly scaled even when inserted
424 // before the first page.
425 // Note that the pointers are used later on as general page pointers.
426 SdPage* pRefPage = GetSdPage(0, PageKind::Standard);
427 Size aSize(pRefPage->GetSize());
428 sal_Int32 nLeft = pRefPage->GetLeftBorder();
429 sal_Int32 nRight = pRefPage->GetRightBorder();
430 sal_Int32 nUpper = pRefPage->GetUpperBorder();
431 sal_Int32 nLower = pRefPage->GetLowerBorder();
432 Orientation eOrient = pRefPage->GetOrientation();
433
434 SdPage* pNPage = GetSdPage(0, PageKind::Notes);
435 Size aNSize(pNPage->GetSize());
436 sal_Int32 nNLeft = pNPage->GetLeftBorder();
437 sal_Int32 nNRight = pNPage->GetRightBorder();
438 sal_Int32 nNUpper = pNPage->GetUpperBorder();
439 sal_Int32 nNLower = pNPage->GetLowerBorder();
440 Orientation eNOrient = pNPage->GetOrientation();
441
442 // Adapt page size and margins to those of the later pages?
443 pRefPage = GetSdPage(nSdPageCount - 1, PageKind::Standard);
444
445 if( bNoDialogs )
446 {
447 // If this is clipboard, then no need to scale objects:
448 // this will make copied masters to differ from the originals,
449 // and thus InsertBookmarkAsPage_FindDuplicateLayouts will
450 // duplicate masters on insert to same document
451 m_bTransportContainer = (SD_MOD()->pTransferClip &&
452 SD_MOD()->pTransferClip->GetWorkDocument() == this);
454 {
455 if (rBookmarkList.empty())
456 bScaleObjects = pRefPage->IsScaleObjects();
457 else
458 bScaleObjects = true;
459 }
460 }
461 else
462 {
463 SdPage* pBMPage = pBookmarkDoc->GetSdPage(0,PageKind::Standard);
464
465 if (pBMPage->GetSize() != pRefPage->GetSize() ||
466 pBMPage->GetLeftBorder() != pRefPage->GetLeftBorder() ||
467 pBMPage->GetRightBorder() != pRefPage->GetRightBorder() ||
468 pBMPage->GetUpperBorder() != pRefPage->GetUpperBorder() ||
469 pBMPage->GetLowerBorder() != pRefPage->GetLowerBorder())
470 {
471 OUString aStr(SdResId(STR_SCALE_OBJECTS));
472 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(nullptr,
473 VclMessageType::Question, VclButtonsType::YesNo,
474 aStr));
475 xQueryBox->add_button(GetStandardText(StandardButtonType::Cancel), RET_CANCEL);
476 sal_uInt16 nBut = xQueryBox->run();
477
478 bScaleObjects = nBut == RET_YES;
479 bContinue = nBut != RET_CANCEL;
480
481 if (!bContinue)
482 {
483 return bContinue;
484 }
485 }
486 }
487
488 // Get the necessary presentation stylesheets and transfer them before
489 // the pages, else, the text objects won't reference their styles anymore.
490 SfxUndoManager* pUndoMgr = nullptr;
491 if( mpDocSh )
492 {
493 pUndoMgr = mpDocSh->GetUndoManager();
494 ViewShellId nViewShellId(-1);
495 if (sd::ViewShell* pViewShell = mpDocSh->GetViewShell())
496 nViewShellId = pViewShell->GetViewShellBase().GetViewShellId();
497 pUndoMgr->EnterListAction(SdResId(STR_UNDO_INSERTPAGES), "", 0, nViewShellId);
498 }
499
500 // Refactored copy'n'pasted layout name collection into IterateBookmarkPages
501
502 std::vector<OUString> aLayoutsToTransfer;
503 InsertBookmarkAsPage_FindDuplicateLayouts aSearchFunctor( aLayoutsToTransfer );
504 lcl_IterateBookmarkPages( *this, pBookmarkDoc, rBookmarkList, nBMSdPageCount, aSearchFunctor, ( rBookmarkList.empty() && pBookmarkDoc != this ) );
505
506 // Copy the style that we actually need.
507 SdStyleSheetPool& rBookmarkStyleSheetPool = dynamic_cast<SdStyleSheetPool&>(*pBookmarkDoc->GetStyleSheetPool());
508 SdStyleSheetPool& rStyleSheetPool = dynamic_cast<SdStyleSheetPool&>(*GetStyleSheetPool());
509
510 // When copying styles, also copy the master pages!
511 if( !aLayoutsToTransfer.empty() )
512 bMergeMasterPages = true;
513
514 for ( const OUString& layoutName : aLayoutsToTransfer )
515 {
516 StyleSheetCopyResultVector aCreatedStyles;
517
518 rStyleSheetPool.CopyLayoutSheets(layoutName, rBookmarkStyleSheetPool,aCreatedStyles);
519
520 if(!aCreatedStyles.empty())
521 {
522 if( pUndoMgr )
523 {
524 pUndoMgr->AddUndoAction(std::make_unique<SdMoveStyleSheetsUndoAction>(this, aCreatedStyles, true));
525 }
526 }
527 }
528
529 // Copy styles. This unconditionally copies all styles, even those
530 // that are not used in any of the inserted pages. The unused styles
531 // are then removed at the end of the function, where we also create
532 // undo records for the inserted styles.
533 StyleSheetCopyResultVector aNewGraphicStyles;
534 OUString aRenameStr;
535 if(!bReplace && !bNoDialogs)
536 aRenameStr = "_";
537 rStyleSheetPool.RenameAndCopyGraphicSheets(rBookmarkStyleSheetPool, aNewGraphicStyles, aRenameStr);
538 StyleSheetCopyResultVector aNewCellStyles;
539 rStyleSheetPool.CopyCellSheets(rBookmarkStyleSheetPool, aNewCellStyles);
540
541 // TODO handle undo of table styles too
542 XStyleVector aNewTableStyles;
543 rStyleSheetPool.CopyTableStyles(rBookmarkStyleSheetPool, aNewTableStyles);
544
545 // Insert document
546
547 const bool bUndo = IsUndoEnabled();
548
549 if( bUndo )
550 BegUndo(SdResId(STR_UNDO_INSERTPAGES));
551
552 if (rBookmarkList.empty())
553 {
554 if (nInsertPos >= GetPageCount())
555 {
556 // Add pages to the end
557 nInsertPos = GetPageCount();
558 }
559
560 sal_uInt16 nActualInsertPos = nInsertPos;
561
562 sal_uInt16 nBMSdPage;
563 std::set<sal_uInt16> aRenameSet;
564 std::map<sal_uInt16,OUString> aNameMap;
565
566 for (nBMSdPage=0; nBMSdPage < nBMSdPageCount; nBMSdPage++)
567 {
568 SdPage* pBMPage = pBookmarkDoc->GetSdPage(nBMSdPage, PageKind::Standard);
569 OUString sName(pBMPage->GetName());
570 bool bIsMasterPage;
571
572 if (bLink)
573 {
574 // Remember the names of all pages
575 aNameMap.insert(std::make_pair(nBMSdPage,sName));
576 }
577
578 // Have to check for duplicate names here, too
579 // don't change name if source and dest model are the same!
580 if( pBookmarkDoc != this &&
581 GetPageByName(sName, bIsMasterPage ) != SDRPAGE_NOTFOUND )
582 {
583 // delay renaming *after* pages are copied (might destroy source otherwise)
584 aRenameSet.insert(nBMSdPage);
585 }
586 }
587
588 Merge(*pBookmarkDoc,
589 1, // Not the handout page
590 0xFFFF, // But all others
591 nActualInsertPos, // Insert at position ...
592 bMergeMasterPages, // Move master pages?
593 false, // But only the master pages used
594 true, // Create an undo action
595 bCopy); // Copy (or merge) pages?
596
597 for (nBMSdPage=0; nBMSdPage < nBMSdPageCount; nBMSdPage++)
598 {
599 SdPage* pPage = static_cast<SdPage*>( GetPage(nActualInsertPos) );
600 SdPage* pNotesPage = static_cast<SdPage*>( GetPage(nActualInsertPos+1) );
601
602 // delay renaming *after* pages are copied (might destroy source otherwise)
603 if( aRenameSet.find(nBMSdPage) != aRenameSet.end() )
604 {
605 // Page name already in use -> Use default name for default and
606 // notes page
607 pPage->SetName(OUString());
608 pNotesPage->SetName(OUString());
609 }
610
611 if (bLink)
612 {
613 OUString aName(aNameMap[nBMSdPage]);
614
615 // Assemble all link names
616 pPage->SetFileName(aBookmarkName);
617 pPage->SetBookmarkName(aName);
618 }
619
620 nActualInsertPos += 2;
621 }
622 }
623 else
624 {
625 // Insert selected pages
626 SdPage* pBMPage;
627
628 if (nInsertPos >= GetPageCount())
629 {
630 // Add pages to the end
631 bReplace = false;
632 nInsertPos = GetPageCount();
633 }
634
635 sal_uInt16 nActualInsertPos = nInsertPos;
636
637 // Collect the bookmarked pages
638 ::std::vector<SdPage*> aBookmarkedPages (rBookmarkList.size(), nullptr);
639 for ( size_t nPos = 0, n = rBookmarkList.size(); nPos < n; ++nPos)
640 {
641 OUString aPgName(rBookmarkList[nPos]);
642 bool bIsMasterPage;
643 sal_uInt16 nBMPage = pBookmarkDoc->GetPageByName( aPgName, bIsMasterPage );
644
645 if (nBMPage != SDRPAGE_NOTFOUND)
646 {
647 aBookmarkedPages[nPos] = dynamic_cast<SdPage*>(pBookmarkDoc->GetPage(nBMPage));
648 }
649 }
650
651 for ( size_t nPos = 0, n = rBookmarkList.size(); nPos < n; ++nPos)
652 {
653 pBMPage = aBookmarkedPages[nPos];
654 sal_uInt16 nBMPage = pBMPage!=nullptr ? pBMPage->GetPageNum() : SDRPAGE_NOTFOUND;
655
656 if (pBMPage && pBMPage->GetPageKind()==PageKind::Standard && !pBMPage->IsMasterPage())
657 {
658 // It has to be a default page
659 bool bMustRename = false;
660
661 // delay renaming *after* pages are copied (might destroy source otherwise)
662 // don't change name if source and dest model are the same!
663 // avoid renaming if replacing the same page
664 OUString aPgName(rBookmarkList[nPos]);
665 bool bIsMasterPage;
666 sal_uInt16 nPageSameName = GetPageByName(aPgName, bIsMasterPage);
667 if( pBookmarkDoc != this &&
668 nPageSameName != SDRPAGE_NOTFOUND &&
669 ( !bReplace ||
670 nPageSameName != nActualInsertPos ) )
671 {
672 bMustRename = true;
673 }
674
675 SdPage* pBookmarkPage = pBMPage;
676 if (bReplace )
677 {
678 ReplacePageInCustomShows( dynamic_cast< SdPage* >( GetPage( nActualInsertPos ) ), pBookmarkPage );
679 }
680
681 Merge(*pBookmarkDoc,
682 nBMPage, // From page (default page)
683 nBMPage+1, // To page (notes page)
684 nActualInsertPos, // Insert at position
685 bMergeMasterPages, // Move master pages?
686 false, // But only the master pages used
687 true, // Create undo action
688 bCopy); // Copy (or merge) pages?
689
690 if( bReplace )
691 {
692 if( GetPage( nActualInsertPos ) != pBookmarkPage )
693 {
694 // bookmark page was not moved but cloned, so update custom shows again
695 ReplacePageInCustomShows( pBookmarkPage, dynamic_cast< SdPage* >( GetPage( nActualInsertPos ) ) );
696 }
697 }
698
699 if( bMustRename )
700 {
701 // Page name already in use -> use default name for default and
702 // notes page
703 SdPage* pPage = static_cast<SdPage*>( GetPage(nActualInsertPos) );
704 pPage->SetName(OUString());
705 SdPage* pNotesPage = static_cast<SdPage*>( GetPage(nActualInsertPos+1) );
706 pNotesPage->SetName(OUString());
707 }
708
709 if (bLink)
710 {
711 SdPage* pPage = static_cast<SdPage*>( GetPage(nActualInsertPos) );
712 pPage->SetFileName(aBookmarkName);
713 pPage->SetBookmarkName(aPgName);
714 }
715
716 if (bReplace)
717 {
718 // Remove page and notes page.
719 const sal_uInt16 nDestPageNum(nActualInsertPos + 2);
720 SdPage* pStandardPage = nullptr;
721
722 if(nDestPageNum < GetPageCount())
723 {
724 pStandardPage = static_cast<SdPage*>(GetPage(nDestPageNum));
725 }
726
727 if (pStandardPage)
728 {
729 if( bPreservePageNames )
730 {
731 // Take old slide names for inserted pages
732 SdPage* pPage = static_cast<SdPage*>( GetPage(nActualInsertPos) );
733 pPage->SetName( pStandardPage->GetRealName() );
734 }
735
736 if( bUndo )
737 AddUndo(GetSdrUndoFactory().CreateUndoDeletePage(*pStandardPage));
738
739 RemovePage(nDestPageNum);
740 }
741
742 SdPage* pNotesPage = nullptr;
743
744 if(nDestPageNum < GetPageCount())
745 {
746 pNotesPage = static_cast<SdPage*>(GetPage(nDestPageNum));
747 }
748
749 if (pNotesPage)
750 {
751 if( bPreservePageNames )
752 {
753 // Take old slide names for inserted pages
754 SdPage* pNewNotesPage = static_cast<SdPage*>( GetPage(nActualInsertPos+1));
755 if( pNewNotesPage )
756 pNewNotesPage->SetName( pStandardPage->GetRealName() );
757 }
758
759 if( bUndo )
760 AddUndo(GetSdrUndoFactory().CreateUndoDeletePage(*pNotesPage));
761
762 RemovePage(nDestPageNum);
763 }
764
765 nReplacedStandardPages++;
766 }
767
768 nActualInsertPos += 2;
769 }
770 }
771 }
772
773 // We might have duplicate master pages now, as the drawing engine does not
774 // recognize duplicates. Remove these now.
775 sal_uInt16 nNewMPageCount = GetMasterPageCount();
776
777 // Go backwards, so the numbers don't become messed up
778 for (sal_uInt16 nPage = nNewMPageCount - 1; nPage >= nMPageCount; nPage--)
779 {
780 pRefPage = static_cast<SdPage*>( GetMasterPage(nPage) );
781 OUString aMPLayout(pRefPage->GetLayoutName());
782 PageKind eKind = pRefPage->GetPageKind();
783
784 // Does this already exist?
785 for (sal_uInt16 nTest = 0; nTest < nMPageCount; nTest++)
786 {
787 SdPage* pTest = static_cast<SdPage*>( GetMasterPage(nTest) );
788 OUString aTest(pTest->GetLayoutName());
789
790 // nInsertPos > 2 is always true when inserting into non-empty models
791 if ( nInsertPos > 2 &&
792 aTest == aMPLayout &&
793 eKind == pTest->GetPageKind() )
794 {
795 if( bUndo )
796 AddUndo(GetSdrUndoFactory().CreateUndoDeletePage(*pRefPage));
797
798 RemoveMasterPage(nPage);
799
800 nNewMPageCount--;
801 break;
802 }
803 }
804 }
805
806 // nInsertPos > 2 is always true when inserting into non-empty models
807 if (nInsertPos > 0)
808 {
809 sal_uInt16 nSdPageStart = (nInsertPos - 1) / 2;
810 sal_uInt16 nSdPageEnd = bReplace
811 ? nSdPageStart + nReplacedStandardPages - 1
812 : GetSdPageCount(PageKind::Standard) - nSdPageCount + nSdPageStart - 1;
813 const bool bRemoveEmptyPresObj =
814 (pBookmarkDoc->GetDocumentType() == DocumentType::Impress) &&
816
817 std::vector<OUString>::iterator pExchangeIter;
818
819 if (pExchangeList)
820 pExchangeIter = pExchangeList->begin();
821
822 for (sal_uInt16 nSdPage = nSdPageStart; nSdPage <= nSdPageEnd; nSdPage++)
823 {
824 pRefPage = GetSdPage(nSdPage, PageKind::Standard);
825
826 if (pExchangeList && pExchangeIter != pExchangeList->end())
827 {
828 // Get the name to use from Exchange list
829 OUString aExchangeName(*pExchangeIter);
830 pRefPage->SetName(aExchangeName);
831 Broadcast(SdrHint(SdrHintKind::PageOrderChange, pRefPage));
832
833 SdPage* pNewNotesPage = GetSdPage(nSdPage, PageKind::Notes);
834 pNewNotesPage->SetName(aExchangeName);
835 Broadcast(SdrHint(SdrHintKind::PageOrderChange, pNewNotesPage));
836
837 ++pExchangeIter;
838 }
839
840 OUString aLayout(pRefPage->GetLayoutName());
841 sal_Int32 nIndex = aLayout.indexOf( SD_LT_SEPARATOR );
842 if( nIndex != -1 )
843 aLayout = aLayout.copy(0, nIndex);
844
845 // update layout and referred master page
846 pRefPage->SetPresentationLayout(aLayout);
847 if( bUndo )
848 AddUndo( GetSdrUndoFactory().CreateUndoPageChangeMasterPage( *pRefPage ) );
849
850 if (bScaleObjects)
851 {
852 ::tools::Rectangle aBorderRect(nLeft, nUpper, nRight, nLower);
853 pRefPage->ScaleObjects(aSize, aBorderRect, true);
854 }
855 pRefPage->SetSize(aSize);
856 pRefPage->SetBorder(nLeft, nUpper, nRight, nLower);
857 pRefPage->SetOrientation( eOrient );
858
859 if( bRemoveEmptyPresObj )
861
862 pRefPage = GetSdPage(nSdPage, PageKind::Notes);
863
864 // update layout and referred master page
865 pRefPage->SetPresentationLayout(aLayout);
866 if( bUndo )
867 AddUndo( GetSdrUndoFactory().CreateUndoPageChangeMasterPage( *pRefPage ) );
868
869 if (bScaleObjects)
870 {
871 ::tools::Rectangle aBorderRect(nNLeft, nNUpper, nNRight, nNLower);
872 pRefPage->ScaleObjects(aNSize, aBorderRect, true);
873 }
874
875 pRefPage->SetSize(aNSize);
876 pRefPage->SetBorder(nNLeft, nNUpper, nNRight, nNLower);
877 pRefPage->SetOrientation( eNOrient );
878
879 if( bRemoveEmptyPresObj )
881 }
882
884 if ( pExchangeList )
885 pExchangeList->erase(pExchangeList->begin(),pExchangeIter);
886
887 for (sal_uInt16 nPage = nMPageCount; nPage < nNewMPageCount; nPage++)
888 {
889 pRefPage = static_cast<SdPage*>( GetMasterPage(nPage) );
890 if (pRefPage->GetPageKind() == PageKind::Standard)
891 {
892 if (bScaleObjects)
893 {
894 ::tools::Rectangle aBorderRect(nLeft, nUpper, nRight, nLower);
895 pRefPage->ScaleObjects(aSize, aBorderRect, true);
896 }
897 pRefPage->SetSize(aSize);
898 pRefPage->SetBorder(nLeft, nUpper, nRight, nLower);
899 pRefPage->SetOrientation( eOrient );
900 }
901 else // Can only be notes
902 {
903 if (bScaleObjects)
904 {
905 ::tools::Rectangle aBorderRect(nNLeft, nNUpper, nNRight, nNLower);
906 pRefPage->ScaleObjects(aNSize, aBorderRect, true);
907 }
908 pRefPage->SetSize(aNSize);
909 pRefPage->SetBorder(nNLeft, nNUpper, nNRight, nNLower);
910 pRefPage->SetOrientation( eNOrient );
911 }
912
913 if( bRemoveEmptyPresObj )
915 }
916 }
917
918 // Make absolutely sure no double masterpages are there
919 RemoveUnnecessaryMasterPages(nullptr, true);
920
921 // Rename object styles if necessary
922 if(!aRenameStr.isEmpty())
923 {
924 try
925 {
926 for(sal_uInt32 p = nInsertPos; p < sal_uInt32(nInsertPos) + sal_uInt32(nBMSdPageCount); p++)
927 {
928 SdPage *pPg = static_cast<SdPage *>( GetPage(p) );
929 for(size_t i = 0; pPg && (i < pPg->GetObjCount()); ++i)
930 {
931 if(pPg->GetObj(i)->GetStyleSheet())
932 {
933 OUString aStyleName = pPg->GetObj(i)->GetStyleSheet()->GetName();
934 SfxStyleSheet *pSheet = lcl_findStyle(aNewGraphicStyles, Concat2View(aStyleName + aRenameStr));
935 if(pSheet != nullptr)
936 pPg->GetObj(i)->SetStyleSheet(pSheet, true);
937 }
938 }
939 }
940 }
941 catch(...)
942 {
943 TOOLS_WARN_EXCEPTION( "sd", "Exception while renaming styles @ SdDrawDocument::InsertBookmarkAsPage");
944 }
945 }
946 // remove copied styles not used on any inserted page and create
947 // undo records
948 // WARNING: SdMoveStyleSheetsUndoAction clears the passed list of
949 // styles, so it cannot be used after this point
950 lcl_removeUnusedStyles(GetStyleSheetPool(), aNewGraphicStyles);
951 if (!aNewGraphicStyles.empty() && pUndoMgr)
952 pUndoMgr->AddUndoAction(std::make_unique<SdMoveStyleSheetsUndoAction>(this, aNewGraphicStyles, true));
953 lcl_removeUnusedTableStyles(static_cast<SdStyleSheetPool*>(GetStyleSheetPool()), aNewTableStyles);
954 lcl_removeUnusedStyles(GetStyleSheetPool(), aNewCellStyles);
955
956 if( bUndo )
957 EndUndo();
958
959 if (pUndoMgr)
960 pUndoMgr->LeaveListAction();
961
962 return bContinue;
963}
964
965// Inserts a bookmark as an object
967 const std::vector<OUString> &rBookmarkList,
968 const std::vector<OUString> &rExchangeList, // List of names to use
969 ::sd::DrawDocShell* pBookmarkDocSh,
970 Point const * pObjPos,
971 bool bCalcObjCount)
972{
973 bool bOK = true;
974 bool bOLEObjFound = false;
975 std::unique_ptr<::sd::View> pBMView;
976
977 SdDrawDocument* pBookmarkDoc = nullptr;
978
979 if (pBookmarkDocSh)
980 {
981 pBookmarkDoc = pBookmarkDocSh->GetDoc();
982 }
983 else if ( mxBookmarkDocShRef.is() )
984 {
985 pBookmarkDoc = mxBookmarkDocShRef->GetDoc();
986 }
987 else
988 {
989 return false;
990 }
991
992 if (rBookmarkList.empty())
993 {
994 pBMView.reset(new ::sd::View(*pBookmarkDoc, nullptr));
995 pBMView->EndListening(*pBookmarkDoc);
996 pBMView->MarkAll();
997 }
998 else
999 {
1000 SdrPage* pPage;
1001 SdrPageView* pPV;
1002
1003 for ( const auto& rBookmark : rBookmarkList )
1004 {
1005 // Get names of bookmarks from the list
1006 SdrObject* pObj = pBookmarkDoc->GetObj(rBookmark);
1007
1008 if (pObj)
1009 {
1010 // Found an object
1011 if (pObj->GetObjInventor() == SdrInventor::Default &&
1012 pObj->GetObjIdentifier() == SdrObjKind::OLE2)
1013 {
1014 bOLEObjFound = true;
1015 }
1016
1017 if (!pBMView)
1018 {
1019 // Create View for the first time
1020 pBMView.reset(new ::sd::View(*pBookmarkDoc, nullptr));
1021 pBMView->EndListening(*pBookmarkDoc);
1022 }
1023
1024 pPage = pObj->getSdrPageFromSdrObject();
1025
1026 if (pPage->IsMasterPage())
1027 {
1028 pPV = pBMView->ShowSdrPage(pBMView->GetModel().GetMasterPage(pPage->GetPageNum()));
1029 }
1030 else
1031 {
1032 pPV = pBMView->GetSdrPageView();
1033 if( !pPV || (pPV->GetPage() != pPage))
1034 pPV = pBMView->ShowSdrPage(pPage);
1035 }
1036
1037 pBMView->MarkObj(pObj, pPV);
1038 }
1039 }
1040 }
1041
1042 if (pBMView)
1043 {
1044 // Insert selected objects
1045 std::optional<::sd::View> pView(std::in_place, *this, nullptr);
1046 pView->EndListening(*this);
1047
1048 // Look for the page into which the objects are supposed to be inserted
1050
1051 if (mpDocSh)
1052 {
1053 ::sd::ViewShell* pViewSh = mpDocSh->GetViewShell();
1054
1055 if (pViewSh)
1056 {
1057 // Which page is currently in view?
1058 SdrPageView* pPV = pViewSh->GetView()->GetSdrPageView();
1059
1060 if (pPV)
1061 {
1062 pPage = pPV->GetPage();
1063 }
1064 else if (pViewSh->GetActualPage())
1065 {
1066 pPage = pViewSh->GetActualPage();
1067 }
1068 }
1069 }
1070
1071 Point aObjPos;
1072
1073 if (pObjPos)
1074 {
1075 aObjPos = *pObjPos;
1076 }
1077 else
1078 {
1079 aObjPos = ::tools::Rectangle(Point(), pPage->GetSize()).Center();
1080 }
1081
1082 size_t nCountBefore = 0;
1083
1084 if (!rExchangeList.empty() || bCalcObjCount)
1085 {
1086 // Sort OrdNums and get the number of objects before inserting
1087 pPage->RecalcObjOrdNums();
1088 nCountBefore = pPage->GetObjCount();
1089 }
1090
1091 if (bOLEObjFound)
1092 pBMView->GetDoc().SetAllocDocSh(true);
1093
1094 SdDrawDocument* pTmpDoc = static_cast<SdDrawDocument*>( pBMView->CreateMarkedObjModel().release() );
1095 bOK = pView->Paste(*pTmpDoc, aObjPos, pPage, SdrInsertFlags::NONE);
1096
1097 if (bOLEObjFound)
1098 pBMView->GetDoc().SetAllocDocSh(false);
1099
1100 if (!bOLEObjFound)
1101 delete pTmpDoc; // Would otherwise be destroyed by DocShell
1102
1103 pView.reset();
1104
1105 // Get number of objects after inserting.
1106 const size_t nCount = pPage->GetObjCount();
1107 if (nCountBefore < nCount)
1108 {
1109 size_t nObj = nCountBefore;
1110 for (const auto& rExchange : rExchangeList)
1111 {
1112 // Get the name to use from the Exchange list
1113 if (pPage->GetObj(nObj))
1114 {
1115 pPage->GetObj(nObj)->SetName(rExchange);
1116 }
1117
1118 ++nObj;
1119 if (nObj >= nCount)
1120 break;
1121 }
1122 }
1123 }
1124
1125 return bOK;
1126}
1127
1128// Stops the bookmark insertion
1130{
1131 if (mxBookmarkDocShRef.is())
1132 {
1133 mxBookmarkDocShRef->DoClose();
1134 }
1135
1137 maBookmarkFile.clear();
1138}
1139
1140// Is this document read-only?
1142{
1143 return false;
1144}
1145
1146// In the subsequent AllocModel() a DocShell (xAllocedDocShRef) is created.
1147// Any pre-existing DocShell is deleted
1149{
1150 mbAllocDocSh = bAlloc;
1151
1152 if(mxAllocedDocShRef.is())
1153 {
1154 mxAllocedDocShRef->DoClose();
1155 }
1156
1158}
1159
1160// Return list of CustomShows (create it, too, if necessary)
1162{
1163 if (!mpCustomShowList && bCreate)
1164 {
1166 }
1167
1168 return mpCustomShowList.get();
1169}
1170
1171// Remove unused master pages and layouts
1172void SdDrawDocument::RemoveUnnecessaryMasterPages(SdPage* pMasterPage, bool bOnlyDuplicatePages, bool bUndo)
1173{
1174 ::sd::View* pView = nullptr;
1175 SfxUndoManager* pUndoMgr = nullptr;
1176
1177 if( bUndo && !IsUndoEnabled() )
1178 bUndo = false;
1179
1180 if (mpDocSh)
1181 {
1182 pUndoMgr = mpDocSh->GetUndoManager();
1183
1184 if (mpDocSh->GetViewShell())
1185 pView = mpDocSh->GetViewShell()->GetView();
1186 }
1187
1188 // Check all master pages
1189 sal_uInt16 nSdMasterPageCount = GetMasterSdPageCount( PageKind::Standard );
1190 for (sal_Int32 nMPage = nSdMasterPageCount - 1; nMPage >= 0; nMPage--)
1191 {
1192 SdPage* pMaster = pMasterPage;
1193 SdPage* pNotesMaster = nullptr;
1194
1195 if (!pMaster)
1196 {
1197 pMaster = GetMasterSdPage( static_cast<sal_uInt16>(nMPage), PageKind::Standard );
1198 pNotesMaster = GetMasterSdPage( static_cast<sal_uInt16>(nMPage), PageKind::Notes );
1199 }
1200 else
1201 {
1202 for ( sal_uInt16 nMPg = 0; nMPg < GetMasterPageCount(); nMPg++ )
1203 {
1204 if ( pMaster == GetMasterPage( nMPg ) )
1205 {
1206 pNotesMaster = static_cast<SdPage*>( GetMasterPage( ++nMPg ) );
1207 break;
1208 }
1209 }
1210 }
1211
1212 DBG_ASSERT( pMaster->GetPageKind() == PageKind::Standard, "wrong page kind" );
1213
1214 if ( pMaster->GetPageKind() == PageKind::Standard &&
1215 GetMasterPageUserCount( pMaster ) == 0 &&
1216 pNotesMaster )
1217 {
1218 // Do not delete master pages that have their precious flag set
1219 bool bDeleteMaster = !pMaster->IsPrecious();
1220 OUString aLayoutName = pMaster->GetLayoutName();
1221
1222 if(bOnlyDuplicatePages )
1223 {
1224 // remove only duplicate pages
1225 bDeleteMaster = false;
1226 for (sal_uInt16 i = 0; i < GetMasterSdPageCount( PageKind::Standard ); i++)
1227 {
1229 if( pMPg != pMaster &&
1230 pMPg->GetLayoutName() == aLayoutName )
1231 {
1232 // duplicate page found -> remove it
1233 bDeleteMaster = true;
1234 }
1235 }
1236 }
1237
1238 if( bDeleteMaster )
1239 {
1240 if (pView)
1241 {
1242 // if MasterPage is visible hide on pageview
1243 SdrPageView* pPgView = pView->GetSdrPageView();
1244 if (pPgView)
1245 {
1246 SdrPage* pShownPage = pPgView->GetPage();
1247 if( (pShownPage == pMaster) || (pShownPage == pNotesMaster) )
1248 {
1249 pView->HideSdrPage();
1251 }
1252 }
1253 }
1254
1255 if( bUndo )
1256 {
1257 BegUndo();
1258 AddUndo( GetSdrUndoFactory().CreateUndoDeletePage( *pNotesMaster ) );
1259 }
1260
1261 RemoveMasterPage( pNotesMaster->GetPageNum() );
1262
1263 if( bUndo )
1264 AddUndo(GetSdrUndoFactory().CreateUndoDeletePage(*pMaster));
1265
1266 RemoveMasterPage( pMaster->GetPageNum() );
1267
1268 if( bUndo )
1269 EndUndo(); // do this here already, so Joe's actions happen _between_ our own
1270
1271 // Delete old, unused layout stylesheets
1272 bool bDeleteOldStyleSheets = true;
1273 for ( sal_uInt16 nMPg = 0;
1274 nMPg < GetMasterPageCount() && bDeleteOldStyleSheets;
1275 nMPg++ )
1276 {
1277 SdPage* pMPg = static_cast<SdPage*>( GetMasterPage(nMPg) );
1278 if (pMPg->GetLayoutName() == aLayoutName)
1279 {
1280 bDeleteOldStyleSheets = false;
1281 }
1282 }
1283
1284 if (bDeleteOldStyleSheets)
1285 {
1286 SdStyleSheetVector aRemove;
1287 static_cast<SdStyleSheetPool*>( mxStyleSheetPool.get())->CreateLayoutSheetList( aLayoutName, aRemove );
1288
1289 if( bUndo )
1290 {
1291 StyleSheetCopyResultVector aUndoRemove;
1292 aUndoRemove.reserve(aRemove.size());
1293 for (const auto& a : aRemove)
1294 aUndoRemove.emplace_back(a.get(), true);
1295
1296 if (pUndoMgr)
1297 pUndoMgr->AddUndoAction(std::make_unique<SdMoveStyleSheetsUndoAction>(this, aUndoRemove, false));
1298 }
1299
1300 for( const auto& a : aRemove )
1301 static_cast<SdStyleSheetPool*>( mxStyleSheetPool.get())->Remove(a.get());
1302 }
1303 }
1304 }
1305
1306 if (pMasterPage)
1307 break; // Just this one master page!
1308 }
1309}
1310
1325// #i121863# factored out functionality
1326static bool isMasterPageLayoutNameUnique(const SdDrawDocument& rDoc, std::u16string_view rCandidate)
1327{
1328 if (rCandidate.empty())
1329 {
1330 return false;
1331 }
1332
1333 const sal_uInt16 nPageCount(rDoc.GetMasterPageCount());
1334
1335 for(sal_uInt16 a(0); a < nPageCount; a++)
1336 {
1337 const SdrPage* pCandidate = rDoc.GetMasterPage(a);
1338 OUString aPageLayoutName(pCandidate->GetLayoutName());
1339 sal_Int32 nIndex = aPageLayoutName.indexOf(SD_LT_SEPARATOR);
1340 if( nIndex != -1 )
1341 aPageLayoutName = aPageLayoutName.copy(0, nIndex);
1342
1343 if(aPageLayoutName == rCandidate)
1344 {
1345 return false;
1346 }
1347 }
1348
1349 return true;
1350}
1351
1352// #i121863# factored out functionality
1354{
1355 const OUString aBaseName(SdResId(STR_LAYOUT_DEFAULT_NAME));
1356 sal_uInt16 nCount(0);
1357 for (;;)
1358 {
1359 OUString aRetval = aBaseName;
1360 if(nCount)
1361 {
1362 aRetval += OUString::number(nCount);
1363 }
1364 if (isMasterPageLayoutNameUnique(rDoc, aRetval))
1365 return aRetval;
1366 nCount++;
1367 }
1368}
1369
1370void SdDrawDocument::SetMasterPage(sal_uInt16 nSdPageNum,
1371 std::u16string_view rLayoutName,
1372 SdDrawDocument* pSourceDoc,
1373 bool bMaster,
1374 bool bCheckMasters)
1375{
1376 SfxUndoManager* pUndoMgr = nullptr;
1377
1378 if( mpDocSh )
1379 {
1380 mpDocSh->SetWaitCursor( true );
1381 pUndoMgr = mpDocSh->GetUndoManager();
1382 }
1383
1384 const bool bUndo = pUndoMgr && IsUndoEnabled();
1385
1386 if (bUndo)
1387 {
1388 ViewShellId nViewShellId(-1);
1389 if (sd::ViewShell* pViewShell = mpDocSh->GetViewShell())
1390 nViewShellId = pViewShell->GetViewShellBase().GetViewShellId();
1391 pUndoMgr->EnterListAction(SdResId(STR_UNDO_SET_PRESLAYOUT), OUString(), 0, nViewShellId);
1392 }
1393
1394 SdPage* pSelectedPage = GetSdPage(nSdPageNum, PageKind::Standard);
1395 SdPage* pNotes = static_cast<SdPage*>( GetPage(pSelectedPage->GetPageNum()+1) );
1396 SdPage& rOldMaster = static_cast<SdPage&>(pSelectedPage->TRG_GetMasterPage());
1397 SdPage& rOldNotesMaster = static_cast<SdPage&>(pNotes->TRG_GetMasterPage());
1398 rtl::Reference<SdPage> pMaster;
1399 rtl::Reference<SdPage> pNotesMaster;
1400 OUString aOldPageLayoutName(pSelectedPage->GetLayoutName());
1401 OUString aOldLayoutName(aOldPageLayoutName);
1402 sal_Int32 nIndex = aOldLayoutName.indexOf( SD_LT_SEPARATOR );
1403 if( nIndex != -1 )
1404 aOldLayoutName = aOldLayoutName.copy(0, nIndex);
1405
1406 if (pSourceDoc)
1407 {
1408 std::vector<StyleReplaceData> aReplList; // List of replaced stylesheets
1409 bool bLayoutReloaded = false; // Was ex. layout reloaded?
1410
1411 // LayoutName, Page and Notes page
1412 if (rLayoutName.empty())
1413 {
1414 // No LayoutName: take first MasterPage
1415 pMaster = pSourceDoc->GetMasterSdPage(0, PageKind::Standard);
1416 pNotesMaster = pSourceDoc->GetMasterSdPage(0, PageKind::Notes);
1417 }
1418 else
1419 {
1420 OUString aSearchFor
1421 = OUString::Concat(rLayoutName) + SD_LT_SEPARATOR + STR_LAYOUT_OUTLINE;
1422
1423 for (sal_uInt16 nMP = 0; nMP < pSourceDoc->GetMasterPageCount(); ++nMP)
1424 {
1425 SdPage* pMP = static_cast<SdPage*>( pSourceDoc->GetMasterPage(nMP) );
1426
1427 if (pMP->GetLayoutName() == aSearchFor)
1428 {
1429 if (pMP->GetPageKind() == PageKind::Standard)
1430 pMaster = pMP;
1431 if (pMP->GetPageKind() == PageKind::Notes)
1432 pNotesMaster = pMP;
1433 }
1434 if (pMaster && pNotesMaster)
1435 break;
1436 }
1437 DBG_ASSERT(pMaster, "MasterPage (Standard page) not found");
1438 DBG_ASSERT(pNotesMaster, "MasterPage (Notes page) not found");
1439
1440 // this should not happen, but looking at crash reports, it does
1441 if( (pMaster == nullptr) || (pNotesMaster == nullptr) )
1442 {
1443 // so take the first MasterPage
1444 pMaster = pSourceDoc->GetMasterSdPage(0, PageKind::Standard);
1445 pNotesMaster = pSourceDoc->GetMasterSdPage(0, PageKind::Notes);
1446 }
1447 }
1448
1449 // we should never reach this, but one never knows...
1450 if( (pMaster == nullptr) || (pNotesMaster == nullptr) )
1451 {
1452 if (bUndo)
1453 pUndoMgr->LeaveListAction();
1454
1455 if( mpDocSh )
1456 mpDocSh->SetWaitCursor( false );
1457
1458 OSL_FAIL( "SdDrawDocument::SetMasterPage() failed!" );
1459
1460 return;
1461 }
1462
1463 const OUString aOriginalNewLayoutName( pMaster->GetName() );
1464 OUString aTargetNewLayoutName(aOriginalNewLayoutName);
1465
1466 if (pSourceDoc != this)
1467 {
1468 // #i121863# clone masterpages, they are from another model (!)
1469 rtl::Reference<SdPage> pNewNotesMaster(dynamic_cast< SdPage* >(pNotesMaster->CloneSdrPage(*this).get()));
1470 rtl::Reference<SdPage> pNewMaster(dynamic_cast< SdPage* >(pMaster->CloneSdrPage(*this).get()));
1471
1472 if(!pNewNotesMaster || !pNewMaster)
1473 {
1474 OSL_FAIL("SdDrawDocument::SetMasterPage() cloning of MasterPage/NoteAmsterPage failed!" );
1475 return;
1476 }
1477
1478 pNotesMaster = pNewNotesMaster;
1479 pMaster = pNewMaster;
1480
1481 // layout name needs to be unique
1482 aTargetNewLayoutName = pMaster->GetLayoutName();
1483 sal_Int32 nIndex2 = aTargetNewLayoutName.indexOf(SD_LT_SEPARATOR);
1484 if( nIndex2 != -1 )
1485 aTargetNewLayoutName = aTargetNewLayoutName.copy(0, nIndex2);
1486
1487 if(!isMasterPageLayoutNameUnique(*this, aTargetNewLayoutName))
1488 {
1489 aTargetNewLayoutName = createNewMasterPageLayoutName(*this);
1490
1491 OUString aTemp = aTargetNewLayoutName + SD_LT_SEPARATOR + STR_LAYOUT_OUTLINE;
1492
1493 pMaster->SetName(aTargetNewLayoutName);
1494 pMaster->SetLayoutName(aTemp);
1495
1496 pNotesMaster->SetName(aTargetNewLayoutName);
1497 pNotesMaster->SetLayoutName(aTemp);
1498 }
1499 }
1500
1501 if (pSourceDoc != this)
1502 {
1503 const sal_uInt16 nMasterPageCount = GetMasterPageCount();
1504 for ( sal_uInt16 nMPage = 0; nMPage < nMasterPageCount; nMPage++ )
1505 {
1506 SdPage* pCheckMaster = static_cast<SdPage*>(GetMasterPage(nMPage));
1507 if( pCheckMaster->GetName() == aTargetNewLayoutName )
1508 {
1509 bLayoutReloaded = true;
1510 break;
1511 }
1512 }
1513
1514 // Correct or create presentation templates --
1515 // only worry about presentation templates
1516 OUString aName;
1517 SdStyleSheetPool* pSourceStyleSheetPool = static_cast<SdStyleSheetPool*>( pSourceDoc->GetStyleSheetPool() );
1518
1519 StyleSheetCopyResultVector aCreatedStyles; // List of created stylesheets
1520 SfxStyleSheetBase* pHisSheet = pSourceStyleSheetPool->First(SfxStyleFamily::Page);
1521
1522 while (pHisSheet)
1523 {
1524 aName = pHisSheet->GetName();
1525
1526 // #i121863# search in source styles with original style name from source of
1527 // evtl. cloned master (not-cloned, renamed for uniqueness)
1528 if( aName.startsWith( aOriginalNewLayoutName ) )
1529 {
1530 // #i121863# build name of evtl. cloned master style to search for
1531 if(aOriginalNewLayoutName != aTargetNewLayoutName)
1532 {
1533 const sal_Int32 nPos(aName.indexOf(SD_LT_SEPARATOR));
1534 aName = aTargetNewLayoutName + aName.subView(nPos);
1535 }
1536
1537 SfxStyleSheet* pMySheet = static_cast<SfxStyleSheet*>( mxStyleSheetPool->Find(aName, SfxStyleFamily::Page) );
1538
1539 if (pMySheet)
1540 {
1541 // A stylesheet of the same name already exists -> overwrite contents
1542 bool bTest = pMySheet->SetName(pHisSheet->GetName());
1543 DBG_ASSERT(bTest, "Renaming StyleSheet failed.");
1544 pMySheet->GetItemSet().ClearItem(); // Delete all
1545
1546 if (bUndo)
1547 {
1548 pUndoMgr->AddUndoAction(std::make_unique<StyleSheetUndoAction>(this,
1549 pMySheet, &pHisSheet->GetItemSet()));
1550 }
1551 pMySheet->GetItemSet().Put(pHisSheet->GetItemSet());
1552 pMySheet->Broadcast(SfxHint(SfxHintId::DataChanged));
1553 }
1554 else
1555 {
1556 // create new style
1557 OUString aHelpFile;
1558 pMySheet = static_cast<SfxStyleSheet*>( &mxStyleSheetPool->Make(aName, SfxStyleFamily::Page, pHisSheet->GetMask()) );
1559 pMySheet->SetHelpId( aHelpFile, pHisSheet->GetHelpId(aHelpFile) );
1560 pMySheet->GetItemSet().ClearItem(); // Delete all
1561 pMySheet->GetItemSet().Put(pHisSheet->GetItemSet());
1562
1563 aCreatedStyles.emplace_back(static_cast<SdStyleSheet*>(pMySheet), true);
1564 }
1565
1566 StyleReplaceData aReplData;
1567 aReplData.nNewFamily = pMySheet->GetFamily();
1568 aReplData.nFamily = pMySheet->GetFamily();
1569 aReplData.aNewName = pMySheet->GetName();
1570
1571 // #i121863# re-create original name of style used at page where to replace with
1572 // this new style
1573 OUString aTemp(pMySheet->GetName());
1574 const sal_Int32 nPos(aTemp.indexOf(SD_LT_SEPARATOR));
1575 aTemp = aOldLayoutName + aTemp.subView(nPos);
1576 aReplData.aName = aTemp;
1577 aReplList.push_back(aReplData);
1578 }
1579
1580 pHisSheet = pSourceStyleSheetPool->Next();
1581 }
1582
1583 // If new styles were created: re-create parent chaining of the item
1584 // sets in the styles.
1585 if(!aCreatedStyles.empty())
1586 {
1587 for ( const auto& rRData : aReplList )
1588 {
1589 SfxStyleSheetBase* pSOld = mxStyleSheetPool->Find(rRData.aName, SfxStyleFamily::Page);
1590 SfxStyleSheetBase* pSNew = mxStyleSheetPool->Find(rRData.aNewName, SfxStyleFamily::Page);
1591
1592 if (pSOld && pSNew)
1593 {
1594 const OUString& rParentOfOld = pSOld->GetParent();
1595 const OUString& rParentOfNew = pSNew->GetParent();
1596
1597 if (!rParentOfOld.isEmpty() && rParentOfNew.isEmpty())
1598 {
1599 std::vector<StyleReplaceData>::iterator pRDIter = std::find_if(aReplList.begin(), aReplList.end(),
1600 [&rParentOfOld](const StyleReplaceData& rRD) { return (rRD.aName == rParentOfOld) && (rRD.aName != rRD.aNewName); });
1601 if (pRDIter != aReplList.end())
1602 {
1603 OUString aParentOfNew(pRDIter->aNewName);
1604 pSNew->SetParent(aParentOfNew);
1605 }
1606 }
1607 }
1608 }
1609 }
1610
1611 if (bUndo && !aCreatedStyles.empty())
1612 {
1613 // Add UndoAction for creating and inserting the stylesheets to
1614 // the top of the UndoManager
1615 pUndoMgr->AddUndoAction(std::make_unique<SdMoveStyleSheetsUndoAction>( this, aCreatedStyles, true));
1616 }
1617 }
1618
1619 // Create layout name based upon the name of the page layout of the
1620 // master page
1621 OUString aPageLayoutName(pMaster->GetLayoutName());
1622 OUString aLayoutName = aPageLayoutName;
1623 sal_Int32 nIndex2 = aLayoutName.indexOf( SD_LT_SEPARATOR );
1624 if( nIndex2 != -1 )
1625 aLayoutName = aLayoutName.copy( 0, nIndex2);
1626
1627 // #i121863# Do *not* remove from original document any longer, it is potentially used there
1628 // and would lead to crashes. Rely on the automatic process of removing unused masterpages
1629 // (see RemoveUnnecessaryMasterPages)
1630 //if (pSourceDoc != this)
1631 //{
1632 // // Remove from the source document
1633 // pSourceDoc->RemoveMasterPage(pNotesMaster->GetPageNum());
1634 // pSourceDoc->RemoveMasterPage(pMaster->GetPageNum());
1635 //}
1636
1637 // Register the new master pages with the document and then use
1638 // the new presentation layout for the default and notes pages
1639 if (pSourceDoc != this)
1640 {
1641 // Insert the master pages:
1642 // Insert master pages from new layouts at the end.
1643 // If a layout is being replaced, however, insert them before the
1644 // position of the old master page, so from now on the new master
1645 // page will be found when searching (e.g.
1646 // SdPage::SetPresentationLayout).
1647 sal_uInt16 nInsertPos = rOldMaster.GetPageNum();
1648 BegUndo();
1649
1650 if (!bLayoutReloaded)
1651 nInsertPos = 0xFFFF;
1652 InsertMasterPage(pMaster.get(), nInsertPos);
1653 if( bUndo )
1654 AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pMaster));
1655
1656 nInsertPos++;
1657 if (!bLayoutReloaded)
1658 nInsertPos = 0xFFFF;
1659 InsertMasterPage(pNotesMaster.get(), nInsertPos);
1660 if( bUndo )
1661 {
1662 AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pNotesMaster));
1663
1664 EndUndo(); // do this here already, so Joe's actions happen _between_ our own.
1665 }
1666 }
1667
1668 // Fill list with pages
1669 std::vector<rtl::Reference<SdPage>> aPageList;
1670
1671// #98456, this has to be removed according to CL (KA 07/08/2002)
1672// #109884# but we need them again to restore the styles of the presentation objects while undo
1673 aPageList.push_back(pMaster);
1674 aPageList.push_back(pNotesMaster);
1675
1676 if (bMaster || bLayoutReloaded)
1677 {
1678 for (sal_uInt16 nPage = 1; nPage < GetPageCount(); nPage++)
1679 {
1680 SdPage* pPage = static_cast<SdPage*>( GetPage(nPage) );
1681 OUString aTest = pPage->GetLayoutName();
1682 if (aTest == aOldPageLayoutName)
1683 {
1684 aPageList.push_back(pPage);
1685 }
1686 }
1687
1688 }
1689 else
1690 {
1691 aPageList.push_back(pSelectedPage);
1692 aPageList.push_back(pNotes);
1693 }
1694
1695 for (rtl::Reference<SdPage>& pPage : aPageList)
1696 {
1697 AutoLayout eAutoLayout = pPage->GetAutoLayout();
1698
1699 if( bUndo )
1700 {
1701 pUndoMgr->AddUndoAction(std::make_unique<SdPresentationLayoutUndoAction>
1702 (this,
1703 pPage->IsMasterPage() ? aLayoutName : aOldLayoutName,
1704 aLayoutName,
1705 eAutoLayout, eAutoLayout, false, pPage.get()));
1706 }
1707 pPage->SetPresentationLayout(aLayoutName);
1708 pPage->SetAutoLayout(eAutoLayout);
1709 }
1710
1711 // Adapt new master pages
1712 if (pSourceDoc != this)
1713 {
1714 Size aSize(rOldMaster.GetSize());
1715 ::tools::Rectangle aBorderRect(rOldMaster.GetLeftBorder(),
1716 rOldMaster.GetUpperBorder(),
1717 rOldMaster.GetRightBorder(),
1718 rOldMaster.GetLowerBorder());
1719 pMaster->ScaleObjects(aSize, aBorderRect, true);
1720 pMaster->SetSize(aSize);
1721 pMaster->SetBorder(rOldMaster.GetLeftBorder(),
1722 rOldMaster.GetUpperBorder(),
1723 rOldMaster.GetRightBorder(),
1724 rOldMaster.GetLowerBorder());
1725 pMaster->SetOrientation( rOldMaster.GetOrientation() );
1726 pMaster->SetAutoLayout(pMaster->GetAutoLayout());
1727
1728 aSize = rOldNotesMaster.GetSize();
1729 ::tools::Rectangle aNotesBorderRect(rOldNotesMaster.GetLeftBorder(),
1730 rOldNotesMaster.GetUpperBorder(),
1731 rOldNotesMaster.GetRightBorder(),
1732 rOldNotesMaster.GetLowerBorder());
1733 pNotesMaster->ScaleObjects(aSize, aNotesBorderRect, true);
1734 pNotesMaster->SetSize(aSize);
1735 pNotesMaster->SetBorder(rOldNotesMaster.GetLeftBorder(),
1736 rOldNotesMaster.GetUpperBorder(),
1737 rOldNotesMaster.GetRightBorder(),
1738 rOldNotesMaster.GetLowerBorder());
1739 pNotesMaster->SetOrientation( rOldNotesMaster.GetOrientation() );
1740 pNotesMaster->SetAutoLayout(pNotesMaster->GetAutoLayout());
1741
1742 if( (pSourceDoc->GetDocumentType() == DocumentType::Impress) &&
1744 {
1745 pMaster->RemoveEmptyPresentationObjects();
1746 pNotesMaster->RemoveEmptyPresentationObjects();
1747 }
1748 }
1749 }
1750 else
1751 {
1752 // Find a new name for the layout
1753 OUString aName(createNewMasterPageLayoutName(*this));
1754 OUString aPageLayoutName(aName + SD_LT_SEPARATOR + STR_LAYOUT_OUTLINE);
1755
1756 // Generate new stylesheets
1757 static_cast<SdStyleSheetPool*>( mxStyleSheetPool.get())->CreateLayoutStyleSheets(aName);
1758 SdStyleSheetVector aCreatedStyles;
1759 static_cast<SdStyleSheetPool*>( mxStyleSheetPool.get())->CreateLayoutSheetList(aName, aCreatedStyles);
1760
1761 if( bUndo )
1762 {
1763 StyleSheetCopyResultVector aUndoInsert;
1764 aUndoInsert.reserve(aCreatedStyles.size());
1765 for (const auto& a : aCreatedStyles)
1766 aUndoInsert.emplace_back(a.get(), true);
1767 pUndoMgr->AddUndoAction(std::make_unique<SdMoveStyleSheetsUndoAction>(this, aUndoInsert, true));
1768 // Generate new master pages and register them with the document
1769 BegUndo();
1770 }
1771
1772 pMaster = AllocSdPage(true);
1773 pMaster->SetSize(pSelectedPage->GetSize());
1774 pMaster->SetBorder(pSelectedPage->GetLeftBorder(),
1775 pSelectedPage->GetUpperBorder(),
1776 pSelectedPage->GetRightBorder(),
1777 pSelectedPage->GetLowerBorder() );
1778 pMaster->SetName(aName);
1779 pMaster->SetLayoutName(aPageLayoutName);
1780 InsertMasterPage(pMaster.get());
1781
1782 if( bUndo )
1783 AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pMaster));
1784
1785 pMaster->SetAutoLayout(AUTOLAYOUT_NONE, true, true);
1786
1787 pNotesMaster = AllocSdPage(true);
1788 pNotesMaster->SetPageKind(PageKind::Notes);
1789 pNotesMaster->SetSize(pNotes->GetSize());
1790 pNotesMaster->SetBorder(pNotes->GetLeftBorder(),
1791 pNotes->GetUpperBorder(),
1792 pNotes->GetRightBorder(),
1793 pNotes->GetLowerBorder() );
1794 pNotesMaster->SetName(aName);
1795 pNotesMaster->SetLayoutName(aPageLayoutName);
1796 InsertMasterPage(pNotesMaster.get());
1797
1798 if( bUndo )
1799 AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pNotesMaster));
1800
1801 pNotesMaster->SetAutoLayout(AUTOLAYOUT_NOTES, true, true);
1802
1803 if( bUndo )
1804 EndUndo();
1805
1806 // Create a list of affected default and notes pages
1807 std::vector<SdPage*> aPageList;
1808 if (bMaster)
1809 {
1810 for (sal_uInt16 nPage = 1; nPage < GetPageCount(); nPage++)
1811 {
1812 SdPage* pPage = static_cast<SdPage*>( GetPage(nPage) );
1813 if (pPage->GetLayoutName() == aOldPageLayoutName)
1814 {
1815 aPageList.push_back(pPage);
1816 }
1817 }
1818 }
1819 else
1820 {
1821 aPageList.push_back(pSelectedPage);
1822 aPageList.push_back(pNotes);
1823 }
1824
1825 // Set presentation layout and AutoLayout for the affected pages
1826 for ( auto& rpPage : aPageList )
1827 {
1828 AutoLayout eOldAutoLayout = rpPage->GetAutoLayout();
1829 AutoLayout eNewAutoLayout =
1830 rpPage->GetPageKind() == PageKind::Standard ? AUTOLAYOUT_NONE : AUTOLAYOUT_NOTES;
1831
1832 if( bUndo )
1833 {
1834 pUndoMgr->AddUndoAction(std::make_unique<SdPresentationLayoutUndoAction>
1835 (this, aOldLayoutName, aName,
1836 eOldAutoLayout, eNewAutoLayout, true,
1837 rpPage));
1838 }
1839
1840 rpPage->SetPresentationLayout(aName);
1841 rpPage->SetAutoLayout(eNewAutoLayout);
1842 }
1843 }
1844
1845 // If the old master pages aren't used anymore, they and their styles have
1846 // to be removed.
1847 if (bCheckMasters)
1848 {
1849 // Check all
1851 }
1852 else
1853 {
1854 // Check only the master page that was replaced
1855 RemoveUnnecessaryMasterPages(&rOldMaster);
1856 }
1857
1858 if( bUndo )
1859 pUndoMgr->LeaveListAction();
1860
1861 if( mpDocSh )
1862 mpDocSh->SetWaitCursor( false );
1863}
1864
1866 sal_uInt16 nFirstPageNum, sal_uInt16 nLastPageNum,
1867 sal_uInt16 nDestPos,
1868 bool bMergeMasterPages, bool bAllMasterPages,
1869 bool bUndo, bool bTreadSourceAsConst)
1870{
1871 sal_uInt16 nMasterPageCount = GetMasterPageCount();
1872 SdrModel::Merge( rSourceModel, nFirstPageNum, nLastPageNum, nDestPos, bMergeMasterPages, bAllMasterPages, bUndo, bTreadSourceAsConst );
1873
1874 // add style family for each new master page
1875 for( sal_uInt16 nMaster = nMasterPageCount; nMaster < GetMasterPageCount(); nMaster++ )
1876 {
1877 SdPage* pPage = static_cast< SdPage* >( GetMasterPage( nMaster ) );
1878 if( pPage && pPage->IsMasterPage() && (pPage->GetPageKind() == PageKind::Standard) )
1879 {
1880 // new master page created, add its style family
1881 SdStyleSheetPool* pStylePool = static_cast<SdStyleSheetPool*>( GetStyleSheetPool() );
1882 if( pStylePool )
1883 pStylePool->AddStyleFamily( pPage );
1884 }
1885 }
1886}
1887
1888/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxApplication * SfxGetpApp()
AutoLayout
AUTOLAYOUT_NONE
AUTOLAYOUT_NOTES
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
virtual void HideSdrPage() override
virtual SdrPageView * ShowSdrPage(SdrPage *pPage) override
SAL_DLLPRIVATE void ReplacePageInCustomShows(const SdPage *pOldPage, const SdPage *pNewPage)
replacespOldPage from all custom shows with pNewPage or removes pOldPage from all custom shows if pNe...
sal_uInt16 GetMasterSdPageCount(PageKind ePgKind) const
Definition: drawdoc2.cxx:222
bool mbAllocDocSh
Definition: drawdoc.hxx:164
std::unique_ptr< SdCustomShowList > mpCustomShowList
Definition: drawdoc.hxx:141
SAL_DLLPRIVATE sal_uInt16 GetMasterPageUserCount(SdrPage const *pMaster) const
Definition: drawdoc4.cxx:694
virtual SAL_DLLPRIVATE void InsertMasterPage(SdrPage *pPage, sal_uInt16 nPos=0xFFFF) override
Definition: drawdoc2.cxx:434
SAL_DLLPRIVATE bool InsertBookmarkAsPage(const std::vector< OUString > &rBookmarkList, std::vector< OUString > *pExchangeList, bool bLink, bool bReplace, sal_uInt16 nPgPos, bool bNoDialogs, ::sd::DrawDocShell *pBookmarkDocSh, bool bCopy, bool bMergeMasterPages, bool bPreservePageNames)
Insert pages into this document.
Definition: drawdoc3.cxx:375
SAL_DLLPRIVATE void InsertBookmark(const std::vector< OUString > &rBookmarkList, std::vector< OUString > &rExchangeList, bool bLink, sal_uInt16 nPgPos, ::sd::DrawDocShell *pBookmarkDocSh, Point const *pObjPos)
Definition: drawdoc3.cxx:274
SAL_DLLPRIVATE void SetAllocDocSh(bool bAlloc)
Definition: drawdoc3.cxx:1148
SdPage * GetSdPage(sal_uInt16 nPgNum, PageKind ePgKind) const
Definition: drawdoc2.cxx:207
virtual SAL_DLLPRIVATE bool IsReadOnly() const override
Definition: drawdoc3.cxx:1141
::sd::DrawDocShell * mpDocSh
Definition: drawdoc.hxx:142
OUString maBookmarkFile
Definition: drawdoc.hxx:146
SdDrawDocument * OpenBookmarkDoc(const OUString &rBookmarkFile)
Definition: drawdoc3.cxx:256
SAL_DLLPRIVATE sal_uInt16 GetPageByName(std::u16string_view rPgName, bool &rbIsMasterPage) const
Return the first page that has the given name.
Definition: drawdoc2.cxx:126
SdCustomShowList * GetCustomShowList(bool bCreate=false)
Definition: drawdoc3.cxx:1161
SAL_DLLPRIVATE bool InsertBookmarkAsObject(const std::vector< OUString > &rBookmarkList, const std::vector< OUString > &rExchangeList, ::sd::DrawDocShell *pBookmarkDocSh, Point const *pObjPos, bool bCalcObjCount)
Definition: drawdoc3.cxx:966
virtual SAL_DLLPRIVATE rtl::Reference< SdrPage > RemoveMasterPage(sal_uInt16 nPgNum) override
Definition: drawdoc2.cxx:446
::sd::DrawDocShellRef mxBookmarkDocShRef
Definition: drawdoc.hxx:147
SAL_DLLPRIVATE void RenameLayoutTemplate(const OUString &rOldLayoutName, const OUString &rNewName)
Definition: drawdoc4.cxx:1018
::sd::DrawDocShellRef mxAllocedDocShRef
Definition: drawdoc.hxx:163
SdPage * GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind)
Definition: drawdoc2.cxx:217
SAL_DLLPRIVATE SdrObject * GetObj(std::u16string_view rObjName) const
Definition: drawdoc2.cxx:66
void SetMasterPage(sal_uInt16 nSdPageNum, std::u16string_view rLayoutName, SdDrawDocument *pSourceDoc, bool bMaster, bool bCheckMasters)
Definition: drawdoc3.cxx:1370
SAL_DLLPRIVATE void RemoveUnnecessaryMasterPages(SdPage *pMaster=nullptr, bool bOnlyDuplicatePages=false, bool bUndo=true)
Definition: drawdoc3.cxx:1172
SAL_DLLPRIVATE void Merge(SdrModel &rSourceModel, sal_uInt16 nFirstPageNum, sal_uInt16 nLastPageNum, sal_uInt16 nDestPos, bool bMergeMasterPages, bool bAllMasterPages, bool bUndo=true, bool bTreadSourceAsConst=false) override
Definition: drawdoc3.cxx:1865
void CloseBookmarkDoc()
Definition: drawdoc3.cxx:1129
SAL_DLLPRIVATE rtl::Reference< SdrPage > RemovePage(sal_uInt16 nPgNum) override
Definition: drawdoc2.cxx:409
SAL_DLLPRIVATE DocumentType GetDocumentType() const
Definition: drawdoc.hxx:251
SAL_DLLPRIVATE rtl::Reference< SdPage > AllocSdPage(bool bMasterPage)
Definition: drawdoc.cxx:644
sal_uInt16 GetSdPageCount(PageKind ePgKind) const
Definition: drawdoc2.cxx:212
virtual void SetOrientation(Orientation eOrient) override
Definition: sdpage.cxx:2557
virtual Orientation GetOrientation() const override
Definition: sdpage.cxx:2562
PageKind GetPageKind() const
Definition: sdpage.hxx:205
virtual void SetBorder(sal_Int32 nLft, sal_Int32 nUpp, sal_Int32 nRgt, sal_Int32 Lwr) override
Definition: sdpage.cxx:1756
OUString const & GetRealName() const
Definition: sdpage.hxx:269
bool IsScaleObjects() const
Definition: sdpage.hxx:225
void SetBookmarkName(const OUString &aName)
Definition: sdpage.hxx:259
bool IsPrecious() const
The "precious" flag is used for master pages to prevent some unused master pages from being deleted a...
Definition: sdpage.hxx:368
void RemoveEmptyPresentationObjects()
removes all empty presentation objects from this slide
Definition: sdpage2.cxx:485
bool Equals(const SdPage &) const
Definition: sdpage2.cxx:528
void ScaleObjects(const Size &rNewPageSize, const ::tools::Rectangle &rNewBorderRect, bool bScaleAllObj)
Definition: sdpage.cxx:1807
void SetFileName(const OUString &aName)
Definition: sdpage.hxx:257
virtual OUString GetLayoutName() const override
Definition: sdpage.hxx:255
const OUString & GetName() const
Definition: sdpage.cxx:2505
void SetName(const OUString &rName)
Set the name of the page and broadcast a model change.
Definition: sdpage.cxx:2703
AutoLayout GetAutoLayout() const
Definition: sdpage.hxx:190
void SetPresentationLayout(std::u16string_view rLayoutName, bool bReplaceStyleSheets=true, bool bSetMasterPage=true, bool bReverseOrder=false)
Definition: sdpage2.cxx:75
virtual void SetSize(const Size &aSize) override
Definition: sdpage.cxx:1746
void RenameAndCopyGraphicSheets(SdStyleSheetPool &rSourcePool, StyleSheetCopyResultVector &rCreatedSheets, std::u16string_view rRenameSuffix)
Definition: stlpool.cxx:580
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
Definition: stlpool.cxx:1221
void CopyCellSheets(SdStyleSheetPool &rSourcePool)
Definition: stlpool.cxx:518
void CopyLayoutSheets(std::u16string_view rLayoutName, SdStyleSheetPool &rSourcePool, StyleSheetCopyResultVector &rCreatedSheets)
Definition: stlpool.cxx:718
void AddStyleFamily(const SdPage *pPage)
Definition: stlpool.cxx:1174
void CopyTableStyles(SdStyleSheetPool const &rSourcePool)
Definition: stlpool.cxx:523
void BegUndo()
bool m_bTransportContainer
virtual void Merge(SdrModel &rSourceModel, sal_uInt16 nFirstPageNum, sal_uInt16 nLastPageNum, sal_uInt16 nDestPos, bool bMergeMasterPages, bool bAllMasterPages, bool bUndo=true, bool bTreadSourceAsConst=false)
const SdrPage * GetMasterPage(sal_uInt16 nPgNum) const
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
sal_uInt16 GetMasterPageCount() const
SfxStyleSheetBasePool * GetStyleSheetPool() const
SdrUndoFactory & GetSdrUndoFactory() const
bool IsUndoEnabled() const
const SdrPage * GetPage(sal_uInt16 nPgNum) const
rtl::Reference< SfxStyleSheetBasePool > mxStyleSheetPool
sal_uInt16 GetPageCount() const
void EndUndo()
SdrObject * GetObj(size_t nNum) const
size_t GetObjCount() const
void RecalcObjOrdNums()
void SetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr)
virtual SdrInventor GetObjInventor() const
SfxStyleSheet * GetStyleSheet() const
virtual SdrObjKind GetObjIdentifier() const
SdrPage * getSdrPageFromSdrObject() const
virtual void SetName(const OUString &rStr, const bool bSetChanged=true)
SdrPage * GetPage() const
SdrPage & TRG_GetMasterPage() const
sal_uInt16 GetPageNum() const
virtual OUString GetLayoutName() const
bool IsMasterPage() const
Size GetSize() const
sal_Int32 GetUpperBorder() const
sal_Int32 GetRightBorder() const
sal_Int32 GetLeftBorder() const
sal_Int32 GetLowerBorder() const
SdrPageView * GetSdrPageView() const
SfxFilterMatcher & GetFilterMatcher()
void Broadcast(const SfxHint &rHint)
ErrCode GuessFilter(SfxMedium &rMedium, std::shared_ptr< const SfxFilter > &, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const std::shared_ptr< const SfxFilter > & GetFilter() const
void UseInteractionHandler(bool)
const OUString & GetName() const
void SetWaitCursor(bool bSet) const
SfxMedium * GetMedium() const
virtual void Remove(SfxStyleSheetBase *)
SfxStyleSearchBits GetMask() const
virtual bool SetName(const OUString &rNewName, bool bReindexNow=true)
virtual const OUString & GetParent() const
const OUString & GetName() const
SfxStyleFamily GetFamily() const
virtual sal_uLong GetHelpId(OUString &rFile)
virtual void SetHelpId(const OUString &r, sal_uLong nId)
virtual bool SetParent(const OUString &)
virtual SfxItemSet & GetItemSet()
size_t LeaveListAction()
virtual void EnterListAction(const OUString &rComment, const OUString &rRepeatComment, sal_uInt16 nId, ViewShellId nViewShellId)
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
virtual SfxUndoManager * GetUndoManager() override
Definition: docshell.cxx:363
sd::ViewShell * GetViewShell()
SdDrawDocument * GetDoc()
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
virtual SdPage * GetActualPage()=0
::sd::View * GetView() const
Definition: ViewShell.hxx:144
constexpr Point Center() const
bool is() const
int nCount
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
static void lcl_IterateBookmarkPages(SdDrawDocument &rDoc, SdDrawDocument *pBookmarkDoc, const std::vector< OUString > &rBookmarkList, sal_uInt16 nBMSdPageCount, InsertBookmarkAsPage_FindDuplicateLayouts &rPageIterator, bool bRenameDuplicates)
Definition: drawdoc3.cxx:125
static OUString createNewMasterPageLayoutName(const SdDrawDocument &rDoc)
Definition: drawdoc3.cxx:1353
static bool isMasterPageLayoutNameUnique(const SdDrawDocument &rDoc, std::u16string_view rCandidate)
Exchange master page.
Definition: drawdoc3.cxx:1326
OUString sName
constexpr OUStringLiteral SD_LT_SEPARATOR
Definition: glob.hxx:49
sal_Int32 nIndex
OUString aName
void * p
sal_Int64 n
uno_Any a
sal_uInt16 nPos
aStr
OSQLColumns::const_iterator find(const OSQLColumns::const_iterator &first, const OSQLColumns::const_iterator &last, std::u16string_view _rVal, const ::comphelper::UStringMixEqual &_rCase)
int i
PageKind
Definition: pres.hxx:45
Orientation
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
#define SD_MOD()
Definition: sdmod.hxx:184
OUString VCL_DLLPUBLIC GetStandardText(StandardButtonType eButton)
std::vector< css::uno::Reference< css::style::XStyle > > XStyleVector
Definition: stlsheet.hxx:171
std::vector< rtl::Reference< SdStyleSheet > > SdStyleSheetVector
Definition: stlsheet.hxx:170
std::vector< StyleSheetCopyResult > StyleSheetCopyResultVector
Definition: stlsheet.hxx:184
constexpr OUStringLiteral STR_LAYOUT_OUTLINE
Definition: strings.hxx:16
OUString aName
Definition: drawdoc.hxx:85
OUString aNewName
Definition: drawdoc.hxx:86
SfxStyleFamily nNewFamily
Definition: drawdoc.hxx:84
SfxStyleFamily nFamily
Definition: drawdoc.hxx:83
#define SDRPAGE_NOTFOUND
RET_CANCEL
RET_YES