summaryrefslogtreecommitdiff
path: root/sw/inc/calbck.hxx
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2018-05-29 11:37:29 +0200
committerMichael Stahl <Michael.Stahl@cib.de>2018-06-08 21:51:32 +0200
commit75e0f0e6c1ef98d1b5bd10330774307cbce6cfc1 (patch)
treed1a34a673fb58cd1ee36e8d8da8f36ca1187c534 /sw/inc/calbck.hxx
parent4966b1d4d0dc7bce0a1741f9347dada7406a7fb4 (diff)
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
Diffstat (limited to 'sw/inc/calbck.hxx')
-rw-r--r--sw/inc/calbck.hxx106
1 files changed, 94 insertions, 12 deletions
diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx
index 913a7f6e173e..967e4be6a314 100644
--- a/sw/inc/calbck.hxx
+++ b/sw/inc/calbck.hxx
@@ -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;
};