summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2020-02-24 18:35:18 +0100
committerSzymon Kłos <szymon.klos@collabora.com>2020-05-13 10:02:55 +0200
commit0ca1828712d70fe131f81ed2d5a35ccd85b81f22 (patch)
tree466232dbfa8bb9fcf6617968c746de926b543339 /vcl
parent787fac3456ab706768cc4efb6fbc4fc235239091 (diff)
Resend jsdialog on entry change
Change-Id: Ic255b8ba56f5b355a95ddc9a9587e1747b66702a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94071 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/jsdialog/jsdialogbuilder.hxx37
-rw-r--r--vcl/jsdialog/jsdialogbuilder.cxx70
2 files changed, 79 insertions, 28 deletions
diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx b/vcl/inc/jsdialog/jsdialogbuilder.hxx
index 5167409614f7..956c3001fc22 100644
--- a/vcl/inc/jsdialog/jsdialogbuilder.hxx
+++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx
@@ -8,22 +8,45 @@
#include <vcl/builder.hxx>
#include <salvtables.hxx>
+class JSDialogSender
+{
+ VclPtr<vcl::Window> m_aOwnedToplevel;
+
+public:
+ JSDialogSender(VclPtr<vcl::Window> aOwnedToplevel)
+ : m_aOwnedToplevel(aOwnedToplevel)
+ {
+ }
+
+ void notifyDialogState();
+};
+
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;
+ 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;
+ virtual std::unique_ptr<weld::Entry> weld_entry(const OString& id,
+ bool bTakeOwnership = false) override;
};
-class VCL_DLLPUBLIC JSLabel : public SalInstanceLabel
+class VCL_DLLPUBLIC JSLabel : public SalInstanceLabel, public JSDialogSender
{
- VclPtr<vcl::Window> m_aOwnedToplevel;
-
public:
- JSLabel(VclPtr<vcl::Window> aOwnedToplevel, FixedText* pLabel,
- SalInstanceBuilder* pBuilder, bool bTakeOwnership);
+ JSLabel(VclPtr<vcl::Window> aOwnedToplevel, FixedText* pLabel, SalInstanceBuilder* pBuilder,
+ bool bTakeOwnership);
virtual void set_label(const OUString& rText) override;
};
+class VCL_DLLPUBLIC JSEntry : public SalInstanceEntry, public JSDialogSender
+{
+public:
+ JSEntry(VclPtr<vcl::Window> aOwnedToplevel, ::Edit* pEntry, SalInstanceBuilder* pBuilder,
+ bool bTakeOwnership);
+ virtual void set_text(const OUString& rText) override;
+};
+
#endif \ No newline at end of file
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index 0484e91c9a41..fc1c7a0159e9 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -7,18 +7,37 @@
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)
+void JSDialogSender::notifyDialogState()
+{
+ if (!m_aOwnedToplevel)
+ return;
+
+ 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());
+ }
+}
+
+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);
+ 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");
@@ -40,32 +59,41 @@ std::unique_ptr<weld::Dialog> JSInstanceBuilder::weld_dialog(const OString& id,
return pRet;
}
-std::unique_ptr<weld::Label> JSInstanceBuilder::weld_label(const OString &id, bool bTakeOwnership)
+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);
}
+std::unique_ptr<weld::Entry> JSInstanceBuilder::weld_entry(const OString& id, bool bTakeOwnership)
+{
+ Edit* pEntry = m_xBuilder->get<Edit>(id);
+ return pEntry ? std::make_unique<JSEntry>(m_aOwnedToplevel, pEntry, this, bTakeOwnership)
+ : nullptr;
+}
+
JSLabel::JSLabel(VclPtr<vcl::Window> aOwnedToplevel, FixedText* pLabel,
- SalInstanceBuilder* pBuilder, bool bTakeOwnership)
-: SalInstanceLabel(pLabel, pBuilder, bTakeOwnership)
-, m_aOwnedToplevel(aOwnedToplevel)
+ SalInstanceBuilder* pBuilder, bool bTakeOwnership)
+ : SalInstanceLabel(pLabel, pBuilder, bTakeOwnership)
+ , JSDialogSender(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());
- }
+ notifyDialogState();
};
+JSEntry::JSEntry(VclPtr<vcl::Window> aOwnedToplevel, ::Edit* pEntry, SalInstanceBuilder* pBuilder,
+ bool bTakeOwnership)
+ : SalInstanceEntry(pEntry, pBuilder, bTakeOwnership)
+ , JSDialogSender(aOwnedToplevel)
+{
+}
+
+void JSEntry::set_text(const OUString& rText)
+{
+ SalInstanceEntry::set_text(rText);
+ notifyDialogState();
+}