diff options
author | Maxim Monastirsky <momonasmon@gmail.com> | 2017-01-19 11:20:25 +0200 |
---|---|---|
committer | Maxim Monastirsky <momonasmon@gmail.com> | 2017-01-19 11:23:04 +0200 |
commit | c3e6d12301b42a44bd0d4584005686e324533b60 (patch) | |
tree | 9265273b884413cea94337cdf59e0e6f8cab2860 /sfx2 | |
parent | 41ef8d6df116c72f81bfa19c8e067a412c7f46db (diff) |
Using SfxDispatcher was not that good idea after all
Being a context menu it will append verbs if OLE object
is selected. Also most existing clients of context menu
interception check only current selection context, not
the menu URL (because it didn't work prior to 5.2, see
release notes), so again we might get unwanted items.
For now, just instantiate the menu controller directly.
Change-Id: Idfca6a81c12bfb6623805d5337e313eb8611f4bc
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/control/dispatch.cxx | 4 | ||||
-rw-r--r-- | sfx2/source/notebookbar/SfxNotebookBar.cxx | 31 |
2 files changed, 29 insertions, 6 deletions
diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx index fefdf6aa87ab..b56fa9cb6168 100644 --- a/sfx2/source/control/dispatch.cxx +++ b/sfx2/source/control/dispatch.cxx @@ -1942,7 +1942,7 @@ void SfxDispatcher::ExecutePopup( vcl::Window *pWin, const Point *pPos ) } } -void SfxDispatcher::ExecutePopup( const OUString& rResName, vcl::Window* pWin, const Point* pPos, PopupMenuFlags nFlags ) +void SfxDispatcher::ExecutePopup( const OUString& rResName, vcl::Window* pWin, const Point* pPos ) { css::uno::Sequence< css::uno::Any > aArgs( 3 ); aArgs[0] <<= comphelper::makePropertyValue( "Value", rResName ); @@ -1987,7 +1987,7 @@ void SfxDispatcher::ExecutePopup( const OUString& rResName, vcl::Window* pWin, c OUString aMenuURL = "private:resource/popupmenu/" + rResName; if (pVCLMenu && GetFrame()->GetViewShell()->TryContextMenuInterception(*pVCLMenu, aMenuURL, aEvent)) { - pVCLMenu->Execute(pWindow, Rectangle(aPos, aPos), nFlags); + pVCLMenu->Execute(pWindow, aPos); } } diff --git a/sfx2/source/notebookbar/SfxNotebookBar.cxx b/sfx2/source/notebookbar/SfxNotebookBar.cxx index 203c0f93f729..2ced9f926204 100644 --- a/sfx2/source/notebookbar/SfxNotebookBar.cxx +++ b/sfx2/source/notebookbar/SfxNotebookBar.cxx @@ -11,11 +11,13 @@ #include <sfx2/dispatch.hxx> #include <sfx2/notebookbar/SfxNotebookBar.hxx> #include <unotools/viewoptions.hxx> +#include <toolkit/awt/vclxmenu.hxx> #include <vcl/notebookbar.hxx> #include <vcl/syswin.hxx> #include <vcl/tabctrl.hxx> #include <sfx2/viewfrm.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/propertyvalue.hxx> #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp> #include <com/sun/star/ui/XContextChangeEventMultiplexer.hpp> #include <com/sun/star/util/URLTransformer.hpp> @@ -23,6 +25,7 @@ #include <officecfg/Office/UI/Notebookbar.hxx> #include <com/sun/star/frame/XModuleManager.hpp> #include <com/sun/star/frame/ModuleManager.hpp> +#include <com/sun/star/frame/XPopupMenuController.hpp> #include <unotools/confignode.hxx> #include <comphelper/types.hxx> @@ -336,12 +339,32 @@ void SfxNotebookBar::RemoveListeners(SystemWindow* pSysWindow) IMPL_STATIC_LINK(SfxNotebookBar, OpenNotebookbarPopupMenu, NotebookBar*, pNotebookbar, void) { SfxViewFrame* pViewFrame = SfxViewFrame::Current(); - SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : nullptr; - if (pNotebookbar && pDispatcher) + if (pNotebookbar && pViewFrame) { + css::uno::Sequence<css::uno::Any> aArgs { + css::uno::makeAny(comphelper::makePropertyValue("Value", OUString("notebookbar"))), + css::uno::makeAny(comphelper::makePropertyValue("Frame", pViewFrame->GetFrame().GetFrameInterface())) }; + + css::uno::Reference<css::uno::XComponentContext> xContext = comphelper::getProcessComponentContext(); + css::uno::Reference<css::frame::XPopupMenuController> xPopupController( + xContext->getServiceManager()->createInstanceWithArgumentsAndContext( + "com.sun.star.comp.framework.ResourceMenuController", aArgs, xContext), css::uno::UNO_QUERY); + + css::uno::Reference<css::awt::XPopupMenu> xPopupMenu(xContext->getServiceManager()->createInstanceWithContext( + "com.sun.star.awt.PopupMenu", xContext), css::uno::UNO_QUERY); + + if (!xPopupController.is() || !xPopupMenu.is()) + return; + + xPopupController->setPopupMenu(xPopupMenu); + VCLXMenu* pAwtMenu = VCLXMenu::GetImplementation(xPopupMenu); + PopupMenu* pVCLMenu = static_cast<PopupMenu*>(pAwtMenu->GetMenu()); Point aPos(0, NotebookbarTabControl::GetHeaderHeight()); - pDispatcher->ExecutePopup("notebookbar", pNotebookbar, &aPos, - PopupMenuFlags::ExecuteDown|PopupMenuFlags::NoMouseUpClose); + pVCLMenu->Execute(pNotebookbar, Rectangle(aPos, aPos),PopupMenuFlags::ExecuteDown|PopupMenuFlags::NoMouseUpClose); + + css::uno::Reference<css::lang::XComponent> xComponent(xPopupController, css::uno::UNO_QUERY); + if (xComponent.is()) + xComponent->dispose(); } } |