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

Generated by: LCOV version 1.11