bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / sidebar / RecentMasterPagesSelector.cxx
blob0cfbdb0ce0aff31d72955bfa44026422e8445cf2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "RecentMasterPagesSelector.hxx"
22 #include <ViewShellBase.hxx>
23 #include "RecentlyUsedMasterPages.hxx"
24 #include "MasterPageContainerProviders.hxx"
25 #include <MasterPageObserver.hxx>
26 #include <sdpage.hxx>
27 #include <drawdoc.hxx>
28 #include <app.hrc>
29 #include <helpids.h>
31 #include <vcl/bitmap.hxx>
33 namespace sd { namespace sidebar {
35 VclPtr<vcl::Window> RecentMasterPagesSelector::Create (
36 vcl::Window* pParent,
37 ViewShellBase& rViewShellBase,
38 const css::uno::Reference<css::ui::XSidebar>& rxSidebar)
40 SdDrawDocument* pDocument = rViewShellBase.GetDocument();
41 if (pDocument == nullptr)
42 return nullptr;
44 std::shared_ptr<MasterPageContainer> pContainer (new MasterPageContainer());
46 VclPtrInstance<RecentMasterPagesSelector> pSelector(
47 pParent,
48 *pDocument,
49 rViewShellBase,
50 pContainer,
51 rxSidebar);
52 pSelector->LateInit();
53 pSelector->SetHelpId(HID_SD_TASK_PANE_PREVIEW_RECENT);
55 return pSelector;
58 RecentMasterPagesSelector::RecentMasterPagesSelector (
59 vcl::Window* pParent,
60 SdDrawDocument& rDocument,
61 ViewShellBase& rBase,
62 const std::shared_ptr<MasterPageContainer>& rpContainer,
63 const css::uno::Reference<css::ui::XSidebar>& rxSidebar)
64 : MasterPagesSelector (pParent, rDocument, rBase, rpContainer, rxSidebar)
68 RecentMasterPagesSelector::~RecentMasterPagesSelector()
70 disposeOnce();
73 void RecentMasterPagesSelector::dispose()
75 RecentlyUsedMasterPages::Instance().RemoveEventListener (
76 LINK(this,RecentMasterPagesSelector,MasterPageListListener));
77 MasterPagesSelector::dispose();
80 void RecentMasterPagesSelector::LateInit()
82 MasterPagesSelector::LateInit();
84 MasterPagesSelector::Fill();
85 RecentlyUsedMasterPages::Instance().AddEventListener (
86 LINK(this,RecentMasterPagesSelector,MasterPageListListener));
89 IMPL_LINK_NOARG(RecentMasterPagesSelector, MasterPageListListener, LinkParamNone*, void)
91 MasterPagesSelector::Fill();
94 void RecentMasterPagesSelector::Fill (ItemList& rItemList)
96 // Create a set of names of the master pages used by the document.
97 MasterPageObserver::MasterPageNameSet aCurrentNames;
98 sal_uInt16 nMasterPageCount = mrDocument.GetMasterSdPageCount(PageKind::Standard);
99 for (sal_uInt16 nIndex=0; nIndex<nMasterPageCount; nIndex++)
101 SdPage* pMasterPage = mrDocument.GetMasterSdPage (nIndex, PageKind::Standard);
102 if (pMasterPage != nullptr)
103 aCurrentNames.insert (pMasterPage->GetName());
106 // Insert the recently used master pages that are currently not used.
107 RecentlyUsedMasterPages& rInstance (RecentlyUsedMasterPages::Instance());
108 int nPageCount = rInstance.GetMasterPageCount();
109 for (int nIndex=0; nIndex<nPageCount; nIndex++)
111 // Add an entry when a) the page is already known to the
112 // MasterPageContainer, b) the style name is empty, i.e. it has not yet
113 // been loaded (and thus can not be in use) or otherwise c) the
114 // style name is not currently in use.
115 MasterPageContainer::Token aToken (rInstance.GetTokenForIndex(nIndex));
116 if (aToken != MasterPageContainer::NIL_TOKEN)
118 OUString sStyleName (mpContainer->GetStyleNameForToken(aToken));
119 if (sStyleName.isEmpty()
120 || aCurrentNames.find(sStyleName) == aCurrentNames.end())
122 rItemList.push_back(aToken);
128 void RecentMasterPagesSelector::AssignMasterPageToPageList (
129 SdPage* pMasterPage,
130 const std::shared_ptr<std::vector<SdPage*> >& rpPageList)
132 sal_uInt16 nSelectedItemId = PreviewValueSet::GetSelectedItemId();
134 MasterPagesSelector::AssignMasterPageToPageList(pMasterPage, rpPageList);
136 // Restore the selection.
137 if (PreviewValueSet::GetItemCount() > 0)
139 if (PreviewValueSet::GetItemCount() >= nSelectedItemId)
140 PreviewValueSet::SelectItem(nSelectedItemId);
141 else
142 PreviewValueSet::SelectItem(PreviewValueSet::GetItemCount());
146 void RecentMasterPagesSelector::ProcessPopupMenu (Menu& rMenu)
148 sal_uInt16 nItemid = rMenu.GetItemId("edit");
149 if (rMenu.GetItemPos(nItemid) != MENU_ITEM_NOTFOUND)
150 rMenu.EnableItem(nItemid, false);
153 } } // end of namespace sd::sidebar
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */