sw/source/core/txtnode/ndtxt.cxx  |   59 +++--------
 sw/source/core/txtnode/swfont.cxx |  198 ++++++++++++++------------------------
 sw/source/core/txtnode/thints.cxx |   17 ---
 3 files changed, 97 insertions(+), 177 deletions(-)

New commits:
commit 09b50bcd11e35e68b5b303666bfeaec89d6c6ed8
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Mar 2 17:59:03 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Mar 3 08:52:24 2022 +0100

    use SfxItemSet::GetItemIfSet in sw/source/core/txtnode
    
    Change-Id: I3b6315e987899476ec46b3d7ec98f085a5cd598e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130881
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index 8bf495792385..349433958147 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -81,6 +81,7 @@
 #include <unoparagraph.hxx>
 #include <wrtsh.hxx>
 #include <frameformats.hxx>
+#include <fmtpdsc.hxx>
 #include <svx/sdr/attribute/sdrallfillattributeshelper.hxx>
 #include <svl/itemiter.hxx>
 
@@ -754,8 +755,8 @@ SwTextNode *SwTextNode::SplitContentNode(const SwPosition & 
rPos,
         // Send Hint for PageDesc. This should be done in the Layout when
         // pasting the frames, but that causes other problems that look
         // expensive to solve.
-        const SfxPoolItem *pItem;
-        if(HasWriterListeners() && SfxItemState::SET == 
pNode->GetSwAttrSet().GetItemState(RES_PAGEDESC, true, &pItem))
+        const SwFormatPageDesc *pItem;
+        if(HasWriterListeners() && (pItem = 
pNode->GetSwAttrSet().GetItemIfSet(RES_PAGEDESC)))
             pNode->TriggerNodeUpdate(sw::LegacyModifyHint(pItem, pItem));
     }
     return pNode;
@@ -3791,7 +3792,6 @@ namespace {
             }
             case RES_ATTRSET_CHG:
             {
-                const SfxPoolItem* pItem = nullptr;
                 const SwNumRule* pFormerNumRuleAtTextNode =
                     rTextNode.GetNum() ? rTextNode.GetNum()->GetNumRule() : 
nullptr;
                 if ( pFormerNumRuleAtTextNode )
@@ -3800,7 +3800,7 @@ namespace {
                 }
 
                 const SwAttrSetChg* pSet = dynamic_cast<const 
SwAttrSetChg*>(pNewValue);
-                if ( pSet && pSet->GetChgSet()->GetItemState( 
RES_PARATR_NUMRULE, false, &pItem ) ==
+                if ( pSet && pSet->GetChgSet()->GetItemState( 
RES_PARATR_NUMRULE, false ) ==
                         SfxItemState::SET )
                 {
                     // #i70748#
@@ -4690,15 +4690,11 @@ namespace {
           // #i70748#
           mbOutlineLevelSet( false )
     {
-        const SfxPoolItem* pItem = nullptr;
         // handle RES_PARATR_NUMRULE
-        if ( rItemSet.GetItemState( RES_PARATR_NUMRULE, false, &pItem ) == 
SfxItemState::SET )
+        if ( const SwNumRuleItem* pNumRuleItem = rItemSet.GetItemIfSet( 
RES_PARATR_NUMRULE, false ) )
         {
             mrTextNode.RemoveFromList();
 
-            const SwNumRuleItem* pNumRuleItem =
-                            dynamic_cast<const SwNumRuleItem*>(pItem);
-            assert(pNumRuleItem);
             if ( !pNumRuleItem->GetValue().isEmpty() )
             {
                 mbAddTextNodeToList = true;
@@ -4708,13 +4704,10 @@ namespace {
         }
 
         // handle RES_PARATR_LIST_ID
-        if ( rItemSet.GetItemState( RES_PARATR_LIST_ID, false, &pItem ) == 
SfxItemState::SET )
+        if ( const SfxStringItem* pListIdItem = rItemSet.GetItemIfSet( 
RES_PARATR_LIST_ID, false ) )
         {
-            const SfxStringItem* pListIdItem =
-                                    dynamic_cast<const SfxStringItem*>(pItem);
             const OUString sListIdOfTextNode = mrTextNode.GetListId();
-            if ( pListIdItem &&
-                 pListIdItem->GetValue() != sListIdOfTextNode )
+            if ( pListIdItem->GetValue() != sListIdOfTextNode )
             {
                 mbAddTextNodeToList = true;
                 if ( mrTextNode.IsInList() )
@@ -4725,46 +4718,37 @@ namespace {
         }
 
         // handle RES_PARATR_LIST_LEVEL
-        if ( rItemSet.GetItemState( RES_PARATR_LIST_LEVEL, false, &pItem ) == 
SfxItemState::SET )
+        if ( const SfxInt16Item* pListLevelItem = rItemSet.GetItemIfSet( 
RES_PARATR_LIST_LEVEL, false ) )
         {
-            const SfxInt16Item* pListLevelItem =
-                                dynamic_cast<const SfxInt16Item*>(pItem);
-            if (pListLevelItem && pListLevelItem->GetValue() != 
mrTextNode.GetAttrListLevel())
+            if (pListLevelItem->GetValue() != mrTextNode.GetAttrListLevel())
             {
                 mbUpdateListLevel = true;
             }
         }
 
         // handle RES_PARATR_LIST_ISRESTART
-        if ( rItemSet.GetItemState( RES_PARATR_LIST_ISRESTART, false, &pItem ) 
== SfxItemState::SET )
+        if ( const SfxBoolItem* pListIsRestartItem = rItemSet.GetItemIfSet( 
RES_PARATR_LIST_ISRESTART, false ) )
         {
-            const SfxBoolItem* pListIsRestartItem =
-                                dynamic_cast<const SfxBoolItem*>(pItem);
-            if (pListIsRestartItem && pListIsRestartItem->GetValue() != 
mrTextNode.IsListRestart())
+            if (pListIsRestartItem->GetValue() != mrTextNode.IsListRestart())
             {
                 mbUpdateListRestart = true;
             }
         }
 
         // handle RES_PARATR_LIST_RESTARTVALUE
-        if ( rItemSet.GetItemState( RES_PARATR_LIST_RESTARTVALUE, false, 
&pItem ) == SfxItemState::SET )
+        if ( const SfxInt16Item* pListRestartValueItem = 
rItemSet.GetItemIfSet( RES_PARATR_LIST_RESTARTVALUE, false ) )
         {
-            const SfxInt16Item* pListRestartValueItem =
-                                dynamic_cast<const SfxInt16Item*>(pItem);
-            if ( !mrTextNode.HasAttrListRestartValue() || 
(pListRestartValueItem &&
-                 pListRestartValueItem->GetValue() != 
mrTextNode.GetAttrListRestartValue()) )
+            if ( !mrTextNode.HasAttrListRestartValue() ||
+                 pListRestartValueItem->GetValue() != 
mrTextNode.GetAttrListRestartValue() )
             {
                 mbUpdateListRestart = true;
             }
         }
 
         // handle RES_PARATR_LIST_ISCOUNTED
-        if ( rItemSet.GetItemState( RES_PARATR_LIST_ISCOUNTED, false, &pItem ) 
== SfxItemState::SET )
+        if ( const SfxBoolItem* pIsCountedInListItem = rItemSet.GetItemIfSet( 
RES_PARATR_LIST_ISCOUNTED, false ) )
         {
-            const SfxBoolItem* pIsCountedInListItem =
-                                dynamic_cast<const SfxBoolItem*>(pItem);
-            if (pIsCountedInListItem && pIsCountedInListItem->GetValue() !=
-                mrTextNode.IsCountedInList())
+            if (pIsCountedInListItem->GetValue() != 
mrTextNode.IsCountedInList())
             {
                 mbUpdateListCount = true;
             }
@@ -4772,12 +4756,9 @@ namespace {
 
         // #i70748#
         // handle RES_PARATR_OUTLINELEVEL
-        if ( rItemSet.GetItemState( RES_PARATR_OUTLINELEVEL, false, &pItem ) 
== SfxItemState::SET )
+        if ( const SfxUInt16Item* pOutlineLevelItem = rItemSet.GetItemIfSet( 
RES_PARATR_OUTLINELEVEL, false ) )
         {
-            const SfxUInt16Item* pOutlineLevelItem =
-                                dynamic_cast<const SfxUInt16Item*>(pItem);
-            if (pOutlineLevelItem && pOutlineLevelItem->GetValue() !=
-                mrTextNode.GetAttrOutlineLevel())
+            if (pOutlineLevelItem->GetValue() != 
mrTextNode.GetAttrOutlineLevel())
             {
                 mbOutlineLevelSet = true;
             }
@@ -4835,9 +4816,7 @@ namespace {
         }
         else
         {
-            const SfxPoolItem* pItem = nullptr;
-            if ( mrTextNode.GetSwAttrSet().GetItemState( RES_PARATR_NUMRULE,
-                                                        true, &pItem )
+            if ( mrTextNode.GetSwAttrSet().GetItemState( RES_PARATR_NUMRULE )
                                                             != 
SfxItemState::SET )
             {
                 mrTextNode.SetEmptyListStyleDueToSetOutlineLevelAttr();
diff --git a/sw/source/core/txtnode/swfont.cxx 
b/sw/source/core/txtnode/swfont.cxx
index 028f20d14386..67028f766761 100644
--- a/sw/source/core/txtnode/swfont.cxx
+++ b/sw/source/core/txtnode/swfont.cxx
@@ -477,143 +477,112 @@ void SwFont::SetDiffFnt( const SfxItemSet *pAttrSet,
 
     if( pAttrSet )
     {
-        const SfxPoolItem* pItem;
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_FONT,
-            true, &pItem ))
+
+        if( const SvxFontItem* pFont = pAttrSet->GetItemIfSet( RES_CHRATR_FONT 
) )
         {
-            const SvxFontItem *pFont = static_cast<const SvxFontItem *>(pItem);
             m_aSub[SwFontScript::Latin].SetFamily( pFont->GetFamily() );
             m_aSub[SwFontScript::Latin].Font::SetFamilyName( 
pFont->GetFamilyName() );
             m_aSub[SwFontScript::Latin].Font::SetStyleName( 
pFont->GetStyleName() );
             m_aSub[SwFontScript::Latin].Font::SetPitch( pFont->GetPitch() );
             m_aSub[SwFontScript::Latin].Font::SetCharSet( pFont->GetCharSet() 
);
         }
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_FONTSIZE,
-            true, &pItem ))
+        if( const SvxFontHeightItem *pHeight = pAttrSet->GetItemIfSet( 
RES_CHRATR_FONTSIZE ) )
         {
-            const SvxFontHeightItem *pHeight = static_cast<const 
SvxFontHeightItem *>(pItem);
             m_aSub[SwFontScript::Latin].SvxFont::SetPropr( 100 );
             m_aSub[SwFontScript::Latin].m_aSize = 
m_aSub[SwFontScript::Latin].Font::GetFontSize();
             Size aTmpSize = m_aSub[SwFontScript::Latin].m_aSize;
             aTmpSize.setHeight( pHeight->GetHeight() );
             m_aSub[SwFontScript::Latin].SetSize( aTmpSize );
         }
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_POSTURE,
-            true, &pItem ))
-            m_aSub[SwFontScript::Latin].Font::SetItalic( static_cast<const 
SvxPostureItem*>(pItem)->GetPosture() );
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_WEIGHT,
-            true, &pItem ))
-            m_aSub[SwFontScript::Latin].Font::SetWeight( static_cast<const 
SvxWeightItem*>(pItem)->GetWeight() );
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_LANGUAGE,
-            true, &pItem ))
-            m_aSub[SwFontScript::Latin].SetLanguage( static_cast<const 
SvxLanguageItem*>(pItem)->GetLanguage() );
-
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_CJK_FONT,
-            true, &pItem ))
+        if( const SvxPostureItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_POSTURE ) )
+            m_aSub[SwFontScript::Latin].Font::SetItalic( pItem->GetPosture() );
+        if( const SvxWeightItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_WEIGHT ) )
+            m_aSub[SwFontScript::Latin].Font::SetWeight( pItem->GetWeight() );
+        if( const SvxLanguageItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_LANGUAGE ) )
+            m_aSub[SwFontScript::Latin].SetLanguage( pItem->GetLanguage() );
+
+        if( const SvxFontItem* pFont = pAttrSet->GetItemIfSet( 
RES_CHRATR_CJK_FONT ) )
         {
-            const SvxFontItem *pFont = static_cast<const SvxFontItem *>(pItem);
             m_aSub[SwFontScript::CJK].SetFamily( pFont->GetFamily() );
             m_aSub[SwFontScript::CJK].Font::SetFamilyName( 
pFont->GetFamilyName() );
             m_aSub[SwFontScript::CJK].Font::SetStyleName( 
pFont->GetStyleName() );
             m_aSub[SwFontScript::CJK].Font::SetPitch( pFont->GetPitch() );
             m_aSub[SwFontScript::CJK].Font::SetCharSet( pFont->GetCharSet() );
         }
-        if( SfxItemState::SET == pAttrSet->GetItemState( 
RES_CHRATR_CJK_FONTSIZE,
-            true, &pItem ))
+        if( const SvxFontHeightItem* pHeight = pAttrSet->GetItemIfSet( 
RES_CHRATR_CJK_FONTSIZE) )
         {
-            const SvxFontHeightItem *pHeight = static_cast<const 
SvxFontHeightItem *>(pItem);
             m_aSub[SwFontScript::CJK].SvxFont::SetPropr( 100 );
             m_aSub[SwFontScript::CJK].m_aSize = 
m_aSub[SwFontScript::CJK].Font::GetFontSize();
             Size aTmpSize = m_aSub[SwFontScript::CJK].m_aSize;
             aTmpSize.setHeight( pHeight->GetHeight() );
             m_aSub[SwFontScript::CJK].SetSize( aTmpSize );
         }
-        if( SfxItemState::SET == pAttrSet->GetItemState( 
RES_CHRATR_CJK_POSTURE,
-            true, &pItem ))
-            m_aSub[SwFontScript::CJK].Font::SetItalic( static_cast<const 
SvxPostureItem*>(pItem)->GetPosture() );
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_CJK_WEIGHT,
-            true, &pItem ))
-            m_aSub[SwFontScript::CJK].Font::SetWeight( static_cast<const 
SvxWeightItem*>(pItem)->GetWeight() );
-        if( SfxItemState::SET == pAttrSet->GetItemState( 
RES_CHRATR_CJK_LANGUAGE,
-            true, &pItem ))
+        if( const SvxPostureItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_CJK_POSTURE ) )
+            m_aSub[SwFontScript::CJK].Font::SetItalic( pItem->GetPosture() );
+        if( const SvxWeightItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_CJK_WEIGHT ) )
+            m_aSub[SwFontScript::CJK].Font::SetWeight( pItem->GetWeight() );
+        if( const SvxLanguageItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_CJK_LANGUAGE ) )
         {
-            LanguageType eNewLang = static_cast<const 
SvxLanguageItem*>(pItem)->GetLanguage();
+            LanguageType eNewLang = pItem->GetLanguage();
             m_aSub[SwFontScript::CJK].SetLanguage( eNewLang );
             m_aSub[SwFontScript::Latin].SetCJKContextLanguage( eNewLang );
             m_aSub[SwFontScript::CJK].SetCJKContextLanguage( eNewLang );
             m_aSub[SwFontScript::CTL].SetCJKContextLanguage( eNewLang );
         }
 
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_CTL_FONT,
-            true, &pItem ))
+        if( const SvxFontItem* pFont = pAttrSet->GetItemIfSet( 
RES_CHRATR_CTL_FONT ) )
         {
-            const SvxFontItem *pFont = static_cast<const SvxFontItem *>(pItem);
             m_aSub[SwFontScript::CTL].SetFamily( pFont->GetFamily() );
             m_aSub[SwFontScript::CTL].Font::SetFamilyName( 
pFont->GetFamilyName() );
             m_aSub[SwFontScript::CTL].Font::SetStyleName( 
pFont->GetStyleName() );
             m_aSub[SwFontScript::CTL].Font::SetPitch( pFont->GetPitch() );
             m_aSub[SwFontScript::CTL].Font::SetCharSet( pFont->GetCharSet() );
         }
-        if( SfxItemState::SET == pAttrSet->GetItemState( 
RES_CHRATR_CTL_FONTSIZE,
-            true, &pItem ))
+        if( const SvxFontHeightItem* pHeight = pAttrSet->GetItemIfSet( 
RES_CHRATR_CTL_FONTSIZE ) )
         {
-            const SvxFontHeightItem *pHeight = static_cast<const 
SvxFontHeightItem *>(pItem);
             m_aSub[SwFontScript::CTL].SvxFont::SetPropr( 100 );
             m_aSub[SwFontScript::CTL].m_aSize = 
m_aSub[SwFontScript::CTL].Font::GetFontSize();
             Size aTmpSize = m_aSub[SwFontScript::CTL].m_aSize;
             aTmpSize.setHeight( pHeight->GetHeight() );
             m_aSub[SwFontScript::CTL].SetSize( aTmpSize );
         }
-        if( SfxItemState::SET == pAttrSet->GetItemState( 
RES_CHRATR_CTL_POSTURE,
-            true, &pItem ))
-            m_aSub[SwFontScript::CTL].Font::SetItalic( static_cast<const 
SvxPostureItem*>(pItem)->GetPosture() );
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_CTL_WEIGHT,
-            true, &pItem ))
-            m_aSub[SwFontScript::CTL].Font::SetWeight( static_cast<const 
SvxWeightItem*>(pItem)->GetWeight() );
-        if( SfxItemState::SET == pAttrSet->GetItemState( 
RES_CHRATR_CTL_LANGUAGE,
-            true, &pItem ))
-            m_aSub[SwFontScript::CTL].SetLanguage( static_cast<const 
SvxLanguageItem*>(pItem)->GetLanguage() );
-
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_UNDERLINE,
-            true, &pItem ))
+        if( const SvxPostureItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_CTL_POSTURE ) )
+            m_aSub[SwFontScript::CTL].Font::SetItalic(pItem->GetPosture() );
+        if( const SvxWeightItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_CTL_WEIGHT ) )
+            m_aSub[SwFontScript::CTL].Font::SetWeight( pItem->GetWeight() );
+        if( const SvxLanguageItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_CTL_LANGUAGE ) )
+            m_aSub[SwFontScript::CTL].SetLanguage( pItem->GetLanguage() );
+
+        if( const SvxUnderlineItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_UNDERLINE ) )
         {
-            SetUnderline( static_cast<const 
SvxUnderlineItem*>(pItem)->GetLineStyle() );
-            SetUnderColor( static_cast<const 
SvxUnderlineItem*>(pItem)->GetColor() );
+            SetUnderline( pItem->GetLineStyle() );
+            SetUnderColor( pItem->GetColor() );
         }
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_OVERLINE,
-            true, &pItem ))
+        if( const SvxOverlineItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_OVERLINE ) )
         {
-            SetOverline( static_cast<const 
SvxOverlineItem*>(pItem)->GetLineStyle() );
-            SetOverColor( static_cast<const 
SvxOverlineItem*>(pItem)->GetColor() );
+            SetOverline( pItem->GetLineStyle() );
+            SetOverColor( pItem->GetColor() );
         }
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_CROSSEDOUT,
-            true, &pItem ))
-            SetStrikeout( static_cast<const 
SvxCrossedOutItem*>(pItem)->GetStrikeout() );
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_COLOR,
-            true, &pItem ))
-            SetColor( static_cast<const SvxColorItem*>(pItem)->GetValue() );
-        if( SfxItemState::SET == pAttrSet->GetItemState( 
RES_CHRATR_EMPHASIS_MARK,
-            true, &pItem ))
-            SetEmphasisMark( static_cast<const 
SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark() );
+        if( const SvxCrossedOutItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_CROSSEDOUT ) )
+            SetStrikeout( pItem->GetStrikeout() );
+        if( const SvxColorItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_COLOR ) )
+            SetColor( pItem->GetValue() );
+        if( const SvxEmphasisMarkItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_EMPHASIS_MARK ))
+            SetEmphasisMark( pItem->GetEmphasisMark() );
 
         SetTransparent( true );
         SetAlign( ALIGN_BASELINE );
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_CONTOUR,
-            true, &pItem ))
-            SetOutline( static_cast<const SvxContourItem*>(pItem)->GetValue() 
);
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_SHADOWED,
-            true, &pItem ))
-            SetShadow( static_cast<const SvxShadowedItem*>(pItem)->GetValue() 
);
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_RELIEF,
-            true, &pItem ))
-            SetRelief( static_cast<const 
SvxCharReliefItem*>(pItem)->GetValue() );
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_SHADOWED,
-            true, &pItem ))
-            SetPropWidth(static_cast<const 
SvxShadowedItem*>(pItem)->GetValue() ? 50 : 100 );
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_AUTOKERN,
-            true, &pItem ))
+        if( const SvxContourItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_CONTOUR ) )
+            SetOutline( pItem->GetValue() );
+        if( const SvxShadowedItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_SHADOWED ) )
+            SetShadow( pItem->GetValue() );
+        if( const SvxCharReliefItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_RELIEF ) )
+            SetRelief( pItem->GetValue() );
+        if( const SvxShadowedItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_SHADOWED ))
+            SetPropWidth( pItem->GetValue() ? 50 : 100 );
+        if( const SvxAutoKernItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_AUTOKERN ) )
         {
-            if( static_cast<const SvxAutoKernItem*>(pItem)->GetValue() )
+            if( pItem->GetValue() )
             {
                 SetAutoKern( ( !pIDocumentSettingAccess ||
                                
!pIDocumentSettingAccess->get(DocumentSettingId::KERN_ASIAN_PUNCTUATION) ) ?
@@ -623,37 +592,27 @@ void SwFont::SetDiffFnt( const SfxItemSet *pAttrSet,
             else
                 SetAutoKern( FontKerning::NONE );
         }
-        if( SfxItemState::SET == pAttrSet->GetItemState( 
RES_CHRATR_WORDLINEMODE,
-            true, &pItem ))
-            SetWordLineMode( static_cast<const 
SvxWordLineModeItem*>(pItem)->GetValue() );
+        if( const SvxWordLineModeItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_WORDLINEMODE ) )
+            SetWordLineMode( pItem->GetValue() );
 
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_ESCAPEMENT,
-            true, &pItem ))
+        if( const SvxEscapementItem* pEsc = pAttrSet->GetItemIfSet( 
RES_CHRATR_ESCAPEMENT ) )
         {
-            const SvxEscapementItem *pEsc = static_cast<const 
SvxEscapementItem *>(pItem);
             SetEscapement( pEsc->GetEsc() );
             if( m_aSub[SwFontScript::Latin].IsEsc() )
                 SetProportion( pEsc->GetProportionalHeight() );
         }
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_CASEMAP,
-            true, &pItem ))
-            SetCaseMap( static_cast<const 
SvxCaseMapItem*>(pItem)->GetCaseMap() );
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_KERNING,
-            true, &pItem ))
-            SetFixKerning( static_cast<const 
SvxKerningItem*>(pItem)->GetValue() );
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_ROTATE,
-            true, &pItem ))
-            SetVertical( static_cast<const 
SvxCharRotateItem*>(pItem)->GetValue() );
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_BACKGROUND,
-            true, &pItem ))
-            mxBackColor = static_cast<const SvxBrushItem*>(pItem)->GetColor();
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_HIGHLIGHT,
-            true, &pItem ))
-            SetHighlightColor(static_cast<const 
SvxBrushItem*>(pItem)->GetColor());
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_BOX,
-            true, &pItem ))
+        if( const SvxCaseMapItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_CASEMAP ) )
+            SetCaseMap( pItem->GetCaseMap() );
+        if( const SvxKerningItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_KERNING ) )
+            SetFixKerning( pItem->GetValue() );
+        if( const SvxCharRotateItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_ROTATE ) )
+            SetVertical( pItem->GetValue() );
+        if( const SvxBrushItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_BACKGROUND ) )
+            mxBackColor = pItem->GetColor();
+        if( const SvxBrushItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_HIGHLIGHT ) )
+            SetHighlightColor(pItem->GetColor());
+        if( const SvxBoxItem* pBoxItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_BOX ) )
         {
-            const SvxBoxItem* pBoxItem = static_cast<const SvxBoxItem*>(pItem);
             SetTopBorder(pBoxItem->GetTop());
             SetBottomBorder(pBoxItem->GetBottom());
             SetRightBorder(pBoxItem->GetRight());
@@ -663,19 +622,15 @@ void SwFont::SetDiffFnt( const SfxItemSet *pAttrSet,
             SetRightBorderDist(pBoxItem->GetDistance(SvxBoxItemLine::RIGHT));
             SetLeftBorderDist(pBoxItem->GetDistance(SvxBoxItemLine::LEFT));
         }
-        if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_SHADOW,
-            true, &pItem ))
+        if( const SvxShadowItem* pShadowItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_SHADOW ) )
         {
-            const SvxShadowItem* pShadowItem = static_cast<const 
SvxShadowItem*>(pItem);
             SetShadowColor(pShadowItem->GetColor());
             SetShadowWidth(pShadowItem->GetWidth());
             SetShadowLocation(pShadowItem->GetLocation());
         }
-        const SfxPoolItem* pTwoLinesItem = nullptr;
-        if( SfxItemState::SET ==
-                pAttrSet->GetItemState( RES_CHRATR_TWO_LINES, true, 
&pTwoLinesItem ))
-            if ( static_cast<const 
SvxTwoLinesItem*>(pTwoLinesItem)->GetValue() )
-                SetVertical( 0_deg10 );
+        const SvxTwoLinesItem* pTwoLinesItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_TWO_LINES );
+        if( pTwoLinesItem && pTwoLinesItem->GetValue() )
+            SetVertical( 0_deg10 );
     }
     else
     {
@@ -809,19 +764,14 @@ SwFont::SwFont( const SwAttrSet* pAttrSet,
         SetProportion( rEsc.GetProportionalHeight() );
     SetCaseMap( pAttrSet->GetCaseMap().GetCaseMap() );
     SetFixKerning( pAttrSet->GetKerning().GetValue() );
-    const SfxPoolItem* pItem;
-    if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_BACKGROUND,
-        true, &pItem ))
-        mxBackColor = static_cast<const SvxBrushItem*>(pItem)->GetColor();
-    if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_HIGHLIGHT,
-        true, &pItem ))
-        SetHighlightColor(static_cast<const SvxBrushItem*>(pItem)->GetColor());
+    if( const SvxBrushItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_BACKGROUND ) )
+        mxBackColor = pItem->GetColor();
+    if( const SvxBrushItem* pItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_HIGHLIGHT ) )
+        SetHighlightColor(pItem->GetColor());
     else
         SetHighlightColor(COL_TRANSPARENT);
-    if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_BOX,
-        true, &pItem ))
+    if( const SvxBoxItem* pBoxItem = pAttrSet->GetItemIfSet( RES_CHRATR_BOX ) )
     {
-        const SvxBoxItem* pBoxItem = static_cast<const SvxBoxItem*>(pItem);
         SetTopBorder(pBoxItem->GetTop());
         SetBottomBorder(pBoxItem->GetBottom());
         SetRightBorder(pBoxItem->GetRight());
@@ -843,10 +793,8 @@ SwFont::SwFont( const SwAttrSet* pAttrSet,
         SetLeftBorderDist(0);
     }
 
-    if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_SHADOW,
-        true, &pItem ))
+    if( const SvxShadowItem* pShadowItem = pAttrSet->GetItemIfSet( 
RES_CHRATR_SHADOW ) )
     {
-        const SvxShadowItem* pShadowItem = static_cast<const 
SvxShadowItem*>(pItem);
         SetShadowColor(pShadowItem->GetColor());
         SetShadowWidth(pShadowItem->GetWidth());
         SetShadowLocation(pShadowItem->GetLocation());
diff --git a/sw/source/core/txtnode/thints.cxx 
b/sw/source/core/txtnode/thints.cxx
index 383d5763cd2e..2ac714a1d02e 100644
--- a/sw/source/core/txtnode/thints.cxx
+++ b/sw/source/core/txtnode/thints.cxx
@@ -1348,9 +1348,7 @@ bool SwTextNode::InsertHint( SwTextAttr * const pAttr, 
const SetAttrMode nMode )
                     //JP 11.05.98: if the anchor is already set correctly,
                     // fix it after inserting the char, so that clients don't
                     // have to worry about it.
-                    const SwFormatAnchor* pAnchor = nullptr;
-                    (void)pFormat->GetItemState( RES_ANCHOR, false,
-                        reinterpret_cast<const SfxPoolItem**>(&pAnchor) );
+                    const SwFormatAnchor* pAnchor = pFormat->GetItemIfSet( 
RES_ANCHOR, false );
 
                     SwIndex aIdx( this, pAttr->GetStart() );
                     const OUString c(GetCharOfTextAttr(*pAttr));
@@ -1761,8 +1759,7 @@ void SwTextNode::DeleteAttributes(
             {
                 // Check if character format contains hidden attribute:
                 const SwCharFormat* pFormat = 
pTextHt->GetCharFormat().GetCharFormat();
-                const SfxPoolItem* pItem;
-                if ( SfxItemState::SET == pFormat->GetItemState( 
RES_CHRATR_HIDDEN, true, &pItem ) )
+                if ( SfxItemState::SET == pFormat->GetItemState( 
RES_CHRATR_HIDDEN ) )
                     SetCalcHiddenCharFlags();
             }
             // #i75430# Recalc hidden flags if necessary
@@ -1886,12 +1883,9 @@ bool SwTextNode::SetAttr(
             }
 
             // check for auto style:
-            const SfxPoolItem* pItem;
-            const bool bAutoStyle = SfxItemState::SET == 
aTextSet.GetItemState( RES_TXTATR_AUTOFMT, false, &pItem );
-            if ( bAutoStyle )
+            if ( const SwFormatAutoFormat* pItem = aTextSet.GetItemIfSet( 
RES_TXTATR_AUTOFMT, false ) )
             {
-                const std::shared_ptr<SfxItemSet> & pAutoStyleSet = 
static_cast<const SwFormatAutoFormat*>(pItem)->GetStyleHandle();
-                const bool bRet = SetAttr( *pAutoStyleSet );
+                const bool bRet = SetAttr( *pItem->GetStyleHandle() );
                 if( 1 == aTextSet.Count() )
                     return bRet;
             }
@@ -2983,8 +2977,7 @@ bool SwpHints::TryInsertHint(
     {
         // Check if character format contains hidden attribute:
         const SwCharFormat* pFormat = pHint->GetCharFormat().GetCharFormat();
-        const SfxPoolItem* pItem;
-        if ( SfxItemState::SET == pFormat->GetItemState( RES_CHRATR_HIDDEN, 
true, &pItem ) )
+        if ( SfxItemState::SET == pFormat->GetItemState( RES_CHRATR_HIDDEN ) )
             rNode.SetCalcHiddenCharFlags();
 
         static_txtattr_cast<SwTextCharFormat*>(pHint)->ChgTextNode( &rNode );

Reply via email to