1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sd.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "ViewClipboard.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "DrawDocShell.hxx" 34*cdf0e10cSrcweir #include "View.hxx" 35*cdf0e10cSrcweir #include "ViewShell.hxx" 36*cdf0e10cSrcweir #include "Window.hxx" 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include "drawdoc.hxx" 39*cdf0e10cSrcweir #include "sdpage.hxx" 40*cdf0e10cSrcweir #include "sdxfer.hxx" 41*cdf0e10cSrcweir #include "sdresid.hxx" 42*cdf0e10cSrcweir #include "glob.hrc" 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #include <svx/svdpagv.hxx> 45*cdf0e10cSrcweir #include <vos/mutex.hxx> 46*cdf0e10cSrcweir #include <vcl/svapp.hxx> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir namespace sd { 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir ViewClipboard::ViewClipboard (::sd::View& rView) 51*cdf0e10cSrcweir : mrView(rView) 52*cdf0e10cSrcweir { 53*cdf0e10cSrcweir } 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir ViewClipboard::~ViewClipboard (void) 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir void ViewClipboard::HandlePageDrop (const SdTransferable& rTransferable) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir // Determine whether to insert the given set of slides or to assign a 68*cdf0e10cSrcweir // given master page. 69*cdf0e10cSrcweir SdPage* pMasterPage = GetFirstMasterPage (rTransferable); 70*cdf0e10cSrcweir if (pMasterPage != NULL) 71*cdf0e10cSrcweir AssignMasterPage (rTransferable, pMasterPage); 72*cdf0e10cSrcweir else 73*cdf0e10cSrcweir InsertSlides (rTransferable, DetermineInsertPosition (rTransferable)); 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir SdPage* ViewClipboard::GetFirstMasterPage (const SdTransferable& rTransferable) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir SdPage* pFirstMasterPage = NULL; 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir if (rTransferable.HasPageBookmarks()) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir do 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir const List* pBookmarks = &rTransferable.GetPageBookmarks(); 88*cdf0e10cSrcweir if (pBookmarks == NULL) 89*cdf0e10cSrcweir break; 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir DrawDocShell* pDocShell = rTransferable.GetPageDocShell(); 92*cdf0e10cSrcweir if (pDocShell == NULL) 93*cdf0e10cSrcweir break; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir SdDrawDocument* pDocument = pDocShell->GetDoc(); 96*cdf0e10cSrcweir if (pDocument == NULL) 97*cdf0e10cSrcweir break; 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir if (pBookmarks->Count() <= 0) 100*cdf0e10cSrcweir break; 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir int nBookmarkCount = pBookmarks->Count(); 103*cdf0e10cSrcweir for (int nIndex=0; nIndex<nBookmarkCount; nIndex++) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir String sName (*(String*) pBookmarks->GetObject(nIndex)); 106*cdf0e10cSrcweir sal_Bool bIsMasterPage; 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir // SdPage* GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind); 109*cdf0e10cSrcweir // sal_uInt16 GetMasterSdPageCount(PageKind ePgKind) const; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir sal_uInt16 nBMPage = pDocument->GetPageByName ( 112*cdf0e10cSrcweir sName, bIsMasterPage); 113*cdf0e10cSrcweir if ( ! bIsMasterPage) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir // At least one regular slide: return NULL to indicate 116*cdf0e10cSrcweir // that not all bookmarks point to master pages. 117*cdf0e10cSrcweir pFirstMasterPage = NULL; 118*cdf0e10cSrcweir break; 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir else if (pFirstMasterPage == NULL) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir // Remember the first master page for later. 123*cdf0e10cSrcweir if (nBMPage != SDRPAGE_NOTFOUND) 124*cdf0e10cSrcweir pFirstMasterPage = static_cast<SdPage*>( 125*cdf0e10cSrcweir pDocument->GetMasterPage(nBMPage)); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir while (false); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir return pFirstMasterPage; 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir void ViewClipboard::AssignMasterPage ( 139*cdf0e10cSrcweir const SdTransferable& rTransferable, 140*cdf0e10cSrcweir SdPage* pMasterPage) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir do 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir if (pMasterPage == NULL) 145*cdf0e10cSrcweir return; 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir // Get the target page to which the master page is assigned. 148*cdf0e10cSrcweir SdrPageView* pPageView = mrView.GetSdrPageView(); 149*cdf0e10cSrcweir if (pPageView == NULL) 150*cdf0e10cSrcweir break; 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir SdPage* pPage = static_cast<SdPage*>(pPageView->GetPage()); 153*cdf0e10cSrcweir if (pPage == NULL) 154*cdf0e10cSrcweir break; 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir SdDrawDocument* pDocument = mrView.GetDoc(); 157*cdf0e10cSrcweir if (pDocument == NULL) 158*cdf0e10cSrcweir break; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir if ( ! rTransferable.HasPageBookmarks()) 161*cdf0e10cSrcweir break; 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir DrawDocShell* pDataDocShell = rTransferable.GetPageDocShell(); 164*cdf0e10cSrcweir if (pDataDocShell == NULL) 165*cdf0e10cSrcweir break; 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir SdDrawDocument* pSourceDocument = pDataDocShell->GetDoc(); 168*cdf0e10cSrcweir if (pSourceDocument == NULL) 169*cdf0e10cSrcweir break; 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir // We have to remove the layout suffix from the layout name which is 172*cdf0e10cSrcweir // appended again by SetMasterPage() to the given name. Don't ask. 173*cdf0e10cSrcweir String sLayoutSuffix (RTL_CONSTASCII_STRINGPARAM(SD_LT_SEPARATOR)); 174*cdf0e10cSrcweir sLayoutSuffix.Append (SdResId(STR_LAYOUT_OUTLINE)); 175*cdf0e10cSrcweir sal_uInt16 nLength = sLayoutSuffix.Len(); 176*cdf0e10cSrcweir String sLayoutName (pMasterPage->GetLayoutName()); 177*cdf0e10cSrcweir if (String(sLayoutName, sLayoutName.Len()-nLength, nLength).Equals ( 178*cdf0e10cSrcweir sLayoutSuffix)) 179*cdf0e10cSrcweir sLayoutName = String(sLayoutName, 0, sLayoutName.Len()-nLength); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir pDocument->SetMasterPage ( 182*cdf0e10cSrcweir pPage->GetPageNum() / 2, 183*cdf0e10cSrcweir sLayoutName, 184*cdf0e10cSrcweir pSourceDocument, 185*cdf0e10cSrcweir sal_False, // Exchange the master page of only the target page. 186*cdf0e10cSrcweir sal_False // Keep unused master pages. 187*cdf0e10cSrcweir ); 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir while (false); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir sal_uInt16 ViewClipboard::DetermineInsertPosition ( 196*cdf0e10cSrcweir const SdTransferable& ) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir SdDrawDocument* pDoc = mrView.GetDoc(); 199*cdf0e10cSrcweir sal_uInt16 nPgCnt = pDoc->GetSdPageCount( PK_STANDARD ); 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir // Insert position is the behind the last selected page or behind the 202*cdf0e10cSrcweir // last page when the selection is empty. 203*cdf0e10cSrcweir sal_uInt16 nInsertPos = pDoc->GetSdPageCount( PK_STANDARD ) * 2 + 1; 204*cdf0e10cSrcweir for( sal_uInt16 nPage = 0; nPage < nPgCnt; nPage++ ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir SdPage* pPage = pDoc->GetSdPage( nPage, PK_STANDARD ); 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir if( pPage->IsSelected() ) 209*cdf0e10cSrcweir nInsertPos = nPage * 2 + 3; 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir return nInsertPos; 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir sal_uInt16 ViewClipboard::InsertSlides ( 219*cdf0e10cSrcweir const SdTransferable& rTransferable, 220*cdf0e10cSrcweir sal_uInt16 nInsertPosition) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir SdDrawDocument* pDoc = mrView.GetDoc(); 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir sal_uInt16 nInsertPgCnt = 0; 225*cdf0e10cSrcweir sal_Bool bMergeMasterPages = !rTransferable.HasSourceDoc( pDoc ); 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir // Prepare the insertion. 228*cdf0e10cSrcweir const List* pBookmarkList; 229*cdf0e10cSrcweir DrawDocShell* pDataDocSh; 230*cdf0e10cSrcweir if (rTransferable.HasPageBookmarks()) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir // When the transferable contains page bookmarks then the referenced 233*cdf0e10cSrcweir // pages are inserted. 234*cdf0e10cSrcweir pBookmarkList = &rTransferable.GetPageBookmarks(); 235*cdf0e10cSrcweir pDataDocSh = rTransferable.GetPageDocShell(); 236*cdf0e10cSrcweir nInsertPgCnt = (sal_uInt16)pBookmarkList->Count(); 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir else 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir // Otherwise all pages of the document of the transferable are 241*cdf0e10cSrcweir // inserted. 242*cdf0e10cSrcweir SfxObjectShell* pShell = rTransferable.GetDocShell(); 243*cdf0e10cSrcweir pDataDocSh = (DrawDocShell*) pShell; 244*cdf0e10cSrcweir SdDrawDocument* pDataDoc = pDataDocSh->GetDoc(); 245*cdf0e10cSrcweir pBookmarkList = NULL; 246*cdf0e10cSrcweir if (pDataDoc!=NULL && pDataDoc->GetSdPageCount(PK_STANDARD)) 247*cdf0e10cSrcweir nInsertPgCnt = pDataDoc->GetSdPageCount(PK_STANDARD); 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir if (nInsertPgCnt > 0) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 252*cdf0e10cSrcweir ::sd::Window* pWin = mrView.GetViewShell()->GetActiveWindow(); 253*cdf0e10cSrcweir const sal_Bool bWait = pWin && pWin->IsWait(); 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir if( bWait ) 256*cdf0e10cSrcweir pWin->LeaveWait(); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir pDoc->InsertBookmarkAsPage( 259*cdf0e10cSrcweir const_cast<List*>(pBookmarkList), 260*cdf0e10cSrcweir NULL, 261*cdf0e10cSrcweir sal_False, 262*cdf0e10cSrcweir sal_False, 263*cdf0e10cSrcweir nInsertPosition, 264*cdf0e10cSrcweir (&rTransferable == SD_MOD()->pTransferDrag), 265*cdf0e10cSrcweir pDataDocSh, 266*cdf0e10cSrcweir sal_True, 267*cdf0e10cSrcweir bMergeMasterPages, 268*cdf0e10cSrcweir sal_False); 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir if( bWait ) 271*cdf0e10cSrcweir pWin->EnterWait(); 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir return nInsertPgCnt; 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir } // end of namespace ::sd 279