sc/source/core/data/attarray.cxx |   42 +-
 sc/source/core/data/column2.cxx  |   32 +-
 sc/source/core/data/docpool.cxx  |    7 
 sc/source/core/data/documen4.cxx |    4 
 sc/source/core/data/documen8.cxx |    3 
 sc/source/core/data/fillinfo.cxx |   46 +--
 sc/source/core/data/global.cxx   |    6 
 sc/source/core/data/patattr.cxx  |  594 +++++++++++++++++++--------------------
 sc/source/core/data/stlpool.cxx  |   15 
 sc/source/core/data/table2.cxx   |    6 
 sc/source/core/data/table5.cxx   |   12 
 11 files changed, 379 insertions(+), 388 deletions(-)

New commits:
commit a5a1863e16d209eb40758cd1f77500c6ff945f59
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Mar 1 08:57:10 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Mar 1 10:05:14 2022 +0100

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

diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx
index 1f48990aa05d..71efb305750c 100644
--- a/sc/source/core/data/attarray.cxx
+++ b/sc/source/core/data/attarray.cxx
@@ -299,11 +299,9 @@ void ScAttrArray::AddCondFormat( SCROW nStartRow, SCROW 
nEndRow, sal_uInt32 nInd
             GetPatternRange( nPatternStartRow, nPatternEndRow, nTempStartRow );
 
             nTempEndRow = std::min<SCROW>( nPatternEndRow, nEndRow );
-            const SfxPoolItem* pItem = nullptr;
-            pPattern->GetItemSet().GetItemState( ATTR_CONDITIONAL, true, 
&pItem );
-            if(pItem)
+            if (const ScCondFormatItem* pItem = 
pPattern->GetItemSet().GetItemIfSet( ATTR_CONDITIONAL ))
             {
-                ScCondFormatIndexes const & rCondFormatData = 
static_cast<const ScCondFormatItem*>(pItem)->GetCondFormatData();
+                ScCondFormatIndexes const & rCondFormatData = 
pItem->GetCondFormatData();
                 if (rCondFormatData.find(nIndex) == rCondFormatData.end())
                 {
                     ScCondFormatIndexes aNewCondFormatData;
@@ -357,9 +355,7 @@ void ScAttrArray::RemoveCondFormat( SCROW nStartRow, SCROW 
nEndRow, sal_uInt32 n
             GetPatternRange( nPatternStartRow, nPatternEndRow, nTempStartRow );
 
             nTempEndRow = std::min<SCROW>( nPatternEndRow, nEndRow );
-            const SfxPoolItem* pItem = nullptr;
-            pPattern->GetItemSet().GetItemState( ATTR_CONDITIONAL, true, 
&pItem );
-            if(pItem)
+            if (const ScCondFormatItem* pItem = 
pPattern->GetItemSet().GetItemIfSet( ATTR_CONDITIONAL ))
             {
                 auto pPatternAttr = std::make_unique<ScPatternAttr>( *pPattern 
);
                 if (nIndex == 0)
@@ -370,7 +366,7 @@ void ScAttrArray::RemoveCondFormat( SCROW nStartRow, SCROW 
nEndRow, sal_uInt32 n
                 }
                 else
                 {
-                    ScCondFormatIndexes const & rCondFormatData = 
static_cast<const ScCondFormatItem*>(pItem)->GetCondFormatData();
+                    ScCondFormatIndexes const & rCondFormatData = 
pItem->GetCondFormatData();
                     auto itr = rCondFormatData.find(nIndex);
                     if(itr != rCondFormatData.end())
                     {
@@ -739,23 +735,20 @@ void ScAttrArray::ApplyLineStyleArea( SCROW nStartRow, 
SCROW nEndRow,
     {
         const ScPatternAttr*    pOldPattern = mvData[nPos].pPattern;
         const SfxItemSet&       rOldSet = pOldPattern->GetItemSet();
-        const SfxPoolItem*      pBoxItem = nullptr;
-        SfxItemState            eState = rOldSet.GetItemState( ATTR_BORDER, 
true, &pBoxItem );
-        const SfxPoolItem*      pTLBRItem = nullptr;
-        SfxItemState            eTLBRState = rOldSet.GetItemState( 
ATTR_BORDER_TLBR, true, &pTLBRItem );
-        const SfxPoolItem*      pBLTRItem = nullptr;
-        SfxItemState            eBLTRState = rOldSet.GetItemState( 
ATTR_BORDER_BLTR, true, &pBLTRItem );
+        const SvxBoxItem*       pBoxItem = rOldSet.GetItemIfSet( ATTR_BORDER );
+        const SvxLineItem*      pTLBRItem = rOldSet.GetItemIfSet( 
ATTR_BORDER_TLBR );
+        const SvxLineItem*      pBLTRItem = rOldSet.GetItemIfSet( 
ATTR_BORDER_BLTR );
 
-        if ( (SfxItemState::SET == eState) || (SfxItemState::SET == 
eTLBRState) || (SfxItemState::SET == eBLTRState) )
+        if ( pBoxItem || pTLBRItem || pBLTRItem )
         {
             std::unique_ptr<ScPatternAttr> pNewPattern(new 
ScPatternAttr(*pOldPattern));
             SfxItemSet&     rNewSet = pNewPattern->GetItemSet();
             SCROW           nY1 = nStart;
             SCROW           nY2 = mvData[nPos].nEndRow;
 
-            std::unique_ptr<SvxBoxItem>  pNewBoxItem( pBoxItem ? 
static_cast<SvxBoxItem*>(pBoxItem->Clone()) : nullptr);
-            std::unique_ptr<SvxLineItem> pNewTLBRItem( pTLBRItem ? 
static_cast<SvxLineItem*>(pTLBRItem->Clone()) : nullptr);
-            std::unique_ptr<SvxLineItem> pNewBLTRItem(pBLTRItem ? 
static_cast<SvxLineItem*>(pBLTRItem->Clone()) : nullptr);
+            std::unique_ptr<SvxBoxItem>  pNewBoxItem( pBoxItem ? 
pBoxItem->Clone() : nullptr);
+            std::unique_ptr<SvxLineItem> pNewTLBRItem( pTLBRItem ? 
pTLBRItem->Clone() : nullptr);
+            std::unique_ptr<SvxLineItem> pNewBLTRItem(pBLTRItem ? 
pBLTRItem->Clone() : nullptr);
 
             // fetch line and update attributes with parameters
 
@@ -1325,10 +1318,9 @@ bool ScAttrArray::HasAttrib_Impl(const ScPatternAttr* 
pPattern, HasAttrFlags nMa
             {
                 const SfxItemSet* pSet = rDocument.GetCondResult( nCol, 
nRowCond, nTab );
 
-                const SfxPoolItem* pItem;
-                if( pSet && pSet->GetItemState( ATTR_PROTECTION, true, &pItem 
) == SfxItemState::SET )
+                const ScProtectionAttr* pCondProtect;
+                if( pSet && (pCondProtect = pSet->GetItemIfSet( 
ATTR_PROTECTION )) )
                 {
-                    const ScProtectionAttr* pCondProtect = static_cast<const 
ScProtectionAttr*>(pItem);
                     if( pCondProtect->GetProtection() || 
pCondProtect->GetHideCell() )
                         bFoundCond = true;
                     else
@@ -1716,11 +1708,11 @@ void ScAttrArray::ChangeIndent( SCROW nStartRow, SCROW 
nEndRow, bool bIncrement
     {
         const ScPatternAttr* pOldPattern = mvData[nIndex].pPattern;
         const SfxItemSet& rOldSet = pOldPattern->GetItemSet();
-        const SfxPoolItem* pItem;
+        const SvxHorJustifyItem* pItem;
 
-        bool bNeedJust = ( rOldSet.GetItemState( ATTR_HOR_JUSTIFY, false, 
&pItem ) != SfxItemState::SET
-                           || (static_cast<const 
SvxHorJustifyItem*>(pItem)->GetValue() != SvxCellHorJustify::Left &&
-                               static_cast<const 
SvxHorJustifyItem*>(pItem)->GetValue() != SvxCellHorJustify::Right ));
+        bool bNeedJust = !( pItem = rOldSet.GetItemIfSet( ATTR_HOR_JUSTIFY, 
false ) )
+                           || (pItem->GetValue() != SvxCellHorJustify::Left &&
+                               pItem->GetValue() != SvxCellHorJustify::Right );
         sal_uInt16 nOldValue = rOldSet.Get( ATTR_INDENT ).GetValue();
         sal_uInt16 nNewValue = nOldValue;
         // To keep Increment indent from running outside the cell1659
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index f24ac6726495..60c2f7b0a4e6 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -144,19 +144,18 @@ tools::Long ScColumn::GetNeededSize(
     }
     //  line break?
 
-    const SfxPoolItem* pCondItem;
+    const SvxHorJustifyItem* pCondItem;
     SvxCellHorJustify eHorJust;
-    if (pCondSet &&
-            pCondSet->GetItemState(ATTR_HOR_JUSTIFY, true, &pCondItem) == 
SfxItemState::SET)
-        eHorJust = static_cast<const 
SvxHorJustifyItem*>(pCondItem)->GetValue();
+    if (pCondSet && (pCondItem = pCondSet->GetItemIfSet(ATTR_HOR_JUSTIFY)) )
+        eHorJust = pCondItem->GetValue();
     else
         eHorJust = pPattern->GetItem( ATTR_HOR_JUSTIFY ).GetValue();
     bool bBreak;
+    const ScLineBreakCell* pLineBreakCell;
     if ( eHorJust == SvxCellHorJustify::Block )
         bBreak = true;
-    else if ( pCondSet &&
-                pCondSet->GetItemState(ATTR_LINEBREAK, true, &pCondItem) == 
SfxItemState::SET)
-        bBreak = static_cast<const ScLineBreakCell*>(pCondItem)->GetValue();
+    else if ( pCondSet && (pLineBreakCell = 
pCondSet->GetItemIfSet(ATTR_LINEBREAK)) )
+        bBreak = pLineBreakCell->GetValue();
     else
         bBreak = pPattern->GetItem(ATTR_LINEBREAK).GetValue();
 
@@ -216,16 +215,18 @@ tools::Long ScColumn::GetNeededSize(
     SvxRotateMode eRotMode = SVX_ROTATE_MODE_STANDARD;
     if ( eOrient == SvxCellOrientation::Standard )
     {
+        const ScRotateValueItem* pRotateValueItem;
         if (pCondSet &&
-                pCondSet->GetItemState(ATTR_ROTATE_VALUE, true, &pCondItem) == 
SfxItemState::SET)
-            nRotate = static_cast<const 
ScRotateValueItem*>(pCondItem)->GetValue();
+                (pRotateValueItem = pCondSet->GetItemIfSet(ATTR_ROTATE_VALUE)) 
)
+            nRotate = pRotateValueItem->GetValue();
         else
             nRotate = pPattern->GetItem(ATTR_ROTATE_VALUE).GetValue();
         if ( nRotate )
         {
+            const SvxRotateModeItem* pRotateModeItem;
             if (pCondSet &&
-                    pCondSet->GetItemState(ATTR_ROTATE_MODE, true, &pCondItem) 
== SfxItemState::SET)
-                eRotMode = static_cast<const 
SvxRotateModeItem*>(pCondItem)->GetValue();
+                    (pRotateModeItem = 
pCondSet->GetItemIfSet(ATTR_ROTATE_MODE)) )
+                eRotMode = pRotateModeItem->GetValue();
             else
                 eRotMode = pPattern->GetItem(ATTR_ROTATE_MODE).GetValue();
 
@@ -244,16 +245,17 @@ tools::Long ScColumn::GetNeededSize(
 
     const SvxMarginItem* pMargin;
     if (pCondSet &&
-            pCondSet->GetItemState(ATTR_MARGIN, true, &pCondItem) == 
SfxItemState::SET)
-        pMargin = static_cast<const SvxMarginItem*>(pCondItem);
+            (pMargin = pCondSet->GetItemIfSet(ATTR_MARGIN)) )
+        ;
     else
         pMargin = &pPattern->GetItem(ATTR_MARGIN);
     sal_uInt16 nIndent = 0;
     if ( eHorJust == SvxCellHorJustify::Left )
     {
+        const ScIndentItem* pIndentItem;
         if (pCondSet &&
-                pCondSet->GetItemState(ATTR_INDENT, true, &pCondItem) == 
SfxItemState::SET)
-            nIndent = static_cast<const ScIndentItem*>(pCondItem)->GetValue();
+                (pIndentItem = pCondSet->GetItemIfSet(ATTR_INDENT)) )
+            nIndent = pIndentItem->GetValue();
         else
             nIndent = pPattern->GetItem(ATTR_INDENT).GetValue();
     }
diff --git a/sc/source/core/data/docpool.cxx b/sc/source/core/data/docpool.cxx
index 6131be280c5d..e0a07582e453 100644
--- a/sc/source/core/data/docpool.cxx
+++ b/sc/source/core/data/docpool.cxx
@@ -399,17 +399,16 @@ static bool lcl_HFPresentation
 )
 {
     const SfxItemSet& rSet = static_cast<const 
SfxSetItem&>(rItem).GetItemSet();
-    const SfxPoolItem* pItem;
 
-    if ( SfxItemState::SET == rSet.GetItemState(ATTR_PAGE_ON,false,&pItem) )
+    if ( const SfxBoolItem* pItem = rSet.GetItemIfSet(ATTR_PAGE_ON,false) )
     {
-        if( !static_cast<const SfxBoolItem*>(pItem)->GetValue() )
+        if( !pItem->GetValue() )
             return false;
     }
 
     SfxItemIter aIter( rSet );
 
-    for (pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem())
+    for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = 
aIter.NextItem())
     {
         sal_uInt16 nWhich = pItem->Which();
 
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index 6dff5a3cdb8b..b7eecde0edb1 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -760,8 +760,7 @@ const SfxPoolItem* ScDocument::GetEffItem(
     if ( pPattern )
     {
         const SfxItemSet& rSet = pPattern->GetItemSet();
-        const SfxPoolItem* pItem;
-        if ( rSet.GetItemState( ATTR_CONDITIONAL, true, &pItem ) == 
SfxItemState::SET )
+        if ( rSet.GetItemState( ATTR_CONDITIONAL ) == SfxItemState::SET )
         {
             const ScCondFormatIndexes& rIndex = 
pPattern->GetItem(ATTR_CONDITIONAL).GetCondFormatData();
             ScConditionalFormatList* pCondFormList = GetCondFormList( nTab );
@@ -779,6 +778,7 @@ const SfxPoolItem* ScDocument::GetEffItem(
                         {
                             SfxStyleSheetBase* pStyleSheet = 
mxPoolHelper->GetStylePool()->Find(
                                     aStyle, SfxStyleFamily::Para );
+                            const SfxPoolItem* pItem = nullptr;
                             if ( pStyleSheet && 
pStyleSheet->GetItemSet().GetItemState(
                                         nWhich, true, &pItem ) == 
SfxItemState::SET )
                                 return pItem;
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index ff79c90fb56f..e0abb1d3b8ea 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -227,8 +227,7 @@ void ScDocument::ModifyStyleSheet( SfxStyleSheetBase& 
rStyleSheet,
 
                 if( SvtCTLOptions().IsCTLFontEnabled() )
                 {
-                    const SfxPoolItem *pItem = nullptr;
-                    if( rChanges.GetItemState(ATTR_WRITINGDIR, true, &pItem ) 
== SfxItemState::SET )
+                    if( rChanges.GetItemState(ATTR_WRITINGDIR ) == 
SfxItemState::SET )
                         ScChartHelper::DoUpdateAllCharts( *this );
                 }
             }
diff --git a/sc/source/core/data/fillinfo.cxx b/sc/source/core/data/fillinfo.cxx
index ccff98180089..0e5e6664db93 100644
--- a/sc/source/core/data/fillinfo.cxx
+++ b/sc/source/core/data/fillinfo.cxx
@@ -309,10 +309,9 @@ bool handleConditionalFormat(ScConditionalFormatList& 
rCondFormList, const ScCon
                 // TODO: moggi: looks like there is a bug around bHidden and 
bHideFormula
                 //              They are normally for the whole pattern and 
not for a single cell
                 // we need to check already here for protected cells
-                const SfxPoolItem* pItem;
-                if ( bTabProtect && pInfo->pConditionSet->GetItemState( 
ATTR_PROTECTION, true, &pItem ) == SfxItemState::SET )
+                const ScProtectionAttr* pProtAttr;
+                if ( bTabProtect && (pProtAttr = 
pInfo->pConditionSet->GetItemIfSet( ATTR_PROTECTION )) )
                 {
-                    const ScProtectionAttr* pProtAttr = static_cast<const 
ScProtectionAttr*>(pItem);
                     bHidden = pProtAttr->GetHideCell();
                     bHideFormula = pProtAttr->GetHideFormula();
 
@@ -659,28 +658,26 @@ void ScDocument::FillInfo(
 
                 if (pCondSet)
                 {
-                    const SfxPoolItem* pItem;
-
                             // Background
-                    if ( pCondSet->GetItemState( ATTR_BACKGROUND, true, &pItem 
) == SfxItemState::SET )
+                    if ( const SvxBrushItem* pItem = pCondSet->GetItemIfSet( 
ATTR_BACKGROUND ) )
                     {
-                        pInfo->pBackground = static_cast<const 
SvxBrushItem*>(pItem);
+                        pInfo->pBackground = pItem;
                         pRowInfo[nArrRow].bEmptyBack = false;
                     }
 
                             // Border
-                    if ( pCondSet->GetItemState( ATTR_BORDER, true, &pItem ) 
== SfxItemState::SET )
-                        pInfo->pLinesAttr = static_cast<const 
SvxBoxItem*>(pItem);
+                    if ( const SvxBoxItem* pItem = pCondSet->GetItemIfSet( 
ATTR_BORDER ) )
+                        pInfo->pLinesAttr = pItem;
 
-                    if ( pCondSet->GetItemState( ATTR_BORDER_TLBR, true, 
&pItem ) == SfxItemState::SET )
-                        pInfo->mpTLBRLine = static_cast< const SvxLineItem* >( 
pItem );
-                    if ( pCondSet->GetItemState( ATTR_BORDER_BLTR, true, 
&pItem ) == SfxItemState::SET )
-                        pInfo->mpBLTRLine = static_cast< const SvxLineItem* >( 
pItem );
+                    if ( const SvxLineItem* pItem = pCondSet->GetItemIfSet( 
ATTR_BORDER_TLBR ) )
+                        pInfo->mpTLBRLine = pItem;
+                    if ( const SvxLineItem* pItem = pCondSet->GetItemIfSet( 
ATTR_BORDER_BLTR ) )
+                        pInfo->mpBLTRLine = pItem;
 
                             //  Shadow
-                    if ( pCondSet->GetItemState( ATTR_SHADOW, true, &pItem ) 
== SfxItemState::SET )
+                    if ( const SvxShadowItem* pItem = pCondSet->GetItemIfSet( 
ATTR_SHADOW ) )
                     {
-                        pInfo->pShadowAttr = static_cast<const 
SvxShadowItem*>(pItem);
+                        pInfo->pShadowAttr = pItem;
                         bAnyShadow = true;
                     }
                 }
@@ -718,22 +715,23 @@ void ScDocument::FillInfo(
                                         nStartX,nStartY, nEndX,nEndY );
                     const ScPatternAttr* pStartPattern = GetPattern( 
nStartX,nStartY,nTab );
                     const SfxItemSet* pStartCond = GetCondResult( 
nStartX,nStartY,nTab );
-                    const SfxPoolItem* pItem;
 
                     // Copy Background (or in output.cxx)
 
-                    if ( !pStartCond || pStartCond->
-                                    GetItemState(ATTR_BACKGROUND,true,&pItem) 
!= SfxItemState::SET )
-                        pItem = &pStartPattern->GetItem(ATTR_BACKGROUND);
-                    pInfo->pBackground = static_cast<const 
SvxBrushItem*>(pItem);
+                    const SvxBrushItem* pBrushItem = nullptr;
+                    if ( !pStartCond ||
+                        !(pBrushItem = 
pStartCond->GetItemIfSet(ATTR_BACKGROUND)) )
+                        pBrushItem = &pStartPattern->GetItem(ATTR_BACKGROUND);
+                    pInfo->pBackground = pBrushItem;
                     pRowInfo[nArrRow].bEmptyBack = false;
 
                     // Shadow
 
-                    if ( !pStartCond || pStartCond->
-                                    GetItemState(ATTR_SHADOW,true,&pItem) != 
SfxItemState::SET )
-                        pItem = &pStartPattern->GetItem(ATTR_SHADOW);
-                    pInfo->pShadowAttr = static_cast<const 
SvxShadowItem*>(pItem);
+                    const SvxShadowItem* pShadowItem = nullptr;
+                    if ( !pStartCond ||
+                        !(pShadowItem = pStartCond->GetItemIfSet(ATTR_SHADOW)) 
)
+                        pShadowItem = &pStartPattern->GetItem(ATTR_SHADOW);
+                    pInfo->pShadowAttr = pShadowItem;
                     if (pInfo->pShadowAttr != pDefShadow)
                         bAnyShadow = true;
                 }
diff --git a/sc/source/core/data/global.cxx b/sc/source/core/data/global.cxx
index a9e184aee0ed..0c52427539c0 100644
--- a/sc/source/core/data/global.cxx
+++ b/sc/source/core/data/global.cxx
@@ -958,12 +958,12 @@ void ScGlobal::AddLanguage( SfxItemSet& rSet, const 
SvNumberFormatter& rFormatte
     OSL_ENSURE( rSet.GetItemState( ATTR_LANGUAGE_FORMAT, false ) == 
SfxItemState::DEFAULT,
         "ScGlobal::AddLanguage - language already added");
 
-    const SfxPoolItem* pHardItem;
-    if ( rSet.GetItemState( ATTR_VALUE_FORMAT, false, &pHardItem ) != 
SfxItemState::SET )
+    const SfxUInt32Item* pHardItem = rSet.GetItemIfSet( ATTR_VALUE_FORMAT, 
false );
+    if ( !pHardItem )
         return;
 
     const SvNumberformat* pHardFormat = rFormatter.GetEntry(
-        static_cast<const SfxUInt32Item*>(pHardItem)->GetValue() );
+        pHardItem->GetValue() );
 
     sal_uInt32 nParentFmt = 0; // Pool default
     const SfxItemSet* pParent = rSet.GetParent();
diff --git a/sc/source/core/data/patattr.cxx b/sc/source/core/data/patattr.cxx
index 2fa97d3a03dc..7e5d3b73f51c 100644
--- a/sc/source/core/data/patattr.cxx
+++ b/sc/source/core/data/patattr.cxx
@@ -206,7 +206,11 @@ SvxCellOrientation ScPatternAttr::GetCellOrientation( 
const SfxItemSet* pCondSet
 namespace {
 
 void getFontIDsByScriptType(SvtScriptType nScript,
-sal_uInt16& nFontId, sal_uInt16& nHeightId, sal_uInt16& nWeightId, sal_uInt16& 
nPostureId, sal_uInt16& nLangId)
+        TypedWhichId<SvxFontItem>& nFontId,
+        TypedWhichId<SvxFontHeightItem>& nHeightId,
+        TypedWhichId<SvxWeightItem>& nWeightId,
+        TypedWhichId<SvxPostureItem>& nPostureId,
+        TypedWhichId<SvxLanguageItem>& nLangId)
 {
     if ( nScript == SvtScriptType::ASIAN )
     {
@@ -259,78 +263,90 @@ void ScPatternAttr::GetFont(
     Color aColor;
     LanguageType eLang;
 
-    sal_uInt16 nFontId, nHeightId, nWeightId, nPostureId, nLangId;
+    TypedWhichId<SvxFontItem> nFontId(0);
+    TypedWhichId<SvxFontHeightItem> nHeightId(0);
+    TypedWhichId<SvxWeightItem> nWeightId(0);
+    TypedWhichId<SvxPostureItem> nPostureId(0);
+    TypedWhichId<SvxLanguageItem> nLangId(0);
     getFontIDsByScriptType(nScript, nFontId, nHeightId, nWeightId, nPostureId, 
nLangId);
 
     if ( pCondSet )
     {
-        const SfxPoolItem* pItem;
-
-        if ( pCondSet->GetItemState( nFontId, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rItemSet.Get( nFontId );
-        pFontAttr = static_cast<const SvxFontItem*>(pItem);
-
-        if ( pCondSet->GetItemState( nHeightId, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rItemSet.Get( nHeightId );
-        nFontHeight = static_cast<const 
SvxFontHeightItem*>(pItem)->GetHeight();
-
-        if ( pCondSet->GetItemState( nWeightId, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rItemSet.Get( nWeightId );
-        eWeight = static_cast<const SvxWeightItem*>(pItem)->GetValue();
-
-        if ( pCondSet->GetItemState( nPostureId, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rItemSet.Get( nPostureId );
-        eItalic = static_cast<const SvxPostureItem*>(pItem)->GetValue();
-
-        if ( pCondSet->GetItemState( ATTR_FONT_UNDERLINE, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rItemSet.Get( ATTR_FONT_UNDERLINE );
-        eUnder = static_cast<const SvxUnderlineItem*>(pItem)->GetValue();
-
-        if ( pCondSet->GetItemState( ATTR_FONT_OVERLINE, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rItemSet.Get( ATTR_FONT_OVERLINE );
-        eOver = static_cast<const SvxOverlineItem*>(pItem)->GetValue();
-
-        if ( pCondSet->GetItemState( ATTR_FONT_WORDLINE, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rItemSet.Get( ATTR_FONT_WORDLINE );
-        bWordLine = static_cast<const SvxWordLineModeItem*>(pItem)->GetValue();
-
-        if ( pCondSet->GetItemState( ATTR_FONT_CROSSEDOUT, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rItemSet.Get( ATTR_FONT_CROSSEDOUT );
-        eStrike = static_cast<const SvxCrossedOutItem*>(pItem)->GetValue();
-
-        if ( pCondSet->GetItemState( ATTR_FONT_CONTOUR, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rItemSet.Get( ATTR_FONT_CONTOUR );
-        bOutline = static_cast<const SvxContourItem*>(pItem)->GetValue();
-
-        if ( pCondSet->GetItemState( ATTR_FONT_SHADOWED, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rItemSet.Get( ATTR_FONT_SHADOWED );
-        bShadow = static_cast<const SvxShadowedItem*>(pItem)->GetValue();
-
-        if ( pCondSet->GetItemState( ATTR_FONT_EMPHASISMARK, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rItemSet.Get( ATTR_FONT_EMPHASISMARK );
-        eEmphasis = static_cast<const 
SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark();
-
-        if ( pCondSet->GetItemState( ATTR_FONT_RELIEF, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rItemSet.Get( ATTR_FONT_RELIEF );
-        eRelief = static_cast<const SvxCharReliefItem*>(pItem)->GetValue();
-
-        if ( pCondSet->GetItemState( ATTR_FONT_COLOR, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rItemSet.Get( ATTR_FONT_COLOR );
-        aColor = static_cast<const SvxColorItem*>(pItem)->GetValue();
-
-        if ( pCondSet->GetItemState( nLangId, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rItemSet.Get( nLangId );
-        eLang = static_cast<const SvxLanguageItem*>(pItem)->GetLanguage();
+        pFontAttr = pCondSet->GetItemIfSet( nFontId );
+        if ( !pFontAttr )
+            pFontAttr = &rItemSet.Get( nFontId );
+
+        const SvxFontHeightItem* pFontHeightItem = pCondSet->GetItemIfSet( 
nHeightId );
+        if ( !pFontHeightItem )
+            pFontHeightItem = &rItemSet.Get( nHeightId );
+        nFontHeight = pFontHeightItem->GetHeight();
+
+        const SvxWeightItem* pFontHWeightItem = pCondSet->GetItemIfSet( 
nWeightId );
+        if ( !pFontHWeightItem )
+            pFontHWeightItem = &rItemSet.Get( nWeightId );
+        eWeight = pFontHWeightItem->GetValue();
+
+        const SvxPostureItem* pPostureItem = pCondSet->GetItemIfSet( 
nPostureId );
+        if ( !pPostureItem )
+            pPostureItem = &rItemSet.Get( nPostureId );
+        eItalic = pPostureItem->GetValue();
+
+        const SvxUnderlineItem* pUnderlineItem = pCondSet->GetItemIfSet( 
ATTR_FONT_UNDERLINE );
+        if ( !pUnderlineItem )
+            pUnderlineItem = &rItemSet.Get( ATTR_FONT_UNDERLINE );
+        eUnder = pUnderlineItem->GetValue();
+
+        const SvxOverlineItem* pOverlineItem = pCondSet->GetItemIfSet( 
ATTR_FONT_OVERLINE );
+        if ( !pOverlineItem )
+            pOverlineItem = &rItemSet.Get( ATTR_FONT_OVERLINE );
+        eOver = pOverlineItem->GetValue();
+
+        const SvxWordLineModeItem* pWordlineItem = pCondSet->GetItemIfSet( 
ATTR_FONT_WORDLINE );
+        if ( !pWordlineItem )
+            pWordlineItem = &rItemSet.Get( ATTR_FONT_WORDLINE );
+        bWordLine = pWordlineItem->GetValue();
+
+        const SvxCrossedOutItem* pCrossedOutItem = pCondSet->GetItemIfSet( 
ATTR_FONT_CROSSEDOUT );
+        if ( !pCrossedOutItem )
+            pCrossedOutItem = &rItemSet.Get( ATTR_FONT_CROSSEDOUT );
+        eStrike = pCrossedOutItem->GetValue();
+
+        const SvxContourItem* pContourItem = pCondSet->GetItemIfSet( 
ATTR_FONT_CONTOUR );
+        if ( !pContourItem )
+            pContourItem = &rItemSet.Get( ATTR_FONT_CONTOUR );
+        bOutline = pContourItem->GetValue();
+
+        const SvxShadowedItem* pShadowedItem = pCondSet->GetItemIfSet( 
ATTR_FONT_SHADOWED );
+        if ( !pShadowedItem )
+            pShadowedItem = &rItemSet.Get( ATTR_FONT_SHADOWED );
+        bShadow = pShadowedItem->GetValue();
+
+        const SvxEmphasisMarkItem* pEmphasisMarkItem = pCondSet->GetItemIfSet( 
ATTR_FONT_EMPHASISMARK );
+        if ( !pEmphasisMarkItem )
+            pEmphasisMarkItem = &rItemSet.Get( ATTR_FONT_EMPHASISMARK );
+        eEmphasis = pEmphasisMarkItem->GetEmphasisMark();
+
+        const SvxCharReliefItem* pCharReliefItem = pCondSet->GetItemIfSet( 
ATTR_FONT_RELIEF );
+        if ( !pCharReliefItem )
+            pCharReliefItem = &rItemSet.Get( ATTR_FONT_RELIEF );
+        eRelief = pCharReliefItem->GetValue();
+
+        const SvxColorItem* pColorItem = pCondSet->GetItemIfSet( 
ATTR_FONT_COLOR );
+        if ( !pColorItem )
+            pColorItem = &rItemSet.Get( ATTR_FONT_COLOR );
+        aColor = pColorItem->GetValue();
+
+        const SvxLanguageItem* pLanguageItem = pCondSet->GetItemIfSet( nLangId 
);
+        if ( !pLanguageItem )
+            pLanguageItem = &rItemSet.Get( nLangId );
+        eLang = pLanguageItem->GetLanguage();
     }
     else    // Everything from rItemSet
     {
-        pFontAttr = &static_cast<const SvxFontItem&>(rItemSet.Get( nFontId ));
-        nFontHeight = static_cast<const SvxFontHeightItem&>(
-                        rItemSet.Get( nHeightId )).GetHeight();
-        eWeight = static_cast<const SvxWeightItem&>(
-                        rItemSet.Get( nWeightId )).GetValue();
-        eItalic = static_cast<const SvxPostureItem&>(
-                        rItemSet.Get( nPostureId )).GetValue();
+        pFontAttr = &rItemSet.Get( nFontId );
+        nFontHeight = rItemSet.Get( nHeightId ).GetHeight();
+        eWeight = rItemSet.Get( nWeightId ).GetValue();
+        eItalic = rItemSet.Get( nPostureId ).GetValue();
         eUnder = rItemSet.Get( ATTR_FONT_UNDERLINE ).GetValue();
         eOver = rItemSet.Get( ATTR_FONT_OVERLINE ).GetValue();
         bWordLine = rItemSet.Get( ATTR_FONT_WORDLINE ).GetValue();
@@ -341,7 +357,7 @@ void ScPatternAttr::GetFont(
         eRelief = rItemSet.Get( ATTR_FONT_RELIEF ).GetValue();
         aColor = rItemSet.Get( ATTR_FONT_COLOR ).GetValue();
         // for graphite language features
-        eLang = static_cast<const SvxLanguageItem&>(rItemSet.Get( nLangId 
)).GetLanguage();
+        eLang = rItemSet.Get( nLangId ).GetLanguage();
     }
     OSL_ENSURE(pFontAttr,"Oops?");
 
@@ -400,10 +416,10 @@ void ScPatternAttr::GetFont(
             Color aBackColor;
             if ( pCondSet )
             {
-                const SfxPoolItem* pItem;
-                if ( pCondSet->GetItemState( ATTR_BACKGROUND, true, &pItem ) 
!= SfxItemState::SET )
+                const SvxBrushItem* pItem = pCondSet->GetItemIfSet( 
ATTR_BACKGROUND );
+                if ( !pItem )
                     pItem = &rItemSet.Get( ATTR_BACKGROUND );
-                aBackColor = static_cast<const 
SvxBrushItem*>(pItem)->GetColor();
+                aBackColor = pItem->GetColor();
             }
             else
                 aBackColor = rItemSet.Get( ATTR_BACKGROUND ).GetColor();
@@ -480,99 +496,100 @@ void ScPatternAttr::GetFont(
 
 ScDxfFont ScPatternAttr::GetDxfFont(const SfxItemSet& rItemSet, SvtScriptType 
nScript)
 {
-    sal_uInt16 nFontId, nHeightId, nWeightId, nPostureId, nLangId;
+    TypedWhichId<SvxFontItem> nFontId(0);
+    TypedWhichId<SvxFontHeightItem> nHeightId(0);
+    TypedWhichId<SvxWeightItem> nWeightId(0);
+    TypedWhichId<SvxPostureItem> nPostureId(0);
+    TypedWhichId<SvxLanguageItem> nLangId(0);
     getFontIDsByScriptType(nScript, nFontId, nHeightId, nWeightId, nPostureId, 
nLangId);
-    const SfxPoolItem* pItem;
 
     ScDxfFont aReturn;
 
-    if ( rItemSet.GetItemState( nFontId, true, &pItem ) == SfxItemState::SET )
+    if ( const SvxFontItem* pItem = rItemSet.GetItemIfSet( nFontId ) )
     {
-        pItem = &rItemSet.Get( nFontId );
-        aReturn.pFontAttr = static_cast<const SvxFontItem*>(pItem);
+        aReturn.pFontAttr = pItem;
     }
 
-    if ( rItemSet.GetItemState( nHeightId, true, &pItem ) == SfxItemState::SET 
)
+    if ( const SvxFontHeightItem* pItem = rItemSet.GetItemIfSet( nHeightId ) )
     {
-        pItem = &rItemSet.Get( nHeightId );
-        aReturn.nFontHeight = static_cast<const 
SvxFontHeightItem*>(pItem)->GetHeight();
+        aReturn.nFontHeight = pItem->GetHeight();
     }
 
-    if ( rItemSet.GetItemState( nWeightId, true, &pItem ) == SfxItemState::SET 
)
+    if ( const SvxWeightItem* pItem = rItemSet.GetItemIfSet( nWeightId ) )
     {
-        pItem = &rItemSet.Get( nWeightId );
-        aReturn.eWeight = static_cast<const SvxWeightItem*>(pItem)->GetValue();
+        aReturn.eWeight = pItem->GetValue();
     }
 
-    if ( rItemSet.GetItemState( nPostureId, true, &pItem ) == 
SfxItemState::SET )
+    if ( const SvxPostureItem* pItem = rItemSet.GetItemIfSet( nPostureId ) )
     {
-        pItem = &rItemSet.Get( nPostureId );
-        aReturn.eItalic = static_cast<const 
SvxPostureItem*>(pItem)->GetValue();
+        aReturn.eItalic = pItem->GetValue();
     }
 
-    if ( rItemSet.GetItemState( ATTR_FONT_UNDERLINE, true, &pItem ) == 
SfxItemState::SET )
+    if ( const SvxUnderlineItem* pItem = rItemSet.GetItemIfSet( 
ATTR_FONT_UNDERLINE ) )
     {
         pItem = &rItemSet.Get( ATTR_FONT_UNDERLINE );
-        aReturn.eUnder = static_cast<const 
SvxUnderlineItem*>(pItem)->GetValue();
+        aReturn.eUnder = pItem->GetValue();
     }
 
-    if ( rItemSet.GetItemState( ATTR_FONT_OVERLINE, true, &pItem ) == 
SfxItemState::SET )
+    if ( const SvxOverlineItem* pItem = rItemSet.GetItemIfSet( 
ATTR_FONT_OVERLINE ) )
     {
-        pItem = &rItemSet.Get( ATTR_FONT_OVERLINE );
-        aReturn.eOver = static_cast<const SvxOverlineItem*>(pItem)->GetValue();
+        aReturn.eOver = pItem->GetValue();
     }
 
-    if ( rItemSet.GetItemState( ATTR_FONT_WORDLINE, true, &pItem ) == 
SfxItemState::SET )
+    if ( const SvxWordLineModeItem* pItem = rItemSet.GetItemIfSet( 
ATTR_FONT_WORDLINE ) )
     {
-        pItem = &rItemSet.Get( ATTR_FONT_WORDLINE );
-        aReturn.bWordLine = static_cast<const 
SvxWordLineModeItem*>(pItem)->GetValue();
+        aReturn.bWordLine = pItem->GetValue();
     }
 
-    if ( rItemSet.GetItemState( ATTR_FONT_CROSSEDOUT, true, &pItem ) == 
SfxItemState::SET )
+    if ( const SvxCrossedOutItem* pItem = rItemSet.GetItemIfSet( 
ATTR_FONT_CROSSEDOUT ) )
     {
         pItem = &rItemSet.Get( ATTR_FONT_CROSSEDOUT );
-        aReturn.eStrike = static_cast<const 
SvxCrossedOutItem*>(pItem)->GetValue();
+        aReturn.eStrike = pItem->GetValue();
     }
 
-    if ( rItemSet.GetItemState( ATTR_FONT_CONTOUR, true, &pItem ) == 
SfxItemState::SET )
+    if ( const SvxContourItem* pItem = rItemSet.GetItemIfSet( 
ATTR_FONT_CONTOUR ) )
     {
-        pItem = &rItemSet.Get( ATTR_FONT_CONTOUR );
-        aReturn.bOutline = static_cast<const 
SvxContourItem*>(pItem)->GetValue();
+        aReturn.bOutline = pItem->GetValue();
     }
 
-    if ( rItemSet.GetItemState( ATTR_FONT_SHADOWED, true, &pItem ) == 
SfxItemState::SET )
+    if ( const SvxShadowedItem* pItem = rItemSet.GetItemIfSet( 
ATTR_FONT_SHADOWED ) )
     {
         pItem = &rItemSet.Get( ATTR_FONT_SHADOWED );
-        aReturn.bShadow = static_cast<const 
SvxShadowedItem*>(pItem)->GetValue();
+        aReturn.bShadow = pItem->GetValue();
     }
 
-    if ( rItemSet.GetItemState( ATTR_FONT_EMPHASISMARK, true, &pItem ) == 
SfxItemState::SET )
+    if ( const SvxEmphasisMarkItem* pItem = rItemSet.GetItemIfSet( 
ATTR_FONT_EMPHASISMARK ) )
     {
-        pItem = &rItemSet.Get( ATTR_FONT_EMPHASISMARK );
-        aReturn.eEmphasis = static_cast<const 
SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark();
+        aReturn.eEmphasis = pItem->GetEmphasisMark();
     }
 
-    if ( rItemSet.GetItemState( ATTR_FONT_RELIEF, true, &pItem ) == 
SfxItemState::SET )
+    if ( const SvxCharReliefItem* pItem = rItemSet.GetItemIfSet( 
ATTR_FONT_RELIEF ) )
     {
-        pItem = &rItemSet.Get( ATTR_FONT_RELIEF );
-        aReturn.eRelief = static_cast<const 
SvxCharReliefItem*>(pItem)->GetValue();
+        aReturn.eRelief = pItem->GetValue();
     }
 
-    if ( rItemSet.GetItemState( ATTR_FONT_COLOR, true, &pItem ) == 
SfxItemState::SET )
+    if ( const SvxColorItem* pItem = rItemSet.GetItemIfSet( ATTR_FONT_COLOR ) )
     {
-        pItem = &rItemSet.Get( ATTR_FONT_COLOR );
-        aReturn.aColor = static_cast<const SvxColorItem*>(pItem)->GetValue();
+        aReturn.aColor = pItem->GetValue();
     }
 
-    if ( rItemSet.GetItemState( nLangId, true, &pItem ) == SfxItemState::SET )
+    if ( const SvxLanguageItem* pItem = rItemSet.GetItemIfSet( nLangId ) )
     {
-        pItem = &rItemSet.Get( nLangId );
-        aReturn.eLang = static_cast<const 
SvxLanguageItem*>(pItem)->GetLanguage();
+        aReturn.eLang = pItem->GetLanguage();
     }
 
     return aReturn;
 }
 
+template <class T>
+static void lcl_populate( std::unique_ptr<T>& rxItem, TypedWhichId<T> nWhich, 
const SfxItemSet& rSrcSet, const SfxItemSet* pCondSet )
+{
+    const T* pItem = pCondSet->GetItemIfSet( nWhich );
+    if ( !pItem )
+        pItem = &rSrcSet.Get( nWhich );
+    rxItem.reset(pItem->Clone());
+}
+
 void ScPatternAttr::FillToEditItemSet( SfxItemSet& rEditSet, const SfxItemSet& 
rSrcSet, const SfxItemSet* pCondSet )
 {
     //  Read Items
@@ -601,106 +618,109 @@ void ScPatternAttr::FillToEditItemSet( SfxItemSet& 
rEditSet, const SfxItemSet& r
 
     if ( pCondSet )
     {
-        const SfxPoolItem* pItem;
-
-        if ( pCondSet->GetItemState( ATTR_FONT_COLOR, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_FONT_COLOR );
-        aColorItem.reset(&pItem->Clone()->StaticWhichCast(ATTR_FONT_COLOR));
-
-        if ( pCondSet->GetItemState( ATTR_FONT, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_FONT );
-        aFontItem.reset(&pItem->Clone()->StaticWhichCast(ATTR_FONT));
-
-        if ( pCondSet->GetItemState( ATTR_CJK_FONT, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_CJK_FONT );
-        aCjkFontItem.reset(&pItem->Clone()->StaticWhichCast(ATTR_CJK_FONT));
-
-        if ( pCondSet->GetItemState( ATTR_CTL_FONT, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_CTL_FONT );
-        aCtlFontItem.reset(&pItem->Clone()->StaticWhichCast(ATTR_CTL_FONT));
-
-        if ( pCondSet->GetItemState( ATTR_FONT_HEIGHT, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_FONT_HEIGHT );
-        nTHeight = static_cast<const SvxFontHeightItem*>(pItem)->GetHeight();
-        if ( pCondSet->GetItemState( ATTR_CJK_FONT_HEIGHT, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_CJK_FONT_HEIGHT );
-        nCjkTHeight = static_cast<const 
SvxFontHeightItem*>(pItem)->GetHeight();
-        if ( pCondSet->GetItemState( ATTR_CTL_FONT_HEIGHT, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_CTL_FONT_HEIGHT );
-        nCtlTHeight = static_cast<const 
SvxFontHeightItem*>(pItem)->GetHeight();
-
-        if ( pCondSet->GetItemState( ATTR_FONT_WEIGHT, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_FONT_WEIGHT );
-        eWeight = static_cast<const SvxWeightItem*>(pItem)->GetValue();
-        if ( pCondSet->GetItemState( ATTR_CJK_FONT_WEIGHT, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_CJK_FONT_WEIGHT );
-        eCjkWeight = static_cast<const SvxWeightItem*>(pItem)->GetValue();
-        if ( pCondSet->GetItemState( ATTR_CTL_FONT_WEIGHT, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_CTL_FONT_WEIGHT );
-        eCtlWeight = static_cast<const SvxWeightItem*>(pItem)->GetValue();
-
-        if ( pCondSet->GetItemState( ATTR_FONT_POSTURE, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_FONT_POSTURE );
-        eItalic = static_cast<const SvxPostureItem*>(pItem)->GetValue();
-        if ( pCondSet->GetItemState( ATTR_CJK_FONT_POSTURE, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_CJK_FONT_POSTURE );
-        eCjkItalic = static_cast<const SvxPostureItem*>(pItem)->GetValue();
-        if ( pCondSet->GetItemState( ATTR_CTL_FONT_POSTURE, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_CTL_FONT_POSTURE );
-        eCtlItalic = static_cast<const SvxPostureItem*>(pItem)->GetValue();
-
-        if ( pCondSet->GetItemState( ATTR_FONT_UNDERLINE, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_FONT_UNDERLINE );
-        
aUnderlineItem.reset(&pItem->Clone()->StaticWhichCast(ATTR_FONT_UNDERLINE));
-
-        if ( pCondSet->GetItemState( ATTR_FONT_OVERLINE, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_FONT_OVERLINE );
-        
aOverlineItem.reset(&pItem->Clone()->StaticWhichCast(ATTR_FONT_OVERLINE));
-
-        if ( pCondSet->GetItemState( ATTR_FONT_WORDLINE, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_FONT_WORDLINE );
-        bWordLine = static_cast<const SvxWordLineModeItem*>(pItem)->GetValue();
-
-        if ( pCondSet->GetItemState( ATTR_FONT_CROSSEDOUT, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_FONT_CROSSEDOUT );
-        eStrike = static_cast<const SvxCrossedOutItem*>(pItem)->GetValue();
-
-        if ( pCondSet->GetItemState( ATTR_FONT_CONTOUR, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_FONT_CONTOUR );
-        bOutline = static_cast<const SvxContourItem*>(pItem)->GetValue();
-
-        if ( pCondSet->GetItemState( ATTR_FONT_SHADOWED, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_FONT_SHADOWED );
-        bShadow = static_cast<const SvxShadowedItem*>(pItem)->GetValue();
-
-        if ( pCondSet->GetItemState( ATTR_FORBIDDEN_RULES, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_FORBIDDEN_RULES );
-        bForbidden = static_cast<const 
SvxForbiddenRuleItem*>(pItem)->GetValue();
-
-        if ( pCondSet->GetItemState( ATTR_FONT_EMPHASISMARK, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_FONT_EMPHASISMARK );
-        eEmphasis = static_cast<const 
SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark();
-        if ( pCondSet->GetItemState( ATTR_FONT_RELIEF, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_FONT_RELIEF );
-        eRelief = static_cast<const SvxCharReliefItem*>(pItem)->GetValue();
-
-        if ( pCondSet->GetItemState( ATTR_FONT_LANGUAGE, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_FONT_LANGUAGE );
-        eLang = static_cast<const SvxLanguageItem*>(pItem)->GetLanguage();
-        if ( pCondSet->GetItemState( ATTR_CJK_FONT_LANGUAGE, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_CJK_FONT_LANGUAGE );
-        eCjkLang = static_cast<const SvxLanguageItem*>(pItem)->GetLanguage();
-        if ( pCondSet->GetItemState( ATTR_CTL_FONT_LANGUAGE, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_CTL_FONT_LANGUAGE );
-        eCtlLang = static_cast<const SvxLanguageItem*>(pItem)->GetLanguage();
-
-        if ( pCondSet->GetItemState( ATTR_HYPHENATE, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_HYPHENATE );
-        bHyphenate = static_cast<const ScHyphenateCell*>(pItem)->GetValue();
-
-        if ( pCondSet->GetItemState( ATTR_WRITINGDIR, true, &pItem ) != 
SfxItemState::SET )
-            pItem = &rSrcSet.Get( ATTR_WRITINGDIR );
-        eDirection = static_cast<const 
SvxFrameDirectionItem*>(pItem)->GetValue();
+        lcl_populate(aColorItem, ATTR_FONT_COLOR, rSrcSet, pCondSet);
+        lcl_populate(aFontItem, ATTR_FONT, rSrcSet, pCondSet);
+        lcl_populate(aCjkFontItem, ATTR_CJK_FONT, rSrcSet, pCondSet);
+        lcl_populate(aCtlFontItem, ATTR_CTL_FONT, rSrcSet, pCondSet);
+
+        const SvxFontHeightItem* pFontHeightItem = pCondSet->GetItemIfSet( 
ATTR_FONT_HEIGHT );
+        if (!pFontHeightItem)
+            pFontHeightItem = &rSrcSet.Get( ATTR_FONT_HEIGHT );
+        nTHeight = pFontHeightItem->GetHeight();
+        pFontHeightItem = pCondSet->GetItemIfSet( ATTR_CJK_FONT_HEIGHT );
+        if ( !pFontHeightItem )
+            pFontHeightItem = &rSrcSet.Get( ATTR_CJK_FONT_HEIGHT );
+        nCjkTHeight = pFontHeightItem->GetHeight();
+        pFontHeightItem = pCondSet->GetItemIfSet( ATTR_CTL_FONT_HEIGHT );
+        if ( !pFontHeightItem )
+            pFontHeightItem = &rSrcSet.Get( ATTR_CTL_FONT_HEIGHT );
+        nCtlTHeight = pFontHeightItem->GetHeight();
+
+        const SvxWeightItem* pWeightItem = pCondSet->GetItemIfSet( 
ATTR_FONT_WEIGHT );
+        if ( !pWeightItem )
+            pWeightItem = &rSrcSet.Get( ATTR_FONT_WEIGHT );
+        eWeight = pWeightItem->GetValue();
+        pWeightItem = pCondSet->GetItemIfSet( ATTR_CJK_FONT_WEIGHT );
+        if ( !pWeightItem )
+            pWeightItem = &rSrcSet.Get( ATTR_CJK_FONT_WEIGHT );
+        eCjkWeight = pWeightItem->GetValue();
+        pWeightItem = pCondSet->GetItemIfSet( ATTR_CTL_FONT_WEIGHT );
+        if ( !pWeightItem )
+            pWeightItem = &rSrcSet.Get( ATTR_CTL_FONT_WEIGHT );
+        eCtlWeight = pWeightItem->GetValue();
+
+        const SvxPostureItem* pPostureItem = pCondSet->GetItemIfSet( 
ATTR_FONT_POSTURE );
+        if ( !pPostureItem )
+            pPostureItem = &rSrcSet.Get( ATTR_FONT_POSTURE );
+        eItalic = pPostureItem->GetValue();
+        pPostureItem = pCondSet->GetItemIfSet( ATTR_CJK_FONT_POSTURE );
+        if ( !pPostureItem )
+            pPostureItem = &rSrcSet.Get( ATTR_CJK_FONT_POSTURE );
+        eCjkItalic = pPostureItem->GetValue();
+        pPostureItem = pCondSet->GetItemIfSet( ATTR_CTL_FONT_POSTURE );
+        if ( !pPostureItem )
+            pPostureItem = &rSrcSet.Get( ATTR_CTL_FONT_POSTURE );
+        eCtlItalic = pPostureItem->GetValue();
+
+        lcl_populate(aUnderlineItem, ATTR_FONT_UNDERLINE, rSrcSet, pCondSet);
+        lcl_populate(aOverlineItem, ATTR_FONT_OVERLINE, rSrcSet, pCondSet);
+
+        const SvxWordLineModeItem* pWordLineModeItem = pCondSet->GetItemIfSet( 
ATTR_FONT_WORDLINE );
+        if ( !pWordLineModeItem )
+            pWordLineModeItem = &rSrcSet.Get( ATTR_FONT_WORDLINE );
+        bWordLine = pWordLineModeItem->GetValue();
+
+        const SvxCrossedOutItem* pCrossedOutItem = pCondSet->GetItemIfSet( 
ATTR_FONT_CROSSEDOUT );
+        if ( !pCrossedOutItem )
+            pCrossedOutItem = &rSrcSet.Get( ATTR_FONT_CROSSEDOUT );
+        eStrike = pCrossedOutItem->GetValue();
+
+        const SvxContourItem* pContourItem = pCondSet->GetItemIfSet( 
ATTR_FONT_CONTOUR );
+        if ( !pContourItem )
+            pContourItem = &rSrcSet.Get( ATTR_FONT_CONTOUR );
+        bOutline = pContourItem->GetValue();
+
+        const SvxShadowedItem* pShadowedItem = pCondSet->GetItemIfSet( 
ATTR_FONT_SHADOWED );
+        if ( !pShadowedItem )
+            pShadowedItem = &rSrcSet.Get( ATTR_FONT_SHADOWED );
+        bShadow = pShadowedItem->GetValue();
+
+        const SvxForbiddenRuleItem* pForbiddenRuleItem = 
pCondSet->GetItemIfSet( ATTR_FORBIDDEN_RULES );
+        if ( !pForbiddenRuleItem )
+            pForbiddenRuleItem = &rSrcSet.Get( ATTR_FORBIDDEN_RULES );
+        bForbidden = pForbiddenRuleItem->GetValue();
+
+        const SvxEmphasisMarkItem* pEmphasisMarkItem = pCondSet->GetItemIfSet( 
ATTR_FONT_EMPHASISMARK );
+        if ( !pEmphasisMarkItem )
+            pEmphasisMarkItem = &rSrcSet.Get( ATTR_FONT_EMPHASISMARK );
+        eEmphasis = pEmphasisMarkItem->GetEmphasisMark();
+        const SvxCharReliefItem* pCharReliefItem = pCondSet->GetItemIfSet( 
ATTR_FONT_RELIEF );
+        if ( !pCharReliefItem )
+            pCharReliefItem = &rSrcSet.Get( ATTR_FONT_RELIEF );
+        eRelief = pCharReliefItem->GetValue();
+
+        const SvxLanguageItem* pLanguageItem = pCondSet->GetItemIfSet( 
ATTR_FONT_LANGUAGE );
+        if ( !pLanguageItem )
+            pLanguageItem = &rSrcSet.Get( ATTR_FONT_LANGUAGE );
+        eLang = pLanguageItem->GetLanguage();
+        pLanguageItem = pCondSet->GetItemIfSet( ATTR_CJK_FONT_LANGUAGE );
+        if ( !pLanguageItem )
+            pLanguageItem = &rSrcSet.Get( ATTR_CJK_FONT_LANGUAGE );
+        eCjkLang = pLanguageItem->GetLanguage();
+        pLanguageItem = pCondSet->GetItemIfSet( ATTR_CTL_FONT_LANGUAGE );
+        if ( !pLanguageItem )
+            pLanguageItem = &rSrcSet.Get( ATTR_CTL_FONT_LANGUAGE );
+        eCtlLang = pLanguageItem->GetLanguage();
+
+        const ScHyphenateCell* pHyphenateCell = pCondSet->GetItemIfSet( 
ATTR_HYPHENATE );
+        if ( !pHyphenateCell )
+            pHyphenateCell = &rSrcSet.Get( ATTR_HYPHENATE );
+        bHyphenate = pHyphenateCell->GetValue();
+
+        const SvxFrameDirectionItem* pFrameDirectionItem = 
pCondSet->GetItemIfSet( ATTR_WRITINGDIR );
+        if ( !pFrameDirectionItem )
+            pFrameDirectionItem = &rSrcSet.Get( ATTR_WRITINGDIR );
+        eDirection = pFrameDirectionItem->GetValue();
     }
     else        // Everything directly from Pattern
     {
@@ -804,86 +824,86 @@ void ScPatternAttr::FillEditItemSet( SfxItemSet* 
pEditSet, const SfxItemSet* pCo
 
 void ScPatternAttr::GetFromEditItemSet( SfxItemSet& rDestSet, const 
SfxItemSet& rEditSet )
 {
-    const SfxPoolItem* pItem;
-
-    if (rEditSet.GetItemState(EE_CHAR_COLOR,true,&pItem) == SfxItemState::SET)
-        rDestSet.Put( *static_cast<const SvxColorItem*>(pItem), 
ATTR_FONT_COLOR );
-
-    if (rEditSet.GetItemState(EE_CHAR_FONTINFO,true,&pItem) == 
SfxItemState::SET)
-        rDestSet.Put( *static_cast<const SvxFontItem*>(pItem), ATTR_FONT );
-    if (rEditSet.GetItemState(EE_CHAR_FONTINFO_CJK,true,&pItem) == 
SfxItemState::SET)
-        rDestSet.Put( *static_cast<const SvxFontItem*>(pItem), ATTR_CJK_FONT );
-    if (rEditSet.GetItemState(EE_CHAR_FONTINFO_CTL,true,&pItem) == 
SfxItemState::SET)
-        rDestSet.Put( *static_cast<const SvxFontItem*>(pItem), ATTR_CTL_FONT );
-
-    if (rEditSet.GetItemState(EE_CHAR_FONTHEIGHT,true,&pItem) == 
SfxItemState::SET)
-        rDestSet.Put( SvxFontHeightItem(o3tl::toTwips(static_cast<const 
SvxFontHeightItem*>(pItem)->GetHeight(), o3tl::Length::mm100),
+    if (const SvxColorItem* pItem = rEditSet.GetItemIfSet(EE_CHAR_COLOR))
+        rDestSet.Put( *pItem, ATTR_FONT_COLOR );
+
+    if (const SvxFontItem* pItem = rEditSet.GetItemIfSet(EE_CHAR_FONTINFO))
+        rDestSet.Put( *pItem, ATTR_FONT );
+    if (const SvxFontItem* pItem = rEditSet.GetItemIfSet(EE_CHAR_FONTINFO_CJK))
+        rDestSet.Put( *pItem, ATTR_CJK_FONT );
+    if (const SvxFontItem* pItem = rEditSet.GetItemIfSet(EE_CHAR_FONTINFO_CTL))
+        rDestSet.Put( *pItem, ATTR_CTL_FONT );
+
+    if (const SvxFontHeightItem* pItem = 
rEditSet.GetItemIfSet(EE_CHAR_FONTHEIGHT))
+        rDestSet.Put( SvxFontHeightItem(o3tl::toTwips(pItem->GetHeight(), 
o3tl::Length::mm100),
                         100, ATTR_FONT_HEIGHT ) );
-    if (rEditSet.GetItemState(EE_CHAR_FONTHEIGHT_CJK,true,&pItem) == 
SfxItemState::SET)
-        rDestSet.Put( SvxFontHeightItem(o3tl::toTwips(static_cast<const 
SvxFontHeightItem*>(pItem)->GetHeight(), o3tl::Length::mm100),
+    if (const SvxFontHeightItem* pItem = 
rEditSet.GetItemIfSet(EE_CHAR_FONTHEIGHT_CJK))
+        rDestSet.Put( SvxFontHeightItem(o3tl::toTwips(pItem->GetHeight(), 
o3tl::Length::mm100),
                         100, ATTR_CJK_FONT_HEIGHT ) );
-    if (rEditSet.GetItemState(EE_CHAR_FONTHEIGHT_CTL,true,&pItem) == 
SfxItemState::SET)
-        rDestSet.Put( SvxFontHeightItem(o3tl::toTwips(static_cast<const 
SvxFontHeightItem*>(pItem)->GetHeight(), o3tl::Length::mm100),
+    if (const SvxFontHeightItem* pItem = 
rEditSet.GetItemIfSet(EE_CHAR_FONTHEIGHT_CTL))
+        rDestSet.Put( SvxFontHeightItem(o3tl::toTwips(pItem->GetHeight(), 
o3tl::Length::mm100),
                         100, ATTR_CTL_FONT_HEIGHT ) );
 
-    if (rEditSet.GetItemState(EE_CHAR_WEIGHT,true,&pItem) == SfxItemState::SET)
-        rDestSet.Put( SvxWeightItem( static_cast<const 
SvxWeightItem*>(pItem)->GetValue(),
+    if (const SvxWeightItem* pItem = rEditSet.GetItemIfSet(EE_CHAR_WEIGHT))
+        rDestSet.Put( SvxWeightItem( pItem->GetValue(),
                         ATTR_FONT_WEIGHT) );
-    if (rEditSet.GetItemState(EE_CHAR_WEIGHT_CJK,true,&pItem) == 
SfxItemState::SET)
-        rDestSet.Put( SvxWeightItem( static_cast<const 
SvxWeightItem*>(pItem)->GetValue(),
+    if (const SvxWeightItem* pItem = rEditSet.GetItemIfSet(EE_CHAR_WEIGHT_CJK))
+        rDestSet.Put( SvxWeightItem( pItem->GetValue(),
                         ATTR_CJK_FONT_WEIGHT) );
-    if (rEditSet.GetItemState(EE_CHAR_WEIGHT_CTL,true,&pItem) == 
SfxItemState::SET)
-        rDestSet.Put( SvxWeightItem( static_cast<const 
SvxWeightItem*>(pItem)->GetValue(),
+    if (const SvxWeightItem* pItem = rEditSet.GetItemIfSet(EE_CHAR_WEIGHT_CTL))
+        rDestSet.Put( SvxWeightItem( pItem->GetValue(),
                         ATTR_CTL_FONT_WEIGHT) );
 
     // SvxTextLineItem contains enum and color
-    if (rEditSet.GetItemState(EE_CHAR_UNDERLINE,true,&pItem) == 
SfxItemState::SET)
-        rDestSet.Put( *static_cast<const SvxUnderlineItem*>(pItem), 
ATTR_FONT_UNDERLINE );
-    if (rEditSet.GetItemState(EE_CHAR_OVERLINE,true,&pItem) == 
SfxItemState::SET)
-        rDestSet.Put( *static_cast<const SvxOverlineItem*>(pItem), 
ATTR_FONT_OVERLINE );
-    if (rEditSet.GetItemState(EE_CHAR_WLM,true,&pItem) == SfxItemState::SET)
-        rDestSet.Put( SvxWordLineModeItem( static_cast<const 
SvxWordLineModeItem*>(pItem)->GetValue(),
+    if (const SvxUnderlineItem* pItem = 
rEditSet.GetItemIfSet(EE_CHAR_UNDERLINE))
+        rDestSet.Put( *pItem, ATTR_FONT_UNDERLINE );
+    if (const SvxOverlineItem* pItem = rEditSet.GetItemIfSet(EE_CHAR_OVERLINE))
+        rDestSet.Put( *pItem, ATTR_FONT_OVERLINE );
+    if (const SvxWordLineModeItem* pItem = rEditSet.GetItemIfSet(EE_CHAR_WLM))
+        rDestSet.Put( SvxWordLineModeItem( pItem->GetValue(),
                         ATTR_FONT_WORDLINE) );
 
-    if (rEditSet.GetItemState(EE_CHAR_STRIKEOUT,true,&pItem) == 
SfxItemState::SET)
-        rDestSet.Put( SvxCrossedOutItem( static_cast<const 
SvxCrossedOutItem*>(pItem)->GetValue(),
+    if (const SvxCrossedOutItem* pItem = 
rEditSet.GetItemIfSet(EE_CHAR_STRIKEOUT))
+        rDestSet.Put( SvxCrossedOutItem( pItem->GetValue(),
                         ATTR_FONT_CROSSEDOUT) );
 
-    if (rEditSet.GetItemState(EE_CHAR_ITALIC,true,&pItem) == SfxItemState::SET)
-        rDestSet.Put( SvxPostureItem( static_cast<const 
SvxPostureItem*>(pItem)->GetValue(),
+    if (const SvxPostureItem* pItem = rEditSet.GetItemIfSet(EE_CHAR_ITALIC))
+        rDestSet.Put( SvxPostureItem( pItem->GetValue(),
                         ATTR_FONT_POSTURE) );
-    if (rEditSet.GetItemState(EE_CHAR_ITALIC_CJK,true,&pItem) == 
SfxItemState::SET)
-        rDestSet.Put( SvxPostureItem( static_cast<const 
SvxPostureItem*>(pItem)->GetValue(),
+    if (const SvxPostureItem* pItem = 
rEditSet.GetItemIfSet(EE_CHAR_ITALIC_CJK))
+        rDestSet.Put( SvxPostureItem( pItem->GetValue(),
                         ATTR_CJK_FONT_POSTURE) );
-    if (rEditSet.GetItemState(EE_CHAR_ITALIC_CTL,true,&pItem) == 
SfxItemState::SET)
-        rDestSet.Put( SvxPostureItem( static_cast<const 
SvxPostureItem*>(pItem)->GetValue(),
+    if (const SvxPostureItem* pItem = 
rEditSet.GetItemIfSet(EE_CHAR_ITALIC_CTL))
+        rDestSet.Put( SvxPostureItem( pItem->GetValue(),
                         ATTR_CTL_FONT_POSTURE) );
 
-    if (rEditSet.GetItemState(EE_CHAR_OUTLINE,true,&pItem) == 
SfxItemState::SET)
-        rDestSet.Put( SvxContourItem( static_cast<const 
SvxContourItem*>(pItem)->GetValue(),
+    if (const SvxContourItem* pItem = rEditSet.GetItemIfSet(EE_CHAR_OUTLINE))
+        rDestSet.Put( SvxContourItem( pItem->GetValue(),
                         ATTR_FONT_CONTOUR) );
-    if (rEditSet.GetItemState(EE_CHAR_SHADOW,true,&pItem) == SfxItemState::SET)
-        rDestSet.Put( SvxShadowedItem( static_cast<const 
SvxShadowedItem*>(pItem)->GetValue(),
+    if (const SvxShadowedItem* pItem = rEditSet.GetItemIfSet(EE_CHAR_SHADOW))
+        rDestSet.Put( SvxShadowedItem( pItem->GetValue(),
                         ATTR_FONT_SHADOWED) );
-    if (rEditSet.GetItemState(EE_CHAR_EMPHASISMARK,true,&pItem) == 
SfxItemState::SET)
-        rDestSet.Put( SvxEmphasisMarkItem( static_cast<const 
SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark(),
+    if (const SvxEmphasisMarkItem* pItem = 
rEditSet.GetItemIfSet(EE_CHAR_EMPHASISMARK))
+        rDestSet.Put( SvxEmphasisMarkItem( pItem->GetEmphasisMark(),
                         ATTR_FONT_EMPHASISMARK) );
-    if (rEditSet.GetItemState(EE_CHAR_RELIEF,true,&pItem) == SfxItemState::SET)
-        rDestSet.Put( SvxCharReliefItem( static_cast<const 
SvxCharReliefItem*>(pItem)->GetValue(),
+    if (const SvxCharReliefItem* pItem = rEditSet.GetItemIfSet(EE_CHAR_RELIEF))
+        rDestSet.Put( SvxCharReliefItem( pItem->GetValue(),
                         ATTR_FONT_RELIEF) );
 
-    if (rEditSet.GetItemState(EE_CHAR_LANGUAGE,true,&pItem) == 
SfxItemState::SET)
-        rDestSet.Put( SvxLanguageItem(static_cast<const 
SvxLanguageItem*>(pItem)->GetValue(), ATTR_FONT_LANGUAGE) );
-    if (rEditSet.GetItemState(EE_CHAR_LANGUAGE_CJK,true,&pItem) == 
SfxItemState::SET)
-        rDestSet.Put( SvxLanguageItem(static_cast<const 
SvxLanguageItem*>(pItem)->GetValue(), ATTR_CJK_FONT_LANGUAGE) );
-    if (rEditSet.GetItemState(EE_CHAR_LANGUAGE_CTL,true,&pItem) == 
SfxItemState::SET)
-        rDestSet.Put( SvxLanguageItem(static_cast<const 
SvxLanguageItem*>(pItem)->GetValue(), ATTR_CTL_FONT_LANGUAGE) );
+    if (const SvxLanguageItem* pItem = rEditSet.GetItemIfSet(EE_CHAR_LANGUAGE))
+        rDestSet.Put( SvxLanguageItem(pItem->GetValue(), ATTR_FONT_LANGUAGE) );
+    if (const SvxLanguageItem* pItem = 
rEditSet.GetItemIfSet(EE_CHAR_LANGUAGE_CJK))
+        rDestSet.Put( SvxLanguageItem(pItem->GetValue(), 
ATTR_CJK_FONT_LANGUAGE) );
+    if (const SvxLanguageItem* pItem = 
rEditSet.GetItemIfSet(EE_CHAR_LANGUAGE_CTL))
+        rDestSet.Put( SvxLanguageItem(pItem->GetValue(), 
ATTR_CTL_FONT_LANGUAGE) );
+
+    const SvxAdjustItem* pAdjustItem = rEditSet.GetItemIfSet(EE_PARA_JUST);
 
-    if (rEditSet.GetItemState(EE_PARA_JUST,true,&pItem) != SfxItemState::SET)
+    if (!pAdjustItem)
         return;
 
     SvxCellHorJustify eVal;
-    switch ( static_cast<const SvxAdjustItem*>(pItem)->GetAdjust() )
+    switch ( pAdjustItem->GetAdjust() )
     {
         case SvxAdjust::Left:
             // EditEngine Default is always set in the GetAttribs() ItemSet !
@@ -1023,11 +1043,11 @@ static SfxStyleSheetBase* lcl_CopyStyleToPool
         // number format exchange list has to be handled here, too
         // (only called for cell styles)
 
-        const SfxPoolItem* pSrcItem;
+        const SfxUInt32Item* pSrcItem;
         if ( pFormatExchangeList &&
-             rSrcSet.GetItemState( ATTR_VALUE_FORMAT, false, &pSrcItem ) == 
SfxItemState::SET )
+             (pSrcItem = rSrcSet.GetItemIfSet( ATTR_VALUE_FORMAT, false )) )
         {
-            sal_uLong nOldFormat = static_cast<const 
SfxUInt32Item*>(pSrcItem)->GetValue();
+            sal_uLong nOldFormat = pSrcItem->GetValue();
             SvNumberFormatterIndexTable::const_iterator it = 
pFormatExchangeList->find(nOldFormat);
             if (it != pFormatExchangeList->end())
             {
@@ -1129,36 +1149,27 @@ bool ScPatternAttr::IsVisible() const
 {
     const SfxItemSet& rSet = GetItemSet();
 
-    const SfxPoolItem* pItem;
-    SfxItemState eState;
-
-    eState = rSet.GetItemState( ATTR_BACKGROUND, true, &pItem );
-    if ( eState == SfxItemState::SET )
-        if ( static_cast<const SvxBrushItem*>(pItem)->GetColor() != 
COL_TRANSPARENT )
+    if ( const SvxBrushItem* pItem = rSet.GetItemIfSet( ATTR_BACKGROUND ) )
+        if ( pItem->GetColor() != COL_TRANSPARENT )
             return true;
 
-    eState = rSet.GetItemState( ATTR_BORDER, true, &pItem );
-    if ( eState == SfxItemState::SET )
+    if ( const SvxBoxItem* pBoxItem = rSet.GetItemIfSet( ATTR_BORDER ) )
     {
-        const SvxBoxItem* pBoxItem = static_cast<const SvxBoxItem*>(pItem);
         if ( pBoxItem->GetTop() || pBoxItem->GetBottom() ||
              pBoxItem->GetLeft() || pBoxItem->GetRight() )
             return true;
     }
 
-    eState = rSet.GetItemState( ATTR_BORDER_TLBR, true, &pItem );
-    if ( eState == SfxItemState::SET )
-        if( static_cast< const SvxLineItem* >( pItem )->GetLine() )
+    if ( const SvxLineItem* pItem = rSet.GetItemIfSet( ATTR_BORDER_TLBR ) )
+        if( pItem->GetLine() )
             return true;
 
-    eState = rSet.GetItemState( ATTR_BORDER_BLTR, true, &pItem );
-    if ( eState == SfxItemState::SET )
-        if( static_cast< const SvxLineItem* >( pItem )->GetLine() )
+    if ( const SvxLineItem* pItem = rSet.GetItemIfSet( ATTR_BORDER_BLTR ) )
+        if( pItem->GetLine() )
             return true;
 
-    eState = rSet.GetItemState( ATTR_SHADOW, true, &pItem );
-    if ( eState == SfxItemState::SET )
-        if ( static_cast<const SvxShadowItem*>(pItem)->GetLocation() != 
SvxShadowLocation::NONE )
+    if ( const SvxShadowItem* pItem = rSet.GetItemIfSet( ATTR_SHADOW ) )
+        if ( pItem->GetLocation() != SvxShadowLocation::NONE )
             return true;
 
     return false;
@@ -1259,9 +1270,8 @@ void ScPatternAttr::StyleToName()
 
 bool ScPatternAttr::IsSymbolFont() const
 {
-    const SfxPoolItem* pItem;
-    if( GetItemSet().GetItemState( ATTR_FONT, true, &pItem ) == 
SfxItemState::SET )
-        return static_cast<const SvxFontItem*>(pItem)->GetCharSet() == 
RTL_TEXTENCODING_SYMBOL;
+    if( const SvxFontItem* pItem = GetItemSet().GetItemIfSet( ATTR_FONT ) )
+        return pItem->GetCharSet() == RTL_TEXTENCODING_SYMBOL;
     else
         return false;
 }
@@ -1302,14 +1312,12 @@ sal_uInt32 ScPatternAttr::GetNumberFormat( 
SvNumberFormatter* pFormatter,
 
     // Conditional format takes precedence over style and even hard format.
 
-    const SfxPoolItem* pFormItem;
     sal_uInt32 nFormat;
-    const SfxPoolItem* pLangItem;
     LanguageType eLang;
-    if (pCondSet->GetItemState(ATTR_VALUE_FORMAT, true, &pFormItem) == 
SfxItemState::SET )
+    if (pCondSet->GetItemState(ATTR_VALUE_FORMAT) == SfxItemState::SET )
     {
         nFormat = getNumberFormatKey(*pCondSet);
-        if (pCondSet->GetItemState(ATTR_LANGUAGE_FORMAT, true, &pLangItem) == 
SfxItemState::SET)
+        if (pCondSet->GetItemState(ATTR_LANGUAGE_FORMAT) == SfxItemState::SET)
             eLang = getLanguageType(*pCondSet);
         else
             eLang = getLanguageType(GetItemSet());
diff --git a/sc/source/core/data/stlpool.cxx b/sc/source/core/data/stlpool.cxx
index a03cc61180ec..5ca89c37a510 100644
--- a/sc/source/core/data/stlpool.cxx
+++ b/sc/source/core/data/stlpool.cxx
@@ -141,21 +141,19 @@ void ScStyleSheetPool::CopyStyleFrom( ScStyleSheetPool* 
pSrcPool,
     SfxItemSet& rDestSet = pDestSheet->GetItemSet();
     rDestSet.PutExtended( rSourceSet, SfxItemState::DONTCARE, 
SfxItemState::DEFAULT );
 
-    const SfxPoolItem* pItem;
     if ( eFamily == SfxStyleFamily::Page )
     {
         //  Set-Items
 
-        if ( rSourceSet.GetItemState( ATTR_PAGE_HEADERSET, false, &pItem ) == 
SfxItemState::SET )
+        if ( const SvxSetItem* pSetItem = rSourceSet.GetItemIfSet( 
ATTR_PAGE_HEADERSET, false ) )
         {
-            const SfxItemSet& rSrcSub = static_cast<const 
SvxSetItem*>(pItem)->GetItemSet();
+            const SfxItemSet& rSrcSub = pSetItem->GetItemSet();
             SfxItemSet aDestSub( *rDestSet.GetPool(), rSrcSub.GetRanges() );
             aDestSub.PutExtended( rSrcSub, SfxItemState::DONTCARE, 
SfxItemState::DEFAULT );
-            rDestSet.Put( SvxSetItem( ATTR_PAGE_HEADERSET, aDestSub ) );
         }
-        if ( rSourceSet.GetItemState( ATTR_PAGE_FOOTERSET, false, &pItem ) == 
SfxItemState::SET )
+        if ( const SvxSetItem* pSetItem = rSourceSet.GetItemIfSet( 
ATTR_PAGE_FOOTERSET, false ) )
         {
-            const SfxItemSet& rSrcSub = static_cast<const 
SvxSetItem*>(pItem)->GetItemSet();
+            const SfxItemSet& rSrcSub = pSetItem->GetItemSet();
             SfxItemSet aDestSub( *rDestSet.GetPool(), rSrcSub.GetRanges() );
             aDestSub.PutExtended( rSrcSub, SfxItemState::DONTCARE, 
SfxItemState::DEFAULT );
             rDestSet.Put( SvxSetItem( ATTR_PAGE_FOOTERSET, aDestSub ) );
@@ -165,10 +163,11 @@ void ScStyleSheetPool::CopyStyleFrom( ScStyleSheetPool* 
pSrcPool,
     {
         // number format exchange list has to be handled here, too
 
+        const SfxUInt32Item* pItem;
         if ( pDoc && pDoc->GetFormatExchangeList() &&
-             rSourceSet.GetItemState( ATTR_VALUE_FORMAT, false, &pItem ) == 
SfxItemState::SET )
+             (pItem = rSourceSet.GetItemIfSet( ATTR_VALUE_FORMAT, false )) )
         {
-            sal_uLong nOldFormat = static_cast<const 
SfxUInt32Item*>(pItem)->GetValue();
+            sal_uLong nOldFormat = pItem->GetValue();
             SvNumberFormatterIndexTable::const_iterator it = 
pDoc->GetFormatExchangeList()->find(nOldFormat);
             if (it != pDoc->GetFormatExchangeList()->end())
             {
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index ee4be3d802b3..b65d1651e56d 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -2394,14 +2394,12 @@ void ScTable::FindMaxRotCol( RowInfo* pRowInfo, SCSIZE 
nArrCount, SCCOL nX1, SCC
             const ScPatternAttr* pPattern = aIter.GetNext( nAttrCol, 
nAttrRow1, nAttrRow2 );
             while ( pPattern )
             {
-                const SfxPoolItem* pCondItem;
-                if ( pPattern->GetItemSet().GetItemState( ATTR_CONDITIONAL, 
true, &pCondItem )
-                        == SfxItemState::SET )
+                if ( const ScCondFormatItem* pCondItem = 
pPattern->GetItemSet().GetItemIfSet( ATTR_CONDITIONAL ) )
                 {
                     //  Run through all formats, so that each cell does not 
have to be
                     //  handled individually
 
-                    const ScCondFormatIndexes& rCondFormatData = 
static_cast<const ScCondFormatItem*>(pCondItem)->GetCondFormatData();
+                    const ScCondFormatIndexes& rCondFormatData = 
pCondItem->GetCondFormatData();
                     ScStyleSheetPool* pStylePool = 
rDocument.GetStyleSheetPool();
                     if (mpCondFormatList && pStylePool && 
!rCondFormatData.empty())
                     {
diff --git a/sc/source/core/data/table5.cxx b/sc/source/core/data/table5.cxx
index 4c510213edd9..cddb28e6e1da 100644
--- a/sc/source/core/data/table5.cxx
+++ b/sc/source/core/data/table5.cxx
@@ -75,7 +75,6 @@ void ScTable::UpdatePageBreaks(const ScRange* pUserArea)
         return;
     }
     SfxItemSet* pStyleSet = &pStyle->GetItemSet();
-    const SfxPoolItem* pItem;
 
     SCCOL nStartCol = 0;
     SCROW nStartRow = 0;
@@ -124,18 +123,15 @@ void ScTable::UpdatePageBreaks(const ScRange* pUserArea)
 
     if (!mbForceBreaks)
     {
-        if (pStyleSet->GetItemState(ATTR_PAGE_SCALETOPAGES, false, &pItem) == 
SfxItemState::SET)
+        if (const SfxUInt16Item* pItem = 
pStyleSet->GetItemIfSet(ATTR_PAGE_SCALETOPAGES, false))
         {
-            assert(dynamic_cast<const SfxUInt16Item*>(pItem) && "invalid 
Item");
-            bSkipColBreaks = bSkipRowBreaks
-                = static_cast<const SfxUInt16Item*>(pItem)->GetValue() > 0;
+            bSkipColBreaks = bSkipRowBreaks = pItem->GetValue() > 0;
         }
 
-        if (!bSkipColBreaks
-            && pStyleSet->GetItemState(ATTR_PAGE_SCALETO, false, &pItem) == 
SfxItemState::SET)
+        const ScPageScaleToItem* pScaleToItem;
+        if (!bSkipColBreaks && (pScaleToItem = 
pStyleSet->GetItemIfSet(ATTR_PAGE_SCALETO, false)))
         {
             // #i54993# when fitting to width or height, ignore only manual 
breaks in that direction
-            const ScPageScaleToItem* pScaleToItem = static_cast<const 
ScPageScaleToItem*>(pItem);
             if (pScaleToItem->GetWidth() > 0)
                 bSkipColBreaks = true;
             if (pScaleToItem->GetHeight() > 0)

Reply via email to