xref: /aoo41x/main/svx/source/svdraw/svdlayer.cxx (revision 027cdf4a)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f6e50924SAndrew Rist  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19f6e50924SAndrew Rist  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <svx/svdlayer.hxx>
29cdf0e10cSrcweir #include <svx/svdmodel.hxx> // fuer Broadcasting
30cdf0e10cSrcweir #include "svx/svdglob.hxx"  // StringCache
31cdf0e10cSrcweir #include "svx/svdstr.hrc"   // Namen aus der Resource
32cdf0e10cSrcweir 
33cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
34cdf0e10cSrcweir // SetOfByte
35cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
36cdf0e10cSrcweir 
IsEmpty() const37cdf0e10cSrcweir sal_Bool SetOfByte::IsEmpty() const
38cdf0e10cSrcweir {
39cdf0e10cSrcweir 	for(sal_uInt16 i(0); i < 32; i++)
40cdf0e10cSrcweir 	{
41cdf0e10cSrcweir 		if(aData[i] != 0)
42cdf0e10cSrcweir 			return sal_False;
43cdf0e10cSrcweir 	}
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 	return sal_True;
46cdf0e10cSrcweir }
47cdf0e10cSrcweir 
IsFull() const48cdf0e10cSrcweir sal_Bool SetOfByte::IsFull() const
49cdf0e10cSrcweir {
50cdf0e10cSrcweir 	for(sal_uInt16 i(0); i < 32; i++)
51cdf0e10cSrcweir 	{
52cdf0e10cSrcweir 		if(aData[i] != 0xFF)
53cdf0e10cSrcweir 			return sal_False;
54cdf0e10cSrcweir 	}
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 	return sal_True;
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
GetSetCount() const59cdf0e10cSrcweir sal_uInt16 SetOfByte::GetSetCount() const
60cdf0e10cSrcweir {
61cdf0e10cSrcweir 	sal_uInt16 nRet(0);
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 	for(sal_uInt16 i(0); i < 32; i++)
64cdf0e10cSrcweir 	{
65cdf0e10cSrcweir 		sal_uInt8 a(aData[i]);
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 		if(a != 0)
68cdf0e10cSrcweir 		{
69cdf0e10cSrcweir 			if(a & 0x80) nRet++;
70cdf0e10cSrcweir 			if(a & 0x40) nRet++;
71cdf0e10cSrcweir 			if(a & 0x20) nRet++;
72cdf0e10cSrcweir 			if(a & 0x10) nRet++;
73cdf0e10cSrcweir 			if(a & 0x08) nRet++;
74cdf0e10cSrcweir 			if(a & 0x04) nRet++;
75cdf0e10cSrcweir 			if(a & 0x02) nRet++;
76cdf0e10cSrcweir 			if(a & 0x01) nRet++;
77cdf0e10cSrcweir 		}
78cdf0e10cSrcweir 	}
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	return nRet;
81cdf0e10cSrcweir }
82cdf0e10cSrcweir 
GetSetBit(sal_uInt16 nNum) const83cdf0e10cSrcweir sal_uInt8 SetOfByte::GetSetBit(sal_uInt16 nNum) const
84cdf0e10cSrcweir {
85cdf0e10cSrcweir 	nNum++;
86cdf0e10cSrcweir 	sal_uInt16 i(0), j(0);
87cdf0e10cSrcweir 	sal_uInt16 nRet(0);
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	while(j < nNum && i < 256)
90cdf0e10cSrcweir 	{
91cdf0e10cSrcweir 		if(IsSet(sal_uInt8(i)))
92cdf0e10cSrcweir 			j++;
93cdf0e10cSrcweir 		i++;
94cdf0e10cSrcweir 	}
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	if(j == nNum)
97cdf0e10cSrcweir 		nRet = i - 1;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	return sal_uInt8(nRet);
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
GetClearCount() const102cdf0e10cSrcweir sal_uInt16 SetOfByte::GetClearCount() const
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 	return sal_uInt16(256 - GetSetCount());
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
GetClearBit(sal_uInt16 nNum) const107cdf0e10cSrcweir sal_uInt8 SetOfByte::GetClearBit(sal_uInt16 nNum) const
108cdf0e10cSrcweir {
109cdf0e10cSrcweir 	nNum++;
110cdf0e10cSrcweir 	sal_uInt16 i(0), j(0);
111cdf0e10cSrcweir 	sal_uInt16 nRet(0);
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	while(j < nNum && i < 256)
114cdf0e10cSrcweir 	{
115cdf0e10cSrcweir 		if(!IsSet(sal_uInt8(i)))
116cdf0e10cSrcweir 			j++;
117cdf0e10cSrcweir 		i++;
118cdf0e10cSrcweir 	}
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	if(j == nNum)
121cdf0e10cSrcweir 		nRet = i - 1;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	return sal_uInt8(nRet);
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
operator &=(const SetOfByte & r2ndSet)126cdf0e10cSrcweir void SetOfByte::operator&=(const SetOfByte& r2ndSet)
127cdf0e10cSrcweir {
128cdf0e10cSrcweir 	for(sal_uInt16 i(0); i < 32; i++)
129cdf0e10cSrcweir 	{
130cdf0e10cSrcweir 		aData[i] &= r2ndSet.aData[i];
131cdf0e10cSrcweir 	}
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
operator |=(const SetOfByte & r2ndSet)134cdf0e10cSrcweir void SetOfByte::operator|=(const SetOfByte& r2ndSet)
135cdf0e10cSrcweir {
136cdf0e10cSrcweir 	for(sal_uInt16 i(0); i < 32; i++)
137cdf0e10cSrcweir 	{
138cdf0e10cSrcweir 		aData[i] |= r2ndSet.aData[i];
139cdf0e10cSrcweir 	}
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir /** initialize this set with a uno sequence of sal_Int8
143cdf0e10cSrcweir */
PutValue(const com::sun::star::uno::Any & rAny)144cdf0e10cSrcweir void SetOfByte::PutValue( const com::sun::star::uno::Any & rAny )
145cdf0e10cSrcweir {
146cdf0e10cSrcweir 	com::sun::star::uno::Sequence< sal_Int8 > aSeq;
147cdf0e10cSrcweir 	if( rAny >>= aSeq )
148cdf0e10cSrcweir 	{
149cdf0e10cSrcweir 		sal_Int16 nCount = (sal_Int16)aSeq.getLength();
150cdf0e10cSrcweir 		if( nCount > 32 )
151cdf0e10cSrcweir 			nCount = 32;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 		sal_Int16 nIndex;
154cdf0e10cSrcweir 		for( nIndex = 0; nIndex < nCount; nIndex++ )
155cdf0e10cSrcweir 		{
156cdf0e10cSrcweir 			aData[nIndex] = static_cast<sal_uInt8>(aSeq[nIndex]);
157cdf0e10cSrcweir 		}
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 		for( ; nIndex < 32; nIndex++ )
160cdf0e10cSrcweir 		{
161cdf0e10cSrcweir 			aData[nIndex] = 0;
162cdf0e10cSrcweir 		}
163cdf0e10cSrcweir 	}
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir /** returns a uno sequence of sal_Int8
167cdf0e10cSrcweir */
QueryValue(com::sun::star::uno::Any & rAny) const168cdf0e10cSrcweir void SetOfByte::QueryValue( com::sun::star::uno::Any & rAny ) const
169cdf0e10cSrcweir {
170cdf0e10cSrcweir 	sal_Int16 nNumBytesSet = 0;
171cdf0e10cSrcweir 	sal_Int16 nIndex;
172cdf0e10cSrcweir 	for( nIndex = 31; nIndex >= 00; nIndex-- )
173cdf0e10cSrcweir 	{
174cdf0e10cSrcweir 		if( 0 != aData[nIndex] )
175cdf0e10cSrcweir 		{
176cdf0e10cSrcweir 			nNumBytesSet = nIndex + 1;
177cdf0e10cSrcweir 			break;
178cdf0e10cSrcweir 		}
179cdf0e10cSrcweir 	}
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 	com::sun::star::uno::Sequence< sal_Int8 > aSeq( nNumBytesSet );
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 	for( nIndex = 0; nIndex < nNumBytesSet; nIndex++ )
184cdf0e10cSrcweir 	{
185cdf0e10cSrcweir 		aSeq[nIndex] = static_cast<sal_Int8>(aData[nIndex]);
186cdf0e10cSrcweir 	}
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 	rAny <<= aSeq;
189cdf0e10cSrcweir }
190cdf0e10cSrcweir 
191cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
192cdf0e10cSrcweir // SdrLayer
193cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
194cdf0e10cSrcweir 
SetStandardLayer(FASTBOOL bStd)195cdf0e10cSrcweir void SdrLayer::SetStandardLayer(FASTBOOL bStd)
196cdf0e10cSrcweir {
197cdf0e10cSrcweir 	nType=(sal_uInt16)bStd;
198cdf0e10cSrcweir 	if (bStd) {
199cdf0e10cSrcweir 		aName=ImpGetResStr(STR_StandardLayerName);
200cdf0e10cSrcweir 	}
201cdf0e10cSrcweir 	if (pModel!=NULL) {
202cdf0e10cSrcweir 		SdrHint aHint(HINT_LAYERCHG);
203cdf0e10cSrcweir 		pModel->Broadcast(aHint);
204cdf0e10cSrcweir 		pModel->SetChanged();
205cdf0e10cSrcweir 	}
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
SetName(const XubString & rNewName)208cdf0e10cSrcweir void SdrLayer::SetName(const XubString& rNewName)
209cdf0e10cSrcweir {
210cdf0e10cSrcweir 	if(!rNewName.Equals(aName))
211cdf0e10cSrcweir 	{
212cdf0e10cSrcweir 		aName = rNewName;
213cdf0e10cSrcweir 		nType = 0; // Userdefined
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 		if(pModel)
216cdf0e10cSrcweir 		{
217cdf0e10cSrcweir 			SdrHint aHint(HINT_LAYERCHG);
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 			pModel->Broadcast(aHint);
220cdf0e10cSrcweir 			pModel->SetChanged();
221cdf0e10cSrcweir 		}
222cdf0e10cSrcweir 	}
223cdf0e10cSrcweir }
224cdf0e10cSrcweir 
operator ==(const SdrLayer & rCmpLayer) const225cdf0e10cSrcweir bool SdrLayer::operator==(const SdrLayer& rCmpLayer) const
226cdf0e10cSrcweir {
227cdf0e10cSrcweir 	return (nID == rCmpLayer.nID
228cdf0e10cSrcweir 		&& nType == rCmpLayer.nType
229cdf0e10cSrcweir 		&& aName.Equals(rCmpLayer.aName));
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
232cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
233cdf0e10cSrcweir // SdrLayerAdmin
234cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
235cdf0e10cSrcweir 
SdrLayerAdmin(SdrLayerAdmin * pNewParent)236cdf0e10cSrcweir SdrLayerAdmin::SdrLayerAdmin(SdrLayerAdmin* pNewParent):
237cdf0e10cSrcweir 	aLayer(1024,16,16),
238cdf0e10cSrcweir 	aLSets(1024,16,16),
239cdf0e10cSrcweir 	pModel(NULL)
240cdf0e10cSrcweir {
241*027cdf4aSHerbert Dürr 	const sal_Char aTextControls[] = "Controls";
242*027cdf4aSHerbert Dürr 	aControlLayerName = String(aTextControls, sizeof(aTextControls)-1);
243cdf0e10cSrcweir 	pParent=pNewParent;
244cdf0e10cSrcweir }
245cdf0e10cSrcweir 
SdrLayerAdmin(const SdrLayerAdmin & rSrcLayerAdmin)246cdf0e10cSrcweir SdrLayerAdmin::SdrLayerAdmin(const SdrLayerAdmin& rSrcLayerAdmin):
247cdf0e10cSrcweir 	aLayer(1024,16,16),
248cdf0e10cSrcweir 	aLSets(1024,16,16),
249cdf0e10cSrcweir 	pParent(NULL),
250cdf0e10cSrcweir 	pModel(NULL)
251cdf0e10cSrcweir {
252*027cdf4aSHerbert Dürr 	const sal_Char aTextControls[] = "Controls";
253*027cdf4aSHerbert Dürr 	aControlLayerName = String(aTextControls, sizeof(aTextControls)-1);
254cdf0e10cSrcweir 	*this = rSrcLayerAdmin;
255cdf0e10cSrcweir }
256cdf0e10cSrcweir 
~SdrLayerAdmin()257cdf0e10cSrcweir SdrLayerAdmin::~SdrLayerAdmin()
258cdf0e10cSrcweir {
259cdf0e10cSrcweir 	ClearLayer();
260cdf0e10cSrcweir }
261cdf0e10cSrcweir 
ClearLayer()262cdf0e10cSrcweir void SdrLayerAdmin::ClearLayer()
263cdf0e10cSrcweir {
264cdf0e10cSrcweir 	SdrLayer* pL;
265cdf0e10cSrcweir 	pL=(SdrLayer*)aLayer.First();
266cdf0e10cSrcweir 	while (pL!=NULL) {
267cdf0e10cSrcweir 		delete pL;
268cdf0e10cSrcweir 		pL=(SdrLayer*)aLayer.Next();
269cdf0e10cSrcweir 	}
270cdf0e10cSrcweir 	aLayer.Clear();
271cdf0e10cSrcweir }
272cdf0e10cSrcweir 
operator =(const SdrLayerAdmin & rSrcLayerAdmin)273cdf0e10cSrcweir const SdrLayerAdmin& SdrLayerAdmin::operator=(const SdrLayerAdmin& rSrcLayerAdmin)
274cdf0e10cSrcweir {
275cdf0e10cSrcweir 	ClearLayer();
276cdf0e10cSrcweir 	pParent=rSrcLayerAdmin.pParent;
277cdf0e10cSrcweir 	sal_uInt16 i;
278cdf0e10cSrcweir 	sal_uInt16 nAnz=rSrcLayerAdmin.GetLayerCount();
279cdf0e10cSrcweir 	for (i=0; i<nAnz; i++) {
280cdf0e10cSrcweir 		aLayer.Insert(new SdrLayer(*rSrcLayerAdmin.GetLayer(i)),CONTAINER_APPEND);
281cdf0e10cSrcweir 	}
282cdf0e10cSrcweir 	return *this;
283cdf0e10cSrcweir }
284cdf0e10cSrcweir 
operator ==(const SdrLayerAdmin & rCmpLayerAdmin) const285cdf0e10cSrcweir bool SdrLayerAdmin::operator==(const SdrLayerAdmin& rCmpLayerAdmin) const
286cdf0e10cSrcweir {
287cdf0e10cSrcweir 	if (pParent!=rCmpLayerAdmin.pParent ||
288cdf0e10cSrcweir 		aLayer.Count()!=rCmpLayerAdmin.aLayer.Count() ||
289cdf0e10cSrcweir 		aLSets.Count()!=rCmpLayerAdmin.aLSets.Count()) return sal_False;
290cdf0e10cSrcweir 	FASTBOOL bOk=sal_True;
291cdf0e10cSrcweir 	sal_uInt16 nAnz=GetLayerCount();
292cdf0e10cSrcweir 	sal_uInt16 i=0;
293cdf0e10cSrcweir 	while (bOk && i<nAnz) {
294cdf0e10cSrcweir 		bOk=*GetLayer(i)==*rCmpLayerAdmin.GetLayer(i);
295cdf0e10cSrcweir 		i++;
296cdf0e10cSrcweir 	}
297cdf0e10cSrcweir 	return bOk;
298cdf0e10cSrcweir }
299cdf0e10cSrcweir 
SetModel(SdrModel * pNewModel)300cdf0e10cSrcweir void SdrLayerAdmin::SetModel(SdrModel* pNewModel)
301cdf0e10cSrcweir {
302cdf0e10cSrcweir 	if (pNewModel!=pModel) {
303cdf0e10cSrcweir 		pModel=pNewModel;
304cdf0e10cSrcweir 		sal_uInt16 nAnz=GetLayerCount();
305cdf0e10cSrcweir 		sal_uInt16 i;
306cdf0e10cSrcweir 		for (i=0; i<nAnz; i++) {
307cdf0e10cSrcweir 			GetLayer(i)->SetModel(pNewModel);
308cdf0e10cSrcweir 		}
309cdf0e10cSrcweir 	}
310cdf0e10cSrcweir }
311cdf0e10cSrcweir 
Broadcast() const312cdf0e10cSrcweir void SdrLayerAdmin::Broadcast() const
313cdf0e10cSrcweir {
314cdf0e10cSrcweir 	if (pModel!=NULL) {
315cdf0e10cSrcweir 		SdrHint aHint(HINT_LAYERORDERCHG);
316cdf0e10cSrcweir 		pModel->Broadcast(aHint);
317cdf0e10cSrcweir 		pModel->SetChanged();
318cdf0e10cSrcweir 	}
319cdf0e10cSrcweir }
320cdf0e10cSrcweir 
RemoveLayer(sal_uInt16 nPos)321cdf0e10cSrcweir SdrLayer* SdrLayerAdmin::RemoveLayer(sal_uInt16 nPos)
322cdf0e10cSrcweir {
323cdf0e10cSrcweir 	SdrLayer* pRetLayer=(SdrLayer*)(aLayer.Remove(nPos));
324cdf0e10cSrcweir 	Broadcast();
325cdf0e10cSrcweir 	return pRetLayer;
326cdf0e10cSrcweir }
327cdf0e10cSrcweir 
NewLayer(const XubString & rName,sal_uInt16 nPos)328cdf0e10cSrcweir SdrLayer* SdrLayerAdmin::NewLayer(const XubString& rName, sal_uInt16 nPos)
329cdf0e10cSrcweir {
330cdf0e10cSrcweir 	SdrLayerID nID=GetUniqueLayerID();
331cdf0e10cSrcweir 	SdrLayer* pLay=new SdrLayer(nID,rName);
332cdf0e10cSrcweir 	pLay->SetModel(pModel);
333cdf0e10cSrcweir 	aLayer.Insert(pLay,nPos);
334cdf0e10cSrcweir 	Broadcast();
335cdf0e10cSrcweir 	return pLay;
336cdf0e10cSrcweir }
337cdf0e10cSrcweir 
NewStandardLayer(sal_uInt16 nPos)338cdf0e10cSrcweir SdrLayer* SdrLayerAdmin::NewStandardLayer(sal_uInt16 nPos)
339cdf0e10cSrcweir {
340cdf0e10cSrcweir 	SdrLayerID nID=GetUniqueLayerID();
341cdf0e10cSrcweir 	SdrLayer* pLay=new SdrLayer(nID,String());
342cdf0e10cSrcweir 	pLay->SetStandardLayer();
343cdf0e10cSrcweir 	pLay->SetModel(pModel);
344cdf0e10cSrcweir 	aLayer.Insert(pLay,nPos);
345cdf0e10cSrcweir 	Broadcast();
346cdf0e10cSrcweir 	return pLay;
347cdf0e10cSrcweir }
348cdf0e10cSrcweir 
MoveLayer(sal_uInt16 nPos,sal_uInt16 nNewPos)349cdf0e10cSrcweir SdrLayer* SdrLayerAdmin::MoveLayer(sal_uInt16 nPos, sal_uInt16 nNewPos)
350cdf0e10cSrcweir {
351cdf0e10cSrcweir 	SdrLayer* pLayer=(SdrLayer*)(aLayer.Remove(nPos));
352cdf0e10cSrcweir 	if (pLayer!=NULL) {
353cdf0e10cSrcweir 		aLayer.Insert(pLayer,nNewPos);
354cdf0e10cSrcweir 	}
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 	Broadcast();
357cdf0e10cSrcweir 	return pLayer;
358cdf0e10cSrcweir }
359cdf0e10cSrcweir 
MoveLayer(SdrLayer * pLayer,sal_uInt16 nNewPos)360cdf0e10cSrcweir void SdrLayerAdmin::MoveLayer(SdrLayer* pLayer, sal_uInt16 nNewPos)
361cdf0e10cSrcweir {
362cdf0e10cSrcweir 	sal_uIntPtr nPos=aLayer.GetPos(pLayer);
363cdf0e10cSrcweir 	if (nPos!=CONTAINER_ENTRY_NOTFOUND) {
364cdf0e10cSrcweir 		aLayer.Remove(nPos);
365cdf0e10cSrcweir 		aLayer.Insert(pLayer,nNewPos);
366cdf0e10cSrcweir 		Broadcast();
367cdf0e10cSrcweir 	}
368cdf0e10cSrcweir }
369cdf0e10cSrcweir 
GetLayerPos(SdrLayer * pLayer) const370cdf0e10cSrcweir sal_uInt16 SdrLayerAdmin::GetLayerPos(SdrLayer* pLayer) const
371cdf0e10cSrcweir {
372cdf0e10cSrcweir 	sal_uIntPtr nRet=SDRLAYER_NOTFOUND;
373cdf0e10cSrcweir 	if (pLayer!=NULL) {
374cdf0e10cSrcweir 		nRet=aLayer.GetPos(pLayer);
375cdf0e10cSrcweir 		if (nRet==CONTAINER_ENTRY_NOTFOUND) {
376cdf0e10cSrcweir 			nRet=SDRLAYER_NOTFOUND;
377cdf0e10cSrcweir 		}
378cdf0e10cSrcweir 	}
379cdf0e10cSrcweir 	return sal_uInt16(nRet);
380cdf0e10cSrcweir }
381cdf0e10cSrcweir 
GetLayer(const XubString & rName,FASTBOOL) const382cdf0e10cSrcweir const SdrLayer* SdrLayerAdmin::GetLayer(const XubString& rName, FASTBOOL /*bInherited*/) const
383cdf0e10cSrcweir {
384cdf0e10cSrcweir 	sal_uInt16 i(0);
385cdf0e10cSrcweir 	const SdrLayer* pLay = NULL;
386cdf0e10cSrcweir 
387cdf0e10cSrcweir 	while(i < GetLayerCount() && !pLay)
388cdf0e10cSrcweir 	{
389cdf0e10cSrcweir 		if(rName.Equals(GetLayer(i)->GetName()))
390cdf0e10cSrcweir 			pLay = GetLayer(i);
391cdf0e10cSrcweir 		else
392cdf0e10cSrcweir 			i++;
393cdf0e10cSrcweir 	}
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 	if(!pLay && pParent)
396cdf0e10cSrcweir 	{
397cdf0e10cSrcweir 		pLay = pParent->GetLayer(rName, sal_True);
398cdf0e10cSrcweir 	}
399cdf0e10cSrcweir 
400cdf0e10cSrcweir 	return pLay;
401cdf0e10cSrcweir }
402cdf0e10cSrcweir 
GetLayerID(const XubString & rName,FASTBOOL bInherited) const403cdf0e10cSrcweir SdrLayerID SdrLayerAdmin::GetLayerID(const XubString& rName, FASTBOOL bInherited) const
404cdf0e10cSrcweir {
405cdf0e10cSrcweir 	SdrLayerID nRet=SDRLAYER_NOTFOUND;
406cdf0e10cSrcweir 	const SdrLayer* pLay=GetLayer(rName,bInherited);
407cdf0e10cSrcweir 	if (pLay!=NULL) nRet=pLay->GetID();
408cdf0e10cSrcweir 	return nRet;
409cdf0e10cSrcweir }
410cdf0e10cSrcweir 
GetLayerPerID(sal_uInt16 nID) const411cdf0e10cSrcweir const SdrLayer* SdrLayerAdmin::GetLayerPerID(sal_uInt16 nID) const
412cdf0e10cSrcweir {
413cdf0e10cSrcweir 	sal_uInt16 i=0;
414cdf0e10cSrcweir 	const SdrLayer* pLay=NULL;
415cdf0e10cSrcweir 	while (i<GetLayerCount() && pLay==NULL) {
416cdf0e10cSrcweir 		if (nID==GetLayer(i)->GetID()) pLay=GetLayer(i);
417cdf0e10cSrcweir 		else i++;
418cdf0e10cSrcweir 	}
419cdf0e10cSrcweir 	return pLay;
420cdf0e10cSrcweir }
421cdf0e10cSrcweir 
422cdf0e10cSrcweir // Globale LayerID's beginnen mit 0 aufsteigend.
423cdf0e10cSrcweir // Lokale LayerID's beginnen mit 254 absteigend.
424cdf0e10cSrcweir // 255 ist reserviert fuer SDRLAYER_NOTFOUND
425cdf0e10cSrcweir 
GetUniqueLayerID() const426cdf0e10cSrcweir SdrLayerID SdrLayerAdmin::GetUniqueLayerID() const
427cdf0e10cSrcweir {
428cdf0e10cSrcweir 	SetOfByte aSet;
429cdf0e10cSrcweir 	sal_Bool bDown = (pParent == NULL);
430cdf0e10cSrcweir 	sal_uInt16 j;
431cdf0e10cSrcweir 	for (j=0; j<GetLayerCount(); j++)
432cdf0e10cSrcweir     {
433cdf0e10cSrcweir 		aSet.Set(GetLayer((sal_uInt16)j)->GetID());
434cdf0e10cSrcweir 	}
435cdf0e10cSrcweir 	SdrLayerID i;
436cdf0e10cSrcweir 	if (!bDown)
437cdf0e10cSrcweir     {
438cdf0e10cSrcweir 		i=254;
439cdf0e10cSrcweir 		while (i && aSet.IsSet(sal_uInt8(i)))
440cdf0e10cSrcweir             --i;
441cdf0e10cSrcweir 		if (i == 0)
442cdf0e10cSrcweir             i=254;
443cdf0e10cSrcweir 	}
444cdf0e10cSrcweir     else
445cdf0e10cSrcweir     {
446cdf0e10cSrcweir 		i=0;
447cdf0e10cSrcweir 		while (i<=254 && aSet.IsSet(sal_uInt8(i)))
448cdf0e10cSrcweir             i++;
449cdf0e10cSrcweir 		if (i>254)
450cdf0e10cSrcweir             i=0;
451cdf0e10cSrcweir 	}
452cdf0e10cSrcweir 	return i;
453cdf0e10cSrcweir }
454cdf0e10cSrcweir 
455