diff options
author | Pranav Kant <pranavk@collabora.co.uk> | 2017-03-14 15:27:42 +0530 |
---|---|---|
committer | Pranav Kant <pranavk@collabora.co.uk> | 2017-03-23 20:30:55 +0530 |
commit | c0166f03bf3ab64682b7a12b519551acb8e80726 (patch) | |
tree | 401c0fe3956e2c5c0cac6b459a909ff1a6efad4d /sw | |
parent | d5b15909bf65e456920e286bee1801c3916f19fc (diff) |
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@collabora.co.uk>
Tested-by: pranavk <pranavk@collabora.co.uk>
(cherry picked from commit 1eb69f6b9c78b19d3944c90c17ff8d498affc316)
Conflicts:
sw/source/core/doc/docredln.cxx
Change-Id: Ifbd6014198838b1106e873c9563d215e95b3572d
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/docary.hxx | 6 | ||||
-rw-r--r-- | sw/qa/extras/tiledrendering/tiledrendering.cxx | 20 | ||||
-rw-r--r-- | sw/source/core/doc/docredln.cxx | 14 | ||||
-rw-r--r-- | sw/source/core/txtnode/ndtxt.cxx | 24 |
4 files changed, 56 insertions, 8 deletions
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, |