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
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
#include <sfx2/viewsh.hxx>
|
#include <sfx2/viewsh.hxx>
|
||||||
#include <sfx2/viewfrm.hxx>
|
#include <sfx2/viewfrm.hxx>
|
||||||
#include <sfx2/bindings.hxx>
|
#include <sfx2/bindings.hxx>
|
||||||
|
#include <comphelper/string.hxx>
|
||||||
#include <cairo.h>
|
#include <cairo.h>
|
||||||
|
|
||||||
#include <lib/init.hxx>
|
#include <lib/init.hxx>
|
||||||
@@ -100,6 +101,7 @@ public:
|
|||||||
void testTrackChanges();
|
void testTrackChanges();
|
||||||
void testRedlineCalc();
|
void testRedlineCalc();
|
||||||
void testPaintPartTile();
|
void testPaintPartTile();
|
||||||
|
void testWriterCommentInsertCursor();
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE(DesktopLOKTest);
|
CPPUNIT_TEST_SUITE(DesktopLOKTest);
|
||||||
CPPUNIT_TEST(testGetStyles);
|
CPPUNIT_TEST(testGetStyles);
|
||||||
@@ -131,6 +133,7 @@ public:
|
|||||||
CPPUNIT_TEST(testTrackChanges);
|
CPPUNIT_TEST(testTrackChanges);
|
||||||
CPPUNIT_TEST(testRedlineCalc);
|
CPPUNIT_TEST(testRedlineCalc);
|
||||||
CPPUNIT_TEST(testPaintPartTile);
|
CPPUNIT_TEST(testPaintPartTile);
|
||||||
|
CPPUNIT_TEST(testWriterCommentInsertCursor);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
uno::Reference<lang::XComponent> mxComponent;
|
uno::Reference<lang::XComponent> mxComponent;
|
||||||
@@ -1484,6 +1487,7 @@ class ViewCallback
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool m_bTilesInvalidated;
|
bool m_bTilesInvalidated;
|
||||||
|
Rectangle m_aOwnCursor;
|
||||||
|
|
||||||
ViewCallback()
|
ViewCallback()
|
||||||
: m_bTilesInvalidated(false)
|
: m_bTilesInvalidated(false)
|
||||||
@@ -1495,8 +1499,9 @@ public:
|
|||||||
static_cast<ViewCallback*>(pData)->callbackImpl(nType, pPayload);
|
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)
|
switch (nType)
|
||||||
{
|
{
|
||||||
case LOK_CALLBACK_INVALIDATE_TILES:
|
case LOK_CALLBACK_INVALIDATE_TILES:
|
||||||
@@ -1504,6 +1509,18 @@ public:
|
|||||||
m_bTilesInvalidated = true;
|
m_bTilesInvalidated = true;
|
||||||
}
|
}
|
||||||
break;
|
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();
|
mxComponent.clear();
|
||||||
comphelper::LibreOfficeKit::setActive(false);
|
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_TEST_SUITE_REGISTRATION(DesktopLOKTest);
|
||||||
|
|
||||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||||
|
@@ -59,6 +59,7 @@
|
|||||||
#include <sfx2/lokhelper.hxx>
|
#include <sfx2/lokhelper.hxx>
|
||||||
#include <comphelper/string.hxx>
|
#include <comphelper/string.hxx>
|
||||||
#include <paintfrm.hxx>
|
#include <paintfrm.hxx>
|
||||||
|
#include <PostItMgr.hxx>
|
||||||
|
|
||||||
// Here static members are defined. They will get changed on alteration of the
|
// 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
|
// 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() );
|
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)
|
// notify about page number change (if that happened)
|
||||||
sal_uInt16 nPage, nVirtPage;
|
sal_uInt16 nPage, nVirtPage;
|
||||||
|
Reference in New Issue
Block a user