diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2020-03-17 14:50:39 +0100 |
---|---|---|
committer | Szymon Kłos <eszkadev@gmail.com> | 2020-05-20 10:30:07 +0200 |
commit | bc551d879062359627d74482b9a7c2bb423be9a8 (patch) | |
tree | debb5d0d221de233d9961f627c698cb9c8ddb03c | |
parent | c2952065c9964a062510d27f97ab5c8885a5a726 (diff) |
jsdialog: use for message dialogs on mobile
Change-Id: Ib172dc264d7f55fef08dc474f7e6f4d1b3108085
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94431
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
-rw-r--r-- | include/vcl/jsdialog/jsdialogbuilder.hxx | 14 | ||||
-rw-r--r-- | include/vcl/salvtables.hxx | 2 | ||||
-rw-r--r-- | include/vcl/svapp.hxx | 3 | ||||
-rw-r--r-- | sc/source/core/data/validat.cxx | 7 | ||||
-rw-r--r-- | vcl/jsdialog/jsdialogbuilder.cxx | 43 | ||||
-rw-r--r-- | vcl/source/window/builder.cxx | 8 |
6 files changed, 72 insertions, 5 deletions
diff --git a/include/vcl/jsdialog/jsdialogbuilder.hxx b/include/vcl/jsdialog/jsdialogbuilder.hxx index 8befb2b0f79b..660be3ea75d3 100644 --- a/include/vcl/jsdialog/jsdialogbuilder.hxx +++ b/include/vcl/jsdialog/jsdialogbuilder.hxx @@ -52,6 +52,10 @@ public: virtual std::unique_ptr<weld::Notebook> weld_notebook(const OString& id, bool bTakeOwnership = false) override; + static weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent, + VclMessageType eMessageType, + VclButtonsType eButtonType, + const OUString& rPrimaryMessage); static weld::Widget* FindWeldWidgetsMap(vcl::LOKWindowId nWindowId, const OString& rWidget); }; @@ -146,4 +150,14 @@ public: virtual void append_page(const OString& rIdent, const OUString& rLabel) override; }; +class VCL_DLLPUBLIC JSMessageDialog : public SalInstanceMessageDialog, public JSDialogSender +{ +public: + JSMessageDialog(::MessageDialog* pDialog, SalInstanceBuilder* pBuilder, bool bTakeOwnership); + + virtual void set_primary_text(const OUString& rText) override; + + virtual void set_secondary_text(const OUString& rText) override; +}; + #endif diff --git a/include/vcl/salvtables.hxx b/include/vcl/salvtables.hxx index 6222423551bc..a6cd713e19c4 100644 --- a/include/vcl/salvtables.hxx +++ b/include/vcl/salvtables.hxx @@ -906,7 +906,7 @@ public: class SalInstanceMessageDialog : public SalInstanceDialog, public virtual weld::MessageDialog { -private: +protected: VclPtr<::MessageDialog> m_xMessageDialog; public: diff --git a/include/vcl/svapp.hxx b/include/vcl/svapp.hxx index 7392ef3be86f..08efa5a95c0f 100644 --- a/include/vcl/svapp.hxx +++ b/include/vcl/svapp.hxx @@ -1345,7 +1345,8 @@ public: static weld::Builder* CreateInterimBuilder(weld::Widget* pParent, const OUString &rUIFile); //for the duration of same SfxTabPages in mixed parent types static weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType, - VclButtonsType eButtonType, const OUString& rPrimaryMessage); + VclButtonsType eButtonType, const OUString& rPrimaryMessage, + bool bMobile = false); static weld::Window* GetFrameWeld(const css::uno::Reference<css::awt::XWindow>& rWindow); private: diff --git a/sc/source/core/data/validat.cxx b/sc/source/core/data/validat.cxx index 4fd89ccb206f..409ecbe6c70d 100644 --- a/sc/source/core/data/validat.cxx +++ b/sc/source/core/data/validat.cxx @@ -49,6 +49,8 @@ #include <tokenarray.hxx> #include <scmatrix.hxx> #include <cellvalue.hxx> +#include <comphelper/lok.hxx> +#include <sfx2/lokhelper.hxx> #include <math.h> #include <memory> @@ -405,8 +407,11 @@ bool ScValidationData::DoError(weld::Window* pParent, const OUString& rInput, break; } + bool bIsMobile = comphelper::LibreOfficeKit::isActive() + && SfxViewShell::Current() && SfxViewShell::Current()->isLOKMobilePhone(); + std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pParent, eType, - eStyle, aMessage)); + eStyle, aMessage, bIsMobile)); xBox->set_title(aTitle); switch (eErrorStyle) diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx index 080d5089eeb2..15a482e0ac48 100644 --- a/vcl/jsdialog/jsdialogbuilder.cxx +++ b/vcl/jsdialog/jsdialogbuilder.cxx @@ -204,6 +204,30 @@ std::unique_ptr<weld::Notebook> 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<SalInstanceWidget*>(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<vcl::Window> aOwnedToplevel, FixedText* pLabel, SalInstanceBuilder* pBuilder, bool bTakeOwnership) : JSWidget<SalInstanceLabel, FixedText>(aOwnedToplevel, pLabel, pBuilder, bTakeOwnership) @@ -322,3 +346,22 @@ void JSNotebook::append_page(const OString& rIdent, const OUString& rLabel) SalInstanceNotebook::append_page(rIdent, rLabel); 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 eb87ea7403f2..92d4ea38fefd 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -171,9 +171,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<css::awt::XWindow>& rWindow) |