diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2021-11-15 09:13:35 +0100 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2021-11-16 19:55:04 +0100 |
commit | f43f08133f6004043ab4a0fb0fd0f51cd8b871fb (patch) | |
tree | 65c0213a37faa18541f86b4b54b44bc3bb11f24b /vcl | |
parent | b95adc80a01b9caf97ade47a4cdb15a210ddd5eb (diff) |
jsdialog: use string identifiers
Thanks to that it is easier to debug and find widgets in maps.
Sidebar and notebookbar are now in different map entries.
This fixes the issue when destroying notebookbar deleted sidebar's
widgets.
After this patch sidebar works correctly when using notebookbar mode in
lok.
Change-Id: Ie9dcb82675129bdb567b766e29779744f500cb48
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125216
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/jsdialog/jsdialogbuilder.hxx | 19 | ||||
-rw-r--r-- | vcl/jsdialog/executor.cxx | 4 | ||||
-rw-r--r-- | vcl/jsdialog/jsdialogbuilder.cxx | 51 |
3 files changed, 43 insertions, 31 deletions
diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx b/vcl/inc/jsdialog/jsdialogbuilder.hxx index 9f52846206d7..ccd2489d797b 100644 --- a/vcl/inc/jsdialog/jsdialogbuilder.hxx +++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx @@ -209,15 +209,17 @@ class JSInstanceBuilder : public SalInstanceBuilder, public JSDialogSender /// When LOKNotifier is set by jsdialogs code we need to release it VclPtr<vcl::Window> m_aWindowToRelease; - friend VCL_DLLPUBLIC bool jsdialog::ExecuteAction(sal_uInt64 nWindowId, const OString& rWidget, - StringMap& rData); - friend VCL_DLLPUBLIC void jsdialog::SendFullUpdate(sal_uInt64 nWindowId, + friend VCL_DLLPUBLIC bool jsdialog::ExecuteAction(const std::string& nWindowId, + const OString& rWidget, StringMap& rData); + friend VCL_DLLPUBLIC void jsdialog::SendFullUpdate(const std::string& nWindowId, const OString& rWidget); - static std::map<sal_uInt64, WidgetMap>& GetLOKWeldWidgetsMap(); - static void InsertWindowToMap(sal_uInt64 nWindowId); + static std::map<std::string, WidgetMap>& GetLOKWeldWidgetsMap(); + static void InsertWindowToMap(const std::string& nWindowId); void RememberWidget(const OString& id, weld::Widget* pWidget); - static weld::Widget* FindWeldWidgetsMap(sal_uInt64 nWindowId, const OString& rWidget); + static weld::Widget* FindWeldWidgetsMap(const std::string& nWindowId, const OString& rWidget); + + std::string getMapIdFromWindowId() const; /// used for dialogs or popups JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile, @@ -281,8 +283,9 @@ public: VclButtonsType eButtonType, const OUString& rPrimaryMessage); - static void AddChildWidget(sal_uInt64 nWindowId, const OString& id, weld::Widget* pWidget); - static void RemoveWindowWidget(sal_uInt64 nWindowId); + static void AddChildWidget(const std::string& nWindowId, const OString& id, + weld::Widget* pWidget); + static void RemoveWindowWidget(const std::string& nWindowId); private: const std::string& GetTypeOfJSON(); diff --git a/vcl/jsdialog/executor.cxx b/vcl/jsdialog/executor.cxx index bddf849d503f..cddee247c531 100644 --- a/vcl/jsdialog/executor.cxx +++ b/vcl/jsdialog/executor.cxx @@ -34,7 +34,7 @@ StringMap jsonToStringMap(const char* pJSON) return aArgs; } -void SendFullUpdate(sal_uInt64 nWindowId, const OString& rWidget) +void SendFullUpdate(const std::string& nWindowId, const OString& rWidget) { weld::Widget* pWidget = JSInstanceBuilder::FindWeldWidgetsMap(nWindowId, rWidget); @@ -45,7 +45,7 @@ void SendFullUpdate(sal_uInt64 nWindowId, const OString& rWidget) } } -bool ExecuteAction(sal_uInt64 nWindowId, const OString& rWidget, StringMap& rData) +bool ExecuteAction(const std::string& nWindowId, const OString& rWidget, StringMap& rData) { weld::Widget* pWidget = JSInstanceBuilder::FindWeldWidgetsMap(nWindowId, rWidget); diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx index c74d0532a420..6bee71f4d71a 100644 --- a/vcl/jsdialog/jsdialogbuilder.cxx +++ b/vcl/jsdialog/jsdialogbuilder.cxx @@ -487,6 +487,14 @@ void JSDropTarget::fire_dragEnter(const css::datatransfer::dnd::DropTargetDragEn } } +std::string JSInstanceBuilder::getMapIdFromWindowId() const +{ + if (m_sTypeOfJSON == "sidebar" || m_sTypeOfJSON == "notebookbar") + return std::to_string(m_nWindowId) + m_sTypeOfJSON; + else + return std::to_string(m_nWindowId); +} + // used for dialogs JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile, bool bPopup) @@ -510,7 +518,7 @@ JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIR m_aParentDialog = pRoot->GetParent()->GetParentWithLOKNotifier(); if (m_aParentDialog) m_nWindowId = m_aParentDialog->GetLOKWindowId(); - InsertWindowToMap(m_nWindowId); + InsertWindowToMap(getMapIdFromWindowId()); } initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON()); @@ -547,7 +555,7 @@ JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIR m_aContentWindow = m_aContentWindow->GetParent(); } - InsertWindowToMap(m_nWindowId); + InsertWindowToMap(getMapIdFromWindowId()); initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON()); } @@ -577,7 +585,7 @@ JSInstanceBuilder::JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRo m_nWindowId = nWindowId; m_bIsNotebookbar = true; } - InsertWindowToMap(m_nWindowId); + InsertWindowToMap(getMapIdFromWindowId()); } initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON()); @@ -602,7 +610,7 @@ JSInstanceBuilder::JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRo m_aParentDialog = pRoot->GetParent()->GetParentWithLOKNotifier(); if (m_aParentDialog) m_nWindowId = m_aParentDialog->GetLOKWindowId(); - InsertWindowToMap(m_nWindowId); + InsertWindowToMap(getMapIdFromWindowId()); } initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON()); @@ -655,11 +663,11 @@ JSInstanceBuilder::~JSInstanceBuilder() if (m_nWindowId && (m_bHasTopLevelDialog || m_bIsNotebookbar)) { - GetLOKWeldWidgetsMap().erase(m_nWindowId); + GetLOKWeldWidgetsMap().erase(getMapIdFromWindowId()); } else { - auto it = GetLOKWeldWidgetsMap().find(m_nWindowId); + auto it = GetLOKWeldWidgetsMap().find(getMapIdFromWindowId()); if (it != GetLOKWeldWidgetsMap().end()) { std::for_each(m_aRememberedWidgets.begin(), m_aRememberedWidgets.end(), @@ -668,15 +676,16 @@ JSInstanceBuilder::~JSInstanceBuilder() } } -std::map<sal_uInt64, WidgetMap>& JSInstanceBuilder::GetLOKWeldWidgetsMap() +std::map<std::string, WidgetMap>& JSInstanceBuilder::GetLOKWeldWidgetsMap() { // Map to remember the LOKWindowId <-> weld widgets binding. - static std::map<sal_uInt64, WidgetMap> s_aLOKWeldBuildersMap; + static std::map<std::string, WidgetMap> s_aLOKWeldBuildersMap; return s_aLOKWeldBuildersMap; } -weld::Widget* JSInstanceBuilder::FindWeldWidgetsMap(sal_uInt64 nWindowId, const OString& rWidget) +weld::Widget* JSInstanceBuilder::FindWeldWidgetsMap(const std::string& nWindowId, + const OString& rWidget) { const auto it = GetLOKWeldWidgetsMap().find(nWindowId); @@ -690,17 +699,17 @@ weld::Widget* JSInstanceBuilder::FindWeldWidgetsMap(sal_uInt64 nWindowId, const return nullptr; } -void JSInstanceBuilder::InsertWindowToMap(sal_uInt64 nWindowId) +void JSInstanceBuilder::InsertWindowToMap(const std::string& nWindowId) { WidgetMap map; auto it = GetLOKWeldWidgetsMap().find(nWindowId); if (it == GetLOKWeldWidgetsMap().end()) - GetLOKWeldWidgetsMap().insert(std::map<sal_uInt64, WidgetMap>::value_type(nWindowId, map)); + GetLOKWeldWidgetsMap().insert(std::map<std::string, WidgetMap>::value_type(nWindowId, map)); } void JSInstanceBuilder::RememberWidget(const OString& id, weld::Widget* pWidget) { - auto it = GetLOKWeldWidgetsMap().find(m_nWindowId); + auto it = GetLOKWeldWidgetsMap().find(getMapIdFromWindowId()); if (it != GetLOKWeldWidgetsMap().end()) { it->second.erase(id); @@ -709,7 +718,7 @@ void JSInstanceBuilder::RememberWidget(const OString& id, weld::Widget* pWidget) } } -void JSInstanceBuilder::AddChildWidget(sal_uInt64 nWindowId, const OString& id, +void JSInstanceBuilder::AddChildWidget(const std::string& nWindowId, const OString& id, weld::Widget* pWidget) { auto it = GetLOKWeldWidgetsMap().find(nWindowId); @@ -720,7 +729,7 @@ void JSInstanceBuilder::AddChildWidget(sal_uInt64 nWindowId, const OString& id, } } -void JSInstanceBuilder::RemoveWindowWidget(sal_uInt64 nWindowId) +void JSInstanceBuilder::RemoveWindowWidget(const std::string& nWindowId) { auto it = JSInstanceBuilder::GetLOKWeldWidgetsMap().find(nWindowId); if (it != JSInstanceBuilder::GetLOKWeldWidgetsMap().end()) @@ -754,7 +763,7 @@ std::unique_ptr<weld::Dialog> JSInstanceBuilder::weld_dialog(const OString& id) m_nWindowId = pDialog->GetLOKWindowId(); pDialog->SetLOKTunnelingState(false); - InsertWindowToMap(m_nWindowId); + InsertWindowToMap(getMapIdFromWindowId()); assert(!m_aOwnedToplevel && "only one toplevel per .ui allowed"); m_aOwnedToplevel.set(pDialog); @@ -782,7 +791,7 @@ std::unique_ptr<weld::MessageDialog> JSInstanceBuilder::weld_message_dialog(cons m_nWindowId = pMessageDialog->GetLOKWindowId(); pMessageDialog->SetLOKTunnelingState(false); - InsertWindowToMap(m_nWindowId); + InsertWindowToMap(getMapIdFromWindowId()); assert(!m_aOwnedToplevel && "only one toplevel per .ui allowed"); m_aOwnedToplevel.set(pMessageDialog); @@ -1030,7 +1039,7 @@ std::unique_ptr<weld::Popover> JSInstanceBuilder::weld_popover(const OString& id m_aParentDialog = pPopupRoot; m_aWindowToRelease = pPopupRoot; m_nWindowId = m_aParentDialog->GetLOKWindowId(); - InsertWindowToMap(m_nWindowId); + InsertWindowToMap(getMapIdFromWindowId()); initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON()); } } @@ -1099,7 +1108,7 @@ weld::MessageDialog* JSInstanceBuilder::CreateMessageDialog(weld::Widget* pParen } xMessageDialog->SetLOKTunnelingState(false); - InsertWindowToMap(xMessageDialog->GetLOKWindowId()); + InsertWindowToMap(std::to_string(xMessageDialog->GetLOKWindowId())); return new JSMessageDialog(xMessageDialog, nullptr, true); } @@ -1308,7 +1317,7 @@ JSMessageDialog::JSMessageDialog(::MessageDialog* pDialog, SalInstanceBuilder* p = dynamic_cast<::OKButton*>(m_xMessageDialog->get_widget_for_response(RET_OK))) { m_pOK.reset(new JSButton(m_pSender, pOKBtn, nullptr, false)); - JSInstanceBuilder::AddChildWidget(m_xMessageDialog->GetLOKWindowId(), + JSInstanceBuilder::AddChildWidget(std::to_string(m_xMessageDialog->GetLOKWindowId()), pOKBtn->get_id().toUtf8(), m_pOK.get()); m_pOK->connect_clicked(LINK(this, JSMessageDialog, OKHdl)); } @@ -1317,7 +1326,7 @@ JSMessageDialog::JSMessageDialog(::MessageDialog* pDialog, SalInstanceBuilder* p = dynamic_cast<::CancelButton*>(m_xMessageDialog->get_widget_for_response(RET_CANCEL))) { m_pCancel.reset(new JSButton(m_pSender, pCancelBtn, nullptr, false)); - JSInstanceBuilder::AddChildWidget(m_xMessageDialog->GetLOKWindowId(), + JSInstanceBuilder::AddChildWidget(std::to_string(m_xMessageDialog->GetLOKWindowId()), pCancelBtn->get_id().toUtf8(), m_pCancel.get()); m_pCancel->connect_clicked(LINK(this, JSMessageDialog, CancelHdl)); } @@ -1327,7 +1336,7 @@ JSMessageDialog::JSMessageDialog(::MessageDialog* pDialog, SalInstanceBuilder* p JSMessageDialog::~JSMessageDialog() { if (m_pOK || m_pCancel) - JSInstanceBuilder::RemoveWindowWidget(m_xMessageDialog->GetLOKWindowId()); + JSInstanceBuilder::RemoveWindowWidget(std::to_string(m_xMessageDialog->GetLOKWindowId())); } IMPL_LINK_NOARG(JSMessageDialog, OKHdl, weld::Button&, void) { response(RET_OK); } |