1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 #ifndef SD_VIEW_MASTER_PAGE_OBSERVER_HXX 23 #define SD_VIEW_MASTER_PAGE_OBSERVER_HXX 24 25 #include "tools/SdGlobalResourceContainer.hxx" 26 #include <osl/mutex.hxx> 27 #include <tools/link.hxx> 28 #include <memory> 29 #include <set> 30 31 class SdDrawDocument; 32 class String; 33 34 namespace sd { 35 36 /** This singleton observes all registered documents for changes in the used 37 master pages and in turn informs its listeners about it. One such 38 listener is the master page selector control in the tool panel that 39 shows the recently used master pages. 40 */ 41 class MasterPageObserver 42 : public SdGlobalResource 43 { 44 public: 45 typedef ::std::set<String> MasterPageNameSet; 46 47 /** Return the single instance of this class. 48 */ 49 static MasterPageObserver& Instance (void); 50 51 /** The master page observer will listen to events of this document and 52 detect changes of the use of master pages. 53 */ 54 void RegisterDocument (SdDrawDocument& rDocument); 55 56 /** The master page observer will stop to listen to events of this 57 document. 58 */ 59 void UnregisterDocument (SdDrawDocument& rDocument); 60 61 /** Add a listener that is informed of master pages that are newly 62 assigned to slides or become unassigned. 63 @param rEventListener 64 The event listener to call for future events. Call 65 RemoveEventListener() before the listener is destroyed. 66 */ 67 void AddEventListener (const Link& rEventListener); 68 69 /** Remove the given listener from the list of listeners. 70 @param rEventListener 71 After this method returns the given listener is not called back 72 from this object. Passing a listener that has not 73 been registered before is safe and is silently ignored. 74 */ 75 void RemoveEventListener (const Link& rEventListener); 76 77 private: 78 static ::osl::Mutex maMutex; 79 80 class Implementation; 81 ::std::auto_ptr<Implementation> mpImpl; 82 83 MasterPageObserver (void); 84 virtual ~MasterPageObserver (void); 85 86 // The copy constructor is not implemented. Do not use! 87 MasterPageObserver (const MasterPageObserver&); 88 89 // The assignment operator is not implemented. Do not use! 90 MasterPageObserver& operator= (const MasterPageObserver&); 91 }; 92 93 94 /** Objects of this class are sent to listeners of the MasterPageObserver 95 singleton when the list of master pages of one document has changed. 96 */ 97 class MasterPageObserverEvent 98 { 99 public: 100 enum EventType { 101 // Master page already exists when document is registered. 102 ET_MASTER_PAGE_EXISTS, 103 // Master page has been added to a document. 104 ET_MASTER_PAGE_ADDED, 105 // Master page has been removed from to a document. 106 ET_MASTER_PAGE_REMOVED 107 }; 108 109 EventType meType; 110 SdDrawDocument& mrDocument; 111 const String& mrMasterPageName; 112 113 MasterPageObserverEvent ( 114 EventType eType, 115 SdDrawDocument& rDocument, 116 const String& rMasterPageName) 117 : meType(eType), 118 mrDocument(rDocument), 119 mrMasterPageName(rMasterPageName) 120 {} 121 122 }; 123 124 } // end of namespace sd 125 126 #endif 127 128 /* vim: set noet sw=4 ts=4: */ 129