From 9c2a2aff948cf8b14e4f35a5637ae07c2a2f687c Mon Sep 17 00:00:00 2001 From: Pranav Kant Date: Tue, 14 Nov 2017 18:45:02 +0530 Subject: lokdialog: Expose cursor visible status Change the notifyDialog API a bit. Use a std::vector to keep track of each payload item that needs to be fed to the resulting JSON. Change-Id: If3229a88d2df5368e14290a0e80ebe6206780639 Reviewed-on: https://gerrit.libreoffice.org/44722 Reviewed-by: pranavk Tested-by: pranavk --- include/sfx2/lokhelper.hxx | 5 +++- include/vcl/IDialogRenderable.hxx | 6 ++++- include/vcl/dialog.hxx | 2 +- sfx2/source/view/lokhelper.cxx | 14 ++++++++--- sw/inc/unotxdoc.hxx | 4 +++- sw/source/uibase/uno/unotxdoc.cxx | 6 +++-- vcl/source/control/edit.cxx | 49 ++++++++++++++++++++++++++++++--------- vcl/source/window/dialog.cxx | 14 +++++++---- 8 files changed, 75 insertions(+), 25 deletions(-) diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index 01d519173c2a..a98c65cc02a2 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -10,6 +10,7 @@ #ifndef INCLUDED_SFX2_LOKHELPER_HXX #define INCLUDED_SFX2_LOKHELPER_HXX +#include #include #include #include @@ -41,7 +42,9 @@ public: /// 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); /// Emits a LOK_CALLBACK_DIALOG - static void notifyDialog(const OUString& rPayload, const OUString& rAction, const Rectangle* rRect); + static void notifyDialog(const OUString& rDialogId, + const OUString& rAction, + const std::vector& rPayload); /// Emits a LOK_CALLBACK_DIALOG_CHILD static void notifyDialogChild(const OUString& rDialogID, const OUString& rAction, const Point& rPos); /// Emits a LOK_CALLBACK_INVALIDATE_TILES, but tweaks it according to setOptionalFeatures() if needed. diff --git a/include/vcl/IDialogRenderable.hxx b/include/vcl/IDialogRenderable.hxx index 357926b40446..b02a701c01b7 100644 --- a/include/vcl/IDialogRenderable.hxx +++ b/include/vcl/IDialogRenderable.hxx @@ -23,6 +23,8 @@ namespace vcl { +typedef std::pair LOKPayloadItem; + typedef OUString DialogID; class VCL_DLLPUBLIC IDialogRenderable @@ -47,7 +49,9 @@ public: int nCount, int nButtons, int nModifier) = 0; // Callbacks - virtual void notifyDialog(const DialogID& rDialogID, const OUString& rAction, const Rectangle* rRect) = 0; + virtual void notifyDialog(const DialogID& rDialogID, + const OUString& rAction, + const std::vector& rPayload = std::vector()) = 0; virtual void notifyDialogChild(const DialogID& rDialogID, const OUString& rAction, const Point& rPos) = 0; }; diff --git a/include/vcl/dialog.hxx b/include/vcl/dialog.hxx index e1cb91d1dac1..74e5323c4996 100644 --- a/include/vcl/dialog.hxx +++ b/include/vcl/dialog.hxx @@ -87,7 +87,7 @@ public: void LOKKeyInput(const KeyEvent& rKeyEvent); void LOKKeyUp(const KeyEvent& rKeyEvent); - void LOKCursorInvalidate(const Rectangle& rRect); + void LOKCursor(const OUString& rAction, const std::vector& rPayload); protected: explicit Dialog( WindowType nType ); diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index 7e43b7ff0ce6..d24e0a7a3db6 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -132,7 +132,9 @@ void SfxLokHelper::notifyOtherViews(SfxViewShell* pThisView, int nType, const OS } } -void SfxLokHelper::notifyDialog(const OUString& rDialogID, const OUString& rAction, const Rectangle* rRect) +void SfxLokHelper::notifyDialog(const OUString& rDialogID, + const OUString& rAction, + const std::vector& rPayload) { if (SfxLokHelper::getViewsCount() <= 0 || rDialogID.isEmpty()) return; @@ -140,9 +142,15 @@ void SfxLokHelper::notifyDialog(const OUString& rDialogID, const OUString& rActi SfxViewShell* pViewShell = SfxViewShell::GetFirst(); OString aPayload = OString("{ \"dialogId\": \"") + OUStringToOString(rDialogID, RTL_TEXTENCODING_UTF8).getStr() + OString("\""); aPayload += OString(", \"action\": \"") + OUStringToOString(rAction, RTL_TEXTENCODING_UTF8).getStr() + OString("\""); - if (!rAction.isEmpty() && rRect && !rRect->IsEmpty()) - aPayload += OString(", \"rectangle\": \"") + rRect->toString() + OString("\""); + for (const auto& rItem: rPayload) + { + if (!rItem.first.isEmpty() && !rItem.second.isEmpty()) + { + aPayload += OString(", \"") + rItem.first + OString("\": \"") + + rItem.second + OString("\""); + } + } aPayload += "}"; while (pViewShell) diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx index 00b2887e60c6..90b5cb315a05 100644 --- a/sw/inc/unotxdoc.hxx +++ b/sw/inc/unotxdoc.hxx @@ -464,7 +464,9 @@ public: void postDialogChildMouseEvent(const vcl::DialogID& rDialogID, int nType, int nX, int nY, int nCount, int nButtons, int nModifier) override; - void notifyDialog(const vcl::DialogID& rDialogID, const OUString& rAction, const Rectangle* rRect) override; + void notifyDialog(const vcl::DialogID& rDialogID, + const OUString& rAction, + const std::vector& rPayload = std::vector()) override; void notifyDialogChild(const vcl::DialogID& rDialogID, const OUString& rAction, const Point& rPos) override; diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 45e905646ed0..33a9aeda0a0b 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -3873,9 +3873,11 @@ void SwXTextDocument::postDialogChildMouseEvent(const vcl::DialogID& rDialogID, } } -void SwXTextDocument::notifyDialog(const vcl::DialogID& rDialogID, const OUString& rAction, const Rectangle* rRect) +void SwXTextDocument::notifyDialog(const vcl::DialogID& rDialogID, + const OUString& rAction, + const std::vector& rPayload) { - SfxLokHelper::notifyDialog(rDialogID, rAction, rRect); + SfxLokHelper::notifyDialog(rDialogID, rAction, rPayload); } void SwXTextDocument::notifyDialogChild(const vcl::DialogID& rDialogID, const OUString& rAction, const Point& rPos) diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx index 6f8dd26a2ba3..afba61a662db 100644 --- a/vcl/source/control/edit.cxx +++ b/vcl/source/control/edit.cxx @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -1156,18 +1157,23 @@ void Edit::ImplShowCursor( bool bOnlyIfVisible ) pCursor->SetPos( Point( nCursorPosX, nCursorPosY ) ); pCursor->SetSize( Size( nCursorWidth, nTextHeight ) ); pCursor->Show(); - } - if (comphelper::LibreOfficeKit::isActive()) - { - const long X = GetOutOffXPixel() + pCursor->GetPos().X(); - const long Y = GetOutOffYPixel() + pCursor->GetPos().Y(); - if (nCursorWidth == 0) - nCursorWidth = 2; - const Rectangle aRect(Point(X, Y), Size(nCursorWidth, pCursor->GetHeight())); - Dialog* pParentDlg = GetParentDialog(); - if (pParentDlg) - pParentDlg->LOKCursorInvalidate(aRect); + if (comphelper::LibreOfficeKit::isActive()) + { + const long X = GetOutOffXPixel() + pCursor->GetPos().X(); + const long Y = GetOutOffYPixel() + pCursor->GetPos().Y(); + + if (nCursorWidth == 0) + nCursorWidth = 2; + const Rectangle aRect(Point(X, Y), Size(nCursorWidth, pCursor->GetHeight())); + + std::vector aPayload; + aPayload.push_back(std::make_pair("rectangle", aRect.toString())); + + Dialog* pParentDlg = GetParentDialog(); + if (pParentDlg) + pParentDlg->LOKCursor("cursor_invalidate", aPayload); + } } } @@ -1906,6 +1912,16 @@ void Edit::GetFocus() SetInputContext( InputContext( GetFont(), !IsReadOnly() ? InputContextFlags::Text|InputContextFlags::ExtText : InputContextFlags::NONE ) ); } + // notify dialog's cursor visible status + if (comphelper::LibreOfficeKit::isActive()) + { + std::vector aPayload; + aPayload.push_back(std::make_pair(OString("visible"), OString("true"))); + Dialog* pParentDlg = GetParentDialog(); + if (pParentDlg) + pParentDlg->LOKCursor("cursor_visible", aPayload); + } + Control::GetFocus(); } @@ -1933,6 +1949,17 @@ void Edit::LoseFocus() ImplInvalidateOrRepaint(); // Selektion malen } + + // notify dialog's cursor visible status + if (comphelper::LibreOfficeKit::isActive()) + { + std::vector aPayload; + aPayload.push_back(std::make_pair(OString("visible"), OString("false"))); + Dialog* pParentDlg = GetParentDialog(); + if (pParentDlg) + pParentDlg->LOKCursor("cursor_visible", aPayload); + } + Control::LoseFocus(); } diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx index 0137b0950a3b..d15072cce7f6 100644 --- a/vcl/source/window/dialog.cxx +++ b/vcl/source/window/dialog.cxx @@ -596,7 +596,7 @@ void Dialog::dispose() if (comphelper::LibreOfficeKit::isActive() && mpDialogRenderable) { - mpDialogRenderable->notifyDialog(maID, "close", nullptr); + mpDialogRenderable->notifyDialog(maID, "close"); } SystemWindow::dispose(); @@ -974,7 +974,11 @@ void Dialog::LogicInvalidate(const Rectangle* pRectangle) { if (!comphelper::LibreOfficeKit::isDialogPainting() && mpDialogRenderable && !maID.isEmpty()) { - mpDialogRenderable->notifyDialog(maID, "invalidate", pRectangle); + std::vector aPayload; + if (pRectangle) + aPayload.push_back(std::make_pair(OString("rectangle"), pRectangle->toString())); + + mpDialogRenderable->notifyDialog(maID, "invalidate", aPayload); } } @@ -1016,13 +1020,13 @@ void Dialog::LOKKeyUp(const KeyEvent& rKeyEvent) ImplWindowFrameProc(this, SalEvent::ExternalKeyUp, &rKeyEvent); } -void Dialog::LOKCursorInvalidate(const Rectangle& aRect) +void Dialog::LOKCursor(const OUString& rAction, const std::vector& rPayload) { assert(comphelper::LibreOfficeKit::isActive()); if (!comphelper::LibreOfficeKit::isDialogPainting() && mpDialogRenderable && !maID.isEmpty()) { - mpDialogRenderable->notifyDialog(maID, "cursor_invalidate", &aRect); + mpDialogRenderable->notifyDialog(maID, rAction, rPayload); } } @@ -1353,7 +1357,7 @@ void Dialog::Resize() // inform LOK clients if (!comphelper::LibreOfficeKit::isDialogPainting() && mpDialogRenderable && !maID.isEmpty()) { - mpDialogRenderable->notifyDialog(maID, "invalidate", nullptr); + mpDialogRenderable->notifyDialog(maID, "invalidate"); } } -- cgit v1.2.3