xref: /trunk/main/svx/inc/svx/svdlayer.hxx (revision 3334a7e6) !
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SVDLAYER_HXX
25 #define _SVDLAYER_HXX
26 
27 #include <tools/string.hxx>
28 #include <tools/stream.hxx>
29 #include <svx/svdsob.hxx>
30 #include <svx/svdtypes.hxx> // fuer typedef SdrLayerID
31 #include "svx/svxdllapi.h"
32 
33 class SdrModel;
34 
35 class SVX_DLLPUBLIC SdrLayer
36 {
37 friend class SdrLayerAdmin;
38 protected:
39 	String     aName;
40 	String		maTitle;
41 	String		maDescription;
42 	SdrModel*  pModel; // zum Broadcasten
43 	sal_uInt16     nType;  // 0=Userdefined,1=Standardlayer
44 	SdrLayerID nID;
45 protected:
SdrLayer(SdrLayerID nNewID,const String & rNewName)46 	SdrLayer(SdrLayerID nNewID, const String& rNewName)       { nID=nNewID; aName=rNewName; nType=0; pModel=NULL; }
SetID(SdrLayerID nNewID)47 	void SetID(SdrLayerID nNewID)                             { nID=nNewID; }
48 public:
SdrLayer()49 	SdrLayer(): pModel(NULL),nType(0),nID(0)                  {}
50 	bool      operator==(const SdrLayer& rCmpLayer) const;
operator !=(const SdrLayer & rCmpLayer) const51 	bool      operator!=(const SdrLayer& rCmpLayer) const { return !operator==(rCmpLayer); }
52 
53 	void          SetName(const String& rNewName);
GetName() const54 	const String& GetName() const                             { return aName; }
55 
SetTitle(const String & rTitle)56 	void          SetTitle(const String& rTitle) { maTitle = rTitle; }
GetTitle() const57 	const String& GetTitle() const { return maTitle; }
58 
SetDescription(const String & rDesc)59 	void          SetDescription(const String& rDesc) { maDescription = rDesc; }
GetDescription() const60 	const String& GetDescription() const { return maDescription; }
61 
GetID() const62 	SdrLayerID    GetID() const                               { return nID; }
SetModel(SdrModel * pNewModel)63 	void          SetModel(SdrModel* pNewModel)               { pModel=pNewModel; }
GetModel() const64 	SdrModel*     GetModel() const                            { return pModel; }
65 	// Einem SdrLayer kann man sagen dass er ein (der) Standardlayer sein soll.
66 	// Es wird dann laenderspeziefisch der passende Name gesetzt. SetName()
67 	// setzt das Flag "StandardLayer" ggf. zurueck auf "Userdefined".
68 	void          SetStandardLayer(FASTBOOL bStd=sal_True);
IsStandardLayer() const69 	FASTBOOL      IsStandardLayer() const                     { return nType==1; }
70 };
71 
72 // Beim Aendern von Layerdaten muss man derzeit
73 // noch selbst das Modify-Flag am Model setzen.
74 #define SDRLAYER_MAXCOUNT 255
75 class SVX_DLLPUBLIC SdrLayerAdmin {
76 friend class SdrView;
77 friend class SdrModel;
78 friend class SdrPage;
79 
80 protected:
81 	Container      aLayer;
82 	Container      aLSets;
83 	SdrLayerAdmin* pParent; // Der Admin der Seite kennt den Admin des Docs
84 	SdrModel*      pModel; // zum Broadcasten
85 	String         aControlLayerName;
86 protected:
87 	// Eine noch nicht verwendete LayerID raussuchen. Sind bereits alle
88 	// verbraucht, so gibt's 'ne 0. Wer sicher gehen will, muss vorher
89 	// GetLayerCount()<SDRLAYER_MAXCOUNT abfragen, denn sonst sind alle
90 	// vergeben.
91 	SdrLayerID           GetUniqueLayerID() const;
92 	void                 Broadcast() const;
93 public:
94 	SdrLayerAdmin(SdrLayerAdmin* pNewParent=NULL);
95 	SdrLayerAdmin(const SdrLayerAdmin& rSrcLayerAdmin);
96 	~SdrLayerAdmin();
97 	const SdrLayerAdmin& operator=(const SdrLayerAdmin& rSrcLayerAdmin);
98 	bool             operator==(const SdrLayerAdmin& rCmpLayerAdmin) const;
operator !=(const SdrLayerAdmin & rCmpLayerAdmin) const99 	bool             operator!=(const SdrLayerAdmin& rCmpLayerAdmin) const       { return !operator==(rCmpLayerAdmin); }
GetParent() const100 	SdrLayerAdmin*       GetParent() const                                           { return pParent; }
SetParent(SdrLayerAdmin * pNewParent)101 	void                 SetParent(SdrLayerAdmin* pNewParent)                        { pParent=pNewParent; }
102 	void                 SetModel(SdrModel* pNewModel);
GetModel() const103 	SdrModel*            GetModel() const                                            { return pModel; }
InsertLayer(SdrLayer * pLayer,sal_uInt16 nPos=0xFFFF)104 	void                 InsertLayer(SdrLayer* pLayer, sal_uInt16 nPos=0xFFFF)           { aLayer.Insert(pLayer,nPos); pLayer->SetModel(pModel); Broadcast(); }
105 	SdrLayer*            RemoveLayer(sal_uInt16 nPos);
106 	// Alle Layer loeschen
107 	void               ClearLayer();
108 	// Neuer Layer wird angelegt und eingefuegt
109 	SdrLayer*          NewLayer(const String& rName, sal_uInt16 nPos=0xFFFF);
DeleteLayer(SdrLayer * pLayer)110 	void               DeleteLayer(SdrLayer* pLayer)                                 { aLayer.Remove(pLayer); delete pLayer; Broadcast(); }
111 	void               MoveLayer(SdrLayer* pLayer, sal_uInt16 nNewPos=0xFFFF);
112 	SdrLayer*          MoveLayer(sal_uInt16 nPos, sal_uInt16 nNewPos);
113 	// Neuer Layer, Name wird aus der Resource geholt
114 	SdrLayer*          NewStandardLayer(sal_uInt16 nPos=0xFFFF);
115 
116 	// Iterieren ueber alle Layer
GetLayerCount() const117 	sal_uInt16             GetLayerCount() const                                         { return sal_uInt16(aLayer.Count()); }
GetLayer(sal_uInt16 i)118 	SdrLayer*          GetLayer(sal_uInt16 i)                                            { return (SdrLayer*)(aLayer.GetObject(i)); }
GetLayer(sal_uInt16 i) const119 	const SdrLayer*    GetLayer(sal_uInt16 i) const                                      { return (SdrLayer*)(aLayer.GetObject(i)); }
120 
121 	sal_uInt16             GetLayerPos(SdrLayer* pLayer) const;
122 
GetLayer(const String & rName,FASTBOOL bInherited)123 	SdrLayer*          GetLayer(const String& rName, FASTBOOL bInherited)            { return (SdrLayer*)(((const SdrLayerAdmin*)this)->GetLayer(rName,bInherited)); }
124 	const SdrLayer*    GetLayer(const String& rName, FASTBOOL bInherited) const;
125 		  SdrLayerID   GetLayerID(const String& rName, FASTBOOL bInherited) const;
GetLayerPerID(sal_uInt16 nID)126 		  SdrLayer*    GetLayerPerID(sal_uInt16 nID)                                     { return (SdrLayer*)(((const SdrLayerAdmin*)this)->GetLayerPerID(nID)); }
127 	const SdrLayer*    GetLayerPerID(sal_uInt16 nID) const;
128 
SetControlLayerName(const String & rNewName)129 	void     	       SetControlLayerName(const String& rNewName) { aControlLayerName=rNewName; }
GetControlLayerName() const130 	const String& 	   GetControlLayerName() const                 { return aControlLayerName; }
131 };
132 
133 /*
134 Anmerkung zu den Layer - Gemischt symbolisch/ID-basierendes Interface
135 	Einen neuen Layer macht man sich mit:
136 	  pLayerAdmin->NewLayer("Der neue Layer");
137 	Der Layer wird dann automatisch an das Ende der Liste angehaengt.
138 	Entsprechdes gilt fuer Layersets gleichermassen.
139 	Das Interface am SdrLayerSet basiert auf LayerID's. Die App muss sich
140 	dafuer am SdrLayerAdmin eine ID abholen:
141 		SdrLayerID nLayerID=pLayerAdmin->GetLayerID("Der neue Layer");
142 	Wird der Layer nicht gefunden, so liefert die Methode SDRLAYER_NOTFOUND
143 	zurueck. Die Methoden mit ID-Interface fangen diesen Wert jedoch i.d.R
144 	sinnvoll ab.
145 	Hat man nicht nur den Namen, sondern gar einen SdrLayer*, so kann man
146 	sich die ID natuerlich wesentlich schneller direkt vom Layer abholen.
147 bInherited:
148 	TRUE: Wird der Layer/LayerSet nicht gefunden, so wird im Parent-LayerAdmin
149 		  nachgesehen, ob es dort einen entsprechende Definition gibt.
150 	FALSE: Es wird nur dieser LayerAdmin durchsucht.
151 	Jeder LayerAdmin einer Seite hat einen Parent-LayerAdmin, n�mlich den des
152 	Model. Das Model selbst hat keinen Parent.
153 */
154 
155 #endif //_SVDLAYER_HXX
156 
157