[Libreoffice-commits] core.git: include/sfx2 sc/source sd/qa sd/source sfx2/source sw/inc sw/source

Miklos Vajna vmiklos at collabora.co.uk
Tue Jul 19 08:32:17 UTC 2016


 include/sfx2/viewsh.hxx                      |    2 
 sc/source/ui/inc/tabvwsh.hxx                 |    2 
 sc/source/ui/unoobj/docuno.cxx               |    2 
 sc/source/ui/view/tabvwshc.cxx               |    5 ++
 sd/qa/unit/tiledrendering/data/shape.odp     |binary
 sd/qa/unit/tiledrendering/tiledrendering.cxx |   57 +++++++++++++++++++++++++--
 sd/source/ui/inc/ViewShellBase.hxx           |    2 
 sd/source/ui/unoidl/unomodel.cxx             |    3 -
 sd/source/ui/view/ViewShellBase.cxx          |   13 ++++++
 sfx2/source/view/lokhelper.cxx               |    2 
 sfx2/source/view/viewsh.cxx                  |    5 ++
 sw/inc/view.hxx                              |    2 
 sw/source/uibase/uiview/viewprt.cxx          |   12 +++++
 sw/source/uibase/uno/unotxdoc.cxx            |   10 +---
 14 files changed, 104 insertions(+), 13 deletions(-)

New commits:
commit 299b9377469473abd8f58ba7f1054794491bdc56
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Jul 19 10:02:08 2016 +0200

    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 <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index fba08dfea..56888ca 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -331,6 +331,8 @@ public:
     void setTiledSearching(bool bTiledSearching);
     /// Are we doing tiled searching?
     bool isTiledSearching() const;
+    /// See lok::Document::getPart().
+    virtual int getPart() const;
 };
 
 
diff --git a/sc/source/ui/inc/tabvwsh.hxx b/sc/source/ui/inc/tabvwsh.hxx
index b937da8..6bae511 100644
--- a/sc/source/ui/inc/tabvwsh.hxx
+++ b/sc/source/ui/inc/tabvwsh.hxx
@@ -384,6 +384,8 @@ public:
     // #i123629#
     bool    GetForceFocusOnCurCell() const { return bForceFocusOnCurCell; }
     void SetForceFocusOnCurCell(bool bFlag) { bForceFocusOnCurCell=bFlag; }
+    /// See SfxViewShell::getPart().
+    int getPart() const override;
 };
 
 #endif
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index af54d38..f7d8b91 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -514,7 +514,7 @@ int ScModelObj::getParts()
 int ScModelObj::getPart()
 {
     ScViewData* pViewData = ScDocShell::GetViewData();
-    return pViewData->GetTabNo();
+    return pViewData->GetViewShell()->getPart();
 }
 
 OUString ScModelObj::getPartName( int nPart )
diff --git a/sc/source/ui/view/tabvwshc.cxx b/sc/source/ui/view/tabvwshc.cxx
index bfe6d8e..9cdc11e 100644
--- a/sc/source/ui/view/tabvwshc.cxx
+++ b/sc/source/ui/view/tabvwshc.cxx
@@ -536,4 +536,9 @@ VclPtr<SfxModelessDialog> ScTabViewShell::CreateRefDialog(
     return pResult;
 }
 
+int ScTabViewShell::getPart() const
+{
+    return GetViewData().GetTabNo();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/qa/unit/tiledrendering/data/shape.odp b/sd/qa/unit/tiledrendering/data/shape.odp
index f734761..b1ffa54 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 a465b63..948f06d 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<ViewCallback*>(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<int>() == 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<beans::PropertyValue>());
+    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();
diff --git a/sd/source/ui/inc/ViewShellBase.hxx b/sd/source/ui/inc/ViewShellBase.hxx
index 546dbef..4d92b0d 100644
--- a/sd/source/ui/inc/ViewShellBase.hxx
+++ b/sd/source/ui/inc/ViewShellBase.hxx
@@ -217,6 +217,8 @@ public:
     /** returns the ui descriptive name for the given uno slot. The result is taken from the configuration
         and not cached, so do not use it excessive (f.e. in status updates) */
     OUString RetrieveLabelFromCommand( const OUString& aCmdURL ) const;
+    /// See SfxViewShell::getPart().
+    int getPart() const override;
 
 protected:
 
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index 6902bba..851f38c 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2309,8 +2309,7 @@ int SdXImpressDocument::getPart()
     if (!pViewSh)
         return 0;
 
-    // curPageId seems to start at 1
-    return pViewSh->GetCurPageId() - 1;
+    return pViewSh->GetViewShellBase().getPart();
 }
 
 OUString SdXImpressDocument::getPartName( int nPart )
