Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/svx/svdlayer.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
#ifndef INCLUDED_SVX_SVDLAYER_HXX
21
#define INCLUDED_SVX_SVDLAYER_HXX
22
23
#include <svx/svdsob.hxx>
24
#include <svx/svdtypes.hxx>
25
#include <svx/svxdllapi.h>
26
#include <memory>
27
#include <utility>
28
#include <vector>
29
30
/**
31
 * Note on the layer mix with symbolic/ID-based interface:
32
 * You create a new layer with
33
 *    pLayerAdmin->NewLayer("A new layer");
34
 * This layer is automatically appended to the end of the list.
35
 *
36
 * The same holds true for layer sets.
37
 *
38
 * The interface for SdrLayerSet is based on LayerIDs. The app must get
39
 * an ID for it at the SdrLayerAdmin, like so:
40
 *   SdrLayerID nLayerID=pLayerAdmin->GetLayerID("A new layer");
41
 *
42
 * If the layer cannot be found, SDRLAYER_NOTFOUND is returned.
43
 * The methods with the ID interface usually handle that error in a
44
 * meaningful way.
45
 * If you not only got a name, but even a SdrLayer*, you can get the ID
46
 * much faster via the layer directly.
47
 *
48
 * @param bInherited:
49
 * TRUE If the layer/layer set cannot be found, we examine the parent layer admin,
50
 *      whether there's a corresponding definition
51
 * FALSE We only search this layer admin
52
 *
53
 * Every page's layer admin has a parent layer admin (the model's). The model
54
 * itself does not have a parent.
55
 */
56
57
class SdrModel;
58
59
class SVXCORE_DLLPUBLIC SdrLayer
60
{
61
    friend class SdrLayerAdmin;
62
63
    OUString maName;
64
    OUString maTitle;
65
    OUString maDescription;
66
    SdrModel*  m_pModel; // For broadcasting
67
    bool mbVisibleODF; // corresponds to ODF draw:display
68
    bool mbPrintableODF; // corresponds to ODF draw:display
69
    bool mbLockedODF; // corresponds to ODF draw:protected
70
    SdrLayerID m_nID;
71
72
    SdrLayer(SdrLayerID nNewID, OUString aNewName);
73
74
public:
75
    bool operator==(const SdrLayer& rCmpLayer) const;
76
77
    void SetName(const OUString& rNewName);
78
7.40M
    const OUString& GetName() const { return maName; }
79
80
1.66k
    void SetTitle(const OUString& rTitle) { maTitle = rTitle; }
81
0
    const OUString& GetTitle() const { return maTitle; }
82
83
1.66k
    void SetDescription(const OUString& rDesc) { maDescription = rDesc; }
84
0
    const OUString& GetDescription() const { return maDescription; }
85
86
1.66k
    void SetVisibleODF(bool bVisibleODF) { mbVisibleODF = bVisibleODF; }
87
43.0k
    bool IsVisibleODF() const { return mbVisibleODF; }
88
89
1.66k
    void SetPrintableODF(bool bPrintableODF) { mbPrintableODF = bPrintableODF; }
90
43.0k
    bool IsPrintableODF() const { return mbPrintableODF; }
91
92
1.66k
    void SetLockedODF(bool bLockedODF) { mbLockedODF = bLockedODF; }
93
43.0k
    bool IsLockedODF() const { return mbLockedODF; }
94
95
5.03M
    SdrLayerID    GetID() const                               { return m_nID; }
96
826k
    void          SetModel(SdrModel* pNewModel)               { m_pModel=pNewModel; }
97
};
98
99
#define SDRLAYER_MAXCOUNT 255
100
0
#define SDRLAYERPOS_NOTFOUND 0xffff
101
102
// When Changing the layer data you currently have to set the Modify flag manually
103
class SVXCORE_DLLPUBLIC SdrLayerAdmin {
104
friend class SdrView;
105
friend class SdrModel;
106
friend class SdrPage;
107
108
    std::vector<std::unique_ptr<SdrLayer>> maLayers;
109
    SdrLayerAdmin* m_pParent; // The page's admin knows the doc's admin
110
    SdrModel* m_pModel; // For broadcasting
111
    OUString maControlLayerName;
112
    // Find a LayerID which is not in use yet. If all have been used up,
113
    // we return 0.
114
    // If you want to play safe, check GetLayerCount()<SDRLAYER_MAXCOUNT
115
    // first, else all are given away already.
116
    SAL_DLLPRIVATE SdrLayerID         GetUniqueLayerID() const;
117
    SAL_DLLPRIVATE void               Broadcast() const;
118
public:
119
    SAL_DLLPRIVATE explicit SdrLayerAdmin(SdrLayerAdmin* pNewParent=nullptr);
120
    SdrLayerAdmin(const SdrLayerAdmin& rSrcLayerAdmin);
121
    ~SdrLayerAdmin();
122
    SAL_DLLPRIVATE SdrLayerAdmin& operator=(const SdrLayerAdmin& rSrcLayerAdmin);
123
124
    SAL_DLLPRIVATE void               SetModel(SdrModel* pNewModel);
125
126
    SAL_DLLPRIVATE void               InsertLayer(std::unique_ptr<SdrLayer> pLayer, sal_uInt16 nPos);
127
    SAL_DLLPRIVATE std::unique_ptr<SdrLayer> RemoveLayer(sal_uInt16 nPos);
128
129
    // Delete all layers
130
    SAL_DLLPRIVATE void               ClearLayers();
131
132
    // New layer is created and inserted
133
    SdrLayer*          NewLayer(const OUString& rName, sal_uInt16 nPos=0xFFFF);
134
135
    // Iterate over all layers
136
13.1M
    sal_uInt16         GetLayerCount() const                                         { return sal_uInt16(maLayers.size()); }
137
138
0
    SdrLayer*          GetLayer(sal_uInt16 i)                                        { return maLayers[i].get(); }
139
11.8M
    const SdrLayer*    GetLayer(sal_uInt16 i) const                                  { return maLayers[i].get(); }
140
141
    SAL_DLLPRIVATE sal_uInt16         GetLayerPos(const SdrLayer* pLayer) const;
142
143
    SdrLayer*          GetLayer(const OUString& rName);
144
    const SdrLayer*    GetLayer(const OUString& rName) const;
145
    SdrLayerID         GetLayerID(const OUString& rName) const;
146
392
    SdrLayer*          GetLayerPerID(SdrLayerID nID) { return const_cast<SdrLayer*>(std::as_const(*this).GetLayerPerID(nID)); }
147
    const SdrLayer*    GetLayerPerID(SdrLayerID nID) const;
148
149
    void               SetControlLayerName(const OUString& rNewName);
150
263k
    const OUString&    GetControlLayerName() const { return maControlLayerName; }
151
152
    // Removes all elements in rOutSet and then adds all IDs of layers from member aLayer
153
    // that fulfill the criterion visible, printable, or locked respectively.
154
    void               getVisibleLayersODF( SdrLayerIDSet& rOutSet) const;
155
    void               getPrintableLayersODF( SdrLayerIDSet& rOutSet) const;
156
    void               getLockedLayersODF( SdrLayerIDSet& rOutSet) const;
157
158
    // Generates a bitfield for settings.xml from the SdrLayerIDSet.
159
    // Output is a UNO sequence of BYTE (which is 'short' in API).
160
    void               QueryValue(const SdrLayerIDSet& rViewLayerSet, css::uno::Any& rAny);
161
};
162
163
#endif // INCLUDED_SVX_SVDLAYER_HXX
164
165
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */