Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / svx / svdlayer.hxx
blob1a60d8b249467f0023f5d17414237760412d0558
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SVX_SVDLAYER_HXX
21 #define INCLUDED_SVX_SVDLAYER_HXX
23 #include <svx/svdsob.hxx>
24 #include <svx/svdtypes.hxx>
25 #include <svx/svxdllapi.h>
26 #include <algorithm>
27 #include <vector>
29 /**
30 * Note on the layer mix with symbolic/ID-based interface:
31 * You create a new layer with
32 * pLayerAdmin->NewLayer("A new layer");
33 * This layer is automatically appended to the end of the list.
35 * The same holds true for layer sets.
37 * The interface for SdrLayerSet is based on LayerIDs. The app must get
38 * an ID for it at the SdrLayerAdmin, like so:
39 * SdrLayerID nLayerID=pLayerAdmin->GetLayerID("A new layer");
41 * If the layer cannot be found, SDRLAYER_NOTFOUND is returned.
42 * The methods with the ID interface usually handle that error in a
43 * meaningful way.
44 * If you not only got a name, but even a SdrLayer*, you can get the ID
45 * much faster via the layer directly.
47 * @param bInherited:
48 * TRUE If the layer/layer set cannot be found, we examine the parent layer admin,
49 * whether there's a corresponding definition
50 * FALSE We only search this layer admin
52 * Every page's layer admin has a parent layer admin (the model's). The model
53 * itself does not have a parent.
56 class SdrModel;
58 class SVX_DLLPUBLIC SdrLayer
60 friend class SdrLayerAdmin;
62 OUString maName;
63 OUString maTitle;
64 OUString maDescription;
65 SdrModel* pModel; // For broadcasting
66 sal_uInt16 nType; // 0= userdefined, 1= default layer
67 SdrLayerID nID;
69 SdrLayer(SdrLayerID nNewID, const OUString& rNewName);
71 public:
72 bool operator==(const SdrLayer& rCmpLayer) const;
74 void SetName(const OUString& rNewName);
75 const OUString& GetName() const { return maName; }
77 void SetTitle(const OUString& rTitle) { maTitle = rTitle; }
78 const OUString& GetTitle() const { return maTitle; }
80 void SetDescription(const OUString& rDesc) { maDescription = rDesc; }
81 const OUString& GetDescription() const { return maDescription; }
83 SdrLayerID GetID() const { return nID; }
84 void SetModel(SdrModel* pNewModel) { pModel=pNewModel; }
85 // A SdrLayer should be considered the standard Layer. It shall then set the
86 // appropriate country-specific name. SetName() sets the "StandardLayer" flag
87 // and if necessary returns "Userdefined".
88 void SetStandardLayer();
91 #define SDRLAYER_MAXCOUNT 255
92 #define SDRLAYERPOS_NOTFOUND 0xffff
94 // When Changing the layer data you currently have to set the Modify flag manually
95 class SVX_DLLPUBLIC SdrLayerAdmin {
96 friend class SdrView;
97 friend class SdrModel;
98 friend class SdrPage;
100 protected:
101 std::vector<SdrLayer*> aLayer;
102 SdrLayerAdmin* pParent; // The page's admin knows the doc's admin
103 SdrModel* pModel; // For broadcasting
104 OUString maControlLayerName;
105 protected:
106 // Find a LayerID which is not in use yet. If all have been used up,
107 // we return 0.
108 // If you want to play safe, check GetLayerCount()<SDRLAYER_MAXCOUNT
109 // first, else all are given away already.
110 SdrLayerID GetUniqueLayerID() const;
111 void Broadcast() const;
112 public:
113 explicit SdrLayerAdmin(SdrLayerAdmin* pNewParent=nullptr);
114 SdrLayerAdmin(const SdrLayerAdmin& rSrcLayerAdmin);
115 ~SdrLayerAdmin();
116 SdrLayerAdmin& operator=(const SdrLayerAdmin& rSrcLayerAdmin);
117 void SetParent(SdrLayerAdmin* pNewParent) { pParent=pNewParent; }
118 void SetModel(SdrModel* pNewModel);
119 void InsertLayer(SdrLayer* pLayer, sal_uInt16 nPos)
121 if(nPos==0xFFFF)
122 aLayer.push_back(pLayer);
123 else
124 aLayer.insert(aLayer.begin() + nPos, pLayer);
125 pLayer->SetModel(pModel);
126 Broadcast();
128 SdrLayer* RemoveLayer(sal_uInt16 nPos);
130 // Delete the entire layer
131 void ClearLayer();
133 // New layer is created and inserted
134 SdrLayer* NewLayer(const OUString& rName, sal_uInt16 nPos=0xFFFF);
136 // New layer, name is retrieved from the resource
137 void NewStandardLayer(sal_uInt16 nPos);
139 // Iterate over all layers
140 sal_uInt16 GetLayerCount() const { return sal_uInt16(aLayer.size()); }
142 SdrLayer* GetLayer(sal_uInt16 i) { return aLayer[i]; }
143 const SdrLayer* GetLayer(sal_uInt16 i) const { return aLayer[i]; }
145 sal_uInt16 GetLayerPos(SdrLayer* pLayer) const;
147 SdrLayer* GetLayer(const OUString& rName);
148 const SdrLayer* GetLayer(const OUString& rName) const;
149 SdrLayerID GetLayerID(const OUString& rName) const;
150 SdrLayer* GetLayerPerID(SdrLayerID nID) { return const_cast<SdrLayer*>(const_cast<const SdrLayerAdmin*>(this)->GetLayerPerID(nID)); }
151 const SdrLayer* GetLayerPerID(SdrLayerID nID) const;
153 void SetControlLayerName(const OUString& rNewName);
154 const OUString& GetControlLayerName() const { return maControlLayerName; }
157 #endif // INCLUDED_SVX_SVDLAYER_HXX
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */