1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/frame/DispatchResultState.hpp>
21 #include <com/sun/star/frame/Desktop.hpp>
23 #include <swmodule.hxx>
25 #include "unomodule.hxx"
26 #include <cppuhelper/supportsservice.hxx>
27 #include <comphelper/processfactory.hxx>
28 #include <sfx2/objface.hxx>
29 #include <sfx2/bindings.hxx>
30 #include <sfx2/request.hxx>
31 #include <sfx2/sfxsids.hrc>
32 #include <sfx2/frame.hxx>
33 #include <vcl/svapp.hxx>
37 extern "C" SAL_DLLPUBLIC_EXPORT
uno::XInterface
*
38 com_sun_star_comp_Writer_WriterModule_get_implementation(uno::XComponentContext
* /*pCtx*/,
39 uno::Sequence
<uno::Any
> const& /*rSeq*/)
41 SolarMutexGuard aGuard
;
42 return cppu::acquire(new SwUnoModule
);
46 void SAL_CALL
SwUnoModule::dispatchWithNotification( const util::URL
& aURL
, const uno::Sequence
< beans::PropertyValue
>& aArgs
, const uno::Reference
< frame::XDispatchResultListener
>& xListener
)
48 // there is no guarantee, that we are holded alive during this method!
49 // May the outside dispatch container will be updated by a CONTEXT_CHANGED
51 uno::Reference
< uno::XInterface
> xThis(static_cast< frame::XNotifyingDispatch
* >(this));
53 SolarMutexGuard aGuard
;
55 SwModule
* mod
= SwModule::get();
56 const SfxSlot
* pSlot
= mod
->GetInterface()->GetSlot(aURL
.Complete
);
58 sal_Int16 aState
= frame::DispatchResultState::DONTKNOW
;
60 aState
= frame::DispatchResultState::FAILURE
;
63 SfxRequest
aReq(pSlot
, aArgs
, SfxCallMode::SYNCHRON
, mod
->GetPool());
64 SfxAllItemSet
aInternalSet( SfxGetpApp()->GetPool() );
66 css::uno::Reference
<css::frame::XDesktop2
> xDesktop
= css::frame::Desktop::create(::comphelper::getProcessComponentContext());
67 css::uno::Reference
<css::frame::XFrame
> xCurrentFrame
= xDesktop
->getCurrentFrame();
68 if (xCurrentFrame
.is()) // an empty set is no problem ... but an empty frame reference can be a problem !
69 aInternalSet
.Put(SfxUnoFrameItem(SID_FILLFRAME
, xCurrentFrame
));
71 aReq
.SetInternalArgs_Impl(aInternalSet
);
72 const SfxPoolItemHolder
& rResult(mod
->ExecuteSlot(aReq
));
74 aState
= frame::DispatchResultState::SUCCESS
;
76 aState
= frame::DispatchResultState::FAILURE
;
81 xListener
->dispatchFinished(
82 frame::DispatchResultEvent(
83 xThis
, aState
, uno::Any()));
88 void SAL_CALL
SwUnoModule::dispatch( const util::URL
& aURL
, const uno::Sequence
< beans::PropertyValue
>& aArgs
)
90 dispatchWithNotification(aURL
, aArgs
, uno::Reference
< frame::XDispatchResultListener
>());
93 void SAL_CALL
SwUnoModule::addStatusListener(
94 const uno::Reference
< frame::XStatusListener
> & /*xControl*/,
95 const util::URL
& /*aURL*/)
99 void SAL_CALL
SwUnoModule::removeStatusListener(
100 const uno::Reference
< frame::XStatusListener
> & /*xControl*/,
101 const util::URL
& /*aURL*/)
105 uno::Sequence
< uno::Reference
< frame::XDispatch
> > SAL_CALL
SwUnoModule::queryDispatches(
106 const uno::Sequence
< frame::DispatchDescriptor
>& seqDescripts
)
108 sal_Int32 nCount
= seqDescripts
.getLength();
109 uno::Sequence
< uno::Reference
< frame::XDispatch
> > lDispatcher( nCount
);
111 std::transform(seqDescripts
.begin(), seqDescripts
.end(), lDispatcher
.getArray(),
112 [this](const frame::DispatchDescriptor
& rDescr
) -> uno::Reference
< frame::XDispatch
> {
113 return queryDispatch( rDescr
.FeatureURL
, rDescr
.FrameName
, rDescr
.SearchFlags
); });
119 uno::Reference
< frame::XDispatch
> SAL_CALL
SwUnoModule::queryDispatch(
120 const util::URL
& aURL
, const OUString
& /*sTargetFrameName*/,
121 sal_Int32
/*eSearchFlags*/ )
123 uno::Reference
< frame::XDispatch
> xReturn
;
125 SolarMutexGuard aGuard
;
127 const SfxSlot
* pSlot
= SwModule::get()->GetInterface()->GetSlot(aURL
.Complete
);
135 OUString SAL_CALL
SwUnoModule::getImplementationName( )
137 return u
"com.sun.star.comp.Writer.WriterModule"_ustr
;
140 sal_Bool SAL_CALL
SwUnoModule::supportsService( const OUString
& sServiceName
)
142 return cppu::supportsService(this, sServiceName
);
145 uno::Sequence
< OUString
> SAL_CALL
SwUnoModule::getSupportedServiceNames( )
147 uno::Sequence
<OUString
> aSeq
{ u
"com.sun.star.text.ModuleDispatcher"_ustr
};
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */