diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-06-20 16:42:34 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-06-20 15:12:54 +0000 |
commit | c544a8b674dd7ac9dd466a84a440ede030942438 (patch) | |
tree | 3da18d0b6717c9f50edc1c157c9f5d77b2d0e0a3 | |
parent | 55bd0ac154a7118f7cce48ffd1e44a48d9099413 (diff) |
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@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
-rw-r--r-- | desktop/source/lib/init.cxx | 2 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKitEnums.h | 17 | ||||
-rw-r--r-- | include/sfx2/lokhelper.hxx | 2 | ||||
-rw-r--r-- | libreofficekit/source/gtk/lokdocview.cxx | 7 | ||||
-rw-r--r-- | sfx2/source/view/lokhelper.cxx | 12 | ||||
-rw-r--r-- | sw/source/core/crsr/viscrs.cxx | 22 |
6 files changed, 58 insertions, 4 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index c0477a5c34ba..a150535c9d53 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 4b8ff351689d..4229e73e6728 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 2a691f65759c..43c01892e98b 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 6f2b8eaf12a7..d4ca4a9861d6 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 3a306cfbe362..ba42188c178b 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 30f6f8f60c4e..d4cc5061d80f 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() ) |