1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 // System - Includes -----------------------------------------------------
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/frame/DispatchResultState.hpp>
29
30 #include "swmodule.hxx"
31 #include "swdll.hxx"
32 #include "unomodule.hxx"
33 #include <sfx2/objface.hxx>
34 #include <sfx2/bindings.hxx>
35 #include <sfx2/request.hxx>
36 #include <vos/mutex.hxx>
37 #include <vcl/svapp.hxx>
38
39 using namespace ::com::sun::star;
40
SwUnoModule_getImplementationName()41 ::rtl::OUString SAL_CALL SwUnoModule_getImplementationName()
42 {
43 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Writer.WriterModule" ) );
44 }
45
SwUnoModule_getSupportedServiceNames()46 uno::Sequence< rtl::OUString > SAL_CALL SwUnoModule_getSupportedServiceNames()
47 {
48 uno::Sequence< rtl::OUString > aSeq( 1 );
49 aSeq[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.ModuleDispatcher"));
50 return aSeq;
51 }
52
SwUnoModule_createInstance(const uno::Reference<lang::XMultiServiceFactory> & rSMgr)53 uno::Reference< uno::XInterface > SAL_CALL SwUnoModule_createInstance(
54 const uno::Reference< lang::XMultiServiceFactory > & rSMgr )
55 {
56 ::vos::OGuard aGuard( Application::GetSolarMutex() );
57 return uno::Reference< uno::XInterface >( dynamic_cast< frame::XDispatch * >(new SwUnoModule( rSMgr )), uno::UNO_QUERY );
58 }
59
60 // XNotifyingDispatch
dispatchWithNotification(const util::URL & aURL,const uno::Sequence<beans::PropertyValue> & aArgs,const uno::Reference<frame::XDispatchResultListener> & xListener)61 void SAL_CALL SwUnoModule::dispatchWithNotification( const util::URL& aURL, const uno::Sequence< beans::PropertyValue >& aArgs, const uno::Reference< frame::XDispatchResultListener >& xListener )
62 {
63 // there is no guarantee, that we are holded alive during this method!
64 // May the outside dispatch container will be updated by a CONTEXT_CHANGED
65 // asynchronous ...
66 uno::Reference< uno::XInterface > xThis(static_cast< frame::XNotifyingDispatch* >(this));
67
68 ::vos::OGuard aGuard( Application::GetSolarMutex() );
69 SwDLL::Init();
70 const SfxSlot* pSlot = SW_MOD()->GetInterface()->GetSlot( aURL.Complete );
71
72 sal_Int16 aState = frame::DispatchResultState::DONTKNOW;
73 if ( !pSlot )
74 aState = frame::DispatchResultState::FAILURE;
75 else
76 {
77 SfxRequest aReq( pSlot, aArgs, SFX_CALLMODE_SYNCHRON, SW_MOD()->GetPool() );
78 const SfxPoolItem* pResult = SW_MOD()->ExecuteSlot( aReq );
79 if ( pResult )
80 aState = frame::DispatchResultState::SUCCESS;
81 else
82 aState = frame::DispatchResultState::FAILURE;
83 }
84
85 if ( xListener.is() )
86 {
87 xListener->dispatchFinished(
88 frame::DispatchResultEvent(
89 xThis, aState, uno::Any()));
90 }
91 }
92
93 // XDispatch
dispatch(const util::URL & aURL,const uno::Sequence<beans::PropertyValue> & aArgs)94 void SAL_CALL SwUnoModule::dispatch( const util::URL& aURL, const uno::Sequence< beans::PropertyValue >& aArgs )
95 {
96 dispatchWithNotification(aURL, aArgs, uno::Reference< frame::XDispatchResultListener >());
97 }
98
addStatusListener(const uno::Reference<frame::XStatusListener> &,const util::URL &)99 void SAL_CALL SwUnoModule::addStatusListener(
100 const uno::Reference< frame::XStatusListener > & /*xControl*/,
101 const util::URL& /*aURL*/)
102 {
103 }
104
removeStatusListener(const uno::Reference<frame::XStatusListener> &,const util::URL &)105 void SAL_CALL SwUnoModule::removeStatusListener(
106 const uno::Reference< frame::XStatusListener > & /*xControl*/,
107 const util::URL& /*aURL*/)
108 {
109 }
110
queryDispatches(const SEQUENCE<DISPATCHDESCRIPTOR> & seqDescripts)111 SEQUENCE< REFERENCE< XDISPATCH > > SAL_CALL SwUnoModule::queryDispatches(
112 const SEQUENCE< DISPATCHDESCRIPTOR >& seqDescripts )
113 {
114 sal_Int32 nCount = seqDescripts.getLength();
115 SEQUENCE< REFERENCE< XDISPATCH > > lDispatcher( nCount );
116
117 for( sal_Int32 i=0; i<nCount; ++i )
118 {
119 lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL ,
120 seqDescripts[i].FrameName ,
121 seqDescripts[i].SearchFlags );
122 }
123
124 return lDispatcher;
125 }
126
127 // XDispatchProvider
queryDispatch(const UNOURL & aURL,const OUSTRING &,sal_Int32)128 REFERENCE< XDISPATCH > SAL_CALL SwUnoModule::queryDispatch(
129 const UNOURL& aURL, const OUSTRING& /*sTargetFrameName*/,
130 sal_Int32 /*eSearchFlags*/ )
131 {
132 REFERENCE< XDISPATCH > xReturn;
133
134 ::vos::OGuard aGuard( Application::GetSolarMutex() );
135 SwDLL::Init();
136 const SfxSlot* pSlot = SW_MOD()->GetInterface()->GetSlot( aURL.Complete );
137 if ( pSlot )
138 xReturn = REFERENCE< XDISPATCH >(static_cast< XDISPATCH* >(this), uno::UNO_QUERY);
139
140 return xReturn;
141 }
142
143 // XServiceInfo
getImplementationName()144 ::rtl::OUString SAL_CALL SwUnoModule::getImplementationName( )
145 {
146 return SwUnoModule_getImplementationName();
147 }
148
supportsService(const::rtl::OUString & sServiceName)149 sal_Bool SAL_CALL SwUnoModule::supportsService( const ::rtl::OUString& sServiceName )
150 {
151 UNOSEQUENCE< UNOOUSTRING > seqServiceNames = getSupportedServiceNames();
152 const UNOOUSTRING* pArray = seqServiceNames.getConstArray();
153 for ( sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength(); nCounter++ )
154 {
155 if ( pArray[nCounter] == sServiceName )
156 {
157 return sal_True ;
158 }
159 }
160 return sal_False ;
161 }
162
getSupportedServiceNames()163 uno::Sequence< ::rtl::OUString > SAL_CALL SwUnoModule::getSupportedServiceNames( )
164 {
165 return SwUnoModule_getSupportedServiceNames();
166 }
167