Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sd/source/ui/sidebar/RecentlyUsedMasterPages.hxx
Line
Count
Source
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 <tools/SdGlobalResourceContainer.hxx>
23
#include <tools/link.hxx>
24
#include <utility>
25
#include <vector>
26
27
#include "MasterPageContainer.hxx"
28
29
namespace sd {
30
class MasterPageObserverEvent;
31
}
32
33
namespace sd::sidebar {
34
35
/** This singleton holds a list of the most recently used master pages.
36
*/
37
class RecentlyUsedMasterPages
38
    : public SdGlobalResource
39
{
40
public:
41
    /** Return the single instance of this class.
42
    */
43
    static RecentlyUsedMasterPages& Instance();
44
45
    void AddEventListener (const Link<LinkParamNone*,void>& rEventListener);
46
    void RemoveEventListener (const Link<LinkParamNone*,void>& rEventListener);
47
48
    int GetMasterPageCount() const;
49
    MasterPageContainer::Token GetTokenForIndex (sal_uInt32 nIndex) const;
50
51
private:
52
    class Descriptor
53
    {
54
    public:
55
        OUString msURL;
56
        OUString msName;
57
        ::sd::sidebar::MasterPageContainer::Token maToken;
58
        Descriptor (::sd::sidebar::MasterPageContainer::Token aToken,
59
                    OUString sURL, OUString sName)
60
0
            : msURL(std::move(sURL)),
61
0
              msName(std::move(sName)),
62
0
              maToken(aToken)
63
0
        {}
64
65
        class TokenComparator
66
        {
67
        public:
68
            explicit TokenComparator(::sd::sidebar::MasterPageContainer::Token aToken)
69
0
                : maToken(aToken) {}
70
            bool operator () (const Descriptor& rDescriptor)
71
0
            { return maToken==rDescriptor.maToken; }
72
73
        private:
74
            ::sd::sidebar::MasterPageContainer::Token maToken;
75
        };
76
    };
77
78
    /** The single instance of this class.  It is created on demand when
79
        Instance() is called for the first time.
80
    */
81
    static RecentlyUsedMasterPages* mpInstance;
82
83
    ::std::vector<Link<LinkParamNone*,void>> maListeners;
84
85
    typedef ::std::vector<Descriptor> MasterPageList;
86
    MasterPageList mvMasterPages;
87
    std::shared_ptr<MasterPageContainer> mpContainer;
88
89
    RecentlyUsedMasterPages();
90
    virtual ~RecentlyUsedMasterPages() override;
91
92
    /** Call this method after a new object has been created.
93
    */
94
    void LateInit();
95
96
    RecentlyUsedMasterPages (const RecentlyUsedMasterPages&) = delete;
97
98
    RecentlyUsedMasterPages& operator= (const RecentlyUsedMasterPages&) = delete;
99
100
    void SendEvent();
101
    DECL_LINK(MasterPageChangeListener, MasterPageObserverEvent&, void);
102
    DECL_LINK(MasterPageContainerChangeListener, MasterPageContainerChangeEvent&, void);
103
104
    /** Add a descriptor for the specified master page to the end of the
105
        list of most recently used master pages.  When the page is already a
106
        member of that list the associated descriptor is moved to the end of
107
        the list to make it the most recently used entry.
108
    */
109
    void AddMasterPage(MasterPageContainer::Token aToken);
110
111
    /** Load the list of recently used master pages from the registry where
112
        it was saved to make it persistent.
113
    */
114
    void LoadPersistentValues();
115
116
    /** Save the list of recently used master pages to the registry to make
117
        it persistent.
118
    */
119
    void SavePersistentValues();
120
121
    void ResolveList();
122
123
    void ImplDestroy();
124
};
125
126
} // end of namespace sd::sidebar
127
128
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */