diff options
Diffstat (limited to 'sw')
34 files changed, 519 insertions, 603 deletions
diff --git a/sw/source/uibase/app/apphdl.cxx b/sw/source/uibase/app/apphdl.cxx index 8042ed313605..e0934b78ce94 100644 --- a/sw/source/uibase/app/apphdl.cxx +++ b/sw/source/uibase/app/apphdl.cxx @@ -244,13 +244,13 @@ std::shared_ptr<SwMailMergeConfigItem> SwView::EnsureMailMergeConfigItem(const S xMMConfig->SetSourceView(this); //set the first used database as default source on the config item - const SfxPoolItem* pItem = nullptr; - if (pArgs && SfxItemState::SET == pArgs->GetItemState( - FN_PARAM_DATABASE_PROPERTIES, false, &pItem)) + const SfxUnoAnyItem* pItem = nullptr; + if (pArgs && (pItem = pArgs->GetItemIfSet( + FN_PARAM_DATABASE_PROPERTIES, false))) { //mailmerge has been called from the database beamer uno::Sequence< beans::PropertyValue> aDBValues; - if (static_cast<const SfxUnoAnyItem*>(pItem)->GetValue() >>= aDBValues) + if (pItem->GetValue() >>= aDBValues) { SwDBData aDBData; svx::ODataAccessDescriptor aDescriptor(aDBValues); diff --git a/sw/source/uibase/app/appopt.cxx b/sw/source/uibase/app/appopt.cxx index c4fe62e2ffa9..77033c4940f0 100644 --- a/sw/source/uibase/app/appopt.cxx +++ b/sw/source/uibase/app/appopt.cxx @@ -228,15 +228,12 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) SwViewOption aViewOpt = *GetUsrPref(!bTextDialog); SwMasterUsrPref* pPref = bTextDialog ? m_pUsrPref.get() : m_pWebUsrPref.get(); - const SfxPoolItem* pItem; SfxBindings *pBindings = pAppView ? &pAppView->GetViewFrame()->GetBindings() : nullptr; // Interpret the page Documentview - if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_DOCDISP, false, &pItem )) + if( const SwDocDisplayItem* pDocDispItem = rSet.GetItemIfSet( FN_PARAM_DOCDISP, false )) { - const SwDocDisplayItem* pDocDispItem = static_cast<const SwDocDisplayItem*>(pItem); - if(!aViewOpt.IsViewMetaChars()) { if( (!aViewOpt.IsTab( true ) && pDocDispItem->m_bTab) || @@ -261,9 +258,8 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) // Elements - interpret Item bool bFlag = true; - if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_ELEM, false, &pItem ) ) + if( const SwElemItem* pElemItem = rSet.GetItemIfSet( FN_PARAM_ELEM, false ) ) { - const SwElemItem* pElemItem = static_cast<const SwElemItem*>(pItem); pElemItem->FillViewOptions( aViewOpt ); SwWrtShell* pWrtShell = GetActiveWrtShell(); @@ -280,42 +276,38 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) } } - if( SfxItemState::SET == rSet.GetItemState(SID_ATTR_METRIC, false, &pItem ) ) + if( const SfxUInt16Item* pMetricItem = rSet.GetItemIfSet(SID_ATTR_METRIC, false ) ) { SfxGetpApp()->SetOptions(rSet); - PutItem(*pItem); - const SfxUInt16Item* pMetricItem = static_cast<const SfxUInt16Item*>(pItem); + PutItem(*pMetricItem); ::SetDfltMetric(static_cast<FieldUnit>(pMetricItem->GetValue()), !bTextDialog); } - if( SfxItemState::SET == rSet.GetItemState(SID_ATTR_APPLYCHARUNIT, - false, &pItem ) ) + if( const SfxBoolItem* pCharItem = rSet.GetItemIfSet(SID_ATTR_APPLYCHARUNIT, + false ) ) { SfxGetpApp()->SetOptions(rSet); - const SfxBoolItem* pCharItem = static_cast<const SfxBoolItem*>(pItem); ::SetApplyCharUnit(pCharItem->GetValue(), !bTextDialog); } - if( SfxItemState::SET == rSet.GetItemState(FN_HSCROLL_METRIC, false, &pItem ) ) + if( const SfxUInt16Item* pMetricItem = rSet.GetItemIfSet(FN_HSCROLL_METRIC, false ) ) { - const SfxUInt16Item* pMetricItem = static_cast<const SfxUInt16Item*>(pItem); FieldUnit eUnit = static_cast<FieldUnit>(pMetricItem->GetValue()); pPref->SetHScrollMetric(eUnit); if(pAppView) pAppView->ChangeTabMetric(eUnit); } - if( SfxItemState::SET == rSet.GetItemState(FN_VSCROLL_METRIC, false, &pItem ) ) + if( const SfxUInt16Item* pMetricItem = rSet.GetItemIfSet(FN_VSCROLL_METRIC, false ) ) { - const SfxUInt16Item* pMetricItem = static_cast<const SfxUInt16Item*>(pItem); FieldUnit eUnit = static_cast<FieldUnit>(pMetricItem->GetValue()); pPref->SetVScrollMetric(eUnit); if(pAppView) pAppView->ChangeVRulerMetric(eUnit); } - if( SfxItemState::SET == rSet.GetItemState(SID_ATTR_DEFTABSTOP, false, &pItem ) ) + if( const SfxUInt16Item* pItem = rSet.GetItemIfSet(SID_ATTR_DEFTABSTOP, false ) ) { - sal_uInt16 nTabDist = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); + sal_uInt16 nTabDist = pItem->GetValue(); pPref->SetDefTabInMm100(convertTwipToMm100(nTabDist)); if(pAppView) { @@ -333,10 +325,8 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) } // Interpret page Grid Settings - if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS, false, &pItem )) + if( const SvxGridItem* pGridItem = rSet.GetItemIfSet( SID_ATTR_GRID_OPTIONS, false )) { - const SvxGridItem* pGridItem = static_cast<const SvxGridItem*>(pItem); - aViewOpt.SetSnap( pGridItem->GetUseGridSnap() ); aViewOpt.SetSynchronize(pGridItem->GetSynchronize()); if( aViewOpt.IsGridVisible() != pGridItem->GetGridVisible() ) @@ -359,20 +349,18 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) } // Interpret Writer Printer Options - if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_ADDPRINTER, false, &pItem )) + if( const SwAddPrinterItem* pAddPrinterAttr = rSet.GetItemIfSet( FN_PARAM_ADDPRINTER, false ) ) { SwPrintOptions* pOpt = GetPrtOptions(!bTextDialog); if (pOpt) { - const SwAddPrinterItem* pAddPrinterAttr = static_cast<const SwAddPrinterItem*>(pItem); *pOpt = *pAddPrinterAttr; } - } - if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_SHADOWCURSOR, false, &pItem )) + if( const SwShadowCursorItem* pItem = rSet.GetItemIfSet( FN_PARAM_SHADOWCURSOR, false )) { - static_cast<const SwShadowCursorItem*>(pItem)->FillViewOptions( aViewOpt ); + pItem->FillViewOptions( aViewOpt ); if(pBindings) pBindings->Invalidate(FN_SHADOWCURSOR); } @@ -388,9 +376,9 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) rWrtSh.AlignAllFormulasToBaseline(); } - if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_CRSR_IN_PROTECTED, false, &pItem )) + if( const SfxBoolItem* pItem = rSet.GetItemIfSet( FN_PARAM_CRSR_IN_PROTECTED, false )) { - aViewOpt.SetCursorInProtectedArea(static_cast<const SfxBoolItem*>(pItem)->GetValue()); + aViewOpt.SetCursorInProtectedArea(pItem->GetValue()); } // set elements for the current view and shell diff --git a/sw/source/uibase/app/docsh.cxx b/sw/source/uibase/app/docsh.cxx index facceefc11e7..1be72f73fec8 100644 --- a/sw/source/uibase/app/docsh.cxx +++ b/sw/source/uibase/app/docsh.cxx @@ -141,11 +141,11 @@ Reader* SwDocShell::StartConvertFrom(SfxMedium& rMedium, SwReaderPtr& rpRdr, SwPaM* pPaM ) { bool bAPICall = false; - const SfxPoolItem* pApiItem; - const SfxItemSet* pMedSet; - if( nullptr != ( pMedSet = rMedium.GetItemSet() ) && SfxItemState::SET == - pMedSet->GetItemState( FN_API_CALL, true, &pApiItem ) ) - bAPICall = static_cast<const SfxBoolItem*>(pApiItem)->GetValue(); + const SfxBoolItem* pApiItem; + const SfxItemSet* pMedSet = rMedium.GetItemSet(); + if( pMedSet && + (pApiItem = pMedSet->GetItemIfSet( FN_API_CALL )) ) + bAPICall = pApiItem->GetValue(); std::shared_ptr<const SfxFilter> pFlt = rMedium.GetFilter(); if( !pFlt ) @@ -189,11 +189,11 @@ Reader* SwDocShell::StartConvertFrom(SfxMedium& rMedium, SwReaderPtr& rpRdr, pFlt->GetUserData() == FILTER_TEXT_DLG ) { SwAsciiOptions aOpt; - const SfxItemSet* pSet; - const SfxPoolItem* pItem; - if( nullptr != ( pSet = rMedium.GetItemSet() ) && SfxItemState::SET == - pSet->GetItemState( SID_FILE_FILTEROPTIONS, true, &pItem ) ) - aOpt.ReadUserData( static_cast<const SfxStringItem*>(pItem)->GetValue() ); + const SfxItemSet* pSet = rMedium.GetItemSet(); + const SfxStringItem* pItem; + if( pSet && + (pItem = pSet->GetItemIfSet( SID_FILE_FILTEROPTIONS )) ) + aOpt.ReadUserData( pItem->GetValue() ); pRead->GetReaderOpt().SetASCIIOpts( aOpt ); } @@ -750,10 +750,8 @@ bool SwDocShell::ConvertTo( SfxMedium& rMedium ) const SfxItemSet* pSet = rMedium.GetItemSet(); if( nullptr != pSet ) { - const SfxPoolItem* pItem; - if( SfxItemState::SET == pSet->GetItemState( SID_FILE_FILTEROPTIONS, - true, &pItem ) ) - sItemOpt = static_cast<const SfxStringItem*>(pItem)->GetValue(); + if( const SfxStringItem* pItem = pSet->GetItemIfSet( SID_FILE_FILTEROPTIONS ) ) + sItemOpt = pItem->GetValue(); } if(!sItemOpt.isEmpty()) aOpt.ReadUserData( sItemOpt ); @@ -1377,12 +1375,12 @@ void SwDocShell::SetChangeRecording( bool bActivate, bool bLockAllViews ) void SwDocShell::SetProtectionPassword( const OUString &rNewPassword ) { const SfxAllItemSet aSet( GetPool() ); - const SfxPoolItem* pItem = nullptr; IDocumentRedlineAccess& rIDRA = m_pWrtShell->getIDocumentRedlineAccess(); Sequence< sal_Int8 > aPasswd = rIDRA.GetRedlinePassword(); - if (SfxItemState::SET == aSet.GetItemState(FN_REDLINE_PROTECT, false, &pItem) - && static_cast<const SfxBoolItem*>(pItem)->GetValue() == aPasswd.hasElements()) + const SfxBoolItem* pRedlineProtectItem = aSet.GetItemIfSet(FN_REDLINE_PROTECT, false); + if (pRedlineProtectItem + && pRedlineProtectItem->GetValue() == aPasswd.hasElements()) return; if (!rNewPassword.isEmpty()) @@ -1405,12 +1403,12 @@ bool SwDocShell::GetProtectionHash( /*out*/ css::uno::Sequence< sal_Int8 > &rPas bool bRes = false; const SfxAllItemSet aSet( GetPool() ); - const SfxPoolItem* pItem = nullptr; IDocumentRedlineAccess& rIDRA = m_pWrtShell->getIDocumentRedlineAccess(); const Sequence< sal_Int8 >& aPasswdHash( rIDRA.GetRedlinePassword() ); - if (SfxItemState::SET == aSet.GetItemState(FN_REDLINE_PROTECT, false, &pItem) - && static_cast<const SfxBoolItem*>(pItem)->GetValue() == aPasswdHash.hasElements()) + const SfxBoolItem* pRedlineProtectItem = aSet.GetItemIfSet(FN_REDLINE_PROTECT, false); + if (pRedlineProtectItem + && pRedlineProtectItem->GetValue() == aPasswdHash.hasElements()) return false; rPasswordHash = aPasswdHash; bRes = true; diff --git a/sw/source/uibase/app/docsh2.cxx b/sw/source/uibase/app/docsh2.cxx index 208848bf9a05..4568f8ee685b 100644 --- a/sw/source/uibase/app/docsh2.cxx +++ b/sw/source/uibase/app/docsh2.cxx @@ -422,9 +422,9 @@ void SwDocShell::Execute(SfxRequest& rReq) SfxItemSetFixed<SID_AUTO_CORRECT_DLG, SID_AUTO_CORRECT_DLG, SID_OPEN_SMARTTAGOPTIONS, SID_OPEN_SMARTTAGOPTIONS> aSet( pApp->GetPool() ); aSet.Put( aSwOptions ); - const SfxPoolItem* pOpenSmartTagOptionsItem = nullptr; - if( pArgs && SfxItemState::SET == pArgs->GetItemState( SID_OPEN_SMARTTAGOPTIONS, false, &pOpenSmartTagOptionsItem ) ) - aSet.Put( *static_cast<const SfxBoolItem*>(pOpenSmartTagOptionsItem) ); + const SfxBoolItem* pOpenSmartTagOptionsItem = nullptr; + if( pArgs && (pOpenSmartTagOptionsItem = pArgs->GetItemIfSet( SID_OPEN_SMARTTAGOPTIONS, false )) ) + aSet.Put( *pOpenSmartTagOptionsItem ); SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create(); VclPtr<SfxAbstractTabDialog> pDlg = pFact->CreateAutoCorrTabDialog(GetView()->GetFrameWeld(), &aSet); @@ -1199,9 +1199,9 @@ void SwDocShell::Execute(SfxRequest& rReq) SwWrtShell* pSh = GetWrtShell(); const OUString& rValue = static_cast<const SfxStringItem*>(pItem)->GetValue(); auto eType = SfxClassificationPolicyType::IntellectualProperty; - if (pArgs->GetItemState(SID_TYPE_NAME, false, &pItem) == SfxItemState::SET) + if (const SfxStringItem* pTypeNameItem = pArgs->GetItemIfSet(SID_TYPE_NAME, false)) { - const OUString& rType = static_cast<const SfxStringItem*>(pItem)->GetValue(); + const OUString& rType = pTypeNameItem->GetValue(); eType = SfxClassificationHelper::stringToPolicyType(rType); } pSh->SetClassification(rValue, eType); @@ -1251,14 +1251,14 @@ void SwDocShell::Execute(SfxRequest& rReq) SfxWatermarkItem aItem; aItem.SetText( static_cast<const SfxStringItem*>( pItem )->GetValue() ); - if ( pArgs->GetItemState( SID_WATERMARK_FONT, false, &pItem ) == SfxItemState::SET ) - aItem.SetFont( static_cast<const SfxStringItem*>( pItem )->GetValue() ); - if ( pArgs->GetItemState( SID_WATERMARK_ANGLE, false, &pItem ) == SfxItemState::SET ) - aItem.SetAngle( static_cast<const SfxInt16Item*>( pItem )->GetValue() ); - if ( pArgs->GetItemState( SID_WATERMARK_TRANSPARENCY, false, &pItem ) == SfxItemState::SET ) - aItem.SetTransparency( static_cast<const SfxInt16Item*>( pItem )->GetValue() ); - if ( pArgs->GetItemState( SID_WATERMARK_COLOR, false, &pItem ) == SfxItemState::SET ) - aItem.SetColor( Color(ColorTransparency, static_cast<const SfxUInt32Item*>( pItem )->GetValue()) ); + if ( const SfxStringItem* pFontItem = pArgs->GetItemIfSet( SID_WATERMARK_FONT, false ) ) + aItem.SetFont( pFontItem->GetValue() ); + if ( const SfxInt16Item* pAngleItem = pArgs->GetItemIfSet( SID_WATERMARK_ANGLE, false ) ) + aItem.SetAngle( pAngleItem->GetValue() ); + if ( const SfxInt16Item* pTransItem = pArgs->GetItemIfSet( SID_WATERMARK_TRANSPARENCY, false ) ) + aItem.SetTransparency( pTransItem->GetValue() ); + if ( const SfxUInt32Item* pColorItem = pArgs->GetItemIfSet( SID_WATERMARK_COLOR, false ) ) + aItem.SetColor( Color(ColorTransparency, pColorItem->GetValue()) ); pSh->SetWatermark( aItem ); } diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx index 857850f1a55d..42eeebf1bf70 100644 --- a/sw/source/uibase/app/docst.cxx +++ b/sw/source/uibase/app/docst.cxx @@ -439,9 +439,8 @@ void SwDocShell::ExecStyleSheet( SfxRequest& rReq ) if( SfxItemState::SET == pArgs->GetItemState(SID_STYLE_MASK, false, &pItem )) nMask = static_cast<SfxStyleSearchBits>(static_cast<const SfxUInt16Item*>(pItem)->GetValue()); - if( SfxItemState::SET == pArgs->GetItemState(FN_PARAM_WRTSHELL, - false, &pItem )) - pActShell = pShell = static_cast<SwWrtShell*>(static_cast<const SwPtrItem*>(pItem)->GetValue()); + if( const SwPtrItem* pShellItem = pArgs->GetItemIfSet(FN_PARAM_WRTSHELL, false )) + pActShell = pShell = static_cast<SwWrtShell*>(pShellItem->GetValue()); if( nSlot == SID_STYLE_UPDATE_BY_EXAMPLE && aParam.isEmpty() ) { @@ -469,15 +468,15 @@ void SwDocShell::ExecStyleSheet( SfxRequest& rReq ) } break; case SfxStyleFamily::Pseudo: - if(SfxItemState::SET == pArgs->GetItemState(SID_STYLE_UPD_BY_EX_NAME, false, &pItem)) + if(const SfxStringItem* pExName = pArgs->GetItemIfSet(SID_STYLE_UPD_BY_EX_NAME, false)) { - aParam = static_cast<const SfxStringItem*>(pItem)->GetValue(); + aParam = pExName->GetValue(); } break; case SfxStyleFamily::Table: - if(SfxItemState::SET == pArgs->GetItemState(SID_STYLE_UPD_BY_EX_NAME, false, &pItem)) + if(const SfxStringItem* pExName = pArgs->GetItemIfSet(SID_STYLE_UPD_BY_EX_NAME, false)) { - aParam = static_cast<const SfxStringItem*>(pItem)->GetValue(); + aParam = pExName->GetValue(); } break; default: break; @@ -624,13 +623,11 @@ IMPL_LINK_NOARG(ApplyStyle, ApplyHdl, LinkParamNone*, void) if (m_nFamily == SfxStyleFamily::Page) { - const SfxPoolItem* pItem = nullptr; - if (aTmpSet.HasItem(SID_ATTR_CHAR_GRABBAG, &pItem)) + if (const SfxGrabBagItem* pGrabBagItem = aTmpSet.GetItemIfSet(SID_ATTR_CHAR_GRABBAG)) { - const auto& rGrabBagItem = static_cast<const SfxGrabBagItem&>(*pItem); bool bGutterAtTop{}; - auto it = rGrabBagItem.GetGrabBag().find("GutterAtTop"); - if (it != rGrabBagItem.GetGrabBag().end()) + auto it = pGrabBagItem->GetGrabBag().find("GutterAtTop"); + if (it != pGrabBagItem->GetGrabBag().end()) { it->second >>= bGutterAtTop; } @@ -647,14 +644,12 @@ IMPL_LINK_NOARG(ApplyStyle, ApplyHdl, LinkParamNone*, void) if (m_nFamily == SfxStyleFamily::Frame) { - const SfxPoolItem* pItem = nullptr; - if (aTmpSet.HasItem(FN_KEEP_ASPECT_RATIO, &pItem)) + if (const SfxBoolItem* pBoolItem = aTmpSet.GetItemIfSet(FN_KEEP_ASPECT_RATIO)) { - const auto& rBoolItem = static_cast<const SfxBoolItem&>(*pItem); const SwViewOption* pVOpt = pWrtShell->GetViewOptions(); SwViewOption aUsrPref(*pVOpt); - aUsrPref.SetKeepRatio(rBoolItem.GetValue()); - if (rBoolItem.GetValue() != pVOpt->IsKeepRatio()) + aUsrPref.SetKeepRatio(pBoolItem->GetValue()); + if (pBoolItem->GetValue() != pVOpt->IsKeepRatio()) { SW_MOD()->ApplyUsrPref(aUsrPref, &pWrtShell->GetView()); } @@ -917,10 +912,9 @@ void SwDocShell::Edit( rSet.Put(SvxPatternListItem(pDrawModel->GetPatternList(), SID_PATTERN_LIST)); std::optional<SfxGrabBagItem> oGrabBag; - SfxPoolItem const* pItem(nullptr); - if (SfxItemState::SET == rSet.GetItemState(SID_ATTR_CHAR_GRABBAG, true, &pItem)) + if (SfxGrabBagItem const* pItem = rSet.GetItemIfSet(SID_ATTR_CHAR_GRABBAG)) { - oGrabBag.emplace(*static_cast<SfxGrabBagItem const*>(pItem)); + oGrabBag.emplace(*pItem); } else { diff --git a/sw/source/uibase/app/docstyle.cxx b/sw/source/uibase/app/docstyle.cxx index 398f8775ba47..1eab72ad12a9 100644 --- a/sw/source/uibase/app/docstyle.cxx +++ b/sw/source/uibase/app/docstyle.cxx @@ -1484,16 +1484,12 @@ void SwDocStyleSheet::SetItemSet( const SfxItemSet& rSet, case SfxStyleFamily::Para : { OSL_ENSURE(m_pColl, "Where's Collection"); - const SfxPoolItem* pAutoUpdate; - if(SfxItemState::SET == rSet.GetItemState(SID_ATTR_AUTO_STYLE_UPDATE,false, &pAutoUpdate )) + if(const SfxBoolItem* pAutoUpdate = rSet.GetItemIfSet(SID_ATTR_AUTO_STYLE_UPDATE,false)) { - m_pColl->SetAutoUpdateFormat(static_cast<const SfxBoolItem*>(pAutoUpdate)->GetValue()); + m_pColl->SetAutoUpdateFormat(pAutoUpdate->GetValue()); } - const SwCondCollItem* pCondItem; - if( SfxItemState::SET != rSet.GetItemState( FN_COND_COLL, false, - reinterpret_cast<const SfxPoolItem**>(&pCondItem) )) - pCondItem = nullptr; + const SwCondCollItem* pCondItem = rSet.GetItemIfSet( FN_COND_COLL, false ); if( RES_CONDTXTFMTCOLL == m_pColl->Which() && pCondItem ) { @@ -1558,8 +1554,7 @@ void SwDocStyleSheet::SetItemSet( const SfxItemSet& rSet, // we have to create a physical instance of the numbering style. If we do not and // neither the paragraph style nor the numbering style is used in the document // the numbering style will not be saved with the document and the assignment got lost. - const SfxPoolItem* pNumRuleItem = nullptr; - if( SfxItemState::SET == rSet.GetItemState( RES_PARATR_NUMRULE, false, &pNumRuleItem ) ) + if( const SfxPoolItem* pNumRuleItem = rSet.GetItemIfSet( RES_PARATR_NUMRULE, false ) ) { // Setting a numbering rule? const OUString sNumRule = static_cast<const SwNumRuleItem*>(pNumRuleItem)->GetValue(); if (!sNumRule.isEmpty()) @@ -1608,8 +1603,8 @@ void SwDocStyleSheet::SetItemSet( const SfxItemSet& rSet, case SfxStyleFamily::Frame: { OSL_ENSURE(m_pFrameFormat, "Where's FrameFormat"); - const SfxPoolItem* pAutoUpdate; - if(SfxItemState::SET == rSet.GetItemState(SID_ATTR_AUTO_STYLE_UPDATE,false, &pAutoUpdate )) + + if(const SfxPoolItem* pAutoUpdate = rSet.GetItemIfSet(SID_ATTR_AUTO_STYLE_UPDATE,false)) { m_pFrameFormat->SetAutoUpdateFormat(static_cast<const SfxBoolItem*>(pAutoUpdate)->GetValue()); } diff --git a/sw/source/uibase/dialog/regionsw.cxx b/sw/source/uibase/dialog/regionsw.cxx index 73c7bd725dc4..dbc331c6ea88 100644 --- a/sw/source/uibase/dialog/regionsw.cxx +++ b/sw/source/uibase/dialog/regionsw.cxx @@ -68,12 +68,10 @@ void SwBaseShell::InsertRegionDialog(SfxRequest& rReq) } else { - const SfxPoolItem *pItem = nullptr; OUString aTmpStr; - if ( SfxItemState::SET == - pSet->GetItemState(FN_PARAM_REGION_NAME, true, &pItem) ) + if ( const SfxStringItem* pItem = pSet->GetItemIfSet(FN_PARAM_REGION_NAME) ) { - const OUString sRemoveWhenUniStringIsGone = static_cast<const SfxStringItem *>(pItem)->GetValue(); + const OUString sRemoveWhenUniStringIsGone = pItem->GetValue(); aTmpStr = rSh.GetUniqueSectionName(&sRemoveWhenUniStringIsGone); } else @@ -83,44 +81,47 @@ void SwBaseShell::InsertRegionDialog(SfxRequest& rReq) rReq.SetReturnValue(SfxStringItem(FN_INSERT_REGION, aTmpStr)); aSet.Put( *pSet ); - if(SfxItemState::SET == pSet->GetItemState(SID_ATTR_COLUMNS, false, &pItem)|| - SfxItemState::SET == pSet->GetItemState(FN_INSERT_REGION, false, &pItem)) + const SfxUInt16Item *pColRegionItem = nullptr; + if((pColRegionItem = pSet->GetItemIfSet(SID_ATTR_COLUMNS, false)) || + (pColRegionItem = pSet->GetItemIfSet(FN_INSERT_REGION, false))) { SwFormatCol aCol; SwRect aRect; rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR); tools::Long nWidth = aRect.Width(); - sal_uInt16 nCol = static_cast<const SfxUInt16Item *>(pItem)->GetValue(); + sal_uInt16 nCol = pColRegionItem->GetValue(); if(nCol) { aCol.Init( nCol, 0, static_cast< sal_uInt16 >(nWidth) ); aSet.Put(aCol); } } - else if(SfxItemState::SET == pSet->GetItemState(RES_COL, false, &pItem)) + else if(const SwFormatCol* pFormatCol = pSet->GetItemIfSet(RES_COL, false)) { - aSet.Put(*pItem); + aSet.Put(*pFormatCol); } - const bool bHidden = SfxItemState::SET == pSet->GetItemState(FN_PARAM_REGION_HIDDEN, true, &pItem) && - static_cast<const SfxBoolItem *>(pItem)->GetValue(); - const bool bProtect = SfxItemState::SET == pSet->GetItemState(FN_PARAM_REGION_PROTECT, true, &pItem) && - static_cast<const SfxBoolItem *>(pItem)->GetValue(); + const SfxBoolItem* pBoolItem; + const bool bHidden = (pBoolItem = pSet->GetItemIfSet(FN_PARAM_REGION_HIDDEN)) && + pBoolItem->GetValue(); + const bool bProtect = (pBoolItem = pSet->GetItemIfSet(FN_PARAM_REGION_PROTECT)) && + pBoolItem->GetValue(); // #114856# edit in readonly sections - const bool bEditInReadonly = SfxItemState::SET == pSet->GetItemState(FN_PARAM_REGION_EDIT_IN_READONLY, true, &pItem) && - static_cast<const SfxBoolItem *>(pItem)->GetValue(); + const bool bEditInReadonly = (pBoolItem = pSet->GetItemIfSet(FN_PARAM_REGION_EDIT_IN_READONLY)) && + pBoolItem->GetValue(); aSection.SetProtectFlag(bProtect); aSection.SetHidden(bHidden); // #114856# edit in readonly sections aSection.SetEditInReadonlyFlag(bEditInReadonly); - if(SfxItemState::SET == - pSet->GetItemState(FN_PARAM_REGION_CONDITION, true, &pItem)) - aSection.SetCondition(static_cast<const SfxStringItem *>(pItem)->GetValue()); + if(const SfxStringItem* pConditionItem = + pSet->GetItemIfSet(FN_PARAM_REGION_CONDITION)) + aSection.SetCondition(pConditionItem->GetValue()); OUString aFile, aSub; + const SfxPoolItem* pItem; if(SfxItemState::SET == pSet->GetItemState(FN_PARAM_1, true, &pItem)) aFile = static_cast<const SfxStringItem *>(pItem)->GetValue(); diff --git a/sw/source/uibase/docvw/HeaderFooterWin.cxx b/sw/source/uibase/docvw/HeaderFooterWin.cxx index dfec7984a52c..9a40c0fecd84 100644 --- a/sw/source/uibase/docvw/HeaderFooterWin.cxx +++ b/sw/source/uibase/docvw/HeaderFooterWin.cxx @@ -448,9 +448,8 @@ void SwHeaderFooterWin::ExecuteCommand(std::string_view rIdent) aSet.MergeRange(SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER); // Create a box info item... needed by the dialog std::shared_ptr<SvxBoxInfoItem> aBoxInfo(std::make_shared<SvxBoxInfoItem>(SID_ATTR_BORDER_INNER)); - const SfxPoolItem *pBoxInfo; - if (SfxItemState::SET == pHFFormat->GetAttrSet().GetItemState(SID_ATTR_BORDER_INNER, true, &pBoxInfo)) - aBoxInfo.reset(static_cast<SvxBoxInfoItem*>(pBoxInfo->Clone())); + if (const SvxBoxInfoItem *pBoxInfo = pHFFormat->GetAttrSet().GetItemIfSet(SID_ATTR_BORDER_INNER)) + aBoxInfo.reset(pBoxInfo->Clone()); aBoxInfo->SetTable(false); aBoxInfo->SetDist(true); diff --git a/sw/source/uibase/frmdlg/colex.cxx b/sw/source/uibase/frmdlg/colex.cxx index 0b11ab168ab4..8649a33e049d 100644 --- a/sw/source/uibase/frmdlg/colex.cxx +++ b/sw/source/uibase/frmdlg/colex.cxx @@ -171,13 +171,12 @@ void SwPageExample::UpdateExample( const SfxItemSet& rSet ) SetFooter( false ); } - if(SfxItemState::SET == rSet.GetItemState(RES_BACKGROUND, false, &pItem)) + if(const SvxBrushItem* pBrushItem = rSet.GetItemIfSet(RES_BACKGROUND, false)) { // create FillAttributes from SvxBrushItem - const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(*pItem); SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST> aTempSet(*rSet.GetPool()); - setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet); + setSvxBrushItemAsFillAttributesToTargetSet(*pBrushItem, aTempSet); setPageFillAttributes( std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>( aTempSet)); diff --git a/sw/source/uibase/frmdlg/frmmgr.cxx b/sw/source/uibase/frmdlg/frmmgr.cxx index 69065a7fb457..50ce75e7b7e0 100644 --- a/sw/source/uibase/frmdlg/frmmgr.cxx +++ b/sw/source/uibase/frmdlg/frmmgr.cxx @@ -142,10 +142,8 @@ void SwFlyFrameAttrMgr::UpdateAttrMgr() void SwFlyFrameAttrMgr::UpdateFlyFrame_() { - const SfxPoolItem* pItem = nullptr; - - if (m_aSet.GetItemState(FN_SET_FRM_NAME, false, &pItem) == SfxItemState::SET) - m_pOwnSh->SetFlyName(static_cast<const SfxStringItem *>(pItem)->GetValue()); + if (const SfxStringItem* pItem = m_aSet.GetItemIfSet(FN_SET_FRM_NAME, false)) + m_pOwnSh->SetFlyName(pItem->GetValue()); m_pOwnSh->SetModified(); @@ -166,14 +164,13 @@ void SwFlyFrameAttrMgr::UpdateFlyFrame() return; //JP 6.8.2001: set never an invalid anchor into the core. - const SfxPoolItem *pGItem, *pItem; - if( SfxItemState::SET == m_aSet.GetItemState( RES_ANCHOR, false, &pItem )) + const SwFormatAnchor *pGItem, *pItem; + if( (pItem = m_aSet.GetItemIfSet( RES_ANCHOR, false )) ) { SfxItemSetFixed<RES_ANCHOR, RES_ANCHOR> aGetSet( *m_aSet.GetPool() ); if( m_pOwnSh->GetFlyFrameAttr( aGetSet ) && 1 == aGetSet.Count() && - SfxItemState::SET == aGetSet.GetItemState( RES_ANCHOR, false, &pGItem ) - && static_cast<const SwFormatAnchor*>(pGItem)->GetAnchorId() == - static_cast<const SwFormatAnchor*>(pItem)->GetAnchorId() ) + (pGItem = aGetSet.GetItemIfSet( RES_ANCHOR, false )) + && pGItem->GetAnchorId() == pItem->GetAnchorId() ) m_aSet.ClearItem( RES_ANCHOR ); } diff --git a/sw/source/uibase/shells/annotsh.cxx b/sw/source/uibase/shells/annotsh.cxx index 21b249fb00d2..ce410ba0e3a9 100644 --- a/sw/source/uibase/shells/annotsh.cxx +++ b/sw/source/uibase/shells/annotsh.cxx @@ -559,8 +559,8 @@ void SwAnnotationShell::Exec( SfxRequest &rReq ) aAttr( *aNewAttr.GetPool() ); SvxAdjust nAdjust = SvxAdjust::Left; - if( SfxItemState::SET == aEditAttr.GetItemState(EE_PARA_JUST, true, &pPoolItem ) ) - nAdjust = static_cast<const SvxAdjustItem*>(pPoolItem)->GetAdjust(); + if( const SvxAdjustItem* pAdjustItem = aEditAttr.GetItemIfSet(EE_PARA_JUST ) ) + nAdjust = pAdjustItem->GetAdjust(); if( bLeftToRight ) { @@ -747,8 +747,7 @@ void SwAnnotationShell::GetState(SfxItemSet& rSet) else if (nWhich==SID_ATTR_PARA_ADJUST_BLOCK) eAdjust = SvxAdjust::Block; - const SfxPoolItem *pAdjust = nullptr; - aEditAttr.GetItemState( EE_PARA_JUST, false, &pAdjust); + const SvxAdjustItem *pAdjust = aEditAttr.GetItemIfSet( EE_PARA_JUST, false ); if( !pAdjust || IsInvalidItem( pAdjust )) { @@ -756,7 +755,7 @@ void SwAnnotationShell::GetState(SfxItemSet& rSet) } else { - if ( eAdjust == static_cast<const SvxAdjustItem*>(pAdjust)->GetAdjust()) + if ( eAdjust == pAdjust->GetAdjust()) rSet.Put( SfxBoolItem( nWhich, true )); else rSet.InvalidateItem( nWhich ); @@ -778,8 +777,7 @@ void SwAnnotationShell::GetState(SfxItemSet& rSet) else if (nWhich==SID_ATTR_PARA_LINESPACE_20) nLSpace = 200; - const SfxPoolItem *pLSpace = nullptr; - aEditAttr.GetItemState( EE_PARA_SBL, false, &pLSpace ); + const SvxLineSpacingItem *pLSpace = aEditAttr.GetItemIfSet( EE_PARA_SBL, false ); if( !pLSpace || IsInvalidItem( pLSpace )) { @@ -787,7 +785,7 @@ void SwAnnotationShell::GetState(SfxItemSet& rSet) } else { - if( nLSpace == static_cast<const SvxLineSpacingItem*>(pLSpace)->GetPropLineSpace() ) + if( nLSpace == pLSpace->GetPropLineSpace() ) rSet.Put( SfxBoolItem( nWhich, true )); else { @@ -1733,19 +1731,17 @@ void SwAnnotationShell::InsertSymbol(SfxRequest& rReq) OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView(); const SfxItemSet *pArgs = rReq.GetArgs(); - const SfxPoolItem* pItem = nullptr; + const SfxStringItem* pCharMapItem = nullptr; if( pArgs ) - pArgs->GetItemState(SID_CHARMAP, false, &pItem); + pCharMapItem = pArgs->GetItemIfSet(SID_CHARMAP, false); OUString sSym; OUString sFontName; - if ( pItem ) + if ( pCharMapItem ) { - sSym = static_cast<const SfxStringItem*>(pItem)->GetValue(); - const SfxPoolItem* pFtItem = nullptr; - pArgs->GetItemState( SID_ATTR_SPECIALCHAR, false, &pFtItem); - - if (const SfxStringItem* pFontItem = dynamic_cast<const SfxStringItem*>(pFtItem)) + sSym = pCharMapItem->GetValue(); + const SfxStringItem* pFontItem = pArgs->GetItemIfSet( SID_ATTR_SPECIALCHAR, false); + if (pFontItem) sFontName = pFontItem->GetValue(); } diff --git a/sw/source/uibase/shells/basesh.cxx b/sw/source/uibase/shells/basesh.cxx index 70dd94f905f4..cca3bf5cc432 100644 --- a/sw/source/uibase/shells/basesh.cxx +++ b/sw/source/uibase/shells/basesh.cxx @@ -600,8 +600,9 @@ void SwBaseShell::ExecUndo(SfxRequest &rReq) // Repair mode: allow undo/redo of all undo actions, even if access would // be limited based on the view shell ID. bool bRepair = false; - if (pArgs && pArgs->GetItemState(SID_REPAIRPACKAGE, false, &pItem) == SfxItemState::SET) - bRepair = static_cast<const SfxBoolItem*>(pItem)->GetValue(); + const SfxBoolItem* pRepairItem; + if (pArgs && (pRepairItem = pArgs->GetItemIfSet(SID_REPAIRPACKAGE, false))) + bRepair = pRepairItem->GetValue(); // #i106349#: save pointer: undo/redo may delete the shell, i.e., this! SfxViewFrame *const pViewFrame( GetView().GetViewFrame() ); diff --git a/sw/source/uibase/shells/drawdlg.cxx b/sw/source/uibase/shells/drawdlg.cxx index c3ab179a1bf2..55de755ef81a 100644 --- a/sw/source/uibase/shells/drawdlg.cxx +++ b/sw/source/uibase/shells/drawdlg.cxx @@ -251,9 +251,9 @@ namespace } } } - else if (SfxItemState::SET == pArgs->GetItemState(SID_ATTR_LINE_WIDTH_ARG, false, &pItem)) + else if (const SvxDoubleItem* pWidthItem = pArgs->GetItemIfSet(SID_ATTR_LINE_WIDTH_ARG, false)) { - double fValue = static_cast<const SvxDoubleItem*>(pItem)->GetValue(); + double fValue = pWidthItem->GetValue(); // FIXME: different units... int nPow = 100; int nValue = fValue * nPow; @@ -261,15 +261,11 @@ namespace XLineWidthItem aItem(nValue); pArgs->Put(aItem); } - if (SfxItemState::SET == pArgs->GetItemState(SID_FILL_GRADIENT_JSON, false, &pItem)) + if (const SfxStringItem* pJSON = pArgs->GetItemIfSet(SID_FILL_GRADIENT_JSON, false)) { - const SfxStringItem* pJSON = static_cast<const SfxStringItem*>(pItem); - if (pJSON) - { - XGradient aGradient = XGradient::fromJSON(pJSON->GetValue()); - XFillGradientItem aItem(aGradient); - pArgs->Put(aItem); - } + XGradient aGradient = XGradient::fromJSON(pJSON->GetValue()); + XFillGradientItem aItem(aGradient); + pArgs->Put(aItem); } } } diff --git a/sw/source/uibase/shells/drwbassh.cxx b/sw/source/uibase/shells/drwbassh.cxx index 0665ca4a0c3f..a8477ad3a09c 100644 --- a/sw/source/uibase/shells/drwbassh.cxx +++ b/sw/source/uibase/shells/drwbassh.cxx @@ -145,11 +145,10 @@ void SwDrawBaseShell::Execute(SfxRequest const &rReq) if (pDlg->Execute() == RET_OK) { - const SfxPoolItem* pWrapItem; const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); - if(SfxItemState::SET == pOutSet->GetItemState(FN_DRAW_WRAP_DLG, false, &pWrapItem)) + if(const SfxInt16Item* pWrapItem = pOutSet->GetItemIfSet(FN_DRAW_WRAP_DLG, false)) { - short nLayer = static_cast<const SfxInt16Item*>(pWrapItem)->GetValue(); + short nLayer = pWrapItem->GetValue(); if (nLayer == 1) pSh->SelectionToHeaven(); else @@ -272,63 +271,58 @@ void SwDrawBaseShell::Execute(SfxRequest const &rReq) bool bSingleSelection = rMarkList.GetMarkCount() == 1; - const SfxPoolItem* pAnchorItem; - if(SfxItemState::SET == pOutSet->GetItemState( - SID_ATTR_TRANSFORM_ANCHOR, false, &pAnchorItem)) + if(const SfxInt16Item* pAnchorItem = pOutSet->GetItemIfSet( + SID_ATTR_TRANSFORM_ANCHOR, false)) { if(!bSingleSelection) - pSh->ChgAnchor(static_cast<RndStdIds>(static_cast<const SfxInt16Item*>(pAnchorItem) + pSh->ChgAnchor(static_cast<RndStdIds>(pAnchorItem ->GetValue()), false, bPosCorr ); else { SwFormatAnchor aAnchor(pFrameFormat->GetAnchor()); - aAnchor.SetType(static_cast<RndStdIds>(static_cast<const SfxInt16Item*>(pAnchorItem)->GetValue())); + aAnchor.SetType(static_cast<RndStdIds>(pAnchorItem->GetValue())); aFrameAttrSet.Put( aAnchor ); } } - const SfxPoolItem* pHoriOrient = nullptr; - const SfxPoolItem* pHoriRelation = nullptr; - const SfxPoolItem* pHoriPosition = nullptr; - const SfxPoolItem* pHoriMirror = nullptr; - pOutSet->GetItemState(SID_ATTR_TRANSFORM_HORI_ORIENT, false, &pHoriOrient); - pOutSet->GetItemState(SID_ATTR_TRANSFORM_HORI_RELATION, false, &pHoriRelation); - pOutSet->GetItemState(SID_ATTR_TRANSFORM_HORI_POSITION, false, &pHoriPosition); - pOutSet->GetItemState(SID_ATTR_TRANSFORM_HORI_MIRROR, false, &pHoriMirror); + const SfxInt16Item* pHoriOrient = + pOutSet->GetItemIfSet(SID_ATTR_TRANSFORM_HORI_ORIENT, false); + const SfxInt16Item* pHoriRelation = + pOutSet->GetItemIfSet(SID_ATTR_TRANSFORM_HORI_RELATION, false); + const SfxInt32Item* pHoriPosition = + pOutSet->GetItemIfSet(SID_ATTR_TRANSFORM_HORI_POSITION, false); + const SfxBoolItem* pHoriMirror = + pOutSet->GetItemIfSet(SID_ATTR_TRANSFORM_HORI_MIRROR, false); if(pHoriOrient || pHoriRelation || pHoriPosition || pHoriMirror) { if(pHoriOrient) - aHOrientFinal.SetHoriOrient( - static_cast<const SfxInt16Item*>(pHoriOrient)->GetValue()); + aHOrientFinal.SetHoriOrient(pHoriOrient->GetValue()); if(pHoriRelation) - aHOrientFinal.SetRelationOrient( - static_cast<const SfxInt16Item*>(pHoriRelation)->GetValue()); + aHOrientFinal.SetRelationOrient(pHoriRelation->GetValue()); if(pHoriPosition) - aHOrientFinal.SetPos( static_cast<const SfxInt32Item*>(pHoriPosition)->GetValue()); + aHOrientFinal.SetPos( pHoriPosition->GetValue()); if(pHoriMirror) - aHOrientFinal.SetPosToggle( static_cast<const SfxBoolItem*>(pHoriMirror)->GetValue()); + aHOrientFinal.SetPosToggle( pHoriMirror->GetValue()); aFrameAttrSet.Put(aHOrientFinal); } - const SfxPoolItem* pVertOrient = nullptr; - const SfxPoolItem* pVertRelation = nullptr; - const SfxPoolItem* pVertPosition = nullptr; - pOutSet->GetItemState(SID_ATTR_TRANSFORM_VERT_ORIENT, false, &pVertOrient); - pOutSet->GetItemState(SID_ATTR_TRANSFORM_VERT_RELATION, false, &pVertRelation); - pOutSet->GetItemState(SID_ATTR_TRANSFORM_VERT_POSITION, false, &pVertPosition); + const SfxInt16Item* pVertOrient = + pOutSet->GetItemIfSet(SID_ATTR_TRANSFORM_VERT_ORIENT, false); + const SfxInt16Item* pVertRelation = + pOutSet->GetItemIfSet(SID_ATTR_TRANSFORM_VERT_RELATION, false); + const SfxInt32Item* pVertPosition = + pOutSet->GetItemIfSet(SID_ATTR_TRANSFORM_VERT_POSITION, false); if(pVertOrient || pVertRelation || pVertPosition ) { if(pVertOrient) - aVOrientFinal.SetVertOrient( - static_cast<const SfxInt16Item*>(pVertOrient)->GetValue()); + aVOrientFinal.SetVertOrient(pVertOrient->GetValue()); if(pVertRelation) - aVOrientFinal.SetRelationOrient( - static_cast<const SfxInt16Item*>(pVertRelation)->GetValue()); + aVOrientFinal.SetRelationOrient(pVertRelation->GetValue()); if(pVertPosition) - aVOrientFinal.SetPos( static_cast<const SfxInt32Item*>(pVertPosition)->GetValue()); + aVOrientFinal.SetPos( pVertPosition->GetValue()); aFrameAttrSet.Put( aVOrientFinal ); } - const SfxPoolItem* pFollowItem = nullptr; - pOutSet->GetItemState(RES_FOLLOW_TEXT_FLOW, false, &pFollowItem); + const SwFormatFollowTextFlow* pFollowItem = + pOutSet->GetItemIfSet(RES_FOLLOW_TEXT_FLOW, false); if(pFollowItem) aFrameAttrSet.Put(*pFollowItem); diff --git a/sw/source/uibase/shells/drwtxtex.cxx b/sw/source/uibase/shells/drwtxtex.cxx index 01ba8b743c63..101e970ad2cb 100644 --- a/sw/source/uibase/shells/drwtxtex.cxx +++ b/sw/source/uibase/shells/drwtxtex.cxx @@ -89,12 +89,11 @@ namespace { Color aColor; OUString sColor; - const SfxPoolItem* pItem = nullptr; - - if (SfxItemState::SET != rArgs.GetItemState(SID_ATTR_COLOR_STR, false, &pItem)) + const SfxStringItem* pItem = rArgs.GetItemIfSet(SID_ATTR_COLOR_STR, false); + if (!pItem) return; - sColor = static_cast<const SfxStringItem*>(pItem)->GetValue(); + sColor = pItem->GetValue(); if (sColor == "transparent") aColor = COL_TRANSPARENT; @@ -604,8 +603,8 @@ void SwDrawTextShell::Execute( SfxRequest &rReq ) EE_PARA_JUST, EE_PARA_JUST> aAttr( *aNewAttr.GetPool() ); SvxAdjust nAdjust = SvxAdjust::Left; - if( SfxItemState::SET == aEditAttr.GetItemState(EE_PARA_JUST, true, &pPoolItem ) ) - nAdjust = static_cast<const SvxAdjustItem*>(pPoolItem)->GetAdjust(); + if( const SvxAdjustItem* pAdjustItem = aEditAttr.GetItemIfSet(EE_PARA_JUST) ) + nAdjust = pAdjustItem->GetAdjust(); if( bLeftToRight ) { @@ -679,7 +678,9 @@ void SwDrawTextShell::GetState(SfxItemSet& rSet) sal_uInt16 nWhich = aIter.FirstWhich(); SfxItemSet aEditAttr(pOLV->GetAttribs()); - const SfxPoolItem *pAdjust = nullptr, *pLSpace = nullptr, *pEscItem = nullptr; + const SvxAdjustItem *pAdjust = nullptr; + const SvxLineSpacingItem *pLSpace = nullptr; + const SfxPoolItem *pEscItem = nullptr; SvxAdjust eAdjust; int nLSpace; SvxEscapement nEsc; @@ -731,7 +732,7 @@ void SwDrawTextShell::GetState(SfxItemSet& rSet) ASK_ADJUST: { if (!pAdjust) - aEditAttr.GetItemState(EE_PARA_JUST, false, &pAdjust); + pAdjust = aEditAttr.GetItemIfSet(EE_PARA_JUST, false); if (!pAdjust || IsInvalidItem(pAdjust)) { @@ -739,7 +740,7 @@ void SwDrawTextShell::GetState(SfxItemSet& rSet) nSlotId = 0; } else - bFlag = eAdjust == static_cast<const SvxAdjustItem*>(pAdjust)->GetAdjust(); + bFlag = eAdjust == pAdjust->GetAdjust(); } break; @@ -821,7 +822,7 @@ void SwDrawTextShell::GetState(SfxItemSet& rSet) ASK_LINESPACE: { if (!pLSpace) - aEditAttr.GetItemState(EE_PARA_SBL, false, &pLSpace); + pLSpace = aEditAttr.GetItemIfSet(EE_PARA_SBL, false); if (!pLSpace || IsInvalidItem(pLSpace)) { @@ -829,7 +830,7 @@ void SwDrawTextShell::GetState(SfxItemSet& rSet) nSlotId = 0; } else if (nLSpace - == static_cast<const SvxLineSpacingItem*>(pLSpace)->GetPropLineSpace()) + == pLSpace->GetPropLineSpace()) bFlag = true; else { diff --git a/sw/source/uibase/shells/drwtxtsh.cxx b/sw/source/uibase/shells/drwtxtsh.cxx index 2416c3a4863c..776cd31c01da 100644 --- a/sw/source/uibase/shells/drwtxtsh.cxx +++ b/sw/source/uibase/shells/drwtxtsh.cxx @@ -675,18 +675,16 @@ void SwDrawTextShell::InsertSymbol(SfxRequest& rReq) if(!pOLV) return; const SfxItemSet *pArgs = rReq.GetArgs(); - const SfxPoolItem* pItem = nullptr; + const SfxStringItem* pItem = nullptr; if( pArgs ) - pArgs->GetItemState(SID_CHARMAP, false, &pItem); + pItem = pArgs->GetItemIfSet(SID_CHARMAP, false); OUString sSym; OUString sFontName; if ( pItem ) { - sSym = static_cast<const SfxStringItem*>(pItem)->GetValue(); - const SfxPoolItem* pFtItem = nullptr; - pArgs->GetItemState( SID_ATTR_SPECIALCHAR, false, &pFtItem); - const SfxStringItem* pFontItem = dynamic_cast<const SfxStringItem*>( pFtItem ); + sSym = pItem->GetValue(); + const SfxStringItem* pFontItem = pArgs->GetItemIfSet( SID_ATTR_SPECIALCHAR, false); if ( pFontItem ) sFontName = pFontItem->GetValue(); } diff --git a/sw/source/uibase/shells/frmsh.cxx b/sw/source/uibase/shells/frmsh.cxx index 997e40a07da5..2cea80a45f68 100644 --- a/sw/source/uibase/shells/frmsh.cxx +++ b/sw/source/uibase/shells/frmsh.cxx @@ -177,8 +177,8 @@ void SwFrameShell::Execute(SfxRequest &rReq) { // Frame already exists, only the number of columns will be changed. sal_uInt16 nCols = 1; - if(pArgs->GetItemState(SID_ATTR_COLUMNS, false, &pItem) == SfxItemState::SET) - nCols = static_cast<const SfxUInt16Item *>(pItem)->GetValue(); + if(const SfxUInt16Item* pColsItem = pArgs->GetItemIfSet(SID_ATTR_COLUMNS, false)) + nCols = pColsItem->GetValue(); SfxItemSetFixed<RES_COL,RES_COL> aSet(GetPool()); rSh.GetFlyFrameAttr( aSet ); @@ -363,32 +363,33 @@ void SwFrameShell::Execute(SfxRequest &rReq) bool bApplyNewSize = false; Point aNewPos = aMgr.GetPos(); - if (pArgs && - SfxItemState::SET == pArgs->GetItemState(SID_ATTR_TRANSFORM_POS_X, false, &pItem)) + if (pArgs) { - aNewPos.setX( static_cast<const SfxInt32Item*>(pItem)->GetValue() ); - bApplyNewPos = true; - } - if (pArgs && - SfxItemState::SET == pArgs->GetItemState(SID_ATTR_TRANSFORM_POS_Y, false, &pItem)) - { - aNewPos.setY( static_cast<const SfxInt32Item*>(pItem)->GetValue() ); - bApplyNewPos = true; + if (const SfxInt32Item* pXItem = pArgs->GetItemIfSet(SID_ATTR_TRANSFORM_POS_X, false)) + { + aNewPos.setX( pXItem->GetValue() ); + bApplyNewPos = true; + } + if (const SfxInt32Item* pYItem = pArgs->GetItemIfSet(SID_ATTR_TRANSFORM_POS_Y, false)) + { + aNewPos.setY( pYItem->GetValue() ); + bApplyNewPos = true; + } } Size aNewSize = aMgr.GetSize(); - if (pArgs && - SfxItemState::SET == pArgs->GetItemState(SID_ATTR_TRANSFORM_WIDTH, false, &pItem)) - { - aNewSize.setWidth( static_cast< const SfxUInt32Item* >(pItem)->GetValue() ); - bApplyNewSize = true; - } - - if (pArgs && - SfxItemState::SET == pArgs->GetItemState(SID_ATTR_TRANSFORM_HEIGHT, false, &pItem)) + if (pArgs) { - aNewSize.setHeight( static_cast< const SfxUInt32Item* >(pItem)->GetValue() ); - bApplyNewSize = true; + if (const SfxUInt32Item* pWidthItem = pArgs->GetItemIfSet(SID_ATTR_TRANSFORM_WIDTH, false)) + { + aNewSize.setWidth( pWidthItem->GetValue() ); + bApplyNewSize = true; + } + if (const SfxUInt32Item* pHeightItem = pArgs->GetItemIfSet(SID_ATTR_TRANSFORM_HEIGHT, false)) + { + aNewSize.setHeight( pHeightItem->GetValue() ); + bApplyNewSize = true; + } } if (pArgs && (pArgs->HasItem(SID_ATTR_TRANSFORM_ANGLE) || pArgs->HasItem(SID_ATTR_TRANSFORM_DELTA_ANGLE))) @@ -398,9 +399,9 @@ void SwFrameShell::Execute(SfxRequest &rReq) const SwRotationGrf& rRotation = aSet.Get(RES_GRFATR_ROTATION); const Degree10 nOldRot(rRotation.GetValue()); - if (pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_TRANSFORM_DELTA_ANGLE, false, &pItem)) + if (const SdrAngleItem* pAngleItem = pArgs->GetItemIfSet(SID_ATTR_TRANSFORM_DELTA_ANGLE, false)) { - const Degree10 nDeltaRot = to<Degree10>(static_cast<const SdrAngleItem*>(pItem)->GetValue()); + const Degree10 nDeltaRot = to<Degree10>(pAngleItem->GetValue()); aMgr.SetRotation(nOldRot, nOldRot + nDeltaRot, rRotation.GetUnrotatedSize()); } @@ -408,9 +409,9 @@ void SwFrameShell::Execute(SfxRequest &rReq) // value setter uses SID_ATTR_TRANSFORM and a group of three values. Rotation is // added now, so use it in this central place. Do no forget to convert angle from // 100th degrees in SID_ATTR_TRANSFORM_ANGLE to 10th degrees in RES_GRFATR_ROTATION - if (pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_TRANSFORM_ANGLE, false, &pItem)) + if (const SdrAngleItem* pTransformItem = pArgs->GetItemIfSet(SID_ATTR_TRANSFORM_ANGLE, false)) { - const Degree10 nNewRot = to<Degree10>(static_cast<const SdrAngleItem*>(pItem)->GetValue()); + const Degree10 nNewRot = to<Degree10>(pTransformItem->GetValue()); // RotGrfFlyFrame: Rotation change here, SwFlyFrameAttrMgr aMgr is available aMgr.SetRotation(nOldRot, nNewRot, rRotation.GetUnrotatedSize()); @@ -509,8 +510,9 @@ void SwFrameShell::Execute(SfxRequest &rReq) aSet.Put( SfxBoolItem( FN_OLE_IS_MATH, xObj.is() && SotExchange::IsMath( xObj->getClassID() ) ) ); OString sDefPage; - if(pArgs && pArgs->GetItemState(FN_FORMAT_FRAME_DLG, false, &pItem) == SfxItemState::SET) - sDefPage = OUStringToOString(static_cast<const SfxStringItem *>(pItem)->GetValue(), RTL_TEXTENCODING_UTF8); + const SfxStringItem* pDlgItem; + if(pArgs && (pDlgItem = pArgs->GetItemIfSet(FN_FORMAT_FRAME_DLG, false))) + sDefPage = OUStringToOString(pDlgItem->GetValue(), RTL_TEXTENCODING_UTF8); aSet.Put(SfxFrameItem( SID_DOCFRAME, &GetView().GetViewFrame()->GetFrame())); FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebView*>( &GetView()) != nullptr ); @@ -537,20 +539,21 @@ void SwFrameShell::Execute(SfxRequest &rReq) if(pOutSet) { rReq.Done(*pOutSet); + const SfxBoolItem* pRatioItem = nullptr; if(nSel & SelectionType::Ole && - SfxItemState::SET == pOutSet->GetItemState(FN_KEEP_ASPECT_RATIO, true, &pItem)) + (pRatioItem = pOutSet->GetItemIfSet(FN_KEEP_ASPECT_RATIO))) { SwViewOption aUsrPref( *pVOpt ); - aUsrPref.SetKeepRatio(static_cast<const SfxBoolItem*>(pItem)->GetValue()); + aUsrPref.SetKeepRatio(pRatioItem->GetValue()); SW_MOD()->ApplyUsrPref(aUsrPref, &GetView()); } - if (SfxItemState::SET == pOutSet->GetItemState(FN_SET_FRM_ALT_NAME, true, &pItem)) + if (const SfxStringItem* pAltNameItem = pOutSet->GetItemIfSet(FN_SET_FRM_ALT_NAME)) { // #i73249# - rSh.SetObjTitle(static_cast<const SfxStringItem*>(pItem)->GetValue()); + rSh.SetObjTitle(pAltNameItem->GetValue()); } - if (SfxItemState::SET == pOutSet->GetItemState(FN_UNO_DESCRIPTION, true, &pItem)) - rSh.SetObjDescription(static_cast<const SfxStringItem*>(pItem)->GetValue()); + if (const SfxStringItem* pDescripItem = pOutSet->GetItemIfSet(FN_UNO_DESCRIPTION)) + rSh.SetObjDescription(pDescripItem->GetValue()); // Template AutoUpdate SwFrameFormat* pFormat = rSh.GetSelectedFrameFormat(); @@ -558,28 +561,26 @@ void SwFrameShell::Execute(SfxRequest &rReq) { rSh.AutoUpdateFrame(pFormat, *pOutSet); // Anything which is not supported by the format must be set hard. - if(SfxItemState::SET == pOutSet->GetItemState(FN_SET_FRM_NAME, false, &pItem)) - rSh.SetFlyName(static_cast<const SfxStringItem*>(pItem)->GetValue()); + if(const SfxStringItem* pFrameName = pOutSet->GetItemIfSet(FN_SET_FRM_NAME, false)) + rSh.SetFlyName(pFrameName->GetValue()); SfxItemSetFixed< RES_FRM_SIZE, RES_FRM_SIZE, RES_SURROUND, RES_ANCHOR> aShellSet( GetPool() ); aShellSet.Put(*pOutSet); aMgr.SetAttrSet(aShellSet); - if(SfxItemState::SET == pOutSet->GetItemState(FN_SET_FRM_NAME, false, &pItem)) - rSh.SetFlyName(static_cast<const SfxStringItem*>(pItem)->GetValue()); + if(const SfxStringItem* pFrameName = pOutSet->GetItemIfSet(FN_SET_FRM_NAME, false)) + rSh.SetFlyName(pFrameName->GetValue()); } else aMgr.SetAttrSet( *pOutSet ); const SwFrameFormat* pCurrFlyFormat = rSh.GetFlyFrameFormat(); - if(SfxItemState::SET == - pOutSet->GetItemState(FN_PARAM_CHAIN_PREVIOUS, - false, &pItem)) + if(const SfxStringItem* pPreviousItem = + pOutSet->GetItemIfSet(FN_PARAM_CHAIN_PREVIOUS, false)) { rSh.HideChainMarker(); - OUString sPrevName = - static_cast<const SfxStringItem*>(pItem)->GetValue(); + OUString sPrevName = pPreviousItem->GetValue(); const SwFormatChain &rChain = pCurrFlyFormat->GetChain(); //needs cast - no non-const method available SwFlyFrameFormat* pFlyFormat = @@ -607,13 +608,11 @@ void SwFrameShell::Execute(SfxRequest &rReq) } rSh.SetChainMarker(); } - if(SfxItemState::SET == - pOutSet->GetItemState(FN_PARAM_CHAIN_NEXT, false, - &pItem)) + if(const SfxStringItem* pChainNextItem = + pOutSet->GetItemIfSet(FN_PARAM_CHAIN_NEXT, false)) { rSh.HideChainMarker(); - OUString sNextName = - static_cast<const SfxStringItem*>(pItem)->GetValue(); + OUString sNextName = pChainNextItem->GetValue(); const SwFormatChain &rChain = pCurrFlyFormat->GetChain(); //needs cast - no non-const method available SwFlyFrameFormat* pFlyFormat = @@ -912,14 +911,12 @@ void SwFrameShell::GetState(SfxItemSet& rSet) case SID_HYPERLINK_GETLINK: { SvxHyperlinkItem aHLinkItem; - const SfxPoolItem* pItem; SfxItemSetFixed<RES_URL, RES_URL> aURLSet(GetPool()); rSh.GetFlyFrameAttr( aURLSet ); - if(SfxItemState::SET == aURLSet.GetItemState(RES_URL, true, &pItem)) + if(const SwFormatURL* pFormatURL = aURLSet.GetItemIfSet(RES_URL)) { - const SwFormatURL* pFormatURL = static_cast<const SwFormatURL*>(pItem); aHLinkItem.SetURL(pFormatURL->GetURL()); aHLinkItem.SetTargetFrame(pFormatURL->GetTargetFrameName()); aHLinkItem.SetName(rSh.GetFlyName()); @@ -1099,7 +1096,6 @@ void SwFrameShell::ExecFrameStyle(SfxRequest const & rReq) std::unique_ptr<SvxBoxItem> aBoxItem(rBoxItem.Clone()); SvxBorderLine aBorderLine; - const SfxPoolItem *pItem = nullptr; if(pArgs) // Any controller can sometimes deliver nothing #48169# { @@ -1107,9 +1103,9 @@ void SwFrameShell::ExecFrameStyle(SfxRequest const & rReq) { case SID_ATTR_BORDER: { - if (pArgs->GetItemState(RES_BOX, true, &pItem) == SfxItemState::SET) + if (const SvxBoxItem* pBoxItem = pArgs->GetItemIfSet(RES_BOX)) { - std::unique_ptr<SvxBoxItem> aNewBox(static_cast<SvxBoxItem*>(pItem->Clone())); + std::unique_ptr<SvxBoxItem> aNewBox(pBoxItem->Clone()); const SvxBorderLine* pBorderLine; pBorderLine = aBoxItem->GetTop(); @@ -1157,11 +1153,8 @@ void SwFrameShell::ExecFrameStyle(SfxRequest const & rReq) case SID_FRAME_LINESTYLE: { - if (pArgs->GetItemState(SID_FRAME_LINESTYLE, false, &pItem) == SfxItemState::SET) + if ( const SvxLineItem* pLineItem = pArgs->GetItemIfSet(SID_FRAME_LINESTYLE, false)) { - const SvxLineItem* pLineItem = - static_cast<const SvxLineItem*>(pItem); - if ( pLineItem->GetLine() ) { aBorderLine = *(pLineItem->GetLine()); @@ -1211,9 +1204,9 @@ void SwFrameShell::ExecFrameStyle(SfxRequest const & rReq) case SID_FRAME_LINECOLOR: { - if (pArgs->GetItemState(SID_FRAME_LINECOLOR, false, &pItem) == SfxItemState::SET) + if (const SvxColorItem* pColorItem = pArgs->GetItemIfSet(SID_FRAME_LINECOLOR, false)) { - const Color& rNewColor = static_cast<const SvxColorItem*>(pItem)->GetValue(); + const Color& rNewColor = pColorItem->GetValue(); if (!aBoxItem->GetTop() && !aBoxItem->GetBottom() && !aBoxItem->GetLeft() && !aBoxItem->GetRight()) diff --git a/sw/source/uibase/shells/grfsh.cxx b/sw/source/uibase/shells/grfsh.cxx index 06e4049cd87c..bb60338f1ce0 100644 --- a/sw/source/uibase/shells/grfsh.cxx +++ b/sw/source/uibase/shells/grfsh.cxx @@ -406,22 +406,21 @@ void SwGrfShell::Execute(SfxRequest &rReq) { rSh.StartAllAction(); rSh.StartUndo(SwUndoId::START); - const SfxPoolItem* pItem; SfxItemSet* pSet = const_cast<SfxItemSet*>(pDlg->GetOutputItemSet()); rReq.Done(*pSet); // change the 2 frmsize SizeItems to the correct SwFrameSizeItem - if( SfxItemState::SET == pSet->GetItemState( - SID_ATTR_GRAF_FRMSIZE, false, &pItem )) + if( const SvxSizeItem* pSizeItem = pSet->GetItemIfSet( + SID_ATTR_GRAF_FRMSIZE, false )) { SwFormatFrameSize aSize; - const Size& rSz = static_cast<const SvxSizeItem*>(pItem)->GetSize(); + const Size& rSz = pSizeItem->GetSize(); aSize.SetWidth( rSz.Width() ); aSize.SetHeight( rSz.Height() ); - if( SfxItemState::SET == pSet->GetItemState( - SID_ATTR_GRAF_FRMSIZE_PERCENT, false, &pItem )) + pSizeItem = pSet->GetItemIfSet( SID_ATTR_GRAF_FRMSIZE_PERCENT, false ); + if( pSizeItem ) { - const Size& rRelativeSize = static_cast<const SvxSizeItem*>(pItem)->GetSize(); + const Size& rRelativeSize = pSizeItem->GetSize(); aSize.SetWidthPercent( static_cast< sal_uInt8 >( rRelativeSize.Width() ) ); aSize.SetHeightPercent( static_cast< sal_uInt8 >( rRelativeSize.Height() ) ); } @@ -446,18 +445,16 @@ void SwGrfShell::Execute(SfxRequest &rReq) aMgr.UpdateFlyFrame(); bool bApplyUsrPref = false; - if (SfxItemState::SET == pSet->GetItemState( - FN_KEEP_ASPECT_RATIO, true, &pItem )) + if (const SfxBoolItem* pRatioItem = pSet->GetItemIfSet( + FN_KEEP_ASPECT_RATIO )) { - aUsrPref.SetKeepRatio( - static_cast<const SfxBoolItem*>(pItem)->GetValue() ); + aUsrPref.SetKeepRatio( pRatioItem->GetValue() ); bApplyUsrPref = true; } - if( SfxItemState::SET == pSet->GetItemState( - SID_ATTR_GRAF_KEEP_ZOOM, true, &pItem )) + if( const SfxBoolItem* pZoomItem = pSet->GetItemIfSet( + SID_ATTR_GRAF_KEEP_ZOOM )) { - aUsrPref.SetGrfKeepZoom( - static_cast<const SfxBoolItem*>(pItem)->GetValue() ); + aUsrPref.SetGrfKeepZoom( pZoomItem->GetValue() ); bApplyUsrPref = true; } @@ -465,16 +462,16 @@ void SwGrfShell::Execute(SfxRequest &rReq) SW_MOD()->ApplyUsrPref(aUsrPref, &GetView()); // and now set all the graphic attributes and other stuff - if( SfxItemState::SET == pSet->GetItemState( - SID_ATTR_GRAF_GRAPHIC, true, &pItem )) + if( const SvxBrushItem* pGraphicBrushItem = pSet->GetItemIfSet( + SID_ATTR_GRAF_GRAPHIC )) { - if( !static_cast<const SvxBrushItem*>(pItem)->GetGraphicLink().isEmpty() ) - sGrfNm = static_cast<const SvxBrushItem*>(pItem)->GetGraphicLink(); + if( !pGraphicBrushItem->GetGraphicLink().isEmpty() ) + sGrfNm = pGraphicBrushItem->GetGraphicLink(); else sGrfNm.clear(); - if( !static_cast<const SvxBrushItem*>(pItem)->GetGraphicFilter().isEmpty() ) - sFilterNm = static_cast<const SvxBrushItem*>(pItem)->GetGraphicFilter(); + if( !pGraphicBrushItem->GetGraphicFilter().isEmpty() ) + sFilterNm = pGraphicBrushItem->GetGraphicFilter(); else sFilterNm.clear(); @@ -492,21 +489,21 @@ void SwGrfShell::Execute(SfxRequest &rReq) sFilterNm ); } } - if ( SfxItemState::SET == pSet->GetItemState( - FN_SET_FRM_ALT_NAME, true, &pItem )) + if ( const SfxStringItem* pNameItem = pSet->GetItemIfSet( + FN_SET_FRM_ALT_NAME )) { // #i73249# - rSh.SetObjTitle( static_cast<const SfxStringItem*>(pItem)->GetValue() ); + rSh.SetObjTitle( pNameItem->GetValue() ); } - if ( SfxItemState::SET == pSet->GetItemState( - FN_UNO_DESCRIPTION, true, &pItem )) - rSh.SetObjDescription( static_cast<const SfxStringItem*>(pItem)->GetValue() ); + if ( const SfxStringItem* pDescriptionItem = pSet->GetItemIfSet( + FN_UNO_DESCRIPTION )) + rSh.SetObjDescription( pDescriptionItem->GetValue() ); // RotGrfFlyFrame: Get and process evtl. changed RotationAngle - if ( SfxItemState::SET == pSet->GetItemState(SID_ATTR_TRANSFORM_ANGLE, false, &pItem )) + if ( const SdrAngleItem* pAngleItem = pSet->GetItemIfSet(SID_ATTR_TRANSFORM_ANGLE, false )) { - const Degree10 aNewRotation = to<Degree10>(static_cast<const SdrAngleItem*>(pItem)->GetValue() % 36000_deg100); + const Degree10 aNewRotation = to<Degree10>(pAngleItem->GetValue() % 36000_deg100); // RotGrfFlyFrame: Possible rotation change here, SwFlyFrameAttrMgr aMgr is available aMgr.SetRotation(nCurrentRotation, aNewRotation, aUnrotatedSize); diff --git a/sw/source/uibase/shells/tabsh.cxx b/sw/source/uibase/shells/tabsh.cxx index 5532edb95dda..a7136e38ba17 100644 --- a/sw/source/uibase/shells/tabsh.cxx +++ b/sw/source/uibase/shells/tabsh.cxx @@ -271,25 +271,23 @@ void ItemSetToTableParam( const SfxItemSet& rSet, { rSh.StartAllAction(); rSh.StartUndo( SwUndoId::TABLE_ATTR ); - const SfxPoolItem* pItem = nullptr; - if(SfxItemState::SET == rSet.GetItemState(SID_BACKGRND_DESTINATION, false, &pItem)) + if(const SfxUInt16Item* pDestItem = rSet.GetItemIfSet(SID_BACKGRND_DESTINATION, false)) { SwViewOption aUsrPref( *rSh.GetViewOptions() ); - aUsrPref.SetTableDest(static_cast<sal_uInt8>(static_cast<const SfxUInt16Item*>(pItem)->GetValue())); + aUsrPref.SetTableDest(static_cast<sal_uInt8>(pDestItem->GetValue())); SW_MOD()->ApplyUsrPref(aUsrPref, &rSh.GetView()); } bool bBorder = ( SfxItemState::SET == rSet.GetItemState( RES_BOX ) || SfxItemState::SET == rSet.GetItemState( SID_ATTR_BORDER_INNER ) ); - pItem = nullptr; - bool bBackground = SfxItemState::SET == rSet.GetItemState( RES_BACKGROUND, false, &pItem ); - const SfxPoolItem* pRowItem = nullptr, *pTableItem = nullptr; - bBackground |= SfxItemState::SET == rSet.GetItemState( SID_ATTR_BRUSH_ROW, false, &pRowItem ); - bBackground |= SfxItemState::SET == rSet.GetItemState( SID_ATTR_BRUSH_TABLE, false, &pTableItem ); - const SfxPoolItem* pSplit = nullptr; - bool bRowSplit = SfxItemState::SET == rSet.GetItemState( RES_ROW_SPLIT, false, &pSplit ); - const SfxPoolItem* pBoxDirection = nullptr; - bool bBoxDirection = SfxItemState::SET == rSet.GetItemState( FN_TABLE_BOX_TEXTORIENTATION, false, &pBoxDirection ); + const SvxBrushItem* pBackgroundItem = rSet.GetItemIfSet( RES_BACKGROUND, false ); + const SvxBrushItem* pRowItem = rSet.GetItemIfSet( SID_ATTR_BRUSH_ROW, false ); + const SvxBrushItem* pTableItem = rSet.GetItemIfSet( SID_ATTR_BRUSH_TABLE, false ); + bool bBackground = pBackgroundItem || pRowItem || pTableItem; + const SwFormatRowSplit* pSplit = rSet.GetItemIfSet( RES_ROW_SPLIT, false ); + bool bRowSplit = pSplit != nullptr; + const SvxFrameDirectionItem* pBoxDirection = rSet.GetItemIfSet( FN_TABLE_BOX_TEXTORIENTATION, false ); + bool bBoxDirection = pBoxDirection != nullptr; if( bBackground || bBorder || bRowSplit || bBoxDirection) { // The border will be applied to the present selection. @@ -300,17 +298,17 @@ void ItemSetToTableParam( const SfxItemSet& rSet, if(bBackground) { - if(pItem) - rSh.SetBoxBackground( *static_cast<const SvxBrushItem*>(pItem) ); + if(pBackgroundItem) + rSh.SetBoxBackground( *pBackgroundItem ); if(pRowItem) { - std::unique_ptr<SvxBrushItem> aBrush(static_cast<SvxBrushItem*>(pRowItem->Clone())); + std::unique_ptr<SvxBrushItem> aBrush(pRowItem->Clone()); aBrush->SetWhich(RES_BACKGROUND); rSh.SetRowBackground(*aBrush); } if(pTableItem) { - std::unique_ptr<SvxBrushItem> aBrush(static_cast<SvxBrushItem*>(pTableItem->Clone())); + std::unique_ptr<SvxBrushItem> aBrush(pTableItem->Clone()); aBrush->SetWhich(RES_BACKGROUND); rSh.SetTabBackground( *aBrush ); } @@ -319,7 +317,7 @@ void ItemSetToTableParam( const SfxItemSet& rSet, if(bBoxDirection) { SvxFrameDirectionItem aDirection( SvxFrameDirection::Environment, RES_FRAMEDIR ); - aDirection.SetValue(static_cast< const SvxFrameDirectionItem* >(pBoxDirection)->GetValue()); + aDirection.SetValue(pBoxDirection->GetValue()); rSh.SetBoxDirection(aDirection); } @@ -335,7 +333,7 @@ void ItemSetToTableParam( const SfxItemSet& rSet, if(bRowSplit) { - rSh.SetRowSplit(*static_cast<const SwFormatRowSplit*>(pSplit)); + rSh.SetRowSplit(*pSplit); } if(!bTableSel) @@ -353,9 +351,9 @@ void ItemSetToTableParam( const SfxItemSet& rSet, SwTableRep* pRep = nullptr; SwFrameFormat *pFormat = rSh.GetTableFormat(); SfxItemSetFixed<RES_FRMATR_BEGIN, RES_FRMATR_END-1> aSet( rSh.GetAttrPool() ); - if(SfxItemState::SET == rSet.GetItemState( FN_TABLE_REP, false, &pItem )) + if(const SwPtrItem* pRepItem = rSet.GetItemIfSet( FN_TABLE_REP, false )) { - pRep = static_cast<SwTableRep*>(static_cast<const SwPtrItem*>(pItem)->GetValue()); + pRep = static_cast<SwTableRep*>(pRepItem->GetValue()); const SwTwips nWidth = pRep->GetWidth(); if ( text::HoriOrientation::FULL == pRep->GetAlign() ) @@ -393,14 +391,14 @@ void ItemSetToTableParam( const SfxItemSet& rSet, } } - if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_TABLE_HEADLINE, false, &pItem)) - rSh.SetRowsToRepeat( static_cast<const SfxUInt16Item*>(pItem)->GetValue() ); + if( const SfxUInt16Item* pHeadlineItem = rSet.GetItemIfSet( FN_PARAM_TABLE_HEADLINE, false )) + rSh.SetRowsToRepeat( pHeadlineItem->GetValue() ); - if( SfxItemState::SET == rSet.GetItemState( FN_TABLE_SET_VERT_ALIGN, false, &pItem)) - rSh.SetBoxAlign(static_cast<const SfxUInt16Item*>(pItem)->GetValue()); + if( const SfxUInt16Item* pAlignItem = rSet.GetItemIfSet( FN_TABLE_SET_VERT_ALIGN, false )) + rSh.SetBoxAlign(pAlignItem->GetValue()); - if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_TABLE_NAME, false, &pItem )) - rSh.SetTableName( *pFormat, static_cast<const SfxStringItem*>(pItem)->GetValue() ); + if( const SfxStringItem* pNameItem = rSet.GetItemIfSet( FN_PARAM_TABLE_NAME, false )) + rSh.SetTableName( *pFormat, pNameItem->GetValue() ); // Copy the chosen attributes in the ItemSet. static const sal_uInt16 aIds[] = @@ -417,6 +415,7 @@ void ItemSetToTableParam( const SfxItemSet& rSet, // <-- collapsing borders 0 }; + const SfxPoolItem* pItem = nullptr; for( const sal_uInt16* pIds = aIds; *pIds; ++pIds ) if( SfxItemState::SET == rSet.GetItemState( *pIds, false, &pItem)) aSet.Put( *pItem ); @@ -471,10 +470,10 @@ void SwTableShell::Execute(SfxRequest &rReq) aCoreSet.Put(aCoreInfo); rSh.GetTabBorders( aCoreSet ); const SvxBoxItem& rCoreBox = aCoreSet.Get(RES_BOX); - const SfxPoolItem *pBoxItem = nullptr; - if ( pArgs->GetItemState(RES_BOX, true, &pBoxItem) == SfxItemState::SET ) + const SvxBoxItem *pBoxItem = pArgs->GetItemIfSet(RES_BOX); + if ( pBoxItem ) { - aBox.reset(static_cast<SvxBoxItem*>(pBoxItem->Clone())); + aBox.reset(pBoxItem->Clone()); sal_uInt16 nDefValue = MIN_BORDER_DIST; if ( !rReq.IsAPI() ) nDefValue = 55; @@ -489,13 +488,13 @@ void SwTableShell::Execute(SfxRequest &rReq) //since the drawing layer also supports borders the which id might be a different one std::shared_ptr<SvxBoxInfoItem> aInfo(std::make_shared<SvxBoxInfoItem>(SID_ATTR_BORDER_INNER)); - if (pArgs->GetItemState(SID_ATTR_BORDER_INNER, true, &pBoxItem) == SfxItemState::SET) + if (const SvxBoxInfoItem* pBoxInfoItem = pArgs->GetItemIfSet(SID_ATTR_BORDER_INNER)) { - aInfo.reset(static_cast<SvxBoxInfoItem*>(pBoxItem->Clone())); + aInfo.reset(pBoxInfoItem->Clone()); } - else if( pArgs->GetItemState(SDRATTR_TABLE_BORDER_INNER, true, &pBoxItem) == SfxItemState::SET ) + else if( const SvxBoxInfoItem* pBoxInfoInnerItem = pArgs->GetItemIfSet(SDRATTR_TABLE_BORDER_INNER)) { - aInfo.reset(static_cast<SvxBoxInfoItem*>(pBoxItem->Clone())); + aInfo.reset(pBoxInfoInnerItem->Clone()); aInfo->SetWhich(SID_ATTR_BORDER_INNER); } @@ -695,14 +694,15 @@ void SwTableShell::Execute(SfxRequest &rReq) pNumberFormatItem->GetNumberFormatter()->DeleteEntry( key ); } - const SfxPoolItem* pNumberFormatValueItem = nullptr; - if( SfxItemState::SET == pDlg->GetOutputItemSet()->GetItemState( - SID_ATTR_NUMBERFORMAT_VALUE, false, &pNumberFormatValueItem )) + const SfxUInt32Item* pNumberFormatValueItem = + pDlg->GetOutputItemSet()->GetItemIfSet( + SID_ATTR_NUMBERFORMAT_VALUE, false); + if( pNumberFormatValueItem ) { SfxItemSetFixed<RES_BOXATR_FORMAT, RES_BOXATR_FORMAT> aBoxFormatSet( *aCoreSet.GetPool() ); aBoxFormatSet.Put( SwTableBoxNumFormat( - static_cast<const SfxUInt32Item*>(pNumberFormatValueItem)->GetValue() )); + pNumberFormatValueItem->GetValue() )); rSh.SetTableBoxFormulaAttrs( aBoxFormatSet ); } @@ -869,8 +869,8 @@ void SwTableShell::Execute(SfxRequest &rReq) if (pItem) { nCount = static_cast<const SfxInt16Item* >(pItem)->GetValue(); - if(SfxItemState::SET == pArgs->GetItemState(FN_PARAM_INSERT_AFTER, true, &pItem)) - bAfter = static_cast<const SfxBoolItem* >(pItem)->GetValue(); + if(const SfxBoolItem* pAfterItem = pArgs->GetItemIfSet(FN_PARAM_INSERT_AFTER)) + bAfter = pAfterItem->GetValue(); } else if( !rReq.IsAPI() ) { diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx index ee20d9c74f65..ffd638270588 100644 --- a/sw/source/uibase/shells/textfld.cxx +++ b/sw/source/uibase/shells/textfld.cxx @@ -216,9 +216,9 @@ void SwTextShell::ExecField(SfxRequest &rReq) OUString aPar2; sal_Int32 nCommand = 0; - if( SfxItemState::SET == pArgs->GetItemState( FN_PARAM_FIELD_TYPE, - false, &pItem )) - nType = static_cast<SwFieldTypesEnum>(static_cast<const SfxUInt16Item *>(pItem)->GetValue()); + if( const SfxUInt16Item* pFieldItem = pArgs->GetItemIfSet( FN_PARAM_FIELD_TYPE, + false )) + nType = static_cast<SwFieldTypesEnum>(pFieldItem->GetValue()); aPar1 += OUStringChar(DB_DELIM); if( SfxItemState::SET == pArgs->GetItemState( FN_PARAM_1, false, &pItem )) @@ -236,12 +236,12 @@ void SwTextShell::ExecField(SfxRequest &rReq) { aPar1 += static_cast<const SfxStringItem *>(pItem)->GetValue(); } - if( SfxItemState::SET == pArgs->GetItemState( - FN_PARAM_FIELD_CONTENT, false, &pItem )) - aPar2 = static_cast<const SfxStringItem *>(pItem)->GetValue(); - if( SfxItemState::SET == pArgs->GetItemState( - FN_PARAM_FIELD_FORMAT, false, &pItem )) - nFormat = static_cast<const SfxUInt32Item *>(pItem)->GetValue(); + if( const SfxStringItem* pContentItem = pArgs->GetItemIfSet( + FN_PARAM_FIELD_CONTENT, false )) + aPar2 = pContentItem->GetValue(); + if( const SfxUInt32Item* pFormatItem = pArgs->GetItemIfSet( + FN_PARAM_FIELD_FORMAT, false )) + nFormat = pFormatItem->GetValue(); OSL_FAIL("Command is not yet used"); SwInsertField_Data aData(nType, 0, aPar1, aPar2, nFormat, GetShellPtr(), ' '/*separator*/ ); bRes = aFieldMgr.InsertField(aData); @@ -262,18 +262,18 @@ void SwTextShell::ExecField(SfxRequest &rReq) OUString aPar2; sal_Unicode cSeparator = ' '; - if( SfxItemState::SET == pArgs->GetItemState( FN_PARAM_FIELD_TYPE, - false, &pItem )) - nType = static_cast<SwFieldTypesEnum>(static_cast<const SfxUInt16Item *>(pItem)->GetValue()); - if( SfxItemState::SET == pArgs->GetItemState( FN_PARAM_FIELD_SUBTYPE, - false, &pItem )) - nSubType = static_cast<const SfxUInt16Item *>(pItem)->GetValue(); - if( SfxItemState::SET == pArgs->GetItemState( - FN_PARAM_FIELD_CONTENT, false, &pItem )) - aPar2 = static_cast<const SfxStringItem *>(pItem)->GetValue(); - if( SfxItemState::SET == pArgs->GetItemState( - FN_PARAM_FIELD_FORMAT, false, &pItem )) - nFormat = static_cast<const SfxUInt32Item *>(pItem)->GetValue(); + if( const SfxUInt16Item* pTypeItem = pArgs->GetItemIfSet( FN_PARAM_FIELD_TYPE, + false )) + nType = static_cast<SwFieldTypesEnum>(pTypeItem->GetValue()); + if( const SfxUInt16Item* pSubtypeItem = pArgs->GetItemIfSet( FN_PARAM_FIELD_SUBTYPE, + false )) + nSubType = pSubtypeItem->GetValue(); + if( const SfxStringItem* pContentItem = pArgs->GetItemIfSet( + FN_PARAM_FIELD_CONTENT, false )) + aPar2 = pContentItem->GetValue(); + if( const SfxUInt32Item* pFormatItem = pArgs->GetItemIfSet( + FN_PARAM_FIELD_FORMAT, false )) + nFormat = pFormatItem->GetValue(); if( SfxItemState::SET == pArgs->GetItemState( FN_PARAM_3, false, &pItem )) { @@ -989,8 +989,7 @@ void SwTextShell::InsertHyperlink(const SvxHyperlinkItem& rHlnkItem) SfxItemSetFixed<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT> aSet(GetPool()); rSh.GetCurAttr( aSet ); - const SfxPoolItem* pItem; - if(SfxItemState::SET == aSet.GetItemState(RES_TXTATR_INETFMT, false, &pItem)) + if(SfxItemState::SET == aSet.GetItemState(RES_TXTATR_INETFMT, false)) { // Select links rSh.SwCursorShell::SelectTextAttr(RES_TXTATR_INETFMT, false); diff --git a/sw/source/uibase/shells/textsh.cxx b/sw/source/uibase/shells/textsh.cxx index 8fe5862e3479..879bb4809efa 100644 --- a/sw/source/uibase/shells/textsh.cxx +++ b/sw/source/uibase/shells/textsh.cxx @@ -386,11 +386,12 @@ void SwTextShell::ExecInsert(SfxRequest &rReq) bool bModifier1 = rReq.GetModifier() == KEY_MOD1; if(pArgs) { + const SfxUInt16Item* pColsItem = nullptr; if(FN_INSERT_FRAME_INTERACT_NOCOL != nSlot && - pArgs->GetItemState(SID_ATTR_COLUMNS, false, &pItem) == SfxItemState::SET) - nCols = static_cast<const SfxUInt16Item *>(pItem)->GetValue(); - if(pArgs->GetItemState(SID_MODIFIER, false, &pItem) == SfxItemState::SET) - bModifier1 |= KEY_MOD1 == static_cast<const SfxUInt16Item *>(pItem)->GetValue(); + (pColsItem = pArgs->GetItemIfSet(SID_ATTR_COLUMNS, false))) + nCols = pColsItem->GetValue(); + if(const SfxUInt16Item* pModifierItem = pArgs->GetItemIfSet(SID_MODIFIER, false)) + bModifier1 |= KEY_MOD1 == pModifierItem->GetValue(); } if(bModifier1 ) { @@ -448,9 +449,9 @@ void SwTextShell::ExecInsert(SfxRequest &rReq) aPos = static_cast<const SfxPointItem *>(pItem)->GetValue(); if(pArgs->GetItemState(FN_PARAM_2, false, &pItem) == SfxItemState::SET) aSize = static_cast<const SvxSizeItem *>(pItem)->GetSize(); - if(pArgs->GetItemState(SID_ATTR_COLUMNS, false, &pItem) == SfxItemState::SET) + if(const SfxUInt16Item* pColsItem = pArgs->GetItemIfSet(SID_ATTR_COLUMNS, false)) { - const sal_uInt16 nCols = static_cast<const SfxUInt16Item *>(pItem)->GetValue(); + const sal_uInt16 nCols = pColsItem->GetValue(); if( !bSingleCol && 1 < nCols ) { SwFormatCol aFormatCol; @@ -637,10 +638,8 @@ void SwTextShell::StateInsert( SfxItemSet &rSet ) rSh.GetCurAttr( aSet ); SvxHyperlinkItem aHLinkItem; - const SfxPoolItem* pItem; - if(SfxItemState::SET == aSet.GetItemState(RES_TXTATR_INETFMT, false, &pItem)) + if(const SwFormatINetFormat* pINetFormat = aSet.GetItemIfSet(RES_TXTATR_INETFMT, false)) { - const SwFormatINetFormat* pINetFormat = static_cast<const SwFormatINetFormat*>(pItem); aHLinkItem.SetURL(pINetFormat->GetValue()); aHLinkItem.SetTargetFrame(pINetFormat->GetTargetFrame()); aHLinkItem.SetIntName(pINetFormat->GetName()); @@ -876,17 +875,15 @@ SfxItemSet SwTextShell::CreateInsertFrameItemSet(SwFlyFrameAttrMgr& rMgr) void SwTextShell::InsertSymbol( SfxRequest& rReq ) { const SfxItemSet *pArgs = rReq.GetArgs(); - const SfxPoolItem* pItem = nullptr; + const SfxStringItem* pItem = nullptr; if( pArgs ) - pArgs->GetItemState(SID_CHARMAP, false, &pItem); + pItem = pArgs->GetItemIfSet(SID_CHARMAP, false); OUString aChars, aFontName; if ( pItem ) { - aChars = static_cast<const SfxStringItem*>(pItem)->GetValue(); - const SfxPoolItem* pFtItem = nullptr; - pArgs->GetItemState( SID_ATTR_SPECIALCHAR, false, &pFtItem); - const SfxStringItem* pFontItem = dynamic_cast<const SfxStringItem*>( pFtItem ); + aChars = pItem->GetValue(); + const SfxStringItem* pFontItem = pArgs->GetItemIfSet( SID_ATTR_SPECIALCHAR, false ); if ( pFontItem ) aFontName = pFontItem->GetValue(); } diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx index 5a8b7bf93de7..c7b05a53b4c6 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -203,14 +203,14 @@ static void sw_CharDialogResult(const SfxItemSet* pSet, SwWrtShell &rWrtSh, std: SfxItemSet aTmpSet( *pSet ); ::ConvertAttrGenToChar(aTmpSet, *pCoreSet); - const SfxPoolItem* pSelectionItem; + const SfxStringItem* pSelectionItem; bool bInsert = false; sal_Int32 nInsert = 0; // The old item is for unknown reasons back in the set again. - if( !bSelectionPut && SfxItemState::SET == aTmpSet.GetItemState(FN_PARAM_SELECTION, false, &pSelectionItem) ) + if( !bSelectionPut && (pSelectionItem = aTmpSet.GetItemIfSet(FN_PARAM_SELECTION, false)) ) { - OUString sInsert = static_cast<const SfxStringItem*>(pSelectionItem)->GetValue(); + OUString sInsert = pSelectionItem->GetValue(); bInsert = !sInsert.isEmpty(); if(bInsert) { @@ -280,11 +280,10 @@ static void sw_ParagraphDialogResult(SfxItemSet* pSet, SwWrtShell &rWrtSh, SfxRe if( pSet->Count() ) { rWrtSh.StartAction(); - const SfxPoolItem* pItem = nullptr; - if ( SfxItemState::SET == pSet->GetItemState(FN_DROP_TEXT, false, &pItem) ) + if ( const SfxStringItem* pDropTextItem = pSet->GetItemIfSet(FN_DROP_TEXT, false) ) { - if ( !static_cast<const SfxStringItem*>(pItem)->GetValue().isEmpty() ) - rWrtSh.ReplaceDropText(static_cast<const SfxStringItem*>(pItem)->GetValue(), pPaM); + if ( !pDropTextItem->GetValue().isEmpty() ) + rWrtSh.ReplaceDropText(pDropTextItem->GetValue(), pPaM); } rWrtSh.SetAttrSet(*pSet, SetAttrMode::DEFAULT, pPaM); rWrtSh.EndAction(); @@ -986,10 +985,9 @@ void SwTextShell::Execute(SfxRequest &rReq) if ( pArgs ) { - const SfxPoolItem* pPaMItem = nullptr; - pArgs->GetItemState( GetPool().GetWhich( FN_PARAM_PAM ), false, &pPaMItem ); + const SwPaMItem* pPaMItem = pArgs->GetItemIfSet( GetPool().GetWhich( FN_PARAM_PAM ), false ); if ( pPaMItem ) - pPaM = static_cast< const SwPaMItem* >( pPaMItem )->GetValue( ); + pPaM = pPaMItem->GetValue( ); } if ( !pPaM ) @@ -1106,9 +1104,8 @@ void SwTextShell::Execute(SfxRequest &rReq) // Apply defaults if necessary. SfxItemSet* pSet = const_cast<SfxItemSet*>(pDlg->GetOutputItemSet()); sal_uInt16 nNewDist; - const SfxPoolItem* pItem2 = nullptr; - if (SfxItemState::SET == pSet->GetItemState(SID_ATTR_TABSTOP_DEFAULTS, false, &pItem2) && - nDefDist != (nNewDist = static_cast<const SfxUInt16Item*>(pItem2)->GetValue()) ) + const SfxUInt16Item* pDefaultsItem = pSet->GetItemIfSet(SID_ATTR_TABSTOP_DEFAULTS, false); + if (pDefaultsItem && nDefDist != (nNewDist = pDefaultsItem->GetValue()) ) { SvxTabStopItem aDefTabs( 0, 0, SvxTabAdjust::Default, RES_PARATR_TABSTOP ); MakeDefTabs( nNewDist, aDefTabs ); @@ -1116,17 +1113,18 @@ void SwTextShell::Execute(SfxRequest &rReq) pSet->ClearItem( SID_ATTR_TABSTOP_DEFAULTS ); } + const SfxPoolItem* pItem2 = nullptr; if (SfxItemState::SET == pSet->GetItemState(FN_PARAM_1, false, &pItem2)) { pSet->Put(SfxStringItem(FN_DROP_TEXT, static_cast<const SfxStringItem*>(pItem2)->GetValue())); pSet->ClearItem(FN_PARAM_1); } - if (SfxItemState::SET == pSet->GetItemState(RES_PARATR_DROP, false, &pItem2)) + if (const SwFormatDrop* pDropItem = pSet->GetItemIfSet(RES_PARATR_DROP, false)) { OUString sCharStyleName; - if (static_cast<const SwFormatDrop*>(pItem2)->GetCharFormat()) - sCharStyleName = static_cast<const SwFormatDrop*>(pItem2)->GetCharFormat()->GetName(); + if (pDropItem->GetCharFormat()) + sCharStyleName = pDropItem->GetCharFormat()->GetName(); pSet->Put(SfxStringItem(FN_DROP_CHAR_STYLE_NAME, sCharStyleName)); } @@ -1220,7 +1218,7 @@ void SwTextShell::Execute(SfxRequest &rReq) case SID_ATTR_CHAR_COLOR2: { Color aSet; - const SfxPoolItem* pColorStringItem = nullptr; + const SfxStringItem* pColorStringItem = nullptr; bool bHasItem = false; if(pItem) @@ -1228,9 +1226,9 @@ void SwTextShell::Execute(SfxRequest &rReq) aSet = static_cast<const SvxColorItem*>(pItem)->GetValue(); bHasItem = true; } - else if (pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_COLOR_STR, false, &pColorStringItem)) + else if (pArgs && (pColorStringItem = pArgs->GetItemIfSet(SID_ATTR_COLOR_STR, false))) { - OUString sColor = static_cast<const SfxStringItem*>(pColorStringItem)->GetValue(); + OUString sColor = pColorStringItem->GetValue(); aSet = Color(ColorTransparency, sColor.toInt32(16)); bHasItem = true; } @@ -1257,11 +1255,11 @@ void SwTextShell::Execute(SfxRequest &rReq) case SID_ATTR_CHAR_COLOR_EXT: { Color aSet; - const SfxPoolItem* pColorStringItem = nullptr; + const SfxStringItem* pColorStringItem = nullptr; - if (pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_COLOR_STR, false, &pColorStringItem)) + if (pArgs && (pColorStringItem = pArgs->GetItemIfSet(SID_ATTR_COLOR_STR, false))) { - OUString sColor = static_cast<const SfxStringItem*>(pColorStringItem)->GetValue(); + OUString sColor = pColorStringItem->GetValue(); if (sColor == "transparent") aSet = COL_TRANSPARENT; else diff --git a/sw/source/uibase/shells/textsh2.cxx b/sw/source/uibase/shells/textsh2.cxx index efdb74694949..582a7d9a5efa 100644 --- a/sw/source/uibase/shells/textsh2.cxx +++ b/sw/source/uibase/shells/textsh2.cxx @@ -67,40 +67,36 @@ void SwTextShell::ExecDB(SfxRequest const &rReq) SwDBManager* pDBManager = GetShell().GetDBManager(); OUString sSourceArg, sCommandArg; sal_Int32 nCommandTypeArg = 0; - - const SfxPoolItem* pSourceItem = nullptr; - const SfxPoolItem* pCursorItem = nullptr; - const SfxPoolItem* pConnectionItem = nullptr; - const SfxPoolItem* pCommandItem = nullptr; - const SfxPoolItem* pCommandTypeItem = nullptr; - const SfxPoolItem* pSelectionItem = nullptr; + const SfxUnoAnyItem* pSourceItem = nullptr; + const SfxUnoAnyItem* pCommandItem = nullptr; + const SfxUnoAnyItem* pCommandTypeItem = nullptr; + const SfxUnoAnyItem* pConnectionItem = nullptr; // first get the selection of rows to be inserted - pArgs->GetItemState(FN_DB_DATA_SELECTION_ANY, false, &pSelectionItem); Sequence<Any> aSelection; - if(pSelectionItem) - static_cast<const SfxUnoAnyItem*>(pSelectionItem)->GetValue() >>= aSelection; + if(const SfxUnoAnyItem* pSelectionItem = pArgs->GetItemIfSet(FN_DB_DATA_SELECTION_ANY, false)) + pSelectionItem->GetValue() >>= aSelection; // get the data source name - pArgs->GetItemState(FN_DB_DATA_SOURCE_ANY, false, &pSourceItem); + pSourceItem = pArgs->GetItemIfSet(FN_DB_DATA_SOURCE_ANY, false); if(pSourceItem) - static_cast<const SfxUnoAnyItem*>(pSourceItem)->GetValue() >>= sSourceArg; + pSourceItem->GetValue() >>= sSourceArg; // get the command - pArgs->GetItemState(FN_DB_DATA_COMMAND_ANY, false, &pCommandItem); + pCommandItem = pArgs->GetItemIfSet(FN_DB_DATA_COMMAND_ANY, false); if(pCommandItem) - static_cast<const SfxUnoAnyItem*>(pCommandItem)->GetValue() >>= sCommandArg; + pCommandItem->GetValue() >>= sCommandArg; // get the command type - pArgs->GetItemState(FN_DB_DATA_COMMAND_TYPE_ANY, false, &pCommandTypeItem); + pCommandTypeItem = pArgs->GetItemIfSet(FN_DB_DATA_COMMAND_TYPE_ANY, false); if(pCommandTypeItem) - static_cast<const SfxUnoAnyItem*>(pCommandTypeItem)->GetValue() >>= nCommandTypeArg; + pCommandTypeItem->GetValue() >>= nCommandTypeArg; Reference<XConnection> xConnection; - pArgs->GetItemState(FN_DB_CONNECTION_ANY, false, &pConnectionItem); - if ( pConnectionItem ) - static_cast<const SfxUnoAnyItem*>(pConnectionItem)->GetValue() >>= xConnection; + pConnectionItem = pArgs->GetItemIfSet(FN_DB_CONNECTION_ANY, false); + if(pConnectionItem) + pConnectionItem->GetValue() >>= xConnection; // may be we even get no connection if ( !xConnection.is() ) { @@ -113,9 +109,8 @@ void SwTextShell::ExecDB(SfxRequest const &rReq) // get the cursor, we use to travel, may be NULL Reference<XResultSet> xCursor; - pArgs->GetItemState(FN_DB_DATA_CURSOR_ANY, false, &pCursorItem); - if ( pCursorItem ) - static_cast<const SfxUnoAnyItem*>(pCursorItem)->GetValue() >>= xCursor; + if ( const SfxUnoAnyItem* pCursorItem = pArgs->GetItemIfSet(FN_DB_DATA_CURSOR_ANY, false) ) + pCursorItem->GetValue() >>= xCursor; switch (rReq.GetSlot()) { @@ -167,15 +162,13 @@ void SwTextShell::ExecDB(SfxRequest const &rReq) case FN_QRY_INSERT_FIELD: { - const SfxPoolItem* pColumnItem = nullptr; - const SfxPoolItem* pColumnNameItem = nullptr; - - pArgs->GetItemState(FN_DB_COLUMN_ANY, false, &pColumnItem); - pArgs->GetItemState(FN_DB_DATA_COLUMN_NAME_ANY, false, &pColumnNameItem); + const SfxUnoAnyItem* pColumnItem = pArgs->GetItemIfSet(FN_DB_COLUMN_ANY, false); + const SfxUnoAnyItem* pColumnNameItem = + pArgs->GetItemIfSet(FN_DB_DATA_COLUMN_NAME_ANY, false); OUString sColumnName; if(pColumnNameItem) - static_cast<const SfxUnoAnyItem*>(pColumnNameItem)->GetValue() >>= sColumnName; + pColumnNameItem->GetValue() >>= sColumnName; OUString sDBName = sSourceArg + OUStringChar(DB_DELIM) + sCommandArg + OUStringChar(DB_DELIM) + OUString::number(nCommandTypeArg) @@ -184,9 +177,9 @@ void SwTextShell::ExecDB(SfxRequest const &rReq) SwFieldMgr aFieldMgr(GetShellPtr()); SwInsertField_Data aData(SwFieldTypesEnum::Database, 0, sDBName, OUString(), 0); if(pConnectionItem) - aData.m_aDBConnection = static_cast<const SfxUnoAnyItem*>(pConnectionItem)->GetValue(); + aData.m_aDBConnection = pConnectionItem->GetValue(); if(pColumnItem) - aData.m_aDBColumn = static_cast<const SfxUnoAnyItem*>(pColumnItem)->GetValue(); + aData.m_aDBColumn = pColumnItem->GetValue(); aFieldMgr.InsertField(aData); SfxViewFrame* pViewFrame = GetView().GetViewFrame(); uno::Reference< XDispatchRecorder > xRecorder = diff --git a/sw/source/uibase/shells/txtattr.cxx b/sw/source/uibase/shells/txtattr.cxx index ef9d878233c2..44c6ee6aa152 100644 --- a/sw/source/uibase/shells/txtattr.cxx +++ b/sw/source/uibase/shells/txtattr.cxx @@ -39,6 +39,7 @@ #include <editeng/cmapitem.hxx> #include <osl/diagnose.h> #include <paratr.hxx> +#include <editeng/pmdlitem.hxx> #include <fmtinfmt.hxx> #include <wrtsh.hxx> @@ -497,10 +498,10 @@ void SwTextShell::ExecParaAttrArgs(SfxRequest &rReq) { rSh.StartAction(); rSh.StartUndo( SwUndoId::START ); - if ( SfxItemState::SET == aSet.GetItemState(HINT_END,false,&pItem) ) + if ( const SfxStringItem* pHintItem = aSet.GetItemIfSet(HINT_END,false) ) { - if ( !static_cast<const SfxStringItem*>(pItem)->GetValue().isEmpty() ) - rSh.ReplaceDropText(static_cast<const SfxStringItem*>(pItem)->GetValue()); + if ( !pHintItem->GetValue().isEmpty() ) + rSh.ReplaceDropText(pHintItem->GetValue()); } rSh.SetAttrSet(*pDlg->GetOutputItemSet()); rSh.EndUndo( SwUndoId::END ); diff --git a/sw/source/uibase/shells/txtcrsr.cxx b/sw/source/uibase/shells/txtcrsr.cxx index bc1c86fe1a2b..f8ec0d7a6e27 100644 --- a/sw/source/uibase/shells/txtcrsr.cxx +++ b/sw/source/uibase/shells/txtcrsr.cxx @@ -52,11 +52,10 @@ void SwTextShell::ExecBasicMove(SfxRequest &rReq) sal_Int32 nCount = 1; if(pArgs) { - const SfxPoolItem *pItem; - if(SfxItemState::SET == pArgs->GetItemState(FN_PARAM_MOVE_COUNT, true, &pItem)) - nCount = static_cast<const SfxInt32Item *>(pItem)->GetValue(); - if(SfxItemState::SET == pArgs->GetItemState(FN_PARAM_MOVE_SELECTION, true, &pItem)) - bSelect = static_cast<const SfxBoolItem *>(pItem)->GetValue(); + if(const SfxInt32Item* pCountItem = pArgs->GetItemIfSet(FN_PARAM_MOVE_COUNT)) + nCount = pCountItem->GetValue(); + if(const SfxBoolItem* pSelectionItem = pArgs->GetItemIfSet(FN_PARAM_MOVE_SELECTION)) + bSelect = pSelectionItem->GetValue(); } switch(rReq.GetSlot()) { diff --git a/sw/source/uibase/shells/txtnum.cxx b/sw/source/uibase/shells/txtnum.cxx index 88daf7482267..34a95d13ee8e 100644 --- a/sw/source/uibase/shells/txtnum.cxx +++ b/sw/source/uibase/shells/txtnum.cxx @@ -203,12 +203,12 @@ void SwTextShell::ExecEnterNum(SfxRequest &rReq) pDlg->StartExecuteAsync([aSet, pDlg, pNumRuleAtCurrentSelection, pRequest, this](sal_Int32 nResult){ if (RET_OK == nResult) { - const SfxPoolItem* pItem; - if (SfxItemState::SET == pDlg->GetOutputItemSet()->GetItemState(SID_ATTR_NUMBERING_RULE, false, &pItem)) + const SvxNumBulletItem* pBulletItem = pDlg->GetOutputItemSet()->GetItemIfSet(SID_ATTR_NUMBERING_RULE, false); + if (pBulletItem) { - pRequest->AppendItem(*pItem); + pRequest->AppendItem(*pBulletItem); pRequest->Done(); - SvxNumRule& rSetRule = const_cast<SvxNumRule&>(static_cast<const SvxNumBulletItem*>(pItem)->GetNumRule()); + SvxNumRule& rSetRule = const_cast<SvxNumRule&>(pBulletItem->GetNumRule()); rSetRule.UnLinkGraphics(); SwNumRule aSetRule(pNumRuleAtCurrentSelection != nullptr ? pNumRuleAtCurrentSelection->GetName() @@ -224,11 +224,11 @@ void SwTextShell::ExecEnterNum(SfxRequest &rReq) // If the Dialog was leaved with OK but nothing was chosen then the // numbering must be at least activated, if it is not already. else if (pNumRuleAtCurrentSelection == nullptr - && SfxItemState::SET == aSet.GetItemState(SID_ATTR_NUMBERING_RULE, false, &pItem)) + && (pBulletItem = aSet.GetItemIfSet(SID_ATTR_NUMBERING_RULE, false))) { - pRequest->AppendItem(*pItem); + pRequest->AppendItem(*pBulletItem); pRequest->Done(); - const SvxNumRule& rSetRule = static_cast<const SvxNumBulletItem*>(pItem)->GetNumRule(); + const SvxNumRule& rSetRule = pBulletItem->GetNumRule(); SwNumRule aSetRule( GetShell().GetUniqueNumRuleName(), numfunc::GetDefaultPositionAndSpaceMode()); diff --git a/sw/source/uibase/uiview/formatclipboard.cxx b/sw/source/uibase/uiview/formatclipboard.cxx index 2bf4dd036fef..5e7e8f768108 100644 --- a/sw/source/uibase/uiview/formatclipboard.cxx +++ b/sw/source/uibase/uiview/formatclipboard.cxx @@ -140,27 +140,26 @@ void lcl_getTableAttributes( SfxItemSet& rSet, SwWrtShell &rSh ) void lcl_setTableAttributes( const SfxItemSet& rSet, SwWrtShell &rSh ) { - const SfxPoolItem* pItem = nullptr; bool bBorder = ( SfxItemState::SET == rSet.GetItemState( RES_BOX ) || SfxItemState::SET == rSet.GetItemState( SID_ATTR_BORDER_INNER ) ); - bool bBackground = SfxItemState::SET == rSet.GetItemState( RES_BACKGROUND, false, &pItem ); - const SfxPoolItem* pRowItem = nullptr, *pTableItem = nullptr; - bBackground |= SfxItemState::SET == rSet.GetItemState( SID_ATTR_BRUSH_ROW, false, &pRowItem ); - bBackground |= SfxItemState::SET == rSet.GetItemState( SID_ATTR_BRUSH_TABLE, false, &pTableItem ); + const SvxBrushItem* pBackgroundItem = rSet.GetItemIfSet( RES_BACKGROUND, false ); + const SvxBrushItem* pRowItem = rSet.GetItemIfSet( SID_ATTR_BRUSH_ROW, false ); + const SvxBrushItem* pTableItem = rSet.GetItemIfSet( SID_ATTR_BRUSH_TABLE, false ); + bool bBackground = pBackgroundItem || pRowItem || pTableItem; if(bBackground) { - if(pItem) - rSh.SetBoxBackground( *static_cast<const SvxBrushItem*>(pItem) ); + if(pBackgroundItem) + rSh.SetBoxBackground( *pBackgroundItem ); if(pRowItem) { - std::unique_ptr<SvxBrushItem> aBrush(static_cast<SvxBrushItem*>(pRowItem->Clone())); + std::unique_ptr<SvxBrushItem> aBrush(pRowItem->Clone()); aBrush->SetWhich(RES_BACKGROUND); rSh.SetRowBackground(*aBrush); } if(pTableItem) { - std::unique_ptr<SvxBrushItem> aBrush(static_cast<SvxBrushItem*>(pTableItem->Clone())); + std::unique_ptr<SvxBrushItem> aBrush(pTableItem->Clone()); aBrush->SetWhich(RES_BACKGROUND); rSh.SetTabBackground(*aBrush); } @@ -168,61 +167,55 @@ void lcl_setTableAttributes( const SfxItemSet& rSet, SwWrtShell &rSh ) if(bBorder) rSh.SetTabBorders( rSet ); - if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_TABLE_HEADLINE, false, &pItem) ) - rSh.SetRowsToRepeat( static_cast<const SfxUInt16Item*>(pItem)->GetValue() ); + if( const SfxUInt16Item* pHeadlineItem = rSet.GetItemIfSet( FN_PARAM_TABLE_HEADLINE, false) ) + rSh.SetRowsToRepeat( pHeadlineItem->GetValue() ); SwFrameFormat* pFrameFormat = rSh.GetTableFormat(); if(pFrameFormat) { //RES_SHADOW - pItem=nullptr; - rSet.GetItemState(rSet.GetPool()->GetWhich(RES_SHADOW), false, &pItem); + const SfxPoolItem* pItem = rSet.GetItemIfSet(rSet.GetPool()->GetWhich(RES_SHADOW), false); if(pItem) pFrameFormat->SetFormatAttr( *pItem ); //RES_BREAK - pItem=nullptr; - rSet.GetItemState(rSet.GetPool()->GetWhich(RES_BREAK), false, &pItem); + pItem = rSet.GetItemIfSet(rSet.GetPool()->GetWhich(RES_BREAK), false); if(pItem) pFrameFormat->SetFormatAttr( *pItem ); //RES_PAGEDESC - pItem=nullptr; - rSet.GetItemState(rSet.GetPool()->GetWhich(RES_PAGEDESC), false, &pItem); + pItem = rSet.GetItemIfSet(rSet.GetPool()->GetWhich(RES_PAGEDESC), false); if(pItem) pFrameFormat->SetFormatAttr( *pItem ); //RES_LAYOUT_SPLIT - pItem=nullptr; - rSet.GetItemState(rSet.GetPool()->GetWhich(RES_LAYOUT_SPLIT), false, &pItem); + pItem = rSet.GetItemIfSet(rSet.GetPool()->GetWhich(RES_LAYOUT_SPLIT), false); if(pItem) pFrameFormat->SetFormatAttr( *pItem ); //RES_KEEP - pItem=nullptr; - rSet.GetItemState(rSet.GetPool()->GetWhich(RES_KEEP), false, &pItem); + pItem = rSet.GetItemIfSet(rSet.GetPool()->GetWhich(RES_KEEP), false); if(pItem) pFrameFormat->SetFormatAttr( *pItem ); //RES_FRAMEDIR - pItem=nullptr; - rSet.GetItemState(rSet.GetPool()->GetWhich(RES_FRAMEDIR), false, &pItem); + pItem = rSet.GetItemIfSet(rSet.GetPool()->GetWhich(RES_FRAMEDIR), false); if(pItem) pFrameFormat->SetFormatAttr( *pItem ); } - if( SfxItemState::SET == rSet.GetItemState( FN_TABLE_BOX_TEXTORIENTATION, false, &pItem) ) + if( const SvxFrameDirectionItem* pTextOriItem = rSet.GetItemIfSet( FN_TABLE_BOX_TEXTORIENTATION, false ) ) { SvxFrameDirectionItem aDirection( SvxFrameDirection::Environment, RES_FRAMEDIR ); - aDirection.SetValue(static_cast< const SvxFrameDirectionItem* >(pItem)->GetValue()); + aDirection.SetValue(pTextOriItem->GetValue()); rSh.SetBoxDirection(aDirection); } - if( SfxItemState::SET == rSet.GetItemState( FN_TABLE_SET_VERT_ALIGN, false, &pItem)) - rSh.SetBoxAlign(static_cast<const SfxUInt16Item*>(pItem)->GetValue()); + if( const SfxUInt16Item* pVertAlignItem = rSet.GetItemIfSet( FN_TABLE_SET_VERT_ALIGN, false )) + rSh.SetBoxAlign(pVertAlignItem->GetValue()); - if( SfxItemState::SET == rSet.GetItemState( RES_ROW_SPLIT, false, &pItem) ) - rSh.SetRowSplit(*static_cast<const SwFormatRowSplit*>(pItem)); + if( const SwFormatRowSplit* pSplitItem = rSet.GetItemIfSet( RES_ROW_SPLIT, false ) ) + rSh.SetRowSplit(*pSplitItem); } }//end anonymous namespace diff --git a/sw/source/uibase/uiview/pview.cxx b/sw/source/uibase/uiview/pview.cxx index 2ef6de717240..80c6bc3c6f2b 100644 --- a/sw/source/uibase/uiview/pview.cxx +++ b/sw/source/uibase/uiview/pview.cxx @@ -723,7 +723,6 @@ void SwPagePreview::Execute( SfxRequest &rReq ) case SID_ATTR_ZOOM: { const SfxItemSet *pArgs = rReq.GetArgs(); - const SfxPoolItem* pItem; ScopedVclPtr<AbstractSvxZoomDialog> pDlg; if(!pArgs) { @@ -750,13 +749,13 @@ void SwPagePreview::Execute( SfxRequest &rReq ) { SvxZoomType eType = SvxZoomType::PERCENT; sal_uInt16 nZoomFactor = USHRT_MAX; - if(SfxItemState::SET == pArgs->GetItemState(SID_ATTR_ZOOM, true, &pItem)) + if(const SvxZoomItem* pZoomItem = pArgs->GetItemIfSet(SID_ATTR_ZOOM)) { - eType = static_cast<const SvxZoomItem *>(pItem)->GetType(); - nZoomFactor = static_cast<const SvxZoomItem *>(pItem)->GetValue(); + eType = pZoomItem->GetType(); + nZoomFactor = pZoomItem->GetValue(); } - else if(SfxItemState::SET == pArgs->GetItemState(FN_PREVIEW_ZOOM, true, &pItem)) - nZoomFactor = static_cast<const SfxUInt16Item *>(pItem)->GetValue(); + else if(const SfxUInt16Item* pPreviewItem = pArgs->GetItemIfSet(FN_PREVIEW_ZOOM)) + nZoomFactor = pPreviewItem->GetValue(); if(USHRT_MAX != nZoomFactor) SetZoom(eType, nZoomFactor); } @@ -765,11 +764,11 @@ void SwPagePreview::Execute( SfxRequest &rReq ) case SID_ATTR_ZOOMSLIDER : { const SfxItemSet *pArgs = rReq.GetArgs(); - const SfxPoolItem* pItem; + const SvxZoomSliderItem* pItem; - if ( pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_ZOOMSLIDER, true, &pItem ) ) + if ( pArgs && (pItem = pArgs->GetItemIfSet(SID_ATTR_ZOOMSLIDER ) ) ) { - const sal_uInt16 nCurrentZoom = static_cast<const SvxZoomSliderItem *>(pItem)->GetValue(); + const sal_uInt16 nCurrentZoom = pItem->GetValue(); SetZoom( SvxZoomType::PERCENT, nCurrentZoom ); } } @@ -1038,8 +1037,7 @@ void SwPagePreview::GetState( SfxItemSet& rSet ) const SfxPoolItem* pItem; SfxItemSetFixed<SID_PRINTDOC, SID_PRINTDOC> aSet( *rSet.GetPool() ); GetSlotState( SID_PRINTDOC, SfxViewShell::GetInterface(), &aSet ); - if( SfxItemState::DISABLED == aSet.GetItemState( SID_PRINTDOC, - false, &pItem )) + if( SfxItemState::DISABLED == aSet.GetItemState( SID_PRINTDOC, false )) rSet.DisableItem( nWhich ); else if( SfxItemState::SET == aSet.GetItemState( SID_PRINTDOC, false, &pItem )) diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx index 0aeb611d5ed4..bd7bc6be0b17 100644 --- a/sw/source/uibase/uiview/view.cxx +++ b/sw/source/uibase/uiview/view.cxx @@ -522,10 +522,10 @@ IMPL_LINK_NOARG(SwView, AttrChangedNotify, LinkParamNone*, void) m_bAttrChgNotified = true; m_aTimer.Start(); - const SfxPoolItem *pItem; - if ( SfxItemState::SET != GetObjectShell()->GetMedium()->GetItemSet()-> - GetItemState( SID_HIDDEN, false, &pItem ) || - !static_cast<const SfxBoolItem*>(pItem)->GetValue() ) + const SfxBoolItem *pItem = + GetObjectShell()->GetMedium()->GetItemSet()-> + GetItemIfSet( SID_HIDDEN, false ); + if ( !pItem || !pItem->GetValue() ) { GetViewFrame()->GetBindings().ENTERREGISTRATIONS(); m_bAttrChgNotifiedWithRegistrations = true; diff --git a/sw/source/uibase/uiview/view2.cxx b/sw/source/uibase/uiview/view2.cxx index 17acec2e3da7..25049e808cbd 100644 --- a/sw/source/uibase/uiview/view2.cxx +++ b/sw/source/uibase/uiview/view2.cxx @@ -977,21 +977,21 @@ void SwView::Execute(SfxRequest &rReq) if( pArgs ) { - if( SfxItemState::SET == pArgs->GetItemState( SID_FILE_NAME, false, &pItem )) - sFileName = static_cast<const SfxStringItem*>(pItem)->GetValue(); + if( const SfxStringItem* pFileItem = pArgs->GetItemIfSet( SID_FILE_NAME, false )) + sFileName = pFileItem->GetValue(); bHasFileName = !sFileName.isEmpty(); - if( SfxItemState::SET == pArgs->GetItemState( SID_FILTER_NAME, false, &pItem )) - sFilterName = static_cast<const SfxStringItem*>(pItem)->GetValue(); + if( const SfxStringItem* pFilterNameItem = pArgs->GetItemIfSet( SID_FILTER_NAME, false )) + sFilterName = pFilterNameItem->GetValue(); - if( SfxItemState::SET == pArgs->GetItemState( SID_VERSION, false, &pItem )) + if( const SfxInt16Item* pVersionItem = pArgs->GetItemIfSet( SID_VERSION, false )) { - nVersion = static_cast<const SfxInt16Item *>(pItem)->GetValue(); + nVersion = pVersionItem->GetValue(); m_pViewImpl->SetParam( nVersion ); } - if( SfxItemState::SET == pArgs->GetItemState( SID_NO_ACCEPT_DIALOG, false, &pItem )) + if( const SfxBoolItem* pDialogItem = pArgs->GetItemIfSet( SID_NO_ACCEPT_DIALOG, false )) { - bNoAcceptDialog = static_cast<const SfxBoolItem *>(pItem)->GetValue(); + bNoAcceptDialog = pDialogItem->GetValue(); } } @@ -1217,21 +1217,25 @@ void SwView::Execute(SfxRequest &rReq) case SID_ATTR_DEFTABSTOP: { - if(pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_DEFTABSTOP, false, &pItem)) + const SfxUInt16Item* pTabStopItem = nullptr; + if(pArgs && (pTabStopItem = pArgs->GetItemIfSet(SID_ATTR_DEFTABSTOP, false))) { SvxTabStopItem aDefTabs( 0, 0, SvxTabAdjust::Default, RES_PARATR_TABSTOP ); - const sal_uInt16 nTab = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); + const sal_uInt16 nTab = pTabStopItem->GetValue(); MakeDefTabs( nTab, aDefTabs ); m_pWrtShell->SetDefault( aDefTabs ); } } break; case SID_ATTR_LANGUAGE : - if(pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_LANGUAGE, false, &pItem)) { - SvxLanguageItem aLang(static_cast<const SvxLanguageItem*>(pItem)->GetLanguage(), RES_CHRATR_LANGUAGE); - m_pWrtShell->SetDefault( aLang ); - lcl_SetAllTextToDefaultLanguage( *m_pWrtShell, RES_CHRATR_LANGUAGE ); + const SvxLanguageItem* pLangItem; + if(pArgs && (pLangItem = pArgs->GetItemIfSet(SID_ATTR_LANGUAGE, false))) + { + SvxLanguageItem aLang(pLangItem->GetLanguage(), RES_CHRATR_LANGUAGE); + m_pWrtShell->SetDefault( aLang ); + lcl_SetAllTextToDefaultLanguage( *m_pWrtShell, RES_CHRATR_LANGUAGE ); + } } break; case SID_ATTR_CHAR_CTL_LANGUAGE: @@ -1958,22 +1962,23 @@ void SwView::ExecuteStatusLine(SfxRequest &rReq) pSet = pDlg->GetOutputItemSet(); } - const SfxPoolItem* pViewLayoutItem = nullptr; - if ( pSet && SfxItemState::SET == pSet->GetItemState(SID_ATTR_VIEWLAYOUT, true, &pViewLayoutItem)) + const SvxViewLayoutItem* pViewLayoutItem = nullptr; + if ( pSet && (pViewLayoutItem = pSet->GetItemIfSet(SID_ATTR_VIEWLAYOUT))) { - const sal_uInt16 nColumns = static_cast<const SvxViewLayoutItem *>(pViewLayoutItem)->GetValue(); - const bool bBookMode = static_cast<const SvxViewLayoutItem *>(pViewLayoutItem)->IsBookMode(); + const sal_uInt16 nColumns = pViewLayoutItem->GetValue(); + const bool bBookMode = pViewLayoutItem->IsBookMode(); SetViewLayout( nColumns, bBookMode ); } - if ( pSet && SfxItemState::SET == pSet->GetItemState(SID_ATTR_ZOOM, true, &pItem)) + const SvxZoomItem* pZoomItem = nullptr; + if ( pSet && (pZoomItem = pSet->GetItemIfSet(SID_ATTR_ZOOM))) { - SvxZoomType eType = static_cast<const SvxZoomItem *>(pItem)->GetType(); - SetZoom( eType, static_cast<const SvxZoomItem *>(pItem)->GetValue() ); + SvxZoomType eType = pZoomItem->GetType(); + SetZoom( eType, pZoomItem->GetValue() ); } bUp = true; - if ( pItem ) - rReq.AppendItem( *pItem ); + if ( pZoomItem ) + rReq.AppendItem( *pZoomItem ); rReq.Done(); } } @@ -1984,11 +1989,10 @@ void SwView::ExecuteStatusLine(SfxRequest &rReq) if ( pArgs && !rSh.getIDocumentSettingAccess().get(DocumentSettingId::BROWSE_MODE) && ( ( GetDocShell()->GetCreateMode() != SfxObjectCreateMode::EMBEDDED ) || !GetDocShell()->IsInPlaceActive() ) ) { - if ( SfxItemState::SET == pArgs->GetItemState(SID_ATTR_VIEWLAYOUT, true, &pItem )) + if ( const SvxViewLayoutItem* pLayoutItem = pArgs->GetItemIfSet(SID_ATTR_VIEWLAYOUT )) { - const sal_uInt16 nColumns = static_cast<const SvxViewLayoutItem *>(pItem)->GetValue(); - const bool bBookMode = (0 != nColumns && 0 == (nColumns % 2)) && - static_cast<const SvxViewLayoutItem *>(pItem)->IsBookMode(); + const sal_uInt16 nColumns = pLayoutItem->GetValue(); + const bool bBookMode = (0 != nColumns && 0 == (nColumns % 2)) && pLayoutItem->IsBookMode(); SetViewLayout( nColumns, bBookMode ); } @@ -2005,9 +2009,9 @@ void SwView::ExecuteStatusLine(SfxRequest &rReq) { if ( pArgs && ( ( GetDocShell()->GetCreateMode() != SfxObjectCreateMode::EMBEDDED ) || !GetDocShell()->IsInPlaceActive() ) ) { - if ( SfxItemState::SET == pArgs->GetItemState(SID_ATTR_ZOOMSLIDER, true, &pItem )) + if ( const SvxZoomSliderItem* pZoomItem = pArgs->GetItemIfSet(SID_ATTR_ZOOMSLIDER) ) { - const sal_uInt16 nCurrentZoom = static_cast<const SvxZoomSliderItem *>(pItem)->GetValue(); + const sal_uInt16 nCurrentZoom = pZoomItem->GetValue(); SetZoom( SvxZoomType::PERCENT, nCurrentZoom ); } @@ -2385,11 +2389,10 @@ static size_t lcl_PageDescWithHeader( const SwDoc& rDoc ) { const SwPageDesc& rPageDesc = rDoc.GetPageDesc( i ); const SwFrameFormat& rMaster = rPageDesc.GetMaster(); - const SfxPoolItem* pItem; - if( ( SfxItemState::SET == rMaster.GetAttrSet().GetItemState( RES_HEADER, false, &pItem ) && - static_cast<const SwFormatHeader*>(pItem)->IsActive() ) || - ( SfxItemState::SET == rMaster.GetAttrSet().GetItemState( RES_FOOTER, false, &pItem ) && - static_cast<const SwFormatFooter*>(pItem)->IsActive()) ) + const SwFormatHeader* pHeaderItem = rMaster.GetAttrSet().GetItemIfSet( RES_HEADER, false ); + const SwFormatFooter* pFooterItem = rMaster.GetAttrSet().GetItemIfSet( RES_FOOTER, false ); + if( (pHeaderItem && pHeaderItem->IsActive()) || + (pFooterItem && pFooterItem->IsActive()) ) ++nRet; } return nRet; // number of page styles with active header/footer diff --git a/sw/source/uibase/uiview/viewprt.cxx b/sw/source/uibase/uiview/viewprt.cxx index 038d9a722df3..162d0469b868 100644 --- a/sw/source/uibase/uiview/viewprt.cxx +++ b/sw/source/uibase/uiview/viewprt.cxx @@ -83,9 +83,9 @@ void SetPrinter( IDocumentDeviceAccess* pIDDA, SfxPrinter const * pNew, bool bWe // Reading Application own printing options from SfxPrinter const SfxItemSet& rSet = pNew->GetOptions(); - const SwAddPrinterItem* pAddPrinterAttr; - if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_ADDPRINTER, false, - reinterpret_cast<const SfxPoolItem**>(&pAddPrinterAttr) ) ) + const SwAddPrinterItem* pAddPrinterAttr = + rSet.GetItemIfSet( FN_PARAM_ADDPRINTER, false ); + if( pAddPrinterAttr ) { if( pIDDA ) pIDDA->setPrintData( *pAddPrinterAttr ); diff --git a/sw/source/uibase/uiview/viewtab.cxx b/sw/source/uibase/uiview/viewtab.cxx index c911971fd314..563d29fab1f5 100644 --- a/sw/source/uibase/uiview/viewtab.cxx +++ b/sw/source/uibase/uiview/viewtab.cxx @@ -701,26 +701,25 @@ void SwView::ExecTabWin( SfxRequest const & rReq ) break; case SID_PARAGRAPH_CHANGE_STATE: { - const SfxPoolItem *fLineIndent, *pLeftIndent, *pRightIndent; if (pReqArgs) { SfxItemSetFixed<RES_LR_SPACE, RES_LR_SPACE> aLRSpaceSet( GetPool() ); rSh.GetCurAttr( aLRSpaceSet ); SvxLRSpaceItem aParaMargin( aLRSpaceSet.Get( RES_LR_SPACE ) ); - if (pReqArgs->GetItemState(SID_PARAGRAPH_FIRST_LINE_INDENT,true,&fLineIndent) == SfxItemState::SET) + if (const SfxStringItem *fLineIndent = pReqArgs->GetItemIfSet(SID_PARAGRAPH_FIRST_LINE_INDENT)) { - const OUString ratio = static_cast<const SfxStringItem*>(fLineIndent)->GetValue(); + const OUString ratio = fLineIndent->GetValue(); aParaMargin.SetTextFirstLineOffset(nPageWidth * ratio.toFloat()); } - else if (pReqArgs->GetItemState(SID_PARAGRAPH_LEFT_INDENT,true,&pLeftIndent) == SfxItemState::SET) + else if (const SfxStringItem *pLeftIndent = pReqArgs->GetItemIfSet(SID_PARAGRAPH_LEFT_INDENT)) { - const OUString ratio = static_cast<const SfxStringItem*>(pLeftIndent)->GetValue(); + const OUString ratio = pLeftIndent->GetValue(); aParaMargin.SetLeft(nPageWidth * ratio.toFloat()); } - else if (pReqArgs->GetItemState(SID_PARAGRAPH_RIGHT_INDENT,true,&pRightIndent) == SfxItemState::SET) + else if (const SfxStringItem *pRightIndent = pReqArgs->GetItemIfSet(SID_PARAGRAPH_RIGHT_INDENT)) { - const OUString ratio = static_cast<const SfxStringItem*>(pRightIndent)->GetValue(); + const OUString ratio = pRightIndent->GetValue(); aParaMargin.SetRight(nPageWidth * ratio.toFloat()); } rSh.SetAttrItem(aParaMargin); @@ -874,18 +873,16 @@ void SwView::ExecTabWin( SfxRequest const & rReq ) break; case SID_RULER_CHANGE_STATE: + if (pReqArgs) { - const SfxPoolItem *pMargin1, *pMargin2; - if ( pReqArgs && - pReqArgs->GetItemState(SID_RULER_MARGIN1,true,&pMargin1) == SfxItemState::SET ) + if ( const SfxStringItem *pMargin1 = pReqArgs->GetItemIfSet(SID_RULER_MARGIN1) ) { - const OUString ratio = static_cast<const SfxStringItem*>(pMargin1)->GetValue(); + const OUString ratio = pMargin1->GetValue(); GetHRuler().SetValues(RulerChangeType::MARGIN1, GetHRuler().GetPageWidth() * ratio.toFloat()); } - else if ( pReqArgs && - pReqArgs->GetItemState(SID_RULER_MARGIN2,true,&pMargin2) == SfxItemState::SET ) + else if ( const SfxStringItem *pMargin2 = pReqArgs->GetItemIfSet(SID_RULER_MARGIN2) ) { - const OUString ratio = static_cast<const SfxStringItem*>(pMargin2)->GetValue(); + const OUString ratio = pMargin2->GetValue(); GetHRuler().SetValues(RulerChangeType::MARGIN2, GetHRuler().GetPageWidth() * ratio.toFloat()); } } @@ -1063,9 +1060,8 @@ void SwView::ExecTabWin( SfxRequest const & rReq ) } } bool bSingleLine = false; - const SfxPoolItem* pSingleLine; - if( SfxItemState::SET == rReq.GetArgs()->GetItemState(SID_RULER_ACT_LINE_ONLY, false, &pSingleLine)) - bSingleLine = static_cast<const SfxBoolItem*>(pSingleLine)->GetValue(); + if( const SfxBoolItem* pSingleLine = rReq.GetArgs()->GetItemIfSet(SID_RULER_ACT_LINE_ONLY, false) ) + bSingleLine = pSingleLine->GetValue(); if ( m_bSetTabRowFromDoc ) { if( !rSh.IsViewLocked() ) @@ -1084,18 +1080,16 @@ void SwView::ExecTabWin( SfxRequest const & rReq ) { if (pReqArgs) { - const SfxPoolItem *pBorderType; - const SfxPoolItem *pIndex; - const SfxPoolItem *pOffset; + const SfxStringItem *pBorderType = pReqArgs->GetItemIfSet(SID_TABLE_BORDER_TYPE); + const SfxUInt16Item *pIndex = pReqArgs->GetItemIfSet(SID_TABLE_BORDER_INDEX); + const SfxInt32Item *pOffset = pReqArgs->GetItemIfSet(SID_TABLE_BORDER_OFFSET); constexpr tools::Long constDistanceOffset = 40; - if (pReqArgs->GetItemState(SID_TABLE_BORDER_TYPE, true, &pBorderType) == SfxItemState::SET - && pReqArgs->GetItemState(SID_TABLE_BORDER_INDEX, true, &pIndex) == SfxItemState::SET - && pReqArgs->GetItemState(SID_TABLE_BORDER_OFFSET, true, &pOffset) == SfxItemState::SET) + if (pBorderType && pIndex && pOffset) { - const OUString sType = static_cast<const SfxStringItem*>(pBorderType)->GetValue(); - const sal_uInt16 nIndex = static_cast<const SfxUInt16Item*>(pIndex)->GetValue(); - const sal_Int32 nOffset = static_cast<const SfxInt32Item*>(pOffset)->GetValue(); + const OUString sType = pBorderType->GetValue(); + const sal_uInt16 nIndex = pIndex->GetValue(); + const sal_Int32 nOffset = pOffset->GetValue(); if (sType.startsWith("column")) { diff --git a/sw/source/uibase/utlui/numfmtlb.cxx b/sw/source/uibase/utlui/numfmtlb.cxx index ee668f4d11a9..0aab232852f0 100644 --- a/sw/source/uibase/utlui/numfmtlb.cxx +++ b/sw/source/uibase/utlui/numfmtlb.cxx @@ -410,20 +410,20 @@ void SwNumFormatBase::CallSelectHdl() if (RET_OK == pDlg->Execute()) { - const SfxPoolItem* pItem = pView->GetDocShell()-> + const SvxNumberInfoItem* pFormatInfoItem = pView->GetDocShell()-> GetItem( SID_ATTR_NUMBERFORMAT_INFO ); - if( pItem ) + if( pFormatInfoItem ) { - for ( sal_uInt32 key : static_cast<const SvxNumberInfoItem*>(pItem)->GetDelFormats() ) + for ( sal_uInt32 key : pFormatInfoItem->GetDelFormats() ) pFormatter->DeleteEntry( key ); } const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); - if( SfxItemState::SET == pOutSet->GetItemState( - SID_ATTR_NUMBERFORMAT_VALUE, false, &pItem )) + if( const SfxUInt32Item* pFormatValueItem = pOutSet->GetItemIfSet( + SID_ATTR_NUMBERFORMAT_VALUE, false )) { - sal_uInt32 nNumberFormat = static_cast<const SfxUInt32Item*>(pItem)->GetValue(); + sal_uInt32 nNumberFormat = pFormatValueItem->GetValue(); // oj #105473# change order of calls const SvNumberformat* pFormat = pFormatter->GetEntry(nNumberFormat); if( pFormat ) @@ -431,10 +431,11 @@ void SwNumFormatBase::CallSelectHdl() // SetDefFormat uses eCurLanguage to look for if this format already in the list SetDefFormat(nNumberFormat); } - if( m_bShowLanguageControl && SfxItemState::SET == pOutSet->GetItemState( - SID_ATTR_NUMBERFORMAT_ADD_AUTO, false, &pItem )) + const SfxBoolItem* pAddAutoItem; + if( m_bShowLanguageControl && (pAddAutoItem = pOutSet->GetItemIfSet( + SID_ATTR_NUMBERFORMAT_ADD_AUTO, false))) { - m_bUseAutomaticLanguage = static_cast<const SfxBoolItem*>(pItem)->GetValue(); + m_bUseAutomaticLanguage = pAddAutoItem->GetValue(); } } else diff --git a/sw/source/uibase/utlui/uitool.cxx b/sw/source/uibase/utlui/uitool.cxx index ff11dc23eae7..51da2892b672 100644 --- a/sw/source/uibase/utlui/uitool.cxx +++ b/sw/source/uibase/utlui/uitool.cxx @@ -82,11 +82,10 @@ using namespace ::com::sun::star; void PrepareBoxInfo(SfxItemSet& rSet, const SwWrtShell& rSh) { std::shared_ptr<SvxBoxInfoItem> aBoxInfo(std::make_shared<SvxBoxInfoItem>(SID_ATTR_BORDER_INNER)); - const SfxPoolItem *pBoxInfo; - if ( SfxItemState::SET == rSet.GetItemState( SID_ATTR_BORDER_INNER, true, &pBoxInfo)) + if ( const SvxBoxInfoItem *pBoxInfo = rSet.GetItemIfSet( SID_ATTR_BORDER_INNER )) { - aBoxInfo.reset(static_cast<SvxBoxInfoItem*>(pBoxInfo->Clone())); + aBoxInfo.reset(pBoxInfo->Clone()); } // Table variant: If more than one table cells are selected @@ -109,10 +108,9 @@ void ConvertAttrCharToGen(SfxItemSet& rSet, bool bIsPara) // Background / highlight { // Always use the visible background - const SfxPoolItem *pTmpBrush; - if( SfxItemState::SET == rSet.GetItemState( RES_CHRATR_HIGHLIGHT, true, &pTmpBrush ) ) + if( const SvxBrushItem *pTmpBrush = rSet.GetItemIfSet( RES_CHRATR_HIGHLIGHT ) ) { - SvxBrushItem aTmpBrush( pTmpBrush->StaticWhichCast(RES_CHRATR_HIGHLIGHT) ); + SvxBrushItem aTmpBrush( *pTmpBrush ); if( aTmpBrush.GetColor() != COL_TRANSPARENT ) { aTmpBrush.SetWhich( RES_CHRATR_BACKGROUND ); @@ -147,17 +145,16 @@ void ConvertAttrCharToGen(SfxItemSet& rSet, bool bIsPara) void ConvertAttrGenToChar(SfxItemSet& rSet, const SfxItemSet& rOrigSet, bool bIsPara) { // Background / highlighting - const SfxPoolItem *pTmpItem; - if( SfxItemState::SET == rSet.GetItemState( RES_CHRATR_BACKGROUND, false, &pTmpItem ) ) + if( SfxItemState::SET == rSet.GetItemState( RES_CHRATR_BACKGROUND, false ) ) { // Highlight is an MS specific thing, so remove it at the first time when LO modifies // this part of the imported document. rSet.Put( SvxBrushItem(RES_CHRATR_HIGHLIGHT) ); // Remove shading marker - if (SfxItemState::SET == rOrigSet.GetItemState(RES_CHRATR_GRABBAG, false, &pTmpItem)) + if (const SfxGrabBagItem* pGrabBagItem = rOrigSet.GetItemIfSet(RES_CHRATR_GRABBAG, false)) { - SfxGrabBagItem aGrabBag(pTmpItem->StaticWhichCast(RES_CHRATR_GRABBAG)); + SfxGrabBagItem aGrabBag(*pGrabBagItem); std::map<OUString, css::uno::Any>& rMap = aGrabBag.GetGrabBag(); auto aIterator = rMap.find("CharShadingMarker"); if( aIterator != rMap.end() ) @@ -173,9 +170,9 @@ void ConvertAttrGenToChar(SfxItemSet& rSet, const SfxItemSet& rOrigSet, bool bIs rSet.ClearItem( RES_BACKGROUND ); - if (SfxItemState::SET == rOrigSet.GetItemState(RES_PARATR_GRABBAG, false, &pTmpItem)) + if (const SfxGrabBagItem* pGrabBagItem = rOrigSet.GetItemIfSet(RES_PARATR_GRABBAG, false)) { - SfxGrabBagItem aGrabBag(pTmpItem->StaticWhichCast(RES_PARATR_GRABBAG)); + SfxGrabBagItem aGrabBag(*pGrabBagItem); std::map<OUString, css::uno::Any>& rMap = aGrabBag.GetGrabBag(); auto aIterator = rMap.find("OrigItemSetRanges"); if (aIterator != rMap.end()) @@ -213,10 +210,9 @@ void ApplyCharBackground(const Color& rBackgroundColor, SwWrtShell& rShell) rShell.SetAttrItem(SvxBrushItem(RES_CHRATR_HIGHLIGHT)); // Remove shading marker - const SfxPoolItem *pTmpItem; - if (SfxItemState::SET == aCoreSet.GetItemState(RES_CHRATR_GRABBAG, false, &pTmpItem)) + if (const SfxGrabBagItem* pGrabBagItem = aCoreSet.GetItemIfSet(RES_CHRATR_GRABBAG, false)) { - SfxGrabBagItem aGrabBag(pTmpItem->StaticWhichCast(RES_CHRATR_GRABBAG)); + SfxGrabBagItem aGrabBag(*pGrabBagItem); std::map<OUString, css::uno::Any>& rMap = aGrabBag.GetGrabBag(); auto aIterator = rMap.find("CharShadingMarker"); if (aIterator != rMap.end()) @@ -286,10 +282,8 @@ void ItemSetToPageDesc( const SfxItemSet& rSet, SwPageDesc& rPageDesc ) // before SetFormatAttr() in case it contains RES_BACKGROUND_FULL_SIZE // itself, as it does when called from SwXPageStyle - SfxPoolItem const* pItem(nullptr); - if (SfxItemState::SET == rSet.GetItemState(SID_ATTR_CHAR_GRABBAG, true, &pItem)) + if (const SfxGrabBagItem* pGrabBag = rSet.GetItemIfSet(SID_ATTR_CHAR_GRABBAG)) { - SfxGrabBagItem const*const pGrabBag(static_cast<SfxGrabBagItem const*>(pItem)); bool bValue; if (pGrabBag->GetGrabBag().find("BackgroundFullSize")->second >>= bValue) { @@ -327,10 +321,10 @@ void ItemSetToPageDesc( const SfxItemSet& rSet, SwPageDesc& rPageDesc ) rMaster.SetFormatAttr(aSize); } // Evaluate header attributes - if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_PAGE_HEADERSET, - false, &pItem ) ) + if( const SvxSetItem* pHeaderSetItem = rSet.GetItemIfSet( SID_ATTR_PAGE_HEADERSET, + false ) ) { - const SfxItemSet& rHeaderSet = static_cast<const SvxSetItem*>(pItem)->GetItemSet(); + const SfxItemSet& rHeaderSet = pHeaderSetItem->GetItemSet(); const SfxBoolItem& rHeaderOn = rHeaderSet.Get(SID_ATTR_PAGE_ON); if(rHeaderOn.GetValue()) @@ -363,10 +357,10 @@ void ItemSetToPageDesc( const SfxItemSet& rSet, SwPageDesc& rPageDesc ) } // Evaluate footer attributes - if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_PAGE_FOOTERSET, - false, &pItem ) ) + if( const SvxSetItem* pFooterSetItem = rSet.GetItemIfSet( SID_ATTR_PAGE_FOOTERSET, + false ) ) { - const SfxItemSet& rFooterSet = static_cast<const SvxSetItem*>(pItem)->GetItemSet(); + const SfxItemSet& rFooterSet = pFooterSetItem->GetItemSet(); const SfxBoolItem& rFooterOn = rFooterSet.Get(SID_ATTR_PAGE_ON); if(rFooterOn.GetValue()) @@ -402,25 +396,26 @@ void ItemSetToPageDesc( const SfxItemSet& rSet, SwPageDesc& rPageDesc ) // Footnotes - if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_FTN_INFO, - false, &pItem ) ) - rPageDesc.SetFootnoteInfo( static_cast<const SwPageFootnoteInfoItem*>(pItem)->GetPageFootnoteInfo() ); + if( const SwPageFootnoteInfoItem* pFootnoteItem = rSet.GetItemIfSet( FN_PARAM_FTN_INFO, + false ) ) + rPageDesc.SetFootnoteInfo( pFootnoteItem->GetPageFootnoteInfo() ); // Columns // Register compliant - if(SfxItemState::SET != rSet.GetItemState( - SID_SWREGISTER_MODE, false, &pItem)) + const SfxBoolItem* pRegisterModeItem = rSet.GetItemIfSet( + SID_SWREGISTER_MODE, false); + if(!pRegisterModeItem) return; - bool bSet = static_cast<const SfxBoolItem*>(pItem)->GetValue(); + bool bSet = pRegisterModeItem->GetValue(); if(!bSet) rPageDesc.SetRegisterFormatColl(nullptr); - else if(SfxItemState::SET == rSet.GetItemState( - SID_SWREGISTER_COLLECTION, false, &pItem)) + else if(const SfxStringItem* pCollectionItem = rSet.GetItemIfSet( + SID_SWREGISTER_COLLECTION, false)) { - const OUString& rColl = static_cast<const SfxStringItem*>(pItem)->GetValue(); + const OUString& rColl = pCollectionItem->GetValue(); SwDoc& rDoc = *rMaster.GetDoc(); SwTextFormatColl* pColl = rDoc.FindTextFormatCollByName( rColl ); if( !pColl ) @@ -484,11 +479,10 @@ void PageDescToItemSet( const SwPageDesc& rPageDesc, SfxItemSet& rSet) rSet.Put(rMaster.GetAttrSet()); std::shared_ptr<SvxBoxInfoItem> aBoxInfo(std::make_shared<SvxBoxInfoItem>(SID_ATTR_BORDER_INNER)); - const SfxPoolItem *pBoxInfo; - if ( SfxItemState::SET == rSet.GetItemState( SID_ATTR_BORDER_INNER, true, &pBoxInfo) ) + if ( const SvxBoxInfoItem *pBoxInfo = rSet.GetItemIfSet( SID_ATTR_BORDER_INNER ) ) { - aBoxInfo.reset(static_cast<SvxBoxInfoItem*>(pBoxInfo->Clone())); + aBoxInfo.reset(pBoxInfo->Clone()); } aBoxInfo->SetTable( false ); @@ -619,10 +613,9 @@ void PageDescToItemSet( const SwPageDesc& rPageDesc, SfxItemSet& rSet) rSet.Put(SfxStringItem(SID_SWREGISTER_COLLECTION, pCol->GetName())); std::optional<SfxGrabBagItem> oGrabBag; - SfxPoolItem const* pItem(nullptr); - if (SfxItemState::SET == rSet.GetItemState(SID_ATTR_CHAR_GRABBAG, true, &pItem)) + if (SfxGrabBagItem const* pItem = rSet.GetItemIfSet(SID_ATTR_CHAR_GRABBAG)) { - oGrabBag.emplace(*static_cast<SfxGrabBagItem const*>(pItem)); + oGrabBag.emplace(*pItem); } else { @@ -687,9 +680,9 @@ void SfxToSwPageDescAttr( const SwWrtShell& rShell, SfxItemSet& rSet ) assert(false); // unexpected break; } - if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_PARA_MODEL, false, &pItem )) + if( const SvxPageModelItem* pModelItem = rSet.GetItemIfSet( SID_ATTR_PARA_MODEL, false )) { - const OUString& rDescName = static_cast<const SvxPageModelItem*>(pItem)->GetValue(); + const OUString& rDescName = pModelItem->GetValue(); if( !rDescName.isEmpty() ) // No name -> disable PageDesc! { // Delete only, if PageDesc will be enabled! @@ -706,9 +699,9 @@ void SfxToSwPageDescAttr( const SwWrtShell& rShell, SfxItemSet& rSet ) { SfxItemSetFixed<RES_PAGEDESC, RES_PAGEDESC> aCoreSet(rShell.GetView().GetPool()); rShell.GetCurAttr( aCoreSet ); - if(SfxItemState::SET == aCoreSet.GetItemState( RES_PAGEDESC, true, &pItem ) ) + if(const SwFormatPageDesc* pPageDescItem = aCoreSet.GetItemIfSet( RES_PAGEDESC ) ) { - auto pPageDesc = pItem->StaticWhichCast(RES_PAGEDESC).GetPageDesc(); + const SwPageDesc* pPageDesc = pPageDescItem->GetPageDesc(); if( pPageDesc ) { aPgDesc.RegisterToPageDesc( *const_cast<SwPageDesc*>(pPageDesc) ); @@ -723,7 +716,7 @@ void SfxToSwPageDescAttr( const SwWrtShell& rShell, SfxItemSet& rSet ) // Inquire if in the set is a Sfx-PageDesc combination present and return it. void SwToSfxPageDescAttr( SfxItemSet& rCoreSet ) { - const SfxPoolItem* pItem = nullptr; + const SwFormatPageDesc* pItem = nullptr; OUString aName; ::std::optional<sal_uInt16> oNumOffset; bool bPut = true; |