From d92602c5b13d0a60439d86c5a033d124178726ca Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 10 Sep 2014 14:20:18 +0200 Subject: more fixes for SfxItemState In commit 88a874fc "convert SfxItemState constants to a proper enum" I made some mistakes in converting bitwise logic to boolean logic. I fixed one of those places in commit 7ad83656 "fix bitwise->logic conversion in SfxItemState commit" This commit fixes the other places where I converted bitwise to normal boolean logic. I also validated that none of the existing code tries to uses combinations of these enum values. This commit also introduces an exception-throwing check in the one place where the enum is explicitly cast to make sure that no combinations sneak in. Change-Id: I545f7d17b76c4fd999078867caec314e83ffe165 Signed-off-by: Stephan Bergmann --- chart2/source/controller/dialogs/tp_AxisLabel.cxx | 6 +++--- sfx2/source/toolbox/tbxitem.cxx | 16 ++++++++++++++-- svx/source/tbxctrls/formatpaintbrushctrl.cxx | 2 +- sw/source/core/doc/DocumentContentOperationsManager.cxx | 4 ++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/chart2/source/controller/dialogs/tp_AxisLabel.cxx b/chart2/source/controller/dialogs/tp_AxisLabel.cxx index 35676394c983..5163ebb27ead 100644 --- a/chart2/source/controller/dialogs/tp_AxisLabel.cxx +++ b/chart2/source/controller/dialogs/tp_AxisLabel.cxx @@ -153,7 +153,7 @@ void SchAxisLabelTabPage::Reset( const SfxItemSet* rInAttrs ) bCheck = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue(); m_pCbShowDescription->Check( bCheck ); - if( aState != SFX_ITEM_DEFAULT && aState != SFX_ITEM_SET) + if( aState != SFX_ITEM_DEFAULT && aState != SFX_ITEM_SET ) m_pCbShowDescription->Hide(); } @@ -201,7 +201,7 @@ void SchAxisLabelTabPage::Reset( const SfxItemSet* rInAttrs ) bCheck = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue(); m_pCbTextOverlap->Check( bCheck ); - if( aState != SFX_ITEM_DEFAULT ) + if( aState != SFX_ITEM_DEFAULT && aState != SFX_ITEM_SET ) m_pCbTextOverlap->Hide(); } @@ -220,7 +220,7 @@ void SchAxisLabelTabPage::Reset( const SfxItemSet* rInAttrs ) bCheck = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue(); m_pCbTextBreak->Check( bCheck ); - if( aState != SFX_ITEM_DEFAULT ) + if( aState != SFX_ITEM_DEFAULT && aState != SFX_ITEM_SET ) { m_pCbTextBreak->Hide(); if( ! m_pCbTextOverlap->IsVisible() ) diff --git a/sfx2/source/toolbox/tbxitem.cxx b/sfx2/source/toolbox/tbxitem.cxx index 47348ec1e989..22a36a73c2ae 100644 --- a/sfx2/source/toolbox/tbxitem.cxx +++ b/sfx2/source/toolbox/tbxitem.cxx @@ -547,7 +547,13 @@ throw ( ::com::sun::star::uno::RuntimeException, std::exception ) { ItemStatus aItemStatus; rEvent.State >>= aItemStatus; - eState = (SfxItemState) aItemStatus.State; + SfxItemState tmpState = (SfxItemState) aItemStatus.State; + // make sure no-one tries to send us a combination of states + if (eState != SfxItemState::UNKNOWN && eState != SFX_ITEM_DISABLED && + eState != SFX_ITEM_READONLY && eState != SFX_ITEM_DONTCARE && + eState != SFX_ITEM_DEFAULT && eState != SFX_ITEM_SET) + throw ::com::sun::star::uno::RuntimeException("unknown status"); + eState = tmpState; pItem = new SfxVoidItem( nSlotId ); } else if ( pType == cppu::UnoType< ::com::sun::star::frame::status::Visibility>::get() ) @@ -1095,7 +1101,13 @@ throw ( ::com::sun::star::uno::RuntimeException, std::exception ) { ItemStatus aItemStatus; rEvent.State >>= aItemStatus; - eState = (SfxItemState) aItemStatus.State; + SfxItemState tmpState = (SfxItemState) aItemStatus.State; + // make sure no-one tries to send us a combination of states + if (eState != SfxItemState::UNKNOWN && eState != SFX_ITEM_DISABLED && + eState != SFX_ITEM_READONLY && eState != SFX_ITEM_DONTCARE && + eState != SFX_ITEM_DEFAULT && eState != SFX_ITEM_SET) + throw ::com::sun::star::uno::RuntimeException("unknown status"); + eState = tmpState; pItem = new SfxVoidItem( nSlotId ); } else if ( pType == cppu::UnoType< ::com::sun::star::frame::status::Visibility>::get() ) diff --git a/svx/source/tbxctrls/formatpaintbrushctrl.cxx b/svx/source/tbxctrls/formatpaintbrushctrl.cxx index 27c6c8aa8067..7e5619deeffa 100644 --- a/svx/source/tbxctrls/formatpaintbrushctrl.cxx +++ b/svx/source/tbxctrls/formatpaintbrushctrl.cxx @@ -96,7 +96,7 @@ void FormatPaintBrushToolBoxControl::Select(sal_uInt16 /*nSelectModifier*/) void FormatPaintBrushToolBoxControl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ) { - if( eState != SFX_ITEM_SET ) + if( eState != SFX_ITEM_DEFAULT && eState != SFX_ITEM_SET ) m_bPersistentCopy = false; SfxToolBoxControl::StateChanged( nSID, eState, pState ); } diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx index f60fc5e445f0..e9aeddb0e5de 100644 --- a/sw/source/core/doc/DocumentContentOperationsManager.cxx +++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx @@ -4024,8 +4024,8 @@ static void lcl_PushNumruleState( SfxItemState &aNumRuleState, SwNumRuleItem &aN } } -static void lcl_PopNumruleState( int aNumRuleState, const SwNumRuleItem &aNumRuleItem, - int aListIdState, const SfxStringItem &aListIdItem, +static void lcl_PopNumruleState( SfxItemState aNumRuleState, const SwNumRuleItem &aNumRuleItem, + SfxItemState aListIdState, const SfxStringItem &aListIdItem, SwTxtNode *pDestTxtNd, const SwPaM& rPam ) { /* If only a part of one paragraph is copied -- cgit