sw lok: add LOK_CALLBACK_TEXT_VIEW_SELECTION
So a view can be aware where selections of other views are.
Change-Id: I5026b1ff2b99a4eedfd0bde32a05ceb8e2f424bc
Reviewed-on: https://gerrit.libreoffice.org/26542
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index 4229e73..4dfb8be 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -316,7 +316,6 @@ typedef enum
* 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:
*
* {
@@ -329,6 +328,21 @@ typedef enum
*/
LOK_CALLBACK_INVALIDATE_VIEW_CURSOR,
/**
* The the text selection in one of the other views has changed.
*
* The payload format:
*
* {
* "viewId": "..."
* "selection": "..."
* }
*
* - viewId is a value returned earlier by lok::Document::createView()
* - selection uses the format of LOK_CALLBACK_TEXT_SELECTION.
*/
LOK_CALLBACK_TEXT_VIEW_SELECTION,
}
LibreOfficeKitCallbackType;
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index ec68ed6..4cfe081 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -13,6 +13,7 @@
#include <sfx2/dllapi.h>
#include <cstddef>
#include <cstdint>
#include <rtl/string.hxx>
class SfxViewShell;
@@ -29,6 +30,9 @@ public:
static std::uintptr_t getView(SfxViewShell* pViewShell = nullptr);
/// Get the number of views of the current object shell.
static std::size_t getViews();
/// 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);
};
#endif
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 60d4cce..39676f3 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -346,6 +346,8 @@ callbackTypeToString (int nType)
return "LOK_CALLBACK_CONTEXT_MENU";
case LOK_CALLBACK_INVALIDATE_VIEW_CURSOR:
return "LOK_CALLBACK_INVALIDATE_VIEW_CURSOR";
case LOK_CALLBACK_TEXT_VIEW_SELECTION:
return "LOK_CALLBACK_TEXT_VIEW_SELECTION";
}
return nullptr;
}
@@ -1175,6 +1177,11 @@ callback (gpointer pData)
gtk_widget_queue_draw(GTK_WIDGET(pDocView));
break;
}
case LOK_CALLBACK_TEXT_VIEW_SELECTION:
{
// TODO: Implement me
break;
}
default:
g_assert(false);
break;
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index c994877..b44392c 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -8,6 +8,9 @@
*/
#include <sfx2/lokhelper.hxx>
#include <boost/property_tree/json_parser.hpp>
#include <sfx2/viewsh.hxx>
#include <sfx2/request.hxx>
#include <sfx2/viewfrm.hxx>
@@ -86,4 +89,26 @@ std::size_t SfxLokHelper::getViews()
return nRet;
}
void SfxLokHelper::notifyOtherViews(SfxViewShell* pThisView, int nType, const OString& rKey, const OString& rPayload)
{
if (SfxLokHelper::getViews() <= 1)
return;
SfxViewShell* pViewShell = SfxViewShell::GetFirst();
while (pViewShell)
{
if (pViewShell != pThisView)
{
boost::property_tree::ptree aTree;
aTree.put("viewId", SfxLokHelper::getView(pThisView));
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());
}
pViewShell = SfxViewShell::GetNext(*pViewShell);
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index b244635..a24042f 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -551,7 +551,7 @@ public:
ViewCallback()
: m_bOwnCursorInvalidated(false),
m_bViewCursorInvalidated(false)
m_bViewCursorInvalidated(false)
{
}
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index d4cc506..1ba80d9 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -198,26 +198,7 @@ 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);
}
}
SfxLokHelper::notifyOtherViews(m_pCursorShell->GetSfxViewShell(), LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, "rectangle", sRect);
}
if ( !m_pCursorShell->IsCursorReadonly() || m_pCursorShell->GetViewOptions()->IsSelectionInReadonly() )
@@ -417,6 +398,7 @@ void SwSelPaintRects::Show(std::vector<OString>* pSelectionRectangles)
if (!pSelectionRectangles)
{
GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, sRect.getStr());
SfxLokHelper::notifyOtherViews(GetShell()->GetSfxViewShell(), LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", sRect);
}
else
pSelectionRectangles->push_back(sRect);
@@ -624,6 +606,7 @@ void SwShellCursor::Show()
}
OString sRect = comphelper::string::join("; ", aRect);
GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, sRect.getStr());
SfxLokHelper::notifyOtherViews(GetShell()->GetSfxViewShell(), LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", sRect);
}
}