summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2022-01-27 14:49:29 +0000
committerCaolán McNamara <caolanm@redhat.com>2022-01-27 18:26:32 +0100
commita951590bfb8d161096d87dbc953552f653318e92 (patch)
treec35cc0e0c8f21a85b873112edab3892d21a98996
parent40456ff3d26c7edc2eb49c14077b2cbfa492af3c (diff)
let SfxDispatcher::fillPopupMenu operate on css::awt::XPopupMenu
rather than need to be passed its internal PopupMenu Change-Id: Iff1106b80b71602cf8b77361086517f0e8f11c6c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129052 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--chart2/source/controller/main/ChartController_Window.cxx3
-rw-r--r--include/sfx2/dispatch.hxx4
-rw-r--r--sfx2/source/control/dispatch.cxx199
-rw-r--r--sw/source/uibase/uiview/viewling.cxx2
4 files changed, 108 insertions, 100 deletions
diff --git a/chart2/source/controller/main/ChartController_Window.cxx b/chart2/source/controller/main/ChartController_Window.cxx
index 9d5a703b27a4..c63a01b337fc 100644
--- a/chart2/source/controller/main/ChartController_Window.cxx
+++ b/chart2/source/controller/main/ChartController_Window.cxx
@@ -1302,8 +1302,7 @@ void ChartController::execute_Command( const CommandEvent& rCEvt )
}
}
- Menu* pPopupMenu = comphelper::getFromUnoTunnel<VCLXMenu>(xPopupMenu)->GetMenu();
- boost::property_tree::ptree aMenu = SfxDispatcher::fillPopupMenu(pPopupMenu);
+ boost::property_tree::ptree aMenu = SfxDispatcher::fillPopupMenu(xPopupMenu);
boost::property_tree::ptree aRoot;
aRoot.add_child("menu", aMenu);
diff --git a/include/sfx2/dispatch.hxx b/include/sfx2/dispatch.hxx
index 6e87c89217f4..7b5e3611546e 100644
--- a/include/sfx2/dispatch.hxx
+++ b/include/sfx2/dispatch.hxx
@@ -32,7 +32,6 @@
#include <boost/property_tree/ptree_fwd.hpp>
#include <initializer_list>
-class Menu;
class SfxSlotServer;
class SfxRequest;
class SfxViewFrame;
@@ -41,6 +40,7 @@ class SfxModule;
class Point;
struct SfxDispatcher_Impl;
+namespace com::sun::star::awt { class XPopupMenu; }
namespace vcl { class Window; }
enum class SfxDispatcherPopFlags
@@ -171,7 +171,7 @@ public:
SAL_DLLPRIVATE void DoDeactivate_Impl( bool bMDI, SfxViewFrame const * pNew );
SAL_DLLPRIVATE void InvalidateBindings_Impl(bool);
- static boost::property_tree::ptree fillPopupMenu(Menu* pMenu);
+ static boost::property_tree::ptree fillPopupMenu(css::uno::Reference<css::awt::XPopupMenu>& rMenu);
};
#endif
diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx
index b0eee6eefb22..71f01cd76968 100644
--- a/sfx2/source/control/dispatch.cxx
+++ b/sfx2/source/control/dispatch.cxx
@@ -1705,6 +1705,109 @@ void SfxDispatcher::ExecutePopup( vcl::Window *pWin, const Point *pPos )
}
}
+namespace {
+
+boost::property_tree::ptree fillPopupMenu(Menu* pMenu)
+{
+ // Activate this menu first
+ pMenu->HandleMenuActivateEvent(pMenu);
+ pMenu->HandleMenuDeActivateEvent(pMenu);
+
+ boost::property_tree::ptree aTree;
+ // If last item inserted is some valid text
+ bool bIsLastItemText = false;
+ sal_uInt16 nCount = pMenu->GetItemCount();
+ for (sal_uInt16 nPos = 0; nPos < nCount; nPos++)
+ {
+ boost::property_tree::ptree aItemTree;
+ const MenuItemType aItemType = pMenu->GetItemType(nPos);
+
+ if (aItemType == MenuItemType::DONTKNOW)
+ continue;
+
+ if (aItemType == MenuItemType::SEPARATOR)
+ {
+ if (bIsLastItemText)
+ aItemTree.put("type", "separator");
+ bIsLastItemText = false;
+ }
+ else
+ {
+ const sal_uInt16 nItemId = pMenu->GetItemId(nPos);
+ OUString aCommandURL = pMenu->GetItemCommand(nItemId);
+
+ if (aCommandURL.isEmpty())
+ {
+ const SfxSlot *pSlot = SFX_SLOTPOOL().GetSlot(nItemId);
+ if (pSlot)
+ aCommandURL = pSlot->GetCommandString();
+ }
+
+ const OUString aItemText = pMenu->GetItemText(nItemId);
+ Menu* pPopupSubmenu = pMenu->GetPopupMenu(nItemId);
+
+ if (!aItemText.isEmpty())
+ aItemTree.put("text", aItemText.toUtf8().getStr());
+
+ if (pPopupSubmenu)
+ {
+ boost::property_tree::ptree aSubmenu = ::fillPopupMenu(pPopupSubmenu);
+ if (aSubmenu.empty())
+ continue;
+
+ aItemTree.put("type", "menu");
+ if (!aCommandURL.isEmpty())
+ aItemTree.put("command", aCommandURL.toUtf8().getStr());
+ aItemTree.push_back(std::make_pair("menu", aSubmenu));
+ }
+ else
+ {
+ // no point in exposing choices that don't have the .uno:
+ // command
+ if (aCommandURL.isEmpty())
+ continue;
+
+ aItemTree.put("type", "command");
+ aItemTree.put("command", aCommandURL.toUtf8().getStr());
+ }
+
+ aItemTree.put("enabled", pMenu->IsItemEnabled(nItemId));
+
+ MenuItemBits aItemBits = pMenu->GetItemBits(nItemId);
+ bool bHasChecks = true;
+ if (aItemBits & MenuItemBits::CHECKABLE)
+ aItemTree.put("checktype", "checkmark");
+ else if (aItemBits & MenuItemBits::RADIOCHECK)
+ aItemTree.put("checktype", "radio");
+ else if (aItemBits & MenuItemBits::AUTOCHECK)
+ aItemTree.put("checktype", "auto");
+ else
+ bHasChecks = false;
+
+ if (bHasChecks)
+ aItemTree.put("checked", pMenu->IsItemChecked(nItemId));
+ }
+
+ if (!aItemTree.empty())
+ {
+ aTree.push_back(std::make_pair("", aItemTree));
+ if (aItemType != MenuItemType::SEPARATOR)
+ bIsLastItemText = true;
+ }
+ }
+
+ return aTree;
+}
+
+}
+
+boost::property_tree::ptree SfxDispatcher::fillPopupMenu(css::uno::Reference<css::awt::XPopupMenu>& rPopupMenu)
+{
+ VCLXMenu* pAwtMenu = comphelper::getFromUnoTunnel<VCLXMenu>(rPopupMenu);
+ PopupMenu* pVCLMenu = static_cast<PopupMenu*>(pAwtMenu->GetMenu());
+ return ::fillPopupMenu(pVCLMenu);
+}
+
void SfxDispatcher::ExecutePopup( const OUString& rResName, vcl::Window* pWin, const Point* pPos )
{
css::uno::Sequence< css::uno::Any > aArgs{
@@ -1735,9 +1838,7 @@ void SfxDispatcher::ExecutePopup( const OUString& rResName, vcl::Window* pWin, c
xPopupController->setPopupMenu( xPopupMenu );
if (comphelper::LibreOfficeKit::isActive())
{
- VCLXMenu* pAwtMenu = comphelper::getFromUnoTunnel<VCLXMenu>( xPopupMenu );
- PopupMenu* pVCLMenu = static_cast< PopupMenu* >( pAwtMenu->GetMenu() );
- boost::property_tree::ptree aMenu = fillPopupMenu(pVCLMenu);
+ boost::property_tree::ptree aMenu = fillPopupMenu(xPopupMenu);
boost::property_tree::ptree aRoot;
aRoot.add_child("menu", aMenu);
@@ -1972,96 +2073,4 @@ SfxModule* SfxDispatcher::GetModule() const
}
}
-boost::property_tree::ptree SfxDispatcher::fillPopupMenu(Menu* pMenu)
-{
- // Activate this menu first
- pMenu->HandleMenuActivateEvent(pMenu);
- pMenu->HandleMenuDeActivateEvent(pMenu);
-
- boost::property_tree::ptree aTree;
- // If last item inserted is some valid text
- bool bIsLastItemText = false;
- sal_uInt16 nCount = pMenu->GetItemCount();
- for (sal_uInt16 nPos = 0; nPos < nCount; nPos++)
- {
- boost::property_tree::ptree aItemTree;
- const MenuItemType aItemType = pMenu->GetItemType(nPos);
-
- if (aItemType == MenuItemType::DONTKNOW)
- continue;
-
- if (aItemType == MenuItemType::SEPARATOR)
- {
- if (bIsLastItemText)
- aItemTree.put("type", "separator");
- bIsLastItemText = false;
- }
- else
- {
- const sal_uInt16 nItemId = pMenu->GetItemId(nPos);
- OUString aCommandURL = pMenu->GetItemCommand(nItemId);
-
- if (aCommandURL.isEmpty())
- {
- const SfxSlot *pSlot = SFX_SLOTPOOL().GetSlot(nItemId);
- if (pSlot)
- aCommandURL = pSlot->GetCommandString();
- }
-
- const OUString aItemText = pMenu->GetItemText(nItemId);
- Menu* pPopupSubmenu = pMenu->GetPopupMenu(nItemId);
-
- if (!aItemText.isEmpty())
- aItemTree.put("text", aItemText.toUtf8().getStr());
-
- if (pPopupSubmenu)
- {
- boost::property_tree::ptree aSubmenu = fillPopupMenu(pPopupSubmenu);
- if (aSubmenu.empty())
- continue;
-
- aItemTree.put("type", "menu");
- if (!aCommandURL.isEmpty())
- aItemTree.put("command", aCommandURL.toUtf8().getStr());
- aItemTree.push_back(std::make_pair("menu", aSubmenu));
- }
- else
- {
- // no point in exposing choices that don't have the .uno:
- // command
- if (aCommandURL.isEmpty())
- continue;
-
- aItemTree.put("type", "command");
- aItemTree.put("command", aCommandURL.toUtf8().getStr());
- }
-
- aItemTree.put("enabled", pMenu->IsItemEnabled(nItemId));
-
- MenuItemBits aItemBits = pMenu->GetItemBits(nItemId);
- bool bHasChecks = true;
- if (aItemBits & MenuItemBits::CHECKABLE)
- aItemTree.put("checktype", "checkmark");
- else if (aItemBits & MenuItemBits::RADIOCHECK)
- aItemTree.put("checktype", "radio");
- else if (aItemBits & MenuItemBits::AUTOCHECK)
- aItemTree.put("checktype", "auto");
- else
- bHasChecks = false;
-
- if (bHasChecks)
- aItemTree.put("checked", pMenu->IsItemChecked(nItemId));
- }
-
- if (!aItemTree.empty())
- {
- aTree.push_back(std::make_pair("", aItemTree));
- if (aItemType != MenuItemType::SEPARATOR)
- bIsLastItemText = true;
- }
- }
-
- return aTree;
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uiview/viewling.cxx b/sw/source/uibase/uiview/viewling.cxx
index 2c349138f765..93b2d5577da9 100644
--- a/sw/source/uibase/uiview/viewling.cxx
+++ b/sw/source/uibase/uiview/viewling.cxx
@@ -769,7 +769,7 @@ bool SwView::ExecSpellPopup(const Point& rPt)
{
if (SfxViewShell* pViewShell = SfxViewShell::Current())
{
- boost::property_tree::ptree aMenu = SfxDispatcher::fillPopupMenu(&xPopup->GetMenu());
+ boost::property_tree::ptree aMenu = SfxDispatcher::fillPopupMenu(xMenuInterface);
boost::property_tree::ptree aRoot;
aRoot.add_child("menu", aMenu);