diff options
author | Henry Castro <hcastro@collabora.com> | 2021-03-02 19:09:21 -0400 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2021-03-09 13:49:51 +0100 |
commit | 94376bb8299db8dfcba6afba16de7845c647ecdd (patch) | |
tree | 9d38844acaa92ad1387885dd07e2c9af44aa0733 /vcl | |
parent | 91aaa36286208791327aaa28460374942a237dc6 (diff) |
jsdialog: JSMessageDialog tweaks when builder is nullptr
"CreateMessageDialog" creates the message dialog without
builder, so some buttons need a click handler to close the
message dialog.
Change-Id: I73ac99020abfb23a1b1313468b6b0f5a8a17f039
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111852
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/jsdialog/jsdialogbuilder.hxx | 9 | ||||
-rw-r--r-- | vcl/jsdialog/jsdialogbuilder.cxx | 58 |
2 files changed, 67 insertions, 0 deletions
diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx b/vcl/inc/jsdialog/jsdialogbuilder.hxx index 24dbf8744d03..a6b8021a50b4 100644 --- a/vcl/inc/jsdialog/jsdialogbuilder.hxx +++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx @@ -265,6 +265,9 @@ public: VclButtonsType eButtonType, const OUString& rPrimaryMessage); + static void AddChildWidget(sal_uInt64 nWindowId, const OString& id, weld::Widget* pWidget); + static void RemoveWindowWidget(sal_uInt64 nWindowId); + private: const std::string& GetTypeOfJSON(); VclPtr<vcl::Window>& GetContentWindow(); @@ -466,11 +469,17 @@ public: class JSMessageDialog : public JSWidget<SalInstanceMessageDialog, ::MessageDialog> { std::unique_ptr<JSDialogSender> m_pOwnedSender; + std::unique_ptr<JSButton> m_pOK; + std::unique_ptr<JSButton> m_pCancel; + + DECL_LINK(OKHdl, weld::Button&, void); + DECL_LINK(CancelHdl, weld::Button&, void); public: JSMessageDialog(JSDialogSender* pSender, ::MessageDialog* pDialog, SalInstanceBuilder* pBuilder, bool bTakeOwnership); JSMessageDialog(::MessageDialog* pDialog, SalInstanceBuilder* pBuilder, bool bTakeOwnership); + virtual ~JSMessageDialog(); virtual void set_primary_text(const OUString& rText) override; diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx index 3fd84f281ef7..b102b557002f 100644 --- a/vcl/jsdialog/jsdialogbuilder.cxx +++ b/vcl/jsdialog/jsdialogbuilder.cxx @@ -520,6 +520,25 @@ void JSInstanceBuilder::RememberWidget(const OString& id, weld::Widget* pWidget) } } +void JSInstanceBuilder::AddChildWidget(sal_uInt64 nWindowId, const OString& id, weld::Widget* pWidget) +{ + auto it = GetLOKWeldWidgetsMap().find(nWindowId); + if (it != GetLOKWeldWidgetsMap().end()) + { + it->second.erase(id); + it->second.insert(WidgetMap::value_type(id, pWidget)); + } +} + +void JSInstanceBuilder::RemoveWindowWidget(sal_uInt64 nWindowId) +{ + auto it = JSInstanceBuilder::GetLOKWeldWidgetsMap().find(nWindowId); + if (it != JSInstanceBuilder::GetLOKWeldWidgetsMap().end()) + { + JSInstanceBuilder::GetLOKWeldWidgetsMap().erase(it); + } +} + const std::string& JSInstanceBuilder::GetTypeOfJSON() { return m_sTypeOfJSON; } VclPtr<vcl::Window>& JSInstanceBuilder::GetContentWindow() @@ -810,6 +829,8 @@ weld::MessageDialog* JSInstanceBuilder::CreateMessageDialog(weld::Widget* pParen pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, message.c_str()); } + xMessageDialog->SetLOKTunnelingState(false); + InsertWindowToMap(xMessageDialog->GetLOKWindowId()); return new JSMessageDialog(xMessageDialog, nullptr, true); } @@ -999,6 +1020,43 @@ JSMessageDialog::JSMessageDialog(::MessageDialog* pDialog, SalInstanceBuilder* p , m_pOwnedSender(new JSDialogSender(pDialog, pDialog, "dialog")) { m_pSender = m_pOwnedSender.get(); + + if (!pBuilder) + { + if(::OKButton* pOKBtn = dynamic_cast<::OKButton*>(m_xMessageDialog->get_widget_for_response(RET_OK))) + { + m_pOK.reset(new JSButton(m_pSender, pOKBtn, nullptr, false)); + JSInstanceBuilder::AddChildWidget(m_xMessageDialog->GetLOKWindowId(), + pOKBtn->get_id().toUtf8(), + m_pOK.get()); + m_pOK->connect_clicked(LINK(this, JSMessageDialog, OKHdl)); + } + + if(::CancelButton* pCancelBtn = dynamic_cast<::CancelButton*>(m_xMessageDialog->get_widget_for_response(RET_CANCEL))) + { + m_pCancel.reset(new JSButton(m_pSender, pCancelBtn, nullptr, false)); + JSInstanceBuilder::AddChildWidget(m_xMessageDialog->GetLOKWindowId(), + pCancelBtn->get_id().toUtf8(), + m_pCancel.get()); + m_pCancel->connect_clicked(LINK(this, JSMessageDialog, CancelHdl)); + } + } +} + +JSMessageDialog::~JSMessageDialog() +{ + if (m_pOK || m_pCancel) + JSInstanceBuilder::RemoveWindowWidget(m_xMessageDialog->GetLOKWindowId()); +} + +IMPL_LINK_NOARG(JSMessageDialog, OKHdl, weld::Button&, void) +{ + response(RET_OK); +} + +IMPL_LINK_NOARG(JSMessageDialog, CancelHdl, weld::Button&, void) +{ + response(RET_CANCEL); } void JSMessageDialog::set_primary_text(const OUString& rText) |