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