Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / uno / unomodule.cxx
blobda821aece71aebd0fe92a730a5d2e563b4f16d7f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
24 #include <swdll.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>
35 using namespace css;
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);
45 // XNotifyingDispatch
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
50 // asynchronous ...
51 uno::Reference< uno::XInterface > xThis(static_cast< frame::XNotifyingDispatch* >(this));
53 SolarMutexGuard aGuard;
54 SwGlobals::ensure();
55 const SfxSlot* pSlot = SW_MOD()->GetInterface()->GetSlot( aURL.Complete );
57 sal_Int16 aState = frame::DispatchResultState::DONTKNOW;
58 if ( !pSlot )
59 aState = frame::DispatchResultState::FAILURE;
60 else
62 SfxRequest aReq( pSlot, aArgs, SfxCallMode::SYNCHRON, SW_MOD()->GetPool() );
63 SfxAllItemSet aInternalSet( SfxGetpApp()->GetPool() );
65 css::uno::Reference<css::frame::XDesktop2> xDesktop = css::frame::Desktop::create(::comphelper::getProcessComponentContext());
66 css::uno::Reference<css::frame::XFrame> xCurrentFrame = xDesktop->getCurrentFrame();
67 if (xCurrentFrame.is()) // an empty set is no problem ... but an empty frame reference can be a problem !
68 aInternalSet.Put(SfxUnoFrameItem(SID_FILLFRAME, xCurrentFrame));
70 aReq.SetInternalArgs_Impl(aInternalSet);
71 const SfxPoolItem* pResult = SW_MOD()->ExecuteSlot( aReq );
72 if ( pResult )
73 aState = frame::DispatchResultState::SUCCESS;
74 else
75 aState = frame::DispatchResultState::FAILURE;
78 if ( xListener.is() )
80 xListener->dispatchFinished(
81 frame::DispatchResultEvent(
82 xThis, aState, uno::Any()));
86 // XDispatch
87 void SAL_CALL SwUnoModule::dispatch( const util::URL& aURL, const uno::Sequence< beans::PropertyValue >& aArgs )
89 dispatchWithNotification(aURL, aArgs, uno::Reference< frame::XDispatchResultListener >());
92 void SAL_CALL SwUnoModule::addStatusListener(
93 const uno::Reference< frame::XStatusListener > & /*xControl*/,
94 const util::URL& /*aURL*/)
98 void SAL_CALL SwUnoModule::removeStatusListener(
99 const uno::Reference< frame::XStatusListener > & /*xControl*/,
100 const util::URL& /*aURL*/)
104 uno::Sequence< uno::Reference< frame::XDispatch > > SAL_CALL SwUnoModule::queryDispatches(
105 const uno::Sequence< frame::DispatchDescriptor >& seqDescripts )
107 sal_Int32 nCount = seqDescripts.getLength();
108 uno::Sequence< uno::Reference< frame::XDispatch > > lDispatcher( nCount );
110 std::transform(seqDescripts.begin(), seqDescripts.end(), lDispatcher.getArray(),
111 [this](const frame::DispatchDescriptor& rDescr) -> uno::Reference< frame::XDispatch > {
112 return queryDispatch( rDescr.FeatureURL, rDescr.FrameName, rDescr.SearchFlags ); });
114 return lDispatcher;
117 // XDispatchProvider
118 uno::Reference< frame::XDispatch > SAL_CALL SwUnoModule::queryDispatch(
119 const util::URL& aURL, const OUString& /*sTargetFrameName*/,
120 sal_Int32 /*eSearchFlags*/ )
122 uno::Reference< frame::XDispatch > xReturn;
124 SolarMutexGuard aGuard;
125 SwGlobals::ensure();
126 const SfxSlot* pSlot = SW_MOD()->GetInterface()->GetSlot( aURL.Complete );
127 if ( pSlot )
128 xReturn = this;
130 return xReturn;
133 // XServiceInfo
134 OUString SAL_CALL SwUnoModule::getImplementationName( )
136 return "com.sun.star.comp.Writer.WriterModule";
139 sal_Bool SAL_CALL SwUnoModule::supportsService( const OUString& sServiceName )
141 return cppu::supportsService(this, sServiceName);
144 uno::Sequence< OUString > SAL_CALL SwUnoModule::getSupportedServiceNames( )
146 uno::Sequence<OUString> aSeq { "com.sun.star.text.ModuleDispatcher" };
147 return aSeq;
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */