[Libreoffice-commits] core.git: desktop/source include/LibreOfficeKit include/sfx2 libreofficekit/source sfx2/source sw/source

Miklos Vajna vmiklos at collabora.co.uk
Mon Jun 20 15:13:15 UTC 2016


 desktop/source/lib/init.cxx                  |    2 ++
 include/LibreOfficeKit/LibreOfficeKitEnums.h |   17 +++++++++++++++++
 include/sfx2/lokhelper.hxx                   |    2 +-
 libreofficekit/source/gtk/lokdocview.cxx     |    7 +++++++
 sfx2/source/view/lokhelper.cxx               |   12 +++++++++---
 sw/source/core/crsr/viscrs.cxx               |   22 ++++++++++++++++++++++
 6 files changed, 58 insertions(+), 4 deletions(-)

New commits:
commit c544a8b674dd7ac9dd466a84a440ede030942438
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Jun 20 16:42:34 2016 +0200

    sw lok: add LOK_CALLBACK_INVALIDATE_VIEW_CURSOR
    
    So a view can be aware where cursors of other views are.
    
    Change-Id: I6133fb55aa2869843c0284b7d76264bab3b3d5da
    Reviewed-on: https://gerrit.libreoffice.org/26513
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index c0477a5..a150535 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -446,6 +446,7 @@ CallbackFlushHandler::CallbackFlushHandler(LibreOfficeKitDocument* pDocument, Li
     m_states.emplace(LOK_CALLBACK_TEXT_SELECTION, "NIL");
     m_states.emplace(LOK_CALLBACK_GRAPHIC_SELECTION, "NIL");
     m_states.emplace(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, "NIL");
+    m_states.emplace(LOK_CALLBACK_INVALIDATE_VIEW_CURSOR , "NIL");
     m_states.emplace(LOK_CALLBACK_STATE_CHANGED, "NIL");
     m_states.emplace(LOK_CALLBACK_MOUSE_POINTER, "NIL");
     m_states.emplace(LOK_CALLBACK_CELL_CURSOR, "NIL");
@@ -561,6 +562,7 @@ void CallbackFlushHandler::queue(const int type, const char* data)
         // These come with rects, so drop earlier
         // only when the latter includes former ones.
         case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
+        case LOK_CALLBACK_INVALIDATE_VIEW_CURSOR:
         case LOK_CALLBACK_INVALIDATE_TILES:
             if (payload.empty())
             {
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index 4b8ff35..4229e73 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -312,6 +312,23 @@ typedef enum
      */
     LOK_CALLBACK_CONTEXT_MENU,
 
+    /**
+     * The size and/or the position of the view cursor changed. A view cursor
+     * is a cursor of an other view, the current view can't change it.
+     *
+     * Rectangle format is the same as LOK_CALLBACK_INVALIDATE_TILES.
+     * The payload format:
+     *
+     * {
+     *     "viewId": "..."
+     *     "rectangle": "..."
+     * }
+     *
+     * - viewId is a value returned earlier by lok::Document::createView()
+     * - rectangle uses the format of LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR
+     */
+    LOK_CALLBACK_INVALIDATE_VIEW_CURSOR,
+
 }
 LibreOfficeKitCallbackType;
 
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index 2a691f6..43c0189 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -26,7 +26,7 @@ public:
     /// Set a view shell as current one.
     static void setView(std::uintptr_t nId);
     /// Get the currently active view.
-    static std::uintptr_t getView();
+    static std::uintptr_t getView(SfxViewShell *pViewShell = nullptr);
     /// Get the number of views of the current object shell.
     static std::size_t getViews();
 };
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 6f2b8ea..d4ca4a9 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -341,6 +341,8 @@ callbackTypeToString (int nType)
         return "LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY";
     case LOK_CALLBACK_CONTEXT_MENU:
         return "LOK_CALLBACK_CONTEXT_MENU";
+    case LOK_CALLBACK_INVALIDATE_VIEW_CURSOR:
+        return "LOK_CALLBACK_INVALIDATE_VIEW_CURSOR";
     }
     return nullptr;
 }
@@ -1158,6 +1160,11 @@ callback (gpointer pData)
         // TODO: Implement me
         break;
     }
+    case LOK_CALLBACK_INVALIDATE_VIEW_CURSOR:
+    {
+        // TODO: Implement me
+        break;
+    }
     default:
         g_assert(false);
         break;
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 3a306cf..ba42188 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -60,16 +60,22 @@ void SfxLokHelper::setView(std::uintptr_t nId)
 
 }
 
-std::uintptr_t SfxLokHelper::getView()
+std::uintptr_t SfxLokHelper::getView(SfxViewShell *pViewShell)
 {
-    return reinterpret_cast<std::uintptr_t>(SfxViewShell::Current());
+    if (!pViewShell)
+        pViewShell = SfxViewShell::Current();
+    return reinterpret_cast<std::uintptr_t>(pViewShell);
 }
 
 std::size_t SfxLokHelper::getViews()
 {
     std::size_t nRet = 0;
 
-    SfxObjectShell* pObjectShell = SfxViewFrame::Current()->GetObjectShell();
+    SfxViewFrame* pViewFrame = SfxViewFrame::Current();
+    if (!pViewFrame)
+        return nRet;
+
+    SfxObjectShell* pObjectShell = pViewFrame->GetObjectShell();
     SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
     for (SfxViewShell* i : rViewArr)
     {
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index 30f6f8f..d4cc506 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -52,9 +52,11 @@
 #include <overlayrangesoutline.hxx>
 
 #include <memory>
+#include <boost/property_tree/json_parser.hpp>
 
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <comphelper/lok.hxx>
+#include <sfx2/lokhelper.hxx>
 #include <comphelper/string.hxx>
 #include <paintfrm.hxx>
 
@@ -196,6 +198,26 @@ void SwVisibleCursor::SetPosAndShow()
         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());
+
+        if (SfxLokHelper::getViews() > 1)
+        {
+            // Notify other views about the invalidated cursor.
+            SfxViewShell* pViewShell = SfxViewShell::GetFirst();
+            while (pViewShell)
+            {
+                if (pViewShell != m_pCursorShell->GetSfxViewShell())
+                {
+                    boost::property_tree::ptree aTree;
+                    aTree.put("viewId", SfxLokHelper::getView(m_pCursorShell->GetSfxViewShell()));
+                    aTree.put("rectangle", sRect.getStr());
+                    std::stringstream aStream;
+                    boost::property_tree::write_json(aStream, aTree);
+                    OString aPayload = aStream.str().c_str();
+                    pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, aPayload.getStr());
+                }
+                pViewShell = SfxViewShell::GetNext(*pViewShell);
+            }
+        }
     }
 
     if ( !m_pCursorShell->IsCursorReadonly()  || m_pCursorShell->GetViewOptions()->IsSelectionInReadonly() )


More information about the Libreoffice-commits mailing list