Kaydet (Commit) 8c6342c2 authored tarafından Matúš Kukan's avatar Matúš Kukan

sfx: Use constructor feature for SfxAppDispatchProvider.

Change-Id: I2ca8abb284e8441a49c6e96a10cf76b5680e48e2
üst 90a1232f
......@@ -46,27 +46,6 @@
#include <tools/errcode.hxx>
#include <sfx2/sfxuno.hxx>
class SfxAppDispatchProvider : public ::cppu::WeakImplHelper3< ::com::sun::star::frame::XAppDispatchProvider,
::com::sun::star::lang::XServiceInfo,
::com::sun::star::lang::XInitialization >
{
::com::sun::star::uno::WeakReference < ::com::sun::star::frame::XFrame > m_xFrame;
public:
SfxAppDispatchProvider( const com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory >& )
{}
SFX_DECL_XSERVICEINFO
virtual ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatch > SAL_CALL
queryDispatch( const ::com::sun::star::util::URL& aURL, const OUString& sTargetFrameName,
FrameSearchFlags eSearchFlags ) throw( ::com::sun::star::uno::RuntimeException ) ;
virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatch > > SAL_CALL
queryDispatches( const ::com::sun::star::uno::Sequence < ::com::sun::star::frame::DispatchDescriptor >& seqDescriptor )
throw( ::com::sun::star::uno::RuntimeException ) ;
virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Sequence< sal_Int16 > SAL_CALL getSupportedCommandGroups() throw (::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchInformation > SAL_CALL getConfigurableDispatchInformation( sal_Int16 ) throw (::com::sun::star::uno::RuntimeException);
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -88,6 +88,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
sfx2/source/appl/appchild \
sfx2/source/appl/appdata \
sfx2/source/appl/appdde \
sfx2/source/appl/appdispatchprovider \
sfx2/source/appl/appinit \
sfx2/source/appl/appmain \
sfx2/source/appl/appmisc \
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/config.h>
#include <com/sun/star/frame/XAppDispatchProvider.hpp>
#include <com/sun/star/frame/XDispatch.hpp>
#include <com/sun/star/frame/XFrame.hpp>
#include <com/sun/star/frame/DispatchDescriptor.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/uno/Exception.hpp>
#include <com/sun/star/util/URL.hpp>
#include <basic/basmgr.hxx>
#include <basic/sbuno.hxx>
#include <comphelper/sequence.hxx>
#include <cppuhelper/implbase2.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <rtl/ref.hxx>
#include <sfx2/app.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/docfile.hxx>
#include <sfx2/fcontnr.hxx>
#include <sfx2/frame.hxx>
#include <sfx2/module.hxx>
#include <sfx2/msg.hxx>
#include <sfx2/msgpool.hxx>
#include <sfx2/objsh.hxx>
#include <sfx2/request.hxx>
#include <sfx2/sfxbasecontroller.hxx>
#include <sfx2/sfxsids.hrc>
#include <sfx2/sfxuno.hxx>
#include <sfx2/unoctitm.hxx>
#include <svl/intitem.hxx>
#include <tools/urlobj.hxx>
#include <vcl/svapp.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::uno;
namespace {
class SfxAppDispatchProvider : public ::cppu::WeakImplHelper2< css::frame::XAppDispatchProvider,
css::lang::XServiceInfo>
{
css::uno::WeakReference < css::frame::XFrame > m_xFrame;
public:
SfxAppDispatchProvider( const css::uno::Sequence< css::uno::Any >& aArguments )
throw (css::uno::Exception, css::uno::RuntimeException);
virtual OUString SAL_CALL getImplementationName()
throw (css::uno::RuntimeException);
virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
throw (css::uno::RuntimeException);
virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
throw (css::uno::RuntimeException);
virtual css::uno::Reference < css::frame::XDispatch > SAL_CALL queryDispatch(
const css::util::URL& aURL, const OUString& sTargetFrameName,
FrameSearchFlags eSearchFlags )
throw( css::uno::RuntimeException );
virtual css::uno::Sequence< css::uno::Reference < css::frame::XDispatch > > SAL_CALL queryDispatches(
const css::uno::Sequence < css::frame::DispatchDescriptor >& seqDescriptor )
throw( css::uno::RuntimeException );
virtual css::uno::Sequence< sal_Int16 > SAL_CALL getSupportedCommandGroups()
throw (css::uno::RuntimeException);
virtual css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL getConfigurableDispatchInformation( sal_Int16 )
throw (css::uno::RuntimeException);
};
SfxAppDispatchProvider::SfxAppDispatchProvider( const uno::Sequence<uno::Any>& aArguments )
throw (uno::Exception, uno::RuntimeException)
{
Reference < XFrame > xFrame;
if ( aArguments.getLength() )
{
aArguments[0] >>= xFrame;
m_xFrame = xFrame;
}
}
OUString SAL_CALL SfxAppDispatchProvider::getImplementationName() throw( css::uno::RuntimeException )
{
return OUString( "com.sun.star.comp.sfx2.AppDispatchProvider" );
}
sal_Bool SAL_CALL SfxAppDispatchProvider::supportsService( const OUString& sServiceName ) throw( css::uno::RuntimeException )
{
return cppu::supportsService(this, sServiceName);
}
css::uno::Sequence< OUString > SAL_CALL SfxAppDispatchProvider::getSupportedServiceNames() throw( css::uno::RuntimeException )
{
css::uno::Sequence< OUString > seqServiceNames( 2 );
seqServiceNames.getArray()[0] = "com.sun.star.frame.DispatchProvider";
seqServiceNames.getArray()[1] = "com.sun.star.frame.AppDispatchProvider";
return seqServiceNames;
}
Reference < XDispatch > SAL_CALL SfxAppDispatchProvider::queryDispatch(
const util::URL& aURL,
const OUString& /*sTargetFrameName*/,
FrameSearchFlags /*eSearchFlags*/ ) throw( RuntimeException )
{
sal_uInt16 nId( 0 );
sal_Bool bMasterCommand( sal_False );
Reference < XDispatch > xDisp;
const SfxSlot* pSlot = 0;
SfxDispatcher* pAppDisp = SFX_APP()->GetAppDispatcher_Impl();
if ( aURL.Protocol == "slot:" || aURL.Protocol == "commandId:" )
{
nId = (sal_uInt16) aURL.Path.toInt32();
SfxShell* pShell;
pAppDisp->GetShellAndSlot_Impl( nId, &pShell, &pSlot, sal_True, sal_True );
}
else if ( aURL.Protocol == ".uno:" )
{
// Support ".uno" commands. Map commands to slotid
bMasterCommand = SfxOfficeDispatch::IsMasterUnoCommand( aURL );
if ( bMasterCommand )
pSlot = pAppDisp->GetSlot( SfxOfficeDispatch::GetMasterUnoCommand( aURL ) );
else
pSlot = pAppDisp->GetSlot( aURL.Main );
}
if ( pSlot )
{
SfxOfficeDispatch* pDispatch = new SfxOfficeDispatch( pAppDisp, pSlot, aURL ) ;
pDispatch->SetFrame(m_xFrame);
pDispatch->SetMasterUnoCommand( bMasterCommand );
xDisp = pDispatch;
}
return xDisp;
}
Sequence< Reference < XDispatch > > SAL_CALL SfxAppDispatchProvider::queryDispatches( const Sequence < DispatchDescriptor >& seqDescriptor )
throw( RuntimeException )
{
sal_Int32 nCount = seqDescriptor.getLength();
uno::Sequence< uno::Reference < frame::XDispatch > > lDispatcher(nCount);
for( sal_Int32 i=0; i<nCount; ++i )
lDispatcher[i] = this->queryDispatch( seqDescriptor[i].FeatureURL,
seqDescriptor[i].FrameName,
seqDescriptor[i].SearchFlags );
return lDispatcher;
}
Sequence< sal_Int16 > SAL_CALL SfxAppDispatchProvider::getSupportedCommandGroups()
throw (uno::RuntimeException)
{
SolarMutexGuard aGuard;
std::list< sal_Int16 > aGroupList;
SfxSlotPool* pAppSlotPool = &SFX_APP()->GetAppSlotPool_Impl();
const sal_uIntPtr nMode( SFX_SLOT_TOOLBOXCONFIG|SFX_SLOT_ACCELCONFIG|SFX_SLOT_MENUCONFIG );
// Gruppe anw"ahlen ( Gruppe 0 ist intern )
for ( sal_uInt16 i=0; i<pAppSlotPool->GetGroupCount(); i++ )
{
pAppSlotPool->SeekGroup( i );
const SfxSlot* pSfxSlot = pAppSlotPool->FirstSlot();
while ( pSfxSlot )
{
if ( pSfxSlot->GetMode() & nMode )
{
sal_Int16 nCommandGroup = MapGroupIDToCommandGroup( pSfxSlot->GetGroupId() );
aGroupList.push_back( nCommandGroup );
break;
}
pSfxSlot = pAppSlotPool->NextSlot();
}
}
uno::Sequence< sal_Int16 > aSeq =
comphelper::containerToSequence< sal_Int16, std::list< sal_Int16 > >( aGroupList );
return aSeq;
}
Sequence< frame::DispatchInformation > SAL_CALL SfxAppDispatchProvider::getConfigurableDispatchInformation( sal_Int16 nCmdGroup )
throw (uno::RuntimeException)
{
std::list< frame::DispatchInformation > aCmdList;
SolarMutexGuard aGuard;
SfxSlotPool* pAppSlotPool = &SFX_APP()->GetAppSlotPool_Impl();
if ( pAppSlotPool )
{
const sal_uIntPtr nMode( SFX_SLOT_TOOLBOXCONFIG|SFX_SLOT_ACCELCONFIG|SFX_SLOT_MENUCONFIG );
OUString aCmdPrefix( ".uno:" );
// Gruppe anw"ahlen ( Gruppe 0 ist intern )
for ( sal_uInt16 i=0; i<pAppSlotPool->GetGroupCount(); i++ )
{
pAppSlotPool->SeekGroup( i );
const SfxSlot* pSfxSlot = pAppSlotPool->FirstSlot();
if ( pSfxSlot )
{
sal_Int16 nCommandGroup = MapGroupIDToCommandGroup( pSfxSlot->GetGroupId() );
if ( nCommandGroup == nCmdGroup )
{
while ( pSfxSlot )
{
if ( pSfxSlot->GetMode() & nMode )
{
frame::DispatchInformation aCmdInfo;
OUStringBuffer aBuf( aCmdPrefix );
aBuf.appendAscii( pSfxSlot->GetUnoName() );
aCmdInfo.Command = aBuf.makeStringAndClear();
aCmdInfo.GroupId = nCommandGroup;
aCmdList.push_back( aCmdInfo );
}
pSfxSlot = pAppSlotPool->NextSlot();
}
}
}
}
}
uno::Sequence< frame::DispatchInformation > aSeq =
comphelper::containerToSequence< frame::DispatchInformation, std::list< frame::DispatchInformation > >( aCmdList );
return aSeq;
}
}
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
com_sun_star_comp_sfx2_AppDispatchProvider_get_implementation(
css::uno::XComponentContext *,
css::uno::Sequence<css::uno::Any> const &arguments)
{
rtl::Reference<SfxAppDispatchProvider> x(new SfxAppDispatchProvider(arguments));
x->acquire();
return static_cast<cppu::OWeakObject *>(x.get());
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -21,8 +21,6 @@
#pragma warning( disable : 4290 )
#endif
#include <sfx2/appuno.hxx>
#include "backingcomp.hxx"
#include "SfxDocumentMetaData.hxx"
#include "appbaslib.hxx"
......@@ -1705,186 +1703,6 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence<b
rArgs = aSequ;
}
/* XServiceInfo */
OUString SAL_CALL SfxAppDispatchProvider::getImplementationName() throw( css::uno::RuntimeException )
{
return impl_getStaticImplementationName();
}
/* XServiceInfo */
sal_Bool SAL_CALL SfxAppDispatchProvider::supportsService( const OUString& sServiceName ) throw( css::uno::RuntimeException )
{
return cppu::supportsService(this, sServiceName);
}
/* XServiceInfo */
css::uno::Sequence< OUString > SAL_CALL SfxAppDispatchProvider::getSupportedServiceNames() throw( css::uno::RuntimeException )
{
return impl_getStaticSupportedServiceNames();
}
/* Helper for XServiceInfo */
css::uno::Sequence< OUString > SfxAppDispatchProvider::impl_getStaticSupportedServiceNames()
{
css::uno::Sequence< OUString > seqServiceNames( 2 );
seqServiceNames.getArray()[0] = "com.sun.star.frame.DispatchProvider";
seqServiceNames.getArray()[1] = "com.sun.star.frame.AppDispatchProvider";
return seqServiceNames;
}
/* Helper for XServiceInfo */
OUString SfxAppDispatchProvider::impl_getStaticImplementationName()
{
return OUString( "com.sun.star.comp.sfx2.AppDispatchProvider" );
}
/* Helper for registry */
css::uno::Reference< css::uno::XInterface > SAL_CALL SfxAppDispatchProvider::impl_createInstance( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ) throw( css::uno::Exception )
{
return css::uno::Reference< css::uno::XInterface >( *new SfxAppDispatchProvider( xServiceManager ) );
}
SFX_IMPL_SINGLEFACTORY( SfxAppDispatchProvider );
void SAL_CALL SfxAppDispatchProvider::initialize( const uno::Sequence<uno::Any>& aArguments ) throw (uno::Exception, uno::RuntimeException)
{
Reference < XFrame > xFrame;
if ( aArguments.getLength() )
{
aArguments[0] >>= xFrame;
m_xFrame = xFrame;
}
}
Reference < XDispatch > SAL_CALL SfxAppDispatchProvider::queryDispatch(
const util::URL& aURL,
const OUString& /*sTargetFrameName*/,
FrameSearchFlags /*eSearchFlags*/ ) throw( RuntimeException )
{
sal_uInt16 nId( 0 );
sal_Bool bMasterCommand( sal_False );
Reference < XDispatch > xDisp;
const SfxSlot* pSlot = 0;
SfxDispatcher* pAppDisp = SFX_APP()->GetAppDispatcher_Impl();
if ( aURL.Protocol == "slot:" || aURL.Protocol == "commandId:" )
{
nId = (sal_uInt16) aURL.Path.toInt32();
SfxShell* pShell;
pAppDisp->GetShellAndSlot_Impl( nId, &pShell, &pSlot, sal_True, sal_True );
}
else if ( aURL.Protocol == ".uno:" )
{
// Support ".uno" commands. Map commands to slotid
bMasterCommand = SfxOfficeDispatch::IsMasterUnoCommand( aURL );
if ( bMasterCommand )
pSlot = pAppDisp->GetSlot( SfxOfficeDispatch::GetMasterUnoCommand( aURL ) );
else
pSlot = pAppDisp->GetSlot( aURL.Main );
}
if ( pSlot )
{
SfxOfficeDispatch* pDispatch = new SfxOfficeDispatch( pAppDisp, pSlot, aURL ) ;
pDispatch->SetFrame(m_xFrame);
pDispatch->SetMasterUnoCommand( bMasterCommand );
xDisp = pDispatch;
}
return xDisp;
}
Sequence< Reference < XDispatch > > SAL_CALL SfxAppDispatchProvider::queryDispatches( const Sequence < DispatchDescriptor >& seqDescriptor )
throw( RuntimeException )
{
sal_Int32 nCount = seqDescriptor.getLength();
uno::Sequence< uno::Reference < frame::XDispatch > > lDispatcher(nCount);
for( sal_Int32 i=0; i<nCount; ++i )
lDispatcher[i] = this->queryDispatch( seqDescriptor[i].FeatureURL,
seqDescriptor[i].FrameName,
seqDescriptor[i].SearchFlags );
return lDispatcher;
}
Sequence< sal_Int16 > SAL_CALL SfxAppDispatchProvider::getSupportedCommandGroups()
throw (uno::RuntimeException)
{
SolarMutexGuard aGuard;
std::list< sal_Int16 > aGroupList;
SfxSlotPool* pAppSlotPool = &SFX_APP()->GetAppSlotPool_Impl();
const sal_uIntPtr nMode( SFX_SLOT_TOOLBOXCONFIG|SFX_SLOT_ACCELCONFIG|SFX_SLOT_MENUCONFIG );
// Gruppe anw"ahlen ( Gruppe 0 ist intern )
for ( sal_uInt16 i=0; i<pAppSlotPool->GetGroupCount(); i++ )
{
pAppSlotPool->SeekGroup( i );
const SfxSlot* pSfxSlot = pAppSlotPool->FirstSlot();
while ( pSfxSlot )
{
if ( pSfxSlot->GetMode() & nMode )
{
sal_Int16 nCommandGroup = MapGroupIDToCommandGroup( pSfxSlot->GetGroupId() );
aGroupList.push_back( nCommandGroup );
break;
}
pSfxSlot = pAppSlotPool->NextSlot();
}
}
uno::Sequence< sal_Int16 > aSeq =
comphelper::containerToSequence< sal_Int16, std::list< sal_Int16 > >( aGroupList );
return aSeq;
}
Sequence< frame::DispatchInformation > SAL_CALL SfxAppDispatchProvider::getConfigurableDispatchInformation( sal_Int16 nCmdGroup )
throw (uno::RuntimeException)
{
std::list< frame::DispatchInformation > aCmdList;
SolarMutexGuard aGuard;
SfxSlotPool* pAppSlotPool = &SFX_APP()->GetAppSlotPool_Impl();
if ( pAppSlotPool )
{
const sal_uIntPtr nMode( SFX_SLOT_TOOLBOXCONFIG|SFX_SLOT_ACCELCONFIG|SFX_SLOT_MENUCONFIG );
OUString aCmdPrefix( ".uno:" );
// Gruppe anw"ahlen ( Gruppe 0 ist intern )
for ( sal_uInt16 i=0; i<pAppSlotPool->GetGroupCount(); i++ )
{
pAppSlotPool->SeekGroup( i );
const SfxSlot* pSfxSlot = pAppSlotPool->FirstSlot();
if ( pSfxSlot )
{
sal_Int16 nCommandGroup = MapGroupIDToCommandGroup( pSfxSlot->GetGroupId() );
if ( nCommandGroup == nCmdGroup )
{
while ( pSfxSlot )
{
if ( pSfxSlot->GetMode() & nMode )
{
frame::DispatchInformation aCmdInfo;
OUStringBuffer aBuf( aCmdPrefix );
aBuf.appendAscii( pSfxSlot->GetUnoName() );
aCmdInfo.Command = aBuf.makeStringAndClear();
aCmdInfo.GroupId = nCommandGroup;
aCmdList.push_back( aCmdInfo );
}
pSfxSlot = pAppSlotPool->NextSlot();
}
}
}
}
}
uno::Sequence< frame::DispatchInformation > aSeq =
comphelper::containerToSequence< frame::DispatchInformation, std::list< frame::DispatchInformation > >( aCmdList );
return aSeq;
}
#ifdef TEST_HANDLERS
#include <cppuhelper/implbase2.hxx>
......@@ -1985,7 +1803,6 @@ SFX2_DLLPUBLIC void* SAL_CALL sfx_component_getFactory(
IF_NAME_CREATECOMPONENTFACTORY( BackingComp )
IF_NAME_CREATECOMPONENTFACTORY( SfxGlobalEvents_Impl )
IF_NAME_CREATECOMPONENTFACTORY( SfxFrameLoader_Impl )
IF_NAME_CREATECOMPONENTFACTORY( SfxAppDispatchProvider )
IF_NAME_CREATECOMPONENTFACTORY( SfxDocTplService )
IF_NAME_CREATECOMPONENTFACTORY( ShutdownIcon )
IF_NAME_CREATECOMPONENTFACTORY( SfxApplicationScriptLibraryContainer )
......
......@@ -44,7 +44,8 @@
<service name="com.sun.star.frame.SynchronousFrameLoader"/>
<service name="com.sun.star.frame.OfficeFrameLoader"/>
</implementation>
<implementation name="com.sun.star.comp.sfx2.AppDispatchProvider">
<implementation name="com.sun.star.comp.sfx2.AppDispatchProvider"
constructor="com_sun_star_comp_sfx2_AppDispatchProvider_get_implementation">
<service name="com.sun.star.frame.ProtocolHandler"/>
<service name="com.sun.star.frame.AppDispatchProvider"/>
</implementation>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment