LibreOffice Module sd (master) 1
RecentMasterPagesSelector.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
22#include <ViewShellBase.hxx>
25#include <sdpage.hxx>
26#include <drawdoc.hxx>
27#include <helpids.h>
28
29namespace sd::sidebar {
30
31std::unique_ptr<PanelLayout> RecentMasterPagesSelector::Create (
32 weld::Widget* pParent,
33 ViewShellBase& rViewShellBase,
34 const css::uno::Reference<css::ui::XSidebar>& rxSidebar)
35{
36 SdDrawDocument* pDocument = rViewShellBase.GetDocument();
37 if (pDocument == nullptr)
38 return nullptr;
39
40 auto pContainer = std::make_shared<MasterPageContainer>();
41
42 auto xSelector(std::make_unique<RecentMasterPagesSelector>(
43 pParent,
44 *pDocument,
45 rViewShellBase,
46 pContainer,
47 rxSidebar));
48 xSelector->LateInit();
49 xSelector->SetHelpId(HID_SD_TASK_PANE_PREVIEW_RECENT);
50
51 return xSelector;
52}
53
55 weld::Widget* pParent,
56 SdDrawDocument& rDocument,
57 ViewShellBase& rBase,
58 const std::shared_ptr<MasterPageContainer>& rpContainer,
59 const css::uno::Reference<css::ui::XSidebar>& rxSidebar)
60 : MasterPagesSelector (pParent, rDocument, rBase, rpContainer, rxSidebar, "modules/simpress/ui/masterpagepanelrecent.ui", "recentvalueset")
61{
62}
63
65{
67 LINK(this,RecentMasterPagesSelector,MasterPageListListener));
68}
69
71{
73
76 LINK(this,RecentMasterPagesSelector,MasterPageListListener));
77}
78
80{
82}
83
85{
86 // Create a set of names of the master pages used by the document.
88 sal_uInt16 nMasterPageCount = mrDocument.GetMasterSdPageCount(PageKind::Standard);
89 for (sal_uInt16 nIndex=0; nIndex<nMasterPageCount; nIndex++)
90 {
92 if (pMasterPage != nullptr)
93 aCurrentNames.insert (pMasterPage->GetName());
94 }
95
96 // Insert the recently used master pages that are currently not used.
98 int nPageCount = rInstance.GetMasterPageCount();
99 for (int nIndex=0; nIndex<nPageCount; nIndex++)
100 {
101 // Add an entry when a) the page is already known to the
102 // MasterPageContainer, b) the style name is empty, i.e. it has not yet
103 // been loaded (and thus can not be in use) or otherwise c) the
104 // style name is not currently in use.
106 if (aToken != MasterPageContainer::NIL_TOKEN)
107 {
108 OUString sStyleName (mpContainer->GetStyleNameForToken(aToken));
109 if (sStyleName.isEmpty()
110 || aCurrentNames.find(sStyleName) == aCurrentNames.end())
111 {
112 rItemList.push_back(aToken);
113 }
114 }
115 }
116}
117
119 SdPage* pMasterPage,
120 const std::shared_ptr<std::vector<SdPage*> >& rpPageList)
121{
122 sal_uInt16 nSelectedItemId = mxPreviewValueSet->GetSelectedItemId();
123
125
126 // Restore the selection.
127 if (mxPreviewValueSet->GetItemCount() > 0)
128 {
129 if (mxPreviewValueSet->GetItemCount() >= nSelectedItemId)
130 mxPreviewValueSet->SelectItem(nSelectedItemId);
131 else
132 mxPreviewValueSet->SelectItem(mxPreviewValueSet->GetItemCount());
133 }
134}
135
136} // end of namespace sd::sidebar
137
138/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 GetMasterSdPageCount(PageKind ePgKind) const
Definition: drawdoc2.cxx:222
SdPage * GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind)
Definition: drawdoc2.cxx:217
const OUString & GetName() const
Definition: sdpage.cxx:2505
::std::set< OUString > MasterPageNameSet
SfxViewShell descendant that the stacked Draw/Impress shells are based on.
SdDrawDocument * GetDocument() const
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 AssignMasterPageToPageList(SdPage *pMasterPage, const std::shared_ptr< std::vector< SdPage * > > &rPageList)
std::shared_ptr< MasterPageContainer > mpContainer
::std::vector< MasterPageContainer::Token > ItemList
Show the recently used master pages (that are not currently used).
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, ViewShellBase &rViewShellBase, const css::uno::Reference< css::ui::XSidebar > &rxSidebar)
RecentMasterPagesSelector(weld::Widget *pParent, SdDrawDocument &rDocument, ViewShellBase &rBase, const std::shared_ptr< MasterPageContainer > &rpContainer, const css::uno::Reference< css::ui::XSidebar > &rxSidebar)
virtual void AssignMasterPageToPageList(SdPage *pMasterPage, const std::shared_ptr< std::vector< SdPage * > > &rpPageList) override
Forward this call to the base class but save and restore the currently selected item.
This singleton holds a list of the most recently used master pages.
void RemoveEventListener(const Link< LinkParamNone *, void > &rEventListener)
static RecentlyUsedMasterPages & Instance()
Return the single instance of this class.
void AddEventListener(const Link< LinkParamNone *, void > &rEventListener)
MasterPageContainer::Token GetTokenForIndex(sal_uInt32 nIndex) const
constexpr OUStringLiteral HID_SD_TASK_PANE_PREVIEW_RECENT
Definition: helpids.h:45
sal_Int32 nIndex
IMPL_LINK_NOARG(LayoutMenu, ClickHandler, ValueSet *, void)
Definition: LayoutMenu.cxx:369