desktop/source/lib/init.cxx | 134 ++++++++++++++++++++++--------- include/vcl/jsdialog/jsdialogbuilder.hxx | 10 +- include/vcl/salvtables.hxx | 5 - include/vcl/toolkit/combobox.hxx | 2 include/vcl/weld.hxx | 3 vcl/jsdialog/jsdialogbuilder.cxx | 86 ++++++++++++++----- vcl/source/app/salvtables.cxx | 2 7 files changed, 177 insertions(+), 65 deletions(-)
New commits: commit 292d9519bd368db69920cf0f8b94e0e51c3d14a1 Author: Szymon Kłos <szymon.k...@collabora.com> AuthorDate: Fri Mar 6 11:11:57 2020 +0100 Commit: Szymon Kłos <szymon.k...@collabora.com> CommitDate: Sat Jun 20 20:36:25 2020 +0200 jsdialog: remember weld instances Change-Id: Ie55e0fcd2307679aee52751b2d2e434393850418 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94302 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Szymon Kłos <szymon.k...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96735 Tested-by: Jenkins diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 8bbec959b44f..357111d220af 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -3588,7 +3588,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(); @@ -3610,18 +3609,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") @@ -3637,7 +3638,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") @@ -3651,6 +3652,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 382623a83da6..f57d3da7ec7f 100644 --- a/include/vcl/jsdialog/jsdialogbuilder.hxx +++ b/include/vcl/jsdialog/jsdialogbuilder.hxx @@ -10,6 +10,7 @@ #include <vcl/button.hxx> class ComboBox; +typedef std::map<OString, weld::Widget*> WidgetMap; class JSDialogSender { @@ -28,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; @@ -44,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 dc73addd0c10..e14c2c0d5ed3 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -613,7 +613,6 @@ protected: Link<ComboBox&, bool> m_aEntryActivateHdl; Link<OUString&, bool> m_aEntryInsertTextHdl; - void signal_changed() { m_aChangeHdl.Call(*this); } virtual void signal_popup_toggled() { m_aPopupToggledHdl.Call(*this); } Link<render_args, void> m_aRenderHdl; @@ -627,6 +626,8 @@ protected: Size signal_custom_get_size(vcl::RenderContext& rDevice) { return m_aGetSizeHdl.Call(rDevice); } public: + void signal_changed() { m_aChangeHdl.Call(*this); } + 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 5cb4132fc8f8..21c678739d88 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 5c44f1ef779bf196f874f47c14d2d0c7f58fbb2e Author: Szymon Kłos <szymon.k...@collabora.com> AuthorDate: Thu Mar 5 12:24:27 2020 +0100 Commit: Szymon Kłos <szymon.k...@collabora.com> CommitDate: Sat Jun 20 20:36:11 2020 +0200 jsdialog: execute actions using weld wrapper Change-Id: Ib9e1b52742b489e812e0756b364a7f7ac62f84ad Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94300 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Szymon Kłos <szymon.k...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94617 Tested-by: Jenkins diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 2843c0f5c250..8bbec959b44f 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -148,6 +148,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> @@ -3587,6 +3588,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(); @@ -3598,57 +3600,111 @@ static void doc_sendDialogEvent(LibreOfficeKitDocument* /*pThis*/, unsigned nWin } else if (aMap.find("id") != aMap.end()) { - const OUString sSelectAction("SELECT"); + static const OUString sClickAction("CLICK"); + static const OUString sSelectAction("SELECT"); + static const OUString sClearAction("CLEAR"); + static const OUString sTypeAction("TYPE"); + static const OUString sUpAction("UP"); + static const OUString sDownAction("DOWN"); + static const OUString sValue("VALUE"); 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("UP", aMap); - } - else if (aMap["cmd"] == "minus") - { - pUIWindow->execute("DOWN", 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("CLEAR", aMap); - pUIWindow->execute("TYPE", 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("VALUE", 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("CLICK", aMap); + if (bIsClickAction) + pUIWindow->execute(sClickAction, aMap); + } } } catch(...) {} diff --git a/include/vcl/jsdialog/jsdialogbuilder.hxx b/include/vcl/jsdialog/jsdialogbuilder.hxx index 0efd6c0d36ea..382623a83da6 100644 --- a/include/vcl/jsdialog/jsdialogbuilder.hxx +++ b/include/vcl/jsdialog/jsdialogbuilder.hxx @@ -7,9 +7,10 @@ #include <vcl/virdev.hxx> #include <vcl/builder.hxx> #include <vcl/salvtables.hxx> -#include <vcl/toolkit/combobox.hxx> #include <vcl/button.hxx> +class ComboBox; + class JSDialogSender { VclPtr<vcl::Window> m_aOwnedToplevel; diff --git a/include/vcl/salvtables.hxx b/include/vcl/salvtables.hxx index 87d387f43257..ad5827a82e61 100644 --- a/include/vcl/salvtables.hxx +++ b/include/vcl/salvtables.hxx @@ -22,7 +22,8 @@ #include <vcl/toolkit/combobox.hxx> #include <vcl/tabctrl.hxx> #include <vcl/layout.hxx> -#include <messagedialog.hxx> + +class MessageDialog; class SalInstanceBuilder : public weld::Builder { @@ -158,7 +159,7 @@ public: virtual ~SalInstanceBuilder() override; }; -class SalInstanceMenu : public weld::Menu +class SAL_DLLPUBLIC_RTTI SalInstanceMenu : public weld::Menu { private: VclPtr<PopupMenu> m_xMenu; diff --git a/include/vcl/toolkit/combobox.hxx b/include/vcl/toolkit/combobox.hxx index a3c4e1cee5b3..d81e70fbb610 100644 --- a/include/vcl/toolkit/combobox.hxx +++ b/include/vcl/toolkit/combobox.hxx @@ -20,7 +20,7 @@ #ifndef INCLUDED_VCL_COMBOBOX_HXX #define INCLUDED_VCL_COMBOBOX_HXX -#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) && !defined(DESKTOP_DLLIMPLEMENTATION) #error "don't use this in new code" #endif diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx index 938cf471cc76..5cb4132fc8f8 100644 --- a/vcl/jsdialog/jsdialogbuilder.cxx +++ b/vcl/jsdialog/jsdialogbuilder.cxx @@ -5,6 +5,7 @@ #include <vcl/tabpage.hxx> #include <vcl/toolkit/dialog.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> +#include <vcl/toolkit/combobox.hxx> void JSDialogSender::notifyDialogState() { diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 1759a1e83860..08a62cd63e46 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -72,6 +72,8 @@ #include <bitmaps.hlst> #include <wizdlg.hxx> #include <vcl/salvtables.hxx> +#include <messagedialog.hxx> +#include <vcl/toolkit/combobox.hxx> #include <boost/property_tree/ptree.hpp> _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits