desktop/source/lib/init.cxx          |  138 +---------------------------------
 include/vcl/jsdialog/executor.hxx    |    4 
 include/vcl/weld.hxx                 |   12 ++
 vcl/Library_vcl.mk                   |    1 
 vcl/inc/jsdialog/jsdialogbuilder.hxx |    7 -
 vcl/jsdialog/executor.cxx            |  141 +++++++++++++++++++++++++++++++++++
 vcl/jsdialog/jsdialogbuilder.cxx     |    9 --
 7 files changed, 166 insertions(+), 146 deletions(-)

New commits:
commit b017893371d1f92eda6020728494eebca7626a69
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Thu Jul 2 11:01:54 2020 +0200
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Thu Jul 2 12:09:21 2020 +0200

    jsdialog: move executor code to vcl
    
    Change-Id: I9247a652707fe3239dc488a605a2c506d8eec95c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97736
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 93412fbc6473..0eb6b45a0d03 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -158,7 +158,7 @@
 #include <vcl/abstdlg.hxx>
 #include <tools/diagnose_ex.h>
 #include <vcl/uitest/uiobject.hxx>
-#include <vcl/jsdialog/builder.hxx>
+#include <vcl/jsdialog/executor.hxx>
 
 // Needed for getUndoManager()
 #include <com/sun/star/document/XUndoManager.hpp>
@@ -3646,137 +3646,11 @@ static void 
doc_sendDialogEvent(LibreOfficeKitDocument* /*pThis*/, unsigned long
         try
         {
             OString sControlId = OUStringToOString(aMap["id"], 
RTL_TEXTENCODING_ASCII_US);
-            weld::Widget* pWidget = jsdialog::FindWeldWidgetsMap(nWindowId, 
sControlId);
-            if (!pWidget && nWindowId == 0)
-            {
-                pWidget = 
jsdialog::FindWeldWidgetsMap(reinterpret_cast<sal_uInt64>(SfxViewShell::Current()),
 sControlId);
-            }
-
-            bIsWeldedDialog = pWidget != nullptr;
-            bool bContinueWithLOKWindow = false;
-
-            if (bIsWeldedDialog)
-            {
-                OUString sControlType = aMap["type"];
-                OUString sAction = aMap["cmd"];
-
-                if (sControlType == "tabcontrol")
-                {
-                    auto pNotebook = dynamic_cast<weld::Notebook*>(pWidget);
-                    if (pNotebook)
-                    {
-                        if (sAction == "selecttab")
-                        {
-                            OString pageId = OUStringToOString(aMap["data"], 
RTL_TEXTENCODING_ASCII_US);
-                            int page = std::atoi(pageId.getStr());
 
-                            pNotebook->set_current_page(page);
-                        }
-                        else
-                            bContinueWithLOKWindow = true;
-                    }
-                }
-                else if (sControlType == "combobox")
-                {
-                    auto pCombobox = dynamic_cast<weld::ComboBox*>(pWidget);
-                    if (pCombobox)
-                    {
-                        if (sAction == "selected")
-                        {
-                            int separatorPos = aMap["data"].indexOf(';');
-                            if (separatorPos)
-                            {
-                                OUString entryPos = aMap["data"].copy(0, 
separatorPos);
-                                OString posString = 
OUStringToOString(entryPos, RTL_TEXTENCODING_ASCII_US);
-                                int pos = std::atoi(posString.getStr());
-                                pCombobox->set_active(pos);
-                                pCombobox->signal_changed();
-                            }
-                        }
-                        else if (sAction == "change")
-                        {
-                            pCombobox->set_entry_text(aMap["data"]);
-                            pCombobox->signal_changed();
-                        }
-                        else
-                            bContinueWithLOKWindow = true;
-                    }
-                }
-                else if (sControlType == "pushbutton")
-                {
-                    auto pButton = dynamic_cast<weld::Button*>(pWidget);
-                    if (pButton)
-                    {
-                        if (sAction == "click")
-                        {
-                            pButton->clicked();
-                        }
-                        else
-                            bContinueWithLOKWindow = true;
-                    }
-                }
-                else if (sControlType == "drawingarea")
-                {
-                    auto pArea = dynamic_cast<weld::DrawingArea*>(pWidget);
-                    if (pArea)
-                    {
-                        if (sAction == "click")
-                        {
-                            pArea->click(Point(10, 10));
-                        }
-                        else
-                            bContinueWithLOKWindow = true;
-                    }
-                }
-                else if (sControlType == "spinfield")
-                {
-                    auto pSpinField = dynamic_cast<weld::SpinButton*>(pWidget);
-                    if (pSpinField)
-                    {
-                        if (sAction == "plus")
-                        {
-                            pSpinField->set_value(pSpinField->get_value() + 1);
-                        }
-                        else if (sAction == "minus")
-                        {
-                            pSpinField->set_value(pSpinField->get_value() - 1);
-                        }
-                        else
-                            bContinueWithLOKWindow = true;
-                    }
-                }
-                else if (sControlType == "toolbox")
-                {
-                    auto pToolbar = dynamic_cast<weld::Toolbar*>(pWidget);
-                    if (pToolbar)
-                    {
-                        if (sAction == "click")
-                        {
-                            
pToolbar->signal_clicked(OUStringToOString(aMap["data"], 
RTL_TEXTENCODING_ASCII_US));
-                        }
-                        else
-                            bContinueWithLOKWindow = true;
-                    }
-                }
-                else if (sControlType == "edit")
-                {
-                    auto pEdit = dynamic_cast<weld::Entry*>(pWidget);
-                    if (pEdit)
-                    {
-                        if (sAction == "change")
-                        {
-                            pEdit->set_text(aMap["data"]);
-                            pEdit->signal_changed();
-                        }
-                        else
-                            bContinueWithLOKWindow = true;
-                    }
-                }
-                else
-                {
-                    bContinueWithLOKWindow = true;
-                }
-            }
+            bIsWeldedDialog = jsdialog::ExecuteAction(nWindowId, sControlId, 
aMap);
+            if (!bIsWeldedDialog)
+                bIsWeldedDialog = 
jsdialog::ExecuteAction(reinterpret_cast<sal_uInt64>(SfxViewShell::Current()),
+                                                          sControlId, aMap);
 
             if (!pWindow)
             {
@@ -3784,7 +3658,7 @@ static void doc_sendDialogEvent(LibreOfficeKitDocument* 
/*pThis*/, unsigned long
                 return;
             }
 
-            if (!bIsWeldedDialog || bContinueWithLOKWindow)
+            if (!bIsWeldedDialog)
             {
                 WindowUIObject aUIObject(pWindow);
                 std::unique_ptr<UIObject> 
pUIWindow(aUIObject.get_child(aMap["id"]));
diff --git a/include/vcl/jsdialog/builder.hxx 
b/include/vcl/jsdialog/executor.hxx
similarity index 80%
rename from include/vcl/jsdialog/builder.hxx
rename to include/vcl/jsdialog/executor.hxx
index b054b1d00a08..9cc4471551ba 100644
--- a/include/vcl/jsdialog/builder.hxx
+++ b/include/vcl/jsdialog/executor.hxx
@@ -10,12 +10,12 @@
 #pragma once
 
 #include <vcl/dllapi.h>
-#include <vcl/IDialogRenderable.hxx>
+#include <vcl/uitest/uiobject.hxx>
 #include <vcl/weld.hxx>
 
 namespace jsdialog
 {
-VCL_DLLPUBLIC weld::Widget* FindWeldWidgetsMap(sal_uInt64 nWindowId, const 
OString& rWidget);
+VCL_DLLPUBLIC bool ExecuteAction(sal_uInt64 nWindowId, const OString& rWidget, 
StringMap& rData);
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index d5fd850fdcc4..abe893bdf03a 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -10,6 +10,7 @@
 #ifndef INCLUDED_VCL_WELD_HXX
 #define INCLUDED_VCL_WELD_HXX
 
+#include <vcl/jsdialog/executor.hxx>
 #include <basegfx/range/b2irange.hxx>
 #include <rtl/ustring.hxx>
 #include <tools/color.hxx>
@@ -562,6 +563,9 @@ enum class EntryMessageType
 /// A widget used to choose from a list of items.
 class VCL_DLLPUBLIC ComboBox : virtual public Container
 {
+    friend VCL_DLLPUBLIC bool jsdialog::ExecuteAction(sal_uInt64 nWindowId, 
const OString& rWidget,
+                                                      StringMap& rData);
+
 private:
     OUString m_sSavedValue;
 
@@ -571,10 +575,10 @@ protected:
     Link<ComboBox&, bool> m_aEntryActivateHdl;
     Link<OUString&, bool> m_aEntryInsertTextHdl;
 
-public:
     void signal_changed() { m_aChangeHdl.Call(*this); }
     virtual void signal_popup_toggled() { m_aPopupToggledHdl.Call(*this); }
 
+public:
     virtual void insert(int pos, const OUString& rStr, const OUString* pId,
                         const OUString* pIconName, VirtualDevice* 
pImageSurface)
         = 0;
@@ -1242,6 +1246,9 @@ public:
 
 class VCL_DLLPUBLIC Entry : virtual public Widget
 {
+    friend VCL_DLLPUBLIC bool jsdialog::ExecuteAction(sal_uInt64 nWindowId, 
const OString& rWidget,
+                                                      StringMap& rData);
+
 private:
     OUString m_sSavedValue;
 
@@ -1251,12 +1258,11 @@ protected:
     Link<Entry&, void> m_aCursorPositionHdl;
     Link<Entry&, bool> m_aActivateHdl;
 
+    void signal_changed() { m_aChangeHdl.Call(*this); }
     void signal_cursor_position() { m_aCursorPositionHdl.Call(*this); }
     void signal_insert_text(OUString& rString);
 
 public:
-    void signal_changed() { m_aChangeHdl.Call(*this); }
-
     virtual void set_text(const OUString& rText) = 0;
     virtual OUString get_text() const = 0;
     virtual void set_width_chars(int nChars) = 0;
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index af4b972b67e2..94707b6ee6b8 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -472,6 +472,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/backendtest/outputdevice/polyline_b2d \
     vcl/backendtest/outputdevice/rectangle \
     vcl/jsdialog/jsdialogbuilder \
+    vcl/jsdialog/executor \
 ))
 
 $(eval $(call gb_Library_add_cobjects,vcl,\
diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx 
b/vcl/inc/jsdialog/jsdialogbuilder.hxx
index 362344b6a8b0..883ac6ec70a5 100644
--- a/vcl/inc/jsdialog/jsdialogbuilder.hxx
+++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx
@@ -9,8 +9,8 @@
 
 #pragma once
 
-#include <vcl/jsdialog/builder.hxx>
 #include <vcl/weld.hxx>
+#include <vcl/jsdialog/executor.hxx>
 #include <comphelper/string.hxx>
 #include <vcl/sysdata.hxx>
 #include <vcl/virdev.hxx>
@@ -57,12 +57,13 @@ class JSInstanceBuilder : public SalInstanceBuilder
     bool m_bHasTopLevelDialog;
     bool m_bIsNotebookbar;
 
-    friend VCL_DLLPUBLIC weld::Widget* jsdialog::FindWeldWidgetsMap(sal_uInt64 
nWindowId,
-                                                                    const 
OString& rWidget);
+    friend VCL_DLLPUBLIC bool jsdialog::ExecuteAction(sal_uInt64 nWindowId, 
const OString& rWidget,
+                                                      StringMap& rData);
 
     static std::map<sal_uInt64, WidgetMap>& GetLOKWeldWidgetsMap();
     static void InsertWindowToMap(sal_uInt64 nWindowId);
     void RememberWidget(const OString& id, weld::Widget* pWidget);
+    static weld::Widget* FindWeldWidgetsMap(sal_uInt64 nWindowId, const 
OString& rWidget);
 
 public:
     JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, const 
OUString& rUIFile);
diff --git a/vcl/jsdialog/executor.cxx b/vcl/jsdialog/executor.cxx
new file mode 100644
index 000000000000..f5903fb8f5ba
--- /dev/null
+++ b/vcl/jsdialog/executor.cxx
@@ -0,0 +1,141 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <jsdialog/jsdialogbuilder.hxx>
+#include <vcl/weld.hxx>
+#include <vcl/jsdialog/executor.hxx>
+#include <sal/log.hxx>
+
+namespace jsdialog
+{
+bool ExecuteAction(sal_uInt64 nWindowId, const OString& rWidget, StringMap& 
rData)
+{
+    weld::Widget* pWidget = JSInstanceBuilder::FindWeldWidgetsMap(nWindowId, 
rWidget);
+
+    if (pWidget != nullptr)
+    {
+        OUString sControlType = rData["type"];
+        OUString sAction = rData["cmd"];
+
+        if (sControlType == "tabcontrol")
+        {
+            auto pNotebook = dynamic_cast<weld::Notebook*>(pWidget);
+            if (pNotebook)
+            {
+                if (sAction == "selecttab")
+                {
+                    OString pageId = OUStringToOString(rData["data"], 
RTL_TEXTENCODING_ASCII_US);
+                    int page = std::atoi(pageId.getStr());
+
+                    pNotebook->set_current_page(page);
+
+                    return true;
+                }
+            }
+        }
+        else if (sControlType == "combobox")
+        {
+            auto pCombobox = dynamic_cast<weld::ComboBox*>(pWidget);
+            if (pCombobox)
+            {
+                if (sAction == "selected")
+                {
+                    int separatorPos = rData["data"].indexOf(';');
+                    if (separatorPos)
+                    {
+                        OUString entryPos = rData["data"].copy(0, 
separatorPos);
+                        OString posString = OUStringToOString(entryPos, 
RTL_TEXTENCODING_ASCII_US);
+                        int pos = std::atoi(posString.getStr());
+                        pCombobox->set_active(pos);
+                        pCombobox->signal_changed();
+                        return true;
+                    }
+                }
+                else if (sAction == "change")
+                {
+                    pCombobox->set_entry_text(rData["data"]);
+                    pCombobox->signal_changed();
+                    return true;
+                }
+            }
+        }
+        else if (sControlType == "pushbutton")
+        {
+            auto pButton = dynamic_cast<weld::Button*>(pWidget);
+            if (pButton)
+            {
+                if (sAction == "click")
+                {
+                    pButton->clicked();
+                    return true;
+                }
+            }
+        }
+        else if (sControlType == "drawingarea")
+        {
+            auto pArea = dynamic_cast<weld::DrawingArea*>(pWidget);
+            if (pArea)
+            {
+                if (sAction == "click")
+                {
+                    pArea->click(Point(10, 10));
+                    return true;
+                }
+            }
+        }
+        else if (sControlType == "spinfield")
+        {
+            auto pSpinField = dynamic_cast<weld::SpinButton*>(pWidget);
+            if (pSpinField)
+            {
+                if (sAction == "plus")
+                {
+                    pSpinField->set_value(pSpinField->get_value() + 1);
+                    return true;
+                }
+                else if (sAction == "minus")
+                {
+                    pSpinField->set_value(pSpinField->get_value() - 1);
+                    return true;
+                }
+            }
+        }
+        else if (sControlType == "toolbox")
+        {
+            auto pToolbar = dynamic_cast<weld::Toolbar*>(pWidget);
+            if (pToolbar)
+            {
+                if (sAction == "click")
+                {
+                    pToolbar->signal_clicked(
+                        OUStringToOString(rData["data"], 
RTL_TEXTENCODING_ASCII_US));
+                    return true;
+                }
+            }
+        }
+        else if (sControlType == "edit")
+        {
+            auto pEdit = dynamic_cast<weld::Entry*>(pWidget);
+            if (pEdit)
+            {
+                if (sAction == "change")
+                {
+                    pEdit->set_text(rData["data"]);
+                    pEdit->signal_changed();
+                    return true;
+                }
+            }
+        }
+    }
+
+    return false;
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index 73cb41e0e089..a0b2ae652c72 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -115,13 +115,11 @@ std::map<sal_uInt64, WidgetMap>& 
JSInstanceBuilder::GetLOKWeldWidgetsMap()
     return s_aLOKWeldBuildersMap;
 }
 
-namespace jsdialog
+weld::Widget* JSInstanceBuilder::FindWeldWidgetsMap(sal_uInt64 nWindowId, 
const OString& rWidget)
 {
-weld::Widget* FindWeldWidgetsMap(sal_uInt64 nWindowId, const OString& rWidget)
-{
-    const auto it = JSInstanceBuilder::GetLOKWeldWidgetsMap().find(nWindowId);
+    const auto it = GetLOKWeldWidgetsMap().find(nWindowId);
 
-    if (it != JSInstanceBuilder::GetLOKWeldWidgetsMap().end())
+    if (it != GetLOKWeldWidgetsMap().end())
     {
         auto widgetIt = it->second.find(rWidget);
         if (widgetIt != it->second.end())
@@ -130,7 +128,6 @@ weld::Widget* FindWeldWidgetsMap(sal_uInt64 nWindowId, 
const OString& rWidget)
 
     return nullptr;
 }
-}
 
 void JSInstanceBuilder::InsertWindowToMap(sal_uInt64 nWindowId)
 {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to