Update ooo320-m1
[ooovba.git] / svx / source / sdr / properties / defaultproperties.cxx
blobde3021062b22bc1539a88dc0994eaa3baacbf720
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: defaultproperties.cxx,v $
10 * $Revision: 1.9 $
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 <svx/sdr/properties/defaultproperties.hxx>
34 #include <svx/sdr/properties/itemsettools.hxx>
35 #include <svtools/itemset.hxx>
36 #include <svtools/whiter.hxx>
38 #include <vector>
39 #include <svx/svdobj.hxx>
40 #include <svx/svddef.hxx>
41 #include <svx/svdpool.hxx>
42 #include <svx/eeitem.hxx>
44 //////////////////////////////////////////////////////////////////////////////
46 namespace sdr
48 namespace properties
50 SfxItemSet& DefaultProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
52 // Basic implementation; Basic object has NO attributes
53 return *(new SfxItemSet(rPool));
56 DefaultProperties::DefaultProperties(SdrObject& rObj)
57 : BaseProperties(rObj),
58 mpItemSet(0L)
62 DefaultProperties::DefaultProperties(const DefaultProperties& rProps, SdrObject& rObj)
63 : BaseProperties(rObj),
64 mpItemSet(0L)
66 if(rProps.mpItemSet)
68 mpItemSet = rProps.mpItemSet->Clone(TRUE);
70 // do not keep parent info, this may be changed by later construrtors.
71 // This class just copies the ItemSet, ignore parent.
72 if(mpItemSet && mpItemSet->GetParent())
74 mpItemSet->SetParent(0L);
79 BaseProperties& DefaultProperties::Clone(SdrObject& rObj) const
81 return *(new DefaultProperties(*this, rObj));
84 DefaultProperties::~DefaultProperties()
86 if(mpItemSet)
88 delete mpItemSet;
89 mpItemSet = 0L;
93 const SfxItemSet& DefaultProperties::GetObjectItemSet() const
95 if(!mpItemSet)
97 ((DefaultProperties*)this)->mpItemSet = &(((DefaultProperties*)this)->CreateObjectSpecificItemSet(*GetSdrObject().GetObjectItemPool()));
98 ((DefaultProperties*)this)->ForceDefaultAttributes();
101 DBG_ASSERT(mpItemSet, "Could not create an SfxItemSet(!)");
103 return *mpItemSet;
106 void DefaultProperties::SetObjectItem(const SfxPoolItem& rItem)
108 const sal_uInt16 nWhichID(rItem.Which());
110 if(AllowItemChange(nWhichID, &rItem))
112 ItemChange(nWhichID, &rItem);
113 PostItemChange(nWhichID);
115 SfxItemSet aSet(*GetSdrObject().GetObjectItemPool(), nWhichID, nWhichID);
116 aSet.Put(rItem);
117 ItemSetChanged(aSet);
121 void DefaultProperties::SetObjectItemDirect(const SfxPoolItem& rItem)
123 const sal_uInt16 nWhichID(rItem.Which());
125 if(AllowItemChange(nWhichID, &rItem))
127 ItemChange(nWhichID, &rItem);
131 void DefaultProperties::ClearObjectItem(const sal_uInt16 nWhich)
133 if(AllowItemChange(nWhich))
135 ItemChange(nWhich);
136 PostItemChange(nWhich);
138 if(nWhich)
140 SfxItemSet aSet(*GetSdrObject().GetObjectItemPool(), nWhich, nWhich, 0, 0);
141 ItemSetChanged(aSet);
146 void DefaultProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
148 if(AllowItemChange(nWhich))
150 ItemChange(nWhich);
154 void DefaultProperties::SetObjectItemSet(const SfxItemSet& rSet)
156 SfxWhichIter aWhichIter(rSet);
157 sal_uInt16 nWhich(aWhichIter.FirstWhich());
158 const SfxPoolItem *pPoolItem;
159 std::vector< sal_uInt16 > aPostItemChangeList;
160 sal_Bool bDidChange(sal_False);
161 SfxItemSet aSet(*GetSdrObject().GetObjectItemPool(), SDRATTR_START, EE_ITEMS_END, 0, 0);
163 // give a hint to STL_Vector
164 aPostItemChangeList.reserve(rSet.Count());
166 while(nWhich)
168 if(SFX_ITEM_SET == rSet.GetItemState(nWhich, FALSE, &pPoolItem))
170 if(AllowItemChange(nWhich, pPoolItem))
172 bDidChange = sal_True;
173 ItemChange(nWhich, pPoolItem);
174 aPostItemChangeList.push_back( nWhich );
175 aSet.Put(*pPoolItem);
179 nWhich = aWhichIter.NextWhich();
182 if(bDidChange)
184 std::vector< sal_uInt16 >::iterator aIter = aPostItemChangeList.begin();
185 const std::vector< sal_uInt16 >::iterator aEnd = aPostItemChangeList.end();
187 while(aIter != aEnd)
189 PostItemChange(*aIter);
190 aIter++;
193 ItemSetChanged(aSet);
197 void DefaultProperties::ItemSetChanged(const SfxItemSet& /*rSet*/)
201 sal_Bool DefaultProperties::AllowItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/) const
203 return sal_True;
206 void DefaultProperties::ItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/)
210 void DefaultProperties::PostItemChange(const sal_uInt16 /*nWhich*/)
214 void DefaultProperties::SetStyleSheet(SfxStyleSheet* /*pNewStyleSheet*/, sal_Bool /*bDontRemoveHardAttr*/)
216 // no StyleSheet in DefaultProperties
219 SfxStyleSheet* DefaultProperties::GetStyleSheet() const
221 // no StyleSheet in DefaultProperties
222 return 0L;
225 void DefaultProperties::ForceDefaultAttributes()
229 void DefaultProperties::Scale(const Fraction& rScale)
231 if(mpItemSet)
233 ScaleItemSet(*mpItemSet, rScale);
236 } // end of namespace properties
237 } // end of namespace sdr
239 //////////////////////////////////////////////////////////////////////////////
240 // eof