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/jsdialog/jsdialogbuilder.cxx | |
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/jsdialog/jsdialogbuilder.cxx')
-rw-r--r-- | vcl/jsdialog/jsdialogbuilder.cxx | 72 |
1 files changed, 72 insertions, 0 deletions
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()); + } +}; |