diff --git a/sd/source/ui/view/ViewShellBase.cxx b/sd/source/ui/view/ViewShellBase.cxx
index 3da4489..f22a8a4 100644
--- a/sd/source/ui/view/ViewShellBase.cxx
+++ b/sd/source/ui/view/ViewShellBase.cxx
@@ -1020,6 +1020,19 @@ OUString ViewShellBase::RetrieveLabelFromCommand( const OUString& aCmdURL ) cons
     return ImplRetrieveLabelFromCommand( xFrame, aCmdURL );
 }
 
+int ViewShellBase::getPart() const
+{
+    ViewShell* pViewShell = framework::FrameworkHelper::Instance(*const_cast<ViewShellBase*>(this))->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
+
+    if (DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(pViewShell))
+    {
+        // curPageId seems to start at 1
+        return pDrawViewShell->GetCurPageId() - 1;
+    }
+
+    return 0;
+}
+
 //===== ViewShellBase::Implementation =========================================
 
 ViewShellBase::Implementation::Implementation (ViewShellBase& rBase)
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index d027bad..09d78cf 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -108,6 +108,8 @@ void SfxLokHelper::notifyOtherViews(SfxViewShell* pThisView, int nType, const OS
             boost::property_tree::ptree aTree;
             aTree.put("viewId", SfxLokHelper::getView(pThisView));
             aTree.put(rKey.getStr(), rPayload.getStr());
+            aTree.put("part", pThisView->getPart());
+            aTree.put(rKey.getStr(), rPayload.getStr());
             std::stringstream aStream;
             boost::property_tree::write_json(aStream, aTree);
             OString aPayload = aStream.str().c_str();
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index d003d88..1bac0ac5 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -1496,6 +1496,11 @@ bool SfxViewShell::isTiledSearching() const
     return pImpl->m_bTiledSearching;
 }
 
+int SfxViewShell::getPart() const
+{
+    return 0;
+}
+
 bool SfxViewShell::KeyInput( const KeyEvent &rKeyEvent )
 
 /*  [Description]
diff --git a/sw/inc/view.hxx b/sw/inc/view.hxx
index e1f7f3a..a0b0519 100644
--- a/sw/inc/view.hxx
+++ b/sw/inc/view.hxx
@@ -642,6 +642,8 @@ public:
     SAL_DLLPRIVATE virtual VclPtr<SfxTabPage> CreatePrintOptionsPage( vcl::Window* pParent,
                                                     const SfxItemSet& rSet) override;
     static SvxSearchItem* GetSearchItem() { return m_pSrchItem; }
+    /// See SfxViewShell::getPart().
+    int getPart() const override;
 };
 
 inline long SwView::GetXScroll() const
diff --git a/sw/source/uibase/uiview/viewprt.cxx b/sw/source/uibase/uiview/viewprt.cxx
index 532b9e7..f9a116b9 100644
--- a/sw/source/uibase/uiview/viewprt.cxx
+++ b/sw/source/uibase/uiview/viewprt.cxx
@@ -246,6 +246,18 @@ void SwView::ExecutePrint(SfxRequest& rReq)
     }
 }
 
+int SwView::getPart() const
+{
+    if (!m_pWrtShell)
+        return 0;
+
+    sal_uInt16 nPage, nLogPage;
+    OUString sDisplay;
+    m_pWrtShell->GetPageNumber(-1, m_pWrtShell->IsCursorVisible(), nPage, nLogPage, sDisplay);
+
+    return nPage - 1;
+}
+
 // Create page printer/additions for SwView and SwPagePreview
 
 VclPtr<SfxTabPage> CreatePrintOptionsPage( vcl::Window *pParent,
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index a4290b8..2aab84f 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3230,15 +3230,11 @@ int SwXTextDocument::getPart()
 {
     SolarMutexGuard aGuard;
 
-    SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
-    if (!pWrtShell)
+    SwView* pView = pDocShell->GetView();
+    if (!pView)
         return 0;
 
-    sal_uInt16 nPage, nLogPage;
-    OUString sDisplay;
-    pWrtShell->GetPageNumber(-1, pWrtShell->IsCursorVisible(), nPage, nLogPage, sDisplay);
-
-    return nPage - 1;
+    return pView->getPart();
 }
 
 OUString SwXTextDocument::getPartName(int nPart)


More information about the Libreoffice-commits mailing list