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