include/svl/hint.hxx | 1 sw/inc/calbck.hxx | 180 ++------- sw/inc/fmtcol.hxx | 1 sw/inc/fmthdft.hxx | 18 sw/inc/hintids.hxx | 4 sw/inc/hints.hxx | 14 sw/inc/ndtxt.hxx | 2 sw/inc/ring.hxx | 1 sw/inc/swevent.hxx | 19 - sw/inc/txtatr.hxx | 1 sw/qa/core/uwriter.cxx | 4 sw/source/core/attr/BorderCacheOwner.cxx | 1 sw/source/core/attr/calbck.cxx | 126 ++++-- sw/source/core/attr/format.cxx | 53 +- sw/source/core/attr/hints.cxx | 6 sw/source/core/crsr/crsrsh.cxx | 6 sw/source/core/doc/docdesc.cxx | 2 sw/source/core/doc/docfmt.cxx | 2 sw/source/core/doc/docftn.cxx | 11 sw/source/core/doc/fmtcol.cxx | 58 +-- sw/source/core/doc/lineinfo.cxx | 4 sw/source/core/doc/notxtfrm.cxx | 124 +++--- sw/source/core/doc/number.cxx | 25 - sw/source/core/docnode/node.cxx | 24 - sw/source/core/docnode/section.cxx | 127 +++--- sw/source/core/draw/dcontact.cxx | 92 +--- sw/source/core/fields/ddetbl.cxx | 4 sw/source/core/fields/docufld.cxx | 12 sw/source/core/fields/reffld.cxx | 13 sw/source/core/fields/usrfld.cxx | 6 sw/source/core/inc/flyfrm.hxx | 1 sw/source/core/layout/atrfrm.cxx | 124 +++--- sw/source/core/layout/fly.cxx | 33 - sw/source/core/layout/flycnt.cxx | 15 sw/source/core/layout/flyincnt.cxx | 56 +-- sw/source/core/layout/flylay.cxx | 22 - sw/source/core/layout/pagechg.cxx | 18 sw/source/core/layout/pagedesc.cxx | 5 sw/source/core/layout/sectfrm.cxx | 18 sw/source/core/layout/tabfrm.cxx | 142 +++---- sw/source/core/layout/wsfrm.cxx | 34 - sw/source/core/table/swtable.cxx | 107 ++--- sw/source/core/text/txtfrm.cxx | 482 ++++++++++++-------------- sw/source/core/txtnode/atrfld.cxx | 91 ++-- sw/source/core/txtnode/attrcontentcontrol.cxx | 3 sw/source/core/txtnode/attrlinebreak.cxx | 3 sw/source/core/txtnode/fmtatr2.cxx | 10 sw/source/core/txtnode/ndtxt.cxx | 98 +---- sw/source/core/txtnode/txtatr2.cxx | 76 +--- sw/source/core/undo/rolbck.cxx | 55 +- sw/source/core/undo/unattr.cxx | 31 - sw/source/core/undo/undobj1.cxx | 24 - sw/source/core/unocore/unochart.cxx | 3 53 files changed, 1057 insertions(+), 1335 deletions(-)
New commits: commit aa95ece9d8eb0c3c255a7c565e12e377660a176c Author: Stephan Bergmann <stephan.bergm...@allotropia.de> AuthorDate: Wed Jan 8 10:26:49 2025 +0100 Commit: Stephan Bergmann <stephan.bergm...@allotropia.de> CommitDate: Wed Jan 8 12:48:47 2025 +0100 Revert "Revert "Revert "stronger typing for SwClient::GetRegisteredIn"" and fix SwIterator cast" This reverts commit d8e29e2697e90da6acf5858fd74d6054ed9e5aa3. Reason for revert: It causes CppunitTest_sw_rtfexport2 to fail with > /sw/inc/calbck.hxx:428:18: runtime error: downcast of address 0x6060004d0fd8 which does not point to an object of type 'sw::ClientBase<SwModify>' > 0x6060004d0fc0: note: object is base class subobject at offset 24 within object of type 'SwFormatHeader' > 00 00 00 00 90 c6 d3 ea 6e 7f 00 00 01 00 00 00 66 00 48 01 a0 11 00 00 88 be be be 10 c7 d3 ea > ^ ~~~~~~~~~~~ > vptr for 'sw::ClientBase<SwFrameFormat>' base class of 'SwFormatHeader' > #0 0x7f6edd5beb5e in SwIterator<sw::ClientBase<SwModify>, SwModify, (sw::IteratorMode)0>::First() /sw/inc/calbck.hxx:428:18 > #1 0x7f6edd5b6d69 in SwModify::CallSwClientNotify(SfxHint const&) const /sw/source/core/attr/calbck.cxx:237:35 > #2 0x7f6edd5b7c45 in sw::BroadcastingModify::CallSwClientNotify(SfxHint const&) const /sw/source/core/attr/calbck.cxx:259:15 > #3 0x7f6edd5b49c6 in SwModify::SwClientNotify(SwModify const&, SfxHint const&) /sw/source/core/attr/calbck.cxx:229:5 > #4 0x7f6edd605e7b in SwFormat::SwClientNotify(SwModify const&, SfxHint const&) /sw/source/core/attr/format.cxx:309:19 > #5 0x7f6ee039738b in SwFrameFormat::SwClientNotify(SwModify const&, SfxHint const&) /sw/source/core/layout/atrfrm.cxx:2849:15 > #6 0x7f6edd5b8189 in sw::ClientNotifyAttrChg(SwModify&, SwAttrSet const&, SwAttrSet&, SwAttrSet&) /sw/source/core/attr/calbck.cxx:268:13 > #7 0x7f6edd610879 in SwFormat::SetFormatAttr(SfxItemSet const&) /sw/source/core/attr/format.cxx:604:13 > #8 0x7f6ee6495964 in FillHdFt(SwFrameFormat*, SfxItemSet const&) /sw/source/uibase/utlui/uitool.cxx:239:14 > #9 0x7f6ee64914e7 in ItemSetToPageDesc(SfxItemSet const&, SwPageDesc&) /sw/source/uibase/utlui/uitool.cxx:340:13 > #10 0x7f6ee43fe5b4 in SwDocStyleSheet::SetItemSet(SfxItemSet const&, bool, bool) /sw/source/uibase/app/docstyle.cxx:1894:13 > #11 0x7f6ee304306c in SwXPageStyle::SetPropertyValues_Impl(com::sun::star::uno::Sequence<rtl::OUString> const&, com::sun::star::uno::Sequence<com::sun::star::uno::Any> const&) /sw/source/core/unocore/unostyle.cxx:3157:33 > #12 0x7f6ee304d9b9 in SwXPageStyle::setPropertyValue(rtl::OUString const&, com::sun::star::uno::Any const&) /sw/source/core/unocore/unostyle.cxx:3453:5 > #13 0x7f6e9b369897 in writerfilter::dmapper::DomainMapper_Impl::PushPageHeaderFooter(writerfilter::dmapper::PagePartType, writerfilter::dmapper::PageType) /sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx:3910:25 > #14 0x7f6e9b445050 in writerfilter::dmapper::DomainMapper_Impl::substream(unsigned int, tools::SvRef<writerfilter::Reference<writerfilter::Stream> > const&) /sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx:10046:13 > #15 0x7f6e9b101b9d in writerfilter::dmapper::DomainMapper::lcl_substream(unsigned int, tools::SvRef<writerfilter::Reference<writerfilter::Stream> > const&) /sw/source/writerfilter/dmapper/DomainMapper.cxx:4746:14 > #16 0x7f6e9b877f73 in writerfilter::LoggedStream::substream(unsigned int, tools::SvRef<writerfilter::Reference<writerfilter::Stream> > const&) /sw/source/writerfilter/dmapper/LoggedResources.cxx:272:5 > #17 0x7f6e9ad35daf in writerfilter::rtftok::RTFDocumentImpl::resolveSubstream(unsigned long, unsigned int, rtl::OUString const&) /sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx:381:14 > #18 0x7f6e9ad33bc1 in writerfilter::rtftok::RTFDocumentImpl::resolveSubstream(unsigned long, unsigned int) /sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx:356:5 > #19 0x7f6e9ad48f49 in writerfilter::rtftok::RTFDocumentImpl::sectBreak(bool) /sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx:705:9 > #20 0x7f6e9adcd3b7 in writerfilter::rtftok::RTFDocumentImpl::popState() /sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx:3695:13 > #21 0x7f6e9afd2595 in writerfilter::rtftok::RTFTokenizer::resolveParse() /sw/source/writerfilter/rtftok/rtftokenizer.cxx:2011:37 > #22 0x7f6e9ad4ef4f in writerfilter::rtftok::RTFDocumentImpl::resolve(writerfilter::Stream&) /sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx:844:27 > #23 0x7f6e9bd39f91 in (anonymous namespace)::RtfFilter::filter(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> const&) /sw/source/writerfilter/filter/RtfFilter.cxx:164:20 > #24 0x7f6ef659a6a4 in SfxObjectShell::ImportFrom(SfxMedium&, com::sun::star::uno::Reference<com::sun::star::text::XTextRange> const&) /sfx2/source/doc/objstor.cxx:2719:34 > #25 0x7f6ef654cf40 in SfxObjectShell::DoLoad(SfxMedium*) /sfx2/source/doc/objstor.cxx:767:23 > #26 0x7f6ef67df024 in SfxBaseModel::load(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> const&) /sfx2/source/doc/sfxbasemodel.cxx:1991:36 > #27 0x7f6ef703d0f0 in (anonymous namespace)::SfxFrameLoader_Impl::load(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> const&, com::sun::star::uno::Reference<com::sun::star::frame::XFrame> const&) /sfx2/source/view/frmload.cxx:725:28 > #28 0x7f6ec073ee16 in framework::LoadEnv::impl_loadContent() /framework/source/loadenv/loadenv.cxx:1180:37 > #29 0x7f6ec0735cb2 in framework::LoadEnv::start() /framework/source/loadenv/loadenv.cxx:415:20 > #30 0x7f6ec072e172 in framework::LoadEnv::startLoading(rtl::OUString const&, com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> const&, com::sun::star::uno::Reference<com::sun::star::frame::XFrame> const&, rtl::OUString const&, int, LoadEnvFeatures) /framework/source/loadenv/loadenv.cxx:311:5 > #31 0x7f6ec0729554 in framework::LoadEnv::loadComponentFromURL(com::sun::star::uno::Reference<com::sun::star::frame::XComponentLoader> const&, com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&, rtl::OUString const&, rtl::OUString const&, int, com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> const&) /framework/source/loadenv/loadenv.cxx:167:14 > #32 0x7f6ec07fe176 in framework::Desktop::loadComponentFromURL(rtl::OUString const&, rtl::OUString const&, int, com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> const&) /framework/source/services/desktop.cxx:592:16 > #33 0x7f6ec07fe396 in non-virtual thunk to framework::Desktop::loadComponentFromURL(rtl::OUString const&, rtl::OUString const&, int, com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> const&) /framework/source/services/desktop.cxx > #34 0x7f6ed3d9c8c9 in unotest::MacrosTest::loadFromDesktop(rtl::OUString const&, rtl::OUString const&, com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> const&) /unotest/source/cpp/macros_test.cxx:72:62 > #35 0x7f6ef13e8d62 in UnoApiTest::loadWithParams(rtl::OUString const&, com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> const&) /test/source/unoapi_test.cxx:126:19 > #36 0x7f6ef13e7e98 in UnoApiTest::loadFromURL(rtl::OUString const&, char const*) /test/source/unoapi_test.cxx:108:5 > #37 0x7f6efe61e0c7 in SwModelTestBase::loadURL(rtl::OUString const&, char const*) /sw/qa/unit/swmodeltestbase.cxx:384:5 > #38 0x7f6efe632c07 in SwModelTestBase::createSwDoc(char const*, char const*) /sw/qa/unit/swmodeltestbase.cxx:433:9 > #39 0x7f6efe0c635f in (anonymous namespace)::testAllGapsWord::TestBody() /sw/qa/extras/rtfexport/rtfexport2.cxx:771:5 (<https://ci.libreoffice.org/job/lo_ubsan/3418/>) Change-Id: I70bd88050887c8b6c747707f2ea3b89802c7b468 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179946 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de> diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx index 7481fdaa5563..58a336bbc92b 100644 --- a/sw/inc/calbck.hxx +++ b/sw/inc/calbck.hxx @@ -24,7 +24,6 @@ #include <svl/hint.hxx> #include <svl/broadcast.hxx> #include <svl/poolitem.hxx> -#include <tools/debug.hxx> #include "swdllapi.h" #include "ring.hxx" #include <type_traits> @@ -65,18 +64,10 @@ class SwFindNearestNode; This is still subject to refactoring. */ - namespace sw { class ClientIteratorBase; class ListenerEntry; - enum class IteratorMode { Exact, UnwrapMulti }; -} - -template<typename TElementType, typename TSource, sw::IteratorMode eMode> class SwIterator; - -namespace sw -{ void ClientNotifyAttrChg(SwModify& rModify, const SwAttrSet& aSet, SwAttrSet& aOld, SwAttrSet& aNew); struct SAL_DLLPUBLIC_RTTI LegacyModifyHint final: SfxHint { @@ -135,58 +126,52 @@ namespace sw virtual const SwRowFrame* DynCastRowFrame() const { return nullptr; } virtual const SwTable* DynCastTable() const { return nullptr; } }; + enum class IteratorMode { Exact, UnwrapMulti }; +} - template<typename T> - class SW_DLLPUBLIC ClientBase : public ::sw::WriterListener - { - // avoids making the details of the linked list and the callback method public - friend class ::SwModify; - friend class sw::ClientIteratorBase; - friend class sw::ListenerEntry; - template<typename E, typename S, sw::IteratorMode> friend class ::SwIterator; - - T *m_pRegisteredIn; ///< event source +// SwClient +class SW_DLLPUBLIC SwClient : public ::sw::WriterListener +{ + // avoids making the details of the linked list and the callback method public + friend class SwModify; + friend class sw::ClientIteratorBase; + friend class sw::ListenerEntry; + template<typename E, typename S, sw::IteratorMode> friend class SwIterator; - protected: - // single argument ctors shall be explicit. - inline explicit ClientBase( T* pToRegisterIn ) - : m_pRegisteredIn( nullptr ) - { - if(pToRegisterIn) - pToRegisterIn->Add(*this); - } + SwModify *m_pRegisteredIn; ///< event source - // write access to pRegisteredIn shall be granted only to the object itself (protected access) - T* GetRegisteredInNonConst() const { return m_pRegisteredIn; } +protected: + // single argument ctors shall be explicit. + inline explicit SwClient( SwModify* pToRegisterIn ); - // when overriding this, you MUST call SwClient::SwClientNotify() in the override! - virtual void SwClientNotify(const SwModify&, const SfxHint& rHint) override; + // write access to pRegisteredIn shall be granted only to the object itself (protected access) + SwModify* GetRegisteredInNonConst() const { return m_pRegisteredIn; } - public: - ClientBase() : m_pRegisteredIn(nullptr) {} - ClientBase(ClientBase&&) noexcept; - virtual ~ClientBase() override; + // when overriding this, you MUST call SwClient::SwClientNotify() in the override! + virtual void SwClientNotify(const SwModify&, const SfxHint& rHint) override; +public: + SwClient() : m_pRegisteredIn(nullptr) {} + SwClient(SwClient&&) noexcept; + virtual ~SwClient() override; - // in case an SwModify object is destroyed that itself is registered in another SwModify, - // its SwClient objects can decide to get registered to the latter instead by calling this method - std::optional<sw::ModifyChangedHint> CheckRegistration( const SfxPoolItem* pOldValue ); - // SwFormat wants to die different than the rest: It wants to reparent every client to its parent - // and then send a SwFormatChg hint. - void CheckRegistrationFormat(SwFormat& rOld); - const T* GetRegisteredIn() const { return m_pRegisteredIn; } - T* GetRegisteredIn() { return m_pRegisteredIn; } - void EndListeningAll(); - void StartListeningToSameModifyAs(const ClientBase&); + // in case an SwModify object is destroyed that itself is registered in another SwModify, + // its SwClient objects can decide to get registered to the latter instead by calling this method + std::optional<sw::ModifyChangedHint> CheckRegistration( const SfxPoolItem* pOldValue ); + // SwFormat wants to die different than the rest: It wants to reparent every client to its parent + // and then send a SwFormatChg hint. + void CheckRegistrationFormat(SwFormat& rOld); + const SwModify* GetRegisteredIn() const { return m_pRegisteredIn; } + SwModify* GetRegisteredIn() { return m_pRegisteredIn; } + void EndListeningAll(); + void StartListeningToSameModifyAs(const SwClient&); - // get information about attribute - virtual bool GetInfo( SwFindNearestNode& ) const { return true; } - }; -} -typedef sw::ClientBase<SwModify> SwClient; + // get information about attribute + virtual bool GetInfo( SwFindNearestNode& ) const { return true; } +}; // SwModify @@ -196,13 +181,12 @@ class SW_DLLPUBLIC SwModify: public SwClient { friend class sw::ClientIteratorBase; friend void sw::ClientNotifyAttrChg(SwModify&, const SwAttrSet&, SwAttrSet&, SwAttrSet&); - template<typename E, typename S, sw::IteratorMode> friend class ::SwIterator; + template<typename E, typename S, sw::IteratorMode> friend class SwIterator; sw::WriterListener* m_pWriterListeners; // the start of the linked list of clients bool m_bModifyLocked; // don't broadcast changes now SwModify(SwModify const &) = delete; SwModify &operator =(const SwModify&) = delete; - void EnsureBroadcasting(); protected: virtual void SwClientNotify(const SwModify&, const SfxHint& rHint) override; public: @@ -215,8 +199,8 @@ public: virtual ~SwModify() override; - template<typename T> void Add(sw::ClientBase<T>& rDepend); - template<typename T> void Remove(sw::ClientBase<T>& rDepend); + void Add(SwClient& rDepend); + void Remove(SwClient& rDepend); bool HasWriterListeners() const { return m_pWriterListeners; } bool HasOnlyOneListener() const { return m_pWriterListeners && m_pWriterListeners->IsLast(); } @@ -228,6 +212,7 @@ public: bool IsModifyLocked() const { return m_bModifyLocked; } }; +template<typename TElementType, typename TSource, sw::IteratorMode eMode> class SwIterator; namespace sw { @@ -291,7 +276,8 @@ namespace sw }; class ClientIteratorBase : public sw::Ring< ::sw::ClientIteratorBase > { - friend class ::SwModify; + friend void SwModify::Remove(SwClient&); + friend void SwModify::Add(SwClient&); protected: const SwModify& m_rRoot; // the current object in an iteration @@ -419,93 +405,27 @@ public: using sw::ClientIteratorBase::IsChanged; }; -template< typename T, typename TSource > class SwIterator<sw::ClientBase<T>, TSource> final : private sw::ClientIteratorBase +template< typename TSource > class SwIterator<SwClient, TSource> final : private sw::ClientIteratorBase { static_assert(std::is_base_of<SwModify,TSource>::value, "TSource needs to be derived from SwModify"); public: SwIterator( const TSource& rSrc ) : sw::ClientIteratorBase(rSrc) {} - sw::ClientBase<T>* First() - { return static_cast<sw::ClientBase<T>*>(GoStart()); } - sw::ClientBase<T>* Next() + SwClient* First() + { return static_cast<SwClient*>(GoStart()); } + SwClient* Next() { if(!IsChanged()) m_pPosition = GetRightOfPos(); - return static_cast<sw::ClientBase<T>*>(Sync()); + return static_cast<SwClient*>(Sync()); } using sw::ClientIteratorBase::IsChanged; }; -template<typename T> -void SwModify::Add(sw::ClientBase<T>& rDepend) +SwClient::SwClient( SwModify* pToRegisterIn ) + : m_pRegisteredIn( nullptr ) { - DBG_TESTSOLARMUTEX(); -#ifdef DBG_UTIL - EnsureBroadcasting(); - assert(dynamic_cast<T*>(this)); -#endif - - if (rDepend.GetRegisteredIn() == this) - return; - - // deregister new client in case it is already registered elsewhere - if( rDepend.GetRegisteredIn() != nullptr ) - rDepend.m_pRegisteredIn->Remove(rDepend); - - if( !m_pWriterListeners ) - { - // first client added - m_pWriterListeners = &rDepend; - m_pWriterListeners->m_pLeft = nullptr; - m_pWriterListeners->m_pRight = nullptr; - } - else - { - // append client - rDepend.m_pRight = m_pWriterListeners->m_pRight; - m_pWriterListeners->m_pRight = &rDepend; - rDepend.m_pLeft = m_pWriterListeners; - if( rDepend.m_pRight ) - rDepend.m_pRight->m_pLeft = &rDepend; - } - - // connect client to me - rDepend.m_pRegisteredIn = static_cast<T*>(this); + if(pToRegisterIn) + pToRegisterIn->Add(*this); } -template<typename T> -void SwModify::Remove(sw::ClientBase<T>& rDepend) -{ - DBG_TESTSOLARMUTEX(); - assert(rDepend.m_pRegisteredIn == this); - - // SwClient is my listener - // remove it from my list - ::sw::WriterListener* pR = rDepend.m_pRight; - ::sw::WriterListener* pL = rDepend.m_pLeft; - if( m_pWriterListeners == &rDepend ) - m_pWriterListeners = pL ? pL : pR; - - if( pL ) - pL->m_pRight = pR; - if( pR ) - pR->m_pLeft = pL; - - // update ClientIterators - if(sw::ClientIteratorBase::s_pClientIters) - { - for(auto& rIter : sw::ClientIteratorBase::s_pClientIters->GetRingContainer()) - { - if (&rIter.m_rRoot == this && - (rIter.m_pCurrent == &rDepend || rIter.m_pPosition == &rDepend)) - { - // if object being removed is the current or next object in an - // iterator, advance this iterator - rIter.m_pPosition = pR; - } - } - } - rDepend.m_pLeft = nullptr; - rDepend.m_pRight = nullptr; - rDepend.m_pRegisteredIn = nullptr; -} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/inc/fmthdft.hxx b/sw/inc/fmthdft.hxx index 2a0c48eb3f32..731e46b490b2 100644 --- a/sw/inc/fmthdft.hxx +++ b/sw/inc/fmthdft.hxx @@ -25,16 +25,12 @@ #include "calbck.hxx" #include "frmfmt.hxx" -namespace sw { - typedef ClientBase<::SwFrameFormat> FrameFormatClient; -} - class IntlWrapper; /** Header, for PageFormats Client of FrameFormat describing the header. */ -class SW_DLLPUBLIC SwFormatHeader final : public SfxPoolItem, public sw::FrameFormatClient +class SW_DLLPUBLIC SwFormatHeader final : public SfxPoolItem, public SwClient { bool m_bActive; ///< Only for controlling (creation of content). @@ -55,10 +51,10 @@ public: OUString &rText, const IntlWrapper& rIntl ) const override; - const SwFrameFormat *GetHeaderFormat() const { return GetRegisteredIn(); } - SwFrameFormat *GetHeaderFormat() { return GetRegisteredIn(); } + const SwFrameFormat *GetHeaderFormat() const { return static_cast<const SwFrameFormat*>(GetRegisteredIn()); } + SwFrameFormat *GetHeaderFormat() { return static_cast<SwFrameFormat*>(GetRegisteredIn()); } - void RegisterToFormat( SwFrameFormat& rFormat ); + void RegisterToFormat( SwFormat& rFormat ); bool IsActive() const { return m_bActive; } void dumpAsXml(xmlTextWriterPtr pWriter) const override; }; @@ -66,7 +62,7 @@ public: /**Footer, for pageformats Client of FrameFormat describing the footer */ -class SW_DLLPUBLIC SwFormatFooter final : public SfxPoolItem, public sw::FrameFormatClient +class SW_DLLPUBLIC SwFormatFooter final : public SfxPoolItem, public SwClient { bool m_bActive; // Only for controlling (creation of content). @@ -87,8 +83,8 @@ public: OUString &rText, const IntlWrapper& rIntl ) const override; - const SwFrameFormat *GetFooterFormat() const { return GetRegisteredIn(); } - SwFrameFormat *GetFooterFormat() { return GetRegisteredIn(); } + const SwFrameFormat *GetFooterFormat() const { return static_cast<const SwFrameFormat*>(GetRegisteredIn()); } + SwFrameFormat *GetFooterFormat() { return static_cast<SwFrameFormat*>(GetRegisteredIn()); } void RegisterToFormat( SwFormat& rFormat ); bool IsActive() const { return m_bActive; } diff --git a/sw/inc/ring.hxx b/sw/inc/ring.hxx index f9ee213fc6e8..194ed47db10b 100644 --- a/sw/inc/ring.hxx +++ b/sw/inc/ring.hxx @@ -19,7 +19,6 @@ #ifndef INCLUDED_SW_INC_RING_HXX #define INCLUDED_SW_INC_RING_HXX -#include <cassert> #include <utility> #include <sal/types.h> #include <iterator> diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index b7b552a885a4..e4a1f437cef7 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -20,7 +20,6 @@ #include <algorithm> #include <format.hxx> -#include <frmfmt.hxx> #include <hintids.hxx> #include <hints.hxx> #include <osl/diagnose.h> @@ -56,8 +55,7 @@ namespace sw sw::LegacyModifyHint::~LegacyModifyHint() {} -template<typename T> -sw::ClientBase<T>::ClientBase(sw::ClientBase<T>&& o) noexcept +SwClient::SwClient(SwClient&& o) noexcept : m_pRegisteredIn(nullptr) { if(o.m_pRegisteredIn) @@ -67,8 +65,7 @@ sw::ClientBase<T>::ClientBase(sw::ClientBase<T>&& o) noexcept } } -template<typename T> -sw::ClientBase<T>::~ClientBase() +SwClient::~SwClient() { if(GetRegisteredIn()) DBG_TESTSOLARMUTEX(); @@ -77,8 +74,7 @@ sw::ClientBase<T>::~ClientBase() m_pRegisteredIn->Remove(*this); } -template<typename T> -std::optional<sw::ModifyChangedHint> sw::ClientBase<T>::CheckRegistration( const SfxPoolItem* pOld ) +std::optional<sw::ModifyChangedHint> SwClient::CheckRegistration( const SfxPoolItem* pOld ) { DBG_TESTSOLARMUTEX(); // this method only handles notification about dying SwModify objects @@ -108,8 +104,7 @@ std::optional<sw::ModifyChangedHint> sw::ClientBase<T>::CheckRegistration( const return sw::ModifyChangedHint(pAbove); } -template<typename T> -void sw::ClientBase<T>::CheckRegistrationFormat(SwFormat& rOld) +void SwClient::CheckRegistrationFormat(SwFormat& rOld) { assert(GetRegisteredIn() == &rOld); auto pNew = rOld.DerivedFrom(); @@ -120,8 +115,7 @@ void sw::ClientBase<T>::CheckRegistrationFormat(SwFormat& rOld) SwClientNotify(rOld, aHint); } -template<typename T> -void sw::ClientBase<T>::SwClientNotify(const SwModify&, const SfxHint& rHint) +void SwClient::SwClientNotify(const SwModify&, const SfxHint& rHint) { if (rHint.GetId() != SfxHintId::SwLegacyModify) return; @@ -129,8 +123,7 @@ void sw::ClientBase<T>::SwClientNotify(const SwModify&, const SfxHint& rHint) CheckRegistration(pLegacyHint->m_pOld); }; -template<typename T> -void sw::ClientBase<T>::StartListeningToSameModifyAs(const sw::ClientBase<T>& other) +void SwClient::StartListeningToSameModifyAs(const SwClient& other) { if(other.m_pRegisteredIn) other.m_pRegisteredIn->Add(*this); @@ -138,8 +131,7 @@ void sw::ClientBase<T>::StartListeningToSameModifyAs(const sw::ClientBase<T>& ot EndListeningAll(); } -template<typename T> -void sw::ClientBase<T>::EndListeningAll() +void SwClient::EndListeningAll() { if(m_pRegisteredIn) m_pRegisteredIn->Remove(*this); @@ -175,6 +167,85 @@ bool SwModify::GetInfo( SwFindNearestNode& rInfo ) const return true; } +void SwModify::Add(SwClient& rDepend) +{ + DBG_TESTSOLARMUTEX(); +#ifdef DBG_UTIL + // You should not EVER use SwModify directly in new code: + // - Preexisting SwModifys should only ever be used via sw::BroadcastingModify. + // This includes sw::BroadcastMixin, which is the long-term target (without + // SwModify). + // - New classes should use sw::BroadcastMixin alone. + if(!dynamic_cast<sw::BroadcastingModify*>(this)) + { + auto pBT = sal::backtrace_get(20); + SAL_WARN("sw.core", "Modify that is not broadcasting used! " << sal::backtrace_to_string(pBT.get())); + } +#endif + + if (rDepend.m_pRegisteredIn == this) + return; + + // deregister new client in case it is already registered elsewhere + if( rDepend.m_pRegisteredIn != nullptr ) + rDepend.m_pRegisteredIn->Remove(rDepend); + + if( !m_pWriterListeners ) + { + // first client added + m_pWriterListeners = &rDepend; + m_pWriterListeners->m_pLeft = nullptr; + m_pWriterListeners->m_pRight = nullptr; + } + else + { + // append client + rDepend.m_pRight = m_pWriterListeners->m_pRight; + m_pWriterListeners->m_pRight = &rDepend; + rDepend.m_pLeft = m_pWriterListeners; + if( rDepend.m_pRight ) + rDepend.m_pRight->m_pLeft = &rDepend; + } + + // connect client to me + rDepend.m_pRegisteredIn = this; +} + +void SwModify::Remove(SwClient& rDepend) +{ + DBG_TESTSOLARMUTEX(); + assert(rDepend.m_pRegisteredIn == this); + + // SwClient is my listener + // remove it from my list + ::sw::WriterListener* pR = rDepend.m_pRight; + ::sw::WriterListener* pL = rDepend.m_pLeft; + if( m_pWriterListeners == &rDepend ) + m_pWriterListeners = pL ? pL : pR; + + if( pL ) + pL->m_pRight = pR; + if( pR ) + pR->m_pLeft = pL; + + // update ClientIterators + if(sw::ClientIteratorBase::s_pClientIters) + { + for(auto& rIter : sw::ClientIteratorBase::s_pClientIters->GetRingContainer()) + { + if (&rIter.m_rRoot == this && + (rIter.m_pCurrent == &rDepend || rIter.m_pPosition == &rDepend)) + { + // if object being removed is the current or next object in an + // iterator, advance this iterator + rIter.m_pPosition = pR; + } + } + } + rDepend.m_pLeft = nullptr; + rDepend.m_pRight = nullptr; + rDepend.m_pRegisteredIn = nullptr; +} sw::WriterMultiListener::WriterMultiListener(SwClient& rToTell) : m_rToTell(rToTell) @@ -238,22 +309,6 @@ void SwModify::CallSwClientNotify( const SfxHint& rHint ) const pClient->SwClientNotify( *this, rHint ); } -void SwModify::EnsureBroadcasting() -{ -#ifdef DBG_UTIL - // You should not EVER use SwModify directly in new code: - // - Preexisting SwModifys should only ever be used via sw::BroadcastingModify. - // This includes sw::BroadcastMixin, which is the long-term target (without - // SwModify). - // - New classes should use sw::BroadcastMixin alone. - if(!dynamic_cast<sw::BroadcastingModify*>(this)) - { - auto pBT = sal::backtrace_get(20); - SAL_WARN("sw.core", "Modify that is not broadcasting used! " << sal::backtrace_to_string(pBT.get())); - } -#endif -} - void sw::BroadcastingModify::CallSwClientNotify(const SfxHint& rHint) const { SwModify::CallSwClientNotify(rHint); @@ -267,7 +322,4 @@ void sw::ClientNotifyAttrChg(SwModify& rModify, const SwAttrSet& aSet, SwAttrSet const sw::LegacyModifyHint aHint(&aChgOld, &aChgNew); rModify.SwClientNotify(rModify, aHint); } - -template class sw::ClientBase<SwModify>; -template class sw::ClientBase<SwFrameFormat>; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/doc/docdesc.cxx b/sw/source/core/doc/docdesc.cxx index 04c318cdbff1..b03a3558baca 100644 --- a/sw/source/core/doc/docdesc.cxx +++ b/sw/source/core/doc/docdesc.cxx @@ -458,7 +458,7 @@ void SwDoc::ChgPageDesc( size_t i, const SwPageDesc &rChged ) rDesc.GetLeft().ResetFormatAttr(RES_FOOTER); rDesc.GetFirstLeft().ResetFormatAttr(RES_FOOTER); - auto lDelHFFormat = [this](sw::ClientBase<SwFrameFormat>* pToRemove, SwFrameFormat* pFormat) + auto lDelHFFormat = [this](SwClient* pToRemove, SwFrameFormat* pFormat) { // Code taken from lcl_DelHFFormat pFormat->Remove(*pToRemove); diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx index 98f41721d89b..937b30d74e7e 100644 --- a/sw/source/core/layout/atrfrm.cxx +++ b/sw/source/core/layout/atrfrm.cxx @@ -134,10 +134,8 @@ bool GetAtPageRelOrientation(sal_Int16 & rOrientation, bool const isIgnorePrintA } } - } // namespace sw - SfxPoolItem* SwFormatLineNumber::CreateDefault() { return new SwFormatLineNumber; } static sal_Int16 lcl_IntToRelation(const uno::Any& rVal) @@ -148,7 +146,7 @@ static sal_Int16 lcl_IntToRelation(const uno::Any& rVal) return nVal; } -static void lcl_DelHFFormat( sw::FrameFormatClient *pToRemove, SwFrameFormat *pFormat ) +static void lcl_DelHFFormat( SwClient *pToRemove, SwFrameFormat *pFormat ) { //If the client is the last one who uses this format, then we have to delete //it - before this is done, we may need to delete the content-section. @@ -511,21 +509,21 @@ sal_uInt16 SwFormatFillOrder::GetValueCount() const // Partially implemented inline in hxx SwFormatHeader::SwFormatHeader( SwFrameFormat *pHeaderFormat ) : SfxPoolItem( RES_HEADER, SfxItemType::SwFormatHeaderType ), - sw::FrameFormatClient( pHeaderFormat ), + SwClient( pHeaderFormat ), m_bActive( pHeaderFormat ) { } SwFormatHeader::SwFormatHeader( const SwFormatHeader &rCpy ) : SfxPoolItem( RES_HEADER, SfxItemType::SwFormatHeaderType ), - sw::FrameFormatClient( const_cast<SwFrameFormat*>(rCpy.GetRegisteredIn()) ), + SwClient( const_cast<sw::BroadcastingModify*>(static_cast<const sw::BroadcastingModify*>(rCpy.GetRegisteredIn())) ), m_bActive( rCpy.IsActive() ) { } SwFormatHeader::SwFormatHeader( bool bOn ) : SfxPoolItem( RES_HEADER, SfxItemType::SwFormatHeaderType ), - sw::FrameFormatClient( nullptr ), + SwClient( nullptr ), m_bActive( bOn ) { } @@ -548,7 +546,7 @@ SwFormatHeader* SwFormatHeader::Clone( SfxItemPool* ) const return new SwFormatHeader( *this ); } -void SwFormatHeader::RegisterToFormat( SwFrameFormat& rFormat ) +void SwFormatHeader::RegisterToFormat( SwFormat& rFormat ) { rFormat.Add(*this); } @@ -570,21 +568,21 @@ void SwFormatHeader::dumpAsXml(xmlTextWriterPtr pWriter) const // Partially implemented inline in hxx SwFormatFooter::SwFormatFooter( SwFrameFormat *pFooterFormat ) : SfxPoolItem( RES_FOOTER, SfxItemType::SwFormatFooterType ), - sw::FrameFormatClient( pFooterFormat ), + SwClient( pFooterFormat ), m_bActive( pFooterFormat ) { } SwFormatFooter::SwFormatFooter( const SwFormatFooter &rCpy ) : SfxPoolItem( RES_FOOTER, SfxItemType::SwFormatFooterType ), - sw::FrameFormatClient( const_cast<SwFrameFormat*>(rCpy.GetRegisteredIn()) ), + SwClient( const_cast<sw::BroadcastingModify*>(static_cast<const sw::BroadcastingModify*>(rCpy.GetRegisteredIn())) ), m_bActive( rCpy.IsActive() ) { } SwFormatFooter::SwFormatFooter( bool bOn ) : SfxPoolItem( RES_FOOTER, SfxItemType::SwFormatFooterType ), - sw::FrameFormatClient( nullptr ), + SwClient( nullptr ), m_bActive( bOn ) { } commit bea1ab84b2492e72579aeaf82c91ba40c2556479 Author: Stephan Bergmann <stephan.bergm...@allotropia.de> AuthorDate: Wed Jan 8 09:17:30 2025 +0100 Commit: Stephan Bergmann <stephan.bergm...@allotropia.de> CommitDate: Wed Jan 8 12:48:40 2025 +0100 Revert "convert RES_ATTRSET_CHG to SfxHint" This reverts commit 404fbec25740406e3b926844f3bd0f324dc38b8c. Reason for revert: It's follow-up fix bbb53997c3a6890567ee991aed8502b397dcb7a6 "fix ubsan failure" had to be reverted (because it conflicted with a revert of cc56bf56e170492e414a975ad8c07c41ed72e1a4 "convert RES_OBJECTDYING to SfxHint", which in turn is known broken and thus needed to be reverted for now), so revert this known-broken commit for now as well. Change-Id: I4e65c7113e1e5bfdb9841c98bee3712a1beb12ae Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179941 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de> diff --git a/include/svl/hint.hxx b/include/svl/hint.hxx index 0b4c626306b5..48fc8b616dd7 100644 --- a/include/svl/hint.hxx +++ b/include/svl/hint.hxx @@ -232,7 +232,6 @@ enum class SfxHintId { SwRemoveUnoObject, SwHiddenParaPrint, SwFormatChange, - SwAttrSetChange, ThisIsAnSdrHint, ThisIsAnSfxEventHint diff --git a/sw/inc/fmtcol.hxx b/sw/inc/fmtcol.hxx index a966e84049ea..d5cbb8e5842f 100644 --- a/sw/inc/fmtcol.hxx +++ b/sw/inc/fmtcol.hxx @@ -148,6 +148,7 @@ public: switch(nWhich) { case RES_OBJECTDYING: + case RES_ATTRSET_CHG: m_bInSwFntCache = false; } } diff --git a/sw/inc/hintids.hxx b/sw/inc/hintids.hxx index fab0a027a0aa..3d2ae2730c53 100644 --- a/sw/inc/hintids.hxx +++ b/sw/inc/hintids.hxx @@ -30,6 +30,7 @@ class SfxStringItem; class SwFormatChg; class SwUpdateAttr; +class SwAttrSetChg; class SwFormatMeta; class SwFormatContentControl; class SvXMLAttrContainerItem; @@ -429,8 +430,7 @@ inline constexpr sal_uInt16 RES_FORMAT_MSG_BEGIN(RES_FMT_END); inline constexpr TypedWhichId<SwPtrMsgPoolItem> RES_OBJECTDYING(RES_FORMAT_MSG_BEGIN); // 167 inline constexpr sal_uInt16 RES_UPDATEATTR_FMT_CHG( 168); // used by SwUpdateAttr just as an ID to communicate what has changed -inline constexpr sal_uInt16 RES_UPDATEATTR_ATTRSET_CHG( - 169); // used by SwUpdateAttr just as an ID to communicate what has changed +inline constexpr TypedWhichId<SwAttrSetChg> RES_ATTRSET_CHG(169); inline constexpr TypedWhichId<SwUpdateAttr> RES_UPDATE_ATTR(170); // empty inline constexpr sal_uInt16 RES_FORMAT_MSG_END(190); diff --git a/sw/inc/hints.hxx b/sw/inc/hints.hxx index 90eb881012d8..a1d4984b3fb0 100644 --- a/sw/inc/hints.hxx +++ b/sw/inc/hints.hxx @@ -40,7 +40,6 @@ class SwTableBoxFormat; class SwTableLine; class SwTableLineFormat; class SwTableBox; -class SwAttrSetChg; // Base class for all Message-Hints: // "Overhead" of SfxPoolItem is handled here @@ -320,14 +319,7 @@ class PrintHiddenParaHint final : public SfxHint public: PrintHiddenParaHint() : SfxHint(SfxHintId::SwHiddenParaPrint) {} }; -class AttrSetChangeHint final : public SfxHint -{ -public: - const SwAttrSetChg* m_pOld; - const SwAttrSetChg* m_pNew; - AttrSetChangeHint(const SwAttrSetChg* pOld, const SwAttrSetChg* pNew) : SfxHint(SfxHintId::SwAttrSetChange), m_pOld(pOld), m_pNew(pNew) {} -}; -} // namespace sw +} class SwUpdateAttr final : public SwMsgPoolItem { @@ -391,7 +383,7 @@ public: * SwAttrSetChg is sent when something has changed in the SwAttrSet rTheChgdSet. * 2 Hints are always sent, the old and the new items in the rTheChgdSet. */ -class SwAttrSetChg final +class SwAttrSetChg final : public SwMsgPoolItem { bool m_bDelSet; SwAttrSet* m_pChgSet; ///< what has changed @@ -399,7 +391,7 @@ class SwAttrSetChg final public: SwAttrSetChg( const SwAttrSet& rTheSet, SwAttrSet& rSet ); SwAttrSetChg( const SwAttrSetChg& ); - ~SwAttrSetChg(); + virtual ~SwAttrSetChg() override; /// What has changed const SwAttrSet* GetChgSet() const { return m_pChgSet; } diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx index 6e667e30be2c..30951a7d56bd 100644 --- a/sw/inc/ndtxt.hxx +++ b/sw/inc/ndtxt.hxx @@ -73,7 +73,6 @@ class SwFormatChangeHint; namespace sw { class TextNodeNotificationSuppressor; class RemoveUnoObjectHint; - class AttrSetChangeHint; namespace mark { enum class RestoreMode; } } @@ -244,7 +243,6 @@ public: void UpdateDocPos(const SwTwips nDocPos, const sal_uInt32 nIndex); /// for hanging TextFormatCollections somewhere else (Outline-Numbering!) void TriggerNodeUpdate(const sw::LegacyModifyHint&); - void TriggerNodeUpdate(const sw::AttrSetChangeHint&); void TriggerNodeUpdate(const sw::RemoveUnoObjectHint&); void TriggerNodeUpdate(const SwFormatChangeHint&); diff --git a/sw/inc/swevent.hxx b/sw/inc/swevent.hxx index 10d110bca664..d6d79d72a9b7 100644 --- a/sw/inc/swevent.hxx +++ b/sw/inc/swevent.hxx @@ -122,23 +122,24 @@ struct SwCallMouseEvent final SwClient::SwClientNotify(rMod, rHint); if (!GetRegisteredIn() || static_cast<const sw::RemoveUnoObjectHint&>(rHint).m_pObject == PTR.pFormat) Clear(); + return; } - else if(SfxHintId::SwFormatChange == rHint.GetId()) + if(SfxHintId::SwFormatChange == rHint.GetId()) { auto pChgHint = static_cast<const SwFormatChangeHint*>(&rHint); assert(EVENT_OBJECT_IMAGE == eType || EVENT_OBJECT_URLITEM == eType || EVENT_OBJECT_IMAGEMAP == eType); SwClient::SwClientNotify(rMod, rHint); if (!GetRegisteredIn() || pChgHint->m_pOldFormat == PTR.pFormat) Clear(); + return; } - else if (rHint.GetId() == SfxHintId::SwLegacyModify || SfxHintId::SwAttrSetChange == rHint.GetId()) - { - assert(EVENT_OBJECT_IMAGE == eType || EVENT_OBJECT_URLITEM == eType || EVENT_OBJECT_IMAGEMAP == eType); - SwClient::SwClientNotify(rMod, rHint); - bool bClear = !GetRegisteredIn(); - if(bClear) - Clear(); - } + if (rHint.GetId() != SfxHintId::SwLegacyModify) + return; + assert(EVENT_OBJECT_IMAGE == eType || EVENT_OBJECT_URLITEM == eType || EVENT_OBJECT_IMAGEMAP == eType); + SwClient::SwClientNotify(rMod, rHint); + bool bClear = !GetRegisteredIn(); + if(bClear) + Clear(); } }; diff --git a/sw/inc/txtatr.hxx b/sw/inc/txtatr.hxx index 15ed54683e14..e96ea4fbe40d 100644 --- a/sw/inc/txtatr.hxx +++ b/sw/inc/txtatr.hxx @@ -45,7 +45,6 @@ public: void TriggerNodeUpdate(const sw::LegacyModifyHint&); void TriggerNodeUpdate(const SwFormatChangeHint&); - void TriggerNodeUpdate(const sw::AttrSetChangeHint&); // get and set TextNode pointer void ChgTextNode( SwTextNode* pNew ) { m_pTextNode = pNew; } diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx index 4f6be8ff159e..abfce2412516 100644 --- a/sw/qa/core/uwriter.cxx +++ b/sw/qa/core/uwriter.cxx @@ -1681,8 +1681,6 @@ namespace ++m_nNotifyCount; else if(dynamic_cast<const sw::LegacyModifyHint*>(&rHint)) ++m_nModifyCount; - else if(dynamic_cast<const sw::AttrSetChangeHint*>(&rHint)) - ++m_nModifyCount; else if(auto pModifyChangedHint = dynamic_cast<const sw::ModifyChangedHint*>(&rHint)) { ++m_nModifyChangedCount; @@ -1698,8 +1696,6 @@ namespace { if(dynamic_cast<const sw::LegacyModifyHint*>(&rHint)) ++m_nModifyCount; - else if(dynamic_cast<const sw::AttrSetChangeHint*>(&rHint)) - ++m_nModifyCount; } }; struct TestListener : SvtListener diff --git a/sw/source/core/attr/BorderCacheOwner.cxx b/sw/source/core/attr/BorderCacheOwner.cxx index 8673e57389b4..9f9c56144927 100644 --- a/sw/source/core/attr/BorderCacheOwner.cxx +++ b/sw/source/core/attr/BorderCacheOwner.cxx @@ -26,6 +26,7 @@ void BorderCacheOwner::InvalidateInSwCache(const sal_uInt16 nWhich) switch (nWhich) { case RES_OBJECTDYING: + case RES_ATTRSET_CHG: case RES_UL_SPACE: case RES_MARGIN_FIRSTLINE: case RES_MARGIN_TEXTLEFT: diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index 0351ea76b75f..b7b552a885a4 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -218,9 +218,7 @@ sw::ClientIteratorBase* sw::ClientIteratorBase::s_pClientIters = nullptr; void SwModify::SwClientNotify(const SwModify&, const SfxHint& rHint) { - if (rHint.GetId() != SfxHintId::SwLegacyModify - && rHint.GetId() != SfxHintId::SwRemoveUnoObject - && rHint.GetId() != SfxHintId::SwAttrSetChange) + if (rHint.GetId() != SfxHintId::SwLegacyModify && rHint.GetId() != SfxHintId::SwRemoveUnoObject && rHint.GetId() != SfxHintId::SwRemoveUnoObject) return; DBG_TESTSOLARMUTEX(); @@ -266,7 +264,7 @@ void sw::ClientNotifyAttrChg(SwModify& rModify, const SwAttrSet& aSet, SwAttrSet { const SwAttrSetChg aChgOld(aSet, aOld); const SwAttrSetChg aChgNew(aSet, aNew); - const sw::AttrSetChangeHint aHint(&aChgOld, &aChgNew); + const sw::LegacyModifyHint aHint(&aChgOld, &aChgNew); rModify.SwClientNotify(rModify, aHint); } diff --git a/sw/source/core/attr/format.cxx b/sw/source/core/attr/format.cxx index 1ec609f0748d..5c4683a07897 100644 --- a/sw/source/core/attr/format.cxx +++ b/sw/source/core/attr/format.cxx @@ -171,7 +171,7 @@ void SwFormat::CopyAttrs( const SwFormat& rFormat ) SwAttrSetChg aChgOld( m_aSet, aOld ); SwAttrSetChg aChgNew( m_aSet, aNew ); - SwClientNotify(*this, sw::AttrSetChangeHint(&aChgOld, &aChgNew)); // send all modified ones + SwClientNotify(*this, sw::LegacyModifyHint(&aChgOld, &aChgNew)); // send all modified ones } } @@ -234,36 +234,6 @@ void SwFormat::SwClientNotify(const SwModify&, const SfxHint& rHint) SwModify::SwClientNotify(*this, rHint); return; } - if (rHint.GetId() == SfxHintId::SwAttrSetChange) - { - auto pChangeHint = static_cast<const sw::AttrSetChangeHint*>(&rHint); - std::optional<SwAttrSetChg> oOldClientChg, oNewClientChg; - std::optional<sw::AttrSetChangeHint> oDependsHint(std::in_place, pChangeHint->m_pOld, pChangeHint->m_pNew); - InvalidateInSwCache(); - // NB: this still notifies depends even if this condition is not met, which seems non-obvious - auto pOldAttrSetChg = pChangeHint->m_pOld; - auto pNewAttrSetChg = pChangeHint->m_pNew; - if (pOldAttrSetChg && pNewAttrSetChg && pOldAttrSetChg->GetTheChgdSet() != &m_aSet) - { - // pass only those that are not set... - oNewClientChg.emplace(*pNewAttrSetChg); - oNewClientChg->GetChgSet()->Differentiate(m_aSet); - if(oNewClientChg->Count()) // ... if any - { - oOldClientChg.emplace(*pOldAttrSetChg); - oOldClientChg->GetChgSet()->Differentiate(m_aSet); - oDependsHint.emplace(&*oOldClientChg, &*oNewClientChg); - } - else - oDependsHint.reset(); - } - if(oDependsHint) - { - InvalidateInSwFntCache(); - SwModify::SwClientNotify(*this, *oDependsHint); - } - return; - } if (rHint.GetId() != SfxHintId::SwLegacyModify) return; auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); @@ -303,6 +273,27 @@ void SwFormat::SwClientNotify(const SwModify&, const SfxHint& rHint) } break; } + case RES_ATTRSET_CHG: + { + // NB: this still notifies depends even if this condition is not met, which seems non-obvious + auto pOldAttrSetChg = static_cast<const SwAttrSetChg*>(pLegacy->m_pOld); + auto pNewAttrSetChg = static_cast<const SwAttrSetChg*>(pLegacy->m_pNew); + if (pOldAttrSetChg && pNewAttrSetChg && pOldAttrSetChg->GetTheChgdSet() != &m_aSet) + { + // pass only those that are not set... + oNewClientChg.emplace(*pNewAttrSetChg); + oNewClientChg->GetChgSet()->Differentiate(m_aSet); + if(oNewClientChg->Count()) // ... if any + { + oOldClientChg.emplace(*pOldAttrSetChg); + oOldClientChg->GetChgSet()->Differentiate(m_aSet); + oDependsHint.emplace(&*oOldClientChg, &*oNewClientChg); + } + else + oDependsHint.reset(); + } + break; + } default: // attribute is defined in this format if(SfxItemState::SET == m_aSet.GetItemState(nWhich, false)) diff --git a/sw/source/core/attr/hints.cxx b/sw/source/core/attr/hints.cxx index cc41d18a5ea5..c75930ea76a5 100644 --- a/sw/source/core/attr/hints.cxx +++ b/sw/source/core/attr/hints.cxx @@ -85,14 +85,16 @@ SwTableFormulaUpdate::SwTableFormulaUpdate(const SwTable* pNewTable) } SwAttrSetChg::SwAttrSetChg( const SwAttrSet& rTheSet, SwAttrSet& rSet ) - : m_bDelSet( false ), + : SwMsgPoolItem( RES_ATTRSET_CHG ), + m_bDelSet( false ), m_pChgSet( &rSet ), m_pTheChgdSet( &rTheSet ) { } SwAttrSetChg::SwAttrSetChg( const SwAttrSetChg& rChgSet ) - : m_bDelSet( true ), + : SwMsgPoolItem( RES_ATTRSET_CHG ), + m_bDelSet( true ), m_pTheChgdSet( rChgSet.m_pTheChgdSet ) { m_pChgSet = new SwAttrSet( *rChgSet.m_pChgSet ); diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx index 162185339c47..89000ff283f4 100644 --- a/sw/source/core/crsr/crsrsh.cxx +++ b/sw/source/core/crsr/crsrsh.cxx @@ -2907,7 +2907,7 @@ void SwCursorShell::SwClientNotify(const SwModify&, const SfxHint& rHint) m_aGrfArrivedLnk.Call(*this); return; } - if (rHint.GetId() == SfxHintId::SwFormatChange || rHint.GetId() == SfxHintId::SwAttrSetChange) + if (rHint.GetId() == SfxHintId::SwFormatChange) { if( m_bCallChgLnk ) // messages are not forwarded @@ -2925,7 +2925,8 @@ void SwCursorShell::SwClientNotify(const SwModify&, const SfxHint& rHint) nWhich = RES_OBJECTDYING; if( m_bCallChgLnk && ( !isFormatMessage(nWhich) - || nWhich == RES_UPDATE_ATTR )) + || nWhich == RES_UPDATE_ATTR + || nWhich == RES_ATTRSET_CHG )) // messages are not forwarded // #i6681#: RES_UPDATE_ATTR is implicitly unset in // SwTextNode::Insert(SwTextHint*, sal_uInt16); we react here and thus do @@ -2935,6 +2936,7 @@ void SwCursorShell::SwClientNotify(const SwModify&, const SfxHint& rHint) { EndListeningAll(); } + } /** Does the current cursor create a selection? diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx index 2ef3dfd0c104..4945c9f948e8 100644 --- a/sw/source/core/doc/docfmt.cxx +++ b/sw/source/core/doc/docfmt.cxx @@ -662,7 +662,7 @@ void SwDoc::SetDefault( const SfxItemSet& rSet ) { SwAttrSetChg aChgOld( aOld, aOld ); SwAttrSetChg aChgNew( aNew, aNew ); - aCallMod.CallSwClientNotify(sw::AttrSetChangeHint( &aChgOld, &aChgNew )); // all changed are sent + aCallMod.CallSwClientNotify(sw::LegacyModifyHint( &aChgOld, &aChgNew )); // all changed are sent } // remove the default formats from the object again diff --git a/sw/source/core/doc/docftn.cxx b/sw/source/core/doc/docftn.cxx index b829b051248d..cbce97a20fbb 100644 --- a/sw/source/core/doc/docftn.cxx +++ b/sw/source/core/doc/docftn.cxx @@ -249,9 +249,16 @@ void SwEndNoteInfo::SwClientNotify( const SwModify& rModify, const SfxHint& rHin if (rHint.GetId() == SfxHintId::SwLegacyModify) { auto pLegacyHint = static_cast<const sw::LegacyModifyHint*>(&rHint); - CheckRegistration( pLegacyHint->m_pOld ); + switch(pLegacyHint->GetWhich()) + { + case RES_ATTRSET_CHG: + UpdateFormatOrAttr(); + break; + default: + CheckRegistration( pLegacyHint->m_pOld ); + } } - else if (rHint.GetId() == SfxHintId::SwFormatChange || rHint.GetId() == SfxHintId::SwAttrSetChange) + else if (rHint.GetId() == SfxHintId::SwFormatChange) { UpdateFormatOrAttr(); } diff --git a/sw/source/core/doc/fmtcol.cxx b/sw/source/core/doc/fmtcol.cxx index cb3ad58e1277..daecd6760bd6 100644 --- a/sw/source/core/doc/fmtcol.cxx +++ b/sw/source/core/doc/fmtcol.cxx @@ -139,8 +139,7 @@ void SwTextFormatColl::SwClientNotify(const SwModify& rModify, const SfxHint& rH CallSwClientNotify(rHint); return; } - else if (rHint.GetId() != SfxHintId::SwLegacyModify && rHint.GetId() != SfxHintId::SwFormatChange - && rHint.GetId() != SfxHintId::SwAttrSetChange) + else if (rHint.GetId() != SfxHintId::SwLegacyModify && rHint.GetId() != SfxHintId::SwFormatChange) return; if(GetDoc()->IsInDtor()) { @@ -161,9 +160,30 @@ void SwTextFormatColl::SwClientNotify(const SwModify& rModify, const SfxHint& rH { auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); const auto pNew = pLegacy->m_pNew; + const SwAttrSetChg *pNewChgSet = nullptr; switch( pLegacy->GetWhich() ) { + case RES_ATTRSET_CHG: + // Only recalculate if we're not the sender! + pNewChgSet = &pNew->StaticWhichCast(RES_ATTRSET_CHG); + pNewFirstLineIndent = pNewChgSet->GetChgSet()->GetItemIfSet(RES_MARGIN_FIRSTLINE, false); + pNewTextLeftMargin = pNewChgSet->GetChgSet()->GetItemIfSet(RES_MARGIN_TEXTLEFT, false); + pNewRightMargin = pNewChgSet->GetChgSet()->GetItemIfSet(RES_MARGIN_RIGHT, false); + pNewULSpace = pNewChgSet->GetChgSet()->GetItemIfSet( RES_UL_SPACE, false ); + aFontSizeArr[0] = pNewChgSet->GetChgSet()->GetItemIfSet( RES_CHRATR_FONTSIZE, false ); + aFontSizeArr[1] = pNewChgSet->GetChgSet()->GetItemIfSet( RES_CHRATR_CJK_FONTSIZE, false ); + aFontSizeArr[2] = pNewChgSet->GetChgSet()->GetItemIfSet( RES_CHRATR_CTL_FONTSIZE, false ); + // #i70223#, #i84745# + // check, if attribute set is applied to this paragraph style + if ( bAssignedToListLevelOfOutlineStyle && + pNewChgSet->GetTheChgdSet() == &GetAttrSet() ) + { + pNewNumRuleItem = pNewChgSet->GetChgSet()->GetItemIfSet( RES_PARATR_NUMRULE, false ); + } + + break; + case RES_MARGIN_FIRSTLINE: pNewFirstLineIndent = &pNew->StaticWhichCast(RES_MARGIN_FIRSTLINE); break; @@ -196,27 +216,6 @@ void SwTextFormatColl::SwClientNotify(const SwModify& rModify, const SfxHint& rH break; } } - else if (rHint.GetId() == SfxHintId::SwAttrSetChange) - { - auto pChangeHint = static_cast<const sw::AttrSetChangeHint*>(&rHint); - const SwAttrSetChg *pNewChgSet = pChangeHint->m_pNew; - - // Only recalculate if we're not the sender! - pNewFirstLineIndent = pNewChgSet->GetChgSet()->GetItemIfSet(RES_MARGIN_FIRSTLINE, false); - pNewTextLeftMargin = pNewChgSet->GetChgSet()->GetItemIfSet(RES_MARGIN_TEXTLEFT, false); - pNewRightMargin = pNewChgSet->GetChgSet()->GetItemIfSet(RES_MARGIN_RIGHT, false); - pNewULSpace = pNewChgSet->GetChgSet()->GetItemIfSet( RES_UL_SPACE, false ); - aFontSizeArr[0] = pNewChgSet->GetChgSet()->GetItemIfSet( RES_CHRATR_FONTSIZE, false ); - aFontSizeArr[1] = pNewChgSet->GetChgSet()->GetItemIfSet( RES_CHRATR_CJK_FONTSIZE, false ); - aFontSizeArr[2] = pNewChgSet->GetChgSet()->GetItemIfSet( RES_CHRATR_CTL_FONTSIZE, false ); - // #i70223#, #i84745# - // check, if attribute set is applied to this paragraph style - if ( bAssignedToListLevelOfOutlineStyle && - pNewChgSet->GetTheChgdSet() == &GetAttrSet() ) - { - pNewNumRuleItem = pNewChgSet->GetChgSet()->GetItemIfSet( RES_PARATR_NUMRULE, false ); - } - } else // rHint.GetId() == SfxHintId::SwFormatChange { if( GetAttrSet().GetParent() ) @@ -364,13 +363,12 @@ void SwTextFormatColl::SwClientNotify(const SwModify& rModify, const SfxHint& rH // if the parent changed, we can't know how many properties are involved: always notify a change if (rHint.GetId() == SfxHintId::SwLegacyModify) { - if (bNewParent || !nNoNotify) - SwFormatColl::SwClientNotify(rModify, rHint); - } - else if (rHint.GetId() == SfxHintId::SwAttrSetChange) - { - auto pChangeHint = static_cast<const sw::AttrSetChangeHint*>(&rHint); - const SwAttrSetChg *pOldChgSet = pChangeHint->m_pOld; + auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); + const auto pOld = pLegacy->m_pOld; + const SwAttrSetChg *pOldChgSet = nullptr; + + if( pLegacy->GetWhich() == RES_ATTRSET_CHG) + pOldChgSet = &pOld->StaticWhichCast(RES_ATTRSET_CHG); if (bNewParent || !nNoNotify || (pOldChgSet && pOldChgSet->GetChgSet()->Count() > nNoNotify)) SwFormatColl::SwClientNotify(rModify, rHint); diff --git a/sw/source/core/doc/lineinfo.cxx b/sw/source/core/doc/lineinfo.cxx index 8cc455b0aa82..af2094fd0c75 100644 --- a/sw/source/core/doc/lineinfo.cxx +++ b/sw/source/core/doc/lineinfo.cxx @@ -114,9 +114,7 @@ void SwLineNumberInfo::SetCharFormat( SwCharFormat *pChFormat ) void SwLineNumberInfo::SwClientNotify(const SwModify&, const SfxHint& rHint) { - if (rHint.GetId() != SfxHintId::SwLegacyModify - && rHint.GetId() != SfxHintId::SwFormatChange - && rHint.GetId() != SfxHintId::SwAttrSetChange) + if (rHint.GetId() != SfxHintId::SwLegacyModify && rHint.GetId() != SfxHintId::SwFormatChange) return; if (rHint.GetId() == SfxHintId::SwLegacyModify) { diff --git a/sw/source/core/doc/notxtfrm.cxx b/sw/source/core/doc/notxtfrm.cxx index affd0d7388ff..a0a992982a4b 100644 --- a/sw/source/core/doc/notxtfrm.cxx +++ b/sw/source/core/doc/notxtfrm.cxx @@ -756,97 +756,95 @@ void SwNoTextFrame::SwClientNotify(const SwModify& rModify, const SfxHint& rHint InvalidatePrt(); SetCompletePaint(); } + return; } - else if(rHint.GetId() == SfxHintId::SwPreGraphicArrived + if(rHint.GetId() == SfxHintId::SwPreGraphicArrived || rHint.GetId() == SfxHintId::SwGraphicPieceArrived || rHint.GetId() == SfxHintId::SwLinkedGraphicStreamArrived) { OnGraphicArrived(); + return; } else if (rHint.GetId() == SfxHintId::SwFormatChange) { ClearCache(); InvalidatePrt(); SetCompletePaint(); + return; } - else if (rHint.GetId() == SfxHintId::SwAttrSetChange) + else if (rHint.GetId() != SfxHintId::SwLegacyModify) + return; + auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); + sal_uInt16 nWhich = pLegacy->GetWhich(); + + SwContentFrame::SwClientNotify(rModify, rHint); + + switch( nWhich ) { - auto pChangeHint = static_cast<const sw::AttrSetChangeHint*>(&rHint); - SwContentFrame::SwClientNotify(rModify, rHint); + case RES_OBJECTDYING: + break; - sal_uInt16 n; - for( n = RES_GRFATR_BEGIN; n < RES_GRFATR_END; ++n ) - if( SfxItemState::SET == pChangeHint->m_pOld->GetChgSet()-> - GetItemState( n, false )) - { - ClearCache(); + case RES_UPDATE_ATTR: + if (GetNode()->GetNodeType() != SwNodeType::Grf) { + break; + } + ClearCache(); + break; - if(RES_GRFATR_ROTATION == n) + case RES_ATTRSET_CHG: + { + sal_uInt16 n; + for( n = RES_GRFATR_BEGIN; n < RES_GRFATR_END; ++n ) + if( SfxItemState::SET == static_cast<const SwAttrSetChg*>(pLegacy->m_pOld)->GetChgSet()-> + GetItemState( n, false )) { - // RotGrfFlyFrame: Update Handles in view, these may be rotation-dependent - // (e.g. crop handles) and need a visualisation update - if ( GetNode()->GetNodeType() == SwNodeType::Grf ) - { - SwGrfNode* pNd = static_cast<SwGrfNode*>( GetNode()); - SwViewShell *pVSh = pNd->GetDoc().getIDocumentLayoutAccess().GetCurrentViewShell(); + ClearCache(); - if(pVSh) + if(RES_GRFATR_ROTATION == n) + { + // RotGrfFlyFrame: Update Handles in view, these may be rotation-dependent + // (e.g. crop handles) and need a visualisation update + if ( GetNode()->GetNodeType() == SwNodeType::Grf ) { - SdrView* pDrawView = pVSh->GetDrawView(); + SwGrfNode* pNd = static_cast<SwGrfNode*>( GetNode()); + SwViewShell *pVSh = pNd->GetDoc().getIDocumentLayoutAccess().GetCurrentViewShell(); - if(pDrawView) + if(pVSh) { - pDrawView->AdjustMarkHdl(nullptr); + SdrView* pDrawView = pVSh->GetDrawView(); + + if(pDrawView) + { + pDrawView->AdjustMarkHdl(nullptr); + } } - } - // RotateFlyFrame3 - invalidate needed for ContentFrame (inner, this) - // and LayoutFrame (outer, GetUpper). It is possible to only invalidate - // the outer frame, but that leads to an in-between state that gets - // potentially painted - if(GetUpper()) - { - GetUpper()->InvalidateAll_(); - } + // RotateFlyFrame3 - invalidate needed for ContentFrame (inner, this) + // and LayoutFrame (outer, GetUpper). It is possible to only invalidate + // the outer frame, but that leads to an in-between state that gets + // potentially painted + if(GetUpper()) + { + GetUpper()->InvalidateAll_(); + } - InvalidateAll_(); + InvalidateAll_(); + } } + break; } - break; - } - if( RES_GRFATR_END == n ) // not found - return ; - - InvalidatePrt(); - SetCompletePaint(); - } - else if (rHint.GetId() == SfxHintId::SwLegacyModify) - { - auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); - sal_uInt16 nWhich = pLegacy->GetWhich(); - - SwContentFrame::SwClientNotify(rModify, rHint); - - switch( nWhich ) - { - case RES_OBJECTDYING: - break; - - case RES_UPDATE_ATTR: - if (GetNode()->GetNodeType() != SwNodeType::Grf) { - break; - } - ClearCache(); - break; - - default: - if ( !pLegacy->m_pNew || !isGRFATR(nWhich) ) - return; + if( RES_GRFATR_END == n ) // not found + return ; } + break; - InvalidatePrt(); - SetCompletePaint(); + default: + if ( !pLegacy->m_pNew || !isGRFATR(nWhich) ) + return; } + + InvalidatePrt(); + SetCompletePaint(); } static void lcl_correctlyAlignRect( SwRect& rAlignedGrfArea, const SwRect& rInArea, vcl::RenderContext const * pOut ) diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx index 5708fdbf1cb2..f8fc67f0dab7 100644 --- a/sw/source/core/doc/number.cxx +++ b/sw/source/core/doc/number.cxx @@ -308,20 +308,23 @@ void SwNumFormat::SwClientNotify(const SwModify&, const SfxHint& rHint) UpdateNumNodes(*const_cast<SwDoc*>(pFormat->GetDoc())); return; } - if (rHint.GetId() == SfxHintId::SwAttrSetChange) - { - // Look for the NumRules object in the Doc where this NumFormat is set. - // The format does not need to exist! - const SwCharFormat* pFormat = GetCharFormat(); - - if(pFormat && !pFormat->GetDoc()->IsInDtor()) - UpdateNumNodes(*const_cast<SwDoc*>(pFormat->GetDoc())); - return; - } if (rHint.GetId() != SfxHintId::SwLegacyModify) return; auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); - CheckRegistration(pLegacy->m_pOld); + // Look for the NumRules object in the Doc where this NumFormat is set. + // The format does not need to exist! + const SwCharFormat* pFormat = nullptr; + switch(pLegacy->GetWhich()) + { + case RES_ATTRSET_CHG: + pFormat = GetCharFormat(); + break; + } + + if(pFormat && !pFormat->GetDoc()->IsInDtor()) + UpdateNumNodes(*const_cast<SwDoc*>(pFormat->GetDoc())); + else + CheckRegistration(pLegacy->m_pOld); } OUString SwNumFormat::GetCharFormatName() const diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx index a78d72477b45..054176a7682a 100644 --- a/sw/source/core/docnode/node.cxx +++ b/sw/source/core/docnode/node.cxx @@ -1103,7 +1103,7 @@ void SwContentNode::UpdateAttr(const SwUpdateAttr& rUpdate) { if (GetNodes().IsDocNodes() && IsTextNode() - && RES_UPDATEATTR_ATTRSET_CHG == rUpdate.getWhichAttr()) + && RES_ATTRSET_CHG == rUpdate.getWhichAttr()) static_cast<SwTextNode*>(this)->SetCalcHiddenCharFlags(); CallSwClientNotify(sw::LegacyModifyHint(&rUpdate, &rUpdate)); } @@ -1130,23 +1130,13 @@ void SwContentNode::SwClientNotify( const SwModify&, const SfxHint& rHint) AttrSetHandleHelper::SetParent(mpAttrSet, *this, pFormatColl, pFormatColl); CallSwClientNotify(rHint); } - else if (rHint.GetId() == SfxHintId::SwAttrSetChange) - { - auto pChangeHint = static_cast<const sw::AttrSetChangeHint*>(&rHint); - InvalidateInSwCache(); - if (GetNodes().IsDocNodes() - && IsTextNode() - && pChangeHint->m_pOld - && SfxItemState::SET == pChangeHint->m_pOld->GetChgSet()->GetItemState(RES_CHRATR_HIDDEN, false)) - static_cast<SwTextNode*>(this)->SetCalcHiddenCharFlags(); - CallSwClientNotify(rHint); - } else if (rHint.GetId() == SfxHintId::SwLegacyModify) { auto pLegacyHint = static_cast<const sw::LegacyModifyHint*>(&rHint); const sal_uInt16 nWhich = pLegacyHint->GetWhich(); InvalidateInSwCache(nWhich); + bool bCalcHidden = false; switch(nWhich) { case RES_OBJECTDYING: @@ -1165,6 +1155,14 @@ void SwContentNode::SwClientNotify( const SwModify&, const SfxHint& rHint) } break; + case RES_ATTRSET_CHG: + if (GetNodes().IsDocNodes() + && IsTextNode() + && pLegacyHint->m_pOld + && SfxItemState::SET == pLegacyHint->m_pOld->StaticWhichCast(RES_ATTRSET_CHG).GetChgSet()->GetItemState(RES_CHRATR_HIDDEN, false)) + bCalcHidden = true; + break; + case RES_UPDATE_ATTR: // RES_UPDATE_ATTR _should_ always contain a SwUpdateAttr hint in old and new. // However, faking one with just a basic SfxPoolItem setting a WhichId has been observed. @@ -1185,6 +1183,8 @@ void SwContentNode::SwClientNotify( const SwModify&, const SfxHint& rHint) UpdateAttr(rUpdateAttr); return; } + if(bCalcHidden) + static_cast<SwTextNode*>(this)->SetCalcHiddenCharFlags(); CallSwClientNotify(rHint); } else if (rHint.GetId() == SfxHintId::SwAutoFormatUsedHint) diff --git a/sw/source/core/docnode/section.cxx b/sw/source/core/docnode/section.cxx index 9d82953715a1..fbb00098e1e9 100644 --- a/sw/source/core/docnode/section.cxx +++ b/sw/source/core/docnode/section.cxx @@ -403,63 +403,19 @@ void SwSection::Notify(SfxHint const& rHint) auto rSectionHidden = static_cast<const sw::SectionHidden&>(rHint); m_Data.SetHiddenFlag(rSectionHidden.m_isHidden || (m_Data.IsHidden() && m_Data.IsCondHidden())); return; - } else if (rHint.GetId() != SfxHintId::SwLegacyModify && rHint.GetId() != SfxHintId::SwAttrSetChange) + } else if (rHint.GetId() != SfxHintId::SwLegacyModify) return; - + auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); + auto pOld = pLegacy->m_pOld; + auto pNew = pLegacy->m_pNew; bool bUpdateFootnote = false; - if (rHint.GetId() == SfxHintId::SwLegacyModify) - { - auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); - auto pOld = pLegacy->m_pOld; - auto pNew = pLegacy->m_pNew; - switch(pLegacy->GetWhich()) - { - case RES_PROTECT: - if( pNew ) - { - bool bNewFlag = - static_cast<const SvxProtectItem*>(pNew)->IsContentProtected(); - // this used to inherit the flag from the parent, but then there is - // no way to turn it off in an inner section - m_Data.SetProtectFlag( bNewFlag ); - } - return; - // edit in readonly sections - case RES_EDIT_IN_READONLY: - if( pNew ) - { - const bool bNewFlag = - static_cast<const SwFormatEditInReadonly*>(pNew)->GetValue(); - m_Data.SetEditInReadonlyFlag( bNewFlag ); - } - return; - - case RES_COL: - // Is handled by the Layout, if appropriate - break; - - case RES_FTN_AT_TXTEND: - case RES_END_AT_TXTEND: - if( pNew && pOld ) - { - bUpdateFootnote = true; - } - break; - - default: - CheckRegistration( pOld ); - break; - } - } - else // rHint.GetId() == SfxHintId::SwAttrSetChange + switch(pLegacy->GetWhich()) { - auto pChangeHint = static_cast<const sw::AttrSetChangeHint*>(&rHint); - const SwAttrSetChg* pOld = pChangeHint->m_pOld; - const SwAttrSetChg* pNew = pChangeHint->m_pNew; + case RES_ATTRSET_CHG: if (pNew && pOld) { - SfxItemSet* pNewSet = const_cast<SwAttrSetChg*>(pNew)->GetChgSet(); - SfxItemSet* pOldSet = const_cast<SwAttrSetChg*>(pOld)->GetChgSet(); + SfxItemSet* pNewSet = const_cast<SwAttrSetChg*>(static_cast<const SwAttrSetChg*>(pNew))->GetChgSet(); + SfxItemSet* pOldSet = const_cast<SwAttrSetChg*>(static_cast<const SwAttrSetChg*>(pOld))->GetChgSet(); if( const SvxProtectItem* pItem = pNewSet->GetItemIfSet( RES_PROTECT, false ) ) @@ -489,6 +445,43 @@ void SwSection::Notify(SfxHint const& rHint) if( !pNewSet->Count() ) return; } + break; + + case RES_PROTECT: + if( pNew ) + { + bool bNewFlag = + static_cast<const SvxProtectItem*>(pNew)->IsContentProtected(); + // this used to inherit the flag from the parent, but then there is + // no way to turn it off in an inner section + m_Data.SetProtectFlag( bNewFlag ); + } + return; + // edit in readonly sections + case RES_EDIT_IN_READONLY: + if( pNew ) + { + const bool bNewFlag = + static_cast<const SwFormatEditInReadonly*>(pNew)->GetValue(); + m_Data.SetEditInReadonlyFlag( bNewFlag ); + } + return; + + case RES_COL: + // Is handled by the Layout, if appropriate + break; + + case RES_FTN_AT_TXTEND: + case RES_END_AT_TXTEND: + if( pNew && pOld ) + { + bUpdateFootnote = true; + } + break; + + default: + CheckRegistration( pOld ); + break; } if( bUpdateFootnote ) @@ -734,15 +727,19 @@ void SwSectionFormat::SwClientNotify(const SwModify& rMod, const SfxHint& rHint) SwFrameFormat::SwClientNotify(rMod, rHint); return; } - else if (rHint.GetId() == SfxHintId::SwAttrSetChange) + else if (rHint.GetId() != SfxHintId::SwLegacyModify) + return; + auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); + sal_uInt16 nWhich = pLegacy->GetWhich(); + auto pOld = pLegacy->m_pOld; + auto pNew = pLegacy->m_pNew; + switch( nWhich ) { - auto pChangeHint = static_cast<const sw::AttrSetChangeHint*>(&rHint); - const SwAttrSetChg* pOld = pChangeHint->m_pOld; - const SwAttrSetChg* pNew = pChangeHint->m_pNew; + case RES_ATTRSET_CHG: if (HasWriterListeners() && pOld && pNew) { - SfxItemSet* pNewSet = const_cast<SwAttrSetChg*>(pNew)->GetChgSet(); - SfxItemSet* pOldSet = const_cast<SwAttrSetChg*>(pOld)->GetChgSet(); + SfxItemSet* pNewSet = const_cast<SwAttrSetChg*>(static_cast<const SwAttrSetChg*>(pNew))->GetChgSet(); + SfxItemSet* pOldSet = const_cast<SwAttrSetChg*>(static_cast<const SwAttrSetChg*>(pOld))->GetChgSet(); const SfxPoolItem *pItem; if( SfxItemState::SET == pNewSet->GetItemState( RES_PROTECT, false, &pItem )) @@ -775,19 +772,11 @@ void SwSectionFormat::SwClientNotify(const SwModify& rMod, const SfxHint& rHint) pNewSet->ClearItem( RES_END_AT_TXTEND ); pOldSet->ClearItem( RES_END_AT_TXTEND ); } - if( !pOld->GetChgSet()->Count() ) + if( !static_cast<const SwAttrSetChg*>(pOld)->GetChgSet()->Count() ) return; } - SwFrameFormat::SwClientNotify(rMod, rHint); - } - else if (rHint.GetId() != SfxHintId::SwLegacyModify) - return; - auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); - sal_uInt16 nWhich = pLegacy->GetWhich(); - auto pOld = pLegacy->m_pOld; - auto pNew = pLegacy->m_pNew; - switch( nWhich ) - { + break; + case RES_FTN_AT_TXTEND: case RES_END_AT_TXTEND: case RES_PROTECT: diff --git a/sw/source/core/draw/dcontact.cxx b/sw/source/core/draw/dcontact.cxx index 63dbcae0373c..74edb2d3051a 100644 --- a/sw/source/core/draw/dcontact.cxx +++ b/sw/source/core/draw/dcontact.cxx @@ -1398,16 +1398,17 @@ namespace { sal_uInt16 nWhich = _rItem.Which(); const SwFormatAnchor* pAnchorFormat = nullptr; - if ( RES_ANCHOR == nWhich ) + if ( RES_ATTRSET_CHG == nWhich ) + { + pAnchorFormat = static_cast<const SwAttrSetChg&>(_rItem).GetChgSet()-> + GetItemIfSet( RES_ANCHOR, false ); + } + else if ( RES_ANCHOR == nWhich ) { pAnchorFormat = &static_cast<const SwFormatAnchor&>(_rItem); } return pAnchorFormat; } - const SwFormatAnchor* lcl_getAnchorFormat( const SwAttrSetChg& _rItem ) - { - return _rItem.GetChgSet()->GetItemIfSet( RES_ANCHOR, false ); - } } void SwDrawContact::SwClientNotify(const SwModify& rMod, const SfxHint& rHint) @@ -1425,30 +1426,14 @@ void SwDrawContact::SwClientNotify(const SwModify& rMod, const SfxHint& rHint) // #i51474# GetAnchoredObj(nullptr)->ResetLayoutProcessBools(); } - else if (rHint.GetId() == SfxHintId::SwLegacyModify || rHint.GetId() == SfxHintId::SwAttrSetChange) + else if (rHint.GetId() == SfxHintId::SwLegacyModify) { + auto pLegacyHint = static_cast<const sw::LegacyModifyHint*>(&rHint); SAL_WARN_IF(mbDisconnectInProgress, "sw.core", "<SwDrawContact::Modify(..)> called during disconnection."); - const SwFormatAnchor* pNewAnchorFormat = nullptr; - const SwFormatAnchor* pOldAnchorFormat = nullptr; - if (rHint.GetId() == SfxHintId::SwLegacyModify) - { - auto pLegacyHint = static_cast<const sw::LegacyModifyHint*>(&rHint); - if (pLegacyHint->m_pNew) - pNewAnchorFormat = lcl_getAnchorFormat(*pLegacyHint->m_pNew); - if (pLegacyHint->m_pOld) - pOldAnchorFormat = lcl_getAnchorFormat(*pLegacyHint->m_pOld); - } - else // rHint.GetId() == SfxHintId::SwAttrSetChange) - { - auto pChangeHint = static_cast<const sw::AttrSetChangeHint*>(&rHint); - if (pChangeHint->m_pNew) - pNewAnchorFormat = lcl_getAnchorFormat(*pChangeHint->m_pNew); - if (pChangeHint->m_pOld) - pOldAnchorFormat = lcl_getAnchorFormat(*pChangeHint->m_pOld); - } - - if(pNewAnchorFormat) + const SfxPoolItem* pNew = pLegacyHint->m_pNew; + sal_uInt16 nWhich = pNew ? pNew->Which() : 0; + if(const SwFormatAnchor* pNewAnchorFormat = pNew ? lcl_getAnchorFormat(*pNew) : nullptr) { // Do not respond to a Reset Anchor! if(GetFormat()->GetAttrSet().GetItemState(RES_ANCHOR, false) == SfxItemState::SET) @@ -1473,6 +1458,7 @@ void SwDrawContact::SwClientNotify(const SwModify& rMod, const SfxHint& rHint) lcl_NotifyBackgroundOfObj(*this, *GetMaster(), pOldRect); NotifyBackgroundOfAllVirtObjs(pOldRect); + const SwFormatAnchor* pOldAnchorFormat = pLegacyHint->m_pOld ? lcl_getAnchorFormat(*pLegacyHint->m_pOld) : nullptr; if(!pOldAnchorFormat || (pOldAnchorFormat->GetAnchorId() != pNewAnchorFormat->GetAnchorId())) { if(maAnchoredDrawObj.DrawObj()) @@ -1494,40 +1480,34 @@ void SwDrawContact::SwClientNotify(const SwModify& rMod, const SfxHint& rHint) maAnchoredDrawObj.GetDrawObj()->GetUserCall() ) { bool bUpdateSortedObjsList(false); - if (rHint.GetId() == SfxHintId::SwLegacyModify) + switch(nWhich) { - auto pLegacyHint = static_cast<const sw::LegacyModifyHint*>(&rHint); - sal_uInt16 nWhich = pLegacyHint->m_pNew ? pLegacyHint->m_pNew->Which() : 0; - switch(nWhich) + case RES_UL_SPACE: + case RES_LR_SPACE: + case RES_HORI_ORIENT: + case RES_VERT_ORIENT: + case RES_FOLLOW_TEXT_FLOW: // #i28701# - add attribute 'Follow text flow' + break; + case RES_SURROUND: + case RES_OPAQUE: + case RES_WRAP_INFLUENCE_ON_OBJPOS: + // --> #i28701# - on change of wrapping style, hell|heaven layer, + // or wrapping style influence an update of the <SwSortedObjs> list, + // the drawing object is registered in, has to be performed. This is triggered + // by the 1st parameter of method call <InvalidateObjs_(..)>. + bUpdateSortedObjsList = true; + break; + case RES_ATTRSET_CHG: // #i35443# { - case RES_UL_SPACE: - case RES_LR_SPACE: - case RES_HORI_ORIENT: - case RES_VERT_ORIENT: - case RES_FOLLOW_TEXT_FLOW: // #i28701# - add attribute 'Follow text flow' - break; - case RES_SURROUND: - case RES_OPAQUE: - case RES_WRAP_INFLUENCE_ON_OBJPOS: - // --> #i28701# - on change of wrapping style, hell|heaven layer, - // or wrapping style influence an update of the <SwSortedObjs> list, - // the drawing object is registered in, has to be performed. This is triggered - // by the 1st parameter of method call <InvalidateObjs_(..)>. + auto pChgSet = static_cast<const SwAttrSetChg*>(pNew)->GetChgSet(); + if(pChgSet->GetItemState(RES_SURROUND, false) == SfxItemState::SET || + pChgSet->GetItemState(RES_OPAQUE, false) == SfxItemState::SET || + pChgSet->GetItemState(RES_WRAP_INFLUENCE_ON_OBJPOS, false) == SfxItemState::SET) bUpdateSortedObjsList = true; - break; - default: - assert(!"<SwDraw Contact::Modify(..)> - unhandled attribute?"); } - } - else // rHint.GetId() == SfxHintId::SwAttrSetChange) - { - // #i35443# - auto pChangeHint = static_cast<const sw::AttrSetChangeHint*>(&rHint); - auto pChgSet = pChangeHint->m_pNew->GetChgSet(); - if(pChgSet->GetItemState(RES_SURROUND, false) == SfxItemState::SET || - pChgSet->GetItemState(RES_OPAQUE, false) == SfxItemState::SET || - pChgSet->GetItemState(RES_WRAP_INFLUENCE_ON_OBJPOS, false) == SfxItemState::SET) - bUpdateSortedObjsList = true; + break; + default: + assert(!"<SwDraw Contact::Modify(..)> - unhandled attribute?"); } lcl_NotifyBackgroundOfObj(*this, *GetMaster(), nullptr); NotifyBackgroundOfAllVirtObjs(nullptr); diff --git a/sw/source/core/fields/ddetbl.cxx b/sw/source/core/fields/ddetbl.cxx index 5987cb3851cd..b990f2d846bc 100644 --- a/sw/source/core/fields/ddetbl.cxx +++ b/sw/source/core/fields/ddetbl.cxx @@ -85,9 +85,7 @@ SwDDETable::~SwDDETable() void SwDDETable::SwClientNotify(const SwModify& rModify, const SfxHint& rHint) { - if (rHint.GetId() == SfxHintId::SwLegacyModify - || rHint.GetId() == SfxHintId::SwAutoFormatUsedHint - || rHint.GetId() == SfxHintId::SwAttrSetChange) + if (rHint.GetId() == SfxHintId::SwLegacyModify || rHint.GetId() == SfxHintId::SwAutoFormatUsedHint) { SwTable::SwClientNotify(rModify, rHint); } diff --git a/sw/source/core/fields/docufld.cxx b/sw/source/core/fields/docufld.cxx index c6ce1a746922..cced5f680276 100644 --- a/sw/source/core/fields/docufld.cxx +++ b/sw/source/core/fields/docufld.cxx @@ -2266,14 +2266,9 @@ void SwRefPageGetFieldType::SwClientNotify(const SwModify&, const SfxHint& rHint CallSwClientNotify(rHint); return; } - if (rHint.GetId() != SfxHintId::SwLegacyModify && rHint.GetId() != SfxHintId::SwAttrSetChange) + if (rHint.GetId() != SfxHintId::SwLegacyModify) return; - const sw::LegacyModifyHint* pLegacy = nullptr; - const sw::AttrSetChangeHint* pChangeHint = nullptr; - if (rHint.GetId() == SfxHintId::SwLegacyModify) - pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); - else // rHint.GetId() == SfxHintId::SwAttrSetChange - pChangeHint = static_cast<const sw::AttrSetChangeHint*>(&rHint); + auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); auto const ModifyImpl = [this](SwRootFrame const*const pLayout) { // first collect all SetPageRefFields @@ -2288,8 +2283,7 @@ void SwRefPageGetFieldType::SwClientNotify(const SwModify&, const SfxHint& rHint }; // update all GetReference fields - if( (pLegacy && !pLegacy->m_pNew && !pLegacy->m_pOld && HasWriterListeners()) - || (!pChangeHint->m_pNew && !pChangeHint->m_pOld && HasWriterListeners())) + if( !pLegacy->m_pNew && !pLegacy->m_pOld && HasWriterListeners() ) { SwRootFrame const* pLayout(nullptr); SwRootFrame const* pLayoutRLHidden(nullptr); diff --git a/sw/source/core/fields/reffld.cxx b/sw/source/core/fields/reffld.cxx index 496aabffedb1..a063586b482f 100644 --- a/sw/source/core/fields/reffld.cxx +++ b/sw/source/core/fields/reffld.cxx @@ -1165,19 +1165,6 @@ void SwGetRefFieldType::SwClientNotify(const SwModify&, const SfxHint& rHint) CallSwClientNotify(rHint); return; } - if (rHint.GetId() == SfxHintId::SwAttrSetChange) - { - auto pChangeHint = static_cast<const sw::AttrSetChangeHint*>(&rHint); - if(!pChangeHint->m_pNew && !pChangeHint->m_pOld) - // update to all GetReference fields - // hopefully, this codepath is soon dead code, and - // UpdateGetReferences gets only called directly - UpdateGetReferences(); - else - // forward to text fields, they "expand" the text - CallSwClientNotify(rHint); - return; - } if (rHint.GetId() != SfxHintId::SwLegacyModify) return; auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); diff --git a/sw/source/core/fields/usrfld.cxx b/sw/source/core/fields/usrfld.cxx index e9b50826c585..9e170b73b261 100644 --- a/sw/source/core/fields/usrfld.cxx +++ b/sw/source/core/fields/usrfld.cxx @@ -223,12 +223,6 @@ void SwUserFieldType::SwClientNotify(const SwModify&, const SfxHint& rHint) if (!pLegacy->m_pOld && !pLegacy->m_pNew) m_bValidValue = false; } - else if (rHint.GetId() == SfxHintId::SwAttrSetChange) - { - auto pChangeHint = static_cast<const sw::AttrSetChangeHint*>(&rHint); - if (!pChangeHint->m_pOld && !pChangeHint->m_pNew) - m_bValidValue = false; - } CallSwClientNotify(rHint); // update input fields that might be connected to the user field diff --git a/sw/source/core/inc/flyfrm.hxx b/sw/source/core/inc/flyfrm.hxx index f599fa86b888..dc1ce0abc3fd 100644 --- a/sw/source/core/inc/flyfrm.hxx +++ b/sw/source/core/inc/flyfrm.hxx @@ -96,7 +96,6 @@ protected: // Predecessor/Successor for chaining with text flow SwFlyFrame *m_pPrevLink, *m_pNextLink; static const SwFormatAnchor* GetAnchorFromPoolItem(const SfxPoolItem& rItem); - static const SwFormatAnchor* GetAnchorFromPoolItem(const SwAttrSetChg& rItem); private: // It must be possible to block Content-bound flys so that they will be not diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx index d67d2e5a4d43..98f41721d89b 100644 --- a/sw/source/core/layout/atrfrm.cxx +++ b/sw/source/core/layout/atrfrm.cxx @@ -2765,73 +2765,77 @@ void SwFrameFormat::SwClientNotify(const SwModify& rMod, const SfxHint& rHint) SwFormat::SwClientNotify(rMod, rHint); return; } - else if (rHint.GetId() != SfxHintId::SwLegacyModify && rHint.GetId() != SfxHintId::SwAttrSetChange) + else if (rHint.GetId() != SfxHintId::SwLegacyModify) return; - + auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); + const sal_uInt16 nNewWhich = pLegacy->m_pNew ? pLegacy->m_pNew->Which() : 0; + const SwAttrSetChg* pNewAttrSetChg = nullptr; const SwFormatHeader* pH = nullptr; const SwFormatFooter* pF = nullptr; SwNode* pNewAnchorNode = nullptr; - SwNode* pOldAnchorNode = nullptr; - if (rHint.GetId() == SfxHintId::SwLegacyModify) + switch(nNewWhich) { - auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); - const sal_uInt16 nNewWhich = pLegacy->m_pNew ? pLegacy->m_pNew->Which() : 0; - switch(nNewWhich) + case RES_ATTRSET_CHG: { - case RES_HEADER: - pH = static_cast<const SwFormatHeader*>(pLegacy->m_pNew); - break; - case RES_FOOTER: - pF = static_cast<const SwFormatFooter*>(pLegacy->m_pNew); - break; - case RES_ANCHOR: - pNewAnchorNode = static_cast<const SwFormatAnchor*>(pLegacy->m_pNew)->GetAnchorNode(); - break; - } - const sal_uInt16 nOldWhich = pLegacy->m_pOld ? pLegacy->m_pOld->Which() : 0; - switch(nOldWhich) - { - case RES_ANCHOR: - pOldAnchorNode = static_cast<const SwFormatAnchor*>(pLegacy->m_pOld)->GetAnchorNode(); - break; - } - assert(nOldWhich == nNewWhich || !nOldWhich || !nNewWhich); - } - else // rHint.GetId() == SfxHintId::SwAttrSetChange - { - auto pChangeHint = static_cast<const sw::AttrSetChangeHint*>(&rHint); - const SwAttrSetChg* pNewAttrSetChg = pChangeHint->m_pNew; - pH = pNewAttrSetChg->GetChgSet()->GetItem(RES_HEADER, false); - pF = pNewAttrSetChg->GetChgSet()->GetItem(RES_FOOTER, false); + pNewAttrSetChg = static_cast<const SwAttrSetChg*>(pLegacy->m_pNew); + pH = pNewAttrSetChg->GetChgSet()->GetItem(RES_HEADER, false); + pF = pNewAttrSetChg->GetChgSet()->GetItem(RES_FOOTER, false); - // reset fill information - if(maFillAttributes && supportsFullDrawingLayerFillAttributeSet()) - { - SfxItemIter aIter(*pNewAttrSetChg->GetChgSet()); - for(const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem()) + // reset fill information + if(maFillAttributes && supportsFullDrawingLayerFillAttributeSet()) { - if(!IsInvalidItem(pItem) && pItem->Which() >= XATTR_FILL_FIRST && pItem->Which() <= XATTR_FILL_LAST) + SfxItemIter aIter(*pNewAttrSetChg->GetChgSet()); + for(const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem()) { - maFillAttributes.reset(); - break; + if(!IsInvalidItem(pItem) && pItem->Which() >= XATTR_FILL_FIRST && pItem->Which() <= XATTR_FILL_LAST) + { + maFillAttributes.reset(); + break; + } } } + const SwFormatAnchor* pAnchor = pNewAttrSetChg->GetChgSet()->GetItem(RES_ANCHOR, false); + if(pAnchor) + { + pNewAnchorNode = pAnchor->GetAnchorNode(); + assert(pNewAnchorNode == nullptr || // style's set must not contain position! + pNewAttrSetChg->GetTheChgdSet() == &m_aSet); + } + break; } - if (const SwFormatAnchor* pAnchor = pNewAttrSetChg->GetChgSet()->GetItem(RES_ANCHOR, false)) - { - pNewAnchorNode = pAnchor->GetAnchorNode(); - assert(pNewAnchorNode == nullptr || // style's set must not contain position! - pNewAttrSetChg->GetTheChgdSet() == &m_aSet); - } - const SwAttrSetChg* pOldAttrSetChg = pChangeHint->m_pOld; - if (const SwFormatAnchor* pAnchor = pOldAttrSetChg->GetChgSet()->GetItem(RES_ANCHOR, false)) + case RES_HEADER: + pH = static_cast<const SwFormatHeader*>(pLegacy->m_pNew); + break; + case RES_FOOTER: + pF = static_cast<const SwFormatFooter*>(pLegacy->m_pNew); + break; + case RES_ANCHOR: + pNewAnchorNode = static_cast<const SwFormatAnchor*>(pLegacy->m_pNew)->GetAnchorNode(); + break; + } + const sal_uInt16 nOldWhich = pLegacy->m_pOld ? pLegacy->m_pOld->Which() : 0; + SwNode* pOldAnchorNode = nullptr; + switch(nOldWhich) + { + case RES_ATTRSET_CHG: { - pOldAnchorNode = pAnchor->GetAnchorNode(); - assert(pOldAnchorNode == nullptr || // style's set must not contain position! - pOldAttrSetChg->GetTheChgdSet() == &m_aSet); + const SwAttrSetChg* pOldAttrSetChg = nullptr; + pOldAttrSetChg = static_cast<const SwAttrSetChg*>(pLegacy->m_pOld); + const SwFormatAnchor* pAnchor = pOldAttrSetChg->GetChgSet()->GetItem(RES_ANCHOR, false); + if(pAnchor) + { + pOldAnchorNode = pAnchor->GetAnchorNode(); + assert(pOldAnchorNode == nullptr || // style's set must not contain position! + pOldAttrSetChg->GetTheChgdSet() == &m_aSet); + } + break; } + case RES_ANCHOR: + pOldAnchorNode = static_cast<const SwFormatAnchor*>(pLegacy->m_pOld)->GetAnchorNode(); + break; } + assert(nOldWhich == nNewWhich || !nOldWhich || !nNewWhich); if(pH && pH->IsActive() && !pH->GetHeaderFormat()) { //If he doesn't have one, I'll add one SwFrameFormat* pFormat = GetDoc()->getIDocumentLayoutAccess().MakeLayoutFormat(RndStdIds::HEADER, nullptr); diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx index 86cac25337de..60317b17ec28 100644 --- a/sw/source/core/layout/fly.cxx +++ b/sw/source/core/layout/fly.cxx @@ -801,8 +801,7 @@ bool SwFlyFrame::FrameSizeChg( const SwFormatFrameSize &rFrameSize ) void SwFlyFrame::SwClientNotify(const SwModify& rMod, const SfxHint& rHint) { if (rHint.GetId() == SfxHintId::SwFormatChange || - rHint.GetId() == SfxHintId::SwLegacyModify || - rHint.GetId() == SfxHintId::SwAttrSetChange) + rHint.GetId() == SfxHintId::SwLegacyModify) { SwFlyFrameInvFlags eInvFlags = SwFlyFrameInvFlags::NONE; if (rHint.GetId() == SfxHintId::SwFormatChange) @@ -810,17 +809,17 @@ void SwFlyFrame::SwClientNotify(const SwModify& rMod, const SfxHint& rHint) auto pChangeHint = static_cast<const SwFormatChangeHint*>(&rHint); UpdateAttrForFormatChange(pChangeHint->m_pOldFormat, pChangeHint->m_pNewFormat, eInvFlags); } - else if (rHint.GetId() == SfxHintId::SwAttrSetChange) + else // rHint.GetId() == SfxHintId::SwLegacyModify { - auto pChangeHint = static_cast<const sw::AttrSetChangeHint*>(&rHint); - if(pChangeHint->m_pNew && pChangeHint->m_pOld) + auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); + if(pLegacy->m_pNew && pLegacy->m_pOld && RES_ATTRSET_CHG == pLegacy->m_pNew->Which()) { - SfxItemIter aNIter(*pChangeHint->m_pNew->GetChgSet()); - SfxItemIter aOIter(*pChangeHint->m_pOld->GetChgSet()); + SfxItemIter aNIter(*static_cast<const SwAttrSetChg*>(pLegacy->m_pNew)->GetChgSet()); + SfxItemIter aOIter(*static_cast<const SwAttrSetChg*>(pLegacy->m_pOld)->GetChgSet()); const SfxPoolItem* pNItem = aNIter.GetCurItem(); const SfxPoolItem* pOItem = aOIter.GetCurItem(); - SwAttrSetChg aOldSet(*pChangeHint->m_pOld); - SwAttrSetChg aNewSet(*pChangeHint->m_pNew); + SwAttrSetChg aOldSet(*static_cast<const SwAttrSetChg*>(pLegacy->m_pOld)); + SwAttrSetChg aNewSet(*static_cast<const SwAttrSetChg*>(pLegacy->m_pNew)); do { UpdateAttr_(pOItem, pNItem, eInvFlags, &aOldSet, &aNewSet); @@ -828,13 +827,10 @@ void SwFlyFrame::SwClientNotify(const SwModify& rMod, const SfxHint& rHint) pOItem = aOIter.NextItem(); } while(pNItem); if(aOldSet.Count() || aNewSet.Count()) - SwLayoutFrame::SwClientNotify(rMod, sw::AttrSetChangeHint(&aOldSet, &aNewSet)); + SwLayoutFrame::SwClientNotify(rMod, sw::LegacyModifyHint(&aOldSet, &aNewSet)); } - } - else // rHint.GetId() == SfxHintId::SwLegacyModify - { - auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); - UpdateAttr_(pLegacy->m_pOld, pLegacy->m_pNew, eInvFlags); + else + UpdateAttr_(pLegacy->m_pOld, pLegacy->m_pNew, eInvFlags); } if(eInvFlags == SwFlyFrameInvFlags::NONE) @@ -3503,6 +3499,8 @@ const SwFormatAnchor* SwFlyFrame::GetAnchorFromPoolItem(const SfxPoolItem& rItem { switch(rItem.Which()) { + case RES_ATTRSET_CHG: + return rItem.StaticWhichCast(RES_ATTRSET_CHG).GetChgSet()->GetItem(RES_ANCHOR, false); case RES_ANCHOR: return static_cast<const SwFormatAnchor*>(&rItem); default: @@ -3510,11 +3508,6 @@ const SwFormatAnchor* SwFlyFrame::GetAnchorFromPoolItem(const SfxPoolItem& rItem } } -const SwFormatAnchor* SwFlyFrame::GetAnchorFromPoolItem(const SwAttrSetChg& rItem) -{ - return rItem.GetChgSet()->GetItem(RES_ANCHOR, false); -} - const SwFlyFrame* SwFlyFrame::DynCastFlyFrame() const { return this; diff --git a/sw/source/core/layout/flycnt.cxx b/sw/source/core/layout/flycnt.cxx index eb34e63caacc..03d95c979f11 100644 --- a/sw/source/core/layout/flycnt.cxx +++ b/sw/source/core/layout/flycnt.cxx @@ -100,22 +100,13 @@ SwFlyAtContentFrame::~SwFlyAtContentFrame() void SwFlyAtContentFrame::SwClientNotify(const SwModify& rMod, const SfxHint& rHint) { - if (rHint.GetId() != SfxHintId::SwLegacyModify && rHint.GetId() != SfxHintId::SwAttrSetChange) + if (rHint.GetId() != SfxHintId::SwLegacyModify) { SwFlyFrame::SwClientNotify(rMod, rHint); return; } - const SwFormatAnchor* pAnch; - if (rHint.GetId() == SfxHintId::SwLegacyModify) - { - auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); - pAnch = pLegacy->m_pNew ? GetAnchorFromPoolItem(*pLegacy->m_pNew) : nullptr; - } - else // rHint.GetId() == SfxHintId::SwAttrSetChange - { - auto pChangeHint = static_cast<const sw::AttrSetChangeHint*>(&rHint); - pAnch = pChangeHint->m_pNew ? GetAnchorFromPoolItem(*pChangeHint->m_pNew) : nullptr; - } + auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); + const SwFormatAnchor* pAnch = pLegacy->m_pNew ? GetAnchorFromPoolItem(*pLegacy->m_pNew) : nullptr; if(!pAnch) { SwFlyFrame::SwClientNotify(rMod, rHint); diff --git a/sw/source/core/layout/flyincnt.cxx b/sw/source/core/layout/flyincnt.cxx index 712ee61884c0..ed249c322bd0 100644 --- a/sw/source/core/layout/flyincnt.cxx +++ b/sw/source/core/layout/flyincnt.cxx @@ -107,44 +107,36 @@ void SwFlyInContentFrame::SwClientNotify(const SwModify& rMod, const SfxHint& rH AnchorFrame()->Prepare(PrepareHint::FlyFrameAttributesChanged, GetFormat()); return; } - if (rHint.GetId() == SfxHintId::SwAttrSetChange) - { - auto pChangeHint = static_cast<const sw::AttrSetChangeHint*>(&rHint); - std::pair<std::unique_ptr<SwAttrSetChg>, std::unique_ptr<SwAttrSetChg>> aTweakedChgs; - std::pair<const SwAttrSetChg*, const SwAttrSetChg*> aSuperArgs(nullptr, nullptr); - const SwAttrSetChg* pOldAttrSetChg = pChangeHint->m_pOld; - const SwAttrSetChg* pNewAttrSetChg = pChangeHint->m_pNew; - if(pOldAttrSetChg - && pNewAttrSetChg - && ((SfxItemState::SET == pNewAttrSetChg->GetChgSet()->GetItemState(RES_SURROUND, false)) - || (SfxItemState::SET == pNewAttrSetChg->GetChgSet()->GetItemState(RES_FRMMACRO, false)))) - { - aTweakedChgs.second = std::make_unique<SwAttrSetChg>(*pOldAttrSetChg); - aTweakedChgs.second->ClearItem(RES_SURROUND); - aTweakedChgs.second->ClearItem(RES_FRMMACRO); - if(aTweakedChgs.second->Count()) - { - aTweakedChgs.first = std::make_unique<SwAttrSetChg>(*pOldAttrSetChg); - aTweakedChgs.first->ClearItem(RES_SURROUND); - aTweakedChgs.first->ClearItem(RES_FRMMACRO); - aSuperArgs = std::pair<const SwAttrSetChg*, const SwAttrSetChg*>(aTweakedChgs.first.get(), aTweakedChgs.second.get()); - } - } else if (pNewAttrSetChg && pNewAttrSetChg->GetChgSet()->Count()) - aSuperArgs = std::pair<const SwAttrSetChg*, const SwAttrSetChg*>(pChangeHint->m_pOld, pChangeHint->m_pNew); - if(aSuperArgs.second) - { - SwFlyFrame::SwClientNotify(rMod, sw::AttrSetChangeHint(aSuperArgs.first, aSuperArgs.second)); - if(GetAnchorFrame()) - AnchorFrame()->Prepare(PrepareHint::FlyFrameAttributesChanged, GetFormat()); - } - return; - } if (rHint.GetId() != SfxHintId::SwLegacyModify) return; auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); + std::pair<std::unique_ptr<SwAttrSetChg>, std::unique_ptr<SwAttrSetChg>> aTweakedChgs; std::pair<const SfxPoolItem*, const SfxPoolItem*> aSuperArgs(nullptr, nullptr); switch(pLegacy->GetWhich()) { + case RES_ATTRSET_CHG: + { + auto pOldAttrSetChg = static_cast<const SwAttrSetChg*>(pLegacy->m_pOld); + auto pNewAttrSetChg = static_cast<const SwAttrSetChg*>(pLegacy->m_pNew); + if(pOldAttrSetChg + && pNewAttrSetChg + && ((SfxItemState::SET == pNewAttrSetChg->GetChgSet()->GetItemState(RES_SURROUND, false)) + || (SfxItemState::SET == pNewAttrSetChg->GetChgSet()->GetItemState(RES_FRMMACRO, false)))) + { + aTweakedChgs.second = std::make_unique<SwAttrSetChg>(*pOldAttrSetChg); + aTweakedChgs.second->ClearItem(RES_SURROUND); + aTweakedChgs.second->ClearItem(RES_FRMMACRO); + if(aTweakedChgs.second->Count()) + { + aTweakedChgs.first = std::make_unique<SwAttrSetChg>(*pOldAttrSetChg); + aTweakedChgs.first->ClearItem(RES_SURROUND); + aTweakedChgs.first->ClearItem(RES_FRMMACRO); + aSuperArgs = std::pair<const SfxPoolItem*, const SfxPoolItem*>(aTweakedChgs.first.get(), aTweakedChgs.second.get()); + } + } else if (pNewAttrSetChg && pNewAttrSetChg->GetChgSet()->Count()) + aSuperArgs = std::pair<const SfxPoolItem*, const SfxPoolItem*>(pLegacy->m_pOld, pLegacy->m_pNew); + break; + } case RES_SURROUND: case RES_FRMMACRO: break; diff --git a/sw/source/core/layout/flylay.cxx b/sw/source/core/layout/flylay.cxx index 51e5a2b87387..f157a80134bf 100644 --- a/sw/source/core/layout/flylay.cxx +++ b/sw/source/core/layout/flylay.cxx @@ -751,24 +751,12 @@ void SwFlyLayFrame::SwClientNotify(const SwModify& rMod, const SfxHint& rHint) SwFlyFrame::SwClientNotify(rMod, rHint); return; } - if (rHint.GetId() != SfxHintId::SwLegacyModify && rHint.GetId() != SfxHintId::SwAttrSetChange) + if (rHint.GetId() != SfxHintId::SwLegacyModify) return; - - const SwFormatAnchor* pAnch; - if (rHint.GetId() == SfxHintId::SwLegacyModify) - { - auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); - if(!pLegacy->m_pNew) - return; - pAnch = GetAnchorFromPoolItem(*pLegacy->m_pNew); - } - else // rHint.GetId() == SfxHintId::SwAttrSetChange - { - auto pChangeHint = static_cast<const sw::AttrSetChangeHint*>(&rHint); - if(!pChangeHint->m_pNew) - return; - pAnch = GetAnchorFromPoolItem(*pChangeHint->m_pNew); - } -e ... etc. - the rest is truncated