summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2020-02-18 15:41:56 +0100
committerSzymon Kłos <szymon.klos@collabora.com>2020-05-12 19:49:36 +0200
commitad991bce9707e810c38c4897933875886a6b37b0 (patch)
treecfb644cf50fd88689cb29fa097da9eda4c9e95ba
parentfe58fc543bea0a7b370f1df503ce59d83d8b3e2c (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>
-rw-r--r--include/vcl/svapp.hxx2
-rw-r--r--include/vcl/weld.hxx2
-rw-r--r--sfx2/source/dialog/basedlgs.cxx7
-rw-r--r--vcl/Library_vcl.mk1
-rw-r--r--vcl/inc/jsdialog/jsdialogbuilder.hxx29
-rw-r--r--vcl/inc/salvtables.hxx2
-rw-r--r--vcl/jsdialog/jsdialogbuilder.cxx71
-rw-r--r--vcl/source/app/salvtables.cxx5
-rw-r--r--vcl/source/window/builder.cxx16
9 files changed, 127 insertions, 8 deletions
diff --git a/include/vcl/svapp.hxx b/include/vcl/svapp.hxx
index 6d0f16b59e90..f8be58bb6629 100644
--- a/include/vcl/svapp.hxx
+++ b/include/vcl/svapp.hxx
@@ -1376,7 +1376,7 @@ public:
// For vclbootstrapprotector:
static void setDeInitHook(Link<LinkParamNone*,void> const & hook);
- static weld::Builder* CreateBuilder(weld::Widget* pParent, const OUString &rUIFile);
+ static weld::Builder* CreateBuilder(weld::Widget* pParent, const OUString &rUIFile, bool bMobile = false);
static weld::Builder* CreateInterimBuilder(vcl::Window* pParent, const OUString &rUIFile); //for the duration of same SfxTabPages in mixed parent types
static weld::Builder* CreateInterimBuilder(weld::Widget* pParent, const OUString &rUIFile); //for the duration of same SfxTabPages in mixed parent types
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index af862d4cb91e..0017c56e2b1b 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -1419,7 +1419,7 @@ protected:
public:
GenericDialogController(weld::Widget* pParent, const OUString& rUIFile,
- const OString& rDialogId);
+ const OString& rDialogId, bool bMobile = false);
virtual Dialog* getDialog() override;
virtual ~GenericDialogController() COVERITY_NOEXCEPT_FALSE override;
};
diff --git a/sfx2/source/dialog/basedlgs.cxx b/sfx2/source/dialog/basedlgs.cxx
index 7ad50b9b86ad..d593c2596466 100644
--- a/sfx2/source/dialog/basedlgs.cxx
+++ b/sfx2/source/dialog/basedlgs.cxx
@@ -40,6 +40,8 @@
#include <sfx2/viewsh.hxx>
#include <sfx2/sfxhelp.hxx>
#include <workwin.hxx>
+#include <sfx2/lokhelper.hxx>
+#include <comphelper/lok.hxx>
using namespace ::com::sun::star::uno;
@@ -835,7 +837,10 @@ void SfxSingleTabDialog::SetTabPage(SfxTabPage* pTabPage)
SfxDialogController::SfxDialogController(weld::Widget* pParent, const OUString& rUIFile,
const OString& rDialogId)
- : GenericDialogController(pParent, rUIFile, rDialogId)
+ : GenericDialogController(pParent, rUIFile, rDialogId,
+ comphelper::LibreOfficeKit::isActive()
+ && SfxViewShell::Current()
+ && SfxViewShell::Current()->isLOKMobilePhone())
{
m_xDialog->SetInstallLOKNotifierHdl(LINK(this, SfxDialogController, InstallLOKNotifierHdl));
}
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 732c4b3514b5..c3badab07d9f 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -445,6 +445,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/backendtest/outputdevice/polypolygon \
vcl/backendtest/outputdevice/polyline \
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..5167409614f7
--- /dev/null
+++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx
@@ -0,0 +1,29 @@
+#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 f7776b3ff848..a7d07f52efbe 100644
--- a/vcl/inc/salvtables.hxx
+++ b/vcl/inc/salvtables.hxx
@@ -17,7 +17,7 @@
class SalInstanceBuilder : public weld::Builder
{
-private:
+protected:
std::unique_ptr<VclBuilder> m_xBuilder;
VclPtr<vcl::Window> m_aOwnedToplevel;
public:
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
new file mode 100644
index 000000000000..0484e91c9a41
--- /dev/null
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -0,0 +1,71 @@
+#include <jsdialog/jsdialogbuilder.hxx>
+#include <sal/log.hxx>
+#include <boost/property_tree/json_parser.hpp>
+#include <comphelper/lok.hxx>
+#include <vcl/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/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 96de2ec3b213..fb8d1a9b8354 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -3558,8 +3558,9 @@ namespace weld
Dialog* GenericDialogController::getDialog() { return m_xDialog.get(); }
- GenericDialogController::GenericDialogController(weld::Widget* pParent, const OUString &rUIFile, const OString& rDialogId)
- : m_xBuilder(Application::CreateBuilder(pParent, rUIFile))
+ GenericDialogController::GenericDialogController(weld::Widget* pParent, const OUString &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 900e9b6e9007..306e504f8f48 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -62,6 +62,7 @@
#include <tools/svlibrary.h>
#include <tools/diagnose_ex.h>
#include <comphelper/lok.hxx>
+#include <jsdialog/jsdialogbuilder.hxx>
#if defined(DISABLE_DYNLOADING) || defined(LINUX)
#include <dlfcn.h>
@@ -141,9 +142,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)