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 #ifndef INCLUDED_SD_SOURCE_UI_INC_MASTERPAGEOBSERVER_HXX 21 #define INCLUDED_SD_SOURCE_UI_INC_MASTERPAGEOBSERVER_HXX 22 23 #include <rtl/ustring.hxx> 24 #include <tools/link.hxx> 25 #include "tools/SdGlobalResourceContainer.hxx" 26 #include <memory> 27 #include <set> 28 29 namespace osl { class Mutex; } 30 31 class SdDrawDocument; 32 33 namespace sd { 34 35 class MasterPageObserverEvent; 36 37 /** This singleton observes all registered documents for changes in the used 38 master pages and in turn informs its listeners about it. One such 39 listener is the master page selector control in the tool panel that 40 shows the recently used master pages. 41 */ 42 class MasterPageObserver 43 : public SdGlobalResource 44 { 45 public: 46 typedef ::std::set<OUString> MasterPageNameSet; 47 48 /** Return the single instance of this class. 49 */ 50 static MasterPageObserver& Instance(); 51 52 /** The master page observer will listen to events of this document and 53 detect changes of the use of master pages. 54 */ 55 void RegisterDocument (SdDrawDocument& rDocument); 56 57 /** The master page observer will stop to listen to events of this 58 document. 59 */ 60 void UnregisterDocument (SdDrawDocument& rDocument); 61 62 /** Add a listener that is informed of master pages that are newly 63 assigned to slides or become unassigned. 64 @param rEventListener 65 The event listener to call for future events. Call 66 RemoveEventListener() before the listener is destroyed. 67 */ 68 void AddEventListener (const Link<MasterPageObserverEvent&,void>& rEventListener); 69 70 /** Remove the given listener from the list of listeners. 71 @param rEventListener 72 After this method returns the given listener is not called back 73 from this object. Passing a listener that has not 74 been registered before is safe and is silently ignored. 75 */ 76 void RemoveEventListener (const Link<MasterPageObserverEvent&,void>& rEventListener); 77 78 private: 79 static ::osl::Mutex maMutex; 80 81 class Implementation; 82 ::std::unique_ptr<Implementation> mpImpl; 83 84 MasterPageObserver(); 85 virtual ~MasterPageObserver() override; 86 87 MasterPageObserver (const MasterPageObserver&) = delete; 88 89 MasterPageObserver& operator= (const MasterPageObserver&) = delete; 90 }; 91 92 /** Objects of this class are sent to listeners of the MasterPageObserver 93 singleton when the list of master pages of one document has changed. 94 */ 95 class MasterPageObserverEvent 96 { 97 public: 98 enum EventType { 99 /// Master page already exists when document is registered. 100 ET_MASTER_PAGE_EXISTS, 101 /// Master page has been added to a document. 102 ET_MASTER_PAGE_ADDED, 103 /// Master page has been removed from to a document. 104 ET_MASTER_PAGE_REMOVED 105 }; 106 107 EventType const meType; 108 const OUString& mrMasterPageName; 109 MasterPageObserverEvent(EventType eType,const OUString & rMasterPageName)110 MasterPageObserverEvent ( 111 EventType eType, 112 const OUString& rMasterPageName) 113 : meType(eType), 114 mrMasterPageName(rMasterPageName) 115 {} 116 117 }; 118 119 } // end of namespace sd 120 121 #endif 122 123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 124