diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2020-02-18 15:41:56 +0100 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2020-05-18 22:08:05 +0200 |
commit | a76116c867380836080adc86bc37c2248778825d (patch) | |
tree | 36b50e8039aa0b3e30e66de554b2f0e64bf8c029 /vcl | |
parent | c8961ff03fb8f136f6a123bd74f96adffd138840 (diff) |
Create weld::Builder implementation for JSDialog
and use for WordCountDialog on mobile
Change-Id: I12c3455ff9b16c30918067f9282b72f49141a308
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94041
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94055
Tested-by: Jenkins
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/Library_vcl.mk | 1 | ||||
-rw-r--r-- | vcl/inc/jsdialog/jsdialogbuilder.hxx | 31 | ||||
-rw-r--r-- | vcl/inc/salvtables.hxx | 4 | ||||
-rw-r--r-- | vcl/jsdialog/jsdialogbuilder.cxx | 72 | ||||
-rw-r--r-- | vcl/source/app/weldutils.cxx | 4 | ||||
-rw-r--r-- | vcl/source/window/builder.cxx | 17 |
6 files changed, 123 insertions, 6 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 65f65b525f4c..35590174946e 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -472,6 +472,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/backendtest/outputdevice/polyline \ vcl/backendtest/outputdevice/polyline_b2d \ vcl/backendtest/outputdevice/rectangle \ + vcl/jsdialog/jsdialogbuilder \ )) $(eval $(call gb_Library_add_cobjects,vcl,\ diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx b/vcl/inc/jsdialog/jsdialogbuilder.hxx new file mode 100644 index 000000000000..9d8c68516320 --- /dev/null +++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx @@ -0,0 +1,31 @@ +#ifndef INCLUDED_VCL_INC_JSDIALOG_JSDIALOG_HXX +#define INCLUDED_VCL_INC_JSDIALOG_JSDIALOG_HXX + +#include <vcl/weld.hxx> +#include <comphelper/string.hxx> +#include <vcl/sysdata.hxx> +#include <vcl/virdev.hxx> +#include <vcl/builder.hxx> +#include <salvtables.hxx> + +class VCL_DLLPUBLIC JSInstanceBuilder : public SalInstanceBuilder +{ +public: + JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile); + virtual std::unique_ptr<weld::Dialog> weld_dialog(const OString& id, + bool bTakeOwnership = true) override; + virtual std::unique_ptr<weld::Label> weld_label(const OString& id, + bool bTakeOwnership = false) override; +}; + +class VCL_DLLPUBLIC JSLabel : public SalInstanceLabel +{ + VclPtr<vcl::Window> m_aOwnedToplevel; + +public: + JSLabel(VclPtr<vcl::Window> aOwnedToplevel, FixedText* pLabel, SalInstanceBuilder* pBuilder, + bool bTakeOwnership); + virtual void set_label(const OUString& rText) override; +}; + +#endif
\ No newline at end of file diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx index 628b4b707c34..c95f093c898f 100644 --- a/vcl/inc/salvtables.hxx +++ b/vcl/inc/salvtables.hxx @@ -26,7 +26,7 @@ class SalInstanceBuilder : public weld::Builder { -private: +protected: std::unique_ptr<VclBuilder> m_xBuilder; VclPtr<vcl::Window> m_aOwnedToplevel; @@ -393,7 +393,7 @@ public: SystemWindow* getSystemWindow(); }; -class SalInstanceLabel final : public SalInstanceWidget, public virtual weld::Label +class SalInstanceLabel : public SalInstanceWidget, public virtual weld::Label { private: // Control instead of FixedText so we can also use this for diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx new file mode 100644 index 000000000000..1d751ea42847 --- /dev/null +++ b/vcl/jsdialog/jsdialogbuilder.cxx @@ -0,0 +1,72 @@ +#include <jsdialog/jsdialogbuilder.hxx> +#include <sal/log.hxx> +#include <boost/property_tree/json_parser.hpp> +#include <comphelper/lok.hxx> +#include <vcl/toolkit/dialog.hxx> +#include <LibreOfficeKit/LibreOfficeKitEnums.h> + +using namespace weld; + +JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, + const OUString& rUIFile) + : SalInstanceBuilder(dynamic_cast<SalInstanceWidget*>(pParent) + ? dynamic_cast<SalInstanceWidget*>(pParent)->getWidget() + : nullptr, + rUIRoot, rUIFile) +{ +} + +std::unique_ptr<weld::Dialog> JSInstanceBuilder::weld_dialog(const OString& id, bool bTakeOwnership) +{ + ::Dialog* pDialog = m_xBuilder->get<::Dialog>(id); + std::unique_ptr<weld::Dialog> pRet(pDialog ? new SalInstanceDialog(pDialog, this, false) + : nullptr); + if (bTakeOwnership && pDialog) + { + assert(!m_aOwnedToplevel && "only one toplevel per .ui allowed"); + m_aOwnedToplevel.set(pDialog); + m_xBuilder->drop_ownership(pDialog); + } + + const vcl::ILibreOfficeKitNotifier* pNotifier = pDialog->GetLOKNotifier(); + if (pNotifier) + { + std::stringstream aStream; + boost::property_tree::ptree aTree = m_aOwnedToplevel->DumpAsPropertyTree(); + aTree.put("id", m_aOwnedToplevel->GetLOKWindowId()); + boost::property_tree::write_json(aStream, aTree); + const std::string message = aStream.str(); + pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, message.c_str()); + } + + return pRet; +} + +std::unique_ptr<weld::Label> JSInstanceBuilder::weld_label(const OString& id, bool bTakeOwnership) +{ + ::FixedText* pLabel = m_xBuilder->get<FixedText>(id); + return std::make_unique<JSLabel>(m_aOwnedToplevel, pLabel, this, bTakeOwnership); +} + +JSLabel::JSLabel(VclPtr<vcl::Window> aOwnedToplevel, FixedText* pLabel, + SalInstanceBuilder* pBuilder, bool bTakeOwnership) + : SalInstanceLabel(pLabel, pBuilder, bTakeOwnership) + , m_aOwnedToplevel(aOwnedToplevel) +{ +} + +void JSLabel::set_label(const OUString& rText) +{ + SalInstanceLabel::set_label(rText); + + const vcl::ILibreOfficeKitNotifier* pNotifier = m_aOwnedToplevel->GetLOKNotifier(); + if (pNotifier) + { + std::stringstream aStream; + boost::property_tree::ptree aTree = m_aOwnedToplevel->DumpAsPropertyTree(); + aTree.put("id", m_aOwnedToplevel->GetLOKWindowId()); + boost::property_tree::write_json(aStream, aTree); + const std::string message = aStream.str(); + pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, message.c_str()); + } +}; diff --git a/vcl/source/app/weldutils.cxx b/vcl/source/app/weldutils.cxx index 19f6464052d6..69562cf0d8c7 100644 --- a/vcl/source/app/weldutils.cxx +++ b/vcl/source/app/weldutils.cxx @@ -40,8 +40,8 @@ DialogController::~DialogController() COVERITY_NOEXCEPT_FALSE {} Dialog* GenericDialogController::getDialog() { return m_xDialog.get(); } GenericDialogController::GenericDialogController(weld::Widget* pParent, const OUString& rUIFile, - const OString& rDialogId) - : m_xBuilder(Application::CreateBuilder(pParent, rUIFile)) + const OString& rDialogId, bool bMobile) + : m_xBuilder(Application::CreateBuilder(pParent, rUIFile, bMobile)) , m_xDialog(m_xBuilder->weld_dialog(rDialogId)) { } diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 6189412ac8b9..03f9de9926bd 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -68,6 +68,8 @@ #include <tools/diagnose_ex.h> #include <wizdlg.hxx> #include <tools/svlibrary.h> +#include <comphelper/lok.hxx> +#include <jsdialog/jsdialogbuilder.hxx> #if defined(DISABLE_DYNLOADING) || defined(LINUX) #include <dlfcn.h> @@ -151,9 +153,20 @@ namespace } #endif -weld::Builder* Application::CreateBuilder(weld::Widget* pParent, const OUString &rUIFile) +weld::Builder* Application::CreateBuilder(weld::Widget* pParent, const OUString &rUIFile, bool bMobile) { - return ImplGetSVData()->mpDefInst->CreateBuilder(pParent, VclBuilderContainer::getUIRootDir(), rUIFile); + bool bUseJSBuilder = false; + + if (bMobile) + { + if (rUIFile == "modules/swriter/ui/wordcount-mobile.ui") + bUseJSBuilder = true; + } + + if (bUseJSBuilder) + return new JSInstanceBuilder(pParent, VclBuilderContainer::getUIRootDir(), rUIFile); + else + return ImplGetSVData()->mpDefInst->CreateBuilder(pParent, VclBuilderContainer::getUIRootDir(), rUIFile); } weld::Builder* Application::CreateInterimBuilder(vcl::Window* pParent, const OUString &rUIFile) |