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 20 #pragma once 21 22 #include <tools/SdGlobalResourceContainer.hxx> 23 #include <tools/link.hxx> 24 #include <vector> 25 26 #include "MasterPageContainer.hxx" 27 28 namespace sd { 29 class MasterPageObserverEvent; 30 } 31 32 namespace sd::sidebar { 33 34 /** This singleton holds a list of the most recently used master pages. 35 */ 36 class RecentlyUsedMasterPages 37 : public SdGlobalResource 38 { 39 public: 40 /** Return the single instance of this class. 41 */ 42 static RecentlyUsedMasterPages& Instance(); 43 44 void AddEventListener (const Link<LinkParamNone*,void>& rEventListener); 45 void RemoveEventListener (const Link<LinkParamNone*,void>& rEventListener); 46 47 int GetMasterPageCount() const; 48 MasterPageContainer::Token GetTokenForIndex (sal_uInt32 nIndex) const; 49 50 private: 51 class Descriptor 52 { 53 public: 54 OUString msURL; 55 OUString msName; 56 ::sd::sidebar::MasterPageContainer::Token maToken; Descriptor(::sd::sidebar::MasterPageContainer::Token aToken,const OUString & rsURL,const OUString & rsName)57 Descriptor (::sd::sidebar::MasterPageContainer::Token aToken, 58 const OUString& rsURL, const OUString& rsName) 59 : msURL(rsURL), 60 msName(rsName), 61 maToken(aToken) 62 {} 63 64 class TokenComparator 65 { 66 public: TokenComparator(::sd::sidebar::MasterPageContainer::Token aToken)67 explicit TokenComparator(::sd::sidebar::MasterPageContainer::Token aToken) 68 : maToken(aToken) {} operator ()(const Descriptor & rDescriptor)69 bool operator () (const Descriptor& rDescriptor) 70 { return maToken==rDescriptor.maToken; } 71 72 private: 73 ::sd::sidebar::MasterPageContainer::Token maToken; 74 }; 75 }; 76 77 /** The single instance of this class. It is created on demand when 78 Instance() is called for the first time. 79 */ 80 static RecentlyUsedMasterPages* mpInstance; 81 82 ::std::vector<Link<LinkParamNone*,void>> maListeners; 83 84 typedef ::std::vector<Descriptor> MasterPageList; 85 MasterPageList mvMasterPages; 86 std::shared_ptr<MasterPageContainer> mpContainer; 87 88 RecentlyUsedMasterPages(); 89 virtual ~RecentlyUsedMasterPages() override; 90 91 /** Call this method after a new object has been created. 92 */ 93 void LateInit(); 94 95 RecentlyUsedMasterPages (const RecentlyUsedMasterPages&) = delete; 96 97 RecentlyUsedMasterPages& operator= (const RecentlyUsedMasterPages&) = delete; 98 99 void SendEvent(); 100 DECL_LINK(MasterPageChangeListener, MasterPageObserverEvent&, void); 101 DECL_LINK(MasterPageContainerChangeListener, MasterPageContainerChangeEvent&, void); 102 103 /** Add a descriptor for the specified master page to the end of the 104 list of most recently used master pages. When the page is already a 105 member of that list the associated descriptor is moved to the end of 106 the list to make it the most recently used entry. 107 */ 108 void AddMasterPage(MasterPageContainer::Token aToken); 109 110 /** Load the list of recently used master pages from the registry where 111 it was saved to make it persistent. 112 */ 113 void LoadPersistentValues(); 114 115 /** Save the list of recently used master pages to the registry to make 116 it persistent. 117 */ 118 void SavePersistentValues(); 119 120 void ResolveList(); 121 }; 122 123 } // end of namespace sd::sidebar 124 125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 126