1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <fuprlout.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/request.hxx>
#include <svl/stritem.hxx>
#include <sdattr.hrc>
#include <drawdoc.hxx>
#include <sdpage.hxx>
#include <pres.hxx>
#include <DrawViewShell.hxx>
#include <View.hxx>
#include <glob.hxx>
#include <app.hrc>
#include <DrawDocShell.hxx>
#include <SlideSorterViewShell.hxx>
#include <Window.hxx>
#include <drawview.hxx>
#include <sdabstdlg.hxx>
#include <memory>
namespace sd
{
#define DOCUMENT_TOKEN '#'
FuPresentationLayout::FuPresentationLayout (
ViewShell* pViewSh,
::sd::Window* pWin,
::sd::View* pView,
SdDrawDocument* pDoc,
SfxRequest& rReq)
: FuPoor(pViewSh, pWin, pView, pDoc, rReq)
{
}
rtl::Reference<FuPoor> FuPresentationLayout::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
{
rtl::Reference<FuPoor> xFunc( new FuPresentationLayout( pViewSh, pWin, pView, pDoc, rReq ) );
xFunc->DoExecute(rReq);
return xFunc;
}
void FuPresentationLayout::DoExecute( SfxRequest& rReq )
{
// prevent selected objects or objects which are under editing from disappearing
mpView->SdrEndTextEdit();
if(mpView->GetSdrPageView())
{
mpView->UnmarkAll();
}
bool bError = false;
/* if we are on a master page, the changes apply for all pages and notes-
pages who are using the relevant layout */
bool bOnMaster = false;
if (DrawViewShell *pShell = dynamic_cast<DrawViewShell*>(mpViewShell))
{
EditMode eEditMode = pShell->GetEditMode();
if (eEditMode == EditMode::MasterPage)
bOnMaster = true;
}
std::vector<SdPage*> aUnselect;
if (!bOnMaster)
{
//We later rely on IsSelected, so transfer the selection here
//into the document
slidesorter::SlideSorterViewShell* pSlideSorterViewShell
= slidesorter::SlideSorterViewShell::GetSlideSorter(mpViewShell->GetViewShellBase());
if (pSlideSorterViewShell)
{
std::shared_ptr<slidesorter::SlideSorterViewShell::PageSelection> xSelection(
pSlideSorterViewShell->GetPageSelection());
if (xSelection)
{
for (SdPage *pPage : *xSelection)
{
if (pPage->IsSelected() || pPage->GetPageKind() != PageKind::Standard)
continue;
mpDoc->SetSelected(pPage, true);
aUnselect.push_back(pPage);
}
}
}
}
std::vector<SdPage*> aSelectedPages;
std::vector<sal_uInt16> aSelectedPageNums;
// determine the active pages
for (sal_uInt16 nPage = 0; nPage < mpDoc->GetSdPageCount(PageKind::Standard); nPage++)
{
SdPage* pPage = mpDoc->GetSdPage(nPage, PageKind::Standard);
if (pPage->IsSelected())
{
aSelectedPages.push_back(pPage);
aSelectedPageNums.push_back(nPage);
}
}
bool bMasterPage = bOnMaster;
bool bCheckMasters = false;
// call dialog
bool bLoad = false; // appear the new master pages?
OUString aFile;
SfxItemSetFixed<ATTR_PRESLAYOUT_START, ATTR_PRESLAYOUT_END> aSet(mpDoc->GetPool() );
aSet.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD, bLoad));
aSet.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE, bMasterPage ) );
aSet.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS, bCheckMasters ) );
if (!aSelectedPages.empty())
{
OUString aOldLayoutName(aSelectedPages.back()->GetLayoutName());
sal_Int32 nPos = aOldLayoutName.indexOf(SD_LT_SEPARATOR);
if (nPos != -1)
aOldLayoutName = aOldLayoutName.copy(0, nPos);
aSet.Put(SfxStringItem(ATTR_PRESLAYOUT_NAME, aOldLayoutName));
}
const SfxItemSet *pArgs = rReq.GetArgs ();
if (pArgs)
{
if (pArgs->GetItemState(ATTR_PRESLAYOUT_LOAD) == SfxItemState::SET)
bLoad = static_cast<const SfxBoolItem&>(pArgs->Get(ATTR_PRESLAYOUT_LOAD)).GetValue();
if( pArgs->GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE ) == SfxItemState::SET )
bMasterPage = pArgs->Get( ATTR_PRESLAYOUT_MASTER_PAGE ).GetValue();
if( pArgs->GetItemState( ATTR_PRESLAYOUT_CHECK_MASTERS ) == SfxItemState::SET )
bCheckMasters = static_cast<const SfxBoolItem&>( pArgs->Get( ATTR_PRESLAYOUT_CHECK_MASTERS ) ).GetValue();
if (pArgs->GetItemState(ATTR_PRESLAYOUT_NAME) == SfxItemState::SET)
aFile = pArgs->Get(ATTR_PRESLAYOUT_NAME).GetValue();
}
else
{
SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
ScopedVclPtr<AbstractSdPresLayoutDlg> pDlg(pFact->CreateSdPresLayoutDlg(mpWindow ? mpWindow->GetFrameWeld() : nullptr, mpDocSh, aSet));
sal_uInt16 nResult = pDlg->Execute();
switch (nResult)
{
case RET_OK:
{
pDlg->GetAttr(aSet);
if (aSet.GetItemState(ATTR_PRESLAYOUT_LOAD) == SfxItemState::SET)
bLoad = static_cast<const SfxBoolItem&>(aSet.Get(ATTR_PRESLAYOUT_LOAD)).GetValue();
if( aSet.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE ) == SfxItemState::SET )
bMasterPage = aSet.Get( ATTR_PRESLAYOUT_MASTER_PAGE ).GetValue();
if( aSet.GetItemState( ATTR_PRESLAYOUT_CHECK_MASTERS ) == SfxItemState::SET )
bCheckMasters = static_cast<const SfxBoolItem&>(aSet.Get( ATTR_PRESLAYOUT_CHECK_MASTERS ) ).GetValue();
if (aSet.GetItemState(ATTR_PRESLAYOUT_NAME) == SfxItemState::SET)
aFile = aSet.Get(ATTR_PRESLAYOUT_NAME).GetValue();
}
break;
default:
bError = true;
}
}
if (bError)
return;
mpDocSh->SetWaitCursor( true );
/* Here, we only exchange masterpages, therefore the current page
remains the current page. To prevent calling PageOrderChangedHint
during insertion and extraction of the masterpages, we block. */
/* That isn't quite right. If the masterpageview is active and you are
removing a masterpage, it's possible that you are removing the
current masterpage. So you have to call ResetActualPage ! */
if( dynamic_cast< const DrawViewShell *>( mpViewShell ) != nullptr && !bCheckMasters )
static_cast<DrawView*>(mpView)->BlockPageOrderChangedHint(true);
if (bLoad)
{
sal_Int32 nIdx{ 0 };
OUString aFileName = aFile.getToken(0, DOCUMENT_TOKEN, nIdx);
SdDrawDocument* pTempDoc = mpDoc->OpenBookmarkDoc( aFileName );
// #69581: If I chose the standard-template I got no filename and so I get no
// SdDrawDocument-Pointer. But the method SetMasterPage is able to handle
// a NULL-pointer as a Standard-template ( look at SdDrawDocument::SetMasterPage )
OUString aLayoutName;
if( pTempDoc )
aLayoutName = aFile.getToken(0, DOCUMENT_TOKEN, nIdx);
for (auto nSelectedPage : aSelectedPageNums)
mpDoc->SetMasterPage(nSelectedPage, aLayoutName, pTempDoc, bMasterPage, bCheckMasters);
mpDoc->CloseBookmarkDoc();
}
else
{
// use master page with the layout name aFile from current Doc
for (auto nSelectedPage : aSelectedPageNums)
mpDoc->SetMasterPage(nSelectedPage, aFile, mpDoc, bMasterPage, bCheckMasters);
}
// remove blocking
if( dynamic_cast< const DrawViewShell *>( mpViewShell ) != nullptr && !bCheckMasters )
static_cast<DrawView*>(mpView)->BlockPageOrderChangedHint(false);
// if the master page was visible, show it again
if (!aSelectedPages.empty())
{
if (bOnMaster)
{
if( auto pDrawViewShell = dynamic_cast<DrawViewShell *>( mpViewShell ))
{
::sd::View* pView = pDrawViewShell->GetView();
for (auto pSelectedPage : aSelectedPages)
{
sal_uInt16 nPgNum = pSelectedPage->TRG_GetMasterPage().GetPageNum();
if (static_cast<DrawViewShell*>(mpViewShell)->GetPageKind() == PageKind::Notes)
nPgNum++;
pView->HideSdrPage();
pView->ShowSdrPage(pView->GetModel()->GetMasterPage(nPgNum));
}
}
// force update of TabBar
mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_MASTERPAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
}
else
{
for (auto pSelectedPage : aSelectedPages)
pSelectedPage->SetAutoLayout(pSelectedPage->GetAutoLayout());
}
}
//Undo transfer to document selection
for (auto pPage : aUnselect)
mpDoc->SetSelected(pPage, false);
// fake a mode change to repaint the page tab bar
if( auto pDrawViewSh = dynamic_cast<DrawViewShell *>( mpViewShell ) )
{
EditMode eMode = pDrawViewSh->GetEditMode();
bool bLayer = pDrawViewSh->IsLayerModeActive();
pDrawViewSh->ChangeEditMode( eMode, !bLayer );
pDrawViewSh->ChangeEditMode( eMode, bLayer );
}
mpDocSh->SetWaitCursor( false );
}
} // end of namespace sd
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|