diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-07-22 10:31:28 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-07-22 13:18:46 +0200 |
commit | b5c24d544f3a56a22bef47bf9639580748a5d9cd (patch) | |
tree | 45a77080801bb8b93f5edeb53d82da3c592577bf /sw | |
parent | 546f8dc0574a06b17d2d4f7abe2bf22f3971f0bd (diff) |
no need to dynamic_cast when using GetItemSurrogates
since the items returned are guaranteed to be of the right type
Change-Id: I7912c0ec171b4617a7ac393786f553a1f0b6c78e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170836
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/crsr/crstrvl.cxx | 14 | ||||
-rw-r--r-- | sw/source/core/doc/DocumentFieldsManager.cxx | 16 | ||||
-rw-r--r-- | sw/source/core/doc/doc.cxx | 43 | ||||
-rw-r--r-- | sw/source/core/doc/docbasic.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/doc/docfmt.cxx | 6 | ||||
-rw-r--r-- | sw/source/core/doc/doctxm.cxx | 12 | ||||
-rw-r--r-- | sw/source/core/doc/visiturl.cxx | 7 | ||||
-rw-r--r-- | sw/source/core/edit/edfld.cxx | 12 | ||||
-rw-r--r-- | sw/source/core/table/swtable.cxx | 19 | ||||
-rw-r--r-- | sw/source/core/undo/unattr.cxx | 7 | ||||
-rw-r--r-- | sw/source/core/unocore/unostyle.cxx | 6 | ||||
-rw-r--r-- | sw/source/core/view/vprint.cxx | 22 | ||||
-rw-r--r-- | sw/source/filter/html/htmlflywriter.cxx | 26 | ||||
-rw-r--r-- | sw/source/filter/ww8/rtfexport.cxx | 36 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtww8.cxx | 16 | ||||
-rw-r--r-- | sw/source/uibase/utlui/content.cxx | 33 |
16 files changed, 116 insertions, 163 deletions
diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx index fd26d11823d8..effc825987c7 100644 --- a/sw/source/core/crsr/crstrvl.cxx +++ b/sw/source/core/crsr/crstrvl.cxx @@ -426,15 +426,13 @@ bool SwCursorShell::GotoNxtPrvTableFormula( bool bNext, bool bOnlyErrors ) for (const SfxPoolItem* pItem : aSurrogates) { const SwTableBox* pTBox; - auto pFormulaItem = dynamic_cast<const SwTableBoxFormula*>(pItem); - if( !pFormulaItem ) - continue; - pTBox = pFormulaItem->GetTableBox(); + auto & rFormulaItem = static_cast<const SwTableBoxFormula&>(*pItem); + pTBox = rFormulaItem.GetTableBox(); if( pTBox && pTBox->GetSttNd() && pTBox->GetSttNd()->GetNodes().IsDocNodes() && ( !bOnlyErrors || - !pFormulaItem->HasValidBoxes() ) ) + !rFormulaItem.HasValidBoxes() ) ) { SwNodeIndex aIdx( *pTBox->GetSttNd() ); const SwContentNode* pCNd = SwNodes::GoNext(&aIdx); @@ -535,10 +533,8 @@ bool SwCursorShell::GotoNxtPrvTOXMark( bool bNext ) do { for (const SfxPoolItem* pItem : aSurrogates) { - auto pToxMarkItem = dynamic_cast<const SwTOXMark*>(pItem); - if( !pToxMarkItem ) - continue; - pTextTOX = pToxMarkItem->GetTextTOXMark(); + auto & rToxMarkItem = static_cast<const SwTOXMark&>(*pItem); + pTextTOX = rToxMarkItem.GetTextTOXMark(); if( !pTextTOX ) continue; pTextNd = &pTextTOX->GetTextNode(); diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx index 1761b3beeebf..05e26e9cf0f2 100644 --- a/sw/source/core/doc/DocumentFieldsManager.cxx +++ b/sw/source/core/doc/DocumentFieldsManager.cxx @@ -619,9 +619,9 @@ void DocumentFieldsManager::UpdateTableFields(const SwTable* pTable) for (const SfxPoolItem* pItem : aSurrogates) { // SwTableBoxFormula is non-shareable, so const_cast is somewhat OK - auto pBoxFormula = const_cast<SwTableBoxFormula*>(pItem->DynamicWhichCast(RES_BOXATR_FORMULA)); - if(pBoxFormula && pBoxFormula->GetDefinedIn()) - pBoxFormula->ChangeState(); + auto & rBoxFormula = const_cast<SwTableBoxFormula&>(static_cast<const SwTableBoxFormula&>(*pItem)); + if(rBoxFormula.GetDefinedIn()) + rBoxFormula.ChangeState(); } SwRootFrame const* pLayout(nullptr); @@ -720,10 +720,10 @@ void DocumentFieldsManager::UpdateTableFields(const SwTable* pTable) for (const SfxPoolItem* pItem : aSurrogates) { // SwTableBoxFormula is non-shareable, so const_cast is somewhat OK - auto pFormula = const_cast<SwTableBoxFormula*>(pItem->DynamicWhichCast(RES_BOXATR_FORMULA)); - if(!pFormula || !pFormula->GetDefinedIn() || pFormula->IsValid()) + auto & rFormula = const_cast<SwTableBoxFormula&>(static_cast<const SwTableBoxFormula&>(*pItem)); + if(!rFormula.GetDefinedIn() || rFormula.IsValid()) continue; - SwTableBox* pBox = pFormula->GetTableBox(); + SwTableBox* pBox = rFormula.GetTableBox(); if(!pBox || !pBox->GetSttNd() || !pBox->GetSttNd()->GetNodes().IsDocNodes()) continue; const SwTableNode* pTableNd = pBox->GetSttNd()->FindTableNode(); @@ -773,14 +773,14 @@ void DocumentFieldsManager::UpdateTableFields(const SwTable* pTable) } SwTableCalcPara aPara(*oCalc, pTableNd->GetTable(), pLayout); - pFormula->Calc( aPara, nValue ); + rFormula.Calc( aPara, nValue ); if( aPara.IsStackOverflow() ) { bool const bResult = aPara.CalcWithStackOverflow(); if (bResult) { - pFormula->Calc( aPara, nValue ); + rFormula.Calc( aPara, nValue ); } OSL_ENSURE(bResult, "the chained formula could no be calculated"); diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx index 96b8914da893..8ab0b82dce7d 100644 --- a/sw/source/core/doc/doc.cxx +++ b/sw/source/core/doc/doc.cxx @@ -1075,14 +1075,11 @@ const SwFormatRefMark* SwDoc::GetRefMark( std::u16string_view rName ) const GetAttrPool().GetItemSurrogates(aSurrogates, RES_TXTATR_REFMARK); for (const SfxPoolItem* pItem : aSurrogates) { - auto pFormatRef = dynamic_cast<const SwFormatRefMark*>(pItem); - if(!pFormatRef) - continue; - - const SwTextRefMark* pTextRef = pFormatRef->GetTextRefMark(); + const auto & rFormatRef = static_cast<const SwFormatRefMark&>(*pItem); + const SwTextRefMark* pTextRef = rFormatRef.GetTextRefMark(); if( pTextRef && &pTextRef->GetTextNode().GetNodes() == &GetNodes() && - rName == pFormatRef->GetRefName() ) - return pFormatRef; + rName == rFormatRef.GetRefName() ) + return &rFormatRef; } return nullptr; } @@ -1097,15 +1094,13 @@ const SwFormatRefMark* SwDoc::GetRefMark( sal_uInt16 nIndex ) const GetAttrPool().GetItemSurrogates(aSurrogates, RES_TXTATR_REFMARK); for (const SfxPoolItem* pItem : aSurrogates) { - auto pRefMark = dynamic_cast<const SwFormatRefMark*>(pItem); - if( !pRefMark ) - continue; - const SwTextRefMark* pTextRef = pRefMark->GetTextRefMark(); + const auto & rRefMark = static_cast<const SwFormatRefMark&>(*pItem); + const SwTextRefMark* pTextRef = rRefMark.GetTextRefMark(); if( pTextRef && &pTextRef->GetTextNode().GetNodes() == &GetNodes() ) { if(nCount == nIndex) { - pRet = pRefMark; + pRet = &rRefMark; break; } nCount++; @@ -1124,15 +1119,13 @@ sal_uInt16 SwDoc::GetRefMarks( std::vector<OUString>* pNames ) const GetAttrPool().GetItemSurrogates(aSurrogates, RES_TXTATR_REFMARK); for (const SfxPoolItem* pItem : aSurrogates) { - auto pRefMark = dynamic_cast<const SwFormatRefMark*>(pItem); - if( !pRefMark ) - continue; - const SwTextRefMark* pTextRef = pRefMark->GetTextRefMark(); + const auto & rRefMark = static_cast<const SwFormatRefMark&>(*pItem); + const SwTextRefMark* pTextRef = rRefMark.GetTextRefMark(); if( pTextRef && &pTextRef->GetTextNode().GetNodes() == &GetNodes() ) { if( pNames ) { - OUString aTmp(pRefMark->GetRefName()); + OUString aTmp(rRefMark.GetRefName()); pNames->insert(pNames->begin() + nCount, aTmp); } ++nCount; @@ -1149,12 +1142,10 @@ void SwDoc::GetRefMarks( std::vector<const SwFormatRefMark*>& rMarks ) const rMarks.reserve(aSurrogates.size()); for (const SfxPoolItem* pItem : aSurrogates) { - auto pRefMark = dynamic_cast<const SwFormatRefMark*>(pItem); - if( !pRefMark ) - continue; - const SwTextRefMark* pTextRef = pRefMark->GetTextRefMark(); + const auto & rRefMark = static_cast<const SwFormatRefMark&>(*pItem); + const SwTextRefMark* pTextRef = rRefMark.GetTextRefMark(); if( pTextRef && &pTextRef->GetTextNode().GetNodes() == &GetNodes() ) - rMarks.push_back(pRefMark); + rMarks.push_back(&rRefMark); } } @@ -1273,16 +1264,16 @@ const SwFormatINetFormat* SwDoc::FindINetAttr( std::u16string_view rName ) const GetAttrPool().GetItemSurrogates(aSurrogates, RES_TXTATR_INETFMT); for (const SfxPoolItem* pItem : aSurrogates) { - auto pFormatItem = dynamic_cast<const SwFormatINetFormat*>(pItem); - if( !pFormatItem || pFormatItem->GetName() != rName ) + const auto & rFormatItem = static_cast<const SwFormatINetFormat&>(*pItem); + if( rFormatItem.GetName() != rName ) continue; - const SwTextINetFormat* pTextAttr = pFormatItem->GetTextINetFormat(); + const SwTextINetFormat* pTextAttr = rFormatItem.GetTextINetFormat(); if( !pTextAttr ) continue; const SwTextNode* pTextNd = pTextAttr->GetpTextNode(); if( pTextNd && &pTextNd->GetNodes() == &GetNodes() ) { - return pFormatItem; + return &rFormatItem; } } return nullptr; diff --git a/sw/source/core/doc/docbasic.cxx b/sw/source/core/doc/docbasic.cxx index 155a28f73d60..39cd7fe8f000 100644 --- a/sw/source/core/doc/docbasic.cxx +++ b/sw/source/core/doc/docbasic.cxx @@ -144,8 +144,8 @@ sal_uInt16 SwDoc::CallEvent( SvMacroItemId nEvent, const SwCallMouseEvent& rCall GetAttrPool().GetItemSurrogates(aSurrogates, RES_TXTATR_INETFMT); for (const SfxPoolItem* pItem : aSurrogates) { - auto pFormatItem = dynamic_cast<const SwFormatINetFormat*>(pItem); - if( pFormatItem && SfxPoolItem::areSame(rCallEvent.PTR.pINetAttr, pFormatItem) ) + const auto & rFormatItem = static_cast<const SwFormatINetFormat&>(*pItem); + if( SfxPoolItem::areSame(rCallEvent.PTR.pINetAttr, &rFormatItem) ) { bCheckPtr = false; // misuse as a flag break; diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx index b25ae850d022..b048e8238aae 100644 --- a/sw/source/core/doc/docfmt.cxx +++ b/sw/source/core/doc/docfmt.cxx @@ -644,9 +644,9 @@ void SwDoc::SetDefault( const SfxItemSet& rSet ) // Item and *should* not be changed that way. lcl_SetNewDefTabStops // seems to change pTabStopItem (!). This may need to be changed // to use iterateItemSurrogates and a defined write cycle. - if(auto pTabStopItem = pItem2->DynamicWhichCast(RES_PARATR_TABSTOP)) - bChg |= lcl_SetNewDefTabStops( nOldWidth, nNewWidth, - *const_cast<SvxTabStopItem*>(pTabStopItem) ); + const auto & rTabStopItem = static_cast<const SvxTabStopItem&>(*pItem2); + bChg |= lcl_SetNewDefTabStops( nOldWidth, nNewWidth, + const_cast<SvxTabStopItem&>(rTabStopItem) ); } aNew.ClearItem( RES_PARATR_TABSTOP ); diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx index 00d8e06eb0bb..53cf6cf02681 100644 --- a/sw/source/core/doc/doctxm.cxx +++ b/sw/source/core/doc/doctxm.cxx @@ -93,21 +93,19 @@ void SwDoc::GetTOIKeys(SwTOIKeyType eTyp, std::vector<OUString>& rArr, GetAttrPool().GetItemSurrogates(aSurrogates, RES_TXTATR_TOXMARK); for (const SfxPoolItem* pPoolItem : aSurrogates) { - const SwTOXMark* pItem = dynamic_cast<const SwTOXMark*>(pPoolItem); - if( !pItem ) - continue; - const SwTOXType* pTOXType = pItem->GetTOXType(); + const SwTOXMark& rItem = static_cast<const SwTOXMark&>(*pPoolItem); + const SwTOXType* pTOXType = rItem.GetTOXType(); if ( !pTOXType || pTOXType->GetType()!=TOX_INDEX ) continue; - const SwTextTOXMark* pMark = pItem->GetTextTOXMark(); + const SwTextTOXMark* pMark = rItem.GetTextTOXMark(); if ( pMark && pMark->GetpTextNd() && pMark->GetpTextNd()->GetNodes().IsDocNodes() && (!rLayout.IsHideRedlines() || !sw::IsMarkHintHidden(rLayout, *pMark->GetpTextNd(), *pMark))) { const OUString sStr = TOI_PRIMARY == eTyp - ? pItem->GetPrimaryKey() - : pItem->GetSecondaryKey(); + ? rItem.GetPrimaryKey() + : rItem.GetSecondaryKey(); if( !sStr.isEmpty() ) rArr.push_back( sStr ); diff --git a/sw/source/core/doc/visiturl.cxx b/sw/source/core/doc/visiturl.cxx index 377a7d06d657..a12543a4ef55 100644 --- a/sw/source/core/doc/visiturl.cxx +++ b/sw/source/core/doc/visiturl.cxx @@ -61,11 +61,10 @@ void SwURLStateChanged::Notify( SfxBroadcaster& , const SfxHint& rHint ) m_rDoc.GetAttrPool().GetItemSurrogates(aSurrogates, RES_TXTATR_INETFMT); for (const SfxPoolItem* pItem : aSurrogates) { - const SwFormatINetFormat* pFormatItem = dynamic_cast<const SwFormatINetFormat*>(pItem); - if( pFormatItem != nullptr && - ( pFormatItem->GetValue() == sURL || ( !sBkmk.isEmpty() && pFormatItem->GetValue() == sBkmk ))) + const SwFormatINetFormat& rFormatItem = static_cast<const SwFormatINetFormat&>(*pItem); + if( rFormatItem.GetValue() == sURL || ( !sBkmk.isEmpty() && rFormatItem.GetValue() == sBkmk ) ) { - const SwTextINetFormat* pTextAttr = pFormatItem->GetTextINetFormat(); + const SwTextINetFormat* pTextAttr = rFormatItem.GetTextINetFormat(); if (pTextAttr != nullptr) { const SwTextNode* pTextNd = pTextAttr->GetpTextNode(); diff --git a/sw/source/core/edit/edfld.cxx b/sw/source/core/edit/edfld.cxx index 908e7f9a3c40..c07ca0e502f1 100644 --- a/sw/source/core/edit/edfld.cxx +++ b/sw/source/core/edit/edfld.cxx @@ -175,10 +175,10 @@ static SwTextField* lcl_FindInputField( SwDoc* pDoc, const SwField& rField ) pDoc->GetAttrPool().GetItemSurrogates(aSurrogates, RES_TXTATR_INPUTFIELD); for (const SfxPoolItem* pItem : aSurrogates) { - auto pFormatField = dynamic_cast<const SwFormatField*>(pItem); - if( pFormatField && pFormatField->GetField() == &rField ) + const auto & rFormatField = static_cast<const SwFormatField&>(*pItem); + if( rFormatField.GetField() == &rField ) { - pTField = const_cast<SwFormatField*>(pFormatField)->GetTextField(); + pTField = const_cast<SwFormatField&>(rFormatField).GetTextField(); break; } } @@ -190,10 +190,10 @@ static SwTextField* lcl_FindInputField( SwDoc* pDoc, const SwField& rField ) pDoc->GetAttrPool().GetItemSurrogates(aSurrogates, RES_TXTATR_FIELD); for (const SfxPoolItem* pItem : aSurrogates) { - auto pFormatField = dynamic_cast<const SwFormatField*>(pItem); - if( pFormatField && pFormatField->GetField() == &rField ) + const auto & rFormatField = static_cast<const SwFormatField&>(*pItem); + if( rFormatField.GetField() == &rField ) { - pTField = const_cast<SwFormatField*>(pFormatField)->GetTextField(); + pTField = const_cast<SwFormatField&>(rFormatField).GetTextField(); break; } } diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx index 3c1ad8d56094..0e7a24a6dd64 100644 --- a/sw/source/core/table/swtable.cxx +++ b/sw/source/core/table/swtable.cxx @@ -1634,14 +1634,13 @@ void SwTable::GatherFormulas(std::vector<SwTableBoxFormula*>& rvFormulas) GetFrameFormat()->GetDoc()->GetAttrPool().GetItemSurrogates(aSurrogates, RES_BOXATR_FORMULA); for(const SfxPoolItem* pItem: aSurrogates) { - auto pBoxFormula = dynamic_cast<const SwTableBoxFormula*>(pItem); - assert(pBoxFormula); // use StaticWhichCast instead? - if(!pBoxFormula->GetDefinedIn()) + const auto & rBoxFormula = static_cast<const SwTableBoxFormula&>(*pItem); + if(!rBoxFormula.GetDefinedIn()) continue; - const SwNode* pNd = pBoxFormula->GetNodeOfFormula(); + const SwNode* pNd = rBoxFormula.GetNodeOfFormula(); if(!pNd || &pNd->GetNodes() != &pNd->GetDoc().GetNodes()) // is this ever valid or should we assert here? continue; - rvFormulas.push_back(const_cast<SwTableBoxFormula*>(pBoxFormula)); + rvFormulas.push_back(const_cast<SwTableBoxFormula*>(&rBoxFormula)); } } @@ -1727,15 +1726,15 @@ void SwTable::UpdateFields(TableFormulaUpdateFlags eFlags) for(const SfxPoolItem* pItem : aSurrogates) { // SwTableBoxFormula is non-shareable, so const_cast is somewhat OK - auto pBoxFormula = const_cast<SwTableBoxFormula*>(pItem->DynamicWhichCast(RES_BOXATR_FORMULA)); - if(pBoxFormula && pBoxFormula->GetDefinedIn()) + auto & rBoxFormula = const_cast<SwTableBoxFormula&>(static_cast<const SwTableBoxFormula&>(*pItem)); + if(rBoxFormula.GetDefinedIn()) { if(eFlags == TBL_BOXPTR) - pBoxFormula->TryBoxNmToPtr(); + rBoxFormula.TryBoxNmToPtr(); else if(eFlags == TBL_RELBOXNAME) - pBoxFormula->TryRelBoxNm(); + rBoxFormula.TryRelBoxNm(); else - pBoxFormula->ChangeState(); + rBoxFormula.ChangeState(); } } } diff --git a/sw/source/core/undo/unattr.cxx b/sw/source/core/undo/unattr.cxx index a9c626eb5be0..7c185dfdd3da 100644 --- a/sw/source/core/undo/unattr.cxx +++ b/sw/source/core/undo/unattr.cxx @@ -690,12 +690,11 @@ void SwUndoResetAttr::RedoImpl(::sw::UndoRedoContext & rContext) { for (const SfxPoolItem* pItem : aSurrogates) { - assert(dynamic_cast<const SwFormatRefMark*>(pItem)); - const auto pFormatRefMark = static_cast<const SwFormatRefMark*>(pItem); + const auto & rFormatRefMark = static_cast<const SwFormatRefMark&>(*pItem); if (static_cast<SwHistorySetRefMark*>(pHistoryHint)->GetRefName() == - pFormatRefMark->GetRefName()) + rFormatRefMark.GetRefName()) { - rDoc.DeleteFormatRefMark(pFormatRefMark); + rDoc.DeleteFormatRefMark(&rFormatRefMark); rDoc.GetEditShell()->SwViewShell::UpdateFields(); break; } diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 1aed0ab6683d..a6efe66e988a 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -3707,9 +3707,9 @@ SwAutoStylesEnumImpl::SwAutoStylesEnumImpl( SwDoc& rInitDoc, IStyleAccess::SwAut rAttrPool.GetItemSurrogates(aSurrogates, RES_TXTATR_CJK_RUBY); for (const SfxPoolItem* pItem : aSurrogates) { - auto pRubyItem = dynamic_cast<const SwFormatRuby*>(pItem); - if ( pRubyItem && pRubyItem->GetTextRuby() ) - vRubyItems.push_back(pRubyItem); + const auto & rRubyItem = static_cast<const SwFormatRuby&>(*pItem); + if ( rRubyItem.GetTextRuby() ) + vRubyItems.push_back(&rRubyItem); } for (const SwFormatRuby* pRubyItem : vRubyItems) { diff --git a/sw/source/core/view/vprint.cxx b/sw/source/core/view/vprint.cxx index 48fc6db34801..c9e3c2d8b437 100644 --- a/sw/source/core/view/vprint.cxx +++ b/sw/source/core/view/vprint.cxx @@ -603,28 +603,22 @@ bool SwViewShell::IsAnyFieldInDoc() const mxDoc->GetAttrPool().GetItemSurrogates(aSurrogates, RES_TXTATR_FIELD); for (const SfxPoolItem* pItem : aSurrogates) { - auto pFormatField = dynamic_cast<const SwFormatField*>(pItem); - if(pFormatField) + const auto & rFormatField = static_cast<const SwFormatField&>(*pItem); + const SwTextField* pTextField = rFormatField.GetTextField(); + if( pTextField && pTextField->GetTextNode().GetNodes().IsDocNodes() ) { - const SwTextField* pTextField = pFormatField->GetTextField(); - if( pTextField && pTextField->GetTextNode().GetNodes().IsDocNodes() ) - { - return true; - } + return true; } } mxDoc->GetAttrPool().GetItemSurrogates(aSurrogates, RES_TXTATR_INPUTFIELD); for (const SfxPoolItem* pItem : aSurrogates) { - const SwFormatField* pFormatField = dynamic_cast<const SwFormatField*>(pItem); - if(pFormatField) + const SwFormatField& rFormatField = static_cast<const SwFormatField&>(*pItem); + const SwTextField* pTextField = rFormatField.GetTextField(); + if( pTextField && pTextField->GetTextNode().GetNodes().IsDocNodes() ) { - const SwTextField* pTextField = pFormatField->GetTextField(); - if( pTextField && pTextField->GetTextNode().GetNodes().IsDocNodes() ) - { - return true; - } + return true; } } diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx index fbe44a87017e..ddab7d00cf2f 100644 --- a/sw/source/filter/html/htmlflywriter.cxx +++ b/sw/source/filter/html/htmlflywriter.cxx @@ -2237,35 +2237,31 @@ void SwHTMLWriter::CollectLinkTargets() m_pDoc->GetAttrPool().GetItemSurrogates(aSurrogates, RES_TXTATR_INETFMT); for (const SfxPoolItem* pItem : aSurrogates) { - auto pINetFormat = dynamic_cast<const SwFormatINetFormat*>(pItem); + const auto & rINetFormat = static_cast<const SwFormatINetFormat&>(*pItem); const SwTextNode* pTextNd; - if( pINetFormat && - nullptr != ( pTextAttr = pINetFormat->GetTextINetFormat()) && + if( nullptr != ( pTextAttr = rINetFormat.GetTextINetFormat()) && nullptr != ( pTextNd = pTextAttr->GetpTextNode() ) && pTextNd->GetNodes().IsDocNodes() ) { - AddLinkTarget( pINetFormat->GetValue() ); + AddLinkTarget( rINetFormat.GetValue() ); } } m_pDoc->GetAttrPool().GetItemSurrogates(aSurrogates, RES_URL); for (const SfxPoolItem* pItem : aSurrogates) { - auto pURL = dynamic_cast<const SwFormatURL*>(pItem); - if( pURL ) + const auto & rURL = static_cast<const SwFormatURL&>(*pItem); + AddLinkTarget( rURL.GetURL() ); + const ImageMap *pIMap = rURL.GetMap(); + if( pIMap ) { - AddLinkTarget( pURL->GetURL() ); - const ImageMap *pIMap = pURL->GetMap(); - if( pIMap ) + for( size_t i=0; i<pIMap->GetIMapObjectCount(); ++i ) { - for( size_t i=0; i<pIMap->GetIMapObjectCount(); ++i ) + const IMapObject* pObj = pIMap->GetIMapObject( i ); + if( pObj ) { - const IMapObject* pObj = pIMap->GetIMapObject( i ); - if( pObj ) - { - AddLinkTarget( pObj->GetURL() ); - } + AddLinkTarget( pObj->GetURL() ); } } } diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx index 21ab804348d5..460dd409660f 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -1328,9 +1328,8 @@ void RtfExport::OutColorTable() rPool.GetItemSurrogates(aSurrogates, RES_CHRATR_COLOR); for (const SfxPoolItem* pItem : aSurrogates) { - pCol = dynamic_cast<const SvxColorItem*>(pItem); - if (pCol) - InsColor(pCol->GetValue()); + pCol = &static_cast<const SvxColorItem&>(*pItem); + InsColor(pCol->GetValue()); } auto pUnder = GetDfltAttr(RES_CHRATR_UNDERLINE); @@ -1338,9 +1337,8 @@ void RtfExport::OutColorTable() rPool.GetItemSurrogates(aSurrogates, RES_CHRATR_UNDERLINE); for (const SfxPoolItem* pItem : aSurrogates) { - pUnder = dynamic_cast<const SvxUnderlineItem*>(pItem); - if (pUnder) - InsColor(pUnder->GetColor()); + pUnder = &static_cast<const SvxUnderlineItem&>(*pItem); + InsColor(pUnder->GetColor()); } auto pOver = GetDfltAttr(RES_CHRATR_OVERLINE); @@ -1348,9 +1346,8 @@ void RtfExport::OutColorTable() rPool.GetItemSurrogates(aSurrogates, RES_CHRATR_OVERLINE); for (const SfxPoolItem* pItem : aSurrogates) { - pOver = dynamic_cast<const SvxOverlineItem*>(pItem); - if (pOver) - InsColor(pOver->GetColor()); + pOver = &static_cast<const SvxOverlineItem&>(*pItem); + InsColor(pOver->GetColor()); } } @@ -1389,11 +1386,8 @@ void RtfExport::OutColorTable() rPool.GetItemSurrogates(aSurrogates, RES_SHADOW); for (const SfxPoolItem* pItem : aSurrogates) { - pShadow = dynamic_cast<const SvxShadowItem*>(pItem); - if (pShadow) - { - InsColor(pShadow->GetColor()); - } + pShadow = &static_cast<const SvxShadowItem&>(*pItem); + InsColor(pShadow->GetColor()); } } @@ -1405,9 +1399,8 @@ void RtfExport::OutColorTable() rPool.GetItemSurrogates(aSurrogates, RES_BOX); for (const SfxPoolItem* pItem : aSurrogates) { - pBox = dynamic_cast<const SvxBoxItem*>(pItem); - if (pBox) - InsColorLine(*pBox); + pBox = &static_cast<const SvxBoxItem&>(*pItem); + InsColorLine(*pBox); } } @@ -1418,9 +1411,8 @@ void RtfExport::OutColorTable() rPool.GetItemSurrogates(aSurrogates, RES_CHRATR_BOX); for (const SfxPoolItem* pItem : aSurrogates) { - pCharBox = dynamic_cast<const SvxBoxItem*>(pItem); - if (pCharBox) - InsColorLine(*pCharBox); + pCharBox = &static_cast<const SvxBoxItem&>(*pItem); + InsColorLine(*pCharBox); } } @@ -1428,8 +1420,8 @@ void RtfExport::OutColorTable() rPool.GetItemSurrogates(aSurrogates, XATTR_FILLCOLOR); for (const SfxPoolItem* pItem : aSurrogates) { - if (auto pColorItem = dynamic_cast<const XFillColorItem*>(pItem)) - InsColor(pColorItem->GetColorValue()); + const auto& rColorItem = static_cast<const XFillColorItem&>(*pItem); + InsColor(rColorItem.GetColorValue()); } for (std::size_t n = 0; n < m_aColTable.size(); ++n) diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index a8404aa61396..1aeeaf47eefd 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -3372,11 +3372,9 @@ void MSWordExportBase::CollectOutlineBookmarks(const SwDoc &rDoc) rDoc.GetAttrPool().GetItemSurrogates(aSurrogates, RES_TXTATR_INETFMT); for (const SfxPoolItem* pItem : aSurrogates) { - auto pINetFormat = dynamic_cast<const SwFormatINetFormat*>(pItem); - if (!pINetFormat) - continue; + const auto & rINetFormat = static_cast<const SwFormatINetFormat&>(*pItem); - const SwTextINetFormat* pTextAttr = pINetFormat->GetTextINetFormat(); + const SwTextINetFormat* pTextAttr = rINetFormat.GetTextINetFormat(); if (!pTextAttr) continue; @@ -3387,18 +3385,16 @@ void MSWordExportBase::CollectOutlineBookmarks(const SwDoc &rDoc) if (!pTextNd->GetNodes().IsDocNodes()) continue; - AddLinkTarget( pINetFormat->GetValue() ); + AddLinkTarget( rINetFormat.GetValue() ); } rDoc.GetAttrPool().GetItemSurrogates(aSurrogates, RES_URL); for (const SfxPoolItem* pItem : aSurrogates) { - auto pURL = dynamic_cast<const SwFormatURL*>(pItem); - if (!pURL) - continue; + const auto & rURL = static_cast<const SwFormatURL&>(*pItem); - AddLinkTarget(pURL->GetURL()); - const ImageMap *pIMap = pURL->GetMap(); + AddLinkTarget(rURL.GetURL()); + const ImageMap *pIMap = rURL.GetMap(); if (!pIMap) continue; diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx index f0c33a247eef..27c220998b79 100644 --- a/sw/source/uibase/utlui/content.cxx +++ b/sw/source/uibase/utlui/content.cxx @@ -5906,15 +5906,12 @@ void SwContentTree::EditEntry(const weld::TreeIter& rEntry, EditEntryMode nMode) m_pActiveShell->GetDoc()->GetAttrPool().GetItemSurrogates(aSurrogates, RES_TXTATR_REFMARK); for (const SfxPoolItem* pItem : aSurrogates) { - assert(dynamic_cast<const SwFormatRefMark*>(pItem)); - const auto pFormatRefMark = static_cast<const SwFormatRefMark*>(pItem); - if (!pFormatRefMark) - continue; - const SwTextRefMark* pTextRef = pFormatRefMark->GetTextRefMark(); + const auto & rFormatRefMark = static_cast<const SwFormatRefMark&>(*pItem); + const SwTextRefMark* pTextRef = rFormatRefMark.GetTextRefMark(); if (pTextRef && &pTextRef->GetTextNode().GetNodes() == - &m_pActiveShell->GetNodes() && rName == pFormatRefMark->GetRefName()) + &m_pActiveShell->GetNodes() && rName == rFormatRefMark.GetRefName()) { - m_pActiveShell->GetDoc()->DeleteFormatRefMark(pFormatRefMark); + m_pActiveShell->GetDoc()->DeleteFormatRefMark(&rFormatRefMark); m_pActiveShell->SwViewShell::UpdateFields(); break; } @@ -6245,14 +6242,12 @@ void SwContentTree::DeleteAllContentOfEntryContentType(const weld::TreeIter& rEn for (const SfxPoolItem* pItem : aSurrogates) { assert(dynamic_cast<const SwFormatRefMark*>(pItem)); - const auto pFormatRefMark = static_cast<const SwFormatRefMark*>(pItem); - if (!pFormatRefMark) - continue; - const SwTextRefMark* pTextRef = pFormatRefMark->GetTextRefMark(); + const auto & rFormatRefMark = static_cast<const SwFormatRefMark&>(*pItem); + const SwTextRefMark* pTextRef = rFormatRefMark.GetTextRefMark(); if (pTextRef && &pTextRef->GetTextNode().GetNodes() == - &m_pActiveShell->GetNodes() && rName == pFormatRefMark->GetRefName()) + &m_pActiveShell->GetNodes() && rName == rFormatRefMark.GetRefName()) { - m_pActiveShell->GetDoc()->DeleteFormatRefMark(pFormatRefMark); + m_pActiveShell->GetDoc()->DeleteFormatRefMark(&rFormatRefMark); break; } } @@ -6933,13 +6928,11 @@ void SwContentTree::BringEntryToAttention(const weld::TreeIter& rEntry) m_pActiveShell->GetAttrPool().GetItemSurrogates(aSurrogates, RES_TXTATR_REFMARK); for (const SfxPoolItem* pItem : aSurrogates) { - if (const auto pRefMark = dynamic_cast<const SwFormatRefMark*>(pItem)) - { - const SwTextRefMark* pTextRef = pRefMark->GetTextRefMark(); - if (pTextRef && &pTextRef->GetTextNode().GetNodes() == - &m_pActiveShell->GetNodes()) - aTextAttrArr.push_back(pTextRef); - } + const auto rRefMark = static_cast<const SwFormatRefMark&>(*pItem); + const SwTextRefMark* pTextRef = rRefMark.GetTextRefMark(); + if (pTextRef && &pTextRef->GetTextNode().GetNodes() == + &m_pActiveShell->GetNodes()) + aTextAttrArr.push_back(pTextRef); } BringReferencesToAttention(aTextAttrArr); } |