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

Pranav Kant pranavk at collabora.co.uk
Tue Mar 14 14:02:11 UTC 2017


 sw/inc/docary.hxx                              |    6 ++++++
 sw/qa/extras/tiledrendering/tiledrendering.cxx |   20 ++++++++++++++++++++
 sw/source/core/doc/docredln.cxx                |   12 +++++-------
 sw/source/core/txtnode/ndtxt.cxx               |   24 ++++++++++++++++++++++++
 4 files changed, 55 insertions(+), 7 deletions(-)

New commits:
commit 1eb69f6b9c78b19d3944c90c17ff8d498affc316
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Tue Mar 14 15:27:42 2017 +0530

    sw lok: Notify when redline position is changed + unit test
    
    Make RedlineNotification function a static member of SwRedlineTable
    class
    
    Change-Id: Ifbd6014198838b1106e873c9563d215e95b3572d
    Reviewed-on: https://gerrit.libreoffice.org/35177
    Reviewed-by: pranavk <pranavk at collabora.co.uk>
    Tested-by: pranavk <pranavk at collabora.co.uk>

diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx
index f9aa442..cc3bfb4 100644
--- a/sw/inc/docary.hxx
+++ b/sw/inc/docary.hxx
@@ -313,6 +313,9 @@ struct CompareSwRedlineTable
     bool operator()(SwRangeRedline* const &lhs, SwRangeRedline* const &rhs) const;
 };
 
+// Notification type for notifying about redlines to LOK clients
+enum class RedlineNotification { Add, Remove, Modify };
+
 class SwRedlineTable
 {
 public:
@@ -362,6 +365,9 @@ public:
     vector_type::const_iterator begin() const { return maVector.begin(); }
     vector_type::const_iterator end() const { return maVector.end(); }
     void                        Resort() { maVector.Resort(); }
+
+    // Notifies all LOK clients when redliens are added/modified/removed
+    static void                 LOKRedlineNotification(RedlineNotification eType, SwRedlineTable::size_type nPos, SwRangeRedline* pRedline);
 };
 
 /// Table that holds 'extra' redlines, such as 'table row insert\delete', 'paragraph moves' etc...
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 0a55c6c..6fbcded 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -1375,6 +1375,26 @@ void SwTiledRenderingTest::testRedlineUpdateCallback()
     // This was 0, as LOK_CALLBACK_REDLINE_TABLE_ENTRY_MODIFIED wasn't sent.
     CPPUNIT_ASSERT_EQUAL(1, m_nRedlineTableEntryModified);
 
+    // Turn off the change tracking mode, make some modification to left of the
+    // redline so that its position changes
+    xPropertySet->setPropertyValue("RecordChanges", uno::makeAny(false));
+    pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false);
+    pWrtShell->Insert("This text is left of the redline");
+
+    // Position of the redline has changed => Modify callback
+    CPPUNIT_ASSERT_EQUAL(2, m_nRedlineTableEntryModified);
+
+    pWrtShell->DelLeft();
+    // Deletion also emits Modify callback
+    CPPUNIT_ASSERT_EQUAL(3, m_nRedlineTableEntryModified);
+
+    // Make changes to the right of the redline => no position change in redline
+    pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 100/*Go enough right */, /*bBasicCall=*/false);
+    pWrtShell->Insert("This text is right of the redline");
+
+    // No Modify callbacks
+    CPPUNIT_ASSERT_EQUAL(3, m_nRedlineTableEntryModified);
+
     comphelper::LibreOfficeKit::setActive(false);
 }
 
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index 6ae2e29..555cff7 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -60,8 +60,6 @@
 
 using namespace com::sun::star;
 
-enum class RedlineNotification { Add, Remove, Modify };
-
 #ifdef DBG_UTIL
 
     void sw_DebugRedline( const SwDoc* pDoc )
@@ -304,7 +302,7 @@ bool SwExtraRedlineTable::DeleteTableCellRedline( SwDoc* pDoc, const SwTableBox&
 }
 
 /// Emits LOK notification about one addition / removal of a redline item.
