LibreOffice Module svx (master)  1
defaultproperties.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <sal/config.h>
21 
24 #include <svl/itemset.hxx>
25 #include <svl/whiter.hxx>
26 #include <vector>
27 #include <svx/svdobj.hxx>
28 #include <svx/svddef.hxx>
29 #include <editeng/eeitem.hxx>
30 #include <libxml/xmlwriter.h>
31 #include <svx/svdmodel.hxx>
32 #include <svx/svdtrans.hxx>
33 #include <svx/xbtmpit.hxx>
34 
35 namespace sdr::properties
36 {
38  {
39  // Basic implementation; Basic object has NO attributes
40  return SfxItemSet(rPool);
41  }
42 
44  : BaseProperties(rObj)
45  {
46  }
47 
49  : BaseProperties(rObj)
50  {
51  if(!rProps.mxItemSet)
52  return;
53 
54  // Clone may be to another model and thus another ItemPool.
55  // SfxItemSet supports that thus we are able to Clone all
56  // SfxItemState::SET items to the target pool.
57  mxItemSet.emplace(rProps.mxItemSet->CloneAsValue(
58  true,
60 
61  // React on ModelChange: If metric has changed, scale items.
62  // As seen above, clone is supported, but scale is not included,
63  // thus: TTTT maybe add scale to SfxItemSet::Clone() (?)
64  // tdf#117707 correct ModelChange detection
65  const bool bModelChange(&rObj.getSdrModelFromSdrObject() != &rProps.GetSdrObject().getSdrModelFromSdrObject());
66 
67  if(bModelChange)
68  {
69  const MapUnit aOldUnit(rProps.GetSdrObject().getSdrModelFromSdrObject().GetScaleUnit());
70  const MapUnit aNewUnit(rObj.getSdrModelFromSdrObject().GetScaleUnit());
71  const bool bScaleUnitChanged(aNewUnit != aOldUnit);
72 
73  if(bScaleUnitChanged)
74  {
75  const Fraction aMetricFactor(GetMapFactor(aOldUnit, aNewUnit).X());
76 
77  ScaleItemSet(*mxItemSet, aMetricFactor);
78  }
79  }
80 
81  // do not keep parent info, this may be changed by later constructors.
82  // This class just copies the ItemSet, ignore parent.
83  if(mxItemSet && mxItemSet->GetParent())
84  {
85  mxItemSet->SetParent(nullptr);
86  }
87  }
88 
89  std::unique_ptr<BaseProperties> DefaultProperties::Clone(SdrObject& rObj) const
90  {
91  return std::unique_ptr<BaseProperties>(new DefaultProperties(*this, rObj));
92  }
93 
95 
97  {
98  if(!mxItemSet)
99  {
100  mxItemSet.emplace(const_cast<DefaultProperties*>(this)->CreateObjectSpecificItemSet(GetSdrObject().GetObjectItemPool()));
101  const_cast<DefaultProperties*>(this)->ForceDefaultAttributes();
102  }
103 
104  assert(mxItemSet && "Could not create an SfxItemSet(!)");
105 
106  return *mxItemSet;
107  }
108 
110  {
111  const sal_uInt16 nWhichID(rItem.Which());
112 
113  if(AllowItemChange(nWhichID, &rItem))
114  {
115  ItemChange(nWhichID, &rItem);
116  PostItemChange(nWhichID);
117 
119  {
120  SfxItemSet aSet(GetSdrObject().GetObjectItemPool(), nWhichID, nWhichID);
121  aSet.Put(rItem);
122  ItemSetChanged(&aSet);
123  }
124  else
125  ItemSetChanged(nullptr);
126  }
127  }
128 
130  {
131  const sal_uInt16 nWhichID(rItem.Which());
132 
133  if(AllowItemChange(nWhichID, &rItem))
134  {
135  ItemChange(nWhichID, &rItem);
136  }
137  }
138 
139  void DefaultProperties::ClearObjectItem(const sal_uInt16 nWhich)
140  {
141  if(AllowItemChange(nWhich))
142  {
143  ItemChange(nWhich);
144  PostItemChange(nWhich);
145 
146  if(nWhich)
147  {
149  {
150  SfxItemSet aSet(GetSdrObject().GetObjectItemPool(), nWhich, nWhich);
151  ItemSetChanged(&aSet);
152  }
153  else
154  ItemSetChanged(nullptr);
155  }
156  }
157  }
158 
159  void DefaultProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
160  {
161  if(AllowItemChange(nWhich))
162  {
163  ItemChange(nWhich);
164  }
165  }
166 
168  {
169  if (rSet.HasItem(XATTR_FILLBITMAP))
170  {
171  const XFillBitmapItem* pItem = rSet.GetItem(XATTR_FILLBITMAP);
172  const std::shared_ptr<VectorGraphicData>& pVectorData
174  if (pVectorData)
175  {
176  // Shape is filled by a vector graphic: tell it our size as a hint.
177  basegfx::B2DTuple aSizeHint;
178  aSizeHint.setX(GetSdrObject().GetSnapRect().getWidth());
179  aSizeHint.setY(GetSdrObject().GetSnapRect().getHeight());
180  pVectorData->setSizeHint(aSizeHint);
181  }
182  }
183 
184  SfxWhichIter aWhichIter(rSet);
185  sal_uInt16 nWhich(aWhichIter.FirstWhich());
186  const SfxPoolItem *pPoolItem;
187  std::vector< sal_uInt16 > aPostItemChangeList;
188  bool bDidChange(false);
189  std::optional<SfxItemSet> aSet;
191  aSet.emplace(GetSdrObject().GetObjectItemPool(), svl::Items<SDRATTR_START, EE_ITEMS_END>);
192 
193  // give a hint to STL_Vector
194  aPostItemChangeList.reserve(rSet.Count());
195 
196  while(nWhich)
197  {
198  if(SfxItemState::SET == rSet.GetItemState(nWhich, false, &pPoolItem))
199  {
200  if(AllowItemChange(nWhich, pPoolItem))
201  {
202  bDidChange = true;
203  ItemChange(nWhich, pPoolItem);
204  aPostItemChangeList.push_back( nWhich );
205  if (aSet)
206  aSet->Put(*pPoolItem);
207  }
208  }
209 
210  nWhich = aWhichIter.NextWhich();
211  }
212 
213  if(bDidChange)
214  {
215  for (const auto& rItem : aPostItemChangeList)
216  {
217  PostItemChange(rItem);
218  }
219 
220  if (aSet)
221  ItemSetChanged(&*aSet);
222  else
223  ItemSetChanged(nullptr);
224  }
225  }
226 
228  {
229  }
230 
231  bool DefaultProperties::AllowItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/) const
232  {
233  return true;
234  }
235 
236  void DefaultProperties::ItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/)
237  {
238  }
239 
240  void DefaultProperties::PostItemChange(const sal_uInt16 nWhich )
241  {
242  if( (nWhich == XATTR_FILLSTYLE) && mxItemSet )
244  }
245 
246  void DefaultProperties::SetStyleSheet(SfxStyleSheet* /*pNewStyleSheet*/, bool /*bDontRemoveHardAttr*/)
247  {
248  // no StyleSheet in DefaultProperties
249  }
250 
252  {
253  // no StyleSheet in DefaultProperties
254  return nullptr;
255  }
256 
258  {
259  }
260 
262  {
263  (void)xmlTextWriterStartElement(pWriter, BAD_CAST("DefaultProperties"));
264  BaseProperties::dumpAsXml(pWriter);
265  if (mxItemSet)
266  {
267  mxItemSet->dumpAsXml(pWriter);
268  }
269  (void)xmlTextWriterEndElement(pWriter);
270  }
271 } // end of namespace
272 
273 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _xmlTextWriter * xmlTextWriterPtr
virtual void SetObjectItemSet(const SfxItemSet &rSet) override
virtual void SetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr) override
constexpr TypedWhichId< XFillStyleItem > XATTR_FILLSTYLE(XATTR_FILL_FIRST)
virtual const SfxItemSet & GetObjectItemSet() const override
virtual void PostItemChange(const sal_uInt16 nWhich) override
sal_uInt16 FirstWhich()
virtual void SetObjectItemDirect(const SfxPoolItem &rItem) override
virtual void ItemSetChanged(const SfxItemSet *) override
void setX(double fX)
sal_uInt16 NextWhich()
virtual SfxStyleSheet * GetStyleSheet() const override
virtual void SetObjectItem(const SfxPoolItem &rItem) override
MapUnit GetScaleUnit() const
Definition: svdmodel.hxx:364
virtual void ItemChange(const sal_uInt16 nWhich, const SfxPoolItem *pNewItem=nullptr) override
const GraphicObject & GetGraphicObject() const
Definition: xbtmpit.hxx:56
void dumpAsXml(xmlTextWriterPtr pWriter) const override
void ScaleItemSet(SfxItemSet &rSet, const Fraction &rScale)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
void CleanupFillProperties(SfxItemSet &rItemSet)
Definition: properties.cxx:162
constexpr TypedWhichId< XFillBitmapItem > XATTR_FILLBITMAP(XATTR_FILL_FIRST+4)
sal_uInt16 Count() const
virtual bool WantItemSetInItemSetChanged() const
Definition: properties.hxx:110
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: properties.cxx:156
SdrModel & getSdrModelFromSdrObject() const
Definition: svdobj.cxx:279
Abstract DrawObject.
Definition: svdobj.hxx:259
virtual SfxItemSet CreateObjectSpecificItemSet(SfxItemPool &rPool) override
void setY(double fY)
virtual bool AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem *pNewItem=nullptr) const override
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
FrPair GetMapFactor(MapUnit eS, MapUnit eD)
Definition: svdtrans.cxx:612
const Graphic & GetGraphic() const
bool HasItem(sal_uInt16 nWhich, const SfxPoolItem **ppItem=nullptr) const
virtual void ClearObjectItemDirect(const sal_uInt16 nWhich) override
std::optional< SfxItemSet > mxItemSet
MapUnit
const SfxItemPool & GetItemPool() const
Definition: svdmodel.hxx:311
const SdrObject & GetSdrObject() const
Definition: properties.cxx:59
const std::shared_ptr< VectorGraphicData > & getVectorGraphicData() const
virtual std::unique_ptr< BaseProperties > Clone(SdrObject &rObj) const override
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
sal_uInt16 Which() const
virtual void ClearObjectItem(const sal_uInt16 nWhich=0) override
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo