From 77235ac64be61afd707931675fec100c7c50d01c Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 16 Aug 2016 12:34:12 +0200 Subject: [PATCH] editeng: introduce OutlinerViewShell::NotifyOtherViews() This allows notifying other views about e.g. cursor position changes even if SfxLokHelper::notifyOtherViews() is not accessible from editeng. Change-Id: I921e97344ffe562109a221f241e70b3f68ee9aaf Reviewed-on: https://gerrit.libreoffice.org/28162 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- editeng/source/editeng/editview.cxx | 8 +++- editeng/source/editeng/impedit.cxx | 2 + include/editeng/outliner.hxx | 2 + include/sfx2/viewsh.hxx | 2 + sfx2/source/view/viewsh.cxx | 6 +++ .../extras/tiledrendering/tiledrendering.cxx | 43 +++++++++++++++++++ 6 files changed, 61 insertions(+), 2 deletions(-) diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx index f00678fa091e..49aeaf23ff09 100644 --- a/editeng/source/editeng/editview.cxx +++ b/editeng/source/editeng/editview.cxx @@ -403,7 +403,9 @@ void EditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor, bool bActivat if (pImpEditView->mpViewShell && !bActivate) { - pImpEditView->mpViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CURSOR_VISIBLE, OString::boolean(true).getStr()); + OString aPayload = OString::boolean(true); + pImpEditView->mpViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CURSOR_VISIBLE, aPayload.getStr()); + pImpEditView->mpViewShell->NotifyOtherViews(LOK_CALLBACK_VIEW_CURSOR_VISIBLE, "visible", aPayload); } } } @@ -414,7 +416,9 @@ void EditView::HideCursor(bool bDeactivate) if (pImpEditView->mpViewShell && !bDeactivate) { - pImpEditView->mpViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CURSOR_VISIBLE, OString::boolean(false).getStr()); + OString aPayload = OString::boolean(false); + pImpEditView->mpViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CURSOR_VISIBLE, aPayload.getStr()); + pImpEditView->mpViewShell->NotifyOtherViews(LOK_CALLBACK_VIEW_CURSOR_VISIBLE, "visible", aPayload); } } diff --git a/editeng/source/editeng/impedit.cxx b/editeng/source/editeng/impedit.cxx index 13a53acfc0f7..2ef02909e6ee 100644 --- a/editeng/source/editeng/impedit.cxx +++ b/editeng/source/editeng/impedit.cxx @@ -408,6 +408,7 @@ void ImpEditView::DrawSelection( EditSelection aTmpSel, vcl::Region* pRegion, Ou } mpViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, sRectangle.getStr()); + mpViewShell->NotifyOtherViews(LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", sRectangle); pOutWin->Pop(); } @@ -1005,6 +1006,7 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) OString sRect = aRect.toString(); mpViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, sRect.getStr()); + mpViewShell->NotifyOtherViews(LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, "rectangle", sRect); } CursorDirection nCursorDir = CursorDirection::NONE; diff --git a/include/editeng/outliner.hxx b/include/editeng/outliner.hxx index 495352b044e6..fe12127546b0 100644 --- a/include/editeng/outliner.hxx +++ b/include/editeng/outliner.hxx @@ -378,6 +378,8 @@ class SAL_NO_VTABLE SAL_DLLPUBLIC_RTTI OutlinerViewShell public: virtual void libreOfficeKitViewCallback(int nType, const char* pPayload) const = 0; virtual sal_uInt32 GetViewShellId() const = 0; + /// Wrapper around SfxLokHelper::notifyOtherViews(). + virtual void NotifyOtherViews(int nType, const OString& rKey, const OString& rPayload) = 0; protected: ~OutlinerViewShell() throw () {} diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx index 62df5542da7f..b4b38042164c 100644 --- a/include/sfx2/viewsh.hxx +++ b/include/sfx2/viewsh.hxx @@ -336,6 +336,8 @@ public: virtual void dumpAsXml(struct _xmlTextWriter* pWriter) const; /// See OutlinerViewShell::GetViewShellId(). sal_uInt32 GetViewShellId() const override; + /// See OutlinerViewShell::NotifyOtherViews(). + void NotifyOtherViews(int nType, const OString& rKey, const OString& rPayload) override; }; diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index 6ffd25313749..631d712c1dfe 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -81,6 +81,7 @@ #include "workwin.hxx" #include #include +#include #include "openuriexternally.hxx" #include @@ -1510,6 +1511,11 @@ sal_uInt32 SfxViewShell::GetViewShellId() const return pImpl->m_nViewShellId; } +void SfxViewShell::NotifyOtherViews(int nType, const OString& rKey, const OString& rPayload) +{ + SfxLokHelper::notifyOtherViews(this, nType, rKey, rPayload); +} + void SfxViewShell::dumpAsXml(xmlTextWriterPtr pWriter) const { xmlTextWriterStartElement(pWriter, BAD_CAST("sfxViewShell")); diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index c568ddf3c9ca..a87359bd6ad5 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -54,6 +54,7 @@ public: void testPageDownInvalidation(); void testPartHash(); void testViewCursors(); + void testShapeViewCursors(); void testMissingInvalidation(); void testViewCursorVisibility(); void testViewCursorCleanup(); @@ -85,6 +86,7 @@ public: CPPUNIT_TEST(testPageDownInvalidation); CPPUNIT_TEST(testPartHash); CPPUNIT_TEST(testViewCursors); + CPPUNIT_TEST(testShapeViewCursors); CPPUNIT_TEST(testMissingInvalidation); CPPUNIT_TEST(testViewCursorVisibility); CPPUNIT_TEST(testViewCursorCleanup); @@ -735,6 +737,47 @@ void SwTiledRenderingTest::testViewCursors() comphelper::LibreOfficeKit::setActive(false); } +void SwTiledRenderingTest::testShapeViewCursors() +{ + comphelper::LibreOfficeKit::setActive(); + + // Load a document and create a view, so we have 2 ones. + SwXTextDocument* pXTextDocument = createDoc("shape.fodt"); + ViewCallback aView1; + SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1); + SfxLokHelper::createView(); + ViewCallback aView2; + pXTextDocument->initializeForTiledRendering(uno::Sequence()); + SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2); + SwWrtShell* pWrtShell2 = pXTextDocument->GetDocShell()->GetWrtShell(); + + // Start shape text in the second view. + SdrPage* pPage = pWrtShell2->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0); + SdrObject* pObject = pPage->GetObj(0); + SdrView* pView = pWrtShell2->GetDrawView(); + pWrtShell2->GetView().BeginTextEdit(pObject, pView->GetSdrPageView(), pWrtShell2->GetWin()); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'x', 0); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'x', 0); + + // Press a key in the second view, while the first one observes this. + aView1.m_bOwnCursorInvalidated = false; + aView1.m_bViewCursorInvalidated = false; + aView2.m_bOwnCursorInvalidated = false; + aView2.m_bViewCursorInvalidated = false; + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'y', 0); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'y', 0); + // Make sure that aView1 gets a view-only cursor notification, while + // aView2 gets a real cursor notification. + CPPUNIT_ASSERT(!aView1.m_bOwnCursorInvalidated); + CPPUNIT_ASSERT(aView1.m_bViewCursorInvalidated); + CPPUNIT_ASSERT(aView2.m_bOwnCursorInvalidated); + CPPUNIT_ASSERT(!aView2.m_bViewCursorInvalidated); + mxComponent->dispose(); + mxComponent.clear(); + + comphelper::LibreOfficeKit::setActive(false); +} + void SwTiledRenderingTest::testViewCursorVisibility() { comphelper::LibreOfficeKit::setActive();