1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ViewClipboard.cxx,v $
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"
38 #include "ViewShell.hxx"
41 #include "drawdoc.hxx"
44 #include "sdresid.hxx"
47 #include <svx/svdpagv.hxx>
48 #include <vos/mutex.hxx>
49 #include <vcl/svapp.hxx>
53 ViewClipboard::ViewClipboard (::sd::View
& 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
72 SdPage
* pMasterPage
= GetFirstMasterPage (rTransferable
);
73 if (pMasterPage
!= NULL
)
74 AssignMasterPage (rTransferable
, pMasterPage
);
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
)
94 DrawDocShell
* pDocShell
= rTransferable
.GetPageDocShell();
95 if (pDocShell
== NULL
)
98 SdDrawDocument
* pDocument
= pDocShell
->GetDoc();
99 if (pDocument
== NULL
)
102 if (pBookmarks
->Count() <= 0)
105 int nBookmarkCount
= pBookmarks
->Count();
106 for (int nIndex
=0; nIndex
<nBookmarkCount
; nIndex
++)
108 String
sName (*(String
*) pBookmarks
->GetObject(nIndex
));
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
;
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
));
135 return pFirstMasterPage
;
141 void ViewClipboard::AssignMasterPage (
142 const SdTransferable
& rTransferable
,
147 if (pMasterPage
== NULL
)
150 // Get the target page to which the master page is assigned.
151 SdrPageView
* pPageView
= mrView
.GetSdrPageView();
152 if (pPageView
== NULL
)
155 SdPage
* pPage
= static_cast<SdPage
*>(pPageView
->GetPage());
159 SdDrawDocument
* pDocument
= mrView
.GetDoc();
160 if (pDocument
== NULL
)
163 if ( ! rTransferable
.HasPageBookmarks())
166 DrawDocShell
* pDataDocShell
= rTransferable
.GetPageDocShell();
167 if (pDataDocShell
== NULL
)
170 SdDrawDocument
* pSourceDocument
= pDataDocShell
->GetDoc();
171 if (pSourceDocument
== NULL
)
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 (
182 sLayoutName
= String(sLayoutName
, 0, sLayoutName
.Len()-nLength
);
184 pDocument
->SetMasterPage (
185 pPage
->GetPageNum() / 2,
188 FALSE
, // Exchange the master page of only the target page.
189 FALSE
// Keep unused master pages.
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;
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();
243 // Otherwise all pages of the document of the transferable are
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();
261 pDoc
->InsertBookmarkAsPage(
262 const_cast<List
*>(pBookmarkList
),
267 (&rTransferable
== SD_MOD()->pTransferDrag
),
281 } // end of namespace ::sd