Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _SVDLAYER_HXX
30 : : #define _SVDLAYER_HXX
31 : :
32 : : #include <tools/string.hxx>
33 : : #include <tools/stream.hxx>
34 : : #include <svx/svdsob.hxx>
35 : : #include <svx/svdtypes.hxx> // fuer typedef SdrLayerID
36 : : #include "svx/svxdllapi.h"
37 : : #include <algorithm>
38 : :
39 : : class SdrModel;
40 : :
41 : : class SVX_DLLPUBLIC SdrLayer
42 : : {
43 : : friend class SdrLayerAdmin;
44 : : protected:
45 : : String aName;
46 : : String maTitle;
47 : : String maDescription;
48 : : SdrModel* pModel; // zum Broadcasten
49 : : sal_uInt16 nType; // 0=Userdefined,1=Standardlayer
50 : : SdrLayerID nID;
51 : : protected:
52 : : SdrLayer(SdrLayerID nNewID, const String& rNewName) { nID=nNewID; aName=rNewName; nType=0; pModel=NULL; }
53 : : void SetID(SdrLayerID nNewID) { nID=nNewID; }
54 : : public:
55 : : SdrLayer(): pModel(NULL),nType(0),nID(0) {}
56 : : bool operator==(const SdrLayer& rCmpLayer) const;
57 : : bool operator!=(const SdrLayer& rCmpLayer) const { return !operator==(rCmpLayer); }
58 : :
59 : : void SetName(const String& rNewName);
60 : 4584 : const String& GetName() const { return aName; }
61 : :
62 : 55 : void SetTitle(const String& rTitle) { maTitle = rTitle; }
63 : 60 : const String& GetTitle() const { return maTitle; }
64 : :
65 : 55 : void SetDescription(const String& rDesc) { maDescription = rDesc; }
66 : 60 : const String& GetDescription() const { return maDescription; }
67 : :
68 : 8318 : SdrLayerID GetID() const { return nID; }
69 : : void SetModel(SdrModel* pNewModel) { pModel=pNewModel; }
70 : : SdrModel* GetModel() const { return pModel; }
71 : : // Einem SdrLayer kann man sagen dass er ein (der) Standardlayer sein soll.
72 : : // Es wird dann laenderspeziefisch der passende Name gesetzt. SetName()
73 : : // setzt das Flag "StandardLayer" ggf. zurueck auf "Userdefined".
74 : : void SetStandardLayer(bool bStd = true);
75 : : bool IsStandardLayer() const { return nType==1; }
76 : : };
77 : :
78 : : // Beim Aendern von Layerdaten muss man derzeit
79 : : // noch selbst das Modify-Flag am Model setzen.
80 : : #define SDRLAYER_MAXCOUNT 255
81 : : class SVX_DLLPUBLIC SdrLayerAdmin {
82 : : friend class SdrView;
83 : : friend class SdrModel;
84 : : friend class SdrPage;
85 : :
86 : : protected:
87 : : std::vector<SdrLayer*> aLayer;
88 : : SdrLayerAdmin* pParent; // Der Admin der Seite kennt den Admin des Docs
89 : : SdrModel* pModel; // zum Broadcasten
90 : : String aControlLayerName;
91 : : protected:
92 : : // Eine noch nicht verwendete LayerID raussuchen. Sind bereits alle
93 : : // verbraucht, so gibt's 'ne 0. Wer sicher gehen will, muss vorher
94 : : // GetLayerCount()<SDRLAYER_MAXCOUNT abfragen, denn sonst sind alle
95 : : // vergeben.
96 : : SdrLayerID GetUniqueLayerID() const;
97 : : void Broadcast() const;
98 : : public:
99 : : explicit SdrLayerAdmin(SdrLayerAdmin* pNewParent=NULL);
100 : : SdrLayerAdmin(const SdrLayerAdmin& rSrcLayerAdmin);
101 : : ~SdrLayerAdmin();
102 : : const SdrLayerAdmin& operator=(const SdrLayerAdmin& rSrcLayerAdmin);
103 : : bool operator==(const SdrLayerAdmin& rCmpLayerAdmin) const;
104 : : bool operator!=(const SdrLayerAdmin& rCmpLayerAdmin) const { return !operator==(rCmpLayerAdmin); }
105 : : SdrLayerAdmin* GetParent() const { return pParent; }
106 : : void SetParent(SdrLayerAdmin* pNewParent) { pParent=pNewParent; }
107 : : void SetModel(SdrModel* pNewModel);
108 : : SdrModel* GetModel() const { return pModel; }
109 : : void InsertLayer(SdrLayer* pLayer)
110 : : {
111 : : aLayer.push_back(pLayer);
112 : : pLayer->SetModel(pModel);
113 : : Broadcast();
114 : : }
115 : : void InsertLayer(SdrLayer* pLayer, sal_uInt16 nPos)
116 : : {
117 : : if(nPos==0xFFFF)
118 : : aLayer.push_back(pLayer);
119 : : else
120 : : aLayer.insert(aLayer.begin() + nPos, pLayer);
121 : : pLayer->SetModel(pModel);
122 : : Broadcast();
123 : : }
124 : : SdrLayer* RemoveLayer(sal_uInt16 nPos);
125 : : // Alle Layer loeschen
126 : : void ClearLayer();
127 : : // Neuer Layer wird angelegt und eingefuegt
128 : : SdrLayer* NewLayer(const String& rName, sal_uInt16 nPos=0xFFFF);
129 : : void DeleteLayer(SdrLayer* pLayer)
130 : : {
131 : : std::vector<SdrLayer*>::iterator it = std::find(aLayer.begin(), aLayer.end(), pLayer);
132 : : if( it == aLayer.end() )
133 : : return;
134 : : aLayer.erase(it);
135 : : delete pLayer;
136 : : Broadcast();
137 : : }
138 : : // Neuer Layer, Name wird aus der Resource geholt
139 : : SdrLayer* NewStandardLayer(sal_uInt16 nPos=0xFFFF);
140 : :
141 : : // Iterieren ueber alle Layer
142 : 308 : sal_uInt16 GetLayerCount() const { return sal_uInt16(aLayer.size()); }
143 : 1140 : SdrLayer* GetLayer(sal_uInt16 i) { return aLayer[i]; }
144 : 0 : const SdrLayer* GetLayer(sal_uInt16 i) const { return aLayer[i]; }
145 : :
146 : : sal_uInt16 GetLayerPos(SdrLayer* pLayer) const;
147 : :
148 : 120 : SdrLayer* GetLayer(const String& rName, bool bInherited) { return (SdrLayer*)(((const SdrLayerAdmin*)this)->GetLayer(rName,bInherited)); }
149 : : const SdrLayer* GetLayer(const String& rName, bool bInherited) const;
150 : : SdrLayerID GetLayerID(const String& rName, bool bInherited) const;
151 : 2683 : SdrLayer* GetLayerPerID(sal_uInt16 nID) { return (SdrLayer*)(((const SdrLayerAdmin*)this)->GetLayerPerID(nID)); }
152 : : const SdrLayer* GetLayerPerID(sal_uInt16 nID) const;
153 : :
154 : 178 : void SetControlLayerName(const String& rNewName) { aControlLayerName=rNewName; }
155 : 0 : const String& GetControlLayerName() const { return aControlLayerName; }
156 : : };
157 : :
158 : : /*
159 : : Anmerkung zu den Layer - Gemischt symbolisch/ID-basierendes Interface
160 : : Einen neuen Layer macht man sich mit:
161 : : pLayerAdmin->NewLayer("Der neue Layer");
162 : : Der Layer wird dann automatisch an das Ende der Liste angehaengt.
163 : : Entsprechdes gilt fuer Layersets gleichermassen.
164 : : Das Interface am SdrLayerSet basiert auf LayerID's. Die App muss sich
165 : : dafuer am SdrLayerAdmin eine ID abholen:
166 : : SdrLayerID nLayerID=pLayerAdmin->GetLayerID("Der neue Layer");
167 : : Wird der Layer nicht gefunden, so liefert die Methode SDRLAYER_NOTFOUND
168 : : zurueck. Die Methoden mit ID-Interface fangen diesen Wert jedoch i.d.R
169 : : sinnvoll ab.
170 : : Hat man nicht nur den Namen, sondern gar einen SdrLayer*, so kann man
171 : : sich die ID natuerlich wesentlich schneller direkt vom Layer abholen.
172 : : bInherited:
173 : : TRUE: Wird der Layer/LayerSet nicht gefunden, so wird im Parent-LayerAdmin
174 : : nachgesehen, ob es dort einen entsprechende Definition gibt.
175 : : FALSE: Es wird nur dieser LayerAdmin durchsucht.
176 : : Jeder LayerAdmin einer Seite hat einen Parent-LayerAdmin, n�mlich den des
177 : : Model. Das Model selbst hat keinen Parent.
178 : : */
179 : :
180 : : #endif //_SVDLAYER_HXX
181 : :
182 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|