LibreOffice Module sd (master) 1
AllMasterPagesSelector.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#include <ViewShellBase.hxx>
24#include <helpids.h>
25
26#include <set>
27
28namespace {
29
30using namespace sd::sidebar;
31
32int GetURLPriority (const SharedMasterPageDescriptor& rpDescriptor)
33{
34 int nPriority (0);
35 switch (rpDescriptor->GetURLClassification())
36 {
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;
44 }
45 return nPriority;
46}
47
48class MasterPageDescriptorOrder
49{
50public:
51 bool operator() (
53 const SharedMasterPageDescriptor& rp2) const
54 {
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);
63 }
64};
65
66} // end of anonymous namespace
67
68namespace sd::sidebar {
69
71 : public ::std::set<SharedMasterPageDescriptor,MasterPageDescriptorOrder>
72{
73public:
75};
76
77std::unique_ptr<PanelLayout> AllMasterPagesSelector::Create (
78 weld::Widget* pParent,
79 ViewShellBase& rViewShellBase,
80 const css::uno::Reference<css::ui::XSidebar>& rxSidebar)
81{
82 SdDrawDocument* pDocument = rViewShellBase.GetDocument();
83 if (pDocument == nullptr)
84 return nullptr;
85
86 auto pContainer = std::make_shared<MasterPageContainer>();
87
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);
96
97 return xSelector;
98}
99
101 weld::Widget* pParent,
102 SdDrawDocument& rDocument,
103 ViewShellBase& rBase,
104 const std::shared_ptr<MasterPageContainer>& rpContainer,
105 const css::uno::Reference<css::ui::XSidebar>& rxSidebar)
106 : MasterPagesSelector(pParent, rDocument, rBase, rpContainer, rxSidebar, "modules/simpress/ui/masterpagepanelall.ui", "allvalueset"),
107 mpSortedMasterPages(new SortedMasterPageDescriptorList())
108{
110}
111
113{
114}
115
117{
118 if (mpSortedMasterPages->empty())
120 UpdatePageSet(rItemList);
121}
122
124 const MasterPageContainerChangeEvent& rEvent)
125{
126 switch (rEvent.meEventType)
127 {
129 AddItem(rEvent.maChildToken);
131 break;
132
134 mpSortedMasterPages->clear();
136 break;
137
138 default:
140 break;
141 }
142}
143
145{
146 mpSortedMasterPages->clear();
147 int nTokenCount = mpContainer->GetTokenCount();
148 for (int i=0; i<nTokenCount; i++)
149 AddItem(mpContainer->GetTokenForIndex(i));
150}
151
153{
154 switch (mpContainer->GetOriginForToken(aToken))
155 {
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;
166
167 default:
168 break;
169 }
170}
171
173{
174 for (const auto& rxDescriptor : *mpSortedMasterPages)
175 rItemList.push_back(rxDescriptor->maToken);
176}
177
178} // end of namespace sd::sidebar
179
180/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewShell descendant that the stacked Draw/Impress shells are based on.
SdDrawDocument * GetDocument() const
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, ViewShellBase &rViewShellBase, const css::uno::Reference< css::ui::XSidebar > &rxSidebar)
void AddItem(MasterPageContainer::Token aToken)
AllMasterPagesSelector(weld::Widget *pParent, SdDrawDocument &rDocument, ViewShellBase &rBase, const std::shared_ptr< MasterPageContainer > &rpContainer, const css::uno::Reference< css::ui::XSidebar > &rxSidebar)
virtual void NotifyContainerChangeEvent(const MasterPageContainerChangeEvent &rEvent) override
void UpdateMasterPageList()
Update the internal list of master pages that are to show in the control.
void UpdatePageSet(ItemList &rItemList)
Add all items in the internal master page list into the given list.
::std::unique_ptr< SortedMasterPageDescriptorList > mpSortedMasterPages
For some changes to the set of master pages in a MasterPageContainer or to the data stored for each m...
enum sd::sidebar::MasterPageContainerChangeEvent::EventType meEventType
Base class of a menu that lets the user select from a list of templates or designs that are loaded fr...
std::shared_ptr< MasterPageContainer > mpContainer
virtual void NotifyContainerChangeEvent(const MasterPageContainerChangeEvent &rEvent)
::std::vector< MasterPageContainer::Token > ItemList
constexpr OUStringLiteral HID_SD_TASK_PANE_PREVIEW_ALL
Definition: helpids.h:46
int i
std::shared_ptr< MasterPageDescriptor > SharedMasterPageDescriptor