summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-09-26 14:18:17 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-09-26 14:20:11 +0200
commitb9cc6653606c829805c6c01b9613a3a25d81c20b (patch)
tree30dcf0be8e3efcd80084c060015d98bd678149f6
parent5bc4bcfde4955e3e48255310500102775ba4af23 (diff)
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
-rw-r--r--desktop/qa/desktop_lib/test_desktop_lib.cxx48
-rw-r--r--sw/source/core/crsr/viscrs.cxx10
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 <sfx2/viewsh.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/bindings.hxx>
+#include <comphelper/string.hxx>
#include <cairo.h>
#include <lib/init.hxx>
@@ -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<lang::XComponent> 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<ViewCallback*>(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<OUString> aSeq = comphelper::string::convertCommaSeparated(OUString::fromUtf8(aPayload));
+ if (OString("EMPTY") == pPayload)
+ return;
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(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 <sfx2/lokhelper.hxx>
#include <comphelper/string.hxx>
#include <paintfrm.hxx>
+#include <PostItMgr.hxx>
// 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<SwView*>(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;