[Libreoffice-commits] core.git: sw/source

Bjoern Michaelsen (via logerrit) logerrit at kemper.freedesktop.org
Sat Feb 6 20:28:44 UTC 2021


 sw/source/core/txtnode/SwGrammarContact.cxx |   89 ++++++++++++++--------------
 1 file changed, 46 insertions(+), 43 deletions(-)

New commits:
commit dcae40491eea2534c30ba96f10bc45035d073a46
Author:     Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>
AuthorDate: Sat Feb 6 00:54:46 2021 +0100
Commit:     Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>
CommitDate: Sat Feb 6 21:27:58 2021 +0100

    replace SwClient by SvtListener in SwGrammarContact
    
    Change-Id: I9bc31ac6a3990418c11a2f40ec0cc84f79f93d53
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110495
    Tested-by: Jenkins
    Reviewed-by: Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>

diff --git a/sw/source/core/txtnode/SwGrammarContact.cxx b/sw/source/core/txtnode/SwGrammarContact.cxx
index 7b061bdaf9ba..e296cc7375e6 100644
--- a/sw/source/core/txtnode/SwGrammarContact.cxx
+++ b/sw/source/core/txtnode/SwGrammarContact.cxx
@@ -23,6 +23,7 @@
 #include <ndtxt.hxx>
 #include <SwGrammarMarkUp.hxx>
 #include <txtfrm.hxx>
+#include <svl/listener.hxx>
 
 namespace {
 
@@ -37,34 +38,32 @@ namespace {
  * will replace the old list. If the grammar checker has completed the paragraph ('setChecked')
  * then a timer is setup which replaces the old list as well.
  */
-class SwGrammarContact : public IGrammarContact, public SwClient
+class SwGrammarContact : public IGrammarContact, public SvtListener
 {
-    Timer aTimer;
-    std::unique_ptr<SwGrammarMarkUp> mpProxyList;
-    bool mbFinished;
-    SwTextNode* getMyTextNode() { return static_cast<SwTextNode*>(GetRegisteredIn()); }
-      DECL_LINK( TimerRepaint, Timer *, void );
+    Timer m_aTimer;
+    std::unique_ptr<SwGrammarMarkUp> m_pProxyList;
+    bool m_isFinished;
+    SwTextNode* m_pTextNode;
+    DECL_LINK( TimerRepaint, Timer *, void );
 
 public:
     SwGrammarContact();
-    virtual ~SwGrammarContact() override { aTimer.Stop(); }
+    virtual ~SwGrammarContact() override { m_aTimer.Stop(); }
 
     // (pure) virtual functions of IGrammarContact
     virtual void updateCursorPosition( const SwPosition& rNewPos ) override;
     virtual SwGrammarMarkUp* getGrammarCheck( SwTextNode& rTextNode, bool bCreate ) override;
     virtual void finishGrammarCheck( SwTextNode& rTextNode ) override;
-protected:
-    // virtual function of SwClient
-    virtual void SwClientNotify( const SwModify&, const SfxHint& rHint) override;
+    virtual void Notify( const SfxHint& rHint) override;
 };
 
 }
 
-SwGrammarContact::SwGrammarContact() : mbFinished( false )
+SwGrammarContact::SwGrammarContact() : m_isFinished( false ), m_pTextNode(nullptr)
 {
-    aTimer.SetTimeout( 2000 );  // Repaint of grammar check after 'setChecked'
-    aTimer.SetInvokeHandler( LINK(this, SwGrammarContact, TimerRepaint) );
-    aTimer.SetDebugName( "sw::SwGrammarContact TimerRepaint" );
+    m_aTimer.SetTimeout( 2000 );  // Repaint of grammar check after 'setChecked'
+    m_aTimer.SetInvokeHandler( LINK(this, SwGrammarContact, TimerRepaint) );
+    m_aTimer.SetDebugName( "sw::SwGrammarContact TimerRepaint" );
 }
 
 IMPL_LINK( SwGrammarContact, TimerRepaint, Timer *, pTimer, void )
@@ -72,10 +71,10 @@ IMPL_LINK( SwGrammarContact, TimerRepaint, Timer *, pTimer, void )
     if( pTimer )
     {
         pTimer->Stop();
-        if( GetRegisteredIn() )
+        if( m_pTextNode )
         {   //Replace the old wrong list by the proxy list and repaint all frames
-            getMyTextNode()->SetGrammarCheck( mpProxyList.release() );
-            SwTextFrame::repaintTextFrames( *getMyTextNode() );
+            m_pTextNode->SetGrammarCheck( m_pProxyList.release() );
+            SwTextFrame::repaintTextFrames( *m_pTextNode );
         }
     }
 }
@@ -84,48 +83,51 @@ IMPL_LINK( SwGrammarContact, TimerRepaint, Timer *, pTimer, void )
 void SwGrammarContact::updateCursorPosition( const SwPosition& rNewPos )
 {
     SwTextNode* pTextNode = rNewPos.nNode.GetNode().GetTextNode();
-    if( pTextNode == GetRegisteredIn() ) // paragraph has been changed
+    if( pTextNode == m_pTextNode ) // paragraph has been changed
         return;
 
-    aTimer.Stop();
-    if( GetRegisteredIn() ) // My last paragraph has been left
+    m_aTimer.Stop();
+    if( m_pTextNode ) // My last paragraph has been left
     {
-        if( mpProxyList )
+        if( m_pProxyList )
         {   // replace old list by the proxy list and repaint
-            getMyTextNode()->SetGrammarCheck( mpProxyList.release() );
-            SwTextFrame::repaintTextFrames( *getMyTextNode() );
+            m_pTextNode->SetGrammarCheck( m_pProxyList.release() );
+            SwTextFrame::repaintTextFrames( *m_pTextNode );
         }
         EndListeningAll();
     }
     if( pTextNode )
-        pTextNode->Add( this ); // welcome new paragraph
+    {
+        m_pTextNode = pTextNode;
+        StartListening(pTextNode->GetNotifier()); // welcome new paragraph
+    }
 }
 
 /* deliver a grammar check list for the given text node */
 SwGrammarMarkUp* SwGrammarContact::getGrammarCheck( SwTextNode& rTextNode, bool bCreate )
 {
     SwGrammarMarkUp *pRet = nullptr;
-    if( GetRegisteredIn() == &rTextNode ) // hey, that's my current paragraph!
+    if( m_pTextNode == &rTextNode ) // hey, that's my current paragraph!
     {   // so you will get a proxy list...
         if( bCreate )
         {
-            if( mbFinished )
+            if( m_isFinished )
             {
-                mpProxyList.reset();
+                m_pProxyList.reset();
             }
-            if( !mpProxyList )
+            if( !m_pProxyList )
             {
                 if( rTextNode.GetGrammarCheck() )
-                    mpProxyList.reset( static_cast<SwGrammarMarkUp*>(rTextNode.GetGrammarCheck()->Clone()) );
+                    m_pProxyList.reset( static_cast<SwGrammarMarkUp*>(rTextNode.GetGrammarCheck()->Clone()) );
                 else
                 {
-                    mpProxyList.reset( new SwGrammarMarkUp() );
-                    mpProxyList->SetInvalid( 0, COMPLETE_STRING );
+                    m_pProxyList.reset( new SwGrammarMarkUp() );
+                    m_pProxyList->SetInvalid( 0, COMPLETE_STRING );
                 }
             }
-            mbFinished = false;
+            m_isFinished = false;
         }
-        pRet = mpProxyList.get();
+        pRet = m_pProxyList.get();
     }
     else
     {
@@ -141,31 +143,32 @@ SwGrammarMarkUp* SwGrammarContact::getGrammarCheck( SwTextNode& rTextNode, bool
     return pRet;
 }
 
-void SwGrammarContact::SwClientNotify(const SwModify&, const SfxHint& rHint)
+void SwGrammarContact::Notify(const SfxHint& rHint)
 {
     auto pLegacy = dynamic_cast<const sw::LegacyModifyHint*>(&rHint);
     if(!pLegacy || pLegacy->GetWhich() != RES_OBJECTDYING)
         return;
-    aTimer.Stop();
+    m_aTimer.Stop();
     EndListeningAll();
-    mpProxyList.reset();
+    m_pTextNode = nullptr;
+    m_pProxyList.reset();
 }
 
 void SwGrammarContact::finishGrammarCheck( SwTextNode& rTextNode )
 {
-    if( &rTextNode != GetRegisteredIn() ) // not my paragraph
+    if( &rTextNode != m_pTextNode ) // not my paragraph
         SwTextFrame::repaintTextFrames( rTextNode ); // can be repainted directly
     else
     {
-        if( mpProxyList )
+        if( m_pProxyList )
         {
-            mbFinished = true;
-            aTimer.Start(); // will replace old list and repaint with delay
+            m_isFinished = true;
+            m_aTimer.Start(); // will replace old list and repaint with delay
         }
-        else if( getMyTextNode()->GetGrammarCheck() )
+        else if( m_pTextNode->GetGrammarCheck() )
         {   // all grammar problems seems to be gone, no delay needed
-            getMyTextNode()->SetGrammarCheck( nullptr );
-            SwTextFrame::repaintTextFrames( *getMyTextNode() );
+            m_pTextNode->SetGrammarCheck( nullptr );
+            SwTextFrame::repaintTextFrames( *m_pTextNode );
         }
     }
 }


More information about the Libreoffice-commits mailing list