LibreOffice Module sd (master) 1
ViewClipboard.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <ViewClipboard.hxx>
21
22#include <DrawDocShell.hxx>
23#include <DrawViewShell.hxx>
24#include <View.hxx>
25#include <ViewShell.hxx>
26#include <Window.hxx>
27
28#include <drawdoc.hxx>
29#include <sdmod.hxx>
30#include <sdpage.hxx>
31#include <sdxfer.hxx>
32#include <strings.hxx>
33
34#include <svx/svdpagv.hxx>
35#include <vcl/svapp.hxx>
36
37namespace sd {
38
40 : mrView(rView)
41{
42}
43
45{
46}
47
49{
50 // Determine whether to insert the given set of slides or to assign a
51 // given master page.
52 // tdf#113405 only assign master pages to normal pages, don't attempt to assign a master
53 // page to a master page
54 sd::DrawViewShell* pDrawViewShell = dynamic_cast<::sd::DrawViewShell*>(mrView.GetViewShell());
55 SdPage* pMasterPage = (pDrawViewShell && pDrawViewShell->GetEditMode() == EditMode::Page) ? GetFirstMasterPage(rTransferable) : nullptr;
56 if (pMasterPage)
57 AssignMasterPage (rTransferable, pMasterPage);
58 else
59 InsertSlides (rTransferable, DetermineInsertPosition ());
60}
61
63{
64 SdPage* pFirstMasterPage = nullptr;
65
66 if (rTransferable.HasPageBookmarks())
67 {
68 do
69 {
70 const std::vector<OUString> &rBookmarks = rTransferable.GetPageBookmarks();
71
72 if (rBookmarks.empty())
73 break;
74
75 DrawDocShell* pDocShell = rTransferable.GetPageDocShell();
76 if (pDocShell == nullptr)
77 break;
78
79 SdDrawDocument* pDocument = pDocShell->GetDoc();
80 if (pDocument == nullptr)
81 break;
82
83 for (const OUString& sName : rBookmarks)
84 {
85 bool bIsMasterPage;
86
87 // SdPage* GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind);
88 // sal_uInt16 GetMasterSdPageCount(PageKind ePgKind) const;
89
90 sal_uInt16 nBMPage = pDocument->GetPageByName (
91 sName, bIsMasterPage);
92 if ( ! bIsMasterPage)
93 {
94 // At least one regular slide: return NULL to indicate
95 // that not all bookmarks point to master pages.
96 pFirstMasterPage = nullptr;
97 break;
98 }
99 else if (pFirstMasterPage == nullptr)
100 {
101 // Remember the first master page for later.
102 if (nBMPage != SDRPAGE_NOTFOUND)
103 pFirstMasterPage = static_cast<SdPage*>(
104 pDocument->GetMasterPage(nBMPage));
105 }
106 }
107 }
108 while (false);
109 }
110
111 return pFirstMasterPage;
112}
113
115 const SdTransferable& rTransferable,
116 SdPage const * pMasterPage)
117{
118 if (pMasterPage == nullptr)
119 return;
120
121 // Get the target page to which the master page is assigned.
122 SdrPageView* pPageView = mrView.GetSdrPageView();
123 if (pPageView == nullptr)
124 return;
125
126 SdPage* pPage = static_cast<SdPage*>(pPageView->GetPage());
127 if (pPage == nullptr)
128 return;
129
130 SdDrawDocument& rDocument = mrView.GetDoc();
131
132 if ( ! rTransferable.HasPageBookmarks())
133 return;
134
135 DrawDocShell* pDataDocShell = rTransferable.GetPageDocShell();
136 if (pDataDocShell == nullptr)
137 return;
138
139 SdDrawDocument* pSourceDocument = pDataDocShell->GetDoc();
140 if (pSourceDocument == nullptr)
141 return;
142
143 // We have to remove the layout suffix from the layout name which is
144 // appended again by SetMasterPage() to the given name. Don't ask.
145 OUString sLayoutSuffix = SD_LT_SEPARATOR + STR_LAYOUT_OUTLINE;
146 sal_Int32 nLength = sLayoutSuffix.getLength();
147 OUString sLayoutName = pMasterPage->GetLayoutName();
148 if (sLayoutName.endsWith(sLayoutSuffix))
149 sLayoutName = sLayoutName.copy(0, sLayoutName.getLength() - nLength);
150
151 rDocument.SetMasterPage (
152 pPage->GetPageNum() / 2,
153 sLayoutName,
154 pSourceDocument,
155 false, // Exchange the master page of only the target page.
156 false // Keep unused master pages.
157 );
158}
159
161{
162 SdDrawDocument& rDoc = mrView.GetDoc();
163 sal_uInt16 nPgCnt = rDoc.GetSdPageCount( PageKind::Standard );
164
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( PageKind::Standard ) * 2 + 1;
168 for( sal_uInt16 nPage = 0; nPage < nPgCnt; nPage++ )
169 {
170 SdPage* pPage = rDoc.GetSdPage( nPage, PageKind::Standard );
171
172 if( pPage->IsSelected() )
173 nInsertPos = nPage * 2 + 3;
174 }
175
176 return nInsertPos;
177}
178
180 const SdTransferable& rTransferable,
181 sal_uInt16 nInsertPosition)
182{
183 SdDrawDocument& rDoc = mrView.GetDoc();
184
185 sal_uInt16 nInsertPgCnt = 0;
186 bool bMergeMasterPages = !rTransferable.HasSourceDoc( &rDoc );
187
188 // Prepare the insertion.
189 const std::vector<OUString> *pBookmarkList = nullptr;
190 DrawDocShell* pDataDocSh;
191 if (rTransferable.HasPageBookmarks())
192 {
193 // When the transferable contains page bookmarks then the referenced
194 // pages are inserted.
195 pBookmarkList = &rTransferable.GetPageBookmarks();
196 pDataDocSh = rTransferable.GetPageDocShell();
197 nInsertPgCnt = static_cast<sal_uInt16>(pBookmarkList->size());
198 }
199 else
200 {
201 // Otherwise all pages of the document of the transferable are
202 // inserted.
203 SfxObjectShell* pShell = rTransferable.GetDocShell().get();
204 pDataDocSh = static_cast<DrawDocShell*>(pShell);
205 SdDrawDocument* pDataDoc = pDataDocSh->GetDoc();
206
207 if (pDataDoc!=nullptr && pDataDoc->GetSdPageCount(PageKind::Standard))
208 nInsertPgCnt = pDataDoc->GetSdPageCount(PageKind::Standard);
209 }
210 if (nInsertPgCnt > 0)
211 {
212 const SolarMutexGuard aGuard;
214 const bool bWait = pWin && pWin->IsWait();
215
216 if( bWait )
217 pWin->LeaveWait();
218
220 pBookmarkList ? *pBookmarkList : std::vector<OUString>(),
221 nullptr,
222 false,
223 false,
224 nInsertPosition,
225 (&rTransferable == SD_MOD()->pTransferDrag),
226 pDataDocSh,
227 true,
228 bMergeMasterPages,
229 false);
230
231 if( bWait )
232 pWin->EnterWait();
233 }
234
235 return nInsertPgCnt;
236}
237
238} // end of namespace ::sd
239
240/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SlideSorterView & mrView
SAL_DLLPRIVATE bool InsertBookmarkAsPage(const std::vector< OUString > &rBookmarkList, std::vector< OUString > *pExchangeList, bool bLink, bool bReplace, sal_uInt16 nPgPos, bool bNoDialogs, ::sd::DrawDocShell *pBookmarkDocSh, bool bCopy, bool bMergeMasterPages, bool bPreservePageNames)
Insert pages into this document.
Definition: drawdoc3.cxx:375
SdPage * GetSdPage(sal_uInt16 nPgNum, PageKind ePgKind) const
Definition: drawdoc2.cxx:207
SAL_DLLPRIVATE sal_uInt16 GetPageByName(std::u16string_view rPgName, bool &rbIsMasterPage) const
Return the first page that has the given name.
Definition: drawdoc2.cxx:126
void SetMasterPage(sal_uInt16 nSdPageNum, std::u16string_view rLayoutName, SdDrawDocument *pSourceDoc, bool bMaster, bool bCheckMasters)
Definition: drawdoc3.cxx:1370
sal_uInt16 GetSdPageCount(PageKind ePgKind) const
Definition: drawdoc2.cxx:212
bool IsSelected() const
Definition: sdpage.hxx:208
virtual OUString GetLayoutName() const override
Definition: sdpage.hxx:255
const SfxObjectShellRef & GetDocShell() const
Definition: sdxfer.hxx:48
bool HasPageBookmarks() const
Definition: sdxfer.hxx:68
::sd::DrawDocShell * GetPageDocShell() const
Definition: sdxfer.hxx:70
const std::vector< OUString > & GetPageBookmarks() const
Definition: sdxfer.hxx:69
bool HasSourceDoc(const SdDrawDocument *pDoc) const
Definition: sdxfer.hxx:64
const SdrPage * GetMasterPage(sal_uInt16 nPgNum) const
SdrPage * GetPage() const
sal_uInt16 GetPageNum() const
SdrPageView * GetSdrPageView() const
SdDrawDocument * GetDoc()
Base class of the stacked shells that provide graphical views to Draw and Impress documents and editi...
EditMode GetEditMode() const
sal_uInt16 InsertSlides(const SdTransferable &rTransferable, sal_uInt16 nInsertPosition)
Insert the slides in the given transferable behind the last selected slide or, when the selection is ...
virtual ~ViewClipboard()
::sd::View & mrView
virtual sal_uInt16 DetermineInsertPosition()
Return an index of a page after which the pages of the transferable are to be inserted into the targe...
static SdPage * GetFirstMasterPage(const SdTransferable &rTransferable)
Return the first master page of the given transferable.
void AssignMasterPage(const SdTransferable &rTransferable, SdPage const *pMasterPage)
Assign the (first) master page of the given transferable to the (...) slide.
ViewClipboard(::sd::View &rView)
void HandlePageDrop(const SdTransferable &rTransferable)
Handle the drop of a drag-and-drop action where the transferable contains a set of pages.
::sd::Window * GetActiveWindow() const
The active window is usually the mpContentWindow.
Definition: ViewShell.hxx:155
ViewShell * GetViewShell() const
Definition: View.hxx:144
SdDrawDocument & GetDoc() const
Definition: View.hxx:293
An SdWindow contains the actual working area of ViewShell.
Definition: Window.hxx:45
T * get() const
void LeaveWait()
bool IsWait() const
void EnterWait()
OUString sName
constexpr OUStringLiteral SD_LT_SEPARATOR
Definition: glob.hxx:49
#define SD_MOD()
Definition: sdmod.hxx:184
constexpr OUStringLiteral STR_LAYOUT_OUTLINE
Definition: strings.hxx:16
#define SDRPAGE_NOTFOUND
sal_Int32 nLength