Kaydet (Commit) 75e0f0e6 authored tarafından Michael Stahl's avatar Michael Stahl

sw_redlinehide: add an indirect iteration mode to SwIterator

There are lots of existing loops over SwTextFrames of SwTextNodes,
and these need to keep finding the frames if there's a
WriterMultiListener in between.

Add a template parameter to SwIterator that can be used to make the
iteration transparent, i.e. return the client of the
WriterMultiListener instead of the ListenerEntry itself.

Change-Id: I8b67a027b392b08408f5fbf26be22884384aa6cf
üst 4966b1d4
......@@ -110,14 +110,16 @@ namespace sw
public:
bool IsLast() const { return !m_pLeft && !m_pRight; }
};
enum class IteratorMode { Exact, UnwrapMulti };
}
// 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;
template<typename E, typename S> friend class SwIterator;
template<typename E, typename S, sw::IteratorMode> friend class SwIterator;
SwModify *m_pRegisteredIn; ///< event source
......@@ -166,7 +168,7 @@ public:
class SW_DLLPUBLIC SwModify: public SwClient
{
friend class sw::ClientIteratorBase;
template<typename E, typename S> 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 : 1; // don't broadcast changes now
bool m_bLockClientList : 1; // may be set when this instance notifies its clients
......@@ -221,9 +223,42 @@ public:
bool HasOnlyOneListener() { return m_pWriterListeners && m_pWriterListeners->IsLast(); }
};
template<typename TElementType, typename TSource, sw::IteratorMode eMode> class SwIterator;
namespace sw
{
class ListenerEntry;
// this should be hidden but sadly SwIterator template needs it...
class ListenerEntry final : public SwClient
{
private:
template<typename E, typename S, sw::IteratorMode> friend class ::SwIterator;
SwClient *m_pToTell;
public:
ListenerEntry(SwClient *const pTellHim, SwModify *const pDepend)
: SwClient(pDepend), m_pToTell(pTellHim)
{}
ListenerEntry(ListenerEntry&) = delete;
ListenerEntry& operator=(ListenerEntry const&) = delete;
ListenerEntry(ListenerEntry&& other) noexcept
: SwClient(std::move(other))
, m_pToTell(other.m_pToTell)
{ }
ListenerEntry& operator=(ListenerEntry&& other) noexcept
{
m_pToTell = other.m_pToTell;
other.GetRegisteredIn()->Add(this);
other.EndListeningAll();
return *this;
}
/** get Client information */
virtual bool GetInfo( SfxPoolItem& rInfo) const override;
private:
virtual void Modify(const SfxPoolItem* pOldValue, const SfxPoolItem *pNewValue) override;
virtual void SwClientNotify(const SwModify& rModify, const SfxHint& rHint) override;
};
class SW_DLLPUBLIC WriterMultiListener final
{
SwClient& m_rToTell;
......@@ -285,7 +320,9 @@ namespace sw
};
}
template< typename TElementType, typename TSource > class SwIterator final : private sw::ClientIteratorBase
template<typename TElementType, typename TSource,
sw::IteratorMode eMode = sw::IteratorMode::Exact> class SwIterator final
: private sw::ClientIteratorBase
{
//static_assert(!std::is_base_of<SwPageDesc,TSource>::value, "SwPageDesc as TSource is deprecated.");
static_assert(std::is_base_of<SwClient,TElementType>::value, "TElementType needs to be derived from SwClient.");
......@@ -308,24 +345,69 @@ public:
return static_cast<TElementType*>(Sync());
while(GetRightOfPos())
m_pPosition = GetRightOfPos();
if(dynamic_cast<const TElementType *>(m_pPosition) != nullptr)
return static_cast<TElementType*>(Sync());
sw::WriterListener * pCurrent(m_pPosition);
if (eMode == sw::IteratorMode::UnwrapMulti)
{
if (auto const pLE = dynamic_cast<sw::ListenerEntry const*>(pCurrent))
{
pCurrent = pLE->m_pToTell;
}
}
if (dynamic_cast<const TElementType *>(pCurrent) != nullptr)
{
Sync();
return static_cast<TElementType*>(pCurrent);
}
return Previous();
}
TElementType* Next()
{
if(!IsChanged())
m_pPosition = GetRightOfPos();
while(m_pPosition && dynamic_cast<const TElementType *>(m_pPosition) == nullptr)
m_pPosition = GetRightOfPos();
return static_cast<TElementType*>(Sync());
sw::WriterListener *pCurrent(m_pPosition);
while (m_pPosition)
{
if (eMode == sw::IteratorMode::UnwrapMulti)
{
if (auto const pLE = dynamic_cast<sw::ListenerEntry const*>(m_pPosition))
{
pCurrent = pLE->m_pToTell;
}
}
if (dynamic_cast<const TElementType *>(pCurrent) == nullptr)
{
m_pPosition = GetRightOfPos();
pCurrent = m_pPosition;
}
else
break;
}
Sync();
return static_cast<TElementType*>(pCurrent);
}
TElementType* Previous()
{
m_pPosition = GetLeftOfPos();
while(m_pPosition && dynamic_cast<const TElementType *>(m_pPosition) == nullptr)
m_pPosition = GetLeftOfPos();
return static_cast<TElementType*>(Sync());
sw::WriterListener *pCurrent(m_pPosition);
while (m_pPosition)
{
if (eMode == sw::IteratorMode::UnwrapMulti)
{
if (auto const pLE = dynamic_cast<sw::ListenerEntry const*>(m_pPosition))
{
pCurrent = pLE->m_pToTell;
}
}
if (dynamic_cast<const TElementType *>(pCurrent) == nullptr)
{
m_pPosition = GetLeftOfPos();
pCurrent = m_pPosition;
}
else
break;
}
Sync();
return static_cast<TElementType*>(pCurrent);
}
using sw::ClientIteratorBase::IsChanged;
};
......
......@@ -27,51 +27,29 @@
namespace sw
{
class ListenerEntry final : public SwClient
bool ListenerEntry::GetInfo(SfxPoolItem& rInfo) const
{ return m_pToTell == nullptr || m_pToTell->GetInfo( rInfo ); }
void ListenerEntry::Modify(const SfxPoolItem *const pOldValue,
const SfxPoolItem *const pNewValue)
{
SwClient *m_pToTell;
public:
ListenerEntry(SwClient* pTellHim, SwModify * pDepend) : SwClient(pDepend), m_pToTell(pTellHim) {}
ListenerEntry(ListenerEntry&) = delete;
ListenerEntry& operator=(ListenerEntry const&) = delete;
ListenerEntry(ListenerEntry&& other) noexcept
: SwClient(std::move(other))
, m_pToTell(other.m_pToTell)
{ }
ListenerEntry& operator=(ListenerEntry&& other) noexcept
{
m_pToTell = other.m_pToTell;
other.GetRegisteredIn()->Add(this);
other.EndListeningAll();
return *this;
}
/** get Client information */
virtual bool GetInfo( SfxPoolItem& rInfo) const override
{ return m_pToTell == nullptr || m_pToTell->GetInfo( rInfo ); }
private:
virtual void Modify( const SfxPoolItem* pOldValue, const SfxPoolItem *pNewValue ) override
{
SwClientNotify(*GetRegisteredIn(), sw::LegacyModifyHint(pOldValue, pNewValue));
}
virtual void SwClientNotify( const SwModify& rModify, const SfxHint& rHint ) override
SwClientNotify(*GetRegisteredIn(), sw::LegacyModifyHint(pOldValue, pNewValue));
}
void ListenerEntry::SwClientNotify(const SwModify& rModify, const SfxHint& rHint)
{
if (auto pLegacyHint = dynamic_cast<const sw::LegacyModifyHint*>(&rHint))
{
if (auto pLegacyHint = dynamic_cast<const sw::LegacyModifyHint*>(&rHint))
if (pLegacyHint->m_pNew && pLegacyHint->m_pNew->Which() == RES_OBJECTDYING)
{
if( pLegacyHint->m_pNew && pLegacyHint->m_pNew->Which() == RES_OBJECTDYING )
{
auto pModifyChanged = CheckRegistration(pLegacyHint->m_pOld);
if(pModifyChanged)
m_pToTell->SwClientNotify(rModify, *pModifyChanged);
}
else if( m_pToTell )
m_pToTell->ModifyNotification(pLegacyHint->m_pOld, pLegacyHint->m_pNew);
auto pModifyChanged = CheckRegistration(pLegacyHint->m_pOld);
if (pModifyChanged)
m_pToTell->SwClientNotify(rModify, *pModifyChanged);
}
else if(m_pToTell)
m_pToTell->SwClientNotifyCall(rModify, rHint);
else if (m_pToTell)
m_pToTell->ModifyNotification(pLegacyHint->m_pOld, pLegacyHint->m_pNew);
}
};
else if (m_pToTell)
m_pToTell->SwClientNotifyCall(rModify, rHint);
}
}
sw::LegacyModifyHint::~LegacyModifyHint() {}
......
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