From b9cc6653606c829805c6c01b9613a3a25d81c20b Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 26 Sep 2016 14:18:17 +0200 Subject: sw lok: fix cursor position after inserting a comment Make sure SwVisibleCursor::SetPosAndShow() doesn't emit LOK callbacks till a comment window is active. Need to invoke the unit test from desktop/, as the sw tests have the status bar disabled. Change-Id: Iab26024e9bb4da9c939bbd6cf769ec5c4dcb9a19 --- desktop/qa/desktop_lib/test_desktop_lib.cxx | 48 ++++++++++++++++++++++++++++- sw/source/core/crsr/viscrs.cxx | 10 +++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index a7e24fcd7255..3456576c63e0 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -100,6 +101,7 @@ public: void testTrackChanges(); void testRedlineCalc(); void testPaintPartTile(); + void testWriterCommentInsertCursor(); CPPUNIT_TEST_SUITE(DesktopLOKTest); CPPUNIT_TEST(testGetStyles); @@ -131,6 +133,7 @@ public: CPPUNIT_TEST(testTrackChanges); CPPUNIT_TEST(testRedlineCalc); CPPUNIT_TEST(testPaintPartTile); + CPPUNIT_TEST(testWriterCommentInsertCursor); CPPUNIT_TEST_SUITE_END(); uno::Reference mxComponent; @@ -1484,6 +1487,7 @@ class ViewCallback { public: bool m_bTilesInvalidated; + Rectangle m_aOwnCursor; ViewCallback() : m_bTilesInvalidated(false) @@ -1495,8 +1499,9 @@ public: static_cast(pData)->callbackImpl(nType, pPayload); } - void callbackImpl(int nType, const char* /*pPayload*/) + void callbackImpl(int nType, const char* pPayload) { + OString aPayload(pPayload); switch (nType) { case LOK_CALLBACK_INVALIDATE_TILES: @@ -1504,6 +1509,18 @@ public: m_bTilesInvalidated = true; } break; + case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR: + { + uno::Sequence aSeq = comphelper::string::convertCommaSeparated(OUString::fromUtf8(aPayload)); + if (OString("EMPTY") == pPayload) + return; + CPPUNIT_ASSERT_EQUAL(static_cast(4), aSeq.getLength()); + m_aOwnCursor.setX(aSeq[0].toInt32()); + m_aOwnCursor.setY(aSeq[1].toInt32()); + m_aOwnCursor.setWidth(aSeq[2].toInt32()); + m_aOwnCursor.setHeight(aSeq[3].toInt32()); + } + break; } } }; @@ -1552,6 +1569,35 @@ void DesktopLOKTest::testPaintPartTile() mxComponent.clear(); comphelper::LibreOfficeKit::setActive(false); } + +void DesktopLOKTest::testWriterCommentInsertCursor() +{ + // Load a document and type a character into the body text. + comphelper::LibreOfficeKit::setActive(); + LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); + pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}"); + ViewCallback aView1; + pDocument->m_pDocumentClass->registerCallback(pDocument, &ViewCallback::callback, &aView1); + pDocument->m_pDocumentClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 'x', 0); + pDocument->m_pDocumentClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, 'x', 0); + Scheduler::ProcessEventsToIdle(); + Rectangle aBodyCursor = aView1.m_aOwnCursor; + + // Now insert a comment and make sure that the comment's cursor is shown, + // not the body text's one. + const int nCtrlAltC = KEY_MOD1 + KEY_MOD2 + 512 + 'c' - 'a'; + pDocument->m_pDocumentClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 'c', nCtrlAltC); + pDocument->m_pDocumentClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, 'c', nCtrlAltC); + Scheduler::ProcessEventsToIdle(); + // Wait for SfxBindings to actually update the state, which updated the + // cursor as well. + osl::Thread::wait(std::chrono::seconds(1)); + Scheduler::ProcessEventsToIdle(); + // This failed: the body cursor was shown right after inserting a comment. + CPPUNIT_ASSERT(aView1.m_aOwnCursor.getX() > aBodyCursor.getX()); + comphelper::LibreOfficeKit::setActive(false); +} + CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx index 0e848b88a859..7a886e964c21 100644 --- a/sw/source/core/crsr/viscrs.cxx +++ b/sw/source/core/crsr/viscrs.cxx @@ -59,6 +59,7 @@ #include #include #include +#include // Here static members are defined. They will get changed on alteration of the // MapMode. This is done so that on ShowCursor the same size does not have to be @@ -182,7 +183,14 @@ void SwVisibleCursor::SetPosAndShow(SfxViewShell* pViewShell) m_aTextCursor.SetPos( aRect.Pos() ); - if (comphelper::LibreOfficeKit::isActive()) + bool bPostItActive = false; + if (auto pView = dynamic_cast(m_pCursorShell->GetSfxViewShell())) + { + if (SwPostItMgr* pPostItMgr = pView->GetPostItMgr()) + bPostItActive = pPostItMgr->GetActiveSidebarWin() != nullptr; + } + + if (comphelper::LibreOfficeKit::isActive() && !bPostItActive) { // notify about page number change (if that happened) sal_uInt16 nPage, nVirtPage; -- cgit