1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef SD_VIEW_MASTER_PAGE_OBSERVER_HXX 29 #define SD_VIEW_MASTER_PAGE_OBSERVER_HXX 30 31 #include "tools/SdGlobalResourceContainer.hxx" 32 #include <osl/mutex.hxx> 33 #include <tools/link.hxx> 34 #include <memory> 35 #include <set> 36 37 class SdDrawDocument; 38 class String; 39 40 namespace sd { 41 42 /** This singleton observes all registered documents for changes in the used 43 master pages and in turn informs its listeners about it. One such 44 listener is the master page selector control in the tool panel that 45 shows the recently used master pages. 46 */ 47 class MasterPageObserver 48 : public SdGlobalResource 49 { 50 public: 51 typedef ::std::set<String> MasterPageNameSet; 52 53 /** Return the single instance of this class. 54 */ 55 static MasterPageObserver& Instance (void); 56 57 /** The master page observer will listen to events of this document and 58 detect changes of the use of master pages. 59 */ 60 void RegisterDocument (SdDrawDocument& rDocument); 61 62 /** The master page observer will stop to listen to events of this 63 document. 64 */ 65 void UnregisterDocument (SdDrawDocument& rDocument); 66 67 /** Add a listener that is informed of master pages that are newly 68 assigned to slides or become unassigned. 69 @param rEventListener 70 The event listener to call for future events. Call 71 RemoveEventListener() before the listener is destroyed. 72 */ 73 void AddEventListener (const Link& rEventListener); 74 75 /** Remove the given listener from the list of listeners. 76 @param rEventListener 77 After this method returns the given listener is not called back 78 from this object. Passing a listener that has not 79 been registered before is safe and is silently ignored. 80 */ 81 void RemoveEventListener (const Link& rEventListener); 82 83 private: 84 static ::osl::Mutex maMutex; 85 86 class Implementation; 87 ::std::auto_ptr<Implementation> mpImpl; 88 89 MasterPageObserver (void); 90 virtual ~MasterPageObserver (void); 91 92 /// The copy constructor is not implemented. Do not use! 93 MasterPageObserver (const MasterPageObserver&); 94 95 /// The assignment operator is not implemented. Do not use! 96 MasterPageObserver& operator= (const MasterPageObserver&); 97 }; 98 99 100 101 102 /** Objects of this class are sent to listeners of the MasterPageObserver 103 singleton when the list of master pages of one document has changed. 104 */ 105 class MasterPageObserverEvent 106 { 107 public: 108 enum EventType { 109 /// Master page already exists when document is registered. 110 ET_MASTER_PAGE_EXISTS, 111 /// Master page has been added to a document. 112 ET_MASTER_PAGE_ADDED, 113 /// Master page has been removed from to a document. 114 ET_MASTER_PAGE_REMOVED 115 }; 116 117 EventType meType; 118 SdDrawDocument& mrDocument; 119 const String& mrMasterPageName; 120 121 MasterPageObserverEvent ( 122 EventType eType, 123 SdDrawDocument& rDocument, 124 const String& rMasterPageName) 125 : meType(eType), 126 mrDocument(rDocument), 127 mrMasterPageName(rMasterPageName) 128 {} 129 130 }; 131 132 } // end of namespace sd 133 134 #endif 135