android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / attr / format.cxx
blobfe341f21b8daca9ff8cff8870183cd7c0467deed
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <DocumentSettingManager.hxx> //For SwFmt::getIDocumentSettingAccess()
21 #include <IDocumentTimerAccess.hxx>
22 #include <doc.hxx>
23 #include <fmtcolfunc.hxx>
24 #include <format.hxx>
25 #include <frmatr.hxx>
26 #include <hintids.hxx>
27 #include <hints.hxx>
28 #include <o3tl/unit_conversion.hxx>
29 #include <osl/diagnose.h>
30 #include <sal/log.hxx>
31 #include <svl/grabbagitem.hxx>
32 #include <svx/sdr/attribute/sdrallfillattributeshelper.hxx>
33 #include <svx/unobrushitemhelper.hxx>
34 #include <svx/xdef.hxx>
35 #include <utility>
37 using namespace com::sun::star;
39 SwFormat::SwFormat( SwAttrPool& rPool, const char* pFormatNm,
40 const WhichRangesContainer& pWhichRanges, SwFormat *pDrvdFrame,
41 sal_uInt16 nFormatWhich ) :
42 m_aFormatName( OUString::createFromAscii(pFormatNm) ),
43 m_aSet( rPool, pWhichRanges ),
44 m_nWhichId( nFormatWhich ),
45 m_nPoolFormatId( USHRT_MAX ),
46 m_nPoolHelpId( USHRT_MAX ),
47 m_nPoolHlpFileId( UCHAR_MAX )
49 m_bAutoUpdateOnDirectFormat = false; // LAYER_IMPL
50 m_bAutoFormat = true;
51 m_bFormatInDTOR = m_bHidden = false;
53 if( pDrvdFrame )
55 pDrvdFrame->Add(this);
56 m_aSet.SetParent( &pDrvdFrame->m_aSet );
60 SwFormat::SwFormat( SwAttrPool& rPool, OUString aFormatNm,
61 const WhichRangesContainer& pWhichRanges, SwFormat* pDrvdFrame,
62 sal_uInt16 nFormatWhich ) :
63 m_aFormatName( std::move(aFormatNm) ),
64 m_aSet( rPool, pWhichRanges ),
65 m_nWhichId( nFormatWhich ),
66 m_nPoolFormatId( USHRT_MAX ),
67 m_nPoolHelpId( USHRT_MAX ),
68 m_nPoolHlpFileId( UCHAR_MAX )
70 m_bAutoUpdateOnDirectFormat = false; // LAYER_IMPL
71 m_bAutoFormat = true;
72 m_bFormatInDTOR = m_bHidden = false;
74 if( pDrvdFrame )
76 pDrvdFrame->Add(this);
77 m_aSet.SetParent( &pDrvdFrame->m_aSet );
81 SwFormat::SwFormat( const SwFormat& rFormat ) :
82 sw::BorderCacheOwner(),
83 m_aFormatName( rFormat.m_aFormatName ),
84 m_aSet( rFormat.m_aSet ),
85 m_nWhichId( rFormat.m_nWhichId ),
86 m_nPoolFormatId( rFormat.GetPoolFormatId() ),
87 m_nPoolHelpId( rFormat.GetPoolHelpId() ),
88 m_nPoolHlpFileId( rFormat.GetPoolHlpFileId() )
90 m_bFormatInDTOR = false; // LAYER_IMPL
91 m_bAutoFormat = rFormat.m_bAutoFormat;
92 m_bHidden = rFormat.m_bHidden;
93 m_bAutoUpdateOnDirectFormat = rFormat.m_bAutoUpdateOnDirectFormat;
95 if( auto pDerived = rFormat.DerivedFrom() )
97 pDerived->Add(this);
98 m_aSet.SetParent( &pDerived->m_aSet );
100 // a few special treatments for attributes
101 m_aSet.SetModifyAtAttr( this );
104 SwFormat &SwFormat::operator=(const SwFormat& rFormat)
106 if(this == &rFormat)
107 return *this;
109 m_nWhichId = rFormat.m_nWhichId;
110 m_nPoolFormatId = rFormat.GetPoolFormatId();
111 m_nPoolHelpId = rFormat.GetPoolHelpId();
112 m_nPoolHlpFileId = rFormat.GetPoolHlpFileId();
114 InvalidateInSwCache(RES_OBJECTDYING);
116 // copy only array with attributes delta
117 SwAttrSet aOld( *m_aSet.GetPool(), m_aSet.GetRanges() ),
118 aNew( *m_aSet.GetPool(), m_aSet.GetRanges() );
119 m_aSet.Intersect_BC( rFormat.m_aSet, &aOld, &aNew );
120 (void)m_aSet.Put_BC( rFormat.m_aSet, &aOld, &aNew );
122 // a few special treatments for attributes
123 m_aSet.SetModifyAtAttr( this );
125 // create PoolItem attribute for Modify
126 if( aOld.Count() )
128 sw::ClientNotifyAttrChg(*this, m_aSet, aOld, aNew);
131 if(GetRegisteredIn() != rFormat.GetRegisteredIn())
133 StartListeningToSameModifyAs(rFormat);
134 m_aSet.SetParent( GetRegisteredIn()
135 ? &rFormat.m_aSet
136 : nullptr);
139 m_bAutoFormat = rFormat.m_bAutoFormat;
140 m_bHidden = rFormat.m_bHidden;
141 m_bAutoUpdateOnDirectFormat = rFormat.m_bAutoUpdateOnDirectFormat;
142 return *this;
145 void SwFormat::SetFormatName( const OUString& rNewName, bool bBroadcast )
147 OSL_ENSURE( !IsDefault(), "SetName: Defaultformat" );
148 if( bBroadcast )
150 m_aFormatName = rNewName;
151 const sw::NameChanged aHint(m_aFormatName, rNewName);
152 SwClientNotify(*this, aHint);
154 else
156 m_aFormatName = rNewName;
160 /** Copy attributes
162 This function is called in every Copy-Ctor for copying the attributes.
163 The latter can be only copied as soon as the derived class exists since
164 for setting them the Which() function is called and that has the default
165 value of 0 in the base class and is then overridden by the derived class.
167 If we copy over multiple documents then the new document has to be provided
168 in which <this> is defined. Currently this is important for DropCaps
169 because that contains data that needs to be copied deeply.
171 void SwFormat::CopyAttrs( const SwFormat& rFormat )
173 // copy only array with attributes delta
174 InvalidateInSwCache(RES_ATTRSET_CHG);
175 InvalidateInSwFntCache(RES_ATTRSET_CHG);
177 // special treatments for some attributes
178 SwAttrSet* pChgSet = const_cast<SwAttrSet*>(&rFormat.m_aSet);
180 // copy only array with attributes delta
181 if( pChgSet->GetPool() != m_aSet.GetPool() )
182 pChgSet->CopyToModify( *this );
183 else
185 SwAttrSet aOld( *m_aSet.GetPool(), m_aSet.GetRanges() ),
186 aNew( *m_aSet.GetPool(), m_aSet.GetRanges() );
188 if ( m_aSet.Put_BC( *pChgSet, &aOld, &aNew ) )
190 // a few special treatments for attributes
191 m_aSet.SetModifyAtAttr( this );
193 SwAttrSetChg aChgOld( m_aSet, aOld );
194 SwAttrSetChg aChgNew( m_aSet, aNew );
195 SwClientNotify(*this, sw::LegacyModifyHint(&aChgOld, &aChgNew)); // send all modified ones
199 if( pChgSet != &rFormat.m_aSet ) // was a Set created?
200 delete pChgSet;
203 SwFormat::~SwFormat()
205 // This happens at an ObjectDying message. Thus put all dependent
206 // ones on DerivedFrom.
207 if(!HasWriterListeners())
208 return;
210 m_bFormatInDTOR = true;
212 if(!DerivedFrom())
214 SwFormat::ResetFormatAttr(RES_PAGEDESC);
215 SAL_WARN("sw.core", "~SwFormat: format still has clients on death, but parent format is missing: " << GetName());
216 return;
218 SwIterator<SwClient,SwFormat> aIter(*this);
219 for(SwClient* pClient = aIter.First(); pClient; pClient = aIter.Next())
220 pClient->CheckRegistrationFormat(*this);
221 assert(!HasWriterListeners());
224 void SwFormat::SwClientNotify(const SwModify&, const SfxHint& rHint)
226 if (rHint.GetId() != SfxHintId::SwLegacyModify)
227 return;
228 auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
230 std::optional<SwAttrSetChg> oOldClientChg, oNewClientChg;
231 std::optional<sw::LegacyModifyHint> oDependsHint(std::in_place, pLegacy->m_pOld, pLegacy->m_pNew);
232 const sal_uInt16 nWhich = pLegacy->GetWhich();
233 InvalidateInSwCache(nWhich);
234 switch(nWhich)
236 case 0:
237 break;
238 case RES_OBJECTDYING:
240 // NB: this still notifies depends even if pLegacy->m_pNew is nullptr, which seems non-obvious
241 if(!pLegacy->m_pNew)
242 break;
243 // If the dying object is the parent format of this format so
244 // attach this to the parent of the parent
245 SwFormat* pFormat = static_cast<SwFormat*>(pLegacy->m_pNew->StaticWhichCast(RES_OBJECTDYING).pObject);
247 // do not move if this is the topmost format
248 if(GetRegisteredIn() && GetRegisteredIn() == pFormat)
250 if(pFormat->GetRegisteredIn())
252 // if parent so register in new parent
253 pFormat->DerivedFrom()->Add(this);
254 m_aSet.SetParent(&DerivedFrom()->m_aSet);
256 else
258 // otherwise de-register at least from dying one
259 EndListeningAll();
260 m_aSet.SetParent(nullptr);
263 break;
265 case RES_ATTRSET_CHG:
267 // NB: this still notifies depends even if this condition is not met, which seems non-obvious
268 auto pOldAttrSetChg = static_cast<const SwAttrSetChg*>(pLegacy->m_pOld);
269 auto pNewAttrSetChg = static_cast<const SwAttrSetChg*>(pLegacy->m_pNew);
270 if (pOldAttrSetChg && pNewAttrSetChg && pOldAttrSetChg->GetTheChgdSet() != &m_aSet)
272 // pass only those that are not set...
273 oNewClientChg.emplace(*pNewAttrSetChg);
274 oNewClientChg->GetChgSet()->Differentiate(m_aSet);
275 if(oNewClientChg->Count()) // ... if any
277 oOldClientChg.emplace(*pOldAttrSetChg);
278 oOldClientChg->GetChgSet()->Differentiate(m_aSet);
279 oDependsHint.emplace(&*oOldClientChg, &*oNewClientChg);
281 else
282 oDependsHint.reset();
284 break;
286 case RES_FMT_CHG:
288 // if the format parent will be moved so register my attribute set at
289 // the new one
291 // skip my own Modify
292 // NB: this still notifies depends even if this condition is not met, which seems non-obvious
293 auto pOldFormatChg = static_cast<const SwFormatChg*>(pLegacy->m_pOld);
294 auto pNewFormatChg = static_cast<const SwFormatChg*>(pLegacy->m_pNew);
295 if(pOldFormatChg && pNewFormatChg && pOldFormatChg->pChangedFormat != this && pNewFormatChg->pChangedFormat == GetRegisteredIn())
297 // attach Set to new parent
298 m_aSet.SetParent(DerivedFrom() ? &DerivedFrom()->m_aSet : nullptr);
300 break;
302 default:
303 // attribute is defined in this format
304 if(SfxItemState::SET == m_aSet.GetItemState(nWhich, false))
306 // DropCaps might come into this block
307 SAL_WARN_IF(RES_PARATR_DROP != nWhich, "sw.core", "Hint was sent without sender");
308 oDependsHint.reset();
311 if(oDependsHint)
313 InvalidateInSwFntCache(oDependsHint->GetWhich());
314 SwModify::SwClientNotify(*this, *oDependsHint);
318 bool SwFormat::SetDerivedFrom(SwFormat *pDerFrom)
320 if ( pDerFrom )
322 const SwFormat* pFormat = pDerFrom;
323 while ( pFormat != nullptr )
325 if ( pFormat == this )
326 return false;
328 pFormat=pFormat->DerivedFrom();
331 else
333 // nothing provided, search for Dflt format
334 pDerFrom = this;
335 while ( pDerFrom->DerivedFrom() )
336 pDerFrom = pDerFrom->DerivedFrom();
338 if ( (pDerFrom == DerivedFrom()) || (pDerFrom == this) )
339 return false;
341 assert( Which()==pDerFrom->Which()
342 || (Which()==RES_CONDTXTFMTCOLL && pDerFrom->Which()==RES_TXTFMTCOLL)
343 || (Which()==RES_TXTFMTCOLL && pDerFrom->Which()==RES_CONDTXTFMTCOLL)
344 || (Which()==RES_FLYFRMFMT && pDerFrom->Which()==RES_FRMFMT)
347 InvalidateInSwCache(RES_ATTRSET_CHG);
348 InvalidateInSwFntCache(RES_ATTRSET_CHG);
350 pDerFrom->Add( this );
351 m_aSet.SetParent( &pDerFrom->m_aSet );
353 SwFormatChg aOldFormat( this );
354 SwFormatChg aNewFormat( this );
355 const sw::LegacyModifyHint aHint(&aOldFormat, &aNewFormat);
356 SwClientNotify(*this, aHint);
358 return true;
361 bool SwFormat::supportsFullDrawingLayerFillAttributeSet() const
363 return false;
366 const SfxPoolItem& SwFormat::GetFormatAttr( sal_uInt16 nWhich, bool bInParents ) const
368 if (RES_BACKGROUND == nWhich && supportsFullDrawingLayerFillAttributeSet())
370 // FALLBACKBREAKHERE should not be used; instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST]
371 SAL_INFO("sw.core", "Do no longer use SvxBrushItem, instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST] FillAttributes or makeBackgroundBrushItem (simple fallback is in place and used)");
372 static std::unique_ptr<SvxBrushItem> aSvxBrushItem; //(std::make_shared<SvxBrushItem>(RES_BACKGROUND));
374 // fill the local static SvxBrushItem from the current ItemSet so that
375 // the fill attributes [XATTR_FILL_FIRST .. XATTR_FILL_LAST] are used
376 // as good as possible to create a fallback representation and return that
377 aSvxBrushItem = getSvxBrushItemFromSourceSet(m_aSet, RES_BACKGROUND, bInParents);
379 return *aSvxBrushItem;
382 return m_aSet.Get( nWhich, bInParents );
385 SfxItemState SwFormat::GetItemState( sal_uInt16 nWhich, bool bSrchInParent, const SfxPoolItem **ppItem ) const
387 if (RES_BACKGROUND == nWhich && supportsFullDrawingLayerFillAttributeSet())
389 // FALLBACKBREAKHERE should not be used; instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST]
390 SAL_INFO("sw.core", "Do no longer use SvxBrushItem, instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST] FillAttributes or SwFormat::GetBackgroundStat (simple fallback is in place and used)");
391 const drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFill = getSdrAllFillAttributesHelper();
393 // check if the new fill attributes are used
394 if(aFill && aFill->isUsed())
396 // if yes, fill the local SvxBrushItem using the new fill attributes
397 // as good as possible to have an instance for the pointer to point
398 // to and return as state that it is set
399 static std::unique_ptr<SvxBrushItem> aSvxBrushItem; //(RES_BACKGROUND);
401 aSvxBrushItem = getSvxBrushItemFromSourceSet(m_aSet, RES_BACKGROUND, bSrchInParent);
402 if( ppItem )
403 *ppItem = aSvxBrushItem.get();
405 return SfxItemState::SET;
408 // if not, reset pointer and return SfxItemState::DEFAULT to signal that
409 // the item is not set
410 if( ppItem )
411 *ppItem = nullptr;
413 return SfxItemState::DEFAULT;
416 return m_aSet.GetItemState( nWhich, bSrchInParent, ppItem );
419 SfxItemState SwFormat::GetBackgroundState(std::unique_ptr<SvxBrushItem>& rItem) const
421 if (supportsFullDrawingLayerFillAttributeSet())
423 // FALLBACKBREAKHERE should not be used; instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST]
424 const drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFill = getSdrAllFillAttributesHelper();
426 // check if the new fill attributes are used
427 if(aFill && aFill->isUsed())
429 // if yes, fill the local SvxBrushItem using the new fill attributes
430 // as good as possible to have an instance for the pointer to point
431 // to and return as state that it is set
432 rItem = getSvxBrushItemFromSourceSet(m_aSet, RES_BACKGROUND);
433 return SfxItemState::SET;
436 // if not return SfxItemState::DEFAULT to signal that the item is not set
437 return SfxItemState::DEFAULT;
440 const SvxBrushItem* pItem = nullptr;
441 SfxItemState eRet = m_aSet.GetItemState(RES_BACKGROUND, true, &pItem);
442 if (pItem)
443 rItem.reset(pItem->Clone());
444 return eRet;
447 bool SwFormat::SetFormatAttr( const SfxPoolItem& rAttr )
449 const sal_uInt16 nWhich = rAttr.Which();
450 InvalidateInSwFntCache( nWhich );
451 InvalidateInSwCache( nWhich );
453 bool bRet = false;
455 if (RES_BACKGROUND == rAttr.Which() && supportsFullDrawingLayerFillAttributeSet())
457 // FALLBACKBREAKHERE should not be used; instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST]
458 SAL_INFO("sw.core", "Do no longer use SvxBrushItem, instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST] FillAttributes (simple fallback is in place and used)");
459 SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST> aTempSet(*m_aSet.GetPool());
460 const SvxBrushItem& rSource = rAttr.StaticWhichCast(RES_BACKGROUND);
462 // fill a local ItemSet with the attributes corresponding as good as possible
463 // to the new fill properties [XATTR_FILL_FIRST .. XATTR_FILL_LAST] and set these
464 // as ItemSet
465 setSvxBrushItemAsFillAttributesToTargetSet(rSource, aTempSet);
467 if(IsModifyLocked())
469 bRet = m_aSet.Put( aTempSet );
470 if( bRet )
472 m_aSet.SetModifyAtAttr( this );
475 else
477 SwAttrSet aOld(*m_aSet.GetPool(), m_aSet.GetRanges()), aNew(*m_aSet.GetPool(), m_aSet.GetRanges());
479 bRet = m_aSet.Put_BC(aTempSet, &aOld, &aNew);
481 if(bRet)
483 m_aSet.SetModifyAtAttr(this);
484 sw::ClientNotifyAttrChg(*this, m_aSet, aOld, aNew);
488 return bRet;
491 // if Modify is locked then no modifications will be sent;
492 // but call Modify always for FrameFormats
493 const sal_uInt16 nFormatWhich = Which();
494 if( IsModifyLocked() ||
495 ( !HasWriterListeners() &&
496 (RES_GRFFMTCOLL == nFormatWhich ||
497 RES_TXTFMTCOLL == nFormatWhich ) ) )
499 bRet = nullptr != m_aSet.Put( rAttr );
500 if( bRet )
501 m_aSet.SetModifyAtAttr( this );
502 // #i71574#
503 if ( nFormatWhich == RES_TXTFMTCOLL && rAttr.Which() == RES_PARATR_NUMRULE )
505 TextFormatCollFunc::CheckTextFormatCollForDeletionOfAssignmentToOutlineStyle( this );
508 else
510 // copy only array with attributes delta
511 SwAttrSet aOld( *m_aSet.GetPool(), m_aSet.GetRanges() ),
512 aNew( *m_aSet.GetPool(), m_aSet.GetRanges() );
514 bRet = m_aSet.Put_BC( rAttr, &aOld, &aNew );
515 if( bRet )
517 // some special treatments for attributes
518 m_aSet.SetModifyAtAttr( this );
520 sw::ClientNotifyAttrChg(*this, m_aSet, aOld, aNew);
523 return bRet;
526 bool SwFormat::SetFormatAttr( const SfxItemSet& rSet )
528 if( !rSet.Count() )
529 return false;
531 InvalidateInSwCache(RES_ATTRSET_CHG);
532 InvalidateInSwFntCache(RES_ATTRSET_CHG);
534 bool bRet = false;
536 // Use local copy to be able to apply needed changes, e.g. call
537 // CheckForUniqueItemForLineFillNameOrIndex which is needed for NameOrIndex stuff
538 SfxItemSet aTempSet(rSet);
540 // Need to check for unique item for DrawingLayer items of type NameOrIndex
541 // and evtl. correct that item to ensure unique names for that type. This call may
542 // modify/correct entries inside of the given SfxItemSet
543 if(GetDoc())
545 GetDoc()->CheckForUniqueItemForLineFillNameOrIndex(aTempSet);
548 if (supportsFullDrawingLayerFillAttributeSet())
550 if(const SvxBrushItem* pSource = aTempSet.GetItemIfSet(RES_BACKGROUND, false))
552 // FALLBACKBREAKHERE should not be used; instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST]
553 SAL_INFO("sw.core", "Do no longer use SvxBrushItem, instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST] FillAttributes (simple fallback is in place and used)");
555 // copy all items to be set anyways to a local ItemSet with is also prepared for the new
556 // fill attribute ranges [XATTR_FILL_FIRST .. XATTR_FILL_LAST]. Add the attributes
557 // corresponding as good as possible to the new fill properties and set the whole ItemSet
558 setSvxBrushItemAsFillAttributesToTargetSet(*pSource, aTempSet);
560 if(IsModifyLocked())
562 bRet = m_aSet.Put( aTempSet );
563 if( bRet )
565 m_aSet.SetModifyAtAttr( this );
568 else
570 SwAttrSet aOld(*m_aSet.GetPool(), m_aSet.GetRanges()), aNew(*m_aSet.GetPool(), m_aSet.GetRanges());
572 bRet = m_aSet.Put_BC(aTempSet, &aOld, &aNew);
574 if(bRet)
576 m_aSet.SetModifyAtAttr(this);
577 sw::ClientNotifyAttrChg(*this, m_aSet, aOld, aNew);
581 return bRet;
585 // if Modify is locked then no modifications will be sent;
586 // but call Modify always for FrameFormats
587 const sal_uInt16 nFormatWhich = Which();
588 if ( IsModifyLocked() ||
589 ( !HasWriterListeners() &&
590 ( RES_GRFFMTCOLL == nFormatWhich ||
591 RES_TXTFMTCOLL == nFormatWhich ) ) )
593 bRet = m_aSet.Put( aTempSet );
594 if( bRet )
595 m_aSet.SetModifyAtAttr( this );
596 // #i71574#
597 if ( nFormatWhich == RES_TXTFMTCOLL )
599 TextFormatCollFunc::CheckTextFormatCollForDeletionOfAssignmentToOutlineStyle( this );
602 else
604 SwAttrSet aOld( *m_aSet.GetPool(), m_aSet.GetRanges() ),
605 aNew( *m_aSet.GetPool(), m_aSet.GetRanges() );
606 bRet = m_aSet.Put_BC( aTempSet, &aOld, &aNew );
607 if( bRet )
609 // some special treatments for attributes
610 m_aSet.SetModifyAtAttr( this );
611 sw::ClientNotifyAttrChg(*this, m_aSet, aOld, aNew);
614 return bRet;
617 // remove Hint using nWhich from array with delta
618 bool SwFormat::ResetFormatAttr( sal_uInt16 nWhich1, sal_uInt16 nWhich2 )
620 if( !m_aSet.Count() )
621 return false;
623 if( !nWhich2 || nWhich2 < nWhich1 )
624 nWhich2 = nWhich1; // then set to 1st ID, only this item
626 for( sal_uInt16 n = nWhich1; n < nWhich2; ++n )
627 InvalidateInSwFntCache( n );
628 for( sal_uInt16 n = nWhich1; n < nWhich2 && IsInCache(); ++n )
629 InvalidateInSwCache( n );
631 // if Modify is locked then no modifications will be sent
632 if( IsModifyLocked() )
633 return 0 != (( nWhich2 == nWhich1 )
634 ? m_aSet.ClearItem( nWhich1 )
635 : m_aSet.ClearItem_BC( nWhich1, nWhich2 ));
637 SwAttrSet aOld( *m_aSet.GetPool(), m_aSet.GetRanges() ),
638 aNew( *m_aSet.GetPool(), m_aSet.GetRanges() );
639 bool bRet = 0 != m_aSet.ClearItem_BC( nWhich1, nWhich2, &aOld, &aNew );
640 if( bRet )
641 sw::ClientNotifyAttrChg(*this, m_aSet, aOld, aNew);
642 return bRet;
645 // #i73790#
646 sal_uInt16 SwFormat::ResetAllFormatAttr()
648 if( !m_aSet.Count() )
649 return 0;
651 InvalidateInSwCache(RES_ATTRSET_CHG);
652 InvalidateInSwFntCache(RES_ATTRSET_CHG);
654 // if Modify is locked then no modifications will be sent
655 if( IsModifyLocked() )
656 return m_aSet.ClearItem();
658 SwAttrSet aOld( *m_aSet.GetPool(), m_aSet.GetRanges() ),
659 aNew( *m_aSet.GetPool(), m_aSet.GetRanges() );
660 bool bRet = 0 != m_aSet.ClearItem_BC( 0, &aOld, &aNew );
661 if( bRet )
662 sw::ClientNotifyAttrChg(*this, m_aSet, aOld, aNew);
663 return aNew.Count();
666 void SwFormat::DelDiffs( const SfxItemSet& rSet )
668 if( !m_aSet.Count() )
669 return;
671 InvalidateInSwCache(RES_ATTRSET_CHG);
672 InvalidateInSwFntCache(RES_ATTRSET_CHG);
674 // if Modify is locked then no modifications will be sent
675 if( IsModifyLocked() )
677 m_aSet.Intersect( rSet );
678 return;
681 SwAttrSet aOld( *m_aSet.GetPool(), m_aSet.GetRanges() ),
682 aNew( *m_aSet.GetPool(), m_aSet.GetRanges() );
683 bool bRet = 0 != m_aSet.Intersect_BC( rSet, &aOld, &aNew );
684 if( bRet )
685 sw::ClientNotifyAttrChg(*this, m_aSet, aOld, aNew);
688 void SwFormat::SetPageFormatToDefault()
690 const sal_Int32 nSize = o3tl::convert(2, o3tl::Length::cm, o3tl::Length::twip);
691 SetFormatAttr(SvxLRSpaceItem(nSize, nSize, 0, RES_LR_SPACE));
692 SetFormatAttr(SvxULSpaceItem(nSize, nSize, RES_UL_SPACE));
695 /** SwFormat::IsBackgroundTransparent
697 Virtual method to determine, if background of format is transparent.
698 Default implementation returns false. Thus, subclasses have to override
699 method, if the specific subclass can have a transparent background.
701 @return false, default implementation
703 bool SwFormat::IsBackgroundTransparent() const
705 return false;
709 * Document Interface Access
711 const IDocumentSettingAccess& SwFormat::getIDocumentSettingAccess() const { return GetDoc()->GetDocumentSettingManager(); }
712 const IDocumentDrawModelAccess& SwFormat::getIDocumentDrawModelAccess() const { return GetDoc()->getIDocumentDrawModelAccess(); }
713 IDocumentDrawModelAccess& SwFormat::getIDocumentDrawModelAccess() { return GetDoc()->getIDocumentDrawModelAccess(); }
714 const IDocumentLayoutAccess& SwFormat::getIDocumentLayoutAccess() const { return GetDoc()->getIDocumentLayoutAccess(); }
715 IDocumentLayoutAccess& SwFormat::getIDocumentLayoutAccess() { return GetDoc()->getIDocumentLayoutAccess(); }
716 IDocumentTimerAccess& SwFormat::getIDocumentTimerAccess() { return GetDoc()->getIDocumentTimerAccess(); }
717 IDocumentFieldsAccess& SwFormat::getIDocumentFieldsAccess() { return GetDoc()->getIDocumentFieldsAccess(); }
718 IDocumentChartDataProviderAccess& SwFormat::getIDocumentChartDataProviderAccess() { return GetDoc()->getIDocumentChartDataProviderAccess(); }
720 void SwFormat::GetGrabBagItem(uno::Any& rVal) const
722 if (m_pGrabBagItem)
723 m_pGrabBagItem->QueryValue(rVal);
724 else
725 rVal <<= uno::Sequence<beans::PropertyValue>();
728 void SwFormat::SetGrabBagItem(const uno::Any& rVal)
730 if (!m_pGrabBagItem)
731 m_pGrabBagItem = std::make_shared<SfxGrabBagItem>();
733 m_pGrabBagItem->PutValue(rVal, 0);
736 std::unique_ptr<SvxBrushItem> SwFormat::makeBackgroundBrushItem(bool bInP) const
738 if (supportsFullDrawingLayerFillAttributeSet())
740 // FALLBACKBREAKHERE should not be used; instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST]
741 SAL_INFO("sw.core", "Do no longer use SvxBrushItem, instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST] FillAttributes (simple fallback is in place and used)");
743 // fill the local static SvxBrushItem from the current ItemSet so that
744 // the fill attributes [XATTR_FILL_FIRST .. XATTR_FILL_LAST] are used
745 // as good as possible to create a fallback representation and return that
746 return getSvxBrushItemFromSourceSet(m_aSet, RES_BACKGROUND, bInP);
749 return std::unique_ptr<SvxBrushItem>(m_aSet.GetBackground(bInP).Clone());
752 drawinglayer::attribute::SdrAllFillAttributesHelperPtr SwFormat::getSdrAllFillAttributesHelper() const
754 return drawinglayer::attribute::SdrAllFillAttributesHelperPtr();
757 void SwFormat::RemoveAllUnos()
759 SwPtrMsgPoolItem aMsgHint(RES_REMOVE_UNO_OBJECT, this);
760 SwClientNotify(*this, sw::LegacyModifyHint(&aMsgHint, &aMsgHint));
763 SwFormatsBase::~SwFormatsBase()
766 SwFormat* SwFormatsBase::FindFormatByName( const OUString& rName ) const
768 SwFormat* pFnd = nullptr;
769 for( size_t n = 0; n < GetFormatCount(); ++n )
771 // Does the Doc already contain the template?
772 if( GetFormat(n)->HasName( rName ) )
774 pFnd = GetFormat(n);
775 break;
778 return pFnd;
781 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */