diff options
author | Maxim Monastirsky <momonasmon@gmail.com> | 2015-12-17 01:29:29 +0200 |
---|---|---|
committer | Maxim Monastirsky <momonasmon@gmail.com> | 2015-12-18 13:22:30 +0200 |
commit | 399fd4153993c3677eaaf0ad01700d64a1cb5b2c (patch) | |
tree | 2873d7214b8535578c51d2aca9b0c052cbaac702 | |
parent | ffdd3c68205ddaa2d7fd895234461c02f1560e7c (diff) |
tdf#93837 sfx2: Allow loading xml menus by resource name
Change-Id: Ibaeeb0f891017862578440ad874f2ceb91d11874
-rw-r--r-- | include/sfx2/dispatch.hxx | 4 | ||||
-rw-r--r-- | sfx2/source/control/dispatch.cxx | 64 |
2 files changed, 37 insertions, 31 deletions
diff --git a/include/sfx2/dispatch.hxx b/include/sfx2/dispatch.hxx index f09fe3a92314..c6bc45870736 100644 --- a/include/sfx2/dispatch.hxx +++ b/include/sfx2/dispatch.hxx @@ -157,8 +157,8 @@ public: // caller has to clean up the Manager on his own static SfxPopupMenuManager* Popup( sal_uInt16 nConfigId, vcl::Window *pWin, const Point *pPos ); - void ExecutePopup( const ResId &rId, - vcl::Window *pWin = nullptr, const Point *pPosPixel = nullptr ); + void ExecutePopup( const ResId &rId, vcl::Window *pWin = nullptr, const Point *pPos = nullptr ); + 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 2dc5ac8c8394..12444ef21559 100644 --- a/sfx2/source/control/dispatch.cxx +++ b/sfx2/source/control/dispatch.cxx @@ -1882,45 +1882,18 @@ void SfxDispatcher::ExecutePopup( vcl::Window *pWin, const Point *pPos ) if ( rDisp.xImp->bQuiet ) nShLevel = rDisp.xImp->aStack.size(); - vcl::Window *pWindow = pWin ? pWin : rDisp.xImp->pFrame->GetFrame().GetWorkWindow_Impl()->GetWindow(); - Point aPos = pPos ? *pPos : pWindow->GetPointerPosPixel(); for ( pSh = rDisp.GetShell(nShLevel); pSh; ++nShLevel, pSh = rDisp.GetShell(nShLevel) ) { const ResId& rResId = pSh->GetInterface()->GetPopupMenuResId(); const OUString& rResName = pSh->GetInterface()->GetPopupMenuName(); if ( rResId.GetId() ) { - SfxPopupMenuManager::ExecutePopup( rResId, rDisp.GetFrame(), aPos, pWindow ); + rDisp.ExecutePopup( rResId, pWin, pPos ); return; } else if ( !rResName.isEmpty() ) { - css::uno::Sequence< css::uno::Any > aArgs( 3 ); - aArgs[0] <<= comphelper::makePropertyValue( "Value", rResName ); - aArgs[1] <<= comphelper::makePropertyValue( "Frame", rDisp.GetFrame()->GetFrame().GetFrameInterface() ); - aArgs[2] <<= comphelper::makePropertyValue( "IsContextMenu", true ); - - 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() ) - continue; - - css::ui::ContextMenuExecuteEvent aEvent; - aEvent.SourceWindow = VCLUnoHelper::GetInterface( pWindow ); - aEvent.ExecutePosition.X = aPos.X(); - aEvent.ExecutePosition.Y = aPos.Y(); - - xPopupController->setPopupMenu( xPopupMenu ); - VCLXMenu* pAwtMenu = VCLXMenu::GetImplementation( xPopupMenu ); - PopupMenu* pVCLMenu = static_cast< PopupMenu* >( pAwtMenu->GetMenu() ); - if ( pVCLMenu && rDisp.GetFrame()->GetViewShell()->TryContextMenuInterception( *pVCLMenu, rResName, aEvent ) ) - pVCLMenu->Execute( pWindow, aPos ); + rDisp.ExecutePopup( rResName, pWin, pPos ); return; } } @@ -1932,6 +1905,39 @@ void SfxDispatcher::ExecutePopup( const ResId &rId, vcl::Window *pWin, const Poi SfxPopupMenuManager::ExecutePopup( rId, GetFrame(), pPos ? *pPos : pWindow->GetPointerPosPixel(), pWindow ); } +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 ); + aArgs[1] <<= comphelper::makePropertyValue( "Frame", GetFrame()->GetFrame().GetFrameInterface() ); + aArgs[2] <<= comphelper::makePropertyValue( "IsContextMenu", true ); + + 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; + + vcl::Window* pWindow = pWin ? pWin : xImp->pFrame->GetFrame().GetWorkWindow_Impl()->GetWindow(); + Point aPos = pPos ? *pPos : pWindow->GetPointerPosPixel(); + + css::ui::ContextMenuExecuteEvent aEvent; + aEvent.SourceWindow = VCLUnoHelper::GetInterface( pWindow ); + aEvent.ExecutePosition.X = aPos.X(); + aEvent.ExecutePosition.Y = aPos.Y(); + + xPopupController->setPopupMenu( xPopupMenu ); + VCLXMenu* pAwtMenu = VCLXMenu::GetImplementation( xPopupMenu ); + PopupMenu* pVCLMenu = static_cast< PopupMenu* >( pAwtMenu->GetMenu() ); + if ( pVCLMenu && GetFrame()->GetViewShell()->TryContextMenuInterception( *pVCLMenu, rResName, aEvent ) ) + pVCLMenu->Execute( pWindow, aPos ); +} + /** With this method the SfxDispatcher can be locked and released. A locked SfxDispatcher does not perform <SfxRequest>s and does no longer provide status information. It behaves as if all the slots were disabled. |