1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <MasterPageObserver.hxx>
26 #include <drawdoc.hxx>
29 namespace sd::sidebar
{
31 std::unique_ptr
<PanelLayout
> RecentMasterPagesSelector::Create (
32 weld::Widget
* pParent
,
33 ViewShellBase
& rViewShellBase
,
34 const css::uno::Reference
<css::ui::XSidebar
>& rxSidebar
)
36 SdDrawDocument
* pDocument
= rViewShellBase
.GetDocument();
37 if (pDocument
== nullptr)
40 auto pContainer
= std::make_shared
<MasterPageContainer
>();
42 auto xSelector(std::make_unique
<RecentMasterPagesSelector
>(
48 xSelector
->LateInit();
49 xSelector
->SetHelpId(HID_SD_TASK_PANE_PREVIEW_RECENT
);
54 RecentMasterPagesSelector::RecentMasterPagesSelector(
55 weld::Widget
* pParent
, SdDrawDocument
& rDocument
, ViewShellBase
& rBase
,
56 const std::shared_ptr
<MasterPageContainer
>& rpContainer
,
57 const css::uno::Reference
<css::ui::XSidebar
>& rxSidebar
)
58 : MasterPagesSelector(pParent
, rDocument
, rBase
, rpContainer
, rxSidebar
,
59 u
"modules/simpress/ui/masterpagepanelrecent.ui"_ustr
,
60 u
"masterpagerecent_icons"_ustr
)
64 RecentMasterPagesSelector::~RecentMasterPagesSelector()
66 RecentlyUsedMasterPages::Instance().RemoveEventListener (
67 LINK(this,RecentMasterPagesSelector
,MasterPageListListener
));
70 void RecentMasterPagesSelector::LateInit()
72 MasterPagesSelector::LateInit();
74 MasterPagesSelector::Fill();
75 RecentlyUsedMasterPages::Instance().AddEventListener (
76 LINK(this,RecentMasterPagesSelector
,MasterPageListListener
));
79 IMPL_LINK_NOARG(RecentMasterPagesSelector
, MasterPageListListener
, LinkParamNone
*, void)
81 MasterPagesSelector::Fill();
84 void RecentMasterPagesSelector::Fill (ItemList
& rItemList
)
86 // Create a set of names of the master pages used by the document.
87 MasterPageObserver::MasterPageNameSet aCurrentNames
;
88 sal_uInt16 nMasterPageCount
= mrDocument
.GetMasterSdPageCount(PageKind::Standard
);
89 for (sal_uInt16 nIndex
=0; nIndex
<nMasterPageCount
; nIndex
++)
91 SdPage
* pMasterPage
= mrDocument
.GetMasterSdPage (nIndex
, PageKind::Standard
);
92 if (pMasterPage
!= nullptr)
93 aCurrentNames
.insert (pMasterPage
->GetName());
96 // Insert the recently used master pages that are currently not used.
97 RecentlyUsedMasterPages
& rInstance (RecentlyUsedMasterPages::Instance());
98 int nPageCount
= rInstance
.GetMasterPageCount();
99 for (int nIndex
=0; nIndex
<nPageCount
; nIndex
++)
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.
105 MasterPageContainer::Token
aToken (rInstance
.GetTokenForIndex(nIndex
));
106 if (aToken
!= MasterPageContainer::NIL_TOKEN
)
108 OUString
sStyleName (mpContainer
->GetStyleNameForToken(aToken
));
109 if (sStyleName
.isEmpty()
110 || aCurrentNames
.find(sStyleName
) == aCurrentNames
.end())
112 rItemList
.push_back(aToken
);
118 } // end of namespace sd::sidebar
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */