From f89557039270791e7d269460fd5cb988f9380260 Mon Sep 17 00:00:00 2001 From: Szymon Kłos Date: Tue, 17 Mar 2020 14:50:39 +0100 Subject: jsdialog: use for message dialogs on mobile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ib172dc264d7f55fef08dc474f7e6f4d1b3108085 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94431 Tested-by: Jenkins CollaboraOffice Reviewed-by: Szymon Kłos Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96836 Tested-by: Jenkins --- vcl/jsdialog/jsdialogbuilder.cxx | 44 ++++++++++++++++++++++++++++++++++++++++ vcl/source/window/builder.cxx | 8 ++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) (limited to 'vcl') diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx index 88d84d56da94..c360eee7b9e6 100644 --- a/vcl/jsdialog/jsdialogbuilder.cxx +++ b/vcl/jsdialog/jsdialogbuilder.cxx @@ -6,6 +6,7 @@ #include #include #include +#include void JSDialogSender::notifyDialogState() { @@ -204,6 +205,30 @@ std::unique_ptr JSInstanceBuilder::weld_notebook(const OString& return pWeldWidget; } +weld::MessageDialog* JSInstanceBuilder::CreateMessageDialog(weld::Widget* pParent, + VclMessageType eMessageType, + VclButtonsType eButtonType, + const OUString& rPrimaryMessage) +{ + SalInstanceWidget* pParentInstance = dynamic_cast(pParent); + SystemWindow* pParentWidget = pParentInstance ? pParentInstance->getSystemWindow() : nullptr; + VclPtrInstance<::MessageDialog> xMessageDialog(pParentWidget, rPrimaryMessage, eMessageType, + eButtonType); + + const vcl::ILibreOfficeKitNotifier* pNotifier = xMessageDialog->GetLOKNotifier(); + if (pNotifier) + { + std::stringstream aStream; + boost::property_tree::ptree aTree = xMessageDialog->DumpAsPropertyTree(); + aTree.put("id", xMessageDialog->GetLOKWindowId()); + boost::property_tree::write_json(aStream, aTree); + const std::string message = aStream.str(); + pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, message.c_str()); + } + + return new JSMessageDialog(xMessageDialog, nullptr, true); +} + JSLabel::JSLabel(VclPtr aOwnedToplevel, FixedText* pLabel, SalInstanceBuilder* pBuilder, bool bTakeOwnership) : JSWidget(aOwnedToplevel, pLabel, pBuilder, bTakeOwnership) @@ -322,3 +347,22 @@ void JSNotebook::insert_page(const OString& rIdent, const OUString& rLabel, int SalInstanceNotebook::insert_page(rIdent, rLabel, nPos); notifyDialogState(); } + +JSMessageDialog::JSMessageDialog(::MessageDialog* pDialog, SalInstanceBuilder* pBuilder, + bool bTakeOwnership) + : SalInstanceMessageDialog(pDialog, pBuilder, bTakeOwnership) + , JSDialogSender(m_xMessageDialog) +{ +} + +void JSMessageDialog::set_primary_text(const OUString& rText) +{ + SalInstanceMessageDialog::set_primary_text(rText); + notifyDialogState(); +} + +void JSMessageDialog::set_secondary_text(const OUString& rText) +{ + SalInstanceMessageDialog::set_secondary_text(rText); + notifyDialogState(); +} diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index e6e2d7415933..7837320d30b5 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -178,9 +178,13 @@ weld::Builder* Application::CreateInterimBuilder(vcl::Window* pParent, const OUS } weld::MessageDialog* Application::CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType, - VclButtonsType eButtonType, const OUString& rPrimaryMessage) + VclButtonsType eButtonType, const OUString& rPrimaryMessage, + bool bMobile) { - return ImplGetSVData()->mpDefInst->CreateMessageDialog(pParent, eMessageType, eButtonType, rPrimaryMessage); + if (bMobile) + return JSInstanceBuilder::CreateMessageDialog(pParent, eMessageType, eButtonType, rPrimaryMessage); + else + return ImplGetSVData()->mpDefInst->CreateMessageDialog(pParent, eMessageType, eButtonType, rPrimaryMessage); } weld::Window* Application::GetFrameWeld(const css::uno::Reference& rWindow) -- cgit