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 <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
This commit is contained in:
Miklos Vajna 2016-08-16 12:34:12 +02:00
parent b101ff56e8
commit 77235ac64b
6 changed files with 61 additions and 2 deletions

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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 () {}

View File

@ -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;
};

View File

@ -81,6 +81,7 @@
#include "workwin.hxx"
#include <sfx2/objface.hxx>
#include <sfx2/docfilt.hxx>
#include <sfx2/lokhelper.hxx>
#include "openuriexternally.hxx"
#include <shellimpl.hxx>
@ -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"));

View File

@ -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<beans::PropertyValue>());
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();