diff options
author | Maxim Monastirsky <momonasmon@gmail.com> | 2015-12-17 01:29:29 +0200 |
---|---|---|
committer | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2016-07-12 22:06:31 -0400 |
commit | 320188bccca1458f1a40b3bb36f68799c841aab2 (patch) | |
tree | dbbf27b31fc918e557275a92f62e946a9679dd46 /sfx2 | |
parent | 8142805b95c69945b42b4e79c0919e6741da7628 (diff) |
tdf#93837 sfx2: Allow loading xml menus by resource name
Change-Id: Ibaeeb0f891017862578440ad874f2ceb91d11874
(cherry picked from commit 399fd4153993c3677eaaf0ad01700d64a1cb5b2c)
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/control/dispatch.cxx | 64 |
1 files changed, 35 insertions, 29 deletions
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. |