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
35namespace 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 return;
115
116 ItemChange(nWhichID, &rItem);
117 PostItemChange(nWhichID);
118
119 const SfxPoolItem* pItem = &rItem;
120 ItemSetChanged( {&pItem, 1}, 0);
121 }
122
124 {
125 const sal_uInt16 nWhichID(rItem.Which());
126
127 if(AllowItemChange(nWhichID, &rItem))
128 {
129 ItemChange(nWhichID, &rItem);
130 }
131 }
132
133 void DefaultProperties::ClearObjectItem(const sal_uInt16 nWhich)
134 {
135 if(!AllowItemChange(nWhich))
136 return;
137
138 ItemChange(nWhich);
139 PostItemChange(nWhich);
140
141 if(nWhich)
142 {
143 ItemSetChanged({}, nWhich);
144 }
145 }
146
147 void DefaultProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
148 {
149 if(AllowItemChange(nWhich))
150 {
151 ItemChange(nWhich);
152 }
153 }
154
156 {
158 {
160 const std::shared_ptr<VectorGraphicData>& pVectorData
162 if (pVectorData)
163 {
164 // Shape is filled by a vector graphic: tell it our size as a hint.
165 basegfx::B2DTuple aSizeHint;
166 aSizeHint.setX(GetSdrObject().GetSnapRect().getWidth());
167 aSizeHint.setY(GetSdrObject().GetSnapRect().getHeight());
168 pVectorData->setSizeHint(aSizeHint);
169 }
170 }
171
172 SfxWhichIter aWhichIter(rSet);
173 sal_uInt16 nWhich(aWhichIter.FirstWhich());
174 std::vector< const SfxPoolItem * > aPostItemChangeList;
175 // give a hint to STL_Vector
176 aPostItemChangeList.reserve(rSet.Count());
177
178 while(nWhich)
179 {
180 const SfxPoolItem* pPoolItem;
181 if(SfxItemState::SET == aWhichIter.GetItemState(false, &pPoolItem))
182 {
183 if(AllowItemChange(nWhich, pPoolItem))
184 {
185 ItemChange(nWhich, pPoolItem);
186 aPostItemChangeList.emplace_back( pPoolItem );
187 }
188 }
189
190 nWhich = aWhichIter.NextWhich();
191 }
192
193 if(!aPostItemChangeList.empty())
194 {
195 for (const auto& rItem : aPostItemChangeList)
196 {
197 PostItemChange(rItem->Which());
198 }
199
200 ItemSetChanged(aPostItemChangeList, 0);
201 }
202 }
203
204 void DefaultProperties::ItemSetChanged(o3tl::span< const SfxPoolItem* const > /*aChangedItems*/, sal_uInt16 /*nDeletedWhich*/)
205 {
206 }
207
208 bool DefaultProperties::AllowItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/) const
209 {
210 return true;
211 }
212
213 void DefaultProperties::ItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/)
214 {
215 }
216
217 void DefaultProperties::PostItemChange(const sal_uInt16 nWhich )
218 {
219 if( (nWhich == XATTR_FILLSTYLE) && mxItemSet )
221 }
222
223 void DefaultProperties::SetStyleSheet(SfxStyleSheet* /*pNewStyleSheet*/, bool /*bDontRemoveHardAttr*/,
224 bool /*bBroadcast*/)
225 {
226 // no StyleSheet in DefaultProperties
227 }
228
230 {
231 // no StyleSheet in DefaultProperties
232 return nullptr;
233 }
234
236 {
237 }
238
240 {
241 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("DefaultProperties"));
243 if (mxItemSet)
244 {
245 mxItemSet->dumpAsXml(pWriter);
246 }
247 (void)xmlTextWriterEndElement(pWriter);
248 }
249} // end of namespace
250
251/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const Graphic & GetGraphic() const
const std::shared_ptr< VectorGraphicData > & getVectorGraphicData() const
MapUnit GetScaleUnit() const
Definition: svdmodel.hxx:370
const SfxItemPool & GetItemPool() const
Definition: svdmodel.hxx:317
Abstract DrawObject.
Definition: svdobj.hxx:261
SdrModel & getSdrModelFromSdrObject() const
Definition: svdobj.cxx:284
sal_uInt16 Count() const
bool HasItem(sal_uInt16 nWhich, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
sal_uInt16 Which() const
sal_uInt16 FirstWhich()
SfxItemState GetItemState(bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
sal_uInt16 NextWhich()
const GraphicObject & GetGraphicObject() const
Definition: xbtmpit.hxx:56
void setY(TYPE fY)
void setX(TYPE fX)
const SdrObject & GetSdrObject() const
Definition: properties.cxx:43
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: properties.cxx:142
virtual void SetObjectItemSet(const SfxItemSet &rSet) override
virtual void ClearObjectItemDirect(const sal_uInt16 nWhich) override
virtual std::unique_ptr< BaseProperties > Clone(SdrObject &rObj) const override
virtual void SetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr, bool bBroadcast) override
virtual SfxItemSet CreateObjectSpecificItemSet(SfxItemPool &pPool) override
virtual void SetObjectItem(const SfxPoolItem &rItem) override
virtual void ItemSetChanged(o3tl::span< const SfxPoolItem *const > aChangedItems, sal_uInt16 nDeletedWhich)
virtual void ClearObjectItem(const sal_uInt16 nWhich=0) override
virtual bool AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem *pNewItem=nullptr) const
virtual void ItemChange(const sal_uInt16 nWhich, const SfxPoolItem *pNewItem=nullptr)
std::optional< SfxItemSet > mxItemSet
void dumpAsXml(xmlTextWriterPtr pWriter) const override
virtual const SfxItemSet & GetObjectItemSet() const override
virtual void PostItemChange(const sal_uInt16 nWhich)
virtual SfxStyleSheet * GetStyleSheet() const override
virtual void SetObjectItemDirect(const SfxPoolItem &rItem) override
struct _xmlTextWriter * xmlTextWriterPtr
MapUnit
void ScaleItemSet(SfxItemSet &rSet, const Fraction &rScale)
void CleanupFillProperties(SfxItemSet &rItemSet)
Definition: properties.cxx:148
static SfxItemSet & rSet
FrPair GetMapFactor(MapUnit eS, MapUnit eD)
Definition: svdtrans.cxx:603
constexpr TypedWhichId< XFillBitmapItem > XATTR_FILLBITMAP(XATTR_FILL_FIRST+4)
constexpr TypedWhichId< XFillStyleItem > XATTR_FILLSTYLE(XATTR_FILL_FIRST)