LCOV - code coverage report
Current view: top level - sd/source/core - drawdoc2.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 275 643 42.8 %
Date: 2015-06-13 12:38:46 Functions: 27 40 67.5 %
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/XVisualObject.hpp>
      21             : #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
      22             : #include <vcl/wrkwin.hxx>
      23             : #include <vcl/settings.hxx>
      24             : 
      25             : #include <sfx2/printer.hxx>
      26             : #include <sfx2/app.hxx>
      27             : #include "Outliner.hxx"
      28             : #include <editeng/paperinf.hxx>
      29             : #include <svx/svdopage.hxx>
      30             : #include <svx/svdoole2.hxx>
      31             : #include <svx/svdotext.hxx>
      32             : #include <svx/svdograf.hxx>
      33             : #include <svx/svdundo.hxx>
      34             : #include <vcl/svapp.hxx>
      35             : #include <editeng/eeitem.hxx>
      36             : #include <editeng/langitem.hxx>
      37             : #include <svl/itempool.hxx>
      38             : #include <svx/svdpool.hxx>
      39             : #include <editeng/flditem.hxx>
      40             : 
      41             : #include <sfx2/linkmgr.hxx>
      42             : #include <editeng/editdata.hxx>
      43             : #include <svx/dialogs.hrc>
      44             : #include <svx/dialmgr.hxx>
      45             : 
      46             : #include <editeng/outliner.hxx>
      47             : #include <svx/svditer.hxx>
      48             : #include <svtools/imapobj.hxx>
      49             : 
      50             : #include "sdresid.hxx"
      51             : #include "drawdoc.hxx"
      52             : #include "sdpage.hxx"
      53             : #include "pglink.hxx"
      54             : #include "glob.hrc"
      55             : #include "glob.hxx"
      56             : #include "stlpool.hxx"
      57             : #include "sdiocmpt.hxx"
      58             : #include "anminfo.hxx"
      59             : #include "imapinfo.hxx"
      60             : #include "cusshow.hxx"
      61             : #include "undo/undomanager.hxx"
      62             : 
      63             : #include "../ui/inc/DrawDocShell.hxx"
      64             : #include "../ui/inc/FrameView.hxx"
      65             : #include "../ui/inc/cfgids.hxx"
      66             : #include "../ui/inc/strings.hrc"
      67             : 
      68             : #include "PageListWatcher.hxx"
      69             : #include <vcl/virdev.hxx>
      70             : #include "customshowlist.hxx"
      71             : 
      72             : using namespace ::sd;
      73             : 
      74             : const long PRINT_OFFSET = 30;       // see /svx/source/dialog/page.cxx
      75             : 
      76             : using namespace com::sun::star;
      77             : 
      78             : // Looks up an object by name
      79           0 : SdrObject* SdDrawDocument::GetObj(const OUString& rObjName) const
      80             : {
      81           0 :     SdrObject* pObj = NULL;
      82           0 :     SdrObject* pObjFound = NULL;
      83           0 :     const SdPage* pPage = NULL;
      84             : 
      85             :     // First search in all pages
      86           0 :     sal_uInt16 nPage = 0;
      87           0 :     const sal_uInt16 nMaxPages = GetPageCount();
      88             : 
      89           0 :     while (nPage < nMaxPages && !pObjFound)
      90             :     {
      91           0 :         pPage = static_cast<const SdPage*>( GetPage(nPage) );
      92           0 :         SdrObjListIter aIter(*pPage, IM_DEEPWITHGROUPS);
      93             : 
      94           0 :         while (aIter.IsMore() && !pObjFound)
      95             :         {
      96           0 :             pObj = aIter.Next();
      97             : 
      98           0 :             if( ( pObj->GetName().equals(rObjName) ) ||
      99           0 :                 ( SdrInventor == pObj->GetObjInventor() &&
     100           0 :                   OBJ_OLE2 == pObj->GetObjIdentifier() &&
     101           0 :                   rObjName == static_cast< SdrOle2Obj* >( pObj )->GetPersistName() ) )
     102             :             {
     103           0 :                 pObjFound = pObj;
     104             :             }
     105             :         }
     106             : 
     107           0 :         nPage++;
     108           0 :     }
     109             : 
     110             :     // If it couldn't be found, look through all master pages
     111           0 :     nPage = 0;
     112           0 :     const sal_uInt16 nMaxMasterPages = GetMasterPageCount();
     113             : 
     114           0 :     while (nPage < nMaxMasterPages && !pObjFound)
     115             :     {
     116           0 :         pPage = static_cast<const SdPage*>( GetMasterPage(nPage) );
     117           0 :         SdrObjListIter aIter(*pPage, IM_DEEPWITHGROUPS);
     118             : 
     119           0 :         while (aIter.IsMore() && !pObjFound)
     120             :         {
     121           0 :             pObj = aIter.Next();
     122             : 
     123           0 :             if( ( pObj->GetName().equals(rObjName) ) ||
     124           0 :                 ( SdrInventor == pObj->GetObjInventor() &&
     125           0 :                   OBJ_OLE2 == pObj->GetObjIdentifier() &&
     126           0 :                   rObjName == static_cast< SdrOle2Obj* >( pObj )->GetPersistName() ) )
     127             :             {
     128           0 :                 pObjFound = pObj;
     129             :             }
     130             :         }
     131             : 
     132           0 :         nPage++;
     133           0 :     }
     134             : 
     135           0 :     return pObjFound;
     136             : }
     137             : 
     138             : // Find SdPage by name
     139         185 : sal_uInt16 SdDrawDocument::GetPageByName(const OUString& rPgName, bool& rbIsMasterPage) const
     140             : {
     141         185 :     SdPage* pPage = NULL;
     142         185 :     sal_uInt16 nPage = 0;
     143         185 :     const sal_uInt16 nMaxPages = GetPageCount();
     144         185 :     sal_uInt16 nPageNum = SDRPAGE_NOTFOUND;
     145             : 
     146         185 :     rbIsMasterPage = false;
     147             : 
     148             :     // Search all regular pages and all notes pages (handout pages are
     149             :     // ignored)
     150         935 :     while (nPage < nMaxPages && nPageNum == SDRPAGE_NOTFOUND)
     151             :     {
     152             :         pPage = const_cast<SdPage*>(static_cast<const SdPage*>(
     153         565 :             GetPage(nPage)));
     154             : 
     155         565 :         if (pPage != NULL
     156         565 :             && pPage->GetPageKind() != PK_HANDOUT
     157         945 :             && pPage->GetName() == rPgName)
     158             :         {
     159           0 :             nPageNum = nPage;
     160             :         }
     161             : 
     162         565 :         nPage++;
     163             :     }
     164             : 
     165             :     // Search all master pages when not found among non-master pages
     166         185 :     const sal_uInt16 nMaxMasterPages = GetMasterPageCount();
     167         185 :     nPage = 0;
     168             : 
     169         917 :     while (nPage < nMaxMasterPages && nPageNum == SDRPAGE_NOTFOUND)
     170             :     {
     171             :         pPage = const_cast<SdPage*>(static_cast<const SdPage*>(
     172         547 :             GetMasterPage(nPage)));
     173             : 
     174         547 :         if (pPage && pPage->GetName() == rPgName)
     175             :         {
     176          38 :             nPageNum = nPage;
     177          38 :             rbIsMasterPage = true;
     178             :         }
     179             : 
     180         547 :         nPage++;
     181             :     }
     182             : 
     183         185 :     return nPageNum;
     184             : }
     185             : 
     186        7806 : SdPage* SdDrawDocument::GetSdPage(sal_uInt16 nPgNum, PageKind ePgKind) const
     187             : {
     188        7806 :     return mpDrawPageListWatcher->GetSdPage(ePgKind, sal_uInt32(nPgNum));
     189             : }
     190             : 
     191        7592 : sal_uInt16 SdDrawDocument::GetSdPageCount(PageKind ePgKind) const
     192             : {
     193        7592 :     return (sal_uInt16)mpDrawPageListWatcher->GetSdPageCount(ePgKind);
     194             : }
     195             : 
     196        2134 : SdPage* SdDrawDocument::GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind)
     197             : {
     198        2134 :     return mpMasterPageListWatcher->GetSdPage(ePgKind, sal_uInt32(nPgNum));
     199             : }
     200             : 
     201        2738 : sal_uInt16 SdDrawDocument::GetMasterSdPageCount(PageKind ePgKind) const
     202             : {
     203        2738 :     return (sal_uInt16)mpMasterPageListWatcher->GetSdPageCount(ePgKind);
     204             : }
     205             : 
     206         125 : sal_uInt16 SdDrawDocument::GetActiveSdPageCount() const
     207             : {
     208         125 :     return (sal_uInt16)mpDrawPageListWatcher->GetVisibleSdPageCount();
     209             : }
     210             : 
     211             : // Adapt the page numbers that are registered in the page objects of the notes
     212             : // pages
     213        4063 : void SdDrawDocument::UpdatePageObjectsInNotes(sal_uInt16 nStartPos)
     214             : {
     215        4063 :     sal_uInt16  nPageCount  = GetPageCount();
     216        4063 :     SdPage* pPage       = NULL;
     217             : 
     218        5872 :     for (sal_uInt16 nPage = nStartPos; nPage < nPageCount; nPage++)
     219             :     {
     220        1809 :         pPage = static_cast<SdPage*>( GetPage(nPage) );
     221             : 
     222             :         // If this is a notes page, find its page object and correct the page
     223             :         // number
     224        1809 :         if (pPage && pPage->GetPageKind() == PK_NOTES)
     225             :         {
     226         942 :             const size_t nObjCount = pPage->GetObjCount();
     227        1588 :             for (size_t nObj = 0; nObj < nObjCount; ++nObj)
     228             :             {
     229         646 :                 SdrObject* pObj = pPage->GetObj(nObj);
     230         969 :                 if (pObj->GetObjIdentifier() == OBJ_PAGE &&
     231         323 :                     pObj->GetObjInventor() == SdrInventor)
     232             :                 {
     233             :                     // The page object is the preceding page (drawing page)
     234             :                     DBG_ASSERTWARNING(nStartPos, "Position of notes page must not be 0.");
     235             : 
     236             :                     DBG_ASSERTWARNING(nPage > 1, "Page object must not be a handout.");
     237             : 
     238         323 :                     if (nStartPos > 0 && nPage > 1)
     239         323 :                         static_cast<SdrPageObj*>(pObj)->SetReferencedPage(GetPage(nPage - 1));
     240             :                 }
     241             :             }
     242             :         }
     243             :     }
     244        4063 : }
     245             : 
     246        1882 : void SdDrawDocument::UpdatePageRelativeURLs(const OUString& rOldName, const OUString& rNewName)
     247             : {
     248        1882 :     if (rNewName.isEmpty())
     249        2864 :         return;
     250             : 
     251         900 :     SfxItemPool& pPool(GetPool());
     252         900 :     sal_uInt32 nCount = pPool.GetItemCount2(EE_FEATURE_FIELD);
     253        2595 :     for (sal_uInt32 nOff = 0; nOff < nCount; nOff++)
     254             :     {
     255        1695 :         const SfxPoolItem *pItem = pPool.GetItem2(EE_FEATURE_FIELD, nOff);
     256        1695 :         const SvxFieldItem* pFldItem = dynamic_cast< const SvxFieldItem * > (pItem);
     257             : 
     258        1695 :         if(pFldItem)
     259             :         {
     260        1695 :             SvxURLField* pURLField = const_cast< SvxURLField* >( dynamic_cast<const SvxURLField*>( pFldItem->GetField() ) );
     261             : 
     262        1695 :             if(pURLField)
     263             :             {
     264           0 :                 OUString aURL = pURLField->GetURL();
     265             : 
     266           0 :                 if (!aURL.isEmpty() && (aURL[0] == 35) && (aURL.indexOf(rOldName, 1) == 1))
     267             :                 {
     268           0 :                     if (aURL.getLength() == rOldName.getLength() + 1) // standard page name
     269             :                     {
     270           0 :                         aURL = aURL.replaceAt(1, aURL.getLength() - 1, "");
     271           0 :                         aURL += rNewName;
     272           0 :                         pURLField->SetURL(aURL);
     273             :                     }
     274             :                     else
     275             :                     {
     276           0 :                         const OUString sNotes(SD_RESSTR(STR_NOTES));
     277           0 :                         if (aURL.getLength() == rOldName.getLength() + 2 + sNotes.getLength()
     278           0 :                             && aURL.indexOf(sNotes, rOldName.getLength() + 2) == rOldName.getLength() + 2)
     279             :                         {
     280           0 :                             aURL = aURL.replaceAt(1, aURL.getLength() - 1, "");
     281           0 :                             aURL += rNewName + " " + sNotes;
     282           0 :                             pURLField->SetURL(aURL);
     283           0 :                         }
     284             :                     }
     285           0 :                 }
     286             :             }
     287             :         }
     288             :     }
     289             : }
     290             : 
     291         103 : void SdDrawDocument::UpdatePageRelativeURLs(SdPage* pPage, sal_uInt16 nPos, sal_Int32 nIncrement)
     292             : {
     293         103 :     bool bNotes = (pPage->GetPageKind() == PK_NOTES);
     294             : 
     295         103 :     SfxItemPool& pPool(GetPool());
     296         103 :     sal_uInt32 nCount = pPool.GetItemCount2(EE_FEATURE_FIELD);
     297         468 :     for (sal_uInt32 nOff = 0; nOff < nCount; nOff++)
     298             :     {
     299         365 :         const SfxPoolItem *pItem = pPool.GetItem2(EE_FEATURE_FIELD, nOff);
     300             :         const SvxFieldItem* pFldItem;
     301             : 
     302         365 :         if ((pFldItem = dynamic_cast< const SvxFieldItem * > (pItem)) != 0)
     303             :         {
     304         365 :             SvxURLField* pURLField = const_cast< SvxURLField* >( dynamic_cast<const SvxURLField*>( pFldItem->GetField() ) );
     305             : 
     306         365 :             if(pURLField)
     307             :             {
     308           0 :                 OUString aURL = pURLField->GetURL();
     309             : 
     310           0 :                 if (!aURL.isEmpty() && (aURL[0] == 35))
     311             :                 {
     312           0 :                     OUString aHashSlide("#");
     313           0 :                     aHashSlide += SD_RESSTR(STR_PAGE);
     314             : 
     315           0 :                     if (aURL.startsWith(aHashSlide))
     316             :                     {
     317           0 :                         OUString aURLCopy = aURL;
     318           0 :                         const OUString sNotes(SD_RESSTR(STR_NOTES));
     319             : 
     320           0 :                         aURLCopy = aURLCopy.replaceAt(0, aHashSlide.getLength(), "");
     321             : 
     322           0 :                         bool bNotesLink = ( aURLCopy.getLength() >= sNotes.getLength() + 3
     323           0 :                             && aURLCopy.endsWith(sNotes) );
     324             : 
     325           0 :                         if (bNotesLink != bNotes)
     326           0 :                             continue; // no compatible link and page
     327             : 
     328           0 :                         if (bNotes)
     329           0 :                             aURLCopy = aURLCopy.replaceAt(aURLCopy.getLength() - sNotes.getLength(), sNotes.getLength(), "");
     330             : 
     331           0 :                         sal_Int32 number = aURLCopy.toInt32();
     332           0 :                         sal_uInt16 realPageNumber = (nPos + 1)/ 2;
     333             : 
     334           0 :                         if ( number >= realPageNumber )
     335             :                         {
     336             :                             // update link page number
     337           0 :                             number += nIncrement;
     338           0 :                             aURL = aURL.replaceAt(aHashSlide.getLength() + 1, aURL.getLength() - aHashSlide.getLength() - 1, "");
     339           0 :                             aURL += OUString::number(number);
     340           0 :                             if (bNotes)
     341             :                             {
     342           0 :                                 aURL += " " + sNotes;
     343             :                             }
     344           0 :                             pURLField->SetURL(aURL);
     345           0 :                         }
     346           0 :                     }
     347           0 :                 }
     348             :             }
     349             :         }
     350             :     }
     351         103 : }
     352             : 
     353             : // Move page
     354           0 : void SdDrawDocument::MovePage(sal_uInt16 nPgNum, sal_uInt16 nNewPos)
     355             : {
     356           0 :     FmFormModel::MovePage(nPgNum, nNewPos);
     357             : 
     358           0 :     sal_uInt16 nMin = std::min(nPgNum, nNewPos);
     359             : 
     360           0 :     UpdatePageObjectsInNotes(nMin);
     361           0 : }
     362             : 
     363             : // Insert page
     364        1573 : void SdDrawDocument::InsertPage(SdrPage* pPage, sal_uInt16 nPos)
     365             : {
     366        1573 :     bool bLast = (nPos == GetPageCount());
     367             : 
     368        1573 :     FmFormModel::InsertPage(pPage, nPos);
     369             : 
     370        1573 :     static_cast<SdPage*>(pPage)->ConnectLink();
     371             : 
     372        1573 :     UpdatePageObjectsInNotes(nPos);
     373             : 
     374        1573 :     if (!bLast)
     375         101 :         UpdatePageRelativeURLs(static_cast<SdPage*>( pPage ), nPos, 1);
     376             : 
     377        1573 : }
     378             : 
     379             : // Delete page
     380         932 : void SdDrawDocument::DeletePage(sal_uInt16 nPgNum)
     381             : {
     382         932 :     FmFormModel::DeletePage(nPgNum);
     383             : 
     384         932 :     UpdatePageObjectsInNotes(nPgNum);
     385         932 : }
     386             : 
     387             : // Remove page
     388        1558 : SdrPage* SdDrawDocument::RemovePage(sal_uInt16 nPgNum)
     389             : {
     390        1558 :     SdrPage* pPage = FmFormModel::RemovePage(nPgNum);
     391             : 
     392        1558 :     bool bLast = ((nPgNum+1)/2 == (GetPageCount()+1)/2);
     393             : 
     394        1558 :     static_cast<SdPage*>(pPage)->DisconnectLink();
     395        1558 :     ReplacePageInCustomShows( dynamic_cast< SdPage* >( pPage ), 0 );
     396        1558 :     UpdatePageObjectsInNotes(nPgNum);
     397             : 
     398        1558 :     if (!bLast)
     399           2 :         UpdatePageRelativeURLs(static_cast<SdPage*>(pPage), nPgNum, -1);
     400             : 
     401        1558 :     return pPage;
     402             : }
     403             : 
     404             : // Warning: This is not called for new master pages created from SdrModel::Merge,
     405             : // you also have to modify code in SdDrawDocument::Merge!
     406         786 : void SdDrawDocument::InsertMasterPage(SdrPage* pPage, sal_uInt16 nPos )
     407             : {
     408         786 :     FmFormModel::InsertMasterPage( pPage, nPos );
     409         786 :     if( pPage->IsMasterPage() && (static_cast<SdPage*>(pPage)->GetPageKind() == PK_STANDARD) )
     410             :     {
     411             :         // new master page created, add its style family
     412         268 :         SdStyleSheetPool* pStylePool = static_cast<SdStyleSheetPool*>( GetStyleSheetPool() );
     413         268 :         if( pStylePool )
     414         268 :             pStylePool->AddStyleFamily( static_cast<SdPage*>(pPage) );
     415             :     }
     416         786 : }
     417             : 
     418         771 : SdrPage* SdDrawDocument::RemoveMasterPage(sal_uInt16 nPgNum)
     419             : {
     420         771 :     SdPage* pPage = static_cast<SdPage*>(GetMasterPage(nPgNum ));
     421         771 :     if( pPage && pPage->IsMasterPage() && (pPage->GetPageKind() == PK_STANDARD) )
     422             :     {
     423             :         // master page removed, remove its style family
     424         263 :         SdStyleSheetPool* pStylePool = static_cast<SdStyleSheetPool*>( GetStyleSheetPool() );
     425         263 :         if( pStylePool )
     426         263 :             pStylePool->RemoveStyleFamily( pPage );
     427             :     }
     428             : 
     429         771 :     return FmFormModel::RemoveMasterPage(nPgNum);
     430             : }
     431             : 
     432             : //Select pages
     433        1234 : void SdDrawDocument::SetSelected(SdPage* pPage, bool bSelect)
     434             : {
     435        1234 :     PageKind ePageKind = pPage->GetPageKind();
     436             : 
     437        1234 :     if (ePageKind == PK_STANDARD)
     438             :     {
     439        1202 :         pPage->SetSelected(bSelect);
     440             : 
     441        1202 :         const sal_uInt16 nDestPageNum(pPage->GetPageNum() + 1);
     442        1202 :         SdPage* pNotesPage = 0L;
     443             : 
     444        1202 :         if(nDestPageNum < GetPageCount())
     445             :         {
     446        1148 :             pNotesPage = static_cast<SdPage*>(GetPage(nDestPageNum));
     447             :         }
     448             : 
     449        1202 :         if (pNotesPage && pNotesPage->GetPageKind() == PK_NOTES)
     450             :         {
     451        1142 :             pNotesPage->SetSelected(bSelect);
     452             :         }
     453             :     }
     454          32 :     else if (ePageKind == PK_NOTES)
     455             :     {
     456          26 :         pPage->SetSelected(bSelect);
     457          26 :         SdPage* pStandardPage = static_cast<SdPage*>( GetPage( pPage->GetPageNum() - 1 ) );
     458             : 
     459          26 :         if (pStandardPage && pStandardPage->GetPageKind() == PK_STANDARD)
     460          26 :             pStandardPage->SetSelected(bSelect);
     461             :     }
     462        1234 : }
     463             : 
     464             : // If no pages exist yet, create them now
     465         273 : void SdDrawDocument::CreateFirstPages( SdDrawDocument* pRefDocument /* = 0 */ )
     466             : {
     467             :     // If no page exists yet in the model, (File -> New), insert a page
     468         273 :     sal_uInt16 nPageCount = GetPageCount();
     469             : 
     470         273 :     if (nPageCount <= 1)
     471             :     {
     472             :         // #i57181# Paper size depends on Language, like in Writer
     473         238 :         Size aDefSize = SvxPaperInfo::GetDefaultPaperSize( MAP_100TH_MM );
     474             : 
     475             :         // Insert handout page
     476         238 :         SdPage* pHandoutPage = AllocSdPage(false);
     477             : 
     478         238 :         SdPage* pRefPage = NULL;
     479             : 
     480         238 :         if( pRefDocument )
     481           0 :             pRefPage = pRefDocument->GetSdPage( 0, PK_HANDOUT );
     482             : 
     483         238 :         if( pRefPage )
     484             :         {
     485           0 :             pHandoutPage->SetSize(pRefPage->GetSize());
     486           0 :             pHandoutPage->SetBorder( pRefPage->GetLftBorder(), pRefPage->GetUppBorder(), pRefPage->GetRgtBorder(), pRefPage->GetLwrBorder() );
     487             :         }
     488             :         else
     489             :         {
     490         238 :             pHandoutPage->SetSize(aDefSize);
     491         238 :             pHandoutPage->SetBorder(0, 0, 0, 0);
     492             :         }
     493             : 
     494         238 :         pHandoutPage->SetPageKind(PK_HANDOUT);
     495         238 :         pHandoutPage->SetName( SD_RESSTR(STR_HANDOUT) );
     496         238 :         InsertPage(pHandoutPage, 0);
     497             : 
     498             :         // Insert master page and register this with the handout page
     499         238 :         SdPage* pHandoutMPage = AllocSdPage(true);
     500         238 :         pHandoutMPage->SetSize( pHandoutPage->GetSize() );
     501         238 :         pHandoutMPage->SetPageKind(PK_HANDOUT);
     502             :         pHandoutMPage->SetBorder( pHandoutPage->GetLftBorder(),
     503             :                                   pHandoutPage->GetUppBorder(),
     504             :                                   pHandoutPage->GetRgtBorder(),
     505         238 :                                   pHandoutPage->GetLwrBorder() );
     506         238 :         InsertMasterPage(pHandoutMPage, 0);
     507         238 :         pHandoutPage->TRG_SetMasterPage( *pHandoutMPage );
     508             : 
     509             :         // Insert page
     510             :         // If nPageCount==1 is, the model for the clipboard was created, thus a
     511             :         // default page must already exist
     512             :         SdPage* pPage;
     513         238 :         bool bClipboard = false;
     514             : 
     515         238 :         if( pRefDocument )
     516           0 :             pRefPage = pRefDocument->GetSdPage( 0, PK_STANDARD );
     517             : 
     518         238 :         if (nPageCount == 0)
     519             :         {
     520         238 :             pPage = AllocSdPage(false);
     521             : 
     522         238 :             if( pRefPage )
     523             :             {
     524           0 :                 pPage->SetSize( pRefPage->GetSize() );
     525           0 :                 pPage->SetBorder( pRefPage->GetLftBorder(), pRefPage->GetUppBorder(), pRefPage->GetRgtBorder(), pRefPage->GetLwrBorder() );
     526             :             }
     527         238 :             else if (meDocType == DOCUMENT_TYPE_DRAW)
     528             :             {
     529             :                 // Draw: always use default size with margins
     530          91 :                 pPage->SetSize(aDefSize);
     531             : 
     532          91 :                 SfxPrinter* pPrinter = mpDocSh->GetPrinter(false);
     533          91 :                 if (pPrinter && pPrinter->IsValid())
     534             :                 {
     535           0 :                     Size aOutSize(pPrinter->GetOutputSize());
     536           0 :                     Point aPageOffset(pPrinter->GetPageOffset());
     537           0 :                     aPageOffset -= pPrinter->PixelToLogic( Point() );
     538           0 :                     long nOffset = !aPageOffset.X() && !aPageOffset.Y() ? 0 : PRINT_OFFSET;
     539             : 
     540           0 :                     sal_uLong nTop    = aPageOffset.Y();
     541           0 :                     sal_uLong nLeft   = aPageOffset.X();
     542           0 :                     sal_uLong nBottom = std::max((long)(aDefSize.Height() - aOutSize.Height() - nTop + nOffset), 0L);
     543           0 :                     sal_uLong nRight  = std::max((long)(aDefSize.Width() - aOutSize.Width() - nLeft + nOffset), 0L);
     544             : 
     545           0 :                     pPage->SetBorder(nLeft, nTop, nRight, nBottom);
     546             :                 }
     547             :                 else
     548             :                 {
     549             :                     // The printer is not available.  Use a border of 10mm
     550             :                     // on each side instead.
     551             :                     // This has to be kept synchronized with the border
     552             :                     // width set in the
     553             :                     // SvxPageDescPage::PaperSizeSelect_Impl callback.
     554          91 :                     pPage->SetBorder(1000, 1000, 1000, 1000);
     555             :                 }
     556             :             }
     557             :             else
     558             :             {
     559             :                 // Impress: always use screen format, landscape.
     560         147 :                 Size aSz( SvxPaperInfo::GetPaperSize(PAPER_SCREEN_4_3, MAP_100TH_MM) );
     561         147 :                 pPage->SetSize( Size( aSz.Height(), aSz.Width() ) );
     562         147 :                 pPage->SetBorder(0, 0, 0, 0);
     563             :             }
     564             : 
     565         238 :             InsertPage(pPage, 1);
     566             :         }
     567             :         else
     568             :         {
     569           0 :             bClipboard = true;
     570           0 :             pPage = static_cast<SdPage*>( GetPage(1) );
     571             :         }
     572             : 
     573             :         // Insert master page, then register this with the page
     574         238 :         SdPage* pMPage = AllocSdPage(true);
     575         238 :         pMPage->SetSize( pPage->GetSize() );
     576             :         pMPage->SetBorder( pPage->GetLftBorder(),
     577             :                            pPage->GetUppBorder(),
     578             :                            pPage->GetRgtBorder(),
     579         238 :                            pPage->GetLwrBorder() );
     580         238 :         InsertMasterPage(pMPage, 1);
     581         238 :         pPage->TRG_SetMasterPage( *pMPage );
     582         238 :         if( bClipboard )
     583           0 :             pMPage->SetLayoutName( pPage->GetLayoutName() );
     584             : 
     585             :         // Insert notes page
     586         238 :         SdPage* pNotesPage = AllocSdPage(false);
     587             : 
     588         238 :         if( pRefDocument )
     589           0 :             pRefPage = pRefDocument->GetSdPage( 0, PK_NOTES );
     590             : 
     591         238 :         if( pRefPage )
     592             :         {
     593           0 :             pNotesPage->SetSize( pRefPage->GetSize() );
     594           0 :             pNotesPage->SetBorder( pRefPage->GetLftBorder(), pRefPage->GetUppBorder(), pRefPage->GetRgtBorder(), pRefPage->GetLwrBorder() );
     595             :         }
     596             :         else
     597             :         {
     598             :             // Always use portrait format
     599         238 :             if (aDefSize.Height() >= aDefSize.Width())
     600             :             {
     601         238 :                 pNotesPage->SetSize(aDefSize);
     602             :             }
     603             :             else
     604             :             {
     605           0 :                 pNotesPage->SetSize( Size(aDefSize.Height(), aDefSize.Width()) );
     606             :             }
     607             : 
     608         238 :             pNotesPage->SetBorder(0, 0, 0, 0);
     609             :         }
     610         238 :         pNotesPage->SetPageKind(PK_NOTES);
     611         238 :         InsertPage(pNotesPage, 2);
     612         238 :         if( bClipboard )
     613           0 :             pNotesPage->SetLayoutName( pPage->GetLayoutName() );
     614             : 
     615             :         // Insert master page, then register this with the notes page
     616         238 :         SdPage* pNotesMPage = AllocSdPage(true);
     617         238 :         pNotesMPage->SetSize( pNotesPage->GetSize() );
     618         238 :         pNotesMPage->SetPageKind(PK_NOTES);
     619             :         pNotesMPage->SetBorder( pNotesPage->GetLftBorder(),
     620             :                                 pNotesPage->GetUppBorder(),
     621             :                                 pNotesPage->GetRgtBorder(),
     622         238 :                                 pNotesPage->GetLwrBorder() );
     623         238 :         InsertMasterPage(pNotesMPage, 2);
     624         238 :         pNotesPage->TRG_SetMasterPage( *pNotesMPage );
     625         238 :         if( bClipboard )
     626           0 :             pNotesMPage->SetLayoutName( pPage->GetLayoutName() );
     627             : 
     628         238 :         if( !pRefPage && (meDocType != DOCUMENT_TYPE_DRAW) )
     629         147 :             pPage->SetAutoLayout( AUTOLAYOUT_TITLE, true, true );
     630             : 
     631         238 :         mpWorkStartupTimer = new Timer();
     632         238 :         mpWorkStartupTimer->SetTimeoutHdl( LINK(this, SdDrawDocument, WorkStartupHdl) );
     633         238 :         mpWorkStartupTimer->SetTimeout(2000);
     634         238 :         mpWorkStartupTimer->Start();
     635             : 
     636         238 :         SetChanged(false);
     637             :     }
     638         273 : }
     639             : 
     640             : // Creates missing notes and handout pages (after PowerPoint import).
     641             : // We assume that at least one default page and one default master page exist.
     642             : 
     643          12 : bool SdDrawDocument::CreateMissingNotesAndHandoutPages()
     644             : {
     645          12 :     bool bOK = false;
     646          12 :     sal_uInt16 nPageCount = GetPageCount();
     647             : 
     648          12 :     if (nPageCount != 0)
     649             :     {
     650             :         // Set PageKind
     651          12 :         SdPage* pHandoutMPage = static_cast<SdPage*>( GetMasterPage(0) );
     652          12 :         pHandoutMPage->SetPageKind(PK_HANDOUT);
     653             : 
     654          12 :         SdPage* pHandoutPage = static_cast<SdPage*>( GetPage(0) );
     655          12 :         pHandoutPage->SetPageKind(PK_HANDOUT);
     656          12 :         pHandoutPage->TRG_SetMasterPage( *pHandoutMPage );
     657             : 
     658          54 :         for (sal_uInt16 i = 1; i < nPageCount; i = i + 2)
     659             :         {
     660          42 :             SdPage* pPage = static_cast<SdPage*>( GetPage(i) );
     661             : 
     662          42 :             if(!pPage->TRG_HasMasterPage())
     663             :             {
     664             :                 // No master page set -> use first default master page
     665             :                 // (If there was no default page in the PPT)
     666           0 :                 pPage->TRG_SetMasterPage(*GetMasterPage(1));
     667             :             }
     668             : 
     669          42 :             SdPage* pNotesPage = static_cast<SdPage*>( GetPage(i+1) );
     670          42 :             pNotesPage->SetPageKind(PK_NOTES);
     671             : 
     672             :             // Set notes master page
     673          42 :             sal_uInt16 nMasterPageAfterPagesMasterPage = (pPage->TRG_GetMasterPage()).GetPageNum() + 1;
     674          42 :             pNotesPage->TRG_SetMasterPage(*GetMasterPage(nMasterPageAfterPagesMasterPage));
     675             :         }
     676             : 
     677          12 :         bOK = true;
     678          12 :         StopWorkStartupDelay();
     679          12 :         SetChanged(false);
     680             :     }
     681             : 
     682          12 :     return bOK;
     683             : }
     684             : 
     685             : // + Move selected pages after said page
     686             : //   (nTargetPage = (sal_uInt16)-1  --> move before first page)
     687             : // + Returns sal_True when the page has been moved
     688           0 : bool SdDrawDocument::MovePages(sal_uInt16 nTargetPage)
     689             : {
     690           0 :     SdPage* pPage              = NULL;
     691             :     sal_uInt16  nPage;
     692           0 :     sal_uInt16  nNoOfPages         = GetSdPageCount(PK_STANDARD);
     693           0 :     bool    bSomethingHappened = false;
     694             : 
     695           0 :     const bool bUndo = IsUndoEnabled();
     696             : 
     697           0 :     if( bUndo )
     698           0 :         BegUndo(SD_RESSTR(STR_UNDO_MOVEPAGES));
     699             : 
     700             :     // List of selected pages
     701           0 :     std::vector<SdPage*> aPageList;
     702           0 :     for (nPage = 0; nPage < nNoOfPages; nPage++)
     703             :     {
     704           0 :         pPage = GetSdPage(nPage, PK_STANDARD);
     705             : 
     706           0 :         if (pPage->IsSelected())
     707           0 :             aPageList.push_back(pPage);
     708             :     }
     709             : 
     710             :     // If necessary, look backwards, until we find a page that wasn't selected
     711           0 :     nPage = nTargetPage;
     712           0 :     if (nPage != (sal_uInt16)-1)
     713             :     {
     714           0 :         pPage = GetSdPage(nPage, PK_STANDARD);
     715           0 :         while (nPage > 0 && pPage->IsSelected())
     716             :         {
     717           0 :             nPage--;
     718           0 :             pPage = GetSdPage(nPage, PK_STANDARD);
     719             :         }
     720             : 
     721           0 :         if (pPage->IsSelected())
     722             :         {
     723           0 :             nPage = (sal_uInt16)-1;
     724             :         }
     725             :     }
     726             : 
     727             :     // Insert before the first page
     728           0 :     if (nPage == (sal_uInt16)-1)
     729             :     {
     730           0 :         std::vector<SdPage*>::reverse_iterator iter;
     731           0 :         for (iter = aPageList.rbegin(); iter != aPageList.rend(); ++iter)
     732             :         {
     733           0 :             nPage = (*iter)->GetPageNum();
     734           0 :             if (nPage != 0)
     735             :             {
     736           0 :                 SdrPage* pPg = GetPage(nPage);
     737           0 :                 if( bUndo )
     738           0 :                     AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*pPg, nPage, 1));
     739           0 :                 MovePage(nPage, 1);
     740           0 :                 pPg = GetPage(nPage+1);
     741           0 :                 if( bUndo )
     742           0 :                     AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*pPg, nPage+1, 2));
     743           0 :                 MovePage(nPage+1, 2);
     744           0 :                 bSomethingHappened = true;
     745             :             }
     746             :         }
     747             :     }
     748             :     // Insert after <nPage>
     749             :     else
     750             :     {
     751           0 :         nTargetPage = nPage;
     752           0 :         nTargetPage = 2 * nTargetPage + 1;    // PK_STANDARD --> absolute
     753             : 
     754           0 :         std::vector<SdPage*>::iterator iter;
     755           0 :         for (iter = aPageList.begin(); iter != aPageList.end(); ++iter)
     756             :         {
     757           0 :             pPage = *iter;
     758           0 :             nPage = pPage->GetPageNum();
     759           0 :             if (nPage > nTargetPage)
     760             :             {
     761           0 :                 nTargetPage += 2;        // Insert _after_ the page
     762             : 
     763           0 :                 if (nPage != nTargetPage)
     764             :                 {
     765           0 :                     SdrPage* pPg = GetPage(nPage);
     766           0 :                     if( bUndo )
     767           0 :                         AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*pPg, nPage, nTargetPage));
     768           0 :                     MovePage(nPage, nTargetPage);
     769           0 :                     pPg = GetPage(nPage+1);
     770           0 :                     if( bUndo )
     771           0 :                         AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*pPg, nPage+1, nTargetPage+1));
     772           0 :                     MovePage(nPage+1, nTargetPage+1);
     773           0 :                     bSomethingHappened = true;
     774             :                 }
     775             :             }
     776             :             else
     777             :             {
     778           0 :                 if (nPage != nTargetPage)
     779             :                 {
     780           0 :                     SdrPage* pPg = GetPage(nPage+1);
     781           0 :                     if( bUndo )
     782           0 :                         AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*pPg, nPage+1, nTargetPage+1));
     783           0 :                     MovePage(nPage+1, nTargetPage+1);
     784           0 :                     pPg = GetPage(nPage);
     785           0 :                     if( bUndo )
     786           0 :                         AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*pPg, nPage, nTargetPage));
     787           0 :                     MovePage(nPage, nTargetPage);
     788           0 :                     bSomethingHappened = true;
     789             :                 }
     790             :             }
     791           0 :             nTargetPage = pPage->GetPageNum();
     792             :         }
     793             :     }
     794             : 
     795           0 :     if( bUndo )
     796           0 :         EndUndo();
     797             : 
     798           0 :     return bSomethingHappened;
     799             : }
     800             : 
     801             : // Return number of links in sfx2::LinkManager
     802           0 : sal_uLong SdDrawDocument::GetLinkCount()
     803             : {
     804           0 :     return pLinkManager->GetLinks().size();
     805             : }
     806             : 
     807             : // Set Language
     808        1092 : void SdDrawDocument::SetLanguage( const LanguageType eLang, const sal_uInt16 nId )
     809             : {
     810        1092 :     bool bChanged = false;
     811             : 
     812        1092 :     if( nId == EE_CHAR_LANGUAGE && meLanguage != eLang )
     813             :     {
     814         332 :         meLanguage = eLang;
     815         332 :         bChanged = true;
     816             :     }
     817         760 :     else if( nId == EE_CHAR_LANGUAGE_CJK && meLanguageCJK != eLang )
     818             :     {
     819         322 :         meLanguageCJK = eLang;
     820         322 :         bChanged = true;
     821             :     }
     822         438 :     else if( nId == EE_CHAR_LANGUAGE_CTL && meLanguageCTL != eLang )
     823             :     {
     824         321 :         meLanguageCTL = eLang;
     825         321 :         bChanged = true;
     826             :     }
     827             : 
     828        1092 :     if( bChanged )
     829             :     {
     830         975 :         GetDrawOutliner().SetDefaultLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() );
     831         975 :         pHitTestOutliner->SetDefaultLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() );
     832         975 :         pItemPool->SetPoolDefaultItem( SvxLanguageItem( eLang, nId ) );
     833         975 :         SetChanged( bChanged );
     834             :     }
     835        1092 : }
     836             : 
     837             : // Return language
     838        3329 : LanguageType SdDrawDocument::GetLanguage( const sal_uInt16 nId ) const
     839             : {
     840        3329 :     LanguageType eLangType = meLanguage;
     841             : 
     842        3329 :     if( nId == EE_CHAR_LANGUAGE_CJK )
     843         782 :         eLangType = meLanguageCJK;
     844        2547 :     else if( nId == EE_CHAR_LANGUAGE_CTL )
     845         782 :         eLangType = meLanguageCTL;
     846             : 
     847        3329 :     return eLangType;
     848             : }
     849             : 
     850             : // Initiate WorkStartup
     851         238 : IMPL_LINK_NOARG_TYPED(SdDrawDocument, WorkStartupHdl, Timer *, void)
     852             : {
     853         238 :     if( mpDocSh )
     854         238 :         mpDocSh->SetWaitCursor( true );
     855             : 
     856         238 :     bool bChanged = IsChanged();        // remember this
     857             : 
     858             :     // Initialize Autolayouts
     859         238 :     SdPage* pHandoutMPage = GetMasterSdPage(0, PK_HANDOUT);
     860             : 
     861         238 :     if (pHandoutMPage->GetAutoLayout() == AUTOLAYOUT_NONE)
     862             :     {
     863             :         // No AutoLayout yet -> initialize
     864         238 :         pHandoutMPage->SetAutoLayout(AUTOLAYOUT_HANDOUT6, true, true);
     865             :     }
     866             : 
     867         238 :     SdPage* pPage = GetSdPage(0, PK_STANDARD);
     868             : 
     869         238 :     if (pPage->GetAutoLayout() == AUTOLAYOUT_NONE)
     870             :     {
     871             :         // No AutoLayout yet -> initialize
     872          91 :         pPage->SetAutoLayout(AUTOLAYOUT_NONE, true, true);
     873             :     }
     874             : 
     875         238 :     SdPage* pNotesPage = GetSdPage(0, PK_NOTES);
     876             : 
     877         238 :     if (pNotesPage->GetAutoLayout() == AUTOLAYOUT_NONE)
     878             :     {
     879             :         // No AutoLayout yet -> initialize
     880         238 :         pNotesPage->SetAutoLayout(AUTOLAYOUT_NOTES, true, true);
     881             :     }
     882             : 
     883         238 :     SetChanged(bChanged);
     884             : 
     885         238 :     if( mpDocSh )
     886         238 :         mpDocSh->SetWaitCursor( false );
     887         238 : }
     888             : 
     889             : // When the WorkStartupTimer has been created (this only happens in
     890             : // SdDrawViewShell::Construct() ), the timer may be stopped and the WorkStartup
     891             : // may be initiated.
     892         691 : void SdDrawDocument::StopWorkStartupDelay()
     893             : {
     894         691 :     if (mpWorkStartupTimer)
     895             :     {
     896         238 :         if ( mpWorkStartupTimer->IsActive() )
     897             :         {
     898             :             // Timer not yet expired -> initiate WorkStartup
     899         238 :             mpWorkStartupTimer->Stop();
     900         238 :             WorkStartupHdl(NULL);
     901             :         }
     902             : 
     903         238 :         delete mpWorkStartupTimer;
     904         238 :         mpWorkStartupTimer = NULL;
     905             :     }
     906         691 : }
     907             : 
     908             : // When the WorkStartupTimer has been created (this only happens in
     909             : // SdDrawViewShell::Construct() ), the timer may be stopped and the WorkStartup
     910             : // may be initiated.
     911           1 : SdAnimationInfo* SdDrawDocument::GetAnimationInfo(SdrObject* pObject) const
     912             : {
     913             :     DBG_ASSERT(pObject, "sd::SdDrawDocument::GetAnimationInfo(), invalid argument!");
     914           1 :     if( pObject )
     915           1 :         return GetShapeUserData( *pObject, false );
     916             :     else
     917           0 :         return 0;
     918             : }
     919             : 
     920       85083 : SdAnimationInfo* SdDrawDocument::GetShapeUserData(SdrObject& rObject, bool bCreate /* = false */ )
     921             : {
     922       85083 :     sal_uInt16 nUD          = 0;
     923       85083 :     sal_uInt16 nUDCount     = rObject.GetUserDataCount();
     924       85083 :     SdAnimationInfo* pRet = 0;
     925             : 
     926             :     // Can we find animation information within the user data?
     927       85083 :     for (nUD = 0; nUD < nUDCount; nUD++)
     928             :     {
     929       75283 :         SdrObjUserData* pUD = rObject.GetUserData(nUD);
     930       75283 :         if((pUD->GetInventor() == SdUDInventor) && (pUD->GetId() == SD_ANIMATIONINFO_ID))
     931             :         {
     932       75283 :             pRet = dynamic_cast<SdAnimationInfo*>(pUD);
     933       75283 :             break;
     934             :         }
     935             :     }
     936             : 
     937       85083 :     if( (pRet == 0) && bCreate )
     938             :     {
     939        9094 :         pRet = new SdAnimationInfo( rObject );
     940        9094 :         rObject.AppendUserData( pRet);
     941             :     }
     942             : 
     943       85083 :     return pRet;
     944             : }
     945             : 
     946           5 : SdIMapInfo* SdDrawDocument::GetIMapInfo( SdrObject* pObject ) const
     947             : {
     948             :     DBG_ASSERT(pObject, "Without an object there is no IMapInfo");
     949             : 
     950           5 :     SdIMapInfo*     pIMapInfo = NULL;
     951           5 :     sal_uInt16          nCount = pObject->GetUserDataCount();
     952             : 
     953             :     // Can we find IMap information within the user data?
     954          10 :     for ( sal_uInt16 i = 0; i < nCount; i++ )
     955             :     {
     956           5 :         SdrObjUserData* pUserData = pObject->GetUserData( i );
     957             : 
     958           5 :         if ( ( pUserData->GetInventor() == SdUDInventor ) && ( pUserData->GetId() == SD_IMAPINFO_ID ) )
     959           0 :             pIMapInfo = static_cast<SdIMapInfo*>(pUserData);
     960             :     }
     961             : 
     962           5 :     return pIMapInfo;
     963             : }
     964             : 
     965           0 : IMapObject* SdDrawDocument::GetHitIMapObject( SdrObject* pObj,
     966             :                                               const Point& rWinPoint,
     967             :                                               const vcl::Window& /* rCmpWnd */ )
     968             : {
     969           0 :     SdIMapInfo* pIMapInfo = GetIMapInfo( pObj );
     970           0 :     IMapObject* pIMapObj = NULL;
     971             : 
     972           0 :     if ( pIMapInfo )
     973             :     {
     974           0 :         const MapMode       aMap100( MAP_100TH_MM );
     975           0 :         Size                aGraphSize;
     976           0 :         Point               aRelPoint( rWinPoint );
     977           0 :         ImageMap&           rImageMap = (ImageMap&) pIMapInfo->GetImageMap();
     978           0 :         const Rectangle&    rRect = pObj->GetLogicRect();
     979           0 :         bool                bObjSupported = false;
     980             : 
     981             :         // execute HitTest
     982           0 :         if ( pObj->ISA( SdrGrafObj )  ) // simple graphics object
     983             :         {
     984           0 :             const SdrGrafObj*   pGrafObj = static_cast<const SdrGrafObj*>(pObj);
     985           0 :             const GeoStat&      rGeo = pGrafObj->GetGeoStat();
     986           0 :             SdrGrafObjGeoData*  pGeoData = static_cast<SdrGrafObjGeoData*>( pGrafObj->GetGeoData() );
     987             : 
     988             :             // Undo rotation
     989           0 :             if ( rGeo.nRotationAngle )
     990           0 :                 RotatePoint( aRelPoint, rRect.TopLeft(), -rGeo.nSin, rGeo.nCos );
     991             : 
     992             :             // Undo mirroring
     993           0 :             if ( pGeoData->bMirrored )
     994           0 :                 aRelPoint.X() = rRect.Right() + rRect.Left() - aRelPoint.X();
     995             : 
     996             :             // Undo shearing
     997           0 :             if ( rGeo.nShearAngle )
     998           0 :                 ShearPoint( aRelPoint, rRect.TopLeft(), -rGeo.nTan );
     999             : 
    1000           0 :             if ( pGrafObj->GetGrafPrefMapMode().GetMapUnit() == MAP_PIXEL )
    1001           0 :                 aGraphSize = Application::GetDefaultDevice()->PixelToLogic( pGrafObj->GetGrafPrefSize(), aMap100 );
    1002             :             else
    1003           0 :                 aGraphSize = OutputDevice::LogicToLogic( pGrafObj->GetGrafPrefSize(),
    1004           0 :                                                          pGrafObj->GetGrafPrefMapMode(), aMap100 );
    1005             : 
    1006           0 :             delete pGeoData;
    1007           0 :             bObjSupported = true;
    1008             :         }
    1009           0 :         else if ( pObj->ISA( SdrOle2Obj ) ) // OLE object
    1010             :         {
    1011           0 :             aGraphSize = static_cast<SdrOle2Obj*>( pObj )->GetOrigObjSize();
    1012           0 :             bObjSupported = true;
    1013             :         }
    1014             : 
    1015             :         // Everything worked out well, thus execute HitTest
    1016           0 :         if ( bObjSupported )
    1017             :         {
    1018             :             // Calculate relative position of mouse cursor
    1019           0 :             aRelPoint -= rRect.TopLeft();
    1020           0 :             pIMapObj = rImageMap.GetHitIMapObject( aGraphSize, rRect.GetSize(), aRelPoint );
    1021             : 
    1022             :             // We don't care about deactivated objects
    1023           0 :             if ( pIMapObj && !pIMapObj->IsActive() )
    1024           0 :                 pIMapObj = NULL;
    1025           0 :         }
    1026             :     }
    1027             : 
    1028           0 :     return pIMapObj;
    1029             : }
    1030             : 
    1031           0 : ImageMap* SdDrawDocument::GetImageMapForObject(SdrObject* pObj)
    1032             : {
    1033           0 :     SdIMapInfo* pIMapInfo = GetIMapInfo( pObj );
    1034           0 :     if ( pIMapInfo )
    1035             :     {
    1036           0 :         return const_cast<ImageMap*>( &(pIMapInfo->GetImageMap()) );
    1037             :     }
    1038           0 :     return NULL;
    1039             : }
    1040             : 
    1041             : /** this method enforces that the masterpages are in the correct order,
    1042             :     that is at position 1 is a PK_STANDARD masterpage followed by a
    1043             :     PK_NOTES masterpage and so on. #
    1044             : */
    1045           0 : void SdDrawDocument::CheckMasterPages()
    1046             : {
    1047           0 :     sal_uInt16 nMaxPages = GetMasterPageCount();
    1048             : 
    1049             :     // we need at least a handout master and one master page
    1050           0 :     if( nMaxPages < 2 )
    1051             :     {
    1052           0 :         return;
    1053             :     }
    1054             : 
    1055           0 :     SdPage* pPage = NULL;
    1056             : 
    1057             :     sal_uInt16 nPage;
    1058             : 
    1059             :     // first see if the page order is correct
    1060           0 :     for( nPage = 1; nPage < nMaxPages; nPage++ )
    1061             :     {
    1062           0 :         pPage = static_cast<SdPage*> (GetMasterPage( nPage ));
    1063             :         // if an odd page is not a standard page or an even page is not a notes page
    1064           0 :         if( ((1 == (nPage & 1)) && (pPage->GetPageKind() != PK_STANDARD) ) ||
    1065           0 :             ((0 == (nPage & 1)) && (pPage->GetPageKind() != PK_NOTES) ) )
    1066           0 :             break; // then we have a fatal error
    1067             :     }
    1068             : 
    1069           0 :     if( nPage < nMaxPages )
    1070             :     {
    1071           0 :         SdPage* pNotesPage = NULL;
    1072             : 
    1073             :         // there is a fatal error in the master page order,
    1074             :         // we need to repair the document
    1075           0 :         bool bChanged = false;
    1076             : 
    1077           0 :         nPage = 1;
    1078           0 :         while( nPage < nMaxPages )
    1079             :         {
    1080           0 :             pPage = static_cast<SdPage*> (GetMasterPage( nPage ));
    1081           0 :             if( pPage->GetPageKind() != PK_STANDARD )
    1082             :             {
    1083           0 :                 bChanged = true;
    1084           0 :                 sal_uInt16 nFound = nPage + 1;
    1085           0 :                 while( nFound < nMaxPages )
    1086             :                 {
    1087           0 :                     pPage = static_cast<SdPage*>(GetMasterPage( nFound ));
    1088           0 :                     if( PK_STANDARD == pPage->GetPageKind() )
    1089             :                     {
    1090           0 :                         MoveMasterPage( nFound, nPage );
    1091           0 :                         pPage->SetInserted(true);
    1092           0 :                         break;
    1093             : 
    1094             :                     }
    1095             : 
    1096           0 :                     nFound++;
    1097             :                 }
    1098             : 
    1099             :                 // if we don't have any more standard pages, were done
    1100           0 :                 if( nMaxPages == nFound )
    1101           0 :                     break;
    1102             :             }
    1103             : 
    1104           0 :             nPage++;
    1105             : 
    1106           0 :             if( nPage < nMaxPages )
    1107           0 :                 pNotesPage = static_cast<SdPage*>(GetMasterPage( nPage ));
    1108             :             else
    1109           0 :                 pNotesPage = NULL;
    1110             : 
    1111           0 :             if( (NULL == pNotesPage) || (pNotesPage->GetPageKind() != PK_NOTES) || ( pPage->GetLayoutName() != pNotesPage->GetLayoutName() ) )
    1112             :             {
    1113           0 :                 bChanged = true;
    1114             : 
    1115           0 :                 sal_uInt16 nFound = nPage + 1;
    1116           0 :                 while( nFound < nMaxPages )
    1117             :                 {
    1118           0 :                     pNotesPage = static_cast<SdPage*>(GetMasterPage( nFound ));
    1119           0 :                     if( (PK_NOTES == pNotesPage->GetPageKind()) && ( pPage->GetLayoutName() == pNotesPage->GetLayoutName() ) )
    1120             :                     {
    1121           0 :                         MoveMasterPage( nFound, nPage );
    1122           0 :                         pNotesPage->SetInserted(true);
    1123           0 :                         break;
    1124             :                     }
    1125             : 
    1126           0 :                     nFound++;
    1127             :                 }
    1128             : 
    1129             :                 // looks like we lost a notes page
    1130           0 :                 if( nMaxPages == nFound )
    1131             :                 {
    1132             :                     // so create one
    1133             : 
    1134             :                     // first find a reference notes page for size
    1135           0 :                     SdPage* pRefNotesPage = NULL;
    1136           0 :                     nFound = 0;
    1137           0 :                     while( nFound < nMaxPages )
    1138             :                     {
    1139           0 :                         pRefNotesPage = static_cast<SdPage*>(GetMasterPage( nFound ));
    1140           0 :                         if( PK_NOTES == pRefNotesPage->GetPageKind() )
    1141           0 :                             break;
    1142           0 :                         nFound++;
    1143             :                     }
    1144           0 :                     if( nFound == nMaxPages )
    1145           0 :                         pRefNotesPage = NULL;
    1146             : 
    1147           0 :                     SdPage* pNewNotesPage = AllocSdPage(true);
    1148           0 :                     pNewNotesPage->SetPageKind(PK_NOTES);
    1149           0 :                     if( pRefNotesPage )
    1150             :                     {
    1151           0 :                         pNewNotesPage->SetSize( pRefNotesPage->GetSize() );
    1152             :                         pNewNotesPage->SetBorder( pRefNotesPage->GetLftBorder(),
    1153             :                                                 pRefNotesPage->GetUppBorder(),
    1154             :                                                 pRefNotesPage->GetRgtBorder(),
    1155           0 :                                                 pRefNotesPage->GetLwrBorder() );
    1156             :                     }
    1157           0 :                     InsertMasterPage(pNewNotesPage,  nPage );
    1158           0 :                     pNewNotesPage->SetLayoutName( pPage->GetLayoutName() );
    1159           0 :                     pNewNotesPage->SetAutoLayout(AUTOLAYOUT_NOTES, true, true );
    1160           0 :                     nMaxPages++;
    1161             :                 }
    1162             :             }
    1163             : 
    1164           0 :             nPage++;
    1165             :         }
    1166             : 
    1167             :         // now remove all remaining and unused non PK_STANDARD slides
    1168           0 :         while( nPage < nMaxPages )
    1169             :         {
    1170           0 :             bChanged = true;
    1171             : 
    1172           0 :             RemoveMasterPage( nPage );
    1173           0 :             nMaxPages--;
    1174             :         }
    1175             : 
    1176           0 :         if( bChanged )
    1177             :         {
    1178             :             OSL_FAIL( "master pages where in a wrong order" );
    1179           0 :             RecalcPageNums( true);
    1180             :         }
    1181             :     }
    1182             : }
    1183             : 
    1184           0 : sal_uInt16 SdDrawDocument::CreatePage (
    1185             :     SdPage* pActualPage,
    1186             :     PageKind ePageKind,
    1187             :     const OUString& sStandardPageName,
    1188             :     const OUString& sNotesPageName,
    1189             :     AutoLayout eStandardLayout,
    1190             :     AutoLayout eNotesLayout,
    1191             :     bool bIsPageBack,
    1192             :     bool bIsPageObj,
    1193             :     const sal_Int32 nInsertPosition)
    1194             : {
    1195             :     SdPage* pPreviousStandardPage;
    1196             :     SdPage* pPreviousNotesPage;
    1197             :     SdPage* pStandardPage;
    1198             :     SdPage* pNotesPage;
    1199             : 
    1200             :     // From the given page determine the standard page and notes page of which
    1201             :     // to take the layout and the position where to insert the new pages.
    1202           0 :     if (ePageKind == PK_NOTES)
    1203             :     {
    1204           0 :         pPreviousNotesPage = pActualPage;
    1205           0 :         sal_uInt16 nNotesPageNum = pPreviousNotesPage->GetPageNum() + 2;
    1206           0 :         pPreviousStandardPage = static_cast<SdPage*>( GetPage(nNotesPageNum - 3) );
    1207           0 :         eStandardLayout = pPreviousStandardPage->GetAutoLayout();
    1208             :     }
    1209             :     else
    1210             :     {
    1211           0 :         pPreviousStandardPage = pActualPage;
    1212           0 :         sal_uInt16 nStandardPageNum = pPreviousStandardPage->GetPageNum() + 2;
    1213           0 :         pPreviousNotesPage = static_cast<SdPage*>( GetPage(nStandardPageNum - 1) );
    1214           0 :         eNotesLayout = pPreviousNotesPage->GetAutoLayout();
    1215             :     }
    1216             : 
    1217             :     // Create new standard page and set it up
    1218           0 :     pStandardPage = AllocSdPage(false);
    1219             : 
    1220             :     // Set the size here since else the presobj autolayout
    1221             :     // will be wrong.
    1222           0 :     pStandardPage->SetSize( pPreviousStandardPage->GetSize() );
    1223             :     pStandardPage->SetBorder( pPreviousStandardPage->GetLftBorder(),
    1224             :                               pPreviousStandardPage->GetUppBorder(),
    1225             :                               pPreviousStandardPage->GetRgtBorder(),
    1226           0 :                               pPreviousStandardPage->GetLwrBorder() );
    1227             : 
    1228             :     // Use master page of current page.
    1229           0 :     pStandardPage->TRG_SetMasterPage(pPreviousStandardPage->TRG_GetMasterPage());
    1230             : 
    1231             :     // User layout of current standard page
    1232           0 :     pStandardPage->SetLayoutName( pPreviousStandardPage->GetLayoutName() );
    1233           0 :     pStandardPage->SetAutoLayout(eStandardLayout, true);
    1234           0 :     pStandardPage->setHeaderFooterSettings( pPreviousStandardPage->getHeaderFooterSettings() );
    1235             : 
    1236             :     // transition settings of current page
    1237           0 :     pStandardPage->setTransitionType( pPreviousStandardPage->getTransitionType() );
    1238           0 :     pStandardPage->setTransitionSubtype( pPreviousStandardPage->getTransitionSubtype() );
    1239           0 :     pStandardPage->setTransitionDirection( pPreviousStandardPage->getTransitionDirection() );
    1240           0 :     pStandardPage->setTransitionFadeColor( pPreviousStandardPage->getTransitionFadeColor() );
    1241           0 :     pStandardPage->setTransitionDuration( pPreviousStandardPage->getTransitionDuration() );
    1242             : 
    1243             :     // apply previous animation timing
    1244           0 :     pStandardPage->SetPresChange( pPreviousStandardPage->GetPresChange() );
    1245           0 :     pStandardPage->SetTime( pPreviousStandardPage->GetTime() );
    1246             : 
    1247             :     // Create new notes page and set it up
    1248           0 :     pNotesPage = AllocSdPage(false);
    1249           0 :     pNotesPage->SetPageKind(PK_NOTES);
    1250             : 
    1251             :     // Use master page of current page
    1252           0 :     pNotesPage->TRG_SetMasterPage(pPreviousNotesPage->TRG_GetMasterPage());
    1253             : 
    1254             :     // Use layout of current notes page
    1255           0 :     pNotesPage->SetLayoutName( pPreviousNotesPage->GetLayoutName() );
    1256           0 :     pNotesPage->SetAutoLayout(eNotesLayout, true);
    1257           0 :     pNotesPage->setHeaderFooterSettings( pPreviousNotesPage->getHeaderFooterSettings() );
    1258             : 
    1259             :     return InsertPageSet (
    1260             :         pActualPage,
    1261             :         ePageKind,
    1262             :         sStandardPageName,
    1263             :         sNotesPageName,
    1264             :         bIsPageBack,
    1265             :         bIsPageObj,
    1266             :         pStandardPage,
    1267             :         pNotesPage,
    1268           0 :         nInsertPosition);
    1269             : }
    1270             : 
    1271           0 : sal_uInt16 SdDrawDocument::DuplicatePage (sal_uInt16 nPageNum)
    1272             : {
    1273           0 :     PageKind ePageKind = PK_STANDARD;
    1274             : 
    1275             :     // Get current page
    1276           0 :     SdPage* pActualPage = GetSdPage(nPageNum, ePageKind);
    1277             : 
    1278             :     // Get background flags
    1279           0 :     SdrLayerAdmin& rLayerAdmin = GetLayerAdmin();
    1280           0 :     sal_uInt8 aBckgrnd = rLayerAdmin.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRND), false);
    1281           0 :     sal_uInt8 aBckgrndObj = rLayerAdmin.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRNDOBJ), false);
    1282           0 :     SetOfByte aVisibleLayers = pActualPage->TRG_GetMasterPageVisibleLayers();
    1283             : 
    1284             :     return DuplicatePage (
    1285             :         pActualPage, ePageKind,
    1286             :         // No names for the new slides
    1287             :         OUString(), OUString(),
    1288           0 :         aVisibleLayers.IsSet(aBckgrnd),
    1289           0 :         aVisibleLayers.IsSet(aBckgrndObj));
    1290             : }
    1291             : 
    1292           0 : sal_uInt16 SdDrawDocument::DuplicatePage (
    1293             :     SdPage* pActualPage,
    1294             :     PageKind ePageKind,
    1295             :     const OUString& sStandardPageName,
    1296             :     const OUString& sNotesPageName,
    1297             :     bool bIsPageBack,
    1298             :     bool bIsPageObj,
    1299             :     const sal_Int32 nInsertPosition)
    1300             : {
    1301             :     SdPage* pPreviousStandardPage;
    1302             :     SdPage* pPreviousNotesPage;
    1303             :     SdPage* pStandardPage;
    1304             :     SdPage* pNotesPage;
    1305             : 
    1306             :     // From the given page determine the standard page and the notes page
    1307             :     // of which to make copies.
    1308           0 :     if (ePageKind == PK_NOTES)
    1309             :     {
    1310           0 :         pPreviousNotesPage = pActualPage;
    1311           0 :         sal_uInt16 nNotesPageNum = pPreviousNotesPage->GetPageNum() + 2;
    1312           0 :         pPreviousStandardPage = static_cast<SdPage*>( GetPage(nNotesPageNum - 3) );
    1313             :     }
    1314             :     else
    1315             :     {
    1316           0 :         pPreviousStandardPage = pActualPage;
    1317           0 :         sal_uInt16 nStandardPageNum = pPreviousStandardPage->GetPageNum() + 2;
    1318           0 :         pPreviousNotesPage = static_cast<SdPage*>( GetPage(nStandardPageNum - 1) );
    1319             :     }
    1320             : 
    1321             :     // Create duplicates of a standard page and the associated notes page
    1322           0 :     pStandardPage = static_cast<SdPage*>( pPreviousStandardPage->Clone() );
    1323           0 :     pNotesPage = static_cast<SdPage*>( pPreviousNotesPage->Clone() );
    1324             : 
    1325             :     return InsertPageSet (
    1326             :         pActualPage,
    1327             :         ePageKind,
    1328             :         sStandardPageName,
    1329             :         sNotesPageName,
    1330             :         bIsPageBack,
    1331             :         bIsPageObj,
    1332             :         pStandardPage,
    1333             :         pNotesPage,
    1334           0 :         nInsertPosition);
    1335             : }
    1336             : 
    1337           0 : sal_uInt16 SdDrawDocument::InsertPageSet (
    1338             :     SdPage* pActualPage,
    1339             :     PageKind ePageKind,
    1340             :     const OUString& sStandardPageName,
    1341             :     const OUString& sNotesPageName,
    1342             :     bool bIsPageBack,
    1343             :     bool bIsPageObj,
    1344             :     SdPage* pStandardPage,
    1345             :     SdPage* pNotesPage,
    1346             :     sal_Int32 nInsertPosition)
    1347             : {
    1348             :     SdPage* pPreviousStandardPage;
    1349             :     SdPage* pPreviousNotesPage;
    1350             :     sal_uInt16 nStandardPageNum;
    1351             :     sal_uInt16 nNotesPageNum;
    1352           0 :     OUString aStandardPageName(sStandardPageName);
    1353           0 :     OUString aNotesPageName(sNotesPageName);
    1354             : 
    1355             :     // Gather some information about the standard page and the notes page
    1356             :     // that are to be inserted. This makes sure that there is always one
    1357             :     // standard page followed by one notes page.
    1358           0 :     if (ePageKind == PK_NOTES)
    1359             :     {
    1360           0 :         pPreviousNotesPage = pActualPage;
    1361           0 :         nNotesPageNum = pPreviousNotesPage->GetPageNum() + 2;
    1362           0 :         pPreviousStandardPage = static_cast<SdPage*>( GetPage(nNotesPageNum - 3) );
    1363           0 :         nStandardPageNum = nNotesPageNum - 1;
    1364             :     }
    1365             :     else
    1366             :     {
    1367           0 :         pPreviousStandardPage = pActualPage;
    1368           0 :         nStandardPageNum = pPreviousStandardPage->GetPageNum() + 2;
    1369           0 :         pPreviousNotesPage = static_cast<SdPage*>( GetPage(nStandardPageNum - 1) );
    1370           0 :         nNotesPageNum = nStandardPageNum + 1;
    1371           0 :         aNotesPageName = aStandardPageName;
    1372             :     }
    1373             : 
    1374             :     OSL_ASSERT(nNotesPageNum==nStandardPageNum+1);
    1375           0 :     if (nInsertPosition < 0)
    1376           0 :         nInsertPosition = nStandardPageNum;
    1377             : 
    1378             :     // Set up and insert the standard page
    1379             :     SetupNewPage (
    1380             :         pPreviousStandardPage,
    1381             :         pStandardPage,
    1382             :         aStandardPageName,
    1383             :         nInsertPosition,
    1384             :         bIsPageBack,
    1385           0 :         bIsPageObj);
    1386             : 
    1387             :     // Set up and insert the notes page
    1388           0 :     pNotesPage->SetPageKind(PK_NOTES);
    1389             :     SetupNewPage (
    1390             :         pPreviousNotesPage,
    1391             :         pNotesPage,
    1392             :         aNotesPageName,
    1393             :         nInsertPosition+1,
    1394             :         bIsPageBack,
    1395           0 :         bIsPageObj);
    1396             : 
    1397             :     // Return an index that allows the caller to access the newly inserted
    1398             :     // pages by using GetSdPage()
    1399           0 :     return pStandardPage->GetPageNum() / 2;
    1400             : }
    1401             : 
    1402           0 : void SdDrawDocument::SetupNewPage (
    1403             :     SdPage* pPreviousPage,
    1404             :     SdPage* pPage,
    1405             :     const OUString& sPageName,
    1406             :     sal_uInt16 nInsertionPoint,
    1407             :     bool bIsPageBack,
    1408             :     bool bIsPageObj)
    1409             : {
    1410           0 :     if (pPreviousPage != NULL)
    1411             :     {
    1412           0 :         pPage->SetSize( pPreviousPage->GetSize() );
    1413             :         pPage->SetBorder( pPreviousPage->GetLftBorder(),
    1414             :             pPreviousPage->GetUppBorder(),
    1415             :             pPreviousPage->GetRgtBorder(),
    1416           0 :             pPreviousPage->GetLwrBorder() );
    1417             :     }
    1418           0 :     pPage->SetName(sPageName);
    1419             : 
    1420           0 :     InsertPage(pPage, nInsertionPoint);
    1421             : 
    1422           0 :     if (pPreviousPage != NULL)
    1423             :     {
    1424           0 :         SdrLayerAdmin& rLayerAdmin = GetLayerAdmin();
    1425           0 :         sal_uInt8 aBckgrnd = rLayerAdmin.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRND), false);
    1426           0 :         sal_uInt8 aBckgrndObj = rLayerAdmin.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRNDOBJ), false);
    1427           0 :         SetOfByte aVisibleLayers = pPreviousPage->TRG_GetMasterPageVisibleLayers();
    1428           0 :         aVisibleLayers.Set(aBckgrnd, bIsPageBack);
    1429           0 :         aVisibleLayers.Set(aBckgrndObj, bIsPageObj);
    1430           0 :         pPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
    1431             :     }
    1432           0 : }
    1433             : 
    1434       14812 : sd::UndoManager* SdDrawDocument::GetUndoManager() const
    1435             : {
    1436       14812 :     return mpDocSh ? dynamic_cast< sd::UndoManager* >(mpDocSh->GetUndoManager()) : 0;
    1437          66 : }
    1438             : 
    1439             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11