[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.3' - 10 commits - desktop/source sc/qa sc/sdi sc/source sfx2/source sw/inc sw/qa sw/sdi sw/source

Pranav Kant pranavk at collabora.co.uk
Thu Mar 23 15:37:36 UTC 2017


 desktop/source/lib/init.cxx                    |    9 ++-
 sc/qa/unit/tiledrendering/tiledrendering.cxx   |    9 +++
 sc/sdi/scalc.sdi                               |    2 
 sc/source/ui/view/cellsh.cxx                   |    6 +-
 sc/source/ui/view/cellsh1.cxx                  |   41 +++++++++++++++-
 sfx2/source/control/unoctitm.cxx               |    4 +
 sw/inc/IDocumentRedlineAccess.hxx              |   15 +++++
 sw/inc/docary.hxx                              |    6 ++
 sw/inc/redline.hxx                             |    6 +-
 sw/inc/unotxdoc.hxx                            |    2 
 sw/qa/extras/tiledrendering/tiledrendering.cxx |   53 ++++++++++++++++++++-
 sw/qa/extras/uiwriter/uiwriter.cxx             |    9 ++-
 sw/sdi/swriter.sdi                             |    8 +--
 sw/source/core/doc/docredln.cxx                |   63 +++++++++++++++++--------
 sw/source/core/inc/unoport.hxx                 |    2 
 sw/source/core/txtnode/ndtxt.cxx               |   24 +++++++++
 sw/source/core/unocore/unoredline.cxx          |   21 +-------
 sw/source/uibase/docvw/SidebarWin.cxx          |    3 -
 sw/source/uibase/shells/textfld.cxx            |   29 +++++++++++
 sw/source/uibase/uiview/view2.cxx              |   32 +++++++++---
 sw/source/uibase/uno/unotxdoc.cxx              |   47 ++++++++++++++++++
 21 files changed, 323 insertions(+), 68 deletions(-)

New commits:
commit f20bb20f8e1147d8ea1b93ee6dc216722461d456
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Thu Mar 16 19:33:48 2017 +0530

    sw lok: Use unique redline identifier, instead of array indices
    
    Use a static integer counter as identifier to each redline
    
    Change few unit-tets that was testing redlines by using a hardcoded array
    index. Instead use these unique redline identifiers now.
    
    (cherry picked from commit fe3007b013ac74760a6377387bebd15dbd23420f)
    
    Conflicts:
            sw/inc/docary.hxx
            sw/source/core/doc/docredln.cxx
            sw/source/uibase/uiview/view2.cxx
    
    Change-Id: I63aec3fc8ab10d0dad0c936600d16e96999a2bcd

diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx
index 8efe46f59ce5..a3e727435213 100644
--- a/sw/inc/docary.hxx
+++ b/sw/inc/docary.hxx
@@ -365,7 +365,7 @@ public:
     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);
+    static void                 LOKRedlineNotification(RedlineNotification eType, SwRangeRedline* pRedline);
 };
 
 /// Table that holds 'extra' redlines, such as 'table row insert\delete', 'paragraph moves' etc...
diff --git a/sw/inc/redline.hxx b/sw/inc/redline.hxx
index fe55dd657452..f31be5704738 100644
--- a/sw/inc/redline.hxx
+++ b/sw/inc/redline.hxx
@@ -171,6 +171,7 @@ class SW_DLLPUBLIC SwRangeRedline : public SwPaM
     SwNodeIndex* pContentSect;
     bool bDelLastPara : 1;
     bool bIsVisible : 1;
+    sal_uInt32 m_nId;
 
     void MoveToSection();
     void CopyToSection();
@@ -178,6 +179,8 @@ class SW_DLLPUBLIC SwRangeRedline : public SwPaM
     void MoveFromSection(size_t nMyPos);
 
 public:
+    static sal_uInt32 m_nLastId;
+
     SwRangeRedline( RedlineType_t eType, const SwPaM& rPam );
     SwRangeRedline( const SwRedlineData& rData, const SwPaM& rPam );
     SwRangeRedline( const SwRedlineData& rData, const SwPosition& rPos );
@@ -185,11 +188,12 @@ public:
     SwRangeRedline(SwRedlineData* pData, const SwPosition& rPos,
                bool bDelLP) :
         SwPaM( rPos ), pRedlineData( pData ), pContentSect( nullptr ),
-        bDelLastPara( bDelLP ), bIsVisible( true )
+        bDelLastPara( bDelLP ), bIsVisible( true ), m_nId( m_nLastId++ )
     {}
     SwRangeRedline( const SwRangeRedline& );
     virtual ~SwRangeRedline() override;
 
+    sal_uInt32 GetId() const { return m_nId; }
     SwNodeIndex* GetContentIdx() const { return pContentSect; }
     // For Undo.
     void SetContentIdx( const SwNodeIndex* );
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 25e7bef09105..f12d53f26fee 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -31,6 +31,8 @@
 #include <cmdid.h>
 #include <sfx2/viewsh.hxx>
 #include <sfx2/lokhelper.hxx>
+#include <redline.hxx>
+#include <IDocumentRedlineAccess.hxx>
 
 static const char* DATA_DIRECTORY = "/sw/qa/extras/tiledrendering/data/";
 
@@ -651,6 +653,10 @@ public:
     bool m_bViewLock;
     /// Set if any callback was invoked.
     bool m_bCalled;
+    /// Redline table size changed payload
+    boost::property_tree::ptree m_aRedlineTableChanged;
+    /// Redline table modified payload
+    boost::property_tree::ptree m_aRedlineTableModified;
 
     ViewCallback()
         : m_bOwnCursorInvalidated(false),
@@ -757,6 +763,22 @@ public:
             m_bViewLock = aTree.get_child("rectangle").get_value<std::string>() != "EMPTY";
         }
         break;
+        case LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED:
+        {
+            m_aRedlineTableChanged.clear();
+            std::stringstream aStream(pPayload);
+            boost::property_tree::read_json(aStream, m_aRedlineTableChanged);
+            m_aRedlineTableChanged = m_aRedlineTableChanged.get_child("redline");
+        }
+        break;
+        case LOK_CALLBACK_REDLINE_TABLE_ENTRY_MODIFIED:
+        {
+            m_aRedlineTableModified.clear();
+            std::stringstream aStream(pPayload);
+            boost::property_tree::read_json(aStream, m_aRedlineTableModified);
+            m_aRedlineTableModified = m_aRedlineTableModified.get_child("redline");
+        }
+        break;
         }
     }
 };
@@ -1307,15 +1329,22 @@ void SwTiledRenderingTest::testTrackChanges()
     // Turn on trak changes, type "zzz" at the end, and move to the start.
     uno::Reference<beans::XPropertySet> xPropertySet(mxComponent, uno::UNO_QUERY);
     xPropertySet->setPropertyValue("RecordChanges", uno::makeAny(true));
+    ViewCallback aView;
     SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
+    pWrtShell->GetSfxViewShell()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView);
     pWrtShell->EndDoc();
     pWrtShell->Insert("zzz");
     pWrtShell->SttDoc();
 
-    // Reject the change by index, while the cursor does not cover the tracked change.
+    // Get the redline just created
+    const SwRedlineTable& rTable = pWrtShell->GetDoc()->getIDocumentRedlineAccess().GetRedlineTable();
+    CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(1), rTable.size());
+    SwRangeRedline* pRedline = rTable[0];
+
+    // Reject the change by id, while the cursor does not cover the tracked change.
     uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence(
     {
-        {"RejectTrackedChange", uno::makeAny(static_cast<sal_uInt16>(0))}
+        {"RejectTrackedChange", uno::makeAny(static_cast<sal_uInt16>(pRedline->GetId()))}
     }));
     comphelper::dispatchCommand(".uno:RejectTrackedChange", aPropertyValues);
     Scheduler::ProcessEventsToIdle();
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index aec74fa044c5..b345380cf44d 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -3896,11 +3896,14 @@ void SwUiWriterTest::testRedlineParam()
     pWrtShell->EndDoc();
     pWrtShell->Insert("zzz");
 
+    const SwRedlineTable& rTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable();
+    CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(2), rTable.size());
+
     // Select the first redline.
     pWrtShell->SttDoc();
     uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence(
     {
-        {"NextTrackedChange", uno::makeAny(static_cast<sal_uInt16>(0))}
+        {"NextTrackedChange", uno::makeAny(static_cast<sal_uInt16>(rTable[0]->GetId()))}
     }));
     lcl_dispatchCommand(mxComponent, ".uno:NextTrackedChange", aPropertyValues);
     Scheduler::ProcessEventsToIdle();
@@ -3913,7 +3916,7 @@ void SwUiWriterTest::testRedlineParam()
     pWrtShell->SttDoc();
     aPropertyValues = comphelper::InitPropertySequence(
     {
-        {"NextTrackedChange", uno::makeAny(static_cast<sal_uInt16>(1))}
+        {"NextTrackedChange", uno::makeAny(static_cast<sal_uInt16>(rTable[1]->GetId()))}
     });
     lcl_dispatchCommand(mxComponent, ".uno:NextTrackedChange", aPropertyValues);
     Scheduler::ProcessEventsToIdle();
@@ -3924,7 +3927,7 @@ void SwUiWriterTest::testRedlineParam()
     pWrtShell->SttDoc();
     aPropertyValues = comphelper::InitPropertySequence(
     {
-        {"RejectTrackedChange", uno::makeAny(static_cast<sal_uInt16>(1))}
+        {"RejectTrackedChange", uno::makeAny(static_cast<sal_uInt16>(rTable[1]->GetId()))}
     });
     lcl_dispatchCommand(mxComponent, ".uno:RejectTrackedChange", aPropertyValues);
     Scheduler::ProcessEventsToIdle();
diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi
index aef5641d26c0..3226f27b24b3 100644
--- a/sw/sdi/swriter.sdi
+++ b/sw/sdi/swriter.sdi
@@ -663,7 +663,7 @@ SfxVoidItem ClosePreview FN_CLOSE_PAGEPREVIEW
 ]
 
 SfxVoidItem CommentChangeTracking FN_REDLINE_COMMENT
-(SfxUInt16Item ChangeTrackingId FN_REDLINE_COMMENT,SvxPostItTextItem Text SID_ATTR_POSTIT_TEXT)
+(SfxUInt32Item ChangeTrackingId FN_REDLINE_COMMENT,SvxPostItTextItem Text SID_ATTR_POSTIT_TEXT)
 [
     AutoUpdate = FALSE,
     FastCall = FALSE,
@@ -7252,7 +7252,7 @@ SfxBoolItem SpellingAndGrammarDialog FN_SPELL_GRAMMAR_DIALOG
 ]
 
 SfxVoidItem AcceptTrackedChange FN_REDLINE_ACCEPT_DIRECT
-( SfxUInt16Item AcceptTrackedChange FN_REDLINE_ACCEPT_DIRECT )
+( SfxUInt32Item AcceptTrackedChange FN_REDLINE_ACCEPT_DIRECT )
 [
     AutoUpdate = FALSE,
     FastCall = FALSE,
@@ -7271,7 +7271,7 @@ SfxVoidItem AcceptTrackedChange FN_REDLINE_ACCEPT_DIRECT
 ]
 
 SfxVoidItem RejectTrackedChange FN_REDLINE_REJECT_DIRECT
-( SfxUInt16Item RejectTrackedChange FN_REDLINE_REJECT_DIRECT )
+( SfxUInt32Item RejectTrackedChange FN_REDLINE_REJECT_DIRECT )
 [
     AutoUpdate = FALSE,
     FastCall = FALSE,
@@ -7290,7 +7290,7 @@ SfxVoidItem RejectTrackedChange FN_REDLINE_REJECT_DIRECT
 ]
 
 SfxVoidItem NextTrackedChange FN_REDLINE_NEXT_CHANGE
-( SfxUInt16Item NextTrackedChange FN_REDLINE_NEXT_CHANGE )
+( SfxUInt32Item NextTrackedChange FN_REDLINE_NEXT_CHANGE )
 [
     AutoUpdate = FALSE,
     FastCall = FALSE,
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index 1a80bccab96a..2f18017842e6 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -302,7 +302,7 @@ bool SwExtraRedlineTable::DeleteTableCellRedline( SwDoc* pDoc, const SwTableBox&
 }
 
 /// Emits LOK notification about one addition / removal of a redline item.
-void SwRedlineTable::LOKRedlineNotification(RedlineNotification nType, size_t nPos, SwRangeRedline* pRedline)
+void SwRedlineTable::LOKRedlineNotification(RedlineNotification nType, SwRangeRedline* pRedline)
 {
     if (!comphelper::LibreOfficeKit::isActive())
         return;
@@ -311,7 +311,7 @@ void SwRedlineTable::LOKRedlineNotification(RedlineNotification nType, size_t nP
     aRedline.put("action", (nType == RedlineNotification::Add ? "Add" :
                             (nType == RedlineNotification::Remove ? "Remove" :
                              (nType == RedlineNotification::Modify ? "Modify" : "???"))));
-    aRedline.put("index", nPos);
+    aRedline.put("index", pRedline->GetId());
     aRedline.put("author", pRedline->GetAuthorString(1).toUtf8().getStr());
     aRedline.put("type", nsRedlineType_t::SwRedlineTypeToOUString(pRedline->GetRedlineData().GetType()).toUtf8().getStr());
     aRedline.put("comment", pRedline->GetRedlineData().GetComment().toUtf8().getStr());
@@ -361,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();
-        LOKRedlineNotification(RedlineNotification::Add, nP, p);
+        LOKRedlineNotification(RedlineNotification::Add, p);
         p->CallDisplayFunc(nP);
         return rv.second;
     }
@@ -521,7 +521,7 @@ bool SwRedlineTable::Remove( const SwRangeRedline* p )
 
 void SwRedlineTable::Remove( sal_uInt16 nP )
 {
-    LOKRedlineNotification(RedlineNotification::Remove, nP, maVector[nP]);
+    LOKRedlineNotification(RedlineNotification::Remove, maVector[nP]);
     SwDoc* pDoc = nullptr;
     if( !nP && 1 == size() )
         pDoc = maVector.front()->GetDoc();
@@ -545,12 +545,10 @@ void SwRedlineTable::DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL )
     if( !nP && nL && nL == size() )
         pDoc = maVector.front()->GetDoc();
 
-    size_t nCount = 0;
     for( vector_type::const_iterator it = maVector.begin() + nP; it != maVector.begin() + nP + nL; ++it )
     {
-        LOKRedlineNotification(RedlineNotification::Remove, nP + nCount, *it);
+        LOKRedlineNotification(RedlineNotification::Remove, *it);
         delete *it;
-        ++nCount;
     }
     maVector.erase( maVector.begin() + nP, maVector.begin() + nP + nL );
 
@@ -931,10 +929,13 @@ OUString SwRedlineData::GetDescr() const
     return SW_RES(STR_REDLINE_INSERT + GetType());
 }
 
+sal_uInt32 SwRangeRedline::m_nLastId = 1;
+
 SwRangeRedline::SwRangeRedline(RedlineType_t eTyp, const SwPaM& rPam )
     : SwPaM( *rPam.GetMark(), *rPam.GetPoint() ),
     pRedlineData( new SwRedlineData( eTyp, GetDoc()->getIDocumentRedlineAccess().GetRedlineAuthor() ) ),
-    pContentSect( nullptr )
+    pContentSect( nullptr ),
+    m_nId( m_nLastId++ )
 {
     bDelLastPara = false;
     bIsVisible = true;
@@ -945,7 +946,8 @@ SwRangeRedline::SwRangeRedline(RedlineType_t eTyp, const SwPaM& rPam )
 SwRangeRedline::SwRangeRedline( const SwRedlineData& rData, const SwPaM& rPam )
     : SwPaM( *rPam.GetMark(), *rPam.GetPoint() ),
     pRedlineData( new SwRedlineData( rData )),
-    pContentSect( nullptr )
+    pContentSect( nullptr ),
+    m_nId( m_nLastId++ )
 {
     bDelLastPara = false;
     bIsVisible = true;
@@ -956,7 +958,8 @@ SwRangeRedline::SwRangeRedline( const SwRedlineData& rData, const SwPaM& rPam )
 SwRangeRedline::SwRangeRedline( const SwRedlineData& rData, const SwPosition& rPos )
     : SwPaM( rPos ),
     pRedlineData( new SwRedlineData( rData )),
-    pContentSect( nullptr )
+    pContentSect( nullptr ),
+    m_nId( m_nLastId++ )
 {
     bDelLastPara = false;
     bIsVisible = true;
@@ -965,7 +968,8 @@ SwRangeRedline::SwRangeRedline( const SwRedlineData& rData, const SwPosition& rP
 SwRangeRedline::SwRangeRedline( const SwRangeRedline& rCpy )
     : SwPaM( *rCpy.GetMark(), *rCpy.GetPoint() ),
     pRedlineData( new SwRedlineData( *rCpy.pRedlineData )),
-    pContentSect( nullptr )
+    pContentSect( nullptr ),
+    m_nId( rCpy.m_nId )
 {
     bDelLastPara = false;
     bIsVisible = true;
@@ -995,7 +999,7 @@ void SwRangeRedline::MaybeNotifyModification()
     {
         if (rRedTable[i] == this)
         {
-            SwRedlineTable::LOKRedlineNotification(RedlineNotification::Modify, i, this);
+            SwRedlineTable::LOKRedlineNotification(RedlineNotification::Modify, this);
             break;
         }
     }
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index aaffc3c57a88..97198e980e56 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -1225,12 +1225,12 @@ void SwTextNode::Update(
                     // Redline is changed only when some change occurs before it
                     if (nChangePos <= pRedln->Start()->nContent.GetIndex())
                     {
-                        SwRedlineTable::LOKRedlineNotification(RedlineNotification::Modify, nRedlnPos, pRedln);
+                        SwRedlineTable::LOKRedlineNotification(RedlineNotification::Modify, pRedln);
                     }
                 }
             }
             else if (this == &pRedln->GetPoint()->nNode.GetNode())
-                SwRedlineTable::LOKRedlineNotification(RedlineNotification::Modify, nRedlnPos, pRedln);
+                SwRedlineTable::LOKRedlineNotification(RedlineNotification::Modify, pRedln);
         }
     }
 }
diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx
index ed4224c4b7bb..3ef89aa6cd21 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -512,19 +512,14 @@ void SwTextShell::ExecField(SfxRequest &rReq)
 
                 const SwRangeRedline *pRedline = rSh.GetCurrRedline();
                 SwDoc *pDoc = rSh.GetDoc();
-                SwRedlineTable::size_type nRedline = SwRedlineTable::npos;
+                // If index is specified, goto and select the appropriate redline
                 if (pArgs && pArgs->GetItemState(nSlot, false, &pItem) == SfxItemState::SET)
                 {
-                    //TODO: SfxUInt16Item vs. SwRedlineTable::size_type mismatch:
-                    nRedline = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
-                    if (nRedline == USHRT_MAX)
-                        nRedline = SwRedlineTable::npos;
-
-                    if (nRedline != SwRedlineTable::npos)
+                    const sal_uInt32 nChangeId = static_cast<const SfxUInt32Item*>(pItem)->GetValue();
+                    const SwRedlineTable& rRedlineTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable();
+                    for (SwRedlineTable::size_type nRedline = 0; nRedline < rRedlineTable.size(); ++nRedline)
                     {
-                        // If index is specified, goto and select the appropriate redline
-                        const SwRedlineTable& rTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable();
-                        if (nRedline < rTable.size())
+                        if (nChangeId == rRedlineTable[nRedline]->GetId())
                             pRedline = rSh.GotoRedline(nRedline, true);
                     }
                 }
diff --git a/sw/source/uibase/uiview/view2.cxx b/sw/source/uibase/uiview/view2.cxx
index 8865d294597a..a9744b0b48b6 100644
--- a/sw/source/uibase/uiview/view2.cxx
+++ b/sw/source/uibase/uiview/view2.cxx
@@ -665,9 +665,18 @@ void SwView::Execute(SfxRequest &rReq)
         {
             SwDoc *pDoc = m_pWrtShell->GetDoc();
             SwPaM *pCursor = m_pWrtShell->GetCursor();
+            const SwRedlineTable& rRedlineTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable();
+            SwRedlineTable::size_type nRedline = SwRedlineTable::npos;
             sal_uInt16 nRedline = USHRT_MAX;
             if (pArgs && pArgs->GetItemState(nSlot, false, &pItem) == SfxItemState::SET)
-                nRedline = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
+            {
+                const sal_uInt32 nChangeId = static_cast<const SfxUInt32Item*>(pItem)->GetValue();
+                for (SwRedlineTable::size_type i = 0; i < rRedlineTable.size(); ++i)
+                {
+                    if (nChangeId == rRedlineTable[i]->GetId())
+                        nRedline = i;
+                }
+            }
 
             if( pCursor->HasMark() && nRedline == USHRT_MAX)
             {
@@ -687,9 +696,9 @@ void SwView::Execute(SfxRequest &rReq)
                 {
                     // A redline was explicitly requested by specifying an
                     // index, don't guess based on the cursor position.
-                    const SwRedlineTable& rTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable();
-                    if (nRedline < rTable.size())
-                        pRedline = rTable[nRedline];
+
+                    if (nRedline < rRedlineTable.size())
+                        pRedline = rRedlineTable[nRedline];
                 }
                 else
                     pRedline = pDoc->getIDocumentRedlineAccess().GetRedline(*pCursor->Start(), &nRedline);
@@ -710,15 +719,22 @@ void SwView::Execute(SfxRequest &rReq)
         {
             // If a parameter is provided, try going to the nth change, not to
             // the next one.
+            SwDoc* pDoc = m_pWrtShell->GetDoc();
+            const SwRedlineTable& rRedlineTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable();
             sal_uInt16 nRedline = USHRT_MAX;
             if (pArgs && pArgs->GetItemState(nSlot, false, &pItem) == SfxItemState::SET)
-                nRedline = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
+            {
+                const sal_uInt32 nChangeId = static_cast<const SfxUInt32Item*>(pItem)->GetValue();
+                for (SwRedlineTable::size_type i = 0; i < rRedlineTable.size(); ++i)
+                {
+                    if (nChangeId == rRedlineTable[i]->GetId())
+                        nRedline = i;
+                }
+            }
 
             const SwRangeRedline *pCurrent = m_pWrtShell->GetCurrRedline();
-            SwDoc* pDoc = m_pWrtShell->GetDoc();
-            const SwRedlineTable& rTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable();
             const SwRangeRedline *pNext = nullptr;
-            if (nRedline < rTable.size())
+            if (nRedline < rRedlineTable.size())
                 pNext = m_pWrtShell->GotoRedline(nRedline, true);
             else
                 pNext = m_pWrtShell->SelNextRedline();
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index bd01697d2522..7ef82e34934d 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3240,7 +3240,7 @@ OUString SwXTextDocument::getTrackedChanges()
     for (SwRedlineTable::size_type i = 0; i < rRedlineTable.size(); ++i)
     {
         boost::property_tree::ptree aTrackedChange;
-        aTrackedChange.put("index", i);
+        aTrackedChange.put("index", rRedlineTable[i]->GetId());
         aTrackedChange.put("author", rRedlineTable[i]->GetAuthorString(1).toUtf8().getStr());
         aTrackedChange.put("type", nsRedlineType_t::SwRedlineTypeToOUString(rRedlineTable[i]->GetRedlineData().GetType()).toUtf8().getStr());
         aTrackedChange.put("comment", rRedlineTable[i]->GetRedlineData().GetComment().toUtf8().getStr());
commit d33b3b16ec076deab72d9b5802d0a874cc23cfb6
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Thu Mar 16 13:07:21 2017 +0530

    sc lok: Edit annotation by id
    
    Change-Id: Iaea08b7a31fab1a8c9b8edc193754821c6608c53
    Reviewed-on: https://gerrit.libreoffice.org/35249
    Reviewed-by: pranavk <pranavk at collabora.co.uk>
    Tested-by: pranavk <pranavk at collabora.co.uk>
    (cherry picked from commit 055d8821e664446b7e66b73970a324f765e35f9c)

diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx
index 7129f05f0ede..cb9cd2bf3d8b 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -1082,8 +1082,14 @@ void ScTiledRenderingTest::testCommentCallback()
     CPPUNIT_ASSERT_EQUAL(std::string("0, 255, 1274, 254"), aView2.m_aCommentCallbackResult.get<std::string>("cellPos"));
 
     // Edit a comment
+    // Select some random cell, we should be able to edit the cell note without
+    // selecting the cell
+    ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
+    if (pTabViewShell)
+        pTabViewShell->SetCursor(3, 100);
     aArgs = comphelper::InitPropertySequence(
     {
+        {"Id", uno::makeAny(OUString("Sheet1.A2"))},
         {"Text", uno::makeAny(OUString("Edited comment"))},
         {"Author", uno::makeAny(OUString("LOK User2"))},
     });
@@ -1103,7 +1109,6 @@ void ScTiledRenderingTest::testCommentCallback()
     CPPUNIT_ASSERT_EQUAL(std::string("0, 255, 1274, 254"), aView2.m_aCommentCallbackResult.get<std::string>("cellPos"));
 
     // Delete the comment
-    ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
     if (pTabViewShell)
         pTabViewShell->SetCursor(4, 43);
     aArgs = comphelper::InitPropertySequence(
diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx
index 83de21b27898..4c297af272ab 100644
--- a/sc/source/ui/view/cellsh.cxx
+++ b/sc/source/ui/view/cellsh.cxx
@@ -19,6 +19,7 @@
 
 #include "scitems.hxx"
 
+#include <comphelper/lok.hxx>
 #include <svl/slstitm.hxx>
 #include <svl/stritem.hxx>
 #include <svl/whiter.hxx>
@@ -311,7 +312,7 @@ void ScCellShell::GetCellState( SfxItemSet& rSet )
     ScDocument& rDoc = GetViewData()->GetDocShell()->GetDocument();
     ScAddress aCursor( GetViewData()->GetCurX(), GetViewData()->GetCurY(),
                         GetViewData()->GetTabNo() );
-
+    bool isLOKNoTiledAnnotations = comphelper::LibreOfficeKit::isActive() && !comphelper::LibreOfficeKit::isTiledAnnotations();
     SfxWhichIter aIter(rSet);
     sal_uInt16 nWhich = aIter.FirstWhich();
     while ( nWhich )
@@ -370,7 +371,8 @@ void ScCellShell::GetCellState( SfxItemSet& rSet )
             case SID_EDIT_POSTIT:
                 {
                     ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
-                    if( rDoc.GetNote(aPos) )
+                    // Allow editing annotation by Id (without selecting the cell) for LOK
+                    if( isLOKNoTiledAnnotations || rDoc.GetNote(aPos) )
                     {
                         bDisable = false;
                     }
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 30a61adde256..2b1fd53c11f8 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -2202,10 +2202,29 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                 const SfxPoolItem* pText;
                 if ( pReqArgs && pReqArgs->HasItem( SID_ATTR_POSTIT_TEXT, &pText) )
                 {
+                    const SfxPoolItem* pCellId;
+                    OUString aCellId;
+                    // SID_ATTR_POSTIT_ID only argument for SID_EDIT_POSTIT
+                    if (pReqArgs->HasItem( SID_ATTR_POSTIT_ID, &pCellId ))
+                        aCellId = static_cast<const SvxPostItIdItem*>(pCellId)->GetValue();
+
                     const SvxPostItTextItem*    pTextItem   = static_cast<const SvxPostItTextItem*>( pText );
-                    const SvxPostItAuthorItem*  pAuthorItem = static_cast<const SvxPostItAuthorItem*>( pReqArgs->GetItem( SID_ATTR_POSTIT_AUTHOR) );
+                    const SvxPostItAuthorItem*  pAuthorItem = static_cast<const SvxPostItAuthorItem*>( pReqArgs->GetItem( SID_ATTR_POSTIT_AUTHOR ) );
                     const SvxPostItDateItem*    pDateItem   = static_cast<const SvxPostItDateItem*>( pReqArgs->GetItem( SID_ATTR_POSTIT_DATE ) );
 
+                    if (!aCellId.isEmpty())
+                    {
+                        ScAddress aParsedPos;
+                        ScRefFlags nRes = aParsedPos.Parse(aCellId,
+                                                           GetViewData()->GetDocument(),
+                                                           ScAddress::Details(formula::FormulaGrammar::AddressConvention::CONV_ODF));
+                        if (nRes & ScRefFlags::VALID)
+                        {
+                            pTabViewShell->SetTabNo(aParsedPos.Tab());
+                            pTabViewShell->SetCursor(aParsedPos.Col(), aParsedPos.Row());
+                        }
+                    }
+
                     ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
                     pTabViewShell->ReplaceNote( aPos, pTextItem->GetValue(),
                                                 pAuthorItem ? &pAuthorItem->GetValue() : nullptr,
commit 2f4fa3bd6dcc6ca1ba3057c36e2561df290681cb
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Thu Mar 16 12:30:45 2017 +0530

    sc lok: Delete cell note by Id
    
    Change-Id: I97224afb4eb7af36abefd0c3b59ee07de7eaa601
    Reviewed-on: https://gerrit.libreoffice.org/35247
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: pranavk <pranavk at collabora.co.uk>
    (cherry picked from commit fab4640bd3979352d6fde06decea1834f178f348)

diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx
index 3965684b2514..7129f05f0ede 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -1103,8 +1103,12 @@ void ScTiledRenderingTest::testCommentCallback()
     CPPUNIT_ASSERT_EQUAL(std::string("0, 255, 1274, 254"), aView2.m_aCommentCallbackResult.get<std::string>("cellPos"));
 
     // Delete the comment
+    ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
+    if (pTabViewShell)
+        pTabViewShell->SetCursor(4, 43);
     aArgs = comphelper::InitPropertySequence(
     {
+        {"Id", uno::makeAny(OUString("Sheet1.A2"))}
     });
     comphelper::dispatchCommand(".uno:DeleteNote", aArgs);
     Scheduler::ProcessEventsToIdle();
diff --git a/sc/sdi/scalc.sdi b/sc/sdi/scalc.sdi
index aff80507a625..c19e12268024 100644
--- a/sc/sdi/scalc.sdi
+++ b/sc/sdi/scalc.sdi
@@ -3727,7 +3727,7 @@ SfxBoolItem HideNote FID_HIDE_NOTE
 
 
 SfxVoidItem DeleteNote SID_DELETE_NOTE
-()
+(SvxPostItIdItem Id SID_ATTR_POSTIT_ID)
 [
     AutoUpdate = FALSE,
     FastCall = TRUE,
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 1b96a9ab80d9..30a61adde256 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -2311,9 +2311,27 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
             break;
 
         case SID_DELETE_NOTE:
+        {
+            const SfxPoolItem* pId;
+            // If Id is mentioned, select the appropriate cell first
+            if ( pReqArgs && pReqArgs->HasItem( SID_ATTR_POSTIT_ID, &pId) )
+            {
+                const SvxPostItIdItem* pIdItem = static_cast<const SvxPostItIdItem*>(pId);
+                ScAddress aPos;
+                ScRefFlags nRes = aPos.Parse(pIdItem->GetValue(),
+                                             GetViewData()->GetDocument(),
+                                             ScAddress::Details(formula::FormulaGrammar::AddressConvention::CONV_ODF));
+                if (nRes & ScRefFlags::VALID)
+                {
+                    pTabViewShell->SetTabNo(aPos.Tab());
+                    pTabViewShell->SetCursor(aPos.Col(), aPos.Row());
+                }
+            }
+
             pTabViewShell->DeleteContents( InsertDeleteFlags::NOTE );      // delete all notes in selection
             rReq.Done();
-            break;
+        }
+        break;
 
         case SID_CHARMAP:
             if( pReqArgs != nullptr )
commit c0166f03bf3ab64682b7a12b519551acb8e80726
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
    
    Reviewed-on: https://gerrit.libreoffice.org/35177
    Reviewed-by: pranavk <pranavk at collabora.co.uk>
    Tested-by: pranavk <pranavk at collabora.co.uk>
    (cherry picked from commit 1eb69f6b9c78b19d3944c90c17ff8d498affc316)
    
    Conflicts:
            sw/source/core/doc/docredln.cxx
    
    Change-Id: Ifbd6014198838b1106e873c9563d215e95b3572d

diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx
index 45f9e4509ed3..8efe46f59ce5 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:
@@ -360,6 +363,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 c9829f2a84a6..25e7bef09105 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -1377,6 +1377,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 28e981704df8..1a80bccab96a 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, size_t nPos, SwRangeRedline* pRedline)
+void SwRedlineTable::LOKRedlineNotification(RedlineNotification nType, size_t nPos, SwRangeRedline* pRedline)
 {
     if (!comphelper::LibreOfficeKit::isActive())
         return;
@@ -362,8 +360,8 @@ bool SwRedlineTable::Insert( SwRangeRedline* p )
     if( p->HasValidRange() )
     {
         std::pair<vector_type::const_iterator, bool> rv = maVector.insert( p );
-        size_t nP = rv.first - begin();
-        lcl_RedlineNotification(RedlineNotification::Add, nP, p);
+        size_type nP = rv.first - begin();
+        LOKRedlineNotification(RedlineNotification::Add, nP, p);
         p->CallDisplayFunc(nP);
         return rv.second;
     }
@@ -523,7 +521,7 @@ bool SwRedlineTable::Remove( const SwRangeRedline* p )
 
 void SwRedlineTable::Remove( sal_uInt16 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( sal_uInt16 nP, sal_uInt16 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;
     }
@@ -997,7 +995,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 5e78fc0abd7b..aaffc3c57a88 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>
@@ -1209,6 +1210,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,
commit d5b15909bf65e456920e286bee1801c3916f19fc
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Fri Mar 10 19:16:38 2017 +0530

    sw: Simplify - no need to create a pointer here
    
    Change-Id: I5c7d1d47f347b3ce8de6e2e4995da8724a464941
    Reviewed-on: https://gerrit.libreoffice.org/35045
    Reviewed-by: pranavk <pranavk at collabora.co.uk>
    Tested-by: pranavk <pranavk at collabora.co.uk>
    (cherry picked from commit 41c7ee5f0a3d0e128134665d709fd46e663fd373)

diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index abadabe28084..28e981704df8 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -327,14 +327,14 @@ static void lcl_RedlineNotification(RedlineNotification nType, size_t nPos, SwRa
     SwView* pView = dynamic_cast<SwView*>(SfxViewShell::Current());
     if (pView && pContentNd)
     {
-        std::unique_ptr<SwShellCursor> pCursor(new SwShellCursor(pView->GetWrtShell(), *pStartPos));
-        pCursor->SetMark();
-        pCursor->GetMark()->nNode = *pContentNd;
-        pCursor->GetMark()->nContent.Assign(pContentNd, pEndPos->nContent.GetIndex());
+        SwShellCursor aCursor(pView->GetWrtShell(), *pStartPos);
+        aCursor.SetMark();
+        aCursor.GetMark()->nNode = *pContentNd;
+        aCursor.GetMark()->nContent.Assign(pContentNd, pEndPos->nContent.GetIndex());
 
-        pCursor->FillRects();
+        aCursor.FillRects();
 
-        SwRects* pRects(pCursor.get());
+        SwRects* pRects(&aCursor);
         std::vector<OString> aRects;
         for(SwRect& rNextRect : *pRects)
             aRects.push_back(rNextRect.SVRect().toString());
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index add15faaf543..bd01697d2522 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3252,14 +3252,14 @@ OUString SwXTextDocument::getTrackedChanges()
         SwView* pView = dynamic_cast<SwView*>(SfxViewShell::Current());
         if (pView && pContentNd)
         {
-            std::unique_ptr<SwShellCursor> pCursor(new SwShellCursor(pView->GetWrtShell(), *(rRedlineTable[i]->Start()) ));
-            pCursor->SetMark();
-            pCursor->GetMark()->nNode = *pContentNd;
-            pCursor->GetMark()->nContent.Assign(pContentNd, rRedlineTable[i]->End()->nContent.GetIndex());
+            SwShellCursor aCursor(pView->GetWrtShell(), *(rRedlineTable[i]->Start()));
+            aCursor.SetMark();
+            aCursor.GetMark()->nNode = *pContentNd;
+            aCursor.GetMark()->nContent.Assign(pContentNd, rRedlineTable[i]->End()->nContent.GetIndex());
 
-            pCursor->FillRects();
+            aCursor.FillRects();
 
-            SwRects* pRects(pCursor.get());
+            SwRects* pRects(&aCursor);
             std::vector<OString> aRects;
             for(SwRect& rNextRect : *pRects)
                 aRects.push_back(rNextRect.SVRect().toString());
commit aaffd4536c359c67da201e507264bf78636e66ad
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Fri Mar 3 14:57:39 2017 +0530

    lok: Do not use UNO for fetching tracked changes
    
    See inline comment for reasons.
    
    Also, move the SwRedlineTypeToOUString function as inline to same header
    file containing redline types.
    
    Change-Id: I9b4be4f104c095b2ccd8287d935347c81fd25974
    Reviewed-on: https://gerrit.libreoffice.org/34950
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: pranavk <pranavk at collabora.co.uk>
    (cherry picked from commit e6cca48bc9deb1049f8d501406269b71f91511ca)

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index b462c1684f6b..3500d2b7673e 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -2500,7 +2500,10 @@ static char* getTrackedChanges(LibreOfficeKitDocument* pThis)
 
     uno::Reference<document::XRedlinesSupplier> xRedlinesSupplier(pDocument->mxComponent, uno::UNO_QUERY);
     std::stringstream aStream;
-    if (xRedlinesSupplier.is())
+    // We want positions of the track changes also which is not possible from
+    // UNO. Enable positioning information for text documents only for now, so
+    // construct the tracked changes JSON from inside the sw/, not here using UNO
+    if (doc_getDocumentType(pThis) != LOK_DOCTYPE_TEXT && xRedlinesSupplier.is())
     {
         uno::Reference<container::XEnumeration> xRedlines = xRedlinesSupplier->getRedlines()->createEnumeration();
         boost::property_tree::ptree aRedlines;
diff --git a/sw/inc/IDocumentRedlineAccess.hxx b/sw/inc/IDocumentRedlineAccess.hxx
index 757394ded765..5488f7fcd66d 100644
--- a/sw/inc/IDocumentRedlineAccess.hxx
+++ b/sw/inc/IDocumentRedlineAccess.hxx
@@ -80,6 +80,21 @@ namespace nsRedlineType_t
     // When larger than 128, flags can be inserted.
     const RedlineType_t REDLINE_NO_FLAG_MASK = 0x7F;
     const RedlineType_t REDLINE_FORM_AUTOFMT = 0x80;// Can be a flag in RedlineType.
+
+    inline OUString SwRedlineTypeToOUString(RedlineType_t eType)
+    {
+        OUString sRet;
+        switch(eType & nsRedlineType_t::REDLINE_NO_FLAG_MASK)
+        {
+            case nsRedlineType_t::REDLINE_INSERT: sRet = "Insert"; break;
+            case nsRedlineType_t::REDLINE_DELETE: sRet = "Delete"; break;
+            case nsRedlineType_t::REDLINE_FORMAT: sRet = "Format"; break;
+            case nsRedlineType_t::REDLINE_PARAGRAPH_FORMAT: sRet = "ParagraphFormat"; break;
+            case nsRedlineType_t::REDLINE_TABLE:  sRet = "TextTable"; break;
+            case nsRedlineType_t::REDLINE_FMTCOLL:sRet = "Style"; break;
+        }
+        return sRet;
+    }
 }
 
 class IDocumentRedlineAccess
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index 03a338e4ed37..0560b41a04c9 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -438,6 +438,8 @@ public:
     virtual void setClientVisibleArea(const Rectangle& rRectangle) override;
     /// @see vcl::ITiledRenderable::getPointer().
     virtual Pointer getPointer() override;
+    /// @see vcl::ITiledRenderable::getTrackedChanges().
+    OUString getTrackedChanges() override;
     /// @see vcl::ITiledRenderable::getTrackedChangeAuthors().
     OUString getTrackedChangeAuthors() override;
     /// @see vcl::ITiledRenderable::getPostIts().
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index 868fd19e595a..abadabe28084 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -315,7 +315,7 @@ static void lcl_RedlineNotification(RedlineNotification nType, size_t nPos, SwRa
                              (nType == RedlineNotification::Modify ? "Modify" : "???"))));
     aRedline.put("index", nPos);
     aRedline.put("author", pRedline->GetAuthorString(1).toUtf8().getStr());
-    aRedline.put("type", SwRedlineTypeToOUString(pRedline->GetRedlineData().GetType()).toUtf8().getStr());
+    aRedline.put("type", nsRedlineType_t::SwRedlineTypeToOUString(pRedline->GetRedlineData().GetType()).toUtf8().getStr());
     aRedline.put("comment", pRedline->GetRedlineData().GetComment().toUtf8().getStr());
     aRedline.put("description", pRedline->GetDescr().toUtf8().getStr());
     OUString sDateTime = utl::toISO8601(pRedline->GetRedlineData().GetTimeStamp().GetUNODateTime());
diff --git a/sw/source/core/inc/unoport.hxx b/sw/source/core/inc/unoport.hxx
index fa82c830c06c..a01a73c902d6 100644
--- a/sw/source/core/inc/unoport.hxx
+++ b/sw/source/core/inc/unoport.hxx
@@ -306,8 +306,6 @@ public:
                 css::uno::RuntimeException, std::exception) override;
 };
 
-OUString SwRedlineTypeToOUString(RedlineType_t eType);
-
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/unocore/unoredline.cxx b/sw/source/core/unocore/unoredline.cxx
index 3e38c6b9e8f4..42497ef799e7 100644
--- a/sw/source/core/unocore/unoredline.cxx
+++ b/sw/source/core/unocore/unoredline.cxx
@@ -189,21 +189,6 @@ SwXRedlinePortion::~SwXRedlinePortion()
 {
 }
 
-OUString SwRedlineTypeToOUString(RedlineType_t eType)
-{
-    OUString sRet;
-    switch(eType & nsRedlineType_t::REDLINE_NO_FLAG_MASK)
-    {
-        case nsRedlineType_t::REDLINE_INSERT: sRet = "Insert"; break;
-        case nsRedlineType_t::REDLINE_DELETE: sRet = "Delete"; break;
-        case nsRedlineType_t::REDLINE_FORMAT: sRet = "Format"; break;
-        case nsRedlineType_t::REDLINE_PARAGRAPH_FORMAT: sRet = "ParagraphFormat"; break;
-        case nsRedlineType_t::REDLINE_TABLE:  sRet = "TextTable"; break;
-        case nsRedlineType_t::REDLINE_FMTCOLL:sRet = "Style"; break;
-    }
-    return sRet;
-}
-
 static uno::Sequence<beans::PropertyValue> lcl_GetSuccessorProperties(const SwRangeRedline& rRedline)
 {
     uno::Sequence<beans::PropertyValue> aValues(4);
@@ -221,7 +206,7 @@ static uno::Sequence<beans::PropertyValue> lcl_GetSuccessorProperties(const SwRa
         pValues[2].Name = UNO_NAME_REDLINE_COMMENT;
         pValues[2].Value <<= pNext->GetComment();
         pValues[3].Name = UNO_NAME_REDLINE_TYPE;
-        pValues[3].Value <<= SwRedlineTypeToOUString(pNext->GetType());
+        pValues[3].Value <<= nsRedlineType_t::SwRedlineTypeToOUString(pNext->GetType());
     }
     return aValues;
 }
@@ -291,7 +276,7 @@ uno::Any  SwXRedlinePortion::GetPropertyValue( const OUString& rPropertyName, co
         aRet <<= const_cast<SwRangeRedline&>(rRedline).GetDescr();
     else if(rPropertyName == UNO_NAME_REDLINE_TYPE)
     {
-        aRet <<= SwRedlineTypeToOUString(rRedline.GetType());
+        aRet <<= nsRedlineType_t::SwRedlineTypeToOUString(rRedline.GetType());
     }
     else if(rPropertyName == UNO_NAME_REDLINE_SUCCESSOR_DATA)
     {
@@ -331,7 +316,7 @@ uno::Sequence< beans::PropertyValue > SwXRedlinePortion::CreateRedlineProperties
     pRet[nPropIdx].Name = UNO_NAME_REDLINE_DESCRIPTION;
     pRet[nPropIdx++].Value <<= const_cast<SwRangeRedline&>(rRedline).GetDescr();
     pRet[nPropIdx].Name = UNO_NAME_REDLINE_TYPE;
-    pRet[nPropIdx++].Value <<= SwRedlineTypeToOUString(rRedline.GetType());
+    pRet[nPropIdx++].Value <<= nsRedlineType_t::SwRedlineTypeToOUString(rRedline.GetType());
     pRet[nPropIdx].Name = UNO_NAME_REDLINE_IDENTIFIER;
     pRet[nPropIdx++].Value <<= OUString::number(
         sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(&rRedline) ) );
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index b89e6e8bcfda..add15faaf543 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -144,6 +144,7 @@
 #include <svl/stylepool.hxx>
 #include <swatrset.hxx>
 #include <view.hxx>
+#include <viscrs.hxx>
 #include <srcview.hxx>
 #include <edtwin.hxx>
 #include <swdtflvr.hxx>
@@ -3232,6 +3233,52 @@ Pointer SwXTextDocument::getPointer()
     return pWrtShell->GetView().GetEditWin().GetPointer();
 }
 
+OUString SwXTextDocument::getTrackedChanges()
+{
+    const SwRedlineTable& rRedlineTable = pDocShell->GetDoc()->getIDocumentRedlineAccess().GetRedlineTable();
+    boost::property_tree::ptree aTrackedChanges;
+    for (SwRedlineTable::size_type i = 0; i < rRedlineTable.size(); ++i)
+    {
+        boost::property_tree::ptree aTrackedChange;
+        aTrackedChange.put("index", i);
+        aTrackedChange.put("author", rRedlineTable[i]->GetAuthorString(1).toUtf8().getStr());
+        aTrackedChange.put("type", nsRedlineType_t::SwRedlineTypeToOUString(rRedlineTable[i]->GetRedlineData().GetType()).toUtf8().getStr());
+        aTrackedChange.put("comment", rRedlineTable[i]->GetRedlineData().GetComment().toUtf8().getStr());
+        aTrackedChange.put("description", rRedlineTable[i]->GetDescr().toUtf8().getStr());
+        OUString sDateTime = utl::toISO8601(rRedlineTable[i]->GetRedlineData().GetTimeStamp().GetUNODateTime());
+        aTrackedChange.put("dateTime", sDateTime.toUtf8().getStr());
+
+        SwContentNode* pContentNd = rRedlineTable[i]->GetContentNode();
+        SwView* pView = dynamic_cast<SwView*>(SfxViewShell::Current());
+        if (pView && pContentNd)
+        {
+            std::unique_ptr<SwShellCursor> pCursor(new SwShellCursor(pView->GetWrtShell(), *(rRedlineTable[i]->Start()) ));
+            pCursor->SetMark();
+            pCursor->GetMark()->nNode = *pContentNd;
+            pCursor->GetMark()->nContent.Assign(pContentNd, rRedlineTable[i]->End()->nContent.GetIndex());
+
+            pCursor->FillRects();
+
+            SwRects* pRects(pCursor.get());
+            std::vector<OString> aRects;
+            for(SwRect& rNextRect : *pRects)
+                aRects.push_back(rNextRect.SVRect().toString());
+
+            const OString sRects = comphelper::string::join("; ", aRects);
+            aTrackedChange.put("textRange", sRects.getStr());
+        }
+
+        aTrackedChanges.push_back(std::make_pair("", aTrackedChange));
+    }
+
+    boost::property_tree::ptree aTree;
+    aTree.add_child("redlines", aTrackedChanges);
+    std::stringstream aStream;
+    boost::property_tree::write_json(aStream, aTree);
+
+    return OUString::fromUtf8(aStream.str().c_str());
+}
+
 OUString SwXTextDocument::getTrackedChangeAuthors()
 {
     return SW_MOD()->GetRedlineAuthorInfo();
commit 98de85d176fe2a8d77ea55e1f972d92722c5c471
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Fri Mar 3 13:17:39 2017 +0530

    lok: Create change tracking position too
    
    We want to expose change tracking comments to lok clients also. For
    this, lok clients needs to know the position in the document where the
    comment should be shown.
    
    Change-Id: I38794387cef3d11b5e0c1cfd0967408d8e54ded3
    Reviewed-on: https://gerrit.libreoffice.org/34949
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: pranavk <pranavk at collabora.co.uk>
    (cherry picked from commit 9582fae07e9ea2df20a7265c62402180995c57da)

diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index fe20071a3441..868fd19e595a 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -28,6 +28,7 @@
 #include <editeng/udlnitem.hxx>
 #include <editeng/crossedoutitem.hxx>
 #include <comphelper/lok.hxx>
+#include <comphelper/string.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <unotools/datetime.hxx>
 #include <sfx2/viewsh.hxx>
@@ -49,11 +50,13 @@
 #include <hints.hxx>
 #include <pamtyp.hxx>
 #include <poolfmt.hxx>
+#include <view.hxx>
 #include <viewsh.hxx>
+#include <viscrs.hxx>
 #include <rootfrm.hxx>
-
 #include <comcore.hrc>
 #include <unoport.hxx>
+#include <wrtsh.hxx>
 
 using namespace com::sun::star;
 
@@ -317,6 +320,29 @@ static void lcl_RedlineNotification(RedlineNotification nType, size_t nPos, SwRa
     aRedline.put("description", pRedline->GetDescr().toUtf8().getStr());
     OUString sDateTime = utl::toISO8601(pRedline->GetRedlineData().GetTimeStamp().GetUNODateTime());
     aRedline.put("dateTime", sDateTime.toUtf8().getStr());
+
+    SwPosition* pStartPos = pRedline->Start();
+    SwPosition* pEndPos = pRedline->End();
+    SwContentNode* pContentNd = pRedline->GetContentNode();
+    SwView* pView = dynamic_cast<SwView*>(SfxViewShell::Current());
+    if (pView && pContentNd)
+    {
+        std::unique_ptr<SwShellCursor> pCursor(new SwShellCursor(pView->GetWrtShell(), *pStartPos));
+        pCursor->SetMark();
+        pCursor->GetMark()->nNode = *pContentNd;
+        pCursor->GetMark()->nContent.Assign(pContentNd, pEndPos->nContent.GetIndex());
+
+        pCursor->FillRects();
+
+        SwRects* pRects(pCursor.get());
+        std::vector<OString> aRects;
+        for(SwRect& rNextRect : *pRects)
+            aRects.push_back(rNextRect.SVRect().toString());
+
+        const OString sRects = comphelper::string::join("; ", aRects);
+        aRedline.put("textRange", sRects.getStr());
+    }
+
     boost::property_tree::ptree aTree;
     aTree.add_child("redline", aRedline);
     std::stringstream aStream;
@@ -1788,4 +1814,3 @@ SwTableCellRedline::~SwTableCellRedline()
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
-
commit 27c0e2b48fb01d1916134d72c3ee0e2dbf650510
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Wed Mar 1 17:32:08 2017 +0530

    lok: Allow changing comment text of document redlines
    
    The id of the redline is optional. If not mentioned, the current redline
    is assumed to be the one whose comment text will be changed.
    
    Change-Id: Ia859de171603239a78f4bdef5eff0facd580d027
    Reviewed-on: https://gerrit.libreoffice.org/34923
    Reviewed-by: pranavk <pranavk at collabora.co.uk>
    Tested-by: pranavk <pranavk at collabora.co.uk>
    (cherry picked from commit c3d1be64e882f7e0edd0e693b9f73a0556bcb003)

diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi
index 2d7596b5873e..aef5641d26c0 100644
--- a/sw/sdi/swriter.sdi
+++ b/sw/sdi/swriter.sdi
@@ -663,7 +663,7 @@ SfxVoidItem ClosePreview FN_CLOSE_PAGEPREVIEW
 ]
 
 SfxVoidItem CommentChangeTracking FN_REDLINE_COMMENT
-()
+(SfxUInt16Item ChangeTrackingId FN_REDLINE_COMMENT,SvxPostItTextItem Text SID_ATTR_POSTIT_TEXT)
 [
     AutoUpdate = FALSE,
     FastCall = FALSE,
diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx
index b4c296bf1d0d..ed4224c4b7bb 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -511,9 +511,41 @@ void SwTextShell::ExecField(SfxRequest &rReq)
                 */
 
                 const SwRangeRedline *pRedline = rSh.GetCurrRedline();
+                SwDoc *pDoc = rSh.GetDoc();
+                SwRedlineTable::size_type nRedline = SwRedlineTable::npos;
+                if (pArgs && pArgs->GetItemState(nSlot, false, &pItem) == SfxItemState::SET)
+                {
+                    //TODO: SfxUInt16Item vs. SwRedlineTable::size_type mismatch:
+                    nRedline = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
+                    if (nRedline == USHRT_MAX)
+                        nRedline = SwRedlineTable::npos;
+
+                    if (nRedline != SwRedlineTable::npos)
+                    {
+                        // If index is specified, goto and select the appropriate redline
+                        const SwRedlineTable& rTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable();
+                        if (nRedline < rTable.size())
+                            pRedline = rSh.GotoRedline(nRedline, true);
+                    }
+                }
+
+                OUString sCommentText;
+                const SfxStringItem* pTextItem = rReq.GetArg<SvxPostItTextItem>(SID_ATTR_POSTIT_TEXT);
+                if (pTextItem)
+                    sCommentText = pTextItem->GetValue();
 
                 if (pRedline)
                 {
+                    // In case of LOK and comment text is already provided, skip
+                    // dialog creation and just change the redline comment directly
+                    if (comphelper::LibreOfficeKit::isActive() && !sCommentText.isEmpty())
+                    {
+                        rSh.SetRedlineComment(sCommentText);
+                        GetView().AttrChangedNotify(GetShellPtr());
+                        const_cast<SwRangeRedline*>(pRedline)->MaybeNotifyModification();
+                        break;
+                    }
+
                     OUString sComment = convertLineEnd(pRedline->GetComment(), GetSystemLineEnd());
 
                     bool bTravel = false;
@@ -813,7 +845,7 @@ void SwTextShell::StateField( SfxItemSet &rSet )
             break;
 
         case FN_REDLINE_COMMENT:
-            if (!rSh.GetCurrRedline())
+            if (!comphelper::LibreOfficeKit::isActive() && !rSh.GetCurrRedline())
                 rSet.DisableItem(nWhich);
             break;
 
commit 7a01976d04390e29457153148648756849d667b9
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Fri Mar 3 13:42:50 2017 +0530

    sw: Bin unused vector
    
    Change-Id: I948d07c178344b66ea91eddf5771dc65b3ea9d30
    (cherry picked from commit 09b56c34fa6651083c7b2a2973c7ca3986d7a50b)

diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index 85fc5e56d315..5538be92f7f3 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -924,12 +924,9 @@ void SwSidebarWin::SetPosAndSize()
                 EditWin().EnableMapMode();
 
             SwRects* pRects(pTmpCursorForAnnotationTextRange.get());
-            std::vector<OString> aRects;
             for(SwRect & rNextRect : *pRects)
             {
-                aRects.push_back(rNextRect.SVRect().toString());
                 const Rectangle aPntRect(rNextRect.SVRect());
-
                 maAnnotationTextRanges.push_back(basegfx::B2DRange(
                     aPntRect.Left(), aPntRect.Top(),
                     aPntRect.Right() + 1, aPntRect.Bottom() + 1));
commit f5ccb5d646dc50e3639d54044e50f8a974825e90
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Wed Mar 1 15:20:53 2017 +0530

    lok: Listen to change tracking related commands
    
    Change-Id: Ieafd31342b356d7e95e4321cc49580b57f32e5be
    (cherry picked from commit 67dad2676dbbe1557f51a4fb16975499c16829f5)

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index dcadea6426bb..b462c1684f6b 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1522,7 +1522,9 @@ static void doc_iniUnoCommands ()
         OUString(".uno:SortAscending"),
         OUString(".uno:SortDescending"),
         OUString(".uno:TrackChanges"),
-        OUString(".uno:AcceptTrackedChange"),
+        OUString(".uno:ShowTrackedChanges"),
+        OUString(".uno:NextTrackedChange"),
+        OUString(".uno:PreviousTrackedChange")
     };
 
     util::URL aCommandURL;
diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx
index 40455e150b4a..10df8e1f08dd 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -998,7 +998,9 @@ static void InterceptLOKStateChangeEvent(const SfxViewFrame* pViewFrame, const c
         aEvent.FeatureURL.Path == "Underline" ||
         aEvent.FeatureURL.Path == "ModifiedStatus" ||
         aEvent.FeatureURL.Path == "TrackChanges" ||
-        aEvent.FeatureURL.Path == "AcceptTrackedChange" ||
+        aEvent.FeatureURL.Path == "ShowTrackedChanges" ||
+        aEvent.FeatureURL.Path == "NextTrackedChange" ||
+        aEvent.FeatureURL.Path == "PreviousTrackedChange" ||
         aEvent.FeatureURL.Path == "AlignLeft" ||
         aEvent.FeatureURL.Path == "AlignHorizontalCenter" ||
         aEvent.FeatureURL.Path == "AlignRight")


More information about the Libreoffice-commits mailing list