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 .
22 #include <tools/SdGlobalResourceContainer.hxx>
23 #include <tools/link.hxx>
27 #include "MasterPageContainer.hxx"
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
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;
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
)),
68 explicit TokenComparator(::sd::sidebar::MasterPageContainer::Token aToken
)
70 bool operator () (const Descriptor
& rDescriptor
)
71 { return maToken
==rDescriptor
.maToken
; }
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.
96 RecentlyUsedMasterPages (const RecentlyUsedMasterPages
&) = delete;
98 RecentlyUsedMasterPages
& operator= (const RecentlyUsedMasterPages
&) = delete;
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
119 void SavePersistentValues();
124 } // end of namespace sd::sidebar
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */