starmath/inc/starmath.hrc   |   25 +++++++++++++-----------
 starmath/source/cfgitem.cxx |   45 +++++++++++++++++++++-----------------------
 starmath/source/dialog.cxx  |   14 ++++++-------
 3 files changed, 43 insertions(+), 41 deletions(-)

New commits:
commit f1bf33a26b20a2fd0aa941cce5ad40e3737e0eb4
Author:     Noel Grandin <[email protected]>
AuthorDate: Tue Mar 1 08:55:22 2022 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Tue Mar 1 09:12:45 2022 +0100

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

diff --git a/starmath/inc/starmath.hrc b/starmath/inc/starmath.hrc
index c566783156ca..83c17c94da09 100644
--- a/starmath/inc/starmath.hrc
+++ b/starmath/inc/starmath.hrc
@@ -21,6 +21,9 @@
 
 #include <svl/solar.hrc>
 
+class SfxBoolItem;
+class SfxUInt16Item;
+
 #define SID_NEXTERR                 (SID_SMA_START + 1)
 #define SID_PREVERR                 (SID_SMA_START + 2)
 #define SID_NEXTMARK                (SID_SMA_START + 3)
@@ -51,23 +54,23 @@
 #define SID_MODIFYSTATUS            (SID_SMA_START + 110)
 #define SID_TEXTSTATUS              (SID_SMA_START + 111)
 
-#define SID_PRINTTITLE              (SID_SMA_START + 112)
-#define SID_PRINTTEXT               (SID_SMA_START + 113)
-#define SID_PRINTFRAME              (SID_SMA_START + 114)
-#define SID_PRINTSIZE               (SID_SMA_START + 115)
-#define SID_PRINTZOOM               (SID_SMA_START + 116)
+#define SID_PRINTTITLE              TypedWhichId<SfxBoolItem>(SID_SMA_START + 
112)
+#define SID_PRINTTEXT               TypedWhichId<SfxBoolItem>(SID_SMA_START + 
113)
+#define SID_PRINTFRAME              TypedWhichId<SfxBoolItem>(SID_SMA_START + 
114)
+#define SID_PRINTSIZE               TypedWhichId<SfxUInt16Item>(SID_SMA_START 
+ 115)
+#define SID_PRINTZOOM               TypedWhichId<SfxUInt16Item>(SID_SMA_START 
+ 116)
 
 #define SID_COPYOBJECT              (SID_SMA_START + 117)
 #define SID_PASTEOBJECT             (SID_SMA_START + 118)
-#define SID_AUTOREDRAW              (SID_SMA_START + 119)
+#define SID_AUTOREDRAW              TypedWhichId<SfxBoolItem>(SID_SMA_START + 
119)
 
 #define SID_GETEDITTEXT             (SID_SMA_START + 121)
 #define SID_CMDBOXWINDOW            (SID_SMA_START + 122)
-#define SID_NO_RIGHT_SPACES         (SID_SMA_START + 124)
-#define SID_SAVE_ONLY_USED_SYMBOLS  (SID_SMA_START + 125)
+#define SID_NO_RIGHT_SPACES         TypedWhichId<SfxBoolItem>(SID_SMA_START + 
124)
+#define SID_SAVE_ONLY_USED_SYMBOLS  TypedWhichId<SfxBoolItem>(SID_SMA_START + 
125)
 #define SID_ELEMENTSDOCKINGWINDOW   (SID_SMA_START + 126)
-#define SID_AUTO_CLOSE_BRACKETS     (SID_SMA_START + 127)
-#define SID_SMEDITWINDOWZOOM        (SID_SMA_START + 129)
-#define SID_DEFAULT_SM_SYNTAX_VERSION (SID_SMA_START + 130)
+#define SID_AUTO_CLOSE_BRACKETS     TypedWhichId<SfxBoolItem>(SID_SMA_START + 
127)
+#define SID_SMEDITWINDOWZOOM        TypedWhichId<SfxUInt16Item>(SID_SMA_START 
+ 129)
+#define SID_DEFAULT_SM_SYNTAX_VERSION 
TypedWhichId<SfxUInt16Item>(SID_SMA_START + 130)
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/cfgitem.cxx b/starmath/source/cfgitem.cxx
index 16e6d67b7312..7692aaa3ff5c 100644
--- a/starmath/source/cfgitem.cxx
+++ b/starmath/source/cfgitem.cxx
@@ -1357,56 +1357,55 @@ void SmMathConfig::Notify( const css::uno::Sequence< 
OUString >& rNames )
 void SmMathConfig::ItemSetToConfig(const SfxItemSet &rSet)
 {
     CommitLocker aLock(*this);
-    const SfxPoolItem *pItem     = nullptr;
 
     sal_uInt16 nU16;
     bool bVal;
-    if (rSet.GetItemState(SID_PRINTSIZE, true, &pItem) == SfxItemState::SET)
-    {   nU16 = static_cast<const SfxUInt16Item *>(pItem)->GetValue();
+    if (const SfxUInt16Item* pPrintSizeItem = rSet.GetItemIfSet(SID_PRINTSIZE))
+    {   nU16 = pPrintSizeItem->GetValue();
         SetPrintSize( static_cast<SmPrintSize>(nU16) );
     }
-    if (rSet.GetItemState(SID_PRINTZOOM, true, &pItem) == SfxItemState::SET)
-    {   nU16 = static_cast<const SfxUInt16Item *>(pItem)->GetValue();
+    if (const SfxUInt16Item* pPrintZoomItem = rSet.GetItemIfSet(SID_PRINTZOOM))
+    {   nU16 = pPrintZoomItem->GetValue();
         SetPrintZoomFactor( nU16 );
     }
-    if (rSet.GetItemState(SID_SMEDITWINDOWZOOM, true, &pItem) == 
SfxItemState::SET)
-    {   nU16 = static_cast<const SfxUInt16Item *>(pItem)->GetValue();
+    if (const SfxUInt16Item* pPrintZoomItem = 
rSet.GetItemIfSet(SID_SMEDITWINDOWZOOM))
+    {   nU16 = pPrintZoomItem->GetValue();
         SetSmEditWindowZoomFactor( nU16 );
     }
-    if (rSet.GetItemState(SID_PRINTTITLE, true, &pItem) == SfxItemState::SET)
-    {   bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
+    if (const SfxBoolItem* pPrintTitleItem = rSet.GetItemIfSet(SID_PRINTTITLE))
+    {   bVal = pPrintTitleItem->GetValue();
         SetPrintTitle( bVal );
     }
-    if (rSet.GetItemState(SID_PRINTTEXT, true, &pItem) == SfxItemState::SET)
-    {   bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
+    if (const SfxBoolItem* pPrintTextItem = rSet.GetItemIfSet(SID_PRINTTEXT))
+    {   bVal = pPrintTextItem->GetValue();
         SetPrintFormulaText( bVal );
     }
-    if (rSet.GetItemState(SID_PRINTFRAME, true, &pItem) == SfxItemState::SET)
-    {   bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
+    if (const SfxBoolItem* pPrintZoomItem = rSet.GetItemIfSet(SID_PRINTFRAME))
+    {   bVal = pPrintZoomItem->GetValue();
         SetPrintFrame( bVal );
     }
-    if (rSet.GetItemState(SID_AUTOREDRAW, true, &pItem) == SfxItemState::SET)
-    {   bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
+    if (const SfxBoolItem* pRedrawItem = rSet.GetItemIfSet(SID_AUTOREDRAW))
+    {   bVal = pRedrawItem->GetValue();
         SetAutoRedraw( bVal );
     }
-    if (rSet.GetItemState(SID_NO_RIGHT_SPACES, true, &pItem) == 
SfxItemState::SET)
-    {   bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
+    if (const SfxBoolItem* pSpacesItem = 
rSet.GetItemIfSet(SID_NO_RIGHT_SPACES))
+    {   bVal = pSpacesItem->GetValue();
         SetIgnoreSpacesRight( bVal );
     }
-    if (rSet.GetItemState(SID_SAVE_ONLY_USED_SYMBOLS, true, &pItem) == 
SfxItemState::SET)
-    {   bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
+    if (const SfxBoolItem* pSymbolsItem = 
rSet.GetItemIfSet(SID_SAVE_ONLY_USED_SYMBOLS))
+    {   bVal = pSymbolsItem->GetValue();
         SetSaveOnlyUsedSymbols( bVal );
     }
 
-    if (rSet.GetItemState(SID_AUTO_CLOSE_BRACKETS, true, &pItem) == 
SfxItemState::SET)
+    if (const SfxBoolItem* pBracketsItem = 
rSet.GetItemIfSet(SID_AUTO_CLOSE_BRACKETS))
     {
-        bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
+        bVal = pBracketsItem->GetValue();
         SetAutoCloseBrackets( bVal );
     }
 
-    if (rSet.GetItemState(SID_DEFAULT_SM_SYNTAX_VERSION, true, &pItem) == 
SfxItemState::SET)
+    if (const SfxUInt16Item* pSyntaxItem = 
rSet.GetItemIfSet(SID_DEFAULT_SM_SYNTAX_VERSION))
     {
-        nU16 = static_cast<const SfxUInt16Item *>(pItem)->GetValue();
+        nU16 = pSyntaxItem->GetValue();
         SetDefaultSmSyntaxVersion( nU16 );
     }
 }
diff --git a/starmath/source/dialog.cxx b/starmath/source/dialog.cxx
index 1c63416e57c1..559a7e55c789 100644
--- a/starmath/source/dialog.cxx
+++ b/starmath/source/dialog.cxx
@@ -210,7 +210,7 @@ bool SmPrintOptionsTabPage::FillItemSet(SfxItemSet* rSet)
 
 void SmPrintOptionsTabPage::Reset(const SfxItemSet* rSet)
 {
-    SmPrintSize ePrintSize = static_cast<SmPrintSize>(static_cast<const 
SfxUInt16Item &>(rSet->Get(SID_PRINTSIZE)).GetValue());
+    SmPrintSize ePrintSize = 
static_cast<SmPrintSize>(rSet->Get(SID_PRINTSIZE).GetValue());
 
     m_xSizeNormal->set_active(ePrintSize == PRINT_SIZE_NORMAL);
     m_xSizeScaled->set_active(ePrintSize == PRINT_SIZE_SCALED);
@@ -218,15 +218,15 @@ void SmPrintOptionsTabPage::Reset(const SfxItemSet* rSet)
 
     m_xZoom->set_sensitive(m_xSizeZoomed->get_active());
 
-    m_xZoom->set_value(static_cast<const SfxUInt16Item 
&>(rSet->Get(SID_PRINTZOOM)).GetValue(), FieldUnit::PERCENT);
+    m_xZoom->set_value(rSet->Get(SID_PRINTZOOM).GetValue(), 
FieldUnit::PERCENT);
 
     m_xSmZoom->set_sensitive(true);
-    m_xSmZoom->set_value(static_cast<const SfxUInt16Item 
&>(rSet->Get(SID_SMEDITWINDOWZOOM)).GetValue(), FieldUnit::PERCENT);
+    m_xSmZoom->set_value(rSet->Get(SID_SMEDITWINDOWZOOM).GetValue(), 
FieldUnit::PERCENT);
 
-    m_xTitle->set_active(static_cast<const SfxBoolItem 
&>(rSet->Get(SID_PRINTTITLE)).GetValue());
-    m_xNoRightSpaces->set_active(static_cast<const SfxBoolItem 
&>(rSet->Get(SID_NO_RIGHT_SPACES)).GetValue());
-    m_xSaveOnlyUsedSymbols->set_active(static_cast<const SfxBoolItem 
&>(rSet->Get(SID_SAVE_ONLY_USED_SYMBOLS)).GetValue());
-    m_xAutoCloseBrackets->set_active(static_cast<const SfxBoolItem 
&>(rSet->Get(SID_AUTO_CLOSE_BRACKETS)).GetValue());
+    m_xTitle->set_active(rSet->Get(SID_PRINTTITLE).GetValue());
+    m_xNoRightSpaces->set_active(rSet->Get(SID_NO_RIGHT_SPACES).GetValue());
+    
m_xSaveOnlyUsedSymbols->set_active(rSet->Get(SID_SAVE_ONLY_USED_SYMBOLS).GetValue());
+    
m_xAutoCloseBrackets->set_active(rSet->Get(SID_AUTO_CLOSE_BRACKETS).GetValue());
 }
 
 std::unique_ptr<SfxTabPage> SmPrintOptionsTabPage::Create(weld::Container* 
pPage, weld::DialogController* pController, const SfxItemSet& rSet)

Reply via email to