prefer more css::awt::XPopupMenu api
Change-Id: Ib008281d63071ea79935af83cbe434be66155455 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126692 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
This commit is contained in:
@@ -400,7 +400,7 @@ IMPL_LINK(TreeListBox, CommandHdl, const CommandEvent&, rCEvt, bool)
|
||||
aEvent.ExecutePosition.X = -1;
|
||||
aEvent.ExecutePosition.Y = -1;
|
||||
aEvent.ActionTriggerContainer = ::framework::ActionTriggerHelper::CreateActionTriggerContainerFromMenu(
|
||||
pContextMenu.get(), &aMenuIdentifier );
|
||||
xPopupMenu, &aMenuIdentifier );
|
||||
aEvent.Selection = new SelectionSupplier(m_pContextMenuProvider->getCurrentSelection(*m_xTreeView));
|
||||
|
||||
::comphelper::OInterfaceIteratorHelper2 aIter( *pInterceptors );
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <helper/propertysetcontainer.hxx>
|
||||
#include <vcl/menu.hxx>
|
||||
#include <com/sun/star/awt/XPopupMenu.hpp>
|
||||
#include <com/sun/star/container/XNamed.hpp>
|
||||
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
||||
#include <com/sun/star/lang/XServiceInfo.hpp>
|
||||
@@ -40,7 +40,7 @@ class RootActionTriggerContainer final : public PropertySetContainer,
|
||||
public css::container::XNamed
|
||||
{
|
||||
public:
|
||||
RootActionTriggerContainer( const Menu* pMenu, const OUString* pMenuIdentifier);
|
||||
RootActionTriggerContainer(const css::uno::Reference<css::awt::XPopupMenu>& rMenu, const OUString* pMenuIdentifier);
|
||||
virtual ~RootActionTriggerContainer() override;
|
||||
|
||||
// XInterface
|
||||
@@ -92,7 +92,7 @@ class RootActionTriggerContainer final : public PropertySetContainer,
|
||||
void FillContainer();
|
||||
|
||||
bool m_bContainerCreated;
|
||||
VclPtr<const Menu> m_pMenu;
|
||||
css::uno::Reference<css::awt::XPopupMenu> m_xMenu;
|
||||
const OUString* m_pMenuIdentifier;
|
||||
};
|
||||
|
||||
|
||||
@@ -44,10 +44,11 @@ const css::uno::Sequence<sal_Int8>& RootActionTriggerContainer::getUnoTunnelId()
|
||||
return seqID;
|
||||
}
|
||||
|
||||
RootActionTriggerContainer::RootActionTriggerContainer( const Menu* pMenu, const OUString* pMenuIdentifier ) :
|
||||
m_bContainerCreated( false )
|
||||
, m_pMenu( pMenu )
|
||||
, m_pMenuIdentifier( pMenuIdentifier )
|
||||
RootActionTriggerContainer::RootActionTriggerContainer(const css::uno::Reference<css::awt::XPopupMenu>& rMenu,
|
||||
const OUString* pMenuIdentifier)
|
||||
: m_bContainerCreated(false)
|
||||
, m_xMenu(rMenu)
|
||||
, m_pMenuIdentifier(pMenuIdentifier)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -149,10 +150,10 @@ sal_Int32 SAL_CALL RootActionTriggerContainer::getCount()
|
||||
|
||||
if ( !m_bContainerCreated )
|
||||
{
|
||||
if ( m_pMenu )
|
||||
if ( m_xMenu )
|
||||
{
|
||||
SolarMutexGuard aSolarMutexGuard;
|
||||
return m_pMenu->GetItemCount();
|
||||
return m_xMenu->getItemCount();
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
@@ -181,10 +182,10 @@ Type SAL_CALL RootActionTriggerContainer::getElementType()
|
||||
|
||||
sal_Bool SAL_CALL RootActionTriggerContainer::hasElements()
|
||||
{
|
||||
if ( m_pMenu )
|
||||
if (m_xMenu)
|
||||
{
|
||||
SolarMutexGuard aSolarMutexGuard;
|
||||
return ( m_pMenu->GetItemCount() > 0 );
|
||||
return m_xMenu->getItemCount() > 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -237,8 +238,7 @@ void RootActionTriggerContainer::FillContainer()
|
||||
{
|
||||
m_bContainerCreated = true;
|
||||
ActionTriggerHelper::FillActionTriggerContainerFromMenu(
|
||||
this,
|
||||
m_pMenu );
|
||||
this, m_xMenu);
|
||||
}
|
||||
OUString RootActionTriggerContainer::getName()
|
||||
{
|
||||
|
||||
@@ -30,10 +30,9 @@
|
||||
#include <tools/stream.hxx>
|
||||
#include <comphelper/servicehelper.hxx>
|
||||
#include <cppuhelper/weak.hxx>
|
||||
#include <vcl/image.hxx>
|
||||
#include <vcl/svapp.hxx>
|
||||
#include <vcl/graph.hxx>
|
||||
#include <vcl/dibtools.hxx>
|
||||
#include <vcl/graph.hxx>
|
||||
#include <vcl/svapp.hxx>
|
||||
|
||||
const sal_uInt16 START_ITEMID = 1000;
|
||||
|
||||
@@ -228,7 +227,9 @@ static void InsertSubMenuItems(const Reference<XPopupMenu>& rSubMenu, sal_uInt16
|
||||
// implementation helper ( ActionTrigger => menu )
|
||||
|
||||
/// @throws RuntimeException
|
||||
static Reference< XPropertySet > CreateActionTrigger( sal_uInt16 nItemId, const Menu* pMenu, const Reference< XIndexContainer >& rActionTriggerContainer )
|
||||
static Reference< XPropertySet > CreateActionTrigger(sal_uInt16 nItemId,
|
||||
const Reference<XPopupMenu>& rMenu,
|
||||
const Reference<XIndexContainer>& rActionTriggerContainer)
|
||||
{
|
||||
Reference< XPropertySet > xPropSet;
|
||||
|
||||
@@ -243,11 +244,11 @@ static Reference< XPropertySet > CreateActionTrigger( sal_uInt16 nItemId, const
|
||||
try
|
||||
{
|
||||
// Retrieve the menu attributes and set them in our PropertySet
|
||||
OUString aLabel = pMenu->GetItemText( nItemId );
|
||||
OUString aLabel = rMenu->getItemText(nItemId);
|
||||
a <<= aLabel;
|
||||
xPropSet->setPropertyValue("Text", a );
|
||||
|
||||
OUString aCommandURL = pMenu->GetItemCommand( nItemId );
|
||||
OUString aCommandURL = rMenu->getCommand(nItemId);
|
||||
|
||||
if ( aCommandURL.isEmpty() )
|
||||
{
|
||||
@@ -257,12 +258,9 @@ static Reference< XPropertySet > CreateActionTrigger( sal_uInt16 nItemId, const
|
||||
a <<= aCommandURL;
|
||||
xPropSet->setPropertyValue("CommandURL", a );
|
||||
|
||||
Image aImage = pMenu->GetItemImage( nItemId );
|
||||
if ( !!aImage )
|
||||
Reference<XBitmap> xBitmap(rMenu->getItemImage(nItemId), UNO_QUERY);
|
||||
if (xBitmap.is())
|
||||
{
|
||||
Reference<css::graphic::XGraphic> xGraphic = Graphic(aImage.GetBitmapEx()).GetXGraphic();
|
||||
Reference<XBitmap> xBitmap(xGraphic, UNO_QUERY);
|
||||
assert(xGraphic.is() == xBitmap.is());
|
||||
a <<= xBitmap;
|
||||
xPropSet->setPropertyValue("Image", a );
|
||||
}
|
||||
@@ -303,21 +301,22 @@ static Reference< XIndexContainer > CreateActionTriggerContainer( const Referenc
|
||||
return Reference< XIndexContainer >();
|
||||
}
|
||||
|
||||
static void FillActionTriggerContainerWithMenu( const Menu* pMenu, Reference< XIndexContainer > const & rActionTriggerContainer )
|
||||
static void FillActionTriggerContainerWithMenu(const Reference<XPopupMenu>& rMenu,
|
||||
const Reference<XIndexContainer>& rActionTriggerContainer)
|
||||
{
|
||||
SolarMutexGuard aGuard;
|
||||
|
||||
for ( sal_uInt16 nPos = 0; nPos < pMenu->GetItemCount(); nPos++ )
|
||||
for (sal_uInt16 nPos = 0, nCount = rMenu->getItemCount(); nPos < nCount; ++nPos)
|
||||
{
|
||||
sal_uInt16 nItemId = pMenu->GetItemId( nPos );
|
||||
::MenuItemType nType = pMenu->GetItemType( nPos );
|
||||
sal_uInt16 nItemId = rMenu->getItemId(nPos);
|
||||
css::awt::MenuItemType nType = rMenu->getItemType(nPos);
|
||||
|
||||
try
|
||||
{
|
||||
Any a;
|
||||
Reference< XPropertySet > xPropSet;
|
||||
|
||||
if ( nType == ::MenuItemType::SEPARATOR )
|
||||
if (nType == css::awt::MenuItemType_SEPARATOR)
|
||||
{
|
||||
xPropSet = CreateActionTriggerSeparator( rActionTriggerContainer );
|
||||
|
||||
@@ -326,20 +325,20 @@ static void FillActionTriggerContainerWithMenu( const Menu* pMenu, Reference< XI
|
||||
}
|
||||
else
|
||||
{
|
||||
xPropSet = CreateActionTrigger( nItemId, pMenu, rActionTriggerContainer );
|
||||
xPropSet = CreateActionTrigger(nItemId, rMenu, rActionTriggerContainer);
|
||||
|
||||
a <<= xPropSet;
|
||||
rActionTriggerContainer->insertByIndex( nPos, a );
|
||||
|
||||
PopupMenu* pPopupMenu = pMenu->GetPopupMenu( nItemId );
|
||||
if ( pPopupMenu )
|
||||
css::uno::Reference<XPopupMenu> xPopupMenu = rMenu->getPopupMenu(nItemId);
|
||||
if (xPopupMenu.is())
|
||||
{
|
||||
// recursive call to build next sub menu
|
||||
Reference< XIndexContainer > xSubContainer = CreateActionTriggerContainer( rActionTriggerContainer );
|
||||
|
||||
a <<= xSubContainer;
|
||||
xPropSet->setPropertyValue("SubContainer", a );
|
||||
FillActionTriggerContainerWithMenu( pPopupMenu, xSubContainer );
|
||||
FillActionTriggerContainerWithMenu(xPopupMenu, xSubContainer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -361,16 +360,16 @@ void ActionTriggerHelper::CreateMenuFromActionTriggerContainer(
|
||||
|
||||
void ActionTriggerHelper::FillActionTriggerContainerFromMenu(
|
||||
Reference< XIndexContainer > const & xActionTriggerContainer,
|
||||
const Menu* pMenu )
|
||||
const css::uno::Reference<XPopupMenu>& rMenu)
|
||||
{
|
||||
FillActionTriggerContainerWithMenu( pMenu, xActionTriggerContainer );
|
||||
FillActionTriggerContainerWithMenu(rMenu, xActionTriggerContainer);
|
||||
}
|
||||
|
||||
Reference< XIndexContainer > ActionTriggerHelper::CreateActionTriggerContainerFromMenu(
|
||||
const Menu* pMenu,
|
||||
const css::uno::Reference<XPopupMenu>& rMenu,
|
||||
const OUString* pMenuIdentifier )
|
||||
{
|
||||
return new RootActionTriggerContainer( pMenu, pMenuIdentifier );
|
||||
return new RootActionTriggerContainer(rMenu, pMenuIdentifier);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
namespace com::sun::star::awt { class XPopupMenu; }
|
||||
namespace com::sun::star::container { class XIndexContainer; }
|
||||
class Menu;
|
||||
|
||||
namespace framework
|
||||
{
|
||||
@@ -45,20 +44,20 @@ namespace framework
|
||||
// to optimize the time of creation of a menu from an actiontrigger structure.
|
||||
// IMPORTANT: The caller must ensure that the menu pointer is valid through the
|
||||
// life time of the XIndexContainer object!!!
|
||||
// @param pNewMenu = Must be a valid menu. Please be aware that this implementation is based on
|
||||
// the above mentioned restriction!!!
|
||||
// @param rMenu = Must be a valid menu. Please be aware that this implementation is based on
|
||||
// the above mentioned restriction!!!
|
||||
|
||||
static css::uno::Reference< css::container::XIndexContainer > CreateActionTriggerContainerFromMenu(
|
||||
const Menu* pMenu, const OUString* pMenuIdentifier );
|
||||
const css::uno::Reference<css::awt::XPopupMenu>& rMenu, const OUString* pMenuIdentifier );
|
||||
|
||||
// Fills the submitted rActionTriggerContainer with the structure of the menu
|
||||
// provided as the second parameter
|
||||
// @param rActionTriggerContainer = must be an instance of service "com.sun.star.ui.ActionTriggerContainer"
|
||||
// @param pNewMenu = must be a valid menu
|
||||
// @param rMenu = must be a valid menu
|
||||
static void
|
||||
FillActionTriggerContainerFromMenu(
|
||||
css::uno::Reference< css::container::XIndexContainer > const & rActionTriggerContainer,
|
||||
const Menu* pMenu );
|
||||
const css::uno::Reference<css::awt::XPopupMenu>& rMenu);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@ class SfxModule;
|
||||
class SfxViewFrame;
|
||||
class Printer;
|
||||
class SfxPrinter;
|
||||
class Menu;
|
||||
class NotifyEvent;
|
||||
class SfxInPlaceClient;
|
||||
class SfxLokCallbackInterface;
|
||||
@@ -299,7 +298,8 @@ public:
|
||||
void SetController( SfxBaseController* pController );
|
||||
css::uno::Reference<css::frame::XController> GetController() const;
|
||||
|
||||
bool TryContextMenuInterception(const Menu& rIn, const OUString& rMenuIdentifier,
|
||||
bool TryContextMenuInterception(const css::uno::Reference<css::awt::XPopupMenu>& rIn,
|
||||
const OUString& rMenuIdentifier,
|
||||
css::uno::Reference<css::awt::XPopupMenu>& rOut,
|
||||
css::ui::ContextMenuExecuteEvent aEvent);
|
||||
bool TryContextMenuInterception(const css::uno::Reference<css::awt::XPopupMenu>&,
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <svl/eitem.hxx>
|
||||
#include <svl/whiter.hxx>
|
||||
#include <toolkit/awt/vclxmenu.hxx>
|
||||
#include <vcl/menu.hxx>
|
||||
#include <vcl/svapp.hxx>
|
||||
#include <vcl/toolbox.hxx>
|
||||
#include <vcl/weld.hxx>
|
||||
@@ -1850,7 +1849,8 @@ void SfxViewShell::RemoveContextMenuInterceptor_Impl( const uno::Reference< ui::
|
||||
pImpl->aInterceptorContainer.removeInterface( xInterceptor );
|
||||
}
|
||||
|
||||
bool SfxViewShell::TryContextMenuInterception(const Menu& rIn, const OUString& rMenuIdentifier,
|
||||
bool SfxViewShell::TryContextMenuInterception(const css::uno::Reference<css::awt::XPopupMenu>& rIn,
|
||||
const OUString& rMenuIdentifier,
|
||||
css::uno::Reference<css::awt::XPopupMenu>& rOut,
|
||||
ui::ContextMenuExecuteEvent aEvent)
|
||||
{
|
||||
@@ -1859,7 +1859,7 @@ bool SfxViewShell::TryContextMenuInterception(const Menu& rIn, const OUString& r
|
||||
|
||||
// create container from menu
|
||||
aEvent.ActionTriggerContainer = ::framework::ActionTriggerHelper::CreateActionTriggerContainerFromMenu(
|
||||
&rIn, &rMenuIdentifier );
|
||||
rIn, &rMenuIdentifier);
|
||||
|
||||
// get selection from controller
|
||||
aEvent.Selection.set( GetController(), uno::UNO_QUERY );
|
||||
@@ -1920,15 +1920,11 @@ bool SfxViewShell::TryContextMenuInterception(const Menu& rIn, const OUString& r
|
||||
bool SfxViewShell::TryContextMenuInterception(const css::uno::Reference<css::awt::XPopupMenu>& rPopupMenu,
|
||||
const OUString& rMenuIdentifier, css::ui::ContextMenuExecuteEvent aEvent)
|
||||
{
|
||||
VCLXMenu* pAwtMenu = comphelper::getFromUnoTunnel<VCLXMenu>(rPopupMenu);
|
||||
PopupMenu* pVCLMenu = static_cast<PopupMenu*>(pAwtMenu->GetMenu());
|
||||
if (!pVCLMenu)
|
||||
return false;
|
||||
|
||||
bool bModified = false;
|
||||
|
||||
// create container from menu
|
||||
aEvent.ActionTriggerContainer = ::framework::ActionTriggerHelper::CreateActionTriggerContainerFromMenu(pVCLMenu, &rMenuIdentifier);
|
||||
aEvent.ActionTriggerContainer = ::framework::ActionTriggerHelper::CreateActionTriggerContainerFromMenu(
|
||||
rPopupMenu, &rMenuIdentifier);
|
||||
|
||||
// get selection from controller
|
||||
aEvent.Selection = css::uno::Reference< css::view::XSelectionSupplier >( GetController(), css::uno::UNO_QUERY );
|
||||
|
||||
@@ -5377,7 +5377,7 @@ void SwEditWin::Command( const CommandEvent& rCEvt )
|
||||
aEvent.ExecutePosition.X = aPixPos.X();
|
||||
aEvent.ExecutePosition.Y = aPixPos.Y();
|
||||
css::uno::Reference<css::awt::XPopupMenu> xMenu;
|
||||
if (GetView().TryContextMenuInterception(aROPopup.GetMenu(), "private:resource/ReadonlyContextMenu", xMenu, aEvent))
|
||||
if (GetView().TryContextMenuInterception(aROPopup.CreateMenuInterface(), "private:resource/ReadonlyContextMenu", xMenu, aEvent))
|
||||
{
|
||||
if (xMenu.is())
|
||||
{
|
||||
|
||||
@@ -70,7 +70,7 @@ class SwReadOnlyPopup
|
||||
|
||||
public:
|
||||
SwReadOnlyPopup(const Point &rDPos, SwView &rV);
|
||||
PopupMenu& GetMenu() const { return *m_xMenu; }
|
||||
css::uno::Reference<css::awt::XPopupMenu> CreateMenuInterface() { return m_xMenu->CreateMenuInterface(); }
|
||||
~SwReadOnlyPopup();
|
||||
|
||||
void Execute( vcl::Window* pWin, const Point &rPPos );
|
||||
|
||||
@@ -129,6 +129,8 @@ public:
|
||||
return *m_xPopupMenu;
|
||||
}
|
||||
|
||||
css::uno::Reference<css::awt::XPopupMenu> CreateMenuInterface() { return m_xPopupMenu->CreateMenuInterface(); }
|
||||
|
||||
void Execute( const tools::Rectangle& rPopupPos, vcl::Window* pWin );
|
||||
void Execute( sal_uInt16 nId );
|
||||
};
|
||||
|
||||
@@ -713,7 +713,7 @@ bool SwView::ExecSpellPopup(const Point& rPt)
|
||||
|
||||
OUString sMenuName = bUseGrammarContext ?
|
||||
OUString("private:resource/GrammarContextMenu") : OUString("private:resource/SpellContextMenu");
|
||||
if (TryContextMenuInterception(xPopup->GetMenu(), sMenuName, xMenu, aEvent))
|
||||
if (TryContextMenuInterception(xPopup->CreateMenuInterface(), sMenuName, xMenu, aEvent))
|
||||
{
|
||||
//! happy hacking for context menu modifying extensions of this
|
||||
//! 'custom made' menu... *sigh* (code copied from sfx2 and framework)
|
||||
|
||||
Reference in New Issue
Block a user