LCOV - code coverage report
Current view: top level - sd/source/core - drawdoc3.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 17 870 2.0 %
Date: 2015-06-13 12:38:46 Functions: 6 21 28.6 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11