summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2024-12-17 15:35:34 +0100
committerCaolán McNamara <caolan.mcnamara@collabora.com>2024-12-17 17:47:39 +0100
commit84ce4644e9ae9e9ba258608651b292df483fe873 (patch)
tree11afb40cbca219f3527c5375a21f12111c954d01
parent4eac1d004898a2063b21a83a7e5785e22c50ba8a (diff)
jsdialog: setup parent for menu
similar to popup we point what is the parent so we can show menu just below that element / entry Signed-off-by: Szymon Kłos <szymon.klos@collabora.com> Change-Id: I09a524d3da7c5fe1c36de6a2a2033058e5554a40 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178670 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
-rw-r--r--vcl/inc/jsdialog/jsdialogmessages.hxx3
-rw-r--r--vcl/inc/jsdialog/jsdialogsender.hxx3
-rw-r--r--vcl/jsdialog/jsdialogbuilder.cxx15
-rw-r--r--vcl/jsdialog/jsdialogsender.cxx19
4 files changed, 31 insertions, 9 deletions
diff --git a/vcl/inc/jsdialog/jsdialogmessages.hxx b/vcl/inc/jsdialog/jsdialogmessages.hxx
index 7a9ebe904836..1cb4ca01a9e1 100644
--- a/vcl/inc/jsdialog/jsdialogmessages.hxx
+++ b/vcl/inc/jsdialog/jsdialogmessages.hxx
@@ -118,7 +118,8 @@ private:
OString generatePopupMessage(const VclPtr<vcl::Window>& pWindow, const OUString& sParentId,
const OUString& sCloseId) const;
OString generateClosePopupMessage(const OUString& sWindowId) const;
- OString generateMenuMessage(const VclPtr<PopupMenu>& pMenu) const;
+ OString generateMenuMessage(const VclPtr<PopupMenu>& pMenu, const OUString& sParentId,
+ const OUString& sCloseId) const;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/vcl/inc/jsdialog/jsdialogsender.hxx b/vcl/inc/jsdialog/jsdialogsender.hxx
index 44324fb07844..c43cf04cccb4 100644
--- a/vcl/inc/jsdialog/jsdialogsender.hxx
+++ b/vcl/inc/jsdialog/jsdialogsender.hxx
@@ -64,7 +64,8 @@ public:
std::unique_ptr<jsdialog::ActionDataMap> pData);
virtual void sendPopup(const VclPtr<vcl::Window>& pWindow, const OUString& sParentId,
const OUString& sCloseId);
- virtual void sendMenu(const VclPtr<PopupMenu>& pMenu);
+ virtual void sendMenu(const VclPtr<PopupMenu>& pMenu, const OUString& sParentId,
+ const OUString& sCloseId);
virtual void sendClosePopup(vcl::LOKWindowId nWindowId);
void flush() { mpIdleNotify->Invoke(); }
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index 7d8b4db3c53c..79788062b532 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -1972,11 +1972,22 @@ JSMenu::JSMenu(JSDialogSender* pSender, PopupMenu* pPopupMenu, SalInstanceBuilde
{
}
-OUString JSMenu::popup_at_rect(weld::Widget* /*pParent*/, const tools::Rectangle& /*rRect*/,
+OUString JSMenu::popup_at_rect(weld::Widget* pParent, const tools::Rectangle& rRect,
weld::Placement /*ePlace*/)
{
// Do not block with SalInstanceMenu::popup_at_rect(pParent, rRect, ePlace);
- m_pSender->sendMenu(m_pPopupMenu);
+
+ // we find position based on parent widget id and row text inside TreeView for context menu
+ OUString sCancelId;
+ weld::TreeView* pTree = dynamic_cast<weld::TreeView*>(pParent);
+ if (pTree)
+ {
+ std::unique_ptr<weld::TreeIter> itEntry(pTree->make_iterator());
+ if (pTree->get_dest_row_at_pos(rRect.Center(), itEntry.get(), false, false))
+ sCancelId = pTree->get_text(*itEntry);
+ }
+
+ m_pSender->sendMenu(m_pPopupMenu, pParent ? pParent->get_buildable_name() : "", sCancelId);
// Don't return any action - simulate canceled menu
return "";
diff --git a/vcl/jsdialog/jsdialogsender.cxx b/vcl/jsdialog/jsdialogsender.cxx
index fac9cf229013..9df5f99299b3 100644
--- a/vcl/jsdialog/jsdialogsender.cxx
+++ b/vcl/jsdialog/jsdialogsender.cxx
@@ -212,7 +212,9 @@ OString JSDialogNotifyIdle::generateClosePopupMessage(const OUString& sWindowId)
return aJsonWriter.finishAndGetAsOString();
}
-OString JSDialogNotifyIdle::generateMenuMessage(const VclPtr<PopupMenu>& pMenu) const
+OString JSDialogNotifyIdle::generateMenuMessage(const VclPtr<PopupMenu>& pMenu,
+ const OUString& sParentId,
+ const OUString& sCloseId) const
{
if (!pMenu || !m_aNotifierWindow)
return OString();
@@ -230,7 +232,8 @@ OString JSDialogNotifyIdle::generateMenuMessage(const VclPtr<PopupMenu>& pMenu)
aJsonWriter.put("jsontype", "dialog");
aJsonWriter.put("type", "dropdown");
aJsonWriter.put("cancellable", true);
- aJsonWriter.put("popupParent", m_aNotifierWindow->get_id());
+ aJsonWriter.put("popupParent", sParentId);
+ aJsonWriter.put("clickToClose", sCloseId);
aJsonWriter.put("id", m_aNotifierWindow->GetLOKWindowId());
return aJsonWriter.finishAndGetAsOString();
@@ -282,7 +285,8 @@ void JSDialogNotifyIdle::Invoke()
case jsdialog::MessageType::Menu:
{
- send(generateMenuMessage(rMessage.m_pMenu));
+ send(generateMenuMessage(rMessage.m_pMenu, (*rMessage.m_pData)[PARENT_ID ""_ostr],
+ (*rMessage.m_pData)[CLOSE_ID ""_ostr]));
break;
}
}
@@ -371,12 +375,17 @@ void JSDialogSender::sendClosePopup(vcl::LOKWindowId nWindowId)
flush();
}
-void JSDialogSender::sendMenu(const VclPtr<PopupMenu>& pMenu)
+void JSDialogSender::sendMenu(const VclPtr<PopupMenu>& pMenu, const OUString& sParentId,
+ const OUString& sCloseId)
{
if (!mpIdleNotify)
return;
- mpIdleNotify->sendMessage(jsdialog::MessageType::Menu, pMenu);
+ std::unique_ptr<jsdialog::ActionDataMap> pData = std::make_unique<jsdialog::ActionDataMap>();
+ (*pData)[PARENT_ID ""_ostr] = sParentId;
+ (*pData)[CLOSE_ID ""_ostr] = sCloseId;
+
+ mpIdleNotify->sendMessage(jsdialog::MessageType::Menu, pMenu, std::move(pData));
mpIdleNotify->Start();
}