tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / sd / source / ui / sidebar / AllMasterPagesSelector.cxx
blobfdd8ea4618f817f7d1dcac520e8c1def084a2df7
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 "AllMasterPagesSelector.hxx"
21 #include <ViewShellBase.hxx>
22 #include "MasterPageContainer.hxx"
23 #include "MasterPageDescriptor.hxx"
24 #include <helpids.h>
26 #include <set>
28 namespace {
30 using namespace sd::sidebar;
32 int GetURLPriority (const SharedMasterPageDescriptor& rpDescriptor)
34 int nPriority (0);
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;
42 default:
43 case MasterPageDescriptor::URLCLASS_UNDETERMINED: nPriority = 5; break;
45 return nPriority;
48 class MasterPageDescriptorOrder
50 public:
51 bool operator() (
52 const SharedMasterPageDescriptor& rp1,
53 const SharedMasterPageDescriptor& rp2) const
55 if (rp1->meOrigin == MasterPageContainer::DEFAULT)
56 return true;
57 else if (rp2->meOrigin == MasterPageContainer::DEFAULT)
58 return false;
59 else if (rp1->GetURLClassification() == rp2->GetURLClassification())
60 return rp1->mnTemplateIndex < rp2->mnTemplateIndex;
61 else
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>
73 public:
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)
84 return nullptr;
86 auto pContainer = std::make_shared<MasterPageContainer>();
88 auto xSelector(std::make_unique<AllMasterPagesSelector>(
89 pParent,
90 *pDocument,
91 rViewShellBase,
92 pContainer,
93 rxSidebar));
94 xSelector->LateInit();
95 xSelector->SetHelpId(HID_SD_TASK_PANE_PREVIEW_ALL);
97 return xSelector;
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();
131 break;
133 case MasterPageContainerChangeEvent::EventType::INDEX_CHANGED:
134 mpSortedMasterPages->clear();
135 MasterPagesSelector::Fill();
136 break;
138 default:
139 MasterPagesSelector::NotifyContainerChangeEvent(rEvent);
140 break;
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));
165 break;
167 default:
168 break;
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: */