22#include <com/sun/star/frame/XAppDispatchProvider.hpp>
23#include <com/sun/star/frame/XDispatch.hpp>
24#include <com/sun/star/frame/XFrame.hpp>
25#include <com/sun/star/frame/DispatchDescriptor.hpp>
26#include <com/sun/star/lang/IllegalArgumentException.hpp>
27#include <com/sun/star/lang/XInitialization.hpp>
28#include <com/sun/star/lang/XServiceInfo.hpp>
29#include <com/sun/star/util/URL.hpp>
48class SfxAppDispatchProvider :
public ::cppu::WeakImplHelper< css::frame::XAppDispatchProvider,
49 css::lang::XServiceInfo,
50 css::lang::XInitialization >
52 css::uno::WeakReference < css::frame::XFrame >
m_xFrame;
54 SfxAppDispatchProvider() {}
56 virtual void SAL_CALL initialize(
57 css::uno::Sequence<css::uno::Any>
const & aArguments)
override;
65 virtual css::uno::Reference < css::frame::XDispatch > SAL_CALL queryDispatch(
66 const css::util::URL& aURL,
const OUString& sTargetFrameName,
67 sal_Int32 eSearchFlags )
override;
69 virtual css::uno::Sequence< css::uno::Reference < css::frame::XDispatch > > SAL_CALL queryDispatches(
70 const css::uno::Sequence < css::frame::DispatchDescriptor >& seqDescriptor )
override;
72 virtual css::uno::Sequence< sal_Int16 > SAL_CALL getSupportedCommandGroups()
override;
74 virtual css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL getConfigurableDispatchInformation( sal_Int16 )
override;
77void SfxAppDispatchProvider::initialize(
78 css::uno::Sequence<css::uno::Any>
const & aArguments)
80 css::uno::Reference<css::frame::XFrame> f;
81 if (
aArguments.getLength() != 1 || !(aArguments[0] >>= f)) {
82 throw css::lang::IllegalArgumentException(
83 "SfxAppDispatchProvider::initialize expects one XFrame argument",
89OUString SAL_CALL SfxAppDispatchProvider::getImplementationName()
91 return "com.sun.star.comp.sfx2.AppDispatchProvider";
94sal_Bool SAL_CALL SfxAppDispatchProvider::supportsService(
const OUString& sServiceName )
99css::uno::Sequence< OUString > SAL_CALL SfxAppDispatchProvider::getSupportedServiceNames()
101 return {
"com.sun.star.frame.ProtocolHandler",
"com.sun.star.frame.AppDispatchProvider" };
104Reference < XDispatch > SAL_CALL SfxAppDispatchProvider::queryDispatch(
105 const util::URL& aURL,
111 bool bMasterCommand(
false );
112 Reference < XDispatch > xDisp;
113 const SfxSlot* pSlot =
nullptr;
118 if (
aURL.Protocol ==
"slot:" ||
aURL.Protocol ==
"commandId:" )
120 sal_uInt16
nId =
static_cast<sal_uInt16
>(
aURL.Path.toInt32());
124 else if (
aURL.Protocol ==
".uno:" )
128 if ( bMasterCommand )
137 pDispatch->SetFrame(m_xFrame);
138 pDispatch->SetMasterUnoCommand( bMasterCommand );
145Sequence< Reference < XDispatch > > SAL_CALL SfxAppDispatchProvider::queryDispatches(
const Sequence < DispatchDescriptor >& seqDescriptor )
147 sal_Int32
nCount = seqDescriptor.getLength();
148 uno::Sequence< uno::Reference < frame::XDispatch > > lDispatcher(nCount);
149 std::transform(seqDescriptor.begin(), seqDescriptor.end(), lDispatcher.getArray(),
150 [
this](
const DispatchDescriptor& rDescr) -> uno::Reference<frame::XDispatch> {
151 return queryDispatch(rDescr.FeatureURL, rDescr.FrameName, rDescr.SearchFlags); });
155Sequence< sal_Int16 > SAL_CALL SfxAppDispatchProvider::getSupportedCommandGroups()
159 std::vector< sal_Int16 > aGroupList;
171 if ( pSfxSlot->
GetMode() & nMode )
174 aGroupList.push_back( nCommandGroup );
184Sequence< frame::DispatchInformation > SAL_CALL SfxAppDispatchProvider::getConfigurableDispatchInformation( sal_Int16 nCmdGroup )
186 std::vector< frame::DispatchInformation > aCmdVector;
201 if ( nCommandGroup == nCmdGroup )
205 if ( pSfxSlot->
GetMode() & nMode )
207 frame::DispatchInformation aCmdInfo;
209 aCmdInfo.GroupId = nCommandGroup;
210 aCmdVector.push_back( aCmdInfo );
223extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
225 css::uno::XComponentContext *,
226 css::uno::Sequence<css::uno::Any>
const &)
228 return cppu::acquire(
new SfxAppDispatchProvider);
css::uno::Reference< css::lang::XComponent > m_xFrame
SfxApplication * SfxGetpApp()
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_sfx2_AppDispatchProvider_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPRIVATE SfxSlotPool & GetAppSlotPool_Impl() const
SAL_DLLPRIVATE SfxDispatcher * GetAppDispatcher_Impl()
const SfxSlot * GetSlot(const OUString &rCommand)
SAL_DLLPRIVATE bool GetShellAndSlot_Impl(sal_uInt16 nSlot, SfxShell **ppShell, const SfxSlot **ppSlot, bool bOwnShellsOnly, bool bRealSlot)
This method searches in SfxDispatcher after <SfxShell> , from the Slot Id nSlot currently being handl...
static OUString GetMasterUnoCommand(const css::util::URL &aURL)
static bool IsMasterUnoCommand(const css::util::URL &aURL)
The class SfxShell is the base class for all classes, which provide the functionality of the form <Sl...
OUString SeekGroup(sal_uInt16 nNo)
const SfxSlot * FirstSlot()
const SfxSlot * NextSlot()
sal_uInt16 GetGroupCount() const
SfxGroupId GetGroupId() const
SFX2_DLLPUBLIC OUString GetCommand() const
SfxSlotMode GetMode() const
Sequence< PropertyValue > aArguments
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
sal_Int16 MapGroupIDToCommandGroup(SfxGroupId nGroupID)