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 <sal/config.h>
22 #include <svx/sdr/properties/defaultproperties.hxx>
23 #include <sdr/properties/itemsettools.hxx>
24 #include <svl/itemset.hxx>
25 #include <svl/whiter.hxx>
26 #include <vcl/outdev.hxx>
28 #include <svx/svdobj.hxx>
29 #include <svx/svddef.hxx>
30 #include <svx/svdpool.hxx>
31 #include <editeng/eeitem.hxx>
32 #include <libxml/xmlwriter.h>
33 #include <svx/svdmodel.hxx>
34 #include <svx/svdtrans.hxx>
35 #include <svx/xbtmpit.hxx>
41 std::unique_ptr
<SfxItemSet
> DefaultProperties::CreateObjectSpecificItemSet(SfxItemPool
& rPool
)
43 // Basic implementation; Basic object has NO attributes
44 return std::make_unique
<SfxItemSet
>(rPool
);
47 DefaultProperties::DefaultProperties(SdrObject
& rObj
)
48 : BaseProperties(rObj
)
52 DefaultProperties::DefaultProperties(const DefaultProperties
& rProps
, SdrObject
& rObj
)
53 : BaseProperties(rObj
)
57 // Clone may be to another model and thus another ItemPool.
58 // SfxItemSet supports that thus we are able to Clone all
59 // SfxItemState::SET items to the target pool.
60 mpItemSet
= rProps
.mpItemSet
->Clone(
62 &rObj
.getSdrModelFromSdrObject().GetItemPool());
64 // React on ModelChange: If metric has changed, scale items.
65 // As seen above, clone is supported, but scale is not included,
66 // thus: TTTT maybe add scale to SfxItemSet::Clone() (?)
67 // tdf#117707 correct ModelChange detection
68 const bool bModelChange(&rObj
.getSdrModelFromSdrObject() != &rProps
.GetSdrObject().getSdrModelFromSdrObject());
72 const MapUnit
aOldUnit(rProps
.GetSdrObject().getSdrModelFromSdrObject().GetScaleUnit());
73 const MapUnit
aNewUnit(rObj
.getSdrModelFromSdrObject().GetScaleUnit());
74 const bool bScaleUnitChanged(aNewUnit
!= aOldUnit
);
78 const Fraction
aMetricFactor(GetMapFactor(aOldUnit
, aNewUnit
).X());
80 ScaleItemSet(*mpItemSet
, aMetricFactor
);
84 // do not keep parent info, this may be changed by later constructors.
85 // This class just copies the ItemSet, ignore parent.
86 if(mpItemSet
&& mpItemSet
->GetParent())
88 mpItemSet
->SetParent(nullptr);
93 std::unique_ptr
<BaseProperties
> DefaultProperties::Clone(SdrObject
& rObj
) const
95 return std::unique_ptr
<BaseProperties
>(new DefaultProperties(*this, rObj
));
98 DefaultProperties::~DefaultProperties() {}
100 const SfxItemSet
& DefaultProperties::GetObjectItemSet() const
104 const_cast<DefaultProperties
*>(this)->mpItemSet
= const_cast<DefaultProperties
*>(this)->CreateObjectSpecificItemSet(GetSdrObject().GetObjectItemPool());
105 const_cast<DefaultProperties
*>(this)->ForceDefaultAttributes();
108 assert(mpItemSet
&& "Could not create an SfxItemSet(!)");
113 void DefaultProperties::SetObjectItem(const SfxPoolItem
& rItem
)
115 const sal_uInt16
nWhichID(rItem
.Which());
117 if(AllowItemChange(nWhichID
, &rItem
))
119 ItemChange(nWhichID
, &rItem
);
120 PostItemChange(nWhichID
);
122 SfxItemSet
aSet(GetSdrObject().GetObjectItemPool(), {{nWhichID
, nWhichID
}});
124 ItemSetChanged(aSet
);
128 void DefaultProperties::SetObjectItemDirect(const SfxPoolItem
& rItem
)
130 const sal_uInt16
nWhichID(rItem
.Which());
132 if(AllowItemChange(nWhichID
, &rItem
))
134 ItemChange(nWhichID
, &rItem
);
138 void DefaultProperties::ClearObjectItem(const sal_uInt16 nWhich
)
140 if(AllowItemChange(nWhich
))
143 PostItemChange(nWhich
);
147 SfxItemSet
aSet(GetSdrObject().GetObjectItemPool(), {{nWhich
, nWhich
}});
148 ItemSetChanged(aSet
);
153 void DefaultProperties::ClearObjectItemDirect(const sal_uInt16 nWhich
)
155 if(AllowItemChange(nWhich
))
161 void DefaultProperties::SetObjectItemSet(const SfxItemSet
& rSet
)
163 if (rSet
.HasItem(XATTR_FILLBITMAP
))
165 const XFillBitmapItem
* pItem
= rSet
.GetItem(XATTR_FILLBITMAP
);
166 const std::shared_ptr
<VectorGraphicData
>& pVectorData
167 = pItem
->GetGraphicObject().GetGraphic().getVectorGraphicData();
170 // Shape is filled by a vector graphic: tell it our size as a hint.
171 basegfx::B2DTuple aSizeHint
;
172 aSizeHint
.setX(GetSdrObject().GetSnapRect().getWidth());
173 aSizeHint
.setY(GetSdrObject().GetSnapRect().getHeight());
174 pVectorData
->setSizeHint(aSizeHint
);
178 SfxWhichIter
aWhichIter(rSet
);
179 sal_uInt16
nWhich(aWhichIter
.FirstWhich());
180 const SfxPoolItem
*pPoolItem
;
181 std::vector
< sal_uInt16
> aPostItemChangeList
;
182 bool bDidChange(false);
183 SfxItemSet
aSet(GetSdrObject().GetObjectItemPool(), svl::Items
<SDRATTR_START
, EE_ITEMS_END
>{});
185 // give a hint to STL_Vector
186 aPostItemChangeList
.reserve(rSet
.Count());
190 if(SfxItemState::SET
== rSet
.GetItemState(nWhich
, false, &pPoolItem
))
192 if(AllowItemChange(nWhich
, pPoolItem
))
195 ItemChange(nWhich
, pPoolItem
);
196 aPostItemChangeList
.push_back( nWhich
);
197 aSet
.Put(*pPoolItem
);
201 nWhich
= aWhichIter
.NextWhich();
206 for (const auto& rItem
: aPostItemChangeList
)
208 PostItemChange(rItem
);
211 ItemSetChanged(aSet
);
215 void DefaultProperties::ItemSetChanged(const SfxItemSet
& /*rSet*/)
219 bool DefaultProperties::AllowItemChange(const sal_uInt16
/*nWhich*/, const SfxPoolItem
* /*pNewItem*/) const
224 void DefaultProperties::ItemChange(const sal_uInt16
/*nWhich*/, const SfxPoolItem
* /*pNewItem*/)
228 void DefaultProperties::PostItemChange(const sal_uInt16 nWhich
)
230 if( (nWhich
== XATTR_FILLSTYLE
) && (mpItemSet
!= nullptr) )
231 CleanupFillProperties(*mpItemSet
);
234 void DefaultProperties::SetStyleSheet(SfxStyleSheet
* /*pNewStyleSheet*/, bool /*bDontRemoveHardAttr*/)
236 // no StyleSheet in DefaultProperties
239 SfxStyleSheet
* DefaultProperties::GetStyleSheet() const
241 // no StyleSheet in DefaultProperties
245 void DefaultProperties::ForceDefaultAttributes()
249 void DefaultProperties::dumpAsXml(xmlTextWriterPtr pWriter
) const
251 xmlTextWriterStartElement(pWriter
, BAD_CAST("DefaultProperties"));
252 BaseProperties::dumpAsXml(pWriter
);
253 mpItemSet
->dumpAsXml(pWriter
);
254 xmlTextWriterEndElement(pWriter
);
256 } // end of namespace properties
257 } // end of namespace sdr
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */