[Libreoffice-commits] core.git: include/sfx2 sfx2/source

Maxim Monastirsky momonasmon at gmail.com
Thu Jan 19 09:27:16 UTC 2017


 include/sfx2/dispatch.hxx                  |    3 --
 sfx2/source/control/dispatch.cxx           |    4 +--
 sfx2/source/notebookbar/SfxNotebookBar.cxx |   31 +++++++++++++++++++++++++----
 3 files changed, 30 insertions(+), 8 deletions(-)

New commits:
commit c3e6d12301b42a44bd0d4584005686e324533b60
Author: Maxim Monastirsky <momonasmon at gmail.com>
Date:   Thu Jan 19 11:20:25 2017 +0200

    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

diff --git a/include/sfx2/dispatch.hxx b/include/sfx2/dispatch.hxx
index 92d0b42..a172ced 100644
--- a/include/sfx2/dispatch.hxx
+++ b/include/sfx2/dispatch.hxx
@@ -148,8 +148,7 @@ public:
     SfxViewFrame*       GetFrame() const;
     SfxModule*          GetModule() const;
 
-    void                ExecutePopup( const OUString &rResName, vcl::Window *pWin = nullptr, const Point *pPos = nullptr,
-                                      PopupMenuFlags nFlags = PopupMenuFlags::ExecuteDown );
+    void                ExecutePopup( const OUString &rResName, vcl::Window *pWin = nullptr, const Point *pPos = nullptr );
     static void         ExecutePopup( vcl::Window *pWin = nullptr, const Point *pPosPixel = nullptr );
 
     bool                IsAppDispatcher() const;
diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx
index fefdf6a..b56fa9c 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 203c0f9..2ced9f9 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();
     }
 }
 


More information about the Libreoffice-commits mailing list