Kaydet (Commit) b687cebf authored tarafından Tamás Zolnai's avatar Tamás Zolnai

bccu#3100: Writer: Change tracking boxes aren't repositioned with editing

Emit a notification related to the node position change, so the track changes
comment box is repositioned when the text node changes it's position.

Change-Id: I34b5ec453b3dc43895865f15d71aaead46ae6f24
Reviewed-on: https://gerrit.libreoffice.org/50640Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTamás Zolnai <tamas.zolnai@collabora.com>
üst ab63510e
......@@ -30,6 +30,8 @@
#include <cstddef>
#include <memory>
#include <vector>
#include <boost/optional.hpp>
class SfxItemSet;
class SwView;
......@@ -176,6 +178,8 @@ class SW_DLLPUBLIC SwRangeRedline : public SwPaM
bool bIsVisible : 1;
sal_uInt32 m_nId;
boost::optional<long> m_oLOKLastNodeTop;
void MoveToSection();
void CopyToSection();
void DelCopyOfSection(size_t nMyPos);
......@@ -274,6 +278,8 @@ public:
bool operator<( const SwRangeRedline& ) const;
void dumpAsXml(struct _xmlTextWriter* pWriter) const;
void MaybeNotifyRedlinePositionModification(long nTop);
};
SW_DLLPUBLIC void MaybeNotifyRedlineModification(SwRangeRedline* pRedline, SwDoc* pDoc);
......
......@@ -104,6 +104,8 @@ public:
void testTdf115088();
void testRedlineField();
void testIMESupport();
void testSplitNodeRedlineCallback();
void testDeleteNodeRedlineCallback();
CPPUNIT_TEST_SUITE(SwTiledRenderingTest);
CPPUNIT_TEST(testRegisterCallback);
......@@ -156,6 +158,8 @@ public:
CPPUNIT_TEST(testTdf115088);
CPPUNIT_TEST(testRedlineField);
CPPUNIT_TEST(testIMESupport);
CPPUNIT_TEST(testSplitNodeRedlineCallback);
CPPUNIT_TEST(testDeleteNodeRedlineCallback);
CPPUNIT_TEST_SUITE_END();
private:
......@@ -2150,6 +2154,128 @@ void SwTiledRenderingTest::testIMESupport()
comphelper::LibreOfficeKit::setActive(false);
}
void SwTiledRenderingTest::testSplitNodeRedlineCallback()
{
// Load a document.
comphelper::LibreOfficeKit::setActive();
SwXTextDocument* pXTextDocument = createDoc("splitnode_redline_callback.fodt");
SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
pWrtShell->GetSfxViewShell()->registerLibreOfficeKitViewCallback(&SwTiledRenderingTest::callback, this);
// 1. test case
// Move cursor between the two tracked changes
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN);
Scheduler::ProcessEventsToIdle();
// Add a new line
m_nRedlineTableEntryModified = 0;
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_RETURN);
Scheduler::ProcessEventsToIdle();
// Assert that we get a notification about redline modification
// The redline after the inserted node gets a different vertical positon
CPPUNIT_ASSERT_EQUAL(1, m_nRedlineTableEntryModified);
// 2. test case
// Move cursor back to the first line, so adding new line will affect both tracked changes
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_HOME | KEY_MOD1);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_HOME | KEY_MOD1);
Scheduler::ProcessEventsToIdle();
// Add a new line
m_nRedlineTableEntryModified = 0;
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_RETURN);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(2, m_nRedlineTableEntryModified);
// 3. test case
// Move cursor to the end of the document, so adding a new line won't affect any tracked changes
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_END | KEY_MOD1);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_END | KEY_MOD1);
Scheduler::ProcessEventsToIdle();
// Add a new line
m_nRedlineTableEntryModified = 0;
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_RETURN);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(0, m_nRedlineTableEntryModified);
comphelper::LibreOfficeKit::setActive(false);
}
void SwTiledRenderingTest::testDeleteNodeRedlineCallback()
{
// Load a document.
comphelper::LibreOfficeKit::setActive();
SwXTextDocument* pXTextDocument = createDoc("removenode_redline_callback.fodt");
SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
pWrtShell->GetSfxViewShell()->registerLibreOfficeKitViewCallback(&SwTiledRenderingTest::callback, this);
// 1. test case
// Move cursor between the two tracked changes
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN);
Scheduler::ProcessEventsToIdle();
// Remove one (empty) line
m_nRedlineTableEntryModified = 0;
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DELETE);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DELETE);
Scheduler::ProcessEventsToIdle();
// Assert that we get a notification about redline modification
// The redline after the removed node gets a different vertical positon
CPPUNIT_ASSERT_EQUAL(1, m_nRedlineTableEntryModified);
// 2. test case
// Move cursor back to the first line, so removing one line will affect both tracked changes
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_HOME | KEY_MOD1);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_HOME | KEY_MOD1);
Scheduler::ProcessEventsToIdle();
// Remove a new line
m_nRedlineTableEntryModified = 0;
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DELETE);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DELETE);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(2, m_nRedlineTableEntryModified);
// 3. test case
// Move cursor to the end of the document, so removing one line won't affect any tracked changes
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_END | KEY_MOD1);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_END | KEY_MOD1);
Scheduler::ProcessEventsToIdle();
// Remove a line
m_nRedlineTableEntryModified = 0;
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_BACKSPACE);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_BACKSPACE);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(0, m_nRedlineTableEntryModified);
comphelper::LibreOfficeKit::setActive(false);
}
CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest);
CPPUNIT_PLUGIN_IMPLEMENT();
......
......@@ -1083,6 +1083,18 @@ void MaybeNotifyRedlineModification(SwRangeRedline* pRedline, SwDoc* pDoc)
}
}
void SwRangeRedline::MaybeNotifyRedlinePositionModification(long nTop)
{
if (!comphelper::LibreOfficeKit::isActive())
return;
if(!m_oLOKLastNodeTop || *m_oLOKLastNodeTop != nTop)
{
m_oLOKLastNodeTop = nTop;
SwRedlineTable::LOKRedlineNotification(RedlineNotification::Modify, this);
}
}
void SwRangeRedline::SetStart( const SwPosition& rPos, SwPosition* pSttPtr )
{
if( !pSttPtr ) pSttPtr = Start();
......
......@@ -426,7 +426,7 @@ protected:
SwPageFrame *InsertPage( SwPageFrame *pSibling, bool bFootnote );
void PrepareMake(vcl::RenderContext* pRenderContext);
void OptPrepareMake();
void MakePos();
virtual void MakePos();
// Format next frame of table frame to assure keeping attributes.
// In case of nested tables method <SwFrame::MakeAll()> is called to
// avoid formatting of superior table frame.
......
......@@ -154,6 +154,8 @@ class SW_DLLPUBLIC SwTextFrame: public SwContentFrame
// Formats the Follow and ensures disposing on orphans
bool CalcFollow( const sal_Int32 nTextOfst );
virtual void MakePos() override;
// Corrects the position from which we need to format
static sal_Int32 FindBrk(const OUString &rText, const sal_Int32 nStart,
const sal_Int32 nEnd);
......
......@@ -52,6 +52,8 @@
#include "portab.hxx"
#include <editeng/lrspitem.hxx>
#include <editeng/tstpitem.hxx>
#include <redline.hxx>
#include <comphelper/lok.hxx>
// Tolerance in formatting and text output
#define SLOPPY_TWIPS 5
......@@ -343,6 +345,25 @@ bool SwTextFrame::CalcFollow( const sal_Int32 nTextOfst )
return false;
}
void SwTextFrame::MakePos()
{
SwFrame::MakePos();
// Inform LOK clients about change in position of redlines (if any)
if(comphelper::LibreOfficeKit::isActive())
{
const SwTextNode& rTextNode = *GetTextNode();
const SwRedlineTable& rTable = rTextNode.getIDocumentRedlineAccess().GetRedlineTable();
for (SwRedlineTable::size_type nRedlnPos = 0; nRedlnPos < rTable.size(); ++nRedlnPos)
{
SwRangeRedline* pRedln = rTable[nRedlnPos];
if (rTextNode.GetIndex() == pRedln->GetPoint()->nNode.GetNode().GetIndex())
{
pRedln->MaybeNotifyRedlinePositionModification(getFrameArea().Top());
}
}
}
}
void SwTextFrame::AdjustFrame( const SwTwips nChgHght, bool bHasToFit )
{
vcl::RenderContext* pRenderContext = getRootFrame()->GetCurrShell()->GetOut();
......
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