LibreOffice Module sd (master) 1
CurrentMasterPagesSelector.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
21#include "PreviewValueSet.hxx"
22#include <ViewShellBase.hxx>
23#include <DrawViewShell.hxx>
24#include <drawdoc.hxx>
25#include <sdpage.hxx>
29#include <EventMultiplexer.hxx>
30#include <DrawDocShell.hxx>
31#include <osl/diagnose.h>
32
33#include <helpids.h>
34
35#include <set>
36
37using namespace ::com::sun::star;
38
39namespace sd::sidebar {
40
41std::unique_ptr<PanelLayout> CurrentMasterPagesSelector::Create (
42 weld::Widget* pParent,
43 ViewShellBase& rViewShellBase,
44 const css::uno::Reference<css::ui::XSidebar>& rxSidebar)
45{
46 SdDrawDocument* pDocument = rViewShellBase.GetDocument();
47 if (pDocument == nullptr)
48 return nullptr;
49
50 auto pContainer = std::make_shared<MasterPageContainer>();
51
52 auto xSelector(std::make_unique<CurrentMasterPagesSelector>(
53 pParent,
54 *pDocument,
55 rViewShellBase,
56 pContainer,
57 rxSidebar));
58 xSelector->LateInit();
59 xSelector->SetHelpId( HID_SD_TASK_PANE_PREVIEW_CURRENT );
60
61 return xSelector;
62}
63
65 weld::Widget* pParent,
66 SdDrawDocument& rDocument,
67 ViewShellBase& rBase,
68 const std::shared_ptr<MasterPageContainer>& rpContainer,
69 const css::uno::Reference<css::ui::XSidebar>& rxSidebar)
70 : MasterPagesSelector (pParent, rDocument, rBase, rpContainer, rxSidebar, "modules/simpress/ui/masterpagepanel.ui", "usedvalueset")
71{
73 rBase.GetEventMultiplexer()->AddEventListener(aLink);
74}
75
77{
78 if (mrDocument.GetDocSh() != nullptr)
79 {
81 }
82 else
83 {
84 OSL_ASSERT(mrDocument.GetDocSh() != nullptr);
85 }
86
88 mrBase.GetEventMultiplexer()->RemoveEventListener(aLink);
89}
90
92{
95 if (mrDocument.GetDocSh() != nullptr)
96 {
98 }
99 else
100 {
101 OSL_ASSERT(mrDocument.GetDocSh() != nullptr);
102 }
103}
104
106{
107 sal_uInt16 nPageCount = mrDocument.GetMasterSdPageCount(PageKind::Standard);
108 // Remember the names of the master pages that have been inserted to
109 // avoid double insertion.
110 ::std::set<OUString> aMasterPageNames;
111 for (sal_uInt16 nIndex=0; nIndex<nPageCount; nIndex++)
112 {
114 if (pMasterPage == nullptr)
115 continue;
116
117 // Use the name of the master page to avoid duplicate entries.
118 OUString sName (pMasterPage->GetName());
119 if (!aMasterPageNames.insert(sName).second)
120 continue;
121
122 // Look up the master page in the container and, when it is not yet
123 // in it, insert it.
124 MasterPageContainer::Token aToken = mpContainer->GetTokenForPageObject(pMasterPage);
125 if (aToken == MasterPageContainer::NIL_TOKEN)
126 {
127 SharedMasterPageDescriptor pDescriptor = std::make_shared<MasterPageDescriptor>(
129 nIndex,
130 OUString(),
131 pMasterPage->GetName(),
132 OUString(),
133 pMasterPage->IsPrecious(),
134 std::make_shared<ExistingPageProvider>(pMasterPage),
135 std::make_shared<PagePreviewProvider>());
136 aToken = mpContainer->PutMasterPage(pDescriptor);
137 }
138
139 rItemList.push_back(aToken);
140 }
141}
142
144{
145 return "modules/simpress/ui/currentmastermenu.ui";
146}
147
149{
150 // Iterate over all pages and for the selected ones put the name of
151 // their master page into a set.
152 sal_uInt16 nPageCount = mrDocument.GetSdPageCount(PageKind::Standard);
153 ::std::set<OUString> aNames;
154 sal_uInt16 nIndex;
155 bool bLoop (true);
156 for (nIndex=0; nIndex<nPageCount && bLoop; nIndex++)
157 {
159 if (pPage != nullptr && pPage->IsSelected())
160 {
161 if ( ! pPage->TRG_HasMasterPage())
162 {
163 // One of the pages has no master page. This is an
164 // indicator for that this method is called in the middle of
165 // a document change and that the model is not in a valid
166 // state. Therefore we stop update the selection and wait
167 // for another call to UpdateSelection when the model is
168 // valid again.
169 bLoop = false;
170 }
171 else
172 {
173 SdrPage& rMasterPage (pPage->TRG_GetMasterPage());
174 assert(dynamic_cast<SdPage*>(&rMasterPage));
175 aNames.insert(static_cast<SdPage&>(rMasterPage).GetName());
176 }
177 }
178 }
179
180 // Find the items for the master pages in the set.
181 sal_uInt16 nItemCount (mxPreviewValueSet->GetItemCount());
182 for (nIndex=1; nIndex<=nItemCount && bLoop; nIndex++)
183 {
184 OUString sName (mxPreviewValueSet->GetItemText (nIndex));
185 if (aNames.find(sName) != aNames.end())
186 {
187 mxPreviewValueSet->SelectItem (nIndex);
188 }
189 }
190}
191
193{
194 if (rIdent == "delete")
195 {
196 // Check once again that the master page can safely be deleted,
197 // i.e. is not used.
198 SdPage* pMasterPage = GetSelectedMasterPage();
199 if (pMasterPage != nullptr
200 && mrDocument.GetMasterPageUserCount(pMasterPage) == 0)
201 {
202 // Removing the precious flag so that the following call to
203 // RemoveUnnecessaryMasterPages() will remove this master page.
204 pMasterPage->SetPrecious(false);
206 }
207 }
208 else
210}
211
213{
214 // Disable the delete entry when there is only one master page.
216 rMenu.set_sensitive("delete", false);
217
218 std::shared_ptr<DrawViewShell> pDrawViewShell (
219 std::dynamic_pointer_cast<DrawViewShell>(mrBase.GetMainViewShell()));
220 if (pDrawViewShell && pDrawViewShell->GetEditMode() == EditMode::MasterPage)
221 {
222 rMenu.set_sensitive("edit", false);
223 }
224
226}
227
228IMPL_LINK(CurrentMasterPagesSelector,EventMultiplexerListener,
230{
231 switch (rEvent.meEventId)
232 {
237 UpdateSelection();
238 break;
239
241 // This is tricky. If a master page is removed, moved, or
242 // added we have to wait until both the notes master page
243 // and the standard master page have been removed, moved,
244 // or added. We do this by looking at the number of master
245 // pages which has to be odd in the consistent state (the
246 // handout master page is always present). If the number is
247 // even we ignore the hint.
248 if (mrBase.GetDocument()->GetMasterPageCount()%2 == 1)
250 break;
251
255 InvalidatePreview(static_cast<const SdPage*>(rEvent.mpUserData));
256 break;
257 default: break;
258 }
259}
260
261} // end of namespace sd::sidebar
262
263/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ ShapeRemoved
A shape has been removed from a page.
@ PageOrder
One or more pages have been inserted into or deleted from the model.
@ EditModeNormal
Edit mode was (or is being) switched to normal mode.
@ SlideSortedSelection
The selection in the slide sorter has changed, regardless of whether the slide sorter is displayed in...
@ EditModeMaster
Edit mode was (or is being) switched to master mode.
@ ShapeChanged
The state of a shape has changed.
@ CurrentPageChanged
The current page has changed.
@ ShapeInserted
A shape has been inserted to a page.
sal_uInt16 GetMasterSdPageCount(PageKind ePgKind) const
Definition: drawdoc2.cxx:222
SAL_DLLPRIVATE sal_uInt16 GetMasterPageUserCount(SdrPage const *pMaster) const
Definition: drawdoc4.cxx:694
SdPage * GetSdPage(sal_uInt16 nPgNum, PageKind ePgKind) const
Definition: drawdoc2.cxx:207
SdPage * GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind)
Definition: drawdoc2.cxx:217
SAL_DLLPRIVATE void RemoveUnnecessaryMasterPages(SdPage *pMaster=nullptr, bool bOnlyDuplicatePages=false, bool bUndo=true)
Definition: drawdoc3.cxx:1172
SAL_DLLPRIVATE::sd::DrawDocShell * GetDocSh() const
Definition: drawdoc.hxx:242
sal_uInt16 GetSdPageCount(PageKind ePgKind) const
Definition: drawdoc2.cxx:212
bool IsPrecious() const
The "precious" flag is used for master pages to prevent some unused master pages from being deleted a...
Definition: sdpage.hxx:368
bool IsSelected() const
Definition: sdpage.hxx:208
const OUString & GetName() const
Definition: sdpage.cxx:2505
void SetPrecious(const bool bIsPrecious)
Set the "precious" flag to the given value.
Definition: sdpage.cxx:3112
SdrPage & TRG_GetMasterPage() const
bool TRG_HasMasterPage() const
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
SfxViewShell descendant that the stacked Draw/Impress shells are based on.
std::shared_ptr< ViewShell > GetMainViewShell() const
Return the main view shell stacked on the called ViewShellBase object.
std::shared_ptr< tools::EventMultiplexer > const & GetEventMultiplexer() const
Return an event multiplexer.
SdDrawDocument * GetDocument() const
Show the master pages currently used by a SdDrawDocument.
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, ViewShellBase &rViewShellBase, const css::uno::Reference< css::ui::XSidebar > &rxSidebar)
virtual OUString GetContextMenuUIFile() const override
Give derived classes the opportunity to provide their own context menu.
virtual void ProcessPopupMenu(weld::Menu &rMenu) override
CurrentMasterPagesSelector(weld::Widget *pParent, SdDrawDocument &rDocument, ViewShellBase &rBase, const std::shared_ptr< MasterPageContainer > &rpContainer, const css::uno::Reference< css::ui::XSidebar > &rxSidebar)
virtual void ExecuteCommand(const OUString &rIdent) override
void UpdateSelection()
Set the selection so that the master page is selected that is used by the currently selected page of ...
Base class of a menu that lets the user select from a list of templates or designs that are loaded fr...
std::unique_ptr< PreviewValueSet > mxPreviewValueSet
virtual void ExecuteCommand(const OUString &rIdent)
virtual void ProcessPopupMenu(weld::Menu &rMenu)
std::shared_ptr< MasterPageContainer > mpContainer
::std::vector< MasterPageContainer::Token > ItemList
virtual void set_sensitive(const OUString &rIdent, bool bSensitive)=0
virtual OUString GetName() const override
OUString sName
constexpr OUStringLiteral HID_SD_TASK_PANE_PREVIEW_CURRENT
Definition: helpids.h:44
sal_Int32 nIndex
std::shared_ptr< MasterPageDescriptor > SharedMasterPageDescriptor
IMPL_LINK(CurrentMasterPagesSelector, EventMultiplexerListener, sd::tools::EventMultiplexerEvent &, rEvent, void)