cui/source/customize/acccfg.cxx   |    5 -
 cui/source/dialogs/zoom.cxx       |    5 -
 cui/source/inc/align.hxx          |    4 
 cui/source/inc/numpages.hxx       |   13 +-
 cui/source/options/optchart.cxx   |    5 -
 cui/source/options/optgdlg.cxx    |   23 ++--
 cui/source/options/treeopt.cxx    |   19 +---
 cui/source/tabpages/align.cxx     |   32 ++----
 cui/source/tabpages/backgrnd.cxx  |    5 -
 cui/source/tabpages/border.cxx    |   22 ++--
 cui/source/tabpages/chardlg.cxx   |   15 +--
 cui/source/tabpages/grfpage.cxx   |   34 +++----
 cui/source/tabpages/macroass.cxx  |   13 +-
 cui/source/tabpages/numfmt.cxx    |   11 --
 cui/source/tabpages/numpages.cxx  |  180 ++++++++++++++++----------------------
 cui/source/tabpages/page.cxx      |   30 +++---
 cui/source/tabpages/paragrph.cxx  |   15 +--
 cui/source/tabpages/tabstpge.cxx  |   11 --
 cui/source/tabpages/themepage.cxx |    9 -
 cui/source/tabpages/tpbitmap.cxx  |   11 +-
 cui/source/tabpages/tpcolor.cxx   |    5 -
 cui/source/tabpages/tpgradnt.cxx  |   10 +-
 cui/source/tabpages/tphatch.cxx   |   10 +-
 cui/source/tabpages/tpline.cxx    |   13 +-
 cui/source/tabpages/tppattern.cxx |   17 +--
 cui/source/tabpages/tptrans.cxx   |   16 +--
 cui/source/tabpages/transfrm.cxx  |   13 --
 27 files changed, 249 insertions(+), 297 deletions(-)

New commits:
commit e85b482df3fa01e5a2b549df63db96cc49f1ca78
Author:     Noel Grandin <[email protected]>
AuthorDate: Mon Feb 28 12:01:43 2022 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Tue Mar 1 07:49:28 2022 +0100

    use SfxItemSet::GetItemIfSet in cui
    
    Change-Id: I0a6dbf50d29adf9da9512a9136709bf563e478f0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130689
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/cui/source/customize/acccfg.cxx b/cui/source/customize/acccfg.cxx
index 09891003b784..81d1bb10668e 100644
--- a/cui/source/customize/acccfg.cxx
+++ b/cui/source/customize/acccfg.cxx
@@ -1510,10 +1510,9 @@ void SfxAcceleratorConfigPage::Reset(const SfxItemSet* 
rSet)
     RadioHdl(*m_xOfficeButton);
 
 #if HAVE_FEATURE_SCRIPTING
-    const SfxPoolItem* pMacroItem = nullptr;
-    if (SfxItemState::SET == rSet->GetItemState(SID_MACROINFO, true, 
&pMacroItem))
+    if (const SfxMacroInfoItem* pMacroItem = rSet->GetItemIfSet(SID_MACROINFO))
     {
-        m_pMacroInfoItem = &dynamic_cast<const SfxMacroInfoItem&>(*pMacroItem);
+        m_pMacroInfoItem = pMacroItem;
         m_xGroupLBox->SelectMacro(m_pMacroInfoItem);
     }
 #else
diff --git a/cui/source/dialogs/zoom.cxx b/cui/source/dialogs/zoom.cxx
index c1e56d28647d..0c9b189dd0f1 100644
--- a/cui/source/dialogs/zoom.cxx
+++ b/cui/source/dialogs/zoom.cxx
@@ -228,11 +228,8 @@ SvxZoomDialog::SvxZoomDialog(weld::Window* pParent, const 
SfxItemSet& rCoreSet)
         SetFactor(nZoom);
     }
 
