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 ////////////////////////////////////////////////////////////////////////////////////////////////////
38 ////////////////////////////////////////////////////////////////////////////////////////////////////
40 sal_Bool
SetOfByte::IsEmpty() const
42 for(sal_uInt16
i(0); i
< 32; i
++)
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
;
74 sal_Int16 nCount
= (sal_Int16
)aSeq
.getLength();
79 for( nIndex
= 0; nIndex
< nCount
; nIndex
++ )
81 aData
[nIndex
] = static_cast<sal_uInt8
>(aSeq
[nIndex
]);
84 for( ; nIndex
< 32; nIndex
++ )
91 /** returns a uno sequence of sal_Int8
93 void SetOfByte::QueryValue( com::sun::star::uno::Any
& rAny
) const
95 sal_Int16 nNumBytesSet
= 0;
97 for( nIndex
= 31; nIndex
>= 00; nIndex
-- )
99 if( 0 != aData
[nIndex
] )
101 nNumBytesSet
= nIndex
+ 1;
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
]);
116 ////////////////////////////////////////////////////////////////////////////////////////////////////
118 ////////////////////////////////////////////////////////////////////////////////////////////////////
120 void SdrLayer::SetStandardLayer(bool bStd
)
122 nType
=(sal_uInt16
)bStd
;
124 aName
=ImpGetResStr(STR_StandardLayerName
);
127 SdrHint
aHint(HINT_LAYERCHG
);
128 pModel
->Broadcast(aHint
);
129 pModel
->SetChanged();
133 void SdrLayer::SetName(const XubString
& rNewName
)
135 if(!rNewName
.Equals(aName
))
138 nType
= 0; // user defined
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 ////////////////////////////////////////////////////////////////////////////////////////////////////
159 ////////////////////////////////////////////////////////////////////////////////////////////////////
161 SdrLayerAdmin::SdrLayerAdmin(SdrLayerAdmin
* pNewParent
):
166 aControlLayerName
= String(RTL_CONSTASCII_USTRINGPARAM("Controls"));
170 SdrLayerAdmin::SdrLayerAdmin(const SdrLayerAdmin
& rSrcLayerAdmin
):
176 aControlLayerName
= String(RTL_CONSTASCII_USTRINGPARAM("Controls"));
177 *this = rSrcLayerAdmin
;
180 SdrLayerAdmin::~SdrLayerAdmin()
185 void SdrLayerAdmin::ClearLayer()
188 pL
=(SdrLayer
*)aLayer
.First();
191 pL
=(SdrLayer
*)aLayer
.Next();
196 const SdrLayerAdmin
& SdrLayerAdmin::operator=(const SdrLayerAdmin
& rSrcLayerAdmin
)
199 pParent
=rSrcLayerAdmin
.pParent
;
201 sal_uInt16 nAnz
=rSrcLayerAdmin
.GetLayerCount();
202 for (i
=0; i
<nAnz
; i
++) {
203 aLayer
.Insert(new SdrLayer(*rSrcLayerAdmin
.GetLayer(i
)),CONTAINER_APPEND
);
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
;
214 sal_uInt16 nAnz
=GetLayerCount();
216 while (bOk
&& i
<nAnz
) {
217 bOk
=*GetLayer(i
)==*rCmpLayerAdmin
.GetLayer(i
);
223 void SdrLayerAdmin::SetModel(SdrModel
* pNewModel
)
225 if (pNewModel
!=pModel
) {
227 sal_uInt16 nAnz
=GetLayerCount();
229 for (i
=0; i
<nAnz
; i
++) {
230 GetLayer(i
)->SetModel(pNewModel
);
235 void SdrLayerAdmin::Broadcast() const
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
));
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
);
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
);
272 sal_uInt16
SdrLayerAdmin::GetLayerPos(SdrLayer
* pLayer
) const
274 sal_uIntPtr nRet
=SDRLAYER_NOTFOUND
;
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
287 const SdrLayer
* pLay
= NULL
;
289 while(i
< GetLayerCount() && !pLay
)
291 if(rName
.Equals(GetLayer(i
)->GetName()))
299 pLay
= pParent
->GetLayer(rName
, sal_True
);
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();
313 const SdrLayer
* SdrLayerAdmin::GetLayerPerID(sal_uInt16 nID
) const
316 const SdrLayer
* pLay
=NULL
;
317 while (i
<GetLayerCount() && pLay
==NULL
) {
318 if (nID
==GetLayer(i
)->GetID()) pLay
=GetLayer(i
);
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
331 sal_Bool bDown
= (pParent
== NULL
);
333 for (j
=0; j
<GetLayerCount(); j
++)
335 aSet
.Set(GetLayer((sal_uInt16
)j
)->GetID());
341 while (i
&& aSet
.IsSet(sal_uInt8(i
)))
349 while (i
<=254 && aSet
.IsSet(sal_uInt8(i
)))
357 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */