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 <vcl/outdev.hxx>
27 #include <vector>
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 
36 namespace sdr
37 {
38  namespace properties
39  {
40  std::unique_ptr<SfxItemSet> DefaultProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
41  {
42  // Basic implementation; Basic object has NO attributes
43  return std::make_unique<SfxItemSet>(rPool);
44  }
45 
47  : BaseProperties(rObj)
48  {
49  }
50 
52  : BaseProperties(rObj)
53  {
54  if(rProps.mpItemSet)
55  {
56  // Clone may be to another model and thus another ItemPool.
57  // SfxItemSet supports that thus we are able to Clone all
58  // SfxItemState::SET items to the target pool.
59  mpItemSet = rProps.mpItemSet->Clone(
60  true,
62 
63  // React on ModelChange: If metric has changed, scale items.
64  // As seen above, clone is supported, but scale is not included,
65  // thus: TTTT maybe add scale to SfxItemSet::Clone() (?)
66  // tdf#117707 correct ModelChange detection
67  const bool bModelChange(&rObj.getSdrModelFromSdrObject() != &rProps.GetSdrObject().getSdrModelFromSdrObject());
68 
69  if(bModelChange)
70  {
71  const MapUnit aOldUnit(rProps.GetSdrObject().getSdrModelFromSdrObject().GetScaleUnit());
72  const MapUnit aNewUnit(rObj.getSdrModelFromSdrObject().GetScaleUnit());
73  const bool bScaleUnitChanged(aNewUnit != aOldUnit);
74 
75  if(bScaleUnitChanged)
76  {
77  const Fraction aMetricFactor(GetMapFactor(aOldUnit, aNewUnit).X());
78 
79  ScaleItemSet(*mpItemSet, aMetricFactor);
80  }
81  }
82 
83  // do not keep parent info, this may be changed by later constructors.
84  // This class just copies the ItemSet, ignore parent.
85  if(mpItemSet && mpItemSet->GetParent())
86  {
87  mpItemSet->SetParent(nullptr);
88  }
89  }
90  }
91 
92  std::unique_ptr<BaseProperties> DefaultProperties::Clone(SdrObject& rObj) const
93  {
94  return std::unique_ptr<BaseProperties>(new DefaultProperties(*this, rObj));
95  }
96 
98 
100  {
101  if(!mpItemSet)
102  {
103  const_cast<DefaultProperties*>(this)->mpItemSet = const_cast<DefaultProperties*>(this)->CreateObjectSpecificItemSet(GetSdrObject().GetObjectItemPool());
104  const_cast<DefaultProperties*>(this)->ForceDefaultAttributes();
105  }
106 
107  assert(mpItemSet && "Could not create an SfxItemSet(!)");
108 
109  return *mpItemSet;
110  }
111 
113  {
114  const sal_uInt16 nWhichID(rItem.Which());
115 
116  if(AllowItemChange(nWhichID, &rItem))
117  {
118  ItemChange(nWhichID, &rItem);
119  PostItemChange(nWhichID);
120 
121  SfxItemSet aSet(GetSdrObject().GetObjectItemPool(), {{nWhichID, nWhichID}});
122  aSet.Put(rItem);
123  ItemSetChanged(aSet);
124  }
125  }
126 
128  {
129  const sal_uInt16 nWhichID(rItem.Which());
130 
131  if(AllowItemChange(nWhichID, &rItem))
132  {
133  ItemChange(nWhichID, &rItem);
134  }
135  }
136 
137  void DefaultProperties::ClearObjectItem(const sal_uInt16 nWhich)
138  {
139  if(AllowItemChange(nWhich))
140  {
141  ItemChange(nWhich);
142  PostItemChange(nWhich);
143 
144  if(nWhich)
145  {
146  SfxItemSet aSet(GetSdrObject().GetObjectItemPool(), {{nWhich, nWhich}});
147  ItemSetChanged(aSet);
148  }
149  }
150  }
151 
152  void DefaultProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
153  {
154  if(AllowItemChange(nWhich))
155  {
156  ItemChange(nWhich);
157  }
158  }
159 
161  {
162  SfxWhichIter aWhichIter(rSet);
163  sal_uInt16 nWhich(aWhichIter.FirstWhich());
164  const SfxPoolItem *pPoolItem;
165  std::vector< sal_uInt16 > aPostItemChangeList;
166  bool bDidChange(false);
167  SfxItemSet aSet(GetSdrObject().GetObjectItemPool(), svl::Items<SDRATTR_START, EE_ITEMS_END>{});
168 
169  // give a hint to STL_Vector
170  aPostItemChangeList.reserve(rSet.Count());
171 
172  while(nWhich)
173  {
174  if(SfxItemState::SET == rSet.GetItemState(nWhich, false, &pPoolItem))
175  {
176  if(AllowItemChange(nWhich, pPoolItem))
177  {
178  bDidChange = true;
179  ItemChange(nWhich, pPoolItem);
180  aPostItemChangeList.push_back( nWhich );
181  aSet.Put(*pPoolItem);
182  }
183  }
184 
185  nWhich = aWhichIter.NextWhich();
186  }
187 
188  if(bDidChange)
189  {
190  for (const auto& rItem : aPostItemChangeList)
191  {
192  PostItemChange(rItem);
193  }
194 
195  ItemSetChanged(aSet);
196  }
197  }
198 
200  {
201  }
202 
203  bool DefaultProperties::AllowItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/) const
204  {
205  return true;
206  }
207 
208  void DefaultProperties::ItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/)
209  {
210  }
211 
212  void DefaultProperties::PostItemChange(const sal_uInt16 nWhich )
213  {
214  if( (nWhich == XATTR_FILLSTYLE) && (mpItemSet != nullptr) )
216  }
217 
218  void DefaultProperties::SetStyleSheet(SfxStyleSheet* /*pNewStyleSheet*/, bool /*bDontRemoveHardAttr*/)
219  {
220  // no StyleSheet in DefaultProperties
221  }
222 
224  {
225  // no StyleSheet in DefaultProperties
226  return nullptr;
227  }
228 
230  {
231  }
232 
234  {
235  xmlTextWriterStartElement(pWriter, BAD_CAST("DefaultProperties"));
236  BaseProperties::dumpAsXml(pWriter);
237  mpItemSet->dumpAsXml(pWriter);
238  xmlTextWriterEndElement(pWriter);
239  }
240  } // end of namespace properties
241 } // end of namespace sdr
242 
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SetObjectItemSet(const SfxItemSet &rSet) override
virtual void SetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr) override
virtual const SfxItemSet & GetObjectItemSet() const override
virtual void PostItemChange(const sal_uInt16 nWhich) override
sal_uInt16 FirstWhich()
virtual void SetObjectItemDirect(const SfxPoolItem &rItem) override
struct _xmlTextWriter * xmlTextWriterPtr
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
virtual void ItemSetChanged(const SfxItemSet &rSet) override
#define X
virtual void ItemChange(const sal_uInt16 nWhich, const SfxPoolItem *pNewItem=nullptr) override
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
sal_uInt16 Count() const
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: properties.cxx:159
SdrModel & getSdrModelFromSdrObject() const
Definition: svdobj.cxx:299
#define XATTR_FILLSTYLE
Definition: xdef.hxx:107
Abstract DrawObject.
Definition: svdobj.hxx:312
virtual bool AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem *pNewItem=nullptr) const override
FrPair GetMapFactor(MapUnit eS, MapUnit eD)
Definition: svdtrans.cxx:632
virtual std::unique_ptr< SfxItemSet > CreateObjectSpecificItemSet(SfxItemPool &rPool) override
virtual void ClearObjectItemDirect(const sal_uInt16 nWhich) override
MapUnit
const SfxItemPool & GetItemPool() const
Definition: svdmodel.hxx:314
const SdrObject & GetSdrObject() const
Definition: properties.cxx:62
virtual std::unique_ptr< BaseProperties > Clone(SdrObject &rObj) const override
void CleanupFillProperties(SfxItemSet &rItemSet)
Definition: properties.cxx:165
sal_uInt16 Which() const
virtual void ClearObjectItem(const sal_uInt16 nWhich=0) override