Update ooo320-m1
[ooovba.git] / sd / source / ui / view / ViewClipboard.cxx
bloba66b086e5820b6d73b8eaee666b2c9e35ecad93f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ViewClipboard.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "ViewClipboard.hxx"
36 #include "DrawDocShell.hxx"
37 #include "View.hxx"
38 #include "ViewShell.hxx"
39 #include "Window.hxx"
41 #include "drawdoc.hxx"
42 #include "sdpage.hxx"
43 #include "sdxfer.hxx"
44 #include "sdresid.hxx"
45 #include "glob.hrc"
47 #include <svx/svdpagv.hxx>
48 #include <vos/mutex.hxx>
49 #include <vcl/svapp.hxx>
51 namespace sd {
53 ViewClipboard::ViewClipboard (::sd::View& rView)
54 : mrView(rView)
61 ViewClipboard::~ViewClipboard (void)
68 void ViewClipboard::HandlePageDrop (const SdTransferable& rTransferable)
70 // Determine whether to insert the given set of slides or to assign a
71 // given master page.
72 SdPage* pMasterPage = GetFirstMasterPage (rTransferable);
73 if (pMasterPage != NULL)
74 AssignMasterPage (rTransferable, pMasterPage);
75 else
76 InsertSlides (rTransferable, DetermineInsertPosition (rTransferable));
82 SdPage* ViewClipboard::GetFirstMasterPage (const SdTransferable& rTransferable)
84 SdPage* pFirstMasterPage = NULL;
86 if (rTransferable.HasPageBookmarks())
90 const List* pBookmarks = &rTransferable.GetPageBookmarks();
91 if (pBookmarks == NULL)
92 break;
94 DrawDocShell* pDocShell = rTransferable.GetPageDocShell();
95 if (pDocShell == NULL)
96 break;
98 SdDrawDocument* pDocument = pDocShell->GetDoc();
99 if (pDocument == NULL)
100 break;
102 if (pBookmarks->Count() <= 0)
103 break;
105 int nBookmarkCount = pBookmarks->Count();
106 for (int nIndex=0; nIndex<nBookmarkCount; nIndex++)
108 String sName (*(String*) pBookmarks->GetObject(nIndex));
109 BOOL bIsMasterPage;
111 // SdPage* GetMasterSdPage(USHORT nPgNum, PageKind ePgKind);
112 // USHORT GetMasterSdPageCount(PageKind ePgKind) const;
114 USHORT nBMPage = pDocument->GetPageByName (
115 sName, bIsMasterPage);
116 if ( ! bIsMasterPage)
118 // At least one regular slide: return NULL to indicate
119 // that not all bookmarks point to master pages.
120 pFirstMasterPage = NULL;
121 break;
123 else if (pFirstMasterPage == NULL)
125 // Remember the first master page for later.
126 if (nBMPage != SDRPAGE_NOTFOUND)
127 pFirstMasterPage = static_cast<SdPage*>(
128 pDocument->GetMasterPage(nBMPage));
132 while (false);
135 return pFirstMasterPage;
141 void ViewClipboard::AssignMasterPage (
142 const SdTransferable& rTransferable,
143 SdPage* pMasterPage)
147 if (pMasterPage == NULL)
148 return;
150 // Get the target page to which the master page is assigned.
151 SdrPageView* pPageView = mrView.GetSdrPageView();
152 if (pPageView == NULL)
153 break;
155 SdPage* pPage = static_cast<SdPage*>(pPageView->GetPage());
156 if (pPage == NULL)
157 break;
159 SdDrawDocument* pDocument = mrView.GetDoc();
160 if (pDocument == NULL)
161 break;
163 if ( ! rTransferable.HasPageBookmarks())
164 break;
166 DrawDocShell* pDataDocShell = rTransferable.GetPageDocShell();
167 if (pDataDocShell == NULL)
168 break;
170 SdDrawDocument* pSourceDocument = pDataDocShell->GetDoc();
171 if (pSourceDocument == NULL)
172 break;
174 // We have to remove the layout suffix from the layout name which is
175 // appended again by SetMasterPage() to the given name. Don't ask.
176 String sLayoutSuffix (RTL_CONSTASCII_STRINGPARAM(SD_LT_SEPARATOR));
177 sLayoutSuffix.Append (SdResId(STR_LAYOUT_OUTLINE));
178 USHORT nLength = sLayoutSuffix.Len();
179 String sLayoutName (pMasterPage->GetLayoutName());
180 if (String(sLayoutName, sLayoutName.Len()-nLength, nLength).Equals (
181 sLayoutSuffix))
182 sLayoutName = String(sLayoutName, 0, sLayoutName.Len()-nLength);
184 pDocument->SetMasterPage (
185 pPage->GetPageNum() / 2,
186 sLayoutName,
187 pSourceDocument,
188 FALSE, // Exchange the master page of only the target page.
189 FALSE // Keep unused master pages.
192 while (false);
198 USHORT ViewClipboard::DetermineInsertPosition (
199 const SdTransferable& )
201 SdDrawDocument* pDoc = mrView.GetDoc();
202 USHORT nPgCnt = pDoc->GetSdPageCount( PK_STANDARD );
204 // Insert position is the behind the last selected page or behind the
205 // last page when the selection is empty.
206 USHORT nInsertPos = pDoc->GetSdPageCount( PK_STANDARD ) * 2 + 1;
207 for( USHORT nPage = 0; nPage < nPgCnt; nPage++ )
209 SdPage* pPage = pDoc->GetSdPage( nPage, PK_STANDARD );
211 if( pPage->IsSelected() )
212 nInsertPos = nPage * 2 + 3;
215 return nInsertPos;
221 USHORT ViewClipboard::InsertSlides (
222 const SdTransferable& rTransferable,
223 USHORT nInsertPosition)
225 SdDrawDocument* pDoc = mrView.GetDoc();
227 USHORT nInsertPgCnt = 0;
228 BOOL bMergeMasterPages = !rTransferable.HasSourceDoc( pDoc );
230 // Prepare the insertion.
231 const List* pBookmarkList;
232 DrawDocShell* pDataDocSh;
233 if (rTransferable.HasPageBookmarks())
235 // When the transferable contains page bookmarks then the referenced
236 // pages are inserted.
237 pBookmarkList = &rTransferable.GetPageBookmarks();
238 pDataDocSh = rTransferable.GetPageDocShell();
239 nInsertPgCnt = (USHORT)pBookmarkList->Count();
241 else
243 // Otherwise all pages of the document of the transferable are
244 // inserted.
245 SfxObjectShell* pShell = rTransferable.GetDocShell();
246 pDataDocSh = (DrawDocShell*) pShell;
247 SdDrawDocument* pDataDoc = pDataDocSh->GetDoc();
248 pBookmarkList = NULL;
249 if (pDataDoc!=NULL && pDataDoc->GetSdPageCount(PK_STANDARD))
250 nInsertPgCnt = pDataDoc->GetSdPageCount(PK_STANDARD);
252 if (nInsertPgCnt > 0)
254 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
255 ::sd::Window* pWin = mrView.GetViewShell()->GetActiveWindow();
256 const BOOL bWait = pWin && pWin->IsWait();
258 if( bWait )
259 pWin->LeaveWait();
261 pDoc->InsertBookmarkAsPage(
262 const_cast<List*>(pBookmarkList),
263 NULL,
264 FALSE,
265 FALSE,
266 nInsertPosition,
267 (&rTransferable == SD_MOD()->pTransferDrag),
268 pDataDocSh,
269 TRUE,
270 bMergeMasterPages,
271 FALSE);
273 if( bWait )
274 pWin->EnterWait();
277 return nInsertPgCnt;
281 } // end of namespace ::sd