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