summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern Michaelsen <bjoern.michaelsen@libreoffice.org>2018-01-31 01:13:53 +0100
committerBjoern Michaelsen <bjoern.michaelsen@libreoffice.org>2018-01-31 01:13:53 +0100
commit2993749708e0e31c37e267c1c6d339c27cc697ed (patch)
tree6d9c83c696ddd26bd4ceb04dc4b3fd73fbea1cc7
parent5e6608e1d55a423dd9d309d68a6e5c03b29a934f (diff)
intermediate: unoob2.cxx
-rw-r--r--sw/inc/calbck.hxx6
-rw-r--r--sw/inc/swtblfmt.hxx2
-rw-r--r--sw/inc/unotextrange.hxx2
-rw-r--r--sw/source/core/attr/calbck.cxx22
-rw-r--r--sw/source/core/table/swtable.cxx7
-rw-r--r--sw/source/core/unocore/unoobj2.cxx85
-rw-r--r--sw/source/core/unocore/unotbl.cxx2
7 files changed, 72 insertions, 54 deletions
diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx
index e5d90269777e..dea6e20c24aa 100644
--- a/sw/inc/calbck.hxx
+++ b/sw/inc/calbck.hxx
@@ -26,8 +26,7 @@
#include "hints.hxx"
#include <typeinfo>
#include <type_traits>
-#include <vector>
-#include <memory>
+#include <list>
class SwModify;
@@ -236,12 +235,13 @@ private:
class SW_DLLPUBLIC SwMultiDepend final
{
SwClient& m_rToTell;
- std::vector<std::shared_ptr<SwDepend>> m_vpDepends;
+ std::list<SwDepend> m_vDepends;
public:
SwMultiDepend(SwClient& rToTell)
: m_rToTell(rToTell) {}
void StartListening(SwModify* pDepend);
void EndListening(SwModify* pDepend);
+ bool IsListeningTo(const SwModify* const pDepend);
void EndListeningAll();
};
diff --git a/sw/inc/swtblfmt.hxx b/sw/inc/swtblfmt.hxx
index 63f7f3ee46b0..038bccab593b 100644
--- a/sw/inc/swtblfmt.hxx
+++ b/sw/inc/swtblfmt.hxx
@@ -20,6 +20,7 @@
#define INCLUDED_SW_INC_SWTBLFMT_HXX
#include "frmfmt.hxx"
+#include "pam.hxx"
class SwDoc;
@@ -37,6 +38,7 @@ public:
DECL_FIXEDMEMPOOL_NEWDEL(SwTableFormat)
virtual bool supportsFullDrawingLayerFillAttributeSet() const override;
+ SwPosition GetPosition() const;
};
class SwTableLineFormat final : public SwFrameFormat
diff --git a/sw/inc/unotextrange.hxx b/sw/inc/unotextrange.hxx
index 9506a7790852..8631b585519c 100644
--- a/sw/inc/unotextrange.hxx
+++ b/sw/inc/unotextrange.hxx
@@ -112,7 +112,7 @@ public:
const css::uno::Reference< css::text::XText > & xParent,
const enum RangePosition eRange = RANGE_IN_TEXT);
// only for RANGE_IS_TABLE
- SwXTextRange(SwFrameFormat& rTableFormat);
+ SwXTextRange(SwTableFormat& rTableFormat);
const SwDoc& GetDoc() const;
SwDoc& GetDoc();
diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx
index 412da99fc46b..c389e1d3fe14 100644
--- a/sw/source/core/attr/calbck.cxx
+++ b/sw/source/core/attr/calbck.cxx
@@ -284,21 +284,35 @@ void SwModify::CheckCaching( const sal_uInt16 nWhich )
void SwMultiDepend::StartListening(SwModify* pDepend)
{
EndListening(nullptr);
- m_vpDepends.push_back(std::make_unique<SwDepend>(&m_rToTell, pDepend));
+ m_vDepends.emplace(m_vDepends.end(), &m_rToTell, pDepend);
+}
+
+
+bool SwMultiDepend::IsListeningTo(const SwModify* const pBroadcaster)
+{
+ return std::any_of(m_vDepends.begin(), m_vDepends.end(),
+ [&pBroadcaster](const SwDepend& aListener)
+ {
+ return aListener.GetRegisteredIn() == pBroadcaster;
+ });
}
void SwMultiDepend::EndListening(SwModify* pBroadcaster)
{
- m_vpDepends.erase(std::remove_if(m_vpDepends.begin(), m_vpDepends.end(),
+ m_vDepends.remove_if( [&pBroadcaster](const SwDepend& aListener)
+ {
+ return aListener.GetRegisteredIn() == nullptr || aListener.GetRegisteredIn() == pBroadcaster;
+ });
+ /* m_vpDepends.erase(std::remove_if(m_vpDepends.begin(), m_vpDepends.end(),
[&pBroadcaster](const std::shared_ptr<SwDepend> pListener)
{
return pListener->GetRegisteredIn() == nullptr || pListener->GetRegisteredIn() == pBroadcaster;
- }));
+ })); */
}
void SwMultiDepend::EndListeningAll()
{
- m_vpDepends.clear();
+ m_vDepends.clear();
}
sw::ClientIteratorBase* sw::ClientIteratorBase::our_pClientIters = nullptr;
diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx
index 7e8bed4e28ce..5e11520f455c 100644
--- a/sw/source/core/table/swtable.cxx
+++ b/sw/source/core/table/swtable.cxx
@@ -2385,6 +2385,13 @@ bool SwTableFormat::supportsFullDrawingLayerFillAttributeSet() const
return false;
}
+SwPosition SwTableFormat::GetPosition() const
+{
+ SwTable const * const pTable = SwTable::FindTable(this);
+ SwTableNode const * const pTableNode = pTable->GetTableNode();
+ return SwPosition(*pTableNode);
+}
+
bool SwTableLineFormat::supportsFullDrawingLayerFillAttributeSet() const
{
return false;
diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx
index e62a9a01591c..2a8a5f5bb8af 100644
--- a/sw/source/core/unocore/unoobj2.cxx
+++ b/sw/source/core/unocore/unoobj2.cxx
@@ -686,20 +686,24 @@ public:
const enum RangePosition m_eRangePosition;
SwDoc & m_rDoc;
uno::Reference<text::XText> m_xParentText;
- SwDepend m_ObjectDepend; // register at format of table or frame
::sw::mark::IMark * m_pMark;
+ SwTableFormat* m_pTableFormat;
+ SwMultiDepend m_aDepends;
+
Impl( SwDoc & rDoc, const enum RangePosition eRange,
- SwFrameFormat *const pTableFormat,
+ SwTableFormat * const pTableFormat,
const uno::Reference< text::XText > & xParent = nullptr)
: SwClient()
, m_rPropSet(*aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_CURSOR))
, m_eRangePosition(eRange)
, m_rDoc(rDoc)
, m_xParentText(xParent)
- , m_ObjectDepend(this, pTableFormat)
, m_pMark(nullptr)
+ , m_pTableFormat(pTableFormat)
+ , m_aDepends(*this)
{
+ m_aDepends.StartListening(m_pTableFormat);
}
virtual ~Impl() override
@@ -719,35 +723,41 @@ public:
const ::sw::mark::IMark * GetBookmark() const { return m_pMark; }
-protected:
- // SwClient
- virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override;
-};
-
-void SwXTextRange::Impl::Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew)
-{
- const bool bAlreadyRegistered = nullptr != GetRegisteredIn();
- ClientModify(this, pOld, pNew);
- if (m_ObjectDepend.GetRegisteredIn())
+ virtual void SwClientNotify(const SwModify& rModify, const SfxHint& rHint) override
{
- ClientModify(&m_ObjectDepend, pOld, pNew);
- // if the depend was removed then the range must be removed too
- if (!m_ObjectDepend.GetRegisteredIn())
+ if(m_eRangePosition == RANGE_IS_TABLE)
{
- EndListeningAll();
+ if(auto pFormat = dynamic_cast<const SwTableFormat*>(&rModify))
+ m_pTableFormat = const_cast<SwTableFormat*>(pFormat);
}
- // or if the range has been removed but the depend is still
- // connected then the depend must be removed
- else if (bAlreadyRegistered && !GetRegisteredIn())
+ if (auto pLegacyHint = dynamic_cast<const sw::LegacyModifyHint*>(&rHint))
{
- m_ObjectDepend.EndListeningAll();
+ const auto pOld = pLegacyHint->m_pOld;
+ const auto pNew = pLegacyHint->m_pNew;
+ switch( pOld ? pOld->Which() : 0 )
+ {
+ case RES_REMOVE_UNO_OBJECT:
+ case RES_OBJECTDYING:
+ Disconnect();
+ break;
+
+ case RES_FMT_CHG:
+ // Is the move to the new one finished and will the old one be deleted?
+ if( m_aDepends.IsListeningTo(static_cast<const SwFormatChg*>(pNew)->pChangedFormat) &&
+ static_cast<const SwFormatChg*>(pOld)->pChangedFormat->IsFormatInDTOR() )
+ Disconnect();
+ break;
+ }
}
}
- if (!GetRegisteredIn())
+private:
+ void Disconnect()
{
+ m_aDepends.EndListeningAll();
m_pMark = nullptr;
+ m_pTableFormat = nullptr;
}
-}
+};
SwXTextRange::SwXTextRange(SwPaM const & rPam,
const uno::Reference< text::XText > & xParent,
@@ -757,16 +767,13 @@ SwXTextRange::SwXTextRange(SwPaM const & rPam,
SetPositions(rPam);
}
-SwXTextRange::SwXTextRange(SwFrameFormat& rTableFormat)
+SwXTextRange::SwXTextRange(SwTableFormat& rTableFormat)
: m_pImpl(
new SwXTextRange::Impl(*rTableFormat.GetDoc(), RANGE_IS_TABLE, &rTableFormat) )
{
- SwTable *const pTable = SwTable::FindTable( &rTableFormat );
- SwTableNode *const pTableNode = pTable->GetTableNode();
- SwPosition aPosition( *pTableNode );
- SwPaM aPam( aPosition );
-
- SetPositions( aPam );
+
+ SwPaM aPam(rTableFormat.GetPosition());
+ SetPositions(aPam);
}
SwXTextRange::~SwXTextRange()
@@ -794,7 +801,7 @@ void SwXTextRange::SetPositions(const SwPaM& rPam)
IDocumentMarkAccess* const pMA = m_pImpl->m_rDoc.getIDocumentMarkAccess();
m_pImpl->m_pMark = pMA->makeMark(rPam, OUString(),
IDocumentMarkAccess::MarkType::UNO_BOOKMARK, sw::mark::InsertMode::New);
- m_pImpl->m_pMark->Add(m_pImpl.get());
+ m_pImpl->m_aDepends.StartListening(m_pImpl->m_pMark);
}
void SwXTextRange::DeleteAndInsert(
@@ -883,20 +890,8 @@ SwXTextRange::getText()
{
SolarMutexGuard aGuard;
- if (!m_pImpl->m_xParentText.is())
- {
- if (m_pImpl->m_eRangePosition == RANGE_IS_TABLE &&
- m_pImpl->m_ObjectDepend.GetRegisteredIn())
- {
- SwFrameFormat const*const pTableFormat = static_cast<SwFrameFormat const*>(
- m_pImpl->m_ObjectDepend.GetRegisteredIn());
- SwTable const*const pTable = SwTable::FindTable( pTableFormat );
- SwTableNode const*const pTableNode = pTable->GetTableNode();
- const SwPosition aPosition( *pTableNode );
- m_pImpl->m_xParentText =
- ::sw::CreateParentXText(m_pImpl->m_rDoc, aPosition);
- }
- }
+ if (!m_pImpl->m_xParentText.is() && m_pImpl->m_eRangePosition == RANGE_IS_TABLE && m_pImpl->m_pTableFormat)
+ m_pImpl->m_xParentText = ::sw::CreateParentXText(m_pImpl->m_rDoc, m_pImpl->m_pTableFormat->GetPosition());
OSL_ENSURE(m_pImpl->m_xParentText.is(), "SwXTextRange::getText: no text");
return m_pImpl->m_xParentText;
}
diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx
index b56ae533487e..74d8cf74e7bd 100644
--- a/sw/source/core/unocore/unotbl.cxx
+++ b/sw/source/core/unocore/unotbl.cxx
@@ -2180,7 +2180,7 @@ SwXTextTable::attach(const uno::Reference<text::XTextRange> & xTextRange)
uno::Reference<text::XTextRange> SwXTextTable::getAnchor()
{
SolarMutexGuard aGuard;
- SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(this));
+ auto pFormat = dynamic_cast<SwTableFormat*>(lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(this)));
return new SwXTextRange(*pFormat);
}