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
);
144 SdrLayerAdmin::SdrLayerAdmin(SdrLayerAdmin
* pNewParent
):
148 maControlLayerName("Controls")
152 SdrLayerAdmin::SdrLayerAdmin(const SdrLayerAdmin
& rSrcLayerAdmin
):
156 maControlLayerName("Controls")
158 *this = rSrcLayerAdmin
;
161 SdrLayerAdmin::~SdrLayerAdmin()
166 void SdrLayerAdmin::ClearLayer()
168 for( std::vector
<SdrLayer
*>::const_iterator it
= aLayer
.begin(); it
!= aLayer
.end(); ++it
)
173 const SdrLayerAdmin
& SdrLayerAdmin::operator=(const SdrLayerAdmin
& rSrcLayerAdmin
)
176 pParent
=rSrcLayerAdmin
.pParent
;
178 sal_uInt16 nCount
=rSrcLayerAdmin
.GetLayerCount();
179 for (i
=0; i
<nCount
; i
++) {
180 aLayer
.push_back(new SdrLayer(*rSrcLayerAdmin
.GetLayer(i
)));
185 bool SdrLayerAdmin::operator==(const SdrLayerAdmin
& rCmpLayerAdmin
) const
187 if (pParent
!=rCmpLayerAdmin
.pParent
||
188 aLayer
.size()!=rCmpLayerAdmin
.aLayer
.size())
191 sal_uInt16 nCount
=GetLayerCount();
193 while (bOk
&& i
<nCount
) {
194 bOk
=*GetLayer(i
)==*rCmpLayerAdmin
.GetLayer(i
);
200 void SdrLayerAdmin::SetModel(SdrModel
* pNewModel
)
202 if (pNewModel
!=pModel
) {
204 sal_uInt16 nCount
=GetLayerCount();
206 for (i
=0; i
<nCount
; i
++) {
207 GetLayer(i
)->SetModel(pNewModel
);
212 void SdrLayerAdmin::Broadcast() const
215 SdrHint
aHint(HINT_LAYERORDERCHG
);
216 pModel
->Broadcast(aHint
);
217 pModel
->SetChanged();
221 SdrLayer
* SdrLayerAdmin::RemoveLayer(sal_uInt16 nPos
)
223 SdrLayer
* pRetLayer
=aLayer
[nPos
];
224 aLayer
.erase(aLayer
.begin()+nPos
);
229 SdrLayer
* SdrLayerAdmin::NewLayer(const OUString
& rName
, sal_uInt16 nPos
)
231 SdrLayerID nID
=GetUniqueLayerID();
232 SdrLayer
* pLay
=new SdrLayer(nID
,rName
);
233 pLay
->SetModel(pModel
);
235 aLayer
.push_back(pLay
);
237 aLayer
.insert(aLayer
.begin() + nPos
, pLay
);
242 SdrLayer
* SdrLayerAdmin::NewStandardLayer(sal_uInt16 nPos
)
244 SdrLayerID nID
=GetUniqueLayerID();
245 SdrLayer
* pLay
=new SdrLayer(nID
,OUString());
246 pLay
->SetStandardLayer();
247 pLay
->SetModel(pModel
);
249 aLayer
.push_back(pLay
);
251 aLayer
.insert(aLayer
.begin() + nPos
, pLay
);
256 sal_uInt16
SdrLayerAdmin::GetLayerPos(SdrLayer
* pLayer
) const
258 sal_uIntPtr nRet
=SDRLAYER_NOTFOUND
;
260 std::vector
<SdrLayer
*>::const_iterator it
= std::find(aLayer
.begin(), aLayer
.end(), pLayer
);
261 if (it
==aLayer
.end()) {
262 nRet
=SDRLAYER_NOTFOUND
;
264 nRet
=it
- aLayer
.begin();
267 return sal_uInt16(nRet
);
270 SdrLayer
* SdrLayerAdmin::GetLayer(const OUString
& rName
, bool bInherited
)
272 return const_cast<SdrLayer
*>(((const SdrLayerAdmin
*)this)->GetLayer(rName
, bInherited
));
275 const SdrLayer
* SdrLayerAdmin::GetLayer(const OUString
& rName
, bool /*bInherited*/) const
278 const SdrLayer
* pLay
= NULL
;
280 while(i
< GetLayerCount() && !pLay
)
282 if (rName
== GetLayer(i
)->GetName())
290 pLay
= pParent
->GetLayer(rName
, true);
296 SdrLayerID
SdrLayerAdmin::GetLayerID(const OUString
& rName
, bool bInherited
) const
298 SdrLayerID nRet
=SDRLAYER_NOTFOUND
;
299 const SdrLayer
* pLay
=GetLayer(rName
,bInherited
);
300 if (pLay
!=NULL
) nRet
=pLay
->GetID();
304 const SdrLayer
* SdrLayerAdmin::GetLayerPerID(sal_uInt16 nID
) const
307 const SdrLayer
* pLay
=NULL
;
308 while (i
<GetLayerCount() && pLay
==NULL
) {
309 if (nID
==GetLayer(i
)->GetID()) pLay
=GetLayer(i
);
315 // Global LayerIDs begin at 0 and increase,
316 // local LayerIDs begin at 254 and decrease;
317 // 255 is reserved for SDRLAYER_NOTFOUND.
319 SdrLayerID
SdrLayerAdmin::GetUniqueLayerID() const
322 bool bDown
= (pParent
== NULL
);
324 for (j
=0; j
<GetLayerCount(); j
++)
326 aSet
.Set(GetLayer((sal_uInt16
)j
)->GetID());
332 while (i
&& aSet
.IsSet(sal_uInt8(i
)))
340 while (i
<=254 && aSet
.IsSet(sal_uInt8(i
)))
348 void SdrLayerAdmin::SetControlLayerName(const OUString
& rNewName
)
350 maControlLayerName
= rNewName
;
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */