cui/source/tabpages/backgrnd.cxx | 2 +- cui/source/tabpages/labdlg.cxx | 4 ++-- cui/source/tabpages/page.cxx | 16 ++++++++-------- cui/source/tabpages/tparea.cxx | 9 ++++----- cui/source/tabpages/tplnedef.cxx | 2 +- cui/source/tabpages/tpshadow.cxx | 3 +-- include/sfx2/tabdlg.hxx | 6 ++++++ include/svl/itempool.hxx | 3 +++ svx/source/dialog/hdft.cxx | 24 ++++++++++++------------ 9 files changed, 38 insertions(+), 31 deletions(-)
New commits: commit 339fde9d905135e24b2f4e204009ee289d678b0c Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Feb 15 08:56:13 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Feb 15 09:19:34 2022 +0100 add typed GetWhich operations to reduce boilerplate at call sites Change-Id: I290c2bf60ad5e6ddb000aa26cf543830ed39120a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129949 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/cui/source/tabpages/backgrnd.cxx b/cui/source/tabpages/backgrnd.cxx index a52e7da3ee97..ada1d46c1521 100644 --- a/cui/source/tabpages/backgrnd.cxx +++ b/cui/source/tabpages/backgrnd.cxx @@ -308,7 +308,7 @@ IMPL_LINK(SvxBkgTabPage, TblDestinationHdl_Impl, weld::ComboBox&, rBox, void) drawing::FillStyle eXFS = drawing::FillStyle_NONE; if (maSet.GetItemState(XATTR_FILLSTYLE) != SfxItemState::DONTCARE) { - XFillStyleItem aFillStyleItem(static_cast<const XFillStyleItem&>(maSet.Get(GetWhich( XATTR_FILLSTYLE)))); + XFillStyleItem aFillStyleItem(maSet.Get(GetWhich( XATTR_FILLSTYLE))); eXFS = aFillStyleItem.GetValue(); } switch(eXFS) diff --git a/cui/source/tabpages/labdlg.cxx b/cui/source/tabpages/labdlg.cxx index 867a31885af7..cb048426c73a 100644 --- a/cui/source/tabpages/labdlg.cxx +++ b/cui/source/tabpages/labdlg.cxx @@ -255,9 +255,9 @@ void SvxCaptionTabPage::Reset( const SfxItemSet* ) SetMetricValue( *m_xMF_SPACING, nGap, eUnit ); nGap = m_xMF_SPACING->get_value(FieldUnit::NONE); - nCaptionType = static_cast<const SdrCaptionTypeItem&>( rOutAttrs.Get( GetWhich( SDRATTR_CAPTIONTYPE ) ) ).GetValue(); + nCaptionType = rOutAttrs.Get( GetWhich( SDRATTR_CAPTIONTYPE ) ).GetValue(); bFitLineLen = static_cast<const SfxBoolItem&>( rOutAttrs.Get( GetWhich( SDRATTR_CAPTIONFITLINELEN ) ) ).GetValue(); - nEscDir = static_cast<const SdrCaptionEscDirItem&>( rOutAttrs.Get( GetWhich( SDRATTR_CAPTIONESCDIR ) ) ).GetValue(); + nEscDir = rOutAttrs.Get( GetWhich( SDRATTR_CAPTIONESCDIR ) ).GetValue(); bEscRel = static_cast<const SfxBoolItem&>( rOutAttrs.Get( GetWhich( SDRATTR_CAPTIONESCISREL ) ) ).GetValue(); // special treatment!!! XXX diff --git a/cui/source/tabpages/page.cxx b/cui/source/tabpages/page.cxx index 69bbbcc10d94..c3b8e154fc26 100644 --- a/cui/source/tabpages/page.cxx +++ b/cui/source/tabpages/page.cxx @@ -1135,7 +1135,7 @@ void SvxPageDescPage::ResetBackground_Impl(const SfxItemSet& rSet) { const SvxSetItem& rSetItem = static_cast< const SvxSetItem& >(rSet.Get(nWhich, false)); const SfxItemSet& rTmpSet = rSetItem.GetItemSet(); - const SfxBoolItem& rOn = static_cast< const SfxBoolItem& >(rTmpSet.Get(GetWhich(SID_ATTR_PAGE_ON))); + const SfxBoolItem& rOn = rTmpSet.Get(GetWhich(SID_ATTR_PAGE_ON)); if(rOn.GetValue()) { @@ -1171,7 +1171,7 @@ void SvxPageDescPage::ResetBackground_Impl(const SfxItemSet& rSet) { const SvxSetItem& rSetItem = static_cast< const SvxSetItem& >(rSet.Get(nWhich,false)); const SfxItemSet& rTmpSet = rSetItem.GetItemSet(); - const SfxBoolItem& rOn = static_cast< const SfxBoolItem& >(rTmpSet.Get(GetWhich(SID_ATTR_PAGE_ON))); + const SfxBoolItem& rOn = rTmpSet.Get(GetWhich(SID_ATTR_PAGE_ON)); if(rOn.GetValue()) { @@ -1244,12 +1244,12 @@ void SvxPageDescPage::InitHeadFoot_Impl( const SfxItemSet& rSet ) { const SfxItemSet& rHeaderSet = pSetItem->GetItemSet(); const SfxBoolItem& rHeaderOn = - static_cast<const SfxBoolItem&>(rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_ON ) )); + rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_ON ) ); if ( rHeaderOn.GetValue() ) { - const SvxSizeItem& rSize = static_cast<const SvxSizeItem&>( - rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) )); + const SvxSizeItem& rSize = + rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) ); const SvxULSpaceItem& rUL = static_cast<const SvxULSpaceItem&>( rHeaderSet.Get( GetWhich( SID_ATTR_ULSPACE ) )); tools::Long nDist = rUL.GetLower(); @@ -1299,12 +1299,12 @@ void SvxPageDescPage::InitHeadFoot_Impl( const SfxItemSet& rSet ) const SfxItemSet& rFooterSet = pSetItem->GetItemSet(); const SfxBoolItem& rFooterOn = - static_cast<const SfxBoolItem&>(rFooterSet.Get( GetWhich( SID_ATTR_PAGE_ON ) )); + rFooterSet.Get( GetWhich( SID_ATTR_PAGE_ON ) ); if ( rFooterOn.GetValue() ) { - const SvxSizeItem& rSize = static_cast<const SvxSizeItem&>( - rFooterSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) )); + const SvxSizeItem& rSize = + rFooterSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) ); const SvxULSpaceItem& rUL = static_cast<const SvxULSpaceItem&>( rFooterSet.Get( GetWhich( SID_ATTR_ULSPACE ) )); tools::Long nDist = rUL.GetUpper(); diff --git a/cui/source/tabpages/tparea.cxx b/cui/source/tabpages/tparea.cxx index 2bacae4da9f5..0f7cc19737e9 100644 --- a/cui/source/tabpages/tparea.cxx +++ b/cui/source/tabpages/tparea.cxx @@ -156,7 +156,7 @@ void SvxAreaTabPage::ActivatePage( const SfxItemSet& rSet ) drawing::FillStyle eXFS = drawing::FillStyle_NONE; if( rSet.GetItemState( XATTR_FILLSTYLE ) != SfxItemState::DONTCARE ) { - XFillStyleItem aFillStyleItem( static_cast<const XFillStyleItem&>( rSet.Get( GetWhich( XATTR_FILLSTYLE ) ) ) ); + XFillStyleItem aFillStyleItem( rSet.Get( GetWhich( XATTR_FILLSTYLE ) ) ); eXFS = aFillStyleItem.GetValue(); m_rXFSet.Put( aFillStyleItem ); } @@ -171,13 +171,13 @@ void SvxAreaTabPage::ActivatePage( const SfxItemSet& rSet ) } case drawing::FillStyle_SOLID: { - m_rXFSet.Put( static_cast<const XFillColorItem&>( rSet.Get( GetWhich( XATTR_FILLCOLOR ) ) ) ); + m_rXFSet.Put( rSet.Get( GetWhich( XATTR_FILLCOLOR ) ) ); SelectFillType(*m_xBtnColor); break; } case drawing::FillStyle_GRADIENT: { - m_rXFSet.Put( static_cast<const XFillGradientItem&>( rSet.Get( GetWhich( XATTR_FILLGRADIENT ) ) ) ); + m_rXFSet.Put( rSet.Get( GetWhich( XATTR_FILLGRADIENT ) ) ); SelectFillType(*m_xBtnGradient); break; } @@ -191,8 +191,7 @@ void SvxAreaTabPage::ActivatePage( const SfxItemSet& rSet ) } case drawing::FillStyle_BITMAP: { - const bool bPattern - = rSet.Get(TypedWhichId<XFillBitmapItem>(GetWhich(XATTR_FILLBITMAP))).isPattern(); + const bool bPattern = rSet.Get(GetWhich(XATTR_FILLBITMAP)).isPattern(); // pass full item set here, bitmap fill has many attributes (tiling, size, offset etc.) m_rXFSet.Put( rSet ); if (!bPattern) diff --git a/cui/source/tabpages/tplnedef.cxx b/cui/source/tabpages/tplnedef.cxx index 30f4081391d4..66fea1aba4d0 100644 --- a/cui/source/tabpages/tplnedef.cxx +++ b/cui/source/tabpages/tplnedef.cxx @@ -258,7 +258,7 @@ void SvxLineDefTabPage::Reset( const SfxItemSet* rAttrs ) { if( rAttrs->GetItemState( GetWhich( XATTR_LINESTYLE ) ) != SfxItemState::DONTCARE ) { - drawing::LineStyle eXLS = static_cast<const XLineStyleItem&>( rAttrs->Get( GetWhich( XATTR_LINESTYLE ) ) ).GetValue(); + drawing::LineStyle eXLS = rAttrs->Get( GetWhich( XATTR_LINESTYLE ) ).GetValue(); switch( eXLS ) { diff --git a/cui/source/tabpages/tpshadow.cxx b/cui/source/tabpages/tpshadow.cxx index 4a538968536b..795a57f13dde 100644 --- a/cui/source/tabpages/tpshadow.cxx +++ b/cui/source/tabpages/tpshadow.cxx @@ -93,8 +93,7 @@ SvxShadowTabPage::SvxShadowTabPage(weld::Container* pPage, weld::DialogControlle drawing::FillStyle eXFS = drawing::FillStyle_SOLID; if( m_rOutAttrs.GetItemState( XATTR_FILLSTYLE ) != SfxItemState::DONTCARE ) { - eXFS = static_cast<const XFillStyleItem&>( m_rOutAttrs. - Get( GetWhich( XATTR_FILLSTYLE ) ) ).GetValue(); + eXFS = m_rOutAttrs.Get( GetWhich( XATTR_FILLSTYLE ) ).GetValue(); switch( eXFS ) { case drawing::FillStyle_SOLID: diff --git a/include/sfx2/tabdlg.hxx b/include/sfx2/tabdlg.hxx index 2b3de379a627..4c519964e275 100644 --- a/include/sfx2/tabdlg.hxx +++ b/include/sfx2/tabdlg.hxx @@ -197,6 +197,12 @@ protected: sal_uInt16 GetWhich( sal_uInt16 nSlot, bool bDeep = true ) const { return pSet->GetPool()->GetWhich( nSlot, bDeep ); } + template<class T> + TypedWhichId<T> GetWhich( TypedWhichId<T> nSlot, bool bDeep = true ) const + { + return TypedWhichId<T>(GetWhich(sal_uInt16(nSlot), bDeep)); + } + const SfxPoolItem* GetOldItem( const SfxItemSet& rSet, sal_uInt16 nSlot, bool bDeep = true ); template<class T> const T* GetOldItem( const SfxItemSet& rSet, TypedWhichId<T> nSlot, bool bDeep = true ) { diff --git a/include/svl/itempool.hxx b/include/svl/itempool.hxx index 8d1f2324363b..ba07c6befc51 100644 --- a/include/svl/itempool.hxx +++ b/include/svl/itempool.hxx @@ -184,6 +184,9 @@ public: { return IsItemPoolable( rItem.Which() ); } void SetItemInfos( const SfxItemInfo *pInfos ); sal_uInt16 GetWhich( sal_uInt16 nSlot, bool bDeep = true ) const; + template<class T> + TypedWhichId<T> GetWhich( sal_uInt16 nSlot, bool bDeep = true ) const + { return TypedWhichId<T>(GetWhich(sal_uInt16(nSlot), bDeep)); } sal_uInt16 GetSlotId( sal_uInt16 nWhich ) const; sal_uInt16 GetTrueWhich( sal_uInt16 nSlot, bool bDeep = true ) const; sal_uInt16 GetTrueSlotId( sal_uInt16 nWhich ) const; diff --git a/svx/source/dialog/hdft.cxx b/svx/source/dialog/hdft.cxx index 5921d3b53c56..f3bb4eccfd38 100644 --- a/svx/source/dialog/hdft.cxx +++ b/svx/source/dialog/hdft.cxx @@ -335,21 +335,21 @@ void SvxHFPage::Reset( const SfxItemSet* rSet ) { const SfxItemSet& rHeaderSet = pSetItem->GetItemSet(); const SfxBoolItem& rHeaderOn = - static_cast<const SfxBoolItem&>(rHeaderSet.Get(GetWhich(SID_ATTR_PAGE_ON))); + rHeaderSet.Get(GetWhich(SID_ATTR_PAGE_ON)); m_xTurnOnBox->set_active(rHeaderOn.GetValue()); if ( rHeaderOn.GetValue() ) { const SfxBoolItem& rDynamic = - static_cast<const SfxBoolItem&>(rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_DYNAMIC ) )); + rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_DYNAMIC ) ); const SfxBoolItem& rShared = - static_cast<const SfxBoolItem&>(rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SHARED ) )); + rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SHARED ) ); const SfxBoolItem* pSharedFirst = nullptr; if (rHeaderSet.HasItem(GetWhich(SID_ATTR_PAGE_SHARED_FIRST))) pSharedFirst = static_cast<const SfxBoolItem*>(&rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SHARED_FIRST ) )); const SvxSizeItem& rSize = - static_cast<const SvxSizeItem&>(rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) )); + rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) ); const SvxULSpaceItem& rUL = static_cast<const SvxULSpaceItem&>(rHeaderSet.Get( GetWhich( SID_ATTR_ULSPACE ) )); const SvxLRSpaceItem& rLR = @@ -696,7 +696,7 @@ void SvxHFPage::ResetBackground_Impl( const SfxItemSet& rSet ) { const SvxSetItem& rSetItem = static_cast< const SvxSetItem& >(rSet.Get(nWhich, false)); const SfxItemSet& rTmpSet = rSetItem.GetItemSet(); - const SfxBoolItem& rOn = static_cast< const SfxBoolItem& >(rTmpSet.Get(GetWhich(SID_ATTR_PAGE_ON))); + const SfxBoolItem& rOn = rTmpSet.Get(GetWhich(SID_ATTR_PAGE_ON)); if(rOn.GetValue()) { @@ -732,7 +732,7 @@ void SvxHFPage::ResetBackground_Impl( const SfxItemSet& rSet ) { const SvxSetItem& rSetItem = static_cast< const SvxSetItem& >(rSet.Get(nWhich, false)); const SfxItemSet& rTmpSet = rSetItem.GetItemSet(); - const SfxBoolItem& rOn = static_cast< const SfxBoolItem& >(rTmpSet.Get(GetWhich(SID_ATTR_PAGE_ON))); + const SfxBoolItem& rOn = rTmpSet.Get(GetWhich(SID_ATTR_PAGE_ON)); if(rOn.GetValue()) { @@ -855,12 +855,12 @@ void SvxHFPage::ActivatePage( const SfxItemSet& rSet ) { const SfxItemSet& rHeaderSet = pSetItem->GetItemSet(); const SfxBoolItem& rHeaderOn = - static_cast<const SfxBoolItem&>(rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_ON ) )); + rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_ON ) ); if ( rHeaderOn.GetValue() ) { - const SvxSizeItem& rSize = static_cast<const SvxSizeItem&>( - rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) )); + const SvxSizeItem& rSize = + rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) ); const SvxULSpaceItem& rUL = static_cast<const SvxULSpaceItem&>( rHeaderSet.Get( GetWhich(SID_ATTR_ULSPACE ) )); const SvxLRSpaceItem& rLR = static_cast<const SvxLRSpaceItem&>( @@ -895,12 +895,12 @@ void SvxHFPage::ActivatePage( const SfxItemSet& rSet ) { const SfxItemSet& rFooterSet = pSetItem->GetItemSet(); const SfxBoolItem& rFooterOn = - static_cast<const SfxBoolItem&>(rFooterSet.Get( GetWhich( SID_ATTR_PAGE_ON ) )); + rFooterSet.Get( GetWhich( SID_ATTR_PAGE_ON ) ); if ( rFooterOn.GetValue() ) { - const SvxSizeItem& rSize = static_cast<const SvxSizeItem&>( - rFooterSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) )); + const SvxSizeItem& rSize = + rFooterSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) ); const SvxULSpaceItem& rUL = static_cast<const SvxULSpaceItem&>( rFooterSet.Get( GetWhich( SID_ATTR_ULSPACE ) )); const SvxLRSpaceItem& rLR = static_cast<const SvxLRSpaceItem&>(