cui/source/inc/align.hxx                     |    4 +-
 cui/source/tabpages/align.cxx                |   38 +++++++++++++--------------
 editeng/source/editeng/impedit2.cxx          |    4 +-
 reportdesign/source/ui/misc/UITools.cxx      |   12 +++++++-
 sc/qa/unit/ucalc_sort.cxx                    |    8 ++---
 sw/source/core/unocore/unolinebreak.cxx      |    2 -
 sw/source/filter/ww8/docxattributeoutput.cxx |    4 +-
 sw/source/filter/ww8/wrtw8esh.cxx            |    4 +-
 8 files changed, 42 insertions(+), 34 deletions(-)

New commits:
commit f36fa1347dc4ff1e9944f0f49862640a5963fbf8
Author:     Mike Kaganski <[email protected]>
AuthorDate: Mon Jun 9 12:57:55 2025 +0200
Commit:     Mike Kaganski <[email protected]>
CommitDate: Mon Jun 9 19:30:31 2025 +0200

    Avoid some casting
    
    Change-Id: Ic29a6f6f582d3c4f00af78b9b8aa3083b68b7292
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186291
    Reviewed-by: Mike Kaganski <[email protected]>
    Tested-by: Jenkins

diff --git a/cui/source/inc/align.hxx b/cui/source/inc/align.hxx
index 0154e8ab19da..705a045b0513 100644
--- a/cui/source/inc/align.hxx
+++ b/cui/source/inc/align.hxx
@@ -44,7 +44,7 @@ enum VerticalAlign {
 #include <svx/frmdirlbox.hxx>
 #include <vcl/weld.hxx>
 
-class SfxEnumItemInterface;
+class SvxJustifyMethodItem;
 
 namespace svx {
 
@@ -68,7 +68,7 @@ private:
     void                InitVsRefEgde();
     void                UpdateEnableControls();
 
-    bool                HasAlignmentChanged( const SfxItemSet& rNew, 
TypedWhichId<SfxEnumItemInterface> nWhich ) const;
+    bool                HasAlignmentChanged( const SfxItemSet& rNew, 
TypedWhichId<SvxJustifyMethodItem> nWhich ) const;
 
     DECL_LINK(UpdateEnableHdl, weld::ComboBox&, void);
     DECL_LINK(StackedClickHdl, weld::Toggleable&, void);
diff --git a/cui/source/tabpages/align.cxx b/cui/source/tabpages/align.cxx
index 0f4713c33480..638350f515b0 100644
--- a/cui/source/tabpages/align.cxx
+++ b/cui/source/tabpages/align.cxx
@@ -54,26 +54,26 @@ const WhichRangesContainer AlignmentTabPage::s_pRanges(
 
 namespace {
 
-template<typename JustEnumType>
+template<class JustifyItem_t>
 void lcl_MaybeResetAlignToDistro(
-    weld::ComboBox& rLB, sal_uInt16 nListId, const SfxItemSet& rCoreAttrs, 
TypedWhichId<SfxEnumItemInterface> nWhichAlign, 
TypedWhichId<SfxEnumItemInterface> nWhichJM, JustEnumType eBlock)
+    weld::ComboBox& rLB, sal_uInt16 nListId, const SfxItemSet& rCoreAttrs, 
TypedWhichId<JustifyItem_t> nWhichAlign, TypedWhichId<SvxJustifyMethodItem> 
nWhichJM, decltype(std::declval<JustifyItem_t>().GetValue()) eBlock)
 {
-    const SfxEnumItemInterface* p = rCoreAttrs.GetItemIfSet(nWhichAlign);
-    if (!p)
+    const auto* p1 = rCoreAttrs.GetItemIfSet(nWhichAlign);
+    if (!p1)
         // alignment not set.
         return;
 
-    JustEnumType eVal = static_cast<JustEnumType>(p->GetEnumValue());
+    auto eVal = p1->GetValue();
     if (eVal != eBlock)
         // alignment is not 'justify'.  No need to go further.
         return;
 
-    p = rCoreAttrs.GetItemIfSet(nWhichJM);
-    if (!p)
+    const auto* p2 = rCoreAttrs.GetItemIfSet(nWhichJM);
+    if (!p2)
         // justification method is not set.
         return;
 
-    SvxCellJustifyMethod eMethod = 
static_cast<SvxCellJustifyMethod>(p->GetEnumValue());
+    SvxCellJustifyMethod eMethod = p2->GetValue();
     if (eMethod == SvxCellJustifyMethod::Distribute)
     {
         // Select the 'distribute' entry in the specified list box.
@@ -374,12 +374,12 @@ bool AlignmentTabPage::FillItemSet( SfxItemSet* rSet )
 
     // Special treatment for distributed alignment; we need to set the justify
     // method to 'distribute' to distinguish from the normal justification.
-    TypedWhichId<SfxEnumItemInterface> 
nWhichHorJM(GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY_METHOD));
+    TypedWhichId<SvxJustifyMethodItem> 
nWhichHorJM(GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY_METHOD));
     lcl_SetJustifyMethodToItemSet(*rSet, rOldSet, nWhichHorJM, *m_xLbHorAlign, 
ALIGNDLG_HORALIGN_DISTRIBUTED);
     if (!bChanged)
         bChanged = HasAlignmentChanged(*rSet, nWhichHorJM);
 
-    TypedWhichId<SfxEnumItemInterface> 
nWhichVerJM(GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY_METHOD));
+    TypedWhichId<SvxJustifyMethodItem> 
nWhichVerJM(GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY_METHOD));
     lcl_SetJustifyMethodToItemSet(*rSet, rOldSet, nWhichVerJM, *m_xLbVerAlign, 
ALIGNDLG_VERALIGN_DISTRIBUTED);
     if (!bChanged)
         bChanged = HasAlignmentChanged(*rSet, nWhichVerJM);
@@ -620,7 +620,7 @@ void AlignmentTabPage::Reset(const SfxItemSet* pCoreAttrs)
 
     // Special treatment for distributed alignment; we need to set the justify
     // method to 'distribute' to distinguish from the normal justification.
-    TypedWhichId<SfxEnumItemInterface> 
nHorJustifyMethodWhich(GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY_METHOD));
+    TypedWhichId<SvxJustifyMethodItem> 
nHorJustifyMethodWhich(GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY_METHOD));
     SfxItemState eHorJustifyMethodState = 
pCoreAttrs->GetItemState(nHorJustifyMethodWhich);
     if (eHorJustifyMethodState == SfxItemState::UNKNOWN)
     {
@@ -634,11 +634,11 @@ void AlignmentTabPage::Reset(const SfxItemSet* pCoreAttrs)
         // feature known, e.g. calc
         lcl_MaybeResetAlignToDistro(
             *m_xLbHorAlign, ALIGNDLG_HORALIGN_DISTRIBUTED, *pCoreAttrs,
-            
TypedWhichId<SfxEnumItemInterface>(GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY)), 
nHorJustifyMethodWhich,
+            
TypedWhichId<SvxHorJustifyItem>(GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY)), 
nHorJustifyMethodWhich,
             SvxCellHorJustify::Block);
     }
 
-    TypedWhichId<SfxEnumItemInterface> nVerJustifyMethodWhich( 
GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY_METHOD) );
+    TypedWhichId<SvxJustifyMethodItem> nVerJustifyMethodWhich( 
GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY_METHOD) );
     SfxItemState eVerJustifyMethodState = 
pCoreAttrs->GetItemState(nVerJustifyMethodWhich);
     if (eVerJustifyMethodState == SfxItemState::UNKNOWN)
     {
@@ -652,7 +652,7 @@ void AlignmentTabPage::Reset(const SfxItemSet* pCoreAttrs)
         // feature known, e.g. calc
         lcl_MaybeResetAlignToDistro(
             *m_xLbVerAlign, ALIGNDLG_VERALIGN_DISTRIBUTED, *pCoreAttrs,
-            
TypedWhichId<SfxEnumItemInterface>(GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY)), 
nVerJustifyMethodWhich,
+            GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY), nVerJustifyMethodWhich,
             SvxCellVerJustify::Block);
     }
 
@@ -734,19 +734,19 @@ void AlignmentTabPage::UpdateEnableControls()
     m_xNfRotate->set_sensitive(!bHorFill && !bStackedText);
 }
 
-bool AlignmentTabPage::HasAlignmentChanged( const SfxItemSet& rNew, 
TypedWhichId<SfxEnumItemInterface> nWhich ) const
+bool AlignmentTabPage::HasAlignmentChanged( const SfxItemSet& rNew, 
TypedWhichId<SvxJustifyMethodItem> nWhich ) const
 {
     const SfxItemSet& rOld = GetItemSet();
     SvxCellJustifyMethod eMethodOld = SvxCellJustifyMethod::Auto;
     SvxCellJustifyMethod eMethodNew = SvxCellJustifyMethod::Auto;
-    if (const SfxEnumItemInterface* p = rOld.GetItemIfSet(nWhich))
+    if (const SvxJustifyMethodItem* p = rOld.GetItemIfSet(nWhich))
     {
-        eMethodOld = static_cast<SvxCellJustifyMethod>(p->GetEnumValue());
+        eMethodOld = p->GetValue();
     }
 
-    if (const SfxEnumItemInterface* p = rNew.GetItemIfSet(nWhich))
+    if (const SvxJustifyMethodItem* p = rNew.GetItemIfSet(nWhich))
     {
-        eMethodNew = static_cast<SvxCellJustifyMethod>(p->GetEnumValue());
+        eMethodNew = p->GetValue();
     }
 
     return eMethodOld != eMethodNew;
diff --git a/editeng/source/editeng/impedit2.cxx 
b/editeng/source/editeng/impedit2.cxx
index c9b9143b7b8f..e231191b75d1 100644
--- a/editeng/source/editeng/impedit2.cxx
+++ b/editeng/source/editeng/impedit2.cxx
@@ -2070,13 +2070,13 @@ SvxAdjust ImpEditEngine::GetJustification( sal_Int32 
nPara ) const
 SvxCellJustifyMethod ImpEditEngine::GetJustifyMethod( sal_Int32 nPara ) const
 {
     const SvxJustifyMethodItem& rItem = GetParaAttrib(nPara, 
EE_PARA_JUST_METHOD);
-    return static_cast<SvxCellJustifyMethod>(rItem.GetEnumValue());
+    return rItem.GetValue();
 }
 
 SvxCellVerJustify ImpEditEngine::GetVerJustification( sal_Int32 nPara ) const
 {
     const SvxVerJustifyItem& rItem = GetParaAttrib(nPara, EE_PARA_VER_JUST);
-    return static_cast<SvxCellVerJustify>(rItem.GetEnumValue());
+    return rItem.GetValue();
 }
 
 SvxFontUnitMetrics ImpEditEngine::GetFontUnitMetrics(ContentNode* pNode)
diff --git a/reportdesign/source/ui/misc/UITools.cxx 
b/reportdesign/source/ui/misc/UITools.cxx
index d63a50e3ddb7..ab835f675bcc 100644
--- a/reportdesign/source/ui/misc/UITools.cxx
+++ b/reportdesign/source/ui/misc/UITools.cxx
@@ -465,7 +465,11 @@ namespace
             lcl_pushBack( _out_rProperties, PROPERTY_VERTICALALIGN, aValue );
         }
         if ( const SvxCharReliefItem* pReliefItem = _rItemSet.GetItemIfSet( 
ITEMID_CHARRELIEF ) )
-            lcl_pushBack( _out_rProperties, PROPERTY_CHARRELIEF, uno::Any( 
static_cast< sal_Int16 >( pReliefItem->GetEnumValue() ) ) );
+        {
+            uno::Any aValue;
+            pReliefItem->QueryValue(aValue, MID_RELIEF);
+            lcl_pushBack( _out_rProperties, PROPERTY_CHARRELIEF, aValue );
+        }
         if ( const SvxCharHiddenItem* pHiddenItem = _rItemSet.GetItemIfSet( 
ITEMID_CHARHIDDEN ) )
             lcl_pushBack( _out_rProperties, PROPERTY_CHARHIDDEN, uno::Any( 
pHiddenItem->GetValue() ) );
         if ( const SvxAutoKernItem* pKernItem = _rItemSet.GetItemIfSet( 
ITEMID_AUTOKERN ) )
@@ -487,7 +491,11 @@ namespace
         if ( const SvxKerningItem* pKernItem = _rItemSet.GetItemIfSet( 
ITEMID_KERNING ) )
             lcl_pushBack( _out_rProperties, PROPERTY_CHARKERNING, uno::Any( 
pKernItem->GetValue() ) );
         if ( const SvxCaseMapItem* pCaseMapItem = _rItemSet.GetItemIfSet( 
ITEMID_CASEMAP ) )
-            lcl_pushBack( _out_rProperties, PROPERTY_CHARCASEMAP, uno::Any( 
pCaseMapItem->GetEnumValue() ) );
+        {
+            uno::Any aValue;
+            pCaseMapItem->QueryValue(aValue);
+            lcl_pushBack( _out_rProperties, PROPERTY_CHARCASEMAP, aValue );
+        }
         struct Items {
                 TypedWhichId<SvxLanguageItem> nWhich;
                 OUString sPropertyName;
diff --git a/sc/qa/unit/ucalc_sort.cxx b/sc/qa/unit/ucalc_sort.cxx
index b1178bc29303..6853794b0ec6 100644
--- a/sc/qa/unit/ucalc_sort.cxx
+++ b/sc/qa/unit/ucalc_sort.cxx
@@ -559,7 +559,7 @@ CPPUNIT_TEST_FIXTURE(TestSort, testSortWithCellFormats)
 
             CPPUNIT_ASSERT(pItem);
 
-            if (static_cast<const SvxWeightItem*>(pItem)->GetEnumValue() != 
WEIGHT_BOLD)
+            if (pItem->StaticWhichCast(ATTR_FONT_WEIGHT).GetWeight() != 
WEIGHT_BOLD)
             {
                 cerr << "Font weight should be bold." << endl;
                 return false;
@@ -585,7 +585,7 @@ CPPUNIT_TEST_FIXTURE(TestSort, testSortWithCellFormats)
 
             CPPUNIT_ASSERT(pItem);
 
-            if (static_cast<const SvxPostureItem*>(pItem)->GetEnumValue() != 
ITALIC_NORMAL)
+            if (pItem->StaticWhichCast(ATTR_FONT_POSTURE).GetPosture() != 
ITALIC_NORMAL)
             {
                 cerr << "Italic should be applied.." << endl;
                 return false;
@@ -606,7 +606,7 @@ CPPUNIT_TEST_FIXTURE(TestSort, testSortWithCellFormats)
             if (pPat->GetItemSet().HasItem(ATTR_FONT_WEIGHT, &pItem))
             {
                 // Check if the font weight is applied.
-                if (static_cast<const SvxWeightItem*>(pItem)->GetEnumValue() 
== WEIGHT_BOLD)
+                if (pItem->StaticWhichCast(ATTR_FONT_WEIGHT).GetWeight() == 
WEIGHT_BOLD)
                 {
                     cerr << "This cell is bold, but shouldn't." << endl;
                     return false;
@@ -616,7 +616,7 @@ CPPUNIT_TEST_FIXTURE(TestSort, testSortWithCellFormats)
             if (pPat->GetItemSet().HasItem(ATTR_FONT_POSTURE, &pItem))
             {
                 // Check if the italics is applied.
-                if (static_cast<const SvxPostureItem*>(pItem)->GetEnumValue() 
== ITALIC_NORMAL)
+                if (pItem->StaticWhichCast(ATTR_FONT_POSTURE).GetPosture() == 
ITALIC_NORMAL)
                 {
                     cerr << "This cell is italic, but shouldn't." << endl;
                     return false;
diff --git a/sw/source/core/unocore/unolinebreak.cxx 
b/sw/source/core/unocore/unolinebreak.cxx
index 82cdf8512c07..7235f3ae50fd 100644
--- a/sw/source/core/unocore/unolinebreak.cxx
+++ b/sw/source/core/unocore/unolinebreak.cxx
@@ -247,7 +247,7 @@ uno::Any SAL_CALL SwXLineBreak::getPropertyValue(const 
OUString& rPropertyName)
     }
     else
     {
-        aRet <<= m_pImpl->m_pFormatLineBreak->GetEnumValue();
+        m_pImpl->m_pFormatLineBreak->QueryValue(aRet);
     }
     return aRet;
 }
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 466961e899ce..5a5b01cdbfca 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -5552,10 +5552,10 @@ void DocxAttributeOutput::FlyFrameGraphic( const 
SwGrfNode* pGrfNode, const Size
     else
         m_pSerializer->startElementNS(XML_a, XML_blip, FSNS(XML_r, 
nImageType), aRelId);
 
-    const SfxEnumItemInterface* pGrafModeItem = nullptr;
+    const SwDrawModeGrf* pGrafModeItem = nullptr;
     if ( pGrfNode && (pGrafModeItem = 
pGrfNode->GetSwAttrSet().GetItemIfSet(RES_GRFATR_DRAWMODE)))
     {
-        GraphicDrawMode nMode = 
static_cast<GraphicDrawMode>(pGrafModeItem->GetEnumValue());
+        GraphicDrawMode nMode = pGrafModeItem->GetValue();
         if (nMode == GraphicDrawMode::Greys)
             m_pSerializer->singleElementNS (XML_a, XML_grayscl);
         else if (nMode == GraphicDrawMode::Mono) //black/white has a 0,5 
threshold in LibreOffice
diff --git a/sw/source/filter/ww8/wrtw8esh.cxx 
b/sw/source/filter/ww8/wrtw8esh.cxx
index 458fab1111a5..c621d8e54c64 100644
--- a/sw/source/filter/ww8/wrtw8esh.cxx
+++ b/sw/source/filter/ww8/wrtw8esh.cxx
@@ -1680,9 +1680,9 @@ void SwBasicEscherEx::WriteGrfAttr(const SwNoTextNode& 
rNd, const SwFrameFormat&
         nBrightness = pItem->GetValue();
     }
 
-    if (const SfxEnumItemInterface* pItem = 
rNd.GetSwAttrSet().GetItemIfSet(RES_GRFATR_DRAWMODE))
+    if (const SwDrawModeGrf* pItem = 
rNd.GetSwAttrSet().GetItemIfSet(RES_GRFATR_DRAWMODE))
     {
-        nMode = static_cast<GraphicDrawMode>(pItem->GetEnumValue());
+        nMode = pItem->GetValue();
         if (nMode == GraphicDrawMode::Watermark)
         {
             /*

Reply via email to