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

Szymon KÅ‚os (via logerrit) logerrit at kemper.freedesktop.org
Mon May 18 15:53:08 UTC 2020


 compilerplugins/clang/badstatics.cxx     |    1 
 desktop/source/lib/init.cxx              |  126 +++++++++++++++++++++---------
 include/vcl/jsdialog/jsdialogbuilder.hxx |   33 +++++++
 include/vcl/salvtables.hxx               |    2 
 include/vcl/weld.hxx                     |    2 
 vcl/jsdialog/jsdialogbuilder.cxx         |  130 ++++++++++++++++++++++++++++---
 vcl/source/app/salvtables.cxx            |    2 
 vcl/source/window/builder.cxx            |    2 
 8 files changed, 246 insertions(+), 52 deletions(-)

New commits:
commit ca9fb8ca376b14bf64397f0e80b05d129b00b4be
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Fri Mar 6 11:11:57 2020 +0100
Commit:     Szymon Kłos <eszkadev at gmail.com>
CommitDate: Mon May 18 17:52:21 2020 +0200

    jsdialog: remember weld instances
    
    Change-Id: Ie55e0fcd2307679aee52751b2d2e434393850418
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94302
    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 d4050c4def8d..bd5cdc9a937b 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -3552,7 +3552,6 @@ static void doc_sendDialogEvent(LibreOfficeKitDocument* /*pThis*/, unsigned nWin
 
     StringMap aMap(jsonToStringMap(pArguments));
     VclPtr<Window> pWindow = vcl::Window::FindLOKWindow(nWindowId);
-    JSInstanceBuilder* pBuilder = JSInstanceBuilder::FindLOKWeldBuilder(nWindowId);
 
     if (!pWindow && nWindowId >= 1000000000 /* why unsigned? */)
         pWindow = getSidebarWindow();
@@ -3574,18 +3573,20 @@ static void doc_sendDialogEvent(LibreOfficeKitDocument* /*pThis*/, unsigned nWin
 
         try
         {
-            bool bIsWeldedDialog = pBuilder != nullptr;
+            OString sControlId = OUStringToOString(aMap["id"], RTL_TEXTENCODING_ASCII_US);
+            weld::Widget* pWidget = JSInstanceBuilder::FindWeldWidgetsMap(nWindowId, sControlId);
+
+            bool bIsWeldedDialog = pWidget != nullptr;
             bool bContinueWithLOKWindow = false;
 
             if (bIsWeldedDialog)
             {
-                OString sControlId = OUStringToOString(aMap["id"], RTL_TEXTENCODING_ASCII_US);
                 OUString sControlType = aMap["type"];
                 OUString sAction = aMap["cmd"];
 
                 if (sControlType == "tabcontrol")
                 {
-                    auto pNotebook = pBuilder->weld_notebook(sControlId, false);
+                    auto pNotebook = dynamic_cast<weld::Notebook*>(pWidget);
                     if (pNotebook)
                     {
                         if (sAction == "selecttab")
@@ -3601,7 +3602,7 @@ static void doc_sendDialogEvent(LibreOfficeKitDocument* /*pThis*/, unsigned nWin
                 }
                 else if (sControlType == "combobox")
                 {
-                    auto pCombobox = pBuilder->weld_combo_box(sControlId, false);
+                    auto pCombobox = dynamic_cast<weld::ComboBox*>(pWidget);
                     if (pCombobox)
                     {
                         if (sAction == "selected")
@@ -3615,6 +3616,11 @@ static void doc_sendDialogEvent(LibreOfficeKitDocument* /*pThis*/, unsigned nWin
                                 pCombobox->set_active(pos);
                             }
                         }
+                        else if (sAction == "change")
+                        {
+                            pCombobox->set_entry_text(aMap["data"]);
+                            pCombobox->signal_changed();
+                        }
                         else
                             bContinueWithLOKWindow = true;
                     }
diff --git a/include/vcl/jsdialog/jsdialogbuilder.hxx b/include/vcl/jsdialog/jsdialogbuilder.hxx
index b26b2ac2ff16..e0d4bc2dcdc1 100644
--- a/include/vcl/jsdialog/jsdialogbuilder.hxx
+++ b/include/vcl/jsdialog/jsdialogbuilder.hxx
@@ -10,6 +10,8 @@
 #include <vcl/combobox.hxx>
 #include <vcl/button.hxx>
 
+typedef std::map<OString, weld::Widget*> WidgetMap;
+
 class JSDialogSender
 {
     VclPtr<vcl::Window> m_aOwnedToplevel;
@@ -27,6 +29,9 @@ class VCL_DLLPUBLIC JSInstanceBuilder : public SalInstanceBuilder
 {
     vcl::LOKWindowId m_nWindowId;
 
+    static std::map<vcl::LOKWindowId, WidgetMap>& GetLOKWeldWidgetsMap();
+    void RememberWidget(const OString& id, weld::Widget* pWidget);
+
 public:
     JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile);
     virtual ~JSInstanceBuilder() override;
@@ -43,8 +48,7 @@ public:
     virtual std::unique_ptr<weld::Notebook> weld_notebook(const OString& id,
                                                           bool bTakeOwnership = false) override;
 
-    static std::map<vcl::LOKWindowId, JSInstanceBuilder*>& GetLOKWeldBuilderMap();
-    static JSInstanceBuilder* FindLOKWeldBuilder(vcl::LOKWindowId nWindowId);
+    static weld::Widget* FindWeldWidgetsMap(vcl::LOKWindowId nWindowId, const OString& rWidget);
 };
 
 template <class BaseInstanceClass, class VclClass>
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 6e719fd23239..5e63e7bd9804 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -576,10 +576,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;
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index 901f92aac109..da9f04fe4044 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -37,33 +37,48 @@ JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIR
 JSInstanceBuilder::~JSInstanceBuilder()
 {
     if (m_nWindowId)
-        GetLOKWeldBuilderMap().erase(m_nWindowId);
+        GetLOKWeldWidgetsMap().erase(m_nWindowId);
 }
 
-std::map<vcl::LOKWindowId, JSInstanceBuilder*>& JSInstanceBuilder::GetLOKWeldBuilderMap()
+std::map<vcl::LOKWindowId, WidgetMap>& JSInstanceBuilder::GetLOKWeldWidgetsMap()
 {
-    // Map to remember the LOKWindowId <-> Builder binding.
-    static std::map<vcl::LOKWindowId, JSInstanceBuilder*> s_aLOKWeldBuildersMap;
+    // Map to remember the LOKWindowId <-> weld widgets binding.
+    static std::map<vcl::LOKWindowId, WidgetMap> s_aLOKWeldBuildersMap;
 
     return s_aLOKWeldBuildersMap;
 }
 
-JSInstanceBuilder* JSInstanceBuilder::FindLOKWeldBuilder(vcl::LOKWindowId nWindowId)
+weld::Widget* JSInstanceBuilder::FindWeldWidgetsMap(vcl::LOKWindowId nWindowId,
+                                                    const OString& rWidget)
 {
-    const auto it = GetLOKWeldBuilderMap().find(nWindowId);
-    if (it != GetLOKWeldBuilderMap().end())
-        return it->second;
+    const auto it = GetLOKWeldWidgetsMap().find(nWindowId);
+    if (it != GetLOKWeldWidgetsMap().end())
+    {
+        auto widgetIt = it->second.find(rWidget);
+        if (widgetIt != it->second.end())
+            return widgetIt->second;
+    }
 
     return nullptr;
 }
 
+void JSInstanceBuilder::RememberWidget(const OString& id, weld::Widget* pWidget)
+{
+    auto it = GetLOKWeldWidgetsMap().find(m_nWindowId);
+    if (it != GetLOKWeldWidgetsMap().end())
+    {
+        it->second.insert(WidgetMap::value_type(id, pWidget));
+    }
+}
+
 std::unique_ptr<weld::Dialog> JSInstanceBuilder::weld_dialog(const OString& id, bool bTakeOwnership)
 {
     ::Dialog* pDialog = m_xBuilder->get<::Dialog>(id);
     m_nWindowId = pDialog->GetLOKWindowId();
 
-    GetLOKWeldBuilderMap().insert(
-        std::map<vcl::LOKWindowId, JSInstanceBuilder*>::value_type(m_nWindowId, this));
+    WidgetMap map;
+    GetLOKWeldWidgetsMap().insert(
+        std::map<vcl::LOKWindowId, WidgetMap>::value_type(m_nWindowId, map));
 
     std::unique_ptr<weld::Dialog> pRet(pDialog ? new SalInstanceDialog(pDialog, this, false)
                                                : nullptr);
@@ -91,21 +106,32 @@ std::unique_ptr<weld::Dialog> JSInstanceBuilder::weld_dialog(const OString& id,
 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);
+    auto pWeldWidget = std::make_unique<JSLabel>(m_aOwnedToplevel, pLabel, this, bTakeOwnership);
+
+    RememberWidget(id, pWeldWidget.get());
+    return pWeldWidget;
 }
 
 std::unique_ptr<weld::Button> JSInstanceBuilder::weld_button(const OString& id, bool bTakeOwnership)
 {
     ::Button* pButton = m_xBuilder->get<::Button>(id);
-    return pButton ? std::make_unique<JSButton>(m_aOwnedToplevel, pButton, this, bTakeOwnership)
-                   : nullptr;
+    auto pWeldWidget
+        = pButton ? std::make_unique<JSButton>(m_aOwnedToplevel, pButton, this, bTakeOwnership)
+                  : nullptr;
+
+    RememberWidget(id, pWeldWidget.get());
+    return pWeldWidget;
 }
 
 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;
+    auto pWeldWidget
+        = pEntry ? std::make_unique<JSEntry>(m_aOwnedToplevel, pEntry, this, bTakeOwnership)
+                 : nullptr;
+
+    RememberWidget(id, pWeldWidget.get());
+    return pWeldWidget;
 }
 
 std::unique_ptr<weld::ComboBox> JSInstanceBuilder::weld_combo_box(const OString& id,
@@ -113,20 +139,35 @@ std::unique_ptr<weld::ComboBox> JSInstanceBuilder::weld_combo_box(const OString&
 {
     vcl::Window* pWidget = m_xBuilder->get<vcl::Window>(id);
     ::ComboBox* pComboBox = dynamic_cast<::ComboBox*>(pWidget);
+    std::unique_ptr<weld::ComboBox> pWeldWidget;
+
     if (pComboBox)
-        return std::make_unique<JSComboBox>(m_aOwnedToplevel, pComboBox, this, bTakeOwnership);
-    ListBox* pListBox = dynamic_cast<ListBox*>(pWidget);
-    return pListBox ? std::make_unique<JSListBox>(m_aOwnedToplevel, pListBox, this, bTakeOwnership)
-                    : nullptr;
+    {
+        pWeldWidget
+            = std::make_unique<JSComboBox>(m_aOwnedToplevel, pComboBox, this, bTakeOwnership);
+    }
+    else
+    {
+        ListBox* pListBox = dynamic_cast<ListBox*>(pWidget);
+        pWeldWidget = pListBox ? std::make_unique<JSListBox>(m_aOwnedToplevel, pListBox, this,
+                                                             bTakeOwnership)
+                               : nullptr;
+    }
+
+    RememberWidget(id, pWeldWidget.get());
+    return pWeldWidget;
 }
 
 std::unique_ptr<weld::Notebook> JSInstanceBuilder::weld_notebook(const OString& id,
                                                                  bool bTakeOwnership)
 {
     TabControl* pNotebook = m_xBuilder->get<TabControl>(id);
-    return pNotebook
-               ? std::make_unique<JSNotebook>(m_aOwnedToplevel, pNotebook, this, bTakeOwnership)
-               : nullptr;
+    auto pWeldWidget = pNotebook ? std::make_unique<JSNotebook>(m_aOwnedToplevel, pNotebook, this,
+                                                                bTakeOwnership)
+                                 : nullptr;
+
+    RememberWidget(id, pWeldWidget.get());
+    return pWeldWidget;
 }
 
 JSLabel::JSLabel(VclPtr<vcl::Window> aOwnedToplevel, FixedText* pLabel,
commit 425d861812d218df35619624af949fde00a6ad50
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Thu Mar 5 12:24:27 2020 +0100
Commit:     Szymon Kłos <eszkadev at gmail.com>
CommitDate: Mon May 18 17:52:21 2020 +0200

    jsdialog: execute actions using weld wrapper
    
    Change-Id: Ib9e1b52742b489e812e0756b364a7f7ac62f84ad
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94300
    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 7fbd42371fc6..d4050c4def8d 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -154,6 +154,7 @@
 #include <vcl/abstdlg.hxx>
 #include <tools/diagnose_ex.h>
 #include <vcl/uitest/uiobject.hxx>
+#include <vcl/jsdialog/jsdialogbuilder.hxx>
 
 // Needed for getUndoManager()
 #include <com/sun/star/document/XUndoManager.hpp>
@@ -3551,6 +3552,7 @@ static void doc_sendDialogEvent(LibreOfficeKitDocument* /*pThis*/, unsigned nWin
 
     StringMap aMap(jsonToStringMap(pArguments));
     VclPtr<Window> pWindow = vcl::Window::FindLOKWindow(nWindowId);
+    JSInstanceBuilder* pBuilder = JSInstanceBuilder::FindLOKWeldBuilder(nWindowId);
 
     if (!pWindow && nWindowId >= 1000000000 /* why unsigned? */)
         pWindow = getSidebarWindow();
@@ -3572,53 +3574,101 @@ static void doc_sendDialogEvent(LibreOfficeKitDocument* /*pThis*/, unsigned nWin
 
         try
         {
-            WindowUIObject aUIObject(pWindow);
-            std::unique_ptr<UIObject> pUIWindow(aUIObject.get_child(aMap["id"]));
-            if (pUIWindow) {
-                bool bIsClickAction = false;
+            bool bIsWeldedDialog = pBuilder != nullptr;
+            bool bContinueWithLOKWindow = false;
 
-                if (aMap.find("cmd") != aMap.end()) {
-                    if (aMap["cmd"] == "selected")
-                    {
-                        aMap["POS"] = aMap["data"];
-                        aMap["TEXT"] = aMap["data"];
+            if (bIsWeldedDialog)
+            {
+                OString sControlId = OUStringToOString(aMap["id"], RTL_TEXTENCODING_ASCII_US);
+                OUString sControlType = aMap["type"];
+                OUString sAction = aMap["cmd"];
 
-                        pUIWindow->execute(sSelectAction, aMap);
-                    }
-                    else if (aMap["cmd"] == "plus")
-                    {
-                        pUIWindow->execute(sUpAction, aMap);
-                    }
-                    else if (aMap["cmd"] == "minus")
-                    {
-                        pUIWindow->execute(sDownAction, aMap);
-                    }
-                    else if (aMap["cmd"] == "set")
+                if (sControlType == "tabcontrol")
+                {
+                    auto pNotebook = pBuilder->weld_notebook(sControlId, false);
+                    if (pNotebook)
                     {
-                        aMap["TEXT"] = aMap["data"];
+                        if (sAction == "selecttab")
+                        {
+                            OString pageId = OUStringToOString(aMap["data"], RTL_TEXTENCODING_ASCII_US);
+                            int page = std::atoi(pageId.getStr());
 
-                        pUIWindow->execute(sClearAction, aMap);
-                        pUIWindow->execute(sTypeAction, aMap);
+                            pNotebook->set_current_page(page);
+                        }
+                        else
+                            bContinueWithLOKWindow = true;
                     }
-                    else if (aMap["cmd"] == "value")
+                }
+                else if (sControlType == "combobox")
+                {
+                    auto pCombobox = pBuilder->weld_combo_box(sControlId, false);
+                    if (pCombobox)
                     {
-                        aMap["VALUE"] = aMap["data"];
-                        pUIWindow->execute(sValue, aMap);
+                        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);
+                            }
+                        }
+                        else
+                            bContinueWithLOKWindow = true;
                     }
-                    else if (aMap["cmd"] == "selecttab")
-                    {
-                        aMap["POS"] = aMap["data"];
+                }
+                else
+                {
+                    bContinueWithLOKWindow = true;
+                }
+            }
+
+            if (!bIsWeldedDialog || bContinueWithLOKWindow)
+            {
+                WindowUIObject aUIObject(pWindow);
+                std::unique_ptr<UIObject> pUIWindow(aUIObject.get_child(aMap["id"]));
+                if (pUIWindow) {
+                    bool bIsClickAction = false;
+
+                    if (aMap.find("cmd") != aMap.end()) {
+                        if (aMap["cmd"] == "selected")
+                        {
+                            aMap["POS"] = aMap["data"];
+                            aMap["TEXT"] = aMap["data"];
+
+                            pUIWindow->execute(sSelectAction, aMap);
+                        }
+                        else if (aMap["cmd"] == "plus")
+                        {
+                            pUIWindow->execute(sUpAction, aMap);
+                        }
+                        else if (aMap["cmd"] == "minus")
+                        {
+                            pUIWindow->execute(sDownAction, aMap);
+                        }
+                        else if (aMap["cmd"] == "set")
+                        {
+                            aMap["TEXT"] = aMap["data"];
 
-                        pUIWindow->execute(sSelectAction, aMap);
+                            pUIWindow->execute(sClearAction, aMap);
+                            pUIWindow->execute(sTypeAction, aMap);
+                        }
+                        else if (aMap["cmd"] == "value")
+                        {
+                            aMap["VALUE"] = aMap["data"];
+                            pUIWindow->execute(sValue, aMap);
+                        }
+                        else
+                            bIsClickAction = true;
                     }
                     else
                         bIsClickAction = true;
-                }
-                else
-                    bIsClickAction = true;
 
-                if (bIsClickAction)
-                    pUIWindow->execute(sClickAction, aMap);
+                    if (bIsClickAction)
+                        pUIWindow->execute(sClickAction, aMap);
+                }
             }
         } catch(...) {}
 
commit 4134777711854ed68a7c2ffbd42cc118efd62184
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Thu Mar 5 12:18:38 2020 +0100
Commit:     Szymon Kłos <eszkadev at gmail.com>
CommitDate: Mon May 18 17:52:21 2020 +0200

    jsdialog: Remember builder connected with LOK window id
    
    Change-Id: I9e38fe570b2296341c1694fe8128da30ba209494
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94184
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>

diff --git a/compilerplugins/clang/badstatics.cxx b/compilerplugins/clang/badstatics.cxx
index 737330dd10c0..7c595f77207a 100644
--- a/compilerplugins/clang/badstatics.cxx
+++ b/compilerplugins/clang/badstatics.cxx
@@ -205,6 +205,7 @@ public:
                 || (loplugin::DeclCheck(pVarDecl).Var("maThreadSpecific")
                     .Class("ScDocument").GlobalNamespace()) // not owning
                 || name == "s_aLOKWindowsMap" // LOK only, guarded by assert, and LOK never tries to perform a VCL cleanup
+                || name == "s_aLOKWeldBuildersMap" // LOK only, similar case as above
                 || name == "gStaticManager" // vcl/source/graphic/Manager.cxx - stores non-owning pointers
                 || name == "aThreadedInterpreterPool"    // ScInterpreterContext(Pool), not owning
                 || name == "aNonThreadedInterpreterPool" // ScInterpreterContext(Pool), not owning
diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx b/include/vcl/jsdialog/jsdialogbuilder.hxx
similarity index 92%
rename from vcl/inc/jsdialog/jsdialogbuilder.hxx
rename to include/vcl/jsdialog/jsdialogbuilder.hxx
index 0104756b7b55..b26b2ac2ff16 100644
--- a/vcl/inc/jsdialog/jsdialogbuilder.hxx
+++ b/include/vcl/jsdialog/jsdialogbuilder.hxx
@@ -6,7 +6,7 @@
 #include <vcl/sysdata.hxx>
 #include <vcl/virdev.hxx>
 #include <vcl/builder.hxx>
-#include <salvtables.hxx>
+#include <vcl/salvtables.hxx>
 #include <vcl/combobox.hxx>
 #include <vcl/button.hxx>
 
@@ -25,8 +25,11 @@ public:
 
 class VCL_DLLPUBLIC JSInstanceBuilder : public SalInstanceBuilder
 {
+    vcl::LOKWindowId m_nWindowId;
+
 public:
     JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile);
+    virtual ~JSInstanceBuilder() 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,
@@ -39,10 +42,13 @@ public:
                                                            bool bTakeOwnership = false) override;
     virtual std::unique_ptr<weld::Notebook> weld_notebook(const OString& id,
                                                           bool bTakeOwnership = false) override;
+
+    static std::map<vcl::LOKWindowId, JSInstanceBuilder*>& GetLOKWeldBuilderMap();
+    static JSInstanceBuilder* FindLOKWeldBuilder(vcl::LOKWindowId nWindowId);
 };
 
 template <class BaseInstanceClass, class VclClass>
-class JSWidget : public BaseInstanceClass, public JSDialogSender
+class VCL_DLLPUBLIC JSWidget : public BaseInstanceClass, public JSDialogSender
 {
 public:
     JSWidget(VclPtr<vcl::Window> aOwnedToplevel, VclClass* pObject, SalInstanceBuilder* pBuilder,
@@ -130,4 +136,4 @@ public:
     virtual void append_page(const OString& rIdent, const OUString& rLabel) override;
 };
 
-#endif
\ No newline at end of file
+#endif
diff --git a/vcl/inc/salvtables.hxx b/include/vcl/salvtables.hxx
similarity index 100%
rename from vcl/inc/salvtables.hxx
rename to include/vcl/salvtables.hxx
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index 64f78c295bed..901f92aac109 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -1,4 +1,4 @@
-#include <jsdialog/jsdialogbuilder.hxx>
+#include <vcl/jsdialog/jsdialogbuilder.hxx>
 #include <sal/log.hxx>
 #include <boost/property_tree/json_parser.hpp>
 #include <comphelper/lok.hxx>
@@ -30,12 +30,41 @@ JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIR
                              ? dynamic_cast<SalInstanceWidget*>(pParent)->getWidget()
                              : nullptr,
                          rUIRoot, rUIFile)
+    , m_nWindowId(0)
 {
 }
 
+JSInstanceBuilder::~JSInstanceBuilder()
+{
+    if (m_nWindowId)
+        GetLOKWeldBuilderMap().erase(m_nWindowId);
+}
+
+std::map<vcl::LOKWindowId, JSInstanceBuilder*>& JSInstanceBuilder::GetLOKWeldBuilderMap()
+{
+    // Map to remember the LOKWindowId <-> Builder binding.
+    static std::map<vcl::LOKWindowId, JSInstanceBuilder*> s_aLOKWeldBuildersMap;
+
+    return s_aLOKWeldBuildersMap;
+}
+
+JSInstanceBuilder* JSInstanceBuilder::FindLOKWeldBuilder(vcl::LOKWindowId nWindowId)
+{
+    const auto it = GetLOKWeldBuilderMap().find(nWindowId);
+    if (it != GetLOKWeldBuilderMap().end())
+        return it->second;
+
+    return nullptr;
+}
+
 std::unique_ptr<weld::Dialog> JSInstanceBuilder::weld_dialog(const OString& id, bool bTakeOwnership)
 {
     ::Dialog* pDialog = m_xBuilder->get<::Dialog>(id);
+    m_nWindowId = pDialog->GetLOKWindowId();
+
+    GetLOKWeldBuilderMap().insert(
+        std::map<vcl::LOKWindowId, JSInstanceBuilder*>::value_type(m_nWindowId, this));
+
     std::unique_ptr<weld::Dialog> pRet(pDialog ? new SalInstanceDialog(pDialog, this, false)
                                                : nullptr);
     if (bTakeOwnership && pDialog)
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 77334c1cc90d..e4f576201514 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -71,7 +71,7 @@
 #include <aboutdialog.hxx>
 #include <bitmaps.hlst>
 #include <wizdlg.hxx>
-#include <salvtables.hxx>
+#include <vcl/salvtables.hxx>
 
 SalFrame::SalFrame()
     : m_pWindow(nullptr)
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 184313b8c12c..eb87ea7403f2 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -65,7 +65,7 @@
 #include <wizdlg.hxx>
 #include <tools/svlibrary.h>
 #include <comphelper/lok.hxx>
-#include <jsdialog/jsdialogbuilder.hxx>
+#include <vcl/jsdialog/jsdialogbuilder.hxx>
 
 #if defined(DISABLE_DYNLOADING) || defined(LINUX)
 #include <dlfcn.h>
commit 3d2be32a12708e43158f2a490bde24aae8f11f9e
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Wed Mar 4 16:05:10 2020 +0100
Commit:     Szymon Kłos <eszkadev at gmail.com>
CommitDate: Mon May 18 17:52:21 2020 +0200

    jsdialog: refresh on notebook changes
    
    Change-Id: I81159d043add3d8bdd1b81f26f642f99c1430f73
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94183
    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 24b1ef7808c1..0104756b7b55 100644
--- a/vcl/inc/jsdialog/jsdialogbuilder.hxx
+++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx
@@ -37,6 +37,8 @@ public:
                                                     bool bTakeOwnership = false) override;
     virtual std::unique_ptr<weld::ComboBox> weld_combo_box(const OString& id,
                                                            bool bTakeOwnership = false) override;
+    virtual std::unique_ptr<weld::Notebook> weld_notebook(const OString& id,
+                                                          bool bTakeOwnership = false) override;
 };
 
 template <class BaseInstanceClass, class VclClass>
@@ -113,4 +115,19 @@ public:
     virtual void set_entry_text(const OUString& rText) override;
 };
 
+class VCL_DLLPUBLIC JSNotebook : public JSWidget<SalInstanceNotebook, ::TabControl>
+{
+public:
+    JSNotebook(VclPtr<vcl::Window> aOwnedToplevel, ::TabControl* pControl,
+               SalInstanceBuilder* pBuilder, bool bTakeOwnership);
+
+    virtual void set_current_page(int nPage) override;
+
+    virtual void set_current_page(const OString& rIdent) override;
+
+    virtual void remove_page(const OString& rIdent) override;
+
+    virtual void append_page(const OString& rIdent, const OUString& rLabel) override;
+};
+
 #endif
\ No newline at end of file
diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx
index b308f5f8bc8c..6222423551bc 100644
--- a/vcl/inc/salvtables.hxx
+++ b/vcl/inc/salvtables.hxx
@@ -869,7 +869,7 @@ class SalInstanceNotebook : public SalInstanceContainer, public virtual weld::No
 {
 private:
     VclPtr<TabControl> m_xNotebook;
-    mutable std::vector<std::unique_ptr<SalInstanceContainer>> m_aPages;
+    mutable std::vector<std::shared_ptr<SalInstanceContainer>> m_aPages;
     std::vector<VclPtr<TabPage>> m_aAddedPages;
     std::vector<VclPtr<VclGrid>> m_aAddedGrids;
 
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index a9465a4de5bb..64f78c295bed 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -91,6 +91,15 @@ std::unique_ptr<weld::ComboBox> JSInstanceBuilder::weld_combo_box(const OString&
                     : nullptr;
 }
 
+std::unique_ptr<weld::Notebook> JSInstanceBuilder::weld_notebook(const OString& id,
+                                                                 bool bTakeOwnership)
+{
+    TabControl* pNotebook = m_xBuilder->get<TabControl>(id);
+    return pNotebook
+               ? std::make_unique<JSNotebook>(m_aOwnedToplevel, pNotebook, this, bTakeOwnership)
+               : nullptr;
+}
+
 JSLabel::JSLabel(VclPtr<vcl::Window> aOwnedToplevel, FixedText* pLabel,
                  SalInstanceBuilder* pBuilder, bool bTakeOwnership)
     : JSWidget<SalInstanceLabel, FixedText>(aOwnedToplevel, pLabel, pBuilder, bTakeOwnership)
@@ -166,3 +175,34 @@ void JSComboBox::set_entry_text(const OUString& rText)
     SalInstanceComboBoxWithEdit::set_entry_text(rText);
     notifyDialogState();
 }
+
+JSNotebook::JSNotebook(VclPtr<vcl::Window> aOwnedToplevel, ::TabControl* pControl,
+                       SalInstanceBuilder* pBuilder, bool bTakeOwnership)
+    : JSWidget<SalInstanceNotebook, ::TabControl>(aOwnedToplevel, pControl, pBuilder,
+                                                  bTakeOwnership)
+{
+}
+
+void JSNotebook::set_current_page(int nPage)
+{
+    SalInstanceNotebook::set_current_page(nPage);
+    notifyDialogState();
+}
+
+void JSNotebook::set_current_page(const OString& rIdent)
+{
+    SalInstanceNotebook::set_current_page(rIdent);
+    notifyDialogState();
+}
+
+void JSNotebook::remove_page(const OString& rIdent)
+{
+    SalInstanceNotebook::remove_page(rIdent);
+    notifyDialogState();
+}
+
+void JSNotebook::append_page(const OString& rIdent, const OUString& rLabel)
+{
+    SalInstanceNotebook::append_page(rIdent, rLabel);
+    notifyDialogState();
+}


More information about the Libreoffice-commits mailing list