Kaydet (Commit) 88999929 authored tarafından Bjoern Michaelsen's avatar Bjoern Michaelsen Kaydeden (comit) Björn Michaelsen

SwXTextRange::Impl: use WriterMultiListener

Change-Id: Ib850916bfed8a5eb6ca97419db9d7be0bdef1257
Reviewed-on: https://gerrit.libreoffice.org/52217Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarBjörn Michaelsen <bjoern.michaelsen@libreoffice.org>
üst 9401c7c2
...@@ -683,24 +683,27 @@ class SwXTextRange::Impl ...@@ -683,24 +683,27 @@ class SwXTextRange::Impl
: public SwClient : public SwClient
{ {
public: public:
const SfxItemPropertySet & m_rPropSet; const SfxItemPropertySet& m_rPropSet;
const enum RangePosition m_eRangePosition; const enum RangePosition m_eRangePosition;
SwDoc & m_rDoc; SwDoc& m_rDoc;
uno::Reference<text::XText> m_xParentText; uno::Reference<text::XText> m_xParentText;
SwDepend m_ObjectDepend; // register at format of table or frame sw::WriterMultiListener m_aMultiListener;
::sw::mark::IMark * m_pMark; const ::sw::mark::IMark* m_pMark;
const SwFrameFormat* m_pTableFormat;
Impl( SwDoc & rDoc, const enum RangePosition eRange, Impl(SwDoc & rDoc, const enum RangePosition eRange,
SwFrameFormat *const pTableFormat, SwFrameFormat* const pTableFormat,
const uno::Reference< text::XText > & xParent = nullptr) const uno::Reference<text::XText>& xParent = nullptr)
: SwClient() : SwClient()
, m_rPropSet(*aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_CURSOR)) , m_rPropSet(*aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_CURSOR))
, m_eRangePosition(eRange) , m_eRangePosition(eRange)
, m_rDoc(rDoc) , m_rDoc(rDoc)
, m_xParentText(xParent) , m_xParentText(xParent)
, m_ObjectDepend(this, pTableFormat) , m_aMultiListener(*this)
, m_pMark(nullptr) , m_pMark(nullptr)
, m_pTableFormat(pTableFormat)
{ {
m_aMultiListener.StartListening(pTableFormat);
} }
virtual ~Impl() override virtual ~Impl() override
...@@ -722,31 +725,24 @@ public: ...@@ -722,31 +725,24 @@ public:
protected: protected:
// SwClient // SwClient
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override; virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
}; };
void SwXTextRange::Impl::Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) void SwXTextRange::Impl::SwClientNotify(const SwModify& rModify, const SfxHint& rHint)
{ {
const bool bAlreadyRegistered = nullptr != GetRegisteredIn(); assert(!GetRegisteredIn()); // we should only listen with the WriterMultiListener from now on
ClientModify(this, pOld, pNew); if(auto pModifyChangedHint = dynamic_cast<const sw::ModifyChangedHint*>(&rHint))
if (m_ObjectDepend.GetRegisteredIn())
{ {
ClientModify(&m_ObjectDepend, pOld, pNew); if(pModifyChangedHint->m_pNew == nullptr)
// if the depend was removed then the range must be removed too
if (!m_ObjectDepend.GetRegisteredIn())
{
EndListeningAll();
}
// or if the range has been removed but the depend is still
// connected then the depend must be removed
else if (bAlreadyRegistered && !GetRegisteredIn())
{
m_ObjectDepend.EndListeningAll();
}
}
if (!GetRegisteredIn())
{ {
m_aMultiListener.EndListeningAll();
m_pMark = nullptr; m_pMark = nullptr;
m_pTableFormat = nullptr;
}
else if(&rModify == m_pMark)
m_pMark = dynamic_cast<const ::sw::mark::IMark*>(pModifyChangedHint->m_pNew);
else if(&rModify == m_pTableFormat)
m_pTableFormat = dynamic_cast<const SwFrameFormat*>(pModifyChangedHint->m_pNew);
} }
} }
...@@ -795,7 +791,7 @@ void SwXTextRange::SetPositions(const SwPaM& rPam) ...@@ -795,7 +791,7 @@ void SwXTextRange::SetPositions(const SwPaM& rPam)
IDocumentMarkAccess* const pMA = m_pImpl->m_rDoc.getIDocumentMarkAccess(); IDocumentMarkAccess* const pMA = m_pImpl->m_rDoc.getIDocumentMarkAccess();
m_pImpl->m_pMark = pMA->makeMark(rPam, OUString(), m_pImpl->m_pMark = pMA->makeMark(rPam, OUString(),
IDocumentMarkAccess::MarkType::UNO_BOOKMARK, sw::mark::InsertMode::New); IDocumentMarkAccess::MarkType::UNO_BOOKMARK, sw::mark::InsertMode::New);
m_pImpl->m_pMark->Add(m_pImpl.get()); m_pImpl->m_aMultiListener.StartListening(const_cast<::sw::mark::IMark*>(m_pImpl->m_pMark));
} }
void SwXTextRange::DeleteAndInsert( void SwXTextRange::DeleteAndInsert(
...@@ -887,11 +883,9 @@ SwXTextRange::getText() ...@@ -887,11 +883,9 @@ SwXTextRange::getText()
if (!m_pImpl->m_xParentText.is()) if (!m_pImpl->m_xParentText.is())
{ {
if (m_pImpl->m_eRangePosition == RANGE_IS_TABLE && if (m_pImpl->m_eRangePosition == RANGE_IS_TABLE &&
m_pImpl->m_ObjectDepend.GetRegisteredIn()) m_pImpl->m_pTableFormat)
{ {
SwFrameFormat const*const pTableFormat = static_cast<SwFrameFormat const*>( SwTable const*const pTable = SwTable::FindTable( m_pImpl->m_pTableFormat );
m_pImpl->m_ObjectDepend.GetRegisteredIn());
SwTable const*const pTable = SwTable::FindTable( pTableFormat );
SwTableNode const*const pTableNode = pTable->GetTableNode(); SwTableNode const*const pTableNode = pTable->GetTableNode();
const SwPosition aPosition( *pTableNode ); const SwPosition aPosition( *pTableNode );
m_pImpl->m_xParentText = m_pImpl->m_xParentText =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment