Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/sd/source/ui/inc/MasterPageObserver.hxx
Line
Count
Source (jump to first uncovered line)
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
#pragma once
21
22
#include <rtl/ustring.hxx>
23
#include <tools/link.hxx>
24
#include "tools/SdGlobalResourceContainer.hxx"
25
#include <memory>
26
#include <set>
27
28
class SdDrawDocument;
29
30
namespace sd
31
{
32
class MasterPageObserverEvent;
33
34
/** This singleton observes all registered documents for changes in the used
35
    master pages and in turn informs its listeners about it.  One such
36
    listener is the master page selector control in the tool panel that
37
    shows the recently used master pages.
38
*/
39
class MasterPageObserver final : 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();
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<MasterPageObserverEvent&, void>& 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<MasterPageObserverEvent&, void>& rEventListener);
73
74
private:
75
    class Implementation;
76
    ::std::unique_ptr<Implementation> mpImpl;
77
78
    MasterPageObserver();
79
    virtual ~MasterPageObserver() override;
80
81
    MasterPageObserver(const MasterPageObserver&) = delete;
82
83
    MasterPageObserver& operator=(const MasterPageObserver&) = delete;
84
};
85
86
/** Objects of this class are sent to listeners of the MasterPageObserver
87
    singleton when the list of master pages of one document has changed.
88
*/
89
class MasterPageObserverEvent
90
{
91
public:
92
    enum EventType
93
    {
94
        /// Master page already exists when document is registered.
95
        ET_MASTER_PAGE_EXISTS,
96
        /// Master page has been added to a document.
97
        ET_MASTER_PAGE_ADDED,
98
        /// Master page has been removed from to a document.
99
        ET_MASTER_PAGE_REMOVED
100
    };
101
102
    EventType meType;
103
    const OUString& mrMasterPageName;
104
105
    MasterPageObserverEvent(EventType eType, const OUString& rMasterPageName)
106
0
        : meType(eType)
107
0
        , mrMasterPageName(rMasterPageName)
108
0
    {
109
0
    }
110
};
111
112
} // end of namespace sd
113
114
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */