1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svdlayer.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <com/sun/star/uno/Sequence.hxx>
35 #include <svx/svdlayer.hxx>
36 #include <svx/svdmodel.hxx> // fuer Broadcasting
37 #include "svdglob.hxx" // StringCache
38 #include "svdstr.hrc" // Namen aus der Resource
40 ////////////////////////////////////////////////////////////////////////////////////////////////////
42 ////////////////////////////////////////////////////////////////////////////////////////////////////
44 sal_Bool
SetOfByte::IsEmpty() const
46 for(sal_uInt16
i(0); i
< 32; i
++)
55 sal_Bool
SetOfByte::IsFull() const
57 for(sal_uInt16
i(0); i
< 32; i
++)
66 sal_uInt16
SetOfByte::GetSetCount() const
70 for(sal_uInt16
i(0); i
< 32; i
++)
72 sal_uInt8
a(aData
[i
]);
90 sal_uInt8
SetOfByte::GetSetBit(sal_uInt16 nNum
) const
93 sal_uInt16
i(0), j(0);
96 while(j
< nNum
&& i
< 256)
98 if(IsSet(sal_uInt8(i
)))
106 return sal_uInt8(nRet
);
109 sal_uInt16
SetOfByte::GetClearCount() const
111 return sal_uInt16(256 - GetSetCount());
114 sal_uInt8
SetOfByte::GetClearBit(sal_uInt16 nNum
) const
117 sal_uInt16
i(0), j(0);
120 while(j
< nNum
&& i
< 256)
122 if(!IsSet(sal_uInt8(i
)))
130 return sal_uInt8(nRet
);
133 void SetOfByte::operator&=(const SetOfByte
& r2ndSet
)
135 for(sal_uInt16
i(0); i
< 32; i
++)
137 aData
[i
] &= r2ndSet
.aData
[i
];
141 void SetOfByte::operator|=(const SetOfByte
& r2ndSet
)
143 for(sal_uInt16
i(0); i
< 32; i
++)
145 aData
[i
] |= r2ndSet
.aData
[i
];
149 /** initialize this set with a uno sequence of sal_Int8
151 void SetOfByte::PutValue( const com::sun::star::uno::Any
& rAny
)
153 com::sun::star::uno::Sequence
< sal_Int8
> aSeq
;
156 sal_Int16 nCount
= (sal_Int16
)aSeq
.getLength();
161 for( nIndex
= 0; nIndex
< nCount
; nIndex
++ )
163 aData
[nIndex
] = static_cast<BYTE
>(aSeq
[nIndex
]);
166 for( ; nIndex
< 32; nIndex
++ )
173 /** returns a uno sequence of sal_Int8
175 void SetOfByte::QueryValue( com::sun::star::uno::Any
& rAny
) const
177 sal_Int16 nNumBytesSet
= 0;
179 for( nIndex
= 31; nIndex
>= 00; nIndex
-- )
181 if( 0 != aData
[nIndex
] )
183 nNumBytesSet
= nIndex
+ 1;
188 com::sun::star::uno::Sequence
< sal_Int8
> aSeq( nNumBytesSet
);
190 for( nIndex
= 0; nIndex
< nNumBytesSet
; nIndex
++ )
192 aSeq
[nIndex
] = static_cast<sal_Int8
>(aData
[nIndex
]);
198 ////////////////////////////////////////////////////////////////////////////////////////////////////
200 ////////////////////////////////////////////////////////////////////////////////////////////////////
202 void SdrLayer::SetStandardLayer(FASTBOOL bStd
)
206 aName
=ImpGetResStr(STR_StandardLayerName
);
209 SdrHint
aHint(HINT_LAYERCHG
);
210 pModel
->Broadcast(aHint
);
211 pModel
->SetChanged();
215 void SdrLayer::SetName(const XubString
& rNewName
)
217 if(!rNewName
.Equals(aName
))
220 nType
= 0; // Userdefined
224 SdrHint
aHint(HINT_LAYERCHG
);
226 pModel
->Broadcast(aHint
);
227 pModel
->SetChanged();
232 bool SdrLayer::operator==(const SdrLayer
& rCmpLayer
) const
234 return (nID
== rCmpLayer
.nID
235 && nType
== rCmpLayer
.nType
236 && aName
.Equals(rCmpLayer
.aName
));
239 ////////////////////////////////////////////////////////////////////////////////////////////////////
241 ////////////////////////////////////////////////////////////////////////////////////////////////////
243 SdrLayerAdmin::SdrLayerAdmin(SdrLayerAdmin
* pNewParent
):
248 sal_Char aTextControls
[] = "Controls";
249 aControlLayerName
= String(aTextControls
, sizeof(aTextControls
-1));
253 SdrLayerAdmin::SdrLayerAdmin(const SdrLayerAdmin
& rSrcLayerAdmin
):
259 sal_Char aTextControls
[] = "Controls";
260 aControlLayerName
= String(aTextControls
, sizeof(aTextControls
-1));
261 *this = rSrcLayerAdmin
;
264 SdrLayerAdmin::~SdrLayerAdmin()
269 void SdrLayerAdmin::ClearLayer()
272 pL
=(SdrLayer
*)aLayer
.First();
275 pL
=(SdrLayer
*)aLayer
.Next();
280 const SdrLayerAdmin
& SdrLayerAdmin::operator=(const SdrLayerAdmin
& rSrcLayerAdmin
)
283 pParent
=rSrcLayerAdmin
.pParent
;
285 USHORT nAnz
=rSrcLayerAdmin
.GetLayerCount();
286 for (i
=0; i
<nAnz
; i
++) {
287 aLayer
.Insert(new SdrLayer(*rSrcLayerAdmin
.GetLayer(i
)),CONTAINER_APPEND
);
292 bool SdrLayerAdmin::operator==(const SdrLayerAdmin
& rCmpLayerAdmin
) const
294 if (pParent
!=rCmpLayerAdmin
.pParent
||
295 aLayer
.Count()!=rCmpLayerAdmin
.aLayer
.Count() ||
296 aLSets
.Count()!=rCmpLayerAdmin
.aLSets
.Count()) return FALSE
;
298 USHORT nAnz
=GetLayerCount();
300 while (bOk
&& i
<nAnz
) {
301 bOk
=*GetLayer(i
)==*rCmpLayerAdmin
.GetLayer(i
);
307 void SdrLayerAdmin::SetModel(SdrModel
* pNewModel
)
309 if (pNewModel
!=pModel
) {
311 USHORT nAnz
=GetLayerCount();
313 for (i
=0; i
<nAnz
; i
++) {
314 GetLayer(i
)->SetModel(pNewModel
);
319 void SdrLayerAdmin::Broadcast() const
322 SdrHint
aHint(HINT_LAYERORDERCHG
);
323 pModel
->Broadcast(aHint
);
324 pModel
->SetChanged();
328 SdrLayer
* SdrLayerAdmin::RemoveLayer(USHORT nPos
)
330 SdrLayer
* pRetLayer
=(SdrLayer
*)(aLayer
.Remove(nPos
));
335 SdrLayer
* SdrLayerAdmin::NewLayer(const XubString
& rName
, USHORT nPos
)
337 SdrLayerID nID
=GetUniqueLayerID();
338 SdrLayer
* pLay
=new SdrLayer(nID
,rName
);
339 pLay
->SetModel(pModel
);
340 aLayer
.Insert(pLay
,nPos
);
345 SdrLayer
* SdrLayerAdmin::NewStandardLayer(USHORT nPos
)
347 SdrLayerID nID
=GetUniqueLayerID();
348 SdrLayer
* pLay
=new SdrLayer(nID
,String());
349 pLay
->SetStandardLayer();
350 pLay
->SetModel(pModel
);
351 aLayer
.Insert(pLay
,nPos
);
356 SdrLayer
* SdrLayerAdmin::MoveLayer(USHORT nPos
, USHORT nNewPos
)
358 SdrLayer
* pLayer
=(SdrLayer
*)(aLayer
.Remove(nPos
));
360 aLayer
.Insert(pLayer
,nNewPos
);
367 void SdrLayerAdmin::MoveLayer(SdrLayer
* pLayer
, USHORT nNewPos
)
369 ULONG nPos
=aLayer
.GetPos(pLayer
);
370 if (nPos
!=CONTAINER_ENTRY_NOTFOUND
) {
372 aLayer
.Insert(pLayer
,nNewPos
);
377 USHORT
SdrLayerAdmin::GetLayerPos(SdrLayer
* pLayer
) const
379 ULONG nRet
=SDRLAYER_NOTFOUND
;
381 nRet
=aLayer
.GetPos(pLayer
);
382 if (nRet
==CONTAINER_ENTRY_NOTFOUND
) {
383 nRet
=SDRLAYER_NOTFOUND
;
389 const SdrLayer
* SdrLayerAdmin::GetLayer(const XubString
& rName
, FASTBOOL
/*bInherited*/) const
392 const SdrLayer
* pLay
= NULL
;
394 while(i
< GetLayerCount() && !pLay
)
396 if(rName
.Equals(GetLayer(i
)->GetName()))
404 pLay
= pParent
->GetLayer(rName
, TRUE
);
410 SdrLayerID
SdrLayerAdmin::GetLayerID(const XubString
& rName
, FASTBOOL bInherited
) const
412 SdrLayerID nRet
=SDRLAYER_NOTFOUND
;
413 const SdrLayer
* pLay
=GetLayer(rName
,bInherited
);
414 if (pLay
!=NULL
) nRet
=pLay
->GetID();
418 const SdrLayer
* SdrLayerAdmin::GetLayerPerID(USHORT nID
) const
421 const SdrLayer
* pLay
=NULL
;
422 while (i
<GetLayerCount() && pLay
==NULL
) {
423 if (nID
==GetLayer(i
)->GetID()) pLay
=GetLayer(i
);
429 // Globale LayerID's beginnen mit 0 aufsteigend.
430 // Lokale LayerID's beginnen mit 254 absteigend.
431 // 255 ist reserviert fuer SDRLAYER_NOTFOUND
433 SdrLayerID
SdrLayerAdmin::GetUniqueLayerID() const
436 sal_Bool bDown
= (pParent
== NULL
);
438 for (j
=0; j
<GetLayerCount(); j
++)
440 aSet
.Set(GetLayer((sal_uInt16
)j
)->GetID());
446 while (i
&& aSet
.IsSet(BYTE(i
)))
454 while (i
<=254 && aSet
.IsSet(BYTE(i
)))