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;
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
class SW_DLLPUBLIC SwClient : ::boost::noncopyable
class SW_DLLPUBLIC SwClient : ::sw::WriterListener
{
// avoids making the details of the linked list and the callback method public
friend class SwModify;
friend class SwClientIter;
SwClient *pLeft, *pRight; ///< double-linked list of other clients
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:
// single argument ctors shall be explicit.
explicit SwClient(SwModify *pToRegisterIn);
......@@ -82,8 +102,9 @@ protected:
public:
inline SwClient();
SwClient() : pRegisteredIn(nullptr) {}
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,
// its SwClient objects can decide to get registered to the latter instead by calling this method
......@@ -91,12 +112,11 @@ public:
// controlled access to Modify method
// 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 ); }
const SwModify* GetRegisteredIn() const { return pRegisteredIn; }
SwModify* GetRegisteredIn() { return pRegisteredIn; }
bool IsLast() const { return !pLeft && !pRight; }
// needed for class SwClientIter
TYPEINFO();
......@@ -105,16 +125,13 @@ public:
virtual bool GetInfo( SfxPoolItem& ) const;
};
inline SwClient::SwClient() :
pLeft(0), pRight(0), pRegisteredIn(0)
{}
// SwModify
// class has a doubly linked list for dependencies
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 bLockClientList : 1; // may be set when this instance notifies its clients
bool bInDocDTOR : 1; // workaround for problems when a lot of objects are destroyed
......@@ -144,7 +161,7 @@ public:
void Add(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
virtual bool GetInfo( SfxPoolItem& ) const SAL_OVERRIDE;
......
......@@ -28,7 +28,7 @@ static SwClientIter* pClientIters = nullptr;
TYPEINIT0( SwClient );
SwClient::SwClient( SwModify* pToRegisterIn )
: pLeft( nullptr ), pRight( nullptr ), pRegisteredIn( nullptr )
: pRegisteredIn( nullptr )
{
if(pToRegisterIn)
// connect to SwModify
......@@ -63,10 +63,6 @@ void SwClient::Modify( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValu
CheckRegistration( pOldValue, pNewValue );
}
void SwClient::SwClientNotify( const SwModify&, const SfxHint& )
{
}
SwClient::~SwClient()
{
OSL_ENSURE( !pRegisteredIn || pRegisteredIn->GetDepends(), "SwModify still known, but Client already disconnected!" );
......@@ -135,7 +131,7 @@ SwModify::~SwModify()
// remove all clients that have not done themselves
// mba: possibly a hotfix for forgotten base class calls?!
while( pRoot )
pRoot->CheckRegistration( &aDyObject, &aDyObject );
static_cast<SwClient*>(pRoot)->CheckRegistration( &aDyObject, &aDyObject );
}
}
}
......@@ -225,17 +221,17 @@ void SwModify::Add( SwClient* pDepend )
{
// first client added
pRoot = pDepend;
pRoot->pLeft = nullptr;
pRoot->pRight = nullptr;
pRoot->m_pLeft = nullptr;
pRoot->m_pRight = nullptr;
}
else
{
// append client
pDepend->pRight = pRoot->pRight;
pRoot->pRight = pDepend;
pDepend->pLeft = pRoot;
if( pDepend->pRight )
pDepend->pRight->pLeft = pDepend;
pDepend->m_pRight = pRoot->m_pRight;
pRoot->m_pRight = pDepend;
pDepend->m_pLeft = pRoot;
if( pDepend->m_pRight )
pDepend->m_pRight->m_pLeft = pDepend;
}
// connect client to me
......@@ -252,15 +248,15 @@ SwClient* SwModify::Remove( SwClient* pDepend )
{
// SwClient is my listener
// remove it from my list
SwClient* pR = pDepend->pRight;
SwClient* pL = pDepend->pLeft;
::sw::WriterListener* pR = pDepend->m_pRight;
::sw::WriterListener* pL = pDepend->m_pLeft;
if( pRoot == pDepend )
pRoot = pL ? pL : pR;
if( pL )
pL->pRight = pR;
pL->m_pRight = pR;
if( pR )
pR->pLeft = pL;
pR->m_pLeft = pL;
// update ClientIters
SwClientIter* pTmp = pClientIters;
......@@ -270,13 +266,13 @@ SwClient* SwModify::Remove( SwClient* pDepend )
{
// if object being removed is the current or next object in an
// iterator, advance this iterator
pTmp->pDelNext = pR;
pTmp->pDelNext = static_cast<SwClient*>(pR);
}
pTmp = pTmp->pNxtIter;
}
pDepend->pLeft = nullptr;
pDepend->pRight = nullptr;
pDepend->m_pLeft = nullptr;
pDepend->m_pRight = nullptr;
}
else
{
......@@ -412,7 +408,7 @@ SwClient* SwClientIter::operator++()
{
if( pDelNext == pAct )
{
pAct = pAct->pRight;
pAct = static_cast<SwClient*>(pAct->m_pRight);
pDelNext = pAct;
}
else
......@@ -425,8 +421,8 @@ SwClient* SwClientIter::GoStart()
pAct = const_cast<SwClient*>(rRoot.GetDepends());
if( pAct )
{
while( pAct->pLeft )
pAct = pAct->pLeft;
while( pAct->m_pLeft )
pAct = static_cast<SwClient*>(pAct->m_pLeft);
}
pDelNext = pAct;
return pAct;
......@@ -439,8 +435,8 @@ SwClient* SwClientIter::GoEnd()
pAct = const_cast<SwClient*>(rRoot.GetDepends());
if( pAct )
{
while( pAct->pRight )
pAct = pAct->pRight;
while( pAct->m_pRight )
pAct = static_cast<SwClient*>(pAct->m_pRight);
}
pDelNext = pAct;
return pAct;
......@@ -457,7 +453,7 @@ SwClient* SwClientIter::First( TypeId nType )
if( pDelNext == pAct )
{
pAct = pAct->pRight;
pAct = static_cast<SwClient*>(pAct->m_pRight);
pDelNext = pAct;
}
else
......@@ -476,9 +472,9 @@ SwClient* SwClientIter::Last( TypeId nType )
break;
if( pDelNext == pAct )
pAct = pAct->pLeft;
pAct = static_cast<SwClient*>(pAct->m_pLeft);
else
pAct = pDelNext->pLeft;
pAct = static_cast<SwClient*>(pDelNext->m_pLeft);
pDelNext = pAct;
} while( pAct );
return pAct;
......@@ -489,7 +485,7 @@ SwClient* SwClientIter::Next()
do {
if( pDelNext == pAct )
{
pAct = pAct->pRight;
pAct = static_cast<SwClient*>(pAct->m_pRight);
pDelNext = pAct;
}
else
......@@ -505,9 +501,9 @@ SwClient* SwClientIter::Previous()
{
do {
if( pDelNext == pAct )
pAct = pAct->pLeft;
pAct = static_cast<SwClient*>(pAct->m_pLeft);
else
pAct = pDelNext->pLeft;
pAct = static_cast<SwClient*>(pDelNext->m_pLeft);
pDelNext = pAct;
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