sw/inc/node.hxx | 6 ++++++ sw/source/core/access/accpara.cxx | 2 ++ sw/source/core/docnode/node.cxx | 7 +++---- sw/source/core/edit/edattr.cxx | 3 +-- sw/source/core/text/txtfld.cxx | 2 +- sw/source/core/tox/ToxTabStopTokenHandler.cxx | 2 +- sw/source/core/txtnode/ndtxt.cxx | 6 +----- sw/source/filter/html/htmlflywriter.cxx | 2 +- sw/source/filter/html/htmlsect.cxx | 6 ++---- sw/source/filter/html/swhtml.cxx | 7 +++---- sw/source/filter/html/wrthtml.cxx | 3 +-- sw/source/filter/ww8/rtfattributeoutput.cxx | 4 ++-- sw/source/filter/ww8/wrtw8nds.cxx | 2 +- sw/source/filter/ww8/ww8par.cxx | 2 +- 14 files changed, 26 insertions(+), 28 deletions(-)
New commits: commit 8d762c146a79b5971541aa22217541c8aac017a4 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Mon Feb 7 14:21:53 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Feb 8 07:37:58 2022 +0100 add template versions of SwContentNode::GetAttr Change-Id: I62c0d54c9e1dc89c5684210075219c1eeee9f942 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129602 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/node.hxx b/sw/inc/node.hxx index bc0d874f66cb..4706e090290e 100644 --- a/sw/inc/node.hxx +++ b/sw/inc/node.hxx @@ -434,6 +434,9 @@ public: /// If bInParent is FALSE search for attribute only in this node. const SfxPoolItem& GetAttr( sal_uInt16 nWhich, bool bInParent=true ) const; + template<class T> + const T& GetAttr( TypedWhichId<T> nWhich, bool bInParent=true ) const + { return static_cast<const T&>(GetAttr(sal_uInt16(nWhich), bInParent)); } bool GetAttr( SfxItemSet& rSet ) const; /// made virtual virtual bool SetAttr( const SfxPoolItem& ); @@ -444,6 +447,9 @@ public: /// Obtains attribute that is not delivered via conditional style! const SfxPoolItem* GetNoCondAttr( sal_uInt16 nWhich, bool bInParents ) const; + template<class T> + const T* GetNoCondAttr( TypedWhichId<T> nWhich, bool bInParents ) const + { return static_cast<const T*>(GetNoCondAttr(sal_uInt16(nWhich), bInParents)); } /** Does node has already its own auto-attributes? Access to SwAttrSet. */ diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx index e774cc0d6f8d..6de03d5abdc2 100644 --- a/sw/source/core/access/accpara.cxx +++ b/sw/source/core/access/accpara.cxx @@ -75,6 +75,8 @@ #include <wrong.hxx> #include <editeng/brushitem.hxx> #include <editeng/unoprnms.hxx> +#include <editeng/lrspitem.hxx> +#include <editeng/ulspitem.hxx> #include <swatrset.hxx> #include <unosett.hxx> #include <unomap.hxx> diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx index 1995377f9a51..788ce19a177c 100644 --- a/sw/source/core/docnode/node.cxx +++ b/sw/source/core/docnode/node.cxx @@ -497,7 +497,7 @@ const SwPageDesc* SwNode::FindPageDesc( SwNodeOffset* pPgDescNdIdx ) const { pNode = GetContentNode(); if( pNode ) - pPgDesc = static_cast<const SwFormatPageDesc&>(pNode->GetAttr( RES_PAGEDESC )).GetPageDesc(); + pPgDesc = pNode->GetAttr( RES_PAGEDESC ).GetPageDesc(); } // Are we going through the layout? @@ -697,8 +697,7 @@ const SwPageDesc* SwNode::FindPageDesc( SwNodeOffset* pPgDescNdIdx ) const if( nullptr != pNd ) { if( pNd->IsContentNode() ) - pPgDesc = static_cast<const SwFormatPageDesc&>(pNd->GetContentNode()-> - GetAttr( RES_PAGEDESC )).GetPageDesc(); + pPgDesc = pNd->GetContentNode()->GetAttr( RES_PAGEDESC ).GetPageDesc(); else if( pNd->IsTableNode() ) pPgDesc = pNd->GetTableNode()->GetTable(). GetFrameFormat()->GetPageDesc().GetPageDesc(); @@ -1549,7 +1548,7 @@ bool SwContentNode::GetInfo( SfxPoolItem& rInfo ) const break; case RES_FINDNEARESTNODE: - if( static_cast<const SwFormatPageDesc&>(GetAttr( RES_PAGEDESC )).GetPageDesc() ) + if( GetAttr( RES_PAGEDESC ).GetPageDesc() ) static_cast<SwFindNearestNode&>(rInfo).CheckNode( *this ); return true; diff --git a/sw/source/core/edit/edattr.cxx b/sw/source/core/edit/edattr.cxx index b249deb336f0..956110c00c72 100644 --- a/sw/source/core/edit/edattr.cxx +++ b/sw/source/core/edit/edattr.cxx @@ -513,8 +513,7 @@ bool SwEditShell::IsMoveLeftMargin( bool bRight, bool bModulus ) const if( nullptr != pCNd ) { pCNd = sw::GetParaPropsNode(*GetLayout(), *pCNd); - const SvxLRSpaceItem& rLS = static_cast<const SvxLRSpaceItem&>( - pCNd->GetAttr( RES_LR_SPACE )); + const SvxLRSpaceItem& rLS = pCNd->GetAttr( RES_LR_SPACE ); if( bRight ) { tools::Long nNext = rLS.GetTextLeft() + nDefDist; diff --git a/sw/source/core/text/txtfld.cxx b/sw/source/core/text/txtfld.cxx index fc25dc4e9880..90fbf0d630ce 100644 --- a/sw/source/core/text/txtfld.cxx +++ b/sw/source/core/text/txtfld.cxx @@ -424,7 +424,7 @@ static void checkApplyParagraphMarkFormatToNumbering(SwFont* pNumFnt, SwTextForm if( !pIDSA->get(DocumentSettingId::APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING )) return; - SwFormatAutoFormat const& rListAutoFormat(static_cast<SwFormatAutoFormat const&>(rInf.GetTextFrame()->GetTextNodeForParaProps()->GetAttr(RES_PARATR_LIST_AUTOFMT))); + SwFormatAutoFormat const& rListAutoFormat(rInf.GetTextFrame()->GetTextNodeForParaProps()->GetAttr(RES_PARATR_LIST_AUTOFMT)); std::shared_ptr<SfxItemSet> pSet(rListAutoFormat.GetStyleHandle()); // TODO remove this fallback (for WW8/RTF) diff --git a/sw/source/core/tox/ToxTabStopTokenHandler.cxx b/sw/source/core/tox/ToxTabStopTokenHandler.cxx index 7c5bc84f3510..d816e2bc47d3 100644 --- a/sw/source/core/tox/ToxTabStopTokenHandler.cxx +++ b/sw/source/core/tox/ToxTabStopTokenHandler.cxx @@ -106,7 +106,7 @@ DefaultToxTabStopTokenHandler::CalculatePageMarginFromPageDescription(const SwTe DefaultToxTabStopTokenHandler::CanUseLayoutRectangle(const SwTextNode& targetNode, const SwRootFrame *currentLayout) { const SwPageDesc* pageDescription = - static_cast<const SwFormatPageDesc&>( targetNode.SwContentNode::GetAttr(RES_PAGEDESC)).GetPageDesc(); + targetNode.SwContentNode::GetAttr(RES_PAGEDESC).GetPageDesc(); if (!pageDescription) { return false; diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx index 872e4cee96db..8bf495792385 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -5042,12 +5042,8 @@ namespace { // #i105562# else { - assert(!mrTextNode.GetpSwAttrSet() - || dynamic_cast<const SfxUInt16Item*>( - &mrTextNode.GetAttr(RES_PARATR_OUTLINELEVEL, false))); if (mrTextNode.GetpSwAttrSet() - && static_cast<const SfxUInt16Item&>( - mrTextNode.GetAttr(RES_PARATR_OUTLINELEVEL, false)).GetValue() > 0) + && mrTextNode.GetAttr(RES_PARATR_OUTLINELEVEL, false).GetValue() > 0) { mrTextNode.SetEmptyListStyleDueToSetOutlineLevelAttr(); } diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx index 75938fbe217c..e9fe0d12d4b3 100644 --- a/sw/source/filter/html/htmlflywriter.cxx +++ b/sw/source/filter/html/htmlflywriter.cxx @@ -326,7 +326,7 @@ void SwHTMLWriter::CollectFlyFrames() (pACNd = pAPos->nNode.GetNode().GetContentNode()) != nullptr ) { const SvxLRSpaceItem& rLRItem = - static_cast<const SvxLRSpaceItem&>(pACNd->GetAttr(RES_LR_SPACE)); + pACNd->GetAttr(RES_LR_SPACE); if( rLRItem.GetTextLeft() || rLRItem.GetRight() ) { nMode = aHTMLOutFrameParaFrameTable[eType][m_nExportMode]; diff --git a/sw/source/filter/html/htmlsect.cxx b/sw/source/filter/html/htmlsect.cxx index 928e9bfe158d..c41368631eca 100644 --- a/sw/source/filter/html/htmlsect.cxx +++ b/sw/source/filter/html/htmlsect.cxx @@ -451,8 +451,7 @@ void SwHTMLParser::FixHeaderFooterDistance( bool bHeader, if( pTextNode ) { const SvxULSpaceItem& rULSpace = - static_cast<const SvxULSpaceItem&>(pTextNode - ->SwContentNode::GetAttr( RES_UL_SPACE )); + pTextNode->SwContentNode::GetAttr( RES_UL_SPACE ); // The bottom paragraph padding becomes the padding // to header or footer @@ -483,8 +482,7 @@ void SwHTMLParser::FixHeaderFooterDistance( bool bHeader, if( pTextNode ) { const SvxULSpaceItem& rULSpace = - static_cast<const SvxULSpaceItem&>(pTextNode - ->SwContentNode::GetAttr( RES_UL_SPACE )); + pTextNode->SwContentNode::GetAttr( RES_UL_SPACE ); // The top paragraph padding becomes the padding // to headline or footer if it is greater than the diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx index 5212159ae012..e0952dfe11d8 100644 --- a/sw/source/filter/html/swhtml.cxx +++ b/sw/source/filter/html/swhtml.cxx @@ -2203,7 +2203,7 @@ bool SwHTMLParser::AppendTextNode( SwHTMLAppendMode eMode, bool bUpdateNum ) if (pTextNode) { const SvxULSpaceItem& rULSpace = - static_cast<const SvxULSpaceItem&>(pTextNode->SwContentNode::GetAttr( RES_UL_SPACE )); + pTextNode->SwContentNode::GetAttr( RES_UL_SPACE ); bool bChange = AM_NOSPACE==eMode ? rULSpace.GetLower() > 0 : rULSpace.GetLower() == 0; @@ -2504,7 +2504,7 @@ void SwHTMLParser::AddParSpace() return; SvxULSpaceItem rULSpace = - static_cast<const SvxULSpaceItem&>(pTextNode->SwContentNode::GetAttr( RES_UL_SPACE )); + pTextNode->SwContentNode::GetAttr( RES_UL_SPACE ); if( rULSpace.GetLower() ) return; @@ -5006,8 +5006,7 @@ void SwHTMLParser::InsertSpacer() if( pTextNode ) { - SvxULSpaceItem aULSpace( static_cast<const SvxULSpaceItem&>(pTextNode - ->SwContentNode::GetAttr( RES_UL_SPACE )) ); + SvxULSpaceItem aULSpace( pTextNode->SwContentNode::GetAttr( RES_UL_SPACE ) ); aULSpace.SetLower( aULSpace.GetLower() + o3tl::narrowing<sal_uInt16>(nSize) ); pTextNode->SetAttr( aULSpace ); } diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx index 0d6aa170c0ad..2808da051611 100644 --- a/sw/source/filter/html/wrthtml.cxx +++ b/sw/source/filter/html/wrthtml.cxx @@ -1048,8 +1048,7 @@ const SwPageDesc *SwHTMLWriter::MakeHeader( sal_uInt16 &rHeaderAttrs ) SwNode *pNd = m_pDoc->GetNodes()[ nNodeIdx ]; if( pNd->IsContentNode() ) { - pPageDesc = static_cast<const SwFormatPageDesc &>(pNd->GetContentNode() - ->GetAttr(RES_PAGEDESC)).GetPageDesc(); + pPageDesc = pNd->GetContentNode()->GetAttr(RES_PAGEDESC).GetPageDesc(); break; } else if( pNd->IsTableNode() ) diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx index 657160b1ee52..153669189ed6 100644 --- a/sw/source/filter/ww8/rtfattributeoutput.cxx +++ b/sw/source/filter/ww8/rtfattributeoutput.cxx @@ -4070,7 +4070,7 @@ void RtfAttributeOutput::FlyFrameOLEReplacement(const SwFlyFrameFormat* pFlyFram aRendered.setHeight(rSize.Height()); const Graphic* pGraphic = rOLENode.GetGraphic(); Size aMapped(pGraphic->GetPrefSize()); - auto& rCr = static_cast<const SwCropGrf&>(rOLENode.GetAttr(RES_GRFATR_CROPGRF)); + auto& rCr = rOLENode.GetAttr(RES_GRFATR_CROPGRF); const char* pBLIPType = OOO_STRING_SVTOOLS_RTF_PNGBLIP; const sal_uInt8* pGraphicAry = nullptr; SvMemoryStream aStream; @@ -4213,7 +4213,7 @@ void RtfAttributeOutput::FlyFrameGraphic(const SwFlyFrameFormat* pFlyFrameFormat Size aMapped(eGraphicType == GraphicType::Bitmap ? rGraphic.GetSizePixel() : rGraphic.GetPrefSize()); - auto& rCr = static_cast<const SwCropGrf&>(pGrfNode->GetAttr(RES_GRFATR_CROPGRF)); + auto& rCr = pGrfNode->GetAttr(RES_GRFATR_CROPGRF); //Get original size in twips Size aSize(pGrfNode->GetTwipSize()); diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx index a1409a695e0f..36d80ebb427d 100644 --- a/sw/source/filter/ww8/wrtw8nds.cxx +++ b/sw/source/filter/ww8/wrtw8nds.cxx @@ -3158,7 +3158,7 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode ) SfxItemSetFixed<RES_CHRATR_BEGIN, RES_TXTATR_END> aParagraphMarkerProperties(m_rDoc.GetAttrPool()); bool bCharFormatOnly = true; - SwFormatAutoFormat const& rListAutoFormat(static_cast<SwFormatAutoFormat const&>(rNode.GetAttr(RES_PARATR_LIST_AUTOFMT))); + SwFormatAutoFormat const& rListAutoFormat(rNode.GetAttr(RES_PARATR_LIST_AUTOFMT)); if (std::shared_ptr<SfxItemSet> const& pSet = rListAutoFormat.GetStyleHandle()) { aParagraphMarkerProperties.Put(*pSet); diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index f3b5b6e4e958..2e764b755ae6 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -1363,7 +1363,7 @@ void SwWW8FltControlStack::SetAttrInDoc(const SwPosition& rTmpPos, continue; SwContentNode* pNd = static_cast<SwContentNode*>(pNode); - SvxLRSpaceItem aOldLR = static_cast<const SvxLRSpaceItem&>(pNd->GetAttr(RES_LR_SPACE)); + SvxLRSpaceItem aOldLR = pNd->GetAttr(RES_LR_SPACE); SwTextNode *pTextNode = static_cast<SwTextNode*>(pNode);