Kaydet (Commit) 23fd991f authored tarafından Bjoern Michaelsen's avatar Bjoern Michaelsen

separate the sane from the less sane in SwClient

Change-Id: Ie641019e0de26fc73ffb51b825fef2cc072adc6e
üst 3b4a7845
...@@ -56,23 +56,43 @@ class SfxHint; ...@@ -56,23 +56,43 @@ class SfxHint;
code gets polluted by pointer casts (see switerator.hxx). code gets polluted by pointer casts (see switerator.hxx).
*/ */
class SwModify;
class SwClient;
class SwClientIter;
namespace sw
{
/// refactoring out the some of the more sane SwClient functionality
class SW_DLLPUBLIC WriterListener : ::boost::noncopyable
{
friend class ::SwModify;
friend class ::SwClient;
friend class ::SwClientIter;
private:
WriterListener* m_pLeft;
WriterListener* m_pRight; ///< double-linked list of other clients
protected:
WriterListener()
: m_pLeft(nullptr), m_pRight(nullptr)
{}
virtual ~WriterListener() {};
// callbacks received from SwModify (friend class - so these methods can be private)
// should be called only from SwModify the client is registered in
// mba: IMHO these methods should be pure virtual
virtual void Modify(const SfxPoolItem*, const SfxPoolItem*) {};
virtual void SwClientNotify( const SwModify&, const SfxHint&) {};
public:
bool IsLast() const { return !m_pLeft && !m_pRight; }
};
}
// SwClient // SwClient
class SW_DLLPUBLIC SwClient : ::sw::WriterListener
class SW_DLLPUBLIC SwClient : ::boost::noncopyable
{ {
// avoids making the details of the linked list and the callback method public // avoids making the details of the linked list and the callback method public
friend class SwModify; friend class SwModify;
friend class SwClientIter; friend class SwClientIter;
SwClient *pLeft, *pRight; ///< double-linked list of other clients
SwModify *pRegisteredIn; ///< event source SwModify *pRegisteredIn; ///< event source
// callbacks received from SwModify (friend class - so these methods can be private)
// should be called only from SwModify the client is registered in
// mba: IMHO these methods should be pure virtual
virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew);
virtual void SwClientNotify( const SwModify& rModify, const SfxHint& rHint );
protected: protected:
// single argument ctors shall be explicit. // single argument ctors shall be explicit.
explicit SwClient(SwModify *pToRegisterIn); explicit SwClient(SwModify *pToRegisterIn);
...@@ -82,8 +102,9 @@ protected: ...@@ -82,8 +102,9 @@ protected:
public: public:
inline SwClient(); SwClient() : pRegisteredIn(nullptr) {}
virtual ~SwClient(); virtual ~SwClient();
virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew);
// in case an SwModify object is destroyed that itself is registered in another SwModify, // in case an SwModify object is destroyed that itself is registered in another SwModify,
// its SwClient objects can decide to get registered to the latter instead by calling this method // its SwClient objects can decide to get registered to the latter instead by calling this method
...@@ -91,12 +112,11 @@ public: ...@@ -91,12 +112,11 @@ public:
// controlled access to Modify method // controlled access to Modify method
// mba: this is still considered a hack and it should be fixed; the name makes grep-ing easier // mba: this is still considered a hack and it should be fixed; the name makes grep-ing easier
void ModifyNotification( const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue ) { Modify ( pOldValue, pNewValue ); } void ModifyNotification( const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue ) { this->Modify ( pOldValue, pNewValue ); }
void SwClientNotifyCall( const SwModify& rModify, const SfxHint& rHint ) { SwClientNotify( rModify, rHint ); } void SwClientNotifyCall( const SwModify& rModify, const SfxHint& rHint ) { SwClientNotify( rModify, rHint ); }
const SwModify* GetRegisteredIn() const { return pRegisteredIn; } const SwModify* GetRegisteredIn() const { return pRegisteredIn; }
SwModify* GetRegisteredIn() { return pRegisteredIn; } SwModify* GetRegisteredIn() { return pRegisteredIn; }
bool IsLast() const { return !pLeft && !pRight; }
// needed for class SwClientIter // needed for class SwClientIter
TYPEINFO(); TYPEINFO();
...@@ -105,16 +125,13 @@ public: ...@@ -105,16 +125,13 @@ public:
virtual bool GetInfo( SfxPoolItem& ) const; virtual bool GetInfo( SfxPoolItem& ) const;
}; };
inline SwClient::SwClient() :
pLeft(0), pRight(0), pRegisteredIn(0)
{}
// SwModify // SwModify
// class has a doubly linked list for dependencies // class has a doubly linked list for dependencies
class SW_DLLPUBLIC SwModify: public SwClient class SW_DLLPUBLIC SwModify: public SwClient
{ {
SwClient* pRoot; // the start of the linked list of clients sw::WriterListener* pRoot; // the start of the linked list of clients
bool bModifyLocked : 1; // don't broadcast changes now bool bModifyLocked : 1; // don't broadcast changes now
bool bLockClientList : 1; // may be set when this instance notifies its clients bool bLockClientList : 1; // may be set when this instance notifies its clients
bool bInDocDTOR : 1; // workaround for problems when a lot of objects are destroyed bool bInDocDTOR : 1; // workaround for problems when a lot of objects are destroyed
...@@ -144,7 +161,7 @@ public: ...@@ -144,7 +161,7 @@ public:
void Add(SwClient *pDepend); void Add(SwClient *pDepend);
SwClient* Remove(SwClient *pDepend); SwClient* Remove(SwClient *pDepend);
const SwClient* GetDepends() const { return pRoot; } const SwClient* GetDepends() const { return static_cast<SwClient*>(pRoot); }
// get information about attribute // get information about attribute
virtual bool GetInfo( SfxPoolItem& ) const SAL_OVERRIDE; virtual bool GetInfo( SfxPoolItem& ) const SAL_OVERRIDE;
......
...@@ -28,7 +28,7 @@ static SwClientIter* pClientIters = nullptr; ...@@ -28,7 +28,7 @@ static SwClientIter* pClientIters = nullptr;
TYPEINIT0( SwClient ); TYPEINIT0( SwClient );
SwClient::SwClient( SwModify* pToRegisterIn ) SwClient::SwClient( SwModify* pToRegisterIn )
: pLeft( nullptr ), pRight( nullptr ), pRegisteredIn( nullptr ) : pRegisteredIn( nullptr )
{ {
if(pToRegisterIn) if(pToRegisterIn)
// connect to SwModify // connect to SwModify
...@@ -63,10 +63,6 @@ void SwClient::Modify( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValu ...@@ -63,10 +63,6 @@ void SwClient::Modify( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValu
CheckRegistration( pOldValue, pNewValue ); CheckRegistration( pOldValue, pNewValue );
} }
void SwClient::SwClientNotify( const SwModify&, const SfxHint& )
{
}
SwClient::~SwClient() SwClient::~SwClient()
{ {
OSL_ENSURE( !pRegisteredIn || pRegisteredIn->GetDepends(), "SwModify still known, but Client already disconnected!" ); OSL_ENSURE( !pRegisteredIn || pRegisteredIn->GetDepends(), "SwModify still known, but Client already disconnected!" );
...@@ -135,7 +131,7 @@ SwModify::~SwModify() ...@@ -135,7 +131,7 @@ SwModify::~SwModify()
// remove all clients that have not done themselves // remove all clients that have not done themselves
// mba: possibly a hotfix for forgotten base class calls?! // mba: possibly a hotfix for forgotten base class calls?!
while( pRoot ) while( pRoot )
pRoot->CheckRegistration( &aDyObject, &aDyObject ); static_cast<SwClient*>(pRoot)->CheckRegistration( &aDyObject, &aDyObject );
} }
} }
} }
...@@ -225,17 +221,17 @@ void SwModify::Add( SwClient* pDepend ) ...@@ -225,17 +221,17 @@ void SwModify::Add( SwClient* pDepend )
{ {
// first client added // first client added
pRoot = pDepend; pRoot = pDepend;
pRoot->pLeft = nullptr; pRoot->m_pLeft = nullptr;
pRoot->pRight = nullptr; pRoot->m_pRight = nullptr;
} }
else else
{ {
// append client // append client
pDepend->pRight = pRoot->pRight; pDepend->m_pRight = pRoot->m_pRight;
pRoot->pRight = pDepend; pRoot->m_pRight = pDepend;
pDepend->pLeft = pRoot; pDepend->m_pLeft = pRoot;
if( pDepend->pRight ) if( pDepend->m_pRight )
pDepend->pRight->pLeft = pDepend; pDepend->m_pRight->m_pLeft = pDepend;
} }
// connect client to me // connect client to me
...@@ -252,15 +248,15 @@ SwClient* SwModify::Remove( SwClient* pDepend ) ...@@ -252,15 +248,15 @@ SwClient* SwModify::Remove( SwClient* pDepend )
{ {
// SwClient is my listener // SwClient is my listener
// remove it from my list // remove it from my list
SwClient* pR = pDepend->pRight; ::sw::WriterListener* pR = pDepend->m_pRight;
SwClient* pL = pDepend->pLeft; ::sw::WriterListener* pL = pDepend->m_pLeft;
if( pRoot == pDepend ) if( pRoot == pDepend )
pRoot = pL ? pL : pR; pRoot = pL ? pL : pR;
if( pL ) if( pL )
pL->pRight = pR; pL->m_pRight = pR;
if( pR ) if( pR )
pR->pLeft = pL; pR->m_pLeft = pL;
// update ClientIters // update ClientIters
SwClientIter* pTmp = pClientIters; SwClientIter* pTmp = pClientIters;
...@@ -270,13 +266,13 @@ SwClient* SwModify::Remove( SwClient* pDepend ) ...@@ -270,13 +266,13 @@ SwClient* SwModify::Remove( SwClient* pDepend )
{ {
// if object being removed is the current or next object in an // if object being removed is the current or next object in an
// iterator, advance this iterator // iterator, advance this iterator
pTmp->pDelNext = pR; pTmp->pDelNext = static_cast<SwClient*>(pR);
} }
pTmp = pTmp->pNxtIter; pTmp = pTmp->pNxtIter;
} }
pDepend->pLeft = nullptr; pDepend->m_pLeft = nullptr;
pDepend->pRight = nullptr; pDepend->m_pRight = nullptr;
} }
else else
{ {
...@@ -412,7 +408,7 @@ SwClient* SwClientIter::operator++() ...@@ -412,7 +408,7 @@ SwClient* SwClientIter::operator++()
{ {
if( pDelNext == pAct ) if( pDelNext == pAct )
{ {
pAct = pAct->pRight; pAct = static_cast<SwClient*>(pAct->m_pRight);
pDelNext = pAct; pDelNext = pAct;
} }
else else
...@@ -425,8 +421,8 @@ SwClient* SwClientIter::GoStart() ...@@ -425,8 +421,8 @@ SwClient* SwClientIter::GoStart()
pAct = const_cast<SwClient*>(rRoot.GetDepends()); pAct = const_cast<SwClient*>(rRoot.GetDepends());
if( pAct ) if( pAct )
{ {
while( pAct->pLeft ) while( pAct->m_pLeft )
pAct = pAct->pLeft; pAct = static_cast<SwClient*>(pAct->m_pLeft);
} }
pDelNext = pAct; pDelNext = pAct;
return pAct; return pAct;
...@@ -439,8 +435,8 @@ SwClient* SwClientIter::GoEnd() ...@@ -439,8 +435,8 @@ SwClient* SwClientIter::GoEnd()
pAct = const_cast<SwClient*>(rRoot.GetDepends()); pAct = const_cast<SwClient*>(rRoot.GetDepends());
if( pAct ) if( pAct )
{ {
while( pAct->pRight ) while( pAct->m_pRight )
pAct = pAct->pRight; pAct = static_cast<SwClient*>(pAct->m_pRight);
} }
pDelNext = pAct; pDelNext = pAct;
return pAct; return pAct;
...@@ -457,7 +453,7 @@ SwClient* SwClientIter::First( TypeId nType ) ...@@ -457,7 +453,7 @@ SwClient* SwClientIter::First( TypeId nType )
if( pDelNext == pAct ) if( pDelNext == pAct )
{ {
pAct = pAct->pRight; pAct = static_cast<SwClient*>(pAct->m_pRight);
pDelNext = pAct; pDelNext = pAct;
} }
else else
...@@ -476,9 +472,9 @@ SwClient* SwClientIter::Last( TypeId nType ) ...@@ -476,9 +472,9 @@ SwClient* SwClientIter::Last( TypeId nType )
break; break;
if( pDelNext == pAct ) if( pDelNext == pAct )
pAct = pAct->pLeft; pAct = static_cast<SwClient*>(pAct->m_pLeft);
else else
pAct = pDelNext->pLeft; pAct = static_cast<SwClient*>(pDelNext->m_pLeft);
pDelNext = pAct; pDelNext = pAct;
} while( pAct ); } while( pAct );
return pAct; return pAct;
...@@ -489,7 +485,7 @@ SwClient* SwClientIter::Next() ...@@ -489,7 +485,7 @@ SwClient* SwClientIter::Next()
do { do {
if( pDelNext == pAct ) if( pDelNext == pAct )
{ {
pAct = pAct->pRight; pAct = static_cast<SwClient*>(pAct->m_pRight);
pDelNext = pAct; pDelNext = pAct;
} }
else else
...@@ -505,9 +501,9 @@ SwClient* SwClientIter::Previous() ...@@ -505,9 +501,9 @@ SwClient* SwClientIter::Previous()
{ {
do { do {
if( pDelNext == pAct ) if( pDelNext == pAct )
pAct = pAct->pLeft; pAct = static_cast<SwClient*>(pAct->m_pLeft);
else else
pAct = pDelNext->pLeft; pAct = static_cast<SwClient*>(pDelNext->m_pLeft);
pDelNext = pAct; pDelNext = pAct;
if( pAct && pAct->IsA( aSrchId ) ) if( pAct && pAct->IsA( aSrchId ) )
......
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