1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/uno/Sequence.hxx>
22 #include <svx/svdlayer.hxx>
23 #include <svx/svdmodel.hxx>
24 #include "svdglob.hxx"
25 #include "svx/svdstr.hrc"
27 bool SetOfByte::IsEmpty() const
29 for(sal_uInt16
i(0); i
< 32; i
++)
38 void SetOfByte::operator&=(const SetOfByte
& r2ndSet
)
40 for(sal_uInt16
i(0); i
< 32; i
++)
42 aData
[i
] &= r2ndSet
.aData
[i
];
46 void SetOfByte::operator|=(const SetOfByte
& r2ndSet
)
48 for(sal_uInt16
i(0); i
< 32; i
++)
50 aData
[i
] |= r2ndSet
.aData
[i
];
54 /** initialize this set with a uno sequence of sal_Int8
56 void SetOfByte::PutValue( const com::sun::star::uno::Any
& rAny
)
58 com::sun::star::uno::Sequence
< sal_Int8
> aSeq
;
61 sal_Int16 nCount
= (sal_Int16
)aSeq
.getLength();
66 for( nIndex
= 0; nIndex
< nCount
; nIndex
++ )
68 aData
[nIndex
] = static_cast<sal_uInt8
>(aSeq
[nIndex
]);
71 for( ; nIndex
< 32; nIndex
++ )
78 /** returns a uno sequence of sal_Int8
80 void SetOfByte::QueryValue( com::sun::star::uno::Any
& rAny
) const
82 sal_Int16 nNumBytesSet
= 0;
84 for( nIndex
= 31; nIndex
>= 00; nIndex
-- )
86 if( 0 != aData
[nIndex
] )
88 nNumBytesSet
= nIndex
+ 1;
93 com::sun::star::uno::Sequence
< sal_Int8
> aSeq( nNumBytesSet
);
95 for( nIndex
= 0; nIndex
< nNumBytesSet
; nIndex
++ )
97 aSeq
[nIndex
] = static_cast<sal_Int8
>(aData
[nIndex
]);
103 SdrLayer::SdrLayer(SdrLayerID nNewID
, const OUString
& rNewName
) :
104 maName(rNewName
), pModel(NULL
), nType(0), nID(nNewID
)
108 void SdrLayer::SetStandardLayer(bool bStd
)
110 nType
=(sal_uInt16
)bStd
;
112 maName
= ImpGetResStr(STR_StandardLayerName
);
115 SdrHint
aHint(HINT_LAYERCHG
);
116 pModel
->Broadcast(aHint
);
117 pModel
->SetChanged();
121 void SdrLayer::SetName(const OUString
& rNewName
)
123 if (rNewName
== maName
)
127 nType
= 0; // user defined
131 SdrHint
aHint(HINT_LAYERCHG
);
132 pModel
->Broadcast(aHint
);
133 pModel
->SetChanged();
137 bool SdrLayer::operator==(const SdrLayer
& rCmpLayer
) const
139 return (nID
== rCmpLayer
.nID
140 && nType
== rCmpLayer
.nType
141 && maName
== rCmpLayer
.maName
);
148 SdrLayerAdmin::SdrLayerAdmin(SdrLayerAdmin
* pNewParent
):
152 maControlLayerName("Controls")
156 SdrLayerAdmin::SdrLayerAdmin(const SdrLayerAdmin
& rSrcLayerAdmin
):
160 maControlLayerName("Controls")
162 *this = rSrcLayerAdmin
;
165 SdrLayerAdmin::~SdrLayerAdmin()
170 void SdrLayerAdmin::ClearLayer()
172 for( std::vector
<SdrLayer
*>::const_iterator it
= aLayer
.begin(); it
!= aLayer
.end(); ++it
)
177 const SdrLayerAdmin
& SdrLayerAdmin::operator=(const SdrLayerAdmin
& rSrcLayerAdmin
)
180 pParent
=rSrcLayerAdmin
.pParent
;
182 sal_uInt16 nAnz
=rSrcLayerAdmin
.GetLayerCount();
183 for (i
=0; i
<nAnz
; i
++) {
184 aLayer
.push_back(new SdrLayer(*rSrcLayerAdmin
.GetLayer(i
)));
189 bool SdrLayerAdmin::operator==(const SdrLayerAdmin
& rCmpLayerAdmin
) const
191 if (pParent
!=rCmpLayerAdmin
.pParent
||
192 aLayer
.size()!=rCmpLayerAdmin
.aLayer
.size())
195 sal_uInt16 nAnz
=GetLayerCount();
197 while (bOk
&& i
<nAnz
) {
198 bOk
=*GetLayer(i
)==*rCmpLayerAdmin
.GetLayer(i
);
204 void SdrLayerAdmin::SetModel(SdrModel
* pNewModel
)
206 if (pNewModel
!=pModel
) {
208 sal_uInt16 nAnz
=GetLayerCount();
210 for (i
=0; i
<nAnz
; i
++) {
211 GetLayer(i
)->SetModel(pNewModel
);
216 void SdrLayerAdmin::Broadcast() const
219 SdrHint
aHint(HINT_LAYERORDERCHG
);
220 pModel
->Broadcast(aHint
);
221 pModel
->SetChanged();
225 SdrLayer
* SdrLayerAdmin::RemoveLayer(sal_uInt16 nPos
)
227 SdrLayer
* pRetLayer
=aLayer
[nPos
];
228 aLayer
.erase(aLayer
.begin()+nPos
);
233 SdrLayer
* SdrLayerAdmin::NewLayer(const OUString
& rName
, sal_uInt16 nPos
)
235 SdrLayerID nID
=GetUniqueLayerID();
236 SdrLayer
* pLay
=new SdrLayer(nID
,rName
);
237 pLay
->SetModel(pModel
);
239 aLayer
.push_back(pLay
);
241 aLayer
.insert(aLayer
.begin() + nPos
, pLay
);
246 SdrLayer
* SdrLayerAdmin::NewStandardLayer(sal_uInt16 nPos
)
248 SdrLayerID nID
=GetUniqueLayerID();
249 SdrLayer
* pLay
=new SdrLayer(nID
,OUString());
250 pLay
->SetStandardLayer();
251 pLay
->SetModel(pModel
);
253 aLayer
.push_back(pLay
);
255 aLayer
.insert(aLayer
.begin() + nPos
, pLay
);
260 sal_uInt16
SdrLayerAdmin::GetLayerPos(SdrLayer
* pLayer
) const
262 sal_uIntPtr nRet
=SDRLAYER_NOTFOUND
;
264 std::vector
<SdrLayer
*>::const_iterator it
= std::find(aLayer
.begin(), aLayer
.end(), pLayer
);
265 if (it
==aLayer
.end()) {
266 nRet
=SDRLAYER_NOTFOUND
;
268 nRet
=it
- aLayer
.begin();
271 return sal_uInt16(nRet
);
274 SdrLayer
* SdrLayerAdmin::GetLayer(const OUString
& rName
, bool bInherited
)
276 return (SdrLayer
*)(((const SdrLayerAdmin
*)this)->GetLayer(rName
, bInherited
));
279 const SdrLayer
* SdrLayerAdmin::GetLayer(const OUString
& rName
, bool /*bInherited*/) const
282 const SdrLayer
* pLay
= NULL
;
284 while(i
< GetLayerCount() && !pLay
)
286 if (rName
== GetLayer(i
)->GetName())
294 pLay
= pParent
->GetLayer(rName
, true);
300 SdrLayerID
SdrLayerAdmin::GetLayerID(const OUString
& rName
, bool bInherited
) const
302 SdrLayerID nRet
=SDRLAYER_NOTFOUND
;
303 const SdrLayer
* pLay
=GetLayer(rName
,bInherited
);
304 if (pLay
!=NULL
) nRet
=pLay
->GetID();
308 const SdrLayer
* SdrLayerAdmin::GetLayerPerID(sal_uInt16 nID
) const
311 const SdrLayer
* pLay
=NULL
;
312 while (i
<GetLayerCount() && pLay
==NULL
) {
313 if (nID
==GetLayer(i
)->GetID()) pLay
=GetLayer(i
);
319 // Global LayerIDs begin at 0 and increase,
320 // local LayerIDs begin at 254 and decrease;
321 // 255 is reserved for SDRLAYER_NOTFOUND.
323 SdrLayerID
SdrLayerAdmin::GetUniqueLayerID() const
326 bool bDown
= (pParent
== NULL
);
328 for (j
=0; j
<GetLayerCount(); j
++)
330 aSet
.Set(GetLayer((sal_uInt16
)j
)->GetID());
336 while (i
&& aSet
.IsSet(sal_uInt8(i
)))
344 while (i
<=254 && aSet
.IsSet(sal_uInt8(i
)))
352 void SdrLayerAdmin::SetControlLayerName(const OUString
& rNewName
)
354 maControlLayerName
= rNewName
;
357 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */