fdo#46808, Convert framework::ToolBarManager to XComponentContext

Change-Id: I4c5ddd7a2f26f51fef530b70f18a1abf61c49f77
This commit is contained in:
Noel Grandin
2013-03-18 14:47:13 +02:00
parent 86fdce6011
commit c68b934cd0
6 changed files with 37 additions and 42 deletions

View File

@@ -32,7 +32,6 @@
#include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/frame/XModuleManager.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <rtl/ustring.hxx>
#include <cppuhelper/weak.hxx>
@@ -48,7 +47,7 @@ class ToolBar;
class AddonsToolBarManager : public ToolBarManager
{
public:
AddonsToolBarManager( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rServicveManager,
AddonsToolBarManager( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rxContext,
const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame,
const OUString& rResourceName,
ToolBar* pToolBar );

View File

@@ -34,7 +34,6 @@
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/container/XIndexContainer.hpp>
#include <com/sun/star/frame/XModuleManager.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/frame/XUIControllerRegistration.hpp>
#include <com/sun/star/ui/XImageManager.hpp>
#include <com/sun/star/ui/XUIConfigurationManager.hpp>
@@ -78,7 +77,7 @@ class ToolBarManager : public ::com::sun::star::frame::XFrameActionListener
public ::cppu::OWeakObject
{
public:
ToolBarManager( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rServicveManager,
ToolBarManager( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rxContext,
const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame,
const OUString& rResourceName,
ToolBar* pToolBar );
@@ -207,7 +206,7 @@ class ToolBarManager : public ::com::sun::star::frame::XFrameActionListener
com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > m_xUICommandLabels;
ToolBarControllerMap m_aControllerMap;
::cppu::OMultiTypeInterfaceContainerHelper m_aListenerContainer; /// container for ALL Listener
::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xServiceManager;
::com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext;
::com::sun::star::uno::Reference< ::com::sun::star::frame::XUIControllerRegistration > m_xToolbarControllerRegistration;
::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager > m_xModuleImageManager;
::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager > m_xDocImageManager;

View File

@@ -76,11 +76,11 @@ namespace framework
static const char TOOLBOXITEM_SEPARATOR_STR[] = "private:separator";
static const sal_uInt16 TOOLBOXITEM_SEPARATOR_STR_LEN = sizeof( TOOLBOXITEM_SEPARATOR_STR )-1;
AddonsToolBarManager::AddonsToolBarManager( const Reference< XMultiServiceFactory >& rServiceManager,
AddonsToolBarManager::AddonsToolBarManager( const Reference< XComponentContext >& rxContext,
const Reference< XFrame >& rFrame,
const OUString& rResourceName,
ToolBar* pToolBar ) :
ToolBarManager( rServiceManager, rFrame, rResourceName, pToolBar )
ToolBarManager( rxContext, rFrame, rResourceName, pToolBar )
{
m_pToolBar->SetMenuType( TOOLBOX_MENUTYPE_CLIPPEDITEMS );
m_pToolBar->SetSelectHdl( LINK( this, AddonsToolBarManager, Select) );
@@ -215,7 +215,7 @@ void AddonsToolBarManager::FillToolbar( const Sequence< Sequence< PropertyValue
OUString aModuleIdentifier;
try
{
Reference< XModuleManager2 > xModuleManager = ModuleManager::create( comphelper::getComponentContext(m_xServiceManager) );
Reference< XModuleManager2 > xModuleManager = ModuleManager::create( m_xContext );
aModuleIdentifier = xModuleManager->identify( m_xFrame );
}
catch ( const Exception& )
@@ -223,8 +223,6 @@ void AddonsToolBarManager::FillToolbar( const Sequence< Sequence< PropertyValue
}
Reference< XMultiComponentFactory > xToolbarControllerFactory( m_xToolbarControllerRegistration, UNO_QUERY );
Reference< XComponentContext > xComponentContext(
comphelper::getComponentContext( m_xServiceManager ) );
sal_uInt32 nElements( 0 );
sal_Bool bAppendSeparator( sal_False );
@@ -297,7 +295,8 @@ void AddonsToolBarManager::FillToolbar( const Sequence< Sequence< PropertyValue
aPropValue.Value <<= m_xFrame;
aArgs[1] <<= aPropValue;
aPropValue.Name = OUString( "ServiceManager" );
aPropValue.Value <<= m_xServiceManager;
Reference<XMultiServiceFactory> xMSF(m_xContext->getServiceManager(), UNO_QUERY_THROW);
aPropValue.Value <<= xMSF;
aArgs[2] <<= aPropValue;
aPropValue.Name = OUString( "ParentWindow" );
aPropValue.Value <<= xToolbarWindow;
@@ -309,7 +308,7 @@ void AddonsToolBarManager::FillToolbar( const Sequence< Sequence< PropertyValue
try
{
xController = Reference< XStatusListener >( xToolbarControllerFactory->createInstanceWithArgumentsAndContext(
aURL, aArgs, xComponentContext ),
aURL, aArgs, m_xContext ),
UNO_QUERY );
}
catch ( const uno::Exception& )
@@ -322,7 +321,7 @@ void AddonsToolBarManager::FillToolbar( const Sequence< Sequence< PropertyValue
{
::cppu::OWeakObject* pController = 0;
pController = ToolBarMerger::CreateController( xComponentContext, m_xFrame, m_pToolBar, aURL, nId, nWidth, aControlType );
pController = ToolBarMerger::CreateController( m_xContext, m_xFrame, m_pToolBar, aURL, nId, nWidth, aControlType );
xController = Reference< XStatusListener >( pController, UNO_QUERY );
}
@@ -341,7 +340,8 @@ void AddonsToolBarManager::FillToolbar( const Sequence< Sequence< PropertyValue
aPropValue.Value <<= aURL;
aArgs[1] <<= aPropValue;
aPropValue.Name = OUString( "ServiceManager" );
aPropValue.Value <<= m_xServiceManager;
Reference<XMultiServiceFactory> xMSF(m_xContext->getServiceManager(), UNO_QUERY_THROW);
aPropValue.Value <<= xMSF;
aArgs[2] <<= aPropValue;
try
{

View File

@@ -120,7 +120,7 @@ void SAL_CALL AddonsToolBarWrapper::initialize( const Sequence< Any >& aArgument
pToolBar = new ToolBar( pWindow, nStyles );
m_xToolBarWindow = VCLUnoHelper::GetInterface( pToolBar );
pToolBarManager = new AddonsToolBarManager( m_xServiceManager, xFrame, m_aResourceURL, pToolBar );
pToolBarManager = new AddonsToolBarManager( comphelper::getComponentContext(m_xServiceManager), xFrame, m_aResourceURL, pToolBar );
pToolBar->SetToolBarManager( pToolBarManager );
m_xToolBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pToolBarManager ), UNO_QUERY );
}

View File

@@ -207,7 +207,7 @@ DEFINE_XTYPEPROVIDER_6 ( ToolBarManager
::com::sun::star::lang::XEventListener
)
ToolBarManager::ToolBarManager( const Reference< XMultiServiceFactory >& rServiceManager,
ToolBarManager::ToolBarManager( const Reference< XComponentContext >& rxContext,
const Reference< XFrame >& rFrame,
const OUString& rResourceName,
ToolBar* pToolBar ) :
@@ -226,10 +226,12 @@ ToolBarManager::ToolBarManager( const Reference< XMultiServiceFactory >& rServic
m_aResourceName( rResourceName ),
m_xFrame( rFrame ),
m_aListenerContainer( m_aLock.getShareableOslMutex() ),
m_xServiceManager( rServiceManager ),
m_xContext( rxContext ),
m_nSymbolsStyle( SvtMiscOptions().GetCurrentSymbolsStyle() ),
m_bAcceleratorCfg( sal_False )
{
OSL_ASSERT( m_xContext.is() );
Window* pWindow = m_pToolBar;
while ( pWindow && !pWindow->IsSystemWindow() )
pWindow = pWindow->GetParent();
@@ -237,13 +239,8 @@ ToolBarManager::ToolBarManager( const Reference< XMultiServiceFactory >& rServic
if ( pWindow )
((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( m_pToolBar );
if ( m_xServiceManager.is() )
{
m_xToolbarControllerRegistration = frame::ToolBarControllerFactory::create( comphelper::getComponentContext(m_xServiceManager) );
m_xURLTransformer.set(
URLTransformer::create(
::comphelper::getComponentContext(m_xServiceManager)) );
}
m_xToolbarControllerRegistration = frame::ToolBarControllerFactory::create( m_xContext );
m_xURLTransformer = URLTransformer::create( m_xContext );
m_pToolBar->SetSelectHdl( LINK( this, ToolBarManager, Select) );
m_pToolBar->SetActivateHdl( LINK( this, ToolBarManager, Activate) );
@@ -591,7 +588,7 @@ void SAL_CALL ToolBarManager::disposing( const EventObject& Source ) throw ( Run
if ( Source.Source == Reference< XInterface >( m_xFrame, UNO_QUERY ))
m_xFrame.clear();
m_xServiceManager.clear();
m_xContext.clear();
}
}
@@ -664,7 +661,7 @@ void SAL_CALL ToolBarManager::dispose() throw( RuntimeException )
}
m_xFrame.clear();
m_xServiceManager.clear();
m_xContext.clear();
m_xGlobalAcceleratorManager.clear();
m_xModuleAcceleratorManager.clear();
m_xDocAcceleratorManager.clear();
@@ -817,7 +814,7 @@ uno::Sequence< beans::PropertyValue > ToolBarManager::GetPropsForCommand( const
{
if ( !m_bModuleIdentified )
{
Reference< XModuleManager2 > xModuleManager = ModuleManager::create( comphelper::getComponentContext(m_xServiceManager) );
Reference< XModuleManager2 > xModuleManager = ModuleManager::create( m_xContext );
Reference< XInterface > xIfac( m_xFrame, UNO_QUERY );
m_bModuleIdentified = sal_True;
@@ -825,7 +822,7 @@ uno::Sequence< beans::PropertyValue > ToolBarManager::GetPropsForCommand( const
if ( !m_aModuleIdentifier.isEmpty() )
{
Reference< XNameAccess > xNameAccess = frame::UICommandDescription::create( comphelper::getComponentContext(m_xServiceManager) );
Reference< XNameAccess > xNameAccess = frame::UICommandDescription::create( m_xContext );
xNameAccess->getByName( m_aModuleIdentifier ) >>= m_xUICommandLabels;
}
}
@@ -884,8 +881,6 @@ void ToolBarManager::CreateControllers()
RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::ToolBarManager::CreateControllers" );
Reference< XMultiComponentFactory > xToolbarControllerFactory( m_xToolbarControllerRegistration, UNO_QUERY );
Reference< XComponentContext > xComponentContext(
comphelper::getComponentContext( m_xServiceManager ) );
Reference< XWindow > xToolbarWindow = VCLUnoHelper::GetInterface( m_pToolBar );
css::util::URL aURL;
@@ -935,7 +930,8 @@ void ToolBarManager::CreateControllers()
aPropValue.Value <<= m_xFrame;
aPropertyVector.push_back( makeAny( aPropValue ));
aPropValue.Name = OUString( "ServiceManager" );
aPropValue.Value <<= m_xServiceManager;
Reference<XMultiServiceFactory> xMSF(m_xContext->getServiceManager(), UNO_QUERY_THROW);
aPropValue.Value <<= xMSF;
aPropertyVector.push_back( makeAny( aPropValue ));
aPropValue.Name = OUString( "ParentWindow" );
aPropValue.Value <<= xToolbarWindow;
@@ -950,7 +946,7 @@ void ToolBarManager::CreateControllers()
Sequence< Any > aArgs( comphelper::containerToSequence( aPropertyVector ));
xController = Reference< XStatusListener >( xToolbarControllerFactory->createInstanceWithArgumentsAndContext(
aCommandURL, aArgs, xComponentContext ),
aCommandURL, aArgs, m_xContext ),
UNO_QUERY );
bInit = sal_False; // Initialization is done through the factory service
}
@@ -970,7 +966,7 @@ void ToolBarManager::CreateControllers()
OUString aControlType = static_cast< AddonsParams* >( m_pToolBar->GetItemData( nId ))->aControlType;
Reference< XStatusListener > xStatusListener(
ToolBarMerger::CreateController( comphelper::getComponentContext(m_xServiceManager),
ToolBarMerger::CreateController( m_xContext,
m_xFrame,
m_pToolBar,
aCommandURL,
@@ -986,7 +982,7 @@ void ToolBarManager::CreateControllers()
if ( it == m_aMenuMap.end() )
{
xController = Reference< XStatusListener >(
new GenericToolbarController( comphelper::getComponentContext(m_xServiceManager), m_xFrame, m_pToolBar, nId, aCommandURL ));
new GenericToolbarController( m_xContext, m_xFrame, m_pToolBar, nId, aCommandURL ));
// Accessibility support: Set toggle button role for specific commands
sal_Int32 nProps = RetrievePropertiesFromCommand( aCommandURL );
@@ -995,7 +991,7 @@ void ToolBarManager::CreateControllers()
}
else
xController = Reference< XStatusListener >(
new MenuToolbarController( comphelper::getComponentContext(m_xServiceManager), m_xFrame, m_pToolBar, nId, aCommandURL, m_aModuleIdentifier, m_aMenuMap[ nId ] ));
new MenuToolbarController( m_xContext, m_xFrame, m_pToolBar, nId, aCommandURL, m_aModuleIdentifier, m_aMenuMap[ nId ] ));
}
}
else if ( pController )
@@ -1045,7 +1041,8 @@ void ToolBarManager::CreateControllers()
aPropValue.Value <<= aCommandURL;
aPropertyVector.push_back( makeAny( aPropValue ));
aPropValue.Name = OUString( "ServiceManager" );
aPropValue.Value <<= m_xServiceManager;
Reference<XMultiServiceFactory> xMSF(m_xContext->getServiceManager(), UNO_QUERY_THROW);
aPropValue.Value <<= xMSF;
aPropertyVector.push_back( makeAny( aPropValue ));
aPropValue.Name = OUString( "ParentWindow" );
aPropValue.Value <<= xToolbarWindow;
@@ -1140,7 +1137,7 @@ void ToolBarManager::AddImageOrientationListener()
m_bImageOrientationRegistered = sal_True;
ImageOrientationListener* pImageOrientation = new ImageOrientationListener(
Reference< XStatusListener >( static_cast< ::cppu::OWeakObject *>( this ), UNO_QUERY ),
comphelper::getComponentContext(m_xServiceManager),
m_xContext,
m_xFrame );
m_xImageOrientationListener = Reference< XComponent >( static_cast< ::cppu::OWeakObject *>(
pImageOrientation ), UNO_QUERY );
@@ -1187,7 +1184,7 @@ void ToolBarManager::FillToolbar( const Reference< XIndexAccess >& rItemContaine
sal_uInt16 nId( 1 );
Reference< XModuleManager2 > xModuleManager = ModuleManager::create( comphelper::getComponentContext(m_xServiceManager) );
Reference< XModuleManager2 > xModuleManager = ModuleManager::create( m_xContext );
if ( !m_xDocImageManager.is() )
{
Reference< XModel > xModel( GetModelFromFrame() );
@@ -1216,7 +1213,7 @@ void ToolBarManager::FillToolbar( const Reference< XIndexAccess >& rItemContaine
if ( !m_xModuleImageManager.is() )
{
Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier =
ModuleUIConfigurationManagerSupplier::create( comphelper::getComponentContext( m_xServiceManager ) );
ModuleUIConfigurationManagerSupplier::create( m_xContext );
m_xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( m_aModuleIdentifier );
m_xModuleImageManager = Reference< XImageManager >( m_xUICfgMgr->getImageManager(), UNO_QUERY );
m_xModuleImageManager->addConfigurationListener( Reference< XUIConfigurationListener >(
@@ -2238,7 +2235,7 @@ bool ToolBarManager::RetrieveShortcut( const OUString& rCommandURL, OUString& rS
if ( !xModuleAccelCfg.is() )
{
Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier =
ModuleUIConfigurationManagerSupplier::create( comphelper::getComponentContext(m_xServiceManager) );
ModuleUIConfigurationManagerSupplier::create( m_xContext );
try
{
Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( m_aModuleIdentifier );
@@ -2259,7 +2256,7 @@ bool ToolBarManager::RetrieveShortcut( const OUString& rCommandURL, OUString& rS
if ( !xGlobalAccelCfg.is() )
{
xGlobalAccelCfg = GlobalAcceleratorConfiguration::create( comphelper::getComponentContext(m_xServiceManager) );
xGlobalAccelCfg = GlobalAcceleratorConfiguration::create( m_xContext );
m_xGlobalAcceleratorManager = xGlobalAccelCfg;
}
}

View File

@@ -156,7 +156,7 @@ void SAL_CALL ToolBarWrapper::initialize( const Sequence< Any >& aArguments ) th
pToolBar = new ToolBar( pWindow, nStyles );
m_xToolBarWindow = VCLUnoHelper::GetInterface( pToolBar );
pToolBarManager = new ToolBarManager( m_xServiceFactory, xFrame, m_aResourceURL, pToolBar );
pToolBarManager = new ToolBarManager( comphelper::getComponentContext(m_xServiceFactory), xFrame, m_aResourceURL, pToolBar );
pToolBar->SetToolBarManager( pToolBarManager );
m_xToolBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pToolBarManager ), UNO_QUERY );
pToolBar->WillUsePopupMode( bPopupMode );