[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - 2 commits - desktop/source include/vcl vcl/inc vcl/jsdialog

Szymon KÅ‚os (via logerrit) logerrit at kemper.freedesktop.org
Tue Dec 1 10:02:57 UTC 2020


 desktop/source/lib/init.cxx          |   22 ----------
 include/vcl/jsdialog/executor.hxx    |    8 +++
 include/vcl/salvtables.hxx           |    2 
 include/vcl/weld.hxx                 |    4 +
 vcl/inc/jsdialog/jsdialogbuilder.hxx |   20 +++++++++
 vcl/jsdialog/executor.cxx            |   65 +++++++++++++++++++++++++++++
 vcl/jsdialog/jsdialogbuilder.cxx     |   76 +++++++++++++++++++++++++++++++++++
 7 files changed, 176 insertions(+), 21 deletions(-)

New commits:
commit 26b45c96ca1b2c2214a88d24a08de94b712db584
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Mon Nov 2 12:24:49 2020 +0100
Commit:     Szymon Kłos <szymon.klos at collabora.com>
CommitDate: Tue Dec 1 11:02:36 2020 +0100

    jsdialog: execute checkbox action
    
    Change-Id: Ib19997f600404cc9555acbfaf87acac32f8aa5fc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106904
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>

diff --git a/include/vcl/jsdialog/executor.hxx b/include/vcl/jsdialog/executor.hxx
index e49190f31e5f..5dde733a3823 100644
--- a/include/vcl/jsdialog/executor.hxx
+++ b/include/vcl/jsdialog/executor.hxx
@@ -22,6 +22,8 @@ public:
 
     static void trigger_changed(weld::ComboBox& rComboBox) { rComboBox.signal_changed(); }
 
+    static void trigger_toggled(weld::ToggleButton& rButton) { rButton.signal_toggled(); }
+
     static void trigger_row_activated(weld::TreeView& rTreeView)
     {
         rTreeView.signal_row_activated();
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 289c68aa148e..6dcd91c97ccb 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -1126,6 +1126,8 @@ public:
 
 class VCL_DLLPUBLIC ToggleButton : virtual public Button
 {
+    friend class ::LOKTrigger;
+
 protected:
     Link<ToggleButton&, void> m_aToggleHdl;
     TriState m_eSavedValue = TRISTATE_FALSE;
diff --git a/vcl/jsdialog/executor.cxx b/vcl/jsdialog/executor.cxx
index dc98ba525458..a4fb7093b4bf 100644
--- a/vcl/jsdialog/executor.cxx
+++ b/vcl/jsdialog/executor.cxx
@@ -96,6 +96,20 @@ bool ExecuteAction(sal_uInt64 nWindowId, const OString& rWidget, StringMap& rDat
                 }
             }
         }
+        else if (sControlType == "checkbox")
+        {
+            auto pCheckButton = dynamic_cast<weld::CheckButton*>(pWidget);
+            if (pCheckButton)
+            {
+                if (sAction == "change")
+                {
+                    bool bChecked = rData["data"] == "true";
+                    pCheckButton->set_state(bChecked ? TRISTATE_TRUE : TRISTATE_FALSE);
+                    LOKTrigger::trigger_toggled(*static_cast<weld::ToggleButton*>(pCheckButton));
+                    return true;
+                }
+            }
+        }
         else if (sControlType == "drawingarea")
         {
             auto pArea = dynamic_cast<weld::DrawingArea*>(pWidget);
commit c191da8d670262db1631f98ad3c9885f8f05dc10
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Fri Oct 30 10:51:08 2020 +0100
Commit:     Szymon Kłos <szymon.klos at collabora.com>
CommitDate: Tue Dec 1 11:02:22 2020 +0100

    jsdialog: implement TreeView
    
    Change-Id: I7c1cc683e8c5d5bdc00c1e3d3d0a2c85846bbda0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106903
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index c9d5e7d1d489..4b043141e743 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -449,24 +449,6 @@ std::vector<beans::PropertyValue> desktop::jsonToPropertyValuesVector(const char
 }
 
 
-static StringMap jsonToStringMap(const char* pJSON)
-{
-    StringMap aArgs;
-    if (pJSON && pJSON[0] != '\0')
-    {
-        std::stringstream aStream(pJSON);
-        boost::property_tree::ptree aTree;
-        boost::property_tree::read_json(aStream, aTree);
-
-        for (const auto& rPair : aTree)
-        {
-            aArgs[OUString::fromUtf8(rPair.first.c_str())] = OUString::fromUtf8(rPair.second.get_value<std::string>(".").c_str());
-        }
-    }
-    return aArgs;
-}
-
-
 static boost::property_tree::ptree unoAnyToPropertyTree(const uno::Any& anyItem)
 {
     boost::property_tree::ptree aTree;
@@ -3714,7 +3696,7 @@ static void doc_sendDialogEvent(LibreOfficeKitDocument* /*pThis*/, unsigned long
 {
     SolarMutexGuard aGuard;
 
-    StringMap aMap(jsonToStringMap(pArguments));
+    StringMap aMap(jsdialog::jsonToStringMap(pArguments));
     VclPtr<Window> pWindow = vcl::Window::FindLOKWindow(nWindowId);
 
     if (!pWindow && nWindowId >= 1000000000 /* why unsigned? */)
@@ -5704,7 +5686,7 @@ static void doc_sendFormFieldEvent(LibreOfficeKitDocument* pThis, const char* pA
     if (doc_getDocumentType(pThis) != LOK_DOCTYPE_TEXT)
             return;
 
-    StringMap aMap(jsonToStringMap(pArguments));
+    StringMap aMap(jsdialog::jsonToStringMap(pArguments));
     ITiledRenderable* pDoc = getTiledRenderable(pThis);
     if (!pDoc)
     {
diff --git a/include/vcl/jsdialog/executor.hxx b/include/vcl/jsdialog/executor.hxx
index 1cfa24c28a8a..e49190f31e5f 100644
--- a/include/vcl/jsdialog/executor.hxx
+++ b/include/vcl/jsdialog/executor.hxx
@@ -22,6 +22,11 @@ public:
 
     static void trigger_changed(weld::ComboBox& rComboBox) { rComboBox.signal_changed(); }
 
+    static void trigger_row_activated(weld::TreeView& rTreeView)
+    {
+        rTreeView.signal_row_activated();
+    }
+
     static void trigger_clicked(weld::Toolbar& rToolbar, const OString& rIdent)
     {
         rToolbar.signal_clicked(rIdent);
@@ -36,6 +41,7 @@ public:
 namespace jsdialog
 {
 VCL_DLLPUBLIC bool ExecuteAction(sal_uInt64 nWindowId, const OString& rWidget, StringMap& rData);
+VCL_DLLPUBLIC StringMap jsonToStringMap(const char* pJSON);
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/include/vcl/salvtables.hxx b/include/vcl/salvtables.hxx
index 7e98f133251b..ee55bb9fa081 100644
--- a/include/vcl/salvtables.hxx
+++ b/include/vcl/salvtables.hxx
@@ -1103,7 +1103,7 @@ public:
 
 class SalInstanceTreeView : public SalInstanceContainer, public virtual weld::TreeView
 {
-private:
+protected:
     // owner for UserData
     std::vector<std::unique_ptr<OUString>> m_aUserData;
     VclPtr<SvTabListBox> m_xTreeView;
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 248bbfcd80ed..289c68aa148e 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -685,6 +685,8 @@ public:
 */
 class VCL_DLLPUBLIC TreeView : virtual public Container
 {
+    friend class ::LOKTrigger;
+
 public:
     typedef std::pair<const TreeIter&, int> iter_col;
     typedef std::pair<const TreeIter&, OUString> iter_string;
diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx b/vcl/inc/jsdialog/jsdialogbuilder.hxx
index 709030d0c931..86bc0020eaea 100644
--- a/vcl/inc/jsdialog/jsdialogbuilder.hxx
+++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx
@@ -19,6 +19,7 @@
 #include <vcl/combobox.hxx>
 #include <vcl/button.hxx>
 #include <vcl/fmtfield.hxx>
+#include <vcl/svtabbx.hxx>
 
 class ToolBox;
 class SfxViewShell;
@@ -122,6 +123,8 @@ public:
                                                 bool bTakeOwnership = true) override;
     std::unique_ptr<weld::TextView> weld_text_view(const OString& id,
                                                    bool bTakeOwnership = false) override;
+    std::unique_ptr<weld::TreeView> weld_tree_view(const OString& id,
+                                                   bool bTakeOwnership = false) override;
 
     static weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent,
                                                     VclMessageType eMessageType,
@@ -157,6 +160,7 @@ public:
         notifyDialogState();
     }
 
+    using BaseInstanceClass::set_sensitive;
     virtual void set_sensitive(bool sensitive) override
     {
         BaseInstanceClass::set_sensitive(sensitive);
@@ -303,4 +307,20 @@ public:
     virtual void set_text(const OUString& rText) override;
 };
 
+class JSTreeView : public JSWidget<SalInstanceTreeView, ::SvTabListBox>
+{
+public:
+    JSTreeView(VclPtr<vcl::Window> aNotifierWindow, VclPtr<vcl::Window> aContentWindow,
+               ::SvTabListBox* pTextView, SalInstanceBuilder* pBuilder, bool bTakeOwnership,
+               std::string sTypeOfJSON);
+
+    using SalInstanceTreeView::set_toggle;
+    /// pos is used differently here, it defines how many steps of iterator we need to perform to take entry
+    virtual void set_toggle(int pos, TriState eState, int col = -1) override;
+
+    using SalInstanceTreeView::select;
+    /// pos is used differently here, it defines how many steps of iterator we need to perform to take entry
+    virtual void select(int pos) override;
+};
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/vcl/jsdialog/executor.cxx b/vcl/jsdialog/executor.cxx
index 27d61d65209a..dc98ba525458 100644
--- a/vcl/jsdialog/executor.cxx
+++ b/vcl/jsdialog/executor.cxx
@@ -11,9 +11,28 @@
 #include <vcl/weld.hxx>
 #include <vcl/jsdialog/executor.hxx>
 #include <sal/log.hxx>
+#include <rtl/uri.hxx>
 
 namespace jsdialog
 {
+StringMap jsonToStringMap(const char* pJSON)
+{
+    StringMap aArgs;
+    if (pJSON && pJSON[0] != '\0')
+    {
+        std::stringstream aStream(pJSON);
+        boost::property_tree::ptree aTree;
+        boost::property_tree::read_json(aStream, aTree);
+
+        for (const auto& rPair : aTree)
+        {
+            aArgs[OUString::fromUtf8(rPair.first.c_str())]
+                = OUString::fromUtf8(rPair.second.get_value<std::string>(".").c_str());
+        }
+    }
+    return aArgs;
+}
+
 bool ExecuteAction(sal_uInt64 nWindowId, const OString& rWidget, StringMap& rData)
 {
     weld::Widget* pWidget = JSInstanceBuilder::FindWeldWidgetsMap(nWindowId, rWidget);
@@ -143,6 +162,38 @@ bool ExecuteAction(sal_uInt64 nWindowId, const OString& rWidget, StringMap& rDat
                 }
             }
         }
+        else if (sControlType == "treeview")
+        {
+            auto pTreeView = dynamic_cast<weld::TreeView*>(pWidget);
+            if (pTreeView)
+            {
+                if (sAction == "change")
+                {
+                    OUString sDataJSON = rtl::Uri::decode(
+                        rData["data"], rtl_UriDecodeMechanism::rtl_UriDecodeWithCharset,
+                        RTL_TEXTENCODING_UTF8);
+                    StringMap aMap(jsonToStringMap(
+                        OUStringToOString(sDataJSON, RTL_TEXTENCODING_ASCII_US).getStr()));
+
+                    OString nRowString = OUStringToOString(aMap["row"], RTL_TEXTENCODING_ASCII_US);
+                    int nRow = std::atoi(nRowString.getStr());
+                    bool bValue = aMap["value"] == "true";
+
+                    pTreeView->set_toggle(nRow, bValue ? TRISTATE_TRUE : TRISTATE_FALSE);
+
+                    return true;
+                }
+                else if (sAction == "select")
+                {
+                    OString nRowString
+                        = OUStringToOString(rData["data"], RTL_TEXTENCODING_ASCII_US);
+                    int nRow = std::atoi(nRowString.getStr());
+
+                    pTreeView->select(nRow);
+                    LOKTrigger::trigger_row_activated(*pTreeView);
+                }
+            }
+        }
     }
 
     return false;
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index 827cb6aaa44d..877ebaf6e8db 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -15,6 +15,7 @@
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <vcl/toolbox.hxx>
 #include <vcl/vclmedit.hxx>
+#include <vcl/treelistentry.hxx>
 
 using namespace weld;
 
@@ -46,6 +47,25 @@ void JSDialogNotifyIdle::Invoke()
             boost::property_tree::ptree aTree = m_aContentWindow->DumpAsPropertyTree();
             aTree.put("id", m_aNotifierWindow->GetLOKWindowId());
             aTree.put("jsontype", m_sTypeOfJSON);
+
+            if (m_sTypeOfJSON == "autofilter")
+            {
+                vcl::Window* pWindow = m_aContentWindow.get();
+                DockingWindow* pDockingWIndow = dynamic_cast<DockingWindow*>(pWindow);
+                while (pWindow && !pDockingWIndow)
+                {
+                    pWindow = pWindow->GetParent();
+                    pDockingWIndow = dynamic_cast<DockingWindow*>(pWindow);
+                }
+
+                if (pDockingWIndow)
+                {
+                    Point aPos = pDockingWIndow->GetFloatingPos();
+                    aTree.put("posx", aPos.getX());
+                    aTree.put("posy", aPos.getY());
+                }
+            }
+
             boost::property_tree::write_json(aStream, aTree);
             const std::string message = aStream.str();
             if (m_bForce || message != m_LastNotificationMessage)
@@ -428,6 +448,21 @@ std::unique_ptr<weld::TextView> JSInstanceBuilder::weld_text_view(const OString&
     return pWeldWidget;
 }
 
+std::unique_ptr<weld::TreeView> JSInstanceBuilder::weld_tree_view(const OString& id,
+                                                                  bool bTakeOwnership)
+{
+    SvTabListBox* pTreeView = m_xBuilder->get<SvTabListBox>(id);
+    auto pWeldWidget
+        = pTreeView ? std::make_unique<JSTreeView>(GetNotifierWindow(), GetContentWindow(),
+                                                   pTreeView, this, bTakeOwnership, m_sTypeOfJSON)
+                    : nullptr;
+
+    if (pWeldWidget)
+        RememberWidget(id, pWeldWidget.get());
+
+    return pWeldWidget;
+}
+
 weld::MessageDialog* JSInstanceBuilder::CreateMessageDialog(weld::Widget* pParent,
                                                             VclMessageType eMessageType,
                                                             VclButtonsType eButtonType,
@@ -710,4 +745,45 @@ void JSTextView::set_text(const OUString& rText)
     notifyDialogState();
 }
 
+JSTreeView::JSTreeView(VclPtr<vcl::Window> aNotifierWindow, VclPtr<vcl::Window> aContentWindow,
+                       ::SvTabListBox* pTreeView, SalInstanceBuilder* pBuilder, bool bTakeOwnership,
+                       std::string sTypeOfJSON)
+    : JSWidget<SalInstanceTreeView, ::SvTabListBox>(aNotifierWindow, aContentWindow, pTreeView,
+                                                    pBuilder, bTakeOwnership, sTypeOfJSON)
+{
+}
+
+void JSTreeView::set_toggle(int pos, TriState eState, int col)
+{
+    SvTreeListEntry* pEntry = m_xTreeView->GetEntry(nullptr, 0);
+
+    while (pEntry && pos--)
+        pEntry = m_xTreeView->Next(pEntry);
+
+    if (pEntry)
+        SalInstanceTreeView::set_toggle(pEntry, eState, col);
+}
+
+void JSTreeView::select(int pos)
+{
+    assert(m_xTreeView->IsUpdateMode() && "don't select when frozen");
+    disable_notify_events();
+    if (pos == -1 || (pos == 0 && n_children() == 0))
+        m_xTreeView->SelectAll(false);
+    else
+    {
+        SvTreeListEntry* pEntry = m_xTreeView->GetEntry(nullptr, 0);
+
+        while (pEntry && pos--)
+            pEntry = m_xTreeView->Next(pEntry);
+
+        if (pEntry)
+        {
+            m_xTreeView->Select(pEntry, true);
+            m_xTreeView->MakeVisible(pEntry);
+        }
+    }
+    enable_notify_events();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */


More information about the Libreoffice-commits mailing list