-static void lcl_RedlineNotification(RedlineNotification nType, SwRedlineTable::size_type nPos, SwRangeRedline* pRedline)
+void SwRedlineTable::LOKRedlineNotification(RedlineNotification nType, SwRedlineTable::size_type nPos, SwRangeRedline* pRedline)
 {
     if (!comphelper::LibreOfficeKit::isActive())
         return;
@@ -363,7 +361,7 @@ bool SwRedlineTable::Insert( SwRangeRedline* p )
     {
         std::pair<vector_type::const_iterator, bool> rv = maVector.insert( p );
         size_type nP = rv.first - begin();
-        lcl_RedlineNotification(RedlineNotification::Add, nP, p);
+        LOKRedlineNotification(RedlineNotification::Add, nP, p);
         p->CallDisplayFunc(nP);
         return rv.second;
     }
@@ -523,7 +521,7 @@ bool SwRedlineTable::Remove( const SwRangeRedline* p )
 
 void SwRedlineTable::Remove( size_type nP )
 {
-    lcl_RedlineNotification(RedlineNotification::Remove, nP, maVector[nP]);
+    LOKRedlineNotification(RedlineNotification::Remove, nP, maVector[nP]);
     SwDoc* pDoc = nullptr;
     if( !nP && 1 == size() )
         pDoc = maVector.front()->GetDoc();
@@ -550,7 +548,7 @@ void SwRedlineTable::DeleteAndDestroy( size_type nP, size_type nL )
     size_t nCount = 0;
     for( vector_type::const_iterator it = maVector.begin() + nP; it != maVector.begin() + nP + nL; ++it )
     {
-        lcl_RedlineNotification(RedlineNotification::Remove, nP + nCount, *it);
+        LOKRedlineNotification(RedlineNotification::Remove, nP + nCount, *it);
         delete *it;
         ++nCount;
     }
@@ -993,7 +991,7 @@ void SwRangeRedline::MaybeNotifyModification()
     {
         if (rRedTable[i] == this)
         {
-            lcl_RedlineNotification(RedlineNotification::Modify, i, this);
+            SwRedlineTable::LOKRedlineNotification(RedlineNotification::Modify, i, this);
             break;
         }
     }
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index cf22c35..c31f0b2 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -20,6 +20,7 @@
 #include <hintids.hxx>
 #include <hints.hxx>
 
+#include <comphelper/lok.hxx>
 #include <comphelper/string.hxx>
 #include <editeng/fontitem.hxx>
 #include <editeng/formatbreakitem.hxx>
@@ -1206,6 +1207,29 @@ void SwTextNode::Update(
     SwSortedObjs* pSortedObjs = pContentFrame ? pContentFrame->GetDrawObjs() : nullptr;
     if (pSortedObjs)
         pSortedObjs->UpdateAll();
+
+    // Inform LOK clients about change in position of redlines (if any)
+    if (comphelper::LibreOfficeKit::isActive())
+    {
+        const SwRedlineTable& rTable = GetDoc()->getIDocumentRedlineAccess().GetRedlineTable();
+        for (SwRedlineTable::size_type nRedlnPos = 0; nRedlnPos < rTable.size(); ++nRedlnPos)
+        {
+            SwRangeRedline* pRedln = rTable[nRedlnPos];
+            if (pRedln->HasMark())
+            {
+                if (this == &pRedln->End()->nNode.GetNode() && *pRedln->GetPoint() != *pRedln->GetMark())
+                {
+                    // Redline is changed only when some change occurs before it
+                    if (nChangePos <= pRedln->Start()->nContent.GetIndex())
+                    {
+                        SwRedlineTable::LOKRedlineNotification(RedlineNotification::Modify, nRedlnPos, pRedln);
+                    }
+                }
+            }
+            else if (this == &pRedln->GetPoint()->nNode.GetNode())
+                SwRedlineTable::LOKRedlineNotification(RedlineNotification::Modify, nRedlnPos, pRedln);
+        }
+    }
 }
 
 void SwTextNode::ChgTextCollUpdateNum( const SwTextFormatColl *pOldColl,


More information about the Libreoffice-commits mailing list