LibreOffice Module sd (master) 1
ViewShellImplementation.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 <config_features.h>
21
23
24#include <sdpage.hxx>
25#include <drawdoc.hxx>
26#include <sdresid.hxx>
27#include <unokywds.hxx>
28#include <strings.hrc>
29#include <app.hrc>
30#include <unmodpg.hxx>
31#include <DrawDocShell.hxx>
32#include <FactoryIds.hxx>
33#include <ViewShellBase.hxx>
34
35#include <sfx2/bindings.hxx>
36#include <sfx2/dispatch.hxx>
37#include <sfx2/request.hxx>
38#include <sfx2/sfxsids.hrc>
39#include <sfx2/viewfrm.hxx>
41#include <svl/intitem.hxx>
42#include <svl/stritem.hxx>
43#include <svx/imapdlg.hxx>
44#include <basic/sbstar.hxx>
45#include <basic/sberrors.hxx>
46#include <xmloff/autolayout.hxx>
47#include <vcl/svapp.hxx>
48
49#include <undo/undoobjects.hxx>
50
51#include <com/sun/star/drawing/framework/XControllerManager.hpp>
52
53using namespace ::com::sun::star::uno;
55
56namespace sd {
57
59 : mbIsMainViewShell(false),
60 mbIsInitialized(false),
61 mbArrangeActive(false),
62 mrViewShell(rViewShell)
63{
64}
65
67{
68 if ( ! mpUpdateLockForMouse.expired())
69 {
70 std::shared_ptr<ToolBarManagerLock> pLock(mpUpdateLockForMouse);
71 if (pLock != nullptr)
72 {
73 // Force the ToolBarManagerLock to be released even when the
74 // IsUICaptured() returns <TRUE/>.
75 pLock->Release(true);
76 }
77 }
78}
79
81 SfxRequest& rRequest,
82 SdPage* pCurrentPage,
83 PageKind ePageKind)
84{
85 SdDrawDocument* pDocument = mrViewShell.GetDoc();
86 SdrLayerAdmin& rLayerAdmin = pDocument->GetLayerAdmin();
87 SdrLayerIDSet aVisibleLayers;
88 bool bHandoutMode = false;
89 SdPage* pHandoutMPage = nullptr;
90 OUString aNewName;
91
92 AutoLayout aNewAutoLayout;
93
94 bool bBVisible;
95 bool bBObjsVisible;
96 const SfxItemSet* pArgs = rRequest.GetArgs();
97
98 if (pCurrentPage != nullptr && pCurrentPage->TRG_HasMasterPage())
99 aVisibleLayers = pCurrentPage->TRG_GetMasterPageVisibleLayers();
100 else
101 aVisibleLayers.SetAll();
102
103 do
104 {
105 if (pCurrentPage == nullptr)
106 break;
107
108 if (!pArgs || pArgs->Count() == 1 || pArgs->Count() == 2 )
109 {
110 // First make sure that the sidebar is visible
113 mrViewShell.GetViewFrame()->ShowChildWindow(SID_SIDEBAR);
115 u"SdLayoutsPanel",
116 mrViewShell.GetViewFrame()->GetFrame().GetFrameInterface());
117 break;
118 }
119 else if (pArgs->Count() == 4)
120 {
121 const SfxStringItem* pNewName = rRequest.GetArg<SfxStringItem>(ID_VAL_PAGENAME);
122 const SfxUInt32Item* pNewAutoLayout = rRequest.GetArg<SfxUInt32Item>(ID_VAL_WHATLAYOUT);
123 const SfxBoolItem* pBVisible = rRequest.GetArg<SfxBoolItem>(ID_VAL_ISPAGEBACK);
124 const SfxBoolItem* pBObjsVisible = rRequest.GetArg<SfxBoolItem>(ID_VAL_ISPAGEOBJ);
125 assert(pNewName && pNewAutoLayout && pBVisible && pBObjsVisible && "must be present");
126 AutoLayout aLayout (static_cast<AutoLayout>(pNewAutoLayout->GetValue ()));
127 if (aLayout >= AUTOLAYOUT_START
128 && aLayout < AUTOLAYOUT_END)
129 {
130 aNewName = pNewName->GetValue ();
131 aNewAutoLayout = static_cast<AutoLayout>(pNewAutoLayout->GetValue ());
132 bBVisible = pBVisible->GetValue ();
133 bBObjsVisible = pBObjsVisible->GetValue ();
134 }
135 else
136 {
137#if HAVE_FEATURE_SCRIPTING
139#endif
140 rRequest.Ignore ();
141 break;
142 }
143 if (ePageKind == PageKind::Handout)
144 {
145 bHandoutMode = true;
146 pHandoutMPage = pDocument->GetMasterSdPage(0, PageKind::Handout);
147 }
148 }
149 else
150 {
151#if HAVE_FEATURE_SCRIPTING
153#endif
154 rRequest.Ignore ();
155 break;
156 }
157
158 SdPage* pUndoPage =
159 bHandoutMode ? pHandoutMPage : pCurrentPage;
160
161 SfxUndoManager* pUndoManager = mrViewShell.GetDocSh()->GetUndoManager();
162 DBG_ASSERT(pUndoManager, "No UNDO MANAGER ?!?");
163
164 if( pUndoManager )
165 {
166 OUString aComment( SdResId(STR_UNDO_MODIFY_PAGE) );
167 pUndoManager->EnterListAction(aComment, aComment, 0, mrViewShell.GetViewShellBase().GetViewShellId());
168 pUndoManager->AddUndoAction(
169 std::make_unique<ModifyPageUndoAction>(
170 pDocument, pUndoPage, aNewName, aNewAutoLayout, bBVisible, bBObjsVisible));
171
172 // Clear the selection because the selected object may be removed as
173 // a result of the assignment of the layout.
175
176 if (!bHandoutMode)
177 {
178 if (pCurrentPage->GetName() != aNewName)
179 {
180 pCurrentPage->SetName(aNewName);
181
182 if (ePageKind == PageKind::Standard)
183 {
184 sal_uInt16 nPage = (pCurrentPage->GetPageNum()-1) / 2;
185 SdPage* pNotesPage = pDocument->GetSdPage(nPage, PageKind::Notes);
186 if (pNotesPage != nullptr)
187 pNotesPage->SetName(aNewName);
188 }
189 }
190
191 pCurrentPage->SetAutoLayout(aNewAutoLayout, true);
192
193 SdrLayerID aBckgrnd = rLayerAdmin.GetLayerID(sUNO_LayerName_background);
195 aVisibleLayers.Set(aBckgrnd, bBVisible);
196 aVisibleLayers.Set(aBckgrndObj, bBObjsVisible);
197 pCurrentPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
198 }
199 else
200 {
201 pHandoutMPage->SetAutoLayout(aNewAutoLayout, true);
202 }
203
204 mrViewShell.GetViewFrame()->GetDispatcher()->Execute(SID_SWITCHPAGE,
205 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
206
207 bool bSetModified = true;
208
209 if (pArgs->Count() == 1)
210 {
211 bSetModified = static_cast<const SfxBoolItem&>(pArgs->Get(SID_MODIFYPAGE)).GetValue();
212 }
213
214 pUndoManager->AddUndoAction( std::make_unique<UndoAutoLayoutPosAndSize>( *pUndoPage ) );
215 pUndoManager->LeaveListAction();
216
217 pDocument->SetChanged(bSetModified);
218 }
219 }
220 while (false);
221
222 mrViewShell.Cancel();
223 rRequest.Done ();
224}
225
227{
228 const SfxUInt32Item* pWhatPage = rRequest.GetArg<SfxUInt32Item>(ID_VAL_WHATPAGE);
229 const SfxUInt32Item* pWhatLayout = rRequest.GetArg<SfxUInt32Item>(ID_VAL_WHATLAYOUT);
230
231 SdDrawDocument* pDocument = mrViewShell.GetDoc();
232 if( !pDocument )
233 return;
234
235 SdPage* pPage = nullptr;
236 if( pWhatPage )
237 {
238 pPage = pDocument->GetSdPage(static_cast<sal_uInt16>(pWhatPage->GetValue()), ePageKind);
239 }
240
241 if( pPage == nullptr )
242 pPage = mrViewShell.getCurrentPage();
243
244 if( !pPage )
245 return;
246
247 AutoLayout eLayout = pPage->GetAutoLayout();
248
249 if( pWhatLayout )
250 eLayout = static_cast< AutoLayout >( pWhatLayout->GetValue() );
251
252 // Transform the given request into the four argument form that is
253 // understood by ProcessModifyPageSlot().
254 SdrLayerAdmin& rLayerAdmin (mrViewShell.GetViewShellBase().GetDocument()->GetLayerAdmin());
255 SdrLayerID aBackground (rLayerAdmin.GetLayerID(sUNO_LayerName_background));
256 SdrLayerID aBackgroundObject (rLayerAdmin.GetLayerID(sUNO_LayerName_background_objects));
257
258 SdrLayerIDSet aVisibleLayers;
259
260 if( pPage->GetPageKind() == PageKind::Handout )
261 aVisibleLayers.SetAll();
262 else
263 aVisibleLayers = pPage->TRG_GetMasterPageVisibleLayers();
264
265 SfxRequest aRequest(mrViewShell.GetViewShellBase().GetViewFrame(), SID_MODIFYPAGE);
266 aRequest.AppendItem(SfxStringItem (ID_VAL_PAGENAME, pPage->GetName()));
267 aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, eLayout));
268 aRequest.AppendItem(SfxBoolItem(ID_VAL_ISPAGEBACK, aVisibleLayers.IsSet(aBackground)));
269 aRequest.AppendItem(SfxBoolItem(ID_VAL_ISPAGEOBJ, aVisibleLayers.IsSet(aBackgroundObject)));
270
271 // Forward the call with the new arguments.
272 ProcessModifyPageSlot( aRequest, pPage, pPage->GetPageKind());
273}
274
276{
277 switch (mrViewShell.GetShellType())
278 {
282 return IMPRESS_FACTORY_ID;
283
285 return DRAW_FACTORY_ID;
286
288 return OUTLINE_FACTORY_ID;
289
292
295
296 // Since we have to return a view id for every possible shell type
297 // and there is not (yet) a proper ViewShellBase sub class for the
298 // remaining types we chose the Impress factory as a fall back.
301 default:
302 return IMPRESS_FACTORY_ID;
303 }
304}
305
307{
309 if (!pViewFrm)
310 return nullptr;
311
312 SfxChildWindow* pChildWindow = pViewFrm->GetChildWindow(
313 SvxIMapDlgChildWindow::GetChildWindowId());
314 if (pChildWindow == nullptr)
315 return nullptr;
316
317 return dynamic_cast<SvxIMapDlg*>(pChildWindow->GetController().get());
318}
319
320//===== ToolBarManagerLock ====================================================
321
323 void operator() (ToolBarManagerLock* pObject) { delete pObject; }
324};
325
326std::shared_ptr<ViewShell::Implementation::ToolBarManagerLock>
328 const std::shared_ptr<ToolBarManager>& rpManager)
329{
330 std::shared_ptr<ToolBarManagerLock> pLock (
333 pLock->mpSelf = pLock;
334 return pLock;
335}
336
338 const std::shared_ptr<ToolBarManager>& rpManager)
339 : mpLock(new ToolBarManager::UpdateLock(rpManager)),
340 maTimer("sd ToolBarManagerLock maTimer")
341{
342 // Start a timer that will unlock the ToolBarManager update lock when
343 // that is not done explicitly by calling Release().
344 maTimer.SetInvokeHandler(LINK(this,ToolBarManagerLock,TimeoutCallback));
345 maTimer.SetTimeout(100);
346 maTimer.Start();
347}
348
350{
351 // If possible then release the lock now. Otherwise start the timer
352 // and try again later.
354 {
355 maTimer.Start();
356 }
357 else
358 {
359 mpSelf.reset();
360 }
361}
362
364{
365 // If possible then release the lock now. Otherwise try again when the
366 // timer expires.
367 if (bForce || ! Application::IsUICaptured())
368 {
369 mpSelf.reset();
370 }
371}
372
374{
375 mpLock.reset();
376}
377
378} // end of namespace sd
379
380/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwViewShell & mrViewShell
AutoLayout
AUTOLAYOUT_START
AUTOLAYOUT_END
static bool IsUICaptured()
sal_uInt32 GetValue() const
const OUString & GetValue() const
SdPage * GetSdPage(sal_uInt16 nPgNum, PageKind ePgKind) const
Definition: drawdoc2.cxx:207
SdPage * GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind)
Definition: drawdoc2.cxx:217
virtual SAL_DLLPRIVATE void SetChanged(bool bFlag=true) override
Definition: drawdoc.cxx:658
PageKind GetPageKind() const
Definition: sdpage.hxx:205
void SetAutoLayout(AutoLayout eLayout, bool bInit=false, bool bCreate=false)
Definition: sdpage.cxx:1610
const OUString & GetName() const
Definition: sdpage.cxx:2505
void SetName(const OUString &rName)
Set the name of the page and broadcast a model change.
Definition: sdpage.cxx:2703
AutoLayout GetAutoLayout() const
Definition: sdpage.hxx:190
SdrLayerID GetLayerID(const OUString &rName) const
void Set(SdrLayerID a)
bool IsSet(SdrLayerID a) const
const SdrLayerAdmin & GetLayerAdmin() const
virtual SdrEndTextEditKind SdrEndTextEdit(bool bDontDeleteReally=false)
sal_uInt16 GetPageNum() const
void TRG_SetMasterPageVisibleLayers(const SdrLayerIDSet &rNew)
bool TRG_HasMasterPage() const
const SdrLayerIDSet & TRG_GetMasterPageVisibleLayers() const
void UnmarkAll()
std::shared_ptr< SfxDialogController > & GetController()
sal_uInt16 Count() const
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
void Ignore()
const SfxItemSet * GetArgs() const
const T * GetArg(sal_uInt16 nSlotId) const
void AppendItem(const SfxPoolItem &)
void Done(bool bRemove=false)
size_t LeaveListAction()
virtual void EnterListAction(const OUString &rComment, const OUString &rRepeatComment, sal_uInt16 nId, ViewShellId nViewShellId)
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
static SAL_WARN_UNUSED_RESULT SfxViewFrame * Current()
SfxChildWindow * GetChildWindow(sal_uInt16)
static void FatalError(ErrCode)
SwDoc * GetDoc() const
SdrView * GetDrawView()
void SetTimeout(sal_uInt64 nTimeoutMs)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
virtual void Start(bool bStartTimer=true) override
Manage the set of visible tool bars (and object bars).
This update lock for the ToolBarManager exists in order to avoid problems with tool bars being displa...
static std::shared_ptr< ToolBarManagerLock > Create(const std::shared_ptr< ToolBarManager > &rpManager)
Create a new instance.
Timer maTimer
The timer is used both as a safe guard to unlock the update lock when Release() is not called explici...
void Release(bool bForce=false)
Release the lock.
ToolBarManagerLock(const std::shared_ptr< sd::ToolBarManager > &rpManager)
SfxInterfaceId GetViewId() const
Determine the view id of the view shell.
void AssignLayout(SfxRequest const &rRequest, PageKind ePageKind)
Assign the given layout to the given page.
void ProcessModifyPageSlot(SfxRequest &rRequest, SdPage *pCurrentPage, PageKind ePageKind)
Process the SID_MODIFY slot.
static SvxIMapDlg * GetImageMapDialog()
Return a pointer to the image map dialog that is displayed in some child window.
~Implementation() COVERITY_NOEXCEPT_FALSE
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
static void TogglePanel(std::u16string_view rsPanelId, const css::uno::Reference< css::frame::XFrame > &rxFrame)
#define DBG_ASSERT(sCon, aError)
float u
EmbeddedObjectRef * pObject
IMPL_LINK_NOARG(MainSequence, onTimerHdl, Timer *, void)
constexpr auto SLIDE_SORTER_FACTORY_ID
Definition: FactoryIds.hxx:34
constexpr auto DRAW_FACTORY_ID
Definition: FactoryIds.hxx:33
constexpr auto OUTLINE_FACTORY_ID
Definition: FactoryIds.hxx:35
constexpr auto IMPRESS_FACTORY_ID
This are ids used by SfxTopFrame::Create() or CreateViewFrame() to select a factory to create an inst...
Definition: FactoryIds.hxx:32
constexpr auto PRESENTATION_FACTORY_ID
Definition: FactoryIds.hxx:36
const char GetValue[]
PageKind
Definition: pres.hxx:45
#define ERRCODE_BASIC_BAD_PROP_VALUE
#define ERRCODE_BASIC_WRONG_ARGS
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
constexpr OUStringLiteral sUNO_LayerName_background_objects
Definition: unokywds.hxx:30
constexpr OUStringLiteral sUNO_LayerName_background
Definition: unokywds.hxx:29