-    const SfxPoolItem* pPoolViewLayoutItem = nullptr;
-    if (SfxItemState::SET == m_rSet.GetItemState(SID_ATTR_VIEWLAYOUT, false, 
&pPoolViewLayoutItem))
+    if (const SvxViewLayoutItem* pViewLayoutItem = 
m_rSet.GetItemIfSet(SID_ATTR_VIEWLAYOUT, false))
     {
-        const SvxViewLayoutItem* pViewLayoutItem
-            = static_cast<const SvxViewLayoutItem*>(pPoolViewLayoutItem);
         const sal_uInt16 nColumns = pViewLayoutItem->GetValue();
         const bool bBookMode = pViewLayoutItem->IsBookMode();
 
diff --git a/cui/source/inc/align.hxx b/cui/source/inc/align.hxx
index 2be30aec6c71..7f4b906a3923 100644
--- a/cui/source/inc/align.hxx
+++ b/cui/source/inc/align.hxx
@@ -40,6 +40,8 @@
 #include <svx/frmdirlbox.hxx>
 #include <vcl/weld.hxx>
 
+class SfxEnumItemInterface;
+
 namespace svx {
 
 
@@ -62,7 +64,7 @@ private:
     void                InitVsRefEgde();
     void                UpdateEnableControls();
 
-    bool                HasAlignmentChanged( const SfxItemSet& rNew, 
sal_uInt16 nWhich ) const;
+    bool                HasAlignmentChanged( const SfxItemSet& rNew, 
TypedWhichId<SfxEnumItemInterface> nWhich ) const;
 
     DECL_LINK(UpdateEnableHdl, weld::ComboBox&, void);
     DECL_LINK(StackedClickHdl, weld::Toggleable&, void);
diff --git a/cui/source/inc/numpages.hxx b/cui/source/inc/numpages.hxx
index c4f6961f82b0..8f554722fa67 100644
--- a/cui/source/inc/numpages.hxx
+++ b/cui/source/inc/numpages.hxx
@@ -63,8 +63,7 @@ class SvxSingleNumPickTabPage final : public SfxTabPage
     sal_uInt16              nActNumLvl;
     bool                    bModified   : 1;
     bool                    bPreset     : 1;
-
-    sal_uInt16              nNumItemId;
+    TypedWhichId<SvxNumBulletItem> nNumItemId;
 
     std::unique_ptr<SvxNumValueSet> m_xExamplesVS;
     std::unique_ptr<weld::CustomWeld> m_xExamplesVSWin;
@@ -92,7 +91,7 @@ class SvxBulletPickTabPage final : public SfxTabPage
     sal_uInt16          nActNumLvl;
     bool                bModified   : 1;
     bool                bPreset     : 1;
-    sal_uInt16          nNumItemId;
+    TypedWhichId<SvxNumBulletItem> nNumItemId;
 
     OUString            sBulletCharFormatName;
 
@@ -129,7 +128,7 @@ class SvxNumPickTabPage final : public SfxTabPage
     std::unique_ptr<SvxNumRule> pActNum;
     std::unique_ptr<SvxNumRule> pSaveNum;
     sal_uInt16              nActNumLvl;
-    sal_uInt16              nNumItemId;
+    TypedWhichId<SvxNumBulletItem> nNumItemId;
     bool                bModified   : 1;
     bool                bPreset     : 1;
 
@@ -164,7 +163,7 @@ class SvxBitmapPickTabPage final : public SfxTabPage
     std::unique_ptr<SvxNumRule> pActNum;
     std::unique_ptr<SvxNumRule> pSaveNum;
     sal_uInt16              nActNumLvl;
-    sal_uInt16              nNumItemId;
+    TypedWhichId<SvxNumBulletItem> nNumItemId;
     MapUnit             eCoreUnit;
     bool                bModified   : 1;
     bool                bPreset     : 1;
@@ -216,7 +215,7 @@ class SvxNumOptionsTabPage : public SfxTabPage
 
     sal_uInt8           nBullet;
     sal_uInt16          nActNumLvl;
-    sal_uInt16          nNumItemId;
+    TypedWhichId<SvxNumBulletItem> nNumItemId;
     MapUnit             eCoreUnit;
 
     SvxNumberingPreview m_aPreviewWIN;
@@ -312,7 +311,7 @@ class SvxNumPositionTabPage : public SfxTabPage
 
     ImplSVEvent*        m_pLevelHdlEvent;
     sal_uInt16          nActNumLvl;
-    sal_uInt16          nNumItemId;
+    TypedWhichId<SvxNumBulletItem>  nNumItemId;
     MapUnit             eCoreUnit;
 
     bool                bModified           : 1;
diff --git a/cui/source/options/optchart.cxx b/cui/source/options/optchart.cxx
index b8499c5ee886..af9b92322802 100644
--- a/cui/source/options/optchart.cxx
+++ b/cui/source/options/optchart.cxx
@@ -111,11 +111,10 @@ 
SvxDefaultColorOptPage::SvxDefaultColorOptPage(weld::Container* pPage, weld::Dia
 
     m_SvxChartOptionsUniquePtr.reset(new SvxChartOptions);
 
-    const SfxPoolItem* pItem = nullptr;
-    if ( rInAttrs.GetItemState( SID_SCH_EDITOPTIONS, false, &pItem ) == 
SfxItemState::SET )
+    if ( const SvxChartColorTableItem* pEditOptionsItem = 
rInAttrs.GetItemIfSet( SID_SCH_EDITOPTIONS, false ) )
     {
         m_SvxChartColorTableUniquePtr = std::make_unique<SvxChartColorTable>(
-            static_cast<const SvxChartColorTableItem*>(pItem)->GetColorList());
+            pEditOptionsItem->GetColorList());
     }
     else
     {
diff --git a/cui/source/options/optgdlg.cxx b/cui/source/options/optgdlg.cxx
index f34e59bc3696..fb39369984b9 100644
--- a/cui/source/options/optgdlg.cxx
+++ b/cui/source/options/optgdlg.cxx
@@ -295,10 +295,9 @@ void OfaMiscTabPage::Reset( const SfxItemSet* rSet )
     
m_xDocStatusCB->set_active(officecfg::Office::Common::Print::PrintingModifiesDocument::get());
     m_xDocStatusCB->save_state();
 
-    const SfxPoolItem* pItem = nullptr;
-    if ( SfxItemState::SET == rSet->GetItemState( SID_ATTR_YEAR2000, false, 
&pItem ) )
+    if ( const SfxUInt16Item* pYearItem = rSet->GetItemIfSet( 
SID_ATTR_YEAR2000, false ) )
     {
-        m_xYearValueField->set_value( static_cast<const 
SfxUInt16Item*>(pItem)->GetValue() );
+        m_xYearValueField->set_value( pYearItem->GetValue() );
         TwoFigureHdl(*m_xYearValueField);
     }
     else
@@ -312,6 +311,7 @@ void OfaMiscTabPage::Reset( const SfxItemSet* rSet )
     m_xCrashReport->hide();
 #endif
 
+    const SfxPoolItem* pItem = nullptr;
     SfxItemState eState = rSet->GetItemState( SID_ATTR_QUICKLAUNCHER, false, 
&pItem );
     if ( SfxItemState::SET == eState )
         m_xQuickLaunchCB->set_active( static_cast<const 
SfxBoolItem*>(pItem)->GetValue() );
@@ -1554,24 +1554,23 @@ void OfaLanguagesTabPage::Reset( const SfxItemSet* rSet 
)
     {
         m_xCurrentDocCB->set_sensitive(true);
         m_xCurrentDocCB->set_active(bLanguageCurrentDoc_Impl);
-        const SfxPoolItem* pLang;
-        if( SfxItemState::SET == rSet->GetItemState(SID_ATTR_LANGUAGE, false, 
&pLang))
+        if( const SvxLanguageItem* pLangItem = 
rSet->GetItemIfSet(SID_ATTR_LANGUAGE, false))
         {
-            LanguageType eTempCurLang = static_cast<const 
SvxLanguageItem*>(pLang)->GetValue();
+            LanguageType eTempCurLang = pLangItem->GetValue();
             if (MsLangId::resolveSystemLanguageByScriptType(eCurLang, 
css::i18n::ScriptType::LATIN) != eTempCurLang)
                 eCurLang = eTempCurLang;
         }
 
-        if( SfxItemState::SET == 
rSet->GetItemState(SID_ATTR_CHAR_CJK_LANGUAGE, false, &pLang))
+        if( const SvxLanguageItem* pLang = 
rSet->GetItemIfSet(SID_ATTR_CHAR_CJK_LANGUAGE, false))
         {
-            LanguageType eTempCurLang = static_cast<const 
SvxLanguageItem*>(pLang)->GetValue();
+            LanguageType eTempCurLang = pLang->GetValue();
             if (MsLangId::resolveSystemLanguageByScriptType(eCurLangCJK, 
css::i18n::ScriptType::ASIAN) != eTempCurLang)
                 eCurLangCJK = eTempCurLang;
         }
 
-        if( SfxItemState::SET == 
rSet->GetItemState(SID_ATTR_CHAR_CTL_LANGUAGE, false, &pLang))
+        if( const SvxLanguageItem* pLang = 
rSet->GetItemIfSet(SID_ATTR_CHAR_CTL_LANGUAGE, false))
         {
-            LanguageType eTempCurLang = static_cast<const 
SvxLanguageItem*>(pLang)->GetValue();
+            LanguageType eTempCurLang = pLang->GetValue();
             if (MsLangId::resolveSystemLanguageByScriptType(eCurLangCTL, 
css::i18n::ScriptType::COMPLEX) != eTempCurLang)
                 eCurLangCTL = eTempCurLang;
         }
@@ -1603,8 +1602,8 @@ void OfaLanguagesTabPage::Reset( const SfxItemSet* rSet )
 
     // check the box "For the current document only"
     // set the focus to the Western Language box
-    const SfxPoolItem* pLang = nullptr;
-    if ( SfxItemState::SET == rSet->GetItemState(SID_SET_DOCUMENT_LANGUAGE, 
false, &pLang ) && static_cast<const SfxBoolItem*>(pLang)->GetValue() )
+    const SfxBoolItem* pLang = rSet->GetItemIfSet(SID_SET_DOCUMENT_LANGUAGE, 
false );
+    if ( pLang && pLang->GetValue() )
     {
         m_xWesternLanguageLB->grab_focus();
         m_xCurrentDocCB->set_sensitive(true);
diff --git a/cui/source/options/treeopt.cxx b/cui/source/options/treeopt.cxx
index 9e3bca32e10c..8d274f83ce4c 100644
--- a/cui/source/options/treeopt.cxx
+++ b/cui/source/options/treeopt.cxx
@@ -1186,7 +1186,6 @@ void OfaTreeOptionsDialog::ApplyItemSet( sal_uInt16 nId, 
const SfxItemSet& rSet
         {
             std::shared_ptr<comphelper::ConfigurationChanges> 
batch(comphelper::ConfigurationChanges::create());
 
-            const SfxPoolItem* pItem = nullptr;
             SfxItemSetFixed<SID_ATTR_QUICKLAUNCHER, SID_ATTR_QUICKLAUNCHER> 
aOptSet(SfxGetpApp()->GetPool());
             aOptSet.Put(rSet);
             if(aOptSet.Count())
@@ -1196,26 +1195,26 @@ void OfaTreeOptionsDialog::ApplyItemSet( sal_uInt16 
nId, const SfxItemSet& rSet
 
 //          evaluate Year2000
             sal_uInt16 nY2K = USHRT_MAX;
-            if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_YEAR2000, 
false, &pItem ) )
-                nY2K = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
+            const SfxUInt16Item* pYearItem = rSet.GetItemIfSet( 
SID_ATTR_YEAR2000, false );
+            if( pYearItem )
+                nY2K = pYearItem->GetValue();
             if( USHRT_MAX != nY2K )
             {
                 if ( pViewFrame )
                 {
                     SfxDispatcher* pDispatch = pViewFrame->GetDispatcher();
                     pDispatch->ExecuteList(SID_ATTR_YEAR2000,
-                            SfxCallMode::ASYNCHRON, { pItem });
+                            SfxCallMode::ASYNCHRON, { pYearItem });
                 }
                 officecfg::Office::Common::DateFormat::TwoDigitYear::set(nY2K, 
batch);
             }
 
 //          evaluate print
-            if(SfxItemState::SET == 
rSet.GetItemState(SID_PRINTER_NOTFOUND_WARN, false, &pItem))
-                
officecfg::Office::Common::Print::Warning::NotFound::set(static_cast<const 
SfxBoolItem*>(pItem)->GetValue(), batch);
+            if(const SfxBoolItem* pWarnItem = 
rSet.GetItemIfSet(SID_PRINTER_NOTFOUND_WARN, false))
+                
officecfg::Office::Common::Print::Warning::NotFound::set(pWarnItem->GetValue(), 
batch);
 
-            if(SfxItemState::SET == 
rSet.GetItemState(SID_PRINTER_CHANGESTODOC, false, &pItem))
+            if(const SfxFlagItem* pFlag = 
rSet.GetItemIfSet(SID_PRINTER_CHANGESTODOC, false))
             {
-                const SfxFlagItem* pFlag = static_cast<const 
SfxFlagItem*>(pItem);
                 bool bPaperSizeWarning = 
bool(static_cast<SfxPrinterChangeFlags>(pFlag->GetValue()) &  
SfxPrinterChangeFlags::CHG_SIZE);
                 
officecfg::Office::Common::Print::Warning::PaperSize::set(bPaperSizeWarning, 
batch);
                 bool bPaperOrientationWarning = 
bool(static_cast<SfxPrinterChangeFlags>(pFlag->GetValue()) & 
SfxPrinterChangeFlags::CHG_ORIENTATION);
@@ -1267,10 +1266,8 @@ void OfaTreeOptionsDialog::ApplyLanguageOptions(const 
SfxItemSet& rSet)
 
     Reference< XComponentContext >  xContext( 
::comphelper::getProcessComponentContext() );
     Reference< XLinguProperties >  xProp = LinguProperties::create( xContext );
-    if ( SfxItemState::SET == rSet.GetItemState(SID_ATTR_HYPHENREGION, false, 
&pItem ) )
+    if ( const SfxHyphenRegionItem* pHyphenItem = 
rSet.GetItemIfSet(SID_ATTR_HYPHENREGION, false ) )
     {
-        const SfxHyphenRegionItem* pHyphenItem = static_cast<const 
SfxHyphenRegionItem*>(pItem);
-
         xProp->setHyphMinLeading( 
static_cast<sal_Int16>(pHyphenItem->GetMinLead()) );
         xProp->setHyphMinTrailing( 
static_cast<sal_Int16>(pHyphenItem->GetMinTrail()) );
         bSaveSpellCheck = true;
diff --git a/cui/source/tabpages/align.cxx b/cui/source/tabpages/align.cxx
index 837566e29d22..12e93ae65c43 100644
--- a/cui/source/tabpages/align.cxx
+++ b/cui/source/tabpages/align.cxx
@@ -56,24 +56,23 @@ namespace {
 
 template<typename JustContainerType, typename JustEnumType>
 void lcl_MaybeResetAlignToDistro(
-    weld::ComboBox& rLB, sal_uInt16 nListId, const SfxItemSet& rCoreAttrs, 
sal_uInt16 nWhichAlign, sal_uInt16 nWhichJM, JustEnumType eBlock)
+    weld::ComboBox& rLB, sal_uInt16 nListId, const SfxItemSet& rCoreAttrs, 
TypedWhichId<SfxEnumItemInterface> nWhichAlign, 
TypedWhichId<SfxEnumItemInterface> nWhichJM, JustEnumType eBlock)
 {
-    const SfxPoolItem* pItem;
-    if (rCoreAttrs.GetItemState(nWhichAlign, true, &pItem) != 
SfxItemState::SET)
+    const SfxEnumItemInterface* p = rCoreAttrs.GetItemIfSet(nWhichAlign);
+    if (!p)
         // alignment not set.
         return;
 
-    const SfxEnumItemInterface* p = static_cast<const 
SfxEnumItemInterface*>(pItem);
     JustContainerType eVal = static_cast<JustContainerType>(p->GetEnumValue());
     if (eVal != eBlock)
         // alignment is not 'justify'.  No need to go further.
         return;
 
-    if (rCoreAttrs.GetItemState(nWhichJM, true, &pItem) != SfxItemState::SET)
+    p = rCoreAttrs.GetItemIfSet(nWhichJM);
+    if (!p)
         // justification method is not set.
         return;
 
-    p = static_cast<const SfxEnumItemInterface*>(pItem);
     SvxCellJustifyMethod eMethod = 
static_cast<SvxCellJustifyMethod>(p->GetEnumValue());
     if (eMethod == SvxCellJustifyMethod::Distribute)
     {
@@ -376,12 +375,12 @@ bool AlignmentTabPage::FillItemSet( SfxItemSet* rSet )
 
     // Special treatment for distributed alignment; we need to set the justify
     // method to 'distribute' to distinguish from the normal justification.
-    sal_uInt16 nWhichHorJM = GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY_METHOD);
+    TypedWhichId<SfxEnumItemInterface> 
nWhichHorJM(GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY_METHOD));
     lcl_SetJustifyMethodToItemSet(*rSet, rOldSet, nWhichHorJM, *m_xLbHorAlign, 
ALIGNDLG_HORALIGN_DISTRIBUTED);
     if (!bChanged)
         bChanged = HasAlignmentChanged(*rSet, nWhichHorJM);
 
-    sal_uInt16 nWhichVerJM = GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY_METHOD);
+    TypedWhichId<SfxEnumItemInterface> 
nWhichVerJM(GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY_METHOD));
     lcl_SetJustifyMethodToItemSet(*rSet, rOldSet, nWhichVerJM, *m_xLbVerAlign, 
ALIGNDLG_VERALIGN_DISTRIBUTED);
     if (!bChanged)
         bChanged = HasAlignmentChanged(*rSet, nWhichVerJM);
@@ -622,7 +621,7 @@ void AlignmentTabPage::Reset(const SfxItemSet* pCoreAttrs)
 
     // Special treatment for distributed alignment; we need to set the justify
     // method to 'distribute' to distinguish from the normal justification.
-    sal_uInt16 nHorJustifyMethodWhich = 
GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY_METHOD);
+    TypedWhichId<SfxEnumItemInterface> 
nHorJustifyMethodWhich(GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY_METHOD));
     SfxItemState eHorJustifyMethodState = 
pCoreAttrs->GetItemState(nHorJustifyMethodWhich);
     if (eHorJustifyMethodState == SfxItemState::UNKNOWN)
     {
@@ -636,11 +635,11 @@ void AlignmentTabPage::Reset(const SfxItemSet* pCoreAttrs)
         // feature known, e.g. calc
         lcl_MaybeResetAlignToDistro<SvxCellHorJustify, SvxCellHorJustify>(
             *m_xLbHorAlign, ALIGNDLG_HORALIGN_DISTRIBUTED, *pCoreAttrs,
-            GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY), nHorJustifyMethodWhich,
+            
TypedWhichId<SfxEnumItemInterface>(GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY)), 
nHorJustifyMethodWhich,
             SvxCellHorJustify::Block);
     }
 
-    sal_uInt16 nVerJustifyMethodWhich = 
GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY_METHOD);
+    TypedWhichId<SfxEnumItemInterface> nVerJustifyMethodWhich( 
GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY_METHOD) );
     SfxItemState eVerJustifyMethodState = 
pCoreAttrs->GetItemState(nVerJustifyMethodWhich);
     if (eVerJustifyMethodState == SfxItemState::UNKNOWN)
     {
@@ -654,7 +653,7 @@ void AlignmentTabPage::Reset(const SfxItemSet* pCoreAttrs)
         // feature known, e.g. calc
         lcl_MaybeResetAlignToDistro<SvxCellVerJustify, SvxCellVerJustify>(
             *m_xLbVerAlign, ALIGNDLG_VERALIGN_DISTRIBUTED, *pCoreAttrs,
-            GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY), nVerJustifyMethodWhich,
+            
TypedWhichId<SfxEnumItemInterface>(GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY)), 
nVerJustifyMethodWhich,
             SvxCellVerJustify::Block);
     }
 
@@ -736,21 +735,18 @@ void AlignmentTabPage::UpdateEnableControls()
     m_xNfRotate->set_sensitive(!bHorFill && !bStackedText);
 }
 
-bool AlignmentTabPage::HasAlignmentChanged( const SfxItemSet& rNew, sal_uInt16 
nWhich ) const
+bool AlignmentTabPage::HasAlignmentChanged( const SfxItemSet& rNew, 
TypedWhichId<SfxEnumItemInterface> nWhich ) const
 {
     const SfxItemSet& rOld = GetItemSet();
-    const SfxPoolItem* pItem;
     SvxCellJustifyMethod eMethodOld = SvxCellJustifyMethod::Auto;
     SvxCellJustifyMethod eMethodNew = SvxCellJustifyMethod::Auto;
-    if (rOld.GetItemState(nWhich, true, &pItem) == SfxItemState::SET)
+    if (const SfxEnumItemInterface* p = rOld.GetItemIfSet(nWhich))
     {
-        const SfxEnumItemInterface* p = static_cast<const 
SfxEnumItemInterface*>(pItem);
         eMethodOld = static_cast<SvxCellJustifyMethod>(p->GetEnumValue());
     }
 
-    if (rNew.GetItemState(nWhich, true, &pItem) == SfxItemState::SET)
+    if (const SfxEnumItemInterface* p = rNew.GetItemIfSet(nWhich))
     {
-        const SfxEnumItemInterface* p = static_cast<const 
SfxEnumItemInterface*>(pItem);
         eMethodNew = static_cast<SvxCellJustifyMethod>(p->GetEnumValue());
     }
 
diff --git a/cui/source/tabpages/backgrnd.cxx b/cui/source/tabpages/backgrnd.cxx
index 6b9d906ec907..f1c0765fa70e 100644
--- a/cui/source/tabpages/backgrnd.cxx
+++ b/cui/source/tabpages/backgrnd.cxx
@@ -118,10 +118,9 @@ void SvxBkgTabPage::Reset( const SfxItemSet* )
     if ( m_xTblLBox && m_xTblLBox->get_visible() )
     {
         m_nActPos = -1;
-        const SfxPoolItem* pItem;
-        if ( SfxItemState::SET == m_pResetSet->GetItemState( 
SID_BACKGRND_DESTINATION, false, &pItem ) )
+        if ( const SfxUInt16Item* pDestItem = m_pResetSet->GetItemIfSet( 
SID_BACKGRND_DESTINATION, false ) )
         {
-            sal_uInt16 nDestValue = static_cast<const 
SfxUInt16Item*>(pItem)->GetValue();
+            sal_uInt16 nDestValue = pDestItem->GetValue();
             m_xTblLBox->set_active( nDestValue );
             TblDestinationHdl_Impl( *m_xTblLBox );
         }
diff --git a/cui/source/tabpages/border.cxx b/cui/source/tabpages/border.cxx
index 725ab44da0ee..a37a1454efbf 100644
--- a/cui/source/tabpages/border.cxx
+++ b/cui/source/tabpages/border.cxx
@@ -421,19 +421,16 @@ SvxBorderTabPage::SvxBorderTabPage(weld::Container* 
pPage, weld::DialogControlle
             is needed across various functions... */
     mbUseMarginItem = rCoreAttrs.GetItemState(GetWhich(SID_ATTR_ALIGN_MARGIN)) 
!= SfxItemState::UNKNOWN;
 
-    const SfxPoolItem* pItem = nullptr;
-    if (rCoreAttrs.HasItem(SID_ATTR_BORDER_STYLES, &pItem))
+    if (const SfxIntegerListItem* p = 
rCoreAttrs.GetItemIfSet(SID_ATTR_BORDER_STYLES))
     {
-        const SfxIntegerListItem* p = static_cast<const 
SfxIntegerListItem*>(pItem);
         std::vector<sal_Int32> aUsedStyles = p->GetList();
         for (int aUsedStyle : aUsedStyles)
             
maUsedBorderStyles.insert(static_cast<SvxBorderLineStyle>(aUsedStyle));
     }
 
-    if (rCoreAttrs.HasItem(SID_ATTR_BORDER_DEFAULT_WIDTH, &pItem))
+    if (const SfxInt64Item* p = 
rCoreAttrs.GetItemIfSet(SID_ATTR_BORDER_DEFAULT_WIDTH))
     {
         // The caller specifies default line width.  Honor it.
-        const SfxInt64Item* p = static_cast<const SfxInt64Item*>(pItem);
         SetLineWidth(p->GetValue());
     }
 
@@ -546,6 +543,7 @@ SvxBorderTabPage::SvxBorderTabPage(weld::Container* pPage, 
weld::DialogControlle
     SetLineWidth(m_xLineWidthMF->get_value(FieldUnit::NONE));
 
     // connections
+    const SfxPoolItem* pItem = nullptr;
     if (rCoreAttrs.HasItem(GetWhich(SID_ATTR_PARA_GRABBAG), &pItem))
     {
         const SfxGrabBagItem* pGrabBag = static_cast<const 
SfxGrabBagItem*>(pItem);
@@ -845,13 +843,15 @@ void SvxBorderTabPage::Reset( const SfxItemSet* rSet )
         SelStyleHdl_Impl(*m_xLbLineStyle);
     }
 
-    const SfxPoolItem* pItem;
-    SfxObjectShell* pShell;
-    if(SfxItemState::SET == rSet->GetItemState(SID_HTML_MODE, false, &pItem) ||
-        ( nullptr != (pShell = SfxObjectShell::Current()) &&
-                    nullptr != (pItem = pShell->GetItem(SID_HTML_MODE))))
+    const SfxUInt16Item* pHtmlModeItem = rSet->GetItemIfSet(SID_HTML_MODE, 
false);
+    if(!pHtmlModeItem)
+    {
+        if (SfxObjectShell* pShell = SfxObjectShell::Current())
+            pHtmlModeItem = pShell->GetItem(SID_HTML_MODE);
+    }
+    if(pHtmlModeItem)
     {
-        sal_uInt16 nHtmlMode = static_cast<const 
SfxUInt16Item*>(pItem)->GetValue();
+        sal_uInt16 nHtmlMode = pHtmlModeItem->GetValue();
         if(nHtmlMode & HTMLMODE_ON)
         {
             // there are no shadows in Html-mode and only complete borders
diff --git a/cui/source/tabpages/chardlg.cxx b/cui/source/tabpages/chardlg.cxx
index 1d2fed77c86e..5d71363f0299 100644
--- a/cui/source/tabpages/chardlg.cxx
+++ b/cui/source/tabpages/chardlg.cxx
@@ -1364,13 +1364,16 @@ void SvxCharEffectsPage::Initialize()
     SetExchangeSupport();
 
     // HTML-Mode
-    const SfxPoolItem* pItem;
-    SfxObjectShell* pShell;
-    if ( SfxItemState::SET == GetItemSet().GetItemState( SID_HTML_MODE, false, 
&pItem ) ||
-         ( nullptr != ( pShell = SfxObjectShell::Current() ) &&
-           nullptr != ( pItem = pShell->GetItem( SID_HTML_MODE ) ) ) )
+    const SfxUInt16Item* pHtmlModeItem = GetItemSet().GetItemIfSet( 
SID_HTML_MODE, false );
+    if ( !pHtmlModeItem)
+    {
+        SfxObjectShell* pShell = SfxObjectShell::Current();
+        if (pShell)
+           pHtmlModeItem = pShell->GetItem( SID_HTML_MODE );
+    }
+    if (pHtmlModeItem)
     {
-        m_nHtmlMode = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
+        m_nHtmlMode = pHtmlModeItem->GetValue();
         if ( ( m_nHtmlMode & HTMLMODE_ON ) == HTMLMODE_ON )
         {
             //!!! hide some controls please
diff --git a/cui/source/tabpages/grfpage.cxx b/cui/source/tabpages/grfpage.cxx
index 158e6b2b1e79..d5c7fca425c0 100644
--- a/cui/source/tabpages/grfpage.cxx
+++ b/cui/source/tabpages/grfpage.cxx
@@ -184,7 +184,7 @@ void SvxGrfCropPage::Reset( const SfxItemSet *rSet )
     }
 
     bool bFound = false;
-    if( SfxItemState::SET == rSet->GetItemState( SID_ATTR_GRAF_GRAPHIC, false, 
&pItem ) )
+    if( const SvxBrushItem* pGraphicItem = rSet->GetItemIfSet( 
SID_ATTR_GRAF_GRAPHIC, false ) )
     {
         OUString referer;
         SfxStringItem const * it = static_cast<SfxStringItem const *>(
@@ -192,7 +192,7 @@ void SvxGrfCropPage::Reset( const SfxItemSet *rSet )
         if (it != nullptr) {
             referer = it->GetValue();
         }
-        const Graphic* pGrf = static_cast<const 
SvxBrushItem*>(pItem)->GetGraphic(referer);
+        const Graphic* pGrf = pGraphicItem->GetGraphic(referer);
         if( pGrf )
         {
             m_aOrigSize = GetGrfOrigSize( *pGrf );
@@ -208,8 +208,8 @@ void SvxGrfCropPage::Reset( const SfxItemSet *rSet )
                 m_aExampleWN.SetFrameSize( m_aOrigSize );
 
                 bFound = true;
-                if( !static_cast<const 
SvxBrushItem*>(pItem)->GetGraphicLink().isEmpty() )
-                    m_aGraphicName = static_cast<const 
SvxBrushItem*>(pItem)->GetGraphicLink();
+                if( !pGraphicItem->GetGraphicLink().isEmpty() )
+                    m_aGraphicName = pGraphicItem->GetGraphicLink();
             }
         }
     }
@@ -225,21 +225,21 @@ bool SvxGrfCropPage::FillItemSet(SfxItemSet *rSet)
     if( m_xWidthMF->get_value_changed_from_saved() ||
         m_xHeightMF->get_value_changed_from_saved() )
     {
-        constexpr sal_uInt16 nW = SID_ATTR_GRAF_FRMSIZE;
+        constexpr TypedWhichId<SvxSizeItem> nW = SID_ATTR_GRAF_FRMSIZE;
         FieldUnit eUnit = MapToFieldUnit( rSet->GetPool()->GetMetric( nW ));
 
         std::shared_ptr<SvxSizeItem> aSz(std::make_shared<SvxSizeItem>(nW));
 
         // size could already have been set from another page
         const SfxItemSet* pExSet = GetDialogExampleSet();
-        const SfxPoolItem* pItem = nullptr;
-        if( pExSet && SfxItemState::SET ==pExSet->GetItemState( nW, false, 
&pItem ) )
+        const SvxSizeItem* pSizeItem = nullptr;
+        if( pExSet && (pSizeItem = pExSet->GetItemIfSet( nW, false )) )
         {
-            aSz.reset(static_cast< SvxSizeItem*>(pItem->Clone()));
+            aSz.reset(pSizeItem->Clone());
         }
         else
         {
-            aSz.reset(static_cast< 
SvxSizeItem*>(GetItemSet().Get(nW).Clone()));
+            aSz.reset(GetItemSet().Get(nW).Clone());
         }
 
         Size aTmpSz( aSz->GetSize() );
@@ -298,9 +298,8 @@ void SvxGrfCropPage::ActivatePage(const SfxItemSet& rSet)
 
     // Size
     Size aSize;
-    const SfxPoolItem* pItem;
-    if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_GRAF_FRMSIZE, false, 
&pItem ) )
-        aSize = static_cast<const SvxSizeItem*>(pItem)->GetSize();
+    if( const SvxSizeItem* pFrmSizeItem = rSet.GetItemIfSet( 
SID_ATTR_GRAF_FRMSIZE, false ) )
+        aSize = pFrmSizeItem->GetSize();
 
     m_nOldWidth = aSize.Width();
     m_nOldHeight = aSize.Height();
@@ -316,12 +315,11 @@ void SvxGrfCropPage::ActivatePage(const SfxItemSet& rSet)
         m_xHeightMF->set_value(nHeight, FieldUnit::TWIP);
     m_xHeightMF->save_value();
 
-    if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_GRAF_GRAPHIC, false, 
&pItem ) )
+    if( const SvxBrushItem* pBrushItem = rSet.GetItemIfSet( 
SID_ATTR_GRAF_GRAPHIC, false ) )
     {
-        const SvxBrushItem& rBrush = *static_cast<const SvxBrushItem*>(pItem);
-        if( !rBrush.GetGraphicLink().isEmpty() &&
-            m_aGraphicName != rBrush.GetGraphicLink() )
-            m_aGraphicName = rBrush.GetGraphicLink();
+        if( !pBrushItem->GetGraphicLink().isEmpty() &&
+            m_aGraphicName != pBrushItem->GetGraphicLink() )
+            m_aGraphicName = pBrushItem->GetGraphicLink();
 
         OUString referer;
         SfxStringItem const * it = static_cast<SfxStringItem const *>(
@@ -329,7 +327,7 @@ void SvxGrfCropPage::ActivatePage(const SfxItemSet& rSet)
         if (it != nullptr) {
             referer = it->GetValue();
         }
-        const Graphic* pGrf = rBrush.GetGraphic(referer);
+        const Graphic* pGrf = pBrushItem->GetGraphic(referer);
         if( pGrf )
         {
             m_aExampleWN.SetGraphic( *pGrf );
diff --git a/cui/source/tabpages/macroass.cxx b/cui/source/tabpages/macroass.cxx
index 94143e310ebd..eb98f14ab7d1 100644
--- a/cui/source/tabpages/macroass.cxx
+++ b/cui/source/tabpages/macroass.cxx
@@ -178,11 +178,12 @@ void SfxMacroTabPage::ActivatePage( const SfxItemSet& )
 
 void SfxMacroTabPage::PageCreated(const SfxAllItemSet& aSet)
 {
-    const SfxPoolItem* pEventsItem;
-    if( !mpImpl->m_bGotEvents && SfxItemState::SET == aSet.GetItemState( 
SID_EVENTCONFIG, true, &pEventsItem ) )
+    if( mpImpl->m_bGotEvents )
+        return;
+    if( const SfxEventNamesItem* pEventsItem = aSet.GetItemIfSet( 
SID_EVENTCONFIG ) )
     {
         mpImpl->m_bGotEvents = true;
-        const SfxEventNamesList& rList = static_cast<const 
SfxEventNamesItem*>(pEventsItem)->GetEvents();
+        const SfxEventNamesList& rList = pEventsItem->GetEvents();
         for ( size_t nNo = 0, nCnt = rList.size(); nNo < nCnt; ++nNo )
         {
             const SfxEventName &rOwn = rList.at(nNo);
@@ -197,11 +198,11 @@ void SfxMacroTabPage::Reset( const SfxItemSet* rSet )
     if( SfxItemState::SET == rSet->GetItemState( GetWhich( aPageRg[0] ), true, 
&pItem ))
         aTbl = static_cast<const SvxMacroItem*>(pItem)->GetMacroTable();
 
-    const SfxPoolItem* pEventsItem;
-    if( !mpImpl->m_bGotEvents && SfxItemState::SET == rSet->GetItemState( 
SID_EVENTCONFIG, true, &pEventsItem ) )
+    const SfxEventNamesItem* pEventsItem;
+    if( !mpImpl->m_bGotEvents && (pEventsItem = rSet->GetItemIfSet( 
SID_EVENTCONFIG ) ) )
     {
         mpImpl->m_bGotEvents = true;
-        const SfxEventNamesList& rList = static_cast<const 
SfxEventNamesItem*>(pEventsItem)->GetEvents();
+        const SfxEventNamesList& rList = pEventsItem->GetEvents();
         for ( size_t nNo = 0, nCnt = rList.size(); nNo < nCnt; ++nNo )
         {
             const SfxEventName &rOwn = rList.at(nNo);
diff --git a/cui/source/tabpages/numfmt.cxx b/cui/source/tabpages/numfmt.cxx
index e91bef4a8822..5ef4f7c96b96 100644
--- a/cui/source/tabpages/numfmt.cxx
+++ b/cui/source/tabpages/numfmt.cxx
@@ -360,14 +360,9 @@ void SvxNumberFormatTabPage::Reset( const SfxItemSet* rSet 
)
     double                      nValDouble      = 0;
     OUString                    aValString;
 
-    SfxItemState eState = rSet->GetItemState( 
SID_ATTR_NUMBERFORMAT_NOLANGUAGE,true,&pItem);
-
-    if(eState==SfxItemState::SET)
+    if(const SfxBoolItem* pBoolLangItem = rSet->GetItemIfSet( 
SID_ATTR_NUMBERFORMAT_NOLANGUAGE ))
     {
-        const SfxBoolItem* pBoolLangItem =
-                      GetItem( *rSet, SID_ATTR_NUMBERFORMAT_NOLANGUAGE);
-
-        if(pBoolLangItem!=nullptr && pBoolLangItem->GetValue())
+        if(pBoolLangItem->GetValue())
         {
             HideLanguage();
         }
@@ -378,7 +373,7 @@ void SvxNumberFormatTabPage::Reset( const SfxItemSet* rSet )
 
     }
 
-    eState = rSet->GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_INFO 
),true,&pItem);
+    SfxItemState eState = rSet->GetItemState( GetWhich( 
SID_ATTR_NUMBERFORMAT_INFO ),true,&pItem);
 
     if(eState==SfxItemState::SET)
     {
diff --git a/cui/source/tabpages/numpages.cxx b/cui/source/tabpages/numpages.cxx
index c28743eab125..a7de509c30bd 100644
--- a/cui/source/tabpages/numpages.cxx
+++ b/cui/source/tabpages/numpages.cxx
@@ -227,20 +227,19 @@ bool  SvxSingleNumPickTabPage::FillItemSet( SfxItemSet* 
rSet )
 
 void  SvxSingleNumPickTabPage::ActivatePage(const SfxItemSet& rSet)
 {
-    const SfxPoolItem* pItem;
     bPreset = false;
     bool bIsPreset = false;
     const SfxItemSet* pExampleSet = GetDialogExampleSet();
     if(pExampleSet)
     {
-        if(SfxItemState::SET == 
pExampleSet->GetItemState(SID_PARAM_NUM_PRESET, false, &pItem))
-            bIsPreset = static_cast<const SfxBoolItem*>(pItem)->GetValue();
-        if(SfxItemState::SET == 
pExampleSet->GetItemState(SID_PARAM_CUR_NUM_LEVEL, false, &pItem))
-            nActNumLvl = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
+        if(const SfxBoolItem* pPresetItem = 
pExampleSet->GetItemIfSet(SID_PARAM_NUM_PRESET, false))
+            bIsPreset = pPresetItem->GetValue();
+        if(const SfxUInt16Item* pLevelItem = 
pExampleSet->GetItemIfSet(SID_PARAM_CUR_NUM_LEVEL, false))
+            nActNumLvl = pLevelItem->GetValue();
     }
-    if(SfxItemState::SET == rSet.GetItemState(nNumItemId, false, &pItem))
+    if(const SvxNumBulletItem* pNumItem = rSet.GetItemIfSet(nNumItemId, false))
     {
-        pSaveNum.reset( new SvxNumRule(static_cast<const 
SvxNumBulletItem*>(pItem)->GetNumRule()) );
+        pSaveNum.reset( new SvxNumRule(pNumItem->GetNumRule()) );
     }
     if(pActNum && *pSaveNum != *pActNum)
     {
@@ -279,7 +278,7 @@ void  SvxSingleNumPickTabPage::Reset( const SfxItemSet* 
rSet )
 
         if( eState != SfxItemState::SET )
         {
-            pItem = &static_cast< const SvxNumBulletItem& >( rSet->Get( 
nNumItemId ) );
+            pItem = & rSet->Get( nNumItemId );
             eState = SfxItemState::SET;
         }
     }
@@ -372,20 +371,19 @@ bool  SvxBulletPickTabPage::FillItemSet( SfxItemSet* rSet 
)
 
 void  SvxBulletPickTabPage::ActivatePage(const SfxItemSet& rSet)
 {
-    const SfxPoolItem* pItem;
     bPreset = false;
     bool bIsPreset = false;
     const SfxItemSet* pExampleSet = GetDialogExampleSet();
     if(pExampleSet)
     {
-        if(SfxItemState::SET == 
pExampleSet->GetItemState(SID_PARAM_NUM_PRESET, false, &pItem))
-            bIsPreset = static_cast<const SfxBoolItem*>(pItem)->GetValue();
-        if(SfxItemState::SET == 
pExampleSet->GetItemState(SID_PARAM_CUR_NUM_LEVEL, false, &pItem))
-            nActNumLvl = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
+        if(const SfxBoolItem* pPresetItem = 
pExampleSet->GetItemIfSet(SID_PARAM_NUM_PRESET, false))
+            bIsPreset = pPresetItem->GetValue();
+        if(const SfxUInt16Item* pLevelItem = 
pExampleSet->GetItemIfSet(SID_PARAM_CUR_NUM_LEVEL, false))
+            nActNumLvl = pLevelItem->GetValue();
     }
-    if(SfxItemState::SET == rSet.GetItemState(nNumItemId, false, &pItem))
+    if(const SvxNumBulletItem* pBulletItem = rSet.GetItemIfSet(nNumItemId, 
false))
     {
-        pSaveNum.reset( new SvxNumRule(static_cast<const 
SvxNumBulletItem*>(pItem)->GetNumRule()) );
+        pSaveNum.reset( new SvxNumRule(pBulletItem->GetNumRule()) );
     }
     if(pActNum && *pSaveNum != *pActNum)
     {
@@ -412,23 +410,14 @@ DeactivateRC 
SvxBulletPickTabPage::DeactivatePage(SfxItemSet *_pSet)
 
 void  SvxBulletPickTabPage::Reset( const SfxItemSet* rSet )
 {
-    const SfxPoolItem* pItem;
     // in Draw the item exists as WhichId, in Writer only as SlotId
-    SfxItemState eState = rSet->GetItemState(SID_ATTR_NUMBERING_RULE, false, 
&pItem);
-    if(eState != SfxItemState::SET)
+    const SvxNumBulletItem* pItem = 
rSet->GetItemIfSet(SID_ATTR_NUMBERING_RULE, false);
+    if(!pItem)
     {
         nNumItemId = rSet->GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE);
-        eState = rSet->GetItemState(nNumItemId, false, &pItem);
-
-        if( eState != SfxItemState::SET )
-        {
-            pItem = &static_cast< const SvxNumBulletItem& >( rSet->Get( 
nNumItemId ) );
-            eState = SfxItemState::SET;
-        }
-
+        pItem = rSet->GetItemIfSet(nNumItemId, false);
     }
-    DBG_ASSERT(eState == SfxItemState::SET, "no item found!");
-    pSaveNum.reset( new SvxNumRule(static_cast<const 
SvxNumBulletItem*>(pItem)->GetNumRule()) );
+    pSaveNum.reset( new SvxNumRule(pItem->GetNumRule()) );
 
     if(!pActNum)
         pActNum.reset( new SvxNumRule(*pSaveNum) );
@@ -554,20 +543,19 @@ bool  SvxNumPickTabPage::FillItemSet( SfxItemSet* rSet )
 
 void  SvxNumPickTabPage::ActivatePage(const SfxItemSet& rSet)
 {
-    const SfxPoolItem* pItem;
     bPreset = false;
     bool bIsPreset = false;
     const SfxItemSet* pExampleSet = GetDialogExampleSet();
     if(pExampleSet)
     {
-        if(SfxItemState::SET == 
pExampleSet->GetItemState(SID_PARAM_NUM_PRESET, false, &pItem))
-            bIsPreset = static_cast<const SfxBoolItem*>(pItem)->GetValue();
-        if(SfxItemState::SET == 
pExampleSet->GetItemState(SID_PARAM_CUR_NUM_LEVEL, false, &pItem))
-            nActNumLvl = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
+        if(const SfxBoolItem* pPresetItem = 
pExampleSet->GetItemIfSet(SID_PARAM_NUM_PRESET, false))
+            bIsPreset = pPresetItem->GetValue();
+        if(const SfxUInt16Item* pLevelItem = 
pExampleSet->GetItemIfSet(SID_PARAM_CUR_NUM_LEVEL, false))
+            nActNumLvl = pLevelItem->GetValue();
     }
-    if(SfxItemState::SET == rSet.GetItemState(nNumItemId, false, &pItem))
+    if(const SvxNumBulletItem* pBulletItem = rSet.GetItemIfSet(nNumItemId, 
false))
     {
-        pSaveNum.reset( new SvxNumRule(static_cast<const 
SvxNumBulletItem*>(pItem)->GetNumRule()) );
+        pSaveNum.reset( new SvxNumRule(pBulletItem->GetNumRule()) );
     }
     if(pActNum && *pSaveNum != *pActNum)
     {
@@ -594,23 +582,19 @@ DeactivateRC SvxNumPickTabPage::DeactivatePage(SfxItemSet 
*_pSet)
 
 void  SvxNumPickTabPage::Reset( const SfxItemSet* rSet )
 {
-    const SfxPoolItem* pItem;
     // in Draw the item exists as WhichId, in Writer only as SlotId
-    SfxItemState eState = rSet->GetItemState(SID_ATTR_NUMBERING_RULE, false, 
&pItem);
-    if(eState != SfxItemState::SET)
+    const SvxNumBulletItem* pItem = 
rSet->GetItemIfSet(SID_ATTR_NUMBERING_RULE, false);
+    if(!pItem)
     {
         nNumItemId = rSet->GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE);
-        eState = rSet->GetItemState(nNumItemId, false, &pItem);
+        pItem = rSet->GetItemIfSet(nNumItemId, false);
 
-        if( eState != SfxItemState::SET )
+        if( !pItem )
         {
-            pItem = &static_cast< const SvxNumBulletItem& >( rSet->Get( 
nNumItemId ) );
-            eState = SfxItemState::SET;
+            pItem = & rSet->Get( nNumItemId );
         }
-
     }
-    DBG_ASSERT(eState == SfxItemState::SET, "no item found!");
-    pSaveNum.reset( new SvxNumRule(static_cast<const 
SvxNumBulletItem*>(pItem)->GetNumRule()) );
+    pSaveNum.reset( new SvxNumRule(pItem->GetNumRule()) );
 
     if(!pActNum)
         pActNum.reset( new SvxNumRule(*pSaveNum) );
@@ -784,20 +768,19 @@ std::unique_ptr<SfxTabPage> 
SvxBitmapPickTabPage::Create(weld::Container* pPage,
 
 void  SvxBitmapPickTabPage::ActivatePage(const SfxItemSet& rSet)
 {
-    const SfxPoolItem* pItem;
     bPreset = false;
     bool bIsPreset = false;
     const SfxItemSet* pExampleSet = GetDialogExampleSet();
     if(pExampleSet)
     {
-        if(SfxItemState::SET == 
pExampleSet->GetItemState(SID_PARAM_NUM_PRESET, false, &pItem))
-            bIsPreset = static_cast<const SfxBoolItem*>(pItem)->GetValue();
-        if(SfxItemState::SET == 
pExampleSet->GetItemState(SID_PARAM_CUR_NUM_LEVEL, false, &pItem))
-            nActNumLvl = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
+        if(const SfxBoolItem* pPresetItem = 
pExampleSet->GetItemIfSet(SID_PARAM_NUM_PRESET, false))
+            bIsPreset = pPresetItem->GetValue();
+        if(const SfxUInt16Item* pLevelItem = 
pExampleSet->GetItemIfSet(SID_PARAM_CUR_NUM_LEVEL, false))
+            nActNumLvl = pLevelItem->GetValue();
     }
-    if(SfxItemState::SET == rSet.GetItemState(nNumItemId, false, &pItem))
+    if(const SvxNumBulletItem* pBulletItem = rSet.GetItemIfSet(nNumItemId, 
false))
     {
-        pSaveNum.reset( new SvxNumRule(static_cast<const 
SvxNumBulletItem*>(pItem)->GetNumRule()) );
+        pSaveNum.reset( new SvxNumRule(pBulletItem->GetNumRule()) );
     }
     if(pActNum && *pSaveNum != *pActNum)
     {
@@ -841,23 +824,21 @@ bool  SvxBitmapPickTabPage::FillItemSet( SfxItemSet* rSet 
)
 
 void  SvxBitmapPickTabPage::Reset( const SfxItemSet* rSet )
 {
-    const SfxPoolItem* pItem;
     // in Draw the item exists as WhichId, in Writer only as SlotId
-    SfxItemState eState = rSet->GetItemState(SID_ATTR_NUMBERING_RULE, false, 
&pItem);
-    if(eState != SfxItemState::SET)
+    const SvxNumBulletItem* pItem = 
rSet->GetItemIfSet(SID_ATTR_NUMBERING_RULE, false);
+    if(!pItem)
     {
         nNumItemId = rSet->GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE);
-        eState = rSet->GetItemState(nNumItemId, false, &pItem);
+        pItem = rSet->GetItemIfSet(nNumItemId, false);
 
-        if( eState != SfxItemState::SET )
+        if( !pItem )
         {
-            pItem = &static_cast< const SvxNumBulletItem& >( rSet->Get( 
nNumItemId ) );
-            eState = SfxItemState::SET;
+            pItem = & rSet->Get( nNumItemId );
         }
 
     }
-    DBG_ASSERT(eState == SfxItemState::SET, "no item found!");
-    pSaveNum.reset( new SvxNumRule(static_cast<const 
SvxNumBulletItem*>(pItem)->GetNumRule()) );
+    DBG_ASSERT(pItem, "no item found!");
+    pSaveNum.reset( new SvxNumRule(pItem->GetNumRule()) );
 
     if(!pActNum)
         pActNum.reset( new SvxNumRule(*pSaveNum) );
@@ -1136,19 +1117,18 @@ std::unique_ptr<SfxTabPage> 
SvxNumOptionsTabPage::Create(weld::Container* pPage,
 
 void    SvxNumOptionsTabPage::ActivatePage(const SfxItemSet& rSet)
 {
-    const SfxPoolItem* pItem;
     const SfxItemSet* pExampleSet = GetDialogExampleSet();
     sal_uInt16 nTmpNumLvl = 1;
     if(pExampleSet)
     {
-        if(SfxItemState::SET == 
pExampleSet->GetItemState(SID_PARAM_NUM_PRESET, false, &pItem))
-            bPreset = static_cast<const SfxBoolItem*>(pItem)->GetValue();
-        if(SfxItemState::SET == 
pExampleSet->GetItemState(SID_PARAM_CUR_NUM_LEVEL, false, &pItem))
-            nTmpNumLvl = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
+        if(const SfxBoolItem* pPresetItem = 
pExampleSet->GetItemIfSet(SID_PARAM_NUM_PRESET, false))
+            bPreset = pPresetItem->GetValue();
+        if(const SfxUInt16Item* pLevelItem = 
pExampleSet->GetItemIfSet(SID_PARAM_CUR_NUM_LEVEL, false))
+            nTmpNumLvl = pLevelItem->GetValue();
     }
-    if(SfxItemState::SET == rSet.GetItemState(nNumItemId, false, &pItem))
+    if(const SvxNumBulletItem* pBulletItem = rSet.GetItemIfSet(nNumItemId, 
false))
     {
-        pSaveNum.reset( new SvxNumRule(static_cast<const 
SvxNumBulletItem*>(pItem)->GetNumRule()) );
+        pSaveNum.reset( new SvxNumRule(pBulletItem->GetNumRule()) );
     }
 
     bModified = (!pActNum->Get( 0 ) || bPreset);
@@ -1195,23 +1175,21 @@ bool    SvxNumOptionsTabPage::FillItemSet( SfxItemSet* 
rSet )
 
 void    SvxNumOptionsTabPage::Reset( const SfxItemSet* rSet )
 {
-    const SfxPoolItem* pItem;
     // in Draw the item exists as WhichId, in Writer only as SlotId
-    SfxItemState eState = rSet->GetItemState(SID_ATTR_NUMBERING_RULE, false, 
&pItem);
-    if(eState != SfxItemState::SET)
+    const SvxNumBulletItem* pBulletItem =
+        rSet->GetItemIfSet(SID_ATTR_NUMBERING_RULE, false);
+    if(!pBulletItem)
     {
         nNumItemId = rSet->GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE);
-        eState = rSet->GetItemState(nNumItemId, false, &pItem);
+        pBulletItem = rSet->GetItemIfSet(nNumItemId, false);
 
-        if( eState != SfxItemState::SET )
+        if( !pBulletItem )
         {
-            pItem = &static_cast< const SvxNumBulletItem& >( rSet->Get( 
nNumItemId ) );
-            eState = SfxItemState::SET;
+            pBulletItem = & rSet->Get( nNumItemId );
         }
-
     }
-    DBG_ASSERT(eState == SfxItemState::SET, "no item found!");
-    pSaveNum.reset( new SvxNumRule(static_cast<const 
SvxNumBulletItem*>(pItem)->GetNumRule()) );
+    DBG_ASSERT(pBulletItem, "no item found!");
+    pSaveNum.reset( new SvxNumRule(pBulletItem->GetNumRule()) );
 
     // insert levels
     if (!m_xLevelLB->n_children())
@@ -1253,12 +1231,17 @@ void    SvxNumOptionsTabPage::Reset( const SfxItemSet* 
rSet )
     m_aPreviewWIN.SetNumRule(pActNum.get());
     m_xSameLevelCB->set_active(pActNum->IsContinuousNumbering());
 
-    SfxObjectShell* pShell;
-    if ( SfxItemState::SET == rSet->GetItemState( SID_HTML_MODE, false, &pItem 
)
-         || ( nullptr != ( pShell = SfxObjectShell::Current()) &&
-              nullptr != ( pItem = pShell->GetItem( SID_HTML_MODE ) ) ) )
+    const SfxUInt16Item* pHtmlModeItem =
+        rSet->GetItemIfSet( SID_HTML_MODE, false );
+    if (!pHtmlModeItem)
+    {
+        SfxObjectShell* pShell = SfxObjectShell::Current();
+        if (pShell)
+            pHtmlModeItem = pShell->GetItem( SID_HTML_MODE );
+    }
+    if ( pHtmlModeItem )
     {
-        sal_uInt16 nHtmlMode = static_cast<const 
SfxUInt16Item*>(pItem)->GetValue();
+        sal_uInt16 nHtmlMode = pHtmlModeItem->GetValue();
         bHTMLMode = 0 != (nHtmlMode&HTMLMODE_ON);
     }
 
@@ -2747,19 +2730,18 @@ void SvxNumPositionTabPage::InitControls()
 
 void SvxNumPositionTabPage::ActivatePage(const SfxItemSet& rSet)
 {
-    const SfxPoolItem* pItem;
     sal_uInt16 nTmpNumLvl = 1;
     const SfxItemSet* pExampleSet = GetDialogExampleSet();
     if(pExampleSet)
     {
-        if(SfxItemState::SET == 
pExampleSet->GetItemState(SID_PARAM_NUM_PRESET, false, &pItem))
-            bPreset = static_cast<const SfxBoolItem*>(pItem)->GetValue();
-        if(SfxItemState::SET == 
pExampleSet->GetItemState(SID_PARAM_CUR_NUM_LEVEL, false, &pItem))
-            nTmpNumLvl = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
+        if(const SfxBoolItem* pPresetItem = 
pExampleSet->GetItemIfSet(SID_PARAM_NUM_PRESET, false))
+            bPreset = pPresetItem->GetValue();
+        if(const SfxUInt16Item* pLevelItem = 
pExampleSet->GetItemIfSet(SID_PARAM_CUR_NUM_LEVEL, false))
+            nTmpNumLvl = pLevelItem->GetValue();
     }
-    if(SfxItemState::SET == rSet.GetItemState(nNumItemId, false, &pItem))
+    if(const SvxNumBulletItem* pBulletItem = rSet.GetItemIfSet(nNumItemId, 
false))
     {
-        pSaveNum.reset( new SvxNumRule(static_cast<const 
SvxNumBulletItem*>(pItem)->GetNumRule()) );
+        pSaveNum.reset( new SvxNumRule(pBulletItem->GetNumRule()) );
     }
     bModified = (!pActNum->Get( 0 ) || bPreset);
     if(*pSaveNum != *pActNum ||
@@ -2816,23 +2798,21 @@ bool SvxNumPositionTabPage::FillItemSet( SfxItemSet* 
rSet )
 
 void SvxNumPositionTabPage::Reset( const SfxItemSet* rSet )
 {
-    const SfxPoolItem* pItem;
     // in Draw the item exists as WhichId, in Writer only as SlotId
-    SfxItemState eState = rSet->GetItemState(SID_ATTR_NUMBERING_RULE, false, 
&pItem);
-    if(eState != SfxItemState::SET)
+    const SvxNumBulletItem* pItem =
+        rSet->GetItemIfSet(SID_ATTR_NUMBERING_RULE, false);
+    if(!pItem)
     {
         nNumItemId = rSet->GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE);
-        eState = rSet->GetItemState(nNumItemId, false, &pItem);
+        pItem = rSet->GetItemIfSet(nNumItemId, false);
 
-        if( eState != SfxItemState::SET )
+        if( !pItem )
         {
-            pItem = &static_cast< const SvxNumBulletItem& >( rSet->Get( 
nNumItemId ) );
-            eState = SfxItemState::SET;
+            pItem = & rSet->Get( nNumItemId );
         }
-
     }
-    DBG_ASSERT(eState == SfxItemState::SET, "no item found!");
-    pSaveNum.reset( new SvxNumRule(static_cast<const 
SvxNumBulletItem*>(pItem)->GetNumRule()) );
+    DBG_ASSERT(pItem, "no item found!");
+    pSaveNum.reset( new SvxNumRule(pItem->GetNumRule()) );
 
     // insert levels
     if (!m_xLevelLB->count_selected_rows())
diff --git a/cui/source/tabpages/page.cxx b/cui/source/tabpages/page.cxx
index 36a7874996a2..1acd2076c75e 100644
--- a/cui/source/tabpages/page.cxx
+++ b/cui/source/tabpages/page.cxx
@@ -196,13 +196,16 @@ SvxPageDescPage::SvxPageDescPage(weld::Container* pPage, 
weld::DialogController*
     bool bCJK = SvtCJKOptions::IsAsianTypographyEnabled();
     bool bCTL = aCTLLanguageOptions.IsCTLFontEnabled();
     bool bWeb = false;
-    const SfxPoolItem* pItem;
 
-    SfxObjectShell* pShell;
-    if(SfxItemState::SET == rAttr.GetItemState(SID_HTML_MODE, false, &pItem) ||
-        ( nullptr != (pShell = SfxObjectShell::Current()) &&
-                    nullptr != (pItem = pShell->GetItem(SID_HTML_MODE))))
-        bWeb = 0 != (static_cast<const SfxUInt16Item*>(pItem)->GetValue() & 
HTMLMODE_ON);
+    const SfxUInt16Item* pHtmlModeItem = rAttr.GetItemIfSet(SID_HTML_MODE, 
false);
+    if (!pHtmlModeItem)
+    {
+        SfxObjectShell* pShell = SfxObjectShell::Current();
+        if (pShell)
+            pHtmlModeItem = pShell->GetItem(SID_HTML_MODE);
+    }
+    if (pHtmlModeItem)
+        bWeb = 0 != (pHtmlModeItem->GetValue() & HTMLMODE_ON);
 
     //  fill text flow listbox with valid entries
 
@@ -359,12 +362,11 @@ void SvxPageDescPage::Reset( const SfxItemSet* rSet )
             static_cast<sal_uInt16>(ConvertLong_Impl( 
static_cast<tools::Long>(rULSpace.GetLower()), eUnit )) );
     }
 
-    if (rSet->HasItem(SID_ATTR_CHAR_GRABBAG, &pItem))
+    if (const SfxGrabBagItem* pGragbagItem = 
rSet->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 = pGragbagItem->GetGrabBag().find("GutterAtTop");
+        if (it != pGragbagItem->GetGrabBag().end())
         {
             it->second >>= bGutterAtTop;
         }
@@ -378,17 +380,17 @@ void SvxPageDescPage::Reset( const SfxItemSet* rSet )
             // Left.
             m_xGutterPositionLB->set_active(0);
         }
-        it = rGrabBagItem.GetGrabBag().find("RtlGutter");
+        it = pGragbagItem->GetGrabBag().find("RtlGutter");
         bool bRtlGutter{};
-        if (it != rGrabBagItem.GetGrabBag().end())
+        if (it != pGragbagItem->GetGrabBag().end())
         {
             it->second >>= bRtlGutter;
             m_xRtlGutterCB->set_active(bRtlGutter);
             m_xRtlGutterCB->show();
         }
-        it = rGrabBagItem.GetGrabBag().find("BackgroundFullSize");
+        it = pGragbagItem->GetGrabBag().find("BackgroundFullSize");
         bool isBackgroundFullSize{};
-        if (it != rGrabBagItem.GetGrabBag().end())
+        if (it != pGragbagItem->GetGrabBag().end())
         {
             it->second >>= isBackgroundFullSize;
             m_xBackgroundFullSizeCB->set_active(isBackgroundFullSize);
diff --git a/cui/source/tabpages/paragrph.cxx b/cui/source/tabpages/paragrph.cxx
index e1c9437983cf..32146becdf75 100644
--- a/cui/source/tabpages/paragrph.cxx
+++ b/cui/source/tabpages/paragrph.cxx
@@ -138,13 +138,16 @@ void SetLineSpace_Impl( SvxLineSpacingItem& rLineSpace,
 static sal_uInt16 GetHtmlMode_Impl(const SfxItemSet& rSet)
 {
     sal_uInt16 nHtmlMode = 0;
-    const SfxPoolItem* pItem = nullptr;
-    SfxObjectShell* pShell;
-    if(SfxItemState::SET == rSet.GetItemState(SID_HTML_MODE, false, &pItem) ||
-        ( nullptr != (pShell = SfxObjectShell::Current()) &&
-                    nullptr != (pItem = pShell->GetItem(SID_HTML_MODE))))
+    const SfxUInt16Item* pItem = rSet.GetItemIfSet(SID_HTML_MODE, false);
+    if (!pItem)
     {
-        nHtmlMode = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
+        SfxObjectShell* pShell = SfxObjectShell::Current();
+        if (pShell)
+            pItem = pShell->GetItem(SID_HTML_MODE);
+    }
+    if(pItem)
+    {
+        nHtmlMode = pItem->GetValue();
     }
     return nHtmlMode;
 
diff --git a/cui/source/tabpages/tabstpge.cxx b/cui/source/tabpages/tabstpge.cxx
index 7a4beeb8437e..96431ba20a5d 100644
--- a/cui/source/tabpages/tabstpge.cxx
+++ b/cui/source/tabpages/tabstpge.cxx
@@ -312,10 +312,9 @@ void SvxTabulatorTabPage::InitTabPos_Impl( sal_uInt16 
nTabPos )
     m_xTabBox->clear();
 
     tools::Long nOffset = 0;
-    const SfxPoolItem* pItem = nullptr;
-    if (GetItemSet().GetItemState(SID_ATTR_TABSTOP_OFFSET, true, &pItem) == 
SfxItemState::SET)
+    if (const SfxInt32Item* pOffSetItem = 
GetItemSet().GetItemIfSet(SID_ATTR_TABSTOP_OFFSET))
     {
-        nOffset = static_cast<const SfxInt32Item*>(pItem)->GetValue();
+        nOffset = pOffSetItem->GetValue();
         MapUnit eUnit = 
GetItemSet().GetPool()->GetMetric(GetWhich(SID_ATTR_TABSTOP));
         nOffset = OutputDevice::LogicToLogic(nOffset, eUnit, 
MapUnit::Map100thMM);
     }
@@ -426,12 +425,10 @@ void SvxTabulatorTabPage::NewHdl_Impl(const weld::Button* 
pBtn)
         return;
 
     tools::Long nOffset = 0;
-    const SfxPoolItem* pItem = nullptr;
 
-    if ( GetItemSet().GetItemState( SID_ATTR_TABSTOP_OFFSET, true, &pItem ) ==
-         SfxItemState::SET )
+    if ( const SfxInt32Item* pOffsetItem = GetItemSet().GetItemIfSet( 
SID_ATTR_TABSTOP_OFFSET ) )
     {
-        nOffset = static_cast<const SfxInt32Item*>(pItem)->GetValue();
+        nOffset = pOffsetItem->GetValue();
         MapUnit eUnit = GetItemSet().GetPool()->GetMetric( GetWhich( 
SID_ATTR_TABSTOP ) );
         nOffset = OutputDevice::LogicToLogic( nOffset, eUnit, 
MapUnit::Map100thMM  );
     }
diff --git a/cui/source/tabpages/themepage.cxx 
b/cui/source/tabpages/themepage.cxx
index 8d92376fc1d3..a7ea42801b12 100644
--- a/cui/source/tabpages/themepage.cxx
+++ b/cui/source/tabpages/themepage.cxx
@@ -62,16 +62,15 @@ SvxThemePage::~SvxThemePage() = default;
 
 void SvxThemePage::Reset(const SfxItemSet* pAttrs)
 {
-    const SfxPoolItem* pItem = nullptr;
-    if (!pAttrs->HasItem(SID_ATTR_CHAR_GRABBAG, &pItem))
+    const SfxGrabBagItem* pGrabBagItem = 
pAttrs->GetItemIfSet(SID_ATTR_CHAR_GRABBAG);
+    if (!pGrabBagItem)
     {
         SAL_WARN("cui.tabpages", "SvxThemePage::Reset: no SfxGrabBagItem");
         return;
     }
 
-    const auto& rGrabBagItem = static_cast<const SfxGrabBagItem&>(*pItem);
-    auto itTheme = rGrabBagItem.GetGrabBag().find("Theme");
-    if (itTheme == rGrabBagItem.GetGrabBag().end())
+    auto itTheme = pGrabBagItem->GetGrabBag().find("Theme");
+    if (itTheme == pGrabBagItem->GetGrabBag().end())
     {
         // No theme was defined previously, allow specifying colors.
         m_xDk1->set_sensitive(true);
diff --git a/cui/source/tabpages/tpbitmap.cxx b/cui/source/tabpages/tpbitmap.cxx
index 931a7419f6eb..bf3b742a19d2 100644
--- a/cui/source/tabpages/tpbitmap.cxx
+++ b/cui/source/tabpages/tpbitmap.cxx
@@ -464,15 +464,14 @@ IMPL_LINK_NOARG(SvxBitmapTabPage, ModifyBitmapHdl, 
ValueSet*, void)
     }
     else
     {
-        const SfxPoolItem* pPoolItem = nullptr;
-
-        if(SfxItemState::SET == 
m_rOutAttrs.GetItemState(GetWhich(XATTR_FILLSTYLE), true, &pPoolItem))
+        if(const XFillStyleItem* pFillStyleItem = 
m_rOutAttrs.GetItemIfSet(GetWhich(XATTR_FILLSTYLE)))
         {
-            const drawing::FillStyle eXFS(static_cast<const 
XFillStyleItem*>(pPoolItem)->GetValue());
+            const drawing::FillStyle eXFS(pFillStyleItem->GetValue());
 
-            if((drawing::FillStyle_BITMAP == eXFS) && (SfxItemState::SET == 
m_rOutAttrs.GetItemState(GetWhich(XATTR_FILLBITMAP), true, &pPoolItem)))
+            const XFillBitmapItem* pBitmapItem;
+            if((drawing::FillStyle_BITMAP == eXFS) && (pBitmapItem = 
m_rOutAttrs.GetItemIfSet(GetWhich(XATTR_FILLBITMAP))))
             {
-                pGraphicObject.reset(new GraphicObject(static_cast<const 
XFillBitmapItem*>(pPoolItem)->GetGraphicObject()));
+                pGraphicObject.reset(new 
GraphicObject(pBitmapItem->GetGraphicObject()));
             }
         }
 
diff --git a/cui/source/tabpages/tpcolor.cxx b/cui/source/tabpages/tpcolor.cxx
index 5367fc2ed271..e0e19ff86537 100644
--- a/cui/source/tabpages/tpcolor.cxx
+++ b/cui/source/tabpages/tpcolor.cxx
@@ -198,13 +198,12 @@ void SvxColorTabPage::ActivatePage( const SfxItemSet& )
     if( !pColorList.is() )
         return;
 
-    const SfxPoolItem* pPoolItem = nullptr;
-    if( SfxItemState::SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLCOLOR 
), true, &pPoolItem ) )
+    if( const XFillColorItem* pFillColorItem = rOutAttrs.GetItemIfSet( 
GetWhich( XATTR_FILLCOLOR ) ) )
     {
         SetColorModel( ColorModel::RGB );
         ChangeColorModel();
 
-        const Color aColor = static_cast<const 
XFillColorItem*>(pPoolItem)->GetColorValue();
+        const Color aColor = pFillColorItem->GetColorValue();
         ChangeColor( aColor );
         sal_Int32 nPos = FindInPalette( aColor );
 
diff --git a/cui/source/tabpages/tpgradnt.cxx b/cui/source/tabpages/tpgradnt.cxx
index c436874189f0..31a846d9cb96 100644
--- a/cui/source/tabpages/tpgradnt.cxx
+++ b/cui/source/tabpages/tpgradnt.cxx
@@ -503,13 +503,13 @@ void SvxGradientTabPage::ChangeGradientHdl_Impl()
         pGradient.reset(new XGradient( m_pGradientList->GetGradient( 
static_cast<sal_uInt16>( nPos ) )->GetGradient() ));
     else
     {
-        const SfxPoolItem* pPoolItem = nullptr;
-        if( SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( 
XATTR_FILLSTYLE ), true, &pPoolItem ) )
+        if( const XFillStyleItem* pFillStyleItem = m_rOutAttrs.GetItemIfSet( 
GetWhich( XATTR_FILLSTYLE ) ) )
         {
-            if( ( drawing::FillStyle_GRADIENT == static_cast<const 
XFillStyleItem*>( pPoolItem )->GetValue() ) &&
-                ( SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( 
XATTR_FILLGRADIENT ), true, &pPoolItem ) ) )
+            const XFillGradientItem* pGradientItem;
+            if( ( drawing::FillStyle_GRADIENT == pFillStyleItem->GetValue() ) 
&&
+                ( pGradientItem = m_rOutAttrs.GetItemIfSet( GetWhich( 
XATTR_FILLGRADIENT ) ) ) )
             {
-                pGradient.reset(new XGradient( static_cast<const 
XFillGradientItem*>( pPoolItem )->GetGradientValue() ));
+                pGradient.reset(new XGradient( 
pGradientItem->GetGradientValue() ));
             }
         }
         if( !pGradient )
diff --git a/cui/source/tabpages/tphatch.cxx b/cui/source/tabpages/tphatch.cxx
index b5f492aff646..1a35114739fc 100644
--- a/cui/source/tabpages/tphatch.cxx
+++ b/cui/source/tabpages/tphatch.cxx
@@ -358,13 +358,13 @@ void SvxHatchTabPage::ChangeHatchHdl_Impl()
         pHatch.reset(new XHatch( m_pHatchingList->GetHatch( 
static_cast<sal_uInt16>(nPos) )->GetHatch() ));
     else
     {
-        const SfxPoolItem* pPoolItem = nullptr;
-        if( SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( 
XATTR_FILLSTYLE ), true, &pPoolItem ) )
+        if( const XFillStyleItem* pFillStyleItem = m_rOutAttrs.GetItemIfSet( 
GetWhich( XATTR_FILLSTYLE ) ) )
         {
-            if( ( drawing::FillStyle_HATCH == static_cast<const 
XFillStyleItem*>( pPoolItem )->GetValue() ) &&
-                ( SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( 
XATTR_FILLHATCH ), true, &pPoolItem ) ) )
+            const XFillHatchItem* pFillHatchItem;
+            if( ( drawing::FillStyle_HATCH == pFillStyleItem->GetValue() ) &&
+                ( pFillHatchItem = m_rOutAttrs.GetItemIfSet( GetWhich( 
XATTR_FILLHATCH ) ) ) )
             {
-                pHatch.reset(new XHatch( static_cast<const XFillHatchItem*>( 
pPoolItem )->GetHatchValue() ));
+                pHatch.reset(new XHatch( pFillHatchItem->GetHatchValue() ));
             }
         }
         if( !pHatch )
diff --git a/cui/source/tabpages/tpline.cxx b/cui/source/tabpages/tpline.cxx
index 14f202e347d9..60321ae9f3aa 100644
--- a/cui/source/tabpages/tpline.cxx
+++ b/cui/source/tabpages/tpline.cxx
@@ -785,15 +785,14 @@ void SvxLineTabPage::Reset( const SfxItemSet* rAttrs )
     drawing::LineStyle  eXLS; // drawing::LineStyle_NONE, 
drawing::LineStyle_SOLID, drawing::LineStyle_DASH
 
     // Line style
-    const SfxPoolItem *pPoolItem;
     tools::Long nSymType=SVX_SYMBOLTYPE_UNKNOWN;
     bool bPrevSym=false;
     bool bEnable=true;
     bool bIgnoreGraphic=false;
     bool bIgnoreSize=false;
-    
if(rAttrs->GetItemState(rAttrs->GetPool()->GetWhich(SID_ATTR_SYMBOLTYPE),true,&pPoolItem)
 == SfxItemState::SET)
+    if(const SfxInt32Item* pSymbolTypeItem = 
rAttrs->GetItemIfSet(rAttrs->GetPool()->GetWhich(SID_ATTR_SYMBOLTYPE)))
     {
-        nSymType=static_cast<const SfxInt32Item *>(pPoolItem)->GetValue();
+        nSymType = pSymbolTypeItem->GetValue();
     }
 
     if(nSymType == SVX_SYMBOLTYPE_AUTO)
@@ -878,9 +877,9 @@ void SvxLineTabPage::Reset( const SfxItemSet* rAttrs )
         }
         }
     }
-    
if(rAttrs->GetItemState(rAttrs->GetPool()->GetWhich(SID_ATTR_BRUSH),true,&pPoolItem)
 == SfxItemState::SET)
+    if(const SvxBrushItem* pBrushItem = 
rAttrs->GetItemIfSet(rAttrs->GetPool()->GetWhich(SID_ATTR_BRUSH)))
     {
-        const Graphic* pGraphic = static_cast<const SvxBrushItem 
*>(pPoolItem)->GetGraphic();
+        const Graphic* pGraphic = pBrushItem->GetGraphic();
         if( pGraphic )
         {
             if(!bIgnoreGraphic)
@@ -897,9 +896,9 @@ void SvxLineTabPage::Reset( const SfxItemSet* rAttrs )
         }
     }
 
-    
if(rAttrs->GetItemState(rAttrs->GetPool()->GetWhich(SID_ATTR_SYMBOLSIZE),true,&pPoolItem)
 == SfxItemState::SET)
+    if(const SvxSizeItem* pSymbolSizeItem = 
rAttrs->GetItemIfSet(rAttrs->GetPool()->GetWhich(SID_ATTR_SYMBOLSIZE)))
     {
-        m_aSymbolSize = static_cast<const SvxSizeItem *>(pPoolItem)->GetSize();
+        m_aSymbolSize = pSymbolSizeItem->GetSize();
     }
 
     m_xGridIconSize->set_sensitive(bEnable);
diff --git a/cui/source/tabpages/tppattern.cxx 
b/cui/source/tabpages/tppattern.cxx
index 4fc5571fee55..4976a0a0edd3 100644
--- a/cui/source/tabpages/tppattern.cxx
+++ b/cui/source/tabpages/tppattern.cxx
@@ -253,15 +253,14 @@ IMPL_LINK_NOARG(SvxPatternTabPage, ChangePatternHdl_Impl, 
ValueSet*, void)
     }
     else
     {
-        const SfxPoolItem* pPoolItem = nullptr;
-
-        if(SfxItemState::SET == 
m_rOutAttrs.GetItemState(GetWhich(XATTR_FILLSTYLE), true, &pPoolItem))
+        if(const XFillStyleItem* pFillStyleItem = 
m_rOutAttrs.GetItemIfSet(GetWhich(XATTR_FILLSTYLE)))
         {
-            const drawing::FillStyle eXFS(static_cast<const 
XFillStyleItem*>(pPoolItem)->GetValue());
+            const drawing::FillStyle eXFS(pFillStyleItem->GetValue());
 
-            if((drawing::FillStyle_BITMAP == eXFS) && (SfxItemState::SET == 
m_rOutAttrs.GetItemState(GetWhich(XATTR_FILLBITMAP), true, &pPoolItem)))
+            const XFillBitmapItem* pBitmapItem;
+            if((drawing::FillStyle_BITMAP == eXFS) && (pBitmapItem = 
m_rOutAttrs.GetItemIfSet(GetWhich(XATTR_FILLBITMAP))))
             {
-                pGraphicObject.reset(new GraphicObject(static_cast<const 
XFillBitmapItem*>(pPoolItem)->GetGraphicObject()));
+                pGraphicObject.reset(new 
GraphicObject(pBitmapItem->GetGraphicObject()));
             }
         }
 
@@ -370,12 +369,8 @@ IMPL_LINK_NOARG(SvxPatternTabPage, ClickAddHdl_Impl, 
weld::Button&, void)
         }
         else // it must be a not existing imported bitmap
         {
-            const SfxPoolItem* pPoolItem = nullptr;
-
-            if(SfxItemState::SET == m_rOutAttrs.GetItemState(XATTR_FILLBITMAP, 
true, &pPoolItem))
+            if(const XFillBitmapItem* pFillBmpItem = 
m_rOutAttrs.GetItemIfSet(XATTR_FILLBITMAP))
             {
-                auto pFillBmpItem = dynamic_cast<const 
XFillBitmapItem*>(pPoolItem);
-                assert(pFillBmpItem);
                 pEntry.reset(new 
XBitmapEntry(pFillBmpItem->GetGraphicObject(), aName));
             }
             else
diff --git a/cui/source/tabpages/tptrans.cxx b/cui/source/tabpages/tptrans.cxx
index e78fcfffe16d..75180022f3a1 100644
--- a/cui/source/tabpages/tptrans.cxx
+++ b/cui/source/tabpages/tptrans.cxx
@@ -347,20 +347,20 @@ bool SvxTransparenceTabPage::FillItemSet(SfxItemSet* 
rAttrs)
 
 void SvxTransparenceTabPage::Reset(const SfxItemSet* rAttrs)
 {
-    const SfxPoolItem* pGradientItem = nullptr;
-    SfxItemState 
eStateGradient(rAttrs->GetItemState(XATTR_FILLFLOATTRANSPARENCE, true, 
&pGradientItem));
+    const XFillFloatTransparenceItem* pGradientItem =
+        rAttrs->GetItemIfSet(XATTR_FILLFLOATTRANSPARENCE);
+    bool bGradActive = (pGradientItem && pGradientItem->IsEnabled());
     if(!pGradientItem)
         pGradientItem = &rAttrs->Get(XATTR_FILLFLOATTRANSPARENCE);
-    bool bGradActive = (eStateGradient == SfxItemState::SET && 
static_cast<const XFillFloatTransparenceItem*>(pGradientItem)->IsEnabled());
 
-    const SfxPoolItem* pLinearItem = nullptr;
-    SfxItemState eStateLinear(rAttrs->GetItemState(XATTR_FILLTRANSPARENCE, 
true, &pLinearItem));
+    const XFillTransparenceItem* pLinearItem =
+        rAttrs->GetItemIfSet(XATTR_FILLTRANSPARENCE);
+    bool bLinearActive = (pLinearItem && pLinearItem->GetValue() != 0);
     if(!pLinearItem)
         pLinearItem = &rAttrs->Get(XATTR_FILLTRANSPARENCE);
-    bool bLinearActive = (eStateLinear == SfxItemState::SET && 
static_cast<const XFillTransparenceItem*>(pLinearItem)->GetValue() != 0);
 
     // transparence gradient
-    const XGradient& rGradient = static_cast<const 
XFillFloatTransparenceItem*>(pGradientItem)->GetGradientValue();
+    const XGradient& rGradient = pGradientItem->GetGradientValue();
     css::awt::GradientStyle eXGS(rGradient.GetGradientStyle());
     m_xLbTrgrGradientType->set_active(sal::static_int_cast< sal_Int32 >(eXGS));
     m_xMtrTrgrAngle->set_value(rGradient.GetAngle().get() / 10, 
FieldUnit::DEGREE);
@@ -371,7 +371,7 @@ void SvxTransparenceTabPage::Reset(const SfxItemSet* rAttrs)
     
m_xMtrTrgrEndValue->set_value(static_cast<sal_uInt16>(((static_cast<sal_uInt16>(rGradient.GetEndColor().GetRed())
 + 1) * 100) / 255), FieldUnit::PERCENT);
 
     // linear transparence
-    sal_uInt16 nTransp = static_cast<const 
XFillTransparenceItem*>(pLinearItem)->GetValue();
+    sal_uInt16 nTransp = pLinearItem->GetValue();
     m_xMtrTransparent->set_value(bLinearActive ? nTransp : 50, 
FieldUnit::PERCENT);
     ModifyTransparentHdl_Impl(*m_xMtrTransparent);
 
diff --git a/cui/source/tabpages/transfrm.cxx b/cui/source/tabpages/transfrm.cxx
index 8ebe0af11597..c9fd14095b9d 100644
--- a/cui/source/tabpages/transfrm.cxx
+++ b/cui/source/tabpages/transfrm.cxx
@@ -289,8 +289,7 @@ std::unique_ptr<SfxTabPage> 
SvxAngleTabPage::Create(weld::Container* pPage, weld
 
 void SvxAngleTabPage::ActivatePage(const SfxItemSet& rSet)
 {
-    SfxBoolItem const * bPosProtect = nullptr;
-    if(SfxItemState::SET == rSet.GetItemState( SID_ATTR_TRANSFORM_PROTECT_POS, 
false, reinterpret_cast<SfxPoolItem const **>(&bPosProtect) ))
+    if(SfxBoolItem const * bPosProtect = rSet.GetItemIfSet( 
SID_ATTR_TRANSFORM_PROTECT_POS, false ))
     {
         m_xFlPosition->set_sensitive(!bPosProtect->GetValue());
         m_xFlAngle->set_sensitive(!bPosProtect->GetValue());
@@ -689,13 +688,11 @@ std::unique_ptr<SfxTabPage> 
SvxSlantTabPage::Create(weld::Container* pPage, weld
 
 void SvxSlantTabPage::ActivatePage( const SfxItemSet& rSet )
 {
-    SfxBoolItem const * bPosProtect = nullptr;
-    if(SfxItemState::SET == rSet.GetItemState( SID_ATTR_TRANSFORM_PROTECT_POS, 
false, reinterpret_cast<SfxPoolItem const **>(&bPosProtect) ))
+    if(SfxBoolItem const * bPosProtect = rSet.GetItemIfSet( 
SID_ATTR_TRANSFORM_PROTECT_POS, false ))
     {
         m_xFlAngle->set_sensitive(!bPosProtect->GetValue());
     }
-    SfxBoolItem const * bSizeProtect = nullptr;
-    if(SfxItemState::SET == rSet.GetItemState( 
SID_ATTR_TRANSFORM_PROTECT_SIZE, false, reinterpret_cast<SfxPoolItem const 
**>(&bSizeProtect) ))
+    if(SfxBoolItem const * bSizeProtect = rSet.GetItemIfSet( 
SID_ATTR_TRANSFORM_PROTECT_SIZE, false ))
     {
         m_xFlAngle->set_sensitive(!bSizeProtect->GetValue());
     }
@@ -1105,9 +1102,7 @@ std::unique_ptr<SfxTabPage> 
SvxPositionSizeTabPage::Create(weld::Container* pPag
 
 void SvxPositionSizeTabPage::ActivatePage( const SfxItemSet& rSet )
 {
-    SfxRectangleItem const * pRectItem = nullptr;
-
-    if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_TRANSFORM_INTERN, 
false, reinterpret_cast<SfxPoolItem const **>(&pRectItem) ) )
+    if( SfxRectangleItem const * pRectItem = rSet.GetItemIfSet( 
SID_ATTR_TRANSFORM_INTERN, false ) )
     {
         { // #i75273#
             const ::tools::Rectangle aTempRect(pRectItem->GetValue());

Reply via email to