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 {
37  std::unique_ptr<SfxItemSet> DefaultProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
38  {
39  // Basic implementation; Basic object has NO attributes
40  return std::make_unique<SfxItemSet>(rPool);
41  }
42 
44  : BaseProperties(rObj)
45  {
46  }
47 
49  : BaseProperties(rObj)
50  {
51  if(!rProps.mpItemSet)
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  mpItemSet = rProps.mpItemSet->Clone(
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(*mpItemSet, 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(mpItemSet && mpItemSet->GetParent())
84  {
85  mpItemSet->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(!mpItemSet)
99  {
100  const_cast<DefaultProperties*>(this)->mpItemSet = const_cast<DefaultProperties*>(this)->CreateObjectSpecificItemSet(GetSdrObject().GetObjectItemPool());
101  const_cast<DefaultProperties*>(this)->ForceDefaultAttributes();
102  }
103 
104  assert(mpItemSet && "Could not create an SfxItemSet(!)");
105 
106  return *mpItemSet;
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 
118  SfxItemSet aSet(GetSdrObject().GetObjectItemPool(), {{nWhichID, nWhichID}});
119  aSet.Put(rItem);
120  ItemSetChanged(aSet);
121  }
122  }
123 
125  {
126  const sal_uInt16 nWhichID(rItem.Which());
127 
128  if(AllowItemChange(nWhichID, &rItem))
129  {
130  ItemChange(nWhichID, &rItem);
131  }
132  }
133 
134  void DefaultProperties::ClearObjectItem(const sal_uInt16 nWhich)
135  {
136  if(AllowItemChange(nWhich))
137  {
138  ItemChange(nWhich);
139  PostItemChange(nWhich);
140 
141  if(nWhich)
142  {
143  SfxItemSet aSet(GetSdrObject().GetObjectItemPool(), {{nWhich, nWhich}});
144  ItemSetChanged(aSet);
145  }
146  }
147  }
148 
149  void DefaultProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
150  {
151  if(AllowItemChange(nWhich))
152  {
153  ItemChange(nWhich);
154  }
155  }
156 
158  {
159  if (rSet.HasItem(XATTR_FILLBITMAP))
160  {
161  const XFillBitmapItem* pItem = rSet.GetItem(XATTR_FILLBITMAP);
162  const std::shared_ptr<VectorGraphicData>& pVectorData
164  if (pVectorData)
165  {
166  // Shape is filled by a vector graphic: tell it our size as a hint.
167  basegfx::B2DTuple aSizeHint;
168  aSizeHint.setX(GetSdrObject().GetSnapRect().getWidth());
169  aSizeHint.setY(GetSdrObject().GetSnapRect().getHeight());
170  pVectorData->setSizeHint(aSizeHint);
171  }
172  }
173 
174  SfxWhichIter aWhichIter(rSet);
175  sal_uInt16 nWhich(aWhichIter.FirstWhich());
176  const SfxPoolItem *pPoolItem;
177  std::vector< sal_uInt16 > aPostItemChangeList;
178  bool bDidChange(false);
179  SfxItemSet aSet(GetSdrObject().GetObjectItemPool(), svl::Items<SDRATTR_START, EE_ITEMS_END>{});
180 
181  // give a hint to STL_Vector
182  aPostItemChangeList.reserve(rSet.Count());
183 
184  while(nWhich)
185  {
186  if(SfxItemState::SET == rSet.GetItemState(nWhich, false, &pPoolItem))
187  {
188  if(AllowItemChange(nWhich, pPoolItem))
189  {
190  bDidChange = true;
191  ItemChange(nWhich, pPoolItem);
192  aPostItemChangeList.push_back( nWhich );
193  aSet.Put(*pPoolItem);
194  }
195  }
196 
197  nWhich = aWhichIter.NextWhich();
198  }
199 
200  if(bDidChange)
201  {
202  for (const auto& rItem : aPostItemChangeList)
203  {
204  PostItemChange(rItem);
205  }
206 
207  ItemSetChanged(aSet);
208  }
209  }
210 
212  {
213  }
214 
215  bool DefaultProperties::AllowItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/) const
216  {
217  return true;
218  }
219 
220  void DefaultProperties::ItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/)
221  {
222  }
223 
224  void DefaultProperties::PostItemChange(const sal_uInt16 nWhich )
225  {
226  if( (nWhich == XATTR_FILLSTYLE) && (mpItemSet != nullptr) )
228  }
229 
230  void DefaultProperties::SetStyleSheet(SfxStyleSheet* /*pNewStyleSheet*/, bool /*bDontRemoveHardAttr*/)
231  {
232  // no StyleSheet in DefaultProperties
233  }
234 
236  {
237  // no StyleSheet in DefaultProperties
238  return nullptr;
239  }
240 
242  {
243  }
244 
246  {
247  xmlTextWriterStartElement(pWriter, BAD_CAST("DefaultProperties"));
248  BaseProperties::dumpAsXml(pWriter);
249  mpItemSet->dumpAsXml(pWriter);
250  xmlTextWriterEndElement(pWriter);
251  }
252 } // end of namespace
253 
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void setX(double fX)
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
std::unique_ptr< SfxItemSet > mpItemSet
sal_uInt16 NextWhich()
virtual SfxStyleSheet * GetStyleSheet() const override
virtual void SetObjectItem(const SfxPoolItem &rItem) override
MapUnit GetScaleUnit() const
Definition: svdmodel.hxx:367
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
virtual void ItemSetChanged(const SfxItemSet &rSet) override
#define X
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 void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: properties.cxx:156
SdrModel & getSdrModelFromSdrObject() const
Definition: svdobj.cxx:273
Abstract DrawObject.
Definition: svdobj.hxx:261
virtual bool AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem *pNewItem=nullptr) const override
FrPair GetMapFactor(MapUnit eS, MapUnit eD)
Definition: svdtrans.cxx:624
void setY(double fY)
const Graphic & GetGraphic() const
virtual std::unique_ptr< SfxItemSet > CreateObjectSpecificItemSet(SfxItemPool &rPool) override
bool HasItem(sal_uInt16 nWhich, const SfxPoolItem **ppItem=nullptr) const
virtual void ClearObjectItemDirect(const sal_uInt16 nWhich) override
MapUnit
const SfxItemPool & GetItemPool() const
Definition: svdmodel.hxx:314
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