LCOV - code coverage report
Current view: top level - sd/source/ui/view - ViewClipboard.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 94 0.0 %
Date: 2014-04-14 Functions: 0 8 0.0 %
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             : 
      21             : #include "ViewClipboard.hxx"
      22             : 
      23             : #include "DrawDocShell.hxx"
      24             : #include "View.hxx"
      25             : #include "ViewShell.hxx"
      26             : #include "Window.hxx"
      27             : 
      28             : #include "drawdoc.hxx"
      29             : #include "sdpage.hxx"
      30             : #include "sdxfer.hxx"
      31             : #include "sdresid.hxx"
      32             : #include "glob.hrc"
      33             : 
      34             : #include <svx/svdpagv.hxx>
      35             : #include <osl/mutex.hxx>
      36             : #include <vcl/svapp.hxx>
      37             : 
      38             : namespace sd {
      39             : 
      40           0 : ViewClipboard::ViewClipboard (::sd::View& rView)
      41           0 :     : mrView(rView)
      42             : {
      43           0 : }
      44             : 
      45             : 
      46             : 
      47             : 
      48           0 : ViewClipboard::~ViewClipboard (void)
      49             : {
      50           0 : }
      51             : 
      52             : 
      53             : 
      54             : 
      55           0 : void ViewClipboard::HandlePageDrop (const SdTransferable& rTransferable)
      56             : {
      57             :     // Determine whether to insert the given set of slides or to assign a
      58             :     // given master page.
      59           0 :     SdPage* pMasterPage = GetFirstMasterPage (rTransferable);
      60           0 :     if (pMasterPage != NULL)
      61           0 :         AssignMasterPage (rTransferable, pMasterPage);
      62             :     else
      63           0 :         InsertSlides (rTransferable, DetermineInsertPosition (rTransferable));
      64           0 : }
      65             : 
      66             : 
      67             : 
      68             : 
      69           0 : SdPage* ViewClipboard::GetFirstMasterPage (const SdTransferable& rTransferable)
      70             : {
      71           0 :     SdPage* pFirstMasterPage = NULL;
      72             : 
      73           0 :     if (rTransferable.HasPageBookmarks())
      74             :     {
      75             :         do
      76             :         {
      77           0 :             const std::vector<OUString> &rBookmarks = rTransferable.GetPageBookmarks();
      78             : 
      79           0 :             if (rBookmarks.empty())
      80           0 :                 break;
      81             : 
      82           0 :             DrawDocShell* pDocShell = rTransferable.GetPageDocShell();
      83           0 :             if (pDocShell == NULL)
      84           0 :                 break;
      85             : 
      86           0 :             SdDrawDocument* pDocument = pDocShell->GetDoc();
      87           0 :             if (pDocument == NULL)
      88           0 :                 break;
      89             : 
      90           0 :             std::vector<OUString>::const_iterator pIter;
      91           0 :             for ( pIter = rBookmarks.begin(); pIter != rBookmarks.end(); ++pIter )
      92             :             {
      93           0 :                 OUString sName (*pIter);
      94             :                 sal_Bool bIsMasterPage;
      95             : 
      96             :                 // SdPage* GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind);
      97             :                 // sal_uInt16 GetMasterSdPageCount(PageKind ePgKind) const;
      98             : 
      99             :                 sal_uInt16 nBMPage = pDocument->GetPageByName (
     100           0 :                     sName, bIsMasterPage);
     101           0 :                 if ( ! bIsMasterPage)
     102             :                 {
     103             :                     // At least one regular slide: return NULL to indicate
     104             :                     // that not all bookmarks point to master pages.
     105           0 :                     pFirstMasterPage = NULL;
     106           0 :                     break;
     107             :                 }
     108           0 :                 else if (pFirstMasterPage == NULL)
     109             :                 {
     110             :                     // Remember the first master page for later.
     111           0 :                     if (nBMPage != SDRPAGE_NOTFOUND)
     112             :                         pFirstMasterPage = static_cast<SdPage*>(
     113           0 :                             pDocument->GetMasterPage(nBMPage));
     114             :                 }
     115           0 :             }
     116             :         }
     117             :         while (false);
     118             :     }
     119             : 
     120           0 :     return pFirstMasterPage;
     121             : }
     122             : 
     123             : 
     124             : 
     125             : 
     126           0 : void ViewClipboard::AssignMasterPage (
     127             :     const SdTransferable& rTransferable,
     128             :     SdPage* pMasterPage)
     129             : {
     130           0 :     if (pMasterPage == NULL)
     131           0 :         return;
     132             : 
     133             :     // Get the target page to which the master page is assigned.
     134           0 :     SdrPageView* pPageView = mrView.GetSdrPageView();
     135           0 :     if (pPageView == NULL)
     136           0 :         return;
     137             : 
     138           0 :     SdPage* pPage = static_cast<SdPage*>(pPageView->GetPage());
     139           0 :     if (pPage == NULL)
     140           0 :         return;
     141             : 
     142           0 :     SdDrawDocument& rDocument = mrView.GetDoc();
     143             : 
     144           0 :     if ( ! rTransferable.HasPageBookmarks())
     145           0 :         return;
     146             : 
     147           0 :     DrawDocShell* pDataDocShell = rTransferable.GetPageDocShell();
     148           0 :     if (pDataDocShell == NULL)
     149           0 :         return;
     150             : 
     151           0 :     SdDrawDocument* pSourceDocument = pDataDocShell->GetDoc();
     152           0 :     if (pSourceDocument == NULL)
     153           0 :         return;
     154             : 
     155             :     // We have to remove the layout suffix from the layout name which is
     156             :     // appended again by SetMasterPage() to the given name.  Don't ask.
     157           0 :     OUString sLayoutSuffix = SD_LT_SEPARATOR + SD_RESSTR(STR_LAYOUT_OUTLINE);
     158           0 :     sal_Int32 nLength = sLayoutSuffix.getLength();
     159           0 :     OUString sLayoutName = pMasterPage->GetLayoutName();
     160           0 :     if (sLayoutName.endsWith(sLayoutSuffix))
     161           0 :         sLayoutName = sLayoutName.copy(0, sLayoutName.getLength() - nLength);
     162             : 
     163             :     rDocument.SetMasterPage (
     164           0 :         pPage->GetPageNum() / 2,
     165             :         sLayoutName,
     166             :         pSourceDocument,
     167             :         sal_False, // Exchange the master page of only the target page.
     168             :         sal_False // Keep unused master pages.
     169           0 :         );
     170             : }
     171             : 
     172             : 
     173             : 
     174             : 
     175           0 : sal_uInt16 ViewClipboard::DetermineInsertPosition  (
     176             :     const SdTransferable& )
     177             : {
     178           0 :     SdDrawDocument& rDoc = mrView.GetDoc();
     179           0 :     sal_uInt16 nPgCnt = rDoc.GetSdPageCount( PK_STANDARD );
     180             : 
     181             :     // Insert position is the behind the last selected page or behind the
     182             :     // last page when the selection is empty.
     183           0 :     sal_uInt16 nInsertPos = rDoc.GetSdPageCount( PK_STANDARD ) * 2 + 1;
     184           0 :     for( sal_uInt16 nPage = 0; nPage < nPgCnt; nPage++ )
     185             :     {
     186           0 :         SdPage* pPage = rDoc.GetSdPage( nPage, PK_STANDARD );
     187             : 
     188           0 :         if( pPage->IsSelected() )
     189           0 :             nInsertPos = nPage * 2 + 3;
     190             :     }
     191             : 
     192           0 :     return nInsertPos;
     193             : }
     194             : 
     195             : 
     196             : 
     197             : 
     198           0 : sal_uInt16 ViewClipboard::InsertSlides (
     199             :     const SdTransferable& rTransferable,
     200             :     sal_uInt16 nInsertPosition)
     201             : {
     202           0 :     SdDrawDocument& rDoc = mrView.GetDoc();
     203             : 
     204           0 :     sal_uInt16 nInsertPgCnt = 0;
     205           0 :     sal_Bool bMergeMasterPages = !rTransferable.HasSourceDoc( &rDoc );
     206             : 
     207             :     // Prepare the insertion.
     208           0 :     const std::vector<OUString> *pBookmarkList = NULL;
     209             :     DrawDocShell* pDataDocSh;
     210           0 :     if (rTransferable.HasPageBookmarks())
     211             :     {
     212             :         // When the transferable contains page bookmarks then the referenced
     213             :         // pages are inserted.
     214           0 :         pBookmarkList = &rTransferable.GetPageBookmarks();
     215           0 :         pDataDocSh = rTransferable.GetPageDocShell();
     216           0 :         nInsertPgCnt = (sal_uInt16)pBookmarkList->size();
     217             :     }
     218             :     else
     219             :     {
     220             :         // Otherwise all pages of the document of the transferable are
     221             :         // inserted.
     222           0 :         SfxObjectShell* pShell = rTransferable.GetDocShell();
     223           0 :         pDataDocSh = (DrawDocShell*) pShell;
     224           0 :         SdDrawDocument* pDataDoc = pDataDocSh->GetDoc();
     225             : 
     226           0 :         if (pDataDoc!=NULL && pDataDoc->GetSdPageCount(PK_STANDARD))
     227           0 :             nInsertPgCnt = pDataDoc->GetSdPageCount(PK_STANDARD);
     228             :     }
     229           0 :     if (nInsertPgCnt > 0)
     230             :     {
     231           0 :         const SolarMutexGuard aGuard;
     232           0 :         ::sd::Window* pWin = mrView.GetViewShell()->GetActiveWindow();
     233           0 :         const sal_Bool bWait = pWin && pWin->IsWait();
     234             : 
     235           0 :         if( bWait )
     236           0 :             pWin->LeaveWait();
     237             : 
     238             :         rDoc.InsertBookmarkAsPage(
     239             :             pBookmarkList ? *pBookmarkList : std::vector<OUString>(),
     240             :             NULL,
     241             :             sal_False,
     242             :             sal_False,
     243             :             nInsertPosition,
     244           0 :             (&rTransferable == SD_MOD()->pTransferDrag),
     245             :             pDataDocSh,
     246             :             sal_True,
     247             :             bMergeMasterPages,
     248           0 :             sal_False);
     249             : 
     250           0 :         if( bWait )
     251           0 :             pWin->EnterWait();
     252             :     }
     253             : 
     254           0 :     return nInsertPgCnt;
     255             : }
     256             : 
     257             : 
     258             : } // end of namespace ::sd
     259             : 
     260             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10