Kaydet (Commit) c544a8b6 authored tarafından Miklos Vajna's avatar Miklos Vajna

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/26513Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst 55bd0ac1
......@@ -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())
{
......
......@@ -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;
......
......@@ -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();
};
......
......@@ -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;
......
......@@ -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)
{
......
......@@ -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() )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment