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 "AllMasterPagesSelector.hxx"
21 #include <ViewShellBase.hxx>
22 #include "MasterPageContainer.hxx"
23 #include "MasterPageDescriptor.hxx"
30 using namespace sd::sidebar
;
32 int GetURLPriority (const SharedMasterPageDescriptor
& rpDescriptor
)
35 switch (rpDescriptor
->GetURLClassification())
37 case MasterPageDescriptor::URLCLASS_USER
: nPriority
= 0; break;
38 case MasterPageDescriptor::URLCLASS_LAYOUT
: nPriority
= 1; break;
39 case MasterPageDescriptor::URLCLASS_PRESENTATION
: nPriority
= 2; break;
40 case MasterPageDescriptor::URLCLASS_OTHER
: nPriority
= 3; break;
41 case MasterPageDescriptor::URLCLASS_UNKNOWN
: nPriority
= 4; break;
43 case MasterPageDescriptor::URLCLASS_UNDETERMINED
: nPriority
= 5; break;
48 class MasterPageDescriptorOrder
52 const SharedMasterPageDescriptor
& rp1
,
53 const SharedMasterPageDescriptor
& rp2
) const
55 if (rp1
->meOrigin
== MasterPageContainer::DEFAULT
)
57 else if (rp2
->meOrigin
== MasterPageContainer::DEFAULT
)
59 else if (rp1
->GetURLClassification() == rp2
->GetURLClassification())
60 return rp1
->mnTemplateIndex
< rp2
->mnTemplateIndex
;
62 return GetURLPriority(rp1
) < GetURLPriority(rp2
);
66 } // end of anonymous namespace
68 namespace sd::sidebar
{
70 class AllMasterPagesSelector::SortedMasterPageDescriptorList
71 : public ::std::set
<SharedMasterPageDescriptor
,MasterPageDescriptorOrder
>
74 SortedMasterPageDescriptorList() {}
77 std::unique_ptr
<PanelLayout
> AllMasterPagesSelector::Create (
78 weld::Widget
* pParent
,
79 ViewShellBase
& rViewShellBase
,
80 const css::uno::Reference
<css::ui::XSidebar
>& rxSidebar
)
82 SdDrawDocument
* pDocument
= rViewShellBase
.GetDocument();
83 if (pDocument
== nullptr)
86 auto pContainer
= std::make_shared
<MasterPageContainer
>();
88 auto xSelector(std::make_unique
<AllMasterPagesSelector
>(
94 xSelector
->LateInit();
95 xSelector
->SetHelpId(HID_SD_TASK_PANE_PREVIEW_ALL
);
100 AllMasterPagesSelector::AllMasterPagesSelector(
101 weld::Widget
* pParent
, SdDrawDocument
& rDocument
, ViewShellBase
& rBase
,
102 const std::shared_ptr
<MasterPageContainer
>& rpContainer
,
103 const css::uno::Reference
<css::ui::XSidebar
>& rxSidebar
)
104 : MasterPagesSelector(pParent
, rDocument
, rBase
, rpContainer
, rxSidebar
,
105 u
"modules/simpress/ui/masterpagepanelall.ui"_ustr
,
106 u
"masterpageall_icons"_ustr
)
107 , mpSortedMasterPages(new SortedMasterPageDescriptorList())
109 MasterPagesSelector::Fill();
112 AllMasterPagesSelector::~AllMasterPagesSelector()
116 void AllMasterPagesSelector::Fill (ItemList
& rItemList
)
118 if (mpSortedMasterPages
->empty())
119 UpdateMasterPageList();
120 UpdatePageSet(rItemList
);
123 void AllMasterPagesSelector::NotifyContainerChangeEvent (
124 const MasterPageContainerChangeEvent
& rEvent
)
126 switch (rEvent
.meEventType
)
128 case MasterPageContainerChangeEvent::EventType::CHILD_ADDED
:
129 AddItem(rEvent
.maChildToken
);
130 MasterPagesSelector::Fill();
133 case MasterPageContainerChangeEvent::EventType::INDEX_CHANGED
:
134 mpSortedMasterPages
->clear();
135 MasterPagesSelector::Fill();
139 MasterPagesSelector::NotifyContainerChangeEvent(rEvent
);
144 void AllMasterPagesSelector::UpdateMasterPageList()
146 mpSortedMasterPages
->clear();
147 int nTokenCount
= mpContainer
->GetTokenCount();
148 for (int i
=0; i
<nTokenCount
; i
++)
149 AddItem(mpContainer
->GetTokenForIndex(i
));
152 void AllMasterPagesSelector::AddItem (MasterPageContainer::Token aToken
)
154 switch (mpContainer
->GetOriginForToken(aToken
))
156 case MasterPageContainer::DEFAULT
:
157 case MasterPageContainer::TEMPLATE
:
158 // Templates are added only when coming from the
159 // MasterPageContainerFiller so that they have an id which
160 // defines their place in the list. Templates (pre) loaded from
161 // RecentlyUsedMasterPages are ignored (they will be loaded
162 // later by the MasterPageContainerFiller.)
163 if (mpContainer
->GetTemplateIndexForToken(aToken
) >= 0)
164 mpSortedMasterPages
->insert(mpContainer
->GetDescriptorForToken(aToken
));
172 void AllMasterPagesSelector::UpdatePageSet (ItemList
& rItemList
)
174 for (const auto& rxDescriptor
: *mpSortedMasterPages
)
175 rItemList
.push_back(rxDescriptor
->maToken
);
178 } // end of namespace sd::sidebar
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */