include/svl/hint.hxx | 1 sw/inc/hintids.hxx | 1 sw/inc/hints.hxx | 7 ++++ sw/source/core/access/accframebase.cxx | 36 +++++++++------------- sw/source/core/access/acctable.cxx | 54 ++++++++++++++------------------- sw/source/core/attr/format.cxx | 4 -- sw/source/core/layout/atrfrm.cxx | 5 +-- 7 files changed, 50 insertions(+), 58 deletions(-)
New commits: commit f48cb25a914902d92bd109eff86ec3b6d26ba9c3 Author: Bjoern Michaelsen <bjoern.michael...@libreoffice.org> AuthorDate: Thu Sep 15 00:34:50 2022 +0200 Commit: Bjoern Michaelsen <bjoern.michael...@libreoffice.org> CommitDate: Sat Sep 24 15:09:41 2022 +0200 Replace RES_NAME_CHANGED with an SfxHint for stronger typing Change-Id: I0bbe9dc4e10491aafcc623c2add62a246ea67d80 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139961 Tested-by: Jenkins Reviewed-by: Bjoern Michaelsen <bjoern.michael...@libreoffice.org> diff --git a/include/svl/hint.hxx b/include/svl/hint.hxx index 0009a2b3b080..a5cbc1913e2e 100644 --- a/include/svl/hint.hxx +++ b/include/svl/hint.hxx @@ -139,6 +139,7 @@ enum class SfxHintId { SwGatherNodeIndex, SwGatherRefFields, SwGatherFields, + SwNameChanged, // this can possibly be replaced by the generic NameChanged above ThisIsAnSdrHint }; diff --git a/sw/inc/hintids.hxx b/sw/inc/hintids.hxx index 80aa40b9fd8a..b4fddf911179 100644 --- a/sw/inc/hintids.hxx +++ b/sw/inc/hintids.hxx @@ -443,7 +443,6 @@ constexpr TypedWhichId<SwPtrMsgPoolItem> RES_REMOVE_UNO_OBJECT(181); // empty constexpr TypedWhichId<SwFindNearestNode> RES_FINDNEARESTNODE(184); constexpr TypedWhichId<SwPtrMsgPoolItem> RES_CONTENT_VISIBLE(185); -constexpr TypedWhichId<SwStringMsgPoolItem> RES_NAME_CHANGED(187); constexpr TypedWhichId<SwStringMsgPoolItem> RES_TITLE_CHANGED(188); constexpr TypedWhichId<SwStringMsgPoolItem> RES_DESCRIPTION_CHANGED(189); constexpr TypedWhichId<SwMsgPoolItem> RES_LINKED_GRAPHIC_STREAM_ARRIVED(189); diff --git a/sw/inc/hints.hxx b/sw/inc/hints.hxx index 9b4962246fa4..8c15ed64ced6 100644 --- a/sw/inc/hints.hxx +++ b/sw/inc/hints.hxx @@ -191,6 +191,13 @@ public: const SwTableBox& m_rTableBox; TableBoxFormatChanged(const SwTableBoxFormat& rNewFormat, const SwTableBox& rTableBox) : m_rNewFormat(rNewFormat), m_rTableBox(rTableBox) {}; }; +class NameChanged final : public SfxHint +{ +public: + const OUString m_sOld; + const OUString m_sNew; + NameChanged(const OUString& rOld, const OUString& rNew) : SfxHint(SfxHintId::NameChanged), m_sOld(rOld), m_sNew(rNew) {}; +}; } class SwUpdateAttr final : public SwMsgPoolItem diff --git a/sw/source/core/access/accframebase.cxx b/sw/source/core/access/accframebase.cxx index e0821f3ded24..fc94259b5bfd 100644 --- a/sw/source/core/access/accframebase.cxx +++ b/sw/source/core/access/accframebase.cxx @@ -206,35 +206,29 @@ SwAccessibleFrameBase::~SwAccessibleFrameBase() void SwAccessibleFrameBase::Notify(const SfxHint& rHint) { + const SwFlyFrame* pFlyFrame = static_cast<const SwFlyFrame*>(GetFrame()); if(rHint.GetId() == SfxHintId::Dying) { EndListeningAll(); } - else if (rHint.GetId() == SfxHintId::SwLegacyModify) + else if (rHint.GetId() == SfxHintId::SwNameChanged && pFlyFrame) { - auto pLegacyModifyHint = static_cast<const sw::LegacyModifyHint*>(&rHint); - const sal_uInt16 nWhich = pLegacyModifyHint->GetWhich(); - const SwFlyFrame* pFlyFrame = static_cast<const SwFlyFrame*>(GetFrame()); - if(nWhich == RES_NAME_CHANGED && pFlyFrame) - { - const SwFrameFormat* pFrameFormat = pFlyFrame->GetFormat(); + auto rNameChanged = static_cast<const sw::NameChanged&>(rHint); + const SwFrameFormat* pFrameFormat = pFlyFrame->GetFormat(); - const OUString sOldName( GetName() ); - assert( !pLegacyModifyHint->m_pOld || - static_cast<const SwStringMsgPoolItem *>(pLegacyModifyHint->m_pOld)->GetString() == GetName()); + const OUString sOldName( GetName() ); + assert( rNameChanged.m_sOld == sOldName); - SetName( pFrameFormat->GetName() ); - assert( !pLegacyModifyHint->m_pNew || - static_cast<const SwStringMsgPoolItem *>(pLegacyModifyHint->m_pNew)->GetString() == GetName()); + SetName( pFrameFormat->GetName() ); + assert( rNameChanged.m_sNew == GetName()); - if( sOldName != GetName() ) - { - AccessibleEventObject aEvent; - aEvent.EventId = AccessibleEventId::NAME_CHANGED; - aEvent.OldValue <<= sOldName; - aEvent.NewValue <<= GetName(); - FireAccessibleEvent( aEvent ); - } + if( sOldName != GetName() ) + { + AccessibleEventObject aEvent; + aEvent.EventId = AccessibleEventId::NAME_CHANGED; + aEvent.OldValue <<= sOldName; + aEvent.NewValue <<= GetName(); + FireAccessibleEvent( aEvent ); } } } diff --git a/sw/source/core/access/acctable.cxx b/sw/source/core/access/acctable.cxx index 46772c4ec732..0e3101c71cef 100644 --- a/sw/source/core/access/acctable.cxx +++ b/sw/source/core/access/acctable.cxx @@ -632,45 +632,39 @@ SwAccessibleTable::~SwAccessibleTable() void SwAccessibleTable::Notify(const SfxHint& rHint) { + const SwTabFrame* pTabFrame = static_cast<const SwTabFrame*>(GetFrame()); if(rHint.GetId() == SfxHintId::Dying) { EndListeningAll(); } - else if (rHint.GetId() == SfxHintId::SwLegacyModify) + else if (rHint.GetId() == SfxHintId::SwNameChanged && pTabFrame) { - auto pLegacyHint = static_cast<const sw::LegacyModifyHint*>(&rHint); - const sal_uInt16 nWhich = pLegacyHint->GetWhich(); - const SwTabFrame* pTabFrame = static_cast<const SwTabFrame*>(GetFrame()); - if(nWhich == RES_NAME_CHANGED && pTabFrame) - { - const SwFrameFormat *pFrameFormat = pTabFrame->GetFormat(); - - const OUString sOldName( GetName() ); - const OUString sNewTabName = pFrameFormat->GetName(); + const SwFrameFormat *pFrameFormat = pTabFrame->GetFormat(); + const OUString sOldName( GetName() ); + const OUString sNewTabName = pFrameFormat->GetName(); - SetName( sNewTabName + "-" + OUString::number( pTabFrame->GetPhyPageNum() ) ); + SetName( sNewTabName + "-" + OUString::number( pTabFrame->GetPhyPageNum() ) ); - if( sOldName != GetName() ) - { - AccessibleEventObject aEvent; - aEvent.EventId = AccessibleEventId::NAME_CHANGED; - aEvent.OldValue <<= sOldName; - aEvent.NewValue <<= GetName(); - FireAccessibleEvent( aEvent ); - } + if( sOldName != GetName() ) + { + AccessibleEventObject aEvent; + aEvent.EventId = AccessibleEventId::NAME_CHANGED; + aEvent.OldValue <<= sOldName; + aEvent.NewValue <<= GetName(); + FireAccessibleEvent( aEvent ); + } - const OUString sOldDesc( m_sDesc ); - const OUString sArg2( GetFormattedPageNumber() ); + const OUString sOldDesc( m_sDesc ); + const OUString sArg2( GetFormattedPageNumber() ); - m_sDesc = GetResource( STR_ACCESS_TABLE_DESC, &sNewTabName, &sArg2 ); - if( m_sDesc != sOldDesc ) - { - AccessibleEventObject aEvent; - aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED; - aEvent.OldValue <<= sOldDesc; - aEvent.NewValue <<= m_sDesc; - FireAccessibleEvent( aEvent ); - } + m_sDesc = GetResource( STR_ACCESS_TABLE_DESC, &sNewTabName, &sArg2 ); + if( m_sDesc != sOldDesc ) + { + AccessibleEventObject aEvent; + aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED; + aEvent.OldValue <<= sOldDesc; + aEvent.NewValue <<= m_sDesc; + FireAccessibleEvent( aEvent ); } } } diff --git a/sw/source/core/attr/format.cxx b/sw/source/core/attr/format.cxx index 4f458edb8712..5b516d7dc437 100644 --- a/sw/source/core/attr/format.cxx +++ b/sw/source/core/attr/format.cxx @@ -147,10 +147,8 @@ void SwFormat::SetFormatName( const OUString& rNewName, bool bBroadcast ) OSL_ENSURE( !IsDefault(), "SetName: Defaultformat" ); if( bBroadcast ) { - SwStringMsgPoolItem aOld( RES_NAME_CHANGED, m_aFormatName ); - SwStringMsgPoolItem aNew( RES_NAME_CHANGED, rNewName ); m_aFormatName = rNewName; - const sw::LegacyModifyHint aHint(&aOld, &aNew); + const sw::NameChanged aHint(m_aFormatName, rNewName); SwClientNotify(*this, aHint); } else diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx index 7b2d7276beff..1cf992854c6c 100644 --- a/sw/source/core/layout/atrfrm.cxx +++ b/sw/source/core/layout/atrfrm.cxx @@ -2572,16 +2572,15 @@ void SwFrameFormat::SetFormatName( const OUString& rNewName, bool bBroadcast ) assert( m_ffList->end() != it ); SAL_INFO_IF(m_aFormatName == rNewName, "sw.core", "SwFrmFmt not really renamed, as both names are equal"); - const SwStringMsgPoolItem aOld( RES_NAME_CHANGED, m_aFormatName ); // As it's a non-unique list, rename should never fail! + sw::NameChanged aHint(m_aFormatName, rNewName); bool const renamed = m_ffList->m_PosIndex.modify( it, change_name( rNewName ), change_name( m_aFormatName ) ); assert(renamed); (void)renamed; // unused in NDEBUG if (bBroadcast) { - const SwStringMsgPoolItem aNew( RES_NAME_CHANGED, rNewName ); - GetNotifier().Broadcast(sw::LegacyModifyHint( &aOld, &aNew )); + GetNotifier().Broadcast(aHint); } } else