summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern Michaelsen <bjoern.michaelsen@libreoffice.org>2018-05-10 10:51:42 +0200
committerBjörn Michaelsen <bjoern.michaelsen@libreoffice.org>2018-05-12 10:17:33 +0200
commit74b0602a82a8599fab52d6f58d18d0f39946280d (patch)
tree73099229c842ee6d251901f67f2f61c565b19f4b
parent8484e52675052848d2d3ffe07378ce2ad29fd288 (diff)
dont use SwClient/SwModify in unocore: Section
Change-Id: Ic594c5129664b309ce1b6ddd0c715a17df5a3265 Reviewed-on: https://gerrit.libreoffice.org/54091 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Björn Michaelsen <bjoern.michaelsen@libreoffice.org>
-rw-r--r--sw/inc/calbck.hxx14
-rw-r--r--sw/inc/section.hxx1
-rw-r--r--sw/source/core/unocore/unosect.cxx52
3 files changed, 43 insertions, 24 deletions
diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx
index 9f809ea24dbd..595a3deab14d 100644
--- a/sw/inc/calbck.hxx
+++ b/sw/inc/calbck.hxx
@@ -21,6 +21,7 @@
#define INCLUDED_SW_INC_CALBCK_HXX
#include <svl/hint.hxx>
+#include <svl/broadcast.hxx>
#include <svl/poolitem.hxx>
#include "swdllapi.h"
#include "ring.hxx"
@@ -71,6 +72,19 @@ namespace sw
virtual ~ModifyChangedHint() override;
const SwModify* m_pNew;
};
+ // Observer pattern using svl implementation
+ // use this instead of SwClient/SwModify whereever possible
+ // In writer layout, this might not always be possible,
+ // but for listeners outside of it (e.g. unocore) this should be used.
+ // The only "magic" signal this class issues is a ModifyChangedHint
+ // proclaiming its death. It does NOT however provide a new SwModify for
+ // listeners to switch to like the old SwModify/SwClient did, as that leads
+ // to madness.
+ class SW_DLLPUBLIC BroadcasterMixin {
+ SvtBroadcaster m_aNotifier;
+ public:
+ SvtBroadcaster& GetNotifier() { return m_aNotifier; }
+ };
/// refactoring out the some of the more sane SwClient functionality
class SW_DLLPUBLIC WriterListener
{
diff --git a/sw/inc/section.hxx b/sw/inc/section.hxx
index 30b582b89a80..eb4cc6913f38 100644
--- a/sw/inc/section.hxx
+++ b/sw/inc/section.hxx
@@ -270,6 +270,7 @@ enum class SectionSort { Not, Pos };
class SW_DLLPUBLIC SwSectionFormat
: public SwFrameFormat
, public ::sfx2::Metadatable
+ , public sw::BroadcasterMixin
{
friend class SwDoc;
diff --git a/sw/source/core/unocore/unosect.cxx b/sw/source/core/unocore/unosect.cxx
index ec5197cbbfcd..188299134f04 100644
--- a/sw/source/core/unocore/unosect.cxx
+++ b/sw/source/core/unocore/unosect.cxx
@@ -29,6 +29,7 @@
#include <cmdid.h>
#include <hintids.hxx>
#include <svl/urihelper.hxx>
+#include <svl/listener.hxx>
#include <editeng/brushitem.hxx>
#include <editeng/xmlcnitm.hxx>
#include <sfx2/linkmgr.hxx>
@@ -100,7 +101,7 @@ struct SwTextSectionProperties_Impl
};
class SwXTextSection::Impl
- : public SwClient
+ : public SvtListener
{
private:
::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper2
@@ -114,25 +115,33 @@ public:
bool m_bIsDescriptor;
OUString m_sName;
std::unique_ptr<SwTextSectionProperties_Impl> m_pProps;
+ SwSectionFormat* m_pFormat;
- Impl( SwXTextSection & rThis,
- SwSectionFormat *const pFormat, const bool bIndexHeader)
- : SwClient(pFormat)
+ Impl( SwXTextSection& rThis,
+ SwSectionFormat* const pFormat, const bool bIndexHeader)
+ : SvtListener()
, m_rThis(rThis)
, m_rPropSet(*aSwMapProvider.GetPropertySet(PROPERTY_MAP_SECTION))
, m_EventListeners(m_Mutex)
, m_bIndexHeader(bIndexHeader)
, m_bIsDescriptor(nullptr == pFormat)
, m_pProps(pFormat ? nullptr : new SwTextSectionProperties_Impl())
+ , m_pFormat(pFormat)
{
+ if(m_pFormat)
+ StartListening(m_pFormat->GetNotifier());
}
- SwSectionFormat * GetSectionFormat() const
+ void Attach(SwSectionFormat* pFormat)
{
- return static_cast<SwSectionFormat*>(const_cast<SwModify*>(
- GetRegisteredIn()));
+ EndListeningAll();
+ StartListening(pFormat->GetNotifier());
+ m_pFormat = pFormat;
}
+ SwSectionFormat* GetSectionFormat() const
+ { return m_pFormat; }
+
SwSectionFormat & GetSectionFormatOrThrow() const {
SwSectionFormat *const pFormat( GetSectionFormat() );
if (!pFormat) {
@@ -155,27 +164,22 @@ public:
uno::Sequence< uno::Any >
GetPropertyValues_Impl(
const uno::Sequence< OUString >& rPropertyNames);
-protected:
- // SwClient
- virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override;
-
+ virtual void Notify(const SfxHint& rHint) override;
};
-void SwXTextSection::Impl::Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew)
+void SwXTextSection::Impl::Notify(const SfxHint& rHint)
{
- ClientModify(this, pOld, pNew);
- if (GetRegisteredIn())
+ if(rHint.GetId() == SfxHintId::Dying)
{
- return; // core object still alive
- }
-
- uno::Reference<uno::XInterface> const xThis(m_wThis);
- if (!xThis.is())
- { // fdo#72695: if UNO object is already dead, don't revive it with event
- return;
+ m_pFormat = nullptr;
+ uno::Reference<uno::XInterface> const xThis(m_wThis);
+ if (!xThis.is())
+ { // fdo#72695: if UNO object is already dead, don't revive it with event
+ return;
+ }
+ lang::EventObject const ev(xThis);
+ m_EventListeners.disposeAndClear(ev);
}
- lang::EventObject const ev(xThis);
- m_EventListeners.disposeAndClear(ev);
}
SwSectionFormat * SwXTextSection::GetFormat() const
@@ -407,7 +411,7 @@ SwXTextSection::attach(const uno::Reference< text::XTextRange > & xTextRange)
"SwXTextSection::attach(): invalid TextRange",
static_cast< ::cppu::OWeakObject*>(this), 0);
}
- pRet->GetFormat()->Add(m_pImpl.get());
+ m_pImpl->Attach(pRet->GetFormat());
pRet->GetFormat()->SetXObject(static_cast< ::cppu::OWeakObject*>(this));
// XML import must hide sections depending on their old