sw/source/core/docnode/ndcopy.cxx | 14 +++---- sw/source/core/docnode/ndsect.cxx | 10 ++--- sw/source/core/docnode/ndtbl.cxx | 70 +++++++++++++------------------------ sw/source/core/docnode/ndtbl1.cxx | 8 ++-- sw/source/core/docnode/node.cxx | 14 +++---- sw/source/core/docnode/section.cxx | 27 +++++--------- 6 files changed, 58 insertions(+), 85 deletions(-)
New commits: commit 5af30f3c37f5560cc685482e0be29127dda34b4e Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed Mar 2 13:10:34 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed Mar 2 16:54:26 2022 +0100 use SfxItemSet::GetItemIfSet in sw/source/core/docnode Change-Id: I71f6b60e981aa4391563a5214be38bb03646cdf4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130839 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/source/core/docnode/ndcopy.cxx b/sw/source/core/docnode/ndcopy.cxx index 3b572229b4d7..4b26acc0ea86 100644 --- a/sw/source/core/docnode/ndcopy.cxx +++ b/sw/source/core/docnode/ndcopy.cxx @@ -155,11 +155,10 @@ static void lcl_CopyTableBox( SwTableBox* pBox, CopyTable* pCT ) if (pBoxFormat == pBox->GetFrameFormat()) // Create a new one? { - const SfxPoolItem* pItem; - if( SfxItemState::SET == pBoxFormat->GetItemState( RES_BOXATR_FORMULA, false, - &pItem ) && static_cast<const SwTableBoxFormula*>(pItem)->IsIntrnlName() ) + const SwTableBoxFormula* pFormulaItem = pBoxFormat->GetItemIfSet( RES_BOXATR_FORMULA, false ); + if( pFormulaItem && pFormulaItem->IsIntrnlName() ) { - const_cast<SwTableBoxFormula*>(static_cast<const SwTableBoxFormula*>(pItem))->PtrToBoxNm(pCT->m_pOldTable); + const_cast<SwTableBoxFormula*>(pFormulaItem)->PtrToBoxNm(pCT->m_pOldTable); } pBoxFormat = pCT->m_rDoc.MakeTableBoxFormat(); @@ -168,10 +167,11 @@ static void lcl_CopyTableBox( SwTableBox* pBox, CopyTable* pCT ) if( pBox->GetSttIdx() ) { SvNumberFormatter* pN = pCT->m_rDoc.GetNumberFormatter(false); - if( pN && pN->HasMergeFormatTable() && SfxItemState::SET == pBoxFormat-> - GetItemState( RES_BOXATR_FORMAT, false, &pItem ) ) + const SwTableBoxNumFormat* pFormatItem; + if( pN && pN->HasMergeFormatTable() && + (pFormatItem = pBoxFormat->GetItemIfSet( RES_BOXATR_FORMAT, false )) ) { - sal_uLong nOldIdx = static_cast<const SwTableBoxNumFormat*>(pItem)->GetValue(); + sal_uLong nOldIdx = pFormatItem->GetValue(); sal_uLong nNewIdx = pN->GetMergeFormatIndex( nOldIdx ); if( nNewIdx != nOldIdx ) pBoxFormat->SetFormatAttr( SwTableBoxNumFormat( nNewIdx )); diff --git a/sw/source/core/docnode/ndsect.cxx b/sw/source/core/docnode/ndsect.cxx index 1087f9eebfa4..6c0a2a3a9cc4 100644 --- a/sw/source/core/docnode/ndsect.cxx +++ b/sw/source/core/docnode/ndsect.cxx @@ -527,12 +527,10 @@ void SwDoc::DelSectionFormat( SwSectionFormat *pFormat, bool bDelNodes ) if( mpSectionFormatTable->end() != itFormatPos ) { const SwNodeIndex* pIdx = pFormat->GetContent( false ).GetContentIdx(); - const SfxPoolItem* pFootnoteEndAtTextEnd; - if( SfxItemState::SET != pFormat->GetItemState( - RES_FTN_AT_TXTEND, true, &pFootnoteEndAtTextEnd ) || - SfxItemState::SET != pFormat->GetItemState( - RES_END_AT_TXTEND, true, &pFootnoteEndAtTextEnd )) - pFootnoteEndAtTextEnd = nullptr; + const SfxPoolItem* pFootnoteEndAtTextEnd = pFormat->GetItemIfSet( + RES_FTN_AT_TXTEND); + if( !pFootnoteEndAtTextEnd ) + pFootnoteEndAtTextEnd = pFormat->GetItemIfSet(RES_END_AT_TXTEND); const SwSectionNode* pSectNd; diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx index 302fbd007b8d..601de8d62fd9 100644 --- a/sw/source/core/docnode/ndtbl.cxx +++ b/sw/source/core/docnode/ndtbl.cxx @@ -409,10 +409,7 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTableOpts, if (pContentNd) { const SwAttrSet & aNdSet = pContentNd->GetSwAttrSet(); - const SfxPoolItem *pItem = nullptr; - - if (SfxItemState::SET == aNdSet.GetItemState( RES_FRAMEDIR, true, &pItem ) - && pItem != nullptr) + if (const SvxFrameDirectionItem* pItem = aNdSet.GetItemIfSet( RES_FRAMEDIR )) { pTableFormat->SetFormatAttr( *pItem ); } @@ -452,16 +449,14 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTableOpts, if( pNextNd && pNextNd->HasSwAttrSet() ) { const SfxItemSet* pNdSet = pNextNd->GetpSwAttrSet(); - const SfxPoolItem *pItem; - if( SfxItemState::SET == pNdSet->GetItemState( RES_PAGEDESC, false, - &pItem ) ) + if( const SwFormatPageDesc* pItem = pNdSet->GetItemIfSet( RES_PAGEDESC, false ) ) { pTableFormat->SetFormatAttr( *pItem ); pNextNd->ResetAttr( RES_PAGEDESC ); pNdSet = pNextNd->GetpSwAttrSet(); } - if( pNdSet && SfxItemState::SET == pNdSet->GetItemState( RES_BREAK, false, - &pItem ) ) + const SvxFormatBreakItem* pItem; + if( pNdSet && (pItem = pNdSet->GetItemIfSet( RES_BREAK, false )) ) { pTableFormat->SetFormatAttr( *pItem ); pNextNd->ResetAttr( RES_BREAK ); @@ -717,10 +712,7 @@ const SwTable* SwDoc::TextToTable( const SwInsertTableOptions& rInsTableOpts, if (pSttContentNd) { const SwAttrSet & aNdSet = pSttContentNd->GetSwAttrSet(); - const SfxPoolItem *pItem = nullptr; - - if (SfxItemState::SET == aNdSet.GetItemState( RES_FRAMEDIR, true, &pItem ) - && pItem != nullptr) + if (const SvxFrameDirectionItem *pItem = aNdSet.GetItemIfSet( RES_FRAMEDIR ) ) { pTableFormat->SetFormatAttr( *pItem ); } @@ -908,8 +900,7 @@ static void lcl_RemoveBreaks(SwContentNode & rNode, SwTableFormat *const pTableF if (!pSet) return; - const SfxPoolItem* pItem; - if (SfxItemState::SET == pSet->GetItemState(RES_BREAK, false, &pItem)) + if (const SvxFormatBreakItem* pItem = pSet->GetItemIfSet(RES_BREAK, false)) { if (pTableFormat) { @@ -919,13 +910,14 @@ static void lcl_RemoveBreaks(SwContentNode & rNode, SwTableFormat *const pTableF pSet = rTextNode.GetpSwAttrSet(); } + const SwFormatPageDesc* pPageDescItem; if (pSet - && (SfxItemState::SET == pSet->GetItemState(RES_PAGEDESC, false, &pItem)) - && static_cast<SwFormatPageDesc const*>(pItem)->GetPageDesc()) + && (pPageDescItem = pSet->GetItemIfSet(RES_PAGEDESC, false)) + && pPageDescItem->GetPageDesc()) { if (pTableFormat) { - pTableFormat->SetFormatAttr(*pItem); + pTableFormat->SetFormatAttr(*pPageDescItem); } rTextNode.ResetAttr(RES_PAGEDESC); } @@ -1248,10 +1240,7 @@ const SwTable* SwDoc::TextToTable( const std::vector< std::vector<SwNodeRange> > if (pSttContentNd) { const SwAttrSet & aNdSet = pSttContentNd->GetSwAttrSet(); - const SfxPoolItem *pItem = nullptr; - - if (SfxItemState::SET == aNdSet.GetItemState( RES_FRAMEDIR, true, &pItem ) - && pItem != nullptr) + if (const SvxFrameDirectionItem* pItem = aNdSet.GetItemIfSet( RES_FRAMEDIR )) { pTableFormat->SetFormatAttr( *pItem ); } @@ -1629,11 +1618,8 @@ bool SwNodes::TableToText( const SwNodeRange& rRange, sal_Unicode cCh, { // What about UNDO? const SfxItemSet& rTableSet = pTableNd->m_pTable->GetFrameFormat()->GetAttrSet(); - const SfxPoolItem *pBreak, *pDesc; - if( SfxItemState::SET != rTableSet.GetItemState( RES_PAGEDESC, false, &pDesc )) - pDesc = nullptr; - if( SfxItemState::SET != rTableSet.GetItemState( RES_BREAK, false, &pBreak )) - pBreak = nullptr; + const SvxFormatBreakItem* pBreak = rTableSet.GetItemIfSet( RES_BREAK, false ); + const SwFormatPageDesc* pDesc = rTableSet.GetItemIfSet( RES_PAGEDESC, false ); if( pBreak || pDesc ) { @@ -4044,10 +4030,9 @@ bool SwDoc::IsNumberFormat( const OUString& rString, sal_uInt32& F_Index, double void SwDoc::ChkBoxNumFormat( SwTableBox& rBox, bool bCallUpdate ) { // Optimization: If the Box says it's Text, it remains Text - const SfxPoolItem* pNumFormatItem = nullptr; - if( SfxItemState::SET == rBox.GetFrameFormat()->GetItemState( RES_BOXATR_FORMAT, - false, &pNumFormatItem ) && GetNumberFormatter()->IsTextFormat( - static_cast<const SwTableBoxNumFormat*>(pNumFormatItem)->GetValue() )) + const SwTableBoxNumFormat* pNumFormatItem = rBox.GetFrameFormat()->GetItemIfSet( RES_BOXATR_FORMAT, + false ); + if( pNumFormatItem && GetNumberFormatter()->IsTextFormat(pNumFormatItem->GetValue()) ) return ; std::unique_ptr<SwUndoTableNumFormat> pUndo; @@ -4081,7 +4066,7 @@ void SwDoc::ChkBoxNumFormat( SwTableBox& rBox, bool bCallUpdate ) // format recognition if( pNumFormatItem && !bForceNumberFormat ) { - sal_uLong nOldNumFormat = static_cast<const SwTableBoxNumFormat*>(pNumFormatItem)->GetValue(); + sal_uLong nOldNumFormat = pNumFormatItem->GetValue(); SvNumberFormatter* pNumFormatr = GetNumberFormatter(); SvNumFormatType nFormatType = pNumFormatr->GetType( nFormatIdx ); @@ -4128,12 +4113,9 @@ void SwDoc::ChkBoxNumFormat( SwTableBox& rBox, bool bCallUpdate ) else { // It's not a number - const SfxPoolItem* pValueItem = nullptr, *pFormatItem = nullptr; SwTableBoxFormat* pBoxFormat = static_cast<SwTableBoxFormat*>(rBox.GetFrameFormat()); - if( SfxItemState::SET == pBoxFormat->GetItemState( RES_BOXATR_FORMAT, - false, &pFormatItem ) || - SfxItemState::SET == pBoxFormat->GetItemState( RES_BOXATR_VALUE, - false, &pValueItem )) + if( SfxItemState::SET == pBoxFormat->GetItemState( RES_BOXATR_FORMAT, false ) || + SfxItemState::SET == pBoxFormat->GetItemState( RES_BOXATR_VALUE, false ) ) { if (GetIDocumentUndoRedo().DoesUndo()) { @@ -4222,11 +4204,11 @@ void SwDoc::ClearLineNumAttrs( SwPosition const & rPos ) && pTextNode->GetText().isEmpty())) return; - const SfxPoolItem* pFormatItem = nullptr; SfxItemSetFixed<RES_PARATR_BEGIN, RES_PARATR_END - 1> rSet( pTextNode->GetDoc().GetAttrPool() ); pTextNode->SwContentNode::GetAttr( rSet ); - if ( SfxItemState::SET != rSet.GetItemState( RES_PARATR_NUMRULE , false , &pFormatItem ) ) + const SfxStringItem* pFormatItem = rSet.GetItemIfSet( RES_PARATR_NUMRULE, false ); + if ( !pFormatItem ) return; SwUndoDelNum * pUndo; @@ -4242,7 +4224,7 @@ void SwDoc::ClearLineNumAttrs( SwPosition const & rPos ) aRegH.RegisterInModify( pTextNode , *pTextNode ); if ( pUndo ) pUndo->AddNode( *pTextNode ); - std::unique_ptr<SfxStringItem> pNewItem(static_cast<SfxStringItem*>(pFormatItem->Clone())); + std::unique_ptr<SfxStringItem> pNewItem(pFormatItem->Clone()); pNewItem->SetValue(OUString()); rSet.Put( std::move(pNewItem) ); pTextNode->SetAttr( rSet ); @@ -4258,11 +4240,11 @@ void SwDoc::ClearBoxNumAttrs( const SwNodeIndex& rNode ) SwTableBox* pBox = pSttNd->FindTableNode()->GetTable(). GetTableBox( pSttNd->GetIndex() ); - const SfxPoolItem* pFormatItem = nullptr; const SfxItemSet& rSet = pBox->GetFrameFormat()->GetAttrSet(); - if( !(SfxItemState::SET == rSet.GetItemState( RES_BOXATR_FORMAT, false, &pFormatItem ) || + const SwTableBoxNumFormat* pFormatItem = rSet.GetItemIfSet( RES_BOXATR_FORMAT, false ); + if( !pFormatItem || SfxItemState::SET == rSet.GetItemState( RES_BOXATR_FORMULA, false ) || - SfxItemState::SET == rSet.GetItemState( RES_BOXATR_VALUE, false ))) + SfxItemState::SET == rSet.GetItemState( RES_BOXATR_VALUE, false )) return; if (GetIDocumentUndoRedo().DoesUndo()) @@ -4275,7 +4257,7 @@ void SwDoc::ClearBoxNumAttrs( const SwNodeIndex& rNode ) // Keep TextFormats! sal_uInt16 nWhich1 = RES_BOXATR_FORMAT; if( pFormatItem && GetNumberFormatter()->IsTextFormat( - static_cast<const SwTableBoxNumFormat*>(pFormatItem)->GetValue() )) + pFormatItem->GetValue() )) nWhich1 = RES_BOXATR_FORMULA; else // Just resetting Attributes is not enough diff --git a/sw/source/core/docnode/ndtbl1.cxx b/sw/source/core/docnode/ndtbl1.cxx index aaaae3fa8787..fe3c8f6febe0 100644 --- a/sw/source/core/docnode/ndtbl1.cxx +++ b/sw/source/core/docnode/ndtbl1.cxx @@ -682,8 +682,8 @@ void SwDoc::SetTabBorders( const SwCursor& rCursor, const SfxItemSet& rSet ) bLeftValid = true, bRightValid = true; // The Flags in the BoxInfo Item decide whether a BorderLine is valid! - if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_BORDER_INNER, false, - reinterpret_cast<const SfxPoolItem**>(&pSetBoxInfo)) ) + pSetBoxInfo = rSet.GetItemIfSet( SID_ATTR_BORDER_INNER, false ); + if( pSetBoxInfo ) { pHori = pSetBoxInfo->GetHori(); pVert = pSetBoxInfo->GetVert(); @@ -698,8 +698,8 @@ void SwDoc::SetTabBorders( const SwCursor& rCursor, const SfxItemSet& rSet ) bRightValid = pSetBoxInfo->IsValid(SvxBoxInfoItemValidFlags::RIGHT); } - if( SfxItemState::SET == rSet.GetItemState( RES_BOX, false, - reinterpret_cast<const SfxPoolItem**>(&pSetBox)) ) + pSetBox = rSet.GetItemIfSet( RES_BOX, false ); + if( pSetBox ) { pLeft = pSetBox->GetLeft(); pRight = pSetBox->GetRight(); diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx index f51af56a59b5..05100a091cd5 100644 --- a/sw/source/core/docnode/node.cxx +++ b/sw/source/core/docnode/node.cxx @@ -1595,11 +1595,9 @@ bool SwContentNode::SetAttr( const SfxItemSet& rSet ) { InvalidateInSwCache(RES_ATTRSET_CHG); - const SfxPoolItem* pFnd = nullptr; - if( SfxItemState::SET == rSet.GetItemState( RES_AUTO_STYLE, false, &pFnd ) ) + if( const SwFormatAutoFormat* pFnd = rSet.GetItemIfSet( RES_AUTO_STYLE, false ) ) { OSL_ENSURE( rSet.Count() == 1, "SetAutoStyle mixed with other attributes?!" ); - const SwFormatAutoFormat* pTmp = static_cast<const SwFormatAutoFormat*>(pFnd); // If there already is an attribute set (usually containing a numbering // item), we have to merge the attribute of the new set into the old set: @@ -1607,11 +1605,11 @@ bool SwContentNode::SetAttr( const SfxItemSet& rSet ) if ( GetpSwAttrSet() ) { bSetParent = false; - AttrSetHandleHelper::Put( mpAttrSet, *this, *pTmp->GetStyleHandle() ); + AttrSetHandleHelper::Put( mpAttrSet, *this, *pFnd->GetStyleHandle() ); } else { - mpAttrSet = pTmp->GetStyleHandle(); + mpAttrSet = pFnd->GetStyleHandle(); } if ( bSetParent ) @@ -1623,10 +1621,10 @@ bool SwContentNode::SetAttr( const SfxItemSet& rSet ) // fact that nobody else uses the attribute set behind the handle. // FME 2007-07-10 #i78124# If autostyle does not have a parent, // the string is empty. - const SfxPoolItem* pNameItem = nullptr; + const SfxStringItem* pNameItem = nullptr; if ( nullptr != GetCondFormatColl() || - SfxItemState::SET != mpAttrSet->GetItemState( RES_FRMATR_STYLE_NAME, false, &pNameItem ) || - static_cast<const SfxStringItem*>(pNameItem)->GetValue().isEmpty() ) + !(pNameItem = mpAttrSet->GetItemIfSet( RES_FRMATR_STYLE_NAME, false )) || + pNameItem->GetValue().isEmpty() ) AttrSetHandleHelper::SetParent( mpAttrSet, *this, &GetAnyFormatColl(), GetFormatColl() ); else const_cast<SfxItemSet*>(mpAttrSet.get())->SetParent( &GetFormatColl()->GetAttrSet() ); diff --git a/sw/source/core/docnode/section.cxx b/sw/source/core/docnode/section.cxx index 390600cfa3ba..2e33038596cd 100644 --- a/sw/source/core/docnode/section.cxx +++ b/sw/source/core/docnode/section.cxx @@ -422,31 +422,28 @@ void SwSection::Notify(SfxHint const& rHint) { SfxItemSet* pNewSet = const_cast<SwAttrSetChg*>(static_cast<const SwAttrSetChg*>(pNew))->GetChgSet(); SfxItemSet* pOldSet = const_cast<SwAttrSetChg*>(static_cast<const SwAttrSetChg*>(pOld))->GetChgSet(); - const SfxPoolItem* pItem; - if( SfxItemState::SET == pNewSet->GetItemState( - RES_PROTECT, false, &pItem ) ) + if( const SvxProtectItem* pItem = pNewSet->GetItemIfSet( + RES_PROTECT, false ) ) { - m_Data.SetProtectFlag( static_cast<SvxProtectItem const*>(pItem) - ->IsContentProtected() ); + m_Data.SetProtectFlag( pItem->IsContentProtected() ); pNewSet->ClearItem( RES_PROTECT ); pOldSet->ClearItem( RES_PROTECT ); } // --> edit in readonly sections - if( SfxItemState::SET == pNewSet->GetItemState( - RES_EDIT_IN_READONLY, false, &pItem ) ) + if( const SwFormatEditInReadonly* pItem = pNewSet->GetItemIfSet( + RES_EDIT_IN_READONLY, false ) ) { - m_Data.SetEditInReadonlyFlag( - static_cast<SwFormatEditInReadonly const*>(pItem)->GetValue()); + m_Data.SetEditInReadonlyFlag(pItem->GetValue()); pNewSet->ClearItem( RES_EDIT_IN_READONLY ); pOldSet->ClearItem( RES_EDIT_IN_READONLY ); } if( SfxItemState::SET == pNewSet->GetItemState( - RES_FTN_AT_TXTEND, false, &pItem ) || + RES_FTN_AT_TXTEND, false ) || SfxItemState::SET == pNewSet->GetItemState( - RES_END_AT_TXTEND, false, &pItem )) + RES_END_AT_TXTEND, false )) { bUpdateFootnote = true; } @@ -1221,11 +1218,9 @@ static void lcl_UpdateLinksInSect( const SwBaseLink& rUpdLnk, SwSectionNode& rSe if( xDocSh->GetMedium() && rSection.GetLinkFilePassword().isEmpty() ) { - const SfxPoolItem* pItem; - if( SfxItemState::SET == xDocSh->GetMedium()->GetItemSet()-> - GetItemState( SID_PASSWORD, false, &pItem ) ) - rSection.SetLinkFilePassword( - static_cast<const SfxStringItem*>(pItem)->GetValue() ); + if( const SfxStringItem* pItem = xDocSh->GetMedium()->GetItemSet()-> + GetItemIfSet( SID_PASSWORD, false ) ) + rSection.SetLinkFilePassword( pItem->GetValue() ); } SwDoc* pSrcDoc = static_cast<SwDocShell*>( xDocSh.get() )->GetDoc();