From 53a9745c2a1dc4444c659b954d7d6f0588ffb5d7 Mon Sep 17 00:00:00 2001 From: Szymon Kłos Date: Thu, 11 Aug 2022 09:21:30 +0200 Subject: jsdialog: send MessageDialog on run not when built MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - some message boxes doesn't have correct notifier set initially - then when runAsync is called it is ok so we can remember widget Signed-off-by: Szymon Kłos Change-Id: I8ecf2d20ef4c2ebda3acf3b80bb390717b6caf6b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138107 Tested-by: Jenkins CollaboraOffice Reviewed-by: Michael Meeks --- vcl/inc/jsdialog/jsdialogbuilder.hxx | 14 +++++++++-- vcl/jsdialog/jsdialogbuilder.cxx | 45 +++++++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx b/vcl/inc/jsdialog/jsdialogbuilder.hxx index 304b9c330795..e5f3e6916d76 100644 --- a/vcl/inc/jsdialog/jsdialogbuilder.hxx +++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx @@ -219,6 +219,8 @@ class JSInstanceBuilder final : public SalInstanceBuilder, public JSDialogSender /// When LOKNotifier is set by jsdialogs code we need to release it VclPtr m_aWindowToRelease; + friend class JSMessageDialog; // static message boxes have to be registered outside + friend VCL_DLLPUBLIC bool jsdialog::ExecuteAction(const std::string& nWindowId, const OString& rWidget, StringMap& rData); friend VCL_DLLPUBLIC void jsdialog::SendFullUpdate(const std::string& nWindowId, @@ -421,8 +423,7 @@ public: virtual void grab_focus() override { BaseInstanceClass::grab_focus(); - std::unique_ptr pMap - = std::make_unique(); + std::unique_ptr pMap = std::make_unique(); (*pMap)[ACTION_TYPE] = "grab_focus"; sendAction(std::move(pMap)); } @@ -567,6 +568,8 @@ class JSMessageDialog final : public JSWidget aOwner, + const std::function& rEndDialogFn) override; + + bool runAsync(std::shared_ptr const& rxSelf, + const std::function& rEndDialogFn) override; }; class JSCheckButton final : public JSWidget diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx index 11edcb26d94d..5c62face9769 100644 --- a/vcl/jsdialog/jsdialogbuilder.cxx +++ b/vcl/jsdialog/jsdialogbuilder.cxx @@ -1174,18 +1174,14 @@ weld::MessageDialog* JSInstanceBuilder::CreateMessageDialog(weld::Widget* pParen aJsonWriter.put("jsontype", "dialog"); std::unique_ptr message(aJsonWriter.extractData()); pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, message.get()); + + std::string sWindowId = std::to_string(xMessageDialog->GetLOKWindowId()); + InsertWindowToMap(sWindowId); } xMessageDialog->SetLOKTunnelingState(false); - std::string sWindowId = std::to_string(xMessageDialog->GetLOKWindowId()); - InsertWindowToMap(sWindowId); - - weld::MessageDialog* pRet = new JSMessageDialog(xMessageDialog, nullptr, true); - - if (pRet) - RememberWidget(sWindowId, "__DIALOG__", pRet); - return pRet; + return new JSMessageDialog(xMessageDialog, nullptr, true); } JSDialog::JSDialog(JSDialogSender* pSender, ::Dialog* pDialog, SalInstanceBuilder* pBuilder, @@ -1421,6 +1417,39 @@ JSMessageDialog::~JSMessageDialog() JSInstanceBuilder::RemoveWindowWidget(m_sWindowId); } +void JSMessageDialog::RememberMessageDialog() +{ + static OStringLiteral sWidgetName = "__DIALOG__"; + std::string sWindowId = std::to_string(m_xMessageDialog->GetLOKWindowId()); + if (JSInstanceBuilder::FindWeldWidgetsMap(sWindowId, sWidgetName) != nullptr) + return; + + JSInstanceBuilder::InsertWindowToMap(sWindowId); + JSInstanceBuilder::RememberWidget(sWindowId, sWidgetName, this); +} + +bool JSMessageDialog::runAsync(std::shared_ptr aOwner, + const std::function& rEndDialogFn) +{ + bool bRet = SalInstanceMessageDialog::runAsync(aOwner, rEndDialogFn); + + RememberMessageDialog(); + sendFullUpdate(); + + return bRet; +} + +bool JSMessageDialog::runAsync(std::shared_ptr const& rxSelf, + const std::function& rEndDialogFn) +{ + bool bRet = SalInstanceMessageDialog::runAsync(rxSelf, rEndDialogFn); + + RememberMessageDialog(); + sendFullUpdate(); + + return bRet; +} + IMPL_LINK_NOARG(JSMessageDialog, OKHdl, weld::Button&, void) { response(RET_OK); } IMPL_LINK_NOARG(JSMessageDialog, CancelHdl, weld::Button&, void) { response(RET_CANCEL); } -- cgit v1.2.3