/src/libreoffice/svx/source/sdr/properties/defaultproperties.cxx
Line | Count | Source |
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 | | |
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 <vector> |
27 | | #include <svx/svdobj.hxx> |
28 | | #include <libxml/xmlwriter.h> |
29 | | #include <svx/svdmodel.hxx> |
30 | | #include <svx/svdtrans.hxx> |
31 | | #include <svx/xbtmpit.hxx> |
32 | | #include <vcl/vectorgraphicdata.hxx> |
33 | | |
34 | | namespace sdr::properties |
35 | | { |
36 | | SfxItemSet DefaultProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool) |
37 | 0 | { |
38 | | // Basic implementation; Basic object has NO attributes |
39 | 0 | return SfxItemSet(rPool); |
40 | 0 | } |
41 | | |
42 | | DefaultProperties::DefaultProperties(SdrObject& rObj) |
43 | 1.53M | : BaseProperties(rObj) |
44 | 1.53M | { |
45 | 1.53M | } |
46 | | |
47 | | DefaultProperties::DefaultProperties(const DefaultProperties& rProps, SdrObject& rObj) |
48 | 20.0k | : BaseProperties(rObj) |
49 | 20.0k | { |
50 | 20.0k | if(!rProps.moItemSet) |
51 | 0 | return; |
52 | | |
53 | | // Clone may be to another model and thus another ItemPool. |
54 | | // SfxItemSet supports that thus we are able to Clone all |
55 | | // SfxItemState::SET items to the target pool. |
56 | 20.0k | moItemSet.emplace(rProps.moItemSet->CloneAsValue( |
57 | 20.0k | true, |
58 | 20.0k | &rObj.getSdrModelFromSdrObject().GetItemPool())); |
59 | | |
60 | | // React on ModelChange: If metric has changed, scale items. |
61 | | // As seen above, clone is supported, but scale is not included, |
62 | | // thus: TTTT maybe add scale to SfxItemSet::Clone() (?) |
63 | | // tdf#117707 correct ModelChange detection |
64 | 20.0k | const bool bModelChange(&rObj.getSdrModelFromSdrObject() != &rProps.GetSdrObject().getSdrModelFromSdrObject()); |
65 | | |
66 | 20.0k | if(bModelChange) |
67 | 0 | { |
68 | 0 | const MapUnit aOldUnit(rProps.GetSdrObject().getSdrModelFromSdrObject().GetScaleUnit()); |
69 | 0 | const MapUnit aNewUnit(rObj.getSdrModelFromSdrObject().GetScaleUnit()); |
70 | 0 | const bool bScaleUnitChanged(aNewUnit != aOldUnit); |
71 | |
|
72 | 0 | if(bScaleUnitChanged) |
73 | 0 | { |
74 | 0 | const double fMetricFactor(GetMapFactor(aOldUnit, aNewUnit).X()); |
75 | |
|
76 | 0 | ScaleItemSet(*moItemSet, fMetricFactor); |
77 | 0 | } |
78 | 0 | } |
79 | | |
80 | | // do not keep parent info, this may be changed by later constructors. |
81 | | // This class just copies the ItemSet, ignore parent. |
82 | 20.0k | if(moItemSet && moItemSet->GetParent()) |
83 | 0 | { |
84 | 0 | moItemSet->SetParent(nullptr); |
85 | 0 | } |
86 | 20.0k | } |
87 | | |
88 | | std::unique_ptr<BaseProperties> DefaultProperties::Clone(SdrObject& rObj) const |
89 | 0 | { |
90 | 0 | return std::unique_ptr<BaseProperties>(new DefaultProperties(*this, rObj)); |
91 | 0 | } |
92 | | |
93 | 1.55M | DefaultProperties::~DefaultProperties() {} |
94 | | |
95 | | const SfxItemSet& DefaultProperties::GetObjectItemSet() const |
96 | 72.7M | { |
97 | 72.7M | if(!moItemSet) |
98 | 1.48M | { |
99 | 1.48M | moItemSet.emplace(const_cast<DefaultProperties*>(this)->CreateObjectSpecificItemSet(GetSdrObject().GetObjectItemPool())); |
100 | 1.48M | const_cast<DefaultProperties*>(this)->ForceDefaultAttributes(); |
101 | 1.48M | } |
102 | | |
103 | 72.7M | assert(moItemSet && "Could not create an SfxItemSet(!)"); |
104 | | |
105 | 72.7M | return *moItemSet; |
106 | 72.7M | } |
107 | | |
108 | | void DefaultProperties::SetObjectItem(const SfxPoolItem& rItem) |
109 | 2.46M | { |
110 | 2.46M | const sal_uInt16 nWhichID(rItem.Which()); |
111 | | |
112 | 2.46M | if(!AllowItemChange(nWhichID, &rItem)) |
113 | 0 | return; |
114 | | |
115 | 2.46M | ItemChange(nWhichID, &rItem); |
116 | 2.46M | PostItemChange(nWhichID); |
117 | | |
118 | 2.46M | const SfxPoolItem* pItem = &rItem; |
119 | 2.46M | ItemSetChanged( {&pItem, 1}, 0); |
120 | 2.46M | } |
121 | | |
122 | | void DefaultProperties::SetObjectItemDirect(const SfxPoolItem& rItem) |
123 | 3.52M | { |
124 | 3.52M | const sal_uInt16 nWhichID(rItem.Which()); |
125 | | |
126 | 3.52M | if(AllowItemChange(nWhichID, &rItem)) |
127 | 3.52M | { |
128 | 3.52M | ItemChange(nWhichID, &rItem); |
129 | 3.52M | } |
130 | 3.52M | } |
131 | | |
132 | | void DefaultProperties::ClearObjectItem(const sal_uInt16 nWhich) |
133 | 17.6k | { |
134 | 17.6k | if(!AllowItemChange(nWhich)) |
135 | 0 | return; |
136 | | |
137 | 17.6k | ItemChange(nWhich); |
138 | 17.6k | PostItemChange(nWhich); |
139 | | |
140 | 17.6k | if(nWhich) |
141 | 2.27k | { |
142 | 2.27k | ItemSetChanged({}, nWhich); |
143 | 2.27k | } |
144 | 17.6k | } |
145 | | |
146 | | void DefaultProperties::ClearObjectItemDirect(const sal_uInt16 nWhich) |
147 | 4.74k | { |
148 | 4.74k | if(AllowItemChange(nWhich)) |
149 | 4.73k | { |
150 | 4.73k | ItemChange(nWhich); |
151 | 4.73k | } |
152 | 4.74k | } |
153 | | |
154 | | void DefaultProperties::SetObjectItemSet(const SfxItemSet& rSet, bool bAdjustTextFrameWidthAndHeight) |
155 | 3.85M | { |
156 | 3.85M | if (rSet.HasItem(XATTR_FILLBITMAP)) |
157 | 2.48k | { |
158 | 2.48k | const XFillBitmapItem* pItem = rSet.GetItem(XATTR_FILLBITMAP); |
159 | 2.48k | const std::shared_ptr<VectorGraphicData>& pVectorData |
160 | 2.48k | = pItem->GetGraphicObject().GetGraphic().getVectorGraphicData(); |
161 | 2.48k | if (pVectorData) |
162 | 0 | { |
163 | | // Shape is filled by a vector graphic: tell it our size as a hint. |
164 | 0 | basegfx::B2DTuple aSizeHint; |
165 | 0 | aSizeHint.setX(GetSdrObject().GetSnapRect().getOpenWidth()); |
166 | 0 | aSizeHint.setY(GetSdrObject().GetSnapRect().getOpenHeight()); |
167 | 0 | pVectorData->setSizeHint(aSizeHint); |
168 | 0 | } |
169 | 2.48k | } |
170 | | |
171 | 3.85M | SfxWhichIter aWhichIter(rSet); |
172 | 3.85M | sal_uInt16 nWhich(aWhichIter.FirstWhich()); |
173 | 3.85M | std::vector< const SfxPoolItem * > aPostItemChangeList; |
174 | | // give a hint to STL_Vector |
175 | 3.85M | aPostItemChangeList.reserve(rSet.Count()); |
176 | | |
177 | 651M | while(nWhich) |
178 | 647M | { |
179 | 647M | const SfxPoolItem* pPoolItem; |
180 | 647M | if(SfxItemState::SET == aWhichIter.GetItemState(false, &pPoolItem)) |
181 | 15.8M | { |
182 | 15.8M | if(AllowItemChange(nWhich, pPoolItem)) |
183 | 15.8M | { |
184 | 15.8M | ItemChange(nWhich, pPoolItem); |
185 | 15.8M | aPostItemChangeList.emplace_back( pPoolItem ); |
186 | 15.8M | } |
187 | 15.8M | } |
188 | | |
189 | 647M | nWhich = aWhichIter.NextWhich(); |
190 | 647M | } |
191 | | |
192 | 3.85M | if(!aPostItemChangeList.empty()) |
193 | 3.85M | { |
194 | 3.85M | for (const auto& rItem : aPostItemChangeList) |
195 | 15.8M | { |
196 | 15.8M | PostItemChange(rItem->Which()); |
197 | 15.8M | } |
198 | | |
199 | 3.85M | ItemSetChanged(aPostItemChangeList, 0, bAdjustTextFrameWidthAndHeight); |
200 | 3.85M | } |
201 | 3.85M | } |
202 | | |
203 | | void DefaultProperties::ItemSetChanged(std::span< const SfxPoolItem* const > /*aChangedItems*/, sal_uInt16 /*nDeletedWhich*/, bool /*bAdjustTextFrameWidthAndHeight*/) |
204 | 0 | { |
205 | 0 | } |
206 | | |
207 | | bool DefaultProperties::AllowItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/) const |
208 | 21.8M | { |
209 | 21.8M | return true; |
210 | 21.8M | } |
211 | | |
212 | | void DefaultProperties::ItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/) |
213 | 0 | { |
214 | 0 | } |
215 | | |
216 | | void DefaultProperties::PostItemChange(const sal_uInt16 nWhich ) |
217 | 18.3M | { |
218 | 18.3M | if( (nWhich == XATTR_FILLSTYLE) && moItemSet ) |
219 | 585k | CleanupFillProperties(*moItemSet); |
220 | 18.3M | } |
221 | | |
222 | | void DefaultProperties::SetStyleSheet(SfxStyleSheet* /*pNewStyleSheet*/, bool /*bDontRemoveHardAttr*/, |
223 | | bool /*bBroadcast*/, bool /*bAdjustTextFrameWidthAndHeight*/) |
224 | 0 | { |
225 | | // no StyleSheet in DefaultProperties |
226 | 0 | } |
227 | | |
228 | | SfxStyleSheet* DefaultProperties::GetStyleSheet() const |
229 | 0 | { |
230 | | // no StyleSheet in DefaultProperties |
231 | 0 | return nullptr; |
232 | 0 | } |
233 | | |
234 | | void DefaultProperties::ForceDefaultAttributes() |
235 | 12.4k | { |
236 | 12.4k | } |
237 | | |
238 | | void DefaultProperties::dumpAsXml(xmlTextWriterPtr pWriter) const |
239 | 0 | { |
240 | 0 | (void)xmlTextWriterStartElement(pWriter, BAD_CAST("DefaultProperties")); |
241 | 0 | BaseProperties::dumpAsXml(pWriter); |
242 | 0 | if (moItemSet) |
243 | 0 | { |
244 | 0 | moItemSet->dumpAsXml(pWriter); |
245 | 0 | } |
246 | 0 | (void)xmlTextWriterEndElement(pWriter); |
247 | 0 | } |
248 | | } // end of namespace |
249 | | |
250 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |