diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-03-02 18:00:44 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-03-03 08:50:17 +0100 |
commit | 4796e6d60b8d78cff401cc41712c2d2e862eee69 (patch) | |
tree | 0f3e27beee9eaf0cbcbed38be529504dae69e04a | |
parent | 6f50fe6f524d922c27ec1313ebef49352a2f9128 (diff) |
use SfxItemSet::GetItemIfSet in sw/source/core/unocore
Change-Id: I18b05cfb49e5ab3e42db4c8c2c1fbfb4ec4659e2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130884
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | sw/source/core/unocore/unoframe.cxx | 15 | ||||
-rw-r--r-- | sw/source/core/unocore/unoobj.cxx | 18 | ||||
-rw-r--r-- | sw/source/core/unocore/unostyle.cxx | 49 | ||||
-rw-r--r-- | sw/source/core/unocore/unotbl.cxx | 25 |
4 files changed, 49 insertions, 58 deletions
diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx index ad9638cd570f..44b329d1d55c 100644 --- a/sw/source/core/unocore/unoframe.cxx +++ b/sw/source/core/unocore/unoframe.cxx @@ -1559,8 +1559,7 @@ void SwXFrame::setPropertyValue(const OUString& rPropertyName, const ::uno::Any& pFly = pFlyFrameFormat->GetFrame(); if ( pFly ) { - const ::SfxPoolItem* pItem; - if( SfxItemState::SET == pFrameFormat->GetItemState( RES_ANCHOR, false, &pItem )) + if( const SwFormatAnchor* pItem = pFrameFormat->GetItemIfSet( RES_ANCHOR, false )) { pSet.emplace( pDoc->GetAttrPool(), aFrameFormatSetRange ); pSet->Put( *pItem ); @@ -1901,8 +1900,7 @@ void SwXFrame::setPropertyValue(const OUString& rPropertyName, const ::uno::Any& pFly = pFrameFormat->GetFrame(); if (pFly) { - const ::SfxPoolItem* pItem; - if( SfxItemState::SET == aSet.GetItemState( RES_ANCHOR, false, &pItem )) + if( const SwFormatAnchor* pItem = aSet.GetItemIfSet( RES_ANCHOR, false )) { aSet.Put( *pItem ); if ( pFormat->GetDoc()->GetEditShell() != nullptr ) @@ -2762,11 +2760,10 @@ void SwXFrame::attachToRange(uno::Reference<text::XTextRange> const& xTextRange, *aPam.GetMark() = *aIntPam.GetMark(); } - const SfxPoolItem* pItem; RndStdIds eAnchorId = RndStdIds::FLY_AT_PARA; - if(SfxItemState::SET == aFrameSet.GetItemState(RES_ANCHOR, false, &pItem) ) + if(const SwFormatAnchor* pItem = aFrameSet.GetItemIfSet(RES_ANCHOR, false) ) { - eAnchorId = static_cast<const SwFormatAnchor*>(pItem)->GetAnchorId(); + eAnchorId = pItem->GetAnchorId(); if( RndStdIds::FLY_AT_FLY == eAnchorId && !aPam.GetNode().FindFlyStartNode()) { @@ -2775,9 +2772,9 @@ void SwXFrame::attachToRange(uno::Reference<text::XTextRange> const& xTextRange, aFrameSet.Put(aAnchor); } else if ((RndStdIds::FLY_AT_PAGE == eAnchorId) && - 0 == static_cast<const SwFormatAnchor*>(pItem)->GetPageNum() ) + 0 == pItem->GetPageNum() ) { - SwFormatAnchor aAnchor( *static_cast<const SwFormatAnchor*>(pItem) ); + SwFormatAnchor aAnchor( *pItem ); aAnchor.SetAnchor( aPam.GetPoint() ); aFrameSet.Put(aAnchor); } diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx index b26acac97282..94e2e5d37e06 100644 --- a/sw/source/core/unocore/unoobj.cxx +++ b/sw/source/core/unocore/unoobj.cxx @@ -266,11 +266,9 @@ SwUnoCursorHelper::SetPageDesc( return false; } std::unique_ptr<SwFormatPageDesc> pNewDesc; - const SfxPoolItem* pItem; - if(SfxItemState::SET == rSet.GetItemState( RES_PAGEDESC, true, &pItem ) ) + if(const SwFormatPageDesc* pItem = rSet.GetItemIfSet( RES_PAGEDESC )) { - pNewDesc.reset(new SwFormatPageDesc( - *static_cast<const SwFormatPageDesc*>(pItem))); + pNewDesc.reset(new SwFormatPageDesc(*pItem)); } if (!pNewDesc) { @@ -384,11 +382,9 @@ lcl_setDropcapCharStyle(SwPaM const & rPam, SfxItemSet & rItemSet, throw lang::IllegalArgumentException(); } std::unique_ptr<SwFormatDrop> pDrop; - SfxPoolItem const* pItem(nullptr); - if (SfxItemState::SET == - rItemSet.GetItemState(RES_PARATR_DROP, true, &pItem)) + if (const SwFormatDrop* pItem = rItemSet.GetItemIfSet(RES_PARATR_DROP)) { - pDrop.reset(new SwFormatDrop(*static_cast<const SwFormatDrop*>(pItem))); + pDrop.reset(new SwFormatDrop(*pItem)); } if (!pDrop) { @@ -409,11 +405,9 @@ lcl_setRubyCharstyle(SfxItemSet & rItemSet, uno::Any const& rValue) } std::unique_ptr<SwFormatRuby> pRuby; - const SfxPoolItem* pItem; - if (SfxItemState::SET == - rItemSet.GetItemState(RES_TXTATR_CJK_RUBY, true, &pItem)) + if (const SwFormatRuby* pItem = rItemSet.GetItemIfSet(RES_TXTATR_CJK_RUBY)) { - pRuby.reset(new SwFormatRuby(*static_cast<const SwFormatRuby*>(pItem))); + pRuby.reset(new SwFormatRuby(*pItem)); } if (!pRuby) { diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 43722e270a91..b49e4729a54f 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -614,17 +614,17 @@ static bool lcl_GetHeaderFooterItem( SfxItemSet const& rSet, std::u16string_view rPropName, bool const bFooter, SvxSetItem const*& o_rpItem) { - SfxItemState eState = rSet.GetItemState( + o_rpItem = rSet.GetItemIfSet( bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, - false, reinterpret_cast<const SfxPoolItem**>(&o_rpItem)); - if (SfxItemState::SET != eState && + false); + if (!o_rpItem && rPropName == u"" UNO_NAME_FIRST_IS_SHARED) { // fdo#79269 header may not exist, check footer then - eState = rSet.GetItemState( + o_rpItem = rSet.GetItemIfSet( (!bFooter) ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, - false, reinterpret_cast<const SfxPoolItem**>(&o_rpItem)); + false); } - return SfxItemState::SET == eState; + return o_rpItem; } template<enum SfxStyleFamily> @@ -1818,9 +1818,8 @@ void SwXStyle::SetPropertyValue<sal_uInt16(RES_PAGEDESC)>(const SfxItemPropertyM // special handling for RES_PAGEDESC SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet(); std::unique_ptr<SwFormatPageDesc> pNewDesc; - const SfxPoolItem* pItem; - if(SfxItemState::SET == rStyleSet.GetItemState(RES_PAGEDESC, true, &pItem)) - pNewDesc.reset(new SwFormatPageDesc(*static_cast<const SwFormatPageDesc*>(pItem))); + if(const SwFormatPageDesc* pItem = rStyleSet.GetItemIfSet(RES_PAGEDESC)) + pNewDesc.reset(new SwFormatPageDesc(*pItem)); else pNewDesc.reset(new SwFormatPageDesc); const auto sValue(rValue.get<OUString>()); @@ -1943,9 +1942,8 @@ void SwXStyle::SetPropertyValue<sal_uInt16(RES_TXTATR_CJK_RUBY)>(const SfxItemPr const auto sValue(rValue.get<OUString>()); SfxItemSet& rStyleSet(o_rStyleBase.GetItemSet()); std::unique_ptr<SwFormatRuby> pRuby; - const SfxPoolItem* pItem; - if(SfxItemState::SET == rStyleSet.GetItemState(RES_TXTATR_CJK_RUBY, true, &pItem)) - pRuby.reset(new SwFormatRuby(*static_cast<const SwFormatRuby*>(pItem))); + if(const SwFormatRuby* pRubyItem = rStyleSet.GetItemIfSet(RES_TXTATR_CJK_RUBY)) + pRuby.reset(new SwFormatRuby(*pRubyItem)); else pRuby.reset(new SwFormatRuby(OUString())); OUString sStyle; @@ -1972,9 +1970,8 @@ void SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_DROP)>(const SfxItemProper throw lang::IllegalArgumentException(); SfxItemSet& rStyleSet(o_rStyleBase.GetItemSet()); std::unique_ptr<SwFormatDrop> pDrop; - const SfxPoolItem* pItem; - if(SfxItemState::SET == rStyleSet.GetItemState(RES_PARATR_DROP, true, &pItem)) - pDrop.reset(new SwFormatDrop(*static_cast<const SwFormatDrop*>(pItem))); + if(const SwFormatDrop* pDropItem = rStyleSet.GetItemIfSet(RES_PARATR_DROP)) + pDrop.reset(new SwFormatDrop(*pDropItem)); else pDrop.reset(new SwFormatDrop); const auto sValue(rValue.get<OUString>()); @@ -2224,10 +2221,11 @@ uno::Any SwXStyle::GetStyleProperty<sal_uInt16(RES_PAGEDESC)>(const SfxItemPrope if(MID_PAGEDESC_PAGEDESCNAME != rEntry.nMemberId) return GetStyleProperty<HINT_BEGIN>(rEntry, rPropSet, rBase); // special handling for RES_PAGEDESC - const SfxPoolItem* pItem; - if(SfxItemState::SET != rBase.GetItemSet().GetItemState(RES_PAGEDESC, true, &pItem)) + const SwFormatPageDesc* pItem = + rBase.GetItemSet().GetItemIfSet(RES_PAGEDESC); + if(!pItem) return uno::Any(); - const SwPageDesc* pDesc = static_cast<const SwFormatPageDesc*>(pItem)->GetPageDesc(); + const SwPageDesc* pDesc = pItem->GetPageDesc(); if(!pDesc) return uno::Any(); OUString aString; @@ -2925,9 +2923,10 @@ void SwXPageStyle::SetPropertyValues_Impl(const uno::Sequence<OUString>& rProper if (pEntry->nWID == SID_ATTR_PAGE_SHARED_FIRST) { // Need to add this to the other as well - if (SfxItemState::SET == aBaseImpl.GetItemSet().GetItemState( + pSetItem = aBaseImpl.GetItemSet().GetItemIfSet( bFooter ? SID_ATTR_PAGE_HEADERSET : SID_ATTR_PAGE_FOOTERSET, - false, reinterpret_cast<const SfxPoolItem**>(&pSetItem))) + false); + if (pSetItem) { PutItemToSet(pSetItem, *pPropSet, *pEntry, rValues[nProp], aBaseImpl); } @@ -2989,9 +2988,10 @@ void SwXPageStyle::SetPropertyValues_Impl(const uno::Sequence<OUString>& rProper if(bFirstIsShared) // only special handling for headers/footers here break; { - const SvxSetItem* pSetItem = nullptr; + const SvxSetItem* pSetItem = + aBaseImpl.GetItemSet().GetItemIfSet(bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, false); - if(SfxItemState::SET == aBaseImpl.GetItemSet().GetItemState(bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, false, reinterpret_cast<const SfxPoolItem**>(&pSetItem))) + if(pSetItem) { // create a new SvxSetItem and get it's ItemSet as new target std::unique_ptr<SvxSetItem> pNewSetItem(pSetItem->Clone()); @@ -3204,8 +3204,9 @@ uno::Sequence<uno::Any> SwXPageStyle::GetPropertyValues_Impl(const uno::Sequence { rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pBase) ) ); const SfxItemSet& rSet = xStyle->GetItemSet(); - const SvxSetItem* pSetItem; - if(SfxItemState::SET == rSet.GetItemState(bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, false, reinterpret_cast<const SfxPoolItem**>(&pSetItem))) + const SvxSetItem* pSetItem = + rSet.GetItemIfSet(bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, false); + if(pSetItem) { // set at SfxItemSet of the corresponding SfxSetItem const SfxItemSet& rSetSet = pSetItem->GetItemSet(); diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx index 4723379f0024..0357d048dfdf 100644 --- a/sw/source/core/unocore/unotbl.cxx +++ b/sw/source/core/unocore/unotbl.cxx @@ -286,10 +286,9 @@ static uno::Any lcl_GetSpecialProperty(SwFrameFormat* pFormat, const SfxItemProp case RES_PAGEDESC: { const SfxItemSet& rSet = pFormat->GetAttrSet(); - const SfxPoolItem* pItem; - if(SfxItemState::SET == rSet.GetItemState(RES_PAGEDESC, false, &pItem)) + if(const SwFormatPageDesc* pItem = rSet.GetItemIfSet(RES_PAGEDESC, false)) { - const SwPageDesc* pDsc = static_cast<const SwFormatPageDesc*>(pItem)->GetPageDesc(); + const SwPageDesc* pDsc = pItem->GetPageDesc(); if(pDsc) return uno::makeAny<OUString>(SwStyleNameMapper::GetProgName(pDsc->GetName(), SwGetPoolIdFromName::PageDesc )); } @@ -695,13 +694,13 @@ void sw_setValue( SwXCell &rCell, double nVal ) UnoActionContext aAction(pDoc); SwFrameFormat* pBoxFormat = rCell.m_pBox->ClaimFrameFormat(); SfxItemSetFixed<RES_BOXATR_FORMAT, RES_BOXATR_VALUE> aSet(pDoc->GetAttrPool()); - const SfxPoolItem* pItem; //!! do we need to set a new number format? Yes, if // - there is no current number format // - the current number format is not a number format according to the number formatter, but rather a text format - if(SfxItemState::SET != pBoxFormat->GetAttrSet().GetItemState(RES_BOXATR_FORMAT, true, &pItem) - || pDoc->GetNumberFormatter()->IsTextFormat(static_cast<const SwTableBoxNumFormat*>(pItem)->GetValue())) + const SwTableBoxNumFormat* pNumFormat = pBoxFormat->GetAttrSet().GetItemIfSet(RES_BOXATR_FORMAT); + if(!pNumFormat + || pDoc->GetNumberFormatter()->IsTextFormat(pNumFormat->GetValue())) { aSet.Put(SwTableBoxNumFormat(0)); } @@ -853,10 +852,11 @@ void SwXCell::setFormula(const OUString& rFormula) SwDoc* pMyDoc = GetDoc(); UnoActionContext aAction(pMyDoc); SfxItemSetFixed<RES_BOXATR_FORMAT, RES_BOXATR_FORMULA> aSet(pMyDoc->GetAttrPool()); - const SfxPoolItem* pItem; SwFrameFormat* pBoxFormat = m_pBox->GetFrameFormat(); - if(SfxItemState::SET != pBoxFormat->GetAttrSet().GetItemState(RES_BOXATR_FORMAT, true, &pItem) - || pMyDoc->GetNumberFormatter()->IsTextFormat(static_cast<const SwTableBoxNumFormat*>(pItem)->GetValue())) + const SwTableBoxNumFormat* pNumFormat = + pBoxFormat->GetAttrSet().GetItemIfSet(RES_BOXATR_FORMAT); + if(!pNumFormat + || pMyDoc->GetNumberFormatter()->IsTextFormat(pNumFormat->GetValue())) { aSet.Put(SwTableBoxNumFormat(0)); } @@ -1166,15 +1166,14 @@ double SwXCell::GetForcedNumericalValue() const sal_uInt32 nFIndex; SvNumberFormatter* pNumFormatter(const_cast<SvNumberFormatter*>(GetDoc()->GetNumberFormatter())); // look for SwTableBoxNumFormat value in parents as well - const SfxPoolItem* pItem; auto pBoxFormat(GetTableBox()->GetFrameFormat()); - SfxItemState eState = pBoxFormat->GetAttrSet().GetItemState(RES_BOXATR_FORMAT, true, &pItem); + const SwTableBoxNumFormat* pNumFormat = pBoxFormat->GetAttrSet().GetItemIfSet(RES_BOXATR_FORMAT); - if (eState == SfxItemState::SET) + if (pNumFormat) { // please note that the language of the numberformat // is implicitly coded into the below value as well - nFIndex = static_cast<const SwTableBoxNumFormat*>(pItem)->GetValue(); + nFIndex = pNumFormat->GetValue(); // since the current value indicates a text format but the call // to 'IsNumberFormat' below won't work for text formats |