diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2021-01-10 13:58:50 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-01-10 14:59:31 +0100 |
commit | 8f453c674f19188360ba5895c2bd9bd80273a83b (patch) | |
tree | ce569bb8caeaea0b110e1e23e845716cb841588f /sfx2 | |
parent | c5367ee0a60966b755e726de6d175dfcd1630741 (diff) |
static_cast after dynamic_cast
Change-Id: I3792ddadad9582a7e6f4740829c081d9571ddaff
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109049
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/control/bindings.cxx | 28 | ||||
-rw-r--r-- | sfx2/source/toolbox/tbxitem.cxx | 14 |
2 files changed, 24 insertions, 18 deletions
diff --git a/sfx2/source/control/bindings.cxx b/sfx2/source/control/bindings.cxx index d648fdf87537..32021d47285c 100644 --- a/sfx2/source/control/bindings.cxx +++ b/sfx2/source/control/bindings.cxx @@ -1011,14 +1011,16 @@ void SfxBindings::Execute_Impl( SfxRequest& aReq, const SfxSlot* pSlot, SfxShell pNewItem->SetValue( !bOldValue ); aReq.AppendItem( *pNewItem ); } - else if ( dynamic_cast< const SfxEnumItemInterface *>( pOldItem ) != nullptr && - static_cast<const SfxEnumItemInterface *>(pOldItem)->HasBoolValue()) + else if ( auto pOldEnumItem = dynamic_cast< const SfxEnumItemInterface *>( pOldItem ) ) { - // and Enums with Bool-Interface - std::unique_ptr<SfxEnumItemInterface> pNewItem( - static_cast<SfxEnumItemInterface*>(pOldItem->Clone())); - pNewItem->SetBoolValue(!static_cast<const SfxEnumItemInterface *>(pOldItem)->GetBoolValue()); - aReq.AppendItem( *pNewItem ); + if (pOldEnumItem->HasBoolValue()) + { + // and Enums with Bool-Interface + std::unique_ptr<SfxEnumItemInterface> pNewItem( + static_cast<SfxEnumItemInterface*>(pOldEnumItem->Clone())); + pNewItem->SetBoolValue(!pOldEnumItem->GetBoolValue()); + aReq.AppendItem( *pNewItem ); + } } else { OSL_FAIL( "Toggle only for Enums and Bools allowed" ); @@ -1037,12 +1039,14 @@ void SfxBindings::Execute_Impl( SfxRequest& aReq, const SfxSlot* pSlot, SfxShell pNewBoolItem->SetValue( true ); aReq.AppendItem( *pNewItem ); } - else if ( dynamic_cast< const SfxEnumItemInterface *>( pNewItem.get() ) != nullptr && - static_cast<SfxEnumItemInterface *>(pNewItem.get())->HasBoolValue()) + else if ( auto pEnumItem = dynamic_cast<SfxEnumItemInterface *>( pNewItem.get() ) ) { - // and Enums with Bool-Interface - static_cast<SfxEnumItemInterface*>(pNewItem.get())->SetBoolValue(true); - aReq.AppendItem( *pNewItem ); + if (pEnumItem->HasBoolValue()) + { + // and Enums with Bool-Interface + pEnumItem->SetBoolValue(true); + aReq.AppendItem( *pNewItem ); + } } else { OSL_FAIL( "Toggle only for Enums and Bools allowed" ); diff --git a/sfx2/source/toolbox/tbxitem.cxx b/sfx2/source/toolbox/tbxitem.cxx index 88b04852b95d..038b65d55914 100644 --- a/sfx2/source/toolbox/tbxitem.cxx +++ b/sfx2/source/toolbox/tbxitem.cxx @@ -497,13 +497,15 @@ void SfxToolBoxControl::StateChanged eTri = TRISTATE_TRUE; nItemBits |= ToolBoxItemBits::CHECKABLE; } - else if ( dynamic_cast< const SfxEnumItemInterface *>( pState ) != nullptr && - static_cast<const SfxEnumItemInterface *>(pState)->HasBoolValue()) + else if ( auto pEnumItem = dynamic_cast< const SfxEnumItemInterface *>( pState ) ) { - // EnumItem is handled as Bool - if ( static_cast<const SfxEnumItemInterface *>(pState)->GetBoolValue() ) - eTri = TRISTATE_TRUE; - nItemBits |= ToolBoxItemBits::CHECKABLE; + if (pEnumItem->HasBoolValue()) + { + // EnumItem is handled as Bool + if (pEnumItem->GetBoolValue()) + eTri = TRISTATE_TRUE; + nItemBits |= ToolBoxItemBits::CHECKABLE; + } } else if ( pImpl->bShowString && dynamic_cast< const SfxStringItem *>( pState ) != nullptr ) pImpl->pBox->SetItemText(nId, static_cast<const SfxStringItem*>(pState)->GetValue() ); |