use more XPopupMenu methods over PopupMenu ones

Change-Id: I54acdcb82b90d363e48543de99c75adea8fceb2a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126047
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
This commit is contained in:
Caolán McNamara 2021-11-29 11:57:55 +00:00
parent 67df066460
commit 88b69059c3
3 changed files with 23 additions and 22 deletions

View File

@ -60,8 +60,8 @@ namespace framework
void retrieveShortcutsFromConfiguration( const css::uno::Reference< css::ui::XAcceleratorConfiguration >& rAccelCfg,
const css::uno::Sequence< OUString >& rCommands,
std::vector< vcl::KeyCode >& aMenuShortCuts );
void setAccelerators( PopupMenu* pPopupMenu );
void determineAndSetNewDocAccel( PopupMenu* pPopupMenu, const vcl::KeyCode& rKeyCode );
void setAccelerators();
void determineAndSetNewDocAccel(const css::awt::KeyEvent& rKeyCode);
void setMenuImages( PopupMenu* pPopupMenu, bool bSetImages );
private:

View File

@ -22,6 +22,7 @@
#include <services.h>
#include <com/sun/star/awt/MenuItemType.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
@ -106,10 +107,10 @@ void NewMenuController::setMenuImages( PopupMenu* pPopupMenu, bool bSetImages )
}
}
void NewMenuController::determineAndSetNewDocAccel( PopupMenu* pPopupMenu, const vcl::KeyCode& rKeyCode )
void NewMenuController::determineAndSetNewDocAccel(const css::awt::KeyEvent& rKeyCode)
{
sal_uInt16 nCount( pPopupMenu->GetItemCount() );
sal_uInt16 nId( 0 );
sal_uInt16 nCount(m_xPopupMenu->getItemCount());
sal_uInt16 nId( 0 );
bool bFound( false );
OUString aCommand;
@ -119,13 +120,13 @@ void NewMenuController::determineAndSetNewDocAccel( PopupMenu* pPopupMenu, const
for ( sal_uInt16 i = 0; i < nCount; i++ )
{
if ( pPopupMenu->GetItemType( i ) != MenuItemType::SEPARATOR )
if (m_xPopupMenu->getItemType(i) != css::awt::MenuItemType_SEPARATOR)
{
nId = pPopupMenu->GetItemId( i );
aCommand = pPopupMenu->GetItemCommand( nId );
nId = m_xPopupMenu->getItemId(i);
aCommand = m_xPopupMenu->getCommand(nId);
if ( aCommand.startsWith( m_aEmptyDocURL ) )
{
pPopupMenu->SetAccelKey( nId, rKeyCode );
m_xPopupMenu->setAcceleratorKeyEvent(nId, rKeyCode);
bFound = true;
break;
}
@ -143,20 +144,20 @@ void NewMenuController::determineAndSetNewDocAccel( PopupMenu* pPopupMenu, const
for ( sal_uInt16 i = 0; i < nCount; i++ )
{
if ( pPopupMenu->GetItemType( i ) != MenuItemType::SEPARATOR )
if (m_xPopupMenu->getItemType(i) != css::awt::MenuItemType_SEPARATOR)
{
nId = pPopupMenu->GetItemId( i );
aCommand = pPopupMenu->GetItemCommand( nId );
nId = m_xPopupMenu->getItemId(i);
aCommand = m_xPopupMenu->getCommand(nId);
if ( aCommand.indexOf( aDefaultModuleName ) >= 0 )
{
pPopupMenu->SetAccelKey( nId, rKeyCode );
m_xPopupMenu->setAcceleratorKeyEvent(nId, rKeyCode);
break;
}
}
}
}
void NewMenuController::setAccelerators( PopupMenu* pPopupMenu )
void NewMenuController::setAccelerators()
{
if ( !m_bModuleIdentified )
return;
@ -212,18 +213,18 @@ void NewMenuController::setAccelerators( PopupMenu* pPopupMenu )
}
vcl::KeyCode aEmptyKeyCode;
sal_uInt16 nItemCount( pPopupMenu->GetItemCount() );
sal_uInt16 nItemCount(m_xPopupMenu->getItemCount());
std::vector< vcl::KeyCode > aMenuShortCuts;
std::vector< OUString > aCmds;
std::vector< sal_uInt16 > aIds;
for ( sal_uInt16 i = 0; i < nItemCount; i++ )
{
if ( pPopupMenu->GetItemType( i ) != MenuItemType::SEPARATOR )
if (m_xPopupMenu->getItemType(i) != css::awt::MenuItemType_SEPARATOR)
{
sal_uInt16 nId( pPopupMenu->GetItemId( i ));
sal_uInt16 nId(m_xPopupMenu->getItemId(i));
aIds.push_back( nId );
aMenuShortCuts.push_back( aEmptyKeyCode );
aCmds.push_back( pPopupMenu->GetItemCommand( nId ));
aCmds.push_back(m_xPopupMenu->getCommand(nId));
}
}
@ -255,14 +256,14 @@ void NewMenuController::setAccelerators( PopupMenu* pPopupMenu )
const sal_uInt32 nCount2 = aIds.size();
for ( sal_uInt32 i = 0; i < nCount2; i++ )
pPopupMenu->SetAccelKey( aIds[i], aMenuShortCuts[i] );
m_xPopupMenu->setAcceleratorKeyEvent(aIds[i], svt::AcceleratorExecute::st_VCLKey2AWTKey(aMenuShortCuts[i]));
// Special handling for "New" menu short-cut should be set at the
// document which will be opened using it.
if ( m_bNewMenu )
{
if ( aMenuShortCuts[nSeqCount-1] != aEmptyKeyCode )
determineAndSetNewDocAccel( pPopupMenu, aMenuShortCuts[nSeqCount-1] );
determineAndSetNewDocAccel(svt::AcceleratorExecute::st_VCLKey2AWTKey(aMenuShortCuts[nSeqCount-1]));
}
}
@ -436,7 +437,7 @@ void SAL_CALL NewMenuController::itemActivated( const css::awt::MenuEvent& )
setMenuImages( pVCLPopupMenu, m_bShowImages );
}
setAccelerators( pVCLPopupMenu );
setAccelerators();
}
// XPopupMenuController

View File

@ -575,7 +575,7 @@ namespace
return aImage;
}
/** Copied from svtools/inc/acceleratorexecute.hxx */
/** Copied from include/svtools/acceleratorexecute.hxx */
css::awt::KeyEvent lcl_VCLKey2AWTKey(
const vcl::KeyCode& aVCLKey)
{