sw/source/uibase/app/apphdl.cxx | 8 - sw/source/uibase/app/appopt.cxx | 44 +++------- sw/source/uibase/app/docsh.cxx | 38 ++++----- sw/source/uibase/app/docsh2.cxx | 26 +++--- sw/source/uibase/app/docst.cxx | 34 +++----- sw/source/uibase/app/docstyle.cxx | 17 +--- sw/source/uibase/dialog/regionsw.cxx | 37 ++++----- sw/source/uibase/docvw/HeaderFooterWin.cxx | 5 - sw/source/uibase/frmdlg/colex.cxx | 5 - sw/source/uibase/frmdlg/frmmgr.cxx | 15 +-- sw/source/uibase/shells/annotsh.cxx | 28 ++---- sw/source/uibase/shells/basesh.cxx | 5 - sw/source/uibase/shells/drawdlg.cxx | 16 +-- sw/source/uibase/shells/drwbassh.cxx | 64 +++++++-------- sw/source/uibase/shells/drwtxtex.cxx | 23 ++--- sw/source/uibase/shells/drwtxtsh.cxx | 10 -- sw/source/uibase/shells/frmsh.cxx | 115 +++++++++++++--------------- sw/source/uibase/shells/grfsh.cxx | 55 ++++++------- sw/source/uibase/shells/tabsh.cxx | 78 +++++++++--------- sw/source/uibase/shells/textfld.cxx | 45 +++++----- sw/source/uibase/shells/textsh.cxx | 27 ++---- sw/source/uibase/shells/textsh1.cxx | 42 ++++------ sw/source/uibase/shells/textsh2.cxx | 53 +++++------- sw/source/uibase/shells/txtattr.cxx | 7 - sw/source/uibase/shells/txtcrsr.cxx | 9 -- sw/source/uibase/shells/txtnum.cxx | 14 +-- sw/source/uibase/uiview/formatclipboard.cxx | 51 +++++------- sw/source/uibase/uiview/pview.cxx | 20 ++-- sw/source/uibase/uiview/view.cxx | 8 - sw/source/uibase/uiview/view2.cxx | 71 +++++++++-------- sw/source/uibase/uiview/viewprt.cxx | 6 - sw/source/uibase/uiview/viewtab.cxx | 46 ++++------- sw/source/uibase/utlui/numfmtlb.cxx | 19 ++-- sw/source/uibase/utlui/uitool.cxx | 81 +++++++++---------- 34 files changed, 519 insertions(+), 603 deletions(-)
New commits: commit 0a1031a9ecd1502b1841bde26dde7ad51358c638 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu Mar 3 09:56:09 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Mar 3 19:19:39 2022 +0100 use SfxItemSet::GetItemIfSet in sw/source/uibase Change-Id: Ic82df8d321ba2eb94957236264c71c5eb9a940a7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130905 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> 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) ... etc. - the rest is truncated