Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / svx / source / svdraw / svdlayer.cxx
blobf946fc01a90eaa7fc1a13ab0613d7307f78cdf7f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
29 #include <com/sun/star/uno/Sequence.hxx>
31 #include <svx/svdlayer.hxx>
32 #include <svx/svdmodel.hxx> // for Broadcasting
33 #include "svx/svdglob.hxx" // StringCache
34 #include "svx/svdstr.hrc" // names taken from the resource
36 ////////////////////////////////////////////////////////////////////////////////////////////////////
37 // SetOfByte
38 ////////////////////////////////////////////////////////////////////////////////////////////////////
40 sal_Bool SetOfByte::IsEmpty() const
42 for(sal_uInt16 i(0); i < 32; i++)
44 if(aData[i] != 0)
45 return sal_False;
48 return sal_True;
51 void SetOfByte::operator&=(const SetOfByte& r2ndSet)
53 for(sal_uInt16 i(0); i < 32; i++)
55 aData[i] &= r2ndSet.aData[i];
59 void SetOfByte::operator|=(const SetOfByte& r2ndSet)
61 for(sal_uInt16 i(0); i < 32; i++)
63 aData[i] |= r2ndSet.aData[i];
67 /** initialize this set with a uno sequence of sal_Int8
69 void SetOfByte::PutValue( const com::sun::star::uno::Any & rAny )
71 com::sun::star::uno::Sequence< sal_Int8 > aSeq;
72 if( rAny >>= aSeq )
74 sal_Int16 nCount = (sal_Int16)aSeq.getLength();
75 if( nCount > 32 )
76 nCount = 32;
78 sal_Int16 nIndex;
79 for( nIndex = 0; nIndex < nCount; nIndex++ )
81 aData[nIndex] = static_cast<sal_uInt8>(aSeq[nIndex]);
84 for( ; nIndex < 32; nIndex++ )
86 aData[nIndex] = 0;
91 /** returns a uno sequence of sal_Int8
93 void SetOfByte::QueryValue( com::sun::star::uno::Any & rAny ) const
95 sal_Int16 nNumBytesSet = 0;
96 sal_Int16 nIndex;
97 for( nIndex = 31; nIndex >= 00; nIndex-- )
99 if( 0 != aData[nIndex] )
101 nNumBytesSet = nIndex + 1;
102 break;
106 com::sun::star::uno::Sequence< sal_Int8 > aSeq( nNumBytesSet );
108 for( nIndex = 0; nIndex < nNumBytesSet; nIndex++ )
110 aSeq[nIndex] = static_cast<sal_Int8>(aData[nIndex]);
113 rAny <<= aSeq;
116 ////////////////////////////////////////////////////////////////////////////////////////////////////
117 // SdrLayer
118 ////////////////////////////////////////////////////////////////////////////////////////////////////
120 void SdrLayer::SetStandardLayer(bool bStd)
122 nType=(sal_uInt16)bStd;
123 if (bStd) {
124 aName=ImpGetResStr(STR_StandardLayerName);
126 if (pModel!=NULL) {
127 SdrHint aHint(HINT_LAYERCHG);
128 pModel->Broadcast(aHint);
129 pModel->SetChanged();
133 void SdrLayer::SetName(const XubString& rNewName)
135 if(!rNewName.Equals(aName))
137 aName = rNewName;
138 nType = 0; // user defined
140 if(pModel)
142 SdrHint aHint(HINT_LAYERCHG);
144 pModel->Broadcast(aHint);
145 pModel->SetChanged();
150 bool SdrLayer::operator==(const SdrLayer& rCmpLayer) const
152 return (nID == rCmpLayer.nID
153 && nType == rCmpLayer.nType
154 && aName.Equals(rCmpLayer.aName));
157 ////////////////////////////////////////////////////////////////////////////////////////////////////
158 // SdrLayerAdmin
159 ////////////////////////////////////////////////////////////////////////////////////////////////////
161 SdrLayerAdmin::SdrLayerAdmin(SdrLayerAdmin* pNewParent):
162 aLayer(1024,16,16),
163 aLSets(1024,16,16),
164 pModel(NULL)
166 aControlLayerName = String(RTL_CONSTASCII_USTRINGPARAM("Controls"));
167 pParent=pNewParent;
170 SdrLayerAdmin::SdrLayerAdmin(const SdrLayerAdmin& rSrcLayerAdmin):
171 aLayer(1024,16,16),
172 aLSets(1024,16,16),
173 pParent(NULL),
174 pModel(NULL)
176 aControlLayerName = String(RTL_CONSTASCII_USTRINGPARAM("Controls"));
177 *this = rSrcLayerAdmin;
180 SdrLayerAdmin::~SdrLayerAdmin()
182 ClearLayer();
185 void SdrLayerAdmin::ClearLayer()
187 SdrLayer* pL;
188 pL=(SdrLayer*)aLayer.First();
189 while (pL!=NULL) {
190 delete pL;
191 pL=(SdrLayer*)aLayer.Next();
193 aLayer.Clear();
196 const SdrLayerAdmin& SdrLayerAdmin::operator=(const SdrLayerAdmin& rSrcLayerAdmin)
198 ClearLayer();
199 pParent=rSrcLayerAdmin.pParent;
200 sal_uInt16 i;
201 sal_uInt16 nAnz=rSrcLayerAdmin.GetLayerCount();
202 for (i=0; i<nAnz; i++) {
203 aLayer.Insert(new SdrLayer(*rSrcLayerAdmin.GetLayer(i)),CONTAINER_APPEND);
205 return *this;
208 bool SdrLayerAdmin::operator==(const SdrLayerAdmin& rCmpLayerAdmin) const
210 if (pParent!=rCmpLayerAdmin.pParent ||
211 aLayer.Count()!=rCmpLayerAdmin.aLayer.Count() ||
212 aLSets.Count()!=rCmpLayerAdmin.aLSets.Count()) return sal_False;
213 bool bOk = true;
214 sal_uInt16 nAnz=GetLayerCount();
215 sal_uInt16 i=0;
216 while (bOk && i<nAnz) {
217 bOk=*GetLayer(i)==*rCmpLayerAdmin.GetLayer(i);
218 i++;
220 return bOk;
223 void SdrLayerAdmin::SetModel(SdrModel* pNewModel)
225 if (pNewModel!=pModel) {
226 pModel=pNewModel;
227 sal_uInt16 nAnz=GetLayerCount();
228 sal_uInt16 i;
229 for (i=0; i<nAnz; i++) {
230 GetLayer(i)->SetModel(pNewModel);
235 void SdrLayerAdmin::Broadcast() const
237 if (pModel!=NULL) {
238 SdrHint aHint(HINT_LAYERORDERCHG);
239 pModel->Broadcast(aHint);
240 pModel->SetChanged();
244 SdrLayer* SdrLayerAdmin::RemoveLayer(sal_uInt16 nPos)
246 SdrLayer* pRetLayer=(SdrLayer*)(aLayer.Remove(nPos));
247 Broadcast();
248 return pRetLayer;
251 SdrLayer* SdrLayerAdmin::NewLayer(const XubString& rName, sal_uInt16 nPos)
253 SdrLayerID nID=GetUniqueLayerID();
254 SdrLayer* pLay=new SdrLayer(nID,rName);
255 pLay->SetModel(pModel);
256 aLayer.Insert(pLay,nPos);
257 Broadcast();
258 return pLay;
261 SdrLayer* SdrLayerAdmin::NewStandardLayer(sal_uInt16 nPos)
263 SdrLayerID nID=GetUniqueLayerID();
264 SdrLayer* pLay=new SdrLayer(nID,String());
265 pLay->SetStandardLayer();
266 pLay->SetModel(pModel);
267 aLayer.Insert(pLay,nPos);
268 Broadcast();
269 return pLay;
272 sal_uInt16 SdrLayerAdmin::GetLayerPos(SdrLayer* pLayer) const
274 sal_uIntPtr nRet=SDRLAYER_NOTFOUND;
275 if (pLayer!=NULL) {
276 nRet=aLayer.GetPos(pLayer);
277 if (nRet==CONTAINER_ENTRY_NOTFOUND) {
278 nRet=SDRLAYER_NOTFOUND;
281 return sal_uInt16(nRet);
284 const SdrLayer* SdrLayerAdmin::GetLayer(const XubString& rName, bool /*bInherited*/) const
286 sal_uInt16 i(0);
287 const SdrLayer* pLay = NULL;
289 while(i < GetLayerCount() && !pLay)
291 if(rName.Equals(GetLayer(i)->GetName()))
292 pLay = GetLayer(i);
293 else
294 i++;
297 if(!pLay && pParent)
299 pLay = pParent->GetLayer(rName, sal_True);
302 return pLay;
305 SdrLayerID SdrLayerAdmin::GetLayerID(const XubString& rName, bool bInherited) const
307 SdrLayerID nRet=SDRLAYER_NOTFOUND;
308 const SdrLayer* pLay=GetLayer(rName,bInherited);
309 if (pLay!=NULL) nRet=pLay->GetID();
310 return nRet;
313 const SdrLayer* SdrLayerAdmin::GetLayerPerID(sal_uInt16 nID) const
315 sal_uInt16 i=0;
316 const SdrLayer* pLay=NULL;
317 while (i<GetLayerCount() && pLay==NULL) {
318 if (nID==GetLayer(i)->GetID()) pLay=GetLayer(i);
319 else i++;
321 return pLay;
324 // Global LayerIDs begin at 0 and increase,
325 // local LayerIDs begin at 254 and decrease;
326 // 255 is reserved for SDRLAYER_NOTFOUND.
328 SdrLayerID SdrLayerAdmin::GetUniqueLayerID() const
330 SetOfByte aSet;
331 sal_Bool bDown = (pParent == NULL);
332 sal_uInt16 j;
333 for (j=0; j<GetLayerCount(); j++)
335 aSet.Set(GetLayer((sal_uInt16)j)->GetID());
337 SdrLayerID i;
338 if (!bDown)
340 i=254;
341 while (i && aSet.IsSet(sal_uInt8(i)))
342 --i;
343 if (i == 0)
344 i=254;
346 else
348 i=0;
349 while (i<=254 && aSet.IsSet(sal_uInt8(i)))
350 i++;
351 if (i>254)
352 i=0;
354 return i;
357 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */