nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / core / attr / format.cxx
blob459f66ccd3f258cbeb1b1c3128193452d2fda26f
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 <doc.hxx>
21 #include <DocumentSettingManager.hxx> //For SwFmt::getIDocumentSettingAccess()
22 #include <IDocumentTimerAccess.hxx>
23 #include <fmtcolfunc.hxx>
24 #include <frame.hxx>
25 #include <format.hxx>
26 #include <hintids.hxx>
27 #include <hints.hxx>
28 #include <swcache.hxx>
29 #include <frmatr.hxx>
30 #include <svl/grabbagitem.hxx>
31 #include <svx/sdr/attribute/sdrallfillattributeshelper.hxx>
32 #include <svx/unobrushitemhelper.hxx>
33 #include <svx/xdef.hxx>
34 #include <sal/log.hxx>
36 using namespace com::sun::star;
39 SwFormat::SwFormat( SwAttrPool& rPool, const char* pFormatNm,
40 const sal_uInt16* 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_bAutoUpdateFormat = 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, const OUString& rFormatNm,
61 const sal_uInt16* pWhichRanges, SwFormat* pDrvdFrame,
62 sal_uInt16 nFormatWhich ) :
63 m_aFormatName( rFormatNm ),
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_bAutoUpdateFormat = 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 m_aFormatName( rFormat.m_aFormatName ),
83 m_aSet( rFormat.m_aSet ),
84 m_nWhichId( rFormat.m_nWhichId ),
85 m_nPoolFormatId( rFormat.GetPoolFormatId() ),
86 m_nPoolHelpId( rFormat.GetPoolHelpId() ),
87 m_nPoolHlpFileId( rFormat.GetPoolHlpFileId() )
89 m_bFormatInDTOR = false; // LAYER_IMPL
90 m_bAutoFormat = rFormat.m_bAutoFormat;
91 m_bHidden = rFormat.m_bHidden;
92 m_bAutoUpdateFormat = rFormat.m_bAutoUpdateFormat;
94 if( auto pDerived = rFormat.DerivedFrom() )
96 pDerived->Add(this);
97 m_aSet.SetParent( &pDerived->m_aSet );
99 // a few special treatments for attributes
100 m_aSet.SetModifyAtAttr( this );
103 SwFormat &SwFormat::operator=(const SwFormat& rFormat)
105 if(this == &rFormat)
106 return *this;
108 m_nWhichId = rFormat.m_nWhichId;
109 m_nPoolFormatId = rFormat.GetPoolFormatId();
110 m_nPoolHelpId = rFormat.GetPoolHelpId();
111 m_nPoolHlpFileId = rFormat.GetPoolHlpFileId();
113 if ( IsInCache() )
115 SwFrame::GetCache().Delete( this );
116 SetInCache( false );
118 SetInSwFntCache( false );
120 // copy only array with attributes delta
121 SwAttrSet aOld( *m_aSet.GetPool(), m_aSet.GetRanges() ),
122 aNew( *m_aSet.GetPool(), m_aSet.GetRanges() );
123 m_aSet.Intersect_BC( rFormat.m_aSet, &aOld, &aNew );
124 (void)m_aSet.Put_BC( rFormat.m_aSet, &aOld, &aNew );
126 // a few special treatments for attributes
127 m_aSet.SetModifyAtAttr( this );
129 // create PoolItem attribute for Modify
130 if( aOld.Count() )
132 sw::ClientNotifyAttrChg(*this, m_aSet, aOld, aNew);
135 if(GetRegisteredIn() != rFormat.GetRegisteredIn())
137 StartListeningToSameModifyAs(rFormat);
138 m_aSet.SetParent( GetRegisteredIn()
139 ? &rFormat.m_aSet
140 : nullptr);
143 m_bAutoFormat = rFormat.m_bAutoFormat;
144 m_bHidden = rFormat.m_bHidden;
145 m_bAutoUpdateFormat = rFormat.m_bAutoUpdateFormat;
146 return *this;
149 void SwFormat::SetName( const OUString& rNewName, bool bBroadcast )
151 OSL_ENSURE( !IsDefault(), "SetName: Defaultformat" );
152 if( bBroadcast )
154 SwStringMsgPoolItem aOld( RES_NAME_CHANGED, m_aFormatName );
155 SwStringMsgPoolItem aNew( RES_NAME_CHANGED, rNewName );
156 m_aFormatName = rNewName;
157 const sw::LegacyModifyHint aHint(&aOld, &aNew);
158 SwClientNotify(*this, aHint);
160 else
162 m_aFormatName = rNewName;
166 /** Copy attributes
168 This function is called in every Copy-Ctor for copying the attributes.
169 The latter can be only copied as soon as the derived class exists since
170 for setting them the Which() function is called and that has the default
171 value of 0 in the base class and is then overridden by the derived class.
173 If we copy over multiple documents then the new document has to be provided
174 in which <this> is defined. Currently this is important for DropCaps
175 because that contains data that needs to be copied deeply.
177 void SwFormat::CopyAttrs( const SwFormat& rFormat )
179 // copy only array with attributes delta
180 if ( IsInCache() )
182 SwFrame::GetCache().Delete( this );
183 SetInCache( false );
185 SetInSwFntCache( false );
187 // special treatments for some attributes
188 SwAttrSet* pChgSet = const_cast<SwAttrSet*>(&rFormat.m_aSet);
190 // copy only array with attributes delta
191 if( pChgSet->GetPool() != m_aSet.GetPool() )
192 pChgSet->CopyToModify( *this );
193 else
195 SwAttrSet aOld( *m_aSet.GetPool(), m_aSet.GetRanges() ),
196 aNew( *m_aSet.GetPool(), m_aSet.GetRanges() );
198 if ( m_aSet.Put_BC( *pChgSet, &aOld, &aNew ) )
200 // a few special treatments for attributes
201 m_aSet.SetModifyAtAttr( this );
203 SwAttrSetChg aChgOld( m_aSet, aOld );
204 SwAttrSetChg aChgNew( m_aSet, aNew );
205 SwClientNotify(*this, sw::LegacyModifyHint(&aChgOld, &aChgNew)); // send all modified ones
209 if( pChgSet != &rFormat.m_aSet ) // was a Set created?
210 delete pChgSet;
213 SwFormat::~SwFormat()
215 // This happens at an ObjectDying message. Thus put all dependent
216 // ones on DerivedFrom.
217 if( !HasWriterListeners() )
218 return;
220 m_bFormatInDTOR = true;
222 SwFormat* pParentFormat = DerivedFrom();
223 if( !pParentFormat )
225 SAL_WARN(
226 "sw.core",
227 "~SwFormat: parent format missing from: " << GetName() );
229 else
231 SwFormatChg aOldFormat( this );
232 SwFormatChg aNewFormat( pParentFormat );
233 SwIterator<SwClient,SwFormat> aIter(*this);
234 for(SwClient* pClient = aIter.First(); pClient && pParentFormat; pClient = aIter.Next())
236 SAL_INFO("sw.core", "reparenting " << typeid(*pClient).name() << " at " << pClient << " from " << typeid(*this).name() << " at " << this << " to " << typeid(*pParentFormat).name() << " at " << pParentFormat);
237 pParentFormat->Add( pClient );
238 const sw::LegacyModifyHint aHint(&aOldFormat, &aNewFormat);
239 pClient->SwClientNotifyCall(*this, aHint);
244 void SwFormat::Modify( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue )
246 std::unique_ptr<SwAttrSetChg> pOldClientChg, pNewClientChg;
247 auto aDependArgs = std::pair<const SfxPoolItem*, const SfxPoolItem*>(pOldValue, pNewValue);
248 bool bPassToDepends = true;
249 const sal_uInt16 nWhich = pOldValue ? pOldValue->Which()
250 : pNewValue ? pNewValue->Which()
251 : 0;
252 switch( nWhich )
254 case 0: break; // Which-Id of 0?
256 case RES_OBJECTDYING:
257 // NB: this still notifies depends even if pNewValue is nullptr, which seems non-obvious
258 if (pNewValue)
260 // If the dying object is the parent format of this format so
261 // attach this to the parent of the parent
262 SwFormat* pFormat = static_cast<SwFormat*>(static_cast<const SwPtrMsgPoolItem*>(pNewValue)->pObject);
264 // do not move if this is the topmost format
265 if( GetRegisteredIn() && GetRegisteredIn() == pFormat )
267 if( pFormat->GetRegisteredIn() )
269 // if parent so register in new parent
270 pFormat->DerivedFrom()->Add( this );
271 m_aSet.SetParent( &DerivedFrom()->m_aSet );
273 else
275 // otherwise de-register at least from dying one
276 EndListeningAll();
277 m_aSet.SetParent( nullptr );
281 break;
282 case RES_ATTRSET_CHG:
283 // NB: this still notifies depends even if this condition is not met, which seems non-obvious
284 if (pOldValue && pNewValue && static_cast<const SwAttrSetChg*>(pOldValue)->GetTheChgdSet() != &m_aSet)
286 // pass only those that are not set...
287 pNewClientChg.reset( new SwAttrSetChg(*static_cast<const SwAttrSetChg*>(pNewValue)) );
288 pNewClientChg->GetChgSet()->Differentiate( m_aSet );
289 if(pNewClientChg->Count()) // ... if any
291 pOldClientChg.reset( new SwAttrSetChg(*static_cast<const SwAttrSetChg*>(pOldValue)) );
292 pOldClientChg->GetChgSet()->Differentiate( m_aSet );
293 aDependArgs = std::pair<const SfxPoolItem*, const SfxPoolItem*>(pOldClientChg.get(), pNewClientChg.get());
295 else
296 bPassToDepends = false;
298 break;
299 case RES_FMT_CHG:
300 // if the format parent will be moved so register my attribute set at
301 // the new one
303 // skip my own Modify
304 // NB: this still notifies depends even if this condition is not met, which seems non-obvious
305 if ( pOldValue && pNewValue &&
306 static_cast<const SwFormatChg*>(pOldValue)->pChangedFormat != this &&
307 static_cast<const SwFormatChg*>(pNewValue)->pChangedFormat == GetRegisteredIn() )
309 // attach Set to new parent
310 m_aSet.SetParent( DerivedFrom() ? &DerivedFrom()->m_aSet : nullptr );
312 break;
313 default:
315 // attribute is defined in this format
316 if( SfxItemState::SET == m_aSet.GetItemState( nWhich, false ))
318 // DropCaps might come into this block
319 OSL_ENSURE( RES_PARATR_DROP == nWhich, "Modify was sent without sender" );
320 bPassToDepends = false;
324 if(bPassToDepends)
325 NotifyClients(aDependArgs.first, aDependArgs.second);
328 bool SwFormat::SetDerivedFrom(SwFormat *pDerFrom)
330 if ( pDerFrom )
332 const SwFormat* pFormat = pDerFrom;
333 while ( pFormat != nullptr )
335 if ( pFormat == this )
336 return false;
338 pFormat=pFormat->DerivedFrom();
341 else
343 // nothing provided, search for Dflt format
344 pDerFrom = this;
345 while ( pDerFrom->DerivedFrom() )
346 pDerFrom = pDerFrom->DerivedFrom();
348 if ( (pDerFrom == DerivedFrom()) || (pDerFrom == this) )
349 return false;
351 assert( Which()==pDerFrom->Which()
352 || (Which()==RES_CONDTXTFMTCOLL && pDerFrom->Which()==RES_TXTFMTCOLL)
353 || (Which()==RES_TXTFMTCOLL && pDerFrom->Which()==RES_CONDTXTFMTCOLL)
354 || (Which()==RES_FLYFRMFMT && pDerFrom->Which()==RES_FRMFMT)
357 if ( IsInCache() )
359 SwFrame::GetCache().Delete( this );
360 SetInCache( false );
362 SetInSwFntCache( false );
364 pDerFrom->Add( this );
365 m_aSet.SetParent( &pDerFrom->m_aSet );
367 SwFormatChg aOldFormat( this );
368 SwFormatChg aNewFormat( this );
369 const sw::LegacyModifyHint aHint(&aOldFormat, &aNewFormat);
370 SwClientNotify(*this, aHint);
372 return true;
375 bool SwFormat::supportsFullDrawingLayerFillAttributeSet() const
377 return false;
380 const SfxPoolItem& SwFormat::GetFormatAttr( sal_uInt16 nWhich, bool bInParents ) const
382 if (RES_BACKGROUND == nWhich && supportsFullDrawingLayerFillAttributeSet())
384 // FALLBACKBREAKHERE should not be used; instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST]
385 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)");
386 static std::unique_ptr<SvxBrushItem> aSvxBrushItem; //(std::make_shared<SvxBrushItem>(RES_BACKGROUND));
388 // fill the local static SvxBrushItem from the current ItemSet so that
389 // the fill attributes [XATTR_FILL_FIRST .. XATTR_FILL_LAST] are used
390 // as good as possible to create a fallback representation and return that
391 aSvxBrushItem = getSvxBrushItemFromSourceSet(m_aSet, RES_BACKGROUND, bInParents);
393 return *aSvxBrushItem;
396 return m_aSet.Get( nWhich, bInParents );
399 SfxItemState SwFormat::GetItemState( sal_uInt16 nWhich, bool bSrchInParent, const SfxPoolItem **ppItem ) const
401 if (RES_BACKGROUND == nWhich && supportsFullDrawingLayerFillAttributeSet())
403 // FALLBACKBREAKHERE should not be used; instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST]
404 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)");
405 const drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFill = getSdrAllFillAttributesHelper();
407 // check if the new fill attributes are used
408 if(aFill && aFill->isUsed())
410 // if yes, fill the local SvxBrushItem using the new fill attributes
411 // as good as possible to have an instance for the pointer to point
412 // to and return as state that it is set
413 static std::unique_ptr<SvxBrushItem> aSvxBrushItem; //(RES_BACKGROUND);
415 aSvxBrushItem = getSvxBrushItemFromSourceSet(m_aSet, RES_BACKGROUND, bSrchInParent);
416 if( ppItem )
417 *ppItem = aSvxBrushItem.get();
419 return SfxItemState::SET;
422 // if not, reset pointer and return SfxItemState::DEFAULT to signal that
423 // the item is not set
424 if( ppItem )
425 *ppItem = nullptr;
427 return SfxItemState::DEFAULT;
430 return m_aSet.GetItemState( nWhich, bSrchInParent, ppItem );
433 SfxItemState SwFormat::GetBackgroundState(std::unique_ptr<SvxBrushItem>& rItem) const
435 if (supportsFullDrawingLayerFillAttributeSet())
437 // FALLBACKBREAKHERE should not be used; instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST]
438 const drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFill = getSdrAllFillAttributesHelper();
440 // check if the new fill attributes are used
441 if(aFill && aFill->isUsed())
443 // if yes, fill the local SvxBrushItem using the new fill attributes
444 // as good as possible to have an instance for the pointer to point
445 // to and return as state that it is set
446 rItem = getSvxBrushItemFromSourceSet(m_aSet, RES_BACKGROUND);
447 return SfxItemState::SET;
450 // if not return SfxItemState::DEFAULT to signal that the item is not set
451 return SfxItemState::DEFAULT;
454 const SfxPoolItem* pItem = nullptr;
455 SfxItemState eRet = m_aSet.GetItemState(RES_BACKGROUND, true, &pItem);
456 if (pItem)
457 rItem.reset(static_cast<SvxBrushItem*>(pItem->Clone()));
458 return eRet;
461 bool SwFormat::SetFormatAttr( const SfxPoolItem& rAttr )
463 if ( IsInCache() || IsInSwFntCache() )
465 const sal_uInt16 nWhich = rAttr.Which();
466 CheckCaching( nWhich );
469 bool bRet = false;
471 if (RES_BACKGROUND == rAttr.Which() && supportsFullDrawingLayerFillAttributeSet())
473 // FALLBACKBREAKHERE should not be used; instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST]
474 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)");
475 SfxItemSet aTempSet(*m_aSet.GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{});
476 const SvxBrushItem& rSource = static_cast< const SvxBrushItem& >(rAttr);
478 // fill a local ItemSet with the attributes corresponding as good as possible
479 // to the new fill properties [XATTR_FILL_FIRST .. XATTR_FILL_LAST] and set these
480 // as ItemSet
481 setSvxBrushItemAsFillAttributesToTargetSet(rSource, aTempSet);
483 if(IsModifyLocked())
485 bRet = m_aSet.Put( aTempSet );
486 if( bRet )
488 m_aSet.SetModifyAtAttr( this );
491 else
493 SwAttrSet aOld(*m_aSet.GetPool(), m_aSet.GetRanges()), aNew(*m_aSet.GetPool(), m_aSet.GetRanges());
495 bRet = m_aSet.Put_BC(aTempSet, &aOld, &aNew);
497 if(bRet)
499 m_aSet.SetModifyAtAttr(this);
500 sw::ClientNotifyAttrChg(*this, m_aSet, aOld, aNew);
504 return bRet;
507 // if Modify is locked then no modifications will be sent;
508 // but call Modify always for FrameFormats
509 const sal_uInt16 nFormatWhich = Which();
510 if( IsModifyLocked() ||
511 ( !HasWriterListeners() &&
512 (RES_GRFFMTCOLL == nFormatWhich ||
513 RES_TXTFMTCOLL == nFormatWhich ) ) )
515 bRet = nullptr != m_aSet.Put( rAttr );
516 if( bRet )
517 m_aSet.SetModifyAtAttr( this );
518 // #i71574#
519 if ( nFormatWhich == RES_TXTFMTCOLL && rAttr.Which() == RES_PARATR_NUMRULE )
521 TextFormatCollFunc::CheckTextFormatCollForDeletionOfAssignmentToOutlineStyle( this );
524 else
526 // copy only array with attributes delta
527 SwAttrSet aOld( *m_aSet.GetPool(), m_aSet.GetRanges() ),
528 aNew( *m_aSet.GetPool(), m_aSet.GetRanges() );
530 bRet = m_aSet.Put_BC( rAttr, &aOld, &aNew );
531 if( bRet )
533 // some special treatments for attributes
534 m_aSet.SetModifyAtAttr( this );
536 sw::ClientNotifyAttrChg(*this, m_aSet, aOld, aNew);
539 return bRet;
542 bool SwFormat::SetFormatAttr( const SfxItemSet& rSet )
544 if( !rSet.Count() )
545 return false;
547 if ( IsInCache() )
549 SwFrame::GetCache().Delete( this );
550 SetInCache( false );
552 SetInSwFntCache( false );
554 bool bRet = false;
556 // Use local copy to be able to apply needed changes, e.g. call
557 // CheckForUniqueItemForLineFillNameOrIndex which is needed for NameOrIndex stuff
558 SfxItemSet aTempSet(rSet);
560 // Need to check for unique item for DrawingLayer items of type NameOrIndex
561 // and evtl. correct that item to ensure unique names for that type. This call may
562 // modify/correct entries inside of the given SfxItemSet
563 if(GetDoc())
565 GetDoc()->CheckForUniqueItemForLineFillNameOrIndex(aTempSet);
568 if (supportsFullDrawingLayerFillAttributeSet())
570 const SfxPoolItem* pSource = nullptr;
572 if(SfxItemState::SET == aTempSet.GetItemState(RES_BACKGROUND, false, &pSource))
574 // FALLBACKBREAKHERE should not be used; instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST]
575 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)");
577 // copy all items to be set anyways to a local ItemSet with is also prepared for the new
578 // fill attribute ranges [XATTR_FILL_FIRST .. XATTR_FILL_LAST]. Add the attributes
579 // corresponding as good as possible to the new fill properties and set the whole ItemSet
580 const SvxBrushItem& rSource(static_cast< const SvxBrushItem& >(*pSource));
581 setSvxBrushItemAsFillAttributesToTargetSet(rSource, aTempSet);
583 if(IsModifyLocked())
585 bRet = m_aSet.Put( aTempSet );
586 if( bRet )
588 m_aSet.SetModifyAtAttr( this );
591 else
593 SwAttrSet aOld(*m_aSet.GetPool(), m_aSet.GetRanges()), aNew(*m_aSet.GetPool(), m_aSet.GetRanges());
595 bRet = m_aSet.Put_BC(aTempSet, &aOld, &aNew);
597 if(bRet)
599 m_aSet.SetModifyAtAttr(this);
600 sw::ClientNotifyAttrChg(*this, m_aSet, aOld, aNew);
604 return bRet;
608 // if Modify is locked then no modifications will be sent;
609 // but call Modify always for FrameFormats
610 const sal_uInt16 nFormatWhich = Which();
611 if ( IsModifyLocked() ||
612 ( !HasWriterListeners() &&
613 ( RES_GRFFMTCOLL == nFormatWhich ||
614 RES_TXTFMTCOLL == nFormatWhich ) ) )
616 bRet = m_aSet.Put( aTempSet );
617 if( bRet )
618 m_aSet.SetModifyAtAttr( this );
619 // #i71574#
620 if ( nFormatWhich == RES_TXTFMTCOLL )
622 TextFormatCollFunc::CheckTextFormatCollForDeletionOfAssignmentToOutlineStyle( this );
625 else
627 SwAttrSet aOld( *m_aSet.GetPool(), m_aSet.GetRanges() ),
628 aNew( *m_aSet.GetPool(), m_aSet.GetRanges() );
629 bRet = m_aSet.Put_BC( aTempSet, &aOld, &aNew );
630 if( bRet )
632 // some special treatments for attributes
633 m_aSet.SetModifyAtAttr( this );
634 sw::ClientNotifyAttrChg(*this, m_aSet, aOld, aNew);
637 return bRet;
640 // remove Hint using nWhich from array with delta
641 bool SwFormat::ResetFormatAttr( sal_uInt16 nWhich1, sal_uInt16 nWhich2 )
643 if( !m_aSet.Count() )
644 return false;
646 if( !nWhich2 || nWhich2 < nWhich1 )
647 nWhich2 = nWhich1; // then set to 1st ID, only this item
649 if ( IsInCache() || IsInSwFntCache() )
651 for( sal_uInt16 n = nWhich1; n < nWhich2; ++n )
652 CheckCaching( n );
655 // if Modify is locked then no modifications will be sent
656 if( IsModifyLocked() )
657 return 0 != (( nWhich2 == nWhich1 )
658 ? m_aSet.ClearItem( nWhich1 )
659 : m_aSet.ClearItem_BC( nWhich1, nWhich2 ));
661 SwAttrSet aOld( *m_aSet.GetPool(), m_aSet.GetRanges() ),
662 aNew( *m_aSet.GetPool(), m_aSet.GetRanges() );
663 bool bRet = 0 != m_aSet.ClearItem_BC( nWhich1, nWhich2, &aOld, &aNew );
664 if( bRet )
665 sw::ClientNotifyAttrChg(*this, m_aSet, aOld, aNew);
666 return bRet;
669 // #i73790#
670 sal_uInt16 SwFormat::ResetAllFormatAttr()
672 if( !m_aSet.Count() )
673 return 0;
675 if ( IsInCache() )
677 SwFrame::GetCache().Delete( this );
678 SetInCache( false );
680 SetInSwFntCache( false );
682 // if Modify is locked then no modifications will be sent
683 if( IsModifyLocked() )
684 return m_aSet.ClearItem();
686 SwAttrSet aOld( *m_aSet.GetPool(), m_aSet.GetRanges() ),
687 aNew( *m_aSet.GetPool(), m_aSet.GetRanges() );
688 bool bRet = 0 != m_aSet.ClearItem_BC( 0, &aOld, &aNew );
689 if( bRet )
690 sw::ClientNotifyAttrChg(*this, m_aSet, aOld, aNew);
691 return aNew.Count();
694 void SwFormat::DelDiffs( const SfxItemSet& rSet )
696 if( !m_aSet.Count() )
697 return;
699 if ( IsInCache() )
701 SwFrame::GetCache().Delete( this );
702 SetInCache( false );
704 SetInSwFntCache( false );
706 // if Modify is locked then no modifications will be sent
707 if( IsModifyLocked() )
709 m_aSet.Intersect( rSet );
710 return;
713 SwAttrSet aOld( *m_aSet.GetPool(), m_aSet.GetRanges() ),
714 aNew( *m_aSet.GetPool(), m_aSet.GetRanges() );
715 bool bRet = 0 != m_aSet.Intersect_BC( rSet, &aOld, &aNew );
716 if( bRet )
717 sw::ClientNotifyAttrChg(*this, m_aSet, aOld, aNew);
720 /** SwFormat::IsBackgroundTransparent
722 Virtual method to determine, if background of format is transparent.
723 Default implementation returns false. Thus, subclasses have to override
724 method, if the specific subclass can have a transparent background.
726 @return false, default implementation
728 bool SwFormat::IsBackgroundTransparent() const
730 return false;
734 * Document Interface Access
736 const IDocumentSettingAccess& SwFormat::getIDocumentSettingAccess() const { return GetDoc()->GetDocumentSettingManager(); }
737 const IDocumentDrawModelAccess& SwFormat::getIDocumentDrawModelAccess() const { return GetDoc()->getIDocumentDrawModelAccess(); }
738 IDocumentDrawModelAccess& SwFormat::getIDocumentDrawModelAccess() { return GetDoc()->getIDocumentDrawModelAccess(); }
739 const IDocumentLayoutAccess& SwFormat::getIDocumentLayoutAccess() const { return GetDoc()->getIDocumentLayoutAccess(); }
740 IDocumentLayoutAccess& SwFormat::getIDocumentLayoutAccess() { return GetDoc()->getIDocumentLayoutAccess(); }
741 IDocumentTimerAccess& SwFormat::getIDocumentTimerAccess() { return GetDoc()->getIDocumentTimerAccess(); }
742 IDocumentFieldsAccess& SwFormat::getIDocumentFieldsAccess() { return GetDoc()->getIDocumentFieldsAccess(); }
743 IDocumentChartDataProviderAccess& SwFormat::getIDocumentChartDataProviderAccess() { return GetDoc()->getIDocumentChartDataProviderAccess(); }
745 void SwFormat::GetGrabBagItem(uno::Any& rVal) const
747 if (m_pGrabBagItem)
748 m_pGrabBagItem->QueryValue(rVal);
749 else
750 rVal <<= uno::Sequence<beans::PropertyValue>();
753 void SwFormat::SetGrabBagItem(const uno::Any& rVal)
755 if (!m_pGrabBagItem)
756 m_pGrabBagItem = std::make_shared<SfxGrabBagItem>();
758 m_pGrabBagItem->PutValue(rVal, 0);
761 std::unique_ptr<SvxBrushItem> SwFormat::makeBackgroundBrushItem(bool bInP) const
763 if (supportsFullDrawingLayerFillAttributeSet())
765 // FALLBACKBREAKHERE should not be used; instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST]
766 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)");
768 // fill the local static SvxBrushItem from the current ItemSet so that
769 // the fill attributes [XATTR_FILL_FIRST .. XATTR_FILL_LAST] are used
770 // as good as possible to create a fallback representation and return that
771 return getSvxBrushItemFromSourceSet(m_aSet, RES_BACKGROUND, bInP);
774 return std::unique_ptr<SvxBrushItem>(m_aSet.GetBackground(bInP).Clone());
777 drawinglayer::attribute::SdrAllFillAttributesHelperPtr SwFormat::getSdrAllFillAttributesHelper() const
779 return drawinglayer::attribute::SdrAllFillAttributesHelperPtr();
782 void SwFormat::RemoveAllUnos()
784 SwPtrMsgPoolItem aMsgHint(RES_REMOVE_UNO_OBJECT, this);
785 SwClientNotify(*this, sw::LegacyModifyHint(&aMsgHint, &aMsgHint));
787 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */