Avoid some casting

Change-Id: Ic29a6f6f582d3c4f00af78b9b8aa3083b68b7292
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186291
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
This commit is contained in:
Mike Kaganski
2025-06-09 19:30:31 +02:00
parent cc71112ec3
commit f36fa1347d
8 changed files with 42 additions and 34 deletions
+2 -2
View File
@@ -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);
+19 -19
View File
@@ -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;
+2 -2
View File
@@ -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)
+10 -2
View File
@@ -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;
+4 -4
View File
@@ -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;
+1 -1
View File
@@ -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;
}
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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)
{
/*