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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
/* -*- 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 <config_features.h>
#include <ViewShellImplementation.hxx>
#include <sdpage.hxx>
#include <drawdoc.hxx>
#include <sdresid.hxx>
#include <unokywds.hxx>
#include <strings.hrc>
#include <app.hrc>
#include <unmodpg.hxx>
#include <DrawDocShell.hxx>
#include <FactoryIds.hxx>
#include <ViewShellBase.hxx>
#include <sfx2/bindings.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/request.hxx>
#include <sfx2/sfxsids.hrc>
#include <sfx2/viewfrm.hxx>
#include <sfx2/sidebar/Sidebar.hxx>
#include <svl/intitem.hxx>
#include <svl/stritem.hxx>
#include <svx/imapdlg.hxx>
#include <basic/sbstar.hxx>
#include <basic/sberrors.hxx>
#include <xmloff/autolayout.hxx>
#include <vcl/svapp.hxx>
#include <undo/undoobjects.hxx>
#include <com/sun/star/drawing/framework/XControllerManager.hpp>
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::drawing::framework;
namespace sd {
ViewShell::Implementation::Implementation (ViewShell& rViewShell)
: mbIsMainViewShell(false),
mbIsInitialized(false),
mbArrangeActive(false),
mrViewShell(rViewShell)
{
}
ViewShell::Implementation::~Implementation() COVERITY_NOEXCEPT_FALSE
{
if ( ! mpUpdateLockForMouse.expired())
{
std::shared_ptr<ToolBarManagerLock> pLock(mpUpdateLockForMouse);
if (pLock != nullptr)
{
// Force the ToolBarManagerLock to be released even when the
// IsUICaptured() returns <TRUE/>.
pLock->Release(true);
}
}
}
void ViewShell::Implementation::ProcessModifyPageSlot (
SfxRequest& rRequest,
SdPage* pCurrentPage,
PageKind ePageKind)
{
SdDrawDocument* pDocument = mrViewShell.GetDoc();
SdrLayerAdmin& rLayerAdmin = pDocument->GetLayerAdmin();
SdrLayerIDSet aVisibleLayers;
bool bHandoutMode = false;
SdPage* pHandoutMPage = nullptr;
OUString aNewName;
AutoLayout aNewAutoLayout;
bool bBVisible;
bool bBObjsVisible;
const SfxItemSet* pArgs = rRequest.GetArgs();
if (pCurrentPage != nullptr && pCurrentPage->TRG_HasMasterPage())
aVisibleLayers = pCurrentPage->TRG_GetMasterPageVisibleLayers();
else
aVisibleLayers.SetAll();
do
{
if (pCurrentPage == nullptr)
break;
if (!pArgs || pArgs->Count() == 1 || pArgs->Count() == 2 )
{
// First make sure that the sidebar is visible
mrViewShell.GetDrawView()->SdrEndTextEdit();
mrViewShell.GetDrawView()->UnmarkAll();
mrViewShell.GetViewFrame()->ShowChildWindow(SID_SIDEBAR);
sfx2::sidebar::Sidebar::TogglePanel(
u"SdLayoutsPanel",
mrViewShell.GetViewFrame()->GetFrame().GetFrameInterface());
break;
}
else if (pArgs->Count() == 4)
{
const SfxStringItem* pNewName = rRequest.GetArg<SfxStringItem>(ID_VAL_PAGENAME);
const SfxUInt32Item* pNewAutoLayout = rRequest.GetArg<SfxUInt32Item>(ID_VAL_WHATLAYOUT);
const SfxBoolItem* pBVisible = rRequest.GetArg<SfxBoolItem>(ID_VAL_ISPAGEBACK);
const SfxBoolItem* pBObjsVisible = rRequest.GetArg<SfxBoolItem>(ID_VAL_ISPAGEOBJ);
AutoLayout aLayout (static_cast<AutoLayout>(pNewAutoLayout->GetValue ()));
if (aLayout >= AUTOLAYOUT_START
&& aLayout < AUTOLAYOUT_END)
{
aNewName = pNewName->GetValue ();
aNewAutoLayout = static_cast<AutoLayout>(pNewAutoLayout->GetValue ());
bBVisible = pBVisible->GetValue ();
bBObjsVisible = pBObjsVisible->GetValue ();
}
else
{
#if HAVE_FEATURE_SCRIPTING
StarBASIC::FatalError (ERRCODE_BASIC_BAD_PROP_VALUE);
#endif
rRequest.Ignore ();
break;
}
if (ePageKind == PageKind::Handout)
{
bHandoutMode = true;
pHandoutMPage = pDocument->GetMasterSdPage(0, PageKind::Handout);
}
}
else
{
#if HAVE_FEATURE_SCRIPTING
StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
#endif
rRequest.Ignore ();
break;
}
SdPage* pUndoPage =
bHandoutMode ? pHandoutMPage : pCurrentPage;
SfxUndoManager* pUndoManager = mrViewShell.GetDocSh()->GetUndoManager();
DBG_ASSERT(pUndoManager, "No UNDO MANAGER ?!?");
if( pUndoManager )
{
OUString aComment( SdResId(STR_UNDO_MODIFY_PAGE) );
pUndoManager->EnterListAction(aComment, aComment, 0, mrViewShell.GetViewShellBase().GetViewShellId());
pUndoManager->AddUndoAction(
std::make_unique<ModifyPageUndoAction>(
pDocument, pUndoPage, aNewName, aNewAutoLayout, bBVisible, bBObjsVisible));
// Clear the selection because the selected object may be removed as
// a result of the assignment of the layout.
mrViewShell.GetDrawView()->UnmarkAll();
if (!bHandoutMode)
{
if (pCurrentPage->GetName() != aNewName)
{
pCurrentPage->SetName(aNewName);
if (ePageKind == PageKind::Standard)
{
sal_uInt16 nPage = (pCurrentPage->GetPageNum()-1) / 2;
SdPage* pNotesPage = pDocument->GetSdPage(nPage, PageKind::Notes);
if (pNotesPage != nullptr)
pNotesPage->SetName(aNewName);
}
}
pCurrentPage->SetAutoLayout(aNewAutoLayout, true);
SdrLayerID aBckgrnd = rLayerAdmin.GetLayerID(sUNO_LayerName_background);
SdrLayerID aBckgrndObj = rLayerAdmin.GetLayerID(sUNO_LayerName_background_objects);
aVisibleLayers.Set(aBckgrnd, bBVisible);
aVisibleLayers.Set(aBckgrndObj, bBObjsVisible);
pCurrentPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
}
else
{
pHandoutMPage->SetAutoLayout(aNewAutoLayout, true);
}
mrViewShell.GetViewFrame()->GetDispatcher()->Execute(SID_SWITCHPAGE,
SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
bool bSetModified = true;
if (pArgs->Count() == 1)
{
bSetModified = static_cast<const SfxBoolItem&>(pArgs->Get(SID_MODIFYPAGE)).GetValue();
}
pUndoManager->AddUndoAction( std::make_unique<UndoAutoLayoutPosAndSize>( *pUndoPage ) );
pUndoManager->LeaveListAction();
pDocument->SetChanged(bSetModified);
}
}
while (false);
mrViewShell.Cancel();
rRequest.Done ();
}
void ViewShell::Implementation::AssignLayout ( SfxRequest const & rRequest, PageKind ePageKind )
{
const SfxUInt32Item* pWhatPage = rRequest.GetArg<SfxUInt32Item>(ID_VAL_WHATPAGE);
const SfxUInt32Item* pWhatLayout = rRequest.GetArg<SfxUInt32Item>(ID_VAL_WHATLAYOUT);
SdDrawDocument* pDocument = mrViewShell.GetDoc();
if( !pDocument )
return;
SdPage* pPage = nullptr;
if( pWhatPage )
{
pPage = pDocument->GetSdPage(static_cast<sal_uInt16>(pWhatPage->GetValue()), ePageKind);
}
if( pPage == nullptr )
pPage = mrViewShell.getCurrentPage();
if( !pPage )
return;
AutoLayout eLayout = pPage->GetAutoLayout();
if( pWhatLayout )
eLayout = static_cast< AutoLayout >( pWhatLayout->GetValue() );
// Transform the given request into the four argument form that is
// understood by ProcessModifyPageSlot().
SdrLayerAdmin& rLayerAdmin (mrViewShell.GetViewShellBase().GetDocument()->GetLayerAdmin());
SdrLayerID aBackground (rLayerAdmin.GetLayerID(sUNO_LayerName_background));
SdrLayerID aBackgroundObject (rLayerAdmin.GetLayerID(sUNO_LayerName_background_objects));
SdrLayerIDSet aVisibleLayers;
if( pPage->GetPageKind() == PageKind::Handout )
aVisibleLayers.SetAll();
else
aVisibleLayers = pPage->TRG_GetMasterPageVisibleLayers();
SfxRequest aRequest (mrViewShell.GetViewShellBase().GetViewFrame(), SID_MODIFYPAGE);
aRequest.AppendItem(SfxStringItem (ID_VAL_PAGENAME, pPage->GetName()));
aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, eLayout));
aRequest.AppendItem(SfxBoolItem(ID_VAL_ISPAGEBACK, aVisibleLayers.IsSet(aBackground)));
aRequest.AppendItem(SfxBoolItem(ID_VAL_ISPAGEOBJ, aVisibleLayers.IsSet(aBackgroundObject)));
// Forward the call with the new arguments.
ProcessModifyPageSlot( aRequest, pPage, pPage->GetPageKind());
}
SfxInterfaceId ViewShell::Implementation::GetViewId() const
{
switch (mrViewShell.GetShellType())
{
case ViewShell::ST_IMPRESS:
case ViewShell::ST_NOTES:
case ViewShell::ST_HANDOUT:
return IMPRESS_FACTORY_ID;
case ViewShell::ST_DRAW:
return DRAW_FACTORY_ID;
case ViewShell::ST_OUTLINE:
return OUTLINE_FACTORY_ID;
case ViewShell::ST_SLIDE_SORTER:
return SLIDE_SORTER_FACTORY_ID;
case ViewShell::ST_PRESENTATION:
return PRESENTATION_FACTORY_ID;
// Since we have to return a view id for every possible shell type
// and there is not (yet) a proper ViewShellBase sub class for the
// remaining types we chose the Impress factory as a fall back.
case ViewShell::ST_SIDEBAR:
case ViewShell::ST_NONE:
default:
return IMPRESS_FACTORY_ID;
}
}
SvxIMapDlg* ViewShell::Implementation::GetImageMapDialog()
{
SfxViewFrame* pViewFrm = SfxViewFrame::Current();
if (!pViewFrm)
return nullptr;
SfxChildWindow* pChildWindow = pViewFrm->GetChildWindow(
SvxIMapDlgChildWindow::GetChildWindowId());
if (pChildWindow == nullptr)
return nullptr;
return dynamic_cast<SvxIMapDlg*>(pChildWindow->GetController().get());
}
//===== ToolBarManagerLock ====================================================
class ViewShell::Implementation::ToolBarManagerLock::Deleter { public:
void operator() (ToolBarManagerLock* pObject) { delete pObject; }
};
std::shared_ptr<ViewShell::Implementation::ToolBarManagerLock>
ViewShell::Implementation::ToolBarManagerLock::Create (
const std::shared_ptr<ToolBarManager>& rpManager)
{
std::shared_ptr<ToolBarManagerLock> pLock (
new ViewShell::Implementation::ToolBarManagerLock(rpManager),
ViewShell::Implementation::ToolBarManagerLock::Deleter());
pLock->mpSelf = pLock;
return pLock;
}
ViewShell::Implementation::ToolBarManagerLock::ToolBarManagerLock (
const std::shared_ptr<ToolBarManager>& rpManager)
: mpLock(new ToolBarManager::UpdateLock(rpManager)),
maTimer("sd ToolBarManagerLock maTimer")
{
// Start a timer that will unlock the ToolBarManager update lock when
// that is not done explicitly by calling Release().
maTimer.SetInvokeHandler(LINK(this,ToolBarManagerLock,TimeoutCallback));
maTimer.SetTimeout(100);
maTimer.Start();
}
IMPL_LINK_NOARG(ViewShell::Implementation::ToolBarManagerLock, TimeoutCallback, Timer *, void)
{
// If possible then release the lock now. Otherwise start the timer
// and try again later.
if (Application::IsUICaptured())
{
maTimer.Start();
}
else
{
mpSelf.reset();
}
}
void ViewShell::Implementation::ToolBarManagerLock::Release (bool bForce)
{
// If possible then release the lock now. Otherwise try again when the
// timer expires.
if (bForce || ! Application::IsUICaptured())
{
mpSelf.reset();
}
}
ViewShell::Implementation::ToolBarManagerLock::~ToolBarManagerLock()
{
mpLock.reset();
}
} // end of namespace sd
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|