[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - vcl/inc vcl/jsdialog

Szymon KÅ‚os (via logerrit) logerrit at kemper.freedesktop.org
Wed May 13 08:03:25 UTC 2020


 vcl/inc/jsdialog/jsdialogbuilder.hxx |   37 +++++++++++++++---
 vcl/jsdialog/jsdialogbuilder.cxx     |   70 ++++++++++++++++++++++++-----------
 2 files changed, 79 insertions(+), 28 deletions(-)

New commits:
commit 0ca1828712d70fe131f81ed2d5a35ccd85b81f22
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Mon Feb 24 18:35:18 2020 +0100
Commit:     Szymon Kłos <szymon.klos at collabora.com>
CommitDate: Wed May 13 10:02:55 2020 +0200

    Resend jsdialog on entry change
    
    Change-Id: Ic255b8ba56f5b355a95ddc9a9587e1747b66702a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94071
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>

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();
+}


More information about the Libreoffice-commits mailing list