[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.1' - 2 commits - include/sfx2 libreofficekit/source sfx2/source sw/inc sw/source

Miklos Vajna vmiklos at collabora.co.uk
Thu Sep 1 08:31:44 UTC 2016


 include/sfx2/lokhelper.hxx               |    2 ++
 include/sfx2/viewsh.hxx                  |    2 ++
 libreofficekit/source/gtk/lokdocview.cxx |    6 +++++-
 sfx2/source/view/lokhelper.cxx           |   26 +++++++++++++++-----------
 sfx2/source/view/viewsh.cxx              |    9 ++++++---
 sw/inc/crsrsh.hxx                        |    3 +++
 sw/inc/view.hxx                          |    2 ++
 sw/inc/viscrs.hxx                        |    4 ++--
 sw/source/core/crsr/crsrsh.cxx           |    5 +++++
 sw/source/core/crsr/viscrs.cxx           |   18 ++++++++++++++----
 sw/source/uibase/uiview/viewprt.cxx      |    5 +++++
 11 files changed, 61 insertions(+), 21 deletions(-)

New commits:
commit 2a38d1b186428f0b23722f304addfae43e00677e
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Aug 31 17:19:13 2016 +0200

    sfx2 lok: introduce SfxViewShell::NotifyCursor()
    
    It allows removing the hide/show cursor hack in
    SfxViewShell::registerLibreOfficeKitViewCallback() introduced in commit
    4d211384f048b689f20e46d4d586f342b110cb5c (sfx2 lok: fix missing view
    cursors in a new view, 2016-06-20), and instead let the application code
    in sw/sc/sd implement the best way to show existing cursors in a new
    view.
    
    This way the per-app cleanup of view cursors introduced in commit
    bc9b4fd4c83af3532204237157821d4884c42d8e (lok::Document::destroyView:
    clean up view cursors/selections, 2016-07-15) has matching per-app init
    code.
    
    This commit just adds the API + adapts existing sw code to use it, sc/sd
    still has to be implemented.
    
    Based on a patch by Marco Cecchetti, thanks!
    
    Reviewed-on: https://gerrit.libreoffice.org/28557
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit 7167c2b6548830b82280f2f3943d445e9afd6f5e)
    
    Conflicts:
    	sw/inc/viscrs.hxx
    	sw/source/core/crsr/viscrs.cxx
    
    Change-Id: I38510fa4962f405b1b96a79024206c9e7f33cad2

diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index e7dfed4..852aa79 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -32,6 +32,8 @@ public:
 
     /// Invoke the LOK callback of all views except pThisView, with a payload of rKey-rPayload.
     static void notifyOtherViews(SfxViewShell* pThisView, int nType, const OString& rKey, const OString& rPayload);
+    /// Same as notifyOtherViews(), but works on a selected "other" view, not on all of them.
+    static void notifyOtherView(SfxViewShell* pThisView, SfxViewShell* pOtherView, int nType, const OString& rKey, const OString& rPayload);
 };
 
 #endif
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index 0bda743..d74e8b7 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -342,6 +342,8 @@ public:
     sal_uInt32 GetViewShellId() const override;
     /// See OutlinerViewShell::NotifyOtherViews().
     void NotifyOtherViews(int nType, const OString& rKey, const OString& rPayload) override;
+    /// Ask this view to send its cursor position to pViewShell.
+    virtual void NotifyCursor(SfxViewShell* /*pViewShell*/) const;
 };
 
 
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 4113160..6870787 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -88,6 +88,19 @@ std::size_t SfxLokHelper::getViews()
     return rViewArr.size();
 }
 
+void SfxLokHelper::notifyOtherView(SfxViewShell* pThisView, SfxViewShell* pOtherView, int nType, const OString& rKey, const OString& rPayload)
+{
+    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();
+    pOtherView->libreOfficeKitViewCallback(nType, aPayload.getStr());
+}
+
 void SfxLokHelper::notifyOtherViews(SfxViewShell* pThisView, int nType, const OString& rKey, const OString& rPayload)
 {
     if (SfxLokHelper::getViews() <= 1)
@@ -97,17 +110,8 @@ void SfxLokHelper::notifyOtherViews(SfxViewShell* pThisView, int nType, const OS
     while (pViewShell)
     {
         if (pViewShell != pThisView)
-        {
-            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();
-            pViewShell->libreOfficeKitViewCallback(nType, aPayload.getStr());
-        }
+            notifyOtherView(pThisView, pViewShell, nType, rKey, rPayload);
+
         pViewShell = SfxViewShell::GetNext(*pViewShell);
     }
 }
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 694ea7d6..de2f3e8 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -1609,12 +1609,11 @@ void SfxViewShell::registerLibreOfficeKitViewCallback(LibreOfficeKitCallback pCa
     pImp->m_pLibreOfficeKitViewCallback = pCallback;
     pImp->m_pLibreOfficeKitViewData = pData;
 
-    // Ask other views to send their cursor position to the new view.
+    // Ask other views to tell us about their cursors.
     SfxViewShell* pViewShell = SfxViewShell::GetFirst();
     while (pViewShell)
     {
-        pViewShell->ShowCursor(false);
-        pViewShell->ShowCursor();
+        pViewShell->NotifyCursor(this);
         pViewShell = SfxViewShell::GetNext(*pViewShell);
     }
 }
@@ -1642,6 +1641,10 @@ void SfxViewShell::libreOfficeKitViewCallback(int nType, const char* pPayload) c
         pImp->m_pLibreOfficeKitViewCallback(nType, pPayload, pImp->m_pLibreOfficeKitViewData);
 }
 
+void SfxViewShell::NotifyCursor(SfxViewShell* /*pViewShell*/) const
+{
+}
+
 void SfxViewShell::setTiledSearching(bool bTiledSearching)
 {
     pImp->m_bTiledSearching = bTiledSearching;
diff --git a/sw/inc/crsrsh.hxx b/sw/inc/crsrsh.hxx
index c0fa673..1848de5 100644
--- a/sw/inc/crsrsh.hxx
+++ b/sw/inc/crsrsh.hxx
@@ -847,6 +847,9 @@ public:
     virtual void dumpAsXml(struct _xmlTextWriter* pWriter) const override;
     /// Implementation of lok::Document::getPartPageRectangles() for Writer.
     OUString getPageRectangles();
+
+    /// See SwView::NotifyCursor().
+    void NotifyCursor(SfxViewShell* pViewShell) const;
 };
 
 // Cursor Inlines:
diff --git a/sw/inc/view.hxx b/sw/inc/view.hxx
index acaff3e..aaeba12 100644
--- a/sw/inc/view.hxx
+++ b/sw/inc/view.hxx
@@ -655,6 +655,8 @@ public:
     void dumpAsXml(struct _xmlTextWriter* pWriter) const override;
     void SetRedlineAuthor(const OUString& rAuthor);
     const OUString& GetRedlineAuthor();
+    /// See SfxViewShell::NotifyCursor().
+    void NotifyCursor(SfxViewShell* pViewShell) const override;
 };
 
 inline long SwView::GetXScroll() const
diff --git a/sw/inc/viscrs.hxx b/sw/inc/viscrs.hxx
index 701e9cd..6fd615f 100644
--- a/sw/inc/viscrs.hxx
+++ b/sw/inc/viscrs.hxx
@@ -29,6 +29,7 @@
 class SwCursorShell;
 class SwShellCursor;
 class SwTextInputField;
+class SfxViewShell;
 
 // From here classes/methods for non-text cursor.
 
@@ -46,8 +47,6 @@ class SwVisibleCursor
     /// For LibreOfficeKit only - remember what page we were at the last time.
     sal_uInt16 m_nPageLastTime;
 
-    void _SetPosAndShow();
-
 public:
     SwVisibleCursor( const SwCursorShell * pCShell );
     ~SwVisibleCursor();
@@ -57,6 +56,7 @@ public:
 
     bool IsVisible() const { return m_bIsVisible; }
     void SetDragCursor( bool bFlag = true ) { m_bIsDragCursor = bFlag; }
+    void _SetPosAndShow(SfxViewShell* pViewShell);
 };
 
 // From here classes/methods for selections.
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 4b2bb23..d0da782 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -1224,6 +1224,11 @@ OUString SwCursorShell::getPageRectangles()
     return OUString::fromUtf8(comphelper::string::join("; ", v).getStr());
 }
 
+void SwCursorShell::NotifyCursor(SfxViewShell* pViewShell) const
+{
+    m_pVisibleCursor->_SetPosAndShow(pViewShell);
+}
+
 /// go to the next SSelection
 bool SwCursorShell::GoNextCursor()
 {
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index 2c0ca9e..b9e9d01 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -95,7 +95,7 @@ void SwVisibleCursor::Show()
 
         // display at all?
         if( m_pCursorShell->VisArea().IsOver( m_pCursorShell->m_aCharRect ) || comphelper::LibreOfficeKit::isActive() )
-            _SetPosAndShow();
+            _SetPosAndShow(nullptr);
     }
 }
 
@@ -110,7 +110,7 @@ void SwVisibleCursor::Hide()
     }
 }
 
-void SwVisibleCursor::_SetPosAndShow()
+void SwVisibleCursor::_SetPosAndShow(SfxViewShell* pViewShell)
 {
     SwRect aRect;
     long nTmpY = m_pCursorShell->m_aCursorHeight.getY();
@@ -199,8 +199,18 @@ void SwVisibleCursor::_SetPosAndShow()
         // notify about the cursor position & size
         Rectangle aSVRect(aRect.Pos().getX(), aRect.Pos().getY(), aRect.Pos().getX() + aRect.SSize().Width(), aRect.Pos().getY() + aRect.SSize().Height());
         OString sRect = aSVRect.toString();
-        m_pCursorShell->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, sRect.getStr());
-        SfxLokHelper::notifyOtherViews(m_pCursorShell->GetSfxViewShell(), LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, "rectangle", sRect);
+        if (pViewShell)
+        {
+            if (pViewShell == m_pCursorShell->GetSfxViewShell())
+                pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, sRect.getStr());
+            else
+                SfxLokHelper::notifyOtherView(m_pCursorShell->GetSfxViewShell(), pViewShell, LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, "rectangle", sRect);
+        }
+        else
+        {
+            m_pCursorShell->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, sRect.getStr());
+            SfxLokHelper::notifyOtherViews(m_pCursorShell->GetSfxViewShell(), LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, "rectangle", sRect);
+        }
     }
 
     if ( !m_pCursorShell->IsCursorReadonly()  || m_pCursorShell->GetViewOptions()->IsSelectionInReadonly() )
diff --git a/sw/source/uibase/uiview/viewprt.cxx b/sw/source/uibase/uiview/viewprt.cxx
index 00f0f5b..0724784 100644
--- a/sw/source/uibase/uiview/viewprt.cxx
+++ b/sw/source/uibase/uiview/viewprt.cxx
@@ -279,6 +279,11 @@ const OUString& SwView::GetRedlineAuthor()
     return m_pViewImpl->m_sRedlineAuthor;
 }
 
+void SwView::NotifyCursor(SfxViewShell* pViewShell) const
+{
+    m_pWrtShell->NotifyCursor(pViewShell);
+}
+
 // Create page printer/additions for SwView and SwPagePreview
 
 VclPtr<SfxTabPage> CreatePrintOptionsPage( vcl::Window *pParent,
commit bc4a592baa01279bf9718a80fef8eb1410f16831
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Aug 31 11:38:41 2016 +0200

    lokdocview: handle empty LOK_CALLBACK_DOCUMENT_SIZE_CHANGED payload
    
    Calc omits the document size in the payload in several cases, and
    online.git handles that, so handle it in lokdocview as well for now,
    instead of fixing up all the sc code to always emit the doc size in the
    payload.
    
    Change-Id: Ib2cca1770d2a160e32540e3a3158eb00bf13207b
    (cherry picked from commit 127a34ef2cf9fe0ac13a273c12c6d45ef57eaf49)

diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 2e5431c..1f7d330 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -1212,7 +1212,11 @@ callback (gpointer pData)
     break;
     case LOK_CALLBACK_DOCUMENT_SIZE_CHANGED:
     {
-        payloadToSize(pCallback->m_aPayload.c_str(), priv->m_nDocumentWidthTwips, priv->m_nDocumentHeightTwips);
+        if (!pCallback->m_aPayload.empty())
+            payloadToSize(pCallback->m_aPayload.c_str(), priv->m_nDocumentWidthTwips, priv->m_nDocumentHeightTwips);
+        else
+            priv->m_pDocument->pClass->getDocumentSize(priv->m_pDocument, &priv->m_nDocumentWidthTwips, &priv->m_nDocumentHeightTwips);
+
         gtk_widget_set_size_request(GTK_WIDGET(pDocView),
                                     twipToPixel(priv->m_nDocumentWidthTwips, priv->m_fZoom),
                                     twipToPixel(priv->m_nDocumentHeightTwips, priv->m_fZoom));


More information about the Libreoffice-commits mailing list