LCOV - code coverage report
Current view: top level - sd/source/ui/toolpanel/controls - DocumentHelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 187 0.0 %
Date: 2012-08-25 Functions: 0 8 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 389 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "DocumentHelper.hxx"
      31                 :            : 
      32                 :            : #include "drawdoc.hxx"
      33                 :            : #include "DrawDocShell.hxx"
      34                 :            : #include "sdpage.hxx"
      35                 :            : #include "glob.hxx"
      36                 :            : #include "unmovss.hxx"
      37                 :            : #include "strings.hrc"
      38                 :            : #include "sdresid.hxx"
      39                 :            : #include "undoback.hxx"
      40                 :            : #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
      41                 :            : #include <com/sun/star/drawing/XDrawPages.hpp>
      42                 :            : #include <com/sun/star/frame/XComponentLoader.hpp>
      43                 :            : #include <com/sun/star/container/XIndexAccess.hpp>
      44                 :            : #include "stlpool.hxx"
      45                 :            : #include <svx/xfillit0.hxx>
      46                 :            : #include <tools/diagnose_ex.h>
      47                 :            : 
      48                 :            : using namespace ::com::sun::star;
      49                 :            : 
      50                 :            : namespace sd { namespace toolpanel { namespace controls {
      51                 :            : 
      52                 :          0 : SdPage* DocumentHelper::CopyMasterPageToLocalDocument (
      53                 :            :     SdDrawDocument& rTargetDocument,
      54                 :            :     SdPage* pMasterPage)
      55                 :            : {
      56                 :          0 :     SdPage* pNewMasterPage = NULL;
      57                 :            : 
      58                 :            :     do
      59                 :            :     {
      60         [ #  # ]:          0 :         if (pMasterPage == NULL)
      61                 :            :             break;
      62                 :            : 
      63                 :            :         // Check the presence of the source document.
      64                 :            :         SdDrawDocument* pSourceDocument = static_cast<SdDrawDocument*>(
      65         [ #  # ]:          0 :             pMasterPage->GetModel());
      66         [ #  # ]:          0 :         if (pSourceDocument == NULL)
      67                 :            :             break;
      68                 :            : 
      69                 :            :         // When the given master page already belongs to the target document
      70                 :            :         // then there is nothing more to do.
      71         [ #  # ]:          0 :         if (pSourceDocument == &rTargetDocument)
      72                 :            :         {
      73                 :          0 :             pNewMasterPage = pMasterPage;
      74                 :            :             break;
      75                 :            :         }
      76                 :            : 
      77                 :            :         // Test if the master pages of both the slide and its notes page are
      78                 :            :         // present.  This is not the case when we are called during the
      79                 :            :         // creation of the slide master page because then the notes master
      80                 :            :         // page is not there.
      81         [ #  # ]:          0 :         sal_uInt16 nSourceMasterPageCount = pSourceDocument->GetMasterPageCount();
      82         [ #  # ]:          0 :         if (nSourceMasterPageCount%2 == 0)
      83                 :            :             // There should be 1 handout page + n slide masters + n notes
      84                 :            :             // masters = 2*n+1.  An even value indicates that a new slide
      85                 :            :             // master but not yet the notes master has been inserted.
      86                 :            :             break;
      87         [ #  # ]:          0 :         sal_uInt16 nIndex = pMasterPage->GetPageNum();
      88         [ #  # ]:          0 :         if (nSourceMasterPageCount <= nIndex+1)
      89                 :            :             break;
      90                 :            :         // Get the slide master page.
      91         [ #  # ]:          0 :         if (pMasterPage != static_cast<SdPage*>(
      92         [ #  # ]:          0 :             pSourceDocument->GetMasterPage(nIndex)))
      93                 :            :             break;
      94                 :            :         // Get the notes master page.
      95                 :            :         SdPage* pNotesMasterPage = static_cast<SdPage*>(
      96         [ #  # ]:          0 :             pSourceDocument->GetMasterPage(nIndex+1));
      97         [ #  # ]:          0 :         if (pNotesMasterPage == NULL)
      98                 :            :             break;
      99                 :            : 
     100                 :            : 
     101                 :            :         // Check if a master page with the same name as that of the given
     102                 :            :         // master page already exists.
     103                 :          0 :         bool bPageExists (false);
     104         [ #  # ]:          0 :         sal_uInt16 nMasterPageCount(rTargetDocument.GetMasterSdPageCount(PK_STANDARD));
     105         [ #  # ]:          0 :         for (sal_uInt16 nMaster=0; nMaster<nMasterPageCount; nMaster++)
     106                 :            :         {
     107                 :            :             SdPage* pCandidate = static_cast<SdPage*>(
     108         [ #  # ]:          0 :                 rTargetDocument.GetMasterSdPage (nMaster, PK_STANDARD));
     109 [ #  # ][ #  # ]:          0 :             if (pMasterPage!=NULL
                 [ #  # ]
     110 [ #  # ][ #  # ]:          0 :                 && pCandidate->GetName().CompareTo(pMasterPage->GetName())==0)
                 [ #  # ]
     111                 :            :             {
     112                 :          0 :                 bPageExists = true;
     113                 :          0 :                 pNewMasterPage = pCandidate;
     114                 :          0 :                 break;
     115                 :            :             }
     116                 :            :         }
     117         [ #  # ]:          0 :         if (bPageExists)
     118                 :            :             break;
     119                 :            : 
     120                 :            :         // Create a new slide (and its notes page.)
     121                 :            :         uno::Reference<drawing::XDrawPagesSupplier> xSlideSupplier (
     122 [ #  # ][ #  # ]:          0 :             rTargetDocument.getUnoModel(), uno::UNO_QUERY);
     123         [ #  # ]:          0 :         if ( ! xSlideSupplier.is())
     124                 :            :             break;
     125                 :            :         uno::Reference<drawing::XDrawPages> xSlides (
     126 [ #  # ][ #  # ]:          0 :             xSlideSupplier->getDrawPages(), uno::UNO_QUERY);
                 [ #  # ]
     127         [ #  # ]:          0 :         if ( ! xSlides.is())
     128                 :            :             break;
     129 [ #  # ][ #  # ]:          0 :         xSlides->insertNewByIndex (xSlides->getCount());
         [ #  # ][ #  # ]
     130                 :            : 
     131                 :            :         // Set a layout.
     132                 :            :         SdPage* pSlide = rTargetDocument.GetSdPage(
     133         [ #  # ]:          0 :             rTargetDocument.GetSdPageCount(PK_STANDARD)-1,
     134         [ #  # ]:          0 :             PK_STANDARD);
     135         [ #  # ]:          0 :         if (pSlide == NULL)
     136                 :            :             break;
     137         [ #  # ]:          0 :         pSlide->SetAutoLayout(AUTOLAYOUT_TITLE, sal_True);
     138                 :            : 
     139                 :            :         // Create a copy of the master page and the associated notes
     140                 :            :         // master page and insert them into our document.
     141         [ #  # ]:          0 :         pNewMasterPage = AddMasterPage(rTargetDocument, pMasterPage);
     142         [ #  # ]:          0 :         if (pNewMasterPage==NULL)
     143                 :            :             break;
     144                 :            :         SdPage* pNewNotesMasterPage
     145         [ #  # ]:          0 :             = AddMasterPage(rTargetDocument, pNotesMasterPage);
     146         [ #  # ]:          0 :         if (pNewNotesMasterPage==NULL)
     147                 :            :             break;
     148                 :            : 
     149                 :            :         // Make the connection from the new slide to the master page
     150                 :            :         // (and do the same for the notes page.)
     151                 :            :         rTargetDocument.SetMasterPage (
     152         [ #  # ]:          0 :             rTargetDocument.GetSdPageCount(PK_STANDARD)-1,
     153         [ #  # ]:          0 :             pNewMasterPage->GetName(),
     154                 :            :             &rTargetDocument,
     155                 :            :             sal_False, // Connect the new master page with the new slide but
     156                 :            :                    // do not modify other (master) pages.
     157 [ #  # ][ #  # ]:          0 :             sal_True);
                 [ #  # ]
     158                 :            :     }
     159                 :            :     while (false);
     160                 :            : 
     161                 :            :     // We are not interested in any automatisms for our modified internal
     162                 :            :     // document.
     163                 :          0 :     rTargetDocument.SetChanged (sal_False);
     164                 :            : 
     165                 :          0 :     return pNewMasterPage;
     166                 :            : }
     167                 :            : 
     168                 :            : 
     169                 :            : 
     170                 :            : 
     171                 :          0 : SdPage* DocumentHelper::GetSlideForMasterPage (SdPage* pMasterPage)
     172                 :            : {
     173                 :          0 :     SdPage* pCandidate = NULL;
     174                 :            : 
     175                 :          0 :     SdDrawDocument* pDocument = NULL;
     176         [ #  # ]:          0 :     if (pMasterPage != NULL)
     177         [ #  # ]:          0 :         pDocument = dynamic_cast<SdDrawDocument*>(pMasterPage->GetModel());
     178                 :            : 
     179                 :            :     // Iterate over all pages and check if it references the given master
     180                 :            :     // page.
     181 [ #  # ][ #  # ]:          0 :     if (pDocument!=NULL && pDocument->GetSdPageCount(PK_STANDARD) > 0)
                 [ #  # ]
     182                 :            :     {
     183                 :            :         // In most cases a new slide has just been inserted so start with
     184                 :            :         // the last page.
     185                 :          0 :         sal_uInt16 nPageIndex (pDocument->GetSdPageCount(PK_STANDARD)-1);
     186                 :          0 :         bool bFound (false);
     187         [ #  # ]:          0 :         while ( ! bFound)
     188                 :            :         {
     189                 :            :             pCandidate = pDocument->GetSdPage(
     190                 :            :                 nPageIndex,
     191                 :          0 :                 PK_STANDARD);
     192         [ #  # ]:          0 :             if (pCandidate != NULL)
     193                 :            :             {
     194         [ #  # ]:          0 :                 if (static_cast<SdPage*>(&pCandidate->TRG_GetMasterPage())
     195                 :            :                     == pMasterPage)
     196                 :            :                 {
     197                 :          0 :                     bFound = true;
     198                 :          0 :                     break;
     199                 :            :                 }
     200                 :            :             }
     201                 :            : 
     202         [ #  # ]:          0 :             if (nPageIndex == 0)
     203                 :          0 :                 break;
     204                 :            :             else
     205                 :          0 :                 nPageIndex --;
     206                 :            :         }
     207                 :            : 
     208                 :            :         // If no page was found that refernced the given master page reset
     209                 :            :         // the pointer that is returned.
     210         [ #  # ]:          0 :         if ( ! bFound)
     211                 :          0 :             pCandidate = NULL;
     212                 :            :     }
     213                 :            : 
     214                 :          0 :     return pCandidate;
     215                 :            : }
     216                 :            : 
     217                 :            : 
     218                 :            : 
     219                 :            : 
     220                 :          0 : SdPage* DocumentHelper::AddMasterPage (
     221                 :            :     SdDrawDocument& rTargetDocument,
     222                 :            :     SdPage* pMasterPage)
     223                 :            : {
     224                 :          0 :     SdPage* pClonedMasterPage = NULL;
     225                 :            : 
     226         [ #  # ]:          0 :     if (pMasterPage!=NULL)
     227                 :            :     {
     228                 :            :         try
     229                 :            :         {
     230                 :            :             // Duplicate the master page.
     231         [ #  # ]:          0 :             pClonedMasterPage = static_cast<SdPage*>(pMasterPage->Clone());
     232                 :            : 
     233                 :            :             // Copy the necessary styles.
     234                 :            :             SdDrawDocument* pSourceDocument
     235         [ #  # ]:          0 :                 = static_cast<SdDrawDocument*>(pMasterPage->GetModel());
     236         [ #  # ]:          0 :             if (pSourceDocument != NULL)
     237         [ #  # ]:          0 :                 ProvideStyles (*pSourceDocument, rTargetDocument, pClonedMasterPage);
     238                 :            : 
     239                 :            :             // Copy the precious flag.
     240 [ #  # ][ #  # ]:          0 :             pClonedMasterPage->SetPrecious(pMasterPage->IsPrecious());
     241                 :            : 
     242                 :            :             // Now that the styles are available we can insert the cloned
     243                 :            :             // master page.
     244         [ #  # ]:          0 :             rTargetDocument.InsertMasterPage (pClonedMasterPage);
     245                 :            :         }
     246                 :          0 :         catch(const uno::Exception&)
     247                 :            :         {
     248                 :          0 :             pClonedMasterPage = NULL;
     249                 :            :             DBG_UNHANDLED_EXCEPTION();
     250                 :            :         }
     251                 :          0 :         catch(const ::std::exception&)
     252                 :            :         {
     253                 :          0 :             pClonedMasterPage = NULL;
     254                 :            :             OSL_TRACE ("caught general exception");
     255                 :            :         }
     256                 :          0 :         catch(...)
     257                 :            :         {
     258                 :          0 :             pClonedMasterPage = NULL;
     259                 :            :             OSL_TRACE ("caught general exception");
     260                 :            :         }
     261                 :            :     }
     262                 :            : 
     263      [ #  #  # ]:          0 :     return pClonedMasterPage;
     264                 :            : }
     265                 :            : 
     266                 :            : 
     267                 :            : 
     268                 :            : 
     269                 :          0 : void DocumentHelper::ProvideStyles (
     270                 :            :     SdDrawDocument& rSourceDocument,
     271                 :            :     SdDrawDocument& rTargetDocument,
     272                 :            :     SdPage* pPage)
     273                 :            : {
     274                 :            :     // Get the layout name of the given page.
     275         [ #  # ]:          0 :     String sLayoutName (pPage->GetLayoutName());
     276 [ #  # ][ #  # ]:          0 :     sLayoutName.Erase (sLayoutName.SearchAscii (SD_LT_SEPARATOR));
     277                 :            : 
     278                 :            :     // Copy the style sheet from source to target document.
     279                 :            :     SdStyleSheetPool* pSourceStyleSheetPool =
     280         [ #  # ]:          0 :         static_cast<SdStyleSheetPool*>(rSourceDocument.GetStyleSheetPool());
     281                 :            :     SdStyleSheetPool* pTargetStyleSheetPool =
     282         [ #  # ]:          0 :         static_cast<SdStyleSheetPool*>(rTargetDocument.GetStyleSheetPool());
     283         [ #  # ]:          0 :     SdStyleSheetVector aCreatedStyles;
     284                 :            :     pTargetStyleSheetPool->CopyLayoutSheets (
     285                 :            :         sLayoutName,
     286                 :            :         *pSourceStyleSheetPool,
     287         [ #  # ]:          0 :         aCreatedStyles);
     288                 :            : 
     289                 :            :     // Add an undo action for the copied style sheets.
     290         [ #  # ]:          0 :     if( !aCreatedStyles.empty() )
     291                 :            :     {
     292         [ #  # ]:          0 :          ::svl::IUndoManager* pUndoManager = rTargetDocument.GetDocSh()->GetUndoManager();
     293         [ #  # ]:          0 :        if (pUndoManager != NULL)
     294                 :            :        {
     295                 :            :            SdMoveStyleSheetsUndoAction* pMovStyles =
     296                 :            :                new SdMoveStyleSheetsUndoAction (
     297                 :            :                    &rTargetDocument,
     298                 :            :                    aCreatedStyles,
     299 [ #  # ][ #  # ]:          0 :                    sal_True);
     300         [ #  # ]:          0 :            pUndoManager->AddUndoAction (pMovStyles);
     301                 :            :        }
     302         [ #  # ]:          0 :     }
     303                 :          0 : }
     304                 :            : 
     305                 :            : 
     306                 :            : 
     307                 :            : 
     308                 :          0 : void DocumentHelper::AssignMasterPageToPageList (
     309                 :            :     SdDrawDocument& rTargetDocument,
     310                 :            :     SdPage* pMasterPage,
     311                 :            :     const ::boost::shared_ptr<std::vector<SdPage*> >& rpPageList)
     312                 :            : {
     313 [ #  # ][ #  # ]:          0 :     if (pMasterPage == NULL || !pMasterPage->IsMasterPage())
                 [ #  # ]
     314                 :            :         return;
     315                 :            : 
     316                 :            :     // Make the layout name by stripping ouf the layout postfix from the
     317                 :            :     // layout name of the given master page.
     318         [ #  # ]:          0 :     String sFullLayoutName (pMasterPage->GetLayoutName());
     319         [ #  # ]:          0 :     String sBaseLayoutName (sFullLayoutName);
     320 [ #  # ][ #  # ]:          0 :     sBaseLayoutName.Erase (sBaseLayoutName.SearchAscii (SD_LT_SEPARATOR));
     321                 :            : 
     322         [ #  # ]:          0 :     if (rpPageList->empty())
     323                 :            :         return;
     324                 :            : 
     325                 :            :     // Create a second list that contains only the valid pointers to
     326                 :            :     // pages for which an assignment is necessary.
     327                 :          0 :     ::std::vector<SdPage*>::const_iterator iPage;
     328         [ #  # ]:          0 :     ::std::vector<SdPage*> aCleanedList;
     329 [ #  # ][ #  # ]:          0 :     for (iPage=rpPageList->begin(); iPage!=rpPageList->end(); ++iPage)
                 [ #  # ]
     330                 :            :     {
     331                 :            :         OSL_ASSERT(*iPage!=NULL && (*iPage)->GetModel() == &rTargetDocument);
     332 [ #  # ][ #  # ]:          0 :         if (*iPage != NULL
                 [ #  # ]
     333 [ #  # ][ #  # ]:          0 :             && (*iPage)->GetLayoutName().CompareTo(sFullLayoutName)!=0)
         [ #  # ][ #  # ]
                 [ #  # ]
     334                 :            :         {
     335         [ #  # ]:          0 :             aCleanedList.push_back(*iPage);
     336                 :            :         }
     337                 :            :     }
     338         [ #  # ]:          0 :         if (aCleanedList.empty() )
     339                 :            :         return;
     340                 :            : 
     341         [ #  # ]:          0 :     ::svl::IUndoManager* pUndoMgr = rTargetDocument.GetDocSh()->GetUndoManager();
     342         [ #  # ]:          0 :     if( pUndoMgr )
     343 [ #  # ][ #  # ]:          0 :         pUndoMgr->EnterListAction(String(SdResId(STR_UNDO_SET_PRESLAYOUT)), String());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     344                 :            : 
     345         [ #  # ]:          0 :     SdPage* pMasterPageInDocument = ProvideMasterPage(rTargetDocument,pMasterPage,rpPageList);
     346         [ #  # ]:          0 :     if (pMasterPageInDocument == NULL)
     347                 :            :         return;
     348                 :            : 
     349                 :            :     // Assign the master pages to the given list of pages.
     350 [ #  # ][ #  # ]:          0 :     for (iPage=aCleanedList.begin();
                 [ #  # ]
     351                 :          0 :             iPage!=aCleanedList.end();
     352                 :            :             ++iPage)
     353                 :            :     {
     354                 :            :         AssignMasterPageToPage (
     355                 :            :             pMasterPageInDocument,
     356                 :            :             sBaseLayoutName,
     357         [ #  # ]:          0 :             *iPage);
     358                 :            :     }
     359                 :            : 
     360         [ #  # ]:          0 :     if( pUndoMgr )
     361 [ #  # ][ #  # ]:          0 :         pUndoMgr->LeaveListAction();
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     362                 :            : }
     363                 :            : 
     364                 :            : 
     365                 :            : 
     366                 :            : 
     367                 :          0 : SdPage* DocumentHelper::AddMasterPage (
     368                 :            :     SdDrawDocument& rTargetDocument,
     369                 :            :     SdPage* pMasterPage,
     370                 :            :     sal_uInt16 nInsertionIndex)
     371                 :            : {
     372                 :          0 :     SdPage* pClonedMasterPage = NULL;
     373                 :            : 
     374         [ #  # ]:          0 :     if (pMasterPage!=NULL)
     375                 :            :     {
     376                 :            :         // Duplicate the master page.
     377                 :          0 :         pClonedMasterPage = static_cast<SdPage*>(pMasterPage->Clone());
     378                 :            : 
     379                 :            :         // Copy the precious flag.
     380                 :          0 :         pClonedMasterPage->SetPrecious(pMasterPage->IsPrecious());
     381                 :            : 
     382                 :            :         // Copy the necessary styles.
     383                 :            :         SdDrawDocument* pSourceDocument
     384                 :          0 :             = static_cast<SdDrawDocument*>(pMasterPage->GetModel());
     385         [ #  # ]:          0 :         if (pSourceDocument != NULL)
     386                 :            :         {
     387         [ #  # ]:          0 :             ProvideStyles (*pSourceDocument, rTargetDocument, pClonedMasterPage);
     388                 :            : 
     389                 :            :             // Now that the styles are available we can insert the cloned
     390                 :            :             // master page.
     391         [ #  # ]:          0 :             rTargetDocument.InsertMasterPage (pClonedMasterPage, nInsertionIndex);
     392                 :            : 
     393                 :            :             // Adapt the size of the new master page to that of the pages in
     394                 :            :             // the document.
     395 [ #  # ][ #  # ]:          0 :             Size aNewSize (rTargetDocument.GetSdPage(0, pMasterPage->GetPageKind())->GetSize());
     396                 :            :             Rectangle aBorders (
     397                 :          0 :                 pClonedMasterPage->GetLftBorder(),
     398                 :          0 :                 pClonedMasterPage->GetUppBorder(),
     399                 :          0 :                 pClonedMasterPage->GetRgtBorder(),
     400 [ #  # ][ #  # ]:          0 :                 pClonedMasterPage->GetLwrBorder());
         [ #  # ][ #  # ]
                 [ #  # ]
     401         [ #  # ]:          0 :             pClonedMasterPage->ScaleObjects(aNewSize, aBorders, sal_True);
     402         [ #  # ]:          0 :             pClonedMasterPage->SetSize(aNewSize);
     403         [ #  # ]:          0 :             pClonedMasterPage->CreateTitleAndLayout(sal_True);
     404                 :            :         }
     405                 :            :     }
     406                 :            : 
     407                 :          0 :     return pClonedMasterPage;
     408                 :            : }
     409                 :            : 
     410                 :            : 
     411                 :            : 
     412                 :            : 
     413                 :            : /** In here we have to handle three cases:
     414                 :            :     1. pPage is a normal slide.  We can use SetMasterPage to assign the
     415                 :            :     master pages to it.
     416                 :            :     2. pPage is a master page that is used by at least one slide.  We can
     417                 :            :     assign the master page to these slides.
     418                 :            :     3. pPage is a master page that is currently not used by any slide.
     419                 :            :     We can delete that page and add copies of the given master pages
     420                 :            :     instead.
     421                 :            : 
     422                 :            :     For points 2 and 3 where one master page A is assigned to another B we have
     423                 :            :     to keep in mind that the master page that page A has already been
     424                 :            :     inserted into the target document.
     425                 :            : */
     426                 :          0 : void DocumentHelper::AssignMasterPageToPage (
     427                 :            :     SdPage* pMasterPage,
     428                 :            :     const String& rsBaseLayoutName,
     429                 :            :     SdPage* pPage)
     430                 :            : {
     431                 :            :     // Leave early when the parameters are invalid.
     432 [ #  # ][ #  # ]:          0 :     if (pPage == NULL || pMasterPage == NULL)
     433                 :          0 :         return;
     434         [ #  # ]:          0 :     SdDrawDocument* pDocument = dynamic_cast<SdDrawDocument*>(pPage->GetModel());
     435         [ #  # ]:          0 :     if (pDocument == NULL)
     436                 :          0 :         return;
     437                 :            : 
     438         [ #  # ]:          0 :     if ( ! pPage->IsMasterPage())
     439                 :            :     {
     440                 :            :         // 1. Remove the background object (so that that, if it exists, does
     441                 :            :         // not override the new master page) and assign the master page to
     442                 :            :         // the regular slide.
     443                 :          0 :         pDocument->GetDocSh()->GetUndoManager()->AddUndoAction(
     444                 :            :             new SdBackgroundObjUndoAction(
     445         [ #  # ]:          0 :                 *pDocument, *pPage, pPage->getSdrPageProperties().GetItemSet()),
     446                 :          0 :             sal_True);
     447         [ #  # ]:          0 :         pPage->getSdrPageProperties().PutItem(XFillStyleItem(XFILL_NONE));
     448                 :            : 
     449                 :            :         pDocument->SetMasterPage (
     450                 :          0 :             (pPage->GetPageNum()-1)/2,
     451                 :            :             rsBaseLayoutName,
     452                 :            :             pDocument,
     453                 :            :             sal_False,
     454                 :          0 :             sal_False);
     455                 :            :     }
     456                 :            :     else
     457                 :            :     {
     458                 :            :         // Find first slide that uses the master page.
     459                 :          0 :         SdPage* pSlide = NULL;
     460                 :          0 :         sal_uInt16 nPageCount = pDocument->GetSdPageCount(PK_STANDARD);
     461 [ #  # ][ #  # ]:          0 :         for (sal_uInt16 nPage=0; nPage<nPageCount&&pSlide==NULL; nPage++)
                 [ #  # ]
     462                 :            :         {
     463                 :          0 :             SdrPage* pCandidate = pDocument->GetSdPage(nPage,PK_STANDARD);
     464 [ #  # ][ #  #  :          0 :             if (pCandidate != NULL
             #  #  #  # ]
     465                 :          0 :                 && pCandidate->TRG_HasMasterPage()
     466                 :          0 :                 && &(pCandidate->TRG_GetMasterPage()) == pPage)
     467                 :            :             {
     468                 :          0 :                 pSlide = static_cast<SdPage*>(pCandidate);
     469                 :            :             }
     470                 :            :         }
     471                 :            : 
     472         [ #  # ]:          0 :         if (pSlide != NULL)
     473                 :            :         {
     474                 :            :             // 2. Assign the given master pages to the first slide that was
     475                 :            :             // found above that uses the master page.
     476                 :            :             pDocument->SetMasterPage (
     477                 :          0 :                 (pSlide->GetPageNum()-1)/2,
     478                 :            :                 rsBaseLayoutName,
     479                 :            :                 pDocument,
     480                 :            :                 sal_False,
     481                 :          0 :                 sal_False);
     482                 :            :         }
     483                 :            :         else
     484                 :            :         {
     485                 :            :             // 3. Replace the master page A by a copy of the given master
     486                 :            :             // page B.
     487                 :            :             pDocument->RemoveUnnecessaryMasterPages (
     488                 :          0 :                 pPage, sal_False);
     489                 :            :         }
     490                 :            :     }
     491                 :            : }
     492                 :            : 
     493                 :            : 
     494                 :            : 
     495                 :            : 
     496                 :          0 : SdPage* DocumentHelper::ProvideMasterPage (
     497                 :            :     SdDrawDocument& rTargetDocument,
     498                 :            :     SdPage* pMasterPage,
     499                 :            :     const ::boost::shared_ptr<std::vector<SdPage*> >& rpPageList)
     500                 :            : {
     501                 :            :     // Make sure that both the master page and its notes master exist
     502                 :            :     // in the source document.  If one is missing then return without
     503                 :            :     // making any changes.
     504         [ #  # ]:          0 :     if (pMasterPage == NULL)
     505                 :            :     {
     506                 :            :         // The caller should make sure that the master page is valid.
     507                 :            :         OSL_ASSERT(pMasterPage != NULL);
     508                 :          0 :         return NULL;
     509                 :            :     }
     510         [ #  # ]:          0 :     SdDrawDocument* pSourceDocument = static_cast<SdDrawDocument*>(pMasterPage->GetModel());
     511         [ #  # ]:          0 :     if (pSourceDocument == NULL)
     512                 :          0 :         return NULL;
     513                 :            :     SdPage* pNotesMasterPage = static_cast<SdPage*>(
     514 [ #  # ][ #  # ]:          0 :         pSourceDocument->GetMasterPage(pMasterPage->GetPageNum()+1));
     515         [ #  # ]:          0 :     if (pNotesMasterPage == NULL)
     516                 :            :     {
     517                 :            :         // The model is not in a valid state.  Maybe a new master page
     518                 :            :         // is being (not finished yet) created?  Return without making
     519                 :            :         // any changes.
     520                 :          0 :         return NULL;
     521                 :            :     }
     522                 :            : 
     523                 :          0 :     SdPage* pMasterPageInDocument = NULL;
     524                 :            :     // Search for a master page with the same name as the given one in
     525                 :            :     // the target document.
     526 [ #  # ][ #  # ]:          0 :     const rtl::OUString sMasterPageLayoutName (pMasterPage->GetLayoutName());
                 [ #  # ]
     527 [ #  # ][ #  # ]:          0 :     for (sal_uInt16 nIndex=0,nCount=rTargetDocument.GetMasterPageCount(); nIndex<nCount; ++nIndex)
     528                 :            :     {
     529         [ #  # ]:          0 :         SdPage* pCandidate = static_cast<SdPage*>(rTargetDocument.GetMasterPage(nIndex));
     530 [ #  # ][ #  # ]:          0 :         if (pCandidate && sMasterPageLayoutName.equals(pCandidate->GetLayoutName()))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  #  
             #  #  #  # ]
     531                 :            :         {
     532                 :            :             // The requested master page does already exist in the
     533                 :            :             // target document, return it.
     534                 :          0 :             return pCandidate;
     535                 :            :         }
     536                 :            :     }
     537                 :            : 
     538                 :            :     // The given master page does not already belong to the target
     539                 :            :     // document so we have to create copies and insert them into the
     540                 :            :     // targer document.
     541                 :            : 
     542                 :            :     // Determine the position where the new master pages are inserted.
     543                 :            :     // By default they are inserted at the end.  When we assign to a
     544                 :            :     // master page then insert after the last of the (selected) pages.
     545         [ #  # ]:          0 :     sal_uInt16 nInsertionIndex = rTargetDocument.GetMasterPageCount();
     546 [ #  # ][ #  # ]:          0 :     if (rpPageList->front()->IsMasterPage())
     547                 :            :     {
     548 [ #  # ][ #  # ]:          0 :         nInsertionIndex = rpPageList->back()->GetPageNum();
     549                 :            :     }
     550                 :            : 
     551                 :            :     // Clone the master page.
     552 [ #  # ][ #  # ]:          0 :     if (pMasterPage->GetModel() != &rTargetDocument)
     553                 :            :     {
     554         [ #  # ]:          0 :         pMasterPageInDocument = AddMasterPage (rTargetDocument, pMasterPage, nInsertionIndex);
     555 [ #  # ][ #  # ]:          0 :         if( rTargetDocument.IsUndoEnabled() )
     556                 :            :                 rTargetDocument.AddUndo(
     557 [ #  # ][ #  # ]:          0 :                     rTargetDocument.GetSdrUndoFactory().CreateUndoNewPage(*pMasterPageInDocument));
                 [ #  # ]
     558                 :            :     }
     559                 :            :     else
     560                 :          0 :         pMasterPageInDocument = pMasterPage;
     561                 :            : 
     562                 :            :     // Clone the notes master.
     563 [ #  # ][ #  # ]:          0 :     if (pNotesMasterPage->GetModel() != &rTargetDocument)
     564                 :            :     {
     565                 :            :         SdPage* pClonedNotesMasterPage
     566         [ #  # ]:          0 :             = AddMasterPage (rTargetDocument, pNotesMasterPage, nInsertionIndex+1);
     567 [ #  # ][ #  # ]:          0 :         if( rTargetDocument.IsUndoEnabled() )
     568                 :            :             rTargetDocument.AddUndo(
     569 [ #  # ][ #  # ]:          0 :                 rTargetDocument.GetSdrUndoFactory().CreateUndoNewPage(*pClonedNotesMasterPage));
                 [ #  # ]
     570                 :            :     }
     571                 :            : 
     572                 :          0 :     return pMasterPageInDocument;
     573                 :            : }
     574                 :            : 
     575                 :            : 
     576                 :            : 
     577                 :            : 
     578                 :            : 
     579                 :            : } } } // end of namespace ::sd::toolpanel::controls
     580                 :            : 
     581                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10