LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/view - ViewClipboard.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 86 0.0 %
Date: 2012-12-27 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<rtl::OUString> &rBookmarks = rTransferable.GetPageBookmarks();
      78             : 
      79           0 :             if (rBookmarks.empty())
      80             :                 break;
      81             : 
      82           0 :             DrawDocShell* pDocShell = rTransferable.GetPageDocShell();
      83           0 :             if (pDocShell == NULL)
      84             :                 break;
      85             : 
      86           0 :             SdDrawDocument* pDocument = pDocShell->GetDoc();
      87           0 :             if (pDocument == NULL)
      88             :                 break;
      89             : 
      90           0 :             std::vector<rtl::OUString>::const_iterator pIter;
      91           0 :             for ( pIter = rBookmarks.begin(); pIter != rBookmarks.end(); ++pIter )
      92             :             {
      93           0 :                 String 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             :                     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             :         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             :         return;
     137             : 
     138           0 :     SdPage* pPage = static_cast<SdPage*>(pPageView->GetPage());
     139           0 :     if (pPage == NULL)
     140             :         return;
     141             : 
     142           0 :     SdDrawDocument& rDocument = mrView.GetDoc();
     143             : 
     144           0 :     if ( ! rTransferable.HasPageBookmarks())
     145             :         return;
     146             : 
     147           0 :     DrawDocShell* pDataDocShell = rTransferable.GetPageDocShell();
     148           0 :     if (pDataDocShell == NULL)
     149             :         return;
     150             : 
     151           0 :     SdDrawDocument* pSourceDocument = pDataDocShell->GetDoc();
     152           0 :     if (pSourceDocument == NULL)
     153             :         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 :     String sLayoutSuffix (RTL_CONSTASCII_USTRINGPARAM(SD_LT_SEPARATOR));
     158           0 :     sLayoutSuffix.Append (SdResId(STR_LAYOUT_OUTLINE));
     159           0 :     sal_uInt16 nLength = sLayoutSuffix.Len();
     160           0 :     String sLayoutName (pMasterPage->GetLayoutName());
     161           0 :     if (String(sLayoutName, sLayoutName.Len()-nLength, nLength).Equals (
     162           0 :         sLayoutSuffix))
     163           0 :         sLayoutName = String(sLayoutName, 0, sLayoutName.Len()-nLength);
     164             : 
     165             :     rDocument.SetMasterPage (
     166           0 :         pPage->GetPageNum() / 2,
     167             :         sLayoutName,
     168             :         pSourceDocument,
     169             :         sal_False, // Exchange the master page of only the target page.
     170             :         sal_False // Keep unused master pages.
     171           0 :         );
     172             : }
     173             : 
     174             : 
     175             : 
     176             : 
     177           0 : sal_uInt16 ViewClipboard::DetermineInsertPosition  (
     178             :     const SdTransferable& )
     179             : {
     180           0 :     SdDrawDocument& rDoc = mrView.GetDoc();
     181           0 :     sal_uInt16 nPgCnt = rDoc.GetSdPageCount( PK_STANDARD );
     182             : 
     183             :     // Insert position is the behind the last selected page or behind the
     184             :     // last page when the selection is empty.
     185           0 :     sal_uInt16 nInsertPos = rDoc.GetSdPageCount( PK_STANDARD ) * 2 + 1;
     186           0 :     for( sal_uInt16 nPage = 0; nPage < nPgCnt; nPage++ )
     187             :     {
     188           0 :         SdPage* pPage = rDoc.GetSdPage( nPage, PK_STANDARD );
     189             : 
     190           0 :         if( pPage->IsSelected() )
     191           0 :             nInsertPos = nPage * 2 + 3;
     192             :     }
     193             : 
     194           0 :     return nInsertPos;
     195             : }
     196             : 
     197             : 
     198             : 
     199             : 
     200           0 : sal_uInt16 ViewClipboard::InsertSlides (
     201             :     const SdTransferable& rTransferable,
     202             :     sal_uInt16 nInsertPosition)
     203             : {
     204           0 :     SdDrawDocument& rDoc = mrView.GetDoc();
     205             : 
     206           0 :     sal_uInt16 nInsertPgCnt = 0;
     207           0 :     sal_Bool bMergeMasterPages = !rTransferable.HasSourceDoc( &rDoc );
     208             : 
     209             :     // Prepare the insertion.
     210           0 :     const std::vector<rtl::OUString> *pBookmarkList = NULL;
     211             :     DrawDocShell* pDataDocSh;
     212           0 :     if (rTransferable.HasPageBookmarks())
     213             :     {
     214             :         // When the transferable contains page bookmarks then the referenced
     215             :         // pages are inserted.
     216           0 :         pBookmarkList = &rTransferable.GetPageBookmarks();
     217           0 :         pDataDocSh = rTransferable.GetPageDocShell();
     218           0 :         nInsertPgCnt = (sal_uInt16)pBookmarkList->size();
     219             :     }
     220             :     else
     221             :     {
     222             :         // Otherwise all pages of the document of the transferable are
     223             :         // inserted.
     224           0 :         SfxObjectShell* pShell = rTransferable.GetDocShell();
     225           0 :         pDataDocSh = (DrawDocShell*) pShell;
     226           0 :         SdDrawDocument* pDataDoc = pDataDocSh->GetDoc();
     227             : 
     228           0 :         if (pDataDoc!=NULL && pDataDoc->GetSdPageCount(PK_STANDARD))
     229           0 :             nInsertPgCnt = pDataDoc->GetSdPageCount(PK_STANDARD);
     230             :     }
     231           0 :     if (nInsertPgCnt > 0)
     232             :     {
     233           0 :         const SolarMutexGuard aGuard;
     234           0 :         ::sd::Window* pWin = mrView.GetViewShell()->GetActiveWindow();
     235           0 :         const sal_Bool bWait = pWin && pWin->IsWait();
     236             : 
     237           0 :         if( bWait )
     238           0 :             pWin->LeaveWait();
     239             : 
     240             :         rDoc.InsertBookmarkAsPage(
     241             :             pBookmarkList ? *pBookmarkList : std::vector<rtl::OUString>(),
     242             :             NULL,
     243             :             sal_False,
     244             :             sal_False,
     245             :             nInsertPosition,
     246           0 :             (&rTransferable == SD_MOD()->pTransferDrag),
     247             :             pDataDocSh,
     248             :             sal_True,
     249             :             bMergeMasterPages,
     250           0 :             sal_False);
     251             : 
     252           0 :         if( bWait )
     253           0 :             pWin->EnterWait();
     254             :     }
     255             : 
     256           0 :     return nInsertPgCnt;
     257             : }
     258             : 
     259             : 
     260             : } // end of namespace ::sd
     261             : 
     262             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10