Get the style color and number just once
[LibreOffice.git] / sd / source / ui / sidebar / RecentlyUsedMasterPages.hxx
blob7172df6b8660ca7f0a705c61323e89ceb31ad930
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 #pragma once
22 #include <tools/SdGlobalResourceContainer.hxx>
23 #include <tools/link.hxx>
24 #include <utility>
25 #include <vector>
27 #include "MasterPageContainer.hxx"
29 namespace sd {
30 class MasterPageObserverEvent;
33 namespace sd::sidebar {
35 /** This singleton holds a list of the most recently used master pages.
37 class RecentlyUsedMasterPages
38 : public SdGlobalResource
40 public:
41 /** Return the single instance of this class.
43 static RecentlyUsedMasterPages& Instance();
45 void AddEventListener (const Link<LinkParamNone*,void>& rEventListener);
46 void RemoveEventListener (const Link<LinkParamNone*,void>& rEventListener);
48 int GetMasterPageCount() const;
49 MasterPageContainer::Token GetTokenForIndex (sal_uInt32 nIndex) const;
51 private:
52 class Descriptor
54 public:
55 OUString msURL;
56 OUString msName;
57 ::sd::sidebar::MasterPageContainer::Token maToken;
58 Descriptor (::sd::sidebar::MasterPageContainer::Token aToken,
59 OUString sURL, OUString sName)
60 : msURL(std::move(sURL)),
61 msName(std::move(sName)),
62 maToken(aToken)
65 class TokenComparator
67 public:
68 explicit TokenComparator(::sd::sidebar::MasterPageContainer::Token aToken)
69 : maToken(aToken) {}
70 bool operator () (const Descriptor& rDescriptor)
71 { return maToken==rDescriptor.maToken; }
73 private:
74 ::sd::sidebar::MasterPageContainer::Token maToken;
78 /** The single instance of this class. It is created on demand when
79 Instance() is called for the first time.
81 static RecentlyUsedMasterPages* mpInstance;
83 ::std::vector<Link<LinkParamNone*,void>> maListeners;
85 typedef ::std::vector<Descriptor> MasterPageList;
86 MasterPageList mvMasterPages;
87 std::shared_ptr<MasterPageContainer> mpContainer;
89 RecentlyUsedMasterPages();
90 virtual ~RecentlyUsedMasterPages() override;
92 /** Call this method after a new object has been created.
94 void LateInit();
96 RecentlyUsedMasterPages (const RecentlyUsedMasterPages&) = delete;
98 RecentlyUsedMasterPages& operator= (const RecentlyUsedMasterPages&) = delete;
100 void SendEvent();
101 DECL_LINK(MasterPageChangeListener, MasterPageObserverEvent&, void);
102 DECL_LINK(MasterPageContainerChangeListener, MasterPageContainerChangeEvent&, void);
104 /** Add a descriptor for the specified master page to the end of the
105 list of most recently used master pages. When the page is already a
106 member of that list the associated descriptor is moved to the end of
107 the list to make it the most recently used entry.
109 void AddMasterPage(MasterPageContainer::Token aToken);
111 /** Load the list of recently used master pages from the registry where
112 it was saved to make it persistent.
114 void LoadPersistentValues();
116 /** Save the list of recently used master pages to the registry to make
117 it persistent.
119 void SavePersistentValues();
121 void ResolveList();
124 } // end of namespace sd::sidebar
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */