diff options
author | Henry Castro <hcastro@collabora.com> | 2021-03-02 19:09:21 -0400 |
---|---|---|
committer | Henry Castro <hcastro@collabora.com> | 2021-04-07 17:49:19 +0200 |
commit | 54209acb41b25422ce708da3a2aa33d124d3053c (patch) | |
tree | a600e327ff8e866d93479426db65a9cb322b3987 /vcl | |
parent | d41556fecb46a75436c83e6ac07e97ad679be3fa (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>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113692
Tested-by: Jenkins
Reviewed-by: Henry Castro <hcastro@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/jsdialog/jsdialogbuilder.hxx | 9 | ||||
-rw-r--r-- | vcl/jsdialog/jsdialogbuilder.cxx | 53 |
2 files changed, 62 insertions, 0 deletions
diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx b/vcl/inc/jsdialog/jsdialogbuilder.hxx index 2b6672b2da05..5807a20fb1b2 100644 --- a/vcl/inc/jsdialog/jsdialogbuilder.hxx +++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx @@ -250,6 +250,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(); @@ -450,11 +453,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 8414f3f9e262..6cfdea3e8b54 100644 --- a/vcl/jsdialog/jsdialogbuilder.cxx +++ b/vcl/jsdialog/jsdialogbuilder.cxx @@ -537,6 +537,26 @@ 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() @@ -807,6 +827,8 @@ weld::MessageDialog* JSInstanceBuilder::CreateMessageDialog(weld::Widget* pParen pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, message.get()); } + xMessageDialog->SetLOKTunnelingState(false); + InsertWindowToMap(xMessageDialog->GetLOKWindowId()); return new JSMessageDialog(xMessageDialog, nullptr, true); } @@ -996,8 +1018,39 @@ 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) { SalInstanceMessageDialog::set_primary_text(rText); |