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/lang/XMultiServiceFactory.hpp>
21 #include <com/sun/star/frame/DispatchResultState.hpp>
22 #include <com/sun/star/frame/Desktop.hpp>
23 
24 #include <swmodule.hxx>
25 #include <swdll.hxx>
26 #include <unofreg.hxx>
27 #include "unomodule.hxx"
30 #include <sfx2/objface.hxx>
31 #include <sfx2/bindings.hxx>
32 #include <sfx2/request.hxx>
33 #include <sfx2/sfxsids.hrc>
34 #include <sfx2/frame.hxx>
35 #include <vcl/svapp.hxx>
36 
37 using namespace css;
38 
39 extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
41  uno::Sequence<uno::Any> const& /*rSeq*/)
42 {
43  SolarMutexGuard aGuard;
44  return cppu::acquire(new SwUnoModule);
45 }
46 
47  // XNotifyingDispatch
48 void SAL_CALL SwUnoModule::dispatchWithNotification( const util::URL& aURL, const uno::Sequence< beans::PropertyValue >& aArgs, const uno::Reference< frame::XDispatchResultListener >& xListener )
49 {
50  // there is no guarantee, that we are holded alive during this method!
51  // May the outside dispatch container will be updated by a CONTEXT_CHANGED
52  // asynchronous ...
53  uno::Reference< uno::XInterface > xThis(static_cast< frame::XNotifyingDispatch* >(this));
54 
55  SolarMutexGuard aGuard;
57  const SfxSlot* pSlot = SW_MOD()->GetInterface()->GetSlot( aURL.Complete );
58 
59  sal_Int16 aState = frame::DispatchResultState::DONTKNOW;
60  if ( !pSlot )
61  aState = frame::DispatchResultState::FAILURE;
62  else
63  {
64  SfxRequest aReq( pSlot, aArgs, SfxCallMode::SYNCHRON, SW_MOD()->GetPool() );
65  SfxAllItemSet aInternalSet( SfxGetpApp()->GetPool() );
66 
67  css::uno::Reference<css::frame::XDesktop2> xDesktop = css::frame::Desktop::create(::comphelper::getProcessComponentContext());
68  css::uno::Reference<css::frame::XFrame> xCurrentFrame = xDesktop->getCurrentFrame();
69  if (xCurrentFrame.is()) // an empty set is no problem ... but an empty frame reference can be a problem !
70  aInternalSet.Put(SfxUnoFrameItem(SID_FILLFRAME, xCurrentFrame));
71 
72  aReq.SetInternalArgs_Impl(aInternalSet);
73  const SfxPoolItem* pResult = SW_MOD()->ExecuteSlot( aReq );
74  if ( pResult )
75  aState = frame::DispatchResultState::SUCCESS;
76  else
77  aState = frame::DispatchResultState::FAILURE;
78  }
79 
80  if ( xListener.is() )
81  {
82  xListener->dispatchFinished(
83  frame::DispatchResultEvent(
84  xThis, aState, uno::Any()));
85  }
86 }
87 
88  // XDispatch
89 void SAL_CALL SwUnoModule::dispatch( const util::URL& aURL, const uno::Sequence< beans::PropertyValue >& aArgs )
90 {
91  dispatchWithNotification(aURL, aArgs, uno::Reference< frame::XDispatchResultListener >());
92 }
93 
95  const uno::Reference< frame::XStatusListener > & /*xControl*/,
96  const util::URL& /*aURL*/)
97 {
98 }
99 
101  const uno::Reference< frame::XStatusListener > & /*xControl*/,
102  const util::URL& /*aURL*/)
103 {
104 }
105 
106 uno::Sequence< uno::Reference< frame::XDispatch > > SAL_CALL SwUnoModule::queryDispatches(
107  const uno::Sequence< frame::DispatchDescriptor >& seqDescripts )
108 {
109  sal_Int32 nCount = seqDescripts.getLength();
110  uno::Sequence< uno::Reference< frame::XDispatch > > lDispatcher( nCount );
111 
112  std::transform(seqDescripts.begin(), seqDescripts.end(), lDispatcher.begin(),
113  [this](const frame::DispatchDescriptor& rDescr) -> uno::Reference< frame::XDispatch > {
114  return queryDispatch( rDescr.FeatureURL, rDescr.FrameName, rDescr.SearchFlags ); });
115 
116  return lDispatcher;
117 }
118 
119 // XDispatchProvider
120 uno::Reference< frame::XDispatch > SAL_CALL SwUnoModule::queryDispatch(
121  const util::URL& aURL, const OUString& /*sTargetFrameName*/,
122  sal_Int32 /*eSearchFlags*/ )
123 {
124  uno::Reference< frame::XDispatch > xReturn;
125 
126  SolarMutexGuard aGuard;
128  const SfxSlot* pSlot = SW_MOD()->GetInterface()->GetSlot( aURL.Complete );
129  if ( pSlot )
130  xReturn.set(static_cast< frame::XDispatch* >(this), uno::UNO_QUERY);
131 
132  return xReturn;
133 }
134 
135 // XServiceInfo
137 {
138  return "com.sun.star.comp.Writer.WriterModule";
139 }
140 
142 {
143  return cppu::supportsService(this, sServiceName);
144 }
145 
146 uno::Sequence< OUString > SAL_CALL SwUnoModule::getSupportedServiceNames( )
147 {
148  uno::Sequence<OUString> aSeq { "com.sun.star.text.ModuleDispatcher" };
149  return aSeq;
150 }
151 
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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:106
void SetInternalArgs_Impl(const SfxAllItemSet &rArgs)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unomodule.cxx:141
virtual OUString SAL_CALL getImplementationName() override
Definition: unomodule.cxx:136
virtual void SAL_CALL dispatch(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
Definition: unomodule.cxx:89
SfxApplication * SfxGetpApp()
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:48
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
#define SW_MOD()
Definition: swmodule.hxx:256
virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xControl, const css::util::URL &aURL) override
Definition: unomodule.cxx:100
void ensure()
Definition: swdll.cxx:69
unsigned char sal_Bool
virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xControl, const css::util::URL &aURL) override
Definition: unomodule.cxx:94
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unomodule.cxx:146
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SAL_DLLPUBLIC_EXPORT uno::XInterface * com_sun_star_comp_Writer_WriterModule_get_implementation(uno::XComponentContext *, uno::Sequence< uno::Any > const &)
Definition: unomodule.cxx:40
Reference< XComponentContext > getProcessComponentContext()
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:120
const sal_Char sServiceName[]
Definition: accdoc.cxx:61