1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "ViewClipboard.hxx"
22 #include "DrawDocShell.hxx"
24 #include "ViewShell.hxx"
27 #include "drawdoc.hxx"
30 #include "sdresid.hxx"
33 #include <svx/svdpagv.hxx>
34 #include <osl/mutex.hxx>
35 #include <vcl/svapp.hxx>
39 ViewClipboard::ViewClipboard (::sd::View
& rView
)
44 ViewClipboard::~ViewClipboard()
48 void ViewClipboard::HandlePageDrop (const SdTransferable
& rTransferable
)
50 // Determine whether to insert the given set of slides or to assign a
52 SdPage
* pMasterPage
= GetFirstMasterPage (rTransferable
);
53 if (pMasterPage
!= NULL
)
54 AssignMasterPage (rTransferable
, pMasterPage
);
56 InsertSlides (rTransferable
, DetermineInsertPosition (rTransferable
));
59 SdPage
* ViewClipboard::GetFirstMasterPage (const SdTransferable
& rTransferable
)
61 SdPage
* pFirstMasterPage
= NULL
;
63 if (rTransferable
.HasPageBookmarks())
67 const std::vector
<OUString
> &rBookmarks
= rTransferable
.GetPageBookmarks();
69 if (rBookmarks
.empty())
72 DrawDocShell
* pDocShell
= rTransferable
.GetPageDocShell();
73 if (pDocShell
== NULL
)
76 SdDrawDocument
* pDocument
= pDocShell
->GetDoc();
77 if (pDocument
== NULL
)
80 std::vector
<OUString
>::const_iterator pIter
;
81 for ( pIter
= rBookmarks
.begin(); pIter
!= rBookmarks
.end(); ++pIter
)
83 OUString
sName (*pIter
);
86 // SdPage* GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind);
87 // sal_uInt16 GetMasterSdPageCount(PageKind ePgKind) const;
89 sal_uInt16 nBMPage
= pDocument
->GetPageByName (
90 sName
, bIsMasterPage
);
93 // At least one regular slide: return NULL to indicate
94 // that not all bookmarks point to master pages.
95 pFirstMasterPage
= NULL
;
98 else if (pFirstMasterPage
== NULL
)
100 // Remember the first master page for later.
101 if (nBMPage
!= SDRPAGE_NOTFOUND
)
102 pFirstMasterPage
= static_cast<SdPage
*>(
103 pDocument
->GetMasterPage(nBMPage
));
110 return pFirstMasterPage
;
113 void ViewClipboard::AssignMasterPage (
114 const SdTransferable
& rTransferable
,
117 if (pMasterPage
== NULL
)
120 // Get the target page to which the master page is assigned.
121 SdrPageView
* pPageView
= mrView
.GetSdrPageView();
122 if (pPageView
== NULL
)
125 SdPage
* pPage
= static_cast<SdPage
*>(pPageView
->GetPage());
129 SdDrawDocument
& rDocument
= mrView
.GetDoc();
131 if ( ! rTransferable
.HasPageBookmarks())
134 DrawDocShell
* pDataDocShell
= rTransferable
.GetPageDocShell();
135 if (pDataDocShell
== NULL
)
138 SdDrawDocument
* pSourceDocument
= pDataDocShell
->GetDoc();
139 if (pSourceDocument
== NULL
)
142 // We have to remove the layout suffix from the layout name which is
143 // appended again by SetMasterPage() to the given name. Don't ask.
144 OUString sLayoutSuffix
= SD_LT_SEPARATOR
+ SD_RESSTR(STR_LAYOUT_OUTLINE
);
145 sal_Int32 nLength
= sLayoutSuffix
.getLength();
146 OUString sLayoutName
= pMasterPage
->GetLayoutName();
147 if (sLayoutName
.endsWith(sLayoutSuffix
))
148 sLayoutName
= sLayoutName
.copy(0, sLayoutName
.getLength() - nLength
);
150 rDocument
.SetMasterPage (
151 pPage
->GetPageNum() / 2,
154 false, // Exchange the master page of only the target page.
155 false // Keep unused master pages.
159 sal_uInt16
ViewClipboard::DetermineInsertPosition (
160 const SdTransferable
& )
162 SdDrawDocument
& rDoc
= mrView
.GetDoc();
163 sal_uInt16 nPgCnt
= rDoc
.GetSdPageCount( PK_STANDARD
);
165 // Insert position is the behind the last selected page or behind the
166 // last page when the selection is empty.
167 sal_uInt16 nInsertPos
= rDoc
.GetSdPageCount( PK_STANDARD
) * 2 + 1;
168 for( sal_uInt16 nPage
= 0; nPage
< nPgCnt
; nPage
++ )
170 SdPage
* pPage
= rDoc
.GetSdPage( nPage
, PK_STANDARD
);
172 if( pPage
->IsSelected() )
173 nInsertPos
= nPage
* 2 + 3;
179 sal_uInt16
ViewClipboard::InsertSlides (
180 const SdTransferable
& rTransferable
,
181 sal_uInt16 nInsertPosition
)
183 SdDrawDocument
& rDoc
= mrView
.GetDoc();
185 sal_uInt16 nInsertPgCnt
= 0;
186 bool bMergeMasterPages
= !rTransferable
.HasSourceDoc( &rDoc
);
188 // Prepare the insertion.
189 const std::vector
<OUString
> *pBookmarkList
= NULL
;
190 DrawDocShell
* pDataDocSh
;
191 if (rTransferable
.HasPageBookmarks())
193 // When the transferable contains page bookmarks then the referenced
194 // pages are inserted.
195 pBookmarkList
= &rTransferable
.GetPageBookmarks();
196 pDataDocSh
= rTransferable
.GetPageDocShell();
197 nInsertPgCnt
= (sal_uInt16
)pBookmarkList
->size();
201 // Otherwise all pages of the document of the transferable are
203 SfxObjectShell
* pShell
= rTransferable
.GetDocShell();
204 pDataDocSh
= static_cast<DrawDocShell
*>(pShell
);
205 SdDrawDocument
* pDataDoc
= pDataDocSh
->GetDoc();
207 if (pDataDoc
!=NULL
&& pDataDoc
->GetSdPageCount(PK_STANDARD
))
208 nInsertPgCnt
= pDataDoc
->GetSdPageCount(PK_STANDARD
);
210 if (nInsertPgCnt
> 0)
212 const SolarMutexGuard aGuard
;
213 ::sd::Window
* pWin
= mrView
.GetViewShell()->GetActiveWindow();
214 const bool bWait
= pWin
&& pWin
->IsWait();
219 rDoc
.InsertBookmarkAsPage(
220 pBookmarkList
? *pBookmarkList
: std::vector
<OUString
>(),
225 (&rTransferable
== SD_MOD()->pTransferDrag
),
238 } // end of namespace ::sd
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */