Kaydet (Commit) 45fa73f8 authored tarafından Miklos Vajna's avatar Miklos Vajna

sw: avoid emitting invalid cursor pos during end text edit of comment

A comment text edit (provided by editeng) works with relative twip
coordinates, conversion of the cursor position to absolute twips happens
in ImpEditView::ShowCursor(), provided that the pOutWin member has a map
mode origin that respresents the offset correctly.

This is not true during SwSidebarWin::DeactivatePostIt(), the map mode
origin is already reset back to 0, so just don't emit callbacks during
shutdown, the sw body text cursor will be shown later anyway.

Change-Id: I02c15bb9fad99db8e43fd2f37df770dd165be788
üst d3ab1f84
...@@ -331,6 +331,8 @@ public: ...@@ -331,6 +331,8 @@ public:
void setTiledSearching(bool bTiledSearching); void setTiledSearching(bool bTiledSearching);
/// Set if we are doing tiled painting. /// Set if we are doing tiled painting.
void setTiledPainting(bool bTiledPainting); void setTiledPainting(bool bTiledPainting);
/// Get if we are doing tiled painting.
bool getTiledPainting() const;
/// See lok::Document::getPart(). /// See lok::Document::getPart().
virtual int getPart() const; virtual int getPart() const;
virtual void dumpAsXml(struct _xmlTextWriter* pWriter) const; virtual void dumpAsXml(struct _xmlTextWriter* pWriter) const;
......
...@@ -1508,6 +1508,11 @@ void SfxViewShell::setTiledPainting(bool bTiledPainting) ...@@ -1508,6 +1508,11 @@ void SfxViewShell::setTiledPainting(bool bTiledPainting)
pImpl->m_bTiledPainting = bTiledPainting; pImpl->m_bTiledPainting = bTiledPainting;
} }
bool SfxViewShell::getTiledPainting() const
{
return pImpl->m_bTiledPainting;
}
int SfxViewShell::getPart() const int SfxViewShell::getPart() const
{ {
return 0; return 0;
......
...@@ -75,6 +75,7 @@ public: ...@@ -75,6 +75,7 @@ public:
void testCreateViewGraphicSelection(); void testCreateViewGraphicSelection();
void testCreateViewTextSelection(); void testCreateViewTextSelection();
void testRedlineColors(); void testRedlineColors();
void testCommentEndTextEdit();
CPPUNIT_TEST_SUITE(SwTiledRenderingTest); CPPUNIT_TEST_SUITE(SwTiledRenderingTest);
CPPUNIT_TEST(testRegisterCallback); CPPUNIT_TEST(testRegisterCallback);
...@@ -114,10 +115,11 @@ public: ...@@ -114,10 +115,11 @@ public:
CPPUNIT_TEST(testCreateViewGraphicSelection); CPPUNIT_TEST(testCreateViewGraphicSelection);
CPPUNIT_TEST(testCreateViewTextSelection); CPPUNIT_TEST(testCreateViewTextSelection);
CPPUNIT_TEST(testRedlineColors); CPPUNIT_TEST(testRedlineColors);
CPPUNIT_TEST(testCommentEndTextEdit);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
SwXTextDocument* createDoc(const char* pName); SwXTextDocument* createDoc(const char* pName = nullptr);
static void callback(int nType, const char* pPayload, void* pData); static void callback(int nType, const char* pPayload, void* pData);
void callbackImpl(int nType, const char* pPayload); void callbackImpl(int nType, const char* pPayload);
Rectangle m_aInvalidation; Rectangle m_aInvalidation;
...@@ -147,7 +149,10 @@ SwTiledRenderingTest::SwTiledRenderingTest() ...@@ -147,7 +149,10 @@ SwTiledRenderingTest::SwTiledRenderingTest()
SwXTextDocument* SwTiledRenderingTest::createDoc(const char* pName) SwXTextDocument* SwTiledRenderingTest::createDoc(const char* pName)
{ {
load(DATA_DIRECTORY, pName); if (!pName)
loadURL("private:factory/swriter", nullptr);
else
load(DATA_DIRECTORY, pName);
SwXTextDocument* pTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get()); SwXTextDocument* pTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDocument); CPPUNIT_ASSERT(pTextDocument);
...@@ -621,6 +626,7 @@ class ViewCallback ...@@ -621,6 +626,7 @@ class ViewCallback
{ {
public: public:
bool m_bOwnCursorInvalidated; bool m_bOwnCursorInvalidated;
bool m_bOwnCursorAtOrigin;
Rectangle m_aOwnCursor; Rectangle m_aOwnCursor;
bool m_bViewCursorInvalidated; bool m_bViewCursorInvalidated;
Rectangle m_aViewCursor; Rectangle m_aViewCursor;
...@@ -635,6 +641,7 @@ public: ...@@ -635,6 +641,7 @@ public:
ViewCallback() ViewCallback()
: m_bOwnCursorInvalidated(false), : m_bOwnCursorInvalidated(false),
m_bOwnCursorAtOrigin(false),
m_bViewCursorInvalidated(false), m_bViewCursorInvalidated(false),
m_bOwnSelectionSet(false), m_bOwnSelectionSet(false),
m_bViewSelectionSet(false), m_bViewSelectionSet(false),
...@@ -673,6 +680,8 @@ public: ...@@ -673,6 +680,8 @@ public:
m_aOwnCursor.setY(aSeq[1].toInt32()); m_aOwnCursor.setY(aSeq[1].toInt32());
m_aOwnCursor.setWidth(aSeq[2].toInt32()); m_aOwnCursor.setWidth(aSeq[2].toInt32());
m_aOwnCursor.setHeight(aSeq[3].toInt32()); m_aOwnCursor.setHeight(aSeq[3].toInt32());
if (m_aOwnCursor.getX() == 0 && m_aOwnCursor.getY() == 0)
m_bOwnCursorAtOrigin = true;
} }
break; break;
case LOK_CALLBACK_INVALIDATE_VIEW_CURSOR: case LOK_CALLBACK_INVALIDATE_VIEW_CURSOR:
...@@ -1460,6 +1469,40 @@ void SwTiledRenderingTest::testRedlineColors() ...@@ -1460,6 +1469,40 @@ void SwTiledRenderingTest::testRedlineColors()
comphelper::LibreOfficeKit::setActive(false); comphelper::LibreOfficeKit::setActive(false);
} }
void SwTiledRenderingTest::testCommentEndTextEdit()
{
// Create a document, type a character and remember the cursor position.
comphelper::LibreOfficeKit::setActive();
SwXTextDocument* pXTextDocument = createDoc();
ViewCallback aView1;
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'x', 0);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'x', 0);
Rectangle aBodyCursor = aView1.m_aOwnCursor;
// Create a comment and type a character there as well.
const int nCtrlAltC = KEY_MOD1 + KEY_MOD2 + 512 + 'c' - 'a';
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'c', nCtrlAltC);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'c', nCtrlAltC);
Scheduler::ProcessEventsToIdle();
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'x', 0);
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'x', 0);
// End comment text edit by clicking in the body text area, and assert that
// no unexpected cursor callbacks are emitted at origin (top left corner of
// the document).
aView1.m_bOwnCursorAtOrigin = false;
pXTextDocument->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONDOWN, aBodyCursor.getX(), aBodyCursor.getY(), 1, MOUSE_LEFT, 0);
pXTextDocument->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONUP, aBodyCursor.getX(), aBodyCursor.getY(), 1, MOUSE_LEFT, 0);
// This failed, the cursor was at 0, 0 at some point during end text edit
// of the comment.
CPPUNIT_ASSERT(!aView1.m_bOwnCursorAtOrigin);
mxComponent->dispose();
mxComponent.clear();
comphelper::LibreOfficeKit::setActive(false);
}
CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest); CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest);
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
......
...@@ -1260,8 +1260,14 @@ void SwSidebarWin::DeactivatePostIt() ...@@ -1260,8 +1260,14 @@ void SwSidebarWin::DeactivatePostIt()
mpOutliner->CompleteOnlineSpelling(); mpOutliner->CompleteOnlineSpelling();
SetViewState(ViewState::NORMAL); SetViewState(ViewState::NORMAL);
// Make sure this view doesn't emit LOK callbacks during the update, as the
// sidebar window's SidebarTextControl doesn't have a valid twip offset
// (map mode origin) during that operation.
bool bTiledPainting = mrView.getTiledPainting();
mrView.setTiledPainting(true);
// write the visible text back into the SwField // write the visible text back into the SwField
UpdateData(); UpdateData();
mrView.setTiledPainting(bTiledPainting);
if ( !Application::GetSettings().GetStyleSettings().GetHighContrastMode() ) if ( !Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
GetOutlinerView()->SetBackgroundColor(COL_TRANSPARENT); GetOutlinerView()->SetBackgroundColor(COL_TRANSPARENT);
......
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