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 <svx/sdr/properties/defaultproperties.hxx>
21 #include <svx/sdr/properties/itemsettools.hxx>
22 #include <svl/itemset.hxx>
23 #include <svl/whiter.hxx>
26 #include <svx/svdobj.hxx>
27 #include <svx/svddef.hxx>
28 #include <svx/svdpool.hxx>
29 #include <editeng/eeitem.hxx>
31 //////////////////////////////////////////////////////////////////////////////
37 SfxItemSet
& DefaultProperties::CreateObjectSpecificItemSet(SfxItemPool
& rPool
)
39 // Basic implementation; Basic object has NO attributes
40 return *(new SfxItemSet(rPool
));
43 DefaultProperties::DefaultProperties(SdrObject
& rObj
)
44 : BaseProperties(rObj
),
49 DefaultProperties::DefaultProperties(const DefaultProperties
& rProps
, SdrObject
& rObj
)
50 : BaseProperties(rObj
),
55 mpItemSet
= rProps
.mpItemSet
->Clone(sal_True
);
57 // do not keep parent info, this may be changed by later construrtors.
58 // This class just copies the ItemSet, ignore parent.
59 if(mpItemSet
&& mpItemSet
->GetParent())
61 mpItemSet
->SetParent(0L);
66 BaseProperties
& DefaultProperties::Clone(SdrObject
& rObj
) const
68 return *(new DefaultProperties(*this, rObj
));
71 DefaultProperties::~DefaultProperties()
80 const SfxItemSet
& DefaultProperties::GetObjectItemSet() const
84 ((DefaultProperties
*)this)->mpItemSet
= &(((DefaultProperties
*)this)->CreateObjectSpecificItemSet(*GetSdrObject().GetObjectItemPool()));
85 ((DefaultProperties
*)this)->ForceDefaultAttributes();
88 DBG_ASSERT(mpItemSet
, "Could not create an SfxItemSet(!)");
93 void DefaultProperties::SetObjectItem(const SfxPoolItem
& rItem
)
95 const sal_uInt16
nWhichID(rItem
.Which());
97 if(AllowItemChange(nWhichID
, &rItem
))
99 ItemChange(nWhichID
, &rItem
);
100 PostItemChange(nWhichID
);
102 SfxItemSet
aSet(*GetSdrObject().GetObjectItemPool(), nWhichID
, nWhichID
);
104 ItemSetChanged(aSet
);
108 void DefaultProperties::SetObjectItemDirect(const SfxPoolItem
& rItem
)
110 const sal_uInt16
nWhichID(rItem
.Which());
112 if(AllowItemChange(nWhichID
, &rItem
))
114 ItemChange(nWhichID
, &rItem
);
118 void DefaultProperties::ClearObjectItem(const sal_uInt16 nWhich
)
120 if(AllowItemChange(nWhich
))
123 PostItemChange(nWhich
);
127 SfxItemSet
aSet(*GetSdrObject().GetObjectItemPool(), nWhich
, nWhich
, 0, 0);
128 ItemSetChanged(aSet
);
133 void DefaultProperties::ClearObjectItemDirect(const sal_uInt16 nWhich
)
135 if(AllowItemChange(nWhich
))
141 void DefaultProperties::SetObjectItemSet(const SfxItemSet
& rSet
)
143 SfxWhichIter
aWhichIter(rSet
);
144 sal_uInt16
nWhich(aWhichIter
.FirstWhich());
145 const SfxPoolItem
*pPoolItem
;
146 std::vector
< sal_uInt16
> aPostItemChangeList
;
147 sal_Bool
bDidChange(sal_False
);
148 SfxItemSet
aSet(*GetSdrObject().GetObjectItemPool(), SDRATTR_START
, EE_ITEMS_END
);
150 // give a hint to STL_Vector
151 aPostItemChangeList
.reserve(rSet
.Count());
155 if(SFX_ITEM_SET
== rSet
.GetItemState(nWhich
, sal_False
, &pPoolItem
))
157 if(AllowItemChange(nWhich
, pPoolItem
))
159 bDidChange
= sal_True
;
160 ItemChange(nWhich
, pPoolItem
);
161 aPostItemChangeList
.push_back( nWhich
);
162 aSet
.Put(*pPoolItem
);
166 nWhich
= aWhichIter
.NextWhich();
171 for (std::vector
< sal_uInt16
>::const_iterator
aIter(aPostItemChangeList
.begin()), aEnd(aPostItemChangeList
.end()); aIter
!= aEnd
; ++aIter
)
173 PostItemChange(*aIter
);
176 ItemSetChanged(aSet
);
180 void DefaultProperties::ItemSetChanged(const SfxItemSet
& /*rSet*/)
184 sal_Bool
DefaultProperties::AllowItemChange(const sal_uInt16
/*nWhich*/, const SfxPoolItem
* /*pNewItem*/) const
189 void DefaultProperties::ItemChange(const sal_uInt16
/*nWhich*/, const SfxPoolItem
* /*pNewItem*/)
193 void DefaultProperties::PostItemChange(const sal_uInt16 nWhich
)
195 if( (nWhich
== XATTR_FILLSTYLE
) && (mpItemSet
!= NULL
) )
196 CleanupFillProperties(*mpItemSet
);
199 void DefaultProperties::SetStyleSheet(SfxStyleSheet
* /*pNewStyleSheet*/, sal_Bool
/*bDontRemoveHardAttr*/)
201 // no StyleSheet in DefaultProperties
204 SfxStyleSheet
* DefaultProperties::GetStyleSheet() const
206 // no StyleSheet in DefaultProperties
210 void DefaultProperties::ForceDefaultAttributes()
214 void DefaultProperties::Scale(const Fraction
& rScale
)
218 ScaleItemSet(*mpItemSet
, rScale
);
221 } // end of namespace properties
222 } // end of namespace sdr
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */