summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-09-13 16:48:05 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-09-13 16:48:28 +0200
commit586789fe757c0eb350c360a49cf90431a0bd5b24 (patch)
tree0ba705458d22b67b9665fc5ecb8ca969dc06e307 /sw
parent798d55fcd8efc10fcef6b8ac3fa5abdbc82501ec (diff)
sw draw text: emit LOK_CALLBACK_INVALIDATE_VIEW_CURSOR from registerCallback()
With this, in case the first view has an active text edit and a new view is created, then the cursor position is instantly visible in the second view, even if the first view's cursor does not move later. Change-Id: Ia82e7dc1ce9bb58c67a280179ecadc74d3b63026
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/tiledrendering/tiledrendering.cxx37
-rw-r--r--sw/source/core/crsr/crsrsh.cxx23
2 files changed, 54 insertions, 6 deletions
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index a2a88e17c868..0424fea85921 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -602,7 +602,9 @@ class ViewCallback
{
public:
bool m_bOwnCursorInvalidated;
+ Rectangle m_aOwnCursor;
bool m_bViewCursorInvalidated;
+ Rectangle m_aViewCursor;
bool m_bOwnSelectionSet;
bool m_bViewSelectionSet;
OString m_aViewSelection;
@@ -643,11 +645,33 @@ public:
case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
{
m_bOwnCursorInvalidated = true;
+
+ 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;
case LOK_CALLBACK_INVALIDATE_VIEW_CURSOR:
{
m_bViewCursorInvalidated = true;
+ std::stringstream aStream(pPayload);
+ boost::property_tree::ptree aTree;
+ boost::property_tree::read_json(aStream, aTree);
+ OString aRect = aTree.get_child("rectangle").get_value<std::string>().c_str();
+
+ uno::Sequence<OUString> aSeq = comphelper::string::convertCommaSeparated(OUString::fromUtf8(aRect));
+ if (OString("EMPTY") == pPayload)
+ return;
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4), aSeq.getLength());
+ m_aViewCursor.setX(aSeq[0].toInt32());
+ m_aViewCursor.setY(aSeq[1].toInt32());
+ m_aViewCursor.setWidth(aSeq[2].toInt32());
+ m_aViewCursor.setHeight(aSeq[3].toInt32());
}
break;
case LOK_CALLBACK_TEXT_SELECTION:
@@ -1148,6 +1172,8 @@ void SwTiledRenderingTest::testShapeTextUndoGroupShells()
// Load a document and create a view.
comphelper::LibreOfficeKit::setActive();
SwXTextDocument* pXTextDocument = createDoc("shape.fodt");
+ ViewCallback aView1;
+ SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
sal_Int32 nView1 = SfxLokHelper::getView();
// Begin text edit.
@@ -1168,6 +1194,17 @@ void SwTiledRenderingTest::testShapeTextUndoGroupShells()
// This was -1: the view shell id for the (top) undo list action wasn't known.
CPPUNIT_ASSERT_EQUAL(nView1, rUndoManager.GetUndoAction()->GetViewShellId());
+ // Create a second view, and make sure that the new view sees the same
+ // cursor position as the old one.
+ SfxLokHelper::createView();
+ pXTextDocument->initializeForTiledRendering({});
+ ViewCallback aView2;
+ aView2.m_aViewCursor = Rectangle();
+ SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
+ // Difference was 935 twips, the new view didn't see the editeng cursor of
+ // the old one. The new difference should be <1px, but here we deal with twips.
+ CPPUNIT_ASSERT(std::abs(aView1.m_aOwnCursor.Top() - aView2.m_aViewCursor.Top()) < 10);
+
mxComponent->dispose();
mxComponent.clear();
comphelper::LibreOfficeKit::setActive(false);
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 241d8d43ead8..fabf1533e3d0 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -66,6 +66,7 @@
#include <comphelper/lok.hxx>
#include <sfx2/lokhelper.hxx>
#include <comphelper/string.hxx>
+#include <editeng/editview.hxx>
#include <PostItMgr.hxx>
#include <DocumentSettingManager.hxx>
@@ -1194,13 +1195,23 @@ OUString SwCursorShell::getPageRectangles()
void SwCursorShell::NotifyCursor(SfxViewShell* pOtherShell) const
{
- // Cursor position and visibility.
- m_pVisibleCursor->SetPosAndShow(pOtherShell);
- // Text selection.
- m_pCurrentCursor->Show(pOtherShell);
- // Graphic selection.
auto pView = const_cast<SdrView*>(GetDrawView());
- pView->AdjustMarkHdl(pOtherShell);
+ if (pView->GetTextEditObject())
+ {
+ EditView& rEditView = pView->GetTextEditOutlinerView()->GetEditView();
+ rEditView.RegisterOtherShell(pOtherShell);
+ rEditView.ShowCursor();
+ rEditView.RegisterOtherShell(nullptr);
+ }
+ else
+ {
+ // Cursor position and visibility.
+ m_pVisibleCursor->SetPosAndShow(pOtherShell);
+ // Text selection.
+ m_pCurrentCursor->Show(pOtherShell);
+ // Graphic selection.
+ pView->AdjustMarkHdl(pOtherShell);
+ }
}
/// go to the next SSelection