/src/libreoffice/svx/source/sdr/properties/attributeproperties.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 <sdr/properties/attributeproperties.hxx> |
23 | | #include <tools/debug.hxx> |
24 | | #include <svl/itemset.hxx> |
25 | | #include <svl/style.hxx> |
26 | | #include <svl/whiter.hxx> |
27 | | #include <svl/poolitem.hxx> |
28 | | #include <svx/svdobj.hxx> |
29 | | #include <svx/xbtmpit.hxx> |
30 | | #include <svx/xlndsit.hxx> |
31 | | #include <svx/xlnstit.hxx> |
32 | | #include <svx/xlnedit.hxx> |
33 | | #include <svx/xflgrit.hxx> |
34 | | #include <svx/xflftrit.hxx> |
35 | | #include <svx/xflhtit.hxx> |
36 | | #include <svx/svdmodel.hxx> |
37 | | #include <svx/svdpage.hxx> |
38 | | #include <svx/diagram/DiagramHelper_svx.hxx> |
39 | | #include <osl/diagnose.h> |
40 | | |
41 | | namespace sdr::properties |
42 | | { |
43 | | void AttributeProperties::ImpSetParentAtSfxItemSet(bool bDontRemoveHardAttr) |
44 | 1.15M | { |
45 | 1.15M | if(HasSfxItemSet() && mpStyleSheet) |
46 | 1.15M | { |
47 | | // Delete hard attributes where items are set in the style sheet |
48 | 1.15M | if(!bDontRemoveHardAttr) |
49 | 474k | { |
50 | 474k | const SfxItemSet& rStyle = mpStyleSheet->GetItemSet(); |
51 | 474k | SfxWhichIter aIter(rStyle); |
52 | 474k | sal_uInt16 nWhich = aIter.FirstWhich(); |
53 | | |
54 | 102M | while(nWhich) |
55 | 101M | { |
56 | 101M | if(SfxItemState::SET == aIter.GetItemState()) |
57 | 8.31M | { |
58 | 8.31M | moItemSet->ClearItem(nWhich); |
59 | 8.31M | } |
60 | | |
61 | 101M | nWhich = aIter.NextWhich(); |
62 | 101M | } |
63 | 474k | } |
64 | | |
65 | | // set new stylesheet as parent |
66 | 1.15M | moItemSet->SetParent(&mpStyleSheet->GetItemSet()); |
67 | 1.15M | } |
68 | 0 | else |
69 | 0 | { |
70 | 0 | OSL_ENSURE(false, "ImpSetParentAtSfxItemSet called without SfxItemSet/SfxStyleSheet (!)"); |
71 | 0 | } |
72 | 1.15M | } |
73 | | |
74 | | void AttributeProperties::ImpAddStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr) |
75 | 1.21M | { |
76 | | // test if old StyleSheet is cleared, else it would be lost |
77 | | // after this method -> memory leak (!) |
78 | 1.21M | DBG_ASSERT(!mpStyleSheet, "Old style sheet not deleted before setting new one (!)"); |
79 | | |
80 | 1.21M | if(!pNewStyleSheet) |
81 | 56.6k | return; |
82 | | |
83 | | // local remember |
84 | 1.15M | mpStyleSheet = pNewStyleSheet; |
85 | | |
86 | 1.15M | if(HasSfxItemSet()) |
87 | 1.15M | { |
88 | | // register as listener |
89 | 1.15M | StartListening(*pNewStyleSheet->GetPool()); |
90 | 1.15M | StartListening(*pNewStyleSheet); |
91 | | |
92 | | // only apply the following when we have an SfxItemSet already, else |
93 | 1.15M | if(GetStyleSheet()) |
94 | 1.15M | { |
95 | 1.15M | ImpSetParentAtSfxItemSet(bDontRemoveHardAttr); |
96 | 1.15M | } |
97 | 1.15M | } |
98 | 1.15M | } |
99 | | |
100 | | void AttributeProperties::ImpRemoveStyleSheet() |
101 | 2.81M | { |
102 | | // Check type since it is destroyed when the type is deleted |
103 | 2.81M | if(GetStyleSheet() && mpStyleSheet) |
104 | 1.15M | { |
105 | 1.15M | EndListening(*mpStyleSheet); |
106 | 1.15M | if (auto const pool = mpStyleSheet->GetPool()) { // TTTT |
107 | 1.15M | EndListening(*pool); |
108 | 1.15M | } |
109 | | |
110 | | // reset parent of ItemSet |
111 | 1.15M | if(HasSfxItemSet()) |
112 | 1.15M | { |
113 | 1.15M | moItemSet->SetParent(nullptr); |
114 | 1.15M | } |
115 | | |
116 | 1.15M | SdrObject& rObj = GetSdrObject(); |
117 | 1.15M | rObj.SetBoundRectDirty(); |
118 | 1.15M | rObj.SetBoundAndSnapRectsDirty(/*bNotMyself*/true); |
119 | 1.15M | } |
120 | | |
121 | 2.81M | mpStyleSheet = nullptr; |
122 | 2.81M | } |
123 | | |
124 | | // create a new itemset |
125 | | SfxItemSet AttributeProperties::CreateObjectSpecificItemSet(SfxItemPool&) |
126 | 0 | { |
127 | 0 | assert(false && "this class is effectively abstract, should only be instantiating subclasses"); |
128 | 0 | abort(); |
129 | 0 | } |
130 | | |
131 | | AttributeProperties::AttributeProperties(SdrObject& rObj) |
132 | 1.57M | : DefaultProperties(rObj), |
133 | 1.57M | mpStyleSheet(nullptr) |
134 | 1.57M | { |
135 | | // Do nothing else, esp. do *not* try to get and set |
136 | | // a default SfxStyle sheet. Nothing is allowed to be done |
137 | | // that may lead to calls to virtual functions like |
138 | | // CreateObjectSpecificItemSet - these would go *wrong*. |
139 | | // Thus the rest is lazy-init from here. |
140 | 1.57M | } |
141 | | |
142 | | AttributeProperties::AttributeProperties(const AttributeProperties& rProps, SdrObject& rObj) |
143 | 22.9k | : DefaultProperties(rProps, rObj), |
144 | 22.9k | mpStyleSheet(nullptr) |
145 | 22.9k | { |
146 | 22.9k | SfxStyleSheet* pTargetStyleSheet(rProps.GetStyleSheet()); |
147 | | |
148 | 22.9k | if(pTargetStyleSheet) |
149 | 0 | { |
150 | 0 | const bool bModelChange(&rObj.getSdrModelFromSdrObject() != &rProps.GetSdrObject().getSdrModelFromSdrObject()); |
151 | |
|
152 | 0 | if(bModelChange) |
153 | 0 | { |
154 | | // tdf#117506 |
155 | | // The error shows that it is definitely necessary to solve this problem. |
156 | | // Interestingly I already had a note here for 'work needed'. |
157 | | // Checked in libreoffice-6-0 what happened there. In principle, the whole |
158 | | // ::Clone of SdrPage and SdrObject happened in the same SdrModel, only |
159 | | // afterwards a ::SetModel was used at the cloned SdrPage which went through |
160 | | // all layers. The StyleSheet-problem was solved in |
161 | | // AttributeProperties::MoveToItemPool at the end. There, a StyleSheet with the |
162 | | // same name was searched for in the target-SdrModel. |
163 | | // Start by resetting the current TargetStyleSheet so that nothing goes wrong |
164 | | // when we do not find a fitting TargetStyleSheet. |
165 | | // Note: The test for SdrModelChange above was wrong (compared the already set |
166 | | // new SdrObject), so this never triggered and pTargetStyleSheet was never set to |
167 | | // nullptr before. This means that a StyleSheet from another SdrModel was used |
168 | | // what of course is very dangerous. Interestingly did not crash since when that |
169 | | // other SdrModel was destroyed the ::Notify mechanism still worked reliably |
170 | | // and de-connected this Properties successfully from the alien-StyleSheet. |
171 | 0 | pTargetStyleSheet = nullptr; |
172 | | |
173 | | // Check if we have a TargetStyleSheetPool at the target-SdrModel. This *should* |
174 | | // be the case already (SdrModel::Merge and SdDrawDocument::InsertBookmarkAsPage |
175 | | // have already cloned the StyleSheets to the target-SdrModel when used in Draw/impress). |
176 | | // If none is found, ImpGetDefaultStyleSheet will be used to set a 'default' |
177 | | // StyleSheet as StyleSheet implicitly later (that's what happened in the task, |
178 | | // thus the FillStyle changed to the 'default' Blue). |
179 | | // Note: It *may* be necessary to do more for StyleSheets, e.g. clone/copy the |
180 | | // StyleSheet Hierarchy from the source SdrModel and/or add the Items from there |
181 | | // as hard attributes. If needed, have a look at the older AttributeProperties::SetModel |
182 | | // implementation from e.g. libreoffice-6-0. |
183 | 0 | SfxStyleSheetBasePool* pTargetStyleSheetPool(rObj.getSdrModelFromSdrObject().GetStyleSheetPool()); |
184 | |
|
185 | 0 | if(nullptr != pTargetStyleSheetPool) |
186 | 0 | { |
187 | | // If we have a TargetStyleSheetPool, search for the used StyleSheet |
188 | | // in the target SdrModel using the Name from the original StyleSheet |
189 | | // in the source-SdrModel. |
190 | 0 | pTargetStyleSheet = dynamic_cast< SfxStyleSheet* >( |
191 | 0 | pTargetStyleSheetPool->Find( |
192 | 0 | rProps.GetStyleSheet()->GetName(), |
193 | 0 | rProps.GetStyleSheet()->GetFamily())); |
194 | 0 | } |
195 | 0 | } |
196 | 0 | } |
197 | | |
198 | 22.9k | if(!pTargetStyleSheet) |
199 | 22.9k | return; |
200 | | |
201 | 0 | if(HasSfxItemSet()) |
202 | 0 | { |
203 | | // The SfxItemSet has been cloned and exists, |
204 | | // we can directly set the SfxStyleSheet at it |
205 | 0 | ImpAddStyleSheet(pTargetStyleSheet, true); |
206 | 0 | } |
207 | 0 | else |
208 | 0 | { |
209 | | // No SfxItemSet exists yet (there is none in |
210 | | // the source, so none was cloned). Remember the |
211 | | // SfxStyleSheet to set it when the SfxItemSet |
212 | | // got constructed on-demand |
213 | 0 | mpStyleSheet = pTargetStyleSheet; |
214 | 0 | } |
215 | 0 | } |
216 | | |
217 | | AttributeProperties::~AttributeProperties() |
218 | 1.60M | { |
219 | 1.60M | ImpRemoveStyleSheet(); |
220 | 1.60M | } |
221 | | |
222 | | std::unique_ptr<BaseProperties> AttributeProperties::Clone(SdrObject&) const |
223 | 0 | { |
224 | 0 | assert(false && "this class is effectively abstract, should only be instantiating subclasses"); |
225 | 0 | abort(); |
226 | 0 | } |
227 | | |
228 | | const SfxItemSet& AttributeProperties::GetObjectItemSet() const |
229 | 71.6M | { |
230 | | // remember if we had a SfxItemSet already |
231 | 71.6M | const bool bHadSfxItemSet(HasSfxItemSet()); |
232 | | |
233 | | // call parent - this will guarantee SfxItemSet existence |
234 | 71.6M | DefaultProperties::GetObjectItemSet(); |
235 | | |
236 | 71.6M | if(!bHadSfxItemSet) |
237 | 1.51M | { |
238 | | // need to take care for SfxStyleSheet for newly |
239 | | // created SfxItemSet |
240 | 1.51M | if(nullptr == mpStyleSheet) |
241 | 1.51M | { |
242 | | // Set missing defaults without removal of hard attributes. |
243 | | // This is more complicated historically than I first thought: |
244 | | // Originally for GetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj |
245 | | // SetStyleSheet(..., false) was used, while for GetDefaultStyleSheet |
246 | | // SetStyleSheet(..., true) was used. Thus, for SdrGrafObj and SdrOle2Obj |
247 | | // bDontRemoveHardAttr == false -> *do* delete hard attributes was used. |
248 | | // This was probably not done by purpose, adding the method |
249 | | // GetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj additionally to |
250 | | // GetDefaultStyleSheet was an enhancement to allow for SdrGrafObj/SdrOle2Obj |
251 | | // with full AttributeSet (adding e.g. FillAttributes). To stay as compatible |
252 | | // as possible these SdrObjects got a new default-StyleSheet. |
253 | | // There is no reason to delete the HardAttributes and it anyways has only |
254 | | // AFAIK effects on a single Item - the SdrTextHorzAdjustItem. To get things |
255 | | // unified I will stay with not deleting the HardAttributes and adapt the |
256 | | // UnitTests in CppunitTest_sd_import_tests accordingly. |
257 | 1.51M | const_cast< AttributeProperties* >(this)->applyDefaultStyleSheetFromSdrModel(); |
258 | 1.51M | } |
259 | 0 | else |
260 | 0 | { |
261 | | // Late-Init of setting parent to SfxStyleSheet after |
262 | | // it's creation. Can only happen from copy-constructor |
263 | | // (where creation of SfxItemSet is avoided due to the |
264 | | // problem with constructors and virtual functions in C++), |
265 | | // thus DontRemoveHardAttr is not needed. |
266 | 0 | const_cast< AttributeProperties* >(this)->SetStyleSheet( |
267 | 0 | mpStyleSheet, true, true); |
268 | 0 | } |
269 | 1.51M | } |
270 | | |
271 | 71.6M | return *moItemSet; |
272 | 71.6M | } |
273 | | |
274 | | void AttributeProperties::ItemSetChanged(std::span< const SfxPoolItem* const > aChangedItems, sal_uInt16 /*nDeletedWhich*/, bool /*bAdjustTextFrameWidthAndHeight*/) |
275 | 6.35M | { |
276 | | // own modifications |
277 | 6.35M | SdrObject& rObj = GetSdrObject(); |
278 | | |
279 | 6.35M | rObj.SetBoundRectDirty(); |
280 | 6.35M | rObj.SetBoundAndSnapRectsDirty(/*bNotMyself*/true); |
281 | 6.35M | rObj.SetChanged(); |
282 | | |
283 | 6.35M | if (!rObj.getDiagramDataModelID().isEmpty() && !rObj.getSdrModelFromSdrObject().isInImportExport()) |
284 | 1.25M | { |
285 | 1.25M | const std::shared_ptr< svx::diagram::DiagramHelper_svx >& pDiagramHelper(rObj.getDiagramHelper()); |
286 | 1.25M | if (pDiagramHelper) |
287 | 8 | pDiagramHelper->ItemSetInformationChange(aChangedItems); |
288 | 1.25M | } |
289 | 6.35M | } |
290 | | |
291 | | void AttributeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem) |
292 | 22.5M | { |
293 | 22.5M | if(pNewItem) |
294 | 22.5M | { |
295 | 22.5M | std::unique_ptr<SfxPoolItem> pResultItem; |
296 | 22.5M | SdrModel& rModel(GetSdrObject().getSdrModelFromSdrObject()); |
297 | | |
298 | 22.5M | switch( nWhich ) |
299 | 22.5M | { |
300 | 9.32k | case XATTR_FILLBITMAP: |
301 | 9.32k | { |
302 | 9.32k | pResultItem = static_cast<const XFillBitmapItem*>(pNewItem)->checkForUniqueItem( rModel ); |
303 | 9.32k | break; |
304 | 0 | } |
305 | 16.9k | case XATTR_LINEDASH: |
306 | 16.9k | { |
307 | 16.9k | pResultItem = static_cast<const XLineDashItem*>(pNewItem)->checkForUniqueItem( rModel ); |
308 | 16.9k | break; |
309 | 0 | } |
310 | 17.1k | case XATTR_LINESTART: |
311 | 17.1k | { |
312 | 17.1k | pResultItem = static_cast<const XLineStartItem*>(pNewItem)->checkForUniqueItem( rModel ); |
313 | 17.1k | break; |
314 | 0 | } |
315 | 22.6k | case XATTR_LINEEND: |
316 | 22.6k | { |
317 | 22.6k | pResultItem = static_cast<const XLineEndItem*>(pNewItem)->checkForUniqueItem( rModel ); |
318 | 22.6k | break; |
319 | 0 | } |
320 | 11.0k | case XATTR_FILLGRADIENT: |
321 | 11.0k | { |
322 | 11.0k | pResultItem = static_cast<const XFillGradientItem*>(pNewItem)->checkForUniqueItem( rModel ); |
323 | 11.0k | break; |
324 | 0 | } |
325 | 118 | case XATTR_FILLFLOATTRANSPARENCE: |
326 | 118 | { |
327 | | // #85953# allow all kinds of XFillFloatTransparenceItem to be set |
328 | 118 | pResultItem = static_cast<const XFillFloatTransparenceItem*>(pNewItem)->checkForUniqueItem( rModel ); |
329 | 118 | break; |
330 | 0 | } |
331 | 0 | case XATTR_FILLHATCH: |
332 | 0 | { |
333 | 0 | pResultItem = static_cast<const XFillHatchItem*>(pNewItem)->checkForUniqueItem( rModel ); |
334 | 0 | break; |
335 | 0 | } |
336 | 22.5M | } |
337 | | |
338 | | // guarantee SfxItemSet existence |
339 | 22.5M | GetObjectItemSet(); |
340 | | |
341 | 22.5M | if(pResultItem) |
342 | 59.8k | { |
343 | | // force ItemSet |
344 | 59.8k | moItemSet->Put(std::move(pResultItem)); |
345 | 59.8k | } |
346 | 22.4M | else |
347 | 22.4M | { |
348 | 22.4M | moItemSet->Put(*pNewItem); |
349 | 22.4M | } |
350 | 22.5M | } |
351 | 23.2k | else |
352 | 23.2k | { |
353 | | // clear item if ItemSet exists |
354 | 23.2k | if(HasSfxItemSet()) |
355 | 19.4k | { |
356 | 19.4k | moItemSet->ClearItem(nWhich); |
357 | 19.4k | } |
358 | 23.2k | } |
359 | 22.5M | } |
360 | | |
361 | | void AttributeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr, |
362 | | bool /*bBroadcast*/, bool /*bAdjustTextFrameWidthAndHeight*/) |
363 | 1.21M | { |
364 | | // Make sure we have a SfxItemSet. We are deliberately bypassing our |
365 | | // own AttributeProperties::GetObjectItemSet here, because we don't want to set a default stylesheet, |
366 | | // and then immediately remove it, which is costly. |
367 | 1.21M | DefaultProperties::GetObjectItemSet(); |
368 | | |
369 | 1.21M | ImpRemoveStyleSheet(); |
370 | 1.21M | ImpAddStyleSheet(pNewStyleSheet, bDontRemoveHardAttr); |
371 | | |
372 | 1.21M | SdrObject& rObj = GetSdrObject(); |
373 | 1.21M | rObj.SetBoundRectDirty(); |
374 | 1.21M | rObj.SetBoundAndSnapRectsDirty(true); |
375 | 1.21M | } |
376 | | |
377 | | SfxStyleSheet* AttributeProperties::GetStyleSheet() const |
378 | 26.5M | { |
379 | 26.5M | return mpStyleSheet; |
380 | 26.5M | } |
381 | | |
382 | | void AttributeProperties::ForceStyleToHardAttributes() |
383 | 0 | { |
384 | 0 | if(!GetStyleSheet() || mpStyleSheet == nullptr) |
385 | 0 | return; |
386 | | |
387 | | // guarantee SfxItemSet existence |
388 | 0 | GetObjectItemSet(); |
389 | | |
390 | | // prepare copied, new itemset, but WITHOUT parent |
391 | 0 | SfxItemSet aDestItemSet(*moItemSet); |
392 | 0 | aDestItemSet.SetParent(nullptr); |
393 | | |
394 | | // prepare forgetting the current stylesheet like in RemoveStyleSheet() |
395 | 0 | EndListening(*mpStyleSheet); |
396 | 0 | EndListening(*mpStyleSheet->GetPool()); |
397 | | |
398 | | // prepare the iter; use the mpObjectItemSet which may have less |
399 | | // WhichIDs than the style. |
400 | 0 | SfxWhichIter aIter(aDestItemSet); |
401 | 0 | sal_uInt16 nWhich(aIter.FirstWhich()); |
402 | 0 | const SfxPoolItem *pItem = nullptr; |
403 | | |
404 | | // now set all hard attributes of the current at the new itemset |
405 | 0 | while(nWhich) |
406 | 0 | { |
407 | | // #i61284# use mpItemSet with parents, makes things easier and reduces to |
408 | | // one loop |
409 | 0 | if(SfxItemState::SET == moItemSet->GetItemState(nWhich, true, &pItem)) |
410 | 0 | { |
411 | 0 | aDestItemSet.Put(*pItem); |
412 | 0 | } |
413 | |
|
414 | 0 | nWhich = aIter.NextWhich(); |
415 | 0 | } |
416 | | |
417 | | // replace itemsets |
418 | 0 | moItemSet.emplace(std::move(aDestItemSet)); |
419 | | |
420 | | // set necessary changes like in RemoveStyleSheet() |
421 | 0 | GetSdrObject().SetBoundRectDirty(); |
422 | 0 | GetSdrObject().SetBoundAndSnapRectsDirty(/*bNotMyself*/true); |
423 | |
|
424 | 0 | mpStyleSheet = nullptr; |
425 | 0 | } |
426 | | |
427 | | void AttributeProperties::Notify(SfxBroadcaster& rBC, const SfxHint& rHint) |
428 | 17.3M | { |
429 | 17.3M | bool bHintUsed(false); |
430 | | |
431 | 17.3M | SfxHintId id = rHint.GetId(); |
432 | 17.3M | if (id == SfxHintId::StyleSheetChanged |
433 | 17.3M | || id == SfxHintId::StyleSheetErased |
434 | 17.3M | || id == SfxHintId::StyleSheetModified |
435 | 9.51M | || id == SfxHintId::StyleSheetInDestruction |
436 | 9.51M | || id == SfxHintId::StyleSheetModifiedExtended) |
437 | 16.9M | { |
438 | 16.9M | const SfxStyleSheetHint* pStyleHint = static_cast<const SfxStyleSheetHint*>(&rHint); |
439 | | |
440 | 16.9M | if(pStyleHint->GetStyleSheet() == GetStyleSheet()) |
441 | 70.0k | { |
442 | 70.0k | SdrObject& rObj = GetSdrObject(); |
443 | | //SdrPage* pPage = rObj.GetPage(); |
444 | | |
445 | 70.0k | switch(id) |
446 | 70.0k | { |
447 | 0 | case SfxHintId::StyleSheetModified : |
448 | 70.0k | case SfxHintId::StyleSheetModifiedExtended: |
449 | 70.0k | case SfxHintId::StyleSheetChanged : |
450 | 70.0k | { |
451 | | // notify change |
452 | 70.0k | break; |
453 | 70.0k | } |
454 | 0 | case SfxHintId::StyleSheetErased : |
455 | 0 | case SfxHintId::StyleSheetInDestruction : |
456 | 0 | { |
457 | | // Style needs to be exchanged |
458 | 0 | SfxStyleSheet* pNewStSh = nullptr; |
459 | 0 | SdrModel& rModel(rObj.getSdrModelFromSdrObject()); |
460 | | |
461 | | // Do nothing if object is in destruction, else a StyleSheet may be found from |
462 | | // a StyleSheetPool which is just being deleted itself. and thus it would be fatal |
463 | | // to register as listener to that new StyleSheet. |
464 | 0 | if(!rObj.IsInDestruction()) |
465 | 0 | { |
466 | 0 | if(SfxStyleSheet* pStyleSheet = GetStyleSheet()) |
467 | 0 | { |
468 | 0 | pNewStSh = static_cast<SfxStyleSheet*>(rModel.GetStyleSheetPool()->Find( |
469 | 0 | pStyleSheet->GetParent(), pStyleSheet->GetFamily())); |
470 | 0 | } |
471 | |
|
472 | 0 | if(!pNewStSh) |
473 | 0 | { |
474 | 0 | pNewStSh = rModel.GetDefaultStyleSheet(); |
475 | 0 | } |
476 | 0 | } |
477 | | |
478 | | // remove used style, it's erased or in destruction |
479 | 0 | ImpRemoveStyleSheet(); |
480 | |
|
481 | 0 | if(pNewStSh) |
482 | 0 | { |
483 | 0 | ImpAddStyleSheet(pNewStSh, true); |
484 | 0 | } |
485 | |
|
486 | 0 | break; |
487 | 0 | } |
488 | 0 | default: break; |
489 | 70.0k | } |
490 | | |
491 | | // Get old BoundRect. Do this after the style change is handled |
492 | | // in the ItemSet parts because GetBoundRect() may calculate a new |
493 | 70.0k | tools::Rectangle aBoundRect = rObj.GetLastBoundRect(); |
494 | | |
495 | 70.0k | rObj.SetBoundAndSnapRectsDirty(/*bNotMyself*/true); |
496 | | |
497 | | // tell the object about the change |
498 | 70.0k | rObj.SetChanged(); |
499 | 70.0k | rObj.BroadcastObjectChange(); |
500 | | |
501 | | //if(pPage && pPage->IsInserted()) |
502 | | //{ |
503 | | // rObj.BroadcastObjectChange(); |
504 | | //} |
505 | | |
506 | 70.0k | rObj.SendUserCall(SdrUserCallType::ChangeAttr, aBoundRect); |
507 | | |
508 | 70.0k | bHintUsed = true; |
509 | 70.0k | } |
510 | 16.9M | } |
511 | 17.3M | if(!bHintUsed) |
512 | 17.2M | { |
513 | | // forward to SdrObject ATM. Not sure if this will be necessary |
514 | | // in the future. |
515 | 17.2M | GetSdrObject().Notify(rBC, rHint); |
516 | 17.2M | } |
517 | 17.3M | } |
518 | | |
519 | | bool AttributeProperties::isUsedByModel() const |
520 | 38 | { |
521 | 38 | const SdrObject& rObj(GetSdrObject()); |
522 | 38 | if (rObj.IsInserted()) |
523 | 38 | { |
524 | 38 | const SdrPage* const pPage(rObj.getSdrPageFromSdrObject()); |
525 | 38 | if (pPage && pPage->IsInserted()) |
526 | 38 | return true; |
527 | 38 | } |
528 | 0 | return false; |
529 | 38 | } |
530 | | |
531 | | void AttributeProperties::applyDefaultStyleSheetFromSdrModel() |
532 | 1.51M | { |
533 | 1.51M | SfxStyleSheet* pDefaultStyleSheet(GetSdrObject().getSdrModelFromSdrObject().GetDefaultStyleSheet()); |
534 | | |
535 | | // tdf#118139 Only do this when StyleSheet really differs. It may e.g. |
536 | | // be the case that nullptr == pDefaultStyleSheet and there is none set yet, |
537 | | // so indeed no need to set it (needed for some strange old MSWord2003 |
538 | | // documents with CustomShape-'Group' and added Text-Frames, see task description) |
539 | 1.51M | if(pDefaultStyleSheet != GetStyleSheet()) |
540 | 657k | { |
541 | | // do not delete hard attributes when setting dsefault Style |
542 | 657k | SetStyleSheet(pDefaultStyleSheet, true, true); |
543 | 657k | } |
544 | 1.51M | } |
545 | | |
546 | | } // end of namespace |
547 | | |
548 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |