LibreOffice Module sw (master) 1
unomodule.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <com/sun/star/frame/DispatchResultState.hpp>
21#include <com/sun/star/frame/Desktop.hpp>
22
23#include <swmodule.hxx>
24#include <swdll.hxx>
25#include "unomodule.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>
34
35using namespace css;
36
37extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
39 uno::Sequence<uno::Any> const& /*rSeq*/)
40{
41 SolarMutexGuard aGuard;
42 return cppu::acquire(new SwUnoModule);
43}
44
45 // XNotifyingDispatch
46void SAL_CALL SwUnoModule::dispatchWithNotification( const util::URL& aURL, const uno::Sequence< beans::PropertyValue >& aArgs, const uno::Reference< frame::XDispatchResultListener >& xListener )
47{
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));
52
53 SolarMutexGuard aGuard;
55 const SfxSlot* pSlot = SW_MOD()->GetInterface()->GetSlot( aURL.Complete );
56
57 sal_Int16 aState = frame::DispatchResultState::DONTKNOW;
58 if ( !pSlot )
59 aState = frame::DispatchResultState::FAILURE;
60 else
61 {
62 SfxRequest aReq( pSlot, aArgs, SfxCallMode::SYNCHRON, SW_MOD()->GetPool() );
63 SfxAllItemSet aInternalSet( SfxGetpApp()->GetPool() );
64
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));
69
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;
76 }
77
78 if ( xListener.is() )
79 {
80 xListener->dispatchFinished(
81 frame::DispatchResultEvent(
82 xThis, aState, uno::Any()));
83 }
84}
85
86 // XDispatch
87void SAL_CALL SwUnoModule::dispatch( const util::URL& aURL, const uno::Sequence< beans::PropertyValue >& aArgs )
88{
89 dispatchWithNotification(aURL, aArgs, uno::Reference< frame::XDispatchResultListener >());
90}
91
93 const uno::Reference< frame::XStatusListener > & /*xControl*/,
94 const util::URL& /*aURL*/)
95{
96}
97
99 const uno::Reference< frame::XStatusListener > & /*xControl*/,
100 const util::URL& /*aURL*/)
101{
102}
103
104uno::Sequence< uno::Reference< frame::XDispatch > > SAL_CALL SwUnoModule::queryDispatches(
105 const uno::Sequence< frame::DispatchDescriptor >& seqDescripts )
106{
107 sal_Int32 nCount = seqDescripts.getLength();
108 uno::Sequence< uno::Reference< frame::XDispatch > > lDispatcher( nCount );
109
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 ); });
113
114 return lDispatcher;
115}
116
117// XDispatchProvider
118uno::Reference< frame::XDispatch > SAL_CALL SwUnoModule::queryDispatch(
119 const util::URL& aURL, const OUString& /*sTargetFrameName*/,
120 sal_Int32 /*eSearchFlags*/ )
121{
122 uno::Reference< frame::XDispatch > xReturn;
123
124 SolarMutexGuard aGuard;
126 const SfxSlot* pSlot = SW_MOD()->GetInterface()->GetSlot( aURL.Complete );
127 if ( pSlot )
128 xReturn = this;
129
130 return xReturn;
131}
132
133// XServiceInfo
135{
136 return "com.sun.star.comp.Writer.WriterModule";
137}
138
140{
142}
143
144uno::Sequence< OUString > SAL_CALL SwUnoModule::getSupportedServiceNames( )
145{
146 uno::Sequence<OUString> aSeq { "com.sun.star.text.ModuleDispatcher" };
147 return aSeq;
148}
149
150/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral sServiceName
Definition: accdoc.cxx:54
SfxApplication * SfxGetpApp()
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void SetInternalArgs_Impl(const SfxAllItemSet &rArgs)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unomodule.cxx:144
virtual void SAL_CALL dispatchWithNotification(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &aArgs, const css::uno::Reference< css::frame::XDispatchResultListener > &xListener) override
Definition: unomodule.cxx:46
virtual void SAL_CALL dispatch(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
Definition: unomodule.cxx:87
virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(const css::util::URL &aURL, const OUString &sTargetFrameName, sal_Int32 eSearchFlags) override
Definition: unomodule.cxx:118
virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xControl, const css::util::URL &aURL) override
Definition: unomodule.cxx:92
virtual OUString SAL_CALL getImplementationName() override
Definition: unomodule.cxx:134
virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(const css::uno::Sequence< css::frame::DispatchDescriptor > &seqDescriptor) override
Definition: unomodule.cxx:104
virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xControl, const css::util::URL &aURL) override
Definition: unomodule.cxx:98
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unomodule.cxx:139
int nCount
URL aURL
Sequence< sal_Int8 > aSeq
void ensure()
Definition: swdll.cxx:71
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
#define SW_MOD()
Definition: swmodule.hxx:254
unsigned char sal_Bool
SAL_DLLPUBLIC_EXPORT uno::XInterface * com_sun_star_comp_Writer_WriterModule_get_implementation(uno::XComponentContext *, uno::Sequence< uno::Any > const &)
Definition: unomodule.cxx:38