sw/source/filter/ww8/ww8atr.cxx | 34 ++++++++++++++++------------------ sw/source/filter/ww8/ww8graf.cxx | 11 +++++------ sw/source/filter/ww8/ww8par.cxx | 14 ++++++-------- sw/source/filter/ww8/ww8par2.cxx | 11 +++++------ 4 files changed, 32 insertions(+), 38 deletions(-)
New commits: commit 4cefeb50418e42cdad11429a2c5e03f5d21e73fd Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed Mar 9 11:59:31 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed Mar 9 15:48:08 2022 +0100 use SfxItemSet::GetItemIfSet in sw/.../ww8 Change-Id: I304b0cfbb191254db5176049696e5a3f6666f271 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131235 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx index b9ec65d4cfc9..0cf65abc4553 100644 --- a/sw/source/filter/ww8/ww8atr.cxx +++ b/sw/source/filter/ww8/ww8atr.cxx @@ -315,7 +315,6 @@ void MSWordExportBase::OutputItemSet( const SfxItemSet& rSet, bool bPapFormat, b if( !(bExportParentItemSet || rSet.Count()) ) return; - const SfxPoolItem* pItem; m_pISet = &rSet; // for double attributes // If frame dir is set, but not adjust, then force adjust as well @@ -324,7 +323,7 @@ void MSWordExportBase::OutputItemSet( const SfxItemSet& rSet, bool bPapFormat, b // No explicit adjust set ? if ( SfxItemState::SET != rSet.GetItemState( RES_PARATR_ADJUST, bExportParentItemSet ) ) { - pItem = rSet.GetItem( RES_PARATR_ADJUST, bExportParentItemSet ); + const SvxAdjustItem* pItem = rSet.GetItem( RES_PARATR_ADJUST, bExportParentItemSet ); if ( nullptr != pItem ) { // then set the adjust used by the parent format @@ -333,17 +332,19 @@ void MSWordExportBase::OutputItemSet( const SfxItemSet& rSet, bool bPapFormat, b } } - if ( bPapFormat && SfxItemState::SET == rSet.GetItemState( RES_PARATR_NUMRULE, bExportParentItemSet, &pItem ) ) + const SwNumRuleItem* pRuleItem; + if ( bPapFormat && (pRuleItem = rSet.GetItemIfSet( RES_PARATR_NUMRULE, bExportParentItemSet )) ) { - AttrOutput().OutputItem( *pItem ); + AttrOutput().OutputItem( *pRuleItem ); // switch off the numbering? - if ( pItem->StaticWhichCast(RES_PARATR_NUMRULE).GetValue().isEmpty() && + const SfxPoolItem* pLRItem; + if ( pRuleItem->GetValue().isEmpty() && SfxItemState::SET != rSet.GetItemState( RES_LR_SPACE, false) && - SfxItemState::SET == rSet.GetItemState( RES_LR_SPACE, true, &pItem ) ) + (pLRItem = rSet.GetItemIfSet( RES_LR_SPACE )) ) { // the set the LR-Space of the parentformat! - AttrOutput().OutputItem( *pItem ); + AttrOutput().OutputItem( *pLRItem ); } } @@ -357,7 +358,7 @@ void MSWordExportBase::OutputItemSet( const SfxItemSet& rSet, bool bPapFormat, b for ( const auto& rItem : aItems ) { - pItem = rItem.second; + const SfxPoolItem* pItem = rItem.second; sal_uInt16 nWhich = pItem->Which(); // Handle fill attributes just like frame attributes for now. if ( (nWhich >= RES_PARATR_BEGIN && nWhich < RES_FRMATR_END && nWhich != RES_PARATR_NUMRULE ) || @@ -482,7 +483,6 @@ void MSWordExportBase::OutputSectionBreaks( const SfxItemSet *pSet, const SwNode m_bBreakBefore = true; bool bNewPageDesc = false; - const SfxPoolItem* pItem=nullptr; const SwFormatPageDesc *pPgDesc=nullptr; bool bExtraPageBreakBeforeSectionBreak = false; @@ -515,23 +515,23 @@ void MSWordExportBase::OutputSectionBreaks( const SfxItemSet *pSet, const SwNode if ( pSet && pSet->Count() ) { - if ( SfxItemState::SET == pSet->GetItemState( RES_PAGEDESC, false, &pItem ) && - pItem->StaticWhichCast(RES_PAGEDESC).GetRegisteredIn() != nullptr) + const SwFormatPageDesc * pItem = pSet->GetItemIfSet( RES_PAGEDESC, false ); + if ( pItem && pItem->GetRegisteredIn() != nullptr) { bBreakSet = true; bNewPageDesc = true; - pPgDesc = static_cast<const SwFormatPageDesc*>(pItem); + pPgDesc = pItem; m_pCurrentPageDesc = pPgDesc->GetPageDesc(); // tdf#121666: nodes that have pagebreak + sectionbreak may need to export both breaks // tested / implemented with docx format only. // If other formats (rtf /doc) need similar fix, then that may can be done similar way. - if (SfxItemState::SET == pSet->GetItemState(RES_BREAK, false, &pItem)) + if (SfxItemState::SET == pSet->GetItemState(RES_BREAK, false)) { bExtraPageBreakBeforeSectionBreak = true; } } - else if ( SfxItemState::SET == pSet->GetItemState( RES_BREAK, false, &pItem ) ) + else if ( const SvxFormatBreakItem* pBreak = pSet->GetItemIfSet( RES_BREAK, false ) ) { // Word does not like hard break attributes in some table cells bool bRemoveHardBreakInsideTable = false; @@ -569,15 +569,13 @@ void MSWordExportBase::OutputSectionBreaks( const SfxItemSet *pSet, const SwNode if ( m_pCurrentPageDesc ) { // #i76301# - assure that there is a page break before set at the node. - const SvxFormatBreakItem* pBreak = dynamic_cast<const SvxFormatBreakItem*>(pItem); - if ( pBreak && - pBreak->GetBreak() == SvxBreak::PageBefore ) + if ( pBreak->GetBreak() == SvxBreak::PageBefore ) { bNewPageDesc |= SetCurrentPageDescFromNode( rNd ); } } if ( !bNewPageDesc ) - AttrOutput().OutputItem( *pItem ); + AttrOutput().OutputItem( *pBreak ); } } } diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx index 2c7a11452d2f..e942f437c50c 100644 --- a/sw/source/filter/ww8/ww8graf.cxx +++ b/sw/source/filter/ww8/ww8graf.cxx @@ -1748,9 +1748,8 @@ void SwWW8ImplReader::MatchSdrItemsIntoFlySet( SdrObject const * pSdrObj, sal_Int32 nLineThick = 15, nOutside=0; // check if LineStyle is *really* set! - const SfxPoolItem* pItem; - SfxItemState eState = rOldSet.GetItemState(XATTR_LINESTYLE,true,&pItem); + SfxItemState eState = rOldSet.GetItemState(XATTR_LINESTYLE); if( eState == SfxItemState::SET ) { // Now, that we know there is a line style we will make use the @@ -1865,7 +1864,7 @@ void SwWW8ImplReader::MatchSdrItemsIntoFlySet( SdrObject const * pSdrObj, sal_uInt8 nTrans = 0; // Separate transparency - eState = rOldSet.GetItemState(XATTR_FILLTRANSPARENCE, true, &pItem); + eState = rOldSet.GetItemState(XATTR_FILLTRANSPARENCE); if (!bSkipResBackground && eState == SfxItemState::SET) { sal_uInt16 nRes = WW8ITEMVALUE(rOldSet, XATTR_FILLTRANSPARENCE, @@ -1876,10 +1875,10 @@ void SwWW8ImplReader::MatchSdrItemsIntoFlySet( SdrObject const * pSdrObj, } // Background: SvxBrushItem - eState = rOldSet.GetItemState(XATTR_FILLSTYLE, true, &pItem); - if (!bSkipResBackground && eState == SfxItemState::SET) + const XFillStyleItem* pFillStyleItem = rOldSet.GetItemIfSet(XATTR_FILLSTYLE); + if (!bSkipResBackground && pFillStyleItem) { - const drawing::FillStyle eFill = static_cast<const XFillStyleItem*>(pItem)->GetValue(); + const drawing::FillStyle eFill = pFillStyleItem->GetValue(); switch (eFill) { diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index 469118b61ebd..0feefd11d681 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -975,9 +975,7 @@ SdrObject* SwMSDffManager::ProcessObj(SvStream& rSt, SfxItemSet aSet( pSdrModel->GetItemPool() ); ApplyAttributes( rSt, aSet, rObjData ); - const SfxPoolItem* pPoolItem=nullptr; - SfxItemState eState = aSet.GetItemState( XATTR_FILLCOLOR, - false, &pPoolItem ); + SfxItemState eState = aSet.GetItemState( XATTR_FILLCOLOR, false ); if( SfxItemState::DEFAULT == eState ) aSet.Put( XFillColorItem( OUString(), mnDefaultColor ) ); pObj->SetMergedItemSet(aSet); @@ -1663,12 +1661,12 @@ void SwWW8ImplReader::Read_Tab(sal_uInt16 , const sal_uInt8* pData, short nLen) std::unordered_set<size_t> aLoopWatch; while (pSty && !bFound) { - const SfxPoolItem* pTabs; + const SvxTabStopItem* pTabs; bFound = pSty->GetAttrSet().GetItemState(RES_PARATR_TABSTOP, false, &pTabs) == SfxItemState::SET; if( bFound ) { - aAttr.reset(static_cast<SvxTabStopItem*>(pTabs->Clone())); + aAttr.reset(pTabs->Clone()); } else { @@ -5599,10 +5597,10 @@ namespace OUString aPassw; const SfxItemSet* pSet = rMedium.GetItemSet(); - const SfxPoolItem *pPasswordItem; + const SfxStringItem *pPasswordItem; - if(pSet && SfxItemState::SET == pSet->GetItemState(SID_PASSWORD, true, &pPasswordItem)) - aPassw = static_cast<const SfxStringItem *>(pPasswordItem)->GetValue(); + if(pSet && (pPasswordItem = pSet->GetItemIfSet(SID_PASSWORD))) + aPassw = pPasswordItem->GetValue(); else { try diff --git a/sw/source/filter/ww8/ww8par2.cxx b/sw/source/filter/ww8/ww8par2.cxx index 016ce7244634..3ad3684bf807 100644 --- a/sw/source/filter/ww8/ww8par2.cxx +++ b/sw/source/filter/ww8/ww8par2.cxx @@ -2540,19 +2540,18 @@ void WW8TabDesc::CreateSwTable() { if (const SfxItemSet* pSet = pNd->GetpSwAttrSet()) { - SfxPoolItem *pSetAttr = nullptr; - const SfxPoolItem* pItem; - if (SfxItemState::SET == pSet->GetItemState(RES_BREAK, false, &pItem)) + std::unique_ptr<SfxPoolItem> pSetAttr; + + if (const SvxFormatBreakItem* pBreakItem = pSet->GetItemIfSet(RES_BREAK, false)) { - pSetAttr = new SvxFormatBreakItem( *static_cast<const SvxFormatBreakItem*>(pItem) ); + pSetAttr.reset(new SvxFormatBreakItem( *pBreakItem )); pNd->ResetAttr( RES_BREAK ); } // eventually set the PageDesc/Break now to the table if (pSetAttr) { - m_aItemSet.Put(*pSetAttr); - delete pSetAttr; + m_aItemSet.Put(std::move(pSetAttr)); } } }