From fc4bb1254ef77d29368535c9a810875c8db15b77 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 19 Jul 2016 10:02:08 +0200 Subject: sfx2 lok: expose part number in SfxLokHelper::notifyOtherViews() This way a client can decide if the view cursor it gets is relevant (the views show the same part) or not. Change-Id: I7b274b28f0c4f0509df5071831acf50512eff640 Reviewed-on: https://gerrit.libreoffice.org/27311 Reviewed-by: Miklos Vajna Tested-by: Jenkins (cherry picked from commit 299b9377469473abd8f58ba7f1054794491bdc56) --- sd/qa/unit/tiledrendering/data/shape.odp | Bin 10159 -> 10446 bytes sd/qa/unit/tiledrendering/tiledrendering.cxx | 57 +++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 3 deletions(-) (limited to 'sd/qa') diff --git a/sd/qa/unit/tiledrendering/data/shape.odp b/sd/qa/unit/tiledrendering/data/shape.odp index f73476140d73..b1ffa54e367f 100644 Binary files a/sd/qa/unit/tiledrendering/data/shape.odp and b/sd/qa/unit/tiledrendering/data/shape.odp differ diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index 316936f44d47..acff325c6498 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -64,6 +64,7 @@ public: void testResizeTable(); void testResizeTableColumn(); void testViewCursors(); + void testViewCursorParts(); CPPUNIT_TEST_SUITE(SdTiledRenderingTest); CPPUNIT_TEST(testRegisterCallback); @@ -84,6 +85,7 @@ public: CPPUNIT_TEST(testResizeTable); CPPUNIT_TEST(testResizeTableColumn); CPPUNIT_TEST(testViewCursors); + CPPUNIT_TEST(testViewCursorParts); CPPUNIT_TEST_SUITE_END(); private: @@ -814,10 +816,13 @@ class ViewCallback public: bool m_bGraphicSelectionInvalidated; bool m_bGraphicViewSelectionInvalidated; + /// Our current part, to be able to decide if a view cursor/selection is relevant for us. + int m_nPart; ViewCallback() : m_bGraphicSelectionInvalidated(false), - m_bGraphicViewSelectionInvalidated(false) + m_bGraphicViewSelectionInvalidated(false), + m_nPart(0) { } @@ -826,7 +831,7 @@ public: static_cast(pData)->callbackImpl(nType, pPayload); } - void callbackImpl(int nType, const char* /*pPayload*/) + void callbackImpl(int nType, const char* pPayload) { switch (nType) { @@ -837,7 +842,12 @@ public: break; case LOK_CALLBACK_GRAPHIC_VIEW_SELECTION: { - m_bGraphicViewSelectionInvalidated = true; + std::stringstream aStream(pPayload); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + if (aTree.get_child("part").get_value() == m_nPart) + // Ignore callbacks which are for a different part. + m_bGraphicViewSelectionInvalidated = true; } break; } @@ -874,6 +884,47 @@ void SdTiledRenderingTest::testViewCursors() comphelper::LibreOfficeKit::setActive(false); } +void SdTiledRenderingTest::testViewCursorParts() +{ + comphelper::LibreOfficeKit::setActive(); + + // Create two views. + SdXImpressDocument* pXImpressDocument = createDoc("shape.odp"); + ViewCallback aView1; + SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1); + SfxLokHelper::createView(); + pXImpressDocument->initializeForTiledRendering(uno::Sequence()); + ViewCallback aView2; + SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2); + + // Select the shape in the second view. + sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell(); + SdPage* pActualPage = pViewShell->GetActualPage(); + SdrObject* pObject = pActualPage->GetObj(0); + SdrView* pView = pViewShell->GetView(); + pView->MarkObj(pObject, pView->GetSdrPageView()); + Scheduler::ProcessEventsToIdle(); + // First view notices that there was a selection change in the other view. + CPPUNIT_ASSERT(aView1.m_bGraphicViewSelectionInvalidated); + pView->UnmarkAllObj(pView->GetSdrPageView()); + + // Now switch to the second part in the second view. + pXImpressDocument->setPart(1); + aView2.m_nPart = 1; + aView1.m_bGraphicViewSelectionInvalidated = false; + pActualPage = pViewShell->GetActualPage(); + pObject = pActualPage->GetObj(0); + pView->MarkObj(pObject, pView->GetSdrPageView()); + Scheduler::ProcessEventsToIdle(); + // First view ignores view selection, as it would be for part 1, and it's in part 0. + // This failed when the "part" was always 0 in the callback. + CPPUNIT_ASSERT(!aView1.m_bGraphicViewSelectionInvalidated); + + mxComponent->dispose(); + mxComponent.clear(); + comphelper::LibreOfficeKit::setActive(false); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SdTiledRenderingTest); CPPUNIT_PLUGIN_IMPLEMENT(); -- cgit v1.